Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
VectorPostprocessorContext< T > Class Template Reference

#include <VectorPostprocessor.h>

Inheritance diagram for VectorPostprocessorContext< T >:
[legend]

Public Types

enum  AutoOperation { AutoOperation::NONE, AutoOperation::BROADCAST }
 Options for automatic parallel operations to perform by the default context. More...
 

Public Member Functions

 VectorPostprocessorContext (const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state)
 
virtual void finalize () override
 Perform automatic parallel communication based on the producer/consumer modes. More...
 
virtual void copyValuesBack () override
 Called by FEProblemBase::advanceState via ReporterData. More...
 
const ScatterVectorPostprocessorValuegetScatterValue () const
 
const ScatterVectorPostprocessorValuegetScatterValueOld () const
 
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. More...
 
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. More...
 
virtual void resize (dof_id_type local_size) final
 Helper for resizing vector data. More...
 
virtual void clear () final
 Helper for clearing vector data. More...
 
virtual void vectorSum () final
 Helper for summing reporter value. More...
 
virtual std::string contextType () const override
 
const ReporterNamename () const override final
 Return the name of the Reporter value. More...
 
const ReporterState< T > & state () const
 Return a reference to the ReporterState object that is storing the Reporter value. More...
 
virtual std::string type () const override
 Return the type being stored by the associated ReporterState object. More...
 
virtual void transfer (ReporterData &r_data, const ReporterName &r_name, unsigned int time_index=0) const override
 Perform type specific transfer. More...
 
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. More...
 
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. 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...
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Protected Member Functions

void broadcast ()
 
virtual void storeInfo (nlohmann::json &json) const override
 Output meta data to JSON, see JSONOutput. More...
 
virtual void store (nlohmann::json &json) const override
 Output data to JSON, see JSONOutput. More...
 
virtual bool restoreState () override
 Restore state to its old values. More...
 
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

ReporterState< T > & _state
 The state on which this context object operates. More...
 
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
 

Private Attributes

ScatterVectorPostprocessorValue _scatter_value
 
ScatterVectorPostprocessorValue _scatter_value_old
 

Detailed Description

template<typename T>
class VectorPostprocessorContext< T >

Definition at line 110 of file VectorPostprocessor.h.

Member Enumeration Documentation

◆ AutoOperation

template<typename T>
enum ReporterContext::AutoOperation
stronginherited

Options for automatic parallel operations to perform by the default context.

Enumerator
NONE 
BROADCAST 

Definition at line 234 of file ReporterContext.h.

235  {
236  NONE,
237  BROADCAST
238  };

Constructor & Destructor Documentation

◆ VectorPostprocessorContext()

template<typename T >
VectorPostprocessorContext< T >::VectorPostprocessorContext ( const libMesh::ParallelObject other,
const MooseObject producer,
ReporterState< T > &  state 
)

Definition at line 97 of file VectorPostprocessor.C.

100  : ReporterGeneralContext<T>(other, producer, state)
101 {
102 }
const ReporterState< T > & state() const
Return a reference to the ReporterState object that is storing the Reporter value.

Member Function Documentation

◆ broadcast()

template<typename T>
void ReporterContext< T >::broadcast ( )
inlineprotectedinherited

Definition at line 303 of file ReporterContext.h.

304  {
306  this->comm().broadcast(this->_state.value());
307  else
308  mooseError("Cannot broadcast Reporter type '", MooseUtils::prettyCppType<T>(), "'");
309  }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
ReporterState< T > & _state
The state on which this context object operates.
const Parallel::Communicator & comm() const
Custom type trait that has a value of true for types that can be broadcasted.
Definition: MooseUtils.h:991
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const

◆ clear()

template<typename T >
void ReporterGeneralContext< T >::clear ( )
finalvirtualinherited

Helper for clearing vector data.

Implements ReporterContextBase.

Definition at line 498 of file ReporterContext.h.

499 {
500  if constexpr (is_std_vector<T>::value)
501  this->_state.value().clear();
502  else
503  mooseError("Cannot clear non vector-type reporter values.");
504 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
ReporterState< T > & _state
The state on which this context object operates.

◆ contextType()

template<typename T>
virtual std::string ReporterGeneralContext< T >::contextType ( ) const
inlineoverridevirtualinherited
Returns
The derived context type for this context.

This must be overridden in every class.

Implements ReporterContext< T >.

Reimplemented in ReporterGatherContext< T >, ReporterScatterContext< T >, and ReporterBroadcastContext< T >.

Definition at line 470 of file ReporterContext.h.

470 { return MooseUtils::prettyCppType(this); }
std::string prettyCppType(const std::string &cpp_type)
Definition: MooseUtils.C:1246

◆ copyValuesBack()

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

Called by FEProblemBase::advanceState via ReporterData.

Reimplemented from ReporterContext< T >.

Definition at line 129 of file VectorPostprocessor.C.

130 {
133 }
ScatterVectorPostprocessorValue _scatter_value_old
virtual void copyValuesBack() override
Called by FEProblemBase::advanceState via ReporterData.
ScatterVectorPostprocessorValue _scatter_value

◆ declareClone()

template<typename T >
void ReporterGeneralContext< T >::declareClone ( ReporterData r_data,
const ReporterName r_name,
const ReporterMode mode,
const MooseObject producer 
) const
overridevirtualinherited

Declare a reporter value of same type as this context.

NOTE: This is defined in ReporterData.h to avoid cyclic includes that would arise. I don't know of a better solution, if you have one please implement it.

Implements ReporterContextBase.

Definition at line 559 of file ReporterData.h.

563 {
564  r_data.declareReporterValue<T, ReporterGeneralContext<T>>(r_name, mode, producer);
565 }
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.
Definition: ReporterData.h:400

◆ declareVectorClone()

template<typename T >
void ReporterGeneralContext< T >::declareVectorClone ( ReporterData r_data,
const ReporterName r_name,
const ReporterMode mode,
const MooseObject producer 
) const
overridevirtualinherited

Declare a reporter value that is a vector of the same type as this context.

NOTE: This is defined in ReporterData.h to avoid cyclic includes that would arise. I don't know of a better solution, if you have one please implement it.

Implements ReporterContextBase.

Definition at line 570 of file ReporterData.h.

574 {
575  r_data.declareReporterValue<std::vector<T>, ReporterVectorContext<T>>(r_name, mode, producer);
576 }
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.
Definition: ReporterData.h:400
This context is specific for vector types of reporters, mainly for declaring a vector of the type fro...

◆ finalize()

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

Perform automatic parallel communication based on the producer/consumer modes.

Reimplemented from ReporterContext< T >.

Definition at line 106 of file VectorPostprocessor.C.

107 {
109 
110  const auto & consumer_modes = this->state().getConsumers();
111  auto func = [](const std::pair<ReporterMode, const MooseObject *> & mode_pair)
112  { return mode_pair.first == REPORTER_MODE_VPP_SCATTER; };
113  if (std::find_if(consumer_modes.begin(), consumer_modes.end(), func) != consumer_modes.end())
114  {
115  const T & value = this->state().value();
116  if (this->processor_id() == 0 && value.size() != this->n_processors())
117  mooseError("The VectorPostprocessor value to be scatter has a length of ",
118  value.size(),
119  "; it must be the same length as the number of processors (",
120  this->n_processors(),
121  ").");
122 
123  this->comm().scatter(value, _scatter_value);
124  }
125 }
virtual void finalize() override
Perform automatic parallel communication based on the producer/consumer modes.
void scatter(const std::vector< T, A > &data, T &recv, const unsigned int root_id=0) const
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
const ReporterState< T > & state() const
Return a reference to the ReporterState object that is storing the Reporter value.
const Parallel::Communicator & comm() const
processor_id_type n_processors() const
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
ScatterVectorPostprocessorValue _scatter_value
const ReporterMode REPORTER_MODE_VPP_SCATTER("VPP_SCATTER")
processor_id_type processor_id() const

◆ getProducer()

const MooseObject& ReporterContextBase::getProducer ( ) const
inlineinherited

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
inherited

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.

◆ getScatterValue()

template<typename T >
const ScatterVectorPostprocessorValue & VectorPostprocessorContext< T >::getScatterValue ( ) const

Definition at line 137 of file VectorPostprocessor.C.

138 {
139  return _scatter_value;
140 }
ScatterVectorPostprocessorValue _scatter_value

◆ getScatterValueOld()

template<typename T >
const ScatterVectorPostprocessorValue & VectorPostprocessorContext< T >::getScatterValueOld ( ) const

Definition at line 144 of file VectorPostprocessor.C.

145 {
146  return _scatter_value_old;
147 }
ScatterVectorPostprocessorValue _scatter_value_old

◆ init()

void ReporterContextBase::init ( const ReporterMode mode)
inherited

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()

template<typename T>
const ReporterName& ReporterContext< T >::name ( ) const
inlinefinaloverridevirtualinherited

Return the name of the Reporter value.

Implements ReporterContextBase.

Definition at line 251 of file ReporterContext.h.

251 { return _state.getReporterName(); }
ReporterState< T > & _state
The state on which this context object operates.

◆ requiresConsumerModes()

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

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()

template<typename T >
void ReporterGeneralContext< T >::resize ( dof_id_type  local_size)
finalvirtualinherited

Helper for resizing vector data.

Parameters
local_sizeNumber of elements to resize vector to

Implements ReporterContextBase.

Definition at line 486 of file ReporterContext.h.

487 {
488  if constexpr (is_std_vector<T>::value)
489  this->_state.value().resize(size);
490  else
491  {
492  libmesh_ignore(size);
493  mooseError("Cannot resize non vector-type reporter values.");
494  }
495 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
ReporterState< T > & _state
The state on which this context object operates.
void libmesh_ignore(const Args &...)

◆ restoreState()

template<typename T>
virtual bool ReporterContext< T >::restoreState ( )
inlineoverrideprotectedvirtualinherited

Restore state to its old values.

See also
ReporterState::restoreState

Implements ReporterContextBase.

Definition at line 323 of file ReporterContext.h.

323 { return _state.restoreState(); }
ReporterState< T > & _state
The state on which this context object operates.

◆ state()

template<typename T>
const ReporterState<T>& ReporterContext< T >::state ( ) const
inlineinherited

Return a reference to the ReporterState object that is storing the Reporter value.

Definition at line 256 of file ReporterContext.h.

256 { return _state; }
ReporterState< T > & _state
The state on which this context object operates.

◆ store()

template<typename T >
void ReporterContext< T >::store ( nlohmann::json &  json) const
overrideprotectedvirtualinherited

Output data to JSON, see JSONOutput.

Implements ReporterContextBase.

Definition at line 422 of file ReporterContext.h.

423 {
424  nlohmann::to_json(json, this->_state.value());
425 }
ReporterState< T > & _state
The state on which this context object operates.
void to_json(nlohmann::json &json, const Moose::LibtorchArtificialNeuralNet *const &network)

◆ storeInfo()

template<typename T >
void ReporterContext< T >::storeInfo ( nlohmann::json &  json) const
overrideprotectedvirtualinherited

Output meta data to JSON, see JSONOutput.

Implements ReporterContextBase.

Definition at line 415 of file ReporterContext.h.

416 {
417  json["type"] = this->type();
418 }
virtual std::string type() const override
Return the type being stored by the associated ReporterState object.

◆ transfer()

template<typename T >
void ReporterContext< T >::transfer ( ReporterData r_data,
const ReporterName r_name,
unsigned int  time_index = 0 
) const
overridevirtualinherited

Perform type specific transfer.

NOTE: This is defined in ReporterData.h to avoid cyclic includes that would arise. I don't know of a better solution, if you have one please implement it.

Implements ReporterContextBase.

Definition at line 502 of file ReporterData.h.

505 {
506  r_data.setReporterValue<T>(r_name, _state.value(), time_index);
507 }
ReporterState< T > & _state
The state on which this context object operates.
void setReporterValue(const ReporterName &reporter_name, const T &value, const std::size_t time_index=0)
Method for setting Reporter values that already exist.
Definition: ReporterData.h:481

◆ transferFromVector()

template<typename T >
void ReporterContext< T >::transferFromVector ( ReporterData r_data,
const ReporterName r_name,
dof_id_type  index,
unsigned int  time_index = 0 
) const
overridevirtualinherited

Perform type specific transfer from a vector.

NOTE: This is defined in ReporterData.h to avoid cyclic includes that would arise. I don't know of a better solution, if you have one please implement it.

Implements ReporterContextBase.

Definition at line 529 of file ReporterData.h.

533 {
534  if constexpr (is_std_vector<T>::value)
535  {
536  if (index >= _state.value().size())
537  mooseError("Requested index ",
538  index,
539  " is outside the bounds of the vector reporter value ",
540  r_name);
541 
542  using R = typename T::value_type;
543  r_data.setReporterValue<R>(r_name, _state.value()[index], time_index);
544  }
545  else
546  {
547  libmesh_ignore(r_data);
548  libmesh_ignore(r_name);
549  libmesh_ignore(index);
550  libmesh_ignore(time_index);
551  mooseError("transferFromVector can only be used for reporter types that are specializatons of "
552  "std::vector.");
553  }
554 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
ReporterState< T > & _state
The state on which this context object operates.
void libmesh_ignore(const Args &...)
void setReporterValue(const ReporterName &reporter_name, const T &value, const std::size_t time_index=0)
Method for setting Reporter values that already exist.
Definition: ReporterData.h:481

◆ transferToVector()

template<typename T >
void ReporterContext< T >::transferToVector ( ReporterData r_data,
const ReporterName r_name,
dof_id_type  index,
unsigned int  time_index = 0 
) const
overridevirtualinherited

Perform type specific transfer to a vector.

NOTE: This is defined in ReporterData.h to avoid cyclic includes that would arise. I don't know of a better solution, if you have one please implement it.

Implements ReporterContextBase.

Definition at line 512 of file ReporterData.h.

516 {
517  std::vector<T> & vec =
518  const_cast<std::vector<T> &>(r_data.getReporterValue<std::vector<T>>(r_name, time_index));
519 
520  if (index >= vec.size())
521  mooseError(
522  "Requested index ", index, " is outside the bounds of the vector reporter value ", r_name);
523  vec[index] = _state.value();
524 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
ReporterState< T > & _state
The state on which this context object operates.
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.
Definition: ReporterData.h:388

◆ type()

template<typename T>
virtual std::string ReporterContext< T >::type ( ) const
inlineoverridevirtualinherited

Return the type being stored by the associated ReporterState object.

See also
ReporterContext::storeInfo

Implements ReporterContextBase.

Definition at line 263 of file ReporterContext.h.

263 { return MooseUtils::prettyCppType<T>(); }

◆ vectorSum()

template<typename T >
void ReporterGeneralContext< T >::vectorSum ( )
finalvirtualinherited

Helper for summing reporter value.

Implements ReporterContextBase.

Definition at line 508 of file ReporterContext.h.

509 {
510  // Case 1: T is a numeric type that we can sum (excluding bool)
511  if constexpr (std::is_arithmetic<T>::value && !std::is_same<T, bool>::value)
512  {
513  // Perform summation of the scalar value across all processors
514  this->comm().sum(this->_state.value());
515  return;
516  }
517  // Case 2: T is a vector type
518  else if constexpr (is_std_vector<T>::value)
519  {
520  using VectorValueType = typename T::value_type;
521 
522  // Check if the vector elements are of a numeric type
523  if constexpr (std::is_arithmetic<VectorValueType>::value &&
524  !std::is_same<VectorValueType, bool>::value)
525  {
526  // Perform summation of the vector elements across all processors
527  this->comm().sum(this->_state.value());
528  return;
529  }
530  // Check if the vector elements are also vectors
531  else if constexpr (is_std_vector<VectorValueType>::value)
532  {
533  using InnerValueType = typename VectorValueType::value_type;
534 
535  // Check if the inner vector elements are of a numeric type
536  if constexpr (std::is_arithmetic<InnerValueType>::value &&
537  !std::is_same<InnerValueType, bool>::value)
538  {
539 #ifdef DEBUG
540  auto vec_size = this->_state.value().size();
541  this->comm().max(vec_size);
542  // Assert only passes on all ranks if they are all the same size.
543  mooseAssert(this->_state.value().size() == vec_size,
544  "Reporter vector have different sizes on different ranks.");
545 #endif
546  // Iterate over each inner vector in the outer vector
547  for (auto & innerVector : this->_state.value())
548  {
549  // Get the maximum size of the inner vector across all processors
550  dof_id_type maxInnerSize = innerVector.size();
551  this->comm().max(maxInnerSize);
552 
553  // Resize the inner vector to the maximum size
554  innerVector.resize(maxInnerSize);
555 
556  // Perform summation of the inner vector elements across all processors
557  this->comm().sum(innerVector);
558  }
559  return;
560  }
561  }
562  }
563 
564  mooseError("Cannot perform sum operation on non-numeric or unsupported vector types.");
565 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
ReporterState< T > & _state
The state on which this context object operates.
const Parallel::Communicator & comm() const
void max(const T &r, T &o, Request &req) const
uint8_t dof_id_type

Member Data Documentation

◆ _producer

const MooseObject& ReporterContextBase::_producer
protectedinherited

The MooseObject that is producing this Reporter.

Definition at line 214 of file ReporterContext.h.

Referenced by ReporterContextBase::getProducer().

◆ _producer_enum

ReporterProducerEnum ReporterContextBase::_producer_enum
protectedinherited

◆ _scatter_value

template<typename T>
ScatterVectorPostprocessorValue VectorPostprocessorContext< T >::_scatter_value
private

Definition at line 123 of file VectorPostprocessor.h.

◆ _scatter_value_old

template<typename T>
ScatterVectorPostprocessorValue VectorPostprocessorContext< T >::_scatter_value_old
private

Definition at line 124 of file VectorPostprocessor.h.

◆ _state

template<typename T>
ReporterState<T>& ReporterContext< T >::_state
protectedinherited

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