Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 3 : 4 : // This library is free software; you can redistribute it and/or 5 : // modify it under the terms of the GNU Lesser General Public 6 : // License as published by the Free Software Foundation; either 7 : // version 2.1 of the License, or (at your option) any later version. 8 : 9 : // This library is distributed in the hope that it will be useful, 10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 : // Lesser General Public License for more details. 13 : 14 : // You should have received a copy of the GNU Lesser General Public 15 : // License along with this library; if not, write to the Free Software 16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 : 18 : 19 : 20 : #ifndef LIBMESH_SOLVER_CONFIGURATION_H 21 : #define LIBMESH_SOLVER_CONFIGURATION_H 22 : 23 : // Local includes 24 : #include "libmesh/libmesh_common.h" 25 : #include "libmesh/reference_counted_object.h" 26 : 27 : namespace libMesh 28 : { 29 : 30 : /** 31 : * This class stores solver configuration data, e.g. tolerances 32 : * and iteration limits. Override the pure virtual function 33 : * configure_solver() in order to provide specific behavior for 34 : * particular types of solvers (e.g. LinearSolver, EigenSolver, etc). 35 : * 36 : * \author David Knezevic 37 : * \date 2015 38 : */ 39 : class SolverConfiguration : public ReferenceCountedObject<SolverConfiguration> 40 : { 41 : public: 42 : 43 : /** 44 : * Constructor. 45 : */ 46 : SolverConfiguration () = default; 47 : 48 : /** 49 : * Destructor. 50 : */ 51 : virtual ~SolverConfiguration () = default; 52 : 53 : /** 54 : * Apply options during initialization of a solver. 55 : * Default is a no-op. Override in subclasses to provide 56 : * specific behavior. 57 : */ 58 68 : virtual void set_options_during_init() {} 59 : 60 : /** 61 : * Apply solver options to a particular solver. 62 : * Override in subclasses to provide specific behavior. 63 : */ 64 : virtual void configure_solver() = 0; 65 : 66 : /** 67 : * This method can be called after the solver has failed (e.g. on 68 : * catching an exception thrown by a solver). It allows an appropriate 69 : * response to the failure, e.g. terminate the program, or change 70 : * configuration options and try again. 71 : * \p solve_failure_count specifies the number of times we've tried to 72 : * recover from a failure. 73 : */ 74 : virtual void respond_to_solve_failure(unsigned int /*solve_failure_count*/) 75 : { 76 : libmesh_error_msg("Solver error"); // by default just throw an error 77 : } 78 : 79 : /** 80 : * Store real-valued solver parameters in this map, e.g. solver tolerances. 81 : */ 82 : std::map<std::string, Real> real_valued_data; 83 : 84 : /** 85 : * Store integer solver parameters in this map, e.g. iteration limits. 86 : */ 87 : std::map<std::string, int> int_valued_data; 88 : 89 : /** 90 : * Store string data in this map, e.g. "solver_type" : "gmres". 91 : */ 92 : std::map<std::string, std::string> string_data; 93 : 94 : }; 95 : 96 : } // namespace libMesh 97 : 98 : #endif // LIBMESH_SOLVER_CONFIGURATION_H