https://mooseframework.inl.gov
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ReporterContextBase Class Referenceabstract

This is a helper class to aid with parallel communication of compute Reporter values as well as provides a link to the stored Reporter value state object. More...

#include <ReporterContext.h>

Inheritance diagram for ReporterContextBase:
[legend]

Public Member Functions

 ReporterContextBase (const libMesh::ParallelObject &other, const MooseObject &producer)
 
virtual ~ReporterContextBase ()=default
 
virtual const ReporterNamename () const =0
 Return the ReporterName that the context is associated. More...
 
virtual std::string type () const =0
 Return the type of the data stored. More...
 
virtual std::string contextType () const =0
 
virtual void copyValuesBack ()=0
 Called by FEProblemBase::advanceState via ReporterData. More...
 
virtual bool restoreState ()=0
 Called by FEProblemBase::restoreSolutions via ReporterData. More...
 
virtual void storeInfo (nlohmann::json &json) const =0
 Called by JSONOutput::outputReporters to output meta data independent of calculated values. More...
 
virtual void store (nlohmann::json &json) const =0
 Called by JSONOutput::outputReporters to invoke storage of values for output. More...
 
virtual void finalize ()=0
 Called by FEProblemBase::joinAndFinalize via ReporterData. More...
 
void init (const ReporterMode &mode)
 Initialize the producer mode. More...
 
const MooseObjectgetProducer () const
 Return the MooseObject that produces this Reporter. More...
 
const ReporterProducerEnumgetProducerModeEnum () const
 Return the Reporter value produced mode. More...
 
virtual void transfer (ReporterData &r_data, const ReporterName &r_name, unsigned int time_index=0) const =0
 Helper for enabling generic transfer of Reporter values. More...
 
virtual void transferToVector (ReporterData &r_data, const ReporterName &r_name, dof_id_type index, unsigned int time_index=0) const =0
 Helper for enabling generic transfer of Reporter values to a vector. More...
 
virtual void transferFromVector (ReporterData &r_data, const ReporterName &r_name, dof_id_type index, unsigned int time_index=0) const =0
 Helper for enabling generic transfer of a vector Reporter of values to a single value. More...
 
virtual void declareClone (ReporterData &r_data, const ReporterName &r_name, const ReporterMode &mode, const MooseObject &producer) const =0
 Helper for declaring new reporter values based on this context. More...
 
virtual void declareVectorClone (ReporterData &r_data, const ReporterName &r_name, const ReporterMode &mode, const MooseObject &producer) const =0
 Helper for declaring new vector reporter values based on this context. More...
 
virtual void resize (dof_id_type local_size)=0
 Helper for resizing vector data. More...
 
virtual void clear ()=0
 Helper for clearing vector data. More...
 
virtual void vectorSum ()=0
 Helper for summing reporter value. More...
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Protected Member Functions

void requiresConsumerModes (const ReporterStateBase &state, const std::set< ReporterMode > &modes) const
 Helper for checking whether or not the state state has only the modes modes. More...
 

Protected Attributes

const MooseObject_producer
 The MooseObject that is producing this Reporter. More...
 
ReporterProducerEnum _producer_enum
 Defines how the Reporter value can be produced and how it is being produced. More...
 
const Parallel::Communicator_communicator
 

Detailed Description

This is a helper class to aid with parallel communication of compute Reporter values as well as provides a link to the stored Reporter value state object.

See also
Reporter, ReporterData, ReporterState

This file contains several reporter context types with specific polymorphism:

ReporterContextBase—>ReporterContext<T> | | | ReporterGeneralContext<T> | | | | | | | ReporterGatherContext<T> | | ReporterScatterContext<T> | ReporterBroadcastContext<T> | ReporterVectorContext<std::vector<T>>

When creating a new context, it is generally advisable to derive from ReporterGeneralContext (

See also
VectorPostprocessorContext). The reason for the split between ReporterGeneralContext and ReporterVectorContext is due to the declareVectorClone and resize functionality. If we were to declare a vector clone in ReporterContext there would be a infinite instantiation of of vector contexts, which is why this declare is defined in ReporterGeneralContext and an error is thrown in ReporterVectorContext. There is also no easy way to partially instantiate a member function (you have to due it for the entire class), which is why the resize is defined in ReporterVectorContext. That being said, we are always open for improvements, especially for simplifying the polymorphism of these contexts.

Definition at line 57 of file ReporterContext.h.

Constructor & Destructor Documentation

◆ ReporterContextBase()

ReporterContextBase::ReporterContextBase ( const libMesh::ParallelObject other,
const MooseObject producer 
)

