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