Raviart-Thomas elements not correct on manifold

Issue #75 resolved
Chris Richardson created an issue

Running the following test:

mesh2d = UnitSquareMesh(2, 2)

# Convert 2D mesh to 2D mesh in 3D space
mesh3d = Mesh()
e = MeshEditor()
e.open(mesh3d, 2, 3)
e.init_vertices(mesh2d.num_vertices())
for (i, x) in enumerate(mesh2d.coordinates()):
    e.add_vertex(i, x[0], x[1], 0.0)
e.init_cells(mesh2d.num_cells())
for (i, cell) in enumerate(mesh2d.cells()):
    e.add_cell(i, cell[0], cell[1], cell[2])
e.close()

# This makes no difference here
mesh3d.init_cell_orientations(Constant((0, 0, 1)))

mfile2 = File("mesh2d.xdmf")
mfile2 << mesh2d

mfile3 = File("mesh3d.xdmf")
mfile3 << mesh3d

Q2D = FunctionSpace(mesh2d, "RT", 1)
Q3D = FunctionSpace(mesh3d, "RT", 1)
F2D = Function(Q2D)
F3D = Function(Q3D)
F2D.interpolate(Constant((0.0, 1.0)))
F3D.interpolate(Constant((0.0, 1.0, 0.0)))

print F2D.vector().array()
print F3D.vector().array()

v2D=F2D.compute_vertex_values().reshape(2,-1).transpose()
v3D=F3D.compute_vertex_values().reshape(3,-1).transpose()

print v2D
print v3D

output2d = File("f2d.xdmf")
output2d << F2D

output3d = File("f3d.xdmf")
output3d << F3D

results in spurious output. Both should be the same, as the only difference is the geometric dimension of the Mesh.

[ 0.  -0.5 -0.5 -0.5  0.   0.  -0.5 -0.5 -0.5 -0.5  0.   0.  -0.5 -0.5 -0.5
  0. ]
[-0.   0.5  0.5 -0.5 -0.  -0.   0.5  0.5 -0.5  0.5  0.  -0.  -0.5  0.5 -0.5
  0. ]
[[ 0.  1.]
 [ 0.  1.]
 [ 0.  1.]
 [ 0.  1.]
 [ 0.  1.]
 [ 0.  1.]
 [ 0.  1.]
 [ 0.  1.]
 [ 0.  1.]]
[[ 0.  1.  0.]
 [ 0.  1.  0.]
 [ 1.  0. -1.]
 [ 0.  1.  0.]
 [ 0.  1.  0.]
 [ 1.  0. -1.]
 [ 1.  0.  1.]
 [ 1.  0.  1.]
 [ 0.  0.  0.]]

Comments (8)

  1. Chris Richardson reporter

    In a good way or a bad way?

    I just tried the code above again with the latest ffc, and it still does the same. Do you mean that it may have worked correctly prior to that commit?

    Maybe there is something wrong about my assumptions when writing this test code?

  2. Prof Garth Wells

    I mean does the commit fix the problem. I do not believe that the commit has been pushed to master.

  3. Chris Richardson reporter

    I tracked this down in FFC, this patch fixes it... but probably should be done better. I will raise an issue for ffc.

    --- a/ffc/interpolatevertexvalues.py
    +++ b/ffc/interpolatevertexvalues.py
    @@ -97,9 +97,12 @@ def _interpolate_vertex_values_element(data, gdim, tdim, total_value_size,
         change_of_variables = _change_variables(data["mapping"], gdim, tdim,
                                                 space_dim)
    
    +    if(gdim==3 and tdim==2):
    +        total_value_size = 3
    +
         # Create code for each value dimension:
         code = []
    -    for k in range(value_size):
    +    for k in range(total_value_size):
    
  4. Martin Sandve Alnæs

    I don't see how this patch can be correct. The value size of an element is in general independent of gdim/tdim.

  5. Chris Richardson reporter

    I agree that patch is bad - it does produce the right answer for the special case I was looking at (but maybe the wrong way!)

  6. Log in to comment