Skip to content

Commit

Permalink
mo_setsox testing finished--ready for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
mjs271 committed Oct 18, 2023
1 parent 123c01b commit fd88923
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 676 deletions.
16 changes: 10 additions & 6 deletions src/validation/mo_setsox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ include_directories(${PROJECT_BINARY_DIR}/validation)
add_executable(mo_setsox_driver
mo_setsox_driver.cpp
setsox_test.cpp
vtest_test.cpp
calc_ph_values.cpp
calc_sox_aqueous.cpp
calc_ynetpos.cpp
)

target_link_libraries(mo_setsox_driver skywalker;validation;${HAERO_LIBRARIES})
Expand All @@ -28,17 +30,19 @@ endforeach()

# Run the driver in several configurations to produce datasets.
set(TEST_LIST
vtest_test
setsox_ts_355_xlwc_small
setsox_ts_355_merged
calc_ph_values_ts_355
calc_sox_aqueous_ts_355_merged
calc_ynetpos_ts_355
)

set(DEFAULT_TOL 1e-11)

set(ERROR_THRESHOLDS
${DEFAULT_TOL} # vtest_test
${DEFAULT_TOL} # setsox_test
# 4e-8
# ${DEFAULT_TOL_DROPMIXNUC}
${DEFAULT_TOL} # calc_ph_values
${DEFAULT_TOL} # calc_sox_aqueous
${DEFAULT_TOL} # calc_ynetpos
)

foreach(input tol IN ZIP_LISTS TEST_LIST ERROR_THRESHOLDS)
Expand Down
63 changes: 63 additions & 0 deletions src/validation/mo_setsox/calc_ph_values.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// mam4xx: Copyright (c) 2022,
// Battelle Memorial Institute and
// National Technology & Engineering Solutions of Sandia, LLC (NTESS)
// SPDX-License-Identifier: BSD-3-Clause

#include <mam4xx/mam4.hpp>

#include <mam4xx/aero_config.hpp>
#include <skywalker.hpp>
#include <validation.hpp>

using namespace skywalker;
using namespace mam4;
using namespace haero;
void calc_ph_values(Ensemble *ensemble) {
ensemble->process([=](const Input &input, Output &output) {
// Ensemble parameters
// Declare array of strings for input names
std::string input_variables[] = {"dt"};

std::string input_arrays[] = {"temperature", "patm", "xlwc", "t_factor",
"xso2", "xso4", "xhnm", "so4_fact",
"Ra", "xkw", "const0"};

// Iterate over input_variables and error if not in input
for (std::string name : input_variables) {
if (!input.has(name.c_str())) {
std::cerr << "Required name for variable: " << name << std::endl;
exit(1);
}
}
// Iterate over input_arrays and error if not in input
for (std::string name : input_arrays) {
if (!input.has_array(name.c_str())) {
std::cerr << "Required name for array: " << name << std::endl;
exit(1);
}
}

// Parse input
const Real temperature = input.get_array("temperature")[0];
const Real patm = input.get_array("patm")[0];
const Real xlwc = input.get_array("xlwc")[0];
const Real t_factor = input.get_array("t_factor")[0];
const Real xso2 = input.get_array("xso2")[0];
const Real xso4 = input.get_array("xso4")[0];
const Real xhnm = input.get_array("xhnm")[0];
const Real so4_fact = input.get_array("so4_fact")[0];
const Real Ra = input.get_array("Ra")[0];
const Real xkw = input.get_array("xkw")[0];
const Real const0 = input.get_array("const0")[0];

bool converged;
Real xph;

mam4::mo_setsox::calc_ph_values(temperature, patm, xlwc, t_factor, xso2,
xso4, xhnm, so4_fact, Ra, xkw, const0,
converged, xph);

output.set("converged", converged);
output.set("xph", xph);
});
}
75 changes: 75 additions & 0 deletions src/validation/mo_setsox/calc_sox_aqueous.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// mam4xx: Copyright (c) 2022,
// Battelle Memorial Institute and
// National Technology & Engineering Solutions of Sandia, LLC (NTESS)
// SPDX-License-Identifier: BSD-3-Clause

#include <mam4xx/mam4.hpp>

#include <mam4xx/aero_config.hpp>
#include <skywalker.hpp>
#include <validation.hpp>

