Skip to content

Commit

Permalink
Merge branch 'singhbalwinder/eamxx/format-mam4xx-codes' into next (PR #…
Browse files Browse the repository at this point in the history
…7036)

EAMxx: Formats all MAM4xx interfaces using Clang

There are no code changes in the PR except for formatting.

[BFB]

* singhbalwinder/eamxx/format-mam4xx-codes:
  Rebased on current master and clang format
  EAMxx:Formats all MAM4xx interfaces using Clang
  • Loading branch information
singhbalwinder committed Feb 24, 2025
2 parents b5d981e + 3e715a2 commit 5483fbc
Show file tree
Hide file tree
Showing 16 changed files with 740 additions and 742 deletions.
86 changes: 42 additions & 44 deletions components/eamxx/src/physics/mam/eamxx_mam_aci_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ void compute_w0_and_rho(haero::ThreadTeamPolicy team_policy,
static constexpr auto gravit = C::gravit; // Gravity [m/s2]
// Gas constant for dry air [J/(kg*K) or J/Kg/K]
static constexpr auto rair = C::Rair;
Kokkos::parallel_for(
Kokkos::TeamVectorRange(team, 0u, top_lev), [&](int kk) {
w0(icol, kk) = 0;
rho(icol, kk) = -999.0;
});
Kokkos::parallel_for(Kokkos::TeamVectorRange(team, 0u, top_lev),
[&](int kk) {
w0(icol, kk) = 0;
rho(icol, kk) = -999.0;
});
Kokkos::parallel_for(
Kokkos::TeamVectorRange(team, top_lev, nlev), [&](int kk) {
rho(icol, kk) = p_mid(icol, kk) / (rair * T_mid(icol, kk));
Expand All @@ -39,20 +39,20 @@ void compute_w0_and_rho(haero::ThreadTeamPolicy team_policy,
}

void compute_tke_at_interfaces(haero::ThreadTeamPolicy team_policy,
const MAMAci::const_view_2d var_mid,
const MAMAci::view_2d dz, const int nlev_,
MAMAci::view_2d w_sec_int,
// output
MAMAci::view_2d tke) {
const MAMAci::const_view_2d var_mid,
const MAMAci::view_2d dz, const int nlev_,
MAMAci::view_2d w_sec_int,
// output
MAMAci::view_2d tke) {
using CO = scream::ColumnOps<DefaultDevice, Real>;

Kokkos::parallel_for(
team_policy, KOKKOS_LAMBDA(const haero::ThreadTeam &team) {
const int icol = team.league_rank();

const auto var_mid_col = ekat::subview(var_mid, icol);
const auto var_mid_col = ekat::subview(var_mid, icol);
const auto w_sec_int_col = ekat::subview(w_sec_int, icol);
const auto dz_col = ekat::subview(dz, icol);
const auto dz_col = ekat::subview(dz, icol);

const Real bc_top = var_mid_col(0);
const Real bc_bot = var_mid_col(nlev_ - 1);
Expand All @@ -62,9 +62,7 @@ void compute_tke_at_interfaces(haero::ThreadTeamPolicy team_policy,
team.team_barrier();
Kokkos::parallel_for(
Kokkos::TeamVectorRange(team, nlev_ + 1),
[&](int kk) {
tke(icol, kk) = (3.0 / 2.0) * w_sec_int(icol, kk);
});
[&](int kk) { tke(icol, kk) = (3.0 / 2.0) * w_sec_int(icol, kk); });
});
}

Expand All @@ -78,24 +76,24 @@ void compute_subgrid_scale_velocities(
const int icol = team.league_rank();
// More refined computation of sub-grid vertical velocity
// Set to be zero at the surface by initialization.
Kokkos::parallel_for(
Kokkos::TeamVectorRange(team, top_lev), [&](int kk) {
wsub(icol, kk) = wsubmin;
wsubice(icol, kk) = 0.001;
wsig(icol, kk) = 0.001;
});
// parallel_for ranges do not overlap, no need for barrier.
Kokkos::parallel_for(Kokkos::TeamVectorRange(team, top_lev),
[&](int kk) {
wsub(icol, kk) = wsubmin;
wsubice(icol, kk) = 0.001;
wsig(icol, kk) = 0.001;
});
// parallel_for ranges do not overlap, no need for barrier.
Kokkos::parallel_for(
Kokkos::TeamVectorRange(team, top_lev, nlev), [&](int kk) {
wsub(icol, kk) = haero::sqrt(0.5 * (tke(icol, kk) + tke(icol, kk + 1)) *
(2.0 / 3.0));
wsub(icol, kk) = haero::sqrt(
0.5 * (tke(icol, kk) + tke(icol, kk + 1)) * (2.0 / 3.0));
wsig(icol, kk) =
mam4::utils::min_max_bound(0.001, 10.0, wsub(icol, kk));
wsubice(icol, kk) =
mam4::utils::min_max_bound(0.2, 10.0, wsub(icol, kk));
wsub(icol, kk) = haero::max(wsubmin, wsub(icol, kk));
});
});
});
}

