本文整理汇总了Python中dolfin.Mesh.domains方法的典型用法代码示例。如果您正苦于以下问题:Python Mesh.domains方法的具体用法?Python Mesh.domains怎么用?Python Mesh.domains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dolfin.Mesh
的用法示例。
在下文中一共展示了Mesh.domains方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_convert_diffpack
# 需要导入模块: from dolfin import Mesh [as 别名]
# 或者: from dolfin.Mesh import domains [as 别名]
def test_convert_diffpack(self):
from dolfin import Mesh, MPI, MeshFunction
if MPI.num_processes() != 1:
return
fname = os.path.join("data", "diffpack_tet")
dfname = fname+".xml"
# Read triangle file and convert to a dolfin xml mesh file
meshconvert.diffpack2xml(fname+".grid", dfname)
# Read in dolfin mesh and check number of cells and vertices
mesh = Mesh(dfname)
self.assertEqual(mesh.num_vertices(), 27)
self.assertEqual(mesh.num_cells(), 48)
self.assertEqual(mesh.domains().markers(3).size(), 48)
self.assertEqual(mesh.domains().markers(2).size(), 16)
mf_basename = dfname.replace(".xml", "_marker_%d.xml")
for marker, num in [(3, 9), (6, 9), (7, 3), (8, 1)]:
mf_name = mf_basename % marker
mf = MeshFunction("uint", mesh, mf_name)
self.assertEqual(sum(mf.array()==marker), num)
os.unlink(mf_name)
# Clean up
os.unlink(dfname)
示例2: test_convert_diffpack_2d
# 需要导入模块: from dolfin import Mesh [as 别名]
# 或者: from dolfin.Mesh import domains [as 别名]
def test_convert_diffpack_2d(self):
from dolfin import Mesh, MPI, MeshFunction, mpi_comm_world
fname = os.path.join(os.path.dirname(__file__), "data", "diffpack_tri")
dfname = fname+".xml"
# Read triangle file and convert to a dolfin xml mesh file
meshconvert.diffpack2xml(fname+".grid", dfname)
# Read in dolfin mesh and check number of cells and vertices
mesh = Mesh(dfname)
self.assertEqual(mesh.num_vertices(), 41)
self.assertEqual(mesh.num_cells(), 64)
self.assertEqual(len(mesh.domains().markers(2)), 64)
mf_basename = dfname.replace(".xml", "_marker_%d.xml")
for marker, num in [(1,10), (2,5), (3,5)]:
mf_name = mf_basename % marker
mf = MeshFunction("size_t", mesh, mf_name)
self.assertEqual(sum(mf.array()==marker), num)
os.unlink(mf_name)
# Clean up
os.unlink(dfname)
示例3: write_fenics_file
# 需要导入模块: from dolfin import Mesh [as 别名]
# 或者: from dolfin.Mesh import domains [as 别名]
def write_fenics_file(dim, ofilename):
ofile = File(ofilename + '.xml')
mesh = Mesh()
editor = MeshEditor()
editor.open(mesh, dim, dim)
editor.init_vertices(nodes.shape[1])
editor.init_cells(len(cell_map))
for i in range(nodes.shape[1]):
if dim == 2:
editor.add_vertex(i, nodes[0, i], nodes[1, i])
else:
editor.add_vertex(i, nodes[0, i], nodes[1, i], nodes[2, i])
for i in range(1, len(cell_map)+1):
if dim == 2:
editor.add_cell(i-1, cell_map[i][0]-1, cell_map[i][1]-1, cell_map[i][2]-1)
else:
editor.add_cell(i-1, cell_map[i][0]-1, cell_map[i][1]-1, cell_map[i][2]-1, cell_map[i][3]-1)
mesh.order()
mvc = mesh.domains().markers(dim-1)
for zone, cells in boundary_cells.iteritems():
for cell, nds in cells.iteritems():
dolfin_cell = Cell(mesh, cell-1)
nodes_of_cell = dolfin_cell.entities(0)
#print cell
#print nodes_of_cell
nodes_of_face = nds - 1
#print nodes_of_face
for jj, ff in enumerate(facets(dolfin_cell)):
facet_nodes = ff.entities(0)
#print facet_nodes
if all(map(lambda x: x in nodes_of_face, facet_nodes)):
local_index = jj
break
mvc.set_value(cell-1, local_index, zone)
ofile << mesh
from dolfin import plot
plot(mesh, interactive=True)
print 'Finished writing FEniCS mesh\n'
示例4: test_convert_triangle
# 需要导入模块: from dolfin import Mesh [as 别名]
# 或者: from dolfin.Mesh import domains [as 别名]
def test_convert_triangle(self): # Disabled because it fails, see FIXME below
# test no. 1
from dolfin import Mesh, MPI
if MPI.num_processes() != 1:
return
fname = os.path.join("data", "triangle")
dfname = fname+".xml"
# Read triangle file and convert to a dolfin xml mesh file
meshconvert.triangle2xml(fname, dfname)
# Read in dolfin mesh and check number of cells and vertices
mesh = Mesh(dfname)
self.assertEqual(mesh.num_vertices(), 96)
self.assertEqual(mesh.num_cells(), 159)
# Clean up
os.unlink(dfname)
# test no. 2
from dolfin import MPI, Mesh, MeshFunction, \
edges, Edge, faces, Face, \
SubsetIterator, facets, CellFunction
if MPI.num_processes() != 1:
return
fname = os.path.join("data", "test_Triangle_3")
dfname = fname+".xml"
dfname0 = fname+".attr0.xml"
# Read triangle file and convert to a dolfin xml mesh file
meshconvert.triangle2xml(fname, dfname)
# Read in dolfin mesh and check number of cells and vertices
mesh = Mesh(dfname)
mesh.init()
mfun = MeshFunction('double', mesh, dfname0)
self.assertEqual(mesh.num_vertices(), 58)
self.assertEqual(mesh.num_cells(), 58)
# Create a size_t CellFunction and assign the values based on the
# converted Meshfunction
cf = CellFunction("size_t", mesh)
cf.array()[mfun.array()==10.0] = 0
cf.array()[mfun.array()==-10.0] = 1
# Meassure total area of cells with 1 and 2 marker
add = lambda x, y : x+y
area0 = reduce(add, (Face(mesh, cell.index()).area() \
for cell in SubsetIterator(cf, 0)), 0.0)
area1 = reduce(add, (Face(mesh, cell.index()).area() \
for cell in SubsetIterator(cf, 1)), 0.0)
total_area = reduce(add, (face.area() for face in faces(mesh)), 0.0)
# Check that all cells in the two domains are either above or below y=0
self.assertTrue(all(cell.midpoint().y()<0 for cell in SubsetIterator(cf, 0)))
self.assertTrue(all(cell.midpoint().y()>0 for cell in SubsetIterator(cf, 1)))
# Check that the areas add up
self.assertAlmostEqual(area0+area1, total_area)
# Measure the edge length of the two edge domains
edge_markers = mesh.domains().facet_domains()
self.assertTrue(edge_markers is not None)
length0 = reduce(add, (Edge(mesh, e.index()).length() \
for e in SubsetIterator(edge_markers, 0)), 0.0)
length1 = reduce(add, (Edge(mesh, e.index()).length() \
for e in SubsetIterator(edge_markers, 1)), 0.0)
# Total length of all edges and total length of boundary edges
total_length = reduce(add, (e.length() for e in edges(mesh)), 0.0)
boundary_length = reduce(add, (Edge(mesh, f.index()).length() \
for f in facets(mesh) if f.exterior()), 0.0)
# Check that the edges add up
self.assertAlmostEqual(length0+length1, total_length)
self.assertAlmostEqual(length1, boundary_length)
# Clean up
os.unlink(dfname)
os.unlink(dfname0)