diff --git a/share/poet/barite/barite_het.qs2 b/share/poet/barite/barite_het.qs2 index fc5305134..97232a9b3 100644 Binary files a/share/poet/barite/barite_het.qs2 and b/share/poet/barite/barite_het.qs2 differ diff --git a/share/poet/surfex/PoetEGU_surfex_500.qs2 b/share/poet/surfex/PoetEGU_surfex_500.qs2 index 302eb26a2..7c480fff8 100644 Binary files a/share/poet/surfex/PoetEGU_surfex_500.qs2 and b/share/poet/surfex/PoetEGU_surfex_500.qs2 differ diff --git a/src/poet.cpp b/src/poet.cpp index 2f39673be..2f1abd5f1 100644 --- a/src/poet.cpp +++ b/src/poet.cpp @@ -300,6 +300,35 @@ void call_master_iter_end(RInside &R, const Field &trans, const Field &chem) *global_rt_setup = R["setup"]; } +bool checkAndRollback(ChemistryModule &chem, RuntimeParameters ¶ms, uint32_t &iter) +{ + for (uint32_t i = 0; i < chem.error_stats_history.size(); i++) + { + if (iter == chem.error_stats_history[i].iteration) + { + for (uint32_t j = 0; j < params.species_epsilon.size(); j++) + { + if (params.species_epsilon[j] < chem.error_stats_history[i].mape[j] && chem.error_stats_history[i].mape[j] != 0 && chem.control_iteration_counter > 1) + { + uint32_t rollback_iter = iter - params.control_iteration; + + std::cout << chem.getField().GetProps()[j] << " with a MAPE value of " << chem.error_stats_history[i].mape[j] << " exceeds epsilon of " + << params.species_epsilon[j] << "! " << std::endl; + + Checkpoint_s checkpoint_read{.field = chem.getField()}; + read_checkpoint("checkpoint" + std::to_string(rollback_iter) + ".hdf5", checkpoint_read); + iter = checkpoint_read.iteration; + + chem.control_iteration_counter--; + + return true; + } + } + } + } + return false; +} + static Rcpp::List RunMasterLoop(RInsidePOET &R, RuntimeParameters ¶ms, DiffusionModule &diffusion, ChemistryModule &chem) @@ -441,21 +470,15 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, RuntimeParameters ¶ms, MSG("End of *coupling* iteration " + std::to_string(iter) + "/" + std::to_string(maxiter)); - /* - if (params.control_iteration_active) + if (iter % params.control_iteration == 0) { - std::string file_path = "checkpoint" + std::to_string(iter) + ".hdf5"; - write_checkpoint(file_path, - {.field = chem.getField(), .iteration = iter}); - } + writeStatsToCSV(chem.error_stats_history, chem.getField().GetProps(), "stats_overview"); - - if (iter % params.control_iteration == 0 && iter != 0) - { write_checkpoint("checkpoint" + std::to_string(iter) + ".hdf5", {.field = chem.getField(), .iteration = iter}); + checkAndRollback(chem, params, iter); + } - */ // MSG(); } // END SIMULATION LOOP @@ -503,8 +526,6 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, RuntimeParameters ¶ms, chem.MasterLoopBreak(); - writeStatsToCSV(chem.error_stats_history, chem.getField().GetProps(), "stats_overview"); - return profiling; }