Example #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])
Example #2
0
 def grid_1d(self, n_nodes=2):
     x = np.linspace(0, 1, n_nodes)
     g = TensorGrid(x)
     g.nodes = np.tile(x, (3, 1))
     g.compute_geometry()
     g.global_point_ind = 1 + np.arange(n_nodes)
     return g
Example #3
0
 def grid_1d(self, num_pts=3):
     g = TensorGrid(np.arange(num_pts))
     g.nodes = np.vstack(
         (np.linspace(0, 1,
                      num_pts), 0.5 * np.ones(num_pts), np.zeros(num_pts)))
     g.compute_geometry()
     g.global_point_ind = np.arange(g.num_nodes)
     return g
Example #4
0
def remesh_1d(g_old: pp.Grid,
              num_nodes: int,
              tol: Optional[float] = 1e-6) -> pp.Grid:
    """Create a new 1d mesh covering the same domain as an old one.

    The new grid is equispaced, and there is no guarantee that the nodes in
    the old and new grids are coincinding. Use with care, in particular for
    grids with internal boundaries.

    Parameters:
        g_old (pp.Grid): 1d grid to be replaced.
        num_nodes (int): Number of nodes in the new grid.
        tol (double, optional): Tolerance used to compare node coornidates
            (for mapping of boundary conditions). Defaults to 1e-6.

    Returns:
        pp.Grid: New grid.

    """

    # Create equi-spaced nodes covering the same domain as the old grid
    theta = np.linspace(0, 1, num_nodes)
    start, end = g_old.get_all_boundary_nodes()
    # Not sure why the new axis was necessary.
    nodes = g_old.nodes[:, start,
                        np.newaxis] * theta + g_old.nodes[:, end,
                                                          np.newaxis] * (1.0 -
                                                                         theta)

    # Create the new grid, and assign nodes.
    g = TensorGrid(nodes[0, :])
    g.nodes = nodes
    g.compute_geometry()

    # map the tags from the old grid to the new one
    # normally the tags are given at faces/point that are fixed the 1d mesh
    # we use this assumption to proceed.
    for f_old in np.arange(g_old.num_faces):
        # detect in the new grid which face is geometrically the same (upon a tolerance)
        # as in the old grid
        dist = pp.distances.point_pointset(g_old.face_centers[:, f_old],
                                           g.face_centers)
        f_new = np.where(dist < tol)[0]

        # if you find a match transfer all the tags from the face in the old grid to
        # the face in the new grid
        if f_new.size:
            if f_new.size != 1:
                raise ValueError(
                    "It cannot be more than one face, something went wrong")
            for tag in pp.utils.tags.standard_face_tags():
                g.tags[tag][f_new] = g_old.tags[tag][f_old]

    g.update_boundary_node_tag()

    return g
Example #5
0
def remesh_1d(g_old, num_nodes, tol=1e-6):
    """ Create a new 1d mesh covering the same domain as an old one.

    The new grid is equispaced, and there is no guarantee that the nodes in
    the old and new grids are coincinding. Use with care, in particular for
    grids with internal boundaries.

    Parameters:
        g_old (grid): 1d grid to be replaced.
        num_nodes (int): Number of nodes in the new grid.
        tol (double, optional): Tolerance used to compare node coornidates
            (for mapping of boundary conditions). Defaults to 1e-6.

    Returns:
        grid: New grid.

    """

    # Create equi-spaced nodes covering the same domain as the old grid
    theta = np.linspace(0, 1, num_nodes)
    start, end = g_old.get_boundary_nodes()
    # Not sure why the new axis was necessary.
    nodes = g_old.nodes[:, start,
                        np.newaxis] * theta + g_old.nodes[:, end,
                                                          np.newaxis] * (1. -
                                                                         theta)

    # Create the new grid, and assign nodes.
    g = TensorGrid(nodes[0, :])
    g.nodes = nodes
    g.compute_geometry()

    # map the tags from the old grid to the new one

    # retrieve the old faces and the corresponding coordinates
    old_frac_faces = np.where(g_old.tags["fracture_faces"].ravel())[0]

    # compute the mapping from the old boundary to the new boundary
    # we need to go through the coordinates

    new_frac_face = []

    for fi in old_frac_faces:
        nfi = np.where(
            cg.dist_point_pointset(g_old.face_centers[:, fi], nodes) < tol)[0]
        if len(nfi) > 0:
            new_frac_face.append(nfi[0])

    # This can probably be made more elegant
    g.tags["fracture_faces"][new_frac_face] = True

    # Fracture tips should be on the boundary only.
    if np.any(g_old.tags["tip_faces"]):
        g.tags["tip_faces"] = g.tags["domain_boundary_faces"]

    return g
Example #6
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])
Example #7
0
 def create_1d_from_nodes(nodes):
     # From a set of nodes, create a 1d grid. duplicate nodes are removed
     # and we verify that the nodes are indeed colinear
     assert cg.is_collinear(nodes, tol=tol)
     sort_ind = cg.argsort_point_on_line(nodes, tol=tol)
     n = nodes[:, sort_ind]
     unique_nodes, _, _ = unique_columns_tol(n, tol=tol)
     g = TensorGrid(np.arange(unique_nodes.shape[1]))
     g.nodes = unique_nodes
     g.compute_geometry()
     return g, sort_ind
Example #8
0
 def create_1d_from_nodes(nodes):
     # From a set of nodes, create a 1d grid. duplicate nodes are removed
     # and we verify that the nodes are indeed colinear
     if not pp.geometry_property_checks.points_are_collinear(nodes, tol=tol):
         raise ValueError("Nodes are not colinear")
     sort_ind = pp.map_geometry.sort_points_on_line(nodes, tol=tol)
     n = nodes[:, sort_ind]
     unique_nodes, _, _ = unique_columns_tol(n, tol=tol)
     g = TensorGrid(np.arange(unique_nodes.shape[1]))
     g.nodes = unique_nodes
     g.compute_geometry()
     return g, sort_ind
Example #9
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]))
Example #10
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])
Example #11
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)