15 #include "libmesh/id_types.h" 16 #include "libmesh/parallel.h" 17 #include "libmesh/parallel_object.h" 25 #include <type_traits> 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;
199 virtual void clear() = 0;
211 const std::set<ReporterMode> & modes)
const;
227 template <
typename T>
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;
317 virtual std::string
contextType()
const override = 0;
329 template <
typename T>
338 template <
typename T>
342 const T & default_value)
345 _state.value() = default_value;
348 template <
typename T>
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.");
410 template <
typename T>
414 _state.copyValuesBack();
417 template <
typename T>
421 json[
"type"] = this->type();
424 template <
typename T>
431 template <
typename T>
444 const T & default_value)
471 virtual void clear() final;
483 template <
typename T,
typename A>
488 template <
typename T>
493 this->_state.value().resize(size);
497 mooseError(
"Cannot resize non vector-type reporter values.");
500 template <
typename T>
505 this->_state.value().clear();
507 mooseError(
"Cannot clear non vector-type reporter values.");
510 template <
typename T>
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())
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.");
574 template <
typename T>
584 const T & default_value);
589 template <
typename T>
599 template <
typename T>
603 const T & default_value)
610 template <
typename T>
621 template <
typename T>
628 const std::vector<T> & values);
632 const T & default_value,
633 const std::vector<T> & values);
643 template <
typename T>
647 const std::vector<T> & values)
654 template <
typename T>
658 const T & default_value,
659 const std::vector<T> & values)
666 template <
typename T>
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());
683 template <
typename T>
693 const T & default_value);
699 template <
typename T>
709 template <
typename T>
713 const T & default_value)
720 template <
typename T>
725 this->comm().gather(0, this->_state.value());
734 template <
typename T>
744 const std::vector<T> & default_value);
778 if constexpr (std::is_arithmetic<T>::value &&
779 !std::is_same<T, bool>::value)
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.");
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.");
827 template <
typename T>
835 template <
typename T>
839 const std::vector<T> & default_value)
std::string name(const ElemQuality q)
virtual void finalize() override
Perform automatic parallel communication based on the producer/consumer modes.
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.
A special version of RestartableData to aid in storing Reporter values.
virtual void storeInfo(nlohmann::json &json) const override
Output meta data to JSON, see JSONOutput.
const ReporterName & name() const override final
Return the name of the 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 override
Perform type specific transfer.
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.
ReporterGeneralContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state, const T &default_value)
This context is specific for vector types of reporters, mainly for declaring a vector of the type fro...
const ReporterMode REPORTER_MODE_UNSET
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
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 ReporterMode REPORTER_MODE_ROOT
virtual std::string contextType() const override=0
const ReporterState< T > & state() const
Return a reference to the ReporterState object that is storing the Reporter value.
ReporterGeneralContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state)
A context that scatters the Reporter value from the root processor.
virtual ~ReporterContextBase()=default
MooseEnum designed for the ReporterContext objects to define how a ReporterValue can and is being pro...
virtual std::string type() const =0
Return the type of the data stored.
ReporterVectorContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< std::vector< T >> &state)
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.
ReporterScatterContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state, const std::vector< T > &values)
virtual const ReporterName & name() const =0
Return the ReporterName that the context is associated.
void clear()
Clear all available items (i.e., create an empty MooseEnum)
const std::vector< T > & _values
The values to scatter.
ReporterState< T > & _state
The state on which this context object operates.
const Parallel::Communicator & comm() const
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 clear() override
Since we know that the _state value is a vector type, we can clear it.
virtual void clear()=0
Helper for clearing vector data.
ReporterContextBase(const libMesh::ParallelObject &other, const MooseObject &producer)
virtual void vectorSum() override
Helper for summing reporter value.
void libmesh_ignore(const Args &...)
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 void store(nlohmann::json &json) const override
Output data to JSON, see JSONOutput.
A context that gathers the Reporter value to the root processor.
virtual std::string contextType() const =0
This is a helper class to aid with parallel communication of compute Reporter values as well as provi...
virtual void store(nlohmann::json &json) const =0
Called by JSONOutput::outputReporters to invoke storage of values for output.
ReporterContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state)
const ReporterProducerEnum & getProducerModeEnum() const
Return the Reporter value produced mode.
ReporterGatherContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state)
virtual void vectorSum() final
Helper for summing reporter value.
Every object that can be built by the factory should be derived from this class.
virtual void finalize()=0
Called by FEProblemBase::joinAndFinalize via ReporterData.
virtual void copyValuesBack()=0
Called by FEProblemBase::advanceState via ReporterData.
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 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 bool restoreState()=0
Called by FEProblemBase::restoreSolutions via ReporterData.
AutoOperation
Options for automatic parallel operations to perform by the default context.
virtual std::string contextType() const override
virtual void resize(dof_id_type local_size)=0
Helper for resizing vector data.
virtual std::string contextType() const override
ReporterBroadcastContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state)
The base class for storing a Reporter's state.
std::string typeAndName() const
Get the class's combined type and name; useful in error handling.
const ReporterMode REPORTER_MODE_DISTRIBUTED
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 std::string contextType() const override
virtual void clear() final
Helper for clearing vector data.
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
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 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 finalize() override
Perform automatic parallel communication based on the producer/consumer modes.
virtual void storeInfo(nlohmann::json &json) const =0
Called by JSONOutput::outputReporters to output meta data independent of calculated values...
virtual void copyValuesBack() override
Called by FEProblemBase::advanceState via ReporterData.
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 transfer(ReporterData &r_data, const ReporterName &r_name, unsigned int time_index=0) const =0
Helper for enabling generic transfer of Reporter values.
void max(const T &r, T &o, Request &req) const
virtual std::string type() const override
Return the type being stored by the associated ReporterState object.
virtual void finalize() override
Perform automatic parallel communication based on the producer/consumer modes.
void insert(const ReporterMode &mode, Args... modes)
virtual void vectorSum()=0
Helper for summing reporter value.
void to_json(nlohmann::json &json, const Moose::LibtorchArtificialNeuralNet *const &network)
virtual std::string contextType() const override
virtual void finalize() override
Perform automatic parallel communication based on the producer/consumer modes.
T & value(const std::size_t time_index=0)
Return a reference to the current value or one of the old values.
virtual std::string contextType() const override
const ReporterMode REPORTER_MODE_REPLICATED
General context that is called by all Reporter values to manage the old values.
A context that broadcasts the Reporter value from the root processor.
virtual void resize(dof_id_type local_size) final
Helper for resizing vector data.
const MooseObject & getProducer() const
Return the MooseObject that produces this Reporter.
ReporterProducerEnum _producer_enum
Defines how the Reporter value can be produced and how it is being produced.
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.
std::string prettyCppType(const std::string &cpp_type)
virtual bool restoreState() override
Restore state to its old values.
const MooseObject & _producer
The MooseObject that is producing this Reporter.
This is a helper class for managing the storage of declared Reporter object values.