Exemple #1
0
    def test_bound_cell_node_keyword(self):
        # Compute update for a single cell on the boundary
        g, perm, bnd, flux, bound_flux = self.setup()

        inner_cell = 10
        nodes_of_cell = np.array([12, 13, 18, 19])
        faces_of_cell = np.array([12, 13, 40, 45])
        partial_flux, partial_bound, _, _, active_faces = mpfa.mpfa_partial(
            g, perm, bnd, nodes=nodes_of_cell, inverter="python")

        self.assertTrue(faces_of_cell.size == active_faces.size)
        self.assertTrue(
            np.all(np.sort(faces_of_cell) == np.sort(active_faces)))

        diff_flux = (flux - partial_flux).todense()
        diff_bound = (bound_flux - partial_bound).todense()

        self.assertTrue(np.max(np.abs(diff_flux[faces_of_cell])) == 0)
        self.assertTrue(np.max(np.abs(diff_bound[faces_of_cell])) == 0)

        # Only the faces of the central cell should be zero
        partial_flux[faces_of_cell, :] = 0
        partial_bound[faces_of_cell, :] = 0
        self.assertTrue(np.max(np.abs(partial_flux.data)) == 0)
        self.assertTrue(np.max(np.abs(partial_bound.data)) == 0)
Exemple #2
0
    def test_inner_cell_node_keyword(self):
        # Compute update for a single cell in the interior.
        g, perm, bnd, flux, bound_flux = self.setup()

        inner_cell = 12
        nodes_of_cell = np.array([14, 15, 20, 21])
        faces_of_cell = np.array([14, 15, 42, 47])

        partial_flux, partial_bound, active_faces \
                = mpfa.mpfa_partial(g, perm, bnd, nodes=nodes_of_cell,
                                    inverter='python')

        assert faces_of_cell.size == active_faces.size
        assert np.all(np.sort(faces_of_cell) == np.sort(active_faces))

        diff_flux = (flux - partial_flux).todense()
        diff_bound = (bound_flux - partial_bound).todense()

        assert np.max(np.abs(diff_flux[faces_of_cell])) == 0
        assert np.max(np.abs(diff_bound[faces_of_cell])) == 0

        # Only the faces of the central cell should be zero
        partial_flux[faces_of_cell, :] = 0
        partial_bound[faces_of_cell, :] = 0
        assert np.max(np.abs(partial_flux.data)) == 0
        assert np.max(np.abs(partial_bound.data)) == 0
Exemple #3
0
    def test_one_cell_a_time_node_keyword(self):
        # Update one and one cell, and verify that the result is the same as
        # with a single computation.
        # The test is similar to what will happen with a memory-constrained
        # splitting.
        g = CartGrid([3, 3])
        g.compute_geometry()

        # Assign random permeabilities, for good measure
        np.random.seed(42)
        kxx = np.random.random(g.num_cells)
        kyy = np.random.random(g.num_cells)
        # Ensure positive definiteness
        kxy = np.random.random(g.num_cells) * kxx * kyy
        perm = PermTensor(2, kxx=kxx, kyy=kyy, kxy=kxy)

        flux = sps.csr_matrix((g.num_faces, g.num_cells))
        bound_flux = sps.csr_matrix((g.num_faces, g.num_faces))
        faces_covered = np.zeros(g.num_faces, np.bool)

        bnd = bc.BoundaryCondition(g)

        cn = g.cell_nodes()
        for ci in range(g.num_cells):
            ind = np.zeros(g.num_cells)
            ind[ci] = 1
            nodes = np.squeeze(np.where(cn * ind > 0))
            partial_flux, partial_bound, _, _, active_faces = mpfa.mpfa_partial(
                g, perm, bnd, nodes=nodes, inverter="python")

            if np.any(faces_covered):
                partial_flux[faces_covered, :] *= 0
                partial_bound[faces_covered, :] *= 0
            faces_covered[active_faces] = True

            flux += partial_flux
            bound_flux += partial_bound

        flux_full, bound_flux_full, _, _ = mpfa.mpfa(g,
                                                     perm,
                                                     bnd,
                                                     inverter="python")

        self.assertTrue((flux_full - flux).max() < 1e-8)
        self.assertTrue((flux_full - flux).min() > -1e-8)
        self.assertTrue((bound_flux - bound_flux_full).max() < 1e-8)
        self.assertTrue((bound_flux - bound_flux_full).min() > -1e-8)