Automatic Differentiation#
NumPy
Default NumPy-based backend tensortrax for automatic differentiation
(bundled with FElupe).
JAX
Use JAX as backend for automatic differentiation. Preferred option for computationally expensive material formulations.
FElupe supports multiple backends for constitutive material formulations with automatic differentiation. It is straightforward to switch between these backends.
import felupe as fem
import felupe.constitution.tensortrax as mat
import tensortrax.math as tm
def neo_hooke(C, mu):
"Strain energy function of the Neo-Hookean material formulation."
return mu / 2 * (tm.linalg.det(C) ** (-1/3) * tm.trace(C) - 3)
umat = mat.Hyperelastic(neo_hooke, mu=1.0)
import felupe as fem
import felupe.constitution.jax as mat
import jax.numpy as jnp
def neo_hooke(C, mu):
"Strain energy function of the Neo-Hookean material formulation."
return mu / 2 * (jnp.linalg.det(C) ** (-1/3) * jnp.trace(C) - 3)
umat = mat.Hyperelastic(neo_hooke, mu=1.0)
Note
The default backend is available in the top-level package namespace, this includes
all models from felupe.constitution.tensortrax.models.hyperelastic and
felupe.constitution.tensortrax.models.lagrange as well as the material
classes felupe.constitution.tensortrax.Material and
felupe.constitution.tensortrax.Hyperelastic.