From e2ec2d8f1715d7424554ac9e5483403cfeaf2944 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Mon, 3 Jul 2023 17:23:59 +0200 Subject: [PATCH] Add optional title in `Lab(material, title=None)` also lint black with new version --- src/matadi/__about__.py | 2 +- src/matadi/_lab_compressible.py | 10 ++++------ src/matadi/_lab_incompressible.py | 10 ++++------ src/matadi/_material.py | 4 ---- src/matadi/math.py | 11 ----------- src/matadi/models/_helpers.py | 1 - src/matadi/models/_templates.py | 2 -- tests/test_displacement-pressure.py | 3 --- tests/test_eigvals_grad.py | 7 ------- tests/test_fiber.py | 4 ---- tests/test_lab.py | 3 --- tests/test_microsphere.py | 1 - tests/test_models.py | 2 -- tests/test_plane.py | 6 ------ tests/test_scalar.py | 2 -- tests/test_simple.py | 3 --- tests/test_template-materials.py | 5 ----- 17 files changed, 9 insertions(+), 67 deletions(-) diff --git a/src/matadi/__about__.py b/src/matadi/__about__.py index 08f934f..d38c350 100644 --- a/src/matadi/__about__.py +++ b/src/matadi/__about__.py @@ -1 +1 @@ -__version__ = "0.1.18" +__version__ = "0.1.19" diff --git a/src/matadi/_lab_compressible.py b/src/matadi/_lab_compressible.py index c141f6b..779e417 100644 --- a/src/matadi/_lab_compressible.py +++ b/src/matadi/_lab_compressible.py @@ -6,10 +6,11 @@ class LabCompressible: - def __init__(self, material): - + def __init__(self, material, title=None): self.material = material - self.title = self._get_title() + self.title = title + if title is None: + self.title = self._get_title() def _get_title(self): return "Material Formulation: " + "-".join( @@ -305,9 +306,7 @@ def plot(self, data, stability=False): data = data[:-1] for d in data: - if stability: - stable = np.array(d.stability, dtype=bool) unstable_idx = np.arange(len(d.stretch))[~stable] @@ -328,7 +327,6 @@ def plot(self, data, stability=False): ) else: - ax.plot(d.stretch, d.stress, **lineargs[d.label], label=d.label) ax.grid() diff --git a/src/matadi/_lab_incompressible.py b/src/matadi/_lab_incompressible.py index 4336515..2111fbf 100644 --- a/src/matadi/_lab_incompressible.py +++ b/src/matadi/_lab_incompressible.py @@ -5,10 +5,11 @@ class LabIncompressible: - def __init__(self, material): - + def __init__(self, material, title=None): self.material = material - self.title = self._get_title() + self.title = title + if title is None: + self.title = self._get_title() def _get_title(self): return "Material Formulation: " + "-".join( @@ -203,9 +204,7 @@ def plot(self, data, stability=False): data = data[:-1] for d in data: - if stability: - stable = np.array(d.stability, dtype=bool) unstable_idx = np.arange(len(d.stretch))[~stable] @@ -226,7 +225,6 @@ def plot(self, data, stability=False): ) else: - ax.plot(d.stretch, d.stress, **lineargs[d.label], label=d.label) ax.grid() diff --git a/src/matadi/_material.py b/src/matadi/_material.py index 735aa2f..8c1d6e0 100644 --- a/src/matadi/_material.py +++ b/src/matadi/_material.py @@ -9,7 +9,6 @@ class Function: def __init__(self, x, fun, args=(), kwargs={}, compress=False): - self.x = x self._fun = fun @@ -45,7 +44,6 @@ def function(self, x, threads=cpu_count()): class FunctionTensor: def __init__(self, x, fun, args=(), kwargs={}, compress=False): - self.x = x self._fun = fun @@ -83,7 +81,6 @@ class Material(Function): def __init__( self, x, fun, args=(), kwargs={}, compress=False, triu=True, statevars=0 ): - # init Function super().__init__(x=x, fun=fun, args=args, kwargs=kwargs) @@ -206,7 +203,6 @@ class MaterialTensor(FunctionTensor): def __init__( self, x, fun, args=(), kwargs={}, compress=False, triu=True, statevars=0 ): - # init Function super().__init__(x=x, fun=fun, args=args, kwargs=kwargs) self.gradient = self.function diff --git a/src/matadi/math.py b/src/matadi/math.py index e952d3c..c230414 100644 --- a/src/matadi/math.py +++ b/src/matadi/math.py @@ -140,17 +140,14 @@ def zeros_like(T): - return zeros(T.shape) def ones_like(T): - return ones(T.shape) def invariants(T): - I1 = trace(T) I2 = (I1**2 - trace(T @ T)) / 2 I3 = det(T) @@ -159,36 +156,30 @@ def invariants(T): def eigvals(T, eps=1e-4): - D = DM([[1, 0, 0], [0, -1, 0], [0, 0, 0]]) return eig_symbolic(T + D * eps) def cof(T): - return det(T) * transpose(inv(T)) def sym(T): - return (T + transpose(T)) / 2 def dot(A, B): - return _dot(transpose(A), B) def dev(T): - dim = T.shape[0] return T - trace(T) / dim * eye(dim) def ddot(A, B): - return trace(transpose(A) @ B) @@ -211,7 +202,6 @@ def mexp(C, eps=8e-5): def asvoigt(A, scale=1): - if A.shape == (3, 3): return vertcat( A[0, 0], @@ -234,7 +224,6 @@ def asvoigt(A, scale=1): def astensor(A, scale=1): - if A.shape == (6, 1): A0 = vertcat(A[0] / scale, A[3] / scale, A[5]) A1 = vertcat(A[3] / scale, A[1], A[4] / scale) diff --git a/src/matadi/models/_helpers.py b/src/matadi/models/_helpers.py index 80f79a6..c8badcc 100644 --- a/src/matadi/models/_helpers.py +++ b/src/matadi/models/_helpers.py @@ -46,7 +46,6 @@ def displacement_pressure_split(fun): @wraps(fun) def apply_up(*args, **kwargs): - F = args[0][0] f = fun(*args, **kwargs) diff --git a/src/matadi/models/_templates.py b/src/matadi/models/_templates.py index 489ff4b..d982050 100644 --- a/src/matadi/models/_templates.py +++ b/src/matadi/models/_templates.py @@ -11,7 +11,6 @@ class NeoHookeOgdenRoxburgh(MaterialTensorGeneral): def __init__(self, C10=0.5, r=3, m=1, beta=0): def fun(x, C10, r, m, beta): - # split `x` into the deformation gradient and the state variable F, Wmaxn = x[0], x[-1] @@ -44,7 +43,6 @@ def __init__( p8=0.24, ): def fun(x, p1, p2, p3, p4, p5, p6, p7, p8): - P, statevars = morph(x, p1, p2, p3, p4, p5, p6, p7, p8) return P, statevars diff --git a/tests/test_displacement-pressure.py b/tests/test_displacement-pressure.py index 5419fc5..fec2403 100644 --- a/tests/test_displacement-pressure.py +++ b/tests/test_displacement-pressure.py @@ -45,7 +45,6 @@ def fun_morph(x, p1=0.035, p2=0.37, p3=0.17, p4=2.4, p5=0.01, p6=6.4, p7=5.5, p8 def test_up_state(): - # deformation gradient F = Variable("F", 3, 3) @@ -54,7 +53,6 @@ def test_up_state(): functions = [fun_nh_or, fun_morph] for fun, z in zip(functions, statevars): - # get pressure variable from augmented function p = fun.p @@ -77,7 +75,6 @@ def test_up_state(): def test_up_basic(): - # deformation gradient F = Variable("F", 3, 3) diff --git a/tests/test_eigvals_grad.py b/tests/test_eigvals_grad.py index 523a7d7..cd71e4d 100644 --- a/tests/test_eigvals_grad.py +++ b/tests/test_eigvals_grad.py @@ -15,10 +15,8 @@ def fun_mexp(x): def test_eigvals(): - # test several repeated principal stretches for w in [1, 1.1, 0.1, 2.4, 12]: - # variables F = Variable("F", 3, 3) @@ -59,7 +57,6 @@ def test_eigvals(): def test_eigvals_single(): - # variables F = Variable("F", 3, 3) @@ -89,7 +86,6 @@ def test_eigvals_single(): def test_cof(): - # variables F = Variable("F", 3, 3) @@ -120,10 +116,8 @@ def g(x): def test_mexp(): - # test several repeated principal stretches for w in [1, 1.1, 0.1, 2.4, 12]: - # variables F = Variable("F", 3, 3) @@ -144,7 +138,6 @@ def test_mexp(): if __name__ == "__main__": - # test several repeated principal stretches test_eigvals() test_mexp() diff --git a/tests/test_fiber.py b/tests/test_fiber.py index 8086226..e166bcf 100644 --- a/tests/test_fiber.py +++ b/tests/test_fiber.py @@ -6,14 +6,12 @@ def test_fiber(): - # data FF = np.zeros((3, 3, 2)) for a in range(3): FF[a, a] += 1 for model in [fiber, fiber_family]: - # init Material without bulk M = MaterialHyperelastic(model, E=1, angle=30, axis=2, k=0) @@ -43,14 +41,12 @@ def test_fiber(): def test_hgo(): - # data FF = np.zeros((3, 3, 2)) for a in range(3): FF[a, a] += 1 for model in [holzapfel_gasser_ogden]: - # init Material without bulk M = MaterialHyperelastic( model, c=0.0764, k1=996.6, k2=524.6, kappa=0.2, angle=49.98, axis=2 diff --git a/tests/test_lab.py b/tests/test_lab.py index 2f434d5..8ef68a7 100644 --- a/tests/test_lab.py +++ b/tests/test_lab.py @@ -42,7 +42,6 @@ def pre( run_kwargs={}, LabClass=Lab, ): - lib = library() kwargs = lib[model] @@ -94,9 +93,7 @@ def pre( def test_lab(): - for LabClass in [LabIncompressible, LabCompressible, Lab]: - data = pre(neo_hooke, test_without_bulk=True, LabClass=LabClass) data = pre( neo_hooke, diff --git a/tests/test_microsphere.py b/tests/test_microsphere.py index 9485113..3b410a7 100644 --- a/tests/test_microsphere.py +++ b/tests/test_microsphere.py @@ -11,7 +11,6 @@ def nh(stretch, statevars_n, mu=1.0): def test_microsphere_force(): - F = Variable("F", 3, 3) Fn = Variable("Fn", 3, 3) Zn = Variable("Zn", 5, 21) diff --git a/tests/test_models.py b/tests/test_models.py index aad25b3..7d78cae 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -68,7 +68,6 @@ def library(): def test_models(): - # data np.random.seed(2345537) dF = np.random.rand(3, 3, 5, 100) - 0.5 @@ -88,7 +87,6 @@ def test_models(): lib = library() for model, kwargs in lib.items(): - if model not in [md.saint_venant_kirchhoff, md.linear_elastic]: kwargs["bulk"] = 5000.0 diff --git a/tests/test_plane.py b/tests/test_plane.py index deed85a..c1bfcc7 100644 --- a/tests/test_plane.py +++ b/tests/test_plane.py @@ -11,7 +11,6 @@ def pre(): - FF = np.random.rand(2, 2, 8, 1000) for a in range(2): FF[a, a] += 1 @@ -20,7 +19,6 @@ def pre(): def pre_mixed(): - FF = np.random.rand(2, 2, 8, 1000) for a in range(2): FF[a, a] += 1 @@ -32,7 +30,6 @@ def pre_mixed(): def test_plane_strain(): - # data FF = pre() @@ -56,7 +53,6 @@ def test_plane_strain(): def test_plane_strain_mixed(): - # data FF, pp, JJ = pre_mixed() @@ -96,7 +92,6 @@ def test_plane_strain_mixed(): def test_plane_stress_incompr(): - # data FF = pre() @@ -120,7 +115,6 @@ def test_plane_stress_incompr(): def test_plane_stress_linear(): - # data FF = pre() diff --git a/tests/test_scalar.py b/tests/test_scalar.py index 08441b8..e1d47f8 100644 --- a/tests/test_scalar.py +++ b/tests/test_scalar.py @@ -5,7 +5,6 @@ def test_scalar(): - # variables F = Variable("F", 3, 3) p = Variable("p", 1) @@ -63,7 +62,6 @@ def neohooke(x, mu=1.0, bulk=200.0): def test_scalar_compress(): - # variables F = Variable("F", 3, 3) p = Variable("p", 1) diff --git a/tests/test_simple.py b/tests/test_simple.py index eb9df24..99cf839 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -24,7 +24,6 @@ def nh_aslist(x, mu=1.0, bulk=200.0): def test_simple(): - # variables F = Variable("F", 3, 3) @@ -73,7 +72,6 @@ def test_simple(): def test_tensor(): - # variables F = Variable("F", 3, 3) p = Variable("p", 1, 1) @@ -89,7 +87,6 @@ def test_tensor(): # init Material for fun in [lambda x: dev(x[0]) + ddot(x[0], x[0]), lambda x: x]: - W = MaterialTensor(x=[F], fun=fun) W0 = W.gradient([FF]) diff --git a/tests/test_template-materials.py b/tests/test_template-materials.py index 6666323..213af5c 100644 --- a/tests/test_template-materials.py +++ b/tests/test_template-materials.py @@ -12,7 +12,6 @@ def fun(x, C10=0.5, bulk=5000): - F = x[0] J = det(F) @@ -27,13 +26,11 @@ def fun(x, C10=0.5, bulk=5000): def test_templates(): - Custom = MaterialTensorGeneral(fun, statevars_shape=(1, 1)) # Material as a function of `F` # with additional state variables `z` for M in [Custom]: - FF = (np.random.rand(3, 3, 8, 100) - 0.5) / 2 zz = np.random.rand(*M.x[-1].shape, 8, 100) @@ -48,11 +45,9 @@ def test_templates(): def test_templates_models(): - # Material as a function of `F` # with additional state variables `z` for M in [NeoHookeOgdenRoxburgh(), Morph(), Viscoelastic()]: - FF = (np.random.rand(3, 3, 8, 100) - 0.5) / 2 zz = np.random.rand(*M.x[-1].shape, 8, 100)