Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
CommonOutputAction.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 
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 registerMooseAction("MooseApp", CommonOutputAction, "add_output");
29 
32 {
34  params.addClassDescription("Adds short-cut syntax and common parameters to the Outputs block.");
35 
36  // Short-cut methods for typical output objects
37  params.addParam<bool>(
38  "exodus", false, "Output the results using the default settings for Exodus output.");
39  params.addParam<bool>(
40  "nemesis", false, "Output the results using the default settings for Nemesis output");
41  params.addParam<bool>(
42  "console", true, "Output the results using the default settings for Console output");
43  params.addParam<bool>("csv",
44  false,
45  "Output the scalar variable and postprocessors to a *.csv "
46  "file using the default CSV output.");
47  params.addParam<bool>("xml",
48  false,
49  "Output the vector postprocessors to a *.xml "
50  "file using the default XML output.");
51  params.addParam<bool>("json",
52  false,
53  "Output Reporter values to a *.json "
54  "file using the default JSON output.");
55  params.addParam<bool>(
56  "vtk", false, "Output the results using the default settings for VTKOutput output");
57  params.addParam<bool>(
58  "xda", false, "Output the results using the default settings for XDA/XDR output (ascii)");
59  params.addParam<bool>(
60  "xdr", false, "Output the results using the default settings for XDA/XDR output (binary)");
61  params.addParam<bool>(
62  "gmv", false, "Output the results using the default settings for GMV output");
63  params.addParam<bool>(
64  "tecplot", false, "Output the results using the default settings for Tecplot output");
65  params.addParam<bool>(
66  "gnuplot",
67  false,
68  "Output the scalar and postprocessor results using the default settings for GNUPlot output");
69  params.addParam<bool>(
70  "solution_history", false, "Print a solution history file (.slh) using the default settings");
71  params.addParam<bool>("progress", false, "Print a progress bar");
72  params.addParam<bool>("dofmap", false, "Create the dof map .json output file");
73  params.addParam<bool>("controls", false, "Enable the screen output of Control systems.");
74 
75  // Common parameters
76 
77  // Note: Be sure that objects that share these parameters utilize the same defaults
78  params.addParam<bool>("color", true, "Set to false to turn off all coloring in all outputs");
79  params.addParam<std::string>("file_base",
80  "Common file base name to be utilized with all output objects");
81  params.addParam<std::vector<std::string>>("output_if_base_contains",
82  "If this is supplied then output will only be done in "
83  "the case that the output base contains one of these "
84  "strings. This is helpful in outputting only a subset "
85  "of outputs when using MultiApps.");
86  params.addParam<unsigned int>(
87  "time_step_interval", 1, "The interval (number of time steps) at which output occurs");
88  params.addParam<unsigned int>("interval",
89  "The interval (number of time steps) at which output occurs");
90  params.deprecateParam("interval", "time_step_interval", "02/01/2025");
91  params.addParam<std::vector<Real>>("sync_times",
92  std::vector<Real>(),
93  "Times at which the output and solution is forced to occur");
94  params.addParam<Real>(
95  "minimum_time_interval", 0.0, "The minimum simulation time between output steps");
96  params.addParam<bool>(
97  "append_date", false, "When true the date and time are appended to the output filename.");
98  params.addParam<std::string>("append_date_format",
99  "The format of the date/time to append (see "
100  "http://www.cplusplus.com/reference/ctime/"
101  "strftime).");
102 
103  params.addParam<std::vector<VariableName>>(
104  "hide",
105  {},
106  "A list of the variables and postprocessors that should NOT be output to the Exodus "
107  "file (may include Variables, ScalarVariables, and Postprocessor names).");
108  params.addParam<std::vector<VariableName>>(
109  "show",
110  {},
111  "A list of the variables and postprocessors that should be output to the Exodus file "
112  "(may include Variables, ScalarVariables, and Postprocessor names).");
113 
114  // Add the 'execute_on' input parameter
116  exec_enum = {EXEC_INITIAL, EXEC_TIMESTEP_END};
117  params.addParam<ExecFlagEnum>("execute_on", exec_enum, exec_enum.getDocString());
118 
119  // Add special Console flags
120  params.addDeprecatedParam<bool>(
121  "print_perf_log", false, "Use perf_graph instead!", "Use perf_graph instead!");
122 
123  params.addParam<bool>(
124  "perf_graph", false, "Enable printing of the performance graph to the screen (Console)");
125 
126  params.addParam<bool>("perf_graph_live", true, "Enables printing of live progress messages");
127  params.addParam<Real>(
128  "perf_graph_live_time_limit", 5.0, "Time (in seconds) to wait before printing a message.");
129  params.addParam<unsigned int>(
130  "perf_graph_live_mem_limit", 100, "Memory (in MB) to cause a message to be printed.");
131 
132  params.addParam<bool>("print_mesh_changed_info",
133  false,
134  "When true, each time the mesh is changed the mesh information is printed");
135  params.addParam<bool>("print_linear_residuals",
136  true,
137  "Enable printing of linear residuals to the screen (Console)");
138  params.addParam<bool>("print_nonlinear_residuals",
139  true,
140  "Enable printing of nonlinear residuals to the screen (Console)");
141  params.addParam<bool>("print_nonlinear_converged_reason",
142  true,
143  "Enable/disable printing of the nonlinear solver convergence reason to the "
144  "screen. This parameter only affects the output of the third-party solver "
145  "(e.g. PETSc), not MOOSE itself.");
146  params.addParam<bool>("print_linear_converged_reason",
147  true,
148  "Enable/disable printing of the linear solver convergence reason to the "
149  "screen. This parameter only affects the output of the third-party solver "
150  "(e.g. PETSc), not MOOSE itself.");
151 
152  params.addParam<bool>(
153  "solution_invalidity_history",
154  true,
155  "Enable printing of the time history of the solution invalidity occurrences "
156  "to the screen (console)");
157 
158  // Return object
159  return params;
160 }
161 
163  : Action(params), _action_params(_action_factory.getValidParams("AddOutputAction"))
164 {
165 }
166 
167 void
169 {
170  if (_current_task == "common_output")
171  {
172  // Store the common output parameters in the OutputWarehouse
174 
175 // Create the actions for the short-cut methods
176 #ifdef LIBMESH_HAVE_EXODUS_API
177  if (getParam<bool>("exodus"))
178  create("Exodus", "exodus");
179 #else
180  if (getParam<bool>("exodus"))
181  mooseWarning("Exodus output requested but not enabled through libMesh");
182 #endif
183 
184 #ifdef LIBMESH_HAVE_NEMESIS_API
185  if (getParam<bool>("nemesis"))
186  create("Nemesis", "nemesis");
187 #else
188  if (getParam<bool>("nemesis"))
189  mooseWarning("Nemesis output requested but not enabled through libMesh");
190 #endif
191 
192  // Only create a Console if screen output was not created
193  if (getParam<bool>("console") && !hasConsole())
194  create("Console", "console");
195 
196  if (getParam<bool>("csv"))
197  create("CSV", "csv");
198 
199  if (getParam<bool>("xml"))
200  create("XMLOutput", "xml");
201 
202  if (getParam<bool>("json"))
203  create("JSON", "json");
204 
205 #ifdef LIBMESH_HAVE_VTK
206  if (getParam<bool>("vtk"))
207  create("VTK", "vtk");
208 #else
209  if (getParam<bool>("vtk"))
210  mooseWarning("VTK output requested but not enabled through libMesh");
211 #endif
212 
213  if (getParam<bool>("xda"))
214  create("XDA", "xda");
215 
216  if (getParam<bool>("xdr"))
217  create("XDR", "xdr");
218 
219  if (getParam<bool>("gmv"))
220  create("GMV", "gmv");
221 
222  if (getParam<bool>("tecplot"))
223  create("Tecplot", "tecplot");
224 
225  if (getParam<bool>("gnuplot"))
226  create("Gnuplot", "gnuplot");
227 
228  if (getParam<bool>("solution_history"))
229  create("SolutionHistory", "solution_history");
230 
231  if (getParam<bool>("progress"))
232  create("Progress", "progress");
233 
234  if (getParam<bool>("dofmap"))
235  create("DOFMap", "dofmap");
236 
237  {
238  std::optional<std::string> from_param_name;
239  const InputParameters * from_params = nullptr;
240  if (getParam<bool>("controls"))
241  {
242  from_param_name = "controls";
243  from_params = &parameters();
244  }
245  else if (_app.getParam<bool>("show_controls"))
246  {
247  from_param_name = "show_controls";
248  from_params = &_app.parameters();
249  }
250  if (from_param_name)
251  create("ControlOutput", *from_param_name, from_params);
252  }
253 
254  if (!_app.getParam<bool>("no_timing"))
255  {
256  std::optional<std::string> from_param_name;
257  const InputParameters * from_params = nullptr;
258  if (getParam<bool>("perf_graph"))
259  {
260  from_param_name = "perf_graph";
261  from_params = &parameters();
262  }
263  else if (getParam<bool>("print_perf_log"))
264  {
265  from_param_name = "print_perf_log";
266  from_params = &parameters();
267  }
268  else if (_app.getParam<bool>("timing"))
269  {
270  from_param_name = "timing";
271  from_params = &_app.parameters();
272  }
273  if (from_param_name)
274  create("PerfGraphOutput", *from_param_name, from_params);
275 
276  if (!getParam<bool>("perf_graph_live"))
277  {
278  if (!from_param_name)
279  perfGraph().setActive(false);
281  }
282  }
283  else
284  {
285  perfGraph().setActive(false);
287  }
288 
289  perfGraph().setLiveTimeLimit(getParam<Real>("perf_graph_live_time_limit"));
290  perfGraph().setLiveMemoryLimit(getParam<unsigned int>("perf_graph_live_mem_limit"));
291 
292  if (getParam<bool>("solution_invalidity_history"))
293  {
294  create("SolutionInvalidityOutput", "solution_invalidity_history");
295  }
296 
297  if (!getParam<bool>("color"))
298  Moose::setColorConsole(false);
299  }
300  else if (_current_task == "add_output")
301  {
302  // More like remove output. This can't be done during the "common_output" task because the
303  // finite element problem is not yet constructed
304 
305  if (!getParam<bool>("console") || (isParamValid("print_nonlinear_converged_reason") &&
306  !getParam<bool>("print_nonlinear_converged_reason")))
308 
309  if (!getParam<bool>("console") || (isParamValid("print_linear_converged_reason") &&
310  !getParam<bool>("print_linear_converged_reason")))
312  }
313  else
314  mooseError("unrecognized task ", _current_task, " in CommonOutputAction.");
315 }
316 
317 void
318 CommonOutputAction::create(std::string object_type,
319  const std::optional<std::string> & param_name,
320  const InputParameters * const from_params /* = nullptr */)
321 {
322  // Create our copy of the parameters
323  auto params = _action_params;
324 
325  // Associate all action output object errors with param_name
326  // If from_params is specified, it means to associate it with parameters other than parameters()
327  if (param_name)
328  {
329  const InputParameters & associated_params = from_params ? *from_params : parameters();
330  associateWithParameter(associated_params, *param_name, params);
331  }
332 
333  // Set the 'type =' parameters for the desired object
334  params.set<std::string>("type") = object_type;
335 
336  // Create the complete object name (uses lower case of type)
337  std::transform(object_type.begin(), object_type.end(), object_type.begin(), ::tolower);
338 
339  // Create the action
340  std::shared_ptr<MooseObjectAction> action = std::static_pointer_cast<MooseObjectAction>(
341  _action_factory.create("AddOutputAction", object_type, params));
342 
343  // Set flag indicating that the object to be created was created with short-cut syntax
344  action->getObjectParams().set<bool>("_built_by_moose") = true;
345 
346  // Add the action to the warehouse
347  _awh.addActionBlock(action);
348 }
349 
350 bool
352 {
353 
354  // Loop through all of the actions for adding output objects
355  for (ActionIterator it = _awh.actionBlocksWithActionBegin("add_output");
356  it != _awh.actionBlocksWithActionEnd("add_output");
357  it++)
358  {
359  MooseObjectAction * moa = dynamic_cast<MooseObjectAction *>(*it);
360  if (!moa)
361  continue;
362 
363  const std::string & type = moa->getMooseObjectType();
364  InputParameters & params = moa->getObjectParams();
365  if (type.compare("Console") == 0 && params.get<bool>("output_screen"))
366  return true;
367  }
368 
369  return false;
370 }
InputParameters _action_params
Parameters from the action being created (AddOutputAction)
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
void create(std::string object_type, const std::optional< std::string > &param_name, const InputParameters *const from_params=nullptr)
Helper method for creating the short-cut actions.
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:159
bool hasConsole()
Check if a Console object that outputs to the screen has been defined.
InputParameters & parameters()
Get the parameters of the object.
Definition: MooseApp.h:147
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
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:112
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
CommonOutputAction(const InputParameters &params)
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:33
Base class for actions.
Definition: Action.h:33
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters &parameters)
Definition: ActionFactory.C:39
static InputParameters validParams()
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
static InputParameters validParams()
Definition: Action.C:24
InputParameters & getObjectParams()
Retrieve the parameters of the object to be created by this action.
void deprecateParam(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
void setActive(bool active)
Turn on or off timing.
Definition: PerfGraph.h:129
void setLiveMemoryLimit(unsigned int mem_limit)
Sert the memory limit before a message prints.
Definition: PerfGraph.h:157
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
void disableLivePrint()
Completely disables Live Print (cannot be restarted)
Definition: PerfGraph.C:67
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:51
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition: Action.h:162
std::string getDocString() const
Generate a documentation string for the "execute_on" parameter.
Definition: ExecFlagEnum.C:40
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
ActionFactory & _action_factory
Builds Actions.
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:1523
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void dontAddNonlinearConvergedReason(FEProblemBase &fe_problem)
Function to ensure that -snes_converged_reason is not added to the PetscOptions storage object to be ...
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:696
PerfGraph & perfGraph()
Get the PerfGraph.
void associateWithParameter(const std::string &param_name, InputParameters &params) const
Associates the object&#39;s parameters params with the input location from this Action&#39;s parameter with t...
Definition: Action.C:158
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void setCommonParameters(const InputParameters *params_ptr)
Stores the common InputParameters object.
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:168
const InputParameters & parameters() const
Get the parameters of the object.
ActionIterator actionBlocksWithActionEnd(const std::string &task)
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
void dontAddLinearConvergedReason(FEProblemBase &fe_problem)
Function to ensure that -ksp_converged_reason is not added to the PetscOptions storage object to be l...
void setLiveTimeLimit(Real time_limit)
Set the time limit before a message prints.
Definition: PerfGraph.h:149
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:1848
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:28