Skip to content

Commit

Permalink
Add the Van-der-Waals model for JAX
Browse files Browse the repository at this point in the history
  • Loading branch information
adtzlr committed Nov 17, 2024
1 parent c60d4cd commit dc5f4f5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/felupe/constitution/autodiff/jax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ These material model formulations are defined by a strain energy density functio
mooney_rivlin
storakers
third_order_deformation
van_der_waals
yeoh

**Material Models for** :class:`felupe.constitution.jax.Material`
Expand Down Expand Up @@ -101,6 +102,8 @@ formulations in :class:`~felupe.constitution.jax.Material`.

.. autofunction:: felupe.constitution.jax.models.hyperelastic.third_order_deformation

.. autofunction:: felupe.constitution.jax.models.hyperelastic.van_der_waals

.. autofunction:: felupe.constitution.jax.models.hyperelastic.yeoh

.. autofunction:: felupe.constitution.jax.models.lagrange.morph
Expand Down
3 changes: 3 additions & 0 deletions src/felupe/constitution/jax/models/hyperelastic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ._mooney_rivlin import mooney_rivlin
from ._storakers import storakers
from ._third_order_deformation import third_order_deformation
from ._van_der_waals import van_der_waals
from ._yeoh import yeoh

__all__ = [
Expand All @@ -11,6 +12,7 @@
"mooney_rivlin",
"storakers",
"third_order_deformation",
"van_der_waals",
"yeoh",
]

Expand All @@ -20,4 +22,5 @@
mooney_rivlin.kwargs = dict(C10=0, C01=0)
storakers.kwargs = dict(mu=[0], alpha=[2], beta=[1])
third_order_deformation.kwargs = dict(C10=0, C01=0, C11=0, C20=0, C30=0)
van_der_waals.kwargs = dict(mu=0, beta=0, a=0, limit=100)
yeoh.kwargs = dict(C10=0, C20=0, C30=0)
37 changes: 37 additions & 0 deletions src/felupe/constitution/jax/models/hyperelastic/_van_der_waals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
"""
This file is part of FElupe.
FElupe is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FElupe is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FElupe. If not, see <http://www.gnu.org/licenses/>.
"""
from functools import wraps

from jax.lax import select
from jax.numpy import isclose, log, sqrt, trace
from jax.numpy.linalg import det

from ....tensortrax.models.hyperelastic import van_der_waals as van_der_waals_docstring


@wraps(van_der_waals_docstring)
def van_der_waals(C, mu, limit, a, beta):
J3 = det(C) ** (-1 / 3)
I1 = J3 * trace(C)
I2 = (trace(C) ** 2 - J3**2 * trace(C @ C)) / 2
Im = (1 - beta) * I1 + beta * I2
Im = select(isclose(Im, 3), Im + 1e-6, Im)
eta = sqrt((Im - 3) / (limit**2 - 3))
return mu * (
-(limit**2 - 3) * (log(1 - eta) + eta) - 2 / 3 * a * ((Im - 3) / 2) ** (3 / 2)
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
def van_der_waals(C, mu, limit, a, beta):
r"""Strain energy function of the
`Van der Waals <https://doi.org/10.1016/0032-3861(81)90200-7>`_ [1]_ material
formulation.,
formulation.
Parameters
----------
C : tensortrax.Tensor
C : tensortrax.Tensor or jax.Array
Right Cauchy-Green deformation tensor.
mu : float
Initial shear modulus.
Expand All @@ -42,12 +42,22 @@ def van_der_waals(C, mu, limit, a, beta):
Examples
--------
First, choose the desired automatic differentiation backend
.. pyvista-plot::
:context:
>>> # import felupe.constitution.jax as mat
>>> import felupe.constitution.tensortrax as mat
and create the hyperelastic material.
.. pyvista-plot::
:context:
>>> import felupe as fem
>>>
>>> umat = fem.Hyperelastic(fem.van_der_waals, mu=1.0, beta=0.1, a=0.5, limit=5.0)
>>> umat = mat.Hyperelastic(fem.van_der_waals, mu=1.0, beta=0.1, a=0.5, limit=5.0)
>>> ax = umat.plot(incompressible=True)
.. pyvista-plot::
Expand Down
1 change: 1 addition & 0 deletions tests/test_constitution_jax.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def test_hyperelastic_jax():
md.third_order_deformation,
md.miehe_goektepe_lulei,
md.storakers,
md.van_der_waals,
md.blatz_ko,
]:
umat = mat.Hyperelastic(W, **W.kwargs)
Expand Down

0 comments on commit dc5f4f5

Please sign in to comment.