Skip to content
Snippets Groups Projects

Test Meshes with Multiple Groups

Merged Alexandru Fikl requested to merge fikl2/meshmode:multiple-mesh-groups into master
Files
2
+ 34
17
@@ -37,6 +37,7 @@ __doc__ = """
@@ -37,6 +37,7 @@ __doc__ = """
.. autofunction:: perform_flips
.. autofunction:: perform_flips
.. autofunction:: find_bounding_box
.. autofunction:: find_bounding_box
.. autofunction:: merge_disjoint_meshes
.. autofunction:: merge_disjoint_meshes
 
.. autofunction:: split_mesh_groups
.. autofunction:: map_mesh
.. autofunction:: map_mesh
.. autofunction:: affine_map
.. autofunction:: affine_map
"""
"""
@@ -572,9 +573,19 @@ def merge_disjoint_meshes(meshes, skip_tests=False, single_group=False):
@@ -572,9 +573,19 @@ def merge_disjoint_meshes(meshes, skip_tests=False, single_group=False):
# {{{ split meshes
# {{{ split meshes
def split_mesh_groups(mesh, element_flags):
def split_mesh_groups(mesh, element_flags, return_subgroup_mapping=False):
"""Split all the groups in *mesh* in two according to the values of
"""Split all the groups in *mesh* in according to the values of
*element_flags*.
*element_flags*. The element flags are expected to be integers
 
defining, for each group, how the elements are to be split into
 
subgroups. For example, a single-group mesh with flags
 
 
.. code::
 
 
element_flags = [0, 0, 0, 42, 42, 42, 0, 0, 0, 41, 41, 41]
 
 
will create three subgroups. The integer flags need not be increasing
 
or contiguous and can repeat across different groups (i.e. they are
 
group-local).
:arg element_flags: a :class:`numpy.ndarray` with
:arg element_flags: a :class:`numpy.ndarray` with
:attr:`~meshmode.mesh.Mesh.nelements` entries
:attr:`~meshmode.mesh.Mesh.nelements` entries
@@ -582,35 +593,41 @@ def split_mesh_groups(mesh, element_flags):
@@ -582,35 +593,41 @@ def split_mesh_groups(mesh, element_flags):
are to be split.
are to be split.
:returns: a :class:`~meshmode.mesh.Mesh` where each group has been split
:returns: a :class:`~meshmode.mesh.Mesh` where each group has been split
according to flags in *element_flags*.
according to flags in *element_flags*. If *return_subgroup_mapping*
 
is *True*, it also returns a mapping of
 
``(group_index, subgroup) -> new_group_index``
 
"""
"""
assert element_flags.shape == (mesh.nelements,)
assert element_flags.shape == (mesh.nelements,)
new_groups = []
new_groups = []
for grp in mesh.groups:
subgroup_to_group_map = {}
mask = element_flags[
 
for igrp, grp in enumerate(mesh.groups):
 
grp_flags = element_flags[
grp.element_nr_base:grp.element_nr_base + grp.nelements]
grp.element_nr_base:grp.element_nr_base + grp.nelements]
 
unique_grp_flags = np.unique(grp_flags)
vertex_indices = grp.vertex_indices[mask, :].copy()
for iflag, flag in enumerate(unique_grp_flags):
if vertex_indices.size > 0:
subgroup_to_group_map[(igrp, flag)] = len(new_groups)
new_groups.append(grp.copy(
vertex_indices=vertex_indices,
nodes=grp.nodes[:, mask, :].copy()
))
vertex_indices = grp.vertex_indices[~mask, :].copy()
mask = grp_flags == flag
if vertex_indices.size > 0:
new_groups.append(grp.copy(
new_groups.append(grp.copy(
vertex_indices=vertex_indices,
vertex_indices=grp.vertex_indices[mask, :].copy(),
nodes=grp.nodes[:, ~mask, :].copy()
nodes=grp.nodes[:, mask, :].copy()
))
))
from meshmode.mesh import Mesh
from meshmode.mesh import Mesh
return Mesh(
mesh = Mesh(
vertices=mesh.vertices,
vertices=mesh.vertices,
groups=new_groups,
groups=new_groups,
is_conforming=mesh.is_conforming)
is_conforming=mesh.is_conforming)
 
if return_subgroup_mapping:
 
return mesh, subgroup_to_group_map
 
else:
 
return mesh
 
# }}}
# }}}
Loading