Skip to content

Commit 0a06db8

Browse files
authored
Merge pull request #35 from festim-dev/meshtags
extract and create meshtags
2 parents d131553 + 6d228ee commit 0a06db8

9 files changed

Lines changed: 688 additions & 73 deletions

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ description = "Convert OpenFOAM files to dolfinx functions"
1313
readme = "README/md"
1414
requires-python = ">=3.9"
1515
license = { file = "LICENSE" }
16-
dependencies = ["fenics-dolfinx>=0.9.0", "pyvista"]
16+
dependencies = ["fenics-dolfinx>=0.9.0", "pyvista", "scipy"]
1717
classifiers = [
1818
"Natural Language :: English",
1919
"Topic :: Scientific/Engineering",

src/foam2dolfinx/helpers.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import numpy as np
2+
from scipy.spatial import cKDTree
3+
4+
5+
def tag_boundary_patch(
6+
dolfinx_mesh,
7+
patch_dataset,
8+
patch_id,
9+
tol=1e-6,
10+
*,
11+
tree: cKDTree,
12+
facet_indices: np.ndarray,
13+
facet_vertices: np.ndarray,
14+
):
15+
"""Tags the facets of a dolfinx mesh that belong to a given OpenFOAM boundary patch.
16+
17+
Args:
18+
dolfinx_mesh: the dolfinx mesh
19+
patch_dataset: the pyvista dataset for the boundary patch
20+
patch_id: integer tag to assign to matched facets
21+
tol: spatial tolerance for matching patch points to mesh vertices
22+
tree: pre-built cKDTree on mesh geometry points
23+
facet_indices: pre-computed exterior facet indices
24+
facet_vertices: pre-computed 2D array (n_facets, n_verts_per_facet)
25+
of vertex indices for each exterior facet
26+
27+
Returns:
28+
tuple of (matched_facet_indices, tags) as int32 arrays
29+
"""
30+
matched = tree.query_ball_point(patch_dataset.points, tol)
31+
matched_idx = np.unique(
32+
np.fromiter((i for sub in matched for i in sub), dtype=np.intp)
33+
)
34+
35+
vertex_matched = np.zeros(len(dolfinx_mesh.geometry.x), dtype=bool)
36+
if len(matched_idx):
37+
vertex_matched[matched_idx] = True
38+
39+
facet_mask = vertex_matched[facet_vertices].all(axis=1)
40+
matched_facets = facet_indices[facet_mask]
41+
42+
return matched_facets, np.full(len(matched_facets), patch_id, dtype=np.int32)

0 commit comments

Comments
 (0)