Skip to content

Commit

Permalink
Move constitution.jax.isochoric_volumetric_split() (#887)
Browse files Browse the repository at this point in the history
from `constitution.jax.models.hyperelastic.isochoric_volumetric_split()`; also for tensortrax
  • Loading branch information
adtzlr authored Nov 5, 2024
1 parent 461eadc commit b213099
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 43 deletions.
3 changes: 1 addition & 2 deletions src/felupe/constitution/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
)
from .tensortrax import Hyperelastic
from .tensortrax import Material as MaterialAD
from .tensortrax import total_lagrange, updated_lagrange
from .tensortrax import isochoric_volumetric_split, total_lagrange, updated_lagrange
from .tensortrax.models.hyperelastic import (
alexander,
anssari_benam_bucchi,
arruda_boyce,
extended_tube,
finite_strain_viscoelastic,
isochoric_volumetric_split,
lopez_pamies,
miehe_goektepe_lulei,
mooney_rivlin,
Expand Down
3 changes: 2 additions & 1 deletion src/felupe/constitution/jax/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from . import models
from ._helpers import isochoric_volumetric_split, vmap
from ._hyperelastic import Hyperelastic
from ._material import Material
from ._tools import vmap
from ._total_lagrange import total_lagrange
from ._updated_lagrange import updated_lagrange

__all__ = [
"Hyperelastic",
"isochoric_volumetric_split",
"Material",
"models",
"total_lagrange",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def vmap2(fun, in_axes=0, out_axes=0, **kwargs):
)


def total_lagrange(fun):
def as_total_lagrange(fun):
import jax.numpy as jnp

@wraps(fun)
Expand All @@ -101,3 +101,15 @@ def evaluate(F, *args, **kwargs):
return fun(C, *args, **kwargs)

return evaluate


def isochoric_volumetric_split(fun):
"""Apply the material formulation only on the isochoric part of the
multiplicative split of the deformation gradient."""
from jax.numpy.linalg import det

@wraps(fun)
def apply_iso(C, *args, **kwargs):
return fun(det(C) ** (-1 / 3) * C, *args, **kwargs)

return apply_iso
4 changes: 2 additions & 2 deletions src/felupe/constitution/jax/_hyperelastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import numpy as np

from .._material import Material
from ._tools import total_lagrange, vmap2
from ._helpers import as_total_lagrange, vmap2


class Hyperelastic(Material):
Expand Down Expand Up @@ -147,7 +147,7 @@ def __init__(self, fun, nstatevars=0, jit=True, parallel=False, **kwargs):
import jax

has_aux = nstatevars > 0
self.fun = total_lagrange(fun)
self.fun = as_total_lagrange(fun)

if parallel:
warnings.warn("Parallel execution is not implemented.")
Expand Down
2 changes: 1 addition & 1 deletion src/felupe/constitution/jax/_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import numpy as np

from .._material import Material as MaterialDefault
from ._tools import vmap2
from ._helpers import vmap2


class Material(MaterialDefault):
Expand Down
2 changes: 0 additions & 2 deletions src/felupe/constitution/jax/models/hyperelastic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from ._helpers import isochoric_volumetric_split
from ._mooney_rivlin import mooney_rivlin
from ._third_order_deformation import third_order_deformation
from ._yeoh import yeoh

__all__ = [
"isochoric_volumetric_split",
"mooney_rivlin",
"third_order_deformation",
"yeoh",
Expand Down
30 changes: 0 additions & 30 deletions src/felupe/constitution/jax/models/hyperelastic/_helpers.py

This file was deleted.

2 changes: 2 additions & 0 deletions src/felupe/constitution/tensortrax/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from . import models
from ._helpers import isochoric_volumetric_split
from ._hyperelastic import Hyperelastic
from ._material import Material
from ._total_lagrange import total_lagrange
from ._updated_lagrange import updated_lagrange

__all__ = [
"Hyperelastic",
"isochoric_volumetric_split",
"models",
"total_lagrange",
"updated_lagrange",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from ._arruda_boyce import arruda_boyce
from ._extended_tube import extended_tube
from ._finite_strain_viscoelastic import finite_strain_viscoelastic
from ._helpers import isochoric_volumetric_split
from ._lopez_pamies import lopez_pamies
from ._miehe_goektepe_lulei import miehe_goektepe_lulei
from ._mooney_rivlin import mooney_rivlin
Expand All @@ -33,7 +32,6 @@
"arruda_boyce",
"extended_tube",
"finite_strain_viscoelastic",
"isochoric_volumetric_split",
"lopez_pamies",
"miehe_goektepe_lulei",
"mooney_rivlin",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_constitution_newton.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_visco_newton():
field = fem.FieldContainer([fem.FieldPlaneStrain(region, dim=2)])
boundaries, loadcase = fem.dof.uniaxial(field, clamped=True)

@mat.models.hyperelastic.isochoric_volumetric_split
@mat.isochoric_volumetric_split
def finite_strain_viscoelastic_newton(C, Cin, mu, eta, dtime):
"Finite Strain Viscoelastic material formulation."

Expand Down Expand Up @@ -94,7 +94,7 @@ def test_visco_newton_jax():
field = fem.FieldContainer([fem.FieldPlaneStrain(region, dim=2)])
boundaries, loadcase = fem.dof.uniaxial(field, clamped=True)

@mat.models.hyperelastic.isochoric_volumetric_split
@mat.isochoric_volumetric_split
def finite_strain_viscoelastic_newton(C, statevars, mu, eta, dtime):
"Finite Strain Viscoelastic material formulation."

Expand Down

0 comments on commit b213099

Please sign in to comment.