BOUT-dev
BOUT-dev copied to clipboard
Better testing of time `Solver`s
We have a nice integrated test for the time Solvers, but the current setup only allows one set of options for each solver. This means it's not possible to check different options. The nice thing about it however, is we don't need to explicitly list all the solvers individually, so it neatly handles adding new solvers or different build configurations when some might be missing.
Current version looks like:
// Solver-specific options
root["euler"]["mxstep"] = 100000;
root["euler"]["nout"] = NOUT;
root["euler"]["timestep"] = end / (NOUT * 1000);
// more options...
for (auto& name : SolverFactory::getInstance().listAvailable()) {
output_test << "Testing " << name << " solver:";
try {
// Get specific options section for this solver. Can't just use default
// "solver" section, as we run into problems when solvers use the same
// name for an option with inconsistent defaults
auto options = Options::getRoot()->getSection(name);
auto solver = std::unique_ptr<Solver>{Solver::create(name, options)};
Modified form:
// Get specific options section for each solver. Can't just use default
// "solver" section, as we run into problems when solvers use the same
// name for an option with inconsistent defaults
auto* solvers_section = root["solvers"];
for (auto& name : SolverFactory::getInstance().listAvailable()) {
// Make a default section for each available solver
auto* section = solvers_section->getSection(name);
section["type"] = name;
}
// Solver-specific options
solvers_section["euler"]["mxstep"] = 100000;
solvers_section["euler"]["nout"] = NOUT;
solvers_section["euler"]["timestep"] = end / (NOUT * 1000);
// Add new section for a non-default solver
if (/* check if specific solver is available somehow? */) {
solvers_section["solver"]["option"] = true;
}
for (auto& [name, options] : solvers_section->subsections()) {
output_test << "Testing " << name << " solver:";
try {
auto solver = std::unique_ptr<Solver>{Solver::create(options["type"], options)};
I don't remember if we've got a nice way to check if a given solver is available that isn't just try {} catch