Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added edge_node_connectivity to Ugrid2d.from_meshkernel #250

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions tests/test_ugrid2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand All @@ -319,13 +320,53 @@ 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():
Expand Down
6 changes: 4 additions & 2 deletions xugrid/ugrid/ugrid2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading