www.mooseframework.org
CommonOutputAction.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // MOOSE includes
16 #include "CommonOutputAction.h"
17 #include "MooseApp.h"
18 #include "FEProblem.h"
19 #include "MooseObjectAction.h"
20 #include "ActionFactory.h"
21 #include "Output.h"
22 #include "OutputWarehouse.h"
23 
24 // Extrnal includes
25 #include "tinydir.h"
26 #include "pcrecpp.h"
27 #include <libgen.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <unistd.h>
31 
32 template <>
35 {
37 
38  // Short-cut methods for typical output objects
39  params.addParam<bool>(
40  "exodus", false, "Output the results using the default settings for Exodus output");
41  params.addParam<bool>(
42  "nemesis", false, "Output the results using the default settings for Nemesis output");
43  params.addParam<bool>(
44  "console", true, "Output the results using the default settings for Console output");
45  params.addParam<bool>("csv",
46  false,
47  "Output the scalar variable and postprocessors to a *.csv "
48  "file using the default CSV output.");
49  params.addParam<bool>(
50  "vtk", false, "Output the results using the default settings for VTKOutput output");
51  params.addParam<bool>(
52  "xda", false, "Output the results using the default settings for XDA/XDR output (ascii)");
53  params.addParam<bool>(
54  "xdr", false, "Output the results using the default settings for XDA/XDR output (binary)");
55  params.addParam<bool>("checkpoint", false, "Create checkpoint files using the default options.");
56  params.addParam<bool>(
57  "gmv", false, "Output the results using the default settings for GMV output");
58  params.addParam<bool>(
59  "tecplot", false, "Output the results using the default settings for Tecplot output");
60  params.addParam<bool>(
61  "gnuplot",
62  false,
63  "Output the scalar and postprocessor results using the default settings for GNUPlot output");
64  params.addParam<bool>(
65  "solution_history", false, "Print a solution history file (.slh) using the default settings");
66  params.addParam<bool>("dofmap", false, "Create the dof map .json output file");
67  params.addParam<bool>("controls", false, "Enable the screen output of Control systems.");
68 
69  // Common parameters
70 
71  // Note: Be sure that objects that share these parameters utilize the same defaults
72  params.addParam<bool>("color", true, "Set to false to turn off all coloring in all outputs");
73  params.addParam<std::string>("file_base",
74  "Common file base name to be utilized with all output objects");
75  params.addParam<std::vector<std::string>>("output_if_base_contains",
76  "If this is supplied then output will only be done in "
77  "the case that the output base contains one of these "
78  "strings. This is helpful in outputting only a subset "
79  "of outputs when using MultiApps.");
80  params.addParam<unsigned int>(
81  "interval", 1, "The interval at which timesteps are output to the solution file");
82  params.addParam<std::vector<Real>>("sync_times",
83  std::vector<Real>(),
84  "Times at which the output and solution is forced to occur");
85  params.addParam<bool>(
86  "append_date", false, "When true the date and time are appended to the output filename.");
87  params.addParam<std::string>("append_date_format",
88  "The format of the date/time to append (see "
89  "http://www.cplusplus.com/reference/ctime/"
90  "strftime).");
91 
92  params.addParam<std::vector<VariableName>>(
93  "hide",
94  "A list of the variables and postprocessors that should NOT be output to the Exodus "
95  "file (may include Variables, ScalarVariables, and Postprocessor names).");
96  params.addParam<std::vector<VariableName>>(
97  "show",
98  "A list of the variables and postprocessors that should be output to the Exodus file "
99  "(may include Variables, ScalarVariables, and Postprocessor names).");
100 
101  // Add the 'execute_on' input parameter
102  params.addParam<MultiMooseEnum>(
103  "execute_on",
104  Output::getExecuteOptions("initial timestep_end"),
105  "Set to (initial|linear|nonlinear|timestep_end|timestep_begin|final|failed|custom) to "
106  "execute only at that moment (default: 'initial timestep_end')");
107 
108  // Add special Console flags
109  params.addParam<bool>(
110  "print_perf_log", false, "Enable printing of the performance log to the screen (Console)");
111  params.addParam<bool>("print_mesh_changed_info",
112  false,
113  "When true, each time the mesh is changed the mesh information is printed");
114  params.addParam<bool>("print_linear_residuals",
115  true,
116  "Enable printing of linear residuals to the screen (Console)");
117 
118  // Return object
119  return params;
120 }
121 
123  : Action(params), _action_params(_action_factory.getValidParams("AddOutputAction"))
124 {
125 }
126 
127 void
129 {
130  // Store the common output parameters in the OutputWarehouse
132 
133 // Create the actions for the short-cut methods
134 #ifdef LIBMESH_HAVE_EXODUS_API
135  if (getParam<bool>("exodus"))
136  create("Exodus");
137 #else
138  if (getParam<bool>("exodus"))
139  mooseWarning("Exodus output requested but not enabled through libMesh");
140 #endif
141 
142 #ifdef LIBMESH_HAVE_NEMESIS_API
143  if (getParam<bool>("nemesis"))
144  create("Nemesis");
145 #else
146  if (getParam<bool>("nemesis"))
147  mooseWarning("Nemesis output requested but not enabled through libMesh");
148 #endif
149 
150  // Only create a Console if screen output was not created
151  if (getParam<bool>("console") && !hasConsole())
152  create("Console");
153  else
154  _pars.set<bool>("console") = false;
155 
156  if (getParam<bool>("csv"))
157  create("CSV");
158 
159 #ifdef LIBMESH_HAVE_VTK
160  if (getParam<bool>("vtk"))
161  create("VTK");
162 #else
163  if (getParam<bool>("vtk"))
164  mooseWarning("VTK output requested but not enabled through libMesh");
165 #endif
166 
167  if (getParam<bool>("xda"))
168  create("XDA");
169 
170  if (getParam<bool>("xdr"))
171  create("XDR");
172 
173  if (getParam<bool>("checkpoint"))
174  create("Checkpoint");
175 
176  if (getParam<bool>("gmv"))
177  create("GMV");
178 
179  if (getParam<bool>("tecplot"))
180  create("Tecplot");
181 
182  if (getParam<bool>("gnuplot"))
183  create("Gnuplot");
184 
185  if (getParam<bool>("solution_history"))
186  create("SolutionHistory");
187 
188  if (getParam<bool>("dofmap"))
189  create("DOFMap");
190 
191  if (getParam<bool>("controls") || _app.getParam<bool>("show_controls"))
192  create("ControlOutput");
193 
194  if (!getParam<bool>("color"))
195  Moose::setColorConsole(false);
196 }
197 
198 void
199 CommonOutputAction::create(std::string object_type)
200 {
201  // Set the 'type =' parameters for the desired object
202  _action_params.set<std::string>("type") = object_type;
203 
204  // Create the complete object name (uses lower case of type)
205  std::transform(object_type.begin(), object_type.end(), object_type.begin(), ::tolower);
206 
207  // Create the action
208  std::shared_ptr<MooseObjectAction> action = std::static_pointer_cast<MooseObjectAction>(
209  _action_factory.create("AddOutputAction", object_type, _action_params));
210 
211  // Set flag indicating that the object to be created was created with short-cut syntax
212  action->getObjectParams().set<bool>("_built_by_moose") = true;
213 
214  // Add the action to the warehouse
215  _awh.addActionBlock(action);
216 }
217 
218 bool
220 {
221 
222  // Loop through all of the actions for adding output objects
223  for (ActionIterator it = _awh.actionBlocksWithActionBegin("add_output");
224  it != _awh.actionBlocksWithActionEnd("add_output");
225  it++)
226  {
227  MooseObjectAction * moa = static_cast<MooseObjectAction *>(*it);
228  const std::string & type = moa->getMooseObjectType();
229  InputParameters & params = moa->getObjectParams();
230  if (type.compare("Console") == 0 && params.get<bool>("output_screen"))
231  return true;
232  }
233 
234  return false;
235 }
InputParameters _action_params
Parameters from the action being created (AddOutputAction)
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:122
ActionFactory & _action_factory
Builds Actions.
Definition: Action.h:104
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
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.
Base class for actions.
Definition: Action.h:39
const std::string & getMooseObjectType() const
Return the object type to be created.
const std::string & type() const
Definition: Action.h:61
InputParameters & getObjectParams()
Retreive the parameters of the object to be created by this action.
InputParameters _pars
Input parameters for the action.
Definition: Action.h:86
virtual void act() override
InputParameters validParams< CommonOutputAction >()
const T & getParam(const std::string &name)
Retrieve a parameter for the object.
Definition: MooseApp.h:738
bool setColorConsole(bool use_color, bool force=false)
Turns color escape sequences on/off for info written to stdout.
Definition: Moose.C:1276
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters parameters)
Definition: ActionFactory.C:26
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...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
static MultiMooseEnum getExecuteOptions()
Returns the available options for the &#39;execute_on&#39; input parameters.
MooseApp & _app
The MOOSE application this is associated with.
Definition: Action.h:98
ActionIterator actionBlocksWithActionBegin(const std::string &task)
Iterators to the Actions in the warehouse.
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition: MooseApp.C:841
InputParameters validParams< Action >()
Definition: Action.C:23
void mooseWarning(Args &&...args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:194