From 8b5d77624184079714c3c42c6afce47f04b2cd02 Mon Sep 17 00:00:00 2001 From: Andreas D Date: Mon, 27 Sep 2021 21:33:47 +0200 Subject: [PATCH 01/14] add van der waals --- matadi/models/__init__.py | 1 + matadi/models/_hyperelasticity_isotropic.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/matadi/models/__init__.py b/matadi/models/__init__.py index 5f369de..d49a8f2 100644 --- a/matadi/models/__init__.py +++ b/matadi/models/__init__.py @@ -12,6 +12,7 @@ ogden, arruda_boyce, extended_tube, + van_der_waals, ) from ._hyperelasticity_anisotropic import ( diff --git a/matadi/models/_hyperelasticity_isotropic.py b/matadi/models/_hyperelasticity_isotropic.py index 357ae9d..f4491a5 100644 --- a/matadi/models/_hyperelasticity_isotropic.py +++ b/matadi/models/_hyperelasticity_isotropic.py @@ -84,3 +84,15 @@ def extended_tube(F, Gc, delta, Ge, beta): Wc = Gc / 2 * (g + log(1 - delta ** 2 * (D - 3))) We = 2 * Ge / beta ** 2 * sum1(wC ** (-beta / 2) - 1) return Wc + We + + +@isochoric_volumetric_split +def van_der_waals(F, mu, limit, a, beta): + C = transpose(F) @ F + I1 = trace(C) + I2 = trace(inv(C)) + I = (1 - beta) * I1 + beta * I2 + eta = sqrt((I - 3) / (limit ** 2 - 3)) + return mu * ( + -(limit ** 2 - 3) * (log(1 - eta) + eta) - 2 / 3 * a * ((I - 3) / 2) ** (3 / 2) + ) From bb80af273da83ad002dafb8564fc340dcd31c0cd Mon Sep 17 00:00:00 2001 From: Andreas D Date: Mon, 27 Sep 2021 21:33:54 +0200 Subject: [PATCH 02/14] lint black --- matadi/_lab.py | 5 ++++- matadi/models/_helpers.py | 2 +- tests/test_fiber.py | 28 ++++++++++++++++++++++++---- tests/test_lab.py | 6 +++++- tests/test_lab_stability.py | 7 ++++++- tests/test_models.py | 1 + tests/test_simple.py | 6 +++++- 7 files changed, 46 insertions(+), 9 deletions(-) diff --git a/matadi/_lab.py b/matadi/_lab.py index 5043fac..ffb6a72 100644 --- a/matadi/_lab.py +++ b/matadi/_lab.py @@ -254,7 +254,10 @@ def plot(self, data, stability=False): ax.plot(d.stretch, stress_stable, **lineargs[d.label], label=d.label) ax.plot( - d.stretch, stress_unstable, **lineargs[d.label], linestyle="--", + d.stretch, + stress_unstable, + **lineargs[d.label], + linestyle="--", ) else: diff --git a/matadi/models/_helpers.py b/matadi/models/_helpers.py index 3efea9f..e2a6530 100644 --- a/matadi/models/_helpers.py +++ b/matadi/models/_helpers.py @@ -5,7 +5,7 @@ def isochoric_volumetric_split(fun): - """Apply the material formulation only on the isochoric part of the + """Apply the material formulation only on the isochoric part of the multiplicative split of the deformation gradient. Optionally, if the bulk keyword is passed, add a volumetric term.""" diff --git a/tests/test_fiber.py b/tests/test_fiber.py index b956eb3..f6b4763 100644 --- a/tests/test_fiber.py +++ b/tests/test_fiber.py @@ -25,8 +25,18 @@ def test_fiber(): DW = M.hessian([FF]) assert W0[0].shape == (2,) - assert dW[0].shape == (3, 3, 2,) - assert DW[0].shape == (3, 3, 3, 3, 2,) + assert dW[0].shape == ( + 3, + 3, + 2, + ) + assert DW[0].shape == ( + 3, + 3, + 3, + 3, + 2, + ) def test_hgo(): @@ -60,8 +70,18 @@ def test_hgo(): DW = M.hessian([FF]) assert W0[0].shape == (2,) - assert dW[0].shape == (3, 3, 2,) - assert DW[0].shape == (3, 3, 3, 3, 2,) + assert dW[0].shape == ( + 3, + 3, + 2, + ) + assert DW[0].shape == ( + 3, + 3, + 3, + 3, + 2, + ) if __name__ == "__main__": diff --git a/tests/test_lab.py b/tests/test_lab.py index 88f3815..8a1e322 100644 --- a/tests/test_lab.py +++ b/tests/test_lab.py @@ -9,7 +9,11 @@ def test_lab(): # test material without bulk modulus mat = MaterialHyperelastic(neo_hooke, C10=0.5) - mat = MaterialHyperelastic(neo_hooke, C10=0.5, bulk=5000.0,) + mat = MaterialHyperelastic( + neo_hooke, + C10=0.5, + bulk=5000.0, + ) lab = Lab(mat) data = lab.run(ux=False, bx=False, ps=False, num=20) diff --git a/tests/test_lab_stability.py b/tests/test_lab_stability.py index 91e2ee8..908c2be 100644 --- a/tests/test_lab_stability.py +++ b/tests/test_lab_stability.py @@ -6,7 +6,12 @@ def test_lab_stab(): - mat = MaterialHyperelastic(mooney_rivlin, C10=0.0, C01=0.5, bulk=2000.0,) + mat = MaterialHyperelastic( + mooney_rivlin, + C10=0.0, + C01=0.5, + bulk=2000.0, + ) lab = Lab(mat) data = lab.run(ux=True, bx=True, ps=True, num=50, stretch_max=2.5) diff --git a/tests/test_models.py b/tests/test_models.py index 8f8f3f0..3d9e0df 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -24,6 +24,7 @@ def test_models(): matadi.models.ogden, matadi.models.arruda_boyce, matadi.models.extended_tube, + matadi.models.van_der_waals, ] parameters = [ diff --git a/tests/test_simple.py b/tests/test_simple.py index 7d55421..0467dce 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -30,7 +30,11 @@ def test_simple(): FF[a, a] += 1 # init Material - W = Material(x=[F], fun=neohooke, kwargs={"mu": 1.0, "bulk": 10.0},) + W = Material( + x=[F], + fun=neohooke, + kwargs={"mu": 1.0, "bulk": 10.0}, + ) W0 = W.function([FF]) dW = W.gradient([FF]) From 1e0f4474d771cde55ff1d0c7e4d88c45f46afa92 Mon Sep 17 00:00:00 2001 From: Andreas D Date: Mon, 27 Sep 2021 21:39:12 +0200 Subject: [PATCH 03/14] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d27a0b2..9c122b4 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ Available [isotropic hyperelastic material models](https://github.com/adtzlr/mat - [Ogden](https://en.wikipedia.org/wiki/Ogden_(hyperelastic_model)) ([code](https://github.com/adtzlr/matadi/blob/main/matadi/models/_hyperelasticity_isotropic.py#L49-L59)) - [Arruda-Boyce](https://en.wikipedia.org/wiki/Arruda%E2%80%93Boyce_model) ([code](https://github.com/adtzlr/matadi/blob/main/matadi/models/_hyperelasticity_isotropic.py#L62-L75)) - [Extended-Tube](https://meridian.allenpress.com/rct/article-abstract/72/4/602/92819/An-Extended-Tube-Model-for-Rubber-Elasticity?redirectedFrom=fulltext) ([code](https://github.com/adtzlr/matadi/blob/main/matadi/models/_hyperelasticity_isotropic.py#L78-L86)) +- [Van-der-Waals (Kilian)](https://doi.org/10.1016/0032-3861(81)90200-7) ([code](https://github.com/adtzlr/matadi/blob/main/matadi/models/_hyperelasticity_isotropic.py#L89-L98)) Available [anisotropic hyperelastic material models](https://github.com/adtzlr/matadi/blob/main/matadi/models/_hyperelasticity_anisotropic.py): - Fiber ([code](https://github.com/adtzlr/matadi/blob/main/matadi/models/_hyperelasticity_anisotropic.py#L17-L35)) From 930077fdb2106f6225693129e3bfd56e2d66c13b Mon Sep 17 00:00:00 2001 From: Andreas D Date: Mon, 27 Sep 2021 21:39:15 +0200 Subject: [PATCH 04/14] Update test_models.py --- tests/test_models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_models.py b/tests/test_models.py index 3d9e0df..f668a53 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -37,6 +37,7 @@ def test_models(): {"mu": (1.0, 0.2), "alpha": (2.0, -1.5), "bulk": 5000.0}, {"C1": 1.0, "limit": 3.2, "bulk": 5000.0}, {"Gc": 0.1867, "Ge": 0.2169, "beta": 0.2, "delta": 0.09693, "bulk": 5000.0}, + {"mu": 1.0, "beta": 0.1, "a": 20, "limit": 5.0, "bulk": 5000.0}, ] for model, kwargs in zip(models, parameters): From 42478cebd870d83dc38bd5b9961059814026e602 Mon Sep 17 00:00:00 2001 From: Andreas D Date: Mon, 27 Sep 2021 21:41:34 +0200 Subject: [PATCH 05/14] Update _hyperelasticity_isotropic.py fix imports --- matadi/models/_hyperelasticity_isotropic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matadi/models/_hyperelasticity_isotropic.py b/matadi/models/_hyperelasticity_isotropic.py index f4491a5..f4a51c1 100644 --- a/matadi/models/_hyperelasticity_isotropic.py +++ b/matadi/models/_hyperelasticity_isotropic.py @@ -1,5 +1,5 @@ from ._helpers import isochoric_volumetric_split -from ..math import det, transpose, trace, eigvals, sum1, log +from ..math import det, transpose, trace, eigvals, sum1, log, inv, sqrt def saint_venant_kirchhoff(F, mu, lmbda): From ae217ef82d927200996ac2c031b0e068acf32dce Mon Sep 17 00:00:00 2001 From: Andreas D Date: Tue, 28 Sep 2021 08:53:32 +0200 Subject: [PATCH 06/14] replace second invariant formulation --- matadi/models/_hyperelasticity_isotropic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matadi/models/_hyperelasticity_isotropic.py b/matadi/models/_hyperelasticity_isotropic.py index f4a51c1..3442001 100644 --- a/matadi/models/_hyperelasticity_isotropic.py +++ b/matadi/models/_hyperelasticity_isotropic.py @@ -90,7 +90,7 @@ def extended_tube(F, Gc, delta, Ge, beta): def van_der_waals(F, mu, limit, a, beta): C = transpose(F) @ F I1 = trace(C) - I2 = trace(inv(C)) + I2 = (trace(C) ** 2 - trace(C @ C)) / 2 I = (1 - beta) * I1 + beta * I2 eta = sqrt((I - 3) / (limit ** 2 - 3)) return mu * ( From c3a9262f12e2a8de58db0bde9b98b8f59b809781 Mon Sep 17 00:00:00 2001 From: Andreas D Date: Tue, 28 Sep 2021 08:53:48 +0200 Subject: [PATCH 07/14] bump version to 0.0.12 --- 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 b2f0155..6e2648a 100644 --- a/matadi/__about__.py +++ b/matadi/__about__.py @@ -1 +1 @@ -__version__ = "0.0.11" +__version__ = "0.0.12" diff --git a/pyproject.toml b/pyproject.toml index b734726..dc0dbe7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "matadi" -version = "0.0.11" +version = "0.0.12" description = "Material Definition with Automatic Differentiation" readme = "README.md" requires-python = ">=3.6" diff --git a/setup.cfg b/setup.cfg index 8ecb39d..4fb819c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = matadi -version = 0.0.11 +version = 0.0.12 author = Andreas Dutzler author_email = a.dutzler@gmail.com description = Material Definition with Automatic Differentiation From 80d1fb98c2d95421a7615677946b252a0b0bbfde Mon Sep 17 00:00:00 2001 From: Andreas D Date: Tue, 28 Sep 2021 08:54:08 +0200 Subject: [PATCH 08/14] explain upJ-hessian output --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9c122b4..514c978 100644 --- a/README.md +++ b/README.md @@ -84,11 +84,15 @@ W = NH.function([defgrad])[0] P = NH.gradient([defgrad])[0] A = NH.hessian([defgrad])[0] -W_upJ = ThreeFieldVariation(NH).function([defgrad, pressure, volratio]) -P_upJ = ThreeFieldVariation(NH).gradient([defgrad, pressure, volratio]) -A_upJ = ThreeFieldVariation(NH).hessian([defgrad, pressure, volratio]) +NH_upJ = ThreeFieldVariation(NH) + +W_upJ = NH_upJ.function([defgrad, pressure, volratio]) +P_upJ = NH_upJ.gradient([defgrad, pressure, volratio]) +A_upJ = NH_upJ.hessian([defgrad, pressure, volratio]) ``` +The output of `NH_upJ.gradient([defgrad, pressure, volratio])` is a list with gradients of the functional as `[dWdF, dWdp, dWdJ]`. Hessian entries are provided as list of the upper triangle entries, e.g. `NH_upJ.hessian([defgrad, pressure, volratio])` returns `[d2WdFdF, d2WdFdp, d2WdFdJ, d2Wdpdp, d2WdpdJ, d2WdJdJ]`. + Available [isotropic hyperelastic material models](https://github.com/adtzlr/matadi/blob/main/matadi/models/_hyperelasticity_isotropic.py): - [Saint Venant Kirchhoff](https://en.wikipedia.org/wiki/Hyperelastic_material#Saint_Venant%E2%80%93Kirchhoff_model) ([code](https://github.com/adtzlr/matadi/blob/main/matadi/models/_hyperelasticity_isotropic.py#L5-L9)) - [Neo-Hooke](https://en.wikipedia.org/wiki/Neo-Hookean_solid) ([code](https://github.com/adtzlr/matadi/blob/main/matadi/models/_hyperelasticity_isotropic.py#L12-L16)) From 3779fdb6051768b898b3a8dc038c8a453243cbda Mon Sep 17 00:00:00 2001 From: Andreas D Date: Tue, 28 Sep 2021 08:54:26 +0200 Subject: [PATCH 09/14] lint black --- matadi/_lab.py | 5 +---- tests/test_fiber.py | 28 ++++------------------------ tests/test_simple.py | 6 +----- 3 files changed, 6 insertions(+), 33 deletions(-) diff --git a/matadi/_lab.py b/matadi/_lab.py index ffb6a72..5043fac 100644 --- a/matadi/_lab.py +++ b/matadi/_lab.py @@ -254,10 +254,7 @@ def plot(self, data, stability=False): ax.plot(d.stretch, stress_stable, **lineargs[d.label], label=d.label) ax.plot( - d.stretch, - stress_unstable, - **lineargs[d.label], - linestyle="--", + d.stretch, stress_unstable, **lineargs[d.label], linestyle="--", ) else: diff --git a/tests/test_fiber.py b/tests/test_fiber.py index f6b4763..b956eb3 100644 --- a/tests/test_fiber.py +++ b/tests/test_fiber.py @@ -25,18 +25,8 @@ def test_fiber(): DW = M.hessian([FF]) assert W0[0].shape == (2,) - assert dW[0].shape == ( - 3, - 3, - 2, - ) - assert DW[0].shape == ( - 3, - 3, - 3, - 3, - 2, - ) + assert dW[0].shape == (3, 3, 2,) + assert DW[0].shape == (3, 3, 3, 3, 2,) def test_hgo(): @@ -70,18 +60,8 @@ def test_hgo(): DW = M.hessian([FF]) assert W0[0].shape == (2,) - assert dW[0].shape == ( - 3, - 3, - 2, - ) - assert DW[0].shape == ( - 3, - 3, - 3, - 3, - 2, - ) + assert dW[0].shape == (3, 3, 2,) + assert DW[0].shape == (3, 3, 3, 3, 2,) if __name__ == "__main__": diff --git a/tests/test_simple.py b/tests/test_simple.py index 0467dce..7d55421 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -30,11 +30,7 @@ def test_simple(): FF[a, a] += 1 # init Material - W = Material( - x=[F], - fun=neohooke, - kwargs={"mu": 1.0, "bulk": 10.0}, - ) + W = Material(x=[F], fun=neohooke, kwargs={"mu": 1.0, "bulk": 10.0},) W0 = W.function([FF]) dW = W.gradient([FF]) From 68da2af38bc3f125c8056e5bf81334ff58e36bc1 Mon Sep 17 00:00:00 2001 From: Andreas D Date: Tue, 28 Sep 2021 08:54:38 +0200 Subject: [PATCH 10/14] Delete test_lab_stability.py --- tests/test_lab_stability.py | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 tests/test_lab_stability.py diff --git a/tests/test_lab_stability.py b/tests/test_lab_stability.py deleted file mode 100644 index 908c2be..0000000 --- a/tests/test_lab_stability.py +++ /dev/null @@ -1,37 +0,0 @@ -from matadi import MaterialHyperelastic, Lab -from matadi.models import mooney_rivlin - -import matplotlib.pyplot as plt - - -def test_lab_stab(): - - mat = MaterialHyperelastic( - mooney_rivlin, - C10=0.0, - C01=0.5, - bulk=2000.0, - ) - - lab = Lab(mat) - data = lab.run(ux=True, bx=True, ps=True, num=50, stretch_max=2.5) - - fig, ax = lab.plot(data, stability=True) - plt.close(fig) - - # dW and DW are always lists... - assert len(data[0].stress) == 50 - assert len(data[0].stretch) == 50 - - data = lab.run(ux=True, bx=True, ps=True, num=50, stretch_min=0.1, stretch_max=1.0) - - fig, ax = lab.plot(data, stability=True) - # plt.close(fig) - - # dW and DW are always lists... - assert len(data[0].stress) == 50 - assert len(data[0].stretch) == 50 - - -if __name__ == "__main__": - test_lab_stab() From 387e7dfd515f7ca6293366505327de4235b132c6 Mon Sep 17 00:00:00 2001 From: Andreas D Date: Tue, 28 Sep 2021 08:55:06 +0200 Subject: [PATCH 11/14] simplify tests add material library with parameters --- tests/test_models.py | 62 +++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index f668a53..7679909 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,6 +1,35 @@ import numpy as np import matadi +import matadi.models as md + + +def get_title(model): + return "-".join([m.title() for m in model.__name__.split("_")]) + + +def library(): + "Library with models and parameters." + + database = { + md.saint_venant_kirchhoff: {"mu": 1.0, "lmbda": 20.0}, + md.neo_hooke: {"C10": 0.5}, + md.mooney_rivlin: {"C10": 0.3, "C01": 0.8}, + md.yeoh: {"C10": 0.5, "C20": 0.1, "C30": 0.01}, + md.third_order_deformation: { + "C10": 0.3, + "C01": 0.2, + "C11": 0.02, + "C20": -0.1, + "C30": 0.02, + }, + md.ogden: {"mu": (1.0, 0.2), "alpha": (2.0, -1.5)}, + md.arruda_boyce: {"C1": 1.0, "limit": 3.2}, + md.extended_tube: {"Gc": 0.1867, "Ge": 0.2169, "beta": 0.2, "delta": 0.09693}, + md.van_der_waals: {"mu": 1.0, "beta": 0.1, "a": 0.5, "limit": 5.0}, + } + + return database def test_models(): @@ -14,33 +43,12 @@ def test_models(): pp = np.random.rand(5, 100) JJ = 1 + np.random.rand(5, 100) / 10 - models = [ - matadi.models.saint_venant_kirchhoff, - matadi.models.neo_hooke, - matadi.models.neo_hooke, - matadi.models.mooney_rivlin, - matadi.models.yeoh, - matadi.models.third_order_deformation, - matadi.models.ogden, - matadi.models.arruda_boyce, - matadi.models.extended_tube, - matadi.models.van_der_waals, - ] - - parameters = [ - {"mu": 1.0, "lmbda": 20.0}, - {"C10": 1.0}, - {"C10": 1.0, "bulk": 5000.0}, - {"C10": 1.0, "C01": 0.1, "bulk": 5000.0}, - {"C10": 1.0, "C20": 0.1, "C30": 0.01, "bulk": 5000.0}, - {"C10": 1.0, "C01": 0.1, "C11": 0.02, "C20": 0.1, "C30": 0.01, "bulk": 5000.0}, - {"mu": (1.0, 0.2), "alpha": (2.0, -1.5), "bulk": 5000.0}, - {"C1": 1.0, "limit": 3.2, "bulk": 5000.0}, - {"Gc": 0.1867, "Ge": 0.2169, "beta": 0.2, "delta": 0.09693, "bulk": 5000.0}, - {"mu": 1.0, "beta": 0.1, "a": 20, "limit": 5.0, "bulk": 5000.0}, - ] - - for model, kwargs in zip(models, parameters): + lib = library() + + for model, kwargs in lib.items(): + + if model is not md.saint_venant_kirchhoff: + kwargs["bulk"] = 5000.0 HM = matadi.MaterialHyperelastic(model, **kwargs) HM_mixed = matadi.ThreeFieldVariation(HM) From 7c342d5757bb08ef99d26fdcbf3923e989e65ea1 Mon Sep 17 00:00:00 2001 From: Andreas D Date: Tue, 28 Sep 2021 08:55:10 +0200 Subject: [PATCH 12/14] Update test_lab.py --- tests/test_lab.py | 74 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 18 deletions(-) diff --git a/tests/test_lab.py b/tests/test_lab.py index 8a1e322..89718db 100644 --- a/tests/test_lab.py +++ b/tests/test_lab.py @@ -1,32 +1,70 @@ from matadi import MaterialHyperelastic, Lab -from matadi.models import neo_hooke +from matadi.models import neo_hooke, extended_tube, van_der_waals, mooney_rivlin import matplotlib.pyplot as plt +from test_models import library -def test_lab(): - # test material without bulk modulus - mat = MaterialHyperelastic(neo_hooke, C10=0.5) +def pre( + model, + num=20, + test_without_bulk=False, + stability=False, + plot=False, + close=True, + run_all=False, + run_kwargs={}, +): + + lib = library() + kwargs = lib[model] - mat = MaterialHyperelastic( - neo_hooke, - C10=0.5, - bulk=5000.0, - ) + if test_without_bulk: + # init material without bulk modulus + mat = MaterialHyperelastic(model, **kwargs) + # init material with bulk modulus + mat = MaterialHyperelastic(model, **kwargs, bulk=5000.0) + + # init lab lab = Lab(mat) - data = lab.run(ux=False, bx=False, ps=False, num=20) - data = lab.run(ux=True, bx=False, ps=False, num=20) - data = lab.run(ux=True, bx=True, ps=False, num=20) - data = lab.run(ux=True, bx=True, ps=True, num=20) - fig, ax = lab.plot(data) - plt.close(fig) + # run experiments + if run_all: + data = lab.run(ux=False, bx=False, ps=False, num=num, **run_kwargs) + data = lab.run(ux=True, bx=False, ps=False, num=num, **run_kwargs) + data = lab.run(ux=True, bx=True, ps=False, num=num, **run_kwargs) + + data = lab.run(ux=True, bx=True, ps=True, num=num, **run_kwargs) + + if plot: + # plot stress vs. stretch + fig, ax = lab.plot(data, stability=stability) + + if close: + plt.close(fig) + + # dW and DW are lists + assert len(data[0].stress) == num + assert len(data[0].stretch) == num + + return data + + +def test_lab(): + + data = pre(neo_hooke, test_without_bulk=True) + data = pre(neo_hooke, run_all=True) + + run_kwargs = {"stretch_min": 0.1, "stretch_max": 1.0} + + data = pre(neo_hooke, run_kwargs=run_kwargs) + data = pre(extended_tube) + data = pre(van_der_waals) + data = pre(mooney_rivlin, close=True, stability=True, plot=True) - # dW and DW are always lists... - assert len(data[0].stress) == 20 - assert len(data[0].stretch) == 20 + del data if __name__ == "__main__": From 22345e109b1574e59e326a8b8426930a5d366a18 Mon Sep 17 00:00:00 2001 From: Andreas D Date: Tue, 28 Sep 2021 08:59:27 +0200 Subject: [PATCH 13/14] Update test_lab.py --- tests/test_lab.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/test_lab.py b/tests/test_lab.py index 89718db..e79803e 100644 --- a/tests/test_lab.py +++ b/tests/test_lab.py @@ -1,9 +1,32 @@ from matadi import MaterialHyperelastic, Lab +import matadi.models as md from matadi.models import neo_hooke, extended_tube, van_der_waals, mooney_rivlin import matplotlib.pyplot as plt -from test_models import library + +def library(): + "Library with models and parameters." + + database = { + md.saint_venant_kirchhoff: {"mu": 1.0, "lmbda": 20.0}, + md.neo_hooke: {"C10": 0.5}, + md.mooney_rivlin: {"C10": 0.3, "C01": 0.8}, + md.yeoh: {"C10": 0.5, "C20": 0.1, "C30": 0.01}, + md.third_order_deformation: { + "C10": 0.3, + "C01": 0.2, + "C11": 0.02, + "C20": -0.1, + "C30": 0.02, + }, + md.ogden: {"mu": (1.0, 0.2), "alpha": (2.0, -1.5)}, + md.arruda_boyce: {"C1": 1.0, "limit": 3.2}, + md.extended_tube: {"Gc": 0.1867, "Ge": 0.2169, "beta": 0.2, "delta": 0.09693}, + md.van_der_waals: {"mu": 1.0, "beta": 0.1, "a": 0.5, "limit": 5.0}, + } + + return database def pre( From 1890d3a2f3d70269867aa3df9e30170a211fa4d2 Mon Sep 17 00:00:00 2001 From: Andreas D Date: Tue, 28 Sep 2021 09:03:35 +0200 Subject: [PATCH 14/14] Update test_lab.py --- tests/test_lab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_lab.py b/tests/test_lab.py index e79803e..35d0cc9 100644 --- a/tests/test_lab.py +++ b/tests/test_lab.py @@ -78,7 +78,7 @@ def pre( def test_lab(): data = pre(neo_hooke, test_without_bulk=True) - data = pre(neo_hooke, run_all=True) + data = pre(neo_hooke, run_all=True, plot=True, close=True) run_kwargs = {"stretch_min": 0.1, "stretch_max": 1.0}