Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 28 additions & 31 deletions meshkernel/meshkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,18 +1145,29 @@ def get_splines(

return geometry_list_out

def mesh2d_get_mesh_boundaries_as_polygons(self) -> GeometryList:
"""Retrieves the boundaries of a mesh as a series of separated polygons.
def mesh2d_get_mesh_boundaries_as_polygons(
self, geometry_list: GeometryList
) -> GeometryList:
"""Retrieves the boundaries of a mesh as a series of separated polygons within the selecting polygon.
If the polygon is empty, all the mesh boundaries are retrieved.

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.

Args:
geometry_list (GeometryList): The selecting polygon.

Returns:
GeometryList: The output network boundary polygon.
"""

# Get number of polygon nodes
number_of_polygon_nodes = self._mesh2d_count_mesh_boundaries_as_polygons()
number_of_polygon_nodes = self._mesh2d_count_mesh_boundaries_as_polygons(
geometry_list
)

# Create GeometryList instance
c_geometry_list_in = CGeometryList.from_geometrylist(geometry_list)

# Create GeometryList instance
x_coordinates = np.empty(number_of_polygon_nodes, dtype=np.double)
Expand All @@ -1168,24 +1179,36 @@ def mesh2d_get_mesh_boundaries_as_polygons(self) -> GeometryList:
self._execute_function(
self.lib.mkernel_mesh2d_get_mesh_boundaries_as_polygons,
self._meshkernelid,
byref(c_geometry_list_in),
byref(c_geometry_list_out),
)

return geometry_list_out

def _mesh2d_count_mesh_boundaries_as_polygons(self) -> int:
"""For internal use only.
def _mesh2d_count_mesh_boundaries_as_polygons(
self, geometry_list: GeometryList
) -> int:
"""For internal use only. Retrieves the number of boundaries of a mesh within the selecting polygon.
If the polygon is empty, all the mesh boundaries are considered.

Counts the number of polygon nodes contained in the mesh boundary polygons
computed in function mesh2d_get_mesh_boundaries_as_polygons.

Args:
geometry_list (GeometryList): The selecting polygon.

Returns:
int: The number of polygon nodes.
"""
number_of_polygon_nodes = c_int()

# Create GeometryList instance
c_geometry_list_in = CGeometryList.from_geometrylist(geometry_list)

self._execute_function(
self.lib.mkernel_mesh2d_count_mesh_boundaries_as_polygons,
self._meshkernelid,
byref(c_geometry_list_in),
byref(number_of_polygon_nodes),
)
return number_of_polygon_nodes.value
Expand Down Expand Up @@ -2171,32 +2194,6 @@ def curvilinear_refine(
c_int(refinement),
)

def curvilinear_derefine(
self,
x_lower_left_corner: float,
y_lower_left_corner: float,
x_upper_right_corner: float,
y_upper_right_corner: float,
) -> None:
"""Directional curvilinear grid derefinement.
Additional gridlines are removed perpendicularly to the segment defined by lower_left_corner
and upper_right_corner

Args:
x_lower_left_corner (float): The x coordinate of the lower left corner of the block to refine.
y_lower_left_corner (float): The y coordinate of the lower left corner of the block to refine.
x_upper_right_corner (float): The x coordinate of the upper right corner of the block to refine.
y_upper_right_corner (float): The y coordinate of the upper right corner of the block to refine.
"""
self._execute_function(
self.lib.mkernel_curvilinear_derefine,
self._meshkernelid,
c_double(x_lower_left_corner),
c_double(y_lower_left_corner),
c_double(x_upper_right_corner),
c_double(y_upper_right_corner),
)

def curvilinear_compute_transfinite_from_polygon(
self,
geometry_list: GeometryList,
Expand Down
4 changes: 2 additions & 2 deletions meshkernel/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# MeshKernelPy version
__version__ = "7.0.2"
__version__ = "7.0.3"

# MeshKernel version
__backend_version__ = "7.0.2"
__backend_version__ = "7.0.3"
2 changes: 1 addition & 1 deletion tests/test_curvilinear_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def test_curvilinear_refine_derefine():
assert curvilinear_grid.num_m == 11
assert curvilinear_grid.num_n == 14

mk.curvilinear_derefine(2.299, 4.612, 3.074, 3.684)
mk.curvilinear_refine(2.299, 4.612, 3.074, 3.684, -6)

curvilinear_grid = mk.curvilineargrid_get()

Expand Down
8 changes: 7 additions & 1 deletion tests/test_mesh2d_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,13 @@ def test_mesh2d_get_mesh_boundaries_as_polygons(meshkernel_with_mesh2d: MeshKern

mk = meshkernel_with_mesh2d(2, 2)

mesh_boundary = mk.mesh2d_get_mesh_boundaries_as_polygons()
# Create an empty polygon for selecting all boundaries
x_coordinates = np.empty(0, dtype=np.double)
y_coordinates = np.empty(0, dtype=np.double)
geometry_list_in = GeometryList(x_coordinates, y_coordinates)

mesh_boundary = mk.mesh2d_get_mesh_boundaries_as_polygons(geometry_list_in)

assert_array_equal(
mesh_boundary.x_coordinates,
np.array([0.0, 0.0, 0.0, 1.0, 2.0, 2.0, 2.0, 1.0, 0.0], dtype=np.double),
Expand Down
Loading