Hello all,
I have a question that I wish someone could help. Truly appreciate!
I have a 2-sphere mesh that is spited into two regions, which an internal boundary as their interface. I would like to access/set the all values of a function that is below/above the internal boundary (in this case, a horizontal cut with respect to the z-axis). I ran into several difficulties:
- I do not know how to access them with respect to different domains. I have tried to naively access the positive/negative sides across the boundary by using ("+/-"), but it seems does not work.
- The ("-") seems to have no values assigned.
Below is the code.
Thank you!
def sphere_mesh(outer_radius,mesh_density ):
center = Point()
sphere_shell = Sphere(center, outer_radius)#-Sphere(center, inner_radius)
mesh = generate_mesh(sphere_shell, mesh_density)
bmesh = BoundaryMesh(mesh, "exterior")
print(bmesh.topology().dim())
global_normal = Expression(("x[0]", "x[1]", "x[2]"), degree=1)
bmesh.init_cell_orientations(global_normal)
return bmesh
def mark_region(bmesh,z_loc,bc_tol=0.1,tol=1E-10):
class Bc_region(SubDomain):
def inside(self,x,on_boundary):
return (near(x[2],-z_loc,bc_tol) or near(x[2],z_loc,bc_tol) )
class Bulk_region(SubDomain):
def inside(self,x,on_boundary):
return (x[2]<=z_loc+tol and -z_loc-tol <= x[2])# or((near(x[2],-z_loc,bc_tol) or near(x[2],z_loc,bc_tol) ))
bc_region=Bc_region()
bulk_region=Bulk_region()
# define the boundary
boundary_parts =MeshFunction('size_t', bmesh, bmesh.topology().dim()-1, 0) #FacetFunction("size_t", self.bmesh)
#print('bc dimension:'+str(self.bmesh.topology().dim()-1))
boundary_parts.set_all(0)
bulk_parts =MeshFunction('size_t', bmesh, bmesh.topology().dim(), 0) #CellFunction("size_t", self.bmesh)
bulk_parts.set_all(0)
bulk_region.mark(bulk_parts,1)
bc_region.mark(boundary_parts,2)
return boundary_parts, bulk_parts
b_mesh=sphere_mesh(outer_radius=1,mesh_density=30)
mark_region(b_mesh,0.5)
P=FiniteElement('DG',b_mesh.ufl_cell(),1)
element=MixedElement([P,P])
b_space=FunctionSpace(b_mesh,element)
Init_val=Expression(('x[1]*x[0]','x[2]*x[1]'),degree=1)
projected_fuc=project(Init_val,b_space)
#get the value in region below the boundary
fuc_below_bc=projected_fuc("+")
print(project(fuc_below_bc,b_space).compute_vertex_values())
fuc_above_bc=projected_fuc("-")
print(project(fuc_above_bc,b_space).compute_vertex_values())