Esempio n. 1
0
    def test_merge_mat_split_columns_same_pos(self):
        # Test slicing of csr_matrix
        A = sps.csc_matrix(np.array([[0, 0, 0], [1, 0, 0], [0, 0, 3]]))

        B = sps.csc_matrix(np.array([[0, 2], [3, 1], [1, 0]]))

        A_t = sps.csc_matrix(np.array([[2, 0, 0], [1, 0, 0], [0, 0, 3]]))
        try:
            sparse_mat.merge_matrices(A, B, np.array([0, 0], dtype=np.int))
        except ValueError:
            pass
Esempio n. 2
0
    def test_merge_mat_rows(self):
        # Test slicing of csr_matrix
        A = sps.csr_matrix(np.array([[0, 0, 0], [1, 0, 0], [0, 0, 3]]))

        B = sps.csr_matrix(np.array([[0, 2, 2], [3, 1, 3]]))

        A_t = sps.csr_matrix(np.array([[0, 2, 2], [3, 1, 3], [0, 0, 3]]))

        sparse_mat.merge_matrices(A, B, np.array([0, 1], dtype=np.int))

        self.assertTrue(np.sum(A != A_t) == 0)
Esempio n. 3
0
    def test_merge_mat_columns(self):
        # Test slicing of csr_matrix
        A = sps.csc_matrix(np.array([[0, 0, 0],
                                     [1, 0, 0],
                                     [0, 0, 3]]))

        B = sps.csc_matrix(np.array([[0, 2],
                                     [3, 1],
                                     [1, 0]]))

        A_t = sps.csc_matrix(np.array([[0, 0, 2],
                                       [1, 3, 1],
                                       [0, 1, 0]]))

        sparse_mat.merge_matrices(A, B, np.array([1, 2], dtype=np.int))

        assert np.sum(A != A_t) == 0
Esempio n. 4
0
def update_cell_connectivity(g: pp.Grid, face_id: np.ndarray,
                             normal: np.ndarray, x0: np.ndarray) -> int:
    """
    After the faces in a grid are duplicated, we update the cell connectivity
    list. Cells on the right side of the fracture do not change, but the cells
    on the left side are attached to the face duplicates. We assume that all
    faces that have been duplicated lie in the same plane. This plane is
    described by a normal and a point, x0. We attach cell on the left side of
    the plane to the duplicate of face_id. The cell on the right side is
    attached to the face frac_id.

    Parameters:
    ----------
    g         - The grid for wich the cell_face mapping is uppdated
    frac_id   - Indices of the faces that have been duplicated
    normal    - Normal of faces that have been duplicated. Note that we assume
                that all faces have the same normal
    x0        - A point in the plane where the faces lie

    Returns:
    ----------
    int: Flag that informs on what action has been taken. 0 means g.cell_faces has been
        split. -1 means the fracture was on the boundary, and no action taken.

    Raises:
    ----------
    ValueError: If the fracture is not planar

    """

    # We find the cells attached to the tagged faces.
    g.cell_faces = g.cell_faces.tocsr()
    cell_frac = g.cell_faces[face_id, :]
    cell_face_id = np.argwhere(cell_frac)

    # We devide the cells into the cells on the right side of the fracture
    # and cells on the left side of the fracture.
    left_cell = half_space_int(normal, x0, g.cell_centers[:, cell_face_id[:,
                                                                          1]])

    if np.all(left_cell) or not np.any(left_cell):
        # Fracture is on boundary of domain. There is nothing to do.
        # Remove the extra faces. We have not yet updated cell_faces,
        # so we should not delete anything from this matrix.
        rem = np.arange(g.cell_faces.shape[0], g.num_faces)
        remove_faces(g, rem, rem_cell_faces=False)
        return -1

    # Assume that fracture is either on boundary (above case) or completely
    # innside domain. Check that each face added two cells:
    if sum(left_cell) * 2 != left_cell.size:
        raise ValueError("Fractures must either be"
                         "on boundary or completely innside domain")

    # We create a cell_faces mapping for the new faces. This will be added
    # on the end of the excisting cell_faces mapping. We have here assumed
    # that we do not add any mapping during the duplication of faces.
    col = cell_face_id[left_cell, 1]
    row = cell_face_id[left_cell, 0]
    data = np.ravel(g.cell_faces[np.ravel(face_id[row]), col])
    assert data.size == face_id.size
    cell_frac_left = sps.csr_matrix((data, (row, col)),
                                    (face_id.size, g.cell_faces.shape[1]))

    # We now update the cell_faces map of the faces on the right side of
    # the fracture. These faces should only be attached to the right cells.
    # We therefore remove their connection to the cells on the left side of
    # the fracture.
    col = cell_face_id[~left_cell, 1]
    row = cell_face_id[~left_cell, 0]
    data = np.ravel(g.cell_faces[np.ravel(face_id[row]), col])
    cell_frac_right = sps.csr_matrix((data, (row, col)),
                                     (face_id.size, g.cell_faces.shape[1]))

    assert g.cell_faces.getformat() == "csr"

    sparse_mat.merge_matrices(g.cell_faces, cell_frac_right, face_id)

    # And then we add the new left-faces to the cell_face map. We do not
    # change the sign of the matrix since we did not flip the normals.
    # This means that the normals of right and left cells point in the same
    # direction, but their cell_faces values have oposite signs.
    sparse_mat.stack_mat(g.cell_faces, cell_frac_left)
    g.cell_faces = g.cell_faces.tocsc()

    return 0