Skip to content

Commit 94417b7

Browse files
authored
add implementation and test of MOSAIC function fn_Po (#89)
* implementation of fn_Po * inputs and output for fn_Po * testing files * clean up * formatting changes * change tolerance
1 parent 42b4b5c commit 94417b7

File tree

6 files changed

+116
-7
lines changed

6 files changed

+116
-7
lines changed

src/core/impl/TChem_Impl_MOSAIC.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,16 @@ struct MOSAIC{
21472147
Keq = Keq_298*ats<real_type>::exp(a*(tt - 1.0) + b*(1.0 + ats<real_type>::log(tt) - tt));
21482148
} // fn_Keq
21492149

2150+
KOKKOS_INLINE_FUNCTION static
2151+
void fn_Po(const real_type& Po_298,
2152+
const real_type& DH,
2153+
const real_type& T,
2154+
real_type& Po) {
2155+
2156+
// Van't Hoff Equation
2157+
Po = Po_298*ats<real_type>::exp(-(DH/(RUNIV/1000))*(1.0/T - (1/298.15)));
2158+
} // fn_Po
2159+
21502160
};
21512161

21522162
} // namespace Impl
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
TChem-atm:
3+
function: fn_Po
4+
input:
5+
fixed:
6+
Po_298: [ 0.57000000000000003E-004]
7+
DH: [ 0.15600000000000000E+003]
8+
T: [ 0.29142360000000002E+003]
9+
Po: [ 0.29005922138061241E-316]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.Po_298=[[ 0.57000000000000003E-004],]
14+
input.DH=[[ 0.15600000000000000E+003],]
15+
input.T=[[ 0.29142360000000002E+003],]
16+
input.Po=[[ 0.29005922138061241E-316],]
17+
# Output data is stored here.
18+
output = Object()
19+
output.Po=[[ 0.13336165682111354E-004],]

src/verification/mosaic/CMakeLists.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@ add_executable(${DRIVER_NAME}.x
88
do_full_deliquescence.cpp
99
calculate_XT.cpp
1010
fnlog_gamZ.cpp
11-
fn_Keq.cpp)
11+
fn_Keq.cpp
12+
fn_Po.cpp)
13+
1214

1315
TARGET_LINK_LIBRARIES(${DRIVER_NAME}.x verification;${TCHEM_ATM_LINK_LIBRARIES})
1416

1517

1618
# list of test to run
1719
SET(TEST_LIST
18-
adjust_liquid_aerosol_input_ts_0
19-
adjust_solid_aerosol_input_ts_0
20-
do_full_deliquescence_input_ts_0
21-
calculate_XT_input_ts_0
22-
fnlog_gamZ_input_ts_0
23-
fn_Keq_input_ts_0
20+
adjust_liquid_aerosol_input_ts_0
21+
adjust_solid_aerosol_input_ts_0
22+
do_full_deliquescence_input_ts_0
23+
calculate_XT_input_ts_0
24+
fnlog_gamZ_input_ts_0
25+
fn_Keq_input_ts_0
26+
fn_Po_input_ts_0
2427
)
2528

2629
SET(TEST_BASELINE
@@ -30,6 +33,7 @@ SET(TEST_BASELINE
3033
calculate_XT_output_ts_0
3134
fnlog_gamZ_output_ts_0
3235
fn_Keq_output_ts_0
36+
fn_Po_output_ts_0
3337
)
3438

3539
SET(DEFAULT_TOL 1e-9)
@@ -40,6 +44,7 @@ set(ERROR_THRESHOLDS
4044
${DEFAULT_TOL} # calculate_XT_output_ts_0
4145
1e-6 # fnlog_gamZ_output_ts_0
4246
1e-6 # fn_Keq_output_ts_0
47+
1e-8 # fn_Po_output_ts_0
4348
)
4449

4550
foreach(input tol baseline IN ZIP_LISTS TEST_LIST ERROR_THRESHOLDS TEST_BASELINE)

src/verification/mosaic/fn_Po.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include "TChem.hpp"
2+
#include "TChem_Impl_MOSAIC.hpp"
3+
#include <verification.hpp>
4+
#include "skywalker.hpp"
5+
#define KOKKOS_DEBUG
6+
7+
using device_type = typename Tines::UseThisDevice<TChem::exec_space>::type;
8+
using real_type_1d_view = TChem::real_type_1d_view;
9+
using oridinal_type_1d_view = TChem::ordinal_type_1d_view;
10+
using ordinal_type = TChem::ordinal_type;
11+
using namespace skywalker;
12+
using namespace TChem;
13+
14+
void fn_Po(Ensemble *ensemble) {
15+
ensemble->process([=](const Input &input, Output &output) {
16+
17+
const auto Po_298_arr = input.get_array("Po_298");
18+
const auto DH_arr = input.get_array("DH");
19+
const auto T_arr = input.get_array("T");
20+
21+
real_type_1d_view Po_298("Po_298", 1);
22+
verification::convert_1d_vector_to_1d_view_device(Po_298_arr, Po_298);
23+
24+
real_type_1d_view DH("DH", 1);
25+
verification::convert_1d_vector_to_1d_view_device(DH_arr, DH);
26+
27+
real_type_1d_view T("T", 1);
28+
verification::convert_1d_vector_to_1d_view_device(T_arr, T);
29+
30+
// Reals or int that are defined outside of the parallel_for region are passed as const.
31+
real_type_1d_view outputs_fn_Po("outputs_fn_Po", 1);
32+
33+
std::string profile_name ="Verification_test_fn_Po";
34+
using policy_type =
35+
typename TChem::UseThisTeamPolicy<TChem::exec_space>::type;
36+
const auto exec_space_instance = TChem::exec_space();
37+
const auto host_exec_space = TChem::host_exec_space();
38+
policy_type policy(exec_space_instance, 1, Kokkos::AUTO());
39+
40+
Kokkos::parallel_for(
41+
profile_name,
42+
policy,
43+
KOKKOS_LAMBDA(const typename policy_type::member_type& member) {
44+
45+
Real& Po = outputs_fn_Po(0);
46+
47+
// Perform the adjustment calculation
48+
TChem::Impl::MOSAIC<real_type, device_type>::fn_Po(
49+
Po_298(0),
50+
DH(0),
51+
T(0),
52+
Po);
53+
});
54+
55+
const auto outputs_fn_Po_h = Kokkos::create_mirror_view_and_copy(host_exec_space, outputs_fn_Po);
56+
57+
Real Po = outputs_fn_Po_h(0);
58+
59+
output.set("Po", Po);
60+
61+
});
62+
}

src/verification/mosaic/mosaic_driver.cpp

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

2828
void fn_Keq(Ensemble *ensemble);
2929

30+
void fn_Po(Ensemble *ensemble);
31+
3032
int main(int argc, char **argv) {
3133
if (argc == 1) {
3234
usage();
@@ -62,6 +64,8 @@ int main(int argc, char **argv) {
6264
fnlog_gamZ(ensemble);
6365
} else if (func_name == "fn_Keq") {
6466
fn_Keq(ensemble);
67+
} else if (func_name == "fn_Po") {
68+
fn_Po(ensemble);
6569
} else {
6670
std::cerr << "Error: Function name '" << func_name
6771
<< "' does not have an implemented test!" << std::endl;

0 commit comments

Comments
 (0)