def setup(self, remove_tags=False, num_1d=3, pert_node=False):
        g2 = self.grid_2d()
        g1 = self.grid_1d()
        gb = meshing._assemble_in_bucket([[g2], [g1]])

        gb.add_edge_props("face_cells")
        for e, d in gb.edges():
            a = np.zeros((g2.num_faces, g1.num_cells))
            a[2, 1] = 1
            a[3, 0] = 1
            a[7, 0] = 1
            a[8, 1] = 1
            d["face_cells"] = sps.csc_matrix(a.T)
        meshing.create_mortar_grids(gb)

        g_new_2d = self.grid_2d(pert_node)
        g_new_1d = self.grid_1d(num_1d)
        mortars.replace_grids_in_bucket(gb, g_map={g2: g_new_2d, g1: g_new_1d})

        #        if remove_tags:
        #            internal_flag = FaceTag.FRACTURE
        #            [g.remove_face_tag_if_tag(FaceTag.BOUNDARY, internal_flag) for g, _ in gb]

        gb.assign_node_ordering()

        self.set_params(gb)
        return gb
Beispiel #2
0
    def test_mortar_grid_1d_refine_1d_grid(self):
        """ Refine the lower-dimensional grid so that it is matching with the
        higher dimensional grid.
        """

        f1 = np.array([[0, 1], [.5, .5]])

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

        for e, d in gb.edges():

            # refine the 1d-physical grid
            old_g = gb.nodes_of_edge(e)[0]
            new_g = refinement.remesh_1d(old_g, num_nodes=5)
            new_g.compute_geometry()

            gb.update_nodes({old_g: new_g})
            mg = d["mortar_grid"]
            mortars.update_physical_low_grid(mg, new_g, 1e-4)

            high_to_mortar_known = np.matrix(
                [
                    [0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.],
                    [0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.],
                    [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
                    [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.],
                ]
            )
            low_to_mortar_known = np.matrix(
                [
                    [0., 0., 0.5, 0.5],
                    [0.5, 0.5, 0., 0.],
                    [0., 0., 0.5, 0.5],
                    [0.5, 0.5, 0., 0.],
                ]
            )

            self.assertTrue(
                np.allclose(high_to_mortar_known, mg.high_to_mortar_int.todense())
            )

            # The ordering of the cells in the new 1d grid may be flipped on
            # some systems; therefore allow two configurations
            self.assertTrue(
                np.logical_or(
                    np.allclose(low_to_mortar_known, mg.low_to_mortar_int.todense()),
                    np.allclose(
                        low_to_mortar_known, mg.low_to_mortar_int.todense()[::-1]
                    ),
                )
            )
Beispiel #3
0
    def setup_bucket(self, pert=False, include_1d=True):
        # Mainly test of setup of
        if include_1d:
            g3 = self.grid_3d(pert)
            g2 = self.grid_2d_two_cells(pert)
            g1 = self.grid_1d()

            gb = meshing._assemble_in_bucket([[g3], [g2], [g1]],
                                             ensure_matching_face_cell=False)

            gb.add_edge_props("face_cells")
            for e, d in gb.edges():
                gl = gb.nodes_of_edge(e)[0]
                if gl.dim == 1:
                    m = sps.csc_matrix(np.array([[0, 0, 1, 1, 0, 0]]))
                    d["face_cells"] = m
                else:
                    a = np.zeros((16, 2))
                    a[3, 0] = 1
                    a[7, 1] = 1
                    a[11, 0] = 1
                    a[15, 1] = 1
                    d["face_cells"] = sps.csc_matrix(a.T)

        else:
            g3 = self.grid_3d_no_1d(pert)
            g2 = self.grid_2d_two_cells_no_1d(pert)
            gb = meshing._assemble_in_bucket([[g3], [g2]],
                                             ensure_matching_face_cell=False)
            for e, d in gb.edges():
                a = np.zeros((16, 2))
                a[3, 0] = 1
                a[7, 1] = 1
                a[11, 0] = 1
                a[15, 1] = 1
                d["face_cells"] = sps.csc_matrix(a.T)

        meshing.create_mortar_grids(gb)
        return gb
Beispiel #4
0
    def test_mortar_grid_2d(self):

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

        gb.assign_node_ordering()

        for e, d in gb.edges():

            mg = d["mortar_grid"]
            indices_known = np.array([0, 1, 2, 3, 4, 5, 6, 7])
            self.assertTrue(
                np.array_equal(mg.master_to_mortar_int().indices,
                               indices_known))

            indptr_known = np.array([
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                1,
                2,
                3,
                4,
                4,
                4,
                4,
                4,
                5,
                6,
                7,
                8,
            ])
            self.assertTrue(
                np.array_equal(mg.master_to_mortar_int().indptr, indptr_known))

            data_known = np.array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0])
            self.assertTrue(
                np.array_equal(mg.master_to_mortar_int().data, data_known))

            indices_known = np.array([0, 4, 1, 5, 2, 6, 3, 7])
            self.assertTrue(
                np.array_equal(mg.slave_to_mortar_int().indices,
                               indices_known))

            indptr_known = np.array([0, 2, 4, 6, 8])
            self.assertTrue(
                np.array_equal(mg.slave_to_mortar_int().indptr, indptr_known))

            data_known = np.array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0])
            self.assertTrue(
                np.array_equal(mg.slave_to_mortar_int().data, data_known))
Beispiel #5
0
    def test_mortar_grid_1d_refine_1d_grid_2(self):
        """ Refine the 1D grid so that it is no longer matching the 2D grid.
        """

        f1 = np.array([[0, 1], [0.5, 0.5]])

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

        for e, d in gb.edges():

            # refine the 1d-physical grid
            old_g = gb.nodes_of_edge(e)[0]
            new_g = refinement.remesh_1d(old_g, num_nodes=4)
            new_g.compute_geometry()

            gb.update_nodes({old_g: new_g})
            mg = d["mortar_grid"]
            mg.update_slave(new_g, 1e-4)

            high_to_mortar_known = np.matrix([
                [
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    1.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                ],
                [
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    1.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                ],
                [
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    1.0,
                ],
                [
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    1.0,
                    0.0,
                ],
            ])
            low_to_mortar_known = (
                1.0 / 3.0 * np.matrix([[0.0, 1.0, 2.0], [2.0, 1.0, 0.0],
                                       [0.0, 1.0, 2.0], [2.0, 1.0, 0.0]]))

            self.assertTrue(
                np.allclose(high_to_mortar_known,
                            mg.master_to_mortar_int().todense()))
            # The ordering of the cells in the new 1d grid may be flipped on
            # some systems; therefore allow two configurations
            self.assertTrue(
                np.logical_or(
                    np.allclose(low_to_mortar_known,
                                mg.slave_to_mortar_int().todense()),
                    np.allclose(low_to_mortar_known,
                                mg.slave_to_mortar_int().todense()[::-1]),
                ))