Skip to content

Commit

Permalink
Merge pull request #303 from eagles-project/oscar/wet_dep_integration
Browse files Browse the repository at this point in the history
Oscar/wet dep integration
  • Loading branch information
odiazib authored Jun 3, 2024
2 parents 8a568c2 + ce96755 commit b1c7d98
Show file tree
Hide file tree
Showing 16 changed files with 1,463 additions and 342 deletions.
2 changes: 1 addition & 1 deletion src/mam4xx/aero_config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using Tendencies = Prognostics; // fwd decl
// Number of vertical levels per column (must match the number in the
// host model)
constexpr int nlev = @NUM_VERTICAL_LEVELS@;

constexpr int pcnst = 40;
/// @struct MAM4::AeroConfig: for use with all MAM4 process implementations
class AeroConfig final {
public:
Expand Down
14 changes: 8 additions & 6 deletions src/mam4xx/aero_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#ifndef MAM4XX_AERO_MODEL_HPP
#define MAM4XX_AERO_MODEL_HPP

#include <ekat/kokkos/ekat_subview_utils.hpp>
#include <ekat/util/ekat_math_utils.hpp>

#include <haero/atmosphere.hpp>
#include <haero/math.hpp>

Expand All @@ -27,6 +27,8 @@ const int nrainsvmax = 50; // maximum bin number for rain
const int naerosvmax = 51; // maximum bin number for aerosol
const int maxd_aspectype = 14;

constexpr int pcnst = mam4::pcnst;

KOKKOS_INLINE_FUNCTION
void modal_aero_bcscavcoef_get(
const int imode, const bool isprx_kk, const Real dgn_awet_imode_kk, //& ! in
Expand Down Expand Up @@ -579,8 +581,8 @@ void modal_aero_bcscavcoef_init(
const Real sigmag = sigmag_amode[imode];
// clang-format off
// Note: we replaced lspectype_amode and lspectype_amode for
// dry_aero_density
// const int ll = lspectype_amode[0][imode];
// dry_aero_density
// const int ll = lspectype_amode[0][imode];
// const Real rhodryaero = specdens_amode[ll];
// clang-format on
const Real rhodryaero = aerosol_dry_density[imode];
Expand Down Expand Up @@ -716,7 +718,6 @@ int lptr_nacl_a_amode(const int imode) {
return lptr_nacl_a_amode[imode];
}

static constexpr int pcnst = 40;
KOKKOS_INLINE_FUNCTION
int mmtoo_prevap_resusp(const int i) {
const int mmtoo_prevap_resusp[pcnst] = {
Expand Down Expand Up @@ -867,8 +868,9 @@ void set_f_act_coarse(const int kk,
f_act_conv_coarse_nacl = 0.80;

// dust and seasalt mass concentration [kg/kg]
const int lcoardust = aerosol_index_for_mode(ModeIndex::Coarse, AeroId::DST);
const int lcoarnacl = aerosol_index_for_mode(ModeIndex::Coarse, AeroId::NaCl);
const int idx_coarse = static_cast<int>(ModeIndex::Coarse);
const int lcoardust = aero_model::lptr_dust_a_amode(idx_coarse);
const int lcoarnacl = aero_model::lptr_nacl_a_amode(idx_coarse);
const Real tmpdust =
haero::max(0.0, state_q(kk, lcoardust) + ptend_q(kk, lcoardust) * dt);
const Real tmpnacl =
Expand Down
4 changes: 0 additions & 4 deletions src/mam4xx/modal_aer_opt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ constexpr int ntot_amode = mam4::AeroConfig::num_modes();
// FIXME: is top_lev equal to 1 in aerosol optics ?
constexpr int top_lev = 0;
//
constexpr int pcnst = aero_model::pcnst;
// min, max aerosol surface mode radius treated [m]
constexpr Real rmmin = 0.01e-6; // BAD CONSTANT
constexpr Real rmmax = 25.e-6; // BAD CONSTANT
Expand Down Expand Up @@ -911,8 +910,6 @@ void modal_aero_sw(const ThreadTeam &team, const Real dt,
const auto fa_work = View3D(work_ptr, pver, ntot_amode, nswbands);
work_ptr += pver * ntot_amode * nswbands;

constexpr int pcnst = aero_model::pcnst;

constexpr Real zero = 0;

Kokkos::parallel_for(Kokkos::TeamThreadRange(team, nswbands), [&](int i) {
Expand Down Expand Up @@ -1196,7 +1193,6 @@ void modal_aero_lw(const ThreadTeam &team, const Real dt,
// cldn(:,:) layer cloud fraction [fraction]
// qqcw(:) Cloud borne aerosols mixing ratios [kg/kg or 1/kg]
// tauxar(pcols,pver,nlwbands) layer absorption optical depth
constexpr int pcnst = aero_model::pcnst;

constexpr Real zero = 0.0;
// dry mass in each cell
Expand Down
66 changes: 66 additions & 0 deletions src/mam4xx/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,38 @@ void extract_stateq_from_prognostics(const mam4::Prognostics &progs,
}
} // extract_stateq_from_prognostics

KOKKOS_INLINE_FUNCTION
void extract_ptend_from_tendencies(const Tendencies &tends, Real *ptend,
const int klev) {

int s_idx = ekat::ScalarTraits<int>::invalid();
// FIXME: tendencies for first five item (qv, qc, qi, nc, ni) should no be
// modified by mam4xx is this correct ?
if (tends.q_gas[0].data()) { // if gases are defined in dry_aero aerosol state
s_idx = gasses_start_ind(); // gases start at index 9 (index 10 in Fortran
// version)
for (int g = 0; g < AeroConfig::num_gas_ids(); ++g) {
// get mmr at level "klev"
ptend[s_idx] = tends.q_gas[g](klev);
s_idx++; // update index
}
} else {
s_idx = aero_start_ind(); // If no gasses; start with the first index of
// aerosols
}

// Now start adding aerosols mmr into the state_q
for (int m = 0; m < AeroConfig::num_modes(); ++m) {
// First add the aerosol species mmr
for (int a = 0; a < mam4::num_species_mode(m); ++a) {
ptend[s_idx] = tends.q_aero_i[m][a](klev);
s_idx++; // update index even if we lack some aerosol mmrs
}
ptend[s_idx] = tends.n_mode_i[m](klev);
s_idx++; // update index
}
} // extract_stateq_from_prognostics

KOKKOS_INLINE_FUNCTION
void inject_stateq_to_prognostics(const Real *q, mam4::Prognostics &progs,
const int klev) {
Expand Down Expand Up @@ -291,6 +323,40 @@ void inject_stateq_to_prognostics(const Real *q, mam4::Prognostics &progs,
} // m
}

KOKKOS_INLINE_FUNCTION
void inject_ptend_to_tendencies(const Real *ptend, const Tendencies &tends,
const int klev) {

int s_idx = ekat::ScalarTraits<int>::invalid();

if (tends.q_gas[0].data()) { // if gases are defined in dry_aero aerosol state
s_idx = gasses_start_ind(); // gases start at index 9 (index 10 in Fortran
// version)
for (int g = 0; g < AeroConfig::num_gas_ids(); ++g) {
// get mmr at level "klev"
tends.q_gas[g](klev) = ptend[s_idx];
s_idx++; // update index
}
} else {
s_idx = aero_start_ind(); // If no gasses; start with the first index of
// aerosols
} // end if

// Now start adding aerosols mmr into the state_q
for (int m = 0; m < AeroConfig::num_modes(); ++m) {
// // First add the aerosol species mmr
for (int a = 0; a < mam4::num_species_mode(m); ++a) {
if (tends.q_aero_i[m][a].data()) {
tends.q_aero_i[m][a](klev) = ptend[s_idx];
s_idx++; // update index even if we lack some aerosol mmrs
} // end if
} // a
// Now add aerosol number mmr
tends.n_mode_i[m](klev) = ptend[s_idx];
s_idx++; // update index
} // m
}

// Given an AerosolState with views for dry aerosol quantities, creates a
// cloudborne aerosol mmr 1D view for the column with the given index.
// This object can be provided to mam4xx for the column.
Expand Down
Loading

0 comments on commit b1c7d98

Please sign in to comment.