https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 class  AutoOperation { NONE , 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.
 
virtual void copyValuesBack () override
 Called by FEProblemBase::advanceState via ReporterData.
 
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.
 
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.
 
virtual void resize (dof_id_type local_size) final
 Helper for resizing vector data.
 
virtual void clear () final
 Helper for clearing vector data.
 
virtual void vectorSum () final
 Helper for summing reporter value.
 
virtual std::string contextType () const override
 
const ReporterNamename () const override final
 Return the name of the Reporter value.
 
const ReporterState< T > & state () const
 Return a reference to the ReporterState object that is storing the Reporter value.
 
virtual std::string type () const override
 Return the type being stored by the associated ReporterState object.
 
virtual void transfer (ReporterData &r_data, const ReporterName &r_name, unsigned int time_index=0) const override
 Perform type specific transfer.
 
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.
 
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.
 
void init (const ReporterMode &mode)
 Initialize the producer mode.
 
const MooseObjectgetProducer () const
 Return the MooseObject that produces this Reporter.
 
const ReporterProducerEnumgetProducerModeEnum () const
 Return the Reporter value produced mode.
 
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.
 
virtual void store (nlohmann::json &json) const override
 Output data to JSON, see JSONOutput.
 
virtual bool restoreState () override
 Restore state to its old values.
 
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.
 

Protected Attributes

ReporterState< T > & _state
 The state on which this context object operates.
 
const MooseObject_producer
 The MooseObject that is producing this Reporter.
 
ReporterProducerEnum _producer_enum
 Defines how the Reporter value can be produced and how it is being produced.
 
const Parallel::Communicator_communicator
 

Private Attributes

ScatterVectorPostprocessorValue _scatter_value
 
ScatterVectorPostprocessorValue _scatter_value_old
 

Detailed Description

template<typename T>
class VectorPostprocessorContext< T >

Definition at line 118 of file VectorPostprocessor.h.

Member Enumeration Documentation

◆ AutoOperation

template<typename T >
enum class 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.

Constructor & Destructor Documentation

◆ VectorPostprocessorContext()

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

Definition at line 115 of file VectorPostprocessor.C.

118 : ReporterGeneralContext<T>(other, producer, state)
119{
120}
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 {
305 if constexpr (MooseUtils::canBroadcast<T>::value)
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:311
ReporterState< T > & _state
The state on which this context object operates.
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
const Parallel::Communicator & comm() const

◆ clear()

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

Helper for clearing vector data.

Implements ReporterContextBase.

Definition at line 502 of file ReporterContext.h.

503{
504 if constexpr (is_std_vector<T>::value)
505 this->_state.value().clear();
506 else
507 mooseError("Cannot clear non vector-type reporter values.");
508}

◆ 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 ReporterBroadcastContext< T >, ReporterScatterContext< T >, and ReporterGatherContext< T >.

Definition at line 474 of file ReporterContext.h.

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

◆ copyValuesBack()

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

Called by FEProblemBase::advanceState via ReporterData.

Reimplemented from ReporterContext< T >.

Definition at line 147 of file VectorPostprocessor.C.

148{
151}
virtual void copyValuesBack()=0
Called by FEProblemBase::advanceState via ReporterData.
ScatterVectorPostprocessorValue _scatter_value_old
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 572 of file ReporterData.h.

576{
577 r_data.declareReporterValue<T, ReporterGeneralContext<T>>(r_name, mode, producer);
578}
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.

◆ 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 583 of file ReporterData.h.

587{
588 r_data.declareReporterValue<std::vector<T>, ReporterVectorContext<T>>(r_name, mode, producer);
589}
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 124 of file VectorPostprocessor.C.

125{
127
128 const auto & consumer_modes = this->state().getConsumers();
129 auto func = [](const std::pair<ReporterMode, const MooseObject *> & mode_pair)
130 { return mode_pair.first == REPORTER_MODE_VPP_SCATTER; };
131 if (std::find_if(consumer_modes.begin(), consumer_modes.end(), func) != consumer_modes.end())
132 {
133 const T & value = this->state().value();
134 if (this->processor_id() == 0 && value.size() != this->n_processors())
135 mooseError("The VectorPostprocessor value to be scatter has a length of ",
136 value.size(),
137 "; it must be the same length as the number of processors (",
138 this->n_processors(),
139 ").");
140
141 this->comm().scatter(value, _scatter_value);
142 }
143}
const ReporterMode REPORTER_MODE_VPP_SCATTER
virtual void finalize()=0
Called by FEProblemBase::joinAndFinalize via ReporterData.
void scatter(const std::vector< T, A > &data, T &recv, const unsigned int root_id=0) const
processor_id_type processor_id() const
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ getProducer()

const MooseObject & ReporterContextBase::getProducer ( ) const
inlineinherited

Return the MooseObject that produces this Reporter.

Definition at line 118 of file ReporterContext.h.

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

Referenced by ReporterData::getReporterInfo().

◆ getProducerModeEnum()

const ReporterProducerEnum & ReporterContextBase::getProducerModeEnum ( ) const
inherited

Return the Reporter value produced mode.

Definition at line 28 of file ReporterContext.C.

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

Referenced by ReporterData::getReporterMode().

◆ getScatterValue()

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

Definition at line 155 of file VectorPostprocessor.C.

156{
157 return _scatter_value;
158}

◆ getScatterValueOld()

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

Definition at line 162 of file VectorPostprocessor.C.

163{
164 return _scatter_value_old;
165}

◆ 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)
25}
const ReporterMode REPORTER_MODE_UNSET
void assign(const std::string &name, const std::optional< std::string > &context={})
Definition MooseEnum.C:60

