本文整理汇总了Python中dolfin.Mesh.cells方法的典型用法代码示例。如果您正苦于以下问题:Python Mesh.cells方法的具体用法?Python Mesh.cells怎么用?Python Mesh.cells使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dolfin.Mesh
的用法示例。
在下文中一共展示了Mesh.cells方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vtk_ug_to_dolfin_mesh
# 需要导入模块: from dolfin import Mesh [as 别名]
# 或者: from dolfin.Mesh import cells [as 别名]
def vtk_ug_to_dolfin_mesh(ug):
"""
Create a DOLFIN Mesh from a vtkUnstructuredGrid object
"""
if not isinstance(ug, vtk.vtkUnstructuredGrid):
raise TypeError("Expected a 'vtkUnstructuredGrid'")
# Get mesh data
num_cells = int(ug.GetNumberOfCells())
num_vertices = int(ug.GetNumberOfPoints())
# Get topological and geometrical dimensions
cell = ug.GetCell(0)
gdim = int(cell.GetCellDimension())
cell_type = cell.GetCellType()
if cell_type not in [vtk.VTK_TETRA, vtk.VTK_TRIANGLE]:
raise TypeError("DOLFIN only support meshes of triangles " + \
"and tetrahedrons.")
tdim = 3 if cell_type == vtk.VTK_TETRA else 2
# Create empty DOLFIN Mesh
mesh = Mesh()
editor = MeshEditor()
editor.open(mesh, tdim, gdim)
editor.init_cells(num_cells)
editor.init_vertices(num_vertices)
editor.close()
# Assign the cell and vertex informations directly from the vtk data
cells_array = array_handler.vtk2array(ug.GetCells().GetData())
# Get the assumed fixed size of indices and create an index array
cell_size = cell.GetPointIds().GetNumberOfIds()
cellinds = np.arange(len(cells_array))
# Each cell_ids_size:th data point need to be deleted from the
# index array
ind_delete = slice(0, len(cells_array), cell_size+1)
# Check that the removed value all have the same value which should
# be the size of the data
if not np.all(cells_array[ind_delete]==cell_size):
raise ValueError("Expected all cells to be of the same size")
cellinds = np.delete(cellinds, ind_delete)
# Get cell data from mesh and make it writeable (cell data is non
# writeable by default) and update the values
mesh_cells = mesh.cells()
mesh_cells.flags.writeable = True
mesh_cells[:] = np.reshape(cells_array[cellinds], \
(num_cells , cell_size))
# Set coordinates from vtk data
vertex_array = array_handler.vtk2array(ug.GetPoints().GetData())
if vertex_array.shape[1] != gdim:
vertex_array = vertex_array[:,:gdim]
mesh.coordinates()[:] = vertex_array
return mesh
示例2: Mesh
# 需要导入模块: from dolfin import Mesh [as 别名]
# 或者: from dolfin.Mesh import cells [as 别名]
import numpy
from dolfin import Mesh
mesh = Mesh("mesh.xml.gz")
E = mesh.cells()
M = numpy.fromfile('materials.np');
I = -numpy.ones(mesh.num_vertices())
for i in range(6):
edx = numpy.nonzero((M>10*(i+1))*(M<10*(i+2)))[0]
idx = (numpy.unique(E[edx,0:3])).astype(int)
I[idx] = i*0.2
edx = numpy.nonzero(M==7)[0]
idx = (numpy.unique(E[edx,0:3])).astype(int)
I[idx] = -2;
from viper import Viper
pv = Viper(mesh, I)
pv.interactive()