From 5edc65071287af8efcc67c988a10e3ac9104fab2 Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Fri, 27 Oct 2023 12:34:50 +0200 Subject: [PATCH] fixed several testcases --- hydrolib/core/dflowfm/net/models.py | 12 ++++++------ tests/dflowfm/test_net.py | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/hydrolib/core/dflowfm/net/models.py b/hydrolib/core/dflowfm/net/models.py index 534fe8d96..a8d7a6cfa 100644 --- a/hydrolib/core/dflowfm/net/models.py +++ b/hydrolib/core/dflowfm/net/models.py @@ -193,7 +193,7 @@ def create_triangular(self, geometry_list: mk.GeometryList) -> None: geometry_list (mk.GeometryList): GeometryList represeting a polygon within which the mesh is generated. """ # Call meshkernel - self.meshkernel.mesh2d_make_mesh_from_polygon(geometry_list) + self.meshkernel.mesh2d_make_triangular_mesh_from_polygon(geometry_list) # Process new mesh self._process(self.get_mesh2d()) @@ -225,7 +225,7 @@ def _process(self, mesh2d_input) -> None: def clip( self, geometrylist: mk.GeometryList, - deletemeshoption: int = 1, + deletemeshoption: int = 1, #TODO: 1 was changed inside=False, ) -> None: """Clip the 2D mesh by a polygon. Both outside the exterior and inside the interiors is clipped @@ -322,7 +322,7 @@ def refine(self, polygon: mk.GeometryList, level: int): parameters = mk.MeshRefinementParameters( refine_intersected=True, use_mass_center_when_refining=False, - min_face_size=10.0, # Does nothing? + min_edge_size=10.0, # Does nothing? refinement_type=1, # No effect? connect_hanging_nodes=True, account_for_samples_outside_face=False, @@ -635,7 +635,7 @@ def clear(self) -> None: self.link1d2d = np.empty((0, 2), np.int32) # The meshkernel object needs to be resetted self.meshkernel._deallocate_state() - self.meshkernel._allocate_state(self.meshkernel.is_geographic) + self.meshkernel._allocate_state(self.meshkernel.projection) self.meshkernel.contacts_get() def _process(self) -> None: @@ -1110,11 +1110,11 @@ def get_node_mask(self, branchids: List[str] = None): class Network: - def __init__(self, projection: bool = False) -> None: + def __init__(self, projection: mk.ProjectType = mk.ProjectionType.CARTESIAN) -> None: self.meshkernel = mk.MeshKernel(projection=projection) # Monkeypatch the meshkernel object, because the "is_geographic" is not saved # otherwise, and needed for reinitializing the meshkernel - self.meshkernel.projection = projection + # self.meshkernel.projection = projection self._mesh1d = Mesh1d(meshkernel=self.meshkernel) self._mesh2d = Mesh2d(meshkernel=self.meshkernel) diff --git a/tests/dflowfm/test_net.py b/tests/dflowfm/test_net.py index 9801123fd..ca04a4358 100644 --- a/tests/dflowfm/test_net.py +++ b/tests/dflowfm/test_net.py @@ -573,13 +573,13 @@ def test_create_triangular(): ) network.mesh2d_create_triangular_within_polygon(polygon) - + assert np.array_equiv( - network._mesh2d.mesh2d_node_x, + network._mesh2d.mesh2d_node_x, # TODO: array([6., 4., 2., 0., 6., 4., 2., 0.]) np.array([0.0, 6.0, 4.0, 2.0]), ) assert np.array_equiv( - network._mesh2d.mesh2d_node_y, + network._mesh2d.mesh2d_node_y, #TODO: array([2., 7., 6., 0., 2., 7., 6., 0.]) np.array([0.0, 2.0, 7.0, 6.0]), ) assert np.array_equiv( @@ -587,6 +587,16 @@ def test_create_triangular(): np.array([[3, 0], [0, 1], [1, 3], [1, 2], [2, 3]]), ) + #TODO: we end up with more x nodes than before in the network instance (see above) + #when doing this with meshkernel, we get the expected amount of nodes (see below) + #so something is failing in the network class of hydrolib-core + import meshkernel + mk2 = meshkernel.MeshKernel() + mk2.mesh2d_make_triangular_mesh_from_polygon(polygon) + mesh2d_obj = mk2.mesh2d_get() + print(mesh2d_obj.node_x) # [6. 4. 2. 0.] + print(mesh2d_obj.node_y) # [2. 7. 6. 0.] + def test_add_1d2d_links():