Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate gmsh boundary adj #7

Open
wants to merge 3 commits into
base: add-more-gmsh-reading-tests
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion meshmode/mesh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ def make_mesh(
node_vertex_consistency_tolerance: Optional[float] = None,
skip_element_orientation_test: bool = False,
force_positive_orientation: bool = False,
face_vertex_indices_to_tags=None,
) -> "Mesh":
"""Construct a new mesh from a given list of *groups*.

Expand Down Expand Up @@ -1021,6 +1022,15 @@ def make_mesh(
nodal_adjacency = (
NodalAdjacency(neighbors_starts=nb_starts, neighbors=nbs))

face_vert_ind_to_tags_local = None
if face_vertex_indices_to_tags is not None:
face_vert_ind_to_tags_local = face_vertex_indices_to_tags.copy()

if (facial_adjacency_groups is False or facial_adjacency_groups is None):
if face_vertex_indices_to_tags is not None:
facial_adjacency_groups = _compute_facial_adjacency_from_vertices(
groups, np.int32, np.int8, face_vertex_indices_to_tags)

if (
facial_adjacency_groups is not False
and facial_adjacency_groups is not None):
Expand All @@ -1047,8 +1057,13 @@ def make_mesh(
if force_positive_orientation:
if mesh.dim == mesh.ambient_dim:
import meshmode.mesh.processing as mproc
mesh_making_kwargs = {
"face_vertex_indices_to_tags": face_vert_ind_to_tags_local
}
mesh = mproc.perform_flips(
mesh, mproc.find_volume_mesh_element_orientations(mesh) < 0)
mesh=mesh,
flip_flags=mproc.find_volume_mesh_element_orientations(mesh) < 0,
skip_tests=False, mesh_making_kwargs=mesh_making_kwargs)
else:
raise ValueError("cannot enforce positive element orientation "
"on non-volume meshes")
Expand Down
2 changes: 2 additions & 0 deletions meshmode/mesh/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def get_mesh(self, return_tag_to_elements_map=False):

# compute facial adjacency for Mesh if there is tag information
facial_adjacency_groups = None
face_vert_ind_to_tags_local = face_vertex_indices_to_tags.copy()
if is_conforming and self.tags:
from meshmode.mesh import _compute_facial_adjacency_from_vertices
facial_adjacency_groups = _compute_facial_adjacency_from_vertices(
Expand All @@ -257,6 +258,7 @@ def get_mesh(self, return_tag_to_elements_map=False):
vertices, groups,
is_conforming=is_conforming,
facial_adjacency_groups=facial_adjacency_groups,
face_vertex_indices_to_tags=face_vert_ind_to_tags_local,
**self.mesh_construction_kwargs)

return (mesh, tag_to_elements) if return_tag_to_elements_map else mesh
Expand Down
10 changes: 6 additions & 4 deletions meshmode/mesh/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,8 @@ def flip_element_group(
def perform_flips(
mesh: Mesh,
flip_flags: np.ndarray,
skip_tests: bool = False) -> Mesh:
skip_tests: bool = False,
mesh_making_kwargs = None) -> Mesh:
"""
:arg flip_flags: A :class:`numpy.ndarray` with
:attr:`meshmode.mesh.Mesh.nelements` entries
Expand All @@ -808,6 +809,8 @@ def perform_flips(
"""
if mesh.vertices is None:
raise ValueError("Mesh must have vertices to perform flips")
if mesh_making_kwargs is None:
mesh_making_kwargs = {}

flip_flags = flip_flags.astype(bool)

Expand All @@ -823,9 +826,8 @@ def perform_flips(
new_groups.append(new_grp)

return make_mesh(
mesh.vertices, new_groups, skip_tests=skip_tests,
is_conforming=mesh.is_conforming,
)
mesh.vertices, groups=new_groups, skip_tests=skip_tests,
is_conforming=mesh.is_conforming, **mesh_making_kwargs)

# }}}

Expand Down
17 changes: 3 additions & 14 deletions test/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,43 +616,32 @@ def test_element_orientation_via_flipping(case):

boundary_tags = set()
for igrp in range(len(mesh.groups)):
print(f"{meshfile=} Boundaries:")
bdry_fagrps = [
fagrp for fagrp in mesh.facial_adjacency_groups[igrp]
if isinstance(fagrp, BoundaryAdjacencyGroup)]
for bdry_fagrp in bdry_fagrps:
print(f"Boundary tag: {bdry_fagrp.boundary_tag}")
boundary_tags.add(bdry_fagrp.boundary_tag)
# print(f"----{bdry_fagrp.elements=}")
# if bdry_fagrp.boundary_tag == "outer_bdy":
# num_marked_outer_bdy += len(bdry_fagrp.elements)
#if bdry_fagrp.boundary_tag == "inner_bdy":
# num_marked_inner_bdy += len(bdry_fagrp.elements)

mesh_orient = mproc.find_volume_mesh_element_orientations(mesh)
if not (mesh_orient > 0).all():
print(f"Mesh({meshfile}) is negative, trying to reorient.")
logger.info(f"Mesh({meshfile}) is negative, trying to reorient.")
mesh = mio.read_gmsh(
meshfile,
force_ambient_dim=2,
mesh_construction_kwargs={
"skip_tests": True,
"force_positive_orientation": True})

mesh_orient = mproc.find_volume_mesh_element_orientations(mesh)
boundary_tags_reoriented = set()
for igrp in range(len(mesh.groups)):
print(f"{meshfile=} Reoriented Boundaries:")
bdry_fagrps = [
fagrp for fagrp in mesh.facial_adjacency_groups[igrp]
if isinstance(fagrp, BoundaryAdjacencyGroup)]
for bdry_fagrp in bdry_fagrps:
print(f"Boundary tag: {bdry_fagrp.boundary_tag}")
boundary_tags_reoriented.add(bdry_fagrp.boundary_tag)
# print(f"----{bdry_fagrp.elements=}")
# if bdry_fagrp.boundary_tag == "outer_bdy":
# num_marked_outer_bdy += len(bdry_fagrp.elements)
#if bdry_fagrp.boundary_tag == "inner_bdy":
# num_marked_inner_bdy += len(bdry_fagrp.elements)

# Make sure rotation doesn't lose boundaries
assert boundary_tags == boundary_tags_reoriented

Expand Down
Loading