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