def mesh2d_get_mesh_boundaries_as_polygons(self) -> GeometryList: """Retrieves the boundaries of a mesh as a series of separated polygons. For example, if a mesh has an single inner hole, two polygons will be generated, one for the inner boundary and one for the outer boundary. Returns: GeometryList: The output network boundary polygon. """ # Get number of polygon nodes number_of_polygon_nodes = self._mesh2d_count_mesh_boundaries_as_polygons( ) # Create GeometryList instance x_coordinates = np.empty(number_of_polygon_nodes, dtype=np.double) y_coordinates = np.empty(number_of_polygon_nodes, dtype=np.double) geometry_list_out = GeometryList(x_coordinates, y_coordinates) # Get mesh boundary c_geometry_list_out = CGeometryList.from_geometrylist( geometry_list_out) self._execute_function( self.lib.mkernel_mesh2d_get_mesh_boundaries_as_polygons, self._meshkernelid, byref(c_geometry_list_out), ) return geometry_list_out
def mesh2d_get_small_flow_edge_centers( self, small_flow_edges_length_threshold: float) -> GeometryList: """Gets the small mesh2d flow edges centers. The flow edges are the edges connecting face circumcenters. Args: small_flow_edges_length_threshold (float): The configurable length for detecting a small flow edge. Returns: int: The geometry list with the small flow edge center coordinates. """ n_small_flow_edge_centers = self._mesh2d_count_small_flow_edge_centers( small_flow_edges_length_threshold) x_coordinates = np.empty(n_small_flow_edge_centers, dtype=np.double) y_coordinates = np.empty(n_small_flow_edge_centers, dtype=np.double) geometry_list = GeometryList(x_coordinates, y_coordinates) c_geometry_list = CGeometryList.from_geometrylist(geometry_list) self._execute_function( self.lib.mkernel_mesh2d_get_small_flow_edge_centers, self._meshkernelid, c_double(small_flow_edges_length_threshold), byref(c_geometry_list), ) return geometry_list
def polygon_refine( self, polygon: GeometryList, first_node: int, second_node: int, target_edge_length: float, ) -> GeometryList: """Refines the polygon perimeter between two nodes. This interval is refined to achieve a target edge length. Args: polygon (GeometryList): The input polygon to refine. first_node (int): The first index of the refinement interval. second_node (int): The second index of the refinement interval. target_edge_length (float): The target interval edge length. Returns: int: The refined polygon. """ c_polygon = CGeometryList.from_geometrylist(polygon) c_n_polygon_nodes = c_int() self._execute_function( self.lib.mkernel_polygon_count_refine, self._meshkernelid, byref(c_polygon), c_int(first_node), c_int(second_node), c_double(target_edge_length), byref(c_n_polygon_nodes), ) n_coordinates = c_n_polygon_nodes.value x_coordinates = np.empty(n_coordinates, dtype=np.double) y_coordinates = np.empty(n_coordinates, dtype=np.double) refined_polygon = GeometryList(x_coordinates, y_coordinates) c_refined_polygon = CGeometryList.from_geometrylist(refined_polygon) self._execute_function( self.lib.mkernel_polygon_refine, self._meshkernelid, byref(c_polygon), c_int(first_node), c_int(second_node), c_double(target_edge_length), byref(c_refined_polygon), ) return refined_polygon
def mesh2d_averaging_interpolation( self, samples: GeometryList, location_type: Mesh2dLocation, averaging_method: AveragingMethod, relative_search_size: float, min_samples: int, ) -> GeometryList: """Performs averaging interpolation of samples. Args: samples (GeometryList): The samples to interpolate. location_type (Mesh2dLocation): The location type on which to interpolate. averaging_method (AveragingMethod): The averaging method. relative_search_size (float): The relative search size. min_samples (int): The minimum number of samples used for some interpolation algorithms to perform a valid interpolation. Returns: GeometryList: The interpolated samples. """ c_samples = CGeometryList.from_geometrylist(samples) number_of_coordinates = c_samples.n_coordinates x_coordinates = np.empty(number_of_coordinates, dtype=np.double) y_coordinates = np.empty(number_of_coordinates, dtype=np.double) values = np.empty(number_of_coordinates, dtype=np.double) interpolated_samples = GeometryList(x_coordinates, y_coordinates, values) c_interpolated_samples = CGeometryList.from_geometrylist( interpolated_samples) self._execute_function( self.lib.mkernel_mesh2d_averaging_interpolation, self._meshkernelid, byref(c_samples), c_int(location_type), c_int(averaging_method), c_double(relative_search_size), c_size_t(min_samples), byref(c_interpolated_samples), ) return interpolated_samples
def mesh2d_get_obtuse_triangles_mass_centers(self) -> GeometryList: """Gets the mass centers of obtuse mesh2d triangles. Obtuse triangles are those having one angle larger than 90°. Returns: GeometryList: The geometry list with the mass center coordinates. """ n_obtuse_triangles = self._mesh2d_count_obtuse_triangles() x_coordinates = np.empty(n_obtuse_triangles, dtype=np.double) y_coordinates = np.empty(n_obtuse_triangles, dtype=np.double) geometry_list = GeometryList(x_coordinates, y_coordinates) c_geometry_list = CGeometryList.from_geometrylist(geometry_list) self._execute_function( self.lib.mkernel_mesh2d_get_obtuse_triangles_mass_centers, self._meshkernelid, byref(c_geometry_list), ) return geometry_list
def mesh2d_get_smoothness(self): """Gets the smoothness, expressed as the ratio between the values of two neighboring faces areas. Returns: GeometryList: The geometry list with the smoothness values of each edge. """ number_of_coordinates = self._mesh2d_get_dimensions().num_edges x_coordinates = np.empty(number_of_coordinates, dtype=np.double) y_coordinates = np.empty(number_of_coordinates, dtype=np.double) values = np.empty(number_of_coordinates, dtype=np.double) geometry_list_out = GeometryList(x_coordinates, y_coordinates, values) c_geometry_list_out = CGeometryList.from_geometrylist( geometry_list_out) self._execute_function( self.lib.mkernel_mesh2d_get_smoothness, self._meshkernelid, byref(c_geometry_list_out), ) return geometry_list_out
def get_splines(self, geometry_list: GeometryList, number_of_points_between_nodes: int) -> GeometryList: """Get the computed spline points between two corner nodes. Args: geometry_list (GeometryList): The input corner nodes of the splines. number_of_points_between_nodes (int): The number of spline points to generate between two corner nodes. Returns: GeometryList: The output spline. """ # Allocate space for output original_number_of_coordinates = geometry_list.x_coordinates.size number_of_coordinates = ( original_number_of_coordinates * number_of_points_between_nodes - number_of_points_between_nodes + original_number_of_coordinates + 1) x_coordinates = np.empty(number_of_coordinates, dtype=np.double) y_coordinates = np.empty(number_of_coordinates, dtype=np.double) values = np.empty(number_of_coordinates, dtype=np.double) geometry_list_out = GeometryList(x_coordinates, y_coordinates, values) # Convert to CGeometryList c_geometry_list_in = CGeometryList.from_geometrylist(geometry_list) c_geometry_list_out = CGeometryList.from_geometrylist( geometry_list_out) self._execute_function( self.lib.mkernel_get_splines, byref(c_geometry_list_in), byref(c_geometry_list_out), c_int(number_of_points_between_nodes), ) return geometry_list_out
def polygon_get_included_points( self, selecting_polygon: GeometryList, selected_polygon: GeometryList) -> GeometryList: """Selects the polygon points within another polygon. Args: selecting_polygon (GeometryList): The selection polygon. selected_polygon (GeometryList): The polygon of which to get the selected points. Returns: GeometryList: The selection result. The selected points are contained in the values array of the returned GeometryList (0.0 not selected, 1.0 selected). """ c_selecting_polygon = CGeometryList.from_geometrylist( selecting_polygon) c_selected_polygon = CGeometryList.from_geometrylist(selected_polygon) n_coordinates = selected_polygon.x_coordinates.size x_coordinates = np.empty(n_coordinates, dtype=np.double) y_coordinates = np.empty(n_coordinates, dtype=np.double) values = np.empty(n_coordinates, dtype=np.double) selection = GeometryList(x_coordinates, y_coordinates, values) c_selection = CGeometryList.from_geometrylist(selection) self._execute_function( self.lib.mkernel_polygon_get_included_points, self._meshkernelid, byref(c_selecting_polygon), byref(c_selected_polygon), byref(c_selection), ) return selection
def mesh2d_triangulation_interpolation( self, samples: GeometryList, location_type: Mesh2dLocation, ) -> GeometryList: """Performs triangulation interpolation of samples. Args: samples (GeometryList): The samples to interpolate. location_type (Mesh2dLocation): The location type on which to interpolate. Returns: GeometryList: The interpolated samples. """ c_samples = CGeometryList.from_geometrylist(samples) number_of_coordinates = c_samples.n_coordinates x_coordinates = np.empty(number_of_coordinates, dtype=np.double) y_coordinates = np.empty(number_of_coordinates, dtype=np.double) values = np.empty(number_of_coordinates, dtype=np.double) interpolated_samples = GeometryList(x_coordinates, y_coordinates, values) c_interpolated_samples = CGeometryList.from_geometrylist( interpolated_samples) self._execute_function( self.lib.mkernel_mesh2d_triangulation_interpolation, self._meshkernelid, byref(c_samples), c_int(location_type), byref(c_interpolated_samples), ) return interpolated_samples
def mesh2d_get_orthogonality(self) -> GeometryList: """Gets the mesh orthogonality, expressed as the ratio between the edges and the segments connecting the face circumcenters. Returns: GeometryList: The geometry list with the orthogonality values of each edge. """ number_of_coordinates = self._mesh2d_get_dimensions().num_edges x_coordinates = np.empty(number_of_coordinates, dtype=np.double) y_coordinates = np.empty(number_of_coordinates, dtype=np.double) values = np.empty(number_of_coordinates, dtype=np.double) geometry_list_out = GeometryList(x_coordinates, y_coordinates, values) c_geometry_list_out = CGeometryList.from_geometrylist( geometry_list_out) self._execute_function( self.lib.mkernel_mesh2d_get_orthogonality, self._meshkernelid, byref(c_geometry_list_out), ) return geometry_list_out