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 "MooseObject.h" 13 : #include "SetupInterface.h" 14 : #include "PostprocessorInterface.h" 15 : #include "PerfGraphInterface.h" 16 : #include "TransientInterface.h" 17 : 18 : /** 19 : * Base class for convergence criteria. 20 : */ 21 : class Convergence : public MooseObject, 22 : public SetupInterface, 23 : public PostprocessorInterface, 24 : public PerfGraphInterface, 25 : public TransientInterface 26 : { 27 : public: 28 : static InputParameters validParams(); 29 : 30 : /** 31 : * Status returned by calls to \c checkConvergence. 32 : */ 33 : enum class MooseConvergenceStatus 34 : { 35 : ITERATING = 0, 36 : CONVERGED = 1, 37 : DIVERGED = -1 38 : }; 39 : 40 : /// Iteration type 41 : using IterationType = MooseEnumItem; 42 : 43 : Convergence(const InputParameters & parameters); 44 : 45 163986 : virtual void initialSetup() override {} 46 : 47 : /// Perform checks related to the iteration type 48 88722 : virtual void checkIterationType(IterationType /*it_type*/) const {} 49 : 50 : /** 51 : * Method that gets called before each iteration loop 52 : */ 53 11176 : virtual void initialize() {} 54 : 55 : /** 56 : * Method that gets called in each iteration before the solve 57 : */ 58 56950 : virtual void preExecute() {} 59 : 60 : /** 61 : * Returns convergence status. 62 : * 63 : * @param[in] n_iter Number of iterations performed; For example, it should equal 1 for 64 : * the check after the first iteration. Note that some iteration types 65 : * (e.g., nonlinear) can make a check before the first iteration, in 66 : * which case this should be 0. 67 : */ 68 : virtual MooseConvergenceStatus checkConvergence(unsigned int n_iter) = 0; 69 : 70 : /// Returns whether verbose mode has been enabled 71 289428 : bool verbose() const { return _verbose; } 72 : 73 : protected: 74 : /** 75 : * Outputs the stream to the console if verbose output is enabled 76 : */ 77 : void verboseOutput(std::ostringstream & oss); 78 : 79 : /// Performance ID for \c checkConvergence 80 : PerfID _perfid_check_convergence; 81 : 82 : /// Thread ID 83 : THREAD_ID _tid; 84 : 85 : private: 86 : /// Verbose mode enabled 87 : const bool _verbose; 88 : };