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>
320 mutable std::map<ReporterName, ReporterStateBase *>
_states;
328 template <
typename T>
336 const auto error_helper =
337 [
this, &reporter_name, &moose_object, &declare](
const std::string & suffix)
339 std::stringstream oss;
340 oss <<
"While " << (declare ?
"declaring" :
"requesting") <<
" a " 344 oss <<
" and type \"" << MooseUtils::prettyCppType<T>() <<
"\"";
345 oss <<
",\na Reporter with the same name " << suffix <<
".\n\n";
349 moose_object->mooseError(oss.str());
355 error_helper(
"has already been declared");
356 if (!hasReporterState<T>(reporter_name))
358 std::stringstream oss;
359 oss <<
"has been " << (declare || !
hasReporterValue(reporter_name) ?
"requested" :
"declared")
360 <<
" with a different type";
361 error_helper(oss.str());
372 auto state_unique_ptr = std::make_unique<ReporterState<T>>(reporter_name);
376 mooseAssert(state,
"Cast failed. The check above must be broken!");
381 _states.emplace(reporter_name, state);
386 template <
typename T>
391 const std::size_t time_index )
const 393 auto & state = getReporterStateHelper<T>(reporter_name,
false, &consumer);
394 state.addConsumer(mode, consumer);
395 return state.value(time_index);
398 template <
typename T,
typename S,
typename... Args>
406 auto & state = getReporterStateHelper<T>(reporter_name,
true, &producer);
419 if (reporter_name.isPostprocessor() && !state.getReporterName().isPostprocessor())
421 state.setIsPostprocessor();
423 _states.emplace(reporter_name, &state);
425 else if (reporter_name.isVectorPostprocessor() &&
426 !state.getReporterName().isVectorPostprocessor())
428 state.setIsVectorPostprocessor();
430 _states.emplace(reporter_name, &state);
433 mooseAssert(!
_context_ptrs.count(reporter_name),
"Context already exists");
436 auto context_ptr = std::make_unique<S>(
_app, producer, state, args...);
437 context_ptr->init(mode);
438 _context_ptrs.emplace(reporter_name, std::move(context_ptr));
440 return state.value();
443 template <
typename T>
452 template <
typename T>
461 template <
typename T>
464 const std::size_t time_index)
const 466 if (!hasReporterValue<T>(reporter_name))
470 MooseUtils::prettyCppType<T>(),
471 "\" is not declared.");
475 getReporterStateHelper<T>(reporter_name,
false))
479 template <
typename T>
483 const std::size_t time_index)
486 const auto & me = *
this;
487 const_cast<T &
>(me.getReporterValue<T>(reporter_name, time_index)) =
value;
490 template <
typename T>
493 const std::size_t time_index)
495 getReporterValue<T>(reporter_name, 0);
496 getReporterStateHelper<T>(reporter_name,
false).
value(time_index);
500 template <
typename T>
504 unsigned int time_index)
const 510 template <
typename T>
515 unsigned int time_index)
const 517 std::vector<T> & vec =
518 const_cast<std::vector<T> &
>(r_data.
getReporterValue<std::vector<T>>(r_name, time_index));
520 if (index >= vec.size())
522 "Requested index ", index,
" is outside the bounds of the vector reporter value ", r_name);
523 vec[index] = _state.value();
527 template <
typename T>
532 unsigned int time_index)
const 536 if (index >= _state.value().size())
539 " is outside the bounds of the vector reporter value ",
542 using R =
typename T::value_type;
551 mooseError(
"transferFromVector can only be used for reporter types that are specializatons of " 557 template <
typename T>
568 template <
typename T>
579 template <
typename T>
586 mooseError(
"Cannot create clone with ReporterVectorContext.");
590 template <
typename T>
597 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.
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.