https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
ReporterState< T > Class Template Reference

A special version of RestartableData to aid in storing Reporter values. More...

#include <ReporterState.h>

Inheritance diagram for ReporterState< T >:
[legend]

Public Member Functions

 ReporterState (const ReporterName &name)
 
void copyValuesBack ()
 Copy stored values back in time to old/older etc.
 
bool restoreState ()
 Restore values to their old values, i.e.
 
std::string valueType () const override final
 
const ReporterNamegetReporterName () const
 Return the ReporterName that this state is associated with.
 
void addConsumer (ReporterMode mode, const MooseObject &moose_object)
 Add a consumer for this ReporterState.
 
const std::set< std::pair< ReporterMode, const MooseObject * > > & getConsumers () const
 Returns the consumers for this state; a pair that consists of the mode that the state is being consumed by, and the object consuming it.
 
void setIsPostprocessor ()
 Sets the special Reporter type to a Postprocessor.
 
void setIsVectorPostprocessor ()
 Sets the special Reporter type to a VectorPostprocessor.
 
const std::list< T > & get () const
 
std::list< T > & set ()
 
void reset ()
 Resets (destructs) the underlying data.
 
virtual std::string type () const override final
 String identifying the type of parameter stored.
 
virtual const std::type_info & typeId () const override final
 The type ID of the underlying data.
 
virtual bool hasStoreJSON () const override final
 
const std::string & name () const
 The full (unique) name of this particular piece of data.
 
void * context ()
 A context pointer for helping with load / store.
 
bool hasContext () const
 
bool declared () const
 Whether or not this data has been declared.
 
void setDeclared (const SetDeclaredKey)
 Sets that this restartable value has been declared.
 
bool loaded () const
 Whether or not this data has been loaded.
 
void setNotLoaded (const SetNotLoadedKey)
 Sets that this restartable value has been loaded.
 
bool stored () const
 Whether or not this data has been loaded.
 
void setNotStored (const SetNotStoredKey)
 Sets that this restartable value has been loaded.
 
void store (std::ostream &stream)
 Stores the value into the stream stream and sets it as stored.
 
void store (nlohmann::json &json, const StoreJSONParams &params=StoreJSONParams{}) const
 Stores this restartable data in the JSON entry json, with the options set by params (optional; defaults to just the type and underlying value)
 
void load (std::istream &stream)
 Loads the value from the stream stream and sets it as loaded.
 
T & value (const std::size_t time_index=0)
 Return a reference to the current value or one of the old values.
 
const T & value (const std::size_t time_index=0) const
 
void storeInternal (std::ostream &stream) override final
 Loads and stores the data from/to a stream for restart.
 
void loadInternal (std::istream &stream) override final
 Load the RestartableData from a binary stream.
 

Static Public Attributes

static constexpr bool has_store_json
 Whether or not this type has a JSON store method implemented.
 

Protected Member Functions

virtual void storeJSONValue (nlohmann::json &json) const override final
 Internal method for storing the underlying JSON value.
 

Protected Attributes

const std::string _name
 The full (unique) name of this particular piece of data.
 
void *const _context
 A context pointer for helping with load and store.
 

Private Attributes

ReporterName _reporter_name
 Name of data that state is associated.
 
std::set< std::pair< ReporterMode, const MooseObject * > > _consumers
 The consumers for this state; we store the MooseObject for detailed error reporting.
 
std::unique_ptr< std::list< T > > _value
 Stored value.
 
bool _declared
 Whether or not this data has been declared (true) or only retreived (false)
 
bool _loaded
 Whether or not this has value has been loaded.
 
bool _stored
 Whether or not this has value has been stored.
 

Detailed Description

template<typename T>
class ReporterState< T >

A special version of RestartableData to aid in storing Reporter values.

This object is used by the ReporterData object. The objects provides a convenient method to define Reporter data that has a value as well as some number of old data values. Please refer to ReporterData.h for more information regarding the use of this class.

Parameters
nameThe name of the Reporter value

This class stores the current/old/older/... data using a std::list to allow values to be inserted into the data structure without corrupting references to the other values. This allows for arbitrary time data to be stored.

NOTE: Access to the data should be through the value() method to ensure the data is allocated correctly

Definition at line 110 of file ReporterState.h.

Constructor & Destructor Documentation

◆ ReporterState()

