Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : #include "Convergence.h" 13 : #include "Executioner.h" 14 : 15 : /** 16 : * Base class for default convergence criteria. 17 : */ 18 : class DefaultConvergenceBase : public Convergence 19 : { 20 : public: 21 : static InputParameters validParams(); 22 : 23 : DefaultConvergenceBase(const InputParameters & parameters); 24 : 25 : virtual void initialSetup() override; 26 : 27 : protected: 28 : /** 29 : * This method is to be used for parameters that are shared with the executioner. 30 : * 31 : * If the parameter is set by the user in the executioner, get that value; 32 : * otherwise, get this object's value. 33 : * If the parameter is set by the user in both this object and the executioner, 34 : * add it to a list and report an error later. 35 : */ 36 : template <typename T> 37 : const T & getSharedExecutionerParam(const std::string & name); 38 : 39 : /** 40 : * Throws an error if any of the parameters shared with the executioner have 41 : * been set by the user in both places. 42 : * 43 : * This should be called after all calls to \c getSharedExecutionerParam. 44 : * No error is thrown if the Convergence object was added as a default, since 45 : * in that case, any parameters set by the user in the executioner will also 46 : * be considered set by the user in the Convergence. 47 : */ 48 : void checkDuplicateSetSharedExecutionerParams() const; 49 : 50 : private: 51 : /// True if this object was added as a default instead of by the user 52 : const bool _added_as_default; 53 : 54 : /// List of shared executioner parameters that have been set by the user in both places 55 : std::vector<std::string> _duplicate_shared_executioner_params; 56 : }; 57 : 58 : template <typename T> 59 : const T & 60 1257815 : DefaultConvergenceBase::getSharedExecutionerParam(const std::string & param) 61 : { 62 1257815 : const auto * executioner = getMooseApp().getExecutioner(); 63 1257815 : if (executioner->isParamSetByUser(param)) 64 : { 65 17564 : if (isParamSetByUser(param)) 66 17479 : _duplicate_shared_executioner_params.push_back(param); 67 17564 : return executioner->getParam<T>(param); 68 : } 69 : else 70 1240251 : return getParam<T>(param); 71 : }