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
1 change: 1 addition & 0 deletions meshkernel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Mesh1d,
Mesh2d,
Mesh2dLocation,
Mesh2dProperty,
MeshRefinementParameters,
OrthogonalizationParameters,
ProjectionType,
Expand Down
31 changes: 16 additions & 15 deletions meshkernel/meshkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
Mesh1d,
Mesh2d,
Mesh2dLocation,
Mesh2dProperty,
MeshRefinementParameters,
OrthogonalizationParameters,
ProjectionType,
Expand Down Expand Up @@ -515,13 +516,13 @@ def mesh2d_get_face_polygons(self, num_edges: int) -> GeometryList:
return face_polygons

def mesh2d_get_filtered_face_polygons(
self, property: Mesh2d.Property, min_value: float, max_value: float
self, property: Mesh2dProperty, min_value: float, max_value: float
) -> GeometryList:
"""Gets the polygons matching the metric value within the minimum and maximum value.

Args:

property (Mesh2d.Property): The property used to filter the locations
property (Mesh2dProperty): The property used to filter the locations
min_value(float): The minimum value of the metric.
max_value(float): The maximum value of the metric.

Expand Down Expand Up @@ -1657,20 +1658,20 @@ def mesh2d_casulli_derefinement_on_polygon(
byref(c_polygon),
)

def mkernel_delete_property(self, propertyId: int):
def mesh2d_delete_property(self, property_id: int):
"""
Deletes a property and its calculator.
Args:
propertyId (int): The property id.
property_id (int): The property id.
"""

self._execute_function(
self.lib.mkernel_deallocate_property,
self._meshkernelid,
c_int(propertyId),
c_int(property_id),
)

def mkernel_set_property(
def mesh2d_set_property(
self,
interpolation_parameters: InterpolationParameters,
sample_data: GeometryList,
Expand All @@ -1691,29 +1692,29 @@ def mkernel_set_property(
)
c_sample_data = CGeometryList.from_geometrylist(sample_data)

propertyId = c_int()
property_id = c_int()
self._execute_function(
self.lib.mkernel_mesh2d_set_property,
self._meshkernelid,
byref(c_interpolation_parameters),
byref(c_sample_data),
byref(propertyId),
byref(property_id),
)

return propertyId.value
return property_id.value

def mkernel_mesh2d_casulli_refinement_based_on_depths(
def mesh2d_casulli_refinement_based_on_depths(
self,
polygons: GeometryList,
propertyId: int,
property_id: int,
meshRefinementParameters: MeshRefinementParameters,
minimumRefinementDepth: float,
) -> None:
"""
Refine mesh using the Casulli refinement algorithm based on the depth values.
Args:
polygons (GeometryList): The polygon within which the refinement is computed.
propertyId (int): The identifier of the interpolator to be used.
property_id (int): The identifier of the interpolator to be used.
meshRefinementParameters (MeshRefinementParameters): Parameters indicating how the mesh is to be refined.
minimumRefinementDepth (float): Nodes with depth value less than this value will not be marked for refinement.
"""
Expand All @@ -1726,7 +1727,7 @@ def mkernel_mesh2d_casulli_refinement_based_on_depths(
self.lib.mkernel_mesh2d_casulli_refinement_based_on_depths,
self._meshkernelid,
byref(c_polygons),
c_int(propertyId),
c_int(property_id),
byref(c_refinement_params),
c_double(minimumRefinementDepth),
)
Expand Down Expand Up @@ -1821,12 +1822,12 @@ def mesh2d_get_orthogonality(self) -> GeometryList:
return geometry_list_out

def mesh2d_get_property(
self, mesh2d_location: Mesh2dLocation, property: Mesh2d.Property
self, mesh2d_location: Mesh2dLocation, property: Mesh2dProperty
) -> GeometryList:
"""Gets the polygons matching the metric value within the minimum and maximum value.
Args:
mesh2d_location (Mesh2dLocation): The property location
property (Mesh2d.Property): The property to retrieve
property (Mesh2dProperty): The property to retrieve
Returns:
GeometryList: The resulting geometry list containing the value of the properties
"""
Expand Down
21 changes: 11 additions & 10 deletions meshkernel/py_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ class Mesh2dLocation(IntEnum):
EDGES = 2


@unique
class Mesh2dProperty(IntEnum):
"""Different properties on a 2D mesh."""

ORTHOGONALITY = 0
EDGE_LENGTHS = 1
FACE_CIRCUMCENTER = 2
NETLINK_CONTOUR_POLYGON = 3
FACE_BOUNDS = 4


@unique
class AveragingMethod(IntEnum):
"""The averaging methods."""
Expand Down Expand Up @@ -126,16 +137,6 @@ class Mesh2d:

"""

@unique
class Property(IntEnum):
"""Different properties on a 2D mesh."""

ORTHOGONALITY = 0
EDGE_LENGTHS = 1
FACE_CIRCUMCENTER = 2
NETLINK_CONTOUR_POLYGON = 3
FACE_BOUNDS = 4

