tpt-fem

Rust

Modular finite-element method toolkit for Rust — quadrature, elements, mesh I/O, sparse assembly, physics, eigen/continuation solvers, a native tet-mesh generator, and a CLI.

0 stars0 forks0 watchersApache License 2.0
caecomputational-mechanicseigensolverelasticityfemfinite-element-methodgmshheat-transfermesh-generationnumerical-methodsrustscientific-computingsparse-matrixstructural-analysisvtk

Languages

Rust98.5%Python1.4%Just0.1%
README

tpt-fem

A modular finite-element method (FEM) workspace for Rust, part of the tpt-solutions ecosystem. It provides a from-the-ground-up FEM core — reference elements, quadrature, mesh I/O, sparse assembly, physics (thermal, elasticity), eigen- and continuation-solvers, a native tet-mesh generator, and a CLI driver — all under a permissive MIT OR Apache-2.0 policy.

Crates.io publishing is intentionally out of scope for this repository; the crates are consumed as path dependencies within the workspace.

Crates

CratePurposeDepends on
tpt-fem-quadratureFixed-order Gauss quadrature on reference elements (line / tri / quad / tet / hex).
tpt-fem-elementReference elements, Lagrange P1 shape functions, isoparametric Jacobian map.tpt-fem-quadrature
tpt-fem-meshMesh data model, DOF numbering, Gmsh .msh v4.1 import (via mshio), region selectors.mshio
tpt-fem-sparseFEM-specific COO/CSR assembly adapter with an in-house dense LU solve (optional russell sparse-direct backend for large problems).tpt-math-linalg-dense
tpt-fem-assemblyElement-to-global scatter, Dirichlet/Neumann/Robin boundary conditions, reduced-system extraction.tpt-fem-{sparse,element,mesh}
tpt-fem-thermalHeat-conduction / Poisson elements (-∇·(k∇u) = f).tpt-fem-assembly
tpt-fem-io-vtkParaView .vtk / .vtu export (via vtkio).tpt-fem-mesh, vtkio
tpt-fem-elasticity2-D Euler–Bernoulli frames, and 2-D/3-D continuum linear elasticity.tpt-fem-assembly
tpt-fem-solveNewton–Raphson and real arc-length (Crisfield) continuation.tpt-fem-assembly
tpt-fem-eigenSparse shift-invert Lanczos/Arnoldi eigensolver, including the generalized Kx = λMx problem.tpt-fem-sparse
tpt-fem-io-abaqusAbaqus .inp reader/writer.tpt-fem-mesh
tpt-fem-io-exodusExodus II reader/writer (hand-rolled NetCDF-3 codec).tpt-fem-mesh
tpt-fem-mesh-genNative 3-D tetrahedral mesh generation (Delaunay + structured box), dependency-free.tpt-fem-mesh
tpt-fem-dofmapMulti-field DOF map: per-field dofs_per_node, block/interleaved numbering.tpt-fem-mesh
tpt-fem-dynamicTime integration: implicit Newmark-β/HHT-α and explicit central-difference over generic M/C/K.tpt-fem-{sparse,assembly}
tpt-fem-plasticityJ2 (von Mises) plasticity with isotropic/kinematic hardening (radial return).tpt-fem-{assembly,solve}
tpt-fem-hyperelasticNeo-Hookean, Mooney-Rivlin, Ogden soft-tissue models.tpt-fem-{assembly,solve}
tpt-fem-compositeClassical lamination theory and cohesive-zone delamination.tpt-fem-elasticity
tpt-fem-porousBiot consolidation and Darcy flow (steady + transient).tpt-fem-{assembly,dynamic}
tpt-fem-contactSurface-to-surface contact (penalty + augmented Lagrangian), wear.tpt-fem-{assembly,dofmap}
tpt-fem-fluidStokes and low-Re Navier-Stokes (mixed elements, transient).tpt-fem-{dofmap,dynamic,assembly,solve}
tpt-fem-couplingMultiphysics: thermal-structural, electro-thermal, fluid-structure.tpt-fem-{thermal,elasticity,fluid,dofmap,dynamic}
tpt-fem-modalModal analysis + frequency-response / modal superposition.tpt-fem-{eigen,sparse,dynamic}
tpt-fem-topoptSIMP topology optimization for 2-D linear elasticity.tpt-fem-{sparse,assembly,element,quadrature}
tpt-fem-amrAdaptive h-refinement: 1-irregular quadtree Poisson with hanging-node elimination and ZZ error estimation.tpt-fem-sparse
tpt-femUmbrella crate re-exporting all of the above behind Cargo features, plus prelude and end-to-end tests.all of the above
tpt-fem-cliCommand-line driver: solve, elasticity, modal, amr, mesh info, mesh convert.tpt-fem

Every crate is tracked as git in the sibling tpt-rust-map/registry.toml.

Umbrella feature flags

