Skip to content

Commit

Permalink
Removes preprocess function from hpp and a calls from cpp interface f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
singhbalwinder committed Sep 1, 2024
1 parent b1fbda1 commit c6d0711
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ void update_gas_aerosols_using_constituents(
static constexpr int pcnst = mam4::aero_model::pcnst;

// Declare local variables
auto wet_aero_loc = wet_aero;
auto dry_atm_loc = dry_atm;
const int surface_lev = nlev - 1;
auto constituent_fluxes_loc = constituent_fluxes;
const int surface_lev = nlev - 1;

// get the start index for gas species in the state_q array
int istart = mam4::utils::gasses_start_ind();
Expand All @@ -34,8 +31,7 @@ void update_gas_aerosols_using_constituents(
// Create a policy to loop over columns annd number of constituents
// to update
// FIXME: TODO:We don't need a team for "nconstituents", so we can make the
// kookos_for
// simple by using just ncols
// kookos_for simple by using just ncols
const auto policy = ekat::ExeSpaceUtils<MAMConstituentFluxes::KT::ExeSpace>::
get_default_team_policy(ncol, nconstituents);

Expand All @@ -58,7 +54,7 @@ void update_gas_aerosols_using_constituents(
atmosphere_for_column(dry_atm, // output
icol); // input

// Form state%q like array
// Form state%q like array at surface level
Real state_q_at_surf_lev[pcnst] = {};
mam4::utils::extract_stateq_from_prognostics(
progs_at_col, haero_atm, // input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,53 +253,47 @@ void MAMConstituentFluxes::initialize_impl(const RunType run_type) {
get_field_out(gas_mmr_field_name).get_view<Real **>();
}

//-----------------------------------------------------------------
// Setup preprocessing and post processing
//-----------------------------------------------------------------
preprocess_.initialize(ncol_, nlev_, wet_atm_, dry_atm_);

} // end initialize_impl()

// ================================================================
// RUN_IMPL
// ================================================================
void MAMConstituentFluxes::run_impl(const double dt) {
const auto scan_policy = ekat::ExeSpaceUtils<
KT::ExeSpace>::get_thread_range_parallel_scan_team_policy(ncol_, nlev_);

// -------------------------------------------------------------------
// (LONG) NOTE: The following code is an adaptation of cflx.F90 code in
// E3SM. In EAMxx, all constituents are considered "wet" (or have wet
// mixing ratios), we are *not* doing any wet to dry conversions in the
// "preprocess" for this process. We are simply updating the MAM4xx
// tracers using the "constituent fluxes".
// for this process. We are simply updating the MAM4xx tracers using the
// "constituent fluxes".
// We are converting wet atm to dry atm. Since we do not use or update
// any of the water constituents (qc, qv, qi etc.), we should be okay
// to do this conversion. We need to do this conversion as our function
// are built following HAERO data structures.
// -------------------------------------------------------------------

// preprocess input -- needs a scan for the calculation of dry_atm_, wet_aero_
// etc.
// Kokkos::parallel_for("preprocess", scan_policy, preprocess_);
// Kokkos::fence();

// Compute vertical layer heights and updraft velocity. We need these to fully
// populate dry_atm_, so that we can form a HAERO atmosphere object. HAERO
// atmosphere object is used to for state%q like array.
auto lambda =
KOKKOS_LAMBDA(const Kokkos::TeamPolicy<KT::ExeSpace>::member_type &team) {
const int i = team.league_rank(); // column index
const int icol = team.league_rank(); // column index
compute_dry_mixing_ratios(team, wet_atm_, // in
dry_atm_, // out
i); // in
icol); // in
team.team_barrier();
// vertical heights has to be computed after computing dry mixing ratios
// for atmosphere
compute_vertical_layer_heights(team, // in
dry_atm_, // out
i); // in
icol); // in
compute_updraft_velocities(team, wet_atm_, // in
dry_atm_, // out
i); // in
icol); // in
};
// policy
const auto scan_policy = ekat::ExeSpaceUtils<
KT::ExeSpace>::get_thread_range_parallel_scan_team_policy(ncol_, nlev_);

Kokkos::parallel_for("mam_cfi_compute_updraft", scan_policy, lambda);

update_gas_aerosols_using_constituents(ncol_, nlev_, dt, dry_atm_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,47 +69,6 @@ class MAMConstituentFluxes final : public scream::AtmosphereProcess {
// Finalize
void finalize_impl(){/*Do nothing*/};

// Atmosphere processes often have a pre-processing step that constructs
// required variables from the set of fields stored in the field manager.
// This functor implements this step, which is called during run_impl.
struct Preprocess {
Preprocess() = default;
// on host: initializes preprocess functor with necessary state data
void initialize(const int ncol, const int nlev,
const mam_coupling::WetAtmosphere &wet_atm,
const mam_coupling::DryAtmosphere &dry_atm) {
ncol_pre_ = ncol;
nlev_pre_ = nlev;
wet_atm_pre_ = wet_atm;
dry_atm_pre_ = dry_atm;
}

KOKKOS_INLINE_FUNCTION
void operator()(
const Kokkos::TeamPolicy<KT::ExeSpace>::member_type &team) const {
const int i = team.league_rank(); // column index

compute_dry_mixing_ratios(team, wet_atm_pre_, dry_atm_pre_, i);
team.team_barrier();
// vertical heights has to be computed after computing dry mixing ratios
// for atmosphere
compute_vertical_layer_heights(team, dry_atm_pre_, i);
compute_updraft_velocities(team, wet_atm_pre_, dry_atm_pre_, i);
} // operator()

// local variables for preprocess struct
// number of horizontal columns and vertical levels
int ncol_pre_, nlev_pre_;

// local atmospheric and aerosol state data
mam_coupling::WetAtmosphere wet_atm_pre_;
mam_coupling::DryAtmosphere dry_atm_pre_;
}; // Preprocess

private:
// preprocessing scratch pads
Preprocess preprocess_;

}; // MAMConstituentFluxes

} // namespace scream
Expand Down

0 comments on commit c6d0711

Please sign in to comment.