Skip to content

Commit 73ad121

Browse files
authored
add implementation and test for MOSAIC function mean_molecular_speed (#110)
* add implementation of mean_molecular_speed * add verification data * testing logic
1 parent 67e5b5a commit 73ad121

File tree

6 files changed

+96
-0
lines changed

6 files changed

+96
-0
lines changed

src/core/impl/TChem_Impl_MOSAIC.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,14 @@ struct MOSAIC{
25662566
b_mtem(5,jA,jE) ))));
25672567
} // fnlog_gamZ
25682568

2569+
KOKKOS_INLINE_FUNCTION static
2570+
void mean_molecular_speed(const real_type& T_K,
2571+
const real_type& MW,
2572+
real_type& mean_molec_speed) {
2573+
2574+
mean_molec_speed = 1.455e4 * ats<real_type>::sqrt(T_K/MW);
2575+
} // mean_molecular_speed
2576+
25692577
KOKKOS_INLINE_FUNCTION static
25702578
void fn_Keq(const real_type& Keq_298,
25712579
const real_type& a,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
TChem-atm:
3+
function: mean_molecular_speed
4+
input:
5+
fixed:
6+
T_K: [ 0.29142360000000002E+003]
7+
MW: [ 0.98000000000000000E+002]
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.T_K=[[ 0.29142360000000002E+003],]
14+
input.MW=[[ 0.98000000000000000E+002],]
15+
# Output data is stored here.
16+
output = Object()
17+
output.mean_molecular_speed=[[ 0.25090673256801860E+005],]

src/verification/mosaic/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_executable(${DRIVER_NAME}.x
99
do_full_deliquescence.cpp
1010
calculate_XT.cpp
1111
fnlog_gamZ.cpp
12+
mean_molecular_speed.cpp
1213
fn_Keq.cpp
1314
drh_mutual.cpp
1415
fn_Po.cpp
@@ -31,6 +32,7 @@ SET(TEST_LIST
3132
do_full_deliquescence_input_ts_0
3233
calculate_XT_input_ts_0
3334
fnlog_gamZ_input_ts_0
35+
mean_molecular_speed_input_ts_0
3436
fn_Keq_input_ts_0
3537
drh_mutual_input_ts_0
3638
fn_Po_input_ts_0
@@ -48,6 +50,7 @@ SET(TEST_BASELINE
4850
do_full_deliquescence_output_ts_0
4951
calculate_XT_output_ts_0
5052
fnlog_gamZ_output_ts_0
53+
mean_molecular_speed_output_ts_0
5154
fn_Keq_output_ts_0
5255
drh_mutual_output_ts_0
5356
fn_Po_output_ts_0
@@ -66,6 +69,7 @@ set(ERROR_THRESHOLDS
6669
${DEFAULT_TOL} # do_full_deliquescence_output_ts_0
6770
${DEFAULT_TOL} # calculate_XT_output_ts_0
6871
1e-6 # fnlog_gamZ_output_ts_0
72+
${DEFAULT_TOL} # mean_molecular_speed_output_ts_0
6973
1e-6 # fn_Keq_output_ts_0
7074
1e-6 # drh_mutual_output_ts_0
7175
1e-8 # fn_Po_output_ts_0
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 mean_molecular_speed(Ensemble *ensemble) {
14+
ensemble->process([=](const Input &input, Output &output) {
15+
16+
const auto T_K_arr = input.get_array("T_K");
17+
const auto MW_arr = input.get_array("MW");
18+
19+
real_type_1d_view T_K("T_K", 1);
20+
verification::convert_1d_vector_to_1d_view_device(T_K_arr, T_K);
21+
22+
real_type_1d_view MW("MW", 1);
23+
verification::convert_1d_vector_to_1d_view_device(MW_arr, MW);
24+
25+
// Reals or int that are defined outside of the parallel_for region are passed as const.
26+
real_type_1d_view outputs_mean_molecular_speed("outputs_mean_molecular_speed", 1);
27+
28+
std::string profile_name ="Verification_test_mean_molecular_speed";
29+
using policy_type =
30+
typename TChem::UseThisTeamPolicy<TChem::exec_space>::type;
31+
const auto exec_space_instance = TChem::exec_space();
32+
const auto host_exec_space = TChem::host_exec_space();
33+
policy_type policy(exec_space_instance, 1, Kokkos::AUTO());
34+
35+
Kokkos::parallel_for(
36+
profile_name,
37+
policy,
38+
KOKKOS_LAMBDA(const typename policy_type::member_type& member) {
39+
40+
Real& mean_molecular_speed = outputs_mean_molecular_speed(0);
41+
42+
// Perform the adjustment calculation
43+
TChem::Impl::MOSAIC<real_type, device_type>::mean_molecular_speed(
44+
T_K(0),
45+
MW(0),
46+
mean_molecular_speed);
47+
});
48+
49+
const auto outputs_mean_molecular_speed_h = Kokkos::create_mirror_view_and_copy(host_exec_space, outputs_mean_molecular_speed);
50+
51+
Real mean_molecular_speed = outputs_mean_molecular_speed_h(0);
52+
53+
output.set("mean_molecular_speed", mean_molecular_speed);
54+
55+
});
56+
}

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 calculate_XT(Ensemble *ensemble);
2727

2828
void fnlog_gamZ(Ensemble *ensemble);
2929

30+
void mean_molecular_speed(Ensemble *ensemble);
31+
3032
void fn_Keq(Ensemble *ensemble);
3133

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

0 commit comments

Comments
 (0)