Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRIDEDIT-1408: Add mesh2d_get_property #187

Merged
merged 10 commits into from
Sep 4, 2024
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
39 changes: 39 additions & 0 deletions meshkernel/meshkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,45 @@ def mesh2d_get_orthogonality(self) -> GeometryList:

return geometry_list_out

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

Args:

property (Mesh2d.Property): The property to retrieve

Returns:
GeometryList: The resulting geometry list containing the value of the properties
"""

c_geometry_list_dimension = c_int()

self._execute_function(
self.lib.mkernel_mesh2d_get_property_dimension,
self._meshkernelid,
c_int(property),
byref(c_geometry_list_dimension),
)

n_coordinates = c_geometry_list_dimension.value
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)

property_list = GeometryList(
x_coordinates=x_coordinates, y_coordinates=y_coordinates, values=values
)
c_property_list = CGeometryList.from_geometrylist(property_list)

self._execute_function(
self.lib.mkernel_mesh2d_get_property,
self._meshkernelid,
c_int(property),
byref(c_property_list),
lucacarniato marked this conversation as resolved.
Show resolved Hide resolved
)

return property_list

def mesh2d_get_smoothness(self):
"""Gets the smoothness, expressed as the ratio between the values of two neighboring faces areas.

Expand Down
1 change: 1 addition & 0 deletions meshkernel/py_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Property(IntEnum):
"""Different properties on a 2D mesh."""

ORTHOGONALITY = 0
EDGE_LENGTHS = 1

def __init__(
self,
Expand Down
99 changes: 93 additions & 6 deletions tests/test_mesh2d_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,16 +446,16 @@ def test_mesh2d_get_node_index_no_node_in_search_radius(
(
True,
DeleteMeshOption.INSIDE_NOT_INTERSECTED,
4,
4,
1,
16,
24,
9,
),
(
True,
DeleteMeshOption.INSIDE_AND_INTERSECTED,
16,
24,
9,
4,
4,
1,
),
(
False,
Expand Down Expand Up @@ -2308,6 +2308,93 @@ def test_mesh2d_deletion_and_get_orthogonality(
assert len(values) == len(mesh2d.edge_x)


cases_get_property = [
(
Mesh2d.Property.ORTHOGONALITY,
np.array(
[
-999.0,
0.0,
0.0,
-999.0,
-999.0,
0.0,
0.0,
-999.0,
-999.0,
0.0,
0.0,
-999.0,
-999.0,
-999.0,
-999.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-999.0,
-999.0,
-999.0,
],
dtype=np.double,
),
),
(
Mesh2d.Property.EDGE_LENGTHS,
np.array(
[
100.0,
100.0,
100.0,
100.0,
100.0,
100.0,
100.0,
100.0,
100.0,
100.0,
100.0,
100.0,
50.0,
50.0,
50.0,
50.0,
50.0,
50.0,
50.0,
50.0,
50.0,
50.0,
50.0,
50.0,
],
dtype=np.double,
),
),
]


@pytest.mark.parametrize(
"property, expected_values",
cases_get_property,
)
def test_mesh2d_get_property(
meshkernel_with_mesh2d: MeshKernel,
property: Mesh2d.Property,
expected_values: ndarray,
):
"""Test mesh2d_get_property,
getting the mesh2d property values
"""
mk = meshkernel_with_mesh2d(rows=3, columns=3, spacing_x=50.0, spacing_y=100.0)

property_list = mk.mesh2d_get_property(property)

assert property_list.values == approx(expected_values, abs=1e-6)


def test_mesh2d_get_filtered_face_polygons():
"""Test mesh2d_get_filtered_face_polygons,
getting the polygons of faces with all edges having bad orthogonality values
Expand Down
10 changes: 1 addition & 9 deletions tests/test_mesh2d_refinement.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import numpy as np
import pytest
from numpy import ndarray

from meshkernel import (
GeometryList,
MakeGridParameters,
Mesh2d,
MeshKernel,
MeshRefinementParameters,
)
from meshkernel import GeometryList, MakeGridParameters, MeshKernel


def test_mesh2d_casulli_refinement():
Expand Down
Loading