Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacarniato committed Sep 2, 2024
1 parent 62f79e6 commit d57e40b
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 7 deletions.
5 changes: 4 additions & 1 deletion meshkernel/meshkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1620,20 +1620,23 @@ def mesh2d_get_property(self, property: Mesh2d.Property) -> GeometryList:
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
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),
)

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

ORTHOGONALITY = (0,)
ORTHOGONALITY = 0,
EDGE_LENGTHS = 1

def __init__(
Expand Down
87 changes: 87 additions & 0 deletions tests/test_mesh2d_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2305,3 +2305,90 @@ def test_mesh2d_deletion_and_get_orthogonality(
values = values_at_locations_functions(mk).values
mesh2d = mk.mesh2d_get()
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(
[
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.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 orthogonality values
"""
mk = meshkernel_with_mesh2d(3, 3)

property_list = mk.mesh2d_get_property(property)

assert property_list.values == approx(expected_values, abs=1e-6)
6 changes: 1 addition & 5 deletions tests/test_mesh2d_refinement.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import numpy as np
import pytest
from numpy import ndarray

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


Expand Down

0 comments on commit d57e40b

Please sign in to comment.