Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/core/impl/TChem_Impl_MOSAIC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3137,6 +3137,35 @@ struct MOSAIC{
aerosol_water = dum;
} // aerosol_water_up

KOKKOS_INLINE_FUNCTION static
void aerosol_water(const MosaicModelData<DeviceType>& mosaic,
const real_type_1d_view_type& electrolyte,
const real_type& aH2O_a,
const real_type_1d_view_type& molalities,
real_type& jaerosolstate,
real_type& jphase,
real_type& jhyst_leg,
real_type& aerosol_water) {

for (ordinal_type je = 0; je < mosaic.nelectrolyte; je++) {
real_type molality = 0.0;
bin_molality(mosaic, je, aH2O_a, molality); // compute aH2O dependent binary molalities EFFI
molalities(je) = molality;
}

real_type dum = 0.0;
for (ordinal_type je = 0; je < (mosaic.nsalt + 4); je++) { // include hno3 and hcl in water calculation
dum += electrolyte(je) / molalities(je);
}

aerosol_water = dum * 1.0e-9;
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

The magic number 1.0e-9 should be replaced with a named constant to improve code maintainability and clarity about the unit conversion being performed.

Suggested change
aerosol_water = dum * 1.0e-9;
aerosol_water = dum * VOLUME_CONVERSION_NM3_TO_CM3;

Copilot uses AI. Check for mistakes.
if (aerosol_water <= 0.0) {
jaerosolstate = mosaic.all_solid;
jphase = mosaic.jsolid;
jhyst_leg = mosaic.jhyst_lo;
}
}

};

} // namespace Impl
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/verification/data_sets/mosaic/aerosol_water_input_ts_0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

TChem-atm:
function: aerosol_water
input:
fixed:
electrolyte: [ 0.77984160884932792E-003, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.32374869443985588E-003, 0.10558591027558305E-003, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000]
aH2O_a: [ 0.86918676121422112E+000]
jaerosolstate: [ 2]
jphase: [ 2]
jhyst_leg: [ 1]
25 changes: 25 additions & 0 deletions src/verification/data_sets/mosaic/aerosol_water_output_ts_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

# This file was generated by PartMC-mosaic.

from math import nan as nan, inf as inf

