https://mooseframework.inl.gov
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
StochasticReporterContext< T > Class Template Reference

#include <StochasticReporter.h>

Inheritance diagram for StochasticReporterContext< T >:
[legend]

Public Types

enum  AutoOperation
 

Public Member Functions

 StochasticReporterContext (const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< std::vector< T >> &state, const Sampler &sampler)
 
virtual void copyValuesBack () override
 
virtual void finalize () override
 
virtual std::string contextType () const override
 
virtual void storeInfo (nlohmann::json &json) const override
 
virtual void declareClone (ReporterData &r_data, const ReporterName &r_name, const ReporterMode &mode, const MooseObject &producer) const override
 
virtual void declareVectorClone (ReporterData &r_data, const ReporterName &r_name, const ReporterMode &mode, const MooseObject &producer) const override
 
virtual void resize (dof_id_type local_size) final
 
virtual void clear () final
 
virtual void vectorSum () final
 
const ReporterNamename () const override final
 
const ReporterState< std::vector< T > > & state () const
 
virtual std::string type () const override
 
virtual void transfer (ReporterData &r_data, const ReporterName &r_name, unsigned int time_index=0) const override
 
virtual void transferToVector (ReporterData &r_data, const ReporterName &r_name, dof_id_type index, unsigned int time_index=0) const override
 
virtual void transferFromVector (ReporterData &r_data, const ReporterName &r_name, dof_id_type index, unsigned int time_index=0) const override
 
void init (const ReporterMode &mode)
 
const MooseObjectgetProducer () const
 
const ReporterProducerEnumgetProducerModeEnum () const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Protected Member Functions

void broadcast ()
 
virtual void store (nlohmann::json &json) const override
 
virtual bool restoreState () override
 
void requiresConsumerModes (const ReporterStateBase &state, const std::set< ReporterMode > &modes) const
 

Protected Attributes

const Sampler_sampler
 
bool _has_gathered
 
bool _has_allgathered
 
ReporterState< std::vector< T > > & _state
 
const MooseObject_producer
 
ReporterProducerEnum _producer_enum
 
const Parallel::Communicator & _communicator
 

Detailed Description

template<typename T>
class StochasticReporterContext< T >

Definition at line 18 of file StochasticReporter.h.

Constructor & Destructor Documentation

◆ StochasticReporterContext()

template<typename T >
StochasticReporterContext< T >::StochasticReporterContext ( const libMesh::ParallelObject other,
const MooseObject producer,
ReporterState< std::vector< T >> &  state,
const Sampler sampler 
)

Definition at line 38 of file StochasticReporter.h.

42  : ReporterGeneralContext<std::vector<T>>(other, producer, state),
43  _sampler(sampler),
44  _has_gathered(false),
45  _has_allgathered(false)
46 {
47  this->_state.value().resize(_sampler.getNumberOfLocalRows());
48 }
const ReporterState< std::vector< T > > & state() const
ReporterState< std::vector< T > > & _state
dof_id_type getNumberOfLocalRows() const
std::vector< T > & value(const std::size_t time_index=0)

Member Function Documentation

◆ contextType()

template<typename T >
virtual std::string StochasticReporterContext< T >::contextType ( ) const
inlineoverridevirtual

Reimplemented from ReporterGeneralContext< std::vector< T > >.

Definition at line 28 of file StochasticReporter.h.

28 { return MooseUtils::prettyCppType(this); }
std::string prettyCppType(const std::string &cpp_type)

◆ copyValuesBack()

template<typename T >
void StochasticReporterContext< T >::copyValuesBack ( )
overridevirtual

Reimplemented from ReporterGeneralContext< std::vector< T > >.

Definition at line 52 of file StochasticReporter.h.

53 {
54  this->_state.copyValuesBack();
55  if (_has_allgathered || (_has_gathered && this->processor_id() == 0))
56  {
57  auto & val = this->_state.value();
58  val.erase(val.begin(), val.begin() + _sampler.getLocalRowBegin());
59  val.erase(val.begin() + _sampler.getLocalRowEnd(), val.end());
60  }
61  _has_gathered = false;
62  _has_allgathered = false;
63 }
ReporterState< std::vector< T > > & _state
dof_id_type getLocalRowBegin() const
dof_id_type getLocalRowEnd() const
std::vector< T > & value(const std::size_t time_index=0)
processor_id_type processor_id() const

◆ finalize()

template<typename T >
void StochasticReporterContext< T >::finalize ( )
overridevirtual

Reimplemented from ReporterGeneralContext< std::vector< T > >.

Definition at line 67 of file StochasticReporter.h.

68 {
69  bool gather_required = this->_producer_enum == REPORTER_MODE_ROOT;
70  bool allgather_required = this->_producer_enum == REPORTER_MODE_REPLICATED;
71  for (const auto & pair : this->_state.getConsumers())
72  {
73  const ReporterMode consumer = pair.first;
74  if (consumer == REPORTER_MODE_ROOT)
75  gather_required = true;
76  else if (consumer == REPORTER_MODE_REPLICATED)
77  allgather_required = true;
78  }
79 
80  if (allgather_required && !_has_allgathered)
82  else if (gather_required && !_has_gathered)
84 
85  _has_gathered = gather_required || _has_gathered;
86  _has_allgathered = allgather_required || _has_allgathered;
87 }
const std::set< std::pair< ReporterMode, const MooseObject *> > & getConsumers() const
const ReporterMode REPORTER_MODE_ROOT
ReporterState< std::vector< T > > & _state
const Parallel::Communicator & comm() const
void stochasticGather(const libMesh::Parallel::Communicator &, processor_id_type, T &)
std::vector< T > & value(const std::size_t time_index=0)
const ReporterMode REPORTER_MODE_REPLICATED
void stochasticAllGather(const libMesh::Parallel::Communicator &, T &)

◆ storeInfo()

template<typename T >
void StochasticReporterContext< T >::storeInfo ( nlohmann::json &  json) const
overridevirtual

Reimplemented from ReporterGeneralContext< std::vector< T > >.

Definition at line 91 of file StochasticReporter.h.

92 {
94  if (_has_allgathered || (_has_gathered && this->processor_id() == 0))
95  {
96  json["row_begin"] = 0;
97  json["row_end"] = this->_sampler.getNumberOfRows();
98  }
99  else
100  {
101  json["row_begin"] = this->_sampler.getLocalRowBegin();
102  json["row_end"] = this->_sampler.getLocalRowEnd();
103  }
104 }
dof_id_type getLocalRowBegin() const
virtual void storeInfo(nlohmann::json &json) const override
dof_id_type getLocalRowEnd() const
dof_id_type getNumberOfRows() const
processor_id_type processor_id() const

Member Data Documentation

◆ _has_allgathered

template<typename T >
bool StochasticReporterContext< T >::_has_allgathered
protected

Definition at line 34 of file StochasticReporter.h.

◆ _has_gathered

template<typename T >
bool StochasticReporterContext< T >::_has_gathered
protected

Definition at line 33 of file StochasticReporter.h.

◆ _sampler

template<typename T >
const Sampler& StochasticReporterContext< T >::_sampler
protected

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