Definition at line 14 of file ReporterContext.C.

16  : libMesh::ParallelObject(other), _producer(producer)
17 {
18 }
const MooseObject & _producer
The MooseObject that is producing this Reporter.

◆ ~ReporterContextBase()

virtual ReporterContextBase::~ReporterContextBase ( )
virtualdefault

Member Function Documentation

◆ clear()

virtual void ReporterContextBase::clear ( )
pure virtual

Helper for clearing vector data.

Implemented in ReporterVectorContext< T >, and ReporterGeneralContext< T >.

Referenced by ReporterTransferInterface::clearVectorReporter().

◆ contextType()

virtual std::string ReporterContextBase::contextType ( ) const
pure virtual

◆ copyValuesBack()

virtual void ReporterContextBase::copyValuesBack ( )
pure virtual

◆ declareClone()

virtual void ReporterContextBase::declareClone ( ReporterData r_data,
const ReporterName r_name,
const ReporterMode mode,
const MooseObject producer 
) const
pure virtual

Helper for declaring new reporter values based on this context.

Parameters
r_dataThe ReporterData on the app that this value is being declared
r_nameThe name of the Reporter value being declared
modeReporter mode to declare with
See also
ReporterTransferInterface

Implemented in ReporterVectorContext< T >, and ReporterGeneralContext< T >.

Referenced by ReporterTransferInterface::declareClone().

◆ declareVectorClone()

virtual void ReporterContextBase::declareVectorClone ( ReporterData r_data,
const ReporterName r_name,
const ReporterMode mode,
const MooseObject producer 
) const
pure virtual

Helper for declaring new vector reporter values based on this context.

Parameters
r_dataThe ReporterData on the app that this value is being declared
r_nameThe name of the Reporter value being declared
modeReporter mode to declare with
See also
ReporterTransferInterface

Implemented in ReporterVectorContext< T >, and ReporterGeneralContext< T >.

Referenced by ReporterTransferInterface::declareVectorClone().

◆ finalize()

virtual void ReporterContextBase::finalize ( )
pure virtual

◆ getProducer()

const MooseObject& ReporterContextBase::getProducer ( ) const
inline

Return the MooseObject that produces this Reporter.

Definition at line 118 of file ReporterContext.h.

Referenced by ReporterData::getReporterInfo().

118 { return _producer; }
const MooseObject & _producer
The MooseObject that is producing this Reporter.

◆ getProducerModeEnum()

const ReporterProducerEnum & ReporterContextBase::getProducerModeEnum ( ) const

Return the Reporter value produced mode.

Definition at line 28 of file ReporterContext.C.

Referenced by ReporterData::getReporterMode().

29 {
30  return _producer_enum;
31 }
ReporterProducerEnum _producer_enum
Defines how the Reporter value can be produced and how it is being produced.

◆ init()

void ReporterContextBase::init ( const ReporterMode mode)

Initialize the producer mode.

This done after construction to allow the constructor to define the available values in the ReporterProducerEnum.

See also
ReporterData::declareReporterValue

Definition at line 21 of file ReporterContext.C.

22 {
23  if (mode != REPORTER_MODE_UNSET)
24  _producer_enum.assign(mode);
25 }
const ReporterMode REPORTER_MODE_UNSET
void assign(const std::string &name, const std::optional< std::string > &context={})
Definition: MooseEnum.C:60
ReporterProducerEnum _producer_enum
Defines how the Reporter value can be produced and how it is being produced.

◆ name()

virtual const ReporterName& ReporterContextBase::name ( ) const
pure virtual

Return the ReporterName that the context is associated.

Implemented in ReporterContext< T >, and ReporterContext< std::vector< T > >.

Referenced by requiresConsumerModes().

◆ requiresConsumerModes()

void ReporterContextBase::requiresConsumerModes ( const ReporterStateBase state,
const std::set< ReporterMode > &  modes 
) const
protected

Helper for checking whether or not the state state has only the modes modes.

Definition at line 34 of file ReporterContext.C.

36 {
37  for (const auto & mode_object_pair : state.getConsumers())
38  if (!modes.count(mode_object_pair.first))
39  {
40  std::stringstream oss;
41  std::copy(modes.begin(), modes.end(), std::ostream_iterator<ReporterMode>(oss, " "));
42 
43  mooseError("The Reporter value '",
44  name(),
45  "' is being produced in ",
47  " mode, but ",
48  mode_object_pair.second->typeAndName(),
49  " is requesting to consume it in ",
50  mode_object_pair.first,
51  " mode, which is not supported.\n\nThe mode must be { ",
52  oss.str(),
53  " }.\n\n",
54  ReporterData::getReporterInfo(state, this));
55  }
56 }
const std::set< std::pair< ReporterMode, const MooseObject * > > & getConsumers() const
Returns the consumers for this state; a pair that consists of the mode that the state is being consum...
Definition: ReporterState.h:56
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
virtual const ReporterName & name() const =0
Return the ReporterName that the context is associated.
std::string getReporterInfo() const
Gets information about all declared/requested Reporters.
Definition: ReporterData.C:247
ReporterProducerEnum _producer_enum
Defines how the Reporter value can be produced and how it is being produced.