template<typename T >
ReporterState< T >::ReporterState ( const ReporterName name)

Definition at line 162 of file ReporterState.h.

163 : ReporterStateBase(name), RestartableData<std::list<T>>(name.getRestartableName(), nullptr)
164{
165}
The base class for storing a Reporter's state.
const std::string & name() const
The full (unique) name of this particular piece of data.
Concrete definition of a parameter value for a specified type.

Member Function Documentation

◆ addConsumer()

void ReporterStateBase::addConsumer ( ReporterMode  mode,
const MooseObject moose_object 
)
inherited

Add a consumer for this ReporterState.

Parameters
modeThe mode that the object will consume the Reporter value
moose_objectThe MooseObject doing the consuming (for error reporting)
See also
ReporterData

Definition at line 17 of file ReporterState.C.

18{
19 _consumers.emplace(mode, &moose_object);
20}
std::set< std::pair< ReporterMode, const MooseObject * > > _consumers
The consumers for this state; we store the MooseObject for detailed error reporting.

Referenced by ReporterTransferInterface::addReporterTransferMode().

◆ context()

void * RestartableDataValue::context ( )
inlineinherited

A context pointer for helping with load / store.

Definition at line 65 of file RestartableData.h.

65{ return _context; }
void *const _context
A context pointer for helping with load and store.

◆ copyValuesBack()

template<typename T >
void ReporterState< T >::copyValuesBack ( )

Copy stored values back in time to old/older etc.

Definition at line 209 of file ReporterState.h.

210{
211 std::list<T> & values = this->set();
212 for (typename std::list<T>::reverse_iterator iter = values.rbegin();
213 std::next(iter) != values.rend();
214 ++iter)
215 (*iter) = (*std::next(iter));
216}
std::array< Real, 2 > values
Definition MortarUtils.C:52

◆ declared()

bool RestartableDataValue::declared ( ) const
inlineinherited

Whether or not this data has been declared.

Definition at line 85 of file RestartableData.h.

85{ return _declared; }
bool _declared
Whether or not this data has been declared (true) or only retreived (false)

Referenced by RestartableDataValue::store().

◆ get()

const std::list< T > & RestartableData< std::list< T > >::get ( ) const
inlineinherited
Returns
a read-only reference to the parameter value.

Definition at line 237 of file RestartableData.h.

281{
282 mooseAssert(_value, "Not valid");
283 return *_value;
284}
std::unique_ptr< std::list< T > > _value
Stored value.

◆ getConsumers()

const std::set< std::pair< ReporterMode, const MooseObject * > > & ReporterStateBase::getConsumers ( ) const
inlineinherited

Returns the consumers for this state; a pair that consists of the mode that the state is being consumed by, and the object consuming it.

See also
ReporterContext

Definition at line 56 of file ReporterState.h.

57 {
58 return _consumers;
59 }

Referenced by ReporterData::getReporterInfo(), and ReporterContextBase::requiresConsumerModes().

◆ getReporterName()

const ReporterName & ReporterStateBase::getReporterName ( ) const
inlineinherited

Return the ReporterName that this state is associated with.

Definition at line 41 of file ReporterState.h.

41{ return _reporter_name; }
ReporterName _reporter_name
Name of data that state is associated.

Referenced by ReporterData::getReporterInfo().

◆ hasContext()

bool RestartableDataValue::hasContext ( ) const
inlineinherited
Returns
Whether or not the data has context set.

Definition at line 70 of file RestartableData.h.

70{ return _context != nullptr; }

Referenced by RestartableDataValue::store().

◆ hasStoreJSON()

virtual bool RestartableData< std::list< T > >::hasStoreJSON ( ) const
inlinefinaloverridevirtualinherited
Returns
Whether or not this value supports storing JSON via store

Implements RestartableDataValue.

Definition at line 256 of file RestartableData.h.

256{ return has_store_json; }
static constexpr bool has_store_json
Whether or not this type has a JSON store method implemented.

◆ load()

void RestartableDataValue::load ( std::istream &  stream)
inherited

Loads the value from the stream stream and sets it as loaded.

Definition at line 32 of file RestartableData.C.

33{
34 loadInternal(stream);
35 _loaded = true;
36}
virtual void loadInternal(std::istream &stream)=0
Internal method that loads the value from the stream stream in the specialized class.
bool _loaded
Whether or not this has value has been loaded.

