29 "use_legacy_reporter_output",
false,
"Use reporter output that does not group by object.");
30 params.
addParam<
bool>(
"one_file_per_timestep",
32 "Create a unique output file for each time step of the simulation.");
33 params.
addParam<std::vector<ReporterName>>(
34 "reporters",
"Specific reporter values to output; if not set, all will be output");
36 "distributed",
true,
"Whether or not to output distributed data (data not on rank 0)");
42 _reporter_data(_problem_ptr->getReporterData()),
43 _one_file_per_timestep(getParam<bool>(
"one_file_per_timestep")),
45 _json(declareRestartableData<
nlohmann::json>(
"json_out_str"))
55 paramError(
"reporters",
"Reporter value '",
name,
"' was not found");
61 std::ostringstream file_name;
65 file_name <<
'_' << std::setw(
_padding) << std::setprecision(0) << std::setfill(
'0')
72 <<
"." << std::setw(digits) << std::setfill(
'0') <<
processor_id();
77 return file_name.str();
100 std::set<ReporterName> skip_names;
102 if (common_actions.size())
104 mooseAssert(common_actions.size() == 1,
"Should not be more than one");
105 const auto & action = *common_actions[0];
106 const auto & common_names = action.getCommonReporterNames();
107 skip_names.insert(common_names.begin(), common_names.end());
111 std::set<ReporterName> r_names;
123 else if (skip_names.count(r_name))
126 r_names.emplace(r_name);
131 std::any_of(r_names.begin(),
135 return _reporter_data.hasReporterWithMode(
136 n.getObjectName(), REPORTER_MODE_DISTRIBUTED);
141 auto & current_node =
_json[
"time_steps"].emplace_back();
159 auto & r_node =
_json[
"reporters"];
160 for (
const auto & r_name : r_names)
168 auto obj_node_pair = r_node.emplace(r_name.getObjectName(), nlohmann::json());
169 auto & obj_node = *(obj_node_pair.first);
172 bool should_store =
true;
175 if (obj_node_pair.second)
182 std::vector<Reporter *> objs;
186 .condition<AttribName>(r_name.getObjectName())
195 auto & reporter = *objs.front();
199 reporter.store(obj_node);
203 should_store = reporter.shouldStore();
208 auto value_node_pair = obj_node[
"values"].emplace(r_name.getValueName(), nlohmann::json());
210 if (value_node_pair.second)
212 context.storeInfo(*value_node_pair.first);
215 auto & node = current_node[r_name.getObjectName()][r_name.getValueName()];
231 std::ofstream out(
filename().c_str());
232 out << std::setw(4) <<
_json << std::endl;
238dataStore(std::ostream & stream, nlohmann::json & json,
void * )
245dataLoad(std::istream & stream, nlohmann::json & json,
void * )
void dataStore(std::ostream &stream, nlohmann::json &json, void *)
void dataLoad(std::istream &stream, nlohmann::json &json, void *)
registerMooseObjectAliased("MooseApp", JSONOutput, "JSON")
const ExecFlagType EXEC_INITIAL
const ExecFlagType EXEC_LINEAR
const ExecFlagType EXEC_NONLINEAR
const ReporterMode REPORTER_MODE_ROOT
std::vector< const T * > getActions()
Retrieve all actions in a specific type ordered by their names.
Based class for output objects.
const std::set< std::string > & getReporterOutput()
The list of Reporter names that are set for output.
static InputParameters enableOutputTypes(const std::string &names=std::string())
A method for enabling individual output type control.
virtual void output()
A single call to this function should output all the necessary data for a single timestep.
static InputParameters validParams()
Meta-action for creating common output object parameters This action serves two purpose,...
A MultiMooseEnum object to hold "execute_on" flags.
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
TheWarehouse & theWarehouse() const
virtual Real & time() const
virtual int & timeStep() const
unsigned int _padding
Number of digits to pad the extensions.
std::string _file_base
The base filename from the input paramaters.
virtual std::string filename() override
The filename for the output file.
virtual void initialSetup() override
Call init() method on setup.
const std::vector< ReporterName > *const _reporters
The names of the specific reporters to output (if any)
bool _has_distributed
True when distributed data exists for output.
virtual void timestepSetup() override
Gets called at the beginning of the timestep before this object is asked to do its job.
nlohmann::json & _json
The root JSON node for output.
const ReporterData & _reporter_data
const bool _one_file_per_timestep
Flag to create a file for each time step.
JSONOutput(const InputParameters ¶meters)
static InputParameters validParams()
virtual void outputReporters() override
Output Reporter values.
virtual void output() override
A single call to this function should output all the necessary data for a single timestep.
virtual void outputSystemInformation() override
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
const std::string & name() const
Get the name of the class.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
MooseApp & _app
The MOOSE application this is associated with.
bool isValueSet(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
virtual int timeStep()
Get the current time step.
PetscInt _nonlinear_iter
Current non-linear iteration returned from PETSc.
PetscInt _linear_iter
Current linear iteration returned from PETSc.
bool _on_nonlinear_residual
True if current output call is on the non-linear residual (used by time())
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
The Reporter system is comprised of objects that can contain any number of data values.
const ExecFlagEnum & _execute_enum
Execute settings for this object.
virtual void timestepSetup()
Gets called at the beginning of the timestep before this object is asked to do its job.
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse.
std::vector< T * > & queryInto(const std::vector< std::unique_ptr< Attribute > > &conds, std::vector< T * > &results)
queryInto takes the given conditions (i.e.
std::size_t queryID(const std::vector< std::unique_ptr< Attribute > > &conds)
processor_id_type processor_id() const
processor_id_type n_processors() const