From 0a059ae791a02e5c2a16670d1fb17cd2b17f44e6 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Mon, 21 Nov 2022 16:11:08 +0100 Subject: [PATCH 1/2] Template Materials: Switch from u/p to u-framework --- matadi/models/_templates.py | 28 +++++++++------------------- tests/test_template-materials.py | 19 +++++++++---------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/matadi/models/_templates.py b/matadi/models/_templates.py index 560d9c3..933b8b8 100644 --- a/matadi/models/_templates.py +++ b/matadi/models/_templates.py @@ -1,17 +1,15 @@ 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 ..math import gradient from .._templates import MaterialTensorGeneral class NeoHookeOgdenRoxburgh(MaterialTensorGeneral): - "Neo-Hooke and Ogden-Roxburgh material formulations within the u/p framework." + "Neo-Hooke and Ogden-Roxburgh material formulation." - 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): + def __init__(self, C10=0.5, r=3, m=1, beta=0): + def fun(x, C10, r, m, beta): # split `x` into the deformation gradient and the state variable F, Wmaxn = x[0], x[-1] @@ -19,22 +17,21 @@ def fun(x, C10, r, m, beta, bulk): # 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 + return eta * gradient(W, F), Wmax super().__init__( - fun=fun, statevars_shape=(1, 1), C10=C10, r=r, m=m, beta=beta, bulk=bulk + fun=fun, statevars_shape=(1, 1), C10=C10, r=r, m=m, beta=beta ) class Morph(MaterialTensorGeneral): - "MORPH consitutive material formulation within the u/p framework." + "MORPH consitutive material formulation." def __init__( self, @@ -46,18 +43,12 @@ def __init__( 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) + def fun(x, p1, p2, p3, p4, p5, p6, p7, p8): P, statevars = morph(x, p1, p2, p3, p4, p5, p6, p7, p8) - U = volumetric(J, bulk) - return P + gradient(U, F), statevars + return P, statevars super().__init__( fun=fun, @@ -70,5 +61,4 @@ def fun(x, p1, p2, p3, p4, p5, p6, p7, p8, bulk): p6=p6, p7=p7, p8=p8, - bulk=bulk, ) diff --git a/tests/test_template-materials.py b/tests/test_template-materials.py index 16ad2a1..53fbad7 100644 --- a/tests/test_template-materials.py +++ b/tests/test_template-materials.py @@ -20,7 +20,7 @@ def fun(x, C10=0.5, bulk=5000): return gradient(W, F) + gradient(U, F), statevars_new -def test_u_templates(): +def test_templates(): Custom = MaterialTensorGeneral(fun, statevars_shape=(1, 1)) @@ -41,26 +41,25 @@ def test_u_templates(): assert len(A) == 1 -def test_up_templates(): +def test_templates_models(): - # Material as a function of `F` and `p` + # Material as a function of `F` # with additional state variables `z` for M in [NeoHookeOgdenRoxburgh(), Morph()]: 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.gradient([FF, pp, zz]) # stress, constraint, statevars_new - A = M.hessian([FF, pp, zz]) + P = M.gradient([FF, zz]) # stress, constraint, statevars_new + A = M.hessian([FF, zz]) - assert len(P) == 3 - assert len(A) == 3 + assert len(P) == 2 + assert len(A) == 1 if __name__ == "__main__": - test_u_templates() - test_up_templates() + test_templates() + test_templates_models() From 09fb5f65e9a6dcf9fb95ea53082cf0c426f57b76 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Mon, 21 Nov 2022 16:11:21 +0100 Subject: [PATCH 2/2] Update test_template-materials.py --- tests/test_template-materials.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_template-materials.py b/tests/test_template-materials.py index 53fbad7..e6346ee 100644 --- a/tests/test_template-materials.py +++ b/tests/test_template-materials.py @@ -24,7 +24,7 @@ def test_templates(): Custom = MaterialTensorGeneral(fun, statevars_shape=(1, 1)) - # Material as a function of `F` and `p` + # Material as a function of `F` # with additional state variables `z` for M in [Custom]: