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 "AddIterationCountPostprocessorsAction.h" 11 : #include "MooseObjectAction.h" 12 : #include "ActionFactory.h" 13 : #include "ActionWarehouse.h" 14 : 15 : registerMooseAction("ThermalHydraulicsApp", AddIterationCountPostprocessorsAction, "meta_action"); 16 : 17 : InputParameters 18 148 : AddIterationCountPostprocessorsAction::validParams() 19 : { 20 148 : InputParameters params = Action::validParams(); 21 296 : params.addParam<bool>( 22 296 : "count_iterations", false, "Add postprocessors for linear and nonlinear iterations"); 23 148 : params.addClassDescription("Adds postprocessors for linear and nonlinear iterations"); 24 148 : return params; 25 0 : } 26 : 27 148 : AddIterationCountPostprocessorsAction::AddIterationCountPostprocessorsAction( 28 148 : const InputParameters & parameters) 29 296 : : Action(parameters), _add_pps(getParam<bool>("count_iterations")) 30 : { 31 148 : } 32 : 33 : void 34 148 : AddIterationCountPostprocessorsAction::act() 35 : { 36 148 : if (_add_pps) 37 : { 38 : const std::vector<std::string> it_per_step_class_names = {"NumLinearIterations", 39 54 : "NumNonlinearIterations"}; 40 : const std::vector<std::string> it_per_step_names = {"num_linear_iterations_per_step", 41 54 : "num_nonlinear_iterations_per_step"}; 42 : const std::vector<std::string> total_it_names = {"num_linear_iterations", 43 54 : "num_nonlinear_iterations"}; 44 : 45 54 : for (unsigned int i = 0; i < it_per_step_class_names.size(); i++) 46 : { 47 : // iterations per time step 48 : { 49 36 : const std::string class_name = "AddPostprocessorAction"; 50 36 : InputParameters action_params = _action_factory.getValidParams(class_name); 51 72 : associateWithParameter("count_iterations", action_params); 52 36 : action_params.set<std::string>("type") = it_per_step_class_names[i]; 53 : auto action = std::static_pointer_cast<MooseObjectAction>( 54 36 : _action_factory.create(class_name, it_per_step_names[i], action_params)); 55 108 : _awh.addActionBlock(action); 56 36 : } 57 : // cumulative iterations 58 : { 59 36 : const std::string class_name = "AddPostprocessorAction"; 60 36 : InputParameters action_params = _action_factory.getValidParams(class_name); 61 36 : associateWithParameter("count_iterations", action_params); 62 36 : action_params.set<std::string>("type") = "CumulativeValuePostprocessor"; 63 : auto action = std::static_pointer_cast<MooseObjectAction>( 64 72 : _action_factory.create(class_name, total_it_names[i], action_params)); 65 72 : action->getObjectParams().set<PostprocessorName>("postprocessor") = it_per_step_names[i]; 66 108 : _awh.addActionBlock(action); 67 36 : } 68 : } 69 18 : } 70 220 : }