# Object is just a dynamic container that stores input/output data.
class Object(object):
pass
# Settings are stored here.
settings = Object()
# Input is stored here.
input = Object()
input.electrolyte=[[ 0.77984160884932792E-003, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.32374869443985588E-003, 0.10558591027558305E-003, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000,],]
input.aH2O_a=[[ 0.86918676121422112E+000],]
input.jaerosolstate=[[ 2],]
input.jphase=[[ 2],]
input.jhyst_leg=[[ 1],]
# Output data is stored here.
output = Object()
output.jaerosolstate=[[ 2],]
output.jphase=[[ 2],]
output.jhyst_leg=[[ 1],]
output.aerosol_water=[[ 0.27588384862958057E-012],]
output.molalities=[[ 0.39938262305308316E+001, 0.20631562926260667E+001, 0.37125449931321697E+001, 0.37125449931321697E+001, 0.57556783407985233E+001, 0.43319966060422557E+001, 0.36061437563583723E+001, 0.19213285418818216E+001, 0.34951712211340586E+001, 0.34951712211340586E+001, 0.49367058281342588E+001, 0.35858101515618990E+001, 0.24386871472805547E+001, 0.19381152331027600E+001, 0.24386871472805547E+001, 0.27333455732066936E+001, 0.27333455732066936E+001, 0.33978613515005995E+001, 0.29236917930711290E+001, 0.26734712617394891E-004, 0.00000000000000000E+000, 0.00000000000000000E+000,],]
output.aerosol_water=[[ 0.27588384862958057E-012],]
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class Object(object):
input.molality=[[ 0.00000000000000000E+000],]
# Output data is stored here.
output = Object()
output.molality=[[ 0.11753741728360607E+002],]
output.molality=[[ 0.11753752526395242E+002],]
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ input:
fixed:
je: [ 1]
aH2O_a: [ 0.86918676121422112E+000]
molality: [ 0.25344302823602594E-316]
molality: [ 0.25383329068967594E-316]
4 changes: 2 additions & 2 deletions src/verification/data_sets/mosaic/bin_molality_output_ts_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Object(object):
input = Object()
input.je=[[ 1],]
input.aH2O_a=[[ 0.86918676121422112E+000],]
input.molality=[[ 0.25344302823602594E-316],]
input.molality=[[ 0.25383329068967594E-316],]
# Output data is stored here.
output = Object()
output.molality=[[ 0.39937951815127040E+001],]
output.molality=[[ 0.39938262305308316E+001],]
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class Object(object):
input.T_K=[[ 0.29142360000000002E+003],]
# Output data is stored here.
output = Object()
output.drh_mutual=[[ 0.80202077162854152E+002],]
output.drh_mutual=[[ 0.80202061268387610E+002],]
2 changes: 1 addition & 1 deletion src/verification/data_sets/mosaic/fn_Keq_output_ts_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ class Object(object):
input.Keq=[[ 0.10000000000000000E+002],]
# Output data is stored here.
output = Object()
output.Keq=[[ 0.79354086448815266E+002],]
output.Keq=[[ 0.79354109569559270E+002],]
1 change: 0 additions & 1 deletion src/verification/data_sets/mosaic/fn_Po_input_ts_0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ input:
Po_298: [ 0.57000000000000003E-004]
DH: [ 0.15600000000000000E+003]
T_K: [ 0.29142360000000002E+003]
Po: [ 0.29005922138061241E-316]
3 changes: 1 addition & 2 deletions src/verification/data_sets/mosaic/fn_Po_output_ts_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class Object(object):
input.Po_298=[[ 0.57000000000000003E-004],]
input.DH=[[ 0.15600000000000000E+003],]
input.T_K=[[ 0.29142360000000002E+003],]
input.Po=[[ 0.29005922138061241E-316],]
# Output data is stored here.
output = Object()
output.Po=[[ 0.13336165682111354E-004],]
output.Po=[[ 0.13336158741361887E-004],]
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ input:
jA: [ 18]
jE: [ 1]
aH2O: [ 0.86918676121422112E+000]
log_gamZ: [ 0.00000000000000000E+000]
log_gamZ: [ 0.16970466628670999E+000]
4 changes: 2 additions & 2 deletions src/verification/data_sets/mosaic/fnlog_gamZ_output_ts_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Object(object):
input.jA=[[ 18],]
input.jE=[[ 1],]
input.aH2O=[[ 0.86918676121422112E+000],]
input.log_gamZ=[[ 0.00000000000000000E+000],]
input.log_gamZ=[[ 0.16970466628670999E+000],]
# Output data is stored here.
output = Object()
output.log_gamZ=[[ -0.72387479422660039E+000],]
output.log_gamZ=[[ -0.72387466129594991E+000],]
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ TChem-atm:
function: fuchs_sutugin
input:
fixed:
rkn: [ 0.84212889079423601E+001]
rkn: [ 0.11485877229304073E+002]
a: [ 0.10000000149011612E+000]
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Object(object):
settings = Object()
# Input is stored here.
input = Object()
input.rkn=[[ 0.84212889079423601E+001],]
input.rkn=[[ 0.11485877229304073E+002],]
input.a=[[ 0.10000000149011612E+000],]
# Output data is stored here.
output = Object()
output.fuchs_sutugin=[[ 0.88709675466146273E-002],]
output.fuchs_sutugin=[[ 0.65115939063550166E-002],]
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ class Object(object):
input.Vm=[[ 0.42880001068115234E+002],]
# Output data is stored here.
output = Object()
output.gas_diffusivity=[[ 0.11449280832155644E+000],]
output.gas_diffusivity=[[ 0.11449279446086782E+000],]
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ input:
je: [ 5]
aw: [ 0.86918676121422112E+000]
molality_0: [ 0.86918676121422112E+000]
a_zsr: [ 0.43507000000000001E+000, 0.63822000000000001E+001, -0.30197970000000002E+002, 0.53364699999999999E+002, -0.43442030000000003E+002, 0.13461580000000000E+002]
3 changes: 2 additions & 1 deletion src/verification/data_sets/mosaic/molality_0_output_ts_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Object(object):
input.je=[[ 5],]
input.aw=[[ 0.86918676121422112E+000],]
input.molality_0=[[ 0.86918676121422112E+000],]
input.a_zsr=[[ 0.43507000000000001E+000, 0.63822000000000001E+001, -0.30197970000000002E+002, 0.53364699999999999E+002, -0.43442030000000003E+002, 0.13461580000000000E+002,],]
# Output data is stored here.
output = Object()
output.molality_0=[[ 0.57556452605089108E+001],]
output.molality_0=[[ 0.57556783407985233E+001],]
24 changes: 14 additions & 10 deletions src/verification/mosaic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_executable(${DRIVER_NAME}.x
bin_molality_60.cpp
MTEM_compute_log_gamZ.cpp
aerosol_water_up.cpp
aerosol_water.cpp
)


