Skip to content

Commit

Permalink
fixed several testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Oct 27, 2023
1 parent 4a2846d commit 5edc650
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
12 changes: 6 additions & 6 deletions hydrolib/core/dflowfm/net/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 13 additions & 3 deletions tests/dflowfm/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,20 +573,30 @@ 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(
network._mesh2d.mesh2d_edge_nodes,
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():

Expand Down

0 comments on commit 5edc650

Please sign in to comment.