+
Skip to content

Simplify the constitution module #881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ All notable changes to this project will be documented in this file. The format
- Add optional keyword-arguments to `math.transpose(**kwargs)` to support optional `out` and `order`-keywords.
- Add the attribute `RegionBoundary.tangents`, which contains a list of tangent unit vectors. For `quad` cell-types the length of this list is one and for `hexahedron` cell-types it is of length two.
- Add `math.inplane(A, vectors)` to return the in-plane components of a symmetric tensor `A`, where the plane is defined by its standard unit vectors.
- Add `constitution.autodiff.jax.Hyperelastic` as a feature-equivalent alternative to `Hyperelastic` with `jax` as backend.
- Add `constitution.autodiff.jax.Material` as a feature-equivalent alternative to `MaterialAD` with `jax` as backend.
- Add the MORPH-material formulation for a JAX-based material `felupe.constitution.autodiff.jax.models.lagrange.morph()`.
- Add `constitution.jax.Hyperelastic` as a feature-equivalent alternative to `Hyperelastic` with `jax` as backend.
- Add `constitution.jax.Material` as a feature-equivalent alternative to `MaterialAD` with `jax` as backend.
- Add the MORPH-material formulation for a JAX-based material `felupe.constitution.jax.models.lagrange.morph()`.

### Changed
- Change default `np.einsum(..., order="K")` to `np.einsum(..., order="C")` in the methods of `Field`, `FieldAxisymmetric`, `FieldPlaneStrain` and `FieldContainer`.
Expand Down
18 changes: 9 additions & 9 deletions docs/felupe/constitution/jax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@ This page contains material model formulations with automatic differentiation us

.. autosummary::

constitution.autodiff.jax.Hyperelastic
constitution.autodiff.jax.Material
constitution.jax.Hyperelastic
constitution.jax.Material

**Material Models for** :class:`felupe.constitution.autodiff.jax.Material`
**Material Models for** :class:`felupe.constitution.jax.Material`

.. autosummary::

felupe.constitution.autodiff.jax.models.lagrange.morph
felupe.constitution.jax.models.lagrange.morph

**Tools**

.. autosummary::

constitution.autodiff.jax.vmap
constitution.jax.vmap

**Detailed API Reference**

.. autoclass:: felupe.constitution.autodiff.jax.Hyperelastic
.. autoclass:: felupe.constitution.jax.Hyperelastic
:members:
:undoc-members:
:inherited-members:

.. autoclass:: felupe.constitution.autodiff.jax.Material
.. autoclass:: felupe.constitution.jax.Material
:members:
:undoc-members:
:inherited-members:

.. autofunction:: felupe.constitution.autodiff.jax.models.lagrange.morph
.. autofunction:: felupe.constitution.jax.models.lagrange.morph

.. autofunction:: felupe.constitution.autodiff.jax.vmap
.. autofunction:: felupe.constitution.jax.vmap
2 changes: 1 addition & 1 deletion docs/felupe/constitution/lagrange.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This page contains Total- and Updated-Lagrange material formulations with automa
:undoc-members:
:inherited-members:

.. autoclass:: felupe.constitution.autodiff.tensortrax.Material
.. autoclass:: felupe.constitution.tensortrax.Material
:members:
:undoc-members:
:inherited-members:
Expand Down
44 changes: 22 additions & 22 deletions src/felupe/constitution/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,6 @@
from ._material import Material
from ._mixed import NearlyIncompressible, ThreeFieldVariation
from ._view import ViewMaterial, ViewMaterialIncompressible
from .autodiff.tensortrax import Hyperelastic
from .autodiff.tensortrax import Material as MaterialAD
from .autodiff.tensortrax import total_lagrange, updated_lagrange
from .autodiff.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,
neo_hooke,
ogden,
ogden_roxburgh,
saint_venant_kirchhoff,
third_order_deformation,
van_der_waals,
yeoh,
)
from .autodiff.tensortrax.models.lagrange import morph, morph_representative_directions
from .hyperelasticity import NeoHooke, NeoHookeCompressible, OgdenRoxburgh, Volumetric
from .linear_elasticity import (
LinearElastic,
Expand All @@ -42,6 +20,28 @@
linear_elastic,
linear_elastic_plastic_isotropic_hardening,
)
from .tensortrax import Hyperelastic
from .tensortrax import Material as MaterialAD
from .tensortrax import 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,
neo_hooke,
ogden,
ogden_roxburgh,
saint_venant_kirchhoff,
third_order_deformation,
van_der_waals,
yeoh,
)
from .tensortrax.models.lagrange import morph, morph_representative_directions

