コード例 #1
0
 def setup(self):
     g = CartGrid([5, 5])
     g.compute_geometry()
     perm = PermTensor(g.dim, np.ones(g.num_cells))
     bnd = bc.BoundaryCondition(g)
     flux, bound_flux, _, _ = mpfa.mpfa(g, perm, bnd, inverter="python")
     return g, perm, bnd, flux, bound_flux
コード例 #2
0
 def setup(self):
     g = CartGrid([5, 5])
     g.compute_geometry()
     stiffness = StiffnessTensor(g.dim, np.ones(g.num_cells),
                                 np.ones(g.num_cells))
     bnd = bc.BoundaryCondition(g)
     stress, bound_stress = mpsa.mpsa(g, stiffness, bnd, inverter="python")
     return g, stiffness, bnd, stress, bound_stress
コード例 #3
0
def setup_3d_grid():
    g = CartGrid([2, 2, 2], physdims=[1, 1, 1])
    g.compute_geometry()
    d = {'param': Parameters(g)}
    src = np.zeros(g.num_cells)
    src[4] = 1
    d['param'].set_source('flow', src)
    return g, d
コード例 #4
0
ファイル: test_parameters.py プロジェクト: git-taufiq/porepy
 def setUp(self):
     self.g = CartGrid([3, 2])
     self.p = Parameters()
     self.p.update_dictionaries("dummy_kw", {
         "string_key": "string_parameter",
         "list_key": [0, 1]
     })
コード例 #5
0
ファイル: test_darcy.py プロジェクト: mrezajalali/porepy
    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)
コード例 #6
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)
コード例 #7
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)
        mu = np.random.random(g.num_cells)
        lmbda = np.random.random(g.num_cells)
        stiffness = StiffnessTensor(2, mu=mu, lmbda=lmbda)

        stress = sps.csr_matrix((g.num_faces * g.dim, g.num_cells * g.dim))
        bound_stress = sps.csr_matrix(
            (g.num_faces * g.dim, g.num_faces * g.dim))
        faces_covered = np.zeros(g.num_faces, np.bool)

        bnd = bc.BoundaryCondition(g)
        stress_full, bound_stress_full = mpsa.mpsa(g,
                                                   stiffness,
                                                   bnd,
                                                   inverter='python')

        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_stress, partial_bound, active_faces = \
                    mpsa.mpsa_partial(g, stiffness, bnd, nodes=nodes,
                                      inverter='python')

            if np.any(faces_covered):
                del_faces = self.expand_indices_nd(
                    np.where(faces_covered)[0], g.dim)
                partial_stress[del_faces, :] *= 0
                partial_bound[del_faces, :] *= 0
            faces_covered[active_faces] = True

            stress += partial_stress
            bound_stress += partial_bound

        assert (stress_full - stress).max() < 1e-8
        assert (stress_full - stress).min() > -1e-8
        assert (bound_stress - bound_stress_full).max() < 1e-8
        assert (bound_stress - bound_stress_full).min() > -1e-8
コード例 #8
0
 def setUp(self):
     self.g_2d = CartGrid([5, 5])
     self.g_3d = CartGrid([3, 3, 3])
コード例 #9
0
 def setUp(self):
     self.g = CartGrid([3, 2])
     self.nc = self.g.num_cells
     self.v = np.ones(self.nc)
コード例 #10
0
    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.tags['domain_boundary_faces'].nonzero()[0]
            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(sub_g))
            d['param'].set_bc('flow', bc_labels(sub_g))

        problem_mono = elliptic.DualEllipticModel(g, {'param': param_g})
        problem_mult = elliptic.DualEllipticModel(gb)

        up_mono = problem_mono.solve()
        up_mult = problem_mult.solve()

        assert np.allclose(up_mono, up_mult)

        g_gb = next(problem_mult.grid().nodes())

        problem_mono.pressure('pressure')
        problem_mult.split()
        problem_mult.pressure('pressure')

        assert np.allclose(problem_mono.data()['pressure'],
                           g_gb[1]['pressure'])

        problem_mono.discharge('u')
        problem_mult.discharge('u')

        assert np.allclose(problem_mono.data()['u'], g_gb[1]['u'])

        problem_mono.project_discharge('P0u')
        problem_mult.project_discharge('P0u')

        problem_mono.save(['pressure', 'P0u'])
        problem_mult.save(['pressure', 'P0u'])

        assert np.allclose(problem_mono.data()['P0u'], g_gb[1]['P0u'])