www.mooseframework.org
CommonOutputAction.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 // MOOSE includes
11 #include "CommonOutputAction.h"
12 #include "MooseApp.h"
13 #include "FEProblem.h"
14 #include "MooseObjectAction.h"
15 #include "ActionFactory.h"
16 #include "Output.h"
17 #include "OutputWarehouse.h"
18 
19 // Extrnal includes
20 #include "tinydir.h"
21 #include "pcrecpp.h"
22 #include <libgen.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 
27 registerMooseAction("MooseApp", CommonOutputAction, "common_output");
28 
29 template <>
32 {
34 
35  // Short-cut methods for typical output objects
36  params.addParam<bool>(
37  "exodus", false, "Output the results using the default settings for Exodus output");
38  params.addParam<bool>(
39  "nemesis", false, "Output the results using the default settings for Nemesis output");
40  params.addParam<bool>(
41  "console", true, "Output the results using the default settings for Console output");
42  params.addParam<bool>("csv",
43  false,
44  "Output the scalar variable and postprocessors to a *.csv "
45  "file using the default CSV output.");
46  params.addParam<bool>(
47  "vtk", false, "Output the results using the default settings for VTKOutput output");
48  params.addParam<bool>(
49  "xda", false, "Output the results using the default settings for XDA/XDR output (ascii)");
50  params.addParam<bool>(
51  "xdr", false, "Output the results using the default settings for XDA/XDR output (binary)");
52  params.addParam<bool>("checkpoint", false, "Create checkpoint files using the default options.");
53  params.addParam<bool>(
54  "gmv", false, "Output the results using the default settings for GMV output");
55  params.addParam<bool>(
56  "tecplot", false, "Output the results using the default settings for Tecplot output");
57  params.addParam<bool>(
58  "gnuplot",
59  false,
60  "Output the scalar and postprocessor results using the default settings for GNUPlot output");
61  params.addParam<bool>(
62  "solution_history", false, "Print a solution history file (.slh) using the default settings");
63  params.addParam<bool>("dofmap", false, "Create the dof map .json output file");
64  params.addParam<bool>("controls", false, "Enable the screen output of Control systems.");
65 
66  // Common parameters
67 
68  // Note: Be sure that objects that share these parameters utilize the same defaults
69  params.addParam<bool>("color", true, "Set to false to turn off all coloring in all outputs");
70  params.addParam<std::string>("file_base",
71  "Common file base name to be utilized with all output objects");
72  params.addParam<std::vector<std::string>>("output_if_base_contains",
73  "If this is supplied then output will only be done in "
74  "the case that the output base contains one of these "
75  "strings. This is helpful in outputting only a subset "
76  "of outputs when using MultiApps.");
77  params.addParam<unsigned int>(
78  "interval", 1, "The interval at which timesteps are output to the solution file");
79  params.addParam<std::vector<Real>>("sync_times",
80  std::vector<Real>(),
81  "Times at which the output and solution is forced to occur");
82  params.addParam<bool>(
83  "append_date", false, "When true the date and time are appended to the output filename.");
84  params.addParam<std::string>("append_date_format",
85  "The format of the date/time to append (see "
86  "http://www.cplusplus.com/reference/ctime/"
87  "strftime).");
88 
89  params.addParam<std::vector<VariableName>>(
90  "hide",
91  "A list of the variables and postprocessors that should NOT be output to the Exodus "
92  "file (may include Variables, ScalarVariables, and Postprocessor names).");
93  params.addParam<std::vector<VariableName>>(
94  "show",
95  "A list of the variables and postprocessors that should be output to the Exodus file "
96  "(may include Variables, ScalarVariables, and Postprocessor names).");
97 
98  // Add the 'execute_on' input parameter
100  exec_enum = {EXEC_INITIAL, EXEC_TIMESTEP_END};
101  params.addParam<ExecFlagEnum>("execute_on", exec_enum, exec_enum.getDocString());
102 
103  // Add special Console flags
104  params.addDeprecatedParam<bool>(
105  "print_perf_log", false, "Use perf_graph instead!", "Use perf_graph instead!");
106 
107  params.addParam<bool>(
108  "perf_graph", false, "Enable printing of the performance graph to the screen (Console)");
109 
110  params.addParam<bool>("print_mesh_changed_info",
111  false,
112  "When true, each time the mesh is changed the mesh information is printed");
113  params.addParam<bool>("print_linear_residuals",
114  true,
115  "Enable printing of linear residuals to the screen (Console)");
116 
117  // Return object
118  return params;
119 }
120 
122  : Action(params), _action_params(_action_factory.getValidParams("AddOutputAction"))
123 {
124 }
125 
126 void
128 {
129  // Store the common output parameters in the OutputWarehouse
131 
132 // Create the actions for the short-cut methods
133 #ifdef LIBMESH_HAVE_EXODUS_API
134  if (getParam<bool>("exodus"))
135  create("Exodus");
136 #else
137  if (getParam<bool>("exodus"))
138  mooseWarning("Exodus output requested but not enabled through libMesh");
139 #endif
140 
141 #ifdef LIBMESH_HAVE_NEMESIS_API
142  if (getParam<bool>("nemesis"))
143  create("Nemesis");
144 #else
145  if (getParam<bool>("nemesis"))
146  mooseWarning("Nemesis output requested but not enabled through libMesh");
147 #endif
148 
149  // Only create a Console if screen output was not created
150  if (getParam<bool>("console") && !hasConsole())
151  create("Console");
152  else
153  _pars.set<bool>("console") = false;
154 
155  if (getParam<bool>("csv"))
156  create("CSV");
157 
158 #ifdef LIBMESH_HAVE_VTK
159  if (getParam<bool>("vtk"))
160  create("VTK");
161 #else
162  if (getParam<bool>("vtk"))
163  mooseWarning("VTK output requested but not enabled through libMesh");
164 #endif
165 
166  if (getParam<bool>("xda"))
167  create("XDA");
168 
169  if (getParam<bool>("xdr"))
170  create("XDR");
171 
172  if (getParam<bool>("checkpoint"))
173  create("Checkpoint");
174 
175  if (getParam<bool>("gmv"))
176  create("GMV");
177 
178  if (getParam<bool>("tecplot"))
179  create("Tecplot");
180 
181  if (getParam<bool>("gnuplot"))
182  create("Gnuplot");
183 
184  if (getParam<bool>("solution_history"))
185  create("SolutionHistory");
186 
187  if (getParam<bool>("dofmap"))
188  create("DOFMap");
189 
190  if (getParam<bool>("controls") || _app.getParam<bool>("show_controls"))
191  create("ControlOutput");
192 
193  if (!_app.getParam<bool>("no_timing") &&
194  (getParam<bool>("perf_graph") || getParam<bool>("print_perf_log") ||
195  _app.getParam<bool>("timing")))
196  create("PerfGraphOutput");
197 
198  if (!getParam<bool>("color"))
199  Moose::setColorConsole(false);
200 }
201 
202 void
203 CommonOutputAction::create(std::string object_type)
204 {
205  // Set the 'type =' parameters for the desired object
206  _action_params.set<std::string>("type") = object_type;
207 
208  // Create the complete object name (uses lower case of type)
209  std::transform(object_type.begin(), object_type.end(), object_type.begin(), ::tolower);
210 
211  // Create the action
212  std::shared_ptr<MooseObjectAction> action = std::static_pointer_cast<MooseObjectAction>(
213  _action_factory.create("AddOutputAction", object_type, _action_params));
214 
215  // Set flag indicating that the object to be created was created with short-cut syntax
216  action->getObjectParams().set<bool>("_built_by_moose") = true;
217 
218  // Add the action to the warehouse
219  _awh.addActionBlock(action);
220 }
221 
222 bool
224 {
225 
226  // Loop through all of the actions for adding output objects
227  for (ActionIterator it = _awh.actionBlocksWithActionBegin("add_output");
228  it != _awh.actionBlocksWithActionEnd("add_output");
229  it++)
230  {
231  MooseObjectAction * moa = dynamic_cast<MooseObjectAction *>(*it);
232  if (!moa)
233  continue;
234 
235  const std::string & type = moa->getMooseObjectType();
236  InputParameters & params = moa->getObjectParams();
237  if (type.compare("Console") == 0 && params.get<bool>("output_screen"))
238  return true;
239  }
240 
241  return false;
242 }
InputParameters _action_params
Parameters from the action being created (AddOutputAction)
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:24
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
std::list< Action * >::iterator ActionIterator
alias to hide implementation details
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition: Action.h:207
ActionFactory & _action_factory
Builds Actions.
Definition: Action.h:189
void create(std::string object_type)
Helper method for creating the short-cut actions.
bool hasConsole()
Check if a Console object that outputs to the screen has been defined.
void setCommonParameters(InputParameters *params_ptr)
Stores the common InputParameters object.
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:219
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
static ExecFlagEnum getDefaultExecFlagEnum()
Return an ExecFlagEnum object with the available execution flags for Output objects.
Definition: Output.C:77
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
const ExecFlagType EXEC_TIMESTEP_END
Base class for actions.
Definition: Action.h:35
InputParameters & getObjectParams()
Retreive the parameters of the object to be created by this action.
InputParameters _pars
Input parameters for the action.
Definition: Action.h:171
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
std::string getDocString() const
Generate a documentation string for the "execute_on" parameter.
Definition: ExecFlagEnum.C:39
InputParameters validParams< CommonOutputAction >()
const std::string & getMooseObjectType() const
Return the object type to be created.
const T & getParam(const std::string &name)
Retrieve a parameter for the object.
Definition: MooseApp.h:935
registerMooseAction("MooseApp", CommonOutputAction, "common_output")
bool setColorConsole(bool use_color, bool force=false)
Turns color escape sequences on/off for info written to stdout.
Definition: Moose.C:564
const std::string & type() const
Definition: Action.h:86
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters parameters)
Definition: ActionFactory.C:41
CommonOutputAction(InputParameters params)
Class constructor.
ActionIterator actionBlocksWithActionEnd(const std::string &task)
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
MooseApp & _app
The MOOSE application this is associated with.
Definition: Action.h:183
ActionIterator actionBlocksWithActionBegin(const std::string &task)
Iterators to the Actions in the warehouse.
Meta-action for creating common output object parameters This action serves two purpose, first it adds common output object parameters.
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition: MooseApp.C:1055
InputParameters validParams< Action >()
Definition: Action.C:22
const ExecFlagType EXEC_INITIAL