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;
216 const std::set<ReporterMode> & modes)
const;
251 const T & default_value);
268 virtual std::string
type()
const override {
return MooseUtils::prettyCppType<T>(); }
283 unsigned int time_index = 0)
const override;
294 unsigned int time_index = 0)
const override;
305 unsigned int time_index = 0)
const override;
307 virtual void broadcast([[maybe_unused]] processor_id_type root = 0)
override
309 if constexpr (MooseUtils::canBroadcast<T>::value)
312 mooseError(
"Cannot broadcast Reporter type '", MooseUtils::prettyCppType<T>(),
"'");
317 virtual void storeInfo(nlohmann::json & json)
const override;
320 virtual void store(nlohmann::json & json)
const override;
347 const T & default_value)
350 _state.value() = default_value;
361 if (!_producer_enum.isValid())
365 const auto & producer = _producer_enum;
366 for (
const auto & pair : _state.getConsumers())
401 "\" is being produced in ",
405 " is requesting to consume it in ",
407 " mode, which is not supported.");
419 _state.copyValuesBack();
426 json[
"type"] = this->type();
433 nlohmann::to_json(json, this->_state.value());
449 const T & default_value)
475 virtual void resize(dof_id_type local_size)
final;
476 virtual void clear() final;
488template <
typename T,
typename A>
498 this->_state.value().resize(size);
501 libmesh_ignore(size);
502 mooseError(
"Cannot resize non vector-type reporter values.");
510 this->_state.value().clear();
512 mooseError(
"Cannot clear non vector-type reporter values.");
520 if constexpr (std::is_arithmetic<T>::value && !std::is_same<T, bool>::value)
523 this->comm().sum(this->_state.value());
529 using VectorValueType =
typename T::value_type;
532 if constexpr (std::is_arithmetic<VectorValueType>::value &&
533 !std::is_same<VectorValueType, bool>::value)
536 this->comm().sum(this->_state.value());
542 using InnerValueType =
typename VectorValueType::value_type;
545 if constexpr (std::is_arithmetic<InnerValueType>::value &&
546 !std::is_same<InnerValueType, bool>::value)
549 auto vec_size = this->_state.value().size();
550 this->comm().max(vec_size);
552 mooseAssert(this->_state.value().size() == vec_size,
553 "Reporter vector have different sizes on different ranks.");
556 for (
auto & innerVector : this->_state.value())
559 dof_id_type maxInnerSize = innerVector.size();
560 this->comm().max(maxInnerSize);
563 innerVector.resize(maxInnerSize);
566 this->comm().sum(innerVector);
573 mooseError(
"Cannot perform sum operation on non-numeric or unsupported vector types.");
589 const T & default_value);
608 const T & default_value)
633 const std::vector<T> &
values);
637 const T & default_value,
638 const std::vector<T> &
values);
652 const std::vector<T> &
values)
663 const T & default_value,
664 const std::vector<T> &
values)
677 mooseAssert(this->processor_id() == 0 ? _values.size() == this->n_processors() :
true,
678 "Vector to be scattered must be sized to match the number of processors");
680 this->processor_id() > 0 ? _values.size() == 0 :
true,
681 "Vector to be scattered must be sized to zero on processors except for the root processor");
682 this->comm().scatter(_values, this->_state.value());
698 const T & default_value);
718 const T & default_value)
730 this->comm().gather(0, this->_state.value());
749 const std::vector<T> & default_value);
773 virtual void resize(dof_id_type local_size)
override { this->
_state.
value().resize(local_size); }
783 if constexpr (std::is_arithmetic<T>::value &&
784 !std::is_same<T, bool>::value)
787 dof_id_type vec_size = this->
_state.
value().size();
798 dof_id_type vec_size = this->
_state.
value().size();
802 using ValueType =
typename T::value_type;
804 if constexpr (std::is_arithmetic<ValueType>::value && !std::is_same<ValueType, bool>::value)
810 mooseAssert(this->
_state.
value().size() == vec_size,
811 "Reporter vector have different sizes on different ranks.");
816 dof_id_type val_vec_size = val_vec.size();
817 this->
comm().
max(val_vec_size);
818 val_vec.resize(val_vec_size);
826 mooseError(
"Cannot perform sum operation on non-numeric or unsupported vector types.");
844 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 broadcast(processor_id_type root)=0
Helper for broadcasting reporter value from processor root.
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 broadcast(processor_id_type root=0) override
Helper for broadcasting reporter value from processor root.
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)