◆ loaded()

bool RestartableDataValue::loaded ( ) const
inlineinherited

Whether or not this data has been loaded.

This is typically reset on a call to RestartableDataReader::restore()

Definition at line 98 of file RestartableData.h.

98{ return _loaded; }

Referenced by RestartableDataValue::store().

◆ loadInternal()

template<typename T >
void ReporterState< T >::loadInternal ( std::istream &  stream)
finaloverridevirtual

Load the RestartableData from a binary stream.

Reimplemented from RestartableData< std::list< T > >.

Definition at line 244 of file ReporterState.h.

245{
246 // Read the container size
247 std::size_t size = 0;
248 dataLoad(stream, size, nullptr);
249
250 auto & values = this->set();
251
252 // If the current container is undersized, expand it to fit the loaded data
253 if (values.size() < size)
254 values.resize(size);
255
256 // Load each entry of the list directly into the storage
257 // Because we don't shrink the container if the stored size is smaller than
258 // our declared size, we have the odd iterator combo you see below
259 for (auto & val : as_range(values.begin(), std::next(values.begin(), size)))
260 loadHelper(stream, val, nullptr);
261}
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition DataIO.h:1081
void dataLoad(std::istream &stream, LineSegment &l, void *context)
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)

◆ name()

const std::string & RestartableDataValue::name ( ) const
inlineinherited

The full (unique) name of this particular piece of data.

Definition at line 60 of file RestartableData.h.

60{ return _name; }
const std::string _name
The full (unique) name of this particular piece of data.

Referenced by RestartableDataMap::addData(), RestartableDataMap::findData(), and RestartableDataValue::store().

◆ reset()

void RestartableData< std::list< T > >::reset ( )
inlineinherited

Resets (destructs) the underlying data.

Definition at line 247 of file RestartableData.h.

297{
298 mooseAssert(_value, "Not valid"); // shouldn't really call this twice
299 _value.reset();
300}

◆ restoreState()

template<typename T >
bool ReporterState< T >::restoreState ( )

Restore values to their old values, i.e.

value(0) = value(1). This only occurs if old values have been declared, which happens automatically for postprocessors.

Returns
true State was restored
false State was NOT restored

Definition at line 220 of file ReporterState.h.

221{
222 if (this->get().size() <= 1)
223 return false;
224
225 this->set().front() = *std::next(this->get().begin());
226 return true;
227}
const std::list< T > & get() const

◆ set()

std::list< T > & RestartableData< std::list< T > >::set ( )
inlineinherited
Returns
a writable reference to the parameter value.

Definition at line 242 of file RestartableData.h.

289{
290 mooseAssert(_value, "Not valid");
291 return *_value;
292}

◆ setDeclared()

void RestartableDataValue::setDeclared ( const SetDeclaredKey  )
inherited

Sets that this restartable value has been declared.

Definition at line 18 of file RestartableData.C.

19{
20 mooseAssert(!_declared, "Already declared");
21 _declared = true;
22}

Referenced by MooseApp::registerRestartableData().

◆ setIsPostprocessor()

void ReporterStateBase::setIsPostprocessor ( )
inlineinherited

Sets the special Reporter type to a Postprocessor.

See ReporterData::declareReporterValue.

Definition at line 71 of file ReporterState.h.

void setIsPostprocessor()
Sets the special type to a Postprocessor.

◆ setIsVectorPostprocessor()

void ReporterStateBase::setIsVectorPostprocessor ( )
inlineinherited

Sets the special Reporter type to a VectorPostprocessor.

See ReporterData::declareReporterValue.

Definition at line 77 of file ReporterState.h.

void setIsVectorPostprocessor()
Sets the special type to a VectorPostprocessor.

◆ setNotLoaded()

void RestartableDataValue::setNotLoaded ( const SetNotLoadedKey  )
inlineinherited

Sets that this restartable value has been loaded.

Definition at line 113 of file RestartableData.h.

113{ _loaded = false; }

◆ setNotStored()

void RestartableDataValue::setNotStored ( const SetNotStoredKey  )
inlineinherited

Sets that this restartable value has been loaded.

Definition at line 136 of file RestartableData.h.

136{ _stored = false; }
bool _stored
Whether or not this has value has been stored.

◆ store() [1/2]

void RestartableDataValue::store ( nlohmann::json &  json,
const StoreJSONParams params = StoreJSONParams{} 
) const
inherited

