Thank you, I can now read the mesh with no issues.
However, I would like to make sure that the labelled boundaries ds
are correct. To do this, I read the mesh and evaluate a test function at ds
on the left and right edge of the line, here is the minimal working example ‘mwe.py’:
from __future__ import print_function
from fenics import *
from mshr import *
from fenics import *
from mshr import *
L = 1.0
mesh=Mesh()
with XDMFFile("line_mesh.xdmf") as infile:
infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, mesh.topology().dim())
with XDMFFile("line_mesh.xdmf") as infile:
infile.read(mvc, "name_to_read")
mf = dolfin.cpp.mesh.MeshFunctionSizet(mesh, mvc)
# Define function spaces
#finite elements for sigma .... omega
P_v = VectorElement( 'P', mesh.ufl_cell(), 2 )
P_z = FiniteElement( 'P', mesh.ufl_cell(), 1 )
element = MixedElement( [P_v, P_z] )
Q = FunctionSpace(mesh, element)
Q_v = Q.sub( 0 ).collapse()
Q_z= Q.sub( 1 ).collapse()
#analytical expression for a scalar function used to test the ds
class TestFunction( UserExpression ):
def eval(self, values, x):
values[0] = x[0]**2
def value_shape(self):
return (1,)
# test for surface elements
ds_l = Measure( "ds", domain=mesh, subdomain_data=mf, subdomain_id=2 )
ds_r = Measure( "ds", domain=mesh, subdomain_data=mf, subdomain_id=3 )
f_test_ds = Function( Q_z )
f_test_ds.interpolate( TestFunction( element=Q_z.ufl_element() ) )
integral_l = assemble( f_test_ds * ds_l )
integral_r = assemble( f_test_ds * ds_r )
print( "Integral l = ", integral_l, " should be = 0" )
print( "Integral r = ", integral_r, " should be = 1" )
and I get
$python3 mwe.py
Integral l = 0.0 should be = 0
Integral r = 0.0 should be = 1
Shouldn’t I get the value of the function at the boundaries in integral_l and integral_r ?
Is this because the integration domain ds
has zero measure in 1d? If so, how may I test that ds_l and ds_r correspond to the two extremal points of the line ?