This page contains material model formulations with automatic differentiation using
jax.
Note
JAX uses single-precision (32bit) data types by default. This requires to relax the
tolerance of newtonrhapson() to tol=1e-4. If required, JAX may be
enforced to use double-precision at startup with
jax.config.update("jax_enable_x64",True).
Note
The number of local XLA devices available must be greater or equal the number of the
parallel-mapped axis, i.e. the number of quadrature points per cell when used in
Material and
Hyperelastic along with parallel=True. To use
the multiple cores of a CPU device as multiple local XLA devices, the XLA device
count must be defined at startup.
A hyperelastic material definition with a given function for the strain energy density function per unit undeformed volume with Automatic Differentiation provided by jax.
The material model formulations are defined by the first Piola-Kirchhoff stress tensor.
Function-decorators are available to use Total-Lagrange and Updated-Lagrange material
formulations in Material.
A hyperelastic material definition with a given function for the strain energy
density function per unit undeformed volume with Automatic Differentiation provided
by jax.
Parameters:
fun (callable) – A strain energy density function in terms of the right Cauchy-Green deformation
tensor \(\boldsymbol{C}\). Function signature must be
fun=lambdaC,**kwargs:psi for functions without state variables and
fun=lambdaC,statevars,**kwargs:[psi,statevars_new] for functions
with state variables. It is important to use only differentiable math-functions
from jax.
nstatevars (int, optional) – Number of state variables (default is 0).
jit (bool, optional) – A flag to invoke just-in-time compilation (default is True).
parallel (bool, optional) – A flag to invoke parallel strain energy density function evaluations (default
is False). If True, the quadrature points are executed in parallel. The number
of devices must be greater or equal the number of quadrature points per cell.
**kwargs (dict, optional) – Optional keyword-arguments for the strain energy density function.
Notes
The strain energy density function \(\psi\) must be given in terms of the right
Cauchy-Green deformation tensor
\(\boldsymbol{C} = \boldsymbol{F}^T \boldsymbol{F}\).
Warning
It is important to use only differentiable math-functions from jax!
Take this minimal code-block as template
\[\psi = \psi(\boldsymbol{C})\]
importfelupeasfemimportfelupe.constitution.jaxasmatimportjax.numpyasjnpdefneo_hooke(C,mu):"Strain energy function of the Neo-Hookean material formulation."returnmu/2*(jnp.linalg.det(C)**(-1/3)*jnp.trace(C)-3)umat=mat.Hyperelastic(neo_hooke,mu=1)
and this code-block for material formulations with state variables.
importfelupeasfemimportfelupe.constitution.jaxasmatimportjax.numpyasjnpdefviscoelastic(C,Cin,mu,eta,dtime):"Finite strain viscoelastic material formulation."# unimodular part of the right Cauchy-Green deformation tensorCu=jnp.linalg.det(C)**(-1/3)*C# update of state variables by evolution equationCi=Cin.reshape(3,3)+mu/eta*dtime*CuCi=jnp.linalg.det(Ci)**(-1/3)*Ci# first invariant of elastic part of right Cauchy-Green deformation tensorI1=jnp.trace(Cu@jnp.linalg.inv(Ci))# strain energy function and state variablereturnmu/2*(I1-3),Ci.ravel()umat=mat.Hyperelastic(viscoelastic,mu=1,eta=1,dtime=1,nstatevars=9)
Note
See the documentation of JAX for further
details. JAX uses single-precision (32bit) data types by default. This requires
to relax the tolerance of newtonrhapson() to tol=1e-4. If
required, JAX may be enforced to use double-precision at startup with
jax.config.update("jax_enable_x64",True).
Examples
View force-stretch curves on elementary incompressible deformations.
>>> importfelupeasfem>>> importfelupe.constitution.jaxasmat>>> importjax.numpyasjnp>>>>>> defneo_hooke(C,mu):... "Strain energy function of the Neo-Hookean material formulation."... returnmu/2*(jnp.linalg.det(C)**(-1/3)*jnp.trace(C)-3)>>>>>> umat=mat.Hyperelastic(neo_hooke,mu=1)>>> ax=umat.plot(incompressible=True)
Return the evaluated gradient of the strain energy density function.
Parameters:
x (list of ndarray) – The list with input arguments. These contain the extracted fields of a
FieldContainer along with the old vector of state
variables, [*field.extract(),statevars_old].
Returns:
A list with the evaluated gradient(s) of the strain energy density function
and the updated vector of state variables.
Return the evaluated upper-triangle components of the hessian(s) of the
strain energy density function.
Parameters:
x (list of ndarray) – The list with input arguments. These contain the extracted fields of a
FieldContainer along with the old vector of state
variables, [*field.extract(),statevars_old].
Returns:
A list with the evaluated upper-triangle components of the hessian(s) of the
strain energy density function.
Optimize the material parameters by a least-squares fit on experimental
stretch-stress data.
Parameters:
ux (array of shape (2, ...) or None, optional) – Experimental uniaxial stretch and force-per-undeformed-area data (default is
None).
ps (array of shape (2, ...) or None, optional) – Experimental planar-shear stretch and force-per-undeformed-area data
(default is None).
bx (array of shape (2, ...) or None, optional) – Experimental biaxial stretch and force-per-undeformed-area data (default is
None).
incompressible (bool, optional) – A flag to enforce incompressible deformations (default is False).
relative (bool, optional) – A flag to optimize relative instead of absolute residuals, i.e.
(predicted-observed)/observed instead of predicted-observed
(default is False).
Return a plot with normal force per undeformed area vs. stretch curves for
the elementary homogeneous deformations uniaxial tension/compression, planar
shear and biaxial tension of a given isotropic material formulation.
Parameters:
incompressible (bool, optional) – A flag to enforce views on incompressible deformations (default is False).
Create views on normal force per undeformed area vs. stretch curves for the elementary homogeneous deformations uniaxial tension/compression, planar shear and biaxial tension of a given isotropic material formulation.
Create views on normal force per undeformed area vs. stretch curves for the elementary homogeneous incompressible deformations uniaxial tension/compression, planar shear and biaxial tension of a given isotropic material formulation.
Save a screenshot with normal force per undeformed area vs. stretch curves
for the elementary homogeneous deformations uniaxial tension/compression, planar
shear and biaxial tension of a given isotropic material formulation.
Parameters:
filename (str, optional) – The filename of the screenshot (default is “umat.png”).
incompressible (bool, optional) – A flag to enforce views on incompressible deformations (default is False).
Create views on normal force per undeformed area vs. stretch curves for the elementary homogeneous deformations uniaxial tension/compression, planar shear and biaxial tension of a given isotropic material formulation.
Create views on normal force per undeformed area vs. stretch curves for the elementary homogeneous incompressible deformations uniaxial tension/compression, planar shear and biaxial tension of a given isotropic material formulation.
Create views on normal force per undeformed area vs. stretch curves for the
elementary homogeneous deformations uniaxial tension/compression, planar shear
and biaxial tension of a given isotropic material formulation.
Parameters:
incompressible (bool, optional) – A flag to enforce views on incompressible deformations (default is False).
Create views on normal force per undeformed area vs. stretch curves for the elementary homogeneous deformations uniaxial tension/compression, planar shear and biaxial tension of a given isotropic material formulation.
Create views on normal force per undeformed area vs. stretch curves for the elementary homogeneous incompressible deformations uniaxial tension/compression, planar shear and biaxial tension of a given isotropic material formulation.
A material definition with a given function for the partial derivative of the
strain energy function w.r.t. the deformation gradient tensor with Automatic
Differentiation provided by jax.
Parameters:
fun (callable) – A gradient of the strain energy density function w.r.t. the deformation gradient
tensor \(\boldsymbol{F}\). Function signature must be
fun=lambdaF,**kwargs:P for functions without state variables and
fun=lambdaF,statevars,**kwargs:[P,statevars_new] for functions
with state variables. It is important to use only differentiable math-functions
from jax.
nstatevars (int, optional) – Number of state variables (default is 0).
jit (bool, optional) – A flag to invoke just-in-time compilation (default is True).
parallel (bool, optional) – A flag to invoke parallel function evaluations (default is False). If True, the
quadrature points are executed in parallel. The number of devices must be
greater or equal the number of quadrature points per cell.
jacobian (callable or None, optional) – A callable for the Jacobian. Default is None, where jax.jacobian() is
used. This may be used to switch to forward-mode differentian
jax.jacfwd().
**kwargs (dict, optional) – Optional keyword-arguments for the gradient of the strain energy density
function.
Notes
The gradient of the strain energy density function
\(\frac{\partial \psi}{\partial \boldsymbol{F}}\) must be given in terms of the
deformation gradient tensor \(\boldsymbol{F}\).
Warning
It is important to use only differentiable math-functions from jax!
Take this code-block as template
importfelupeasfemimportfelupe.constitution.jaxasmatimportjax.numpyasjnpdefneo_hooke(F,mu):"First Piola-Kirchhoff stress of the Neo-Hookean material formulation."C=F.T@FCu=jnp.linalg.det(C)**(-1/3)*Cdev=lambdaC:C-jnp.trace(C)/3*jnp.eye(3)returnmu*F@dev(Cu)@jnp.linalg.inv(C)umat=mat.Material(neo_hooke,mu=1)
and this code-block for material formulations with state variables:
importfelupeasfemimportfelupe.constitution.jaxasmatimportjax.numpyasjnpdefviscoelastic(F,Cin,mu,eta,dtime):"Finite strain viscoelastic material formulation."# unimodular part of the right Cauchy-Green deformation tensorC=F.T@FCu=jnp.linalg.det(C)**(-1/3)*C# update of state variables by evolution equationfrom_triu=lambdaC:C[jnp.array([[0,1,2],[1,3,4],[2,4,5]])]Ci=from_triu(Cin)+mu/eta*dtime*CuCi=jnp.linalg.det(Ci)**(-1/3)*Ci# second Piola-Kirchhoff stress tensordev=lambdaC:C-jnp.trace(C)/3*jnp.eye(3)S=mu*dev(Cu@jnp.linalg.inv(Ci))@jnp.linalg.inv(C)# first Piola-Kirchhoff stress tensor and state variablei,j=jnp.triu_indices(3)to_triu=lambdaC:C[i,j]returnF@S,to_triu(Ci)umat=mat.Material(viscoelastic,mu=1,eta=1,dtime=1,nstatevars=6)
Note
See the documentation of JAX for further
details. JAX uses single-precision (32bit) data types by default. This requires
to relax the tolerance of newtonrhapson() to tol=1e-4. If
required, JAX may be enforced to use double-precision at startup with
jax.config.update("jax_enable_x64",True).
Examples
View force-stretch curves on elementary incompressible deformations.
>>> importfelupeasfem>>> importfelupe.constitution.jaxasmat>>> importjax.numpyasjnp>>>>>> defneo_hooke(F,mu):... "First Piola-Kirchhoff stress of the Neo-Hookean material formulation."...... C=F.T@F... Cu=jnp.linalg.det(C)**(-1/3)*C... dev=lambdaC:C-jnp.trace(C)/3*jnp.eye(3)...... returnmu*F@dev(Cu)@jnp.linalg.inv(C)>>>>>> umat=mat.Material(neo_hooke,mu=1)>>> ax=umat.plot(incompressible=True)
Return the evaluated gradient of the strain energy density function.
Parameters:
x (list of ndarray) – The list with input arguments. These contain the extracted fields of a
FieldContainer along with the old vector of state
variables, [*field.extract(),statevars_old].
Returns:
A list with the evaluated gradient(s) of the strain energy density function
and the updated vector of state variables.
Return the evaluated upper-triangle components of the hessian(s) of the
strain energy density function.
Parameters:
x (list of ndarray) – The list with input arguments. These contain the extracted fields of a
FieldContainer along with the old vector of state
variables, [*field.extract(),statevars_old].
Returns:
A list with the evaluated upper-triangle components of the hessian(s) of the
strain energy density function.
Optimize the material parameters by a least-squares fit on experimental
stretch-stress data.
Parameters:
ux (array of shape (2, ...) or None, optional) – Experimental uniaxial stretch and force-per-undeformed-area data (default is
None).
ps (array of shape (2, ...) or None, optional) – Experimental planar-shear stretch and force-per-undeformed-area data
(default is None).
bx (array of shape (2, ...) or None, optional) – Experimental biaxial stretch and force-per-undeformed-area data (default is
None).
incompressible (bool, optional) – A flag to enforce incompressible deformations (default is False).
relative (bool, optional) – A flag to optimize relative instead of absolute residuals, i.e.
(predicted-observed)/observed instead of predicted-observed
(default is False).
Return a plot with normal force per undeformed area vs. stretch curves for
the elementary homogeneous deformations uniaxial tension/compression, planar
shear and biaxial tension of a given isotropic material formulation.
Parameters:
incompressible (bool, optional) – A flag to enforce views on incompressible deformations (default is False).
Create views on normal force per undeformed area vs. stretch curves for the elementary homogeneous deformations uniaxial tension/compression, planar shear and biaxial tension of a given isotropic material formulation.
Create views on normal force per undeformed area vs. stretch curves for the elementary homogeneous incompressible deformations uniaxial tension/compression, planar shear and biaxial tension of a given isotropic material formulation.
Save a screenshot with normal force per undeformed area vs. stretch curves
for the elementary homogeneous deformations uniaxial tension/compression, planar
shear and biaxial tension of a given isotropic material formulation.
Parameters:
filename (str, optional) – The filename of the screenshot (default is “umat.png”).
incompressible (bool, optional) – A flag to enforce views on incompressible deformations (default is False).
Create views on normal force per undeformed area vs. stretch curves for the elementary homogeneous deformations uniaxial tension/compression, planar shear and biaxial tension of a given isotropic material formulation.
Create views on normal force per undeformed area vs. stretch curves for the elementary homogeneous incompressible deformations uniaxial tension/compression, planar shear and biaxial tension of a given isotropic material formulation.
Create views on normal force per undeformed area vs. stretch curves for the
elementary homogeneous deformations uniaxial tension/compression, planar shear
and biaxial tension of a given isotropic material formulation.
Parameters:
incompressible (bool, optional) – A flag to enforce views on incompressible deformations (default is False).
Create views on normal force per undeformed area vs. stretch curves for the elementary homogeneous deformations uniaxial tension/compression, planar shear and biaxial tension of a given isotropic material formulation.
Create views on normal force per undeformed area vs. stretch curves for the elementary homogeneous incompressible deformations uniaxial tension/compression, planar shear and biaxial tension of a given isotropic material formulation.
A hyperelastic material definition with a given function for the strain energy density function per unit undeformed volume with Automatic Differentiation provided by jax.
A material definition with a given function for the partial derivative of the strain energy function w.r.t. the deformation gradient tensor with Automatic Differentiation provided by jax.
A hyperelastic material definition with a given function for the strain energy density function per unit undeformed volume with Automatic Differentiation provided by jax.
A material definition with a given function for the partial derivative of the strain energy function w.r.t. the deformation gradient tensor with Automatic Differentiation provided by jax.
The initial shear modulus results from the sum of the cross-link and the constraint
contributions to the total initial shear modulus as denoted in Eq.
(22).
statevars (array) – Vector of stacked state variables (CTS, C, SA).
p (list of float) – A list which contains the 8 material parameters.
Notes
The MORPH material model is implemented as a second Piola-Kirchhoff stress-based
formulation with automatic differentiation. The Tresca invariant of the distortional
part of the right Cauchy-Green deformation tensor is used as internal state
variable, see Eq. (48).
Warning
While the MORPH-material
formulation captures the Mullins effect and quasi-static hysteresis effects of
rubber mixtures very nicely, it has been observed to be unstable for medium- to
highly-distorted states of deformation.
The rate of deformation is described by the Lagrangian tensor and its Tresca-
invariant, see Eq. (50).
Note
It is important to evaluate the incremental right Cauchy-Green tensor by the
difference of the final and the previous state of deformation, not by its
variation with respect to the deformation gradient tensor.
The additional stresses evolve between the limiting stresses, see Eq.
(51). The additional deviatoric-enforcement terms [1]_ are neglected
in this implementation.
Only the upper-triangle entries of the symmetric stress-tensor state
variables are stored in the solid body. Hence, it is necessary to extract such
variables with tm.special.from_triu_1d() and export them as
tm.special.triu_1d().
Examples
First, choose the desired automatic differentiation backend
>>> importfelupeasfem>>>>>> # import felupe.constitution.jax as mat>>> importfelupe.constitution.tensortraxasmat
Vectorizing map. Creates a function which maps fun over argument axes. This
decorator treats all non-specified arguments and keyword-arguments as static.