Ejemplo n.º 1
0
    def atest_mpfa_coupling_3d_2d_1d_0d_dir(self):
        f1 = np.array([[0, 1, 1, 0], [0, 0, 1, 1], [.5, .5, .5, .5]])
        f2 = np.array([[.5, .5, .5, .5], [0, 1, 1, 0], [0, 0, 1, 1]])
        f3 = np.array([[0, 1, 1, 0], [.5, .5, .5, .5], [0, 0, 1, 1]])

        gb = meshing.cart_grid([f1, f2, f3], [2, 2, 2],
                               **{"physdims": [1, 1, 1]})
        gb.compute_geometry()
        gb.assign_node_ordering()
        # Remove flag for dual
        cell_centers1 = np.array([[0.25, 0.75, 0.25, 0.75],
                                  [0.25, 0.25, 0.75, 0.75],
                                  [0.5, 0.5, 0.5, 0.5]])
        cell_centers2 = np.array([[0.5, 0.5, 0.5, 0.5],
                                  [0.25, 0.25, 0.75, 0.75],
                                  [0.75, 0.25, 0.75, 0.25]])
        cell_centers3 = np.array([[0.25, 0.75, 0.25,
                                   0.75], [0.5, 0.5, 0.5, 0.5],
                                  [0.25, 0.25, 0.75, 0.75]])
        cell_centers4 = np.array([[0.5], [0.25], [0.5]])
        cell_centers5 = np.array([[0.5], [0.75], [0.5]])
        cell_centers6 = np.array([[0.75], [0.5], [0.5]])
        cell_centers7 = np.array([[0.25], [0.5], [0.5]])
        cell_centers8 = np.array([[0.5], [0.5], [0.25]])
        cell_centers9 = np.array([[0.5], [0.5], [0.75]])

        for g, d in gb:
            if np.allclose(g.cell_centers[:, 0], cell_centers1[:, 0]):
                d["node_number"] = 1
            elif np.allclose(g.cell_centers[:, 0], cell_centers2[:, 0]):
                d["node_number"] = 2
            elif np.allclose(g.cell_centers[:, 0], cell_centers3[:, 0]):
                d["node_number"] = 3
            elif np.allclose(g.cell_centers[:, 0], cell_centers4[:, 0]):
                d["node_number"] = 4
            elif np.allclose(g.cell_centers[:, 0], cell_centers5[:, 0]):
                d["node_number"] = 5
            elif np.allclose(g.cell_centers[:, 0], cell_centers6[:, 0]):
                d["node_number"] = 6
            elif np.allclose(g.cell_centers[:, 0], cell_centers7[:, 0]):
                d["node_number"] = 7
            elif np.allclose(g.cell_centers[:, 0], cell_centers8[:, 0]):
                d["node_number"] = 8
            elif np.allclose(g.cell_centers[:, 0], cell_centers9[:, 0]):
                d["node_number"] = 9
            else:
                pass

        tol = 1e-3
        solver = mpfa.Mpfa()
        gb.add_node_props(["param"])

        a = 1e-2
        for g, d in gb:
            param = Parameters(g)

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

            p = tensor.SecondOrderTensor(
                3,
                np.ones(g.num_cells) * np.power(1e3, g.dim < gb.dim_max()))
            param.set_tensor("flow", p)
            bound_faces = g.tags["domain_boundary_faces"].nonzero()[0]
            if bound_faces.size != 0:
                bound_face_centers = g.face_centers[:, bound_faces]

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

                labels = np.array(["neu"] * bound_faces.size)
                labels[np.logical_or(left, right)] = ["dir"]

                bc_val = np.zeros(g.num_faces)
                bc_dir = bound_faces[np.logical_or(left, right)]
                bc_val[bc_dir] = g.face_centers[0, bc_dir]

                param.set_bc(solver,
                             bc.BoundaryCondition(g, bound_faces, labels))
                param.set_bc_val(solver, bc_val)
            else:
                param.set_bc("flow",
                             bc.BoundaryCondition(g, np.empty(0), np.empty(0)))
            d["param"] = param

        coupling_conditions = tpfa.TpfaCoupling(solver)
        solver_coupler = coupler.Coupler(solver, coupling_conditions)
        A, rhs = solver_coupler.matrix_rhs(gb)

        A_known, rhs_known, p_known = (
            matrix_rhs_pressure_for_test_mpfa_coupling_3d_2d_1d_0d())

        p = sps.linalg.spsolve(A, rhs)

        rtol = 1e-6
        atol = rtol

        self.assertTrue(np.allclose(A.todense(), A_known, rtol, atol))
        self.assertTrue(np.allclose(rhs, rhs_known, rtol, atol))
        self.assertTrue(np.allclose(p, p_known, rtol, atol))
