def test_create_partition_2d_tri(self):
     g = simplex.StructuredTriangleGrid([3, 2])
     g.compute_geometry()
     part = co.create_partition(co.tpfa_matrix(g))
     known = np.array([1, 1, 1, 0, 0, 1, 0, 2, 2, 0, 2, 2])
     known_map = np.array([4, 3, 7, 5, 11, 8, 1, 2, 10, 6, 12, 9]) - 1
     assert np.array_equal(part, known[known_map])
    def test_create_partition_2d_1d_cross_test6(self):
        # NOTE: Since for python 2.7 and 3.5 the meshes in gridbucket may have
        # non-fixed order, we need to exclude this test.
        if sys.version_info >= (3, 6):
            f1 = np.array([[3., 3.], [1., 5.]])
            f2 = np.array([[1., 5.], [3., 3.]])
            gb = meshing.cart_grid([f1, f2], [6, 6])
            gb.compute_geometry()

            seeds = co.generate_seeds(gb)
            known_seeds = np.array([8, 9, 26, 27, 13, 16, 19, 22])
            assert np.array_equal(np.sort(seeds), np.sort(known_seeds))

            part = co.create_partition(co.tpfa_matrix(gb),
                                       cdepth=3,
                                       seeds=seeds)
            co.generate_coarse_grid(gb, part)

            cell_centers_1 = np.array( \
                          [[3.00000000e+00, 3.00000000e+00, 3.00000000e+00,
                            3.00000000e+00],
                           [4.50000000e+00, 3.50000000e+00, 2.50000000e+00,
                            1.50000000e+00],
                           [-1.66533454e-16, -5.55111512e-17, 5.55111512e-17,
                            1.66533454e-16]])
            cell_centers_2 = np.array( \
                          [[4.50000000e+00, 3.50000000e+00, 2.50000000e+00,
                            1.50000000e+00],
                           [3.00000000e+00, 3.00000000e+00, 3.00000000e+00,
                            3.00000000e+00],
                           [-1.66533454e-16, -5.55111512e-17, 5.55111512e-17,
                            1.66533454e-16]])

            # Test
            for e_d in gb.edges():
                indices, faces, _ = sps.find(e_d[1]['face_cells'])

                if (e_d[0][0].dim == 0 and e_d[0][1].dim == 1) \
                    or \
                   (e_d[0][0].dim == 1 and e_d[0][1].dim == 0):
                    known = [2, 5]
                    known_indices = [0, 0]

                if (e_d[0][0].dim == 1 and e_d[0][1].dim == 2) \
                    or \
                   (e_d[0][0].dim == 2 and e_d[0][1].dim == 1):

                    g = e_d[0][0] if e_d[0][0].dim == 1 else e_d[0][1]

                    if np.allclose(g.cell_centers, cell_centers_1):
                        known = [5, 10, 14, 18, 52, 53, 54, 55]
                        known_indices = [3, 2, 1, 0, 3, 2, 1, 0]
                    elif np.allclose(g.cell_centers, cell_centers_2):
                        known = [37, 38, 39, 40, 56, 57, 58, 59]
                        known_indices = [3, 2, 1, 0, 3, 2, 1, 0]
                    else:
                        raise ValueError('Grid not found')

                assert np.array_equal(faces, np.array(known))
                assert np.array_equal(indices, np.array(known_indices))
 def test_create_partition_2d_cart(self):
     g = structured.CartGrid([5, 5])
     g.compute_geometry()
     part = co.create_partition(co.tpfa_matrix(g))
     known = np.array([0, 0, 0, 1, 1, 0, 0, 2, 1, 1, 3, 2, 2, 2, 1, 3, 3, 2,\
                       4, 4, 3, 3, 4, 4, 4])
     assert np.array_equal(part, known)
Beispiel #4
0
 def test_create_partition_2d_tri(self):
     g = pp.StructuredTriangleGrid([3, 2])
     g.compute_geometry()
     part = co.create_partition(co._tpfa_matrix(g), g)
     known = np.array([1, 1, 1, 0, 0, 1, 0, 2, 2, 0, 2, 2])
     known_map = np.array([4, 3, 7, 5, 11, 8, 1, 2, 10, 6, 12, 9]) - 1
     part = next(iter(part.values()))[1]
     self.assertTrue(np.array_equal(part, known[known_map]))