def __init__(
self,
node_x=np.empty(0, dtype=np.double),
Expand Down
23 changes: 12 additions & 11 deletions tests/test_mesh2d_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
MakeGridParameters,
Mesh2d,
Mesh2dLocation,
Mesh2dProperty,
MeshKernel,
MeshKernelError,
MeshRefinementParameters,
Expand Down Expand Up @@ -2342,7 +2343,7 @@ def test_mesh2d_deletion_and_get_orthogonality(

cases_get_property = [
(
Mesh2d.Property.ORTHOGONALITY,
Mesh2dProperty.ORTHOGONALITY,
Mesh2dLocation.EDGES,
np.array(
[
Expand Down Expand Up @@ -2375,7 +2376,7 @@ def test_mesh2d_deletion_and_get_orthogonality(
),
),
(
Mesh2d.Property.EDGE_LENGTHS,
Mesh2dProperty.EDGE_LENGTHS,
Mesh2dLocation.EDGES,
np.array(
[
Expand Down Expand Up @@ -2416,7 +2417,7 @@ def test_mesh2d_deletion_and_get_orthogonality(
)
def test_mesh2d_get_property(
meshkernel_with_mesh2d: MeshKernel,
property: Mesh2d.Property,
property: Mesh2dProperty,
location: Mesh2dLocation,
expected_values: ndarray,
):
Expand Down Expand Up @@ -2449,7 +2450,7 @@ def test_mesh2d_get_circumcentre_property():
mk.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
mk.curvilinear_convert_to_mesh2d()

property = Mesh2d.Property.FACE_CIRCUMCENTER
property = Mesh2dProperty.FACE_CIRCUMCENTER
location = Mesh2dLocation.FACES
property_list = mk.mesh2d_get_property(location, property)

Expand Down Expand Up @@ -2479,7 +2480,7 @@ def test_mesh2d_get_netlink_countour_polygon_property():
mk.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
mk.curvilinear_convert_to_mesh2d()

property = Mesh2d.Property.NETLINK_CONTOUR_POLYGON
property = Mesh2dProperty.NETLINK_CONTOUR_POLYGON
location = Mesh2dLocation.EDGES

property_list = mk.mesh2d_get_property(location, property)
Expand All @@ -2505,7 +2506,7 @@ def test_mesh2d_get_filtered_face_polygons():
mk.mesh2d_set(input_mesh2d)

face_polygons = mk.mesh2d_get_filtered_face_polygons(
Mesh2d.Property.ORTHOGONALITY, 0.04, 1.0
Mesh2dProperty.ORTHOGONALITY, 0.04, 1.0
)

expected_coordinates_x = np.array([57.0, 49.1, 58.9, 66.7, 57.0], dtype=np.double)
Expand All @@ -2531,11 +2532,11 @@ def test_mesh2d_get_filtered_face_polygons_full_and_empty():
mk.curvilinear_convert_to_mesh2d()

orthogonality = mk.mesh2d_get_filtered_face_polygons(
Mesh2d.Property.ORTHOGONALITY, 0.0, 1.0
Mesh2dProperty.ORTHOGONALITY, 0.0, 1.0
)
assert orthogonality.x_coordinates.shape[0] == 503
orthogonality = mk.mesh2d_get_filtered_face_polygons(
Mesh2d.Property.ORTHOGONALITY, 0.1, 10.0
Mesh2dProperty.ORTHOGONALITY, 0.1, 10.0
)
assert orthogonality.x_coordinates.shape[0] == 0

Expand Down Expand Up @@ -2577,7 +2578,7 @@ def test_mesh2d_casulli_refinement_based_on_depths():

interpolationParameters = InterpolationParameters()

property_id = mk.mkernel_set_property(interpolationParameters, samples)
property_id = mk.mesh2d_set_property(interpolationParameters, samples)

polygons = GeometryList(
x_coordinates=np.empty(0, dtype=np.double),
Expand All @@ -2586,10 +2587,10 @@ def test_mesh2d_casulli_refinement_based_on_depths():

meshRefinementParameters = MeshRefinementParameters()
minimumRefinementDepth = 0.0
mk.mkernel_mesh2d_casulli_refinement_based_on_depths(
mk.mesh2d_casulli_refinement_based_on_depths(
polygons, property_id, meshRefinementParameters, minimumRefinementDepth
)
mk.mkernel_delete_property(property_id)
mk.mesh2d_delete_property(property_id)
mesh2d_refined = mk.mesh2d_get()

# new mesh has more nodes and edges than the starting mesh, it has been refined
Expand Down
1 change: 1 addition & 0 deletions tests/test_py_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
GeometryList,
Mesh2d,
Mesh2dLocation,
Mesh2dProperty,
MeshRefinementParameters,
OrthogonalizationParameters,
ProjectToLandBoundaryOption,
Expand Down
Loading