Ejemplo n.º 2
0
    def atest_mpfa_coupling_2d_1d_bottom_top_dir_neu(self):
        """
        Grid: 1 x 2 cells in matrix + 1 cell in the fracture from left to right.
        Dirichlet + inflow + no-flow, blocking fracture.
        """
        f = np.array([[0, 1], [.5, .5]])
        gb = meshing.cart_grid([f], [1, 2], **{"physdims": [1, 1]})
        gb.compute_geometry()
        gb.assign_node_ordering()

        tol = 1e-3
        solver = mpfa.Mpfa(physics="flow")
        gb.add_node_props(["param"])
        a = 1e-2
        for g, d in gb:
            param = 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 = tensor.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]

            top = bound_face_centers[1, :] > 1 - tol
            bottom = bound_face_centers[1, :] < tol

            labels = np.array(["neu"] * bound_faces.size)
            labels[bottom] = ["dir"]

            bc_val = np.zeros(g.num_faces)
            bc_dir = bound_faces[bottom]
            bc_neu = bound_faces[top]
            bc_val[bc_dir] = g.face_centers[1, bc_dir]
            bc_val[bc_neu] = -g.face_areas[bc_neu] * a_dim

            param.set_bc(solver, bc.BoundaryCondition(g, bound_faces, labels))
            param.set_bc_val(solver, bc_val)

            d["param"] = param

        coupling_conditions = tpfa.TpfaCoupling(solver)
        solver_coupler = coupler.Coupler(solver, coupling_conditions)
        A, rhs = solver_coupler.matrix_rhs(gb)

        A_known = np.array([
            [4.19047619, 0., -0.19047619],
            [0., 0.19047619, -0.19047619],
            [-0.19047619, -0.19047619, 0.38095238],
        ])

        rhs_known = np.array([0, 1, 0])

        rtol = 1e-6
        atol = rtol

        self.assertTrue(np.allclose(A.todense(), A_known, rtol, atol))
        self.assertTrue(np.allclose(rhs, rhs_known, rtol, atol))
