adtzlr / matadi

Material Definition with Automatic Differentiation
GNU General Public License v3.0
21 stars 2 forks source link

Enhance MaterialTensor #84

Closed adtzlr closed 2 years ago

adtzlr commented 2 years ago

With the above enhancements it will be possible to code a u/p - Formulation:

# W(u, p) = w(u) + p (J - 1) - p^2 / (2 K)
# dWdE = dwdE + p J inv(C) (= S)
# dWdp = (J - 1) - p / K (= constraint)
adtzlr commented 2 years ago

Example:

from matadi import MaterialTensor, Variable
from matadi.math import det, dev, inv
import numpy as np

defgrad = np.random.rand(3, 3, 5, 100) - 0.5
for a in range(3):
    defgrad[a, a] += 1.0

pressure = np.random.rand(5, 100)

F = Variable("F", 3, 3)
p = Variable("p")

def nh(x, C10=0.5, bulk=5000):
    """Neo-Hookean material formulation with first Piola-Kirchhoff stress
    and volumetric constraint equation (u/p formulation)."""

    F, p = x

    J = det(F)
    C = F.T @ F

    S = 2 * C10 * dev(J ** (-2 / 3) * C) @ inv(C) + p * J * inv(C)
    constraint = (J - 1) - p / bulk

    return F @ S, constraint

# (u/p) framework
# ===============
# W(u, p) = w(u) + p (J - 1) - p^2 / (2 K)
# dWdE = dwdE + p J inv(C) (= S)
# dWdp = (J - 1) - p / K (= constraint)

NH = MaterialTensor(x=[F, p], fun=nh)

W = NH.function([defgrad, pressure])
P = NH.gradient([defgrad, pressure])