本文整理汇总了Python中dolfin.Mesh.mpi_comm方法的典型用法代码示例。如果您正苦于以下问题:Python Mesh.mpi_comm方法的具体用法?Python Mesh.mpi_comm怎么用?Python Mesh.mpi_comm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dolfin.Mesh
的用法示例。
在下文中一共展示了Mesh.mpi_comm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: readmesh
# 需要导入模块: from dolfin import Mesh [as 别名]
# 或者: from dolfin.Mesh import mpi_comm [as 别名]
def readmesh(mesh_file):
''' read HDF5 or DOLFIN XML mesh '''
# TODO: exceptions, files exist?
from dolfin import Mesh, MeshFunction, CellFunction, HDF5File, \
FacetFunction
tmp = mesh_file.split('/')[-1].split('.')
mesh_type = tmp[-1]
mesh_name = '.'.join(tmp[0:-1])
if mesh_type == 'xml':
mesh = Mesh(mesh_file)
rank = mesh.mpi_comm().Get_rank()
try:
subdomains = MeshFunction("size_t", mesh,
mesh_name+"_physical_region.xml")
except:
if rank == 0:
print('no subdomain file found (%s)' %
(mesh_name+"_physical_region.xml"))
subdomains = CellFunction("size_t", mesh)
try:
boundaries = MeshFunction("size_t", mesh,
mesh_name+"_facet_region.xml")
except:
if rank == 0:
print('no boundary file found (%s)' %
(mesh_name+"_physical_region.xml"))
boundaries = FacetFunction("size_t", mesh)
elif mesh_type == 'h5':
mesh = Mesh()
rank = mesh.mpi_comm().Get_rank()
hdf = HDF5File(mesh.mpi_comm(), mesh_file, "r")
hdf.read(mesh, "/mesh", False)
subdomains = CellFunction("size_t", mesh)
boundaries = FacetFunction("size_t", mesh)
if hdf.has_dataset('subdomains'):
hdf.read(subdomains, "/subdomains")
else:
if rank == 0:
print('no <subdomains> datasets found in file %s' % mesh_file)
if hdf.has_dataset('boundaries'):
hdf.read(boundaries, "/boundaries")
else:
if rank == 0:
print('no <boundaries> datasets found in file %s' % mesh_file)
elif mesh_type in ['xdmf', 'xmf']:
import sys
sys.exit('XDMF not supported yet. Use HDF5 instead!')
else:
import sys
sys.exit('mesh format not recognized. try XML (serial) or HDF5')
# NOTE http://fenicsproject.org/qa/5337/importing-marked-mesh-for-parallel-use
# see file xml2xdmf.py
return mesh, subdomains, boundaries
示例2: make_mesh
# 需要导入模块: from dolfin import Mesh [as 别名]
# 或者: from dolfin.Mesh import mpi_comm [as 别名]
def make_mesh(coordinates, cells, tdim, gdim, mesh=None):
'''Mesh by MeshEditor from vertices and cells'''
if mesh is None:
mesh = Mesh()
assert mesh.mpi_comm().size == 1
module.fill_mesh(coordinates.flatten(), cells.flatten(), tdim, gdim, mesh)
return mesh