def test_elliptic_data_given_values(self): """ test that the elliptic data initialize the correct data. """ p = np.random.rand(3, 10) g = simplex.TetrahedralGrid(p) # Set values bc_val = np.pi * np.ones(g.num_faces) dir_faces = g.tags["domain_boundary_faces"].nonzero()[0] bc_cond = bc.BoundaryCondition(g, dir_faces, ["dir"] * dir_faces.size) porosity = 1 / np.pi * np.ones(g.num_cells) apperture = 0.5 * np.ones(g.num_cells) kxx = 2 * np.ones(g.num_cells) kyy = 3 * np.ones(g.num_cells) K = tensor.SecondOrderTensor(g.dim, kxx, kyy) source = 42 * np.ones(g.num_cells) # Assign to parameter param = Parameters(g) param.set_bc_val("flow", bc_val) param.set_bc("flow", bc_cond) param.set_porosity(porosity) param.set_aperture(apperture) param.set_tensor("flow", K) param.set_source("flow", source) # Define EllipticData class class Data(EllipticDataAssigner): def __init__(self, g, data): EllipticDataAssigner.__init__(self, g, data) def bc(self): return bc_cond def bc_val(self): return bc_val def porosity(self): return porosity def aperture(self): return apperture def permeability(self): return K def source(self): return source elliptic_data = dict() Data(g, elliptic_data) elliptic_param = elliptic_data["param"] self.check_parameters(elliptic_param, param)
def test_elliptic_data_default_values(self): """ test that the elliptic data initialize the correct data. """ p = np.random.rand(3, 10) g = simplex.TetrahedralGrid(p) param = Parameters(g) elliptic_data = dict() EllipticDataAssigner(g, elliptic_data) elliptic_param = elliptic_data['param'] check_parameters(elliptic_param, param)
def create_3d_grids(pts, cells): tet_cells = cells["tetra"] g_3d = simplex.TetrahedralGrid(pts.transpose(), tet_cells.transpose()) # Create mapping to global numbering (will be a unit mapping, but is # crucial for consistency with lower dimensions) g_3d.global_point_ind = np.arange(pts.shape[0]) # Convert to list to be consistent with lower dimensions # This may also become useful in the future if we ever implement domain # decomposition approaches based on gmsh. g_3d = [g_3d] return g_3d
def test_conservation_of_momentum(self): pts = np.random.rand(3, 9) corners = [ [0, 0, 0, 0, 1, 1, 1, 1], [0, 0, 1, 1, 0, 0, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1], ] pts = np.hstack((corners, pts)) gt = simplex.TetrahedralGrid(pts) gc = structured.CartGrid([3, 3, 3], physdims=[1, 1, 1]) g_list = [gt, gc] [g.compute_geometry() for g in g_list] for g in g_list: g.compute_geometry() bot = np.ravel(np.argwhere(g.face_centers[1, :] < 1e-10)) left = np.ravel(np.argwhere(g.face_centers[0, :] < 1e-10)) dir_faces = np.hstack((left, bot)) bound = bc.BoundaryConditionVectorial(g, dir_faces.ravel("F"), ["dir"] * dir_faces.size) constit = setup_stiffness(g) # Python inverter is most efficient for small problems stress, bound_stress = mpsa.mpsa(g, constit, bound, inverter="python") div = fvutils.vector_divergence(g) a = div * stress bndr = g.get_all_boundary_faces() d_x = np.random.rand(bndr.size) d_y = np.random.rand(bndr.size) d_bound = np.zeros((g.dim, g.num_faces)) d_bound[0, bndr] = d_x d_bound[1, bndr] = d_y rhs = div * bound_stress * d_bound.ravel("F") d = np.linalg.solve(a.todense(), -rhs) traction = stress * d + bound_stress * d_bound.ravel("F") traction_2d = traction.reshape((g.dim, -1), order="F") for cell in range(g.num_cells): fid, _, sgn = sps.find(g.cell_faces[:, cell]) self.assertTrue( np.all(np.sum(traction_2d[:, fid] * sgn, axis=1) < 1e-10))