def test_mono_equals_multi(self): """ test that the mono_dimensional elliptic solver gives the same answer as the grid bucket elliptic """ g = CartGrid([10, 10]) g.compute_geometry() gb = meshing.cart_grid([], [10, 10]) param_g = Parameters(g) def bc_val(g): left = g.face_centers[0] < 1e-6 right = g.face_centers[0] > 10 - 1e-6 bc_val = np.zeros(g.num_faces) bc_val[left] = -1 bc_val[right] = 1 return bc_val def bc_labels(g): bound_faces = g.get_boundary_faces() bound_face_centers = g.face_centers[:, bound_faces] left = bound_face_centers[0] < 1e-6 right = bound_face_centers[0] > 10 - 1e-6 labels = np.array(['neu'] * bound_faces.size) labels[np.logical_or(right, left)] = 'dir' bc_labels = bc.BoundaryCondition(g, bound_faces, labels) return bc_labels param_g.set_bc_val('flow', bc_val(g)) param_g.set_bc('flow', bc_labels(g)) gb.add_node_props(['param']) for sub_g, d in gb: d['param'] = Parameters(sub_g) d['param'].set_bc_val('flow', bc_val(g)) d['param'].set_bc('flow', bc_labels(sub_g)) problem_mono = elliptic.EllipticModel(g, {'param': param_g}) problem_mult = elliptic.EllipticModel(gb) p_mono = problem_mono.solve() p_mult = problem_mult.solve() assert np.allclose(p_mono, p_mult)
def test_elliptic_uniform_flow_cart(self): gb = setup_2d_1d([10, 10]) problem = elliptic.EllipticModel(gb) p = problem.solve() problem.split('pressure') for g, d in gb: pressure = d['pressure'] p_analytic = g.cell_centers[1] p_diff = pressure - p_analytic assert np.max(np.abs(p_diff)) < 0.03
def test_elliptic_dirich_neumann_source_sink_cart(self): gb = setup_3d(np.array([4, 4, 4]), simplex_grid=False) problem = elliptic.EllipticModel(gb) p = problem.solve() problem.split('pressure') for g, d in gb: if g.dim == 3: p_ref = elliptic_dirich_neumann_source_sink_cart_ref_3d() assert np.allclose(d['pressure'], p_ref) if g.dim == 0: p_ref = [-10788.06883149] assert np.allclose(d['pressure'], p_ref) return gb
def test_elliptic_uniform_flow_simplex(self): """ Unstructured simplex grid. Note that the solution depends on the grid quality. Also sensitive to the way in which the tpfa half transmissibilities are computed. """ gb = setup_2d_1d(np.array([10, 10]), simplex_grid=True) problem = elliptic.EllipticModel(gb) p = problem.solve() problem.split('pressure') for g, d in gb: pressure = d['pressure'] p_analytic = g.cell_centers[1] p_diff = pressure - p_analytic assert np.max(np.abs(p_diff)) < 0.033
def solve_elliptic_problem(gb): for g, d in gb: if g.dim == 2: d['param'].set_source('flow', source(g, 0.0)) dir_bound = np.argwhere(g.has_face_tag(FaceTag.DOMAIN_BOUNDARY)) bc_cond = bc.BoundaryCondition(g, dir_bound, ['dir'] * dir_bound.size) d['param'].set_bc('flow', bc_cond) gb.add_edge_prop('param') for e, d in gb.edges_props(): g_h = gb.sorted_nodes_of_edge(e)[1] d['param'] = Parameters(g_h) flux = elliptic.EllipticModel(gb) p = flux.solve() flux.split('pressure') fvutils.compute_discharges(gb)
def solve_elliptic_problem(gb): for g, d in gb: if g.dim == 2: d['param'].set_source('flow', source(g, 0.0)) dir_bound = g.tags['domain_boundary_faces'].nonzero()[0] bc_cond = bc.BoundaryCondition(g, dir_bound, ['dir'] * dir_bound.size) d['param'].set_bc('flow', bc_cond) gb.add_edge_props('param') for e, d in gb.edges(): g_h = gb.nodes_of_edge(e)[1] d['param'] = Parameters(g_h) flux = elliptic.EllipticModel(gb) p = flux.solve() flux.split('pressure') fvutils.compute_discharges(gb)
def main(): tol = 1e-6 problem_kwargs = {} problem_kwargs['file_name'] = 'solution' problem_kwargs['folder_name'] = 'tpfa' h = 0.08 grid_kwargs = {} grid_kwargs['mesh_size'] = { 'mode': 'constant', 'value': h, 'bound_value': h, 'tol': tol } file_dfm = 'dfm.csv' gb, domain = importer.dfm_3d_from_csv(file_dfm, tol, **grid_kwargs) gb.compute_geometry() problem = elliptic.EllipticModel(gb, **problem_kwargs) # Assign parameters add_data(gb, domain, tol) problem.solve() problem.split() problem.pressure('pressure') problem.discharge('discharge') problem.save(['pressure', 'frac_num']) problem_kwargs['file_name'] = 'transport' for g, d in gb: d['problem'] = AdvectiveModelData(g, d, domain, tol) advective = AdvectiveModel(gb, **problem_kwargs) advective.solve() advective.save()
def main(): tol = 1e-6 problem_kwargs = {} problem_kwargs["file_name"] = "solution" problem_kwargs["folder_name"] = "tpfa" h = 0.08 grid_kwargs = {} grid_kwargs["mesh_size"] = { "mode": "constant", "value": h, "bound_value": h, "tol": tol, } file_dfm = "dfm.csv" gb, domain = importer.dfm_3d_from_csv(file_dfm, tol, **grid_kwargs) gb.compute_geometry() problem = elliptic.EllipticModel(gb, **problem_kwargs) # Assign parameters add_data(gb, domain, tol) problem.solve() problem.split() problem.pressure("pressure") problem.discharge("discharge") problem.save(["pressure", "frac_num"]) problem_kwargs["file_name"] = "transport" for g, d in gb: d["problem"] = AdvectiveModelData(g, d, domain, tol) advective = AdvectiveModel(gb, **problem_kwargs) advective.solve() advective.save()
for e, d in gb.edges_props(): mg = d["mortar_grid"] g_l = gb.sorted_nodes_of_edge(e)[0] aperture = gb.node_prop(g_l, "param").get_aperture() d["kn"] = data_problem["kf"] / (mg.low_to_mortar_int * aperture) # Create the problem and solve it. Export the pressure and projected velocity for visualization. if VEM: problem = elliptic.DualEllipticModel(gb) up = problem.solve() problem.split(gb) problem.pressure() problem.save("pressure") else: problem = elliptic.EllipticModel(gb) problem.solve() problem.split() problem.pressure("pressure") problem.save(["pressure", "frac_num", "low_zones"]) # problem.discharge('discharge') # problem.project_discharge('P0u') # problem.save(['pressure', 'P0u', 'frac_num', 'low_zones']) # for g in gb.grids_of_dimension(2): # # mx = g.nodes.max(axis=1) # mi = g.nodes.min(axis=1) # dx = mx - mi #