Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions components/eamxx/src/diagnostics/aodvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,14 @@ void AODVis::initialize_impl(const RunType /*run_type*/) {
auto nondim = ekat::units::Units::nondimensional();
const auto &grid_name =
m_diagnostic_output.get_header().get_identifier().get_grid_name();
const auto var_fill_value = constants::fill_value<Real>;

m_mask_val = m_params.get<double>("mask_value", var_fill_value);

std::string mask_name = name() + " mask";
FieldLayout mask_layout({COL}, {m_ncols});
FieldIdentifier mask_fid(mask_name, mask_layout, nondim, grid_name);
Field diag_mask(mask_fid);
diag_mask.allocate_view();

m_diagnostic_output.get_header().set_extra_data("mask_data", diag_mask);
m_diagnostic_output.get_header().set_extra_data("mask_value", m_mask_val);
m_diagnostic_output.get_header().set_extra_data("mask_field", diag_mask);
}

void AODVis::compute_diagnostic_impl() {
Expand All @@ -68,23 +64,24 @@ void AODVis::compute_diagnostic_impl() {
using TPF = ekat::TeamPolicyFactory<typename KT::ExeSpace>;
using RU = ekat::ReductionUtils<typename KT::ExeSpace>;

constexpr auto fill_value = constants::fill_value<Real>;

const auto aod = m_diagnostic_output.get_view<Real *>();
const auto mask = m_diagnostic_output.get_header()
.get_extra_data<Field>("mask_data")
.get_extra_data<Field>("mask_field")
.get_view<Real *>();
const auto tau_vis = get_field_in("aero_tau_sw")
.subfield(1, m_vis_bnd)
.get_view<const Real **>();
const auto sunlit = get_field_in("sunlit").get_view<const Real *>();

const auto num_levs = m_nlevs;
const auto var_fill_value = m_mask_val;
const auto policy = TPF::get_default_team_policy(m_ncols, m_nlevs);
Kokkos::parallel_for(
"Compute " + m_diagnostic_output.name(), policy, KOKKOS_LAMBDA(const MT &team) {
const int icol = team.league_rank();
if(sunlit(icol) == 0.0) {
aod(icol) = var_fill_value;
aod(icol) = fill_value;
Kokkos::single(Kokkos::PerTeam(team), [&] { mask(icol) = 0; });
} else {
auto tau_icol = ekat::subview(tau_vis, icol);
Expand Down
2 changes: 0 additions & 2 deletions components/eamxx/src/diagnostics/aodvis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class AODVis : public AtmosphereDiagnostic {

int m_swbands = eamxx_swbands();
int m_vis_bnd = eamxx_vis_swband_idx();

Real m_mask_val;
};

} // namespace scream
Expand Down
3 changes: 1 addition & 2 deletions components/eamxx/src/diagnostics/atm_backtend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ void AtmBackTendDiag::init_timestep(const util::TimeStamp &start_of_step) {
}

void AtmBackTendDiag::compute_diagnostic_impl() {
Real var_fill_value = constants::fill_value<Real>;
std::int64_t dt;

const auto &f = get_field_in(m_name);
Expand All @@ -77,7 +76,7 @@ void AtmBackTendDiag::compute_diagnostic_impl() {
} else {
// This is the first time we evaluate this diag. We cannot compute a tend
// yet, so fill with an invalid value
m_diagnostic_output.deep_copy(var_fill_value);
m_diagnostic_output.deep_copy(constants::fill_value<Real>);
}
}

Expand Down
16 changes: 7 additions & 9 deletions components/eamxx/src/diagnostics/field_at_pressure_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,14 @@ initialize_impl (const RunType /*run_type*/)
// Add a field representing the mask as extra data to the diagnostic field.
auto nondim = ekat::units::Units::nondimensional();
const auto& gname = fid.get_grid_name();
m_mask_val = m_params.get<double>("mask_value",Real(constants::fill_value<double>));


std::string mask_name = m_diag_name + " mask";
FieldLayout mask_layout( {COL}, {num_cols});
FieldIdentifier mask_fid (mask_name,mask_layout, nondim, gname);
Field diag_mask(mask_fid);
diag_mask.allocate_view();
m_diagnostic_output.get_header().set_extra_data("mask_data",diag_mask);
m_diagnostic_output.get_header().set_extra_data("mask_value",m_mask_val);
m_diagnostic_output.get_header().set_extra_data("mask_field",diag_mask);
m_diagnostic_output.get_header().set_may_be_filled(true);

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

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

auto p_tgt = m_pressure_level;
auto mval = m_mask_val;
constexpr auto fval = constants::fill_value<Real>;
if (rank==2) {
auto policy = KT::RangePolicy(0,ncols);
auto diag = m_diagnostic_output.get_view<Real*>();
auto mask = m_diagnostic_output.get_header().get_extra_data<Field>("mask_data").get_view<Real*>();
auto mask = m_diagnostic_output.get_header().get_extra_data<Field>("mask_field").get_view<Real*>();
auto f_v = f.get_view<const Real**>();
Kokkos::parallel_for(policy,KOKKOS_LAMBDA(const int icol) {
auto x1 = ekat::subview(p_src_v,icol);
Expand All @@ -139,7 +137,7 @@ void FieldAtPressureLevel::compute_diagnostic_impl()
auto end = beg + nlevs;
auto last = beg + (nlevs-1);
if (p_tgt<*beg or p_tgt>*last) {
diag(icol) = mval;
diag(icol) = fval;
mask(icol) = 0;
} else {
auto ub = ekat::upper_bound(beg,end,p_tgt);
Expand All @@ -161,7 +159,7 @@ void FieldAtPressureLevel::compute_diagnostic_impl()
const int ndims = f.get_header().get_identifier().get_layout().get_vector_dim();
auto policy = KT::TeamPolicy(ncols,ndims);
auto diag = m_diagnostic_output.get_view<Real**>();
auto mask = m_diagnostic_output.get_header().get_extra_data<Field>("mask_data").get_view<Real*>();
auto mask = m_diagnostic_output.get_header().get_extra_data<Field>("mask_field").get_view<Real*>();
auto f_v = f.get_view<const Real***>();
Kokkos::parallel_for(policy,KOKKOS_LAMBDA(const MemberType& team) {
int icol = team.league_rank();
Expand All @@ -171,7 +169,7 @@ void FieldAtPressureLevel::compute_diagnostic_impl()
auto last = beg + (nlevs-1);
Kokkos::parallel_for(Kokkos::TeamVectorRange(team,ndims),[&](const int idim) {
if (p_tgt<*beg or p_tgt>*last) {
diag(icol,idim) = mval;
diag(icol,idim) = fval;
Kokkos::single(Kokkos::PerTeam(team),[&]{
mask(icol) = 0;
});
Expand Down
2 changes: 0 additions & 2 deletions components/eamxx/src/diagnostics/field_at_pressure_level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class FieldAtPressureLevel : public AtmosphereDiagnostic

Real m_pressure_level;
int m_num_levs;
Real m_mask_val;

}; // class FieldAtPressureLevel

} //namespace scream
Expand Down
4 changes: 1 addition & 3 deletions components/eamxx/src/diagnostics/tests/aodvis_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ TEST_CASE("aodvis") {
using namespace ShortFieldTagsNames;
using namespace ekat::units;

Real var_fill_value = constants::fill_value<Real>;

Real some_limit = 0.0025;

// A world comm
Expand Down Expand Up @@ -121,7 +119,7 @@ TEST_CASE("aodvis") {

for(int icol = 0; icol < grid->get_num_local_dofs(); ++icol) {
if(sun_h(icol) < some_limit) {
aod_t(icol) = var_fill_value;
aod_t(icol) = constants::fill_value<Real>;
} else {
for(int ilev = 0; ilev < nlevs; ++ilev) {
aod_t(icol) += tau_h(icol, swvis, ilev);
Expand Down
6 changes: 2 additions & 4 deletions components/eamxx/src/diagnostics/tests/atm_backtend_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ TEST_CASE("atm_backtend") {
REQUIRE_THROWS(diag_factory.create("AtmBackTendDiag", comm,
params)); // No 'tendency_name'

Real var_fill_value = constants::fill_value<Real>;

// Set time for qc and randomize its values
qc.get_header().get_tracking().update_time_stamp(t0);
randomize(qc, engine, pdf);
Expand All @@ -83,9 +81,9 @@ TEST_CASE("atm_backtend") {
diag->compute_diagnostic();
auto diag_f = diag->get_diagnostic();

// Check result: diag should be filled with var_fill_value
// Check result: diag should be filled with fill_value
auto some_field = qc.clone();
some_field.deep_copy(var_fill_value);
some_field.deep_copy(constants::fill_value<Real>);
REQUIRE(views_are_equal(diag_f, some_field));

const Real a_day = 24.0 * 60.0 * 60.0; // seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ TEST_CASE("field_at_pressure_level_p2")
diag_f.sync_to_host();
auto test2_diag_v = diag_f.get_view<const Real*, Host>();
// Check the mask field inside the diag_f
auto mask_f = diag_f.get_header().get_extra_data<Field>("mask_data");
auto mask_f = diag_f.get_header().get_extra_data<Field>("mask_field");
mask_f.sync_to_host();
auto test2_mask_v = mask_f.get_view<const Real*, Host>();
//
Expand All @@ -125,13 +125,12 @@ TEST_CASE("field_at_pressure_level_p2")
diag_f.sync_to_host();
auto test2_diag_v = diag_f.get_view<const Real*, Host>();
// Check the mask field inside the diag_f
auto mask_f = diag_f.get_header().get_extra_data<Field>("mask_data");
auto mask_f = diag_f.get_header().get_extra_data<Field>("mask_field");
mask_f.sync_to_host();
auto test2_mask_v = mask_f.get_view<const Real*, Host>();
auto mask_val = diag_f.get_header().get_extra_data<Real>("mask_value");
//

for (int icol=0;icol<ncols;icol++) {
REQUIRE(approx(test2_diag_v(icol),Real(mask_val)));
REQUIRE(approx(test2_diag_v(icol),constants::fill_value<Real>));
REQUIRE(approx(test2_mask_v(icol),Real(0.0)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,21 +344,17 @@ void Nudging::run_impl (const double dt)
const auto fl = f.get_header().get_identifier().get_layout();
const auto v = f.get_view<Real**>();

Real var_fill_value = constants::fill_value<Real>;
// Query the helper field for the fill value, if not present use default
if (f.get_header().has_extra_data("mask_value")) {
var_fill_value = f.get_header().get_extra_data<Real>("mask_value");
}
constexpr Real fill_value = constants::fill_value<Real>;

const int ncols = fl.dim(0);
const int nlevs = fl.dim(1);
const auto thresh = std::abs(var_fill_value)*0.0001;
const auto thresh = std::abs(fill_value)*0.0001;
auto lambda = KOKKOS_LAMBDA(const int icol) {
int first_good = nlevs;
int last_good = -1;
for (int k=0; k<nlevs; ++k) {
if (std::abs(v(icol,k)-var_fill_value)>thresh) {
// This entry is substantially different from var_fill_value, so it's good
if (std::abs(v(icol,k)-fill_value)>thresh) {
// This entry is substantially different from fill_value, so it's good
first_good = ekat::impl::min(first_good,k);
last_good = ekat::impl::max(last_good,k);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ constexpr int nlevs_data = 20;
constexpr int nsteps_data = 5;
constexpr int dt_data = 100;
constexpr int nlevs_filled = 2;
constexpr double fill_val = 1e30;

util::TimeStamp get_t0 () {
return util::TimeStamp ({2000,1,1},{12,0,0});
Expand Down Expand Up @@ -89,27 +88,27 @@ void compute_field (Field f,
const auto f_h = f.get_view<Real**, Host>();
for (int icol=0;icol<ncols;++icol) {
for (int ilev=0; ilev<lev_beg; ++ilev) {
f_h(icol,ilev) = fill_val;
f_h(icol,ilev) = constants::fill_value<Real>;
}
for (int ilev=lev_beg;ilev<lev_end;++ilev) {
f_h(icol,ilev) = step + (offset+icol)*nlevs + ilev + 1;
}
for (int ilev=lev_end; ilev<nlevs; ++ilev) {
f_h(icol,ilev) = fill_val;
f_h(icol,ilev) = constants::fill_value<Real>;
}
}
} else {
const auto f_h = f.get_view<Real***, Host>();
for (int icol=0;icol<ncols;++icol) {
for (int ilev=0; ilev<lev_beg; ++ilev) {
f_h(icol,0,ilev) = f_h(icol,1,ilev) = fill_val;
f_h(icol,0,ilev) = f_h(icol,1,ilev) = constants::fill_value<Real>;
}
for (int ilev=lev_beg;ilev<lev_end;++ilev) {
f_h(icol,0,ilev) = step + (offset+icol)*2*nlevs + ilev + 1;
f_h(icol,1,ilev) = step + (offset+icol)*2*nlevs + ilev + 1;
}
for (int ilev=lev_end; ilev<nlevs; ++ilev) {
f_h(icol,0,ilev) = f_h(icol,1,ilev) = fill_val;
f_h(icol,0,ilev) = f_h(icol,1,ilev) = constants::fill_value<Real>;
}
}
}
Expand Down Expand Up @@ -150,7 +149,6 @@ create_om (const std::string& filename_prefix,
params.set<std::string>("filename_prefix",filename_prefix);
params.set<std::string>("floating_point_precision","real");
params.set("field_names",strvec_t{"p_mid","U","V"});
params.set("fill_value",fill_val);

auto& ctrl_pl = params.sublist("output_control");
ctrl_pl.set<std::string>("frequency_units","nsteps");
Expand Down
3 changes: 3 additions & 0 deletions components/eamxx/src/share/field/field_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class FieldHeader : public FamilyTracking<FieldHeader> {
// - they have the same tracking, alloc_prop and extra data (they were created by alias above)
// - they have the same parent field and their subview info (form alloc prop) are the same
bool is_aliasing (const FieldHeader& rhs) const;

bool may_be_filled () const { return has_extra_data("may_be_filled") and get_extra_data<bool>("may_be_filled"); }
void set_may_be_filled (const bool value) { set_extra_data("may_be_filled",value); }
protected:

// Friend this function, so it can set up a subfield header
Expand Down
Loading
Loading