https://mooseframework.inl.gov
Loading...
Searching...
No Matches
AddIterationCountPostprocessorsAction.C
Go to the documentation of this file.
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
11#include "MooseObjectAction.h"
12#include "ActionFactory.h"
13#include "ActionWarehouse.h"
14
15registerMooseAction("ThermalHydraulicsApp", AddIterationCountPostprocessorsAction, "meta_action");
16
19{
21 params.addParam<bool>(
22 "count_iterations", false, "Add postprocessors for linear and nonlinear iterations");
23 params.addClassDescription("Adds postprocessors for linear and nonlinear iterations");
24 return params;
25}
26
28 const InputParameters & parameters)
29 : Action(parameters), _add_pps(getParam<bool>("count_iterations"))
30{
31}
32
33void
35{
36 if (_add_pps)
37 {
38 const std::vector<std::string> it_per_step_class_names = {"NumLinearIterations",
39 "NumNonlinearIterations"};
40 const std::vector<std::string> it_per_step_names = {"num_linear_iterations_per_step",
41 "num_nonlinear_iterations_per_step"};
42 const std::vector<std::string> total_it_names = {"num_linear_iterations",
43 "num_nonlinear_iterations"};
44
45 for (unsigned int i = 0; i < it_per_step_class_names.size(); i++)
46 {
47 // iterations per time step
48 {
49 const std::string class_name = "AddPostprocessorAction";
50 InputParameters action_params = _action_factory.getValidParams(class_name);
51 associateWithParameter("count_iterations", action_params);
52 action_params.set<std::string>("type") = it_per_step_class_names[i];
53 auto action = std::static_pointer_cast<MooseObjectAction>(
54 _action_factory.create(class_name, it_per_step_names[i], action_params));
55 _awh.addActionBlock(action);
56 }
57 // cumulative iterations
58 {
59 const std::string class_name = "AddPostprocessorAction";
60 InputParameters action_params = _action_factory.getValidParams(class_name);
61 associateWithParameter("count_iterations", action_params);
62 action_params.set<std::string>("type") = "CumulativeValuePostprocessor";
63 auto action = std::static_pointer_cast<MooseObjectAction>(
64 _action_factory.create(class_name, total_it_names[i], action_params));
65 action->getObjectParams().set<PostprocessorName>("postprocessor") = it_per_step_names[i];
66 _awh.addActionBlock(action);
67 }
68 }
69 }
70}
registerMooseAction("ThermalHydraulicsApp", AddIterationCountPostprocessorsAction, "meta_action")
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters &parameters)
InputParameters getValidParams(const std::string &name)
void addActionBlock(std::shared_ptr< Action > blk)
void associateWithParameter(const std::string &param_name, InputParameters &params) const
static InputParameters validParams()
ActionWarehouse & _awh
Action that adds postprocessors for linear and nonlinear iterations.
bool _add_pps
True if iteration count postprocessors should be added.
AddIterationCountPostprocessorsAction(const InputParameters &parameters)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
ActionFactory & _action_factory