Skip to content

Commit

Permalink
Merge pull request #111 from adtzlr/add-template-materials
Browse files Browse the repository at this point in the history
Add template tensor-based materials
  • Loading branch information
adtzlr authored Aug 14, 2022
2 parents 1c6de22 + a284a08 commit 6a53171
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion matadi/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.8"
__version__ = "0.1.9"
2 changes: 2 additions & 0 deletions matadi/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@

from . import microsphere
from .microsphere.nonaffine import miehe_goektepe_lulei

from ._templates import NeoHookeOgdenRoxburgh, Morph
2 changes: 1 addition & 1 deletion matadi/models/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
83 changes: 83 additions & 0 deletions matadi/models/_templates.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = matadi
version = 0.1.8
version = 0.1.9
author = Andreas Dutzler
author_email = [email protected]
description = Material Definition with Automatic Differentiation
Expand Down
29 changes: 29 additions & 0 deletions tests/test_template-materials.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 6a53171

Please sign in to comment.