Skip to content

Commit 6557feb

Browse files
authored
Merge pull request #2837 from E3SM-Project/bartgol/eamxx/fix-vert-lev-diag
Fix and cleanup vertical layer diagnostic Non-BFB
2 parents 8d1bba5 + 6bb577c commit 6557feb

File tree

9 files changed

+348
-311
lines changed

9 files changed

+348
-311
lines changed

components/eamxx/src/diagnostics/field_at_height.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ FieldAtHeight (const ekat::Comm& comm, const ekat::ParameterList& params)
4444
" - field name: " + m_field_name + "\n"
4545
" - surface reference: " + surf_ref + "\n"
4646
" - valid options: sealevel, surface\n");
47-
m_z_name = (surf_ref == "sealevel") ? "z" : "geopotential";
47+
m_z_name = (surf_ref == "sealevel") ? "z" : "height";
4848
const auto& location = m_params.get<std::string>("vertical_location");
4949
auto chars_start = location.find_first_not_of("0123456789.");
5050
EKAT_REQUIRE_MSG (chars_start!=0 && chars_start!=std::string::npos,

components/eamxx/src/diagnostics/register_diagnostics.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ inline void register_diagnostics () {
3636
diag_factory.register_product("Exner",&create_atmosphere_diagnostic<ExnerDiagnostic>);
3737
diag_factory.register_product("VirtualTemperature",&create_atmosphere_diagnostic<VirtualTemperatureDiagnostic>);
3838
diag_factory.register_product("z_int",&create_atmosphere_diagnostic<VerticalLayerDiagnostic>);
39-
diag_factory.register_product("geopotential_int",&create_atmosphere_diagnostic<VerticalLayerDiagnostic>);
4039
diag_factory.register_product("z_mid",&create_atmosphere_diagnostic<VerticalLayerDiagnostic>);
40+
diag_factory.register_product("geopotential_int",&create_atmosphere_diagnostic<VerticalLayerDiagnostic>);
4141
diag_factory.register_product("geopotential_mid",&create_atmosphere_diagnostic<VerticalLayerDiagnostic>);
42+
diag_factory.register_product("height_int",&create_atmosphere_diagnostic<VerticalLayerDiagnostic>);
43+
diag_factory.register_product("height_mid",&create_atmosphere_diagnostic<VerticalLayerDiagnostic>);
4244
diag_factory.register_product("dz",&create_atmosphere_diagnostic<VerticalLayerDiagnostic>);
4345
diag_factory.register_product("DryStaticEnergy",&create_atmosphere_diagnostic<DryStaticEnergyDiagnostic>);
4446
diag_factory.register_product("SeaLevelPressure",&create_atmosphere_diagnostic<SeaLevelPressureDiagnostic>);

components/eamxx/src/diagnostics/tests/field_at_height_tests.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ TEST_CASE("field_at_height")
4646
FieldIdentifier z_surf_fid ("z_surf", FieldLayout({COL },{ncols }),m,grid->name());
4747
FieldIdentifier z_mid_fid ("z_mid", FieldLayout({COL, LEV},{ncols, nlevs }),m,grid->name());
4848
FieldIdentifier z_int_fid ("z_int", FieldLayout({COL, ILEV},{ncols, nlevs+1}),m,grid->name());
49-
FieldIdentifier geo_mid_fid ("geopotential_mid",FieldLayout({COL, LEV},{ncols, nlevs }),m,grid->name());
50-
FieldIdentifier geo_int_fid ("geopotential_int",FieldLayout({COL, ILEV},{ncols, nlevs+1}),m,grid->name());
49+
FieldIdentifier h_mid_fid ("height_mid",FieldLayout({COL, LEV},{ncols, nlevs }),m,grid->name());
50+
FieldIdentifier h_int_fid ("height_int",FieldLayout({COL, ILEV},{ncols, nlevs+1}),m,grid->name());
5151
// Keep track of reference fields for comparison
5252
FieldIdentifier s_tgt_fid ("scalar_target",FieldLayout({COL },{ncols }),m,grid->name());
5353
FieldIdentifier v_tgt_fid ("vector_target",FieldLayout({COL,CMP},{ncols,ndims}),m,grid->name());
@@ -59,8 +59,8 @@ TEST_CASE("field_at_height")
5959
Field z_surf (z_surf_fid);
6060
Field z_mid (z_mid_fid);
6161
Field z_int (z_int_fid);
62-
Field geo_mid (geo_mid_fid);
63-
Field geo_int (geo_int_fid);
62+
Field h_mid (h_mid_fid);
63+
Field h_int (h_int_fid);
6464
Field s_tgt (s_tgt_fid);
6565
Field v_tgt (v_tgt_fid);
6666

@@ -71,8 +71,8 @@ TEST_CASE("field_at_height")
7171
z_surf.allocate_view();
7272
z_mid.allocate_view();
7373
z_int.allocate_view();
74-
geo_mid.allocate_view();
75-
geo_int.allocate_view();
74+
h_mid.allocate_view();
75+
h_int.allocate_view();
7676
s_tgt.allocate_view();
7777
v_tgt.allocate_view();
7878

@@ -83,8 +83,8 @@ TEST_CASE("field_at_height")
8383
z_surf.get_header().get_tracking().update_time_stamp(t0);
8484
z_mid.get_header().get_tracking().update_time_stamp(t0);
8585
z_int.get_header().get_tracking().update_time_stamp(t0);
86-
geo_mid.get_header().get_tracking().update_time_stamp(t0);
87-
geo_int.get_header().get_tracking().update_time_stamp(t0);
86+
h_mid.get_header().get_tracking().update_time_stamp(t0);
87+
h_int.get_header().get_tracking().update_time_stamp(t0);
8888
s_tgt.get_header().get_tracking().update_time_stamp(t0);
8989
v_tgt.get_header().get_tracking().update_time_stamp(t0);
9090

@@ -124,9 +124,9 @@ TEST_CASE("field_at_height")
124124

125125
// Set up vertical structure for the tests. Note,
126126
// z_mid/int represents the height in m above sealevel
127-
// geo_mid/int represente the hegith in m above the surface
127+
// h_mid/int represente the hegith in m above the surface
128128
// So we first construct z_mid/int using z_surf as reference, and
129-
// then can build geo_mid/int from z_mid/int
129+
// then can build h_mid/int from z_mid/int
130130
// Furthermore, z_mid is just the midpoint between two adjacent z_int
131131
// points, so we back z_mid out of z_int.
132132
//
@@ -137,8 +137,8 @@ TEST_CASE("field_at_height")
137137
const auto& zint_v = z_int.get_view<Real**,Host>();
138138
const auto& zmid_v = z_mid.get_view<Real**,Host>();
139139
const auto& zsurf_v = z_surf.get_view<Real*,Host>();
140-
const auto& geoint_v = geo_int.get_view<Real**,Host>();
141-
const auto& geomid_v = geo_mid.get_view<Real**,Host>();
140+
const auto& geoint_v = h_int.get_view<Real**,Host>();
141+
const auto& geomid_v = h_mid.get_view<Real**,Host>();
142142
int min_col_thickness = z_top;
143143
int max_surf = 0;
144144
for (int ii=0; ii<ncols; ++ii) {
@@ -159,21 +159,21 @@ TEST_CASE("field_at_height")
159159
z_mid.sync_to_dev();
160160
z_int.sync_to_dev();
161161
z_surf.sync_to_dev();
162-
geo_int.sync_to_dev();
163-
geo_mid.sync_to_dev();
162+
h_int.sync_to_dev();
163+
h_mid.sync_to_dev();
164164
// Set the PDF for target height in the test to always be within the shortest column.
165165
// This ensures that we don't havea target z that extrapolates everywhere.
166166
// We test this case individually.
167167
IPDF pdf_levs (max_surf,min_col_thickness);
168168
// Sanity check that the geo and z vertical structures are in fact different,
169169
// so we know we are testing above_surface and above_sealevel as different cases.
170-
REQUIRE(! views_are_equal(z_int,geo_int));
171-
REQUIRE(! views_are_equal(z_mid,geo_mid));
170+
REQUIRE(! views_are_equal(z_int,h_int));
171+
REQUIRE(! views_are_equal(z_mid,h_mid));
172172

173173
// Make sure that an unsupported reference height throws an error.
174174
print(" -> Testing throws error with unsupported reference height...\n");
175175
{
176-
REQUIRE_THROWS(run_diag (s_mid,geo_mid,"1m","foobar"));
176+
REQUIRE_THROWS(run_diag (s_mid,h_mid,"1m","foobar"));
177177
}
178178
print(" -> Testing throws error with unsupported reference height... OK\n");
179179

@@ -182,8 +182,8 @@ TEST_CASE("field_at_height")
182182
std::string loc;
183183
for (std::string surf_ref : {"sealevel","surface"}) {
184184
printf(" -> Testing for a reference height above %s...\n",surf_ref.c_str());
185-
const auto mid_src = surf_ref == "sealevel" ? z_mid : geo_mid;
186-
const auto int_src = surf_ref == "sealevel" ? z_int : geo_int;
185+
const auto mid_src = surf_ref == "sealevel" ? z_mid : h_mid;
186+
const auto int_src = surf_ref == "sealevel" ? z_int : h_int;
187187
const int max_surf_4test = surf_ref == "sealevel" ? max_surf : 0;
188188
for (int irun=0; irun<nruns; ++irun) {
189189

@@ -238,23 +238,23 @@ TEST_CASE("field_at_height")
238238
}
239239
}
240240
{
241-
print(" -> Forced extrapolation ...............\n");
241+
print(" -> Forced extrapolation at top...............\n");
242242
auto slope = pdf_m(engine);
243243
auto inter = pdf_y0(engine);
244244
f_z_src(inter, slope, int_src, s_int);
245-
print(" -> at top...............\n");
246245
z_tgt = 2*z_top;
247246
std::string loc = std::to_string(z_tgt) + "m";
248247
auto dtop = run_diag(s_int,int_src,loc,surf_ref);
249248
f_z_tgt(inter,slope,z_tgt,int_src,s_tgt);
250249
REQUIRE (views_are_approx_equal(dtop,s_tgt,tol));
251-
print(" -> at bot...............\n");
250+
print(" -> Forced extrapolation at top............... OK!\n");
251+
print(" -> Forced extrapolation at bot...............\n");
252252
z_tgt = 0;
253253
loc = std::to_string(z_tgt) + "m";
254254
auto dbot = run_diag(s_int,int_src,loc,surf_ref);
255255
f_z_tgt(inter,slope,z_tgt,int_src,s_tgt);
256256
REQUIRE (views_are_approx_equal(dbot,s_tgt,tol));
257-
print(" -> Forced extrapolation............... OK!\n");
257+
print(" -> Forced extrapolation at bot............... OK!\n");
258258
}
259259
printf(" -> Testing for a reference height above %s... OK!\n",surf_ref.c_str());
260260
}

0 commit comments

Comments
 (0)