The tpt-fem umbrella re-exports each constituent behind a Cargo feature (quadrature, element, mesh, sparse, assembly, thermal, io-vtk, elasticity, solve, eigen, io-abaqus, io-exodus, mesh-gen). All are enabled by default. The advanced Phase 12+ crates (dofmap, dynamic, plasticity, hyperelastic, composite, porous, contact, fluid, coupling, modal, topopt, amr) are opt-in features, not enabled by default. use tpt_fem::prelude::*; pulls in the public API of every enabled crate.

Quick start

Add the umbrella (or individual crates) as a path dependency, then:

use tpt_fem::prelude::*;

// Build a structured 3-D tet mesh of the unit cube and solve -∇²u = 1.
let mesh = box_mesh([0.0; 3], [1.0; 3], [8, 8, 8]);
let mut bcs = Vec::new();
for axis in 0..3 {
    for &c in &[0.0, 1.0] {
        for n in mesh.nodes_on_plane(axis, c, 1e-9) {
            bcs.push((n, 0.0));
        }
    }
}
let u = solve_poisson(&mesh, 1.0, 2, |_| 1.0, &bcs, None, None).unwrap();
write_vtk_with_data(&mesh, &[PointData::new("u", u)], "out.vtk").unwrap();

A runnable version lives in crates/tpt-fem/examples/thermal_solve.rs (cargo run -p tpt-fem --example thermal_solve).

See also:

Getting started

Every adoption path begins with a clone — crates.io / PyPI publishing are out of scope for this repository, so there is nothing to cargo add. From a checkout:

# 1. Clone the workspace.
git clone https://github.com/tpt-solutions/tpt-fem.git
cd tpt-fem

# 2. Run the end-to-end Poisson example (uses only the umbrella prelude).
cargo run -p tpt-fem --example thermal_solve

Expected output (values vary slightly with mesh count):

Poisson solution on 864 tets: u in [0.000000, 0.013778]
Wrote thermal_solve.vtk

Open thermal_solve.vtk in ParaView to inspect the temperature field. From here, explore the other examples under crates/tpt-fem/examples/ (frame elasticity, modal analysis, box mesh generation, Abaqus import), or drive a problem from a TOML config with the CLI:

cargo run -p tpt-fem-cli -- solve examples/poisson.toml

Command-line driver

# Scaffold a starter problem config for the chosen problem type.
cargo run -p tpt-fem-cli -- init poisson problem.toml

# Solve a Poisson problem from a TOML config (see crates/tpt-fem-cli for schema).
cargo run -p tpt-fem-cli -- solve problem.toml

# Solve an elasticity / modal problem from a TOML config.
cargo run -p tpt-fem-cli -- elasticity problem.toml
cargo run -p tpt-fem-cli -- modal problem.toml

# Adaptive h-refinement Poisson solve on [0,1]^2 (quadtree + ZZ estimator).
cargo run -p tpt-fem-cli -- amr --max-elements 512 --output amr.vtk

# Inspect a mesh (.msh / .vtk / .inp / .ex).
cargo run -p tpt-fem-cli -- mesh info mesh.msh

# Convert a Gmsh .msh mesh to a ParaView .vtk file.
cargo run -p tpt-fem-cli -- mesh convert mesh.msh mesh.vtk

A problem.toml looks like:

[problem]
type = "poisson"            # or "elasticity" / "modal" (see crates/tpt-fem-cli/examples)

[mesh]
dim = 2                    # 2 or 3; or set `file = "mesh.msh"` to import
min = [0.0, 0.0]
max = [1.0, 1.0]
n   = [20, 20]

[material]
conductivity = 1.0

[source]
constant = 1.0             # volumetric source f(x)

[[bc]]
value = 0.0
boundary = true            # selectors: nodes / plane / box / region / boundary

[output]
vtk = "solution.vtk"

Building & testing

cargo build  --workspace --all-features
cargo test   --workspace --all-features
cargo fmt    --all --check
cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo deny   check

A Justfile wraps these (and the cargo run examples) for convenience.

Status

All phases are implemented: Phases 1–4 (core, assembly, first physics, structural/nonlinear, ecosystem-gap crates), Phase 5 error ergonomics & validation, Phase 6 physics completeness, and Phase 7–8 (CLI, MMS convergence suite, fuzz targets, Python bindings).

Examples

Run with the umbrella crate's re-exported prelude (use tpt_fem::prelude::*;):

ExampleCommandDescription
thermal_solvecargo run -p tpt-fem --example thermal_solveBox-mesh Poisson solve and ParaView .vtk export.
modal_analysiscargo run -p tpt-fem --example modal_analysisNatural-vibration modes of a clamped plate.
mesh_gen_boxcargo run -p tpt-fem --example mesh_gen_boxNative tetrahedral box-mesh generation.
elasticity_framecargo run -p tpt-fem --example elasticity_frame2-D Euler–Bernoulli frame cantilever.
abaqus_importcargo run -p tpt-fem --example abaqus_importRound-trip an Abaqus .inp mesh import.
quadrature_democargo run -p tpt-fem --example quadrature_demoQuadrature weights = area and shape-function partition of unity.
elasticity_bar_democargo run -p tpt-fem --example elasticity_bar_demoAxial-bar element stiffness via the re-exported elasticity API.

License

Licensed under either of MIT or Apache-2.0 at your option.