Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Water uptake final. #222

Merged
merged 16 commits into from
Sep 28, 2023
101 changes: 98 additions & 3 deletions src/mam4xx/water_uptake.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ constexpr Real small_value_31 = 1e-31; // (Bad Constant)
// compute aerosol wet density
//-----------------------------------------------------------------------
KOKKOS_INLINE_FUNCTION
void modal_aero_wateruptake_wetdens(
void modal_aero_water_uptake_wetdens(
const Real wetvol[AeroConfig::num_modes()],
const Real wtrvol[AeroConfig::num_modes()],
const Real drymass[AeroConfig::num_modes()],
Expand Down Expand Up @@ -230,7 +230,7 @@ void modal_aero_kohler(const Real rdry_in, const Real hygro, const Real rh,
//
//-----------------------------------------------------------------------
KOKKOS_INLINE_FUNCTION
void modal_aero_wateruptake_wetaer(
void modal_aero_water_uptake_wetaer(
Real rhcrystal[AeroConfig::num_modes()],
Real rhdeliques[AeroConfig::num_modes()],
Real dgncur_a[AeroConfig::num_modes()],
Expand Down Expand Up @@ -352,7 +352,7 @@ void get_e3sm_parameters(
}

KOKKOS_INLINE_FUNCTION
void modal_aero_wateruptake_dryaer(
void modal_aero_water_uptake_dryaer(
int nspec_amode[AeroConfig::num_modes()],
Real specdens_amode[maxd_aspectype], Real spechygro[maxd_aspectype],
int lspectype_amode[maxd_aspectype][AeroConfig::num_modes()],
Expand Down Expand Up @@ -429,7 +429,102 @@ void modal_aero_wateruptake_dryaer(
}
}

KOKKOS_INLINE_FUNCTION
void modal_aero_water_uptake_dr_b4_wetdnes(
pressel marked this conversation as resolved.
Show resolved Hide resolved
int nspec_amode[AeroConfig::num_modes()],
Real specdens_amode[maxd_aspectype], Real spechygro[maxd_aspectype],
int lspectype_amode[maxd_aspectype][AeroConfig::num_modes()],
Real state_q[nvars], Real temperature, Real pmid, Real cldn,
Real dgncur_a[AeroConfig::num_modes()],
Real dgncur_awet[AeroConfig::num_modes()],
Real wetvol[AeroConfig::num_modes()], Real wtrvol[AeroConfig::num_modes()],
Real drymass[AeroConfig::num_modes()],
Real specdens_1[AeroConfig::num_modes()]) {

//----------------------------------------------------------------------------
// retreive aerosol properties

Real hygro[AeroConfig::num_modes()];
Real naer[AeroConfig::num_modes()];
Real dryrad[AeroConfig::num_modes()];
Real dryvol[AeroConfig::num_modes()];
Real rhcrystal[AeroConfig::num_modes()];
Real rhdeliques[AeroConfig::num_modes()];

modal_aero_water_uptake_dryaer(nspec_amode, specdens_amode, spechygro,
lspectype_amode, state_q, dgncur_a, hygro,
naer, dryrad, dryvol, drymass, rhcrystal,
rhdeliques, specdens_1);

// ----------------------------------------------------------------------------
// estimate clear air relative humidity using cloud fraction
Real rh;
modal_aero_water_uptake_rh_clearair(temperature, pmid, state_q[0], cldn, rh);

//----------------------------------------------------------------------------
// compute wet aerosol properties

// compute aerosol wet radius, volume, diameter and aerosol water
Real wetrad[AeroConfig::num_modes()];
Real qaerwat[AeroConfig::num_modes()];
modal_aero_water_uptake_wetaer(rhcrystal, rhdeliques, dgncur_a, dryrad, hygro,
rh, naer, dryvol, wetrad, wetvol, wtrvol,
dgncur_awet, qaerwat);
}

KOKKOS_INLINE_FUNCTION
void modal_aero_water_uptake_dr(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this function corresponds to the subroutine modal_aero_wateruptake_dr from here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does. I've added comments to make this clear.

int nspec_amode[AeroConfig::num_modes()],
Real specdens_amode[maxd_aspectype], Real spechygro[maxd_aspectype],
int lspectype_amode[maxd_aspectype][AeroConfig::num_modes()],
Real state_q[nvars], Real temperature, Real pmid, Real cldn,
Real dgncur_a[AeroConfig::num_modes()],
Real dgncur_awet[AeroConfig::num_modes()],
Real wetdens[AeroConfig::num_modes()]) {

Real drymass[AeroConfig::num_modes()];
Real specdens_1[AeroConfig::num_modes()];
Real wetvol[AeroConfig::num_modes()];
Real wtrvol[AeroConfig::num_modes()];

modal_aero_water_uptake_dr_b4_wetdnes(nspec_amode, specdens_amode, spechygro,
pressel marked this conversation as resolved.
Show resolved Hide resolved
lspectype_amode, state_q, temperature,
pmid, cldn, dgncur_a, dgncur_awet,
wetvol, wtrvol, drymass, specdens_1);

// compute wet aerosol density
modal_aero_water_uptake_wetdens(wetvol, wtrvol, drymass, specdens_1, wetdens);
}

KOKKOS_INLINE_FUNCTION
void modal_aero_water_uptake_dr(
int nspec_amode[AeroConfig::num_modes()],
Real specdens_amode[maxd_aspectype], Real spechygro[maxd_aspectype],
int lspectype_amode[maxd_aspectype][AeroConfig::num_modes()],
Real state_q[nvars], Real temperature, Real pmid, Real cldn,
Real dgncur_a[AeroConfig::num_modes()],
Real dgncur_awet[AeroConfig::num_modes()]) {

Real drymass[AeroConfig::num_modes()];
Real specdens_1[AeroConfig::num_modes()];
Real wetvol[AeroConfig::num_modes()];
Real wtrvol[AeroConfig::num_modes()];

modal_aero_water_uptake_dr_b4_wetdnes(nspec_amode, specdens_amode, spechygro,
pressel marked this conversation as resolved.
Show resolved Hide resolved
lspectype_amode, state_q, temperature,
pmid, cldn, dgncur_a, dgncur_awet,
wetvol, wtrvol, drymass, specdens_1);
}

}; // namespace water_uptake

// init -- initializes the implementation with MAM4's configuration
inline void Water_Uptake::init(const AeroConfig &aero_config,
const Config &process_config) {

config_ = process_config;
};

} // namespace mam4

#endif
7 changes: 6 additions & 1 deletion src/validation/water_uptake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ add_executable(water_uptake_driver
modal_aero_water_uptake_rh_clearair.cpp
modal_aero_water_uptake_wetaer.cpp
modal_aero_water_uptake_dryaer.cpp
modal_aero_water_uptake_dr.cpp
modal_aero_water_uptake_dr_wetdens.cpp
water_uptake_wetdens.cpp
)
target_link_libraries(water_uptake_driver skywalker;validation;${HAERO_LIBRARIES})

Expand All @@ -29,13 +32,15 @@ target_link_libraries(water_uptake_driver skywalker;validation;${HAERO_LIBRARIES
# Run the driver in several configurations to produce datasets.

foreach (input
water_uptake_wetdens
find_real_solution
makoh_quartic
modal_aero_kohler
modal_aero_water_uptake_rh_clearair
modal_aero_water_uptake_wetaer
modal_aero_water_uptake_dryaer
modal_aero_water_uptake_dr
modal_aero_water_uptake_dr_wetdens
water_uptake_wetdens
)

# copy the baseline file into place; is the skywalker file produced by fortran code?
Expand Down
54 changes: 54 additions & 0 deletions src/validation/water_uptake/modal_aero_water_uptake_dr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// mam4xx: Copyright (c) 2022,
// Battelle Memorial Institute and
// National Technology & Engineering Solutions of Sandia, LLC (NTESS)
// SPDX-License-Identifier: BSD-3-Clause

#include <iostream>
#include <mam4xx/aero_modes.hpp>
#include <mam4xx/mam4.hpp>
#include <mam4xx/water_uptake.hpp>
#include <skywalker.hpp>
#include <validation.hpp>

using namespace skywalker;
using namespace mam4;
using namespace haero;

void modal_aero_water_uptake_dr(Ensemble *ensemble) {

// Run the ensemble.
ensemble->process([=](const Input &input, Output &output) {
EKAT_REQUIRE_MSG(input.has_array("state_q"), "Required name: state_q");
EKAT_REQUIRE_MSG(input.has_array("temperature"),
"Required name: temperature");
EKAT_REQUIRE_MSG(input.has_array("pmid"), "Required name: pmid");
EKAT_REQUIRE_MSG(input.has_array("cldn"), "Required name: cldn");
EKAT_REQUIRE_MSG(input.has_array("dgncur_a"), "Required name: dgncur_a");
EKAT_REQUIRE_MSG(input.has_array("dgncur_awet"),
"Required name: dgncur_awet");
EKAT_REQUIRE_MSG(input.has_array("qaerwat"), "Required name: qaerwat");

auto temperature = input.get_array("temperature")[0];
auto pmid = input.get_array("pmid")[0];
auto cldn = input.get_array("cldn")[0];
auto state_q = input.get_array("state_q");
auto dgncur_a = input.get_array("dgncur_a");
auto dgncur_awet = input.get_array("dgncur_awet");
auto qaerwat = input.get_array("qaerwat");

int nspec_amode[AeroConfig::num_modes()];
int lspectype_amode[water_uptake::maxd_aspectype][AeroConfig::num_modes()];
Real specdens_amode[water_uptake::maxd_aspectype];
Real spechygro[water_uptake::maxd_aspectype];

water_uptake::get_e3sm_parameters(nspec_amode, lspectype_amode,
specdens_amode, spechygro);

water_uptake::modal_aero_water_uptake_dr(
nspec_amode, specdens_amode, spechygro, lspectype_amode, state_q.data(),
temperature, pmid, cldn, dgncur_a.data(), dgncur_awet.data());

output.set("dgncur_awet", dgncur_awet);
output.set("qaerwat", qaerwat);
});
}
57 changes: 57 additions & 0 deletions src/validation/water_uptake/modal_aero_water_uptake_dr_wetdens.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// mam4xx: Copyright (c) 2022,
// Battelle Memorial Institute and
// National Technology & Engineering Solutions of Sandia, LLC (NTESS)
// SPDX-License-Identifier: BSD-3-Clause

#include <iostream>
#include <mam4xx/aero_modes.hpp>
#include <mam4xx/mam4.hpp>
#include <mam4xx/water_uptake.hpp>
#include <skywalker.hpp>
#include <validation.hpp>

using namespace skywalker;
using namespace mam4;
using namespace haero;

void modal_aero_water_uptake_dr_wetdens(Ensemble *ensemble) {

// Run the ensemble.
ensemble->process([=](const Input &input, Output &output) {
EKAT_REQUIRE_MSG(input.has_array("state_q"), "Required name: state_q");
EKAT_REQUIRE_MSG(input.has_array("temperature"),
"Required name: temperature");
EKAT_REQUIRE_MSG(input.has_array("pmid"), "Required name: pmid");
EKAT_REQUIRE_MSG(input.has_array("cldn"), "Required name: cldn");
EKAT_REQUIRE_MSG(input.has_array("dgncur_a"), "Required name: dgncur_a");
EKAT_REQUIRE_MSG(input.has_array("dgncur_awet"),
"Required name: dgncur_awet");
EKAT_REQUIRE_MSG(input.has_array("qaerwat"), "Required name: qaerwat");

auto temperature = input.get_array("temperature")[0];
auto pmid = input.get_array("pmid")[0];
auto cldn = input.get_array("cldn")[0];
auto state_q = input.get_array("state_q");
auto dgncur_a = input.get_array("dgncur_a");
auto dgncur_awet = input.get_array("dgncur_awet");
auto qaerwat = input.get_array("qaerwat");

int nspec_amode[AeroConfig::num_modes()];
int lspectype_amode[water_uptake::maxd_aspectype][AeroConfig::num_modes()];
Real specdens_amode[water_uptake::maxd_aspectype];
Real spechygro[water_uptake::maxd_aspectype];

water_uptake::get_e3sm_parameters(nspec_amode, lspectype_amode,
specdens_amode, spechygro);

std::vector<Real> wetdens(AeroConfig::num_modes(), 0.0);
water_uptake::modal_aero_water_uptake_dr(
nspec_amode, specdens_amode, spechygro, lspectype_amode, state_q.data(),
temperature, pmid, cldn, dgncur_a.data(), dgncur_awet.data(),
wetdens.data());

output.set("dgncur_awet", dgncur_awet);
output.set("qaerwat", qaerwat);
output.set("wetdens", wetdens);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void modal_aero_water_uptake_dryaer(Ensemble *ensemble) {
std::vector<Real> rhdeliques(AeroConfig::num_modes(), 0.0);
std::vector<Real> specdens_1(AeroConfig::num_modes(), 0.0);

water_uptake::modal_aero_wateruptake_dryaer(
water_uptake::modal_aero_water_uptake_dryaer(
nspec_amode, specdens_amode, spechygro, lspectype_amode, state_q.data(),
dgncur_a.data(), hygro.data(), naer.data(), dryrad.data(),
dryvol.data(), drymass.data(), rhcrystal.data(), rhdeliques.data(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void modal_aero_water_uptake_wetaer(Ensemble *ensemble) {
std::vector<Real> dgncur_awet(AeroConfig::num_modes(), 0);
std::vector<Real> qaerwat(AeroConfig::num_modes(), 0);

water_uptake::modal_aero_wateruptake_wetaer(
water_uptake::modal_aero_water_uptake_wetaer(
rhcrystal.data(), rhdeliques.data(), dgncur_a.data(), dryrad.data(),
hygro.data(), rh.data()[0], naer.data(), dryvol.data(), wetrad.data(),
wetvol.data(), wtrvol.data(), dgncur_awet.data(), qaerwat.data());
Expand Down
9 changes: 9 additions & 0 deletions src/validation/water_uptake/water_uptake_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ using namespace skywalker;
using namespace mam4;

// Parameterizations used by the drydep process.
// void water_uptake_wetdens(Ensemble *ensemble);
void water_uptake_wetdens(Ensemble *ensemble);
void find_real_solution(Ensemble *ensemble);
void makoh_quartic(Ensemble *ensemble);
void modal_aero_kohler(Ensemble *ensemble);
void modal_aero_water_uptake_rh_clearair(Ensemble *ensemble);
void modal_aero_water_uptake_wetaer(Ensemble *ensemble);
void modal_aero_water_uptake_dryaer(Ensemble *ensemble);
void modal_aero_water_uptake_dr(Ensemble *ensemble);
void modal_aero_water_uptake_dr_wetdens(Ensemble *ensemble);

void usage() {
std::cerr << "aging_driver: a Skywalker driver for validating the "
Expand Down Expand Up @@ -69,6 +72,12 @@ int main(int argc, char **argv) {
if (func_name == "modal_aero_water_uptake_dryaer") {
modal_aero_water_uptake_dryaer(ensemble);
}
if (func_name == "modal_aero_water_uptake_dr") {
modal_aero_water_uptake_dr(ensemble);
}
if (func_name == "modal_aero_water_uptake_dr_wetdens") {
modal_aero_water_uptake_dr_wetdens(ensemble);
}
} catch (std::exception &e) {
std::cerr << argv[0] << ": Error: " << e.what() << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion src/validation/water_uptake/water_uptake_wetdens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void water_uptake_wetdens(Ensemble *ensemble) {

std::vector<Real> wetdens(AeroConfig::num_modes(), 0);

water_uptake::modal_aero_wateruptake_wetdens(
water_uptake::modal_aero_water_uptake_wetdens(
wetvol.data(), wtrvol.data(), drymass.data(), specdens_1.data(),
wetdens.data());

Expand Down
Loading