Skip to content

Commit e99ac4b

Browse files
committed
Merge branch 'main' into release/v7.0.4
2 parents 7d337ef + c60adec commit e99ac4b

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

meshkernel/meshkernel.py

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,18 +1145,29 @@ def get_splines(
11451145

11461146
return geometry_list_out
11471147

1148-
def mesh2d_get_mesh_boundaries_as_polygons(self) -> GeometryList:
1149-
"""Retrieves the boundaries of a mesh as a series of separated polygons.
1148+
def mesh2d_get_mesh_boundaries_as_polygons(
1149+
self, geometry_list: GeometryList
1150+
) -> GeometryList:
1151+
"""Retrieves the boundaries of a mesh as a series of separated polygons within the selecting polygon.
1152+
If the polygon is empty, all the mesh boundaries are retrieved.
11501153
11511154
For example, if a mesh has an single inner hole, two polygons will be generated,
11521155
one for the inner boundary and one for the outer boundary.
11531156
1157+
Args:
1158+
geometry_list (GeometryList): The selecting polygon.
1159+
11541160
Returns:
11551161
GeometryList: The output network boundary polygon.
11561162
"""
11571163

11581164
# Get number of polygon nodes
1159-
number_of_polygon_nodes = self._mesh2d_count_mesh_boundaries_as_polygons()
1165+
number_of_polygon_nodes = self._mesh2d_count_mesh_boundaries_as_polygons(
1166+
geometry_list
1167+
)
1168+
1169+
# Create GeometryList instance
1170+
c_geometry_list_in = CGeometryList.from_geometrylist(geometry_list)
11601171

11611172
# Create GeometryList instance
11621173
x_coordinates = np.empty(number_of_polygon_nodes, dtype=np.double)
@@ -1168,24 +1179,36 @@ def mesh2d_get_mesh_boundaries_as_polygons(self) -> GeometryList:
11681179
self._execute_function(
11691180
self.lib.mkernel_mesh2d_get_mesh_boundaries_as_polygons,
11701181
self._meshkernelid,
1182+
byref(c_geometry_list_in),
11711183
byref(c_geometry_list_out),
11721184
)
11731185

11741186
return geometry_list_out
11751187

1176-
def _mesh2d_count_mesh_boundaries_as_polygons(self) -> int:
1177-
"""For internal use only.
1188+
def _mesh2d_count_mesh_boundaries_as_polygons(
1189+
self, geometry_list: GeometryList
1190+
) -> int:
1191+
"""For internal use only. Retrieves the number of boundaries of a mesh within the selecting polygon.
1192+
If the polygon is empty, all the mesh boundaries are considered.
11781193
11791194
Counts the number of polygon nodes contained in the mesh boundary polygons
11801195
computed in function mesh2d_get_mesh_boundaries_as_polygons.
11811196
1197+
Args:
1198+
geometry_list (GeometryList): The selecting polygon.
1199+
11821200
Returns:
11831201
int: The number of polygon nodes.
11841202
"""
11851203
number_of_polygon_nodes = c_int()
1204+
1205+
# Create GeometryList instance
1206+
c_geometry_list_in = CGeometryList.from_geometrylist(geometry_list)
1207+
11861208
self._execute_function(
11871209
self.lib.mkernel_mesh2d_count_mesh_boundaries_as_polygons,
11881210
self._meshkernelid,
1211+
byref(c_geometry_list_in),
11891212
byref(number_of_polygon_nodes),
11901213
)
11911214
return number_of_polygon_nodes.value
@@ -2171,32 +2194,6 @@ def curvilinear_refine(
21712194
c_int(refinement),
21722195
)
21732196

2174-
def curvilinear_derefine(
2175-
self,
2176-
x_lower_left_corner: float,
2177-
y_lower_left_corner: float,
2178-
x_upper_right_corner: float,
2179-
y_upper_right_corner: float,
2180-
) -> None:
2181-
"""Directional curvilinear grid derefinement.
2182-
Additional gridlines are removed perpendicularly to the segment defined by lower_left_corner
2183-
and upper_right_corner
2184-
2185-
Args:
2186-
x_lower_left_corner (float): The x coordinate of the lower left corner of the block to refine.
2187-
y_lower_left_corner (float): The y coordinate of the lower left corner of the block to refine.
2188-
x_upper_right_corner (float): The x coordinate of the upper right corner of the block to refine.
2189-
y_upper_right_corner (float): The y coordinate of the upper right corner of the block to refine.
2190-
"""
2191-
self._execute_function(
2192-
self.lib.mkernel_curvilinear_derefine,
2193-
self._meshkernelid,
2194-
c_double(x_lower_left_corner),
2195-
c_double(y_lower_left_corner),
2196-
c_double(x_upper_right_corner),
2197-
c_double(y_upper_right_corner),
2198-
)
2199-
22002197
def curvilinear_compute_transfinite_from_polygon(
22012198
self,
22022199
geometry_list: GeometryList,

tests/test_curvilinear_basics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def test_curvilinear_refine_derefine():
266266
assert curvilinear_grid.num_m == 11
267267
assert curvilinear_grid.num_n == 14
268268

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

271271
curvilinear_grid = mk.curvilineargrid_get()
272272

tests/test_mesh2d_basics.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,13 @@ def test_mesh2d_get_mesh_boundaries_as_polygons(meshkernel_with_mesh2d: MeshKern
11201120

11211121
mk = meshkernel_with_mesh2d(2, 2)
11221122

1123-
mesh_boundary = mk.mesh2d_get_mesh_boundaries_as_polygons()
1123+
# Create an empty polygon for selecting all boundaries
1124+
x_coordinates = np.empty(0, dtype=np.double)
1125+
y_coordinates = np.empty(0, dtype=np.double)
1126+
geometry_list_in = GeometryList(x_coordinates, y_coordinates)
1127+
1128+
mesh_boundary = mk.mesh2d_get_mesh_boundaries_as_polygons(geometry_list_in)
1129+
11241130
assert_array_equal(
11251131
mesh_boundary.x_coordinates,
11261132
np.array([0.0, 0.0, 0.0, 1.0, 2.0, 2.0, 2.0, 1.0, 0.0], dtype=np.double),

0 commit comments

Comments
 (0)