__all__ = [
"alexander",
Expand Down
10 changes: 0 additions & 10 deletions src/felupe/constitution/autodiff/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import numpy as np

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


Expand Down Expand Up @@ -72,7 +72,7 @@ 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 = fem.constitution.autodiff.jax.Hyperelastic(neo_hooke, mu=1)
umat = fem.constitution.jax.Hyperelastic(neo_hooke, mu=1)

and this code-block for material formulations with state variables.

Expand All @@ -83,6 +83,7 @@ def neo_hooke(C, mu):
.. code-block::

import felupe as fem
import felupe.constitution.jax as mat
import jax.numpy as np

def viscoelastic(C, Cin, mu, eta, dtime):
Expand All @@ -101,9 +102,7 @@ def viscoelastic(C, Cin, mu, eta, dtime):
# strain energy function and state variable
return mu / 2 * (I1 - 3), Ci.ravel()

umat = fem.constitution.autodiff.jax.Hyperelastic(
viscoelastic, mu=1, eta=1, dtime=1, nstatevars=9
)
umat = mat.Hyperelastic(viscoelastic, mu=1, eta=1, dtime=1, nstatevars=9)

.. note::
See the `documentation of JAX <https://jax.readthedocs.io>`_ for further
Expand All @@ -120,13 +119,14 @@ def viscoelastic(C, Cin, mu, eta, dtime):
:context:

>>> 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 = fem.constitution.autodiff.jax.Hyperelastic(neo_hooke, mu=1)
>>> umat = mat.Hyperelastic(neo_hooke, mu=1)
>>> ax = umat.plot(incompressible=True)

.. pyvista-plot::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import numpy as np

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


Expand Down Expand Up @@ -63,6 +63,7 @@ class Material(MaterialDefault):
.. code-block::

import felupe as fem
import felupe.constitution.jax as mat
import jax.numpy as jnp

def neo_hooke(F, mu):
Expand All @@ -74,13 +75,14 @@ def neo_hooke(F, mu):

return mu * F @ dev(Cu) @ jnp.linalg.inv(C)

umat = fem.constitution.autodiff.jax.Material(neo_hooke, mu=1)
umat = mat.Material(neo_hooke, mu=1)

and this code-block for material formulations with state variables:

.. code-block::

import felupe as fem
import felupe.constitution.jax as mat
import jax.numpy as jnp

def viscoelastic(F, Cin, mu, eta, dtime):
Expand All @@ -104,9 +106,7 @@ def viscoelastic(F, Cin, mu, eta, dtime):
to_triu = lambda C: C[i, j]
return F @ S, to_triu(Ci)

umat = fem.constitution.autodiff.jax.Material(
viscoelastic, mu=1, eta=1, dtime=1, nstatevars=6
)
umat = mat.Material(viscoelastic, mu=1, eta=1, dtime=1, nstatevars=6)

.. note::
See the `documentation of JAX <https://jax.readthedocs.io>`_ for further
Expand All @@ -123,6 +123,7 @@ def viscoelastic(F, Cin, mu, eta, dtime):
:context:

>>> import felupe as fem
>>> import felupe.constitution.jax as mat
>>> import jax.numpy as jnp
>>>
>>> def neo_hooke(F, mu):
Expand All @@ -134,7 +135,7 @@ def viscoelastic(F, Cin, mu, eta, dtime):
...
... return mu * F @ dev(Cu) @ jnp.linalg.inv(C)
>>>
>>> umat = fem.constitution.autodiff.jax.Material(neo_hooke, mu=1)
>>> umat = mat.Material(neo_hooke, mu=1)
>>> ax = umat.plot(incompressible=True)

.. pyvista-plot::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ def morph(F, statevars, p):
:context:

>>> import felupe as fem
>>> import felupe.constitution.jax as mat
>>>
>>> umat = fem.constitution.autodiff.jax.Material(
... fem.constitution.autodiff.jax.models.lagrange.morph,
>>> umat = mat.Material(
... mat.models.lagrange.morph,
... p=[0.039, 0.371, 0.174, 2.41, 0.0094, 6.84, 5.65, 0.244],
... nstatevars=13,
... )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import numpy as np
import tensortrax as tr

from ....math import cdya_ik, dot, transpose
from ..._material import Material
from ...math import cdya_ik, dot, transpose
from .._material import Material


class Hyperelastic(Material):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import numpy as np
import tensortrax as tr

from ..._material import Material as MaterialDefault
from .._material import Material as MaterialDefault


class Material(MaterialDefault):
Expand Down Expand Up @@ -66,6 +66,7 @@ class Material(MaterialDefault):
.. code-block::

import felupe as fem
import felupe.constitution.tensortrax as mat
import tensortrax.math as tm

def neo_hooke(F, mu):
Expand All @@ -76,13 +77,14 @@ def neo_hooke(F, mu):

return mu * F @ tm.special.dev(Cu) @ tm.linalg.inv(C)

umat = fem.MaterialAD(neo_hooke, mu=1)
umat = mat.Material(neo_hooke, mu=1)

and this code-block for material formulations with state variables:

.. code-block::

import felupe as fem
import felupe.constitution.tensortrax as mat
import tensortrax.math as tm

def viscoelastic(F, Cin, mu, eta, dtime):
Expand All @@ -102,9 +104,7 @@ def viscoelastic(F, Cin, mu, eta, dtime):
# first Piola-Kirchhoff stress tensor and state variable
return F @ S, tm.special.triu_1d(Ci)

umat = fem.MaterialAD(
viscoelastic, mu=1, eta=1, dtime=1, nstatevars=6
)
umat = mat.Material(viscoelastic, mu=1, eta=1, dtime=1, nstatevars=6)

.. note::
See the `documentation of tensortrax <https://github.com/adtzlr/tensortrax>`_
Expand All @@ -116,14 +116,15 @@ def viscoelastic(F, Cin, mu, eta, dtime):
:context:

>>> import felupe as fem
>>> import felupe.constitution.tensortrax as mat
>>> import tensortrax.math as tm
>>>
>>> def neo_hooke(F, mu):
... C = tm.dot(tm.transpose(F), F)
... S = mu * tm.special.dev(tm.linalg.det(C)**(-1/3) * C) @ tm.linalg.inv(C)
... return F @ S
>>>
>>> umat = fem.MaterialAD(neo_hooke, mu=1)
>>> umat = mat.Material(neo_hooke, mu=1)
>>> ax = umat.plot(incompressible=True)

.. pyvista-plot::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def morph_representative_directions(C, statevars, p, ε=1e-8):
:context:

>>> import felupe as fem
>>> import felupe.constitution.autodiff.tensortrax.models as models
>>> import felupe.constitution.tensortrax.models as models
>>>
>>> umat = fem.Hyperelastic(
... models.hyperelastic.morph_representative_directions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from tensortrax.math import einsum, sqrt
from tensortrax.math.linalg import det, inv

from .......quadrature import BazantOh
from ......quadrature import BazantOh


def affine_stretch(C, f, kwargs, quadrature=BazantOh(n=21)):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from tensortrax.math import einsum, sqrt
from tensortrax.math.linalg import det, inv

from .......quadrature import BazantOh
from ......quadrature import BazantOh


def nonaffine_stretch(C, p, f, kwargs, quadrature=BazantOh(n=21)):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from tensortrax.math import einsum, sqrt, trace
from tensortrax.math.linalg import det, inv

from .......quadrature import BazantOh
from ......quadrature import BazantOh
from ...._total_lagrange import total_lagrange


Expand Down
2 changes: 1 addition & 1 deletion tests/test_constitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import pytest

import felupe as fem
import felupe.constitution.autodiff.tensortrax.models as models
import felupe.constitution.tensortrax.models as models


def pre(sym, add_identity, add_random=False):
Expand Down
Loading
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载