|
4 | 4 | #ifndef ERF_METGRIDUTIL_H_ |
5 | 5 | #define ERF_METGRIDUTIL_H_ |
6 | 6 |
|
| 7 | +#include <limits> |
| 8 | + |
7 | 9 | #include <ERF.H> |
8 | 10 | #include <ERF_EOS.H> |
9 | 11 | #include <ERF_Utils.H> |
@@ -820,7 +822,10 @@ interpolate_column_metgrid_linear (const int& i, |
820 | 822 | new_z(i,j,k+1)+new_z(i,j+1,k+1)+new_z(i+1,j,k+1)+new_z(i+1,j+1,k+1)); |
821 | 823 | } |
822 | 824 |
|
823 | | - amrex::Real z0, z1; |
| 825 | + // Initialized to NaN so that any path which fails to set them fails loudly |
| 826 | + // (with amrex.fpe_trap_invalid=1) rather than returning plausible garbage. |
| 827 | + amrex::Real z0 = std::numeric_limits<amrex::Real>::quiet_NaN(); |
| 828 | + amrex::Real z1 = std::numeric_limits<amrex::Real>::quiet_NaN(); |
824 | 829 | int klow = -1; |
825 | 830 | int khi0 = -1; |
826 | 831 | amrex::Real dzlow = amrex::Real(1.0e12); |
@@ -868,6 +873,10 @@ interpolate_column_metgrid_linear (const int& i, |
868 | 873 |
|
869 | 874 | // extrapolate below the bottom surface |
870 | 875 | if (klow == -1) { |
| 876 | + // klow was never found, so z0 was never set above. The two levels used |
| 877 | + // here are khi0 and khi1, both above z, so z0 is the height at khi0 -- |
| 878 | + // which is exactly what the search loop left in z1 before we clobber it. |
| 879 | + z0 = z1; |
871 | 880 | int khi1 = -1; |
872 | 881 | amrex::Real dzhi1 = -amrex::Real(1.0e12); |
873 | 882 | for (int kk = 0; kk < kmax_orig; kk++) { |
@@ -912,6 +921,10 @@ interpolate_column_metgrid_linear (const int& i, |
912 | 921 | } else if (khi0 == -1) { |
913 | 922 | khi0 = klow - 1; |
914 | 923 | int khi1 = klow; |
| 924 | + // khi0 was never found, so z1 was never set above. The upper level used |
| 925 | + // here is khi1 = klow, whose height is currently held in z0 -- capture |
| 926 | + // it before z0 is recomputed at the new (lower) khi0. |
| 927 | + z1 = z0; |
915 | 928 | if (stag == 'M') { |
916 | 929 | z0 = orig_z(i,j,khi0); |
917 | 930 | } |
|
0 commit comments