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;
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())
392 "\" is being produced in ",
396 " is requesting to consume it in ",
398 " mode, which is not supported.");
406 template <
typename T>
410 _state.copyValuesBack();
413 template <
typename T>
417 json[
"type"] = this->type();
420 template <
typename T>
427 template <
typename T>
440 const T & default_value)
467 virtual void clear() final;
479 template <
typename T,
typename A>
484 template <
typename T>
489 this->_state.value().resize(size);
493 mooseError(
"Cannot resize non vector-type reporter values.");
496 template <
typename T>
501 this->_state.value().clear();
503 mooseError(
"Cannot clear non vector-type reporter values.");
506 template <
typename T>
511 if constexpr (std::is_arithmetic<T>::value && !std::is_same<T, bool>::value)
514 this->comm().sum(this->_state.value());
520 using VectorValueType =
typename T::value_type;
523 if constexpr (std::is_arithmetic<VectorValueType>::value &&
524 !std::is_same<VectorValueType, bool>::value)
527 this->comm().sum(this->_state.value());
533 using InnerValueType =
typename VectorValueType::value_type;
536 if constexpr (std::is_arithmetic<InnerValueType>::value &&
537 !std::is_same<InnerValueType, bool>::value)
540 auto vec_size = this->_state.value().size();
541 this->comm().max(vec_size);
543 mooseAssert(this->_state.value().size() == vec_size,
544 "Reporter vector have different sizes on different ranks.");
547 for (
auto & innerVector : this->_state.value())
551 this->comm().max(maxInnerSize);
554 innerVector.resize(maxInnerSize);
557 this->comm().sum(innerVector);
564 mooseError(
"Cannot perform sum operation on non-numeric or unsupported vector types.");
570 template <
typename T>
580 const T & default_value);
585 template <
typename T>
595 template <
typename T>
599 const T & default_value)
606 template <
typename T>
617 template <
typename T>
624 const std::vector<T> & values);
628 const T & default_value,
629 const std::vector<T> & values);
639 template <
typename T>
643 const std::vector<T> & values)
650 template <
typename T>
654 const T & default_value,
655 const std::vector<T> & values)
662 template <
typename T>
668 mooseAssert(this->processor_id() == 0 ? _values.size() == this->n_processors() :
true,
669 "Vector to be scattered must be sized to match the number of processors");
671 this->processor_id() > 0 ? _values.size() == 0 :
true,
672 "Vector to be scattered must be sized to zero on processors except for the root processor");
673 this->comm().scatter(_values, this->_state.value());
679 template <
typename T>
689 const T & default_value);
695 template <
typename T>
705 template <
typename T>
709 const T & default_value)
716 template <
typename T>
721 this->comm().gather(0, this->_state.value());
730 template <
typename T>
740 const std::vector<T> & default_value);
774 if constexpr (std::is_arithmetic<T>::value &&
775 !std::is_same<T, bool>::value)
793 using ValueType =
typename T::value_type;
795 if constexpr (std::is_arithmetic<ValueType>::value && !std::is_same<ValueType, bool>::value)
801 mooseAssert(this->
_state.
value().size() == vec_size,
802 "Reporter vector have different sizes on different ranks.");
808 this->
comm().
max(val_vec_size);
809 val_vec.resize(val_vec_size);
817 mooseError(
"Cannot perform sum operation on non-numeric or unsupported vector types.");
823 template <
typename T>
831 template <
typename T>
835 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)
Custom type trait that has a value of true for types that can be broadcasted.
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.