From 455a4decfc32865c2a13384f4840a5ebcc4c2f5e Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Mon, 15 Aug 2022 00:28:01 +0200 Subject: [PATCH 1/3] add u/p-template materials --- README.md | 2 +- matadi/models/__init__.py | 2 + matadi/models/_misc.py | 2 +- matadi/models/_templates.py | 83 +++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 matadi/models/_templates.py diff --git a/README.md b/README.md index 60b4746..0cedc39 100644 --- a/README.md +++ b/README.md @@ -252,7 +252,7 @@ dWdF, dWdp, statevars_new = NH.function([defgrad, pressure, statevars]) d2WdFdF, d2WdFdp, d2Wdpdp = NH.gradient([defgrad, pressure, statevars]) ``` -**Hint**: *The state variable concept is also implemented for the `Material` class.* +**Hint**: *The above Neo-Hooke as well as the MORPH material model formulation within the u/p-framework are available as template-materials in `matadi.models` as `NeoHookeOgdenRoxburgh()`and `Morph()`. The state variable concept is also implemented for the `Material` class.* Simple examples for using `matadi` with [`scikit-fem`](https://github.com/adtzlr/matadi/discussions/14#) as well as with [`felupe`](https://github.com/adtzlr/matadi/discussions/22) are shown in the Discussion section. diff --git a/matadi/models/__init__.py b/matadi/models/__init__.py index dfc7dd0..209b0bb 100644 --- a/matadi/models/__init__.py +++ b/matadi/models/__init__.py @@ -28,3 +28,5 @@ from . import microsphere from .microsphere.nonaffine import miehe_goektepe_lulei + +from ._templates import NeoHookeOgdenRoxburgh, Morph diff --git a/matadi/models/_misc.py b/matadi/models/_misc.py index 2b52f27..aaa1a48 100644 --- a/matadi/models/_misc.py +++ b/matadi/models/_misc.py @@ -17,7 +17,7 @@ def morph(x, p1, p2, p3, p4, p5, p6, p7, p8): - "MORPH consitututive material formulation." + "MORPH consitutive material formulation." # split input into the deformation gradient and the vector of state variables F, statevars = x[0], x[-1] diff --git a/matadi/models/_templates.py b/matadi/models/_templates.py new file mode 100644 index 0000000..af246a2 --- /dev/null +++ b/matadi/models/_templates.py @@ -0,0 +1,83 @@ +from ._misc import morph +from ._hyperelasticity_isotropic import neo_hooke +from ._pseudo_elasticity import ogden_roxburgh +from ._helpers import volumetric, displacement_pressure_split +from ..math import det, gradient +from .._material import MaterialTensor +from .. import Variable + + +class NeoHookeOgdenRoxburgh(MaterialTensor): + "Neo-Hooke and Ogden-Roxburgh material formulations within the u/p framework." + + def __init__(self, C10=0.5, r=3, m=1, beta=0, bulk=5000): + @displacement_pressure_split + def fun(x, C10, r, m, beta, bulk): + + # split `x` into the deformation gradient and the state variable + F, Wmaxn = x[0], x[-1] + + # isochoric and volumetric parts of the hyperelastic + # strain energy function + W = neo_hooke(F, C10) + U = volumetric(det(F), bulk) + + # pseudo-elastic softening function + eta, Wmax = ogden_roxburgh(W, Wmaxn, r, m, beta) + + # first Piola-Kirchhoff stress and updated state variable + # for a pseudo-elastic material formulation + return eta * gradient(W, F) + gradient(U, F), Wmax + + F = Variable("F", 3, 3) + p = fun.p + z = Variable("z", 1, 1) + + kwargs = {"C10": C10, "r": r, "m": m, "beta": beta, "bulk": bulk} + + super().__init__(x=[F, p, z], fun=fun, triu=True, statevars=1, kwargs=kwargs) + + +class Morph(MaterialTensor): + "MORPH consitutive material formulation within the u/p framework." + + def __init__( + self, + p1=0.035, + p2=0.37, + p3=0.17, + p4=2.4, + p5=0.01, + p6=6.4, + p7=5.5, + p8=0.24, + bulk=4050, + ): + @displacement_pressure_split + def fun(x, p1, p2, p3, p4, p5, p6, p7, p8, bulk): + + F = x[0] + J = det(F) + + P, statevars = morph(x, p1, p2, p3, p4, p5, p6, p7, p8) + U = volumetric(J, bulk) + + return P + gradient(U, F), statevars + + F = Variable("F", 3, 3) + p = fun.p + z = Variable("z", 13, 1) + + kwargs = { + "p1": p1, + "p2": p2, + "p3": p3, + "p4": p4, + "p5": p5, + "p6": p6, + "p7": p7, + "p8": p8, + "bulk": bulk, + } + + super().__init__(x=[F, p, z], fun=fun, triu=True, statevars=1, kwargs=kwargs) From 5ea997ed8d389d280c131f58aec81451bf3fafd0 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Mon, 15 Aug 2022 00:31:53 +0200 Subject: [PATCH 2/3] Create test_template-materials.py --- tests/test_template-materials.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/test_template-materials.py diff --git a/tests/test_template-materials.py b/tests/test_template-materials.py new file mode 100644 index 0000000..1b6c608 --- /dev/null +++ b/tests/test_template-materials.py @@ -0,0 +1,29 @@ +import numpy as np + +from matadi.models import NeoHookeOgdenRoxburgh, Morph + + +def test_up_templates(): + + for MaterialUP in [NeoHookeOgdenRoxburgh, Morph]: + + # Material as a function of `F` and `p` + # with additional state variables `z` + M = MaterialUP() + + FF = (np.random.rand(3, 3, 8, 100) - 0.5) / 2 + pp = np.random.rand(1, 8, 100) + zz = np.random.rand(*M.x[-1].shape, 8, 100) + + for a in range(3): + FF[a, a] += 1 + + P = M.function([FF, pp, zz]) # stress, constraint, statevars_new + A = M.gradient([FF, pp, zz]) + + assert len(P) == 3 + assert len(A) == 3 + + +if __name__ == "__main__": + test_up_templates() From a284a08348fc79c9b58e785929226ba997576537 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Mon, 15 Aug 2022 00:32:20 +0200 Subject: [PATCH 3/3] bump version --- matadi/__about__.py | 2 +- pyproject.toml | 2 +- setup.cfg | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/matadi/__about__.py b/matadi/__about__.py index 9cb17e7..c11f861 100644 --- a/matadi/__about__.py +++ b/matadi/__about__.py @@ -1 +1 @@ -__version__ = "0.1.8" +__version__ = "0.1.9" diff --git a/pyproject.toml b/pyproject.toml index 632fa21..e2b8160 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "matadi" -version = "0.1.8" +version = "0.1.9" description = "Material Definition with Automatic Differentiation" readme = "README.md" requires-python = ">=3.6" diff --git a/setup.cfg b/setup.cfg index 4cd3d8d..c3a535b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = matadi -version = 0.1.8 +version = 0.1.9 author = Andreas Dutzler author_email = a.dutzler@gmail.com description = Material Definition with Automatic Differentiation