def test_two_tessalations_one_with_two_cells(self): # First consists of quad + triangle p1 = [np.array([[0, 1, 1, 0], [0, 0, 1, 1]]), np.array([[0, 1, 0], [1, 1, 2]])] # second is a single triangle p2 = [np.array([[0, 1, 0], [0, 1, 2]])] isect, mappings = pp.intersections.surface_tessalations([p1, p2]) # intersection is split in two known_isect = [ np.array([[0, 1, 0], [0, 1, 1]]), np.array([[0, 1, 0], [1, 1, 2]]), ] self.assertTrue(mappings[0].shape == (2, 2)) # To find the order of triangles in isect relative to the polygons in p1, # we consider the mapping for p1 if mappings[0][0, 0] == 1: self.assertTrue(test_utils.compare_arrays(isect[0], known_isect[0])) self.assertTrue(test_utils.compare_arrays(isect[1], known_isect[1])) self.assertTrue( np.allclose(mappings[0].toarray(), np.array([[1, 0], [0, 1]])) ) else: self.assertTrue(test_utils.compare_arrays(isect[0], known_isect[1])) self.assertTrue(test_utils.compare_arrays(isect[1], known_isect[0])) self.assertTrue( np.allclose(mappings[0].toarray(), np.array([[0, 1], [1, 0]])) ) # p2 is much simpler self.assertTrue(mappings[1].shape == (2, 1)) self.assertTrue(np.allclose(mappings[1].toarray(), np.array([[1], [1]])))
def test_poly_split_by_non_convex_domain_4(self): # Polygon is split into two pieces. The polygon partly extends outside the # bounding box of the domain; there is one point on the domain boundary. # and there are segment crossing the domain bounadry twice. self.setUp() poly = np.array([[-0.1, 1.1, 1.1, -0.1], [0.5, 0.5, 0.5, 0.5], [0.2, 0.2, 0.4, 0.4]]) known_constrained_poly_1 = np.array([[0.0, 0.2, 0.4, 0.0], [0.5, 0.5, 0.5, 0.5], [0.2, 0.2, 0.4, 0.4]]) known_constrained_poly_2 = np.array([[0.8, 1.0, 1.0, 0.6], [0.5, 0.5, 0.5, 0.5], [0.2, 0.2, 0.4, 0.4]]) constrained_poly, inds = pp.constrain_geometry.polygons_by_polyhedron( poly, self.non_convex_polyhedron) self.assertTrue(len(constrained_poly) == 2) self.assertTrue( test_utils.compare_arrays(constrained_poly[0], known_constrained_poly_1) or test_utils.compare_arrays(constrained_poly[0], known_constrained_poly_2)) self.assertTrue( test_utils.compare_arrays(constrained_poly[1], known_constrained_poly_1) or test_utils.compare_arrays(constrained_poly[1], known_constrained_poly_2)) self.assertTrue(np.all(inds == 0))
def test_polyline_two_fractures(self): p = np.array([[0, 0], [1, 1], [2, 2], [4, 4], [5, 5]]) frac_id_1 = 1 frac_id_2 = 2 f = np.hstack(( np.hstack( (frac_id_1 * np.ones(3), frac_id_2 * np.ones(2))).reshape( (-1, 1)), p, )) file_name = "frac.csv" np.savetxt(file_name, f, delimiter=",") network, fid = pp.fracture_importer.network_2d_from_csv( file_name, skip_header=0, polyline=True, return_frac_id=True) known_pts = np.array([[0, 1, 2, 4, 5], [0, 1, 2, 4, 5]]) self.assertTrue(test_utils.compare_arrays(known_pts, network.pts)) known_edges = np.array([[0, 1, 3], [1, 2, 4]]) self.assertTrue(test_utils.compare_arrays(known_edges, network.edges)) self.assertTrue(fid.size == 3) self.assertTrue(np.all(fid[:2] == frac_id_1)) self.assertTrue(np.all(fid[2:] == frac_id_2)) test_utils.delete_file(file_name)
def test_poly_split_by_non_convex_domain(self): self.setUp() # Polygon is split into two pieces. No internal vertexes. poly = np.array([[-1, 2, 2, -1], [0.5, 0.5, 0.5, 0.5], [-1, -1, 0.3, 0.3]]) known_constrained_poly_1 = np.array([[0, 0.3, 0], [0.5, 0.5, 0.5], [0, 0.3, 0.3]]) known_constrained_poly_2 = np.array([[0.7, 1, 1], [0.5, 0.5, 0.5], [0.3, 0.0, 0.3]]) constrained_poly, inds = pp.constrain_geometry.polygons_by_polyhedron( poly, self.non_convex_polyhedron) self.assertTrue(len(constrained_poly) == 2) self.assertTrue( test_utils.compare_arrays(constrained_poly[0], known_constrained_poly_1) or test_utils.compare_arrays(constrained_poly[0], known_constrained_poly_2)) self.assertTrue( test_utils.compare_arrays(constrained_poly[1], known_constrained_poly_1) or test_utils.compare_arrays(constrained_poly[1], known_constrained_poly_2)) self.assertTrue(np.all(inds == 0))
def test_max_num_fracs_keyword(self): p = np.array([[0, 0, 1, 1], [1, 1, 2, 2]]) f = np.hstack((np.arange(2).reshape((-1, 1)), p)) file_name = "frac.csv" np.savetxt(file_name, f, delimiter=",") # First load one fracture only network = pp.fracture_importer.network_2d_from_csv(file_name, skip_header=0, max_num_fracs=1) known_pts = np.array([[0, 1], [0, 1]]) self.assertTrue(test_utils.compare_arrays(known_pts, network.pts)) known_edges = np.array([[0], [1]]) self.assertTrue(test_utils.compare_arrays(known_edges, network.edges)) # Then load no data network = pp.fracture_importer.network_2d_from_csv(file_name, skip_header=0, max_num_fracs=0) self.assertTrue(network.pts.shape == (2, 0)) self.assertTrue(network.edges.shape == (2, 0)) self.assertTrue(network.domain is None) self.assertTrue(network.num_frac == 0) test_utils.delete_file(file_name)
def test_2d_import(self): file_name = "network.csv" known_pts, known_edges = self._2d_network(file_name) network = pp.fracture_importer.network_2d_from_csv(file_name) self.assertTrue(test_utils.compare_arrays(network.pts, known_pts)) self.assertTrue(test_utils.compare_arrays(network.edges, known_edges))
def test_2d_isolated_branch_criterion_network_split(self): file_name = "network.csv" self._2d_network(file_name) network = pp.fracture_importer.network_2d_from_csv(file_name) network = network.split_intersections() macro_network, micro_network = split_network(network, Criterion.isolated) known_edges = np.array([[0, 1, 2, 3, 5, 6, 7, 8], [3, 3, 3, 4, 9, 9, 9, 9]]) known_pts = np.array([ [0.25, 0.75, 0.5, 0.5, 0.5, 0.35, 0.65, 0.5, 0.5, 0.5], [0.25, 0.25, 0.0, 0.25, 0.35, 0.75, 0.75, 1.0, 0.65, 0.75], ]) self.assertTrue(test_utils.compare_arrays(macro_network.pts, known_pts)) self.assertTrue( test_utils.compare_arrays(macro_network.edges, known_edges)) known_edges = np.empty((2, 0)) self.assertTrue(test_utils.compare_arrays(micro_network.pts, known_pts)) self.assertTrue( test_utils.compare_arrays(micro_network.edges, known_edges))
def _verify(self, gb, split, cc, fc, cv, new_cell_volumes, new_fc, num_nodes): # Check that the geometry of a (propagated) GridBucket corresponds to a given # known geometry. gh = gb.grids_of_dimension(gb.dim_max())[0] g = gb.grids_of_dimension(gb.dim_max() - 1)[0] new_cc = gh.face_centers[:, split] if len(split) == 1: new_cc = new_cc.reshape((-1, 1)) cc = np.append(cc, new_cc, axis=1) compare_arrays(g.cell_centers, cc) fc = np.append(fc, new_fc, axis=1) compare_arrays(g.face_centers, fc) cv = np.append(cv, new_cell_volumes) self.assertTrue(np.allclose(g.cell_volumes, cv)) proj = gb.node_props(g)["tangential_normal_projection"] self.assertTrue(proj.normals.shape[1] == g.num_cells) self.assertTrue( np.logical_or(np.all(proj.normals[2] < 0), np.all(proj.normals[2] > 0)) ) hit = np.logical_and(g.face_centers[0] > 1.1, g.face_centers[0] < 1.9) self.assertTrue(np.allclose(g.face_areas[hit], np.sqrt(2))) self.assertTrue(np.allclose(g.face_areas[np.logical_not(hit)], 1)) self.assertTrue(num_nodes == gh.num_nodes) # Return the new geometric fields; these will be needed to validate the next # propagation step. return cc, fc, cv
def test_constrain_to_domain(self): network = pp.FractureNetwork2d(self.p, self.e, self.domain) new_network = network.constrain_to_domain() self.assertTrue(test_utils.compare_arrays(self.p, new_network.pts)) small_network = network.constrain_to_domain(self.small_domain) known_points = np.array([[0, 1.5, 1, 1], [0, 0, 0, 1]]) self.assertTrue(test_utils.compare_arrays(known_points, small_network.pts))
def test_three_parents_four_pairs(self): # Test identification of parallel fractures. # The critical point is that two fractures meet in two intervals self.setUp() p = np.array([[0, 3, 1, 2, 0, 3], [0, 0, 1, 1, 2, 2]]) e = np.array([[0, 2, 4], [1, 3, 5]]) network = pp.FractureNetwork2d(p, e, self.domain) generator = self.generator(network) pairs = generator.parent_pairs self.assertTrue(pairs.size == 6) self.assertTrue(test_utils.compare_arrays(pairs, np.array([[0, 0, 1], [1, 2, 2]]))) i_first = generator.interval_first[(0, 2)][0] self.assertTrue(test_utils.compare_arrays(i_first, np.array([[0, 1], [0, 0]]))) i_sec = generator.interval_second[(0, 2)][0] self.assertTrue(test_utils.compare_arrays(i_sec, np.array([[0, 1], [2, 2]]))) i_first = generator.interval_first[(0, 2)][1] self.assertTrue(test_utils.compare_arrays(i_first, np.array([[2, 3], [0, 0]]))) i_sec = generator.interval_second[(0, 2)][1] self.assertTrue(test_utils.compare_arrays(i_sec, np.array([[2, 3], [2, 2]]))) i_first = generator.interval_first[(0, 1)][0] self.assertTrue(test_utils.compare_arrays(i_first, np.array([[1, 2], [0, 0]]))) i_sec = generator.interval_second[(0, 1)][0] self.assertTrue(test_utils.compare_arrays(i_sec, np.array([[1, 2], [1, 1]]))) i_first = generator.interval_first[(1, 2)][0] self.assertTrue(test_utils.compare_arrays(i_first, np.array([[1, 2], [1, 1]]))) i_sec = generator.interval_second[(1, 2)][0] self.assertTrue(test_utils.compare_arrays(i_sec, np.array([[1, 2], [2, 2]])))
def test_snap_fractures(self): p = np.array([[0, 2, 1, 1], [0, 0, 1e-3, 1]]) e = np.array([[0, 2], [1, 3]]) network = pp.FractureNetwork2d(p, e) snapped = network.snap(tol=1e-2) known_points = np.array([[0, 2, 1, 1], [0, 0, 0, 1]]) self.assertTrue(test_utils.compare_arrays(known_points, snapped.pts)) snapped_2 = network.snap(tol=1e-4) self.assertTrue(test_utils.compare_arrays(p, snapped_2.pts))
def test_add_networks_no_domain(self): network_1 = pp.FractureNetwork2d(self.p, self.e) p2 = np.array([[0, 2, 1, 1], [0, 0, 0, 1]]) + 2 e2 = np.array([[0, 2], [1, 3]]) network_2 = pp.FractureNetwork2d(p2, e2) together = network_1.add_network(network_2) p_known = np.hstack((self.p, p2)) self.assertTrue(test_utils.compare_arrays(p_known, together.pts)) # The known edges has 2 rows, thus by testing for equality, we implicitly # verify there are no tags in the joint network e_known = np.array([[0, 2, 4, 6], [1, 3, 5, 7]]) self.assertTrue(test_utils.compare_arrays(together.edges, e_known))
def test_refinement_single_cell(self): g = self.OneCellGrid() h, parent = refinement.refine_triangle_grid(g) h.compute_geometry() self.assertTrue(h.num_cells == 4) self.assertTrue(h.num_faces == 9) self.assertTrue(h.num_nodes == 6) self.assertTrue(h.cell_volumes.sum() == 0.5) self.assertTrue(np.allclose(h.cell_volumes, 1 / 8)) known_nodes = np.array([[0, 0.5, 1, 0.5, 0, 0], [0, 0, 0, 0.5, 1, 0.5]]) test_utils.compare_arrays(h.nodes[:2], known_nodes) self.assertTrue(np.all(parent == 0))
def test_get_points(self): p = self.p e = self.e network = pp.FractureNetwork2d(p, e) start = network.start_points() self.assertTrue(test_utils.compare_arrays(start, p[:, e[0]])) end = network.end_points() self.assertTrue(test_utils.compare_arrays(end, p[:, e[1]])) # Then index based start = network.start_points(fi=0) self.assertTrue(test_utils.compare_arrays(start, p[:, 0].reshape((-1, 1)))) end = network.end_points(fi=0) self.assertTrue(test_utils.compare_arrays(end, p[:, 1].reshape((-1, 1))))
def test_not_circular_3(self): # The points are not circular, and the isolated points are not contained in the # first column, thus re-arrangement is needed p = np.array([[1, 0], [3, 2], [1, 3]]).T sp = sort_points.sort_point_pairs(p, is_circular=False) truth = np.array([[1, 3], [1, 0], [3, 2]]).T self.assertTrue(test_utils.compare_arrays(sp, truth))
def test_two_intersecting_fractures(self): f_1 = np.array([[-1, 1, 1, -1], [0, 0, 0, 0], [-1, -1, 1, 1]]) f_2 = np.array([[0, 0, 0, 0], [-1, 1, 1, -1], [-0.7, -0.7, 0.8, 0.8]]) new_pt, isect_pt, on_bound, pairs, seg_vert = pp.intersections.polygons_3d( [f_1, f_2]) self.assertTrue(new_pt.shape[1] == 2) self.assertTrue(isect_pt.size == 2) self.assertTrue(np.allclose(np.sort(isect_pt[0]), [0, 1])) self.assertTrue(np.allclose(np.sort(isect_pt[1]), [0, 1])) self.assertTrue(on_bound.size == 2) self.assertTrue(np.all(on_bound[0]) == False) self.assertTrue(np.all(on_bound[1]) == False) known_points = np.array([[0, 0, -0.7], [0, 0, 0.8]]).T self.assertTrue(test_utils.compare_arrays(new_pt, known_points)) self.assertTrue(seg_vert.size == 2) self.assertTrue(len(seg_vert[0]) == 2) for i in range(len(seg_vert[0])): self.assertTrue(len(seg_vert[0][i]) == 0) self.assertTrue(len(seg_vert[1]) == 2) self.assertEqual(seg_vert[1][0], (0, True)) self.assertEqual(seg_vert[1][1], (2, True))
def test_one_pair(self): # Test identification of parallel fractures. # Test should find a single pair self.setUp() p = np.array([[0, 1, 0, 3], [0, 0, 1, 1]]) e = np.array([[0, 2], [1, 3]]) network = pp.FractureNetwork2d(p, e, self.domain) generator = self.generator(network) pairs = generator.parent_pairs self.assertTrue(pairs.size == 2) self.assertTrue(test_utils.compare_arrays(pairs, np.array([[0], [1]]))) i_first = generator.interval_first[(0, 1)][0] self.assertTrue(test_utils.compare_arrays(i_first, np.array([[0, 1], [0, 0]]))) i_sec = generator.interval_second[(0, 1)][0] self.assertTrue(test_utils.compare_arrays(i_sec, np.array([[0, 1], [1, 1]])))
def test_T_intersection_within_polygon(self): """ Two fractures, T-intersection, segment contained within the other polygon. """ f_1 = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]).T f_2 = np.array([[0.5, 0.5, 1], [0.5, 0.5, 0], [0.5, 0.9, 0.0]]).T new_pt, isect_pt, on_bound, _, seg_vert = pp.intersections.polygons_3d( [f_1, f_2]) self.assertTrue(new_pt.shape[1] == 2) self.assertTrue(isect_pt.size == 2) self.assertTrue(len(isect_pt[0]) == 2) self.assertTrue(len(isect_pt[1]) == 2) self.assertTrue(on_bound.size == 2) self.assertTrue(np.sum(on_bound[0]) == 0) self.assertTrue(np.sum(on_bound[1]) == 1) known_points = np.array([[0.5, 0.5, 0], [0.5, 0.9, 0]]).T self.assertTrue(test_utils.compare_arrays(new_pt, known_points)) self.assertEqual(len(seg_vert[0][0]), 0) self.assertEqual(len(seg_vert[0][1]), 0) self.assertEqual(seg_vert[1][0], (1, False)) self.assertEqual(seg_vert[1][1], (2, False))
def test_one_point_in_plane_of_other_fracture_order_reversed(self): """ Two fractures. One has one vertexes in the plane of another fracture """ f_1 = np.array([[-0.5, 0.5, 0.5, -0.5], [-1, -1, 1, 1], [-1, -1, 1, 1]]) f_2 = np.array([[0, 0, 0, 0], [-1, 1, 1, -1], [-1, -1, 2, 1]]) new_pt, isect_pt, on_bound, _, seg_vert = pp.intersections.polygons_3d( [f_2, f_1]) self.assertTrue(new_pt.shape[1] == 2) self.assertTrue(isect_pt.size == 2) self.assertTrue(len(isect_pt[0]) == 2) self.assertTrue(len(isect_pt[1]) == 2) self.assertTrue(on_bound.size == 2) self.assertTrue(np.all(on_bound[0]) == False) self.assertTrue(np.all(on_bound[1]) == False) known_points = np.array([[0, -1, -1], [0, 1, 1]]).T self.assertTrue(test_utils.compare_arrays(new_pt, known_points)) self.assertEqual(seg_vert[1][0], (0, True)) self.assertEqual(seg_vert[1][1], (2, True)) self.assertEqual(seg_vert[0][0], (0, False)) self.assertEqual(seg_vert[0][1], (1, True))
def test_two_fractures(self): # Two fractures, identical coordinates - this will not matter p = np.atleast_2d( np.array([[0, 0, 0, 1, 1, 1, 1, 0, 1], [0, 0, 0, 1, 1, 1, 1, 0, 1]])) file_name = "frac.csv" np.savetxt(file_name, p, delimiter=",") network = pp.fracture_importer.network_3d_from_csv(file_name, has_domain=False) known_p = np.array([[0, 1, 1], [0, 1, 0], [0, 1, 1]]) self.assertTrue(len(network._fractures) == 2) self.assertTrue( test_utils.compare_arrays(known_p, network._fractures[0].p)) self.assertTrue( test_utils.compare_arrays(known_p, network._fractures[1].p))
def test_T_intersection_both_on_boundary(self): """ Two fractures, L-intersection, partly overlapping segments """ f_1 = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]).T f_2 = np.array([[0.5, 0.5, 1], [0.5, 0.0, 0], [0.5, 1.0, 0.0]]).T new_pt, isect_pt, on_bound, _, seg_vert = pp.intersections.polygons_3d( [f_1, f_2]) self.assertTrue(new_pt.shape[1] == 2) self.assertTrue(isect_pt.size == 2) self.assertTrue(len(isect_pt[0]) == 2) self.assertTrue(len(isect_pt[1]) == 2) self.assertTrue(on_bound.size == 2) self.assertTrue(np.sum(on_bound[0]) == 0) self.assertTrue(np.sum(on_bound[1]) == 1) known_points = np.array([[0.5, 0.0, 0], [0.5, 1.0, 0]]).T self.assertTrue(test_utils.compare_arrays(new_pt, known_points)) self.assertEqual(seg_vert[0][0], (0, True)) self.assertEqual(seg_vert[0][1], (2, True)) self.assertEqual(seg_vert[1][0], (1, False)) self.assertEqual(seg_vert[1][1], (2, False))
def test_three_tessalations(self): # First consists of quad + triangle p1 = [ np.array([[0, 1, 1, 0], [0, 0, 1, 1]]), np.array([[0, 1, 0], [1, 1, 2]]) ] # second is a single triangle p2 = [np.array([[0, 1, 0], [0, 1, 2]])] # A third, with a single triangle p3 = [np.array([[0, 1, 0], [0, 0, 1]])] isect, mappings = pp.intersections.surface_tessalations([p1, p2, p3]) self.assertTrue(len(isect) == 1) self.assertTrue( test_utils.compare_arrays(isect[0], np.array([[0, 0.5, 0], [0, 0.5, 1]]))) self.assertTrue(len(mappings) == 3) self.assertTrue(mappings[0].shape == (1, 2)) self.assertTrue(np.allclose(mappings[0].toarray(), np.array([[1, 0]]))) self.assertTrue(mappings[1].shape == (1, 1)) self.assertTrue(np.allclose(mappings[1].toarray(), np.array([[1]]))) self.assertTrue(mappings[2].shape == (1, 1)) self.assertTrue(np.allclose(mappings[2].toarray(), np.array([[1]])))
def test_2d_dummy_criterion(self): file_name = "network.csv" known_pts, known_edges = self._2d_network(file_name) network = pp.fracture_importer.network_2d_from_csv(file_name) macro_network, micro_network = split_network(network, Criterion.none) self.assertTrue(test_utils.compare_arrays(macro_network.pts, known_pts)) self.assertTrue( test_utils.compare_arrays(macro_network.edges, known_edges)) known_edges = np.empty((2, 0)) self.assertTrue(test_utils.compare_arrays(micro_network.pts, known_pts)) self.assertTrue( test_utils.compare_arrays(micro_network.edges, known_edges))
def test_refinement_two_cells(self): g = self.TwoCellsGrid() h, parent = refinement.refine_triangle_grid(g) h.compute_geometry() self.assertTrue(h.num_cells == 8) self.assertTrue(h.num_faces == 16) self.assertTrue(h.num_nodes == 9) self.assertTrue(h.cell_volumes.sum() == 1) self.assertTrue(np.allclose(h.cell_volumes, 1 / 8)) known_nodes = np.array([[0, 0.5, 1, 0.5, 0, 0, 1, 1, 0.5], [0, 0, 0, 0.5, 1, 0.5, 0.5, 1, 1]]) test_utils.compare_arrays(h.nodes[:2], known_nodes) self.assertTrue(np.sum(parent == 0) == 4) self.assertTrue(np.sum(parent == 1) == 4) self.assertTrue(np.allclose(np.bincount(parent, h.cell_volumes), 0.5))
def test_three_pairs(self): # Test identification of parallel fractures. # Test should find pairs between all fractures self.setUp() p = np.array([[0, 2, 1, 3, 0, 2], [0, 0, 1, 1, 2, 2]]) e = np.array([[0, 2, 4], [1, 3, 5]]) network = pp.FractureNetwork2d(p, e, self.domain) generator = self.generator(network) pairs = generator.parent_pairs self.assertTrue(pairs.size == 6) self.assertTrue(test_utils.compare_arrays(pairs, np.array([[0, 0, 1], [1, 2, 2]]))) i_first = generator.interval_first[(0, 2)][0] self.assertTrue(test_utils.compare_arrays(i_first, np.array([[0, 1], [0, 0]]))) i_sec = generator.interval_second[(0, 2)][0] self.assertTrue(test_utils.compare_arrays(i_sec, np.array([[0, 1], [2, 2]]))) i_first = generator.interval_first[(0, 1)][0] self.assertTrue(test_utils.compare_arrays(i_first, np.array([[1, 2], [0, 0]]))) i_sec = generator.interval_second[(0, 1)][0] self.assertTrue(test_utils.compare_arrays(i_sec, np.array([[1, 2], [1, 1]]))) i_first = generator.interval_first[(1, 2)][0] self.assertTrue(test_utils.compare_arrays(i_first, np.array([[1, 2], [1, 1]]))) i_sec = generator.interval_second[(1, 2)][0] self.assertTrue(test_utils.compare_arrays(i_sec, np.array([[1, 2], [2, 2]])))
def test_overlapping_lines(self): p = np.array([[-0.6, 0.4, 0.4, -0.6, 0.4], [-0.5, -0.5, 0.5, 0.5, 0.0]]) lines = np.array([[0, 0, 1, 1, 2], [1, 3, 2, 4, 3]]) new_pts, new_lines = pp.intersections.split_intersecting_segments_2d( p, lines) lines_known = np.array([[0, 1], [0, 3], [1, 4], [2, 4], [2, 3]]).T self.assertTrue(np.allclose(new_pts, p)) self.assertTrue(test_utils.compare_arrays(new_lines, lines_known))
def test_single_fracture(self): p = np.array([0, 0, 1, 1]) f = np.hstack((0, p)) file_name = "frac.csv" np.savetxt(file_name, f, delimiter=",") network = pp.fracture_importer.network_2d_from_csv(file_name, skip_header=0) known_pts = np.array([[0, 1], [0, 1]]) self.assertTrue(test_utils.compare_arrays(known_pts, network.pts)) known_edges = np.array([[0], [1]]) self.assertTrue(test_utils.compare_arrays(known_edges, network.edges)) self.assertTrue(network.domain["xmin"] == 0) self.assertTrue(network.domain["ymin"] == 0) self.assertTrue(network.domain["xmax"] == 1) self.assertTrue(network.domain["ymax"] == 1) test_utils.delete_file(file_name)
def test_polyline_two_branches(self): p = np.array([[0, 0], [1, 1], [2, 2]]) frac_id = 1 f = np.hstack((frac_id * np.ones(3).reshape((-1, 1)), p)) file_name = "frac.csv" np.savetxt(file_name, f, delimiter=",") network, fid = pp.fracture_importer.network_2d_from_csv( file_name, skip_header=0, polyline=True, return_frac_id=True) known_pts = np.array([[0, 1, 2], [0, 1, 2]]) self.assertTrue(test_utils.compare_arrays(known_pts, network.pts)) known_edges = np.array([[0, 1], [1, 2]]) self.assertTrue(test_utils.compare_arrays(known_edges, network.edges)) self.assertTrue(fid.size == 2) self.assertTrue(np.all(fid == frac_id)) test_utils.delete_file(file_name)
def compare_grids(g1, g2): if g1.dim != g2.dim: return False if g1.dim == 0: return np.allclose(g1.cell_centers, g2.cell_centers) n1, n2 = g1.nodes, g2.nodes return test_utils.compare_arrays(n1, n2, sort=False)
def test_2d_isolated_branch_criterion(self): file_name = "network.csv" known_pts, _ = self._2d_network(file_name) network = pp.fracture_importer.network_2d_from_csv(file_name) macro_network, micro_network = split_network(network, Criterion.isolated) known_edges = np.array([[2, 3], [3, 4]]) self.assertTrue(test_utils.compare_arrays(macro_network.pts, known_pts)) self.assertTrue( test_utils.compare_arrays(macro_network.edges, known_edges)) known_edges = np.array([[0, 5, 7], [1, 6, 8]]) self.assertTrue(test_utils.compare_arrays(micro_network.pts, known_pts)) self.assertTrue( test_utils.compare_arrays(micro_network.edges, known_edges))