Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/core/impl/TChem_Impl_MOSAIC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2137,6 +2137,16 @@ struct MOSAIC{
b_mtem(5,jA,jE) ))));
} // fnlog_gamZ

KOKKOS_INLINE_FUNCTION static
void gas_diffusivity(const real_type& T_K,
const real_type& P,
const real_type& MW,
const real_type& Vm,
real_type& gas_diff) {
gas_diff = (1.0e-3 * ats<real_type>::pow(T_K, 1.75) * ats<real_type>::sqrt(1.0/MW + 0.035))/
(P * ats<real_type>::pow(ats<real_type>::pow(Vm, 0.333333) + 2.7189, 2.0));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if replacing 0.333333 with 1./3. might help reduce the ERROR_THRESHOLDS. Given the simplicity of this expression, I was expecting a smaller error margin to pass the test.

} // gas_diffusivity

KOKKOS_INLINE_FUNCTION static
void fn_Keq(const real_type& Keq_298,
const real_type& a,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

TChem-atm:
function: gas_diffusivity
input:
fixed:
T_K: [ 0.29142360000000002E+003]
P: [ 0.98692326671601283E+000]
MW: [ 0.98000000000000000E+002]
Vm: [ 0.42880001068115234E+002]
19 changes: 19 additions & 0 deletions src/verification/data_sets/mosaic/gas_diffusivity_output_ts_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# This file was generated by PartMC-mosaic.

from math import nan as nan, inf as inf

# Object is just a dynamic container that stores input/output data.
class Object(object):
pass
# Settings are stored here.
settings = Object()
# Input is stored here.
input = Object()
input.T_K=[[ 0.29142360000000002E+003],]
input.P=[[ 0.98692326671601283E+000],]
input.MW=[[ 0.98000000000000000E+002],]
input.Vm=[[ 0.42880001068115234E+002],]
# Output data is stored here.
output = Object()
output.gas_diffusivity=[[ 0.11449280832155644E+000],]
4 changes: 4 additions & 0 deletions src/verification/mosaic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_executable(${DRIVER_NAME}.x
do_full_deliquescence.cpp
calculate_XT.cpp
fnlog_gamZ.cpp
gas_diffusivity.cpp
fn_Keq.cpp
fn_Po.cpp
molality_0.cpp
Expand All @@ -28,6 +29,7 @@ SET(TEST_LIST
do_full_deliquescence_input_ts_0
calculate_XT_input_ts_0
fnlog_gamZ_input_ts_0
gas_diffusivity_input_ts_0
fn_Keq_input_ts_0
fn_Po_input_ts_0
molality_0_input_ts_0
Expand All @@ -42,6 +44,7 @@ SET(TEST_BASELINE
do_full_deliquescence_output_ts_0
calculate_XT_output_ts_0
fnlog_gamZ_output_ts_0
gas_diffusivity_output_ts_0
fn_Keq_output_ts_0
fn_Po_output_ts_0
molality_0_output_ts_0
Expand All @@ -57,6 +60,7 @@ set(ERROR_THRESHOLDS
${DEFAULT_TOL} # do_full_deliquescence_output_ts_0
${DEFAULT_TOL} # calculate_XT_output_ts_0
1e-6 # fnlog_gamZ_output_ts_0
1e-7 # gas_diffusivity_output_ts_0
1e-6 # fn_Keq_output_ts_0
1e-8 # fn_Po_output_ts_0
1e-5 # molality_0_output_ts_0
Expand Down
66 changes: 66 additions & 0 deletions src/verification/mosaic/gas_diffusivity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "TChem.hpp"
#include "TChem_Impl_MOSAIC.hpp"
#include <verification.hpp>
#include "skywalker.hpp"

using device_type = typename Tines::UseThisDevice<TChem::exec_space>::type;
using real_type_1d_view = TChem::real_type_1d_view;
using oridinal_type_1d_view = TChem::ordinal_type_1d_view;
using ordinal_type = TChem::ordinal_type;
using namespace skywalker;
using namespace TChem;

void gas_diffusivity(Ensemble *ensemble) {
ensemble->process([=](const Input &input, Output &output) {

const auto T_K_arr = input.get_array("T_K");
const auto P_arr = input.get_array("P");
const auto MW_arr = input.get_array("MW");
const auto Vm_arr = input.get_array("Vm");

real_type_1d_view T_K("T_K", 1);
verification::convert_1d_vector_to_1d_view_device(T_K_arr, T_K);

real_type_1d_view P("P", 1);
verification::convert_1d_vector_to_1d_view_device(P_arr, P);

real_type_1d_view MW("MW", 1);
verification::convert_1d_vector_to_1d_view_device(MW_arr, MW);

real_type_1d_view Vm("Vm", 1);
verification::convert_1d_vector_to_1d_view_device(Vm_arr, Vm);

// Reals or int that are defined outside of the parallel_for region are passed as const.
real_type_1d_view outputs_gas_diffusivity("outputs_gas_diffusivity", 1);

std::string profile_name ="Verification_test_gas_diffusivity";
using policy_type =
typename TChem::UseThisTeamPolicy<TChem::exec_space>::type;
const auto exec_space_instance = TChem::exec_space();
const auto host_exec_space = TChem::host_exec_space();
policy_type policy(exec_space_instance, 1, Kokkos::AUTO());

Kokkos::parallel_for(
profile_name,
policy,
KOKKOS_LAMBDA(const typename policy_type::member_type& member) {

Real& gas_diffusivity = outputs_gas_diffusivity(0);

// Perform the adjustment calculation
TChem::Impl::MOSAIC<real_type, device_type>::gas_diffusivity(
T_K(0),
P(0),
MW(0),
Vm(0),
gas_diffusivity);
});

const auto outputs_gas_diffusivity_h = Kokkos::create_mirror_view_and_copy(host_exec_space, outputs_gas_diffusivity);

Real gas_diffusivity = outputs_gas_diffusivity_h(0);

output.set("gas_diffusivity", gas_diffusivity);

});
}
4 changes: 4 additions & 0 deletions src/verification/mosaic/mosaic_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ void calculate_XT(Ensemble *ensemble);

void fnlog_gamZ(Ensemble *ensemble);

void gas_diffusivity(Ensemble *ensemble);

void fn_Keq(Ensemble *ensemble);

void fn_Po(Ensemble *ensemble);
Expand Down Expand Up @@ -70,6 +72,8 @@ int main(int argc, char **argv) {
calculate_XT(ensemble);
} else if (func_name == "fnlog_gamZ") {
fnlog_gamZ(ensemble);
} else if (func_name == "gas_diffusivity") {
gas_diffusivity(ensemble);
} else if (func_name == "fn_Keq") {
fn_Keq(ensemble);
} else if (func_name == "fn_Po") {
Expand Down