Beispiel #5
0
    def test_create_partition_2d_1d_cross_test5(self):
        # NOTE: Since for python 2.7 and 3.5 the meshes in gridbucket may have
        # non-fixed order, we need to exclude this test.
        if sys.version_info >= (3, 6):
            f1 = np.array([[3.0, 3.0], [1.0, 5.0]])
            f2 = np.array([[1.0, 5.0], [3.0, 3.0]])
            gb = pp.meshing.cart_grid([f1, f2], [6, 6])
            gb.compute_geometry()

            part = co.create_partition(co._tpfa_matrix(gb), gb, cdepth=3)
            co.generate_coarse_grid(gb, part)

            cell_centers_1 = np.array([
                [3.00000000e00, 3.00000000e00, 3.00000000e00, 3.00000000e00],
                [4.50000000e00, 3.50000000e00, 2.50000000e00, 1.50000000e00],
                [
                    -1.66533454e-16, -5.55111512e-17, 5.55111512e-17,
                    1.66533454e-16
                ],
            ])
            cell_centers_2 = np.array([
                [4.50000000e00, 3.50000000e00, 2.50000000e00, 1.50000000e00],
                [3.00000000e00, 3.00000000e00, 3.00000000e00, 3.00000000e00],
                [
                    -1.66533454e-16, -5.55111512e-17, 5.55111512e-17,
                    1.66533454e-16
                ],
            ])

            # Test
            for e_d in gb.edges():
                indices, faces, _ = sps.find(
                    e_d[1]["mortar_grid"].primary_to_mortar_int())

                if (e_d[0][0].dim == 0
                        and e_d[0][1].dim == 1) or (e_d[0][0].dim == 1
                                                    and e_d[0][1].dim == 0):
                    known = [2, 5]
                    known_indices = [0, 1]

                if (e_d[0][0].dim == 1
                        and e_d[0][1].dim == 2) or (e_d[0][0].dim == 2
                                                    and e_d[0][1].dim == 1):

                    g = e_d[0][0] if e_d[0][0].dim == 1 else e_d[0][1]

                    if np.allclose(g.cell_centers, cell_centers_1):
                        known = [4, 9, 12, 16, 44, 45, 46, 47]
                        known_indices = [3, 2, 1, 0, 7, 6, 5, 4]
                    elif np.allclose(g.cell_centers, cell_centers_2):
                        known = [31, 32, 33, 34, 48, 49, 50, 51]
                        known_indices = [3, 2, 1, 0, 7, 6, 5, 4]
                    else:
                        raise ValueError("Grid not found")

                self.assertTrue(np.array_equal(faces, np.array(known)))
                self.assertTrue(
                    np.array_equal(indices, np.array(known_indices)))
Beispiel #6
0
 def test_create_partition_2d_cart(self):
     g = pp.CartGrid([5, 5])
     g.compute_geometry()
     part = co.create_partition(co._tpfa_matrix(g), g)
     known = np.array([
         0, 0, 0, 1, 1, 0, 0, 2, 1, 1, 3, 2, 2, 2, 1, 3, 3, 2, 4, 4, 3, 3,
         4, 4, 4
     ])
     part = next(iter(part.values()))[1]
     self.assertTrue(np.array_equal(part, known))
 def test_create_partition_3d_cart(self):
     g = structured.CartGrid([4, 4, 4])
     g.compute_geometry()
     part = co.create_partition(co.tpfa_matrix(g))
     known = np.array([1, 1, 1, 1, 2, 4, 1, 3, 2, 2, 3, 3, 2, 2, 3, 3, 5, 4,\
                       1, 6, 4, 4, 4, 3, 2, 4, 7,
                       3, 8, 8, 3, 3, 5, 5, 6, 6, 5, 4, 7, 6, 8, 7, 7, 7, 8,\
                       8, 7, 9, 5, 5, 6, 6, 5, 5,
                       6, 6, 8, 8, 7, 9, 8, 8, 9, 9]) - 1
     assert np.array_equal(part, known)
 def test_create_partition_2d_cart_cdepth4(self):
     g = structured.CartGrid([10, 10])
     g.compute_geometry()
     part = co.create_partition(co.tpfa_matrix(g), cdepth=4)
     known = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\
                       1, 1, 1, 1, 1, 1, 1, 1, 1,
                       1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 1, 1, 1, 1,\
                       1, 1, 1, 2, 2, 3, 3, 1, 1,
                       1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 1, 2, 2, 2, 3, 3,\
                       3, 3, 1, 1, 2, 2, 2, 2, 3,
                       3, 3, 3, 3, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 2,\
                       2]) - 1
     assert np.array_equal(part, known)
