Skip to main content

TorchFEA — A PyTorch Finite-Element Analysis Framework

Developed by Zenan Song

TorchFEA is a research-oriented finite-element framework built on PyTorch. It provides a single object model for parts, assemblies, materials, loads, constraints, solvers, and results, with automatic differentiation available through the same tensor-based formulation. Models can be authored from Python, imported from Abaqus-style .inp files, or built interactively in the Gmsh/OCC-based CAE interface.

Features

  • Nonlinear three-dimensional solid mechanics with PyTorch tensors and float64 arithmetic
  • Static implicit Newton–Raphson solving with line search, PARDISO or SuperLU sparse direct solves, and conjugate gradients
  • Dynamic implicit (Newmark-β) and dynamic explicit (central-difference) solvers
  • Neo-Hookean, Mooney–Rivlin, Yeoh, Gent, Arruda–Boyce, Ogden, and Saint Venant–Kirchhoff/linear-elastic material models
  • Pressure, body force, concentrated force, moment, springs, penalty degrees of freedom, self-contact, and body-to-body contact
  • Reference points, node coupling, displacement boundaries, named node/element sets, and surface sets
  • PyTorch automatic differentiation for Jacobians, sensitivities, and optimization workflows
  • Native Gmsh OCC CAD histories with boxes, wedges, cylinders, spheres, cones, tori, STEP import, transforms, and Boolean operations
  • Abaqus-style CAE preprocessing and postprocessing UI with BREP/mesh views, selection, contour plots, deformation-gradient, stress, strain, and result export
  • Native .npz model/result serialization with model check codes for result validation
  • Complete Abaqus/Standard static job export through controller.export_inp("model.inp"); see supported mappings and limitations

Installation

TorchFEA requires Python ≥ 3.12 and uses PyTorch float64 tensors. The macOS target is Apple Silicon with the default CPU device. PyTorch's MPS backend lacks float64 tensor support. On CUDA systems, select the GPU through PyTorch's normal device settings.

Install a released package:

pip install torchfea

Install the current checkout while developing:

pip install -e .

TorchFEA installs PyPardiso automatically on x86-64 Linux and Windows. Sparse direct solves prefer PARDISO whenever its runtime is available. If it cannot load, factorize, or solve a matrix, TorchFEA uses SciPy SuperLU.

On an Apple Silicon Mac, install this checkout with native arm64 Python 3.12. To reproduce the macOS 15 test environment with uv, run these commands from the repository root. The example solves a gravity-loaded joint chain.

uv sync --locked --python 3.12
uv run python examples/joint_chain_test/joint_chain_gravity.py

The GUI entry point is installed with the package:

torchfea-ui

When running directly from the source tree, use:

python -m torchfea.ui

Quick start: INP model and static solve

The following is the same construction pattern used by the pressure examples:

from pathlib import Path

import torch
import torchfea

torch.set_default_dtype(torch.float64)

inp = torchfea.FEA_INP()
inp.read_inp(Path("examples/models/C3D4.inp"))

fe = torchfea.from_inp(inp)
fe.solver = torchfea.solver.StaticImplicitSolver(tol_error=1e-8)

fe.assembly.add_load(
    torchfea.loads.Pressure(
        instance_name="final_model",
        surface_set="surface_1_All",
        pressure=0.06,
    ),
    name="pressure-1",
)
fe.assembly.add_boundary(
    torchfea.boundarys.Boundary_Condition(
        instance_name="final_model",
        set_nodes_name="surface_0_Bottom",
        indexDoF=[0, 1, 2],
    ),
    name="fixed-bottom",
)

result = fe.solve()
print(result.converged, result.GC.shape)

fe.save_model("model.npz")
result.save("result.npz")

The same Assembly API is used for reference points, coupling constraints, springs, contact, additional instances, materials, and boundary conditions. See docs/usage.md for complete examples.

CAD construction from Python

CAD is represented as a serializable feature history owned by FEAController.cad. The history is replayable and independent of the UI:

from torchfea import FEAController
from torchfea.cad import Box, Cylinder, Cut

fe = FEAController()
history = fe.cad.add_part("Part-1")

history.add(Box("Box-1", dx=20, dy=10, dz=5))
history.add(Cylinder("Cylinder-1", x=10, y=5, radius=2, dz=5))
history.add(Cut("Cut-1", object_id="Box-1", tool_id="Cylinder-1"))