void compute_nucleate_ice_tendencies(
Expand Down Expand Up @@ -184,7 +182,7 @@ void store_liquid_cloud_fraction(
// is above qsmall threshold value
//-------------------------------------------------------------
// cut-off for cloud amount (ice or liquid)
static constexpr auto qsmall = 1e-18; // BAD_CONSTANT
static constexpr auto qsmall = 1e-18; // BAD_CONSTANT
Kokkos::parallel_for(
Kokkos::TeamVectorRange(team, top_lev, nlev), [&](int kk) {
if((qc(icol, kk) + qi(icol, kk)) > qsmall) {
Expand All @@ -202,8 +200,8 @@ void call_function_dropmixnuc(
haero::ThreadTeamPolicy team_policy, const Real dt,
mam_coupling::DryAtmosphere &dry_atmosphere, const MAMAci::view_2d rpdel,
const MAMAci::const_view_2d kvh_mid, const MAMAci::view_2d kvh_int,
const MAMAci::view_2d wsub,
const MAMAci::view_2d cloud_frac, const MAMAci::view_2d cloud_frac_prev,
const MAMAci::view_2d wsub, const MAMAci::view_2d cloud_frac,
const MAMAci::view_2d cloud_frac_prev,
const mam_coupling::AerosolState &dry_aero, const int nlev,
const bool &enable_aero_vertical_mix,

Expand Down Expand Up @@ -231,16 +229,15 @@ void call_function_dropmixnuc(
MAMAci::view_2d raercol[mam4::ndrop::pver][2], MAMAci::view_3d state_q_work,
MAMAci::view_3d nact, MAMAci::view_3d mact,
MAMAci::view_2d dropmixnuc_scratch_mem[MAMAci::dropmix_scratch_]) {

using CO = scream::ColumnOps<DefaultDevice, Real>;
// Extract atmosphere variables
MAMAci::const_view_2d T_mid = dry_atmosphere.T_mid;
MAMAci::const_view_2d p_mid = dry_atmosphere.p_mid;
MAMAci::const_view_2d zm = dry_atmosphere.z_mid;
MAMAci::const_view_2d pdel = dry_atmosphere.p_del;
MAMAci::const_view_2d p_int = dry_atmosphere.p_int;
MAMAci::const_view_2d nc = dry_atmosphere.nc;
MAMAci::const_view_2d atm_dz= dry_atmosphere.dz;
MAMAci::const_view_2d T_mid = dry_atmosphere.T_mid;
MAMAci::const_view_2d p_mid = dry_atmosphere.p_mid;
MAMAci::const_view_2d zm = dry_atmosphere.z_mid;
MAMAci::const_view_2d pdel = dry_atmosphere.p_del;
MAMAci::const_view_2d p_int = dry_atmosphere.p_int;
MAMAci::const_view_2d nc = dry_atmosphere.nc;
MAMAci::const_view_2d atm_dz = dry_atmosphere.dz;

//----------------------------------------------------------------------
// ## Declare local variables for class variables
Expand Down Expand Up @@ -357,7 +354,7 @@ void call_function_dropmixnuc(
haero::Atmosphere haero_atm =
atmosphere_for_column(dry_atmosphere, icol);

// Compute kvh at interfaces
// Compute kvh at interfaces
const auto kvh_mid_col = ekat::subview(kvh_mid, icol);
const auto kvh_int_col = ekat::subview(kvh_int, icol);
const auto dz_col = ekat::subview(atm_dz, icol);
Expand Down Expand Up @@ -480,9 +477,10 @@ void update_interstitial_aerosols(
team_policy, KOKKOS_LAMBDA(const haero::ThreadTeam &team) {
const int icol = team.league_rank();
// update values for all levs at this column
Kokkos::parallel_for(Kokkos::TeamVectorRange(team, nlev), [&](int kk) {
aero_mmr(icol, kk) += ptend_view(icol, kk) * dt;
});
Kokkos::parallel_for(
Kokkos::TeamVectorRange(team, nlev), [&](int kk) {
aero_mmr(icol, kk) += ptend_view(icol, kk) * dt;
});
});
// update index for the next species (only if aero_mmr.data() is True)
++s_idx;
Expand All @@ -495,9 +493,9 @@ void update_interstitial_aerosols(
team_policy, KOKKOS_LAMBDA(const haero::ThreadTeam &team) {
const int icol = team.league_rank();
// update values for all levs at this column
Kokkos::parallel_for(Kokkos::TeamVectorRange(team, nlev), [&](int kk) {
aero_nmr(icol, kk) += ptend_view(icol, kk) * dt;
});
Kokkos::parallel_for(
Kokkos::TeamVectorRange(team, nlev),
[&](int kk) { aero_nmr(icol, kk) += ptend_view(icol, kk) * dt; });
});
++s_idx; // update index for the next species
}
Expand Down Expand Up @@ -530,7 +528,7 @@ void call_hetfrz_compute_tendencies(
haero::Atmosphere haero_atm =
atmosphere_for_column(dry_atmosphere, icol);
haero::Surface surf{};
set_min_background_mmr(team, dry_aero,icol);
set_min_background_mmr(team, dry_aero, icol);
mam4::Prognostics progs =
mam_coupling::aerosols_for_column(dry_aero, icol);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ class MAMAci final : public scream::AtmosphereProcess {
MAMAci(const ekat::Comm &comm, const ekat::ParameterList &params);

// Process metadata: Return type of the process
AtmosphereProcessType type() const override { return AtmosphereProcessType::Physics; }
AtmosphereProcessType type() const override {
return AtmosphereProcessType::Physics;
}

// Return name of the process
std::string name() const override { return "mam4_aci"; }
Expand All @@ -179,7 +181,7 @@ class MAMAci final : public scream::AtmosphereProcess {
// process behavior
void initialize_impl(const RunType run_type) override;
void run_impl(const double dt) override;
void finalize_impl() override {/*DO NOTHING*/};
void finalize_impl() override{/*DO NOTHING*/};

// Atmosphere processes often have a pre-processing step that constructs
// required variables from the set of fields stored in the field manager.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,26 +271,27 @@ void MAMConstituentFluxes::run_impl(const double dt) {
// 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.
// NOTE: We cannot pass a member of the interface class (in this case, MAMConstituentFluxes)
// inside a parallel_for. Instead, we must create a soft copy of each member.
const auto & wet_atm = wet_atm_;
const auto & dry_atm= dry_atm_;
// NOTE: We cannot pass a member of the interface class (in this case,
// MAMConstituentFluxes) inside a parallel_for. Instead, we must create a soft
// copy of each member.
const auto &wet_atm = wet_atm_;
const auto &dry_atm = dry_atm_;

auto lambda =
KOKKOS_LAMBDA(const Kokkos::TeamPolicy<KT::ExeSpace>::member_type &team) {
const int icol = team.league_rank(); // column index
const int icol = team.league_rank(); // column index
compute_dry_mixing_ratios(team, wet_atm, // in
dry_atm, // out
icol); // 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
compute_vertical_layer_heights(team, // in
dry_atm, // out
icol); // in
icol); // in
compute_updraft_velocities(team, wet_atm, // in
dry_atm, // out
icol); // in
icol); // in
};
// policy
const auto scan_policy = ekat::ExeSpaceUtils<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ void MAMDryDep::set_grids(

// Layout for 4D (2d horiz X 1d vertical x number of modes) variables
// at mid points
const int num_aero_modes = mam_coupling::num_aero_modes();
const FieldLayout vector3d_mid =
grid_->get_3d_vector_layout(true, num_aero_modes, mam_coupling::num_modes_tag_name());
const int num_aero_modes = mam_coupling::num_aero_modes();
const FieldLayout vector3d_mid = grid_->get_3d_vector_layout(
true, num_aero_modes, mam_coupling::num_modes_tag_name());

using namespace ekat::units;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ void MAMMicrophysics::set_grids(
constexpr int nmodes = mam4::AeroConfig::num_modes();

// layout for 3D (ncol, nmodes, nlevs)
FieldLayout scalar3d_mid_nmodes =
grid_->get_3d_vector_layout(true, nmodes, mam_coupling::num_modes_tag_name());
FieldLayout scalar3d_mid_nmodes = grid_->get_3d_vector_layout(
true, nmodes, mam_coupling::num_modes_tag_name());

// Geometric mean dry diameter for number distribution [m]
add_field<Required>("dgnum", scalar3d_mid_nmodes, m, grid_name);
Expand Down Expand Up @@ -821,9 +821,9 @@ void MAMMicrophysics::run_impl(const double dt) {
constexpr int gas_pcnst = mam_coupling::gas_pcnst();

const auto &elevated_emis_output = elevated_emis_output_;
const auto &extfrc = extfrc_;
const auto &forcings = forcings_;
constexpr int extcnt = mam4::gas_chemistry::extcnt;
const auto &extfrc = extfrc_;
const auto &forcings = forcings_;
constexpr int extcnt = mam4::gas_chemistry::extcnt;

const int offset_aerosol = mam4::utils::gasses_start_ind();
Real adv_mass_kg_per_moles[gas_pcnst];
Expand All @@ -842,10 +842,10 @@ void MAMMicrophysics::run_impl(const double dt) {
const auto &work_set_het = work_set_het_;
const mam4::seq_drydep::Data drydep_data =
mam4::seq_drydep::set_gas_drydep_data();
const auto qv = wet_atm_.qv;
const int month = timestamp().get_month(); // 1-based
const int surface_lev = nlev - 1; // Surface level
const auto & index_season_lai= index_season_lai_;
const auto qv = wet_atm_.qv;
const int month = timestamp().get_month(); // 1-based
const int surface_lev = nlev - 1; // Surface level
const auto &index_season_lai = index_season_lai_;

// loop over atmosphere columns and compute aerosol microphyscs
Kokkos::parallel_for(
Expand Down Expand Up @@ -923,8 +923,8 @@ void MAMMicrophysics::run_impl(const double dt) {
v_wind(icol, surface_lev) * v_wind(icol, surface_lev));

// Total rain at the surface
const Real rain = precip_liq_surf_mass(icol) +
precip_ice_surf_mass(icol);
const Real rain =
precip_liq_surf_mass(icol) + precip_ice_surf_mass(icol);

// Snow depth on land [m]
const Real snow_height = snow_depth_land(icol);
Expand All @@ -936,55 +936,49 @@ void MAMMicrophysics::run_impl(const double dt) {
for(int i = 0; i < mam4::mo_drydep::n_land_type; ++i) {
fraction_landuse_icol[i] = fraction_landuse(icol, i);
}
int index_season[mam4::mo_drydep::n_land_type];
{

//-------------------------------------------------------------------------------------
// define which season (relative to Northern hemisphere climate)
//-------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------
// define season index based on fixed LAI
//-------------------------------------------------------------------------------------
for (int lt = 0; lt < mam4::mo_drydep::n_land_type; ++lt) {
index_season[lt] = index_season_lai(icol, month - 1);
}

//-------------------------------------------------------------------------------------
// special case for snow covered terrain
//-------------------------------------------------------------------------------------
if (snow_height > 0.01) { // BAD_CONSTANT
for (int lt = 0; lt < mam4::mo_drydep::n_land_type; ++lt) {
index_season[lt] = 3;
}
}
int index_season[mam4::mo_drydep::n_land_type];
{
//-------------------------------------------------------------------------------------
// define which season (relative to Northern hemisphere climate)
//-------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------
// define season index based on fixed LAI
//-------------------------------------------------------------------------------------
for(int lt = 0; lt < mam4::mo_drydep::n_land_type; ++lt) {
index_season[lt] = index_season_lai(icol, month - 1);
}

}
//-------------------------------------------------------------------------------------
// special case for snow covered terrain
//-------------------------------------------------------------------------------------
if(snow_height > 0.01) { // BAD_CONSTANT
for(int lt = 0; lt < mam4::mo_drydep::n_land_type; ++lt) {
index_season[lt] = 3;
}
}
}
// These output values need to be put somewhere:
Real dvel[gas_pcnst] = {}; // deposition velocity [1/cm/s]
Real dflx[gas_pcnst] = {}; // deposition flux [1/cm^2/s]

// Output: values are dvel, dvlx
// Input/Output: progs::stateq, progs::qqcw
mam4::microphysics::perform_atmospheric_chemistry_and_microphysics(
team, dt, rlats, sfc_temperature(icol),
sfc_pressure(icol),
wind_speed, rain,
solar_flux, cnst_offline_icol,
forcings_in, atm, photo_table, chlorine_loading, config.setsox,
config.amicphys, config.linoz.psc_T, zenith_angle(icol),
d_sfc_alb_dir_vis(icol), o3_col_dens_i, photo_rates_icol,
extfrc_icol, invariants_icol, work_photo_table_icol,
linoz_o3_clim_icol, linoz_t_clim_icol, linoz_o3col_clim_icol,
linoz_PmL_clim_icol, linoz_dPmL_dO3_icol, linoz_dPmL_dT_icol,
linoz_dPmL_dO3col_icol, linoz_cariolle_pscs_icol, eccf,
adv_mass_kg_per_moles, fraction_landuse_icol,
index_season,
clsmap_4, permute_4, offset_aerosol, config.linoz.o3_sfc,
config.linoz.o3_tau, config.linoz.o3_lbl, dry_diameter_icol,
wet_diameter_icol, wetdens_icol, dry_atm.phis(icol), cmfdqr,
prain_icol, nevapr_icol, work_set_het_icol, drydep_data, dvel, dflx,
progs);
team, dt, rlats, sfc_temperature(icol), sfc_pressure(icol),
wind_speed, rain, solar_flux, cnst_offline_icol, forcings_in, atm,
photo_table, chlorine_loading, config.setsox, config.amicphys,
config.linoz.psc_T, zenith_angle(icol), d_sfc_alb_dir_vis(icol),
o3_col_dens_i, photo_rates_icol, extfrc_icol, invariants_icol,
work_photo_table_icol, linoz_o3_clim_icol, linoz_t_clim_icol,
linoz_o3col_clim_icol, linoz_PmL_clim_icol, linoz_dPmL_dO3_icol,
linoz_dPmL_dT_icol, linoz_dPmL_dO3col_icol,
linoz_cariolle_pscs_icol, eccf, adv_mass_kg_per_moles,
fraction_landuse_icol, index_season, clsmap_4, permute_4,
offset_aerosol, config.linoz.o3_sfc, config.linoz.o3_tau,
config.linoz.o3_lbl, dry_diameter_icol, wet_diameter_icol,
wetdens_icol, dry_atm.phis(icol), cmfdqr, prain_icol, nevapr_icol,
work_set_het_icol, drydep_data, dvel, dflx, progs);

// Update constituent fluxes with gas drydep fluxes (dflx)
// FIXME: Possible units mismatch (dflx is in kg/cm2/s but
Expand Down
Loading

0 comments on commit 5483fbc

Please sign in to comment.