Skip to content

Commit 1318261

Browse files
authored
add implementation and test for MOSAIC function molality_0 (#96)
* add implementation of molality_0 * add verification data * add tes * remove unused macro * fixing indexing and tolerance
1 parent 497d578 commit 1318261

File tree

6 files changed

+126
-1
lines changed

6 files changed

+126
-1
lines changed

src/core/impl/TChem_Impl_MOSAIC.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,34 @@ struct MOSAIC{
21572157
Po = Po_298*ats<real_type>::exp(-(DH/(RUNIV/1000))*(1.0/T - (1/298.15)));
21582158
} // fn_Po
21592159

2160+
KOKKOS_INLINE_FUNCTION static
2161+
void molality_0(const MosaicModelData<DeviceType>& mosaic,
2162+
const ordinal_type& je,
2163+
real_type& aw,
2164+
real_type& molality) {
2165+
2166+
auto aw_min = mosaic.aw_min.template view<DeviceType>();
2167+
auto a_zsr = mosaic.a_zsr.template view<DeviceType>();
2168+
2169+
aw = max(aw, aw_min(je));
2170+
aw = min(aw, 0.999999);
2171+
2172+
if (aw < 0.97) {
2173+
2174+
real_type xm = a_zsr(0,je) +
2175+
aw*(a_zsr(1,je) +
2176+
aw*(a_zsr(2,je) +
2177+
aw*(a_zsr(3,je) +
2178+
aw*(a_zsr(4,je) +
2179+
aw* a_zsr(5,je) ))));
2180+
2181+
molality = 55.509*xm/(1.0 - xm);
2182+
} else {
2183+
auto b_zsr = mosaic.b_zsr.template view<DeviceType>();
2184+
molality = -b_zsr(je)*ats<real_type>::log(aw);
2185+
}
2186+
} // molality_0
2187+
21602188
};
21612189

21622190
} // 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: molality_0
4+
input:
5+
fixed:
6+
je: [ 5]
7+
aw: [ 0.86918676121422112E+000]
8+
molality_0: [ 0.86918676121422112E+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=[[ 5],]
14+
input.aw=[[ 0.86918676121422112E+000],]
15+
input.molality_0=[[ 0.86918676121422112E+000],]
16+
# Output data is stored here.
17+
output = Object()
18+
output.molality_0=[[ 0.57556452605089108E+001],]

src/verification/mosaic/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ add_executable(${DRIVER_NAME}.x
99
calculate_XT.cpp
1010
fnlog_gamZ.cpp
1111
fn_Keq.cpp
12-
fn_Po.cpp)
12+
fn_Po.cpp
13+
molality_0.cpp)
1314

1415

1516
TARGET_LINK_LIBRARIES(${DRIVER_NAME}.x verification;${TCHEM_ATM_LINK_LIBRARIES})
@@ -24,6 +25,7 @@ SET(TEST_LIST
2425
fnlog_gamZ_input_ts_0
2526
fn_Keq_input_ts_0
2627
fn_Po_input_ts_0
28+
molality_0_input_ts_0
2729
)
2830

2931
SET(TEST_BASELINE
@@ -34,6 +36,7 @@ SET(TEST_BASELINE
3436
fnlog_gamZ_output_ts_0
3537
fn_Keq_output_ts_0
3638
fn_Po_output_ts_0
39+
molality_0_output_ts_0
3740
)
3841

3942
SET(DEFAULT_TOL 1e-9)
@@ -45,6 +48,7 @@ set(ERROR_THRESHOLDS
4548
1e-6 # fnlog_gamZ_output_ts_0
4649
1e-6 # fn_Keq_output_ts_0
4750
1e-8 # fn_Po_output_ts_0
51+
1e-5 # molality_0_output_ts_0
4852
)
4953

5054
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 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 molality_0(Ensemble *ensemble) {
14+
ensemble->process([=](const Input &input, Output &output) {
15+
16+
const auto je_arr = input.get_array("je");
17+
const auto aw_arr = input.get_array("aw");
18+
19+
real_type_1d_view je("je", 1);
20+
verification::convert_1d_vector_to_1d_view_device(je_arr, je);
21+
22+
real_type_1d_view aw("aw", 1);
23+
verification::convert_1d_vector_to_1d_view_device(aw_arr, aw);
24+
25+
const auto mmd = TChem::Impl::MosaicModelData<device_type>();
26+
27+
// Prepare variables for output
28+
29+
// Reals or int that are defined outside of the parallel_for region are passed as const.
30+
real_type_1d_view outputs_molality_0("outputs_molality_0", 1);
31+
32+
std::string profile_name ="Verification_test_molality_0";
33+
using policy_type =
34+
typename TChem::UseThisTeamPolicy<TChem::exec_space>::type;
35+
const auto exec_space_instance = TChem::exec_space();
36+
const auto host_exec_space = TChem::host_exec_space();
37+
policy_type policy(exec_space_instance, 1, Kokkos::AUTO());
38+
39+
// Check this routines on GPUs.
40+
Kokkos::parallel_for(
41+
profile_name,
42+
policy,
43+
KOKKOS_LAMBDA(const typename policy_type::member_type& member) {
44+
45+
Real& molality = outputs_molality_0(0);
46+
47+
// Perform the adjustment calculation
48+
TChem::Impl::MOSAIC<real_type, device_type>::molality_0(
49+
mmd,
50+
je(0)-1,
51+
aw(0),
52+
molality);
53+
});
54+
55+
const auto outputs_molality_0_h = Kokkos::create_mirror_view_and_copy(host_exec_space, outputs_molality_0);
56+
57+
Real molality = outputs_molality_0_h(0);
58+
59+
// Assuming the outputs are scalar and can be directly set in the ensemble
60+
output.set("molality_0", molality);
61+
62+
});
63+
}

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 fn_Keq(Ensemble *ensemble);
2929

3030
void fn_Po(Ensemble *ensemble);
3131

32+
void molality_0(Ensemble *ensemble);
33+
3234
int main(int argc, char **argv) {
3335
if (argc == 1) {
3436
usage();
@@ -66,6 +68,8 @@ int main(int argc, char **argv) {
6668
fn_Keq(ensemble);
6769
} else if (func_name == "fn_Po") {
6870
fn_Po(ensemble);
71+
} else if (func_name == "molality_0") {
72+
molality_0(ensemble);
6973
} else {
7074
std::cerr << "Error: Function name '" << func_name
7175
<< "' does not have an implemented test!" << std::endl;

0 commit comments

Comments
 (0)