Skip to content

Commit 87a5e84

Browse files
authored
add implementation and test for MOSAIC function aerosol_water_up (#100)
* implementation of aerosol_water_up * verification data * testing * add missing executable * remove unused line * Update aerosol_water_up.cpp * Update TChem_Impl_MOSAIC.hpp * Update TChem_Impl_MOSAIC.hpp * Update TChem_Impl_MOSAIC.hpp * change input/output fields to match * removed unnecessary output for electrolytes * address comments
1 parent b8608bb commit 87a5e84

File tree

6 files changed

+117
-3
lines changed

6 files changed

+117
-3
lines changed

src/core/impl/TChem_Impl_MOSAIC.hpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,9 +2151,9 @@ struct MOSAIC{
21512151

21522152
KOKKOS_INLINE_FUNCTION static
21532153
void fn_Po(const real_type& Po_298,
2154-
const real_type& DH,
2155-
const real_type& T,
2156-
real_type& Po) {
2154+
const real_type& DH,
2155+
const real_type& T,
2156+
real_type& Po) {
21572157

21582158
// Van't Hoff Equation
21592159
Po = Po_298*ats<real_type>::exp(-(DH/(RUNIV/1000))*(1.0/T - (1/298.15)));
@@ -2624,6 +2624,23 @@ struct MOSAIC{
26242624
log_gamZ(jA,mosaic.jhcl) = log_gamZ_;
26252625
} // MTEM_compute_log_gamZ
26262626

2627+
KOKKOS_INLINE_FUNCTION static
2628+
void aerosol_water_up(const MosaicModelData<DeviceType>& mosaic,
2629+
const real_type_1d_view_type& electrolyte_total,
2630+
real_type& aerosol_water) {
2631+
2632+
real_type dum = 0.0;
2633+
2634+
// TODO: change this for loop to a parallel_reduce
2635+
for (ordinal_type je = 0; je < mosaic.nsalt + 4; je++) {
2636+
real_type molality = 0.0;
2637+
bin_molality_60(mosaic, je, molality);
2638+
dum += 1.e-9*electrolyte_total(je)/molality;
2639+
}
2640+
2641+
aerosol_water = dum;
2642+
} // aerosol_water_up
2643+
26272644
};
26282645

26292646
} // namespace Impl
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
TChem-atm:
3+
function: aerosol_water_up
4+
input:
5+
fixed:
6+
je: [ 0]
7+
electrolyte: [ 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, 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, 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.16512209938719013E-002, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.63332310814312887E-003, 0.21148183165694859E-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]
8+
aerosol_water: [ 0.00000000000000000E+000]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
# This file was generated by PartMC-mosaic.
3+
4+
from math import nan as nan, inf as inf
5+
6+
# Object is just a dynamic container that stores input/output data.
7+
class Object(object):
8+
pass
9+
# Settings are stored here.
10+
settings = Object()
11+
# Input is stored here.
12+
input = Object()
13+
input.je=[[ 0],]
14+
input.electrolyte=[[ 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, 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, 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.16512209938719013E-002, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.00000000000000000E+000, 0.63332310814312887E-003, 0.21148183165694859E-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,],]
15+
input.aerosol_water=[[ 0.00000000000000000E+000],]
16+
# Output data is stored here.
17+
output = Object()
18+
output.aerosol_water=[[ 0.17787296979050271E-012],]

src/verification/mosaic/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_executable(${DRIVER_NAME}.x
1414
bin_molality.cpp
1515
bin_molality_60.cpp
1616
MTEM_compute_log_gamZ.cpp
17+
aerosol_water_up.cpp
1718
)
1819

1920

@@ -34,6 +35,7 @@ SET(TEST_LIST
3435
bin_molality_input_ts_0
3536
bin_molality_60_input_ts_0
3637
MTEM_compute_log_gamZ_input_ts_0
38+
aerosol_water_up_input_ts_0
3739
)
3840

3941
SET(TEST_BASELINE
@@ -48,6 +50,7 @@ SET(TEST_BASELINE
4850
bin_molality_output_ts_0
4951
bin_molality_60_output_ts_0
5052
MTEM_compute_log_gamZ_output_ts_0
53+
aerosol_water_up_output_ts_0
5154
)
5255

5356
SET(DEFAULT_TOL 1e-9)
@@ -63,6 +66,7 @@ set(ERROR_THRESHOLDS
6366
1e-5 # bin_molality_output_ts_0
6467
1e-6 # bin_molality_60_output_ts_0
6568
1.8e-4 # MTEM_compute_log_gamZ
69+
${DEFAULT_TOL} # aerosol_water_up_output_ts_0
6670
)
6771

6872
foreach(input tol baseline IN ZIP_LISTS TEST_LIST ERROR_THRESHOLDS TEST_BASELINE)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include "TChem.hpp"
2+
#include "TChem_Impl_MOSAIC.hpp"
3+
#include <verification.hpp>
4+
#include "skywalker.hpp"
5+
6+
using device_type = typename Tines::UseThisDevice<TChem::exec_space>::type;
7+
using real_type_1d_view = TChem::real_type_1d_view;
8+
using ordinal_type = TChem::ordinal_type;
9+
using namespace skywalker;
10+
using namespace TChem;
11+
12+
void aerosol_water_up(Ensemble *ensemble) {
13+
ensemble->process([=](const Input &input, Output &output) {
14+
15+
const auto electrolyte_db = input.get_array("electrolyte");
16+
17+
const ordinal_type n = 3;
18+
const auto nsize_electrolyte = static_cast<ordinal_type>(electrolyte_db.size())/n;
19+
20+
const auto mmd = TChem::Impl::MosaicModelData<device_type>();
21+
22+
real_type_1d_view electrolyte_solid("electrolyte_solid", nsize_electrolyte);
23+
real_type_1d_view electrolyte_liquid("electrolyte_liquid", nsize_electrolyte);
24+
real_type_1d_view electrolyte_total("electrolyte_total", nsize_electrolyte);
25+
26+
std::vector<std::vector<real_type>> electrolyte_db_2d;
27+
for (size_t i = 0; i < n*nsize_electrolyte; i += nsize_electrolyte) {
28+
std::vector<real_type> electrolyte_temp(electrolyte_db.begin() + i, electrolyte_db.begin() + i + nsize_electrolyte);
29+
electrolyte_db_2d.push_back(electrolyte_temp);
30+
}
31+
32+
verification::convert_1d_vector_to_1d_view_device(electrolyte_db_2d[0], electrolyte_solid);
33+
verification::convert_1d_vector_to_1d_view_device(electrolyte_db_2d[1], electrolyte_liquid);
34+
verification::convert_1d_vector_to_1d_view_device(electrolyte_db_2d[2], electrolyte_total);
35+
36+
real_type_1d_view outputs_aerosol_water_up("outputs_aerosol_water_up", 1);
37+
38+
std::string profile_name ="Verification_test_aerosol_water_up";
39+
using policy_type =
40+
typename TChem::UseThisTeamPolicy<TChem::exec_space>::type;
41+
const auto exec_space_instance = TChem::exec_space();
42+
const auto host_exec_space = TChem::host_exec_space();
43+
policy_type policy(exec_space_instance, 1, Kokkos::AUTO());
44+
45+
Kokkos::parallel_for(
46+
profile_name,
47+
policy,
48+
KOKKOS_LAMBDA(const typename policy_type::member_type& member) {
49+
Real& aerosol_water = outputs_aerosol_water_up(0);
50+
51+
TChem::Impl::MOSAIC<real_type, device_type>::aerosol_water_up(
52+
mmd,
53+
electrolyte_total,
54+
aerosol_water);
55+
});
56+
57+
const auto outputs_aerosol_water_up_h = Kokkos::create_mirror_view_and_copy(host_exec_space, outputs_aerosol_water_up);
58+
59+
Real aerosol_water = outputs_aerosol_water_up_h(0);
60+
61+
output.set("aerosol_water", aerosol_water);
62+
});
63+
}

src/verification/mosaic/mosaic_driver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ void bin_molality_60(Ensemble *ensemble);
3737

3838
void MTEM_compute_log_gamZ(Ensemble *ensemble);
3939

40+
void aerosol_water_up(Ensemble *ensemble);
41+
4042
int main(int argc, char **argv) {
4143
if (argc == 1) {
4244
usage();
@@ -82,6 +84,8 @@ int main(int argc, char **argv) {
8284
bin_molality_60(ensemble);
8385
} else if (func_name == "MTEM_compute_log_gamZ") {
8486
MTEM_compute_log_gamZ(ensemble);
87+
} else if (func_name == "aerosol_water_up") {
88+
aerosol_water_up(ensemble);
8589
} else {
8690
std::cerr << "Error: Function name '" << func_name
8791
<< "' does not have an implemented test!" << std::endl;

0 commit comments

Comments
 (0)