Beispiel #9
0
    def test_create_partition_2d_1d_test0(self):
        gb, _ = pp.grid_buckets_2d.single_horizontal([2, 2], simplex=False)

        part = co.create_partition(co._tpfa_matrix(gb), gb)
        co.generate_coarse_grid(gb, part)

        # Test
        known_indices = np.array([1, 0, 3, 2])
        known = np.array([6, 7, 10, 11])

        for _, d in gb.edges():
            indices, faces, _ = sps.find(
                d["mortar_grid"].primary_to_mortar_int())
            self.assertTrue(np.array_equal(faces, known))
            self.assertTrue(np.array_equal(indices, known_indices))
Beispiel #10
0
    def test_create_partition_2d_1d_test3(self):
        f = np.array([[1., 1.], [1., 2.]])
        gb = meshing.cart_grid([f], [2, 2])
        gb.compute_geometry()

        part = co.create_partition(co.tpfa_matrix(gb))
        co.generate_coarse_grid(gb, part)

        # Test
        known_indices = np.array([0, 0])
        known = np.array([3, 9])

        for _, d in gb.edges():
            indices, faces, _ = sps.find(d['face_cells'])
            assert np.array_equal(faces, known)
            assert np.array_equal(indices, known_indices)
Beispiel #11
0
    def test_create_partition_2d_1d_test3(self):
        f = np.array([[1.0, 1.0], [1.0, 2.0]])
        gb = pp.meshing.cart_grid([f], [2, 2])
        gb.compute_geometry()

        part = co.create_partition(co.tpfa_matrix(gb))
        co.generate_coarse_grid(gb, (None, part))

        # Test
        known_indices = np.array([0, 1])
        known = np.array([3, 9])

        for _, d in gb.edges():
            indices, faces, _ = sps.find(d["mortar_grid"].master_to_mortar_int())
            self.assertTrue(np.array_equal(faces, known))
            self.assertTrue(np.array_equal(indices, known_indices))
Beispiel #12
0
    def test_create_partition_2d_1d_test0(self):
        f = np.array([[1., 1.], [0., 2.]])
        gb = meshing.cart_grid([f], [2, 2])
        gb.compute_geometry()

        part = co.create_partition(co.tpfa_matrix(gb))
        co.generate_coarse_grid(gb, part)

        # Test
        known_indices = np.array([1, 0, 1, 0])
        known = np.array([1, 4, 10, 11])

        for _, d in gb.edges():
            indices, faces, _ = sps.find(d["face_cells"])
            self.assertTrue(np.array_equal(faces, known))
            self.assertTrue(np.array_equal(indices, known_indices))
    def test_create_partition_2d_1d_test4(self):
        gb, _ = pp.grid_buckets_2d.single_horizontal([2, 2],
                                                     x_endpoints=[0.5, 1],
                                                     simplex=False)

        seeds = co.generate_seeds(gb)
        known_seeds = np.array([1, 3])
        self.assertTrue(np.array_equal(seeds, known_seeds))

        part = co.create_partition(co._tpfa_matrix(gb), gb, seeds=seeds)
        co.generate_coarse_grid(gb, part)

        # Test
        known_indices = np.array([0, 1])
        known = np.array([7, 10])

        for _, d in gb.edges():
            indices, faces, _ = sps.find(
                d["mortar_grid"].master_to_mortar_int())
            self.assertTrue(np.array_equal(faces, known))
            self.assertTrue(np.array_equal(indices, known_indices))
