www.mooseframework.org
Output.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 // Standard includes
11 #include <math.h>
12 
13 // MOOSE includes
14 #include "Output.h"
15 #include "FEProblem.h"
16 #include "DisplacedProblem.h"
17 #include "MooseApp.h"
18 #include "Postprocessor.h"
19 #include "Restartable.h"
20 #include "FileMesh.h"
21 #include "MooseUtils.h"
22 #include "MooseApp.h"
23 #include "Console.h"
24 
25 #include "libmesh/equation_systems.h"
26 
27 template <>
30 {
31  // Get the parameters from the parent object
33  params += validParams<SetupInterface>();
34 
35  // Displaced Mesh options
36  params.addParam<bool>(
37  "use_displaced", false, "Enable/disable the use of the displaced mesh for outputting");
38 
39  // Output intervals and timing
40  params.addParam<unsigned int>(
41  "interval", 1, "The interval at which time steps are output to the solution file");
42  params.addParam<std::vector<Real>>("sync_times",
43  "Times at which the output and solution is forced to occur");
44  params.addParam<bool>("sync_only", false, "Only export results at sync times");
45  params.addParam<Real>("start_time", "Time at which this output object begins to operate");
46  params.addParam<Real>("end_time", "Time at which this output object stop operating");
47  params.addParam<int>("start_step", "Time step at which this output object begins to operate");
48  params.addParam<int>("end_step", "Time step at which this output object stop operating");
49  params.addParam<Real>(
50  "time_tolerance", 1e-14, "Time tolerance utilized checking start and end times");
51 
52  // Update the 'execute_on' input parameter for output
53  ExecFlagEnum & exec_enum = params.set<ExecFlagEnum>("execute_on", true);
54  exec_enum = Output::getDefaultExecFlagEnum();
55  exec_enum = {EXEC_INITIAL, EXEC_TIMESTEP_END};
56  params.setDocString("execute_on", exec_enum.getDocString());
57 
58  // Add ability to append to the 'execute_on' list
59  params.addParam<ExecFlagEnum>("additional_execute_on", exec_enum, exec_enum.getDocString());
60  params.set<ExecFlagEnum>("additional_execute_on").clear();
61 
62  // 'Timing' group
63  params.addParamNamesToGroup("time_tolerance interval sync_times sync_only start_time end_time ",
64  "Timing");
65 
66  // Add a private parameter for indicating if it was created with short-cut syntax
67  params.addPrivateParam<bool>("_built_by_moose", false);
68 
69  // Register this class as base class
70  params.declareControllable("enable");
71  params.registerBase("Output");
72 
73  return params;
74 }
75 
78 {
80  exec_enum.addAvailableFlags(EXEC_FAILED);
81  return exec_enum;
82 }
83 
84 Output::Output(const InputParameters & parameters)
85  : MooseObject(parameters),
86  Restartable(this, "Output"),
87  MeshChangedInterface(parameters),
88  SetupInterface(this),
89  PerfGraphInterface(this),
90  _problem_ptr(getParam<FEProblemBase *>("_fe_problem_base")),
91  _transient(_problem_ptr->isTransient()),
92  _use_displaced(getParam<bool>("use_displaced")),
93  _es_ptr(nullptr),
94  _mesh_ptr(nullptr),
95  _execute_on(getParam<ExecFlagEnum>("execute_on")),
96  _time(_problem_ptr->time()),
97  _time_old(_problem_ptr->timeOld()),
98  _t_step(_problem_ptr->timeStep()),
99  _dt(_problem_ptr->dt()),
100  _dt_old(_problem_ptr->dtOld()),
101  _num(0),
102  _interval(getParam<unsigned int>("interval")),
103  _sync_times(std::set<Real>(getParam<std::vector<Real>>("sync_times").begin(),
104  getParam<std::vector<Real>>("sync_times").end())),
105  _start_time(isParamValid("start_time") ? getParam<Real>("start_time")
106  : std::numeric_limits<Real>::lowest()),
107  _end_time(isParamValid("end_time") ? getParam<Real>("end_time")
108  : std::numeric_limits<Real>::max()),
109  _start_step(isParamValid("start_step") ? getParam<int>("start_step")
110  : std::numeric_limits<int>::lowest()),
111  _end_step(isParamValid("end_step") ? getParam<int>("end_step")
112  : std::numeric_limits<int>::max()),
113  _t_tol(getParam<Real>("time_tolerance")),
114  _sync_only(getParam<bool>("sync_only")),
115  _initialized(false),
116  _allow_output(true),
117  _is_advanced(false),
118  _advanced_execute_on(_execute_on, parameters),
119  _output_step_timer(registerTimedSection("outputStep", 2))
120 {
121  if (_use_displaced)
122  {
123  std::shared_ptr<DisplacedProblem> dp = _problem_ptr->getDisplacedProblem();
124  if (dp != nullptr)
125  {
126  _es_ptr = &dp->es();
127  _mesh_ptr = &dp->mesh();
128  }
129  else
130  {
131  mooseWarning(
132  name(),
133  ": Parameter 'use_displaced' ignored, there is no displaced problem in your simulation.");
134  _es_ptr = &_problem_ptr->es();
136  }
137  }
138  else
139  {
140  _es_ptr = &_problem_ptr->es();
142  }
143 
144  // Apply the additional output flags
145  if (isParamValid("additional_execute_on"))
146  {
147  const ExecFlagEnum & add = getParam<ExecFlagEnum>("additional_execute_on");
148  for (auto & me : add)
150  }
151 }
152 
153 void
155 {
156  _initialized = true;
157 }
158 
159 void
161 {
162 }
163 
164 void
166 {
167  // Output is not allowed
168  if (!_allow_output && type != EXEC_FORCED)
169  return;
170 
171  // If recovering disable output of initial condition, it was already output
172  if (type == EXEC_INITIAL && _app.isRecovering())
173  return;
174 
175  // Return if the current output is not on the desired interval
176  if (type != EXEC_FINAL && !onInterval())
177  return;
178 
179  // Call the output method
180  if (shouldOutput(type))
181  {
182  TIME_SECTION(_output_step_timer);
183  output(type);
184  }
185 }
186 
187 bool
189 {
190  // Note that in older versions of MOOSE, this was overloaded (unintentionally) to always return
191  // true for the Console output subclass - basically ignoring execute_on options specified for
192  // the console (e.g. via the input file).
194  return true;
195  return false;
196 }
197 
198 bool
200 {
201  // The output flag to return
202  bool output = false;
203 
204  // Return true if the current step on the current output interval and within the output time range
205  // and within the output step range
206  if (_time >= _start_time && _time <= _end_time && _t_step >= _start_step &&
207  _t_step <= _end_step && (_t_step % _interval) == 0)
208  output = true;
209 
210  // Return false if 'sync_only' is set to true
211  if (_sync_only)
212  output = false;
213 
214  // If sync times are not skipped, return true if the current time is a sync_time
215  if (_sync_times.find(_time) != _sync_times.end())
216  output = true;
217 
218  // Return the output status
219  return output;
220 }
221 
222 Real
224 {
225  if (_transient)
226  return _time;
227  else
228  return _t_step;
229 }
230 
231 Real
233 {
234  if (_transient)
235  return _time_old;
236  else
237  return _t_step - 1;
238 }
239 
240 Real
242 {
243  if (_transient)
244  return _dt;
245  else
246  return 1;
247 }
248 
249 Real
251 {
252  if (_transient)
253  return _dt_old;
254  else
255  return 1;
256 }
257 
258 int
260 {
261  return _t_step;
262 }
263 
264 const MultiMooseEnum &
266 {
267  return _execute_on;
268 }
269 
270 bool
272 {
273  return _is_advanced;
274 }
275 
276 const OutputOnWarehouse &
278 {
279  mooseError("The output object ", name(), " is not an AdvancedOutput, use isAdvanced() to check.");
280  return _advanced_execute_on;
281 }
Real & _time_old
The old time.
Definition: Output.h:191
const MultiMooseEnum & executeOn() const
Get the current &#39;execute_on&#39; selections for display.
Definition: Output.C:265
const ExecFlagType EXEC_FAILED
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:24
virtual Real dtOld()
Get old time step size.
Definition: Output.C:250
A class for creating restricted objects.
Definition: Restartable.h:29
ExecFlagEnum _execute_on
The common Execution types; this is used as the default execution type for everything except system i...
Definition: Output.h:185
const ExecFlagType EXEC_FORCED
OutputOnWarehouse _advanced_execute_on
Storage for the individual component execute flags.
Definition: Output.h:242
void mooseWarning(Args &&... args) const
Definition: MooseObject.h:155
virtual bool onInterval()
Returns true if the output interval is satisfied.
Definition: Output.C:199
virtual void initialSetup()
Initialization method.
Definition: Output.C:154
virtual Real dt()
Get the current time step size.
Definition: Output.C:241
Real & _dt_old
Old time step delta.
Definition: Output.h:200
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:188
Real _start_time
Start outputting time.
Definition: Output.h:212
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 addAvailableFlags(const ExecFlagType &flag, Args... flags)
Add additional execute_on flags to the list of possible flags.
Definition: ExecFlagEnum.h:84
InputParameters validParams< SetupInterface >()
int & _t_step
The current time step.
Definition: Output.h:194
bool _transient
Transient flag (true = transient)
Definition: Output.h:170
const ExecFlagType EXEC_TIMESTEP_END
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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:160
Output(const InputParameters &parameters)
Class constructor.
Definition: Output.C:84
ExecFlagEnum getDefaultExecFlagEnum()
Return the default ExecFlagEnum for MOOSE.
Definition: MooseUtils.C:667
virtual EquationSystems & es() override
const std::string & type() const
Get the type of this object.
Definition: MooseObject.h:53
int _start_step
Start outputting at this time step.
Definition: Output.h:218
bool contains(const std::string &value) const
Contains methods for seeing if a value is in the MultiMooseEnum.
bool _initialized
True if init() has been called.
Definition: Output.h:230
const unsigned int _interval
The output time step interval.
Definition: Output.h:206
virtual Real timeOld()
Get the old output time.
Definition: Output.C:232
Interface for notifications that the mesh has changed.
virtual std::shared_ptr< DisplacedProblem > getDisplacedProblem()
EquationSystems * _es_ptr
Reference the the libMesh::EquationSystems object that contains the data.
Definition: Output.h:176
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
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:165
int _end_step
End outputting at this time step.
Definition: Output.h:221
InputParameters validParams< Output >()
Definition: Output.C:29
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
Definition: Output.h:167
bool _allow_output
Flag for disabling output.
Definition: Output.h:233
A helper warehouse class for storing the "execute_on" settings for the various output types...
std::string getDocString() const
Generate a documentation string for the "execute_on" parameter.
Definition: ExecFlagEnum.C:39
bool _sync_only
Flag for only executing at sync times.
Definition: Output.h:227
PerfID _output_step_timer
Timers.
Definition: Output.h:245
Interface for objects that needs transient capabilities.
InputParameters validParams< MooseObject >()
Definition: MooseObject.C:25
bool _use_displaced
Flag for using displaced mesh.
Definition: Output.h:173
virtual Real time()
Get the output time.
Definition: Output.C:223
bool _is_advanced
Flag for advanced output testing.
Definition: Output.h:236
std::set< Real > _sync_times
Sync times for this outputter.
Definition: Output.h:209
bool isAdvanced()
Returns true if this object is an AdvancedOutput object.
Definition: Output.C:271
MatType type
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:21
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:177
virtual MooseMesh & mesh() override
MooseMesh * _mesh_ptr
A convenience pointer to the current mesh (reference or displaced depending on "use_displaced") ...
Definition: Output.h:179
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
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...
virtual const OutputOnWarehouse & advancedExecuteOn() const
Returns the advanced &#39;execute_on&#39; settings.
Definition: Output.C:277
virtual int timeStep()
Get the current time step.
Definition: Output.C:259
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:89
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition: MooseApp.C:859
const ExecFlagType EXEC_FINAL
Real & _time
The current time for output purposes.
Definition: Output.h:188
Real & _dt
Time step delta.
Definition: Output.h:197
const ExecFlagType EXEC_INITIAL