Exemplo n.º 1
0
def main(kf, description, multi_point, if_export=False):
    mesh_size = 0.045
    gb, domain = make_grid_bucket(mesh_size)
    # Assign parameters
    add_data(gb, domain, kf, mesh_size)

    # Choose discretization and define the solver
    if multi_point:
        solver = pp.MpfaMixedDim("flow")
    else:
        solver = pp.TpfaMixedDim("flow")

    # Discretize
    A, b = solver.matrix_rhs(gb)

    # Solve the linear system
    p = sps.linalg.spsolve(A, b)

    # Store the solution
    gb.add_node_props(["pressure"])
    solver.split(gb, "pressure", p)

    if if_export:
        save = pp.Exporter(gb, "fv", folder="fv_" + description)
        save.write_vtk(["pressure"])
Exemplo n.º 2
0
def solve_mpfa(gb, folder, return_only_matrix=False):

    # Choose and define the solvers and coupler
    solver_flow = pp.MpfaMixedDim("flow")
    A_flow, b_flow = solver_flow.matrix_rhs(gb)

    A = A_flow
    if return_only_matrix:
        return A, mortar_dof_size(A, gb, solver_flow)

    p = sps.linalg.spsolve(A, b_flow)
    solver_flow.split(gb, "pressure", p)

    save = Exporter(gb, "sol", folder=folder)
    save.write_vtk(["pressure"])
Exemplo n.º 3
0
    def test_uniform_flow_cart_2d(self):
        # Structured Cartesian grid
        gb = setup_cart_2d(np.array([10, 10]))

        # Python inverter is most efficient for small problems
        flux_discr = pp.MpfaMixedDim("flow")
        A, rhs = flux_discr.matrix_rhs(gb)
        p = np.linalg.solve(A.A, rhs)

        flux_discr.split(gb, "pressure", p)
        for g, d in gb:
            pressure = d["pressure"]
            pressure_analytic = g.cell_centers[1]
            p_diff = pressure - pressure_analytic
            self.assertTrue(np.max(np.abs(p_diff)) < 0.05)
Exemplo n.º 4
0
def solve_mpfa(gb, folder):

    # Choose and define the solvers and coupler
    logger.info('MPFA discretization')
    tic = time.time()
    solver_flow = pp.MpfaMixedDim("flow")
    A_flow, b_flow = solver_flow.matrix_rhs(gb)

    logger.info('Done. Elapsed time: ' + str(time.time() - tic))
    logger.info('Linear solver')
    tic = time.time()
    p = sps.linalg.spsolve(A_flow, b_flow)
    logger.info('Done. Elapsed time ' + str(time.time() - tic))

    solver_flow.split(gb, "pressure", p)
    pp.fvutils.compute_discharges(gb)

    export(gb, folder)
    sps_io.mmwrite(folder+"/matrix.mtx", A_flow)
Exemplo n.º 5
0
    def test_mpfa_fluxes_2d_1d_left_right_dir_neu(self):
        """
        Grid: 2 x 2 cells in matrix + 2 cells in the fracture from left to right.
        Dirichlet + inflow + no-flow, conductive fracture.
        Tests pressure solution and fluxes.
        """
        f = np.array([[0, 1], [.5, .5]])
        gb = pp.meshing.cart_grid([f], [2, 2], **{'physdims': [1, 1]})
        gb.compute_geometry()
        gb.assign_node_ordering()

        tol = 1e-3
        solver = pp.MpfaMixedDim(physics='flow')
        gb.add_node_props(['param'])
        a = 1e-2
        for g, d in gb:
            param = pp.Parameters(g)

            a_dim = np.power(a, gb.dim_max() - g.dim)
            aperture = np.ones(g.num_cells) * a_dim
            param.set_aperture(aperture)

            p = pp.SecondOrderTensor(
                3,
                np.ones(g.num_cells) * np.power(1e-3, g.dim < gb.dim_max()))
            param.set_tensor('flow', p)
            bound_faces = g.tags['domain_boundary_faces'].nonzero()[0]
            bound_face_centers = g.face_centers[:, bound_faces]

            right = bound_face_centers[0, :] > 1 - tol
            left = bound_face_centers[0, :] < tol

            labels = np.array(['neu'] * bound_faces.size)
            labels[right] = ['dir']

            bc_val = np.zeros(g.num_faces)
            bc_dir = bound_faces[right]
            bc_neu = bound_faces[left]
            bc_val[bc_dir] = g.face_centers[0, bc_dir]
            bc_val[bc_neu] = -g.face_areas[bc_neu] * a_dim

            param.set_bc('flow', pp.BoundaryCondition(g, bound_faces, labels))
            param.set_bc_val('flow', bc_val)

            d['param'] = param

        gb.add_edge_props('param')
        for e, d in gb.edges():
            g_h = gb.nodes_of_edge(e)[1]
            d['param'] = pp.Parameters(g_h)

        A, rhs = solver.matrix_rhs(gb)
        p = sps.linalg.spsolve(A, rhs)
        solver.solver.split(gb, "pressure", p)
        pp.fvutils.compute_discharges(gb)

        p_known = np.array([
            1.7574919, 1.25249747, 1.7574919, 1.25249747, 1.25250298,
            1.80993337
        ])

        # Known discharges
        d_0, d_1 = fluxes_2d_1d_left_right_dir_neu()

        rtol = 1e-6
        atol = rtol

        for _, d in gb:

            if d['node_number'] == 0:
                assert np.allclose(d['discharge'], d_0, rtol, atol)
            if d['node_number'] == 1:
                assert np.allclose(d['discharge'], d_1, rtol, atol)

        assert np.allclose(p, p_known, rtol, atol)