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

Create topology Python wrapper #3406

Merged
merged 34 commits into from
Sep 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
65c9c65
Create topology Python wrapper
jorgensd Sep 15, 2024
153a0b0
Add error handling for missing connectivity
jorgensd Sep 15, 2024
0fcf462
Add docstring to exterior_facet_indices
jorgensd Sep 15, 2024
e14f671
More wrapping
jorgensd Sep 15, 2024
d231d36
Fix wrapper of cell_name
jorgensd Sep 15, 2024
5997f30
Update meshtags calling
jorgensd Sep 15, 2024
f3c2590
Formatting
jorgensd Sep 15, 2024
effa49d
Another wrapper update
jorgensd Sep 15, 2024
c982f13
Fix wrapper and remove unused dictionary/mapping
jorgensd Sep 15, 2024
bc76e5d
Fix conditional
jorgensd Sep 15, 2024
75a50fa
Fix compute integration domain
jorgensd Sep 15, 2024
97fb8d4
Update import in test
jorgensd Sep 15, 2024
4cd7227
Revert change in mixed test that uses C++ mesh directly
jorgensd Sep 15, 2024
cbae680
Update transfer facet meshtags
jorgensd Sep 15, 2024
a12ca47
Fix mixed test
jorgensd Sep 15, 2024
77ad688
Merge branch 'main' into dokken/topology-interface
jorgensd Sep 16, 2024
8d642d6
Fix typo pointed out by Remi
jorgensd Sep 16, 2024
352bc53
Apply suggestions from code review
jorgensd Sep 16, 2024
a973959
Remove cell_name binding + fix docs
jorgensd Sep 16, 2024
d128321
Apply suggestions from code review
jorgensd Sep 16, 2024
26bb2ba
Fix submesh code
jorgensd Sep 16, 2024
568ce22
Merge branch 'main' into dokken/topology-interface
jorgensd Sep 16, 2024
3d5195e
Add documentation to facet permutations
jorgensd Sep 16, 2024
d6b4a33
Merge branch 'main' into dokken/topology-interface
jorgensd Sep 16, 2024
4a9ab9b
Add helper messages + specify bits of each integer
jorgensd Sep 16, 2024
fc3f3c9
Merge branch 'main' into dokken/topology-interface
jorgensd Sep 17, 2024
f432173
Merge branch 'main' into dokken/topology-interface
jhale Sep 17, 2024
63ee875
Merge branch 'main' into dokken/topology-interface
jorgensd Sep 17, 2024
52e844f
Apply suggestions from code review
jorgensd Sep 17, 2024
ca0b8cb
Merge branch 'main' into dokken/topology-interface
jorgensd Sep 18, 2024
323d597
Ruff formatting
jorgensd Sep 18, 2024
d9e7286
Remove mixed mesh oddity comment
jorgensd Sep 18, 2024
c6f959a
Merge branch 'main' into dokken/topology-interface
jorgensd Sep 18, 2024
1c47e3e
Small doc formatting updates
garth-wells Sep 18, 2024
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
Prev Previous commit
Next Next commit
Merge branch 'main' into dokken/topology-interface
jorgensd committed Sep 18, 2024
commit ca0b8cb9cc1928b4548e429457487b237d391ced
83 changes: 83 additions & 0 deletions python/dolfinx/mesh.py
Original file line number Diff line number Diff line change
@@ -215,11 +215,63 @@ def cell_type(self) -> CellType:
return self._cpp_object.cell_type


class Geometry:
"""The geometry of a :class:`dolfinx.mesh.Mesh`"""

_cpp_object: typing.Union[_cpp.mesh.Geometry_float32, _cpp.mesh.Geometry_float64]

def __init__(
self, geometry: typing.Union[_cpp.mesh.Geometry_float32, _cpp.mesh.Geometry_float64]
):
"""Initialize a geometry from a C++ geometry.

Args:
geometry: The C++ geometry object.

Note:
Geometry objects should usually be constructed with the :func:`create_geometry`
and not using this class initializer. This class is combined with different base classes
that depend on the scalar type used in the Geometry.
"""

self._cpp_object = geometry

@property
def cmap(self) -> _CoordinateElement:
"""Element that describes the geometry map."""
return _CoordinateElement(self._cpp_object.cmap)

@property
def dim(self):
"""Dimension of the Euclidean coordinate system."""
return self._cpp_object.dim

@property
def dofmap(self) -> npt.NDArray[np.int32]:
"""Dofmap for the geometry, shape ``(num_cells, dofs_per_cell)``."""
return self._cpp_object.dofmap

def index_map(self) -> _IndexMap:
"""Index map describing the layout of the geometry points (nodes)."""
return self._cpp_object.index_map()

@property
def input_global_indices(self) -> npt.NDArray[np.int64]:
"""Global input indices of the geometry nodes."""
return self._cpp_object.input_global_indices

@property
def x(self) -> typing.Union[npt.NDArray[np.float32], npt.NDArray[np.float64]]:
"""Geometry coordinate points, ``shape=(num_points, 3)``."""
return self._cpp_object.x


class Mesh:
"""A mesh."""

_mesh: typing.Union[_cpp.mesh.Mesh_float32, _cpp.mesh.Mesh_float64]
_topology: Topology
_geometry: Geometry
_ufl_domain: typing.Optional[ufl.Mesh]

def __init__(self, mesh, domain: typing.Optional[ufl.Mesh]):
@@ -236,6 +288,7 @@ def __init__(self, mesh, domain: typing.Optional[ufl.Mesh]):
"""
self._cpp_object = mesh
self._topology = Topology(self._cpp_object.topology)
self._geometry = Geometry(self._cpp_object.geometry)
self._ufl_domain = domain
if self._ufl_domain is not None:
self._ufl_domain._ufl_cargo = self._cpp_object # type: ignore
@@ -935,3 +988,33 @@ def exterior_facet_indices(topology: Topology) -> npt.NDArray[np.int32]:
Sorted list of owned facet indices that are exterior facets of the mesh.
"""
return _cpp.mesh.exterior_facet_indices(topology._cpp_object)

def create_geometry(
index_map: _IndexMap,
dofmap: npt.NDArray[np.int32],
element: _CoordinateElement,
x: np.ndarray,
input_global_indices: npt.NDArray[np.int64],
) -> Geometry:
"""Create a Geometry object.

Args:
index_map: Index map describing the layout of the geometry points (nodes).
dofmap: The geometry (point) dofmap. For a cell, it gives the row
in the point coordinates ``x`` of each local geometry node.
``shape=(num_cells, num_dofs_per_cell)``.
element: Element that describes the cell geometry map.
x: The point coordinates. The shape is ``(num_points, geometric_dimension).``
input_global_indices: The 'global' input index of each point, commonly
from a mesh input file.
"""
if x.dtype == np.float64:
ftype = _cpp.mesh.Geometry_float64
elif x.dtype == np.float32:
ftype = _cpp.mesh.Geometry_float64
else:
raise ValueError("Unknown floating type for geometry, got: {x.dtype}")

if (dtype := np.dtype(element.dtype)) != x.dtype:
raise ValueError(f"Mismatch in x dtype ({x.dtype}) and coordinate element ({dtype})")
return Geometry(ftype(index_map, dofmap, element, x, input_global_indices))
You are viewing a condensed version of this merge commit. You can view the full changes here.