15#include "libmesh/id_types.h"
16#include "libmesh/parallel.h"
17#include "libmesh/parallel_object.h"
68 virtual std::string
type()
const = 0;
85 virtual void storeInfo(nlohmann::json & json)
const = 0;
100 virtual void store(nlohmann::json & json)
const = 0;
134 unsigned int time_index = 0)
const = 0;
146 unsigned int time_index = 0)
const = 0;
159 unsigned int time_index = 0)
const = 0;
194 virtual void resize(dof_id_type local_size) = 0;
211 const std::set<ReporterMode> & modes)
const;
246 const T & default_value);
263 virtual std::string
type()
const override {
return MooseUtils::prettyCppType<T>(); }
278 unsigned int time_index = 0)
const override;
289 unsigned int time_index = 0)
const override;
300 unsigned int time_index = 0)
const override;
305 if constexpr (MooseUtils::canBroadcast<T>::value)
308 mooseError(
"Cannot broadcast Reporter type '", MooseUtils::prettyCppType<T>(),
"'");
312 virtual void storeInfo(nlohmann::json & json)
const override;
315 virtual void store(nlohmann::json & json)
const override;
342 const T & default_value)
345 _state.value() = default_value;
356 if (!_producer_enum.isValid())
360 const auto & producer = _producer_enum;
361 for (
const auto & pair : _state.getConsumers())
396 "\" is being produced in ",
400 " is requesting to consume it in ",
402 " mode, which is not supported.");
414 _state.copyValuesBack();
421 json[
"type"] = this->type();
428 nlohmann::to_json(json, this->_state.value());
444 const T & default_value)
470 virtual void resize(dof_id_type local_size)
final;
471 virtual void clear() final;
483template <
typename T,
typename A>
493 this->_state.value().resize(size);
496 libmesh_ignore(size);
497 mooseError(
"Cannot resize non vector-type reporter values.");
505 this->_state.value().clear();
507 mooseError(
"Cannot clear non vector-type reporter values.");
515 if constexpr (std::is_arithmetic<T>::value && !std::is_same<T, bool>::value)
518 this->comm().sum(this->_state.value());
524 using VectorValueType =
typename T::value_type;
527 if constexpr (std::is_arithmetic<VectorValueType>::value &&
528 !std::is_same<VectorValueType, bool>::value)
531 this->comm().sum(this->_state.value());
537 using InnerValueType =
typename VectorValueType::value_type;
540 if constexpr (std::is_arithmetic<InnerValueType>::value &&
541 !std::is_same<InnerValueType, bool>::value)
544 auto vec_size = this->_state.value().size();
545 this->comm().max(vec_size);
547 mooseAssert(this->_state.value().size() == vec_size,
548 "Reporter vector have different sizes on different ranks.");
551 for (
auto & innerVector : this->_state.value())
554 dof_id_type maxInnerSize = innerVector.size();
555 this->comm().max(maxInnerSize);
558 innerVector.resize(maxInnerSize);
561 this->comm().sum(innerVector);
568 mooseError(
"Cannot perform sum operation on non-numeric or unsupported vector types.");
584 const T & default_value);
603 const T & default_value)
628 const std::vector<T> &
values);
632 const T & default_value,
633 const std::vector<T> &
values);
647 const std::vector<T> &
values)
658 const T & default_value,
659 const std::vector<T> &
values)
672 mooseAssert(this->processor_id() == 0 ? _values.size() == this->n_processors() :
true,
673 "Vector to be scattered must be sized to match the number of processors");
675 this->processor_id() > 0 ? _values.size() == 0 :
true,
676 "Vector to be scattered must be sized to zero on processors except for the root processor");
677 this->comm().scatter(_values, this->_state.value());
693 const T & default_value);
713 const T & default_value)
725 this->comm().gather(0, this->_state.value());
744 const std::vector<T> & default_value);
768 virtual void resize(dof_id_type local_size)
override { this->
_state.
value().resize(local_size); }
778 if constexpr (std::is_arithmetic<T>::value &&
779 !std::is_same<T, bool>::value)
782 dof_id_type vec_size = this->
_state.
value().size();
793 dof_id_type vec_size = this->
_state.
value().size();
797 using ValueType =
typename T::value_type;
799 if constexpr (std::is_arithmetic<ValueType>::value && !std::is_same<ValueType, bool>::value)
805 mooseAssert(this->
_state.
value().size() == vec_size,
806 "Reporter vector have different sizes on different ranks.");
811 dof_id_type val_vec_size = val_vec.size();
812 this->
comm().
max(val_vec_size);
813 val_vec.resize(val_vec_size);
821 mooseError(
"Cannot perform sum operation on non-numeric or unsupported vector types.");
839 const std::vector<T> & default_value)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
std::array< Real, 2 > values
const ReporterMode REPORTER_MODE_REPLICATED
const ReporterMode REPORTER_MODE_DISTRIBUTED
const ReporterMode REPORTER_MODE_UNSET
const ReporterMode REPORTER_MODE_ROOT
std::string typeAndName() const
Get the class's combined type and name; useful in error handling.
Every object that can be built by the factory should be derived from this class.
A context that broadcasts the Reporter value from the root processor.
virtual std::string contextType() const override
ReporterBroadcastContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state)
virtual void finalize() override
Perform automatic parallel communication based on the producer/consumer modes.
This is a helper class to aid with parallel communication of compute Reporter values as well as provi...
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.
virtual const ReporterName & name() const =0
Return the ReporterName that the context is associated.
virtual void resize(dof_id_type local_size)=0
Helper for resizing vector data.
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.
virtual bool restoreState()=0
Called by FEProblemBase::restoreSolutions via ReporterData.
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.
virtual void clear()=0
Helper for clearing vector data.
ReporterProducerEnum _producer_enum
Defines how the Reporter value can be produced and how it is being produced.
const MooseObject & getProducer() const
Return the MooseObject that produces this Reporter.
virtual void storeInfo(nlohmann::json &json) const =0
Called by JSONOutput::outputReporters to output meta data independent of calculated values.
virtual std::string contextType() const =0
const ReporterProducerEnum & getProducerModeEnum() const
Return the Reporter value produced mode.
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.
const MooseObject & _producer
The MooseObject that is producing this Reporter.
virtual ~ReporterContextBase()=default
virtual void store(nlohmann::json &json) const =0
Called by JSONOutput::outputReporters to invoke storage of values for output.
virtual std::string type() const =0
Return the type of the data stored.
virtual void copyValuesBack()=0
Called by FEProblemBase::advanceState via ReporterData.
virtual void finalize()=0
Called by FEProblemBase::joinAndFinalize via ReporterData.
virtual void vectorSum()=0
Helper for summing reporter value.
void init(const ReporterMode &mode)
Initialize the producer mode.
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.
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.
General context that is called by all Reporter values to manage the old values.
ReporterContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state)
virtual void storeInfo(nlohmann::json &json) const override
Output meta data to JSON, see JSONOutput.
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.
ReporterContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state, const T &default_value)
virtual void transfer(ReporterData &r_data, const ReporterName &r_name, unsigned int time_index=0) const override
Perform type specific transfer.
AutoOperation
Options for automatic parallel operations to perform by the default context.
virtual void copyValuesBack() override
Called by FEProblemBase::advanceState via ReporterData.
virtual std::string type() const override
Return the type being stored by the associated ReporterState object.
virtual void store(nlohmann::json &json) const override
Output data to JSON, see JSONOutput.
const ReporterName & name() const override final
Return the name of the Reporter value.
virtual bool restoreState() override
Restore state to its old values.
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.
virtual void finalize() override
Perform automatic parallel communication based on the producer/consumer modes.
const ReporterState< T > & state() const
Return a reference to the ReporterState object that is storing the Reporter value.
ReporterState< T > & _state
The state on which this context object operates.
virtual std::string contextType() const override=0
This is a helper class for managing the storage of declared Reporter object values.
A context that gathers the Reporter value to the root processor.
virtual std::string contextType() const override
ReporterGatherContext(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 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 std::string contextType() const override
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.
ReporterGeneralContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state, const T &default_value)
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.
ReporterGeneralContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state)
MooseEnumItem that automatically creates the ID and doesn't allow the ID to be assigned.
The Reporter system is comprised of objects that can contain any number of data values.
MooseEnum designed for the ReporterContext objects to define how a ReporterValue can and is being pro...
void insert(const ReporterMode &mode, Args... modes)
void clear()
Clear all available items (i.e., create an empty MooseEnum)
A context that scatters the Reporter value from the root processor.
virtual void finalize() override
Perform automatic parallel communication based on the producer/consumer modes.
const std::vector< T > & _values
The values to scatter.
ReporterScatterContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state, const std::vector< T > &values)
virtual std::string contextType() const override
The base class for storing a Reporter's state.
A special version of RestartableData to aid in storing Reporter values.
T & value(const std::size_t time_index=0)
Return a reference to the current value or one of the old values.
This context is specific for vector types of reporters, mainly for declaring a vector of the type fro...
virtual std::string contextType() const override
virtual void resize(dof_id_type local_size) override
Since we know that the _state value is a vector type, we can resize it based on.
virtual void vectorSum() override
Helper for summing reporter value.
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.
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.
ReporterVectorContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< std::vector< T > > &state)
virtual void clear() override
Since we know that the _state value is a vector type, we can clear it.
void max(const T &r, T &o, Request &req) const
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
const Parallel::Communicator & comm() const
std::string prettyCppType(const std::string &cpp_type)