From d5b28a202a0b7f1e72ab6fef57eac227a92193c4 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Thu, 28 Nov 2024 20:54:19 +0100 Subject: [PATCH] add test, format black --- src/felupe/mechanics/_solidbody.py | 8 ++++---- tests/test_free_vibration.py | 17 +++++++++++++++-- tests/test_mechanics.py | 6 +++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/felupe/mechanics/_solidbody.py b/src/felupe/mechanics/_solidbody.py index 7bdaa4af..fa806639 100644 --- a/src/felupe/mechanics/_solidbody.py +++ b/src/felupe/mechanics/_solidbody.py @@ -398,13 +398,13 @@ def _cauchy_stress(self, field=None): return dot(P, transpose(F)) / J def _mass(self, density=None): - + if density is None: density = self.density - + field = self.field[0].as_container() dim = field[0].dim - + form = self._form( fun=[density * np.eye(dim).reshape(dim, dim, 1, 1)], v=field, @@ -413,5 +413,5 @@ def _mass(self, density=None): grad_v=[False], grad_u=[False], ) - + return form.assemble() diff --git a/tests/test_free_vibration.py b/tests/test_free_vibration.py index c4aec5d1..e74129a3 100644 --- a/tests/test_free_vibration.py +++ b/tests/test_free_vibration.py @@ -4,6 +4,20 @@ def test_free_vibration(): + + mesh = fem.Cube(a=(0, 0, 5), b=(50, 100, 30), n=(3, 6, 4)) + region = fem.RegionHexahedron(mesh) + field = fem.FieldContainer([fem.Field(region, dim=3)]) + + umat = fem.NeoHooke(mu=1, bulk=2) + solid = fem.SolidBody(umat=umat, field=field, density=1.5e-9) + + job = fem.FreeVibration([solid]).evaluate(x0=field) + new_field, frequency = job.extract(x0=field, n=-1, inplace=False) + + +def test_free_vibration_mixed(): + meshes = [ fem.Cube(a=(0, 0, 30), b=(50, 100, 35), n=(3, 6, 2)), fem.Cube(a=(0, 0, 5), b=(50, 100, 30), n=(3, 6, 4)), @@ -34,8 +48,7 @@ def test_free_vibration(): job = fem.FreeVibration(solids, boundaries).evaluate(x0=field) new_field, frequency = job.extract(x0=field, n=-1, inplace=False) - assert np.isclose(new_field[0].values.max(), 358.08157) - if __name__ == "__main__": test_free_vibration() + test_free_vibration_mixed() diff --git a/tests/test_mechanics.py b/tests/test_mechanics.py index f27ed6a0..fdf3daa8 100644 --- a/tests/test_mechanics.py +++ b/tests/test_mechanics.py @@ -235,7 +235,11 @@ def test_solidbody_incompressible(): umat = fem.OgdenRoxburgh(fem.NeoHooke(mu=1), r=3, m=1, beta=0) b = fem.SolidBodyNearlyIncompressible( - umat=umat, field=u, bulk=5000, state=fem.StateNearlyIncompressible(u), density=1.0 + umat=umat, + field=u, + bulk=5000, + state=fem.StateNearlyIncompressible(u), + density=1.0, ) M = b.assemble.mass()