Skip to content

Commit

Permalink
Merge pull request #115 from adtzlr/simplify-microsphere-force
Browse files Browse the repository at this point in the history
Simplify microsphere affine force
  • Loading branch information
adtzlr authored Aug 16, 2022
2 parents 7cd77e6 + 935f96a commit 8c12d53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
6 changes: 1 addition & 5 deletions matadi/models/microsphere/affine/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,22 @@ def microsphere_affine_force(x, fun, *args, **kwargs):

# extract current and initial deformation gradient and state variables
F = x[0]
Fn = x[-2]
statevars_n = x[-1]

# volume ratios
J = det(F)
Jn = det(Fn)

# unimodular part of current and initial right Cauchy-Green deformation tensor
C = F.T @ F
CG = J ** (-2 / 3) * (C)
CGn = Jn ** (-2 / 3) * (Fn.T @ Fn)

# affine stretches
lam_n = sqrt(diag(sphere.points.T @ CGn @ sphere.points))
lam = sqrt(diag(sphere.points.T @ CG @ sphere.points))

bulk = kwargs.pop("bulk")

# fiber forces and state variable update
f, statevars = fun(lam, lam_n, statevars_n, *args, **kwargs)
f, statevars = fun(lam, statevars_n, *args, **kwargs)

# Second Piola-Kirchhoff stress tensor
SG = reshape(sum1(f / lam * sphere.weights * sphere.bases), 3, 3)
Expand Down
26 changes: 11 additions & 15 deletions tests/test_microsphere.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@
import numpy as np

from matadi import MaterialTensor, Variable
from matadi.models.microsphere.affine import force
from matadi.models.microsphere import affine


def nh(stretch, stretch_n, statevars_n, mu=1.0):
def nh(stretch, statevars_n, mu=1.0):
"1d-Linear force-stretch consitututive material formulation."

return 3 * mu * stretch, statevars_n


def test_microsphere_force():

param = [nh, 1.0]

F = Variable("F", 3, 3)
Fn = Variable("Fn", 3, 3)
Zn = Variable("Zn", 2, 21)
Zn = Variable("Zn", 5, 21)

umat = MaterialTensor(
x=[F, force.p, Fn, Zn],
fun=force,
args=param,
kwargs={"bulk": 5000},
statevars=2,
x=[F, affine.force.p, Zn],
fun=affine.force,
kwargs={"fun": nh, "mu": 1.0, "bulk": 5000},
statevars=1,
triu=True,
)

F = np.random.rand(3, 3, 8, 100) / 2
Fn = np.random.rand(3, 3, 8, 100) / 2
p = np.random.rand(1, 8, 100)
Zn = np.random.rand(2, 21, 8, 100)
Zn = np.random.rand(5, 21, 8, 100)

for a in range(3):
F[a, a] += 1
Fn[a, a] += 1

P, Q, Z = umat.function([F, p, Fn, Zn])
A = umat.gradient([F, p, Fn, Zn])
P, Q, Z = umat.function([F, p, Zn])
A = umat.gradient([F, p, Zn])

assert P.shape == (3, 3, 8, 100)
assert Q.shape == (1, 1, 8, 100)
assert Z.shape == (2, 21, 8, 100)
assert Z.shape == (5, 21, 8, 100)

assert len(A) == 3

Expand Down

0 comments on commit 8c12d53

Please sign in to comment.