def _create_embedded_2d_grid(loc_coord, glob_id): """ Create a 2d grid that is embedded in a 3d grid. """ loc_center = np.mean(loc_coord, axis=1).reshape((-1, 1)) loc_coord -= loc_center # Check that the points indeed form a line assert pp.geometry_property_checks.points_are_planar(loc_coord) # Find the tangent of the line # Projection matrix rot = pp.map_geometry.project_plane_matrix(loc_coord) loc_coord_2d = rot.dot(loc_coord) # The points are now 2d along two of the coordinate axis, but we # don't know which yet. Find this. sum_coord = np.sum(np.abs(loc_coord_2d), axis=1) active_dimension = np.logical_not(np.isclose(sum_coord, 0)) # Check that we are indeed in 2d assert np.sum(active_dimension) == 2 # Sort nodes, and create grid coord_2d = loc_coord_2d[active_dimension] sort_ind = np.lexsort((coord_2d[0], coord_2d[1])) sorted_coord = coord_2d[:, sort_ind] sorted_coord = np.round(sorted_coord * 1e10) / 1e10 unique_x = np.unique(sorted_coord[0]) unique_y = np.unique(sorted_coord[1]) # assert unique_x.size == unique_y.size g = structured.TensorGrid(unique_x, unique_y) assert np.all(g.nodes[0:2] - sorted_coord == 0) # Project back to active dimension nodes = np.zeros(g.nodes.shape) nodes[active_dimension] = g.nodes[0:2] g.nodes = nodes # Project back again to 3d coordinates irot = rot.transpose() g.nodes = irot.dot(g.nodes) g.nodes += loc_center # Add mapping to global point numbers g.global_point_ind = glob_id[sort_ind] return g
def create_embedded_line_grid(loc_coord, glob_id, tol=1e-4): loc_center = np.mean(loc_coord, axis=1).reshape((-1, 1)) sorted_coord, rot, active_dimension, sort_ind = pp.map_geometry.project_points_to_line( loc_coord, tol) g = structured.TensorGrid(sorted_coord) # Project back to active dimension nodes = np.zeros(g.nodes.shape) nodes[active_dimension] = g.nodes[0] g.nodes = nodes # Project back again to 3d coordinates irot = rot.transpose() g.nodes = irot.dot(g.nodes) g.nodes += loc_center # Add mapping to global point numbers g.global_point_ind = glob_id[sort_ind] return g
def create_embedded_line_grid(loc_coord, glob_id, tol=1e-4): loc_center = np.mean(loc_coord, axis=1).reshape((-1, 1)) loc_coord -= loc_center # Check that the points indeed form a line if not cg.is_collinear(loc_coord, tol): raise ValueError("Elements are not colinear") # Find the tangent of the line tangent = cg.compute_tangent(loc_coord) # Projection matrix rot = cg.project_line_matrix(loc_coord, tangent) loc_coord_1d = rot.dot(loc_coord) # The points are now 1d along one of the coordinate axis, but we # don't know which yet. Find this. sum_coord = np.sum(np.abs(loc_coord_1d), axis=1) sum_coord /= np.amax(sum_coord) active_dimension = np.logical_not( np.isclose(sum_coord, 0, atol=tol, rtol=0)) # Check that we are indeed in 1d assert np.sum(active_dimension) == 1 # Sort nodes, and create grid coord_1d = loc_coord_1d[active_dimension] sort_ind = np.argsort(coord_1d)[0] sorted_coord = coord_1d[0, sort_ind] g = structured.TensorGrid(sorted_coord) # Project back to active dimension nodes = np.zeros(g.nodes.shape) nodes[active_dimension] = g.nodes[0] g.nodes = nodes # Project back again to 3d coordinates irot = rot.transpose() g.nodes = irot.dot(g.nodes) g.nodes += loc_center # Add mapping to global point numbers g.global_point_ind = glob_id[sort_ind] return g