# Generate a C3D4 Part with one global mesh size.
part = fe.cad.mesh_part("Part-1", mesh_size=1.5)

Every feature is an explicit serializable class with a discoverable Python signature. The available operations are Box, Wedge, Cylinder, Sphere, Cone, Torus, StepImport, Fuse, Cut, Intersect, Fragment, Translate, Rotate, Dilate, and Mirror. CADHistory also provides typed convenience methods such as add_box, cut, and rotate. After meshing, attach the returned native Part to an Assembly, assign materials and density to its element blocks, add an Instance, and define the analysis conditions through the normal model API. The CAE UI performs these same kernel operations and saves the history through FEAController.save_model.

CAE workflow

The graphical preprocessor and postprocessor are launched with torchfea-ui. The preprocessor supports:

  1. Gmsh/OCC geometry histories and Boolean features
  2. Part materials, density, node sets, element sets, and surfaces
  3. Reference points, instances, boundaries, couplings, and loads
  4. One project-wide mesh size and FE mesh generation
  5. Part/assembly geometry and mesh views with BREP picking
  6. Native model save, INP export, and STEP import/export

The postprocessor can inspect all instances or one instance, display displacement, deformation-gradient, Green–Lagrange strain, Cauchy stress, Mises values, volume ratio, and strain energy, and export .npz or .csv results. Both CAD and mesh views provide standard camera views and section clipping.

An .npz created from an INP model is treated as a discrete-mesh model: it retains the existing nodes, elements, sets, materials, loads, and constraints without inventing a CAD history or remeshing it. A CAD-created model retains its OCC history and can be rebuilt in the UI.

See docs/cae_ui.md for the complete CAE workflow and docs/materials.md for constitutive equations and small-strain parameter matching.

Persistence and result validation

Use the controller serializer for a complete native model:

import torchfea

model = torchfea.load_model("model.npz")
result = model.solve()

FEAController.save_model stores the assembly, discrete parts, CAD histories, materials, sets, loads, constraints, boundaries, and solver settings in the native torchfea representation. StaticResult.save/load and DynamicResult.save/load store solver results separately. Model and result archives carry a compact model check code; the UI rejects a result whose code or degree-of-freedom layout does not match the loaded model.

Repository layout

src/torchfea/
├── controller.py       # model construction, solve, and serialization
├── inp.py              # typed INP model and lossless parsing/writing
├── converters/         # mappings between native and external models
├── cad/                # Gmsh OCC history and meshing
├── model/              # Assembly, Part, elements, materials, loads, BCs
├── solver/             # static and dynamic solvers/results
└── ui/                 # PySide6 + VTK CAE interface

docs/                   # usage, architecture, solver, loads, and CAE guides
examples/              # element, pressure, contact, dynamics, and sensitivity cases

Useful references:

License and scope

TorchFEA is research software. For production or safety-critical engineering use, validate the formulation, material parameters, mesh convergence, and solver settings for the target problem before relying on the results.

Metadata

Release files for torchfea 1.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torchfea 1.1.7
File Size Uploaded Provenance Actions
torchfea-1.1.7.tar.gz 219.1 kB Without provenance Details for torchfea-1.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for torchfea 1.1.7
File Interpreter ABI Platform Actions
torchfea-1.1.7-py3-none-any.whl Python 3 none any Details for torchfea-1.1.7-py3-none-any.whl

Total release size: 457.3 kB

Release files / torchfea-1.1.7.tar.gz

Download URL torchfea-1.1.7.tar.gz
Size 219.1 kB
Tags Source
SHA-256 checksum
How to use checksums
92622c12bc0dc0654f801128b798ef4030499ff2290f399e406d45fa0e712054
BLAKE2b-256 checksum
How to use checksums
a5b0f12c6e7b9d379a1f695fd7e5098756694396e70207b5fada230ca5357e9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / torchfea-1.1.7-py3-none-any.whl

Download URL torchfea-1.1.7-py3-none-any.whl
Size 238.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09ef49962a7a32b6246063e399691a639ae64ce794a82a8804f8223fa9be78c8
BLAKE2b-256 checksum
How to use checksums
ae0196002aa084da4a764e1fe267b517222b40e0817328ae0cce877fd7cf5bd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for torchfea 1.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page