Esempio n. 1
0
    def test_no_dynamics_2d(self):
        g_list = setup_grids.setup_2d()
        for g in g_list:
            discr = biot.Biot()

            bound_faces = g.get_all_boundary_faces()
            bound = bc.BoundaryCondition(
                g, bound_faces.ravel("F"), ["dir"] * bound_faces.size
            )

            mu = np.ones(g.num_cells)
            c = tensor.FourthOrderTensor(g.dim, mu, mu)
            k = tensor.SecondOrderTensor(g.dim, np.ones(g.num_cells))

            bound_val = np.zeros(g.num_faces)

            param = Parameters(g)
            param.set_bc("flow", bound)
            param.set_bc("mechanics", bound)
            param.set_tensor("flow", k)
            param.set_tensor("mechanics", c)
            param.set_bc_val("mechanics", np.tile(bound_val, g.dim))
            param.set_bc_val("flow", bound_val)
            param.porosity = np.ones(g.num_cells)
            param.biot_alpha = 1
            data = {"param": param, "inverter": "python", "dt": 1}

            A, b = discr.matrix_rhs(g, data)
            sol = np.linalg.solve(A.todense(), b)

            self.assertTrue(np.isclose(sol, np.zeros(g.num_cells * (g.dim + 1))).all())
Esempio n. 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)
Esempio n. 3
0
    def test_no_dynamics_2d(self):
        g_list = setup_grids.setup_2d()
        for g in g_list:
            discr = biot.Biot()

            bound_faces = g.get_all_boundary_faces()
            bound = bc.BoundaryCondition(g, bound_faces.ravel('F'),
                                         ['dir'] * bound_faces.size)

            mu = np.ones(g.num_cells)
            c = tensor.FourthOrderTensor(g.dim, mu, mu)
            k = tensor.SecondOrderTensor(g.dim, np.ones(g.num_cells))

            bound_val = np.zeros(g.num_faces)

            param = Parameters(g)
            param.set_bc('flow', bound)
            param.set_bc('mechanics', bound)
            param.set_tensor('flow', k)
            param.set_tensor('mechanics', c)
            param.set_bc_val('mechanics', np.tile(bound_val, g.dim))
            param.set_bc_val('flow', bound_val)
            param.porosity = np.ones(g.num_cells)
            param.biot_alpha = 1
            data = {'param': param, 'inverter': 'python', 'dt': 1}

            A, b = discr.matrix_rhs(g, data)
            sol = np.linalg.solve(A.todense(), b)

            assert np.isclose(sol, np.zeros(g.num_cells * (g.dim + 1))).all()
Esempio n. 4
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)
Esempio n. 5
0
 def test_matrix_rhs(self):
     g_list = setup_grids.setup_2d()
     kw = "mechanics"
     for g in g_list:
         solver = pp.numerics.fv.mpsa.Mpsa(kw)
         data = pp.initialize_default_data(g, {}, kw)
         A, b = solver.assemble_matrix_rhs(g, data)
         self.assertTrue(
             np.all(A.shape == (g.dim * g.num_cells, g.dim * g.num_cells)))
         self.assertTrue(b.size == g.dim * g.num_cells)
Esempio n. 6
0
    def test_matrix_rhs(self):
        g_list = setup_grids.setup_2d()

        for g in g_list:
            solver = mpsa.Mpsa()
            data = {"param": Parameters(g)}
            A, b = solver.matrix_rhs(g, data)
            self.assertTrue(
                np.all(A.shape == (g.dim * g.num_cells, g.dim * g.num_cells)))
            self.assertTrue(b.size == g.dim * g.num_cells)
Esempio n. 7
0
    def test_matrix_rhs_no_disc(self):
        g_list = setup_grids.setup_2d()

        for g in g_list:
            solver = mpsa.Mpsa()
            data = {"param": Parameters(g)}
            cell_dof = g.dim * g.num_cells
            face_dof = g.dim * g.num_faces
            data["stress"] = sps.csc_matrix((face_dof, cell_dof))
            data["bound_stress"] = sps.csc_matrix((face_dof, face_dof))
            A, b = solver.matrix_rhs(g, data, discretize=False)
            self.assertTrue(np.sum(A != 0) == 0)
            self.assertTrue(np.all(b == 0))
Esempio n. 8
0
 def test_matrix_rhs_no_disc(self):
     g_list = setup_grids.setup_2d()
     kw = "mechanics"
     for g in g_list:
         solver = pp.numerics.fv.mpsa.Mpsa(kw)
         data = pp.initialize_default_data(g, {}, kw)
         cell_dof = g.dim * g.num_cells
         face_dof = g.dim * g.num_faces
         stress = sps.csc_matrix((face_dof, cell_dof))
         bound_stress = sps.csc_matrix((face_dof, face_dof))
         data[pp.DISCRETIZATION_MATRICES][kw] = {
             "stress": stress,
             "bound_stress": bound_stress,
         }
         A, b = solver.assemble_matrix_rhs(g, data)
         self.assertTrue(np.sum(A != 0) == 0)
         self.assertTrue(np.all(b == 0))
Esempio n. 9
0
    def test_no_dynamics_2d(self):
        g_list = setup_grids.setup_2d()
        kw_f = "flow"
        kw_m = "mechanics"
        discr = pp.Biot()
        for g in g_list:

            bound_mech, bound_flow = self.make_boundary_conditions(g)

            mu = np.ones(g.num_cells)
            c = pp.FourthOrderTensor(mu, mu)
            k = pp.SecondOrderTensor(np.ones(g.num_cells))

            bound_val = np.zeros(g.num_faces)
            aperture = np.ones(g.num_cells)

            param = pp.Parameters(g, [kw_f, kw_m], [{}, {}])

            param[kw_f]["bc"] = bound_flow
            param[kw_m]["bc"] = bound_mech
            param[kw_f]["aperture"] = aperture
            param[kw_m]["aperture"] = aperture
            param[kw_f]["second_order_tensor"] = k  # permeability / viscosity
            param[kw_m]["fourth_order_tensor"] = c
            param[kw_f]["bc_values"] = bound_val
            param[kw_m]["bc_values"] = np.tile(bound_val, g.dim)
            param[kw_f]["biot_alpha"] = 1
            param[kw_m]["biot_alpha"] = 1
            param[kw_f]["time_step"] = 1
            param[kw_f]["mass_weight"] = 0  # fluid compressibility * porosity
            param[kw_m]["inverter"] = "python"
            data = {pp.PARAMETERS: param}
            data[pp.DISCRETIZATION_MATRICES] = {kw_f: {}, kw_m: {}}
            discr.discretize(g, data)
            A, b = discr.assemble_matrix_rhs(g, data)
            sol = np.linalg.solve(A.todense(), b)

            self.assertTrue(
                np.isclose(sol, np.zeros(g.num_cells * (g.dim + 1))).all())