def test_two_cart_grids(self): """ We set up the test case -----|--------- | | | | g1 | g2 | | | | -----|--------- with a linear pressure increase from left to right """ n = 2 xmax = 3 ymax = 1 split = 2 gb = self.generate_grids(n, xmax, ymax, split) tol = 1e-6 for g, d in gb: left = g.face_centers[0] < tol right = g.face_centers[0] > xmax - tol dir_bc = left + right bound = pp.BoundaryCondition(g, dir_bc, "dir") bc_val = np.zeros(g.num_faces) bc_val[left] = xmax bc_val[right] = 0 specified_parameters = {"bc": bound, "bc_values": bc_val} pp.initialize_default_data(g, d, "flow", specified_parameters) for e, d in gb.edges(): mg = d["mortar_grid"] d[pp.PARAMETERS] = pp.Parameters(mg, ["flow"], [{}]) pp.params.data.add_discretization_matrix_keyword(d, "flow") # assign discretization data_key = "flow" tpfa = pp.Tpfa(data_key) coupler = pp.FluxPressureContinuity(data_key, tpfa) assembler = test_utils.setup_flow_assembler(gb, tpfa, data_key, coupler=coupler) test_utils.solve_and_distribute_pressure(gb, assembler) # test pressure for g, d in gb: self.assertTrue( np.allclose(d[pp.STATE]["pressure"], xmax - g.cell_centers[0])) # test mortar solution for e, d_e in gb.edges(): mg = d_e["mortar_grid"] g2, g1 = gb.nodes_of_edge(e) master_to_m = mg.master_to_mortar_avg() slave_to_m = mg.slave_to_mortar_avg() master_area = master_to_m * g1.face_areas slave_area = slave_to_m * g2.face_areas self.assertTrue( np.allclose(d_e[pp.STATE]["mortar_flux"] / master_area, 1)) self.assertTrue( np.allclose(d_e[pp.STATE]["mortar_flux"] / slave_area, 1))
def test_uniform_flow_cart_2d_1d_simplex(self): # Unstructured simplex grid gb = setup_2d_1d(np.array([10, 10]), simplex_grid=True) key = "flow" tpfa = pp.Tpfa(key) assembler = test_utils.setup_flow_assembler(gb, tpfa, key) test_utils.solve_and_distribute_pressure(gb, assembler) self.assertTrue(check_pressures(gb))
def test_uniform_flow_cart_2d(self): # Structured Cartesian grid gb = setup_cart_2d(np.array([10, 10])) key = "flow" mpfa = pp.Mpfa(key) assembler = test_utils.setup_flow_assembler(gb, mpfa, key) test_utils.solve_and_distribute_pressure(gb, assembler) for g, d in gb: pressure = d[pp.STATE]["pressure"] pressure_analytic = g.cell_centers[1] p_diff = pressure - pressure_analytic self.assertTrue(np.max(np.abs(p_diff)) < 0.05)