◆ 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(); }

◆ 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",
55 }
56}
unsigned int count
Definition MortarUtils.C:53
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
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.

◆ 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 490 of file ReporterContext.h.

491{
492 if constexpr (is_std_vector<T>::value)
493 this->_state.value().resize(size);
494 else
495 {
496 libmesh_ignore(size);
497 mooseError("Cannot resize non vector-type reporter values.");
498 }
499}
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(); }

◆ 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; }

◆ store()

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

Output data to JSON, see JSONOutput.

Implements ReporterContextBase.

Definition at line 426 of file ReporterContext.h.

427{
428 nlohmann::to_json(json, this->_state.value());
429}

◆ 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 419 of file ReporterContext.h.

420{
421 json["type"] = this->type();
422}
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 515 of file ReporterData.h.

518{
519 r_data.setReporterValue<T>(r_name, _state.value(), time_index);
520}
void setReporterValue(const ReporterName &reporter_name, const T &value, const std::size_t time_index=0)
Method for setting Reporter values that already exist.

◆ 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 542 of file ReporterData.h.

546{
547 if constexpr (is_std_vector<T>::value)
548 {
549 if (index >= _state.value().size())
550 mooseError("Requested index ",
551 index,
552 " is outside the bounds of the vector reporter value ",
553 r_name);
554
555 using R = typename T::value_type;
556 r_data.setReporterValue<R>(r_name, _state.value()[index], time_index);
557 }
558 else
559 {
560 libmesh_ignore(r_data);
561 libmesh_ignore(r_name);
562 libmesh_ignore(index);
563 libmesh_ignore(time_index);
564 mooseError("transferFromVector can only be used for reporter types that are specializatons of "
565 "std::vector.");
566 }
567}

◆ 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 525 of file ReporterData.h.

529{
530 std::vector<T> & vec =
531 const_cast<std::vector<T> &>(r_data.getReporterValue<std::vector<T>>(r_name, time_index));
532
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();
537}
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.

◆ 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 512 of file ReporterContext.h.

513{
514 // Case 1: T is a numeric type that we can sum (excluding bool)
515 if constexpr (std::is_arithmetic<T>::value && !std::is_same<T, bool>::value)
516 {
517 // Perform summation of the scalar value across all processors
518 this->comm().sum(this->_state.value());
519 return;
520 }
521 // Case 2: T is a vector type
522 else if constexpr (is_std_vector<T>::value)
523 {
524 using VectorValueType = typename T::value_type;
525
526 // Check if the vector elements are of a numeric type
527 if constexpr (std::is_arithmetic<VectorValueType>::value &&
528 !std::is_same<VectorValueType, bool>::value)
529 {
530 // Perform summation of the vector elements across all processors
531 this->comm().sum(this->_state.value());
532 return;
533 }
534 // Check if the vector elements are also vectors
535 else if constexpr (is_std_vector<VectorValueType>::value)
536 {
537 using InnerValueType = typename VectorValueType::value_type;
538
539 // Check if the inner vector elements are of a numeric type
540 if constexpr (std::is_arithmetic<InnerValueType>::value &&
541 !std::is_same<InnerValueType, bool>::value)
542 {
543#ifdef DEBUG
544 auto vec_size = this->_state.value().size();
545 this->comm().max(vec_size);
546 // Assert only passes on all ranks if they are all the same size.
547 mooseAssert(this->_state.value().size() == vec_size,
548 "Reporter vector have different sizes on different ranks.");
549#endif
550 // Iterate over each inner vector in the outer vector
551 for (auto & innerVector : this->_state.value())
552 {
553 // Get the maximum size of the inner vector across all processors
554 dof_id_type maxInnerSize = innerVector.size();
555 this->comm().max(maxInnerSize);
556
557 // Resize the inner vector to the maximum size
558 innerVector.resize(maxInnerSize);
559
560 // Perform summation of the inner vector elements across all processors
561 this->comm().sum(innerVector);
562 }
563 return;
564 }
565 }
566 }
567
568 mooseError("Cannot perform sum operation on non-numeric or unsupported vector types.");
569}
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 131 of file VectorPostprocessor.h.

◆ _scatter_value_old

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

Definition at line 132 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: