Skip to content

Commit

Permalink
Changes dims for dgnum in aci interface
Browse files Browse the repository at this point in the history
  • Loading branch information
singhbalwinder committed Oct 14, 2024
1 parent 6fb4b32 commit 1437d21
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 90 deletions.
161 changes: 81 additions & 80 deletions components/eamxx/src/physics/mam/eamxx_mam_aci_process_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ void MAMAci::set_grids(
// Define the different field layouts that will be used for this process
using namespace ShortFieldTagsNames;

// Layout for 3D (2d horiz X 1d vertical) variables
// mid points
FieldLayout scalar3d_layout_mid{{COL, LEV}, {ncol_, nlev_}};
// Layout for 2D (2d horiz) variable
const FieldLayout scalar2d = grid_->get_2d_scalar_layout();

// Layout for 3D (2d horiz X 1d vertical) variable defined at mid-level and
// interfaces
FieldLayout scalar3d_layout_int{{COL, ILEV}, {ncol_, nlev_ + 1}};
const FieldLayout scalar3d_mid = grid_->get_3d_scalar_layout(true);
const FieldLayout scalar3d_int = grid_->get_3d_scalar_layout(false);

// layout for 2D (1d horiz X 1d vertical) variable
FieldLayout scalar2d_layout_col{{COL}, {ncol_}};
Expand All @@ -79,80 +81,81 @@ void MAMAci::set_grids(
};

using namespace ekat::units;
auto q_unit = kg / kg; // units of mass mixing ratios of tracers
auto n_unit = 1 / kg; // units of number mixing ratios of tracers
constexpr auto q_unit = kg / kg; // units of mass mixing ratios of tracers
constexpr auto n_unit = 1 / kg; // units of number mixing ratios of tracers

auto nondim = ekat::units::Units::nondimensional();
constexpr auto nondim = ekat::units::Units::nondimensional();

// atmospheric quantities
// specific humidity [kg/kg]
add_field<Required>("qv", scalar3d_layout_mid, q_unit, grid_name, "tracers");
add_field<Required>("qv", scalar3d_mid, q_unit, grid_name, "tracers");

// cloud liquid mass mixing ratio [kg/kg]
add_field<Required>("qc", scalar3d_layout_mid, q_unit, grid_name, "tracers");
add_field<Required>("qc", scalar3d_mid, q_unit, grid_name, "tracers");

// cloud ice mass mixing ratio [kg/kg]
add_field<Required>("qi", scalar3d_layout_mid, q_unit, grid_name, "tracers");
add_field<Required>("qi", scalar3d_mid, q_unit, grid_name, "tracers");

// cloud liquid number mixing ratio [1/kg]
add_field<Required>("nc", scalar3d_layout_mid, n_unit, grid_name, "tracers");
add_field<Required>("nc", scalar3d_mid, n_unit, grid_name, "tracers");

// cloud ice number mixing ratio [1/kg]
add_field<Required>("ni", scalar3d_layout_mid, n_unit, grid_name, "tracers");
add_field<Required>("ni", scalar3d_mid, n_unit, grid_name, "tracers");

// Temperature[K] at midpoints
add_field<Required>("T_mid", scalar3d_layout_mid, K, grid_name);
add_field<Required>("T_mid", scalar3d_mid, K, grid_name);

// Vertical pressure velocity [Pa/s] at midpoints
add_field<Required>("omega", scalar3d_layout_mid, Pa / s, grid_name);
add_field<Required>("omega", scalar3d_mid, Pa / s, grid_name);

// Total pressure [Pa] at midpoints
add_field<Required>("p_mid", scalar3d_layout_mid, Pa, grid_name);
add_field<Required>("p_mid", scalar3d_mid, Pa, grid_name);

// Total pressure [Pa] at interfaces
add_field<Required>("p_int", scalar3d_layout_int, Pa, grid_name);
add_field<Required>("p_int", scalar3d_int, Pa, grid_name);

// Layer thickness(pdel) [Pa] at midpoints
add_field<Required>("pseudo_density", scalar3d_layout_mid, Pa, grid_name);
add_field<Required>("pseudo_density", scalar3d_mid, Pa, grid_name);

// planetary boundary layer height
add_field<Required>("pbl_height", scalar2d_layout_col, m, grid_name);

// cloud fraction [nondimensional] computed by eamxx_cld_fraction_process
add_field<Required>("cldfrac_tot", scalar3d_layout_mid, nondim, grid_name);
add_field<Required>("cldfrac_tot", scalar3d_mid, nondim, grid_name);

auto m2 = pow(m, 2);
auto s2 = pow(s, 2);
constexpr auto m2 = pow(m, 2);
constexpr auto s2 = pow(s, 2);

// NOTE: w_variance im microp_aero.F90 in EAM is at "itim_old" dynamics time
// step. Since, we are using SE dycore, itim_old is 1 which is equivalent to
// the current time step. For other dycores (such as EUL), it may be different
// and we might need to revisit this.

// Vertical velocity variance at midpoints
add_field<Required>("w_variance", scalar3d_layout_mid, m2 / s2, grid_name);
add_field<Required>("w_variance", scalar3d_mid, m2 / s2, grid_name);

// NOTE: "cldfrac_liq" is updated in SHOC. "cldfrac_liq" in C++ code is
// equivalent to "alst" in the shoc_intr.F90. In the C++ code, it is used as
// "shoc_cldfrac" and in the F90 code it is called "cloud_frac"

// Liquid stratiform cloud fraction at midpoints
add_field<Required>("cldfrac_liq", scalar3d_layout_mid, nondim, grid_name);
add_field<Required>("cldfrac_liq", scalar3d_mid, nondim, grid_name);

// Previous value of liquid stratiform cloud fraction at midpoints
add_field<Required>("cldfrac_liq_prev", scalar3d_layout_mid, nondim,
grid_name);
add_field<Required>("cldfrac_liq_prev", scalar3d_mid, nondim, grid_name);

// Eddy diffusivity for heat
add_field<Required>("eddy_diff_heat", scalar3d_layout_mid, m2 / s, grid_name);
add_field<Required>("eddy_diff_heat", scalar3d_mid, m2 / s, grid_name);

// Layout for 4D (2d horiz X 1d vertical x number of modes) variables
const int num_aero_modes = mam_coupling::num_aero_modes();
FieldLayout scalar4d_layout_mid =
make_layout({ncol_, num_aero_modes, nlev_}, {"COL", "NMODES", "LEV"});
// Number of modes
constexpr int nmodes = mam4::AeroConfig::num_modes();

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

// dry diameter of aerosols [m]
add_field<Required>("dgnum", scalar4d_layout_mid, m, grid_name);
add_field<Required>("dgnum", scalar3d_mid_nmodes, m, grid_name);

// ========================================================================
// Output from this whole process
Expand All @@ -164,96 +167,92 @@ void MAMAci::set_grids(
// interstitial aerosol tracers of interest: number (n) mixing ratios
const char *int_nmr_field_name =
mam_coupling::int_aero_nmr_field_name(mode);
add_field<Updated>(int_nmr_field_name, scalar3d_layout_mid, n_unit,
grid_name, "tracers");
add_field<Updated>(int_nmr_field_name, scalar3d_mid, n_unit, grid_name,
"tracers");

// cloudborne aerosol tracers of interest: number (n) mixing ratios
// NOTE: DO NOT add cld borne aerosols to the "tracer" group as these are
// NOT advected
const char *cld_nmr_field_name =
mam_coupling::cld_aero_nmr_field_name(mode);
add_field<Updated>(cld_nmr_field_name, scalar3d_layout_mid, n_unit,
grid_name);
add_field<Updated>(cld_nmr_field_name, scalar3d_mid, n_unit, grid_name);

for(int a = 0; a < mam_coupling::num_aero_species(); ++a) {
// (interstitial) aerosol tracers of interest: mass (q) mixing ratios
const char *int_mmr_field_name =
mam_coupling::int_aero_mmr_field_name(mode, a);
if(strlen(int_mmr_field_name) > 0) {
add_field<Updated>(int_mmr_field_name, scalar3d_layout_mid, q_unit,
grid_name, "tracers");
add_field<Updated>(int_mmr_field_name, scalar3d_mid, q_unit, grid_name,
"tracers");
}
// (cloudborne) aerosol tracers of interest: mass (q) mixing ratios
// NOTE: DO NOT add cld borne aerosols to the "tracer" group as these are
// NOT advected
const char *cld_mmr_field_name =
mam_coupling::cld_aero_mmr_field_name(mode, a);
if(strlen(cld_mmr_field_name) > 0) {
add_field<Updated>(cld_mmr_field_name, scalar3d_layout_mid, q_unit,
grid_name);
add_field<Updated>(cld_mmr_field_name, scalar3d_mid, q_unit, grid_name);
}
} // end for loop num species
} // end for loop for num modes

for(int g = 0; g < mam_coupling::num_aero_gases(); ++g) {
const char *gas_mmr_field_name = mam_coupling::gas_mmr_field_name(g);
add_field<Updated>(gas_mmr_field_name, scalar3d_layout_mid, q_unit,
grid_name, "tracers");
add_field<Updated>(gas_mmr_field_name, scalar3d_mid, q_unit, grid_name,
"tracers");
} // end for loop num gases

// ------------------------------------------------------------------------
// Output from ice nucleation process
// ------------------------------------------------------------------------

// number of activated aerosol for ice nucleation[#/kg]
add_field<Computed>("ni_activated", scalar3d_layout_mid, n_unit, grid_name);
add_field<Computed>("ni_activated", scalar3d_mid, n_unit, grid_name);

// ------------------------------------------------------------------------
// Output from droplet activation process (dropmixnuc)
// ------------------------------------------------------------------------

// tendency in droplet number mixing ratio [#/kg/s]
add_field<Computed>("nc_nuceat_tend", scalar3d_layout_mid, n_unit / s,
grid_name);
add_field<Computed>("nc_nuceat_tend", scalar3d_mid, n_unit / s, grid_name);

// FIXME: [TEMPORARY]droplet number mixing ratio source tendency [#/kg/s]
add_field<Computed>("nsource", scalar3d_layout_mid, n_unit / s, grid_name);
add_field<Computed>("nsource", scalar3d_mid, n_unit / s, grid_name);

// FIXME: [TEMPORARY]droplet number mixing ratio tendency due to mixing
// [#/kg/s]
add_field<Computed>("ndropmix", scalar3d_layout_mid, n_unit / s, grid_name);
add_field<Computed>("ndropmix", scalar3d_mid, n_unit / s, grid_name);

// FIXME: [TEMPORARY]droplet number as seen by ACI [#/kg]
add_field<Computed>("nc_inp_to_aci", scalar3d_layout_mid, n_unit / s,
grid_name);
const auto cm_tmp = m / 100; // FIXME: [TEMPORARY] remove this
const auto cm3 = cm_tmp * cm_tmp * cm_tmp; // FIXME: [TEMPORARY] remove this
add_field<Computed>("nc_inp_to_aci", scalar3d_mid, n_unit / s, grid_name);
constexpr auto cm_tmp = m / 100; // FIXME: [TEMPORARY] remove this
constexpr auto cm3 = pow(cm_tmp, 3); // FIXME: [TEMPORARY] remove this
// FIXME: [TEMPORARY] remove the following ccn outputs
add_field<Computed>("ccn_0p02", scalar3d_layout_mid, cm3, grid_name);
add_field<Computed>("ccn_0p05", scalar3d_layout_mid, cm3, grid_name);
add_field<Computed>("ccn_0p1", scalar3d_layout_mid, cm3, grid_name);
add_field<Computed>("ccn_0p2", scalar3d_layout_mid, cm3, grid_name);
add_field<Computed>("ccn_0p5", scalar3d_layout_mid, cm3, grid_name);
add_field<Computed>("ccn_1p0", scalar3d_layout_mid, cm3, grid_name);
add_field<Computed>("ccn_0p02", scalar3d_mid, cm3, grid_name);
add_field<Computed>("ccn_0p05", scalar3d_mid, cm3, grid_name);
add_field<Computed>("ccn_0p1", scalar3d_mid, cm3, grid_name);
add_field<Computed>("ccn_0p2", scalar3d_mid, cm3, grid_name);
add_field<Computed>("ccn_0p5", scalar3d_mid, cm3, grid_name);
add_field<Computed>("ccn_1p0", scalar3d_mid, cm3, grid_name);

// ------------------------------------------------------------------------
// Output from hetrozenous freezing
// ------------------------------------------------------------------------

const auto cm = m / 100;
constexpr auto cm = m / 100;

// units of number mixing ratios of tracers
auto frz_unit = 1 / (cm * cm * cm * s);
constexpr auto frz_unit = 1 / (cm * cm * cm * s);
// heterogeneous freezing by immersion nucleation [cm^-3 s^-1]
add_field<Computed>("hetfrz_immersion_nucleation_tend", scalar3d_layout_mid,
add_field<Computed>("hetfrz_immersion_nucleation_tend", scalar3d_mid,
frz_unit, grid_name);

// heterogeneous freezing by contact nucleation [cm^-3 s^-1]
add_field<Computed>("hetfrz_contact_nucleation_tend", scalar3d_layout_mid,
frz_unit, grid_name);
add_field<Computed>("hetfrz_contact_nucleation_tend", scalar3d_mid, frz_unit,
grid_name);

// heterogeneous freezing by deposition nucleation [cm^-3 s^-1]
add_field<Computed>("hetfrz_deposition_nucleation_tend", scalar3d_layout_mid,
add_field<Computed>("hetfrz_deposition_nucleation_tend", scalar3d_mid,
frz_unit, grid_name);
} // function set_grids ends

Expand Down Expand Up @@ -302,11 +301,11 @@ void MAMAci::initialize_impl(const RunType run_type) {

// store rest fo the atm fields in dry_atm_in
dry_atm_.z_surf = 0;
dry_atm_.T_mid = get_field_in("T_mid").get_view<const Real **>();
dry_atm_.p_mid = get_field_in("p_mid").get_view<const Real **>();
dry_atm_.p_int = get_field_in("p_int").get_view<const Real **>();
dry_atm_.p_del = get_field_in("pseudo_density").get_view<const Real **>();
dry_atm_.omega = get_field_in("omega").get_view<const Real **>();
dry_atm_.T_mid = get_field_in("T_mid").get_view<const Real **>();
dry_atm_.p_mid = get_field_in("p_mid").get_view<const Real **>();
dry_atm_.p_int = get_field_in("p_int").get_view<const Real **>();
dry_atm_.p_del = get_field_in("pseudo_density").get_view<const Real **>();
dry_atm_.omega = get_field_in("omega").get_view<const Real **>();

// store fields converted to dry mmr from wet mmr in dry_atm_
dry_atm_.qv = buffer_.qv_dry;
Expand Down Expand Up @@ -564,7 +563,8 @@ void MAMAci::run_impl(const double dt) {
// output
w0_, rho_);

compute_tke_at_interfaces(team_policy, w_sec_mid_, dry_atm_.dz, nlev_, w_sec_int_,
compute_tke_at_interfaces(team_policy, w_sec_mid_, dry_atm_.dz, nlev_,
w_sec_int_,
// output
tke_);

Expand Down Expand Up @@ -597,25 +597,26 @@ void MAMAci::run_impl(const double dt) {
// output
cloud_frac_, cloud_frac_prev_);

mam_coupling::compute_recipical_pseudo_density(team_policy, dry_atm_.p_del, nlev_,
// output
rpdel_);
mam_coupling::compute_recipical_pseudo_density(team_policy, dry_atm_.p_del,
nlev_,
// output
rpdel_);

Kokkos::fence(); // wait for rpdel_ to be computed.

// Compute activated CCN number tendency (tendnd_) and updated
// cloud borne aerosols (stored in a work array) and interstitial
// aerosols tendencies
call_function_dropmixnuc(team_policy, dt, dry_atm_, rpdel_, kvh_mid_, kvh_int_, wsub_,
cloud_frac_, cloud_frac_prev_, dry_aero_, nlev_,
// output
coltend_, coltend_cw_, qcld_, ndropcol_, ndropmix_,
nsource_, wtke_, ccn_,
// ## output to be used by the other processes ##
qqcw_fld_work_, ptend_q_, factnum_, tendnd_,
// work arrays
raercol_cw_, raercol_, state_q_work_, nact_, mact_,
dropmixnuc_scratch_mem_);
call_function_dropmixnuc(
team_policy, dt, dry_atm_, rpdel_, kvh_mid_, kvh_int_, wsub_, cloud_frac_,
cloud_frac_prev_, dry_aero_, nlev_,
// output
coltend_, coltend_cw_, qcld_, ndropcol_, ndropmix_, nsource_, wtke_, ccn_,
// ## output to be used by the other processes ##
qqcw_fld_work_, ptend_q_, factnum_, tendnd_,
// work arrays
raercol_cw_, raercol_, state_q_work_, nact_, mact_,
dropmixnuc_scratch_mem_);
Kokkos::fence(); // wait for ptend_q_ to be computed.

Kokkos::deep_copy(ccn_0p02_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void MAMMicrophysics::set_grids(
nlev_ = grid_->get_num_vertical_levels(); // number of levels per column

// get column geometry and locations
col_latitudes_ = grid_->get_geometry_data("lat").get_view<const Real *>();
col_latitudes_ = grid_->get_geometry_data("lat").get_view<const Real *>();

// define the different field layouts that will be used for this process
using namespace ShortFieldTagsNames;
Expand Down Expand Up @@ -271,7 +271,7 @@ void MAMMicrophysics::set_grids(
} // LINOZ reader

{
oxid_file_name_ = m_params.get<std::string>("mam4_oxid_file_name");
oxid_file_name_ = m_params.get<std::string>("mam4_oxid_file_name");
std::string oxid_map_file = "";
// NOTE: order matches mam4xx:
std::vector<std::string> var_names{"O3", "OH", "NO3", "HO2"};
Expand Down Expand Up @@ -457,10 +457,10 @@ void MAMMicrophysics::initialize_impl(const RunType run_type) {
wet_atm_.qi = get_field_in("qi").get_view<const Real **>();
wet_atm_.ni = get_field_in("ni").get_view<const Real **>();

dry_atm_.T_mid = get_field_in("T_mid").get_view<const Real **>();
dry_atm_.p_mid = get_field_in("p_mid").get_view<const Real **>();
dry_atm_.p_int = get_field_in("p_int").get_view<const Real **>();
dry_atm_.p_del = get_field_in("pseudo_density").get_view<const Real **>();
dry_atm_.T_mid = get_field_in("T_mid").get_view<const Real **>();
dry_atm_.p_mid = get_field_in("p_mid").get_view<const Real **>();
dry_atm_.p_int = get_field_in("p_int").get_view<const Real **>();
dry_atm_.p_del = get_field_in("pseudo_density").get_view<const Real **>();
dry_atm_.cldfrac = get_field_in("cldfrac_liq").get_view<const Real **>();
dry_atm_.pblh = get_field_in("pbl_height").get_view<const Real *>();
dry_atm_.phis = get_field_in("phis").get_view<const Real *>();
Expand Down Expand Up @@ -633,7 +633,7 @@ void MAMMicrophysics::run_impl(const double dt) {
auto linoz_o3_clim = buffer_.scratch[0];
// column o3 above box (climatology) [Dobson Units (DU)]
auto linoz_o3col_clim = buffer_.scratch[1];
auto linoz_t_clim = buffer_.scratch[2]; // temperature (climatology) [K]
auto linoz_t_clim = buffer_.scratch[2]; // temperature (climatology) [K]
auto linoz_PmL_clim = buffer_.scratch[3]; // P minus L (climatology) [vmr/s]
// sensitivity of P minus L to O3 [1/s]
auto linoz_dPmL_dO3 = buffer_.scratch[4];
Expand Down Expand Up @@ -733,7 +733,7 @@ void MAMMicrophysics::run_impl(const double dt) {
}
#endif

const_view_1d &col_latitudes = col_latitudes_;
const_view_1d &col_latitudes = col_latitudes_;
const_view_1d &d_sfc_alb_dir_vis = d_sfc_alb_dir_vis_;

mam_coupling::DryAtmosphere &dry_atm = dry_atm_;
Expand Down Expand Up @@ -829,11 +829,10 @@ void MAMMicrophysics::run_impl(const double dt) {
const Real o3_tau = o3_tau_;
const Real o3_sfc = o3_sfc_;


// loop over atmosphere columns and compute aerosol microphyscs
Kokkos::parallel_for(
policy, KOKKOS_LAMBDA(const ThreadTeam &team) {
const int icol = team.league_rank(); // column index
const int icol = team.league_rank(); // column index
const Real col_lat = col_latitudes(icol); // column latitude (degrees?)

// convert column latitude to radians
Expand Down

0 comments on commit 1437d21

Please sign in to comment.