Skip to content

Commit

Permalink
Merge pull request #131 from adtzlr/models-invariants-args-optional
Browse files Browse the repository at this point in the history
Make secondary arguments of `models` optional
  • Loading branch information
adtzlr authored May 2, 2023
2 parents 8cae7d9 + b504fa7 commit 19838c3
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-line-length = 88
extend-ignore = E203
exclude = tests
2 changes: 1 addition & 1 deletion src/matadi/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.16"
__version__ = "0.1.17"
30 changes: 24 additions & 6 deletions src/matadi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import casadi

from .__about__ import __version__

Variable = casadi.SX.sym

from . import math, models
from .__about__ import __version__
from ._lab_compressible import LabCompressible
from ._lab_compressible import LabCompressible as Lab
from ._lab_incompressible import LabIncompressible
Expand All @@ -26,7 +21,30 @@
TwoFieldVariation,
TwoFieldVariationPlaneStrain,
)
from ._variable import Variable

__all__ = [
"__version__",
"math",
"models",
"LabCompressible",
"LabIncompressible",
"Lab",
"Function",
"FunctionScalar",
"FunctionTensor",
"Material",
"MaterialScalar",
"MaterialTensor",
"MaterialComposite",
"MaterialHyperelastic",
"MaterialHyperelasticPlaneStrain",
"MaterialHyperelasticPlaneStressIncompressible",
"MaterialHyperelasticPlaneStressLinearElastic",
"MaterialTensorGeneral",
"ThreeFieldVariation",
"ThreeFieldVariationPlaneStrain",
"TwoFieldVariation",
"TwoFieldVariationPlaneStrain",
"Variable",
]
1 change: 0 additions & 1 deletion src/matadi/_lab_incompressible.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import root


class LabIncompressible:
Expand Down
2 changes: 1 addition & 1 deletion src/matadi/_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import casadi as ca
import numpy as np

from . import Variable
from ._apply import apply
from ._variable import Variable


class Function:
Expand Down
4 changes: 2 additions & 2 deletions src/matadi/_templates.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from . import Variable
from ._material import Material, MaterialTensor
from ._variable import Variable
from .math import Function, det, eye
from .math import gradient as grad
from .math import horzcat, trace, vertcat, zeros
Expand Down Expand Up @@ -241,7 +241,7 @@ def __init__(self, fun, statevars_shape=(1, 1), x=None, triu=True, **kwargs):
try:
# displacement-pressure split
x.append(fun.p)
except:
except AttributeError:
pass

# add state variables
Expand Down
3 changes: 3 additions & 0 deletions src/matadi/_variable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import casadi

Variable = casadi.SX.sym
75 changes: 71 additions & 4 deletions src/matadi/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,73 @@
vertsplit,
)

__all__ = [
"DM",
"MX",
"SX",
"Function",
"acos",
"acosh",
"adj",
"asin",
"asinh",
"atan",
"atan2",
"atanh",
"ceil",
"cofactor",
"cos",
"cosh",
"cross",
"det",
"diag",
"_dot",
"eig_symbolic",
"erf",
"erfinv",
"exp",
"fabs",
"find",
"floor",
"fmax",
"fmin",
"gradient",
"hessian",
"horzcat",
"horzsplit",
"if_else",
"inv",
"ldl",
"linspace",
"log",
"logic_and",
"logic_not",
"logic_or",
"mmax",
"mmin",
"norm_1",
"pi",
"qr",
"repmat",
"reshape",
"sign",
"sin",
"sinh",
"sqrt",
"sum1",
"sum2",
"sumsqr",
"tan",
"tanh",
"times",
"trace",
"transpose",
"tril",
"triu",
"vertcat",
"vertsplit",
]

eye = SX.eye
ones = SX.ones
zeros = SX.zeros
Expand Down Expand Up @@ -134,11 +201,11 @@ def tresca(C):
def mexp(C, eps=8e-5):
"Exponential Function of a Matrix."
w = eigvals(C, eps=eps)
I = SX.eye(3)
eye = SX.eye(3)

M1 = (C - w[1] * I) * (C - w[2] * I) / (w[0] - w[1]) / (w[0] - w[2])
M2 = (C - w[2] * I) * (C - w[0] * I) / (w[1] - w[2]) / (w[1] - w[0])
M3 = (C - w[0] * I) * (C - w[1] * I) / (w[2] - w[0]) / (w[2] - w[1])
M1 = (C - w[1] * eye) * (C - w[2] * eye) / (w[0] - w[1]) / (w[0] - w[2])
M2 = (C - w[2] * eye) * (C - w[0] * eye) / (w[1] - w[2]) / (w[1] - w[0])
M3 = (C - w[0] * eye) * (C - w[1] * eye) / (w[2] - w[0]) / (w[2] - w[1])

return exp(w[0]) * M1 + exp(w[1]) * M2 + exp(w[2]) * M3

