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 163332 : virtual void initialSetup() override {} 46 : 47 : /// Perform checks related to the iteration type 48 89648 : virtual void checkIterationType(IterationType /*it_type*/) const {} 49 : 50 : /** 51 : * Method that gets called before each iteration loop 52 : */ 53 12225 : virtual void initialize() {} 54 : 55 : /** 56 : * Method that gets called in each iteration before the solve 57 : */ 58 61000 : virtual void preExecute() {} 59 : 60 : /** 61 : * Returns convergence status. 62 : * 63 : * @param[in] iter Iteration index (first index in loop should be 0) 64 : */ 65 : virtual MooseConvergenceStatus checkConvergence(unsigned int iter) = 0; 66 : 67 : /// Returns whether verbose mode has been enabled 68 310277 : bool verbose() const { return _verbose; } 69 : 70 : protected: 71 : /** 72 : * Outputs the stream to the console if verbose output is enabled 73 : */ 74 : void verboseOutput(std::ostringstream & oss); 75 : 76 : /// Performance ID for \c checkConvergence 77 : PerfID _perfid_check_convergence; 78 : 79 : /// Thread ID 80 : THREAD_ID _tid; 81 : 82 : private: 83 : /// Verbose mode enabled 84 : const bool _verbose; 85 : };