From 1f3823a0df3f118c86985330fd64090170aed942 Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Mon, 1 Jul 2024 12:21:26 +0200 Subject: [PATCH 1/3] added edge_node_connectivity to Ugrid2d.from_meshkernel --- tests/test_ugrid2d.py | 7 ++++++- xugrid/ugrid/ugrid2d.py | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_ugrid2d.py b/tests/test_ugrid2d.py index c6e3dfceb..64f10f9df 100644 --- a/tests/test_ugrid2d.py +++ b/tests/test_ugrid2d.py @@ -311,6 +311,7 @@ class Mesh2d(NamedTuple): node_y: np.ndarray face_nodes: np.ndarray nodes_per_face: np.ndarray + edge_nodes: np.ndarray mesh2d = Mesh2d( node_x=np.array([0.0, 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 3.0]), @@ -319,13 +320,17 @@ class Mesh2d(NamedTuple): [0, 1, 5, 4, 1, 2, 6, 5, 2, 3, 7, 6, 4, 5, 9, 8, 5, 6, 10, 9, 6, 7, 11, 10] ), nodes_per_face=np.array([4, 4, 4, 4, 4, 4]), + edge_nodes=np.array([4, 8, 5, 6, 5, 9, 6, 7, 6, 10, 7, 11, 8, 9, 9, 10, 10, 11, + 0, 1, 0, 4, 1, 2, 1, 5, 2, 3, 2, 6, 3, 7, 4, 5]) ) - + grid = xugrid.Ugrid2d.from_meshkernel(mesh2d) + grid.plot() assert grid.n_face == 6 assert np.allclose(mesh2d.node_x, grid.node_x) assert np.allclose(mesh2d.node_y, grid.node_y) assert np.allclose(grid.face_node_connectivity, mesh2d.face_nodes.reshape((6, 4))) + assert np.allclose(grid.edge_node_connectivity, mesh2d.edge_nodes.reshape((-1, 2))) def test_assign_node_coords(): diff --git a/xugrid/ugrid/ugrid2d.py b/xugrid/ugrid/ugrid2d.py index 87ea87ec8..37c63a241 100644 --- a/xugrid/ugrid/ugrid2d.py +++ b/xugrid/ugrid/ugrid2d.py @@ -227,11 +227,13 @@ def from_meshkernel( face_node_connectivity = np.full((n_face, n_max_node), fill_value) isnode = connectivity.ragged_index(n_face, n_max_node, mesh.nodes_per_face) face_node_connectivity[isnode] = mesh.face_nodes + edge_node_connectivity = np.reshape(mesh.edge_nodes, (-1, 2)) return cls( - mesh.node_x, - mesh.node_y, + node_x=mesh.node_x, + node_y=mesh.node_y, fill_value=fill_value, face_node_connectivity=face_node_connectivity, + edge_node_connectivity=edge_node_connectivity, name=name, projected=projected, crs=crs, From c4ba2f3d6593f29bceb8d3989344f14cfb776425 Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Mon, 1 Jul 2024 12:32:22 +0200 Subject: [PATCH 2/3] fixed formatting with black --- tests/test_ugrid2d.py | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/tests/test_ugrid2d.py b/tests/test_ugrid2d.py index 64f10f9df..e6f4ce7dd 100644 --- a/tests/test_ugrid2d.py +++ b/tests/test_ugrid2d.py @@ -320,10 +320,46 @@ class Mesh2d(NamedTuple): [0, 1, 5, 4, 1, 2, 6, 5, 2, 3, 7, 6, 4, 5, 9, 8, 5, 6, 10, 9, 6, 7, 11, 10] ), nodes_per_face=np.array([4, 4, 4, 4, 4, 4]), - edge_nodes=np.array([4, 8, 5, 6, 5, 9, 6, 7, 6, 10, 7, 11, 8, 9, 9, 10, 10, 11, - 0, 1, 0, 4, 1, 2, 1, 5, 2, 3, 2, 6, 3, 7, 4, 5]) + edge_nodes=np.array( + [ + 4, + 8, + 5, + 6, + 5, + 9, + 6, + 7, + 6, + 10, + 7, + 11, + 8, + 9, + 9, + 10, + 10, + 11, + 0, + 1, + 0, + 4, + 1, + 2, + 1, + 5, + 2, + 3, + 2, + 6, + 3, + 7, + 4, + 5, + ] + ), ) - + grid = xugrid.Ugrid2d.from_meshkernel(mesh2d) grid.plot() assert grid.n_face == 6 From b23e3f7935dc943f423a4d5576ece5ead5b924a2 Mon Sep 17 00:00:00 2001 From: veenstrajelmer <60435591+veenstrajelmer@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:19:36 +0200 Subject: [PATCH 3/3] updated changelog --- docs/changelog.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index fce7a1a3e..464be000a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,6 +6,15 @@ All notable changes to this project will be documented in this file. The format is based on `Keep a Changelog`_, and this project adheres to `Semantic Versioning`_. +[Unreleased] +------------ + +Added +~~~~~ + +- included ``edge_node_connectivity`` in :meth:`xugrid.Ugrid2d.from_meshkernel`, + so the ordering of edges is consistent with ``meshkernel``. + [0.10.0] 2024-05-01 -------------------