Beispiel #14
0
 def test_create_partition_3d_cart(self):
     g = pp.CartGrid([4, 4, 4])
     g.compute_geometry()
     part = co.create_partition(co._tpfa_matrix(g), g)
     known = (np.array([
         1,
         1,
         1,
         1,
         2,
         4,
         1,
         3,
         2,
         2,
         3,
         3,
         2,
         2,
         3,
         3,
         5,
         4,
         1,
         6,
         4,
         4,
         4,
         3,
         2,
         4,
         7,
         3,
         8,
         8,
         3,
         3,
         5,
         5,
         6,
         6,
         5,
         4,
         7,
         6,
         8,
         7,
         7,
         7,
         8,
         8,
         7,
         9,
         5,
         5,
         6,
         6,
         5,
         5,
         6,
         6,
         8,
         8,
         7,
         9,
         8,
         8,
         9,
         9,
     ]) - 1)
     part = next(iter(part.values()))[1]
     self.assertTrue(np.array_equal(part, known))
Beispiel #15
0
 def test_create_partition_2d_cart_cdepth4(self):
     g = pp.CartGrid([10, 10])
     g.compute_geometry()
     part = co.create_partition(co._tpfa_matrix(g), g, cdepth=4)
     known = (np.array([
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         2,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         2,
         2,
         3,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         2,
         2,
         3,
         3,
         1,
         1,
         1,
         1,
         1,
         2,
         2,
         2,
         3,
         3,
         3,
         1,
         1,
         1,
         1,
         2,
         2,
         2,
         3,
         3,
         3,
         3,
         1,
         1,
         2,
         2,
         2,
         2,
         3,
         3,
         3,
         3,
         3,
         2,
         2,
         2,
         2,
         2,
         3,
         3,
         3,
         3,
         3,
         2,
         2,
         2,
         2,
         2,
     ]) - 1)
     part = next(iter(part.values()))[1]
     self.assertTrue(np.array_equal(part, known))
