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

Add face edges #84

Merged
merged 4 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
67 changes: 34 additions & 33 deletions docs/examples/01_mesh2d_basics.ipynb

Large diffs are not rendered by default.

30 changes: 21 additions & 9 deletions meshkernel/c_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class CMesh2d(Structure):
Used for communicating with the MeshKernel dll.

The ``_fields_`` attribute of this class contains the following fields:
- edge_faces (POINTER(c_int)): The face indices for each edge.
- edge_nodes (POINTER(c_int)): The nodes composing each mesh 2d edge.
- face_edges (POINTER(c_int)): The edge indices for each face.
- face_nodes (POINTER(c_int)): The nodes composing each mesh 2d face.
- nodes_per_face (POINTER(c_int)): The nodes composing each mesh 2d face.
- node_x (POINTER(c_double)): The x-coordinates of the nodes.
Expand All @@ -44,7 +46,9 @@ class CMesh2d(Structure):
"""

_fields_ = [
("edge_faces", POINTER(c_int)),
("edge_nodes", POINTER(c_int)),
("face_edges", POINTER(c_int)),
("face_nodes", POINTER(c_int)),
("nodes_per_face", POINTER(c_int)),
("node_x", POINTER(c_double)),
Expand Down Expand Up @@ -86,7 +90,9 @@ def from_mesh2d(mesh2d: Mesh2d) -> CMesh2d:
c_mesh2d = CMesh2d()

# Set the pointers
c_mesh2d.edge_faces = as_ctypes(mesh2d.edge_faces)
c_mesh2d.edge_nodes = as_ctypes(mesh2d.edge_nodes)
c_mesh2d.face_edges = as_ctypes(mesh2d.face_edges)
c_mesh2d.face_nodes = as_ctypes(mesh2d.face_nodes)
c_mesh2d.nodes_per_face = as_ctypes(mesh2d.nodes_per_face)
c_mesh2d.node_x = as_ctypes(mesh2d.node_x)
Expand Down Expand Up @@ -122,6 +128,8 @@ def allocate_memory(self) -> Mesh2d:
edge_y = np.empty(self.num_edges, dtype=np.double)
face_x = np.empty(self.num_faces, dtype=np.double)
face_y = np.empty(self.num_faces, dtype=np.double)
edge_faces = np.empty(self.num_edges * 2, dtype=np.int32)
face_edges = np.empty(self.num_face_nodes, dtype=np.int32)

self.edge_nodes = as_ctypes(edge_nodes)
self.face_nodes = as_ctypes(face_nodes)
Expand All @@ -132,17 +140,21 @@ def allocate_memory(self) -> Mesh2d:
self.edge_y = as_ctypes(edge_y)
self.face_x = as_ctypes(face_x)
self.face_y = as_ctypes(face_y)
self.edge_faces = as_ctypes(edge_faces)
self.face_edges = as_ctypes(face_edges)

return Mesh2d(
node_x,
node_y,
edge_nodes,
face_nodes,
nodes_per_face,
edge_x,
edge_y,
face_x,
face_y,
node_x=node_x,
node_y=node_y,
edge_nodes=edge_nodes,
face_nodes=face_nodes,
nodes_per_face=nodes_per_face,
edge_x=edge_x,
edge_y=edge_y,
face_x=face_x,
face_y=face_y,
edge_faces=edge_faces,
face_edges=face_edges,
)


Expand Down
6 changes: 6 additions & 0 deletions meshkernel/py_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class Mesh2d:
edge_y (ndarray, optional): A 1D double array describing x-coordinates of the mesh edges' middle points.
face_x (ndarray, optional): A 1D double array describing x-coordinates of the mesh faces' mass centers.
face_y (ndarray, optional): A 1D double array describing y-coordinates of the mesh faces' mass centers.
edge_faces (ndarray, optional): A 1D integer array describing for each edge the indices of the faces.
face_edges (ndarray, optional): A 1D integer array describing for each face the indices of the edges.

"""

Expand All @@ -113,6 +115,8 @@ def __init__(
edge_y=np.empty(0, dtype=np.double),
face_x=np.empty(0, dtype=np.double),
face_y=np.empty(0, dtype=np.double),
edge_faces=np.empty(0, dtype=np.int32),
face_edges=np.empty(0, dtype=np.int32),
):
self.node_x: ndarray = node_x
self.node_y: ndarray = node_y
Expand All @@ -123,6 +127,8 @@ def __init__(
self.edge_y: ndarray = edge_y
self.face_x: ndarray = face_x
self.face_y: ndarray = face_y
self.edge_faces: ndarray = edge_faces
self.face_edges: ndarray = face_edges

def plot_edges(self, ax, *args, **kwargs):
"""Plots the edges at a given axes.
Expand Down
4 changes: 4 additions & 0 deletions tests/test_c_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def test_cmesh2d_from_mesh2d():
edge_y = np.array([0.0, 0.5, 1.0, 0.5], dtype=np.double)
face_x = np.array([0.5], dtype=np.double)
face_y = np.array([0.5], dtype=np.double)
edge_faces = np.array([0, -1, 0, -1, 0, -1, 0, -1], dtype=np.int32)
face_edges = np.array([0, 1, 2, 3], dtype=np.int32)

mesh2d = Mesh2d(node_x, node_y, edge_nodes)
mesh2d.face_nodes = face_nodes
Expand All @@ -43,6 +45,8 @@ def test_cmesh2d_from_mesh2d():
mesh2d.edge_y = edge_y
mesh2d.face_x = face_x
mesh2d.face_y = face_y
mesh2d.edge_faces = edge_faces
mesh2d.face_edges = face_edges

c_mesh2d = CMesh2d.from_mesh2d(mesh2d)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_curvilinear_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ def test_curvilinear_make_uniform_with_polygon():
curvilinear_grid = mk.curvilineargrid_get()

# Test the number of m and n
assert curvilinear_grid.num_m == 6
assert curvilinear_grid.num_n == 6
assert curvilinear_grid.num_m == 11
assert curvilinear_grid.num_n == 11


def test_curvilinear_refine_derefine():
Expand Down