Exemple #1
0
    def test_uniform_displacement_neumann(self):
        physdims = [1, 1]
        g_size = [4, 8]
        g_list = [structured.CartGrid([n, n], physdims=physdims) for n in g_size]
        [g.compute_geometry() for g in g_list]
        error = []
        for g in g_list:
            bot = np.ravel(np.argwhere(g.face_centers[1, :] < 1e-10))
            left = np.ravel(np.argwhere(g.face_centers[0, :] < 1e-10))
            dir_faces = np.hstack((left, bot))
            bound = bc.BoundaryCondition(
                g, dir_faces.ravel("F"), ["dir"] * dir_faces.size
            )
            constit = setup_stiffness(g)

            # Python inverter is most efficient for small problems
            stress, bound_stress = mpsa.mpsa(g, constit, bound, inverter="python")

            div = fvutils.vector_divergence(g)
            a = div * stress

            d_x = np.random.rand(1)
            d_y = np.random.rand(1)
            d_bound = np.zeros((g.dim, g.num_faces))
            d_bound[0, bound.is_dir] = d_x
            d_bound[1, bound.is_dir] = d_y

            rhs = div * bound_stress * d_bound.ravel("F")

            d = np.linalg.solve(a.todense(), -rhs)

            traction = stress * d + bound_stress * d_bound.ravel("F")
            self.assertTrue(np.max(np.abs(d[::2] - d_x)) < 1e-8)
            self.assertTrue(np.max(np.abs(d[1::2] - d_y)) < 1e-8)
            self.assertTrue(np.max(np.abs(traction)) < 1e-8)
Exemple #2
0
    def test_uniform_displacement(self):

        g_list = setup_grids.setup_2d()

        for g in g_list:
            bound_faces = np.argwhere(
                np.abs(g.cell_faces).sum(axis=1).A.ravel("F") == 1
            )
            bound = bc.BoundaryCondition(
                g, bound_faces.ravel("F"), ["dir"] * bound_faces.size
            )
            constit = setup_stiffness(g)

            # Python inverter is most efficient for small problems
            stress, bound_stress = mpsa.mpsa(g, constit, bound, inverter="python")

            div = fvutils.vector_divergence(g)
            a = div * stress

            d_x = np.random.rand(1)
            d_y = np.random.rand(1)
            d_bound = np.zeros((g.dim, g.num_faces))
            d_bound[0, bound.is_dir] = d_x
            d_bound[1, bound.is_dir] = d_y

            rhs = div * bound_stress * d_bound.ravel("F")

            d = np.linalg.solve(a.todense(), -rhs)

            traction = stress * d + bound_stress * d_bound.ravel("F")

            self.assertTrue(np.max(np.abs(d[::2] - d_x)) < 1e-8)
            self.assertTrue(np.max(np.abs(d[1::2] - d_y)) < 1e-8)
            self.assertTrue(np.max(np.abs(traction)) < 1e-8)
Exemple #3
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
    def setup(self):
        g = pp.CartGrid([5, 5])
        g.compute_geometry()
        stiffness = pp.FourthOrderTensor(np.ones(g.num_cells), np.ones(g.num_cells))
        bnd = pp.BoundaryConditionVectorial(g)
        stress, bound_stress, _, _ = mpsa.mpsa(g, stiffness, bnd, inverter="python")

        return g, stiffness, bnd, stress, bound_stress
Exemple #5
0
    def test_uniform_strain(self):
        g_list = setup_grids.setup_2d()

        for g in g_list:
            bound_faces = np.argwhere(
                np.abs(g.cell_faces).sum(axis=1).A.ravel("F") == 1)
            bound = pp.BoundaryConditionVectorial(g, bound_faces.ravel("F"),
                                                  ["dir"] * bound_faces.size)
            mu = 1
            l = 1
            constit = setup_stiffness(g, mu, l)

            # Python inverter is most efficient for small problems
            stress, bound_stress, _, _ = mpsa.mpsa(g,
                                                   constit,
                                                   bound,
                                                   inverter="python")

            div = fvutils.vector_divergence(g)
            a = div * stress

            xc = g.cell_centers
            xf = g.face_centers

            gx = np.random.rand(1)
            gy = np.random.rand(1)

            dc_x = np.sum(xc * gx, axis=0)
            dc_y = np.sum(xc * gy, axis=0)
            df_x = np.sum(xf * gx, axis=0)
            df_y = np.sum(xf * gy, axis=0)

            d_bound = np.zeros((g.dim, g.num_faces))

            d_bound[0, bound.is_dir[0]] = df_x[bound.is_dir[0]]
            d_bound[1, bound.is_dir[1]] = df_y[bound.is_dir[1]]

            rhs = div * bound_stress * d_bound.ravel("F")

            d = np.linalg.solve(a.todense(), -rhs)

            traction = stress * d + bound_stress * d_bound.ravel("F")

            s_xx = (2 * mu + l) * gx + l * gy
            s_xy = mu * (gx + gy)
            s_yx = mu * (gx + gy)
            s_yy = (2 * mu + l) * gy + l * gx

            n = g.face_normals
            traction_ex_x = s_xx * n[0] + s_xy * n[1]
            traction_ex_y = s_yx * n[0] + s_yy * n[1]

            self.assertTrue(np.max(np.abs(d[::2] - dc_x)) < 1e-8)
            self.assertTrue(np.max(np.abs(d[1::2] - dc_y)) < 1e-8)
            self.assertTrue(
                np.max(np.abs(traction[::2] - traction_ex_x)) < 1e-8)
            self.assertTrue(
                np.max(np.abs(traction[1::2] - traction_ex_y)) < 1e-8)
Exemple #6
0
    def test_conservation_of_momentum(self):
        pts = np.random.rand(3, 9)
        corners = [
            [0, 0, 0, 0, 1, 1, 1, 1],
            [0, 0, 1, 1, 0, 0, 1, 1],
            [0, 1, 0, 1, 0, 1, 0, 1],
        ]
        pts = np.hstack((corners, pts))
        gt = pp.TetrahedralGrid(pts)
        gc = pp.CartGrid([3, 3, 3], physdims=[1, 1, 1])
        g_list = [gt, gc]
        [g.compute_geometry() for g in g_list]
        for g in g_list:
            g.compute_geometry()
            bot = np.ravel(np.argwhere(g.face_centers[1, :] < 1e-10))
            left = np.ravel(np.argwhere(g.face_centers[0, :] < 1e-10))
            dir_faces = np.hstack((left, bot))
            bound = pp.BoundaryConditionVectorial(g, dir_faces.ravel("F"),
                                                  ["dir"] * dir_faces.size)
            constit = setup_stiffness(g)

            # Python inverter is most efficient for small problems
            stress, bound_stress, _, _ = mpsa.mpsa(g,
                                                   constit,
                                                   bound,
                                                   inverter="python")

            div = fvutils.vector_divergence(g)
            a = div * stress

            bndr = g.get_all_boundary_faces()
            d_x = np.random.rand(bndr.size)
            d_y = np.random.rand(bndr.size)
            d_bound = np.zeros((g.dim, g.num_faces))
            d_bound[0, bndr] = d_x
            d_bound[1, bndr] = d_y

            rhs = div * bound_stress * d_bound.ravel("F")

            d = np.linalg.solve(a.todense(), -rhs)

            traction = stress * d + bound_stress * d_bound.ravel("F")
            traction_2d = traction.reshape((g.dim, -1), order="F")
            for cell in range(g.num_cells):
                fid, _, sgn = sps.find(g.cell_faces[:, cell])
                self.assertTrue(
                    np.all(np.sum(traction_2d[:, fid] * sgn, axis=1) < 1e-10))
Exemple #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