Skip to content

Commit 93154e7

Browse files
committed
domain/tetgen_worker: add worker script for TetGen subprocess execution
- Read a surface mesh and config (args/kwargs), run TetGen in a separate Python process, and persist nodes/elements to .npz. - Provides a simple CLI for integration with tetrahedralize().
1 parent b5a6929 commit 93154e7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# tetgen_worker.py
2+
import sys
3+
import json
4+
import numpy as np
5+
import pyvista as pv
6+
import tetgen
7+
8+
9+
def main(surface_path: str, out_path: str, config_path: str):
10+
# Load surface mesh
11+
surface = pv.read(surface_path)
12+
13+
# Load tetrahedralize args/kwargs
14+
with open(config_path, "r") as f:
15+
cfg = json.load(f)
16+
17+
args = cfg.get("args", [])
18+
kwargs = cfg.get("kwargs", {})
19+
20+
# Run TetGen
21+
tgen = tetgen.TetGen(surface)
22+
nodes, elems = tgen.tetrahedralize(*args, **kwargs)
23+
24+
# Save result
25+
np.savez(out_path, nodes=nodes, elems=elems)
26+
27+
28+
if __name__ == "__main__":
29+
if len(sys.argv) != 4:
30+
print(
31+
"Usage: python tetgen_worker.py <surface_path> <out_path> <config_path>",
32+
file=sys.stderr,
33+
)
34+
sys.exit(1)
35+
36+
main(sys.argv[1], sys.argv[2], sys.argv[3])

0 commit comments

Comments
 (0)