Skip to content

Commit

Permalink
fix unmasked connectivity bug
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenworsley committed Jul 22, 2024
1 parent 1c12a90 commit 8f4b24c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 9 additions & 3 deletions esmf_regrid/experimental/unstructured_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,15 @@ def _as_esmf_info(self):
nodeCoord = self.node_coords.flatten()
nodeOwner = np.zeros([num_node]) # regridding currently serial
elemId = np.arange(1, num_elem + 1)
elemType = self.fnc.count(axis=1)
# Experiments seem to indicate that ESMF is using 0 indexing here
elemConn = self.fnc.compressed() - self.nsi
if np.ma.isMaskedArray(self.fnc):
elemType = self.fnc.count(axis=1)
# Experiments seem to indicate that ESMF is using 0 indexing here
elemConn = self.fnc.compressed() - self.nsi
else:
elemType = self.fnc.shape[1] * np.ones(self.fnc.shape[0])
# Experiments seem to indicate that ESMF is using 0 indexing here
elemConn = self.fnc.flatten() - self.nsi

elemCoord = self.elem_coords
result = (
num_node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ def test_make_mesh():
assert esmf_mesh_0.__repr__() == esmf_mesh_1.__repr__() == expected_repr


def test_connectivity_mask_equivalence():
"""Test for handling connectivity masks :meth:`~esmf_regrid.esmf_regridder.GridInfo.make_esmf_field`."""
coords, nodes, _ = _make_small_mesh_args()
coords = coords[:-1]
nodes = nodes[:, :-1]
unmasked_nodes = nodes.filled()
mesh = MeshInfo(coords, unmasked_nodes, 0)
esmf_mesh_unmasked = mesh.make_esmf_field()

mesh = MeshInfo(coords, nodes, 0)
esmf_mesh_masked = mesh.make_esmf_field()
assert esmf_mesh_unmasked.__repr__() == esmf_mesh_masked.__repr__()


def test_regrid_with_mesh():
"""Basic test for regridding with :meth:`~esmf_regrid.esmf_regridder.GridInfo.make_esmf_field`."""
mesh_args = _make_small_mesh_args()
Expand Down

0 comments on commit 8f4b24c

Please sign in to comment.