Mesh data structures and geometry processing in PyTorch for finite element
analysis and AI/ML. The repository is pytorch_fea_mesh; the Python package is
torch_fea_mesh.
The library provides:
- Surface, volume, and polyline mesh containers, including linear and quadratic triangle and tetrahedral elements.
- Connectivity queries, smoothing, repair, surface extraction, and isotropic triangle surface remeshing.
- Rotation, rigid, and similarity transforms, plus structured mesh generation.
- Torch serialization, INP and VTK I/O, geometry utilities, and Chamfer distance.
Python 3.10 or newer is required. Install PyTorch and a matching torch-scatter
build, then install the package from the project root:
python -m pip install .SciPy and torch-scatter are required. VTK-based features, including isotropic remeshing,
are available through the vtk extra:
python -m pip install '.[vtk]'Chamfer distance requires the chamfer extra and a matching pyg-lib build.
See installation for dependencies, optional features,
development setup, and distribution builds.
import torch
from torch_fea_mesh.mesh.triangle_mesh import TriangleMesh
mesh = TriangleMesh(
torch.tensor([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.]], dtype=torch.float64),
[[0, 1, 2]],
)
mesh.update_element_area_and_normal()
print(mesh.element_area) # one triangle with area 0.5
print(mesh.element_normal)With VTK installed, remesh the triangle surface:
from torch_fea_mesh.processing.isotropic_triangle_surface_remesher import (
isotropic_triangle_surface_remesh,
)
remeshed = isotropic_triangle_surface_remesh(
mesh,
target_edge_length=0.4,
flag_process_boundary=False,
max_iter=2,
)For template barycentric remeshing, see example/remesh_template_barycentric.py, with
boundary and interior landmark examples.
See the API overview, remeshing guide, and runnable examples.
torch_fea_mesh/
mesh/ # Mesh containers and geometry methods
processing/ # Connectivity, smoothing, repair, and remeshing
io/ # INP and VTK readers and writers
transform/ # Rotation, rigid, and similarity transforms
generation/ # Synthetic mesh generators
utility/ # Geometry utilities and Chamfer distance
test/ # Automated tests
example/ # Runnable examples with generated inputs
doc/ # Installation, API, architecture, and testing guides
data/ # Local inputs/results; only data_record.json is tracked
Install the development dependencies, then run all tests or select a subset:
python -m pip install -e '.[dev]'
python -m pytest test/ -v
python -m pytest test/test_io.py -v
python -m pytest test/remeshing/ -vOptional-feature and CUDA tests report skips when their dependencies or hardware
are unavailable. The testing guide explains test selection,
coverage, shared input files, and retained test outputs. Only the path-and-purpose
inventory data_record.json is tracked. Download the shared
test and example data from Box
and place the files at the paths listed in that record, relative to data/.
Test inputs belong in data/test/data/ and example inputs in data/example/data/.
Each test run saves files in data/test/<run-id>/output/.
See CONTRIBUTING.md for naming conventions and development practices, architecture for package responsibilities, and the changelog for version information.