Skip to content

Commit c75823f

Browse files
authored
Address issue 3702 (#3731)
1 parent f9ca3c5 commit c75823f

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

Source/Initialization/ERF_MetgridUtils.H

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#ifndef ERF_METGRIDUTIL_H_
55
#define ERF_METGRIDUTIL_H_
66

7+
#include <limits>
8+
79
#include <ERF.H>
810
#include <ERF_EOS.H>
911
#include <ERF_Utils.H>
@@ -820,7 +822,10 @@ interpolate_column_metgrid_linear (const int& i,
820822
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));
821823
}
822824

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();
824829
int klow = -1;
825830
int khi0 = -1;
826831
amrex::Real dzlow = amrex::Real(1.0e12);
@@ -868,6 +873,10 @@ interpolate_column_metgrid_linear (const int& i,
868873

869874
// extrapolate below the bottom surface
870875
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;
871880
int khi1 = -1;
872881
amrex::Real dzhi1 = -amrex::Real(1.0e12);
873882
for (int kk = 0; kk < kmax_orig; kk++) {
@@ -912,6 +921,10 @@ interpolate_column_metgrid_linear (const int& i,
912921
} else if (khi0 == -1) {
913922
khi0 = klow - 1;
914923
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;
915928
if (stag == 'M') {
916929
z0 = orig_z(i,j,khi0);
917930
}

0 commit comments

Comments
 (0)