def test_volume_mesh(self): # Create a mesh out of two tetrahedra with a single, shared face # (1, 2, 3). # # +y # | # o v2 # | # v4 | v1 v0 # ───o────o─────o── +x # / # / # o v3 # / # +z t_left = mut.VolumeElement(v0=2, v1=1, v2=3, v3=4) t_right = mut.VolumeElement(v0=3, v1=1, v2=2, v3=0) self.assertEqual(t_left.vertex(0), 2) self.assertEqual(t_right.vertex(1), 1) v0 = (1, 0, 0) v1 = (0, 0, 0) v2 = (0, 1, 0) v3 = (0, 0, 1) v4 = (-1, 0, 0) self.assertListEqual(list(v0), [1, 0, 0]) dut = mut.VolumeMesh(elements=(t_left, t_right), vertices=(v0, v1, v2, v3, v4)) # Sanity check every accessor. self.assertIsInstance(dut.element(e=0), mut.VolumeElement) self.assertIsInstance(dut.vertex(v=0), np.ndarray) self.assertIsInstance(dut.num_elements(), int) self.assertIsInstance(dut.num_vertices(), int) # Sanity check some calculations self.assertAlmostEqual(dut.CalcTetrahedronVolume(e=1), 1 / 6.0, delta=1e-15) self.assertAlmostEqual(dut.CalcVolume(), 1 / 3.0, delta=1e-15) self.assertIsInstance( dut.CalcBarycentric(p_MQ=[-0.25, 0.25, 0.25], e=0), np.ndarray) self.assertTrue(dut.Equal(mesh=dut)) self.assertEqual(len(dut.tetrahedra()), 2) self.assertIsInstance(dut.tetrahedra()[0], mut.VolumeElement) self.assertEqual(len(dut.vertices()), 5) # Now check the VolumeElement bindings. tetrahedron0 = dut.element(e=0) self.assertEqual(tetrahedron0.vertex(i=0), 2)
def test_convert_volume_to_surface_mesh(self): # Use the volume mesh from `test_volume_mesh()`. t_left = mut.VolumeElement(v0=1, v1=2, v2=3, v3=4) t_right = mut.VolumeElement(v0=1, v1=3, v2=2, v3=0) v0 = (1, 0, 0) v1 = (0, 0, 0) v2 = (0, 1, 0) v3 = (0, 0, -1) v4 = (-1, 0, 0) volume_mesh = mut.VolumeMesh(elements=(t_left, t_right), vertices=(v0, v1, v2, v3, v4)) surface_mesh = mut.ConvertVolumeToSurfaceMesh(volume_mesh) self.assertIsInstance(surface_mesh, mut.TriangleSurfaceMesh)
def test_volume_mesh(self): # Create a mesh out of two tetrahedra with a single, shared face # (1, 2, 3). # # +y # | # o v2 # | # v4 | v1 v0 # ───o────o─────o── +x # / # / # o v3 # / # +z t_left = mut.VolumeElement(v0=2, v1=1, v2=3, v3=4) t_right = mut.VolumeElement(v0=3, v1=1, v2=2, v3=0) self.assertEqual(t_left.vertex(0), 2) self.assertEqual(t_right.vertex(1), 1) v0 = (1, 0, 0) v1 = (0, 0, 0) v2 = (0, 1, 0) v3 = (0, 0, 1) v4 = (-1, 0, 0) self.assertListEqual(list(v0), [1, 0, 0]) mesh = mut.VolumeMesh(elements=(t_left, t_right), vertices=(v0, v1, v2, v3, v4)) self.assertEqual(len(mesh.tetrahedra()), 2) self.assertIsInstance(mesh.tetrahedra()[0], mut.VolumeElement) self.assertEqual(len(mesh.vertices()), 5) self.assertAlmostEqual(mesh.CalcTetrahedronVolume(e=1), 1 / 6.0, delta=1e-15) self.assertAlmostEqual(mesh.CalcVolume(), 1 / 3.0, delta=1e-15)