def markBoundarySubdomains(mesh, boundaries, **kwargs): '''Mark the boundaries of a mesh given a geometry All interior faces are marked with zero boundaries is a dictionary {label: definition of boundary} ''' bndSubdomains = MeshFunction("size_t", mesh, mesh.geometry().dim()-1) bndSubdomains.set_all(0) for i in boundaries: class BndSubDomain(SubDomain): def inside(self, x, on_boundary): value = array([0.0]) boundaries[i].eval(value, x) return (value==1.0) and on_boundary aux = BndSubDomain() aux.mark(bndSubdomains, i) # Save Dolfin XML format of the subdomains if 'outputXmlGz' in kwargs: File(kwargs['outputXmlGz']) << bndSubdomains # Save sub domains to VTK files if 'outputPvd' in kwargs: File(kwargs['outputPvd']) << bndSubdomains return bndSubdomains ## If there exist dirichlet boundary #if hasDirichlet: # if os.path.isfile(dirichletPath): # dirichletSubdomain = MeshFunction("bool", mesh, dirichletPath) # else: # # Mark faces # dirichletSubdomain.set_all(False) # class Aux(SubDomain): # def inside(self, x, on_boundary): # value = array([0.0]) # physics.dirichletBnd.eval(value, x) # return (value==1.0) and on_boundary # aux = Aux() # aux.mark(dirichletSubdomain, True) # aux.mark(bndSubdomains, 0)
def markBoundariesOfMesh(mesh, geo, **kwargs): '''Mark the boundaries of a mesh given a geometry All interior faces are marked with zero If the geometry has no marks, it will be mared using the convention: face[0] = 1 face[1] = 2 ... face[N] = N+1 ''' # Reference point indexes in each face geoBndPoints = [ face[0] for face in geo._faces ] # Face normals geoNormals = geo.getNormals() # Create mesh functions over the cell facets faceSubdomains = MeshFunction("size_t", mesh, geo._nDim-1) # Mark all facets of the domain as 0 faceSubdomains.set_all(0) # Mark boundary faces for face elements for i in range(geo.getNoFaces()): class BndSubDomain(SubDomain): def inside(self, x, on_boundary): return near( geoNormals[i].dot(Point(x)-geo._points[geoBndPoints[i]]), 0.0 ) and on_boundary aSubDomain = BndSubDomain() label = i+1 if hasattr(geo, 'facesMarkers'): label = geo.facesMarkers[i] aSubDomain.mark(faceSubdomains, label) # Save Dolfin XML format of the subdomains if 'outputXmlGz' in kwargs: File(kwargs['outputXmlGz']) << faceSubdomains # Save sub domains to VTK files if 'outputPvd' in kwargs: File(kwargs['outputPvd']) << faceSubdomains return faceSubdomains
# Here we consider 0 as a internal face bndSubdomains = markBoundariesOfMesh(mesh, geo, outputPvd="localBoundary.pvd") globalBndSubdomains = MeshFunction("size_t", mesh, geo._nDim - 1) # If there exist marked boundary if 'boundaries' in dir(physics): if (reutilizeBoundaryInfo and isfile(bndPath)): globalBndSubdomains = MeshFunction("size_t", mesh, bndPath) else: globalBndSubdomains = markBoundarySubdomains(mesh, physics.boundaries, outputXmlGz=bndPath, outputPvd=bndPvd) else: globalBndSubdomains.set_all(0) # Boundary measures ds = Measure('ds', domain=mesh, subdomain_data=bndSubdomains) dsGlobal = Measure('ds', domain=mesh, subdomain_data=globalBndSubdomains) ### ### Numerical configuration ### # MHM parameters psiL = 1 # Psi scalar strings # psiString = [ "1.0" ] # psiString = []
else: print("Mesh bndFile does not exist!") exit(1) # Here we consider 0 as a internal face #dirichletSubdomain = MeshFunction("bool", mesh, geo.nDim-1) bndSubdomains = MeshFunction("size_t", mesh, geo._nDim-1) # If there exist marked boundary if 'boundaries' in dir(physics): if (reutilizeBoundaryInfo and isfile(bndPath)): bndSubdomains = MeshFunction("size_t", mesh, bndPath) else: bndSubdomains = markBoundarySubdomains(mesh, physics.boundaries, outputXmlGz=bndPath, outputPvd=bndPvd) else: bndSubdomains.set_all(0) ## Get the set of subdomains #setneumannSubdomains = set(neumannSubdomains.array()) #nBoundarySubdomains = len(setneumannSubdomains)-1 #exclude 0 labels # Define measures ds = Measure('ds', domain=mesh, subdomain_data=bndSubdomains) # boundary measure # Plot mesh #plot(mesh, interactive=True) #plot(bndSubdomains, interactive=True) #plot(dirichletSubdomain, interactive=True) ### ### Variational scheme