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

Make Mesh into a dataclass #400

Merged
merged 6 commits into from
Apr 26, 2024
Merged
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
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"arraycontext": ("https://documen.tician.de/arraycontext", None),
"fenics": ("https://fenics.readthedocs.io/projects/fiat/en/latest", None),
"FInAT": ("https://finat.github.io/FInAT/", None),
"firedrake": ("https://firedrakeproject.org", None),
"firedrake": ("https://www.firedrakeproject.org", None),
"gmsh_interop": ("https://documen.tician.de/gmsh_interop", None),
"h5py": ("https://docs.h5py.org/en/stable", None),
"loopy": ("https://documen.tician.de/loopy", None),
Expand Down
4 changes: 2 additions & 2 deletions examples/tp-lagrange-stl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import meshmode.mesh.generation as mgen
from meshmode.array_context import PyOpenCLArrayContext
from meshmode.discretization import Discretization
from meshmode.mesh import BTAG_ALL, Mesh
from meshmode.mesh import BTAG_ALL, make_mesh


def main():
Expand Down Expand Up @@ -79,7 +79,7 @@ def main():
from meshmode.mesh.generation import make_group_from_vertices
mod_grp = make_group_from_vertices(vertices, grp.vertex_indices, order=grp.order)

mod_mesh = Mesh(
mod_mesh = make_mesh(
vertices=vertices, groups=[mod_grp],
is_conforming=bdry_mesh.is_conforming)

Expand Down
3 changes: 1 addition & 2 deletions meshmode/discretization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ def copy(self,
group_factory: Optional[ElementGroupFactory] = None,
real_dtype: Optional[np.dtype] = None) -> "Discretization":
"""Creates a new object of the same type with all arguments that are not
*None* replaced. The copy is not recursive (e.g. it does not call
:meth:`meshmode.mesh.Mesh.copy`).
*None* replaced. The copy is not recursive.
"""

return type(self)(
Expand Down
4 changes: 2 additions & 2 deletions meshmode/discretization/connection/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def make_face_restriction(actx, discr, group_factory, boundary_tag,

# }}}

from meshmode.mesh import Mesh, _ModepyElementGroup
from meshmode.mesh import _ModepyElementGroup, make_mesh
bdry_mesh_groups = []
connection_data = {}

Expand Down Expand Up @@ -346,7 +346,7 @@ def make_face_restriction(actx, discr, group_factory, boundary_tag,
unit_nodes=bdry_unit_nodes)
bdry_mesh_groups.append(bdry_mesh_group)

bdry_mesh = Mesh(bdry_vertices, bdry_mesh_groups)
bdry_mesh = make_mesh(bdry_vertices, bdry_mesh_groups)

bdry_discr = discr.copy(
actx=actx,
Expand Down
33 changes: 21 additions & 12 deletions meshmode/interop/firedrake/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
get_affine_reference_simplex_mapping, get_finat_element_unit_nodes)
from meshmode.mesh import (
BTAG_ALL, BTAG_INDUCED_BOUNDARY, BoundaryAdjacencyGroup, InteriorAdjacencyGroup,
Mesh, NodalAdjacency, SimplexElementGroup)
Mesh, NodalAdjacency, SimplexElementGroup, make_mesh)


__doc__ = """
Expand Down Expand Up @@ -214,7 +214,8 @@ def _get_facet_markers(dm, facets):


def _get_firedrake_facial_adjacency_groups(fdrake_mesh_topology,
cells_to_use=None):
cells_to_use=None,
face_id_dtype=None):
"""
Return facial_adjacency_groups corresponding to
the given firedrake mesh topology. Note that as we do not
Expand All @@ -236,6 +237,8 @@ def _get_firedrake_facial_adjacency_groups(fdrake_mesh_topology,
by a :mod:`meshmode` :class:`Mesh`.
"""
top = fdrake_mesh_topology.topology
if face_id_dtype is None:
face_id_dtype = np.int8

# We only need one group
# for interconnectivity and one for boundary connectivity.
Expand Down Expand Up @@ -283,10 +286,10 @@ def _get_firedrake_facial_adjacency_groups(fdrake_mesh_topology,

int_elements = int_facet_cell.flatten()
int_neighbors = np.concatenate((int_facet_cell[:, 1], int_facet_cell[:, 0]))
int_element_faces = int_fac_loc_nr.flatten().astype(Mesh.face_id_dtype)
int_element_faces = int_fac_loc_nr.flatten().astype(face_id_dtype)
int_neighbor_faces = np.concatenate((int_fac_loc_nr[:, 1],
int_fac_loc_nr[:, 0]))
int_neighbor_faces = int_neighbor_faces.astype(Mesh.face_id_dtype)
int_neighbor_faces = int_neighbor_faces.astype(face_id_dtype)
# If only using some of the cells
from pyop2.datatypes import IntType
if cells_to_use is not None:
Expand Down Expand Up @@ -344,7 +347,7 @@ def _get_firedrake_facial_adjacency_groups(fdrake_mesh_topology,

ext_element_faces = np.array([fd_loc_fac_nr_to_mm[fac_nr] for fac_nr in
top.exterior_facets.local_facet_dat.data],
dtype=Mesh.face_id_dtype)
dtype=face_id_dtype)
# If only using some of the cells, throw away unused cells and
# move to new cell index

Expand Down Expand Up @@ -707,11 +710,12 @@ def import_firedrake_mesh(fdrake_mesh, cells_to_use=None,
elif 1 not in face:
no_one_face_ndx = iface

face_id_dtype = np.int8
with ProcessLogger(logger, "Building (possibly) unflipped "
"FacialAdjacencyGroups"):
unflipped_facial_adjacency_groups = \
_get_firedrake_facial_adjacency_groups(fdrake_mesh,
cells_to_use=cells_to_use)
unflipped_facial_adjacency_groups = (
_get_firedrake_facial_adjacency_groups(
fdrake_mesh, cells_to_use=cells_to_use, face_id_dtype=face_id_dtype))

# applied below to take elements and element_faces
# (or neighbors and neighbor_faces) and flip in any faces that need to
Expand Down Expand Up @@ -757,10 +761,15 @@ def flip_local_face_indices(faces, elements):
elements=fagrp.elements,
element_faces=new_element_faces))

return (Mesh(vertices, [group],
nodal_adjacency=nodal_adjacency,
facial_adjacency_groups=facial_adjacency_groups),
orient)
mesh = make_mesh(
vertices, [group],
vertex_id_dtype=vertex_indices.dtype,
element_id_dtype=vertex_indices.dtype,
face_id_dtype=face_id_dtype,
nodal_adjacency=nodal_adjacency,
facial_adjacency_groups=facial_adjacency_groups)

return mesh, orient

# }}}

Expand Down
4 changes: 2 additions & 2 deletions meshmode/interop/nodal_dg.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ def get_discr(self, actx) -> meshmode.discretization.Discretization:
nodes = np.array([self.octave.pull(self.AXES[ax]).T for ax in range(dim)])
vertex_indices = (self.octave.pull("EToV")).astype(np.int32)-1

from meshmode.mesh import Mesh, SimplexElementGroup
from meshmode.mesh import SimplexElementGroup, make_mesh
order = int(self.octave.pull("N"))
egroup = SimplexElementGroup.make_group(
order,
vertex_indices=vertex_indices,
nodes=nodes,
unit_nodes=unit_nodes)

mesh = Mesh(vertices=vertices, groups=[egroup], is_conforming=True)
mesh = make_mesh(vertices=vertices, groups=[egroup], is_conforming=True)

from meshmode.discretization import Discretization
from meshmode.discretization.poly_element import (
Expand Down
Loading
Loading