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;
334 template <
typename T>
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);
392 template <
typename T>
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);
404 template <
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);
431 else if (reporter_name.isVectorPostprocessor() &&
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();
456 template <
typename T>
465 template <
typename T>
474 template <
typename T>
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))
492 template <
typename T>
496 const std::size_t time_index)
499 const auto & me = *
this;
500 const_cast<T &
>(me.getReporterValue<T>(reporter_name, time_index)) =
value;
503 template <
typename T>
506 const std::size_t time_index)
508 getReporterValue<T>(reporter_name, 0);
509 getReporterStateHelper<T>(reporter_name,
false).
value(time_index);
513 template <
typename T>
517 unsigned int time_index)
const 523 template <
typename T>
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();
540 template <
typename T>
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;
564 mooseError(
"transferFromVector can only be used for reporter types that are specializatons of " 570 template <
typename T>
581 template <
typename T>
592 template <
typename T>
599 mooseError(
"Cannot create clone with ReporterVectorContext.");
603 template <
typename T>
610 mooseError(
"Cannot create clone with ReporterVectorContext.");
ReporterData(MooseApp &moose_app)
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
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.
A special version of RestartableData to aid in storing Reporter values.
std::map< ReporterName, ReporterStateBase * > _states
Map from ReporterName -> Reporter state.
bool isVectorPostprocessor() const
virtual void transfer(ReporterData &r_data, const ReporterName &r_name, unsigned int time_index=0) const override
Perform type specific transfer.
const ReporterStateBase & getReporterStateBase(const ReporterName &reporter_name) const
The ReporterStateBase associated with the Reporter with name reporter_name.
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.
This context is specific for vector types of reporters, mainly for declaring a vector of the type fro...
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
MooseEnum designed for the ReporterContext objects to define how a ReporterValue can and is being pro...
WriteKey()
An object that can be passed to FEProblemBase::getReporterData to provide non-const access the Report...
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.
Base class for MOOSE-based applications.
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.
void restoreReporterStateIfAvailable(RestartableDataValue &state) const
Helper for restoring state from the checkpoint reader if available.
Reporter objects allow for the declaration of arbitrary data types that are aggregate values for a si...
RestartableDataValue & getRestartableDataHelper(std::unique_ptr< RestartableDataValue > data_ptr, bool declare) const
Helper for registering data with the MooseApp to avoid cyclic includes.
void libmesh_ignore(const Args &...)
This is a helper class to aid with parallel communication of compute Reporter values as well as provi...
DenseVector< Real > getAllRealReporterValues() const
Get all real reporter values including postprocessor and vector postprocessor values into a dense vec...
std::string specialTypeToName() const
Converts the special type to a usable name for error reporting.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
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.
Every object that can be built by the factory should be derived from this class.
std::vector< std::string > getAllRealReporterFullNames() const
Get full names of all real reporter values Note: For a postprocessor, the full name is the postproces...
bool hasReporterState(const ReporterName &reporter_name) const
void finalize(const std::string &object_name)
Helper function for performing post calculation actions via the ReporterContext objects.
The base class for storing a Reporter's state.
bool isPostprocessor() const
Base class for all Postprocessors.
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.
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::set< ReporterName > getReporterNames() const
Return a list of all reporter names.
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.
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.
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.
void copyValuesBack()
At the end of a timestep this method is called to copy the values back in time in preparation for the...
const ReporterProducerEnum & getReporterMode(const ReporterName &reporter_name) const
Return the ReporterProducerEnum for an existing ReporterValue.
MooseApp & _app
For accessing the restart/recover system, which is where Reporter values are stored.
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.
std::string getReporterInfo() const
Gets information about all declared/requested Reporters.
A class for storing data, it allows the user to change the value of the postprocessor by altering the...
T & value(const std::size_t time_index=0)
Return a reference to the current value or one of the old values.
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
General context that is called by all Reporter values to manage the old values.
bool hasReporterWithMode(const std::string &obj_name, const ReporterMode &mode) const
Return true if the supplied mode exists in the produced Reporter values.
void check() const
Perform integrity check for get/declare calls.
std::set< std::string > getPostprocessorNames() const
Return a list of all postprocessor names.
const std::string & getValueName() const
Return the data name for the Reporter value.
Base class for Postprocessors that produce a vector of values.
MooseEnumItem that automatically creates the ID and doesn't allow the ID to be assigned.
Abstract definition of a RestartableData value.
The Reporter system is comprised of objects that can contain any number of data values.
A class for storing a constant value.
void restoreState(bool verbose=false)
When a time step fails, this method is called to revert the current reporter values to their old stat...
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
This is a helper class for managing the storage of declared Reporter object values.