diff --git a/MathLib/LinAlg/LinearSolverOptions.cpp b/MathLib/LinAlg/LinearSolverOptions.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6c42a036dfad1d211b7daca4c7fb655e8f793847 --- /dev/null +++ b/MathLib/LinAlg/LinearSolverOptions.cpp @@ -0,0 +1,25 @@ +#include "LinearSolverOptions.h" + +#include <set> + +//! Configuration tag names of all known linear solvers for their +//! configuration in the project file. +//! Add your tag name here when you add a new solver. +static +std::set<std::string> +known_linear_solvers { "eigen", "lis", "petsc" }; + +namespace MathLib +{ + + +void +ignoreOtherLinearSolvers(const BaseLib::ConfigTreeNew &config, + const std::string &solver_name) +{ + for (auto const& s : known_linear_solvers) { + if (s!=solver_name) config.ignoreConfParam(s); + } +} + +} diff --git a/MathLib/LinAlg/LinearSolverOptions.h b/MathLib/LinAlg/LinearSolverOptions.h new file mode 100644 index 0000000000000000000000000000000000000000..8a36efd814e7c5fc81d1990256eb4740615ded4e --- /dev/null +++ b/MathLib/LinAlg/LinearSolverOptions.h @@ -0,0 +1,29 @@ +#pragma once + +#include "BaseLib/ConfigTreeNew.h" + +namespace MathLib +{ + +/*! Ignore linear solver settings not needed for the selected one. + * + * The project files support specifying linear solver options for all + * known solver libraries (currently PETSC, LIS, Eigen) even though for + * a specific build only one of those settings is used. + * That clearly conflicts with the requirement of the config tree that + * each setting present in the project file must be read exactly once. + * + * The purpose of this function is to explicitly ignore all the settings + * that are not relevant for the currently used linear solver + * + * \param config The config tree snippet for the linear solver. + * \param solver_name The tag under which the relevant configuration is found. + * All other configurations will be ignored. + * + * This function is currently used in the option parsing code of our + * \c EigenLinearSolver, \c LisOption and \c PETScLinearSolver + */ +void ignoreOtherLinearSolvers(BaseLib::ConfigTreeNew const& config, + std::string const& solver_name); + +}