Skip to content

Commit

Permalink
Added print_state to test_kpp_to_micm.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwfncar committed Oct 8, 2023
1 parent 3abf626 commit 76be908
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions test/kpp/test_kpp_to_micm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,41 @@
template<class T>
using SparseMatrixPolicy = micm::SparseMatrix<T>;

void print_header()
{
std::cout << std::setw(5) << "time"
<< "," << std::setw(10) << "O2"
<< "," << std::setw(9) << "O3"
<< "," << std::setw(9) << "O"
<< "," << std::setw(9) << "O1D"
<< "," << std::setw(9) << "NO2"
<< "," << std::setw(10) << "NO" << std::endl;
}

template<template<class> class T>
void print_state(double time, micm::State<T>& state)
{
std::ios oldState(nullptr);
oldState.copyfmt(std::cout);

std::cout << std::setw(5) << time << ", " << std::flush;

std::cout << std::scientific << std::setw(10) << std::setprecision(2)
<< state.variables_[0][state.variable_map_["O2"]]
<< "," << std::setw(10) << std::setprecision(2)
<< state.variables_[0][state.variable_map_["O3"]]
<< "," << std::setw(10) << std::setprecision(2)
<< state.variables_[0][state.variable_map_["O"]]
<< "," << std::setw(10) << std::setprecision(2)
<< state.variables_[0][state.variable_map_["O1D"]]
<< "," << std::setw(10) << std::setprecision(2)
<< state.variables_[0][state.variable_map_["NO2"]]
<< "," << std::setw(10) << std::setprecision(2)
<< state.variables_[0][state.variable_map_["NO"]] << std::endl;

std::cout.copyfmt(oldState);
}

int main(const int argc, const char *argv[])
{

Expand Down Expand Up @@ -75,21 +110,22 @@ int main(const int argc, const char *argv[])

state.SetConcentrations(solver_params.system_, intial_concentration);

double time_step = 600; // s
double time_step = 10; // s
int nstep = 20;

print_header();
print_state(0, state);

for (int i = 0; i < nstep; ++i) {

double elapsed_solve_time = 0;

std::cout << "iteration, elapsed_time: "
<< i << ", " << elapsed_solve_time << std::endl;

while (elapsed_solve_time < time_step) {
auto result = solver.Solve(time_step - elapsed_solve_time, state);
elapsed_solve_time = result.final_time_;
state.variables_[0] = result.result_.AsVector();
}
print_state(time_step * (i + 1), state);
}

return 0;
Expand Down

0 comments on commit 76be908

Please sign in to comment.