def setUp(self): K_1 = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self.mesh1 = Mesh('mesh/mpfad_pressure_test.h5m', dim=3) self.mesh1.set_boundary_conditions('Dirichlet', {101: 0.0}) self.mesh1.set_boundary_conditions('Neumann', {201: 0.0}) self.mesh1.set_material_prop('permeability', {1: K_1}) self.mpfad1 = MpfaD(self.mesh1)
def setUp(self): K_1 = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self.mesh = Mesh('mesh/mpfad.h5m', dim=3) self.mesh.set_boundary_conditions('Dirichlet', {101: 0.0}) self.mesh.set_material_prop('permeability', {1: K_1})
class PreMpfaDTest(unittest.TestCase): def setUp(self): K_1 = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self.mesh = Mesh('mesh/test_mesh_5_vols.h5m', dim=3) self.mesh.set_boundary_conditions('Dirichlet', {101: 0.0}) self.mesh.set_material_prop('permeability', {1: K_1}) def tearDown(self): del self.mesh def test_preprocessor_class_should_be_none(self): """Test class initiatilization.""" mesh = self.mesh self.assertIsNotNone(mesh)
class MpfaDTest(unittest.TestCase): def setUp(self): K_1 = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self.mesh = Mesh('mesh/mpfad.h5m', dim=3) self.mesh.set_boundary_conditions('Dirichlet', {101: 0.0}) self.mesh.set_material_prop('permeability', {1: K_1}) self.mpfad = MpfaD(self.mesh) def tearDown(self): self.mpfad = None def test_preprocessor_class_should_be_none(self): """Test class initiatilization.""" mpfad = self.mpfad self.assertIsNotNone(mpfad) def test_multiply_is_working(self): b_faces = self.mesh.b_faces tri_faces, tetra_faces = self.mesh.screen_faces_by_verts(b_faces) volumes = self.mesh.get_left_and_right_volumes(tri_faces, boundary=True) N_IJK, tan_JI, tan_JK = self.mesh.construct_face_vectors(tri_faces) perm = self.mesh.permeability[volumes][0][0] K_n_L = self.mpfad.multiply(N_IJK, perm, N_IJK) self.assertTrue(all(K_n_L == 1)) def test_cross_diffusion_term_for_boundary_elems(self): b_faces = self.mesh.b_faces tri_faces, tetra_faces = self.mesh.screen_faces_by_verts(b_faces) volumes = self.mesh.get_left_and_right_volumes(tetra_faces, boundary=True) N_IJK, tan_JI, tan_JK = self.mesh.construct_face_vectors(tetra_faces) perm = self.mesh.permeability[volumes][0][0] K_n_L = self.mpfad.multiply(N_IJK, perm, N_IJK) K_L_JI = self.mpfad.multiply(N_IJK, perm, tan_JI) K_L_JK = self.mpfad.multiply(N_IJK, perm, tan_JK) D_JK = self.get_cross_diffusion_term(tan_JK, LJ, face_area, h_L, K_n_L, K_L_JK, boundary=True) D_JI = self.get_cross_diffusion_term(tan_JI, LJ, face_area, h_L, K_n_L, K_L_JI, boundary=True)
class PressureSolverTest(unittest.TestCase): def setUp(self): K_1 = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self.mesh1 = Mesh('mesh/mpfad_pressure_test.h5m', dim=3) self.mesh1.set_boundary_conditions('Dirichlet', {101: 0.0}) self.mesh1.set_boundary_conditions('Neumann', {201: 0.0}) self.mesh1.set_material_prop('permeability', {1: K_1}) self.mpfad1 = MpfaD(self.mesh1) def tearDown(self): self.mpfad = None def test_assemble_problem_on_triangular_faces_only(self): b_verts = self.mesh1.b_verts
class MpfaDTest(unittest.TestCase): def setUp(self): K_1 = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self.mesh = Mesh('mesh/mpfad.h5m', dim=3) self.mesh.set_boundary_conditions('Dirichlet', {101: 0.0}) self.mesh.set_material_prop('permeability', {1: K_1}) self.mpfad = MpfaD(self.mesh) def tearDown(self): self.mpfad = None def test_preprocessor_class_should_be_none(self): """Test class initiatilization.""" mpfad = self.mpfad self.assertIsNotNone(mpfad) def test_multiply_is_working(self): b_faces = self.mesh.b_faces tri_faces, tetra_faces = self.mesh.screen_faces_by_verts(b_faces) volumes = self.mesh.get_left_and_right_volumes(tri_faces, boundary=True) N_IJK, tan_JI, tan_JK = self.mesh.construct_face_vectors(tri_faces) perm = self.mesh.permeability[volumes][0][0] K_n_L = self.mpfad.multiply(N_IJK, perm, N_IJK) self.assertTrue(all(K_n_L == 1)) def test_cross_diffusion_term_for_boundary_quad_elems(self): b_faces = self.mesh.b_faces tri_faces, tetra_faces = self.mesh.screen_faces_by_verts(b_faces) is_boundary = True volumes = self.mesh.get_left_and_right_volumes(tetra_faces, boundary=is_boundary) N_IJK, tan_JI, tan_JK, tan_J2I, tan_J2K = \ self.mesh.construct_face_vectors(tetra_faces) face_area = self.mesh.get_area(tetra_faces) LJ, h_L = self.mesh.get_additional_vectors_and_height( tetra_faces, boundary=is_boundary) perm = self.mesh.permeability[volumes][0][0] K_L_n = self.mpfad.multiply(N_IJK, perm, N_IJK) K_L_JI = self.mpfad.multiply(N_IJK, perm, tan_JI) K_L_JK = self.mpfad.multiply(N_IJK, perm, tan_JK) K_L_J2I = self.mpfad.multiply(N_IJK, perm, tan_J2I) K_L_J2K = self.mpfad.multiply(N_IJK, perm, tan_J2K) D_JK = self.mpfad.d_flux_term(tan_JK, LJ, face_area / 2, h_L, K_L_n, K_L_JK, boundary=is_boundary) D_JI = self.mpfad.d_flux_term(tan_JI, LJ, face_area / 2, h_L, K_L_n, K_L_JI, boundary=is_boundary) D_J2K = self.mpfad.d_flux_term(tan_J2K, LJ, face_area / 2, h_L, K_L_n, K_L_J2K, boundary=is_boundary) D_J2I = self.mpfad.d_flux_term(tan_J2I, LJ, face_area / 2, h_L, K_L_n, K_L_J2I, boundary=is_boundary) K_eq = self.mpfad.n_flux_term(K_L_n, h_L, face_area, boundary=is_boundary) self.assertListEqual(list(D_JI), list(D_J2K)) self.assertListEqual(list(D_JK), list(D_J2I)) def test_cross_diffusion_term_for_boundary_tri_elems(self): b_faces = self.mesh.b_faces tri_faces, tetra_faces = self.mesh.screen_faces_by_verts(b_faces) is_boundary = True volumes = self.mesh.get_left_and_right_volumes(tri_faces, boundary=is_boundary) N_IJK, tan_JI, tan_JK = self.mesh.construct_face_vectors(tri_faces) face_area = self.mesh.get_area(tri_faces) LJ, h_L = self.mesh.get_additional_vectors_and_height( tri_faces, boundary=is_boundary) perm = self.mesh.permeability[volumes][0][0] K_L_n = self.mpfad.multiply(N_IJK, perm, N_IJK) K_L_JI = self.mpfad.multiply(N_IJK, perm, tan_JI) K_L_JK = self.mpfad.multiply(N_IJK, perm, tan_JK) D_JK = self.mpfad.d_flux_term(tan_JK, LJ, face_area, h_L, K_L_n, K_L_JK, boundary=is_boundary) D_JI = self.mpfad.d_flux_term(tan_JI, LJ, face_area, h_L, K_L_n, K_L_JI, boundary=is_boundary) K_eq = self.mpfad.n_flux_term(K_L_n, h_L, face_area, boundary=is_boundary) self.assertIsNotNone([D_JK, D_JI, K_eq]) def test_cross_diffusion_term_for_itnern_tri_elems(self): in_faces = self.mesh.in_faces tri_faces, tetra_faces = self.mesh.screen_faces_by_verts(in_faces) left_volumes, right_volumes = self.mesh.get_left_and_right_volumes( tetra_faces) N_IJK, tan_JI, tan_JK, tan_J2I, tan_J2K = \ self.mesh.construct_face_vectors(tetra_faces) face_area = self.mesh.get_area(tetra_faces) LR, h_L, h_R = self.mesh.get_additional_vectors_and_height(tetra_faces) left_perm = self.mesh.permeability[left_volumes][0][0] right_perm = self.mesh.permeability[right_volumes][0][0] K_L_n = self.mpfad.multiply(N_IJK, left_perm, N_IJK) K_L_JI = self.mpfad.multiply(N_IJK, left_perm, tan_JI) K_L_JK = self.mpfad.multiply(N_IJK, left_perm, tan_JK) K_L_J2I = self.mpfad.multiply(N_IJK, left_perm, tan_J2I) K_L_J2K = self.mpfad.multiply(N_IJK, left_perm, tan_J2K) K_R_n = self.mpfad.multiply(N_IJK, right_perm, N_IJK) K_R_JI = self.mpfad.multiply(N_IJK, right_perm, tan_JI) K_R_JK = self.mpfad.multiply(N_IJK, right_perm, tan_JK) K_R_J2I = self.mpfad.multiply(N_IJK, right_perm, tan_J2I) K_R_J2K = self.mpfad.multiply(N_IJK, right_perm, tan_J2K) D_JK = self.mpfad.d_flux_term(tan_JK, LR, face_area / 2, h_L, K_L_n, K_L_JK, h_R, K_R_JK, K_R_n) D_JI = self.mpfad.d_flux_term(tan_JI, LR, face_area / 2, h_L, K_L_n, K_L_JI, h_R, K_R_JI, K_R_n) D_J2K = self.mpfad.d_flux_term(tan_J2K, LR, face_area / 2, h_L, K_L_n, K_L_J2K, h_R, K_R_J2K, K_R_n) D_J2I = self.mpfad.d_flux_term(tan_J2I, LR, face_area / 2, h_L, K_L_n, K_L_J2I, h_R, K_R_J2I, K_R_n) K_eq = self.mpfad.n_flux_term(K_L_n, h_L, face_area, K_R_n, h_R) self.assertListEqual(list(D_JI), list(D_J2K)) self.assertListEqual(list(D_JK), list(D_J2I))
class PreMpfaDTest(unittest.TestCase): def setUp(self): K_1 = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] self.mesh = Mesh('mesh/mpfad.h5m', dim=3) self.mesh.set_boundary_conditions('Dirichlet', {101: 0.0}) self.mesh.set_material_prop('permeability', {1: K_1}) def tearDown(self): self.mesh = None def test_preprocessor_class_should_be_none(self): """Test class initiatilization.""" mesh = self.mesh self.assertIsNotNone(mesh) def test_get_all_volumes(self): """Test class get all volumes.""" volumes = self.mesh.all_volumes self.assertEqual(len(volumes), 9) def test_get_all_internal_faces(self): """Test class get all internal faces.""" in_faces = self.mesh.in_faces self.assertEqual(len(in_faces), 12) def test_get_all_boundary_faces(self): """Test class get all boundary faces.""" b_faces = self.mesh.b_faces self.assertEqual(len(b_faces), 16) def test_get_all_internal_verts(self): """Test class get all internal verts.""" in_verts = self.mesh.in_verts self.assertEqual(len(in_verts), 0) def test_get_all_boundary_verts(self): """Test class get all boundary verts.""" b_verts = self.mesh.b_verts self.assertEqual(len(b_verts), 13) def test_screening_faces_gets_only_quadrilateral_intern_faces(self): """Test class to get only quadrilateral faces.""" in_faces = self.mesh.in_faces _, in_quad_faces = self.mesh.screen_faces_by_verts(in_faces) self.assertEqual(len(in_quad_faces), 1) def test_screening_faces_gets_only_triangular_intern_faces(self): """Test class to get only quadrilateral faces.""" in_faces = self.mesh.in_faces tri_faces, _ = self.mesh.screen_faces_by_verts(in_faces) self.assertEqual(len(tri_faces), 11) def test_screening_faces_gets_only_quadrilateral_boundary_faces(self): """Test class to get only quadrilateral faces.""" in_faces = self.mesh.b_faces _, in_quad_faces = self.mesh.screen_faces_by_verts(in_faces) self.assertEqual(len(in_quad_faces), 6) def test_screening_faces_gets_only_triangular_boundary_faces(self): """Test class to get only quadrilateral faces.""" in_faces = self.mesh.b_faces tri_faces, _ = self.mesh.screen_faces_by_verts(in_faces) self.assertEqual(len(tri_faces), 10) def test_if_permeability_tensor_is_assigned(self): """Test if permeability tensor is being assigned for all volumes.""" all_volumes = self.mesh.all_volumes K_1 = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] for volume in all_volumes: perm = self.mesh.M.permeability[[volume]][0] self.assertListEqual(list(perm), K_1) def test_get_dirichlet_faces(self): """Test if Dirichlet BC is implemented.""" d_faces = self.mesh.M.faces.flag[101] dirichlet_faces_pressure = self.mesh.M.dirichlet_faces for face in d_faces: b_pressure = dirichlet_faces_pressure[[face]] self.assertEqual(b_pressure, 0.) def test_position_left_and_right_volumes_for_triangular_intern_faces(self): """Test if all volumes are properly oriented with the normal.""" in_faces = self.mesh.in_faces tri_faces = self.mesh.screen_faces_by_verts(in_faces)[0] (left_volumes, right_volumes) = self.mesh.get_left_and_right_volumes(tri_faces) N_IJK = self.mesh.construct_face_vectors(tri_faces)[0] vector_left_to_right = (self.mesh.M.volumes.center[left_volumes] - self.mesh.M.volumes.center[right_volumes]) is_positive = np.sum(vector_left_to_right * N_IJK, axis=1) self.assertFalse(list(np.flatnonzero(is_positive < 0))) def test_position_left_and_right_volumes_for_quad_intern_faces(self): """Test if all volumes are properly oriented with the normal.""" in_faces = self.mesh.in_faces quad_faces = self.mesh.screen_faces_by_verts(in_faces)[1] (left_volumes, right_volumes) = self.mesh.get_left_and_right_volumes(quad_faces) N_IJK = self.mesh.construct_face_vectors(quad_faces)[0] vector_left_to_right = (self.mesh.M.volumes.center[left_volumes] - self.mesh.M.volumes.center[right_volumes]) is_positive = np.sum(vector_left_to_right * N_IJK, axis=1) self.assertFalse(list(np.flatnonzero(is_positive < 0))) def test_get_normal_face_area_vector_points_outward(self): quad_faces = self.mesh.screen_faces_by_verts(self.mesh.b_faces)[1] N_IJK = self.mesh.construct_face_vectors(quad_faces, boundary=True)[0] adj_vol = self.mesh.M.faces.bridge_adjacencies(quad_faces, 2, 3) i = self.mesh.get_position_IJK_verts(quad_faces)[0] vector_left_to_right = (self.mesh.M.nodes.coords[i] - self.mesh.M.volumes.center[adj_vol]) is_positive = np.sum(vector_left_to_right * N_IJK, axis=1) self.assertFalse(list(np.flatnonzero(is_positive < 0))) def test_calculate_area_vector(self): b_faces = self.mesh.b_faces tri_faces, quad_faces = self.mesh.screen_faces_by_verts(b_faces) face_area_quad = self.mesh.get_area(quad_faces) face_area_tri = self.mesh.get_area(tri_faces) self.assertEqual(face_area_tri[0], .25) self.assertEqual(face_area_quad[2], 1.) def test_calculate_additional_geometric_information(self): in_faces = self.mesh.in_faces quad_faces = self.mesh.screen_faces_by_verts(in_faces)[1] LR, h_L, h_R = self.mesh.get_additional_vectors_and_height(quad_faces) self.assertEqual(LR[0][0], h_L + h_R) def test_calculate_additional_geometric_information_boundary(self): b_faces = self.mesh.b_faces quad_faces = self.mesh.screen_faces_by_verts(b_faces)[1] LJ, h_L = self.mesh.get_additional_vectors_and_height(quad_faces, boundary=True) # print(LJ, h_L) def test_calculate_volumes(self): all_vol_volumes = self.mesh.get_volume(self.mesh.all_volumes) self.assertEqual(sum(all_vol_volumes), 1.)