Skip to content

Commit

Permalink
Add optional title in Lab(material, title=None)
Browse files Browse the repository at this point in the history
also lint black with new version
  • Loading branch information
adtzlr committed Jul 3, 2023
1 parent 08a75f0 commit e2ec2d8
Show file tree
Hide file tree
Showing 17 changed files with 9 additions and 67 deletions.
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.18"
__version__ = "0.1.19"
10 changes: 4 additions & 6 deletions src/matadi/_lab_compressible.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]
Expand All @@ -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()
Expand Down
10 changes: 4 additions & 6 deletions src/matadi/_lab_incompressible.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]
Expand All @@ -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()
Expand Down
4 changes: 0 additions & 4 deletions src/matadi/_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class Function:
def __init__(self, x, fun, args=(), kwargs={}, compress=False):

self.x = x
self._fun = fun

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions src/matadi/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)


Expand All @@ -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],
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/matadi/models/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def displacement_pressure_split(fun):

@wraps(fun)
def apply_up(*args, **kwargs):

F = args[0][0]

f = fun(*args, **kwargs)
Expand Down
2 changes: 0 additions & 2 deletions src/matadi/models/_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions tests/test_displacement-pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand All @@ -77,7 +75,6 @@ def test_up_state():


def test_up_basic():

# deformation gradient
F = Variable("F", 3, 3)

Expand Down
7 changes: 0 additions & 7 deletions tests/test_eigvals_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -59,7 +57,6 @@ def test_eigvals():


def test_eigvals_single():

# variables
F = Variable("F", 3, 3)

Expand Down Expand Up @@ -89,7 +86,6 @@ def test_eigvals_single():


def test_cof():

# variables
F = Variable("F", 3, 3)

Expand Down Expand Up @@ -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)

Expand All @@ -144,7 +138,6 @@ def test_mexp():


if __name__ == "__main__":

# test several repeated principal stretches
test_eigvals()
test_mexp()
Expand Down
4 changes: 0 additions & 4 deletions tests/test_fiber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions tests/test_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def pre(
run_kwargs={},
LabClass=Lab,
):

lib = library()
kwargs = lib[model]

Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion tests/test_microsphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def library():


def test_models():

# data
np.random.seed(2345537)
dF = np.random.rand(3, 3, 5, 100) - 0.5
Expand All @@ -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

Expand Down
6 changes: 0 additions & 6 deletions tests/test_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


def pre():

FF = np.random.rand(2, 2, 8, 1000)
for a in range(2):
FF[a, a] += 1
Expand All @@ -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
Expand All @@ -32,7 +30,6 @@ def pre_mixed():


def test_plane_strain():

# data
FF = pre()

Expand All @@ -56,7 +53,6 @@ def test_plane_strain():


def test_plane_strain_mixed():

# data
FF, pp, JJ = pre_mixed()

Expand Down Expand Up @@ -96,7 +92,6 @@ def test_plane_strain_mixed():


def test_plane_stress_incompr():

# data
FF = pre()

Expand All @@ -120,7 +115,6 @@ def test_plane_stress_incompr():


def test_plane_stress_linear():

# data
FF = pre()

Expand Down
Loading

0 comments on commit e2ec2d8

Please sign in to comment.