Stores this restartable data in the JSON entry json, with the options set by params (optional; defaults to just the type and underlying value)

If the underlying type is not supported for JSON output (if hasStoreJSON() == false), and the parameters have the value output as enabled, this will error.

Definition at line 39 of file RestartableData.C.

40{
41 if (params.value)
42 {
43 if (hasStoreJSON())
44 storeJSONValue(json["value"]);
45 else
46 mooseError("Failed to output restartable data '",
47 name(),
48 "' as JSON because a to_json method is not implemented for the type '",
49 type(),
50 "'");
51 }
52 if (params.type)
53 json["type"] = type();
54 if (params.name)
55 json["name"] = name();
56 if (params.declared)
57 json["declared"] = declared();
58 if (params.loaded)
59 json["loaded"] = loaded();
60 if (params.stored)
61 json["stored"] = stored();
62 if (params.has_context)
63 json["has_context"] = hasContext();
64}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
bool stored() const
Whether or not this data has been loaded.
virtual void storeJSONValue(nlohmann::json &json) const =0
Internal method for storing the underlying JSON value.
bool declared() const
Whether or not this data has been declared.
virtual std::string type() const =0
String identifying the type of parameter stored.
virtual bool hasStoreJSON() const =0
bool loaded() const
Whether or not this data has been loaded.

◆ store() [2/2]

void RestartableDataValue::store ( std::ostream &  stream)
inherited

Stores the value into the stream stream and sets it as stored.

Definition at line 25 of file RestartableData.C.

26{
27 storeInternal(stream);
28 _stored = true;
29}
virtual void storeInternal(std::ostream &stream)=0
Internal method that stores the value into the stream stream in the specialized class.

◆ stored()

bool RestartableDataValue::stored ( ) const
inlineinherited

Whether or not this data has been loaded.

This is typically reset on a call to RestartableDataWriter::write()

Definition at line 121 of file RestartableData.h.

121{ return _stored; }

Referenced by RestartableDataValue::store().

◆ storeInternal()

template<typename T >
void ReporterState< T >::storeInternal ( std::ostream &  stream)
finaloverridevirtual

Loads and stores the data from/to a stream for restart.

This is a special version that handles the fact that the calls declare/getReporterValue occur within the constructor of objects. As such, the storage list already contains data and the references to this data must remain valid.

The default dataLoad assumes the list being populated is empty and simply uses push_back. Therefore, this function loads the data directly into the container to avoid this problem and unnecessary copies.