using namespace skywalker;
using namespace mam4;
using namespace haero;
void calc_sox_aqueous(Ensemble *ensemble) {
ensemble->process([=](const Input &input, Output &output) {
// Ensemble parameters
// Declare array of strings for input names
std::string input_variables[] = {"dt"};

std::string input_arrays[] = {
"const0", "dtime", "h2o2g", "heo3", "heso2", "modal_aerosols",
"o3g", "patm", "rah2o2", "rao3", "so2g", "t_factor",
"xh2o2", "xhnm", "xlwc", "xso2", "xso4", "xso4_init"};

// Iterate over input_variables and error if not in input
for (std::string name : input_variables) {
if (!input.has(name.c_str())) {
std::cerr << "Required name for variable: " << name << std::endl;
exit(1);
}
}
// Iterate over input_arrays and error if not in input
for (std::string name : input_arrays) {
if (!input.has_array(name.c_str())) {
std::cerr << "Required name for array: " << name << std::endl;
exit(1);
}
}

// Parse input
const Real const0 = input.get_array("const0")[0];
const Real dt = input.get_array("dtime")[0];
const Real h2o2g = input.get_array("h2o2g")[0];
const Real heo3 = input.get_array("heo3")[0];
const Real heso2 = input.get_array("heso2")[0];
const bool modal_aerosols = input.get_array("modal_aerosols")[0];
const Real o3g = input.get_array("o3g")[0];
const Real patm = input.get_array("patm")[0];
const Real rah2o2 = input.get_array("rah2o2")[0];
const Real rao3 = input.get_array("rao3")[0];
const Real so2g = input.get_array("so2g")[0];
const Real t_factor = input.get_array("t_factor")[0];
const Real xhnm = input.get_array("xhnm")[0];
const Real xlwc = input.get_array("xlwc")[0];

Real xso2 = input.get_array("xso2")[0];
Real xso4 = input.get_array("xso4")[0];
Real xso4_init = input.get_array("xso4_init")[0];
Real xh2o2 = input.get_array("xh2o2")[0];

Real xdelso4hp;

mam4::mo_setsox::calc_sox_aqueous(modal_aerosols, rah2o2, h2o2g, so2g, o3g,
rao3, patm, dt, t_factor, xlwc, const0,
xhnm, heo3, heso2, xso2, xso4, xso4_init,
xh2o2, xdelso4hp);

output.set("xso2", xso2);
output.set("xso4", xso4);
output.set("xso4_init", xso4_init);
output.set("xh2o2", xh2o2);
output.set("xdelso4hp_ik", xdelso4hp);
});
}
61 changes: 61 additions & 0 deletions src/validation/mo_setsox/calc_ynetpos.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// mam4xx: Copyright (c) 2022,
// Battelle Memorial Institute and
// National Technology & Engineering Solutions of Sandia, LLC (NTESS)
// SPDX-License-Identifier: BSD-3-Clause

#include <mam4xx/mam4.hpp>

#include <mam4xx/aero_config.hpp>
#include <skywalker.hpp>
#include <validation.hpp>

using namespace skywalker;
using namespace mam4;
using namespace haero;
void calc_ynetpos(Ensemble *ensemble) {
ensemble->process([=](const Input &input, Output &output) {
// Ensemble parameters
// Declare array of strings for input names
std::string input_variables[] = {"dt"};

std::string input_arrays[] = {"yph", "fact1_so2", "fact2_so2",
"fact3_so2", "fact4_so2", "Eco2",
"Eh2o", "Eso4", "so4_fact"};

// Iterate over input_variables and error if not in input
for (std::string name : input_variables) {
if (!input.has(name.c_str())) {
std::cerr << "Required name for variable: " << name << std::endl;
exit(1);
}
}
// Iterate over input_arrays and error if not in input
for (std::string name : input_arrays) {
if (!input.has_array(name.c_str())) {
std::cerr << "Required name for array: " << name << std::endl;
exit(1);
}
}

// Parse input
const Real yph = input.get_array("yph")[0];
const Real fact1_so2 = input.get_array("fact1_so2")[0];
const Real fact2_so2 = input.get_array("fact2_so2")[0];
const Real fact3_so2 = input.get_array("fact3_so2")[0];
const Real fact4_so2 = input.get_array("fact4_so2")[0];
const Real Eco2 = input.get_array("Eco2")[0];
const Real Eh2o = input.get_array("Eh2o")[0];
const Real Eso4 = input.get_array("Eso4")[0];
const Real so4_fact = input.get_array("so4_fact")[0];

Real xph;
Real ynetpos;

mam4::mo_setsox::calc_ynetpos(yph, fact1_so2, fact2_so2, fact3_so2,
fact4_so2, Eco2, Eh2o, Eso4, so4_fact, xph,
ynetpos);

output.set("xph", xph);
output.set("ynetpos", ynetpos);
});
}
14 changes: 10 additions & 4 deletions src/validation/mo_setsox/mo_setsox_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ using namespace skywalker;
using namespace mam4;

// Parameterizations used by the mo_setsox() process.
void vtest_test(Ensemble *ensemble);
void setsox_test(Ensemble *ensemble);
void calc_ph_values(Ensemble *ensemble);
void calc_sox_aqueous(Ensemble *ensemble);
void calc_ynetpos(Ensemble *ensemble);

int main(int argc, char **argv) {
if (argc == 1) {
Expand All @@ -47,10 +49,14 @@ int main(int argc, char **argv) {
// Dispatch to the requested function.
auto func_name = settings.get("function");
try {
if (func_name == "vtest_test") {
vtest_test(ensemble);
} else if (func_name == "setsox_test") {
if (func_name == "setsox_test") {
setsox_test(ensemble);
} else if (func_name == "calc_ph_values") {
calc_ph_values(ensemble);
} else if (func_name == "calc_sox_aqueous") {
calc_sox_aqueous(ensemble);
} else if (func_name == "calc_ynetpos") {
calc_ynetpos(ensemble);
} else {
std::cerr << "Error: Function name '" << func_name
<< "' does not have an implemented test!" << std::endl;
Expand Down
Loading

0 comments on commit fd88923

Please sign in to comment.