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 : #include "NumNonlinearIterations.h" 11 : 12 : #include "FEProblem.h" 13 : #include "SubProblem.h" 14 : #include "SystemBase.h" 15 : 16 : registerMooseObject("MooseApp", NumNonlinearIterations); 17 : 18 : InputParameters 19 15563 : NumNonlinearIterations::validParams() 20 : { 21 15563 : InputParameters params = GeneralPostprocessor::validParams(); 22 46689 : params.addParam<bool>( 23 : "accumulate_over_step", 24 31126 : false, 25 : "When set to true, accumulates to count the total over all Picard iterations for each step"); 26 31126 : params.addClassDescription("Outputs the number of nonlinear iterations"); 27 : 28 : // Not supported 29 15563 : params.suppressParameter<bool>("use_displaced_mesh"); 30 15563 : return params; 31 0 : } 32 : 33 405 : NumNonlinearIterations::NumNonlinearIterations(const InputParameters & parameters) 34 : : GeneralPostprocessor(parameters), 35 405 : _fe_problem(dynamic_cast<FEProblemBase *>(&_subproblem)), 36 810 : _accumulate_over_step(getParam<bool>("accumulate_over_step")), 37 405 : _num_iters(0), 38 810 : _time(-std::numeric_limits<Real>::max()) 39 : { 40 405 : if (!_fe_problem) 41 0 : mooseError("Couldn't cast to FEProblemBase"); 42 405 : } 43 : 44 : void 45 1199 : NumNonlinearIterations::timestepSetup() 46 : { 47 1199 : if (_fe_problem->time() != _time) 48 : { 49 1191 : _num_iters = 0; 50 1191 : _time = _fe_problem->time(); 51 : } 52 1199 : } 53 : 54 : void 55 1159 : NumNonlinearIterations::finalize() 56 : { 57 1159 : if (_accumulate_over_step) 58 0 : _num_iters += _subproblem.nNonlinearIterations(_sys.number()); 59 : else 60 1159 : _num_iters = _subproblem.nNonlinearIterations(_sys.number()); 61 1159 : } 62 : 63 : Real 64 1159 : NumNonlinearIterations::getValue() const 65 : { 66 1159 : return _num_iters; 67 : }