◆ resize()

virtual void ReporterContextBase::resize ( dof_id_type  local_size)
pure virtual

Helper for resizing vector data.

Parameters
local_sizeNumber of elements to resize vector to

Implemented in ReporterVectorContext< T >, and ReporterGeneralContext< T >.

Referenced by ReporterTransferInterface::resizeReporter().

◆ restoreState()

virtual bool ReporterContextBase::restoreState ( )
pure virtual

◆ store()

virtual void ReporterContextBase::store ( nlohmann::json &  json) const
pure virtual

Called by JSONOutput::outputReporters to invoke storage of values for output.

This method exists and is distinct from the RestartableData::store method for JSON output via the JSONOutput object. The RestartableData::store/load methods are designed for restart and include all the data including the old values.

This method only outputs the current value within the JSONOutput object. NOTE: nlohmann qualification is needed for argument json because the std::vector overload is not in the std namespace, it's in the nlohmann namespace, and will come up in argument dependent lookup (ADL) only because of this qualification.

See also
JsonIO.h
JSONOutput.h

Implemented in ReporterContext< T >, and ReporterContext< std::vector< T > >.

◆ storeInfo()

virtual void ReporterContextBase::storeInfo ( nlohmann::json &  json) const
pure virtual

Called by JSONOutput::outputReporters to output meta data independent of calculated values.

Implemented in ReporterContext< T >, and ReporterContext< std::vector< T > >.

◆ transfer()

virtual void ReporterContextBase::transfer ( ReporterData r_data,
const ReporterName r_name,
unsigned int  time_index = 0 
) const
pure virtual

Helper for enabling generic transfer of Reporter values.

Parameters
r_dataThe ReporterData on the app that this data is being transferred to
r_nameThe name of the Report being transferred to
See also
MultiAppReporterTransfer

Implemented in ReporterContext< T >, and ReporterContext< std::vector< T > >.

Referenced by ReporterTransferInterface::transferReporter().

◆ transferFromVector()

virtual void ReporterContextBase::transferFromVector ( ReporterData r_data,
const ReporterName r_name,
dof_id_type  index,
unsigned int  time_index = 0 
) const
pure virtual

Helper for enabling generic transfer of a vector Reporter of values to a single value.

Parameters
r_dataThe ReporterData on the app that this data is being transferred to
r_nameThe name of the Reporter being transferred to
See also
ReporterTransferInterface

Implemented in ReporterContext< T >, and ReporterContext< std::vector< T > >.

Referenced by ReporterTransferInterface::transferFromVectorReporter().

◆ transferToVector()

virtual void ReporterContextBase::transferToVector ( ReporterData r_data,
const ReporterName r_name,
dof_id_type  index,
unsigned int  time_index = 0 
) const
pure virtual

Helper for enabling generic transfer of Reporter values to a vector.

Parameters
r_dataThe ReporterData on the app that this data is being transferred to
r_nameThe name of the Report being transfered to
See also
ReporterTransferInterface

Implemented in ReporterContext< T >, and ReporterContext< std::vector< T > >.

Referenced by ReporterTransferInterface::transferToVectorReporter().

◆ type()

virtual std::string ReporterContextBase::type ( ) const
pure virtual

Return the type of the data stored.

Implemented in ReporterContext< T >, and ReporterContext< std::vector< T > >.

Referenced by AccumulateReporter::declareLateValues().

◆ vectorSum()

virtual void ReporterContextBase::vectorSum ( )
pure virtual

Helper for summing reporter value.

Implemented in ReporterVectorContext< T >, and ReporterGeneralContext< T >.

Referenced by ReporterTransferInterface::sumVectorReporter().

Member Data Documentation

◆ _producer

const MooseObject& ReporterContextBase::_producer
protected

The MooseObject that is producing this Reporter.

Definition at line 214 of file ReporterContext.h.

Referenced by getProducer().

◆ _producer_enum

ReporterProducerEnum ReporterContextBase::_producer_enum
protected

The documentation for this class was generated from the following files: