21#include "libmesh/utility.h"
31 "The desired solution output name without an extension. If not provided, MOOSE sets it "
32 "with Outputs/file_base when available. Otherwise, MOOSE uses input file name and this "
33 "object name for a master input or uses master file_base, the subapp name and this object "
34 "name for a subapp input to set it.");
35 params.
addParam<std::string>(
"file_base_suffix",
"Suffix to add to the file base");
37 "append_date",
false,
"When true the date and time are appended to the output filename.");
38 params.
addParam<std::string>(
"append_date_format",
39 "The format of the date/time to append, if not given UTC format "
40 "is used (see http://www.cplusplus.com/reference/ctime/strftime).");
43 "padding", 4,
"The number of digits for the extension suffix (e.g., out.e-s002)");
44 params.
addParam<std::vector<std::string>>(
"output_if_base_contains",
45 std::vector<std::string>(),
46 "If this is supplied then output will only be done in "
47 "the case that the output base contains one of these "
48 "strings. This is helpful in outputting only a subset "
49 "of outputs when using MultiApps.");
51 "file_base append_date append_date_format padding output_if_base_contains",
52 "File name customization");
59 _file_num(declareRecoverableData<unsigned
int>(
"file_num", 0)),
60 _padding(getParam<unsigned
int>(
"padding")),
61 _output_if_base_contains(getParam<
std::vector<
std::string>>(
"output_if_base_contains"))
72 mooseError(
"The parameter 'file_base' may not be specified for a child app when the "
73 "MultiApp has multiple instances of the child app, since all instances would "
74 "use the same file base and thus write to the same file.");
101 if (
_file_base.find(search_string) != std::string::npos)
131 _file_base +=
"_" + getParam<std::string>(
"file_base_suffix");
134 if (getParam<bool>(
"append_date"))
138 format = getParam<std::string>(
"append_date_format");
140 format =
"%Y-%m-%dT%T%z";
148 strftime(buffer, 80, format.c_str(), localtime(&now));
154 std::filesystem::path directory_base =
_file_base;
155 directory_base.remove_filename();
156 if (directory_base.empty())
157 directory_base =
".";
159 directory_base = std::filesystem::relative(std::filesystem::absolute(directory_base));
161 std::filesystem::path possible_dir_to_make;
162 for (
auto it = directory_base.begin(); it != directory_base.end(); ++it)
164 possible_dir_to_make = possible_dir_to_make / *it;
165 const auto dir_string = possible_dir_to_make.generic_string();
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
void ErrorVector unsigned int
FileOutput(const InputParameters ¶meters)
Class constructor.
unsigned int getFileNumber()
Return the current file number for this outputter.
std::vector< std::string > _output_if_base_contains
Storage for 'output_if_base_contains'.
virtual std::string filename()
The filename for the output file.
void setFileNumber(unsigned int num)
Sets the file number manually.
static InputParameters validParams()
virtual bool shouldOutput() override
Checks if the output method should be executed.
std::string _file_base
The base filename from the input paramaters.
void setFileBase(const std::string &file_base)
Sets the file base string if the 'file_base' parameter is not set.
bool checkFilename()
Checks the filename for output Checks the output against the 'output_if_base_contians' list.
virtual void setFileBaseInternal(const std::string &file_base)
Internal function that sets the file_base.
unsigned int & _file_num
A file number counter, initialized to 0 (this must be controlled by the child class,...
processor_id_type processor_id() const
Returns the MPI processor ID of the current processor.
bool isRestarting() const
Whether or not this is a "restart" calculation.
unsigned int multiAppNumber() const
The MultiApp number.
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
MooseApp & _app
The MOOSE application this is associated with.
virtual bool shouldOutput()
Handles logic for determining if a step should be output.
virtual void output()=0
Overload this function with the desired output activities.
Adds the ability to output on every nonlinear and/or linear residual.
virtual Real time() override
Get the output time.
static InputParameters validParams()
int mkdir(const char *pathname)