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