-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
writing instructions for direct inclusion after install
- Loading branch information
Showing
8 changed files
with
260 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This folder tests usage with cmake. These are not tests that can be run with `make test`. | ||
Both of these are tested in the dockerfiles so they are tested as part of the automated build. Please | ||
look at the dockerfiles to see how to test these. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"camp-data": [ | ||
{ | ||
"name": "reaction rates no user defined", | ||
"type": "MECHANISM", | ||
"reactions": [ | ||
{ | ||
"type": "PHOTOLYSIS", | ||
"reactants": { | ||
"A": {} | ||
}, | ||
"products": { | ||
"B": {} | ||
}, | ||
"MUSICA name": "r1" | ||
}, | ||
{ | ||
"type": "PHOTOLYSIS", | ||
"reactants": { | ||
"B": { "qty": 2} | ||
}, | ||
"products": { | ||
"B": {}, | ||
"C": {} | ||
}, | ||
"MUSICA name": "r2" | ||
}, | ||
{ | ||
"type": "PHOTOLYSIS", | ||
"reactants": { | ||
"B": {}, | ||
"C": {} | ||
}, | ||
"products": { | ||
"A": {}, | ||
"C": {} | ||
}, | ||
"MUSICA name": "r3" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"camp-data": [ | ||
{ | ||
"name": "A", | ||
"type": "CHEM_SPEC" | ||
}, | ||
{ | ||
"name": "B", | ||
"type": "CHEM_SPEC" | ||
}, | ||
{ | ||
"name": "C", | ||
"type": "CHEM_SPEC" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
cmake_minimum_required(VERSION 3.11) | ||
|
||
project( | ||
test_micm_fetch_content | ||
VERSION 0.0.0 | ||
LANGUAGES CXX | ||
) | ||
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) | ||
|
||
include(FetchContent) | ||
|
||
FetchContent_Declare(micm | ||
GIT_REPOSITORY https://github.com/NCAR/micm.git | ||
GIT_TAG 0996e5848b097e77ccbb2819f22c49844154f3e3 | ||
) | ||
|
||
FetchContent_MakeAvailable(micm) | ||
|
||
################################################################################ | ||
# Tests | ||
add_executable(test_micm test_micm.cpp) | ||
|
||
target_link_libraries(test_micm | ||
PUBLIC | ||
musica::micm | ||
) | ||
|
||
enable_testing() | ||
|
||
add_test( | ||
NAME test_micm | ||
COMMAND test_micm | ||
) | ||
|
||
add_custom_target(copy_configs ALL ${CMAKE_COMMAND} -E copy_directory | ||
${CMAKE_CURRENT_SOURCE_DIR}/configs ${CMAKE_BINARY_DIR}/configs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include <micm/configure/solver_config.hpp> | ||
#include <micm/solver/rosenbrock.hpp> | ||
|
||
using namespace micm; | ||
|
||
void print_header() | ||
{ | ||
std::cout << std::setw(5) << "time" | ||
<< "," << std::setw(10) << "A" | ||
<< "," << std::setw(10) << "B" | ||
<< "," << std::setw(10) << "C" << std::endl; | ||
} | ||
|
||
template<template<class> class T> | ||
void print_state(double time, State<T>& state) | ||
{ | ||
std::ios oldState(nullptr); | ||
oldState.copyfmt(std::cout); | ||
|
||
std::cout << std::setw(5) << time << ","; | ||
std::cout << std::scientific << std::setprecision(2) | ||
<< std::setw(10) << state.variables_[0][state.variable_map_["A"]] << "," | ||
<< std::setw(10) << state.variables_[0][state.variable_map_["B"]] << "," | ||
<< std::setw(10) << state.variables_[0][state.variable_map_["C"]] | ||
<< std::endl; | ||
|
||
std::cout.copyfmt(oldState); | ||
} | ||
|
||
int main() | ||
{ | ||
constexpr size_t n_threads = 3; | ||
|
||
SolverConfig solverConfig; | ||
|
||
std::string config_path = "./configs/robertson"; | ||
ConfigParseStatus status = solverConfig.ReadAndParse(config_path); | ||
if (status != micm::ConfigParseStatus::Success) | ||
{ | ||
throw "Parsing failed"; | ||
} | ||
|
||
micm::SolverParameters solver_params = solverConfig.GetSolverParams(); | ||
|
||
auto chemical_system = solver_params.system_; | ||
auto reactions = solver_params.processes_; | ||
|
||
RosenbrockSolver<> solver{ chemical_system, | ||
reactions, | ||
RosenbrockSolverParameters::three_stage_rosenbrock_parameters(1, false) }; | ||
State<Matrix> state = solver.GetState(); | ||
|
||
// mol m-3 | ||
state.variables_[0] = { 1, 0, 0 }; | ||
|
||
double k1 = 0.04; | ||
double k2 = 3e7; | ||
double k3 = 1e4; | ||
state.SetCustomRateParameter("PHOTO.r1", k1); | ||
state.SetCustomRateParameter("PHOTO.r2", k2); | ||
state.SetCustomRateParameter("PHOTO.r3", k3); | ||
|
||
double temperature = 272.5; // [K] | ||
double pressure = 101253.3; // [Pa] | ||
double air_density = 1e6; // [mol m-3] | ||
|
||
state.conditions_[0].temperature_ = temperature; | ||
state.conditions_[0].pressure_ = pressure; | ||
state.conditions_[0].air_density_ = air_density; | ||
|
||
double time_step = 200; // s | ||
|
||
print_header(); | ||
print_state(0, state); | ||
for (int i = 0; i < 10; ++i) | ||
{ | ||
double elapsed_solve_time = 0; | ||
|
||
while (elapsed_solve_time < time_step) | ||
{ | ||
auto result = solver.Solve(time_step - elapsed_solve_time, state); | ||
elapsed_solve_time = result.final_time_; | ||
state.variables_ = result.result_; | ||
} | ||
print_state(time_step * (i + 1), state); | ||
} | ||
} |