From 1105495a95e91406b0706ce8df9c88cf1ab8b87c Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Tue, 2 May 2023 16:11:37 +0200 Subject: [PATCH 1/5] Make secondary arguments of `models` optional --- src/matadi/models/_hyperelasticity_isotropic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/matadi/models/_hyperelasticity_isotropic.py b/src/matadi/models/_hyperelasticity_isotropic.py index 9278772..1b11780 100644 --- a/src/matadi/models/_hyperelasticity_isotropic.py +++ b/src/matadi/models/_hyperelasticity_isotropic.py @@ -22,7 +22,7 @@ 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 @@ -30,7 +30,7 @@ def mooney_rivlin(F, C10, C01): @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) @@ -38,7 +38,7 @@ def yeoh(F, C10, C20, C30): @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 From a789a7e4f35654d459b0e9d209ff4f6bf9ac7b0a Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Tue, 2 May 2023 16:27:22 +0200 Subject: [PATCH 2/5] Flake8 compliant code (excluding `/tests`) --- .flake8 | 4 + src/matadi/__init__.py | 29 ++++++- src/matadi/_lab_incompressible.py | 1 - src/matadi/_templates.py | 2 +- src/matadi/math.py | 75 ++++++++++++++++++- src/matadi/models/__init__.py | 27 +++++++ .../models/_hyperelasticity_anisotropic.py | 1 - .../models/_hyperelasticity_isotropic.py | 6 +- src/matadi/models/_misc.py | 4 +- src/matadi/models/microsphere/__init__.py | 10 +++ .../models/microsphere/affine/__init__.py | 6 ++ .../models/microsphere/nonaffine/__init__.py | 6 ++ .../models/microsphere/quadrature/__init__.py | 4 + 13 files changed, 160 insertions(+), 15 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..317f180 --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +max-line-length = 88 +extend-ignore = E203 +exclude = tests diff --git a/src/matadi/__init__.py b/src/matadi/__init__.py index 2aa593b..ffa5c52 100644 --- a/src/matadi/__init__.py +++ b/src/matadi/__init__.py @@ -1,9 +1,5 @@ import casadi - from .__about__ import __version__ - -Variable = casadi.SX.sym - from . import math, models from ._lab_compressible import LabCompressible from ._lab_compressible import LabCompressible as Lab @@ -27,6 +23,31 @@ TwoFieldVariationPlaneStrain, ) +Variable = casadi.SX.sym + __all__ = [ "__version__", + "casadi", + "math", + "models", + "LabCompressible", + "LabIncompressible", + "Lab", + "Function", + "FunctionScalar", + "FunctionTensor", + "Material", + "MaterialScalar", + "MaterialTensor", + "MaterialComposite", + "MaterialHyperelastic", + "MaterialHyperelasticPlaneStrain", + "MaterialHyperelasticPlaneStressIncompressible", + "MaterialHyperelasticPlaneStressLinearElastic", + "MaterialTensorGeneral", + "ThreeFieldVariation", + "ThreeFieldVariationPlaneStrain", + "TwoFieldVariation", + "TwoFieldVariationPlaneStrain", + "Variable", ] diff --git a/src/matadi/_lab_incompressible.py b/src/matadi/_lab_incompressible.py index 01922b9..4336515 100644 --- a/src/matadi/_lab_incompressible.py +++ b/src/matadi/_lab_incompressible.py @@ -2,7 +2,6 @@ import matplotlib.pyplot as plt import numpy as np -from scipy.optimize import root class LabIncompressible: diff --git a/src/matadi/_templates.py b/src/matadi/_templates.py index 5291022..ad63f89 100644 --- a/src/matadi/_templates.py +++ b/src/matadi/_templates.py @@ -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 diff --git a/src/matadi/math.py b/src/matadi/math.py index f68e5a8..e952d3c 100644 --- a/src/matadi/math.py +++ b/src/matadi/math.py @@ -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 @@ -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 diff --git a/src/matadi/models/__init__.py b/src/matadi/models/__init__.py index 4840a8e..f3d6d5a 100644 --- a/src/matadi/models/__init__.py +++ b/src/matadi/models/__init__.py @@ -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", +] diff --git a/src/matadi/models/_hyperelasticity_anisotropic.py b/src/matadi/models/_hyperelasticity_anisotropic.py index 4255086..4c7d7c7 100644 --- a/src/matadi/models/_hyperelasticity_anisotropic.py +++ b/src/matadi/models/_hyperelasticity_anisotropic.py @@ -1,7 +1,6 @@ from ..math import ( DM, cos, - det, exp, if_else, invariants, diff --git a/src/matadi/models/_hyperelasticity_isotropic.py b/src/matadi/models/_hyperelasticity_isotropic.py index 1b11780..1ca1258 100644 --- a/src/matadi/models/_hyperelasticity_isotropic.py +++ b/src/matadi/models/_hyperelasticity_isotropic.py @@ -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) ) diff --git a/src/matadi/models/_misc.py b/src/matadi/models/_misc.py index abf5e32..f194e5f 100644 --- a/src/matadi/models/_misc.py +++ b/src/matadi/models/_misc.py @@ -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)) diff --git a/src/matadi/models/microsphere/__init__.py b/src/matadi/models/microsphere/__init__.py index fee0416..79ae8b6 100644 --- a/src/matadi/models/microsphere/__init__.py +++ b/src/matadi/models/microsphere/__init__.py @@ -1,2 +1,12 @@ from . import affine, nonaffine, quadrature from ._chain import gauss, langevin, langevin2, linear + +__all__ = [ + "affine", + "nonaffine", + "quadrature", + "gauss", + "langevin", + "langevin2", + "linear", +] diff --git a/src/matadi/models/microsphere/affine/__init__.py b/src/matadi/models/microsphere/affine/__init__.py index 9c2cb47..39f3fef 100644 --- a/src/matadi/models/microsphere/affine/__init__.py +++ b/src/matadi/models/microsphere/affine/__init__.py @@ -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", +] diff --git a/src/matadi/models/microsphere/nonaffine/__init__.py b/src/matadi/models/microsphere/nonaffine/__init__.py index 9a1d577..6caa501 100644 --- a/src/matadi/models/microsphere/nonaffine/__init__.py +++ b/src/matadi/models/microsphere/nonaffine/__init__.py @@ -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", +] diff --git a/src/matadi/models/microsphere/quadrature/__init__.py b/src/matadi/models/microsphere/quadrature/__init__.py index 597df36..c604042 100644 --- a/src/matadi/models/microsphere/quadrature/__init__.py +++ b/src/matadi/models/microsphere/quadrature/__init__.py @@ -1 +1,5 @@ from ._bazant_oh import BazantOh + +__all__ = [ + "BazantOh", +] From 8621da472a93980a050825a2bc03572e7c361372 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Tue, 2 May 2023 16:27:42 +0200 Subject: [PATCH 3/5] Update __about__.py --- src/matadi/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/matadi/__about__.py b/src/matadi/__about__.py index 970659c..86205cb 100644 --- a/src/matadi/__about__.py +++ b/src/matadi/__about__.py @@ -1 +1 @@ -__version__ = "0.1.16" +__version__ = "0.1.17" From 8d8f993bcb73130381f21f94722c094396500c55 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Tue, 2 May 2023 16:35:32 +0200 Subject: [PATCH 4/5] Fix imports --- src/matadi/__init__.py | 3 ++- src/matadi/_material.py | 3 ++- src/matadi/_templates.py | 4 +++- src/matadi/models/_helpers.py | 5 ++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/matadi/__init__.py b/src/matadi/__init__.py index ffa5c52..9379a74 100644 --- a/src/matadi/__init__.py +++ b/src/matadi/__init__.py @@ -1,6 +1,7 @@ import casadi -from .__about__ import __version__ + 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 diff --git a/src/matadi/_material.py b/src/matadi/_material.py index bb7cc76..c05eff0 100644 --- a/src/matadi/_material.py +++ b/src/matadi/_material.py @@ -3,9 +3,10 @@ import casadi as ca import numpy as np -from . import Variable from ._apply import apply +Variable = ca.SX.sym + class Function: def __init__(self, x, fun, args=(), kwargs={}, compress=False): diff --git a/src/matadi/_templates.py b/src/matadi/_templates.py index ad63f89..07def68 100644 --- a/src/matadi/_templates.py +++ b/src/matadi/_templates.py @@ -1,11 +1,13 @@ +import casadi import numpy as np -from . import Variable from ._material import Material, MaterialTensor from .math import Function, det, eye from .math import gradient as grad from .math import horzcat, trace, vertcat, zeros +Variable = casadi.SX.sym + class TwoFieldVariation: def __init__(self, material): diff --git a/src/matadi/models/_helpers.py b/src/matadi/models/_helpers.py index 1e03be6..8658a7f 100644 --- a/src/matadi/models/_helpers.py +++ b/src/matadi/models/_helpers.py @@ -1,9 +1,12 @@ from copy import deepcopy from functools import wraps -from .. import Variable +import casadi + from ..math import cof, det, gradient, trace +Variable = casadi.SX.sym + def isochoric_volumetric_split(fun): """Apply the material formulation only on the isochoric part of the From b504fa712b04f190b2d96739280058cc2ef2ccfe Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Tue, 2 May 2023 16:38:33 +0200 Subject: [PATCH 5/5] Rebase `Variable` imports --- src/matadi/__init__.py | 6 +----- src/matadi/_material.py | 3 +-- src/matadi/_templates.py | 4 +--- src/matadi/_variable.py | 3 +++ src/matadi/models/_helpers.py | 5 +---- 5 files changed, 7 insertions(+), 14 deletions(-) create mode 100644 src/matadi/_variable.py diff --git a/src/matadi/__init__.py b/src/matadi/__init__.py index 9379a74..acbaeff 100644 --- a/src/matadi/__init__.py +++ b/src/matadi/__init__.py @@ -1,5 +1,3 @@ -import casadi - from . import math, models from .__about__ import __version__ from ._lab_compressible import LabCompressible @@ -23,12 +21,10 @@ TwoFieldVariation, TwoFieldVariationPlaneStrain, ) - -Variable = casadi.SX.sym +from ._variable import Variable __all__ = [ "__version__", - "casadi", "math", "models", "LabCompressible", diff --git a/src/matadi/_material.py b/src/matadi/_material.py index c05eff0..735aa2f 100644 --- a/src/matadi/_material.py +++ b/src/matadi/_material.py @@ -4,8 +4,7 @@ import numpy as np from ._apply import apply - -Variable = ca.SX.sym +from ._variable import Variable class Function: diff --git a/src/matadi/_templates.py b/src/matadi/_templates.py index 07def68..2622f2c 100644 --- a/src/matadi/_templates.py +++ b/src/matadi/_templates.py @@ -1,13 +1,11 @@ -import casadi import numpy as np 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 -Variable = casadi.SX.sym - class TwoFieldVariation: def __init__(self, material): diff --git a/src/matadi/_variable.py b/src/matadi/_variable.py new file mode 100644 index 0000000..6fd43a7 --- /dev/null +++ b/src/matadi/_variable.py @@ -0,0 +1,3 @@ +import casadi + +Variable = casadi.SX.sym diff --git a/src/matadi/models/_helpers.py b/src/matadi/models/_helpers.py index 8658a7f..80f79a6 100644 --- a/src/matadi/models/_helpers.py +++ b/src/matadi/models/_helpers.py @@ -1,12 +1,9 @@ from copy import deepcopy from functools import wraps -import casadi - +from .._variable import Variable from ..math import cof, det, gradient, trace -Variable = casadi.SX.sym - def isochoric_volumetric_split(fun): """Apply the material formulation only on the isochoric part of the