negative weights in cube_to_target

We (@Mark Taylor @Jishi Zhang) are looking at a corner case in cube_to_target. In short, the current version in E3SM repo will generate very large negative PHIS in some cases. The error is rare and tends to happen when the dx of the target grid is smaller/comparable to the base cube in my experience. So, it shouldn’t affect most users in most cases, but it would be great to fix it in the E3SM repo.

We seek help from Peter H. Lauritzen. He guided us the underlying reasons and pointed out the solution. As he suggested, I opened an issue and potential solutions in NCAP/Topo repo: https://github.com/NCAR/Topo/issues/62.

Description of the problem

In the experience of using the cube_to_target (mapping terr_height/PHIS from the base cube to target) for regionally refined meshes (RRM), we've encountered issues with large negative values for terr_target.
=> related to negative weights_all / weights_out / wt in cube_to_target.F90.

=> resulting from some dominant negative weights in remap.F90 (corresponding to the overlap area “omega_kl” between the target grid and the base cube grid in Lauritzen et al. 2015).

Lauritzen, P. H., Bacmeister, J. T., Callaghan, P. F., & Taylor, M. A. (2015). NCAR_Topo (v1. 0): NCAR global model topography generation software for unstructured grids. Geoscientific Model Development, 8(12), 3975-3986.

This generally happens when the dx of the target grid is comparable/smaller th