Expand Down
27 changes: 27 additions & 0 deletions src/matadi/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,30 @@
from ._templates import Morph, NeoHookeOgdenRoxburgh, Viscoelastic
from ._viscoelasticity import finite_strain_viscoelastic
from .microsphere.nonaffine import miehe_goektepe_lulei

__all__ = [
"microsphere",
"displacement_pressure_split",
"isochoric_volumetric_split",
"volumetric",
"fiber",
"fiber_family",
"holzapfel_gasser_ogden",
"arruda_boyce",
"extended_tube",
"linear_elastic",
"mooney_rivlin",
"neo_hooke",
"ogden",
"saint_venant_kirchhoff",
"third_order_deformation",
"van_der_waals",
"yeoh",
"morph",
"ogden_roxburgh",
"Morph",
"NeoHookeOgdenRoxburgh",
"Viscoelastic",
"finite_strain_viscoelastic",
"miehe_goektepe_lulei",
]
2 changes: 1 addition & 1 deletion src/matadi/models/_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from copy import deepcopy
from functools import wraps

from .. import Variable
from .._variable import Variable
from ..math import cof, det, gradient, trace


Expand Down
1 change: 0 additions & 1 deletion src/matadi/models/_hyperelasticity_anisotropic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from ..math import (
DM,
cos,
det,
exp,
if_else,
invariants,
Expand Down
12 changes: 6 additions & 6 deletions src/matadi/models/_hyperelasticity_isotropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ def neo_hooke(F, C10):


@isochoric_volumetric_split
def mooney_rivlin(F, C10, C01):
def mooney_rivlin(F, C10, C01=0):
C = transpose(F) @ F
I1 = trace(C)
I2 = (trace(C) ** 2 - trace(C @ C)) / 2
return C10 * (I1 - 3) + C01 * (I2 - 3)


@isochoric_volumetric_split
def yeoh(F, C10, C20, C30):
def yeoh(F, C10, C20=0, C30=0):
J = det(F)
C = transpose(F) @ F
I1 = J ** (-2 / 3) * trace(C)
return C10 * (I1 - 3) + C20 * (I1 - 3) ** 2 + C30 * (I1 - 3) ** 3


@isochoric_volumetric_split
def third_order_deformation(F, C10, C01, C11, C20, C30):
def third_order_deformation(F, C10, C01=0, C11=0, C20=0, C30=0):
C = transpose(F) @ F
I1 = trace(C)
I2 = (trace(C) ** 2 - trace(C @ C)) / 2
Expand Down Expand Up @@ -96,8 +96,8 @@ def van_der_waals(F, mu, limit, a, beta):
C = transpose(F) @ F
I1 = trace(C)
I2 = (trace(C) ** 2 - trace(C @ C)) / 2
I = (1 - beta) * I1 + beta * I2
eta = sqrt((I - 3) / (limit**2 - 3))
Im = (1 - beta) * I1 + beta * I2
eta = sqrt((Im - 3) / (limit**2 - 3))
return mu * (
-(limit**2 - 3) * (log(1 - eta) + eta) - 2 / 3 * a * ((I - 3) / 2) ** (3 / 2)
-(limit**2 - 3) * (log(1 - eta) + eta) - 2 / 3 * a * ((Im - 3) / 2) ** (3 / 2)
)
4 changes: 3 additions & 1 deletion src/matadi/models/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def morph(x, p1, p2, p3, p4, p5, p6, p7, p8):
CT_CTS = if_else(CTS > 0, CT / CTS, CT)

# MORPH deformation-dependent material parameters
f = lambda x: 1 / sqrt(1 + x**2)
def f(x):
return 1 / sqrt(1 + x**2)

a = p1 + p2 * f(p3 * CTS)
b = p4 * f(p3 * CTS)
c = p5 * CTS * (1 - f(CTS / p6))
Expand Down
10 changes: 10 additions & 0 deletions src/matadi/models/microsphere/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
from . import affine, nonaffine, quadrature
from ._chain import gauss, langevin, langevin2, linear

__all__ = [
"affine",
"nonaffine",
"quadrature",
"gauss",
"langevin",
"langevin2",
"linear",
]
6 changes: 6 additions & 0 deletions src/matadi/models/microsphere/affine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from ._models import microsphere_affine_force as force
from ._models import microsphere_affine_stretch as stretch
from ._models import microsphere_affine_tube as tube

__all__ = [
"force",
"stretch",
"tube",
]
6 changes: 6 additions & 0 deletions src/matadi/models/microsphere/nonaffine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from ._models import microsphere_nonaffine_miehe_goektepe_lulei as miehe_goektepe_lulei
from ._models import microsphere_nonaffine_stretch as stretch
from ._models import microsphere_nonaffine_tube as tube

__all__ = [
"miehe_goektepe_lulei",
"stretch",
"tube",
]
4 changes: 4 additions & 0 deletions src/matadi/models/microsphere/quadrature/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
from ._bazant_oh import BazantOh

__all__ = [
"BazantOh",
]

0 comments on commit 19838c3

Please sign in to comment.