www.mooseframework.org
Output.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 // Standard includes
16 #include <math.h>
17 
18 // MOOSE includes
19 #include "Output.h"
20 #include "FEProblem.h"
21 #include "DisplacedProblem.h"
22 #include "MooseApp.h"
23 #include "Postprocessor.h"
24 #include "Restartable.h"
25 #include "FileMesh.h"
26 #include "MooseUtils.h"
27 #include "MooseApp.h"
28 #include "Console.h"
29 
30 #include "libmesh/equation_systems.h"
31 
32 template <>
35 {
36  // Get the parameters from the parent object
38 
39  // Displaced Mesh options
40  params.addParam<bool>(
41  "use_displaced", false, "Enable/disable the use of the displaced mesh for outputting");
42 
43  // Output intervals and timing
44  params.addParam<unsigned int>(
45  "interval", 1, "The interval at which time steps are output to the solution file");
46  params.addParam<std::vector<Real>>("sync_times",
47  "Times at which the output and solution is forced to occur");
48  params.addParam<bool>("sync_only", false, "Only export results at sync times");
49  params.addParam<Real>("start_time", "Time at which this output object begins to operate");
50  params.addParam<Real>("end_time", "Time at which this output object stop operating");
51  params.addParam<Real>(
52  "time_tolerance", 1e-14, "Time tolerance utilized checking start and end times");
53 
54  // Add the 'execute_on' input parameter for users to set
55  params.addParam<MultiMooseEnum>("execute_on",
56  Output::getExecuteOptions("initial timestep_end"),
57  "Set to "
58  "(none|initial|linear|nonlinear|timestep_end|timestep_begin|"
59  "final|failed|custom) to execute only at that moment");
60 
61  // Add ability to append to the 'execute_on' list
62  params.addParam<MultiMooseEnum>("additional_execute_on",
64  "This list of output flags is added to the existing flags "
65  "(initial|linear|nonlinear|timestep_end|timestep_begin|final|"
66  "failed|custom) to execute only at that moment");
67 
68  // 'Timing' group
69  params.addParamNamesToGroup("time_tolerance interval sync_times sync_only start_time end_time ",
70  "Timing");
71 
72  // Add a private parameter for indicating if it was created with short-cut syntax
73  params.addPrivateParam<bool>("_built_by_moose", false);
74 
75  // Register this class as base class
76  params.declareControllable("enable");
77  params.registerBase("Output");
78 
79  return params;
80 }
81 
83 Output::getExecuteOptions(std::string default_type)
84 {
85  // Build the string of options
86  std::string options = "none=0x00 initial=0x01 linear=0x02 nonlinear=0x04 timestep_end=0x08 "
87  "timestep_begin=0x10 final=0x20 failed=0x80";
88 
89  // The numbers associated must be in sync with the ExecFlagType in Moose.h
90  return MultiMooseEnum(options, default_type);
91 }
92 
94  : MooseObject(parameters),
95  Restartable(parameters, "Output"),
96  MeshChangedInterface(parameters),
97  SetupInterface(this),
98  _problem_ptr(getParam<FEProblemBase *>("_fe_problem_base")),
99  _transient(_problem_ptr->isTransient()),
100  _use_displaced(getParam<bool>("use_displaced")),
101  _es_ptr(_use_displaced ? &_problem_ptr->getDisplacedProblem()->es() : &_problem_ptr->es()),
102  _execute_on(getParam<MultiMooseEnum>("execute_on")),
103  _time(_problem_ptr->time()),
106  _dt(_problem_ptr->dt()),
108  _num(0),
109  _interval(getParam<unsigned int>("interval")),
110  _sync_times(std::set<Real>(getParam<std::vector<Real>>("sync_times").begin(),
111  getParam<std::vector<Real>>("sync_times").end())),
112  _start_time(isParamValid("start_time") ? getParam<Real>("start_time")
113  : -std::numeric_limits<Real>::max()),
114  _end_time(isParamValid("end_time") ? getParam<Real>("end_time")
115  : std::numeric_limits<Real>::max()),
116  _t_tol(getParam<Real>("time_tolerance")),
117  _sync_only(getParam<bool>("sync_only")),
118  _initialized(false),
119  _allow_output(true),
120  _is_advanced(false),
121  _advanced_execute_on(_execute_on, parameters)
122 {
123  // Apply the additional output flags
124  if (isParamValid("additional_execute_on"))
125  {
126  MultiMooseEnum add = getParam<MultiMooseEnum>("additional_execute_on");
127  for (auto & me : add)
129  }
130 }
131 
132 void
134 {
135  _initialized = true;
136 }
137 
138 void
140 {
141 }
142 
143 void
145 {
146  // Output is not allowed
147  if (!_allow_output && type != EXEC_FORCED)
148  return;
149 
150  // If recovering disable output of initial condition, it was already output
151  if (type == EXEC_INITIAL && _app.isRecovering())
152  return;
153 
154  // Return if the current output is not on the desired interval
155  if (type != EXEC_FINAL && !onInterval())
156  return;
157 
158  // Call the output method
159  if (shouldOutput(type))
160  output(type);
161 }
162 
163 bool
165 {
166  // Note that in older versions of MOOSE, this was overloaded (unintentionally) to always return
167  // true for the Console output subclass - basically ignoring execute_on options specified for
168  // the console (e.g. via the input file).
169  if (_execute_on.contains(type) || type == EXEC_FORCED)
170  return true;
171  return false;
172 }
173 
174 bool
176 {
177  // The output flag to return
178  bool output = false;
179 
180  // Return true if the current step on the current output interval and within the output time range
181  if (_time >= _start_time && _time <= _end_time && (_t_step % _interval) == 0)
182  output = true;
183 
184  // Return false if 'sync_only' is set to true
185  if (_sync_only)
186  output = false;
187 
188  // If sync times are not skipped, return true if the current time is a sync_time
189  if (_sync_times.find(_time) != _sync_times.end())
190  output = true;
191 
192  // Return the output status
193  return output;
194 }
195 
196 Real
198 {
199  if (_transient)
200  return _time;
201  else
202  return _t_step;
203 }
204 
205 Real
207 {
208  if (_transient)
209  return _time_old;
210  else
211  return _t_step - 1;
212 }
213 
214 Real
216 {
217  if (_transient)
218  return _dt;
219  else
220  return 1;
221 }
222 
223 Real
225 {
226  if (_transient)
227  return _dt_old;
228  else
229  return 1;
230 }
231 
232 int
234 {
235  return _t_step;
236 }
237 
238 const MultiMooseEnum &
240 {
241  return _execute_on;
242 }
243 
244 bool
246 {
247  return _is_advanced;
248 }
249 
250 const OutputOnWarehouse &
252 {
253  mooseError("The output object ", name(), " is not an AdvancedOutput, use isAdvanced() to check.");
254  return _advanced_execute_on;
255 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
Real & _time_old
The old time.
Definition: Output.h:192
virtual Real dtOld()
Get old time step size.
Definition: Output.C:224
A class for creating restricted objects.
Definition: Restartable.h:31
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition: MooseApp.C:607
OutputOnWarehouse _advanced_execute_on
Storage for the individual component execute flags.
Definition: Output.h:237
MultiMooseEnum _execute_on
The common Execution types; this is used as the default execution type for everything except system i...
Definition: Output.h:186
virtual bool onInterval()
Returns true if the output interval is satisfied.
Definition: Output.C:175
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
Object is evaluated only once at the beginning of the simulation.
Definition: MooseTypes.h:94
virtual void initialSetup()
Initialization method.
Definition: Output.C:133
virtual Real dt()
Get the current time step size.
Definition: Output.C:215
Real & _dt_old
Old time step delta.
Definition: Output.h:201
virtual void output(const ExecFlagType &type)=0
Overload this function with the desired output activities.
virtual bool shouldOutput(const ExecFlagType &type)
Handles logic for determining if a step should be output.
Definition: Output.C:164
Real _start_time
Start outputting time.
Definition: Output.h:213
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
unsigned int _num
The number of outputs written.
Definition: Output.h:204
int & _t_step
The current time step.
Definition: Output.h:195
bool _transient
Transient flag (true = transient)
Definition: Output.h:174
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
bool contains(const std::string &value) const
Contains methods for seeing if a value is in the MultiMooseEnum.
virtual void solveSetup()
A method called just prior to the solve, this is used by PetscOutput to perform the necessary setup a...
Definition: Output.C:139
Output(const InputParameters &parameters)
Class constructor.
Definition: Output.C:93
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
Forces execution to occur (output only)
Definition: MooseTypes.h:106
bool _initialized
True if init() has been called.
Definition: Output.h:225
const unsigned int _interval
The output time step interval.
Definition: Output.h:207
virtual Real timeOld()
Get the old output time.
Definition: Output.C:206
Interface for notifications that the mesh has changed.
EquationSystems * _es_ptr
Reference the the libMesh::EquationSystems object that contains the data.
Definition: Output.h:180
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:36
virtual const OutputOnWarehouse & advancedExecuteOn() const
Returns the advanced &#39;execute_on&#39; settings.
Definition: Output.C:251
virtual void outputStep(const ExecFlagType &type)
A single call to this function should output all the necessary data for a single timestep.
Definition: Output.C:144
InputParameters validParams< Output >()
Definition: Output.C:34
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
Definition: Output.h:171
bool _allow_output
Flag for disabling output.
Definition: Output.h:228
A helper warehouse class for storing the "execute_on" settings for the various output types...
void declareControllable(const std::string &name)
Declare the given parameters as controllable.
bool _sync_only
Flag for only executing at sync times.
Definition: Output.h:222
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:67
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:122
InputParameters validParams< MooseObject >()
Definition: MooseObject.C:22
bool _use_displaced
Flag for using displaced mesh.
Definition: Output.h:177
virtual Real time()
Get the output time.
Definition: Output.C:197
bool _is_advanced
Flag for advanced output testing.
Definition: Output.h:231
std::set< Real > _sync_times
Sync times for this outputter.
Definition: Output.h:210
bool isAdvanced()
Returns true if this object is an AdvancedOutput object.
Definition: Output.C:245
MatType type
Real _t_tol
Time checking tolerance.
Definition: Output.h:219
void push_back(const std::string &names)
Insert operators Operator to insert (push_back) values into the enum.
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:108
const MultiMooseEnum & executeOn() const
Get the current &#39;execute_on&#39; selections for display.
Definition: Output.C:239
Real _end_time
End outputting time.
Definition: Output.h:216
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:53
Object is evaluated at the end of the simulations (output only)
Definition: MooseTypes.h:104
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
ExecFlagType
Execution flags - when is the object executed/evaluated.
Definition: MooseTypes.h:90
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.
virtual int timeStep()
Get the current time step.
Definition: Output.C:233
Real & _time
The current time for output purposes.
Definition: Output.h:189
Real & _dt
Time step delta.
Definition: Output.h:198
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...