Skip to content

Commit

Permalink
cleanup and additional testing
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Oct 31, 2023
1 parent a08cd43 commit 0e43351
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
1 change: 0 additions & 1 deletion hydrolib/core/dflowfm/net/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def _init_2dmesh(self, ncfile: nc.Dataset, mesh2d: Mesh2d) -> None: # type: ign
"max_nmesh2d_face_nodes", mesh2d.mesh2d_face_nodes.shape[1]
)
mesh2d_output = mesh2d.get_mesh2d()
print(mesh2d.mesh2d_edge_nodes.shape[0])
ncfile.createDimension("mesh2d_nEdges", mesh2d.mesh2d_edge_nodes.shape[0])
ncfile.createDimension("mesh2d_nFaces", mesh2d.mesh2d_face_nodes.shape[0])
ncfile.createDimension("mesh2d_nNodes", mesh2d_output.node_x.size)
Expand Down
25 changes: 21 additions & 4 deletions tests/dflowfm/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,30 @@ def test_create_1d_2d_1d2d():
network_link1d2d = network._link1d2d.link1d2d
network_con_m1d = network._link1d2d.meshkernel.contacts_get().mesh1d_indices
network_con_m2d = network._link1d2d.meshkernel.contacts_get().mesh2d_indices
assert len(network_link1d2d.shape) == (21, 2)
assert len(network_con_m1d.size) == 21
assert len(network_con_m2d.size) == 21
assert network_link1d2d.shape == (21, 2)
assert network_con_m1d.size == 21
assert network_con_m2d.size == 21

# Write to file
network.to_file(test_output_dir / "test_net.nc")
file_out = Path(test_output_dir / "test_net.nc")
network.to_file(file_out)

#read from written file
network2 = NetworkModel(file_out)

mesh2d_output = network2._mesh2d.get_mesh2d()
assert len(mesh2d_output.face_x) == 152
mesh1d_output = network2._mesh1d._get_mesh1d()
assert len(mesh1d_output.node_x) == 110

network_link1d2d = network2._link1d2d.link1d2d
network_con_m1d = network2._link1d2d.meshkernel.contacts_get().mesh1d_indices
network_con_m2d = network2._link1d2d.meshkernel.contacts_get().mesh2d_indices
assert network_link1d2d.shape == (21, 2)
#TODO: below fail, so the meshkernel instance is not up to date for some reason, should it be?
assert network_con_m1d.size == 21
assert network_con_m2d.size == 21

# plot_network(network)


Expand Down

0 comments on commit 0e43351

Please sign in to comment.