Expand All @@ -45,6 +46,7 @@ SET(TEST_LIST
bin_molality_60_input_ts_0
MTEM_compute_log_gamZ_input_ts_0
aerosol_water_up_input_ts_0
aerosol_water_input_ts_0
)

SET(TEST_BASELINE
Expand All @@ -65,27 +67,29 @@ SET(TEST_BASELINE
bin_molality_60_output_ts_0
MTEM_compute_log_gamZ_output_ts_0
aerosol_water_up_output_ts_0
aerosol_water_output_ts_0
)

SET(DEFAULT_TOL 1e-9)
SET(DEFAULT_TOL 1e-8)
set(ERROR_THRESHOLDS
${DEFAULT_TOL} # check_aerosol_mass_output_ts_0
${DEFAULT_TOL} # adjust_liquid_aerosol_output_ts_0
${DEFAULT_TOL} # adjust_solid_aerosol_output_ts_0
${DEFAULT_TOL} # do_full_deliquescence_output_ts_0
${DEFAULT_TOL} # calculate_XT_output_ts_0
1e-6 # fnlog_gamZ_output_ts_0
${DEFAULT_TOL} # fnlog_gamZ_output_ts_0
${DEFAULT_TOL} # fuchs_sutugin_output_ts_0
1e-7 # gas_diffusivity_output_ts_0
${DEFAULT_TOL} # gas_diffusivity_output_ts_0
${DEFAULT_TOL} # mean_molecular_speed_output_ts_0
1e-6 # fn_Keq_output_ts_0
1e-6 # drh_mutual_output_ts_0
1e-8 # fn_Po_output_ts_0
1e-5 # molality_0_output_ts_0
1e-5 # bin_molality_output_ts_0
1e-6 # bin_molality_60_output_ts_0
1.8e-4 # MTEM_compute_log_gamZ
${DEFAULT_TOL} # fn_Keq_output_ts_0
${DEFAULT_TOL} # drh_mutual_output_ts_0
${DEFAULT_TOL} # fn_Po_output_ts_0
${DEFAULT_TOL} # molality_0_output_ts_0
${DEFAULT_TOL} # bin_molality_output_ts_0
${DEFAULT_TOL} # bin_molality_60_output_ts_0
${DEFAULT_TOL} # MTEM_compute_log_gamZ
${DEFAULT_TOL} # aerosol_water_up_output_ts_0
${DEFAULT_TOL} # aerosol_water_output_ts_0
)

foreach(input tol baseline IN ZIP_LISTS TEST_LIST ERROR_THRESHOLDS TEST_BASELINE)
Expand Down
88 changes: 88 additions & 0 deletions src/verification/mosaic/aerosol_water.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "TChem.hpp"
#include "TChem_Impl_MOSAIC.hpp"
#include <verification.hpp>
#include "skywalker.hpp"

using device_type = typename Tines::UseThisDevice<TChem::exec_space>::type;
using real_type_1d_view = TChem::real_type_1d_view;
using ordinal_type = TChem::ordinal_type;
using namespace skywalker;
using namespace TChem;

void aerosol_water(Ensemble *ensemble) {
ensemble->process([=](const Input &input, Output &output) {

const auto electrolyte_arr = input.get_array("electrolyte");
const auto aH2O_a_arr = input.get_array("aH2O_a");
auto jaerosolstate_arr = input.get_array("jaerosolstate");
auto jphase_arr = input.get_array("jphase");
auto jhyst_leg_arr = input.get_array("jhyst_leg");

const auto mmd = TChem::Impl::MosaicModelData<device_type>();

real_type_1d_view electrolyte("electrolyte", mmd.nelectrolyte);
verification::convert_1d_vector_to_1d_view_device(electrolyte_arr, electrolyte);

real_type_1d_view aH2O_a("aH2O_a", 1);
verification::convert_1d_vector_to_1d_view_device(aH2O_a_arr, aH2O_a);

real_type_1d_view jaerosolstate("jaerosolstate", 1);
verification::convert_1d_vector_to_1d_view_device(jaerosolstate_arr, jaerosolstate);

real_type_1d_view jphase("jphase", 1);
verification::convert_1d_vector_to_1d_view_device(jphase_arr, jphase);

real_type_1d_view jhyst_leg("jhyst_leg", 1);
verification::convert_1d_vector_to_1d_view_device(jhyst_leg_arr, jhyst_leg);

real_type_1d_view outputs_aerosol_water("outputs_aerosol_water", 1);

real_type_1d_view molalities("molalities", mmd.nelectrolyte);

std::string profile_name ="Verification_test_aerosol_water";
using policy_type =
typename TChem::UseThisTeamPolicy<TChem::exec_space>::type;
const auto exec_space_instance = TChem::exec_space();
const auto host_exec_space = TChem::host_exec_space();
policy_type policy(exec_space_instance, 1, Kokkos::AUTO());

// Check this routines on GPUs.
Kokkos::parallel_for(
profile_name,
policy,
KOKKOS_LAMBDA(const typename policy_type::member_type& member) {

Real& aerosol_water = outputs_aerosol_water(0);

// Perform the adjustment calculation
TChem::Impl::MOSAIC<real_type, device_type>::aerosol_water(
mmd,
electrolyte,
aH2O_a(0),
molalities,
jaerosolstate(0),
jphase(0),
jhyst_leg(0),
aerosol_water);
});

const auto outputs_aerosol_water_h = Kokkos::create_mirror_view_and_copy(host_exec_space, outputs_aerosol_water);

Real aerosol_water = outputs_aerosol_water_h(0);

output.set("aerosol_water", aerosol_water);

verification::convert_1d_view_device_to_1d_vector(jaerosolstate, jaerosolstate_arr);
output.set("jaerosolstate", jaerosolstate_arr);

verification::convert_1d_view_device_to_1d_vector(jhyst_leg, jhyst_leg_arr);
output.set("jhyst_leg", jhyst_leg_arr);

verification::convert_1d_view_device_to_1d_vector(jphase, jphase_arr);
output.set("jphase", jphase_arr);

std::vector<real_type> molalities_arr(mmd.nelectrolyte);
verification::convert_1d_view_device_to_1d_vector(molalities, molalities_arr);
output.set("molalities", molalities_arr);
});
}
4 changes: 4 additions & 0 deletions src/verification/mosaic/mosaic_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ void MTEM_compute_log_gamZ(Ensemble *ensemble);

void aerosol_water_up(Ensemble *ensemble);

void aerosol_water(Ensemble *ensemble);

int main(int argc, char **argv) {
if (argc == 1) {
usage();
Expand Down Expand Up @@ -128,6 +130,8 @@ int main(int argc, char **argv) {
MTEM_compute_log_gamZ(ensemble);
} else if (func_name == "aerosol_water_up") {
aerosol_water_up(ensemble);
} else if (func_name == "aerosol_water") {
aerosol_water(ensemble);
} else {
std::cerr << "Error: Function name '" << func_name
<< "' does not have an implemented test!" << std::endl;
Expand Down