Exemple #1
0
    def test_merge_1d_grids_equal_nodes(self):
        g = TensorGrid(np.array([0, 1, 2]))
        g.compute_geometry()
        h, offset, g_in_comb, g_in_comb , g_sort, _ =\
            non_conforming.merge_1d_grids(g, g, global_ind_offset=0, tol=1e-4)

        assert np.allclose(h.nodes[:, g_in_comb], g.nodes[:, g_sort])
Exemple #2
0
def match_grids_1d(new_1d, old_1d, tol):
    """ Obtain mappings between the cells of non-matching 1d grids.

    The function constructs an refined 1d grid that consists of all nodes
    of at least one of the input grids.

    It is asumed that the two grids are aligned, with common start and
    endpoints.

    Implementation note: It should be possible to avoid old_1d, by extracting
    points from a 2D grid that lie along the line defined by g_1d.
    However, if g_2d is split along a fracture, the nodes will be
    duplicated. We should then return two grids, probably based on the
    coordinates of the cell centers. sounds cool.

    Parameters:
         new_1d (grid): First grid to be matched
         old_1d (grid): Second grid to be matched.

    Returns:
         np.array: Ratio of cell volume in the common grid and the original grid.
         np.array: Mapping between cell numbers in common and first input
              grid.
         np.array: Mapping between cell numbers in common and second input
              grid.

    """

    # Create a grid that contains all nodes of both the old and new grids.
    combined, _, new_ind, old_ind, _, _ = non_conforming.merge_1d_grids(
        new_1d, old_1d, tol=tol
    )
    combined.compute_geometry()
    weights = combined.cell_volumes

    switch_new = new_ind[0] > new_ind[-1]
    if switch_new:
        new_ind = new_ind[::-1]
    switch_old = old_ind[0] > old_ind[-1]
    if switch_old:
        old_ind = old_ind[::-1]

    diff_new = np.diff(new_ind)
    diff_old = np.diff(old_ind)
    new_in_full = rldecode(np.arange(diff_new.size), diff_new)
    old_in_full = rldecode(np.arange(diff_old.size), diff_old)

    if switch_new:
        new_in_full = new_in_full.max() - new_in_full
    if switch_old:
        old_in_full = old_in_full.max() - old_in_full

    old_1d.compute_geometry()

    weights /= old_1d.cell_volumes[old_in_full]
    return weights, new_in_full, old_in_full
Exemple #3
0
    def test_merge_1d_grids_partly_equal_nodes(self):
        g = TensorGrid(np.array([0, 1, 2]))
        h = TensorGrid(np.array([0, 0.5, 1, 2]))
        g.compute_geometry()
        h.compute_geometry()
        gh, offset, g_in_comb, h_in_comb , g_sort, h_sort=\
            non_conforming.merge_1d_grids(g, h, global_ind_offset=0, tol=1e-4)

        assert np.allclose(gh.nodes[:, g_in_comb], g.nodes[:, g_sort])
        assert np.allclose(gh.nodes[:, h_in_comb], h.nodes[:, h_sort])
Exemple #4
0
    def test_merge_1d_grids_unequal_nodes(self):
        # Unequal nodes along the x-axis
        g = TensorGrid(np.array([0, 1, 2]))
        h = TensorGrid(np.array([0, 0.5, 2]))
        g.compute_geometry()
        h.compute_geometry()
        gh, offset, g_in_comb, h_in_comb, g_sort, h_sort = non_conforming.merge_1d_grids(
            g, h, global_ind_offset=0, tol=1e-4
        )

        self.assertTrue(np.allclose(gh.nodes[:, g_in_comb], g.nodes[:, g_sort]))
        self.assertTrue(np.allclose(gh.nodes[:, h_in_comb], h.nodes[:, h_sort]))
Exemple #5
0
    def test_merge_1d_grids_rotation(self):
        #1d grids rotated
        g = TensorGrid(np.array([0, 1, 2]))
        g.nodes = np.array([[0, 0, 0], [1, 1, 1], [2, 2, 2]]).T
        g.compute_geometry()
        h = TensorGrid(np.array([0, 1, 2]))
        h.nodes = np.array([[0, 0, 0], [0.5, 0.5, 0.5], [2, 2, 2]]).T
        h.compute_geometry()

        gh, offset, g_in_comb, h_in_comb , g_sort, h_sort =\
            non_conforming.merge_1d_grids(g, h, global_ind_offset=0)
        assert np.allclose(gh.nodes[:, g_in_comb], g.nodes[:, g_sort])
        assert np.allclose(gh.nodes[:, h_in_comb], h.nodes[:, h_sort])
Exemple #6
0
    def test_merge_1d_permuted_nodes(self):
        g = TensorGrid(np.array([0, 1, 2]))
        g.nodes = np.array([[1, -1, 0], [0, 0, 0], [0, 0, 0]])
        g.global_point_ind = np.array([2, 0, 1])
        g.face_nodes.indices = np.array([1, 2, 0])

        h = TensorGrid(np.array([-1, 0, 1]))
        h.global_point_ind = np.array([0, 1, 2])
        g.compute_geometry()
        h.compute_geometry()
        c, _, _, _, _, _ = non_conforming.merge_1d_grids(g, h)

        ismem, maps = ismember_rows(c.global_point_ind, g.global_point_ind)
        assert ismem.sum() == c.num_nodes
        assert np.allclose(g.nodes[:, maps], c.nodes)
        ismem, maps = ismember_rows(c.global_point_ind, h.global_point_ind)
        assert ismem.sum() == c.num_nodes
        assert np.allclose(h.nodes[:, maps], c.nodes)