Ejemplo n.º 3
0
    def atest_mpfa_coupling_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 as well as matrix and rhs.
        """
        f = np.array([[0, 1], [.5, .5]])
        gb = meshing.cart_grid([f], [2, 2], **{"physdims": [1, 1]})
        gb.compute_geometry()
        gb.assign_node_ordering()

        tol = 1e-3
        solver = mpfa.Mpfa(physics="flow")
        gb.add_node_props(["param"])
        a = 1e-2
        for g, d in gb:
            param = 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 = tensor.SecondOrderTensor(
                3,
                np.ones(g.num_cells) * np.power(1e3, 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(solver, bc.BoundaryCondition(g, bound_faces, labels))
            param.set_bc_val(solver, bc_val)

            d["param"] = param

        coupling_conditions = tpfa.TpfaCoupling(solver)
        solver_coupler = coupler.Coupler(solver, coupling_conditions)
        A, rhs = solver_coupler.matrix_rhs(gb)

        A_known = np.array([
            [2.99996, -1., 0., 0., 0., -1.99996],
            [-1., 4.99996, 0., 0., -1.99996, 0.],
            [0., 0., 2.99996, -1., 0., -1.99996],
            [0., 0., -1., 4.99996, -1.99996, 0.],
            [0., -1.99996, 0., -1.99996, 63.99992, -20.],
            [-1.99996, 0., -1.99996, 0., -20., 23.99992],
        ])

        rhs_known = np.array([
            5.00000000e-01,
            2.00000000e+00,
            5.00000000e-01,
            2.00000000e+00,
            4.00000000e+01,
            1.00000000e-02,
        ])
        p_known = np.array([
            1.21984244, 1.05198918, 1.21984244, 1.05198918, 1.02005108,
            1.05376576
        ])

        p = sps.linalg.spsolve(A, rhs)

        rtol = 1e-6
        atol = rtol

        self.assertTrue(np.allclose(A.todense(), A_known, rtol, atol))
        self.assertTrue(np.allclose(rhs, rhs_known, rtol, atol))
        self.assertTrue(np.allclose(p, p_known, rtol, atol))
Ejemplo n.º 4
0
    def atest_mpfa_coupling_2d_1d_left_right_cross_dir_neu(self):
        f1 = np.array([[0, 2], [.5, .5]])
        f2 = np.array([[.5, .5], [0, 2]])

        gb = meshing.cart_grid([f1, f2], [2, 2], **{"physdims": [1, 1]})
        gb.compute_geometry()
        gb.assign_node_ordering()

        # Enforce node orderning because of Python 3.5 and 2.7.
        # Don't do it in general.
        cell_centers_1 = np.array([
            [7.50000000e-01, 2.500000000e-01],
            [5.00000000e-01, 5.00000000e-01],
            [-5.55111512e-17, 5.55111512e-17],
        ])
        cell_centers_2 = np.array([
            [5.00000000e-01, 5.00000000e-01],
            [7.50000000e-01, 2.500000000e-01],
            [-5.55111512e-17, 5.55111512e-17],
        ])

        for g, d in gb:
            if g.dim == 1:
                if np.allclose(g.cell_centers, cell_centers_1):
                    d["node_number"] = 1
                elif np.allclose(g.cell_centers, cell_centers_2):
                    d["node_number"] = 2
                else:
                    raise ValueError("Grid not found")

        tol = 1e-3
        solver = mpfa.Mpfa()
        gb.add_node_props(["param"])
        a = 1e-2
        for g, d in gb:
            param = Parameters(g)

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

            kxx = np.ones(g.num_cells) * np.power(1e3, g.dim < gb.dim_max())

            p = tensor.SecondOrderTensor(3, kxx, kyy=kxx, kzz=kxx)

            param.set_tensor("flow", p)
            bound_faces = g.tags["domain_boundary_faces"].nonzero()[0]
            if bound_faces.size != 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(solver,
                             bc.BoundaryCondition(g, bound_faces, labels))
                param.set_bc_val(solver, bc_val)
            else:
                param.set_bc("flow",
                             bc.BoundaryCondition(g, np.empty(0), np.empty(0)))
            d["param"] = param

        coupling_conditions = tpfa.TpfaCoupling(solver)
        solver_coupler = coupler.Coupler(solver, coupling_conditions)
        A, rhs = solver_coupler.matrix_rhs(gb)

        A_known, rhs_known = matrix_rhs_for_2d_1d_cross()

        rtol = 1e-6
        atol = rtol

        self.assertTrue(np.allclose(A.todense(), A_known, rtol, atol))
        self.assertTrue(np.allclose(rhs, rhs_known, rtol, atol))
Ejemplo n.º 5
0
 def permeability(self):
     kxx = np.ones(self.grid().num_cells) * \
         np.power(1e4, self.grid().dim < 2)
     return tensor.SecondOrderTensor(3, kxx)
Ejemplo n.º 6
0
    def atest_mpfa_coupling_2d_1d_left_right_dir(self):
        """
        Grid: 2 x 2 cells in matrix + 2 cells in the fracture from left to right.
        Dirichlet + no-flow, conductive fracture.
        """
        f = np.array([[0, 1], [.5, .5]])
        gb = meshing.cart_grid([f], [2, 2], **{"physdims": [1, 1]})
        gb.compute_geometry()
        gb.assign_node_ordering()

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

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

            p = tensor.SecondOrderTensor(
                3,
                np.ones(g.num_cells) * np.power(1e3, g.dim < gb.dim_max()))
            param.set_tensor("flow", p)
            bound_faces = g.tags["domain_boundary_faces"].nonzero()[0]
            if bound_faces.size != 0:
                bound_face_centers = g.face_centers[:, bound_faces]

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

                labels = np.array(["neu"] * bound_faces.size)
                labels[np.logical_or(left, right)] = ["dir"]

                bc_val = np.zeros(g.num_faces)
                bc_dir = bound_faces[np.logical_or(left, right)]
                bc_val[bc_dir] = g.face_centers[0, bc_dir]

                param.set_bc(solver,
                             bc.BoundaryCondition(g, bound_faces, labels))
                param.set_bc_val(solver, bc_val)
            else:
                param.set_bc("flow",
                             bc.BoundaryCondition(g, np.empty(0), np.empty(0)))
            d["param"] = param

        coupling_conditions = tpfa.TpfaCoupling(solver)
        solver_coupler = coupler.Coupler(solver, coupling_conditions)
        A, rhs = solver_coupler.matrix_rhs(gb)

        A_known = np.array([
            [4.99996, -1., 0., 0., 0., -1.99996],
            [-1., 4.99996, 0., 0., -1.99996, 0.],
            [0., 0., 4.99996, -1., 0., -1.99996],
            [0., 0., -1., 4.99996, -1.99996, 0.],
            [0., -1.99996, 0., -1.99996, 63.99992, -20.],
            [-1.99996, 0., -1.99996, 0., -20., 63.99992],
        ])

        rhs_known = np.array([0., 2., 0., 2., 40., 0.])

        rtol = 1e-6
        atol = rtol

        self.assertTrue(np.allclose(A.todense(), A_known, rtol, atol))
        self.assertTrue(np.allclose(rhs, rhs_known, rtol, atol))
Ejemplo n.º 7
0
    def atest_tpfa_coupling_2d_1d_bottom_top_dir(self):
        """
        Grid: 2 x 2 matrix + 2 x 1 fracture from left to right.
        Dirichlet + no-flow, blocking fracture.
        """

        f = np.array([[0, 1], [.5, .5]])
        gb = meshing.cart_grid([f], [1, 2], **{"physdims": [1, 1]})
        gb.compute_geometry()
        gb.assign_node_ordering()

        tol = 1e-3
        solver = tpfa.Tpfa(physics="flow")
        # solver = tpfa.Tpfa(physics='flow')
        gb.add_node_props(["param"])
        gb.add_edge_props(["kn"])
        a = 1e-2
        for g, d in gb:
            param = Parameters(g)

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

            p = tensor.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]

            top = bound_face_centers[1, :] > 1 - tol
            bottom = bound_face_centers[1, :] < tol

            labels = np.array(["neu"] * bound_faces.size)
            labels[np.logical_or(top, bottom)] = ["dir"]

            bc_val = np.zeros(g.num_faces)
            bc_dir = bound_faces[np.logical_or(top, bottom)]
            bc_val[bc_dir] = g.face_centers[1, bc_dir]

            param.set_bc(solver, bc.BoundaryCondition(g, bound_faces, labels))
            param.set_bc_val(solver, bc_val)

            d["param"] = param

        for e, d in gb.edges():
            d["kn"] = 1e-5

        coupling_conditions = tpfa.TpfaCoupling(solver)
        solver_coupler = coupler.Coupler(solver, coupling_conditions)
        A, rhs = solver_coupler.matrix_rhs(gb)

        A_known = np.array([
            [4., 0., -0, 0., 1],
            [0., 4., -0., 1, 0],
            [0, 0, 0, -1, -1],
            [0, 1, -1, -5.000025e4, 0],
            [1, 0, -1, 0, -5.000025e4],
        ])

        rhs_known = np.array([0., 4., 0., 0, 0])

        rtol = 1e-6
        atol = rtol

        self.assertTrue(np.allclose(A.todense(), A_known, rtol, atol))
        self.assertTrue(np.allclose(rhs, rhs_known, rtol, atol))
Ejemplo n.º 8
0
 def permeability(self):
     kxx = np.ones(self.grid().num_cells)
     return tensor.SecondOrderTensor(self.grid().dim, kxx)
Ejemplo n.º 9
0
def darcy_dualVEM_coupling_example2(**kwargs):
    #######################
    # Simple 2d Darcy problem with known exact solution
    #######################
    np.set_printoptions(linewidth=999999, threshold=np.nan, precision=16)

    f_1 = np.array([[-1, 1, 1, -1], [0, 0, 0, 0], [-1, -1, 1, 1]])
    f_2 = np.array([[0, 0, 0, 0], [-1, 1, 1, -1], [-1.5, -1.5, .8, .8]])
    domain = {
        'xmin': -2,
        'xmax': 2,
        'ymin': -2,
        'ymax': 2,
        'zmin': -2,
        'zmax': 2
    }

    kwargs = {
        'mesh_size_frac': .25,
        'mesh_size_bound': 10,
        'mesh_size_min': .02,
        'gmsh_path': '~/gmsh/bin/gmsh'
    }

    gb = meshing.simplex_grid([f_1, f_2], domain, **kwargs)
    gb.remove_nodes(lambda g: g.dim == gb.dim_max())

    # It's not really working now the coarsening part with the gb
    #    for g, _ in gb:
    #        if g.dim != 1:
    #            part = create_partition(tpfa_matrix(g))
    #            gb.change_nodes({g: generate_coarse_grid(g, part)})
    #
    #    gb.compute_geometry(is_starshaped=True)

    print([g.num_faces for g, _ in gb])
    gb.assign_node_ordering()

    if kwargs['visualize']:
        plot_grid(gb, info="f", alpha=0)

    gb.add_node_props(['perm', 'source', 'bc', 'bc_val'])
    for g, d in gb:
        kxx = np.ones(g.num_cells)
        d['perm'] = tensor.SecondOrderTensor(g.dim, kxx)
        d['source'] = np.zeros(g.num_cells)

        b_faces = g.tags['domain_boundary_faces'].nonzero()[0]
        b_faces_dir = b_faces[np.bitwise_or(g.face_centers[1, b_faces] == -1,
                                            g.face_centers[0, b_faces] == -1)]

        b_faces_dir_cond = g.face_centers[0, b_faces_dir]

        b_faces_neu = np.setdiff1d(b_faces, b_faces_dir, assume_unique=True)
        b_faces = np.hstack((b_faces_dir, b_faces_neu))
        b_faces_label = np.hstack(
            (['dir'] * b_faces_dir.size, ['neu'] * b_faces_neu.size))
        d['bc'] = bc.BoundaryCondition(g, b_faces, b_faces_label)
        d['bc_val'] = {
            'dir': b_faces_dir_cond,
            'neu': np.zeros(b_faces_neu.size)
        }

    gb.add_edge_prop('kn')
    for e, d in gb.edges_props():
        g_l = gb.sorted_nodes_of_edge(e)[0]
        c = g_l.cell_centers[2, :] > -0.5
        d['kn'] = (np.ones(g_l.num_cells) + c.astype('float') * (-1 + 1e-2))

    solver = dual.DualVEM()
    coupling_conditions = dual_coupling.DualCoupling(solver)
    solver_coupler = coupler.Coupler(solver, coupling_conditions)
    A, b = solver_coupler.matrix_rhs(gb)

    up = sps.linalg.spsolve(A, b)
    solver_coupler.split(gb, "up", up)

    gb.add_node_props(["u", 'pressure', "P0u"])
    for g, d in gb:
        d["u"] = solver.extractU(g, d["up"])
        d['pressure'] = solver.extractP(g, d["up"])
        d["P0u"] = solver.projectU(g, d["u"], d)

    if kwargs['visualize']:
        plot_grid(gb, 'pressure', "P0u")

    export_vtk(gb, "grid", ['pressure', "P0u"])
Ejemplo n.º 10
0
    def atest_1d_elimination_3d_2d_1d(self):
        """
        3d case with a single 1d grid.
        """
        f1 = np.array([[0, 1, 1, 0], [0, 0, 1, 1], [.5, .5, .5, .5]])
        f2 = np.array([[.5, .5, .5, .5], [0, 1, 1, 0], [0, 0, 1, 1]])

        gb = meshing.cart_grid([f1, f2], [2, 2, 2], **{"physdims": [1, 1, 1]})
        gb.compute_geometry()
        gb.assign_node_ordering()

        tol = 1e-3
        solver = tpfa.Tpfa()
        gb.add_node_props(["param"])

        a = 1e-2
        for g, d in gb:
            param = Parameters(g)

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

            p = tensor.SecondOrderTensor(
                3,
                np.ones(g.num_cells) * np.power(1e3, 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]

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

            labels = np.array(["neu"] * bound_faces.size)
            labels[np.logical_or(left, right)] = ["dir"]

            bc_val = np.zeros(g.num_faces)
            bc_dir = bound_faces[np.logical_or(left, right)]
            bc_val[bc_dir] = g.face_centers[0, bc_dir]

            param.set_bc(solver, bc.BoundaryCondition(g, bound_faces, labels))
            param.set_bc_val(solver, bc_val)

            d["param"] = param

        coupling_conditions = tpfa.TpfaCoupling(solver)
        solver_coupler = coupler.Coupler(solver, coupling_conditions)
        A, rhs = solver_coupler.matrix_rhs(gb)

        p = sps.linalg.spsolve(A, rhs)
        p_cond, _, _, _ = condensation.solve_static_condensation(A,
                                                                 rhs,
                                                                 gb,
                                                                 dim=1)

        solver_coupler.split(gb, "pressure", p)
        solver_coupler.split(gb, "p_cond", p_cond)

        tol = 1e-5
        self.assertTrue((np.amax(np.absolute(p - p_cond))) < tol)
        self.assertTrue(
            np.sum(
                error.error_L2(g, d["pressure"], d["p_cond"])
                for g, d in gb) < tol)
Ejemplo n.º 11
0
    def atest_1d_elimination_2d_1d(self):
        """
        Simplest case possible:
        2d case with two fractures intersecting in a single 0d grid
        at the center of the domain.
        """
        f1 = np.array([[0, 1], [.5, .5]])

        gb = meshing.cart_grid([f1], [2, 2], **{"physdims": [1, 1]})
        gb.compute_geometry()
        gb.assign_node_ordering()

        tol = 1e-3
        solver = tpfa.Tpfa()
        gb.add_node_props(["param"])
        a = 1e-2
        for g, d in gb:
            param = Parameters(g)

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

            kxx = np.ones(g.num_cells) * np.power(1e3, g.dim < gb.dim_max())
            p = tensor.SecondOrderTensor(3, kxx, kyy=kxx, kzz=kxx)
            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(solver, bc.BoundaryCondition(g, bound_faces, labels))
            param.set_bc_val(solver, bc_val)
            d["param"] = param

        coupling_conditions = tpfa.TpfaCoupling(solver)
        solver_coupler = coupler.Coupler(solver, coupling_conditions)
        A, rhs = solver_coupler.matrix_rhs(gb)

        p = sps.linalg.spsolve(A, rhs)
        p_cond, _, _, _ = condensation.solve_static_condensation(A,
                                                                 rhs,
                                                                 gb,
                                                                 dim=1)

        solver_coupler.split(gb, "pressure", p)
        solver_coupler.split(gb, "p_cond", p_cond)

        tol = 1e-10
        self.assertTrue((np.amax(np.absolute(p - p_cond))) < tol)
        self.assertTrue(
            np.sum(
                error.error_L2(g, d["pressure"], d["p_cond"])
                for g, d in gb) < tol)
Ejemplo n.º 12
0
 def diffusivity(self):
     'Returns diffusivity tensor'
     kxx = np.ones(self.grid().num_cells)
     return tensor.SecondOrderTensor(self.grid().dim, kxx)
Ejemplo n.º 13
0
    def test_upwind_example2(self, if_export=False):
        #######################
        # Simple 2d upwind problem with explicit Euler scheme in time coupled with
        # a Darcy problem
        #######################
        T = 2
        Nx, Ny = 10, 10
        folder = "example2"

        def funp_ex(pt):
            return -np.sin(pt[0]) * np.sin(pt[1]) - pt[0]

        g = structured.CartGrid([Nx, Ny], [1, 1])
        g.compute_geometry()

        param = Parameters(g)

        # Permeability
        perm = tensor.SecondOrderTensor(g.dim, kxx=np.ones(g.num_cells))
        param.set_tensor("flow", perm)

        # Source term
        param.set_source("flow", np.zeros(g.num_cells))

        # Boundaries
        b_faces = g.get_all_boundary_faces()
        bc = BoundaryCondition(g, b_faces, ["dir"] * b_faces.size)
        bc_val = np.zeros(g.num_faces)
        bc_val[b_faces] = funp_ex(g.face_centers[:, b_faces])
        param.set_bc("flow", bc)
        param.set_bc_val("flow", bc_val)

        # Darcy solver
        data = {"param": param}
        solver = vem_dual.DualVEM("flow")
        D_flow, b_flow = solver.matrix_rhs(g, data)

        solver_source = vem_source.DualSource("flow")
        D_source, b_source = solver_source.matrix_rhs(g, data)

        up = sps.linalg.spsolve(D_flow + D_source, b_flow + b_source)

        p, u = solver.extract_p(g, up), solver.extract_u(g, up)
        P0u = solver.project_u(g, u, data)

        save = Exporter(g, "darcy", folder)

        if if_export:
            save.write_vtk({"pressure": p, "P0u": P0u})

        # Discharge
        dis = u

        # Boundaries
        bc = BoundaryCondition(g, b_faces, ["dir"] * b_faces.size)
        bc_val = np.hstack(([1], np.zeros(g.num_faces - 1)))
        param.set_bc("transport", bc)
        param.set_bc_val("transport", bc_val)

        data = {"param": param, "discharge": dis}

        # Advect solver
        advect = upwind.Upwind("transport")

        U, rhs = advect.matrix_rhs(g, data)

        data["deltaT"] = advect.cfl(g, data)
        M, _ = mass_matrix.MassMatrix().matrix_rhs(g, data)

        conc = np.zeros(g.num_cells)
        M_minus_U = M - U
        invM, _ = mass_matrix.InvMassMatrix().matrix_rhs(g, data)

        # Loop over the time
        Nt = int(T / data["deltaT"])
        time = np.empty(Nt)
        save.change_name("conc_darcy")
        for i in np.arange(Nt):

            # Update the solution
            conc = invM.dot((M_minus_U).dot(conc) + rhs)
            time[i] = data["deltaT"] * i
            if if_export:
                save.write_vtk({"conc": conc}, time_step=i)

        if if_export:
            save.write_pvd(time)

        known = np.array([
            9.63168200e-01,
            8.64054875e-01,
            7.25390695e-01,
            5.72228235e-01,
            4.25640080e-01,
            2.99387331e-01,
            1.99574336e-01,
            1.26276876e-01,
            7.59011550e-02,
            4.33431230e-02,
            3.30416807e-02,
            1.13058617e-01,
            2.05372538e-01,
            2.78382057e-01,
            3.14035373e-01,
            3.09920132e-01,
            2.75024694e-01,
            2.23163145e-01,
            1.67386939e-01,
            1.16897527e-01,
            1.06111312e-03,
            1.11951850e-02,
            3.87907727e-02,
            8.38516119e-02,
            1.36617802e-01,
            1.82773271e-01,
            2.10446545e-01,
            2.14651936e-01,
            1.97681518e-01,
            1.66549151e-01,
            3.20751341e-05,
            9.85780113e-04,
            6.07062715e-03,
            1.99393042e-02,
            4.53237556e-02,
            8.00799828e-02,
            1.17199623e-01,
            1.47761481e-01,
            1.64729339e-01,
            1.65390555e-01,
            9.18585872e-07,
            8.08267622e-05,
            8.47227168e-04,
            4.08879583e-03,
            1.26336029e-02,
            2.88705048e-02,
            5.27841497e-02,
            8.10459333e-02,
            1.07956484e-01,
            1.27665318e-01,
            2.51295298e-08,
            6.29844122e-06,
            1.09361990e-04,
            7.56743783e-04,
            3.11384414e-03,
            9.04446601e-03,
            2.03443897e-02,
            3.75208816e-02,
            5.89595194e-02,
            8.11457277e-02,
            6.63498510e-10,
            4.73075468e-07,
            1.33728945e-05,
            1.30243418e-04,
            7.01905707e-04,
            2.55272292e-03,
            6.96686157e-03,
            1.52290448e-02,
            2.78607282e-02,
            4.40402650e-02,
            1.71197497e-11,
            3.47118057e-08,
            1.57974045e-06,
            2.13489614e-05,
            1.48634295e-04,
            6.68104990e-04,
            2.18444135e-03,
            5.58646819e-03,
            1.17334966e-02,
            2.09744728e-02,
            4.37822313e-13,
            2.52373622e-09,
            1.83589660e-07,
            3.40553325e-06,
            3.02948532e-05,
            1.66504215e-04,
            6.45119867e-04,
            1.90731440e-03,
            4.53436628e-03,
            8.99977737e-03,
            1.12627412e-14,
            1.84486857e-10,
            2.13562387e-08,
            5.39492977e-07,
            6.08223906e-06,
            4.05535296e-05,
            1.84731221e-04,
            6.25871542e-04,
            1.66459389e-03,
            3.59980231e-03,
        ])

        assert np.allclose(conc, known)