Skip to content

Commit 67e5b5a

Browse files
authored
add implementation and testing for MOSAIC function drh_mutual (#109)
* add coefficients for MDRH(T) calculation * add implementation of drh_mutual * add fix array size and typos * add verification datasets for drh_mutual * T -> T_K for consistency * testing for drh_mutual
1 parent a53dd6a commit 67e5b5a

File tree

9 files changed

+507
-10
lines changed

9 files changed

+507
-10
lines changed

src/core/impl/TChem_Impl_MOSAIC.hpp

Lines changed: 410 additions & 4 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
TChem-atm:
3+
function: drh_mutual
4+
input:
5+
fixed:
6+
j_index: [ 1]
7+
T_K: [ 0.29142360000000002E+003]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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.j_index=[[ 1],]
14+
input.T_K=[[ 0.29142360000000002E+003],]
15+
# Output data is stored here.
16+
output = Object()
17+
output.drh_mutual=[[ 0.80202077162854152E+002],]

src/verification/data_sets/mosaic/fn_Po_input_ts_0.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ input:
55
fixed:
66
Po_298: [ 0.57000000000000003E-004]
77
DH: [ 0.15600000000000000E+003]
8-
T: [ 0.29142360000000002E+003]
8+
T_K: [ 0.29142360000000002E+003]
99
Po: [ 0.29005922138061241E-316]

src/verification/data_sets/mosaic/fn_Po_output_ts_0.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Object(object):
1212
input = Object()
1313
input.Po_298=[[ 0.57000000000000003E-004],]
1414
input.DH=[[ 0.15600000000000000E+003],]
15-
input.T=[[ 0.29142360000000002E+003],]
15+
input.T_K=[[ 0.29142360000000002E+003],]
1616
input.Po=[[ 0.29005922138061241E-316],]
1717
# Output data is stored here.
1818
output = Object()

src/verification/mosaic/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_executable(${DRIVER_NAME}.x
1010
calculate_XT.cpp
1111
fnlog_gamZ.cpp
1212
fn_Keq.cpp
13+
drh_mutual.cpp
1314
fn_Po.cpp
1415
molality_0.cpp
1516
bin_molality.cpp
@@ -31,6 +32,7 @@ SET(TEST_LIST
3132
calculate_XT_input_ts_0
3233
fnlog_gamZ_input_ts_0
3334
fn_Keq_input_ts_0
35+
drh_mutual_input_ts_0
3436
fn_Po_input_ts_0
3537
molality_0_input_ts_0
3638
bin_molality_input_ts_0
@@ -47,6 +49,7 @@ SET(TEST_BASELINE
4749
calculate_XT_output_ts_0
4850
fnlog_gamZ_output_ts_0
4951
fn_Keq_output_ts_0
52+
drh_mutual_output_ts_0
5053
fn_Po_output_ts_0
5154
molality_0_output_ts_0
5255
bin_molality_output_ts_0
@@ -64,6 +67,7 @@ set(ERROR_THRESHOLDS
6467
${DEFAULT_TOL} # calculate_XT_output_ts_0
6568
1e-6 # fnlog_gamZ_output_ts_0
6669
1e-6 # fn_Keq_output_ts_0
70+
1e-6 # drh_mutual_output_ts_0
6771
1e-8 # fn_Po_output_ts_0
6872
1e-5 # molality_0_output_ts_0
6973
1e-5 # bin_molality_output_ts_0
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 oridinal_type_1d_view = TChem::ordinal_type_1d_view;
9+
using ordinal_type = TChem::ordinal_type;
10+
using namespace skywalker;
11+
using namespace TChem;
12+
13+
void drh_mutual(Ensemble *ensemble) {
14+
ensemble->process([=](const Input &input, Output &output) {
15+
16+
const auto j_index_arr = input.get_array("j_index");
17+
const auto T_K_arr = input.get_array("T_K");
18+
19+
real_type_1d_view j_index("j_index", 1);
20+
verification::convert_1d_vector_to_1d_view_device(j_index_arr, j_index);
21+
22+
real_type_1d_view T_K("T_K", 1);
23+
verification::convert_1d_vector_to_1d_view_device(T_K_arr, T_K);
24+
25+
// Reals or int that are defined outside of the parallel_for region are passed as const.
26+
real_type_1d_view outputs_drh_mutual("outputs_drh_mutual", 1);
27+
28+
const auto mmd = TChem::Impl::MosaicModelData<device_type>();
29+
30+
std::string profile_name ="Verification_test_drh_mutual";
31+
using policy_type =
32+
typename TChem::UseThisTeamPolicy<TChem::exec_space>::type;
33+
const auto exec_space_instance = TChem::exec_space();
34+
const auto host_exec_space = TChem::host_exec_space();
35+
policy_type policy(exec_space_instance, 1, Kokkos::AUTO());
36+
37+
Kokkos::parallel_for(
38+
profile_name,
39+
policy,
40+
KOKKOS_LAMBDA(const typename policy_type::member_type& member) {
41+
42+
Real& drh_mutual = outputs_drh_mutual(0);
43+
44+
// Perform the adjustment calculation
45+
TChem::Impl::MOSAIC<real_type, device_type>::drh_mutual(
46+
mmd,
47+
j_index(0)-1,
48+
T_K(0),
49+
drh_mutual);
50+
});
51+
52+
const auto outputs_drh_mutual_h = Kokkos::create_mirror_view_and_copy(host_exec_space, outputs_drh_mutual);
53+
54+
Real drh_mutual = outputs_drh_mutual_h(0);
55+
56+
output.set("drh_mutual", drh_mutual);
57+
58+
});
59+
}

src/verification/mosaic/fn_Po.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ void fn_Po(Ensemble *ensemble) {
1515

1616
const auto Po_298_arr = input.get_array("Po_298");
1717
const auto DH_arr = input.get_array("DH");
18-
const auto T_arr = input.get_array("T");
18+
const auto T_K_arr = input.get_array("T_K");
1919

2020
real_type_1d_view Po_298("Po_298", 1);
2121
verification::convert_1d_vector_to_1d_view_device(Po_298_arr, Po_298);
2222

2323
real_type_1d_view DH("DH", 1);
2424
verification::convert_1d_vector_to_1d_view_device(DH_arr, DH);
2525

26-
real_type_1d_view T("T", 1);
27-
verification::convert_1d_vector_to_1d_view_device(T_arr, T);
26+
real_type_1d_view T_K("T_K", 1);
27+
verification::convert_1d_vector_to_1d_view_device(T_K_arr, T_K);
2828

2929
// Reals or int that are defined outside of the parallel_for region are passed as const.
3030
real_type_1d_view outputs_fn_Po("outputs_fn_Po", 1);
@@ -47,7 +47,7 @@ void fn_Po(Ensemble *ensemble) {
4747
TChem::Impl::MOSAIC<real_type, device_type>::fn_Po(
4848
Po_298(0),
4949
DH(0),
50-
T(0),
50+
T_K(0),
5151
Po);
5252
});
5353

src/verification/mosaic/mosaic_driver.cpp

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

3030
void fn_Keq(Ensemble *ensemble);
3131

32+
void drh_mutual(Ensemble *ensemble);
33+
3234
void fn_Po(Ensemble *ensemble);
3335

3436
void molality_0(Ensemble *ensemble);
@@ -78,6 +80,8 @@ int main(int argc, char **argv) {
7880
fnlog_gamZ(ensemble);
7981
} else if (func_name == "fn_Keq") {
8082
fn_Keq(ensemble);
83+
} else if (func_name == "drh_mutual") {
84+
drh_mutual(ensemble);
8185
} else if (func_name == "fn_Po") {
8286
fn_Po(ensemble);
8387
} else if (func_name == "molality_0") {

0 commit comments

Comments
 (0)