Skip to content

Commit

Permalink
address some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mahf708 committed May 13, 2024
1 parent 824335f commit 9555a54
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
41 changes: 27 additions & 14 deletions components/eamxx/src/diagnostics/extraaci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,10 @@ void ExtraAci::compute_diagnostic_impl() {
// We aim to find the minimum temperature gradient,
// indicating a positive temperature jump, but pressure
// is decreasing, so a negative gradient.
Real min_tm_grad = 0.0;
int min_tm_grad_lev = 0;
int opt_tm_grad_lev = 0;
if(pblinvalg == 1) {
// Find tm_grad = d(T_mid)/d(p_mid)
Kokkos::parallel_for(Kokkos::TeamThreadRange(team, 1, num_levs),
Kokkos::parallel_for(Kokkos::TeamVectorRange(team, 1, num_levs),
[&](int k) {
tm_grad(k) = (tm_icol(k - 1) - tm_icol(k)) /
(pm_icol(k - 1) - pm_icol(k));
Expand All @@ -219,22 +218,36 @@ void ExtraAci::compute_diagnostic_impl() {
// Find minimum gradient, because d(p_mid) < 0 in definition above
// Starting from the surface, and ensuring p_mid > 70000.0 Pa,
// to avoid resolving to some odd place higher up in the atmosphere.
for(int k = num_levs; k > 1; k--) {
if(tm_grad(k) < min_tm_grad && pm_icol(k) > 70000.0) {
min_tm_grad = tm_grad(k);
min_tm_grad_lev = k; // this is *inside* PBL
}
}
using minloc_t = Kokkos::MinLoc<Real, int>;
using minloc_value_t = typename minloc_t::value_type;
minloc_value_t minloc;
Kokkos::parallel_reduce(
Kokkos::TeamVectorRange(team, 1, num_levs),
[&](const int &k, minloc_value_t &result) {
if(tm_grad(k) < result.val && pm_icol(k) > 70000.0) {
result.val = tm_grad(k);
result.loc = k;
}
},
minloc_t(minloc));
opt_tm_grad_lev = minloc.loc;

// for(int k = num_levs; k > 1; k--) {
// if(tm_grad(k) < opt_tm_grad && pm_icol(k) > 70000.0) {
// opt_tm_grad = tm_grad(k);
// opt_tm_grad_lev = k; // this is *inside* PBL
// }
// }
}

// Save some outputs just above the "mixed" PBL
o_pm_hplus(icol) = pm_icol(min_tm_grad_lev - 1);
o_tl_hplus(icol) = tl_icol(min_tm_grad_lev - 1);
o_qt_hplus(icol) = qt_icol(min_tm_grad_lev - 1);
o_pm_hplus(icol) = pm_icol(opt_tm_grad_lev - 1);
o_tl_hplus(icol) = tl_icol(opt_tm_grad_lev - 1);
o_qt_hplus(icol) = qt_icol(opt_tm_grad_lev - 1);

// Now only need to compute below from min_tm_grad_lev to num_levs
// Now only need to compute below from opt_tm_grad_lev to num_levs
Kokkos::parallel_for(
Kokkos::TeamThreadRange(team, min_tm_grad_lev, num_levs),
Kokkos::TeamVectorRange(team, opt_tm_grad_lev, num_levs),
[&](int k) {
// The time-based tendencies
auto tl_tend = (tl_icol(k) - prev_tliq_icol(k)) / dt;
Expand Down
7 changes: 5 additions & 2 deletions components/eamxx/src/diagnostics/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
function (createDiagTest test_name test_srcs)
CreateUnitTest(${test_name} "${test_srcs}"
LIBS diagnostics physics_share
LABELS diagnostics)
LABELS diagnostics
${ARGN})
endfunction ()

if (NOT SCREAM_ONLY_GENERATE_BASELINES)
Expand Down Expand Up @@ -72,6 +73,8 @@ if (NOT SCREAM_ONLY_GENERATE_BASELINES)
CreateDiagTest(aerocom_cld "aerocom_cld_test.cpp")

# Test Extra ACI diags
CreateDiagTest(extraaci "extraaci_test.cpp")
GetInputFile(cam/scam/iop/DYCOMSrf02_iopfile_4scam.nc)
CreateDiagTest(extraaci "extraaci_test.cpp"
EXE_ARGS "--ekat-test-params iop_file=${SCREAM_INPUT_ROOT}/atm/cam/scam/iop/DYCOMSrf02_iopfile_4scam.nc")

endif()
9 changes: 6 additions & 3 deletions components/eamxx/src/diagnostics/tests/extraaci_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "share/grid/mesh_free_grids_manager.hpp"
#include "share/io/scorpio_input.hpp"
#include "share/util/scream_setup_random_test.hpp"
#include <ekat/util/ekat_test_utils.hpp>

namespace scream {

Expand Down Expand Up @@ -35,9 +36,11 @@ TEST_CASE("extraaci_dummy") {

scorpio::init_subsystem(comm);

std::string iop_file =
"/global/cfs/cdirs/e3sm/inputdata/atm/cam/scam/iop/"
"DYCOMSrf02_iopfile_4scam.nc";
std::string iop_file = ekat::TestSession::get().params.at("iop_file");

// const std::string iop_file = ekat::TestSession.get().params.at("iop_file");
// "/global/cfs/cdirs/e3sm/inputdata/atm/cam/scam/iop/"
// "DYCOMSrf02_iopfile_4scam.nc";
scorpio::register_file(iop_file, scorpio::FileMode::Read);
const int nlevs = scorpio::get_dimlen(iop_file, "lev");
// From now on, when we read vars, "time" must be treated as unlimited, to
Expand Down

0 comments on commit 9555a54

Please sign in to comment.