Skip to main content

Data-driven surrogates for hyperelastic constitutive models in finite element analysis

Project description

hyper-surrogate

Release Build status codecov License

Data-driven surrogates for hyperelastic constitutive models in finite element analysis.

Table of Contents

Why hyper-surrogate?

Finite element solvers need constitutive models (stress-strain relationships) to simulate materials. Writing and maintaining these models — especially user-defined material subroutines (UMATs) for Abaqus/LS-DYNA — is tedious, error-prone, and tightly coupled to the solver.

hyper-surrogate provides an end-to-end pipeline that:

  1. Generates training data from symbolic material definitions (NeoHooke, Mooney-Rivlin, etc.)
  2. Trains neural network surrogates (MLP or Input-Convex NN) that learn the strain energy function
  3. Exports to standalone Fortran 90 with baked-in weights — no Python or external dependencies at runtime

This gives you solver portability (one training, any Fortran-capable solver), thermodynamic consistency (energy-based formulation with automatic stress/tangent derivation), and speed (the exported Fortran is a pure forward pass).

Architecture

Material ─> DeformationGenerator ─> Dataset ─> MLP / ICNN ─> FortranEmitter ─> .f90
   │                                              │
   │         (symbolic SEF)                        │  (trained NN weights)
   │                                              │
   └──── UMATHandler ─────────────────────────────┘
         (analytical Fortran via SymPy CSE)     HybridUMATEmitter
                                                (NN SEF + analytical mechanics)

Features

  • Symbolic mechanics -- Automatic PK2 stress and stiffness tensor derivation via SymPy
  • ML surrogates -- MLP and Input-Convex Neural Network (ICNN) models for constitutive response approximation
  • Hybrid UMAT -- NN-based strain energy with analytical kinematics, stress push-forward, and tangent computation
  • Energy-stress loss -- Joint energy + stress gradient loss for thermodynamic consistency via autograd
  • ICNN convexity -- Input-Convex Neural Networks guarantee convexity of the predicted strain energy
  • Fortran export -- Transpile trained models to standalone Fortran 90 subroutines with baked-in weights
  • Analytical UMAT -- Generate optimized Fortran UMAT subroutines from symbolic expressions via CSE

Quick Start

MLP surrogate (stress-based)

import hyper_surrogate as hs

# Define material and generate training data
material = hs.NeoHooke({"C10": 0.5, "KBULK": 1000.0})
train_ds, val_ds, in_norm, out_norm = hs.create_datasets(
    material, n_samples=5000, input_type="invariants", target_type="pk2_voigt",
)

# Train an MLP surrogate
model = hs.MLP(input_dim=3, output_dim=6, hidden_dims=[32, 32], activation="tanh")
result = hs.Trainer(model, train_ds, val_ds, loss_fn=hs.StressLoss(), max_epochs=500).fit()

# Export to Fortran 90
exported = hs.extract_weights(result.model, in_norm, out_norm)
hs.FortranEmitter(exported).write("nn_surrogate.f90")

ICNN surrogate (energy-based)

import hyper_surrogate as hs

material = hs.NeoHooke({"C10": 0.5, "KBULK": 1000.0})
train_ds, val_ds, in_norm, out_norm = hs.create_datasets(
    material, n_samples=5000, input_type="invariants", target_type="energy",
)

# ICNN guarantees convexity of the predicted strain energy
model = hs.ICNN(input_dim=3, hidden_dims=[32, 32])
result = hs.Trainer(
    model, train_ds, val_ds,
    loss_fn=hs.EnergyStressLoss(alpha=1.0, beta=1.0),
    max_epochs=500,
).fit()

exported = hs.extract_weights(result.model, in_norm, out_norm)
exported.save("icnn_surrogate.npz")

See the examples for more usage patterns, including hybrid UMAT export and analytical Fortran generation.

Installation

pip install hyper-surrogate        # core (NumPy, SymPy)
pip install hyper-surrogate[ml]    # with PyTorch for ML surrogates

From source with uv:

git clone https://github.com/jpsferreira/hyper-surrogate.git
cd hyper-surrogate
uv sync --all-groups --extra ml

Examples

Runnable scripts are in the examples/ directory:

Script Description
train_neohooke_sef.py Train MLP on NeoHooke SEF with hybrid inference
train_neohooke_stress.py Train MLP on PK2 stress with StressLoss
train_icnn_energy.py Train ICNN with EnergyStressLoss
export_hybrid_umat.py End-to-end train + HybridUMATEmitter export
analytical_umat.py Symbolic material to Fortran via UMATHandler

Run any example with:

uv run python examples/<script>.py

Contributing

Contributions are welcome! See CONTRIBUTING.md for setup instructions and guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hyper_surrogate-0.3.0.tar.gz (259.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hyper_surrogate-0.3.0-py3-none-any.whl (57.4 kB view details)

Uploaded Python 3

File details

Details for the file hyper_surrogate-0.3.0.tar.gz.

File metadata

  • Download URL: hyper_surrogate-0.3.0.tar.gz
  • Upload date:
  • Size: 259.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hyper_surrogate-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8d32947669bfb108ea277fef5713f2ee4bb9742a33ec649672ecb687640a97f2
MD5 ef55445a27af68aad8519752615350a5
BLAKE2b-256 4c7843bdc44623ad2b00a3e19be29efc15be59250d5b36336cf5454a59198694

See more details on using hashes here.

File details

Details for the file hyper_surrogate-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: hyper_surrogate-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 57.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hyper_surrogate-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a46c45962261fdc10625444bc314cd80599b329496e465dc9ec0d2d940569a8
MD5 f23f2d0e55cc0a16c274aef0e11912f4
BLAKE2b-256 e961ab0617c2a94556ef036e1d398a52c5bf7fde9287e8faa958d04649cc18c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page