def test_constructor_linear(self): t = Hexahedron() self.assertTrue((t.nodes() == np.array([[-1, -1, -1], [+1, -1, -1], [+1, +1, -1], [-1, +1, -1], [-1, -1, +1], [+1, -1, +1], [+1, +1, +1], [-1, +1, +1]])).all()) # 3D t = Hexahedron([-1, -1, -1], [+1, -1, -1], [+1, +1, -1], [-1, +1, -1], [-1, -1, +1], [+1, -1, +1], [+1, +1, +1], [-1, +1, +1]) self.assertTrue((t.nodes() == np.array([[-1, -1, -1], [+1, -1, -1], [+1, +1, -1], [-1, +1, -1], [-1, -1, +1], [+1, -1, +1], [+1, +1, +1], [-1, +1, +1]])).all()) t = Hexahedron([[-1, -1, -1], [+1, -1, -1], [+1, +1, -1], [-1, +1, -1], [-1, -1, +1], [+1, -1, +1], [+1, +1, +1], [-1, +1, +1]]) self.assertTrue((t.nodes() == np.array([[-1, -1, -1], [+1, -1, -1], [+1, +1, -1], [-1, +1, -1], [-1, -1, +1], [+1, -1, +1], [+1, +1, +1], [-1, +1, +1]])).all())
def test_deformed_liver_hexa(self): m = meshio.read( os.path.join(os.path.dirname(__file__), '..', 'meshes', 'deformed_liver_volume_hexahedrons.vtu')) mesh = Mesh(m.points) if type(m.cells) == dict: cells = m.cells['hexahedron'] else: cells = m.cells_dict['hexahedron'] domain = mesh.add_domain("hexa", Hexahedron(Caribou.Linear), cells) undeformed_markers = np.array([[265.83, -155.11, -1539.04], [260.11, -126.47, -1540.98], [274.25, -176.07, -1505.73], [285.61, -211.77, -1503.08], [260.49, -124.21, -1514.15], [264.56, -143.91, -1478.4], [231.42, -167.12, -1478.51], [204.36, -193.61, -1501.44], [210.5, -149.3, -1519.34], [232.38, -248.64, -1507.46], [271.51, -192.76, -1462.05], [294.9, -162.29, -1478.03], [312.83, -191.94, -1482.31], [302.98, -269.28, -1493.], [315.78, -226.09, -1504.54]]) deformed_markers = np.array( [[270.9119593, -157.71215294, -1555.40946454], [262.14820601, -128.06090875, -1552.47007965], [277.19378591, -177.43088076, -1516.55486109], [293.97624055, -213.41924186, -1522.43362963], [265.88433766, -126.62070365, -1524.0396069], [266.88009204, -147.60863833, -1490.24440459], [262.09361709, -173.36263398, -1499.35976378], [243.77807901, -199.20167085, -1529.01202647], [246.71909105, -156.88296646, -1546.59187345], [252.34989369, -255.47322977, -1531.41912502], [275.70481717, -198.33630816, -1478.29025749], [296.66730156, -168.05975732, -1487.89185992], [316.39825186, -196.90427925, -1493.97027093], [302.8963988, -274.06481598, -1510.41305086], [319.35443171, -231.06013115, -1521.27203137]]) interpolated_displacements = domain.embed( undeformed_markers).interpolate(m.point_data['u']) self.assertMatrixAlmostEqual(interpolated_displacements, (deformed_markers - undeformed_markers))
def test_quadratic_3D(self): t = Hexahedron(Caribou.Quadratic) self.assertEqual(t.number_of_boundary_elements(), 6) self.assertEqual(t.number_of_nodes(), 20) # Center self.assertMatrixAlmostEqual(t.center(), [0, 0, 0]) # Inverse transformation for gauss_node in t.gauss_nodes(): self.assertMatrixAlmostEqual( gauss_node.position, t.local_coordinates(t.world_coordinates(gauss_node.position))) for node in t.nodes(): self.assertMatrixAlmostEqual( node, t.world_coordinates(t.local_coordinates(node))) # Contains point self.assertTrue(t.contains_local(t.local_coordinates(t.center()))) # Integration numerical_solution = 0. for gauss_node in t.gauss_nodes(): x = gauss_node.position w = gauss_node.weight J = t.jacobian(x) detJ = np.linalg.det(J) numerical_solution += p2(t.world_coordinates(x)) * w * detJ analytic_solution = 50.666666666666664 self.assertAlmostEqual(numerical_solution, analytic_solution, delta=1e-10)