From b0e065139b0a8433d0794e8b7f4fd52c63254b90 Mon Sep 17 00:00:00 2001 From: Aaron Zedwick <95507181+aaronzedwick@users.noreply.github.com> Date: Wed, 3 Jul 2024 01:53:38 -0500 Subject: [PATCH] MPAS `face_face_connectivity` parsing (#832) * Added face_face parsing * Added padding with fill values * Update uxarray/io/_mpas.py Co-authored-by: Philip Chmielowiec <67855069+philipc2@users.noreply.github.com> * Update uxarray/io/_mpas.py Co-authored-by: Philip Chmielowiec <67855069+philipc2@users.noreply.github.com> * Update uxarray/io/_mpas.py Co-authored-by: Philip Chmielowiec <67855069+philipc2@users.noreply.github.com> --------- Co-authored-by: Philip Chmielowiec <67855069+philipc2@users.noreply.github.com> --- uxarray/io/_mpas.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/uxarray/io/_mpas.py b/uxarray/io/_mpas.py index c175a9a1a..af155967e 100644 --- a/uxarray/io/_mpas.py +++ b/uxarray/io/_mpas.py @@ -56,6 +56,9 @@ def _primal_to_ugrid(in_ds, out_ds): if "dcEdge" in in_ds: _parse_edge_face_distances(in_ds, out_ds) + if "cellsOnCell" in in_ds: + _parse_face_faces(in_ds, out_ds) + # set global attributes _parse_global_attrs(in_ds, out_ds) @@ -463,6 +466,29 @@ def _parse_global_attrs(in_ds, out_ds): out_ds.attrs = in_ds.attrs +def _parse_face_faces(in_ds, out_ds): + """Parses face-face connectivity for Primal Mesh.""" + cellsOnCell = np.array(in_ds["cellsOnCell"].values, dtype=INT_DTYPE) + nEdgesOnCell = np.array(in_ds["nEdgesOnCell"].values, dtype=INT_DTYPE) + + # replace padded values with fill values + cellsOnCell = _replace_padding(cellsOnCell, nEdgesOnCell) + + # replace missing/zero values with fill values + cellsOnCell = _replace_zeros(cellsOnCell) + + # make zero-indexed + cellsOnCell = _to_zero_index(cellsOnCell) + + face_face_connectivity = cellsOnCell + + out_ds["face_face_connectivity"] = xr.DataArray( + data=face_face_connectivity, + dims=ugrid.FACE_FACE_CONNECTIVITY_DIMS, + attrs=ugrid.FACE_FACE_CONNECTIVITY_ATTRS, + ) + + def _replace_padding(verticesOnCell, nEdgesOnCell): """Replaces the padded values in verticesOnCell defined by nEdgesOnCell with a fill-value.