The default dataStore is very similar, but to ensure consistency (because we're re-defining the load), we implement it again here.

Reimplemented from RestartableData< std::list< T > >.

Definition at line 231 of file ReporterState.h.

232{
233 // Store the container size
234 std::size_t size = this->get().size();
235 dataStore(stream, size, nullptr);
236
237 // Store each entry of the list directly into the storage
238 for (auto & val : this->set())
239 storeHelper(stream, val, nullptr);
240}
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Definition DataIO.h:989
void dataStore(std::ostream &stream, LineSegment &l, void *context)

◆ storeJSONValue()

void RestartableData< std::list< T > >::storeJSONValue ( nlohmann::json &  json) const
inlinefinaloverrideprotectedvirtualinherited

Internal method for storing the underlying JSON value.

Implements RestartableDataValue.

Definition at line 269 of file RestartableData.h.

326{
328 nlohmann::to_json(json, get());
329 else
330 mooseAssert(false, "Should not be called");
331}

◆ type()

std::string RestartableData< std::list< T > >::type ( ) const
inlinefinaloverridevirtualinherited

String identifying the type of parameter stored.

Implements RestartableDataValue.

Definition at line 252 of file RestartableData.h.

305{
306 return MooseUtils::prettyCppType<T>();
307}

◆ typeId()

virtual const std::type_info & RestartableData< std::list< T > >::typeId ( ) const
inlinefinaloverridevirtualinherited

The type ID of the underlying data.

Implements RestartableDataValue.

Definition at line 254 of file RestartableData.h.

254{ return typeid(T); }

◆ value() [1/2]

template<typename T >
T & ReporterState< T >::value ( const std::size_t  time_index = 0)

Return a reference to the current value or one of the old values.

The time_index of 0 returns the current value, 1 returns old, 2 returns older, etc.

Definition at line 169 of file ReporterState.h.

170{
171 // Initialize the data; the first entry is the "current" data
172 if (this->get().empty())
173 this->set().resize(1);
174
175 // If we are a postprocessor, we want to always store an old value so that we can restore the data
176 // if needed. See restoreState.
177 // Note: This can easily be extended to other states like vector-postprocessors or any other
178 // reporter value. However, these states have indeterminate sizes and could create significant,
179 // unecessary memory overhead. In the future, we can extend this to other reporter types if
180 // the need justifies the overhead.
181 if (this->getReporterName().isPostprocessor() && time_index == 0 && this->get().size() <= 1)
182 this->set().push_back(this->get().back());
183
184 // Initialize old, older, ... data
185 if (this->get().size() <= time_index)
186 this->set().resize(time_index + 1, this->get().back());
187
188 return *(std::next(this->set().begin(), time_index));
189}
const ReporterName & getReporterName() const
Return the ReporterName that this state is associated with.

Referenced by ReporterVectorContext< T >::clear(), ReporterVectorContext< T >::resize(), and ReporterVectorContext< T >::vectorSum().

◆ value() [2/2]

template<typename T >
const T & ReporterState< T >::value ( const std::size_t  time_index = 0) const

Definition at line 193 of file ReporterState.h.

194{
195 if (this->get().size() <= time_index)
196 mooseError("The desired time index ",
197 time_index,
198 " does not exists for the '",
200 "' Reporter value, which contains ",
201 this->get().size(),
202 " old value(s). The getReporterValue method must be called with the desired time "
203 "index to be able to access data.");
204 return *(std::next(this->get().begin(), time_index));
205}

◆ valueType()

template<typename T >
std::string ReporterState< T >::valueType ( ) const
inlinefinaloverridevirtual
Returns
The type associated with this state

Implements ReporterStateBase.

Definition at line 139 of file ReporterState.h.

139{ return MooseUtils::prettyCppType<T>(); }

Member Data Documentation

◆ _consumers

std::set<std::pair<ReporterMode, const MooseObject *> > ReporterStateBase::_consumers
privateinherited

The consumers for this state; we store the MooseObject for detailed error reporting.

Definition at line 84 of file ReporterState.h.

Referenced by ReporterStateBase::addConsumer(), and ReporterStateBase::getConsumers().

◆ _context

void* const RestartableDataValue::_context
protectedinherited

A context pointer for helping with load and store.

Definition at line 197 of file RestartableData.h.

Referenced by RestartableDataValue::context(), and RestartableDataValue::hasContext().

◆ _declared

bool RestartableDataValue::_declared
privateinherited

Whether or not this data has been declared (true) or only retreived (false)

Definition at line 201 of file RestartableData.h.

Referenced by RestartableDataValue::declared(), and RestartableDataValue::setDeclared().

◆ _loaded

bool RestartableDataValue::_loaded
privateinherited

Whether or not this has value has been loaded.

Definition at line 204 of file RestartableData.h.

Referenced by RestartableDataValue::load(), RestartableDataValue::loaded(), and RestartableDataValue::setNotLoaded().

◆ _name

const std::string RestartableDataValue::_name
protectedinherited

The full (unique) name of this particular piece of data.

Definition at line 194 of file RestartableData.h.

Referenced by RestartableDataValue::name().

◆ _reporter_name

ReporterName ReporterStateBase::_reporter_name
privateinherited

Name of data that state is associated.

Definition at line 81 of file ReporterState.h.

Referenced by ReporterStateBase::getReporterName(), ReporterStateBase::setIsPostprocessor(), and ReporterStateBase::setIsVectorPostprocessor().

◆ _stored

bool RestartableDataValue::_stored
privateinherited

Whether or not this has value has been stored.

Definition at line 207 of file RestartableData.h.

Referenced by RestartableDataValue::setNotStored(), RestartableDataValue::store(), and RestartableDataValue::stored().

◆ _value

std::unique_ptr<std::list< T > > RestartableData< std::list< T > >::_value
privateinherited

Stored value.

Definition at line 273 of file RestartableData.h.

◆ has_store_json

constexpr bool RestartableData< std::list< T > >::has_store_json
staticconstexprinherited

Whether or not this type has a JSON store method implemented.

Definition at line 219 of file RestartableData.h.


The documentation for this class was generated from the following file: