Skip to main content

Hyperelastic Surrogates

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.2.0.tar.gz (202.1 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.2.0-py3-none-any.whl (42.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hyper_surrogate-0.2.0.tar.gz
  • Upload date:
  • Size: 202.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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.2.0.tar.gz
Algorithm Hash digest
SHA256 8c16959c2b1663f9133d14280fde042991ed455012c4b369bec0d0684f4adcd4
MD5 ec54f9b6d3da2f5e56d0bf7ca5f50258
BLAKE2b-256 b59faf8a2c411ef99976833f3f23b82d56fdab5e2a38244f65bbc9fe1e801762

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hyper_surrogate-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 42.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e3718198ce6315c0319bc9ecc254926a3e898902f55eee8619ef1219c0d7078
MD5 df49e3a2268c40a3f4968246397209c5
BLAKE2b-256 39ba6310f4320ab44fcf79c04604fcd9c60af255d7ca88cc64db8cddc97ae49e

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