17#include "libmesh/parallel_object.h"
18#include "libmesh/dense_vector.h"
131 template <
typename T>
135 const std::size_t time_index = 0)
const;
146 template <
typename T>
148 const std::size_t time_index = 0)
const;
165 template <
typename T>
168 const std::size_t time_index = 0);
177 template <
typename T>
204 template <
typename T,
typename S,
typename... Args>
221 void finalize(
const std::string & object_name);
304 template <
typename T>
326 mutable std::map<ReporterName, ReporterStateBase *>
_states;
342 const auto error_helper =
343 [
this, &reporter_name, &moose_object, &declare](
const std::string & suffix)
345 std::stringstream oss;
346 oss <<
"While " << (declare ?
"declaring" :
"requesting") <<
" a "
350 oss <<
" and type \"" << MooseUtils::prettyCppType<T>() <<
"\"";
351 oss <<
",\na Reporter with the same name " << suffix <<
".\n\n";
355 moose_object->mooseError(oss.str());
361 error_helper(
"has already been declared");
362 if (!hasReporterState<T>(reporter_name))
364 std::stringstream oss;
365 oss <<
"has been " << (declare || !
hasReporterValue(reporter_name) ?
"requested" :
"declared")
366 <<
" with a different type";
367 error_helper(oss.str());
378 auto state_unique_ptr = std::make_unique<ReporterState<T>>(reporter_name);
382 mooseAssert(state,
"Cast failed. The check above must be broken!");
387 _states.emplace(reporter_name, state);
397 const std::size_t time_index )
const
399 auto & state = getReporterStateHelper<T>(reporter_name,
false, &consumer);
400 state.addConsumer(mode, consumer);
401 return state.value(time_index);
404template <
typename T,
typename S,
typename... Args>
412 auto & state = getReporterStateHelper<T>(reporter_name,
true, &producer);
425 if (reporter_name.
isPostprocessor() && !state.getReporterName().isPostprocessor())
427 state.setIsPostprocessor();
429 _states.emplace(reporter_name, &state);
432 !state.getReporterName().isVectorPostprocessor())
434 state.setIsVectorPostprocessor();
436 _states.emplace(reporter_name, &state);
439 mooseAssert(!
_context_ptrs.count(reporter_name),
"Context already exists");
442 auto context_ptr = std::make_unique<S>(
_app, producer, state, args...);
443 context_ptr->init(mode);
444 _context_ptrs.emplace(reporter_name, std::move(context_ptr));
453 return state.value();
477 const std::size_t time_index)
const
479 if (!hasReporterValue<T>(reporter_name))
483 MooseUtils::prettyCppType<T>(),
484 "\" is not declared.");
488 getReporterStateHelper<T>(reporter_name,
false))
496 const std::size_t time_index)
499 const auto & me = *
this;
500 const_cast<T &
>(me.getReporterValue<T>(reporter_name, time_index)) = value;
506 const std::size_t time_index)
508 getReporterValue<T>(reporter_name, 0);
509 getReporterStateHelper<T>(reporter_name,
false).value(time_index);
517 unsigned int time_index)
const
528 unsigned int time_index)
const
530 std::vector<T> & vec =
531 const_cast<std::vector<T> &
>(r_data.
getReporterValue<std::vector<T>>(r_name, time_index));
533 if (index >= vec.size())
535 "Requested index ", index,
" is outside the bounds of the vector reporter value ", r_name);
536 vec[index] = _state.value();
545 unsigned int time_index)
const
549 if (index >= _state.value().size())
552 " is outside the bounds of the vector reporter value ",
555 using R =
typename T::value_type;
560 libmesh_ignore(r_data);
561 libmesh_ignore(r_name);
562 libmesh_ignore(index);
563 libmesh_ignore(time_index);
564 mooseError(
"transferFromVector can only be used for reporter types that are specializatons of "
599 mooseError(
"Cannot create clone with ReporterVectorContext.");
610 mooseError(
"Cannot create clone with ReporterVectorContext.");
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
A class for storing a constant value.
Base class for MOOSE-based applications.
Every object that can be built by the factory should be derived from this class.
Base class for all Postprocessors.
A class for storing data, it allows the user to change the value of the postprocessor by altering the...
This is a helper class to aid with parallel communication of compute Reporter values as well as provi...
General context that is called by all Reporter values to manage the old values.
virtual void transferToVector(ReporterData &r_data, const ReporterName &r_name, dof_id_type index, unsigned int time_index=0) const override
Perform type specific transfer to a vector.
virtual void transfer(ReporterData &r_data, const ReporterName &r_name, unsigned int time_index=0) const override
Perform type specific transfer.
virtual void transferFromVector(ReporterData &r_data, const ReporterName &r_name, dof_id_type index, unsigned int time_index=0) const override
Perform type specific transfer from a vector.
WriteKey()
An object that can be passed to FEProblemBase::getReporterData to provide non-const access the Report...
This is a helper class for managing the storage of declared Reporter object values.
void needReporterTimeIndex(const ReporterName &reporter_name, const std::size_t time_index)
Method for setting that a specific time index is requested for a Reporter value.
std::set< ReporterName > getReporterNames() const
Return a list of all reporter names.
bool hasReporterState(const ReporterName &reporter_name) const
std::vector< std::string > getAllRealReporterFullNames() const
Get full names of all real reporter values Note: For a postprocessor, the full name is the postproces...
const ReporterStateBase & getReporterStateBase(const ReporterName &reporter_name) const
@Returns The ReporterStateBase associated with the Reporter with name reporter_name.
ReporterState< T > & getReporterStateHelper(const ReporterName &reporter_name, bool declare, const MooseObject *moose_object=nullptr) const
Helper method for creating the necessary RestartableData for Reporter values.
MooseApp & _app
For accessing the restart/recover system, which is where Reporter values are stored.
DenseVector< Real > getAllRealReporterValues() const
Get all real reporter values including postprocessor and vector postprocessor values into a dense vec...
T & declareReporterValue(const ReporterName &reporter_name, const ReporterMode &mode, const MooseObject &producer, Args &&... args)
Method for returning a writable reference to the current Reporter value.
void check() const
Perform integrity check for get/declare calls.
void copyValuesBack()
At the end of a timestep this method is called to copy the values back in time in preparation for the...
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.
void setReporterValue(const ReporterName &reporter_name, const T &value, const std::size_t time_index=0)
Method for setting Reporter values that already exist.
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
void restoreState(bool verbose=false)
When a time step fails, this method is called to revert the current reporter values to their old stat...
std::map< ReporterName, ReporterStateBase * > _states
Map from ReporterName -> Reporter state.
const T & getReporterValue(const ReporterName &reporter_name, const MooseObject &consumer, const ReporterMode &mode, const std::size_t time_index=0) const
Method for returning read only references to Reporter values.
std::string getReporterInfo() const
Gets information about all declared/requested Reporters.
void restoreReporterStateIfAvailable(RestartableDataValue &state) const
Helper for restoring state from the checkpoint reader if available.
RestartableDataValue & getRestartableDataHelper(std::unique_ptr< RestartableDataValue > data_ptr, bool declare) const
Helper for registering data with the MooseApp to avoid cyclic includes.
bool hasReporterWithMode(const std::string &obj_name, const ReporterMode &mode) const
Return true if the supplied mode exists in the produced Reporter values.
std::set< std::string > getPostprocessorNames() const
Return a list of all postprocessor names.
const ReporterProducerEnum & getReporterMode(const ReporterName &reporter_name) const
Return the ReporterProducerEnum for an existing ReporterValue.
void finalize(const std::string &object_name)
Helper function for performing post calculation actions via the ReporterContext objects.
virtual void declareClone(ReporterData &r_data, const ReporterName &r_name, const ReporterMode &mode, const MooseObject &producer) const override
Declare a reporter value of same type as this context.
virtual void declareVectorClone(ReporterData &r_data, const ReporterName &r_name, const ReporterMode &mode, const MooseObject &producer) const override
Declare a reporter value that is a vector of the same type as this context.
MooseEnumItem that automatically creates the ID and doesn't allow the ID to be assigned.
The Reporter system is comprised of objects that can contain any number of data values.
std::string specialTypeToName() const
Converts the special type to a usable name for error reporting.
bool isPostprocessor() const
bool isVectorPostprocessor() const
const std::string & getValueName() const
Return the data name for the Reporter value.
MooseEnum designed for the ReporterContext objects to define how a ReporterValue can and is being pro...
The base class for storing a Reporter's state.
A special version of RestartableData to aid in storing Reporter values.
This context is specific for vector types of reporters, mainly for declaring a vector of the type fro...
virtual void declareClone(ReporterData &r_data, const ReporterName &r_name, const ReporterMode &mode, const MooseObject &producer) const final
This simply throws an error to avoid infinite instantiations.
virtual void declareVectorClone(ReporterData &r_data, const ReporterName &r_name, const ReporterMode &mode, const MooseObject &producer) const final
This simply throws an error to avoid infinite instantiations.
Reporter objects allow for the declaration of arbitrary data types that are aggregate values for a si...
Abstract definition of a RestartableData value.
Base class for Postprocessors that produce a vector of values.