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.");
36 "append_date",
false,
"When true the date and time are appended to the output filename.");
37 params.
addParam<std::string>(
"append_date_format",
38 "The format of the date/time to append, if not given UTC format " 39 "is used (see http://www.cplusplus.com/reference/ctime/strftime).");
42 "padding", 4,
"The number of digits for the extension suffix (e.g., out.e-s002)");
43 params.
addParam<std::vector<std::string>>(
"output_if_base_contains",
44 std::vector<std::string>(),
45 "If this is supplied then output will only be done in " 46 "the case that the output base contains one of these " 47 "strings. This is helpful in outputting only a subset " 48 "of outputs when using MultiApps.");
50 "file_base append_date append_date_format padding output_if_base_contains",
51 "File name customization");
58 _file_num(declareRecoverableData<unsigned
int>(
"file_num", 0)),
59 _padding(getParam<unsigned
int>(
"padding")),
60 _output_if_base_contains(getParam<
std::vector<
std::string>>(
"output_if_base_contains"))
71 mooseError(
"The parameter 'file_base' may not be specified for a child app when the " 72 "MultiApp has multiple instances of the child app, since all instances would " 73 "use the same file base and thus write to the same file.");
100 if (
_file_base.find(search_string) != std::string::npos)
130 if (getParam<bool>(
"append_date"))
134 format = getParam<std::string>(
"append_date_format");
136 format =
"%Y-%m-%dT%T%z";
144 strftime(buffer, 80, format.c_str(), localtime(&now));
150 std::filesystem::path directory_base =
_file_base;
151 directory_base.remove_filename();
152 if (directory_base.empty())
153 directory_base =
".";
155 directory_base = std::filesystem::relative(std::filesystem::absolute(directory_base));
157 std::filesystem::path possible_dir_to_make;
158 for (
auto it = directory_base.begin(); it != directory_base.end(); ++it)
160 possible_dir_to_make = possible_dir_to_make / *it;
161 const auto dir_string = possible_dir_to_make.generic_string();
164 if (Utility::mkdir(dir_string.c_str()) == -1)
virtual void setFileBaseInternal(const std::string &file_base)
Internal function that sets the file_base.
virtual bool shouldOutput() override
Checks if the output method should be executed.
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
virtual std::string filename()
The filename for the output file.
virtual Real time() override
Get the output time.
unsigned int getFileNumber()
Return the current file number for this outputter.
std::string _file_base
The base filename from the input paramaters.
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 isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
virtual bool shouldOutput()
Handles logic for determining if a step should be output.
void setFileNumber(unsigned int num)
Sets the file number manually.
static InputParameters validParams()
void setFileBase(const std::string &file_base)
Sets the file base string if the 'file_base' parameter is not set.
static InputParameters validParams()
virtual void output()=0
Overload this function with the desired output activities.
MooseApp & _app
The MOOSE application this is associated with.
std::vector< std::string > _output_if_base_contains
Storage for 'output_if_base_contains'.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
unsigned int & _file_num
A file number counter, initialized to 0 (this must be controlled by the child class, see Exodus)
FileOutput(const InputParameters ¶meters)
Class constructor.
Adds the ability to output on every nonlinear and/or linear residual.
bool checkFilename()
Checks the filename for output Checks the output against the 'output_if_base_contians' list...
void ErrorVector unsigned int