Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chemistry solver update #532

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.18.4)
include(config/petscCompilers.cmake)

# Set the project details
project(ablateLibrary VERSION 0.12.34)
project(ablateLibrary VERSION 0.12.35)

# Load the Required 3rd Party Libaries
pkg_check_modules(PETSc REQUIRED IMPORTED_TARGET GLOBAL PETSc)
Expand Down
55 changes: 32 additions & 23 deletions src/eos/zerork/sourceCalculatorZeroRK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,33 +246,42 @@ void ablate::eos::zerorkeos::SourceCalculator::ComputeSource(const ablate::domai
flag = zerork_reactor_solve(1, time, dt, nReactorsEval, &reactorTEval[0], &reactorPEval[0], &reactorMassFracEval[0], zrm_handle);

if (flag != ZERORK_STATUS_SUCCESS) {
std::cout << "Integration failed 0 source terms are used for rank "
std::cout << "Integration failed on some of the ranks, even after reducing tolerances in ZeroRK."
<< "\n";
if (chemistryConstraints.errorhandle == 0) {
std::cout << "The simulation continues with 0 chemical source for the failing cells."
<< "\n";
} else if (chemistryConstraints.errorhandle == 1) {
if (chemistryConstraints.errorhandle == 1) {
int ii = 0;
// For now try to manually decrease the tolerances and recalculate every rank!
// Zerork in the future will have the ability to reintegrate only the failed ranks
// Zerork already reduced the tolerances
while (flag != ZERORK_STATUS_SUCCESS) {
++ii;
std::cout << "Manually tightening tolerances further."
<< "\n";
zerork_reactor_set_double_option(
"abs_tol", chemistryConstraints.absTolerance * pow(chemistryConstraints.cvode_retry_absolute_tolerance_adjustment, ii * chemistryConstraints.cvode_num_retries), zrm_handle);
flag = zerork_reactor_solve(2, time, dt, nReactorsEval, &reactorTEval[0], &reactorPEval[0], &reactorMassFracEval[0], zrm_handle);
// Try tightening the tolerances
if (ii == 2) {
std::cout << "At this point the tolerances are probably too tight."
<< "\n"
<< "Consider dumping the state, by setting dumpfailed = 1 in the input file and try to understand why is it failing."
<< "\n";
break;
}
}
// Integration error usually only occur for certain specific states, which will hopefully be advected away for the next step...
// Resetting the tolerances to the original inputs
zerork_reactor_set_double_option("abs_tol", chemistryConstraints.absTolerance, zrm_handle);
zerork_reactor_set_double_option("rel_tol", chemistryConstraints.relTolerance, zrm_handle);
}
if (chemistryConstraints.errorhandle == 2) {
try {
while (flag != ZERORK_STATUS_SUCCESS) {
++ii;
std::cout << "Tightening tolerances."
// For errorhandle 2 stop the simualtion
if (flag != ZERORK_STATUS_SUCCESS) {
std::cout << "Warning: Could not integrate chemistry after reducing the tolerances multiple times."
<< "\n";
std::cout << "Option 2 was selected for error handling, the simulations exits now. "
<< "\n";
zerork_reactor_set_double_option("abs_tol", chemistryConstraints.absTolerance * pow(0.01, ii), zrm_handle);
flag = zerork_reactor_solve(2, time, dt, nReactorsEval, &reactorTEval[0], &reactorPEval[0], &reactorMassFracEval[0], zrm_handle);
// If tigethening the
if (ii == 5) {
break;
}
if (flag != ZERORK_STATUS_SUCCESS) {
std::cout << "Warning: Could not integrate chemistry after reducing the tolerances multiple times."
<< "\n";
std::cout << "Consider reducing the timestep or using steplimiter option "
<< "\n";
throw std::runtime_error("ablate::eos::zerorkEOS::Computesource zerork couldn't integrate the simulation.");
}
throw std::runtime_error("ablate::eos::zerorkEOS::Computesource zerork couldn't integrate the simulation.");
}
} catch (const runtime_error& e) {
exit(1);
Expand Down Expand Up @@ -393,4 +402,4 @@ std::istream& ablate::eos::zerorkeos::operator>>(std::istream& is, ablate::eos::
" Default is Contstant volume");
}
return is;
}
}
8 changes: 4 additions & 4 deletions src/eos/zerork/sourceCalculatorZeroRK.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class SourceCalculator : public ChemistryModel::SourceCalculator, private utilit

//! hold a struct that can be used for chemistry constraints
struct ChemistryConstraints {
double relTolerance = 1.0E-6;
double absTolerance = 1.0E-10;
double relTolerance = 1.0E-8;
double absTolerance = 1.0E-12;

// set the limiter on chemical rates of progress,
// for 1D flames set it to a value btw 1e18 and 1e20,
Expand All @@ -39,7 +39,7 @@ class SourceCalculator : public ChemistryModel::SourceCalculator, private utilit
int verbose = 0;

// load balancing
int loadBalance = 1;
int loadBalance = 2; // default to time based load balancing

// load balancing
int gpu = 0;
Expand Down Expand Up @@ -136,4 +136,4 @@ std::istream& operator>>(std::istream& is, SourceCalculator::ReactorType& v);

} // namespace ablate::eos::zerorkeos

#endif // ABLATELIBRARY_BATCHSOURCE_HPP
#endif // ABLATELIBRARY_BATCHSOURCE_HPP
Loading