Beispiel #16
0
    def test_create_partition_2d_1d_cross_test7(self):
        # NOTE: Since for python 2.7 and 3.5 the meshes in gridbucket may have
        # non-fixed order, we need to exclude this test.
        if sys.version_info >= (3, 6):
            N = 20
            f1 = np.array([[N / 2.0, N / 2.0], [1.0, N - 1.0]])
            f2 = np.array([[1.0, N - 1.0], [N / 2.0, N / 2.0]])
            gb = pp.meshing.cart_grid([f1, f2], [N, N])
            gb.compute_geometry()

            seeds = co.generate_seeds(gb)
            known_seeds = np.array([29, 30, 369, 370, 181, 198, 201, 218])
            self.assertTrue(
                np.array_equal(np.sort(seeds), np.sort(known_seeds)))

            part = co.create_partition(co._tpfa_matrix(gb),
                                       gb,
                                       cdepth=3,
                                       seeds=seeds)
            co.generate_coarse_grid(gb, part)

            cell_centers_1 = np.array([
                [
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                ],
                [
                    1.85000000e01,
                    1.75000000e01,
                    1.65000000e01,
                    1.55000000e01,
                    1.45000000e01,
                    1.35000000e01,
                    1.25000000e01,
                    1.15000000e01,
                    1.05000000e01,
                    9.50000000e00,
                    8.50000000e00,
                    7.50000000e00,
                    6.50000000e00,
                    5.50000000e00,
                    4.50000000e00,
                    3.50000000e00,
                    2.50000000e00,
                    1.50000000e00,
                ],
                [
                    -9.43689571e-16,
                    -8.32667268e-16,
                    -7.21644966e-16,
                    -6.10622664e-16,
                    -4.99600361e-16,
                    -3.88578059e-16,
                    -2.77555756e-16,
                    -1.66533454e-16,
                    -5.55111512e-17,
                    5.55111512e-17,
                    1.66533454e-16,
                    2.77555756e-16,
                    3.88578059e-16,
                    4.99600361e-16,
                    6.10622664e-16,
                    7.21644966e-16,
                    8.32667268e-16,
                    9.43689571e-16,
                ],
            ])
            cell_centers_2 = np.array([
                [
                    1.85000000e01,
                    1.75000000e01,
                    1.65000000e01,
                    1.55000000e01,
                    1.45000000e01,
                    1.35000000e01,
                    1.25000000e01,
                    1.15000000e01,
                    1.05000000e01,
                    9.50000000e00,
                    8.50000000e00,
                    7.50000000e00,
                    6.50000000e00,
                    5.50000000e00,
                    4.50000000e00,
                    3.50000000e00,
                    2.50000000e00,
                    1.50000000e00,
                ],
                [
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                    1.00000000e01,
                ],
                [
                    -9.43689571e-16,
                    -8.32667268e-16,
                    -7.21644966e-16,
                    -6.10622664e-16,
                    -4.99600361e-16,
                    -3.88578059e-16,
                    -2.77555756e-16,
                    -1.66533454e-16,
                    -5.55111512e-17,
                    5.55111512e-17,
                    1.66533454e-16,
                    2.77555756e-16,
                    3.88578059e-16,
                    4.99600361e-16,
                    6.10622664e-16,
                    7.21644966e-16,
                    8.32667268e-16,
                    9.43689571e-16,
                ],
            ])

            # Test
            for e_d in gb.edges():
                indices, faces, _ = sps.find(
                    e_d[1]["mortar_grid"].primary_to_mortar_int())

                if (e_d[0][0].dim == 0
                        and e_d[0][1].dim == 1) or (e_d[0][0].dim == 1
                                                    and e_d[0][1].dim == 0):
                    known = [9, 19]
                    known_indices = [0, 1]

                if (e_d[0][0].dim == 1
                        and e_d[0][1].dim == 2) or (e_d[0][0].dim == 2
                                                    and e_d[0][1].dim == 1):

                    g = e_d[0][0] if e_d[0][0].dim == 1 else e_d[0][1]

                    if np.allclose(g.cell_centers, cell_centers_1):
                        known = [
                            10,
                            18,
                            28,
                            37,
                            46,
                            54,
                            62,
                            71,
                            77,
                            84,
                            91,
                            99,
                            108,
                            116,
                            124,
                            134,
                            143,
                            151,
                            328,
                            329,
                            330,
                            331,
                            332,
                            333,
                            334,
                            335,
                            336,
                            337,
                            338,
                            339,
                            340,
                            341,
                            342,
                            343,
                            344,
                            345,
                        ]
                        known_indices = [
                            17,
                            16,
                            15,
                            14,
                            13,
                            12,
                            11,
                            10,
                            9,
                            8,
                            7,
                            6,
                            5,
                            4,
                            3,
                            2,
                            1,
                            0,
                            35,
                            34,
                            33,
                            32,
                            31,
                            30,
                            29,
                            28,
                            27,
                            26,
                            25,
                            24,
                            23,
                            22,
                            21,
                            20,
                            19,
                            18,
                        ]
                    elif np.allclose(g.cell_centers, cell_centers_2):
                        known = [
                            236,
                            237,
                            238,
                            239,
                            240,
                            241,
                            242,
                            243,
                            244,
                            245,
                            246,
                            247,
                            248,
                            249,
                            250,
                            251,
                            252,
                            253,
                            346,
                            347,
                            348,
                            349,
                            350,
                            351,
                            352,
                            353,
                            354,
                            355,
                            356,
                            357,
                            358,
                            359,
                            360,
                            361,
                            362,
                            363,
                        ]
                        known_indices = [
                            17,
                            16,
                            15,
                            14,
                            13,
                            12,
                            11,
                            10,
                            9,
                            8,
                            7,
                            6,
                            5,
                            4,
                            3,
                            2,
                            1,
                            0,
                            35,
                            34,
                            33,
                            32,
                            31,
                            30,
                            29,
                            28,
                            27,
                            26,
                            25,
                            24,
                            23,
                            22,
                            21,
                            20,
                            19,
                            18,
                        ]
                    else:
                        raise ValueError("Grid not found")

                self.assertTrue(np.array_equal(faces, np.array(known)))
                self.assertTrue(
                    np.array_equal(indices, np.array(known_indices)))