Skip to content

Commit d93b6f6

Browse files
committed
EAMxx: enforce a single value for FillValue across eamxx
1 parent 395dac0 commit d93b6f6

23 files changed

+225
-383
lines changed

components/eamxx/src/diagnostics/aodvis.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,40 +49,38 @@ void AODVis::initialize_impl(const RunType /*run_type*/) {
4949
m_diagnostic_output.get_header().get_identifier().get_grid_name();
5050
const auto var_fill_value = constants::DefaultFillValue<Real>().value;
5151

52-
m_mask_val = m_params.get<double>("mask_value", var_fill_value);
53-
5452
std::string mask_name = name() + " mask";
5553
FieldLayout mask_layout({COL}, {m_ncols});
5654
FieldIdentifier mask_fid(mask_name, mask_layout, nondim, grid_name);
5755
Field diag_mask(mask_fid);
5856
diag_mask.allocate_view();
5957

60-
m_diagnostic_output.get_header().set_extra_data("mask_data", diag_mask);
61-
m_diagnostic_output.get_header().set_extra_data("mask_value", m_mask_val);
58+
m_diagnostic_output.get_header().set_extra_data("mask_field", diag_mask);
6259
}
6360

6461
void AODVis::compute_diagnostic_impl() {
6562
using KT = KokkosTypes<DefaultDevice>;
6663
using MT = typename KT::MemberType;
6764
using ESU = ekat::ExeSpaceUtils<typename KT::ExeSpace>;
6865

66+
constexpr auto fill_value = constants::fill_value<Real>();
67+
6968
const auto aod = m_diagnostic_output.get_view<Real *>();
7069
const auto mask = m_diagnostic_output.get_header()
71-
.get_extra_data<Field>("mask_data")
70+
.get_extra_data<Field>("mask_field")
7271
.get_view<Real *>();
7372
const auto tau_vis = get_field_in("aero_tau_sw")
7473
.subfield(1, m_vis_bnd)
7574
.get_view<const Real **>();
7675
const auto sunlit = get_field_in("sunlit").get_view<const Real *>();
7776

7877
const auto num_levs = m_nlevs;
79-
const auto var_fill_value = m_mask_val;
8078
const auto policy = ESU::get_default_team_policy(m_ncols, m_nlevs);
8179
Kokkos::parallel_for(
8280
"Compute " + m_diagnostic_output.name(), policy, KOKKOS_LAMBDA(const MT &team) {
8381
const int icol = team.league_rank();
8482
if(sunlit(icol) == 0.0) {
85-
aod(icol) = var_fill_value;
83+
aod(icol) = fill_value;
8684
Kokkos::single(Kokkos::PerTeam(team), [&] { mask(icol) = 0; });
8785
} else {
8886
auto tau_icol = ekat::subview(tau_vis, icol);

components/eamxx/src/diagnostics/aodvis.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class AODVis : public AtmosphereDiagnostic {
3636

3737
int m_swbands = eamxx_swbands();
3838
int m_vis_bnd = eamxx_vis_swband_idx();
39-
40-
Real m_mask_val;
4139
};
4240

4341
} // namespace scream

components/eamxx/src/diagnostics/field_at_pressure_level.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,14 @@ initialize_impl (const RunType /*run_type*/)
8585
// Add a field representing the mask as extra data to the diagnostic field.
8686
auto nondim = ekat::units::Units::nondimensional();
8787
const auto& gname = fid.get_grid_name();
88-
m_mask_val = m_params.get<double>("mask_value",Real(constants::DefaultFillValue<float>::value));
89-
9088

9189
std::string mask_name = m_diag_name + " mask";
9290
FieldLayout mask_layout( {COL}, {num_cols});
9391
FieldIdentifier mask_fid (mask_name,mask_layout, nondim, gname);
9492
Field diag_mask(mask_fid);
9593
diag_mask.allocate_view();
96-
m_diagnostic_output.get_header().set_extra_data("mask_data",diag_mask);
97-
m_diagnostic_output.get_header().set_extra_data("mask_value",m_mask_val);
94+
m_diagnostic_output.get_header().set_extra_data("mask_field",diag_mask);
95+
m_diagnostic_output.get_header().set_may_be_filled(true);
9896

9997
using stratts_t = std::map<std::string,std::string>;
10098

@@ -126,11 +124,11 @@ void FieldAtPressureLevel::compute_diagnostic_impl()
126124
const int nlevs = pl.dim(1);
127125

128126
auto p_tgt = m_pressure_level;
129-
auto mval = m_mask_val;
127+
constexpr auto fval = constants::fill_value<Real>();
130128
if (rank==2) {
131129
auto policy = KT::RangePolicy(0,ncols);
132130
auto diag = m_diagnostic_output.get_view<Real*>();
133-
auto mask = m_diagnostic_output.get_header().get_extra_data<Field>("mask_data").get_view<Real*>();
131+
auto mask = m_diagnostic_output.get_header().get_extra_data<Field>("mask_field").get_view<Real*>();
134132
auto f_v = f.get_view<const Real**>();
135133
Kokkos::parallel_for(policy,KOKKOS_LAMBDA(const int icol) {
136134
auto x1 = ekat::subview(p_src_v,icol);
@@ -139,7 +137,7 @@ void FieldAtPressureLevel::compute_diagnostic_impl()
139137
auto end = beg + nlevs;
140138
auto last = beg + (nlevs-1);
141139
if (p_tgt<*beg or p_tgt>*last) {
142-
diag(icol) = mval;
140+
diag(icol) = fval;
143141
mask(icol) = 0;
144142
} else {
145143
auto ub = ekat::upper_bound(beg,end,p_tgt);
@@ -161,7 +159,7 @@ void FieldAtPressureLevel::compute_diagnostic_impl()
161159
const int ndims = f.get_header().get_identifier().get_layout().get_vector_dim();
162160
auto policy = KT::TeamPolicy(ncols,ndims);
163161
auto diag = m_diagnostic_output.get_view<Real**>();
164-
auto mask = m_diagnostic_output.get_header().get_extra_data<Field>("mask_data").get_view<Real*>();
162+
auto mask = m_diagnostic_output.get_header().get_extra_data<Field>("mask_field").get_view<Real*>();
165163
auto f_v = f.get_view<const Real***>();
166164
Kokkos::parallel_for(policy,KOKKOS_LAMBDA(const MemberType& team) {
167165
int icol = team.league_rank();
@@ -171,7 +169,7 @@ void FieldAtPressureLevel::compute_diagnostic_impl()
171169
auto last = beg + (nlevs-1);
172170
Kokkos::parallel_for(Kokkos::TeamVectorRange(team,ndims),[&](const int idim) {
173171
if (p_tgt<*beg or p_tgt>*last) {
174-
diag(icol,idim) = mval;
172+
diag(icol,idim) = fval;
175173
Kokkos::single(Kokkos::PerTeam(team),[&]{
176174
mask(icol) = 0;
177175
});

components/eamxx/src/diagnostics/field_at_pressure_level.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ class FieldAtPressureLevel : public AtmosphereDiagnostic
3939

4040
Real m_pressure_level;
4141
int m_num_levs;
42-
Real m_mask_val;
43-
4442
}; // class FieldAtPressureLevel
4543

4644
} //namespace scream

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ TEST_CASE("field_at_pressure_level_p2")
104104
diag_f.sync_to_host();
105105
auto test2_diag_v = diag_f.get_view<const Real*, Host>();
106106
// Check the mask field inside the diag_f
107-
auto mask_f = diag_f.get_header().get_extra_data<Field>("mask_data");
107+
auto mask_f = diag_f.get_header().get_extra_data<Field>("mask_field");
108108
mask_f.sync_to_host();
109109
auto test2_mask_v = mask_f.get_view<const Real*, Host>();
110110
//
@@ -125,13 +125,13 @@ TEST_CASE("field_at_pressure_level_p2")
125125
diag_f.sync_to_host();
126126
auto test2_diag_v = diag_f.get_view<const Real*, Host>();
127127
// Check the mask field inside the diag_f
128-
auto mask_f = diag_f.get_header().get_extra_data<Field>("mask_data");
128+
auto mask_f = diag_f.get_header().get_extra_data<Field>("mask_field");
129129
mask_f.sync_to_host();
130130
auto test2_mask_v = mask_f.get_view<const Real*, Host>();
131-
auto mask_val = diag_f.get_header().get_extra_data<Real>("mask_value");
131+
auto fill_val = constants::fill_value<Real>();
132132
//
133133
for (int icol=0;icol<ncols;icol++) {
134-
REQUIRE(approx(test2_diag_v(icol),Real(mask_val)));
134+
REQUIRE(approx(test2_diag_v(icol),Real(fill_val)));
135135
REQUIRE(approx(test2_mask_v(icol),Real(0.0)));
136136
}
137137
}

components/eamxx/src/physics/nudging/eamxx_nudging_process_interface.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,7 @@ void Nudging::run_impl (const double dt)
344344
const auto fl = f.get_header().get_identifier().get_layout();
345345
const auto v = f.get_view<Real**>();
346346

347-
Real var_fill_value = constants::DefaultFillValue<Real>().value;
348-
// Query the helper field for the fill value, if not present use default
349-
if (f.get_header().has_extra_data("mask_value")) {
350-
var_fill_value = f.get_header().get_extra_data<Real>("mask_value");
351-
}
347+
constexpr Real var_fill_value = constants::fill_value<Real>();
352348

353349
const int ncols = fl.dim(0);
354350
const int nlevs = fl.dim(1);

components/eamxx/src/share/field/field_header.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class FieldHeader : public FamilyTracking<FieldHeader> {
8989
// - they have the same tracking, alloc_prop and extra data (they were created by alias above)
9090
// - they have the same parent field and their subview info (form alloc prop) are the same
9191
bool is_aliasing (const FieldHeader& rhs) const;
92+
93+
bool may_be_filled () const { return has_extra_data("may_be_filled") and get_extra_data<bool>("may_be_filled"); }
94+
void set_may_be_filled (const bool value) { set_extra_data("may_be_filled",value); }
9295
protected:
9396

9497
// Friend this function, so it can set up a subfield header

0 commit comments

Comments
 (0)