https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
ReporterData Class Reference

This is a helper class for managing the storage of declared Reporter object values. More...

#include <ReporterData.h>

Classes

class  WriteKey
 

Public Member Functions

 ReporterData (MooseApp &moose_app)
 
template<typename T >
bool hasReporterValue (const ReporterName &reporter_name) const
 Return True if a Reporter value with the given type and name have been created.
 
bool hasReporterValue (const ReporterName &reporter_name) const
 Return True if a Reporter value with any type exists with the given name.
 
template<typename T >
bool hasReporterState (const ReporterName &reporter_name) const
 
bool hasReporterState (const ReporterName &reporter_name) const
 
std::set< ReporterNamegetReporterNames () const
 Return a list of all reporter names.
 
std::set< std::string > getPostprocessorNames () const
 Return a list of all postprocessor names.
 
DenseVector< Real > getAllRealReporterValues () const
 Get all real reporter values including postprocessor and vector postprocessor values into a dense vector.
 
std::vector< std::string > getAllRealReporterFullNames () const
 Get full names of all real reporter values Note: For a postprocessor, the full name is the postprocessor name plus '/value'.
 
template<typename T >
const T & getReporterValue (const ReporterName &reporter_name, const MooseObject &consumer, const ReporterMode &mode, const std::size_t time_index=0) const
 Method for returning read only references to Reporter values.
 
template<typename T >
const T & getReporterValue (const ReporterName &reporter_name, const std::size_t time_index=0) const
 Method for returning a read-only reference to Reporter values that already exist.
 
template<typename T >
void setReporterValue (const ReporterName &reporter_name, const T &value, const std::size_t time_index=0)
 Method for setting Reporter values that already exist.
 
template<typename T >
void needReporterTimeIndex (const ReporterName &reporter_name, const std::size_t time_index)
 Method for setting that a specific time index is requested for a Reporter value.
 
const ReporterProducerEnumgetReporterMode (const ReporterName &reporter_name) const
 Return the ReporterProducerEnum for an existing ReporterValue.
 
std::string getReporterInfo (const ReporterName &reporter_name) const
 Gets information pertaining to the Reporter with name reporter_name.
 
std::string getReporterInfo () const
 Gets information about all declared/requested Reporters.
 
template<typename T , typename S , typename... Args>
T & declareReporterValue (const ReporterName &reporter_name, const ReporterMode &mode, const MooseObject &producer, Args &&... args)
 Method for returning a writable reference to the current Reporter value.
 
void finalize (const std::string &object_name)
 Helper function for performing post calculation actions via the ReporterContext objects.
 
void copyValuesBack ()
 At the end of a timestep this method is called to copy the values back in time in preparation for the next timestep.
 
void restoreState (bool verbose=false)
 When a time step fails, this method is called to revert the current reporter values to their old state.
 
void check () const
 Perform integrity check for get/declare calls.
 
bool hasReporterWithMode (const std::string &obj_name, const ReporterMode &mode) const
 Return true if the supplied mode exists in the produced Reporter values.
 
const ReporterContextBasegetReporterContextBase (const ReporterName &reporter_name) const
 
ReporterContextBasegetReporterContextBase (const ReporterName &reporter_name)
 
const ReporterStateBasegetReporterStateBase (const ReporterName &reporter_name) const
 @Returns The ReporterStateBase associated with the Reporter with name reporter_name.
 
ReporterStateBasegetReporterStateBase (const ReporterName &reporter_name)
 

Static Public Member Functions

static std::string getReporterInfo (const ReporterStateBase &state, const ReporterContextBase *context)
 Gets information pertaining to the Reporter with state state and possibly context context.
 

Private Member Functions

template<typename T >
ReporterState< T > & getReporterStateHelper (const ReporterName &reporter_name, bool declare, const MooseObject *moose_object=nullptr) const
 Helper method for creating the necessary RestartableData for Reporter values.
 
RestartableDataValuegetRestartableDataHelper (std::unique_ptr< RestartableDataValue > data_ptr, bool declare) const
 Helper for registering data with the MooseApp to avoid cyclic includes.
 
void restoreReporterStateIfAvailable (RestartableDataValue &state) const
 Helper for restoring state from the checkpoint reader if available.
 

Private Attributes

MooseApp_app
 For accessing the restart/recover system, which is where Reporter values are stored.
 
std::map< ReporterName, ReporterStateBase * > _states
 Map from ReporterName -> Reporter state.
 
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
 The ReporterContext objects are created when a value is declared.
 

Detailed Description

This is a helper class for managing the storage of declared Reporter object values.

This design of the system is a generalization of the VectorPostprocessor system that the Reporter objects replaced.

Foremost, this object doesn't store the data. It simply acts as helper for using the restart system of the MooseApp. This object automatically handles the old, older, ... data. All declarations create std::pair<T, std::vector<T>> restartable data on the MooseApp, where the first value is the current value and the data in the vector are the older data.

The ReporterState object is a RestartableData object that serves as a helper for managing the time history. A "context" object also exists that uses the ReporterState for performing special operations. Refer to ReporterState.h/C for more information.

It is important to note that the Reporter values are not threaded. However, the Reporter objects are UserObject based, so the calculation of the values can be threaded.

This object also relies on ReporterName objects, which are simply a combination of the Reporter object name and the data name. If you recall the VectorPostprocessor system on which this is based required an object name and a vector name. The ReporterName class simply provides a convenient way to provide that information in a single object. Special Parser syntax was also defined so that application developers do not have to have input parameters for both the object and data names (see Parser.C/h).

Definition at line 48 of file ReporterData.h.

Constructor & Destructor Documentation

◆ ReporterData()

ReporterData::ReporterData ( MooseApp moose_app)

Definition at line 14 of file ReporterData.C.

14: _app(moose_app) {}
MooseApp & _app
For accessing the restart/recover system, which is where Reporter values are stored.

Member Function Documentation

◆ check()

void ReporterData::check ( ) const

Perform integrity check for get/declare calls.

Definition at line 162 of file ReporterData.C.

163{
164 std::string missing;
165 for (const auto & name_state_pair : _states)
166 if (!hasReporterValue(name_state_pair.first))
167 missing += getReporterInfo(name_state_pair.first) + "\n";
168
169 if (missing.size())
170 mooseError("The following Reporter(s) were not declared:\n\n", missing);
171}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
std::map< ReporterName, ReporterStateBase * > _states
Map from ReporterName -> Reporter state.
std::string getReporterInfo() const
Gets information about all declared/requested Reporters.

◆ copyValuesBack()

void ReporterData::copyValuesBack ( )

At the end of a timestep this method is called to copy the values back in time in preparation for the next timestep.

See FEProblemBase::advanceState

Definition at line 17 of file ReporterData.C.

18{
19 for (const auto & name_context_pair : _context_ptrs)
20 name_context_pair.second->copyValuesBack();
21}
void copyValuesBack()
At the end of a timestep this method is called to copy the values back in time in preparation for the...
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.

Referenced by FEProblemBase::advanceState().

◆ declareReporterValue()

template<typename T , typename S , typename... Args>
T & ReporterData::declareReporterValue ( const ReporterName reporter_name,
const ReporterMode mode,
const MooseObject producer,
Args &&...  args 
)

Method for returning a writable reference to the current Reporter value.

This method is used by the Reporter class to produce values.

Template Parameters
TThe Reporter value C++ type.
S(optional) The ReporterContext for performing specialized actions after the values have been computed. For example, ReporterBroadcastContext automatically broadcasts the computed value. See ReporterState.C/h for more information.
Parameters
reporter_nameThe name of the reporter value, which includes the object name and the data name.
modeThe mode that the produced value will be computed by the Reporter object
producerThe MooseObject that produces this value
args(optional) Any number of optional arguments passed into the Context type given by the S template parameter. If S = ReporterContext then the first argument can be used as the default value (see ReporterContext.h).

The ReporterContext objects allow for custom handling of data (e.g., broadcasting the value). The get/declare methods can be called in any order thus an the underlying RestartableData object is often created by the get method before it is declared. Therefore the custom functionality cannot be handled by specializing the RestartableData/ReporterState object directly because the state is often created prior to the declaration that dictates how the produced value shall be computed. Thus, the reason for the separate ReporterContext objects.

Definition at line 406 of file ReporterData.h.

410{
411 // Get/create the ReporterState
412 auto & state = getReporterStateHelper<T>(reporter_name, /* declare = */ true, &producer);
413
414 // They key in _states (ReporterName) is not unique by special type. This is done on purpose
415 // because we want to store reporter names a single name regardless of special type.
416 // Because of this, we have the case where someone could request a reporter value
417 // that is later declared as a pp or a vpp value. In this case, when it is first
418 // requested, the _state entry will have a key and name with a special type of ANY.
419 // When it's declared here (later), we will still find the correct entry because
420 // we don't check the special type in the key/name. But... we want the actual
421 // key and name to represent a pp or a vpp. Therefore, we'll set it properly,
422 // remove the entry in the map (which has the ANY key), and re-add it so that it
423 // has the pp/vpp key. This allows us to identify Reporters that really represent
424 // pps/vpps in output and in error reporting.
425 if (reporter_name.isPostprocessor() && !state.getReporterName().isPostprocessor())
426 {
427 state.setIsPostprocessor();
428 _states.erase(reporter_name);
429 _states.emplace(reporter_name, &state);
430 }
431 else if (reporter_name.isVectorPostprocessor() &&
432 !state.getReporterName().isVectorPostprocessor())
433 {
434 state.setIsVectorPostprocessor();
435 _states.erase(reporter_name);
436 _states.emplace(reporter_name, &state);
437 }
438
439 mooseAssert(!_context_ptrs.count(reporter_name), "Context already exists");
440
441 // Create the ReporterContext
442 auto context_ptr = std::make_unique<S>(_app, producer, state, args...);
443 context_ptr->init(mode); // initialize the mode, see ContextReporter
444 _context_ptrs.emplace(reporter_name, std::move(context_ptr));
445
446 // On recover, values declared after the bulk restore pass are skipped by it.
447 // Restore this value in place from the still-open checkpoint reader (no-op on
448 // normal runs and for values declared before the bulk restore runs, which are
449 // handled by the bulk pass). This is done after context construction so that
450 // context-driven resizes do not clobber the restore.
452
453 return state.value();
454}
void restoreReporterStateIfAvailable(RestartableDataValue &state) const
Helper for restoring state from the checkpoint reader if available.
bool isPostprocessor() const
bool isVectorPostprocessor() const

Referenced by ReporterTransferInterface::declareClone(), ReporterGeneralContext< T >::declareClone(), VectorPostprocessor::declareVector(), ReporterTransferInterface::declareVectorClone(), and ReporterGeneralContext< T >::declareVectorClone().

◆ finalize()

void ReporterData::finalize ( const std::string &  object_name)

Helper function for performing post calculation actions via the ReporterContext objects.

If you recall, the original VectorPostprocessor system included the ability to perform some scatter and broadcast actions via the special call on the storage helper object. This is a replacement for that method that leverages the ReporterContext objects to perform value specific actions, including some automatic operations depending how the data is produced and consumed.

See FEProblemBase::joinAndFinalize

Definition at line 48 of file ReporterData.C.

49{
50 for (auto & name_context_pair : _context_ptrs)
51 if (name_context_pair.first.getObjectName() == object_name)
52 name_context_pair.second->finalize();
53}
void finalize(const std::string &object_name)
Helper function for performing post calculation actions via the ReporterContext objects.

Referenced by MFEMProblem::executeMFEMObjects(), and FEProblemBase::joinAndFinalize().

◆ getAllRealReporterFullNames()

std::vector< std::string > ReporterData::getAllRealReporterFullNames ( ) const

Get full names of all real reporter values Note: For a postprocessor, the full name is the postprocessor name plus '/value'.

For a vector postprocessor, the full name is the vector postprocessor name plus the vector name followed by '/#' where '#' is the index of the vector.

Definition at line 106 of file ReporterData.C.

107{
108 std::vector<std::string> output;
109
110 for (const auto & name_context_pair : _context_ptrs)
111 {
112 const ReporterName & rname = name_context_pair.first;
113
114 if (hasReporterValue<Real>(rname))
115 output.push_back(rname.getCombinedName());
116
117 if (hasReporterValue<std::vector<Real>>(rname))
118 {
119 auto pname = rname.getCombinedName();
120 const auto & vec = getReporterValue<std::vector<Real>>(pname);
121 for (unsigned int i = 0; i < vec.size(); ++i)
122 output.push_back(pname + "/" + std::to_string(i));
123 }
124 }
125
126 return output;
127}
The Reporter system is comprised of objects that can contain any number of data values.
const std::string getCombinedName() const
Return the name of the object and data as object_name/data_name.

Referenced by FEProblemBase::execute().

◆ getAllRealReporterValues()

DenseVector< Real > ReporterData::getAllRealReporterValues ( ) const

Get all real reporter values including postprocessor and vector postprocessor values into a dense vector.

Definition at line 81 of file ReporterData.C.

82{
83 DenseVector<Real> all_values;
84
85 std::vector<Real> & output = all_values.get_values();
86
87 for (const auto & name_context_pair : _context_ptrs)
88 {
89 const ReporterName & rname = name_context_pair.first;
90
91 if (hasReporterValue<Real>(rname))
92 output.push_back(getReporterValue<Real>(rname.getCombinedName()));
93
94 if (hasReporterValue<std::vector<Real>>(rname))
95 {
96 const auto & vec = getReporterValue<std::vector<Real>>(rname.getCombinedName());
97 for (const auto & v : vec)
98 output.push_back(v);
99 }
100 }
101
102 return all_values;
103}

Referenced by FEProblemBase::execute().

◆ getPostprocessorNames()

std::set< std::string > ReporterData::getPostprocessorNames ( ) const

Return a list of all postprocessor names.

Definition at line 71 of file ReporterData.C.

72{
73 std::set<std::string> output;
74 for (const auto & name_context_pair : _context_ptrs)
75 if (name_context_pair.first.isPostprocessor())
76 output.insert(name_context_pair.first.getObjectName());
77 return output;
78}

Referenced by FEProblemBase::checkDuplicatePostprocessorVariableNames().

◆ getReporterContextBase() [1/2]

ReporterContextBase & ReporterData::getReporterContextBase ( const ReporterName reporter_name)

Definition at line 138 of file ReporterData.C.

139{
140 if (!hasReporterValue(reporter_name))
141 mooseError("Unable to locate Reporter context with name: ", reporter_name);
142 return *_context_ptrs.at(reporter_name);
143}

◆ getReporterContextBase() [2/2]

const ReporterContextBase & ReporterData::getReporterContextBase ( const ReporterName reporter_name) const

◆ getReporterInfo() [1/3]

std::string ReporterData::getReporterInfo ( ) const

Gets information about all declared/requested Reporters.

Definition at line 253 of file ReporterData.C.

254{
255 std::string out = _states.empty() ? "No reporters were requested or declared." : "";
256 for (const auto & name : getReporterNames())
257 out += getReporterInfo(name) + "\n";
258 return out;
259}
std::set< ReporterName > getReporterNames() const
Return a list of all reporter names.
std::string name(const ElemQuality q)
OStreamProxy out(std::cout)

Referenced by check(), getReporterInfo(), getReporterInfo(), getReporterStateHelper(), and ReporterContextBase::requiresConsumerModes().

◆ getReporterInfo() [2/3]

std::string ReporterData::getReporterInfo ( const ReporterName reporter_name) const

Gets information pertaining to the Reporter with name reporter_name.

Definition at line 245 of file ReporterData.C.

246{
247 return getReporterInfo(getReporterStateBase(reporter_name),
248 hasReporterValue(reporter_name) ? &getReporterContextBase(reporter_name)
249 : nullptr);
250}
const ReporterStateBase & getReporterStateBase(const ReporterName &reporter_name) const
@Returns The ReporterStateBase associated with the Reporter with name reporter_name.
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const

◆ getReporterInfo() [3/3]

std::string ReporterData::getReporterInfo ( const ReporterStateBase state,
const ReporterContextBase context 
)
static

Gets information pertaining to the Reporter with state state and possibly context context.

Definition at line 209 of file ReporterData.C.

210{
211 std::stringstream oss;
212
213 const auto & name = state.getReporterName();
214
215 if (name.isPostprocessor())
216 oss << "Postprocessor \"" << name.getObjectName() << "\":\n";
217 else
218 {
219 oss << name.specialTypeToName() << " \"" << name.getCombinedName() << "\":\n Type:\n "
220 << state.valueType() << "\n";
221 }
222 oss << " Producer:\n ";
223 if (context)
224 {
225 oss << context->getProducer().type() << " \"" << context->getProducer().name() << "\"";
226 oss << "\n Context type:\n " << context->contextType();
227 }
228 else
229 oss << "None";
230 oss << "\n Consumer(s):\n";
231 if (state.getConsumers().empty())
232 oss << " None\n";
233 else
234 for (const auto & mode_object_pair : state.getConsumers())
235 {
236 const ReporterMode mode = mode_object_pair.first;
237 const MooseObject * object = mode_object_pair.second;
238 oss << " " << object->typeAndName() << " (mode: " << mode << ")\n";
239 }
240
241 return oss.str();
242}
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
std::string typeAndName() const
Get the class's combined type and name; useful in error handling.
Definition MooseBase.C:57
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
const MooseObject & getProducer() const
Return the MooseObject that produces this Reporter.
virtual std::string contextType() const =0
MooseEnumItem that automatically creates the ID and doesn't allow the ID to be assigned.
const ReporterName & getReporterName() const
Return the ReporterName that this state is associated with.
virtual std::string valueType() const =0
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 consum...

Referenced by ReporterDebugOutput::output().

◆ getReporterMode()

const ReporterProducerEnum & ReporterData::getReporterMode ( const ReporterName reporter_name) const

Return the ReporterProducerEnum for an existing ReporterValue.

Parameters
reporter_nameThe name of the reporter value, which includes the object name and the data name.

Definition at line 197 of file ReporterData.C.

198{
199 return getReporterContextBase(reporter_name).getProducerModeEnum();
200}
const ReporterProducerEnum & getProducerModeEnum() const
Return the Reporter value produced mode.

Referenced by AccumulateReporter::declareAccumulateHelper().

◆ getReporterNames()

std::set< ReporterName > ReporterData::getReporterNames ( ) const

Return a list of all reporter names.

Definition at line 62 of file ReporterData.C.

63{
64 std::set<ReporterName> output;
65 for (const auto & name_context_pair : _context_ptrs)
66 output.insert(name_context_pair.second->name());
67 return output;
68}

Referenced by getReporterInfo(), AdvancedOutput::initAvailableLists(), TableOutput::outputVectorPostprocessors(), and XMLOutput::outputVectorPostprocessors().

◆ getReporterStateBase() [1/2]

ReporterStateBase & ReporterData::getReporterStateBase ( const ReporterName reporter_name)

Definition at line 154 of file ReporterData.C.

155{
156 if (!hasReporterState(reporter_name))
157 mooseError("Unable to locate Reporter state with name: ", reporter_name);
158 return *_states.at(reporter_name);
159}
bool hasReporterState(const ReporterName &reporter_name) const

◆ getReporterStateBase() [2/2]

const ReporterStateBase & ReporterData::getReporterStateBase ( const ReporterName reporter_name) const

@Returns The ReporterStateBase associated with the Reporter with name reporter_name.

Definition at line 146 of file ReporterData.C.

147{
148 if (!hasReporterState(reporter_name))
149 mooseError("Unable to locate Reporter state with name: ", reporter_name);
150 return *_states.at(reporter_name);
151}

Referenced by ReporterTransferInterface::addReporterTransferMode(), getReporterInfo(), and hasReporterState().

◆ getReporterStateHelper()

template<typename T >
ReporterState< T > & ReporterData::getReporterStateHelper ( const ReporterName reporter_name,
bool  declare,
const MooseObject moose_object = nullptr 
) const
private

Helper method for creating the necessary RestartableData for Reporter values.

Template Parameters
TThe desired C++ type for the Reporter value
Parameters
reporter_nameObject/data name for the Reporter value
declareFlag indicating if the ReporterValue is being declared or read. This flag is passed to the existing MooseApp restart/recover system that errors if a value is declared multiple times.
moose_objectThe object requesting/declaring the state, used in error handling.

Definition at line 336 of file ReporterData.h.

339{
340 if (hasReporterState(reporter_name))
341 {
342 const auto error_helper =
343 [this, &reporter_name, &moose_object, &declare](const std::string & suffix)
344 {
345 std::stringstream oss;
346 oss << "While " << (declare ? "declaring" : "requesting") << " a "
347 << reporter_name.specialTypeToName() << " value with the name \""
348 << reporter_name.getValueName() << "\"";
349 if (!reporter_name.isPostprocessor() && !reporter_name.isVectorPostprocessor())
350 oss << " and type \"" << MooseUtils::prettyCppType<T>() << "\"";
351 oss << ",\na Reporter with the same name " << suffix << ".\n\n";
352 oss << getReporterInfo(reporter_name);
353
354 if (moose_object)
355 moose_object->mooseError(oss.str());
356 else
357 mooseError(oss.str());
358 };
359
360 if (declare && hasReporterValue(reporter_name))
361 error_helper("has already been declared");
362 if (!hasReporterState<T>(reporter_name))
363 {
364 std::stringstream oss;
365 oss << "has been " << (declare || !hasReporterValue(reporter_name) ? "requested" : "declared")
366 << " with a different type";
367 error_helper(oss.str());
368 }
369 }
370
371 // Reporter states are stored as restartable data. The act of registering restartable data
372 // may be done multiple times with the same name, which will happen when more than one
373 // get value is done, or a get value and a declare is done. With this, we create a new
374 // state every time, but said created state may not be the actual state if this state
375 // is already registered as restartable data. Therefore, we create a state, and then
376 // cast the restartable data received back to a state (which may be different than
377 // the one we created, but that's okay)
378 auto state_unique_ptr = std::make_unique<ReporterState<T>>(reporter_name);
379 auto & restartable_value = getRestartableDataHelper(std::move(state_unique_ptr), declare);
380
381 auto * state = dynamic_cast<ReporterState<T> *>(&restartable_value);
382 mooseAssert(state, "Cast failed. The check above must be broken!");
383
384 // See declareReporterValue for a comment on what happens if a state for the same
385 // name is requested but with different special types. TLDR: ReporterNames with
386 // different special types are not unique so they'll be the same entry
387 _states.emplace(reporter_name, state);
388
389 return *state;
390}
RestartableDataValue & getRestartableDataHelper(std::unique_ptr< RestartableDataValue > data_ptr, bool declare) const
Helper for registering data with the MooseApp to avoid cyclic includes.
std::string specialTypeToName() const
Converts the special type to a usable name for error reporting.
const std::string & getValueName() const
Return the data name for the Reporter value.
A special version of RestartableData to aid in storing Reporter values.

◆ getReporterValue() [1/2]

template<typename T >
const T & ReporterData::getReporterValue ( const ReporterName reporter_name,
const MooseObject consumer,
const ReporterMode mode,
const std::size_t  time_index = 0 
) const

Method for returning read only references to Reporter values.

Template Parameters
TThe Reporter value C++ type.
Parameters
reporter_nameThe name of the reporter value, which includes the object name and the data name.
consumerThe MooseObject consuming the Reporter value (for error reporting)
modeThe mode that the value will be consumed by the by the ReporterInterface object
time_index(optional) When not provided or zero is provided the current value is returned. If an index greater than zero is provided then the corresponding old data is returned (1 = old, 2 = older, etc.).

Definition at line 394 of file ReporterData.h.

398{
399 auto & state = getReporterStateHelper<T>(reporter_name, /* declare = */ false, &consumer);
400 state.addConsumer(mode, consumer);
401 return state.value(time_index);
402}

Referenced by FEProblemBase::getPostprocessorValueByName(), PostprocessorInterface::getPostprocessorValueByNameInternal(), ReporterInterface::getReporterValueByName(), VectorPostprocessorInterface::getVectorPostprocessorByNameHelper(), VectorPostprocessorInterface::getVectorPostprocessorContextByNameHelper(), FEProblemBase::getVectorPostprocessorValueByName(), ReporterPositions::initialize(), ReporterTimes::initialize(), TableOutput::outputReporter(), Exodus::outputReporters(), TableOutput::outputVectorPostprocessors(), XMLOutput::outputVectorPostprocessors(), and ReporterContext< T >::transferToVector().

◆ getReporterValue() [2/2]

template<typename T >
const T & ReporterData::getReporterValue ( const ReporterName reporter_name,
const std::size_t  time_index = 0 
) const

Method for returning a read-only reference to Reporter values that already exist.

Template Parameters
TThe Reporter value C++ type.
Parameters
reporter_nameThe name of the reporter value, which includes the object name and the data name.
time_index(optional) When not provided or zero is provided the current value is returned. If an index greater than zero is provided then the corresponding old data is returned (1 = old, 2 = older, etc.).

Definition at line 476 of file ReporterData.h.

478{
479 if (!hasReporterValue<T>(reporter_name))
480 mooseError("Reporter name \"",
481 reporter_name,
482 "\" with type \"",
483 MooseUtils::prettyCppType<T>(),
484 "\" is not declared.");
485
486 // Force the const version of value, which does not allow for increasing time index
487 return static_cast<const ReporterState<T> &>(
488 getReporterStateHelper<T>(reporter_name, /* declare = */ false))
489 .value(time_index);
490}
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ getRestartableDataHelper()

RestartableDataValue & ReporterData::getRestartableDataHelper ( std::unique_ptr< RestartableDataValue data_ptr,
bool  declare 
) const
private

Helper for registering data with the MooseApp to avoid cyclic includes.

Definition at line 174 of file ReporterData.C.

176{
177 return _app.registerRestartableData(std::move(data_ptr), 0, !declare);
178}
RestartableDataValue & registerRestartableData(std::unique_ptr< RestartableDataValue > data, THREAD_ID tid, bool read_only, const RestartableDataMapName &metaname="")
Definition MooseApp.C:2449

Referenced by getReporterStateHelper().

◆ hasReporterState() [1/2]

template<typename T >
bool ReporterData::hasReporterState ( const ReporterName reporter_name) const
Returns
True if a ReporterState is defined for the Reporter with name reporter_name and the given type.

Definition at line 467 of file ReporterData.h.

468{
469 if (!hasReporterState(reporter_name))
470 return false;
471 return dynamic_cast<const ReporterState<T> *>(&getReporterStateBase(reporter_name));
472}

Referenced by getReporterStateBase(), getReporterStateBase(), getReporterStateHelper(), and hasReporterState().

◆ hasReporterState() [2/2]

bool ReporterData::hasReporterState ( const ReporterName reporter_name) const
Returns
True if a ReporterState is defined for the Reporter with name reporter_name.

Definition at line 203 of file ReporterData.C.

204{
205 return _states.count(reporter_name);
206}

◆ hasReporterValue() [1/2]

template<typename T >
bool ReporterData::hasReporterValue ( const ReporterName reporter_name) const

◆ hasReporterValue() [2/2]

bool ReporterData::hasReporterValue ( const ReporterName reporter_name) const

Return True if a Reporter value with any type exists with the given name.

Definition at line 56 of file ReporterData.C.

57{
58 return _context_ptrs.count(reporter_name);
59}

◆ hasReporterWithMode()

bool ReporterData::hasReporterWithMode ( const std::string &  obj_name,
const ReporterMode mode 
) const

Return true if the supplied mode exists in the produced Reporter values.

See also
CSV.C/h

Definition at line 187 of file ReporterData.C.

188{
189 for (const auto & name_context_pair : _context_ptrs)
190 if (name_context_pair.first.getObjectName() == obj_name &&
191 name_context_pair.second->getProducerModeEnum() == mode)
192 return true;
193 return false;
194}

Referenced by CSV::output().

◆ needReporterTimeIndex()

template<typename T >
void ReporterData::needReporterTimeIndex ( const ReporterName reporter_name,
const std::size_t  time_index 
)

Method for setting that a specific time index is requested for a Reporter value.

Template Parameters
TThe Reporter value C++ type.
Parameters
reporter_nameThe name of the reporter value, which includes the object name and the data name.
time_indexThe time index that is needed

Definition at line 505 of file ReporterData.h.

507{
508 getReporterValue<T>(reporter_name, 0); // for error checking that it is declared
509 getReporterStateHelper<T>(reporter_name, /* declare = */ false).value(time_index);
510}

Referenced by Receiver::Receiver().

◆ restoreReporterStateIfAvailable()

void ReporterData::restoreReporterStateIfAvailable ( RestartableDataValue state) const
private

Helper for restoring state from the checkpoint reader if available.

Defined in the .C to avoid requiring a complete MooseApp type in the template header.

Definition at line 181 of file ReporterData.C.

182{
183 _app.restoreDataIfAvailable(state, 0, {});
184}
bool restoreDataIfAvailable(RestartableDataValue &value, const THREAD_ID tid, Moose::PassKey< ReporterData >)
Restores value in place from the checkpoint reader if it is present in the checkpoint and has not yet...
Definition MooseApp.h:839

Referenced by declareReporterValue().

◆ restoreState()

void ReporterData::restoreState ( bool  verbose = false)

When a time step fails, this method is called to revert the current reporter values to their old state.

See also
FEProblemBase::restoreSolutions
Parameters
verboseSet true to print whether the reporters were restored or not.

Definition at line 24 of file ReporterData.C.

25{
26 // Table of reporter values that were and were not restored
27 VariadicTable<std::string, std::string, std::string> summary_table({"Name", "Type", "Restored?"});
28
29 for (const auto & [rname, context] : _context_ptrs)
30 {
31 const bool restored = context->restoreState();
32
33 if (verbose)
34 summary_table.addRow(
35 rname.getCombinedName(), rname.specialTypeToName(), restored ? "YES" : "NO");
36 }
37
38 if (verbose && !_context_ptrs.empty())
39 {
40 std::stringstream oss;
41 oss << "Reporter Restoration Summary:\n";
42 summary_table.print(oss);
43 mooseInfo(oss.str());
44 }
45}
void mooseInfo(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
Definition MooseError.h:401
A class for "pretty printing" a table of data.
void addRow(Ts... entries)
Add a row of data.

Referenced by FEProblemBase::restoreSolutions().

◆ setReporterValue()

template<typename T >
void ReporterData::setReporterValue ( const ReporterName reporter_name,
const T &  value,
const std::size_t  time_index = 0 
)

Method for setting Reporter values that already exist.

Template Parameters
TThe Reporter value C++ type.
Parameters
reporter_nameThe name of the reporter value, which includes the object name and the data name.
valueThe value to which the Reporter will be changed to.
time_index(optional) When not provided or zero is provided the current value is returned. If an index greater than zero is provided then the corresponding old data is returned (1 = old, 2 = older, etc.). WARNING! This method is designed for setting values outside of the traditional interfaces such as is necessary for Transfers. This is an advanced capability that should be used with caution.
See also
FEProblemBase::setPostprocessorValueByName

Definition at line 494 of file ReporterData.h.

497{
498 // https://stackoverflow.com/questions/123758/how-do-i-remove-code-duplication-between-similar-const-and-non-const-member-func
499 const auto & me = *this;
500 const_cast<T &>(me.getReporterValue<T>(reporter_name, time_index)) = value;
501}

Referenced by ConstantPostprocessor::ConstantPostprocessor(), FEProblemBase::setPostprocessorValueByName(), FEProblemBase::setVectorPostprocessorValueByName(), ReporterContext< T >::transfer(), and ReporterContext< T >::transferFromVector().

Member Data Documentation

◆ _app

MooseApp& ReporterData::_app
private

For accessing the restart/recover system, which is where Reporter values are stored.

Definition at line 293 of file ReporterData.h.

Referenced by declareReporterValue(), getRestartableDataHelper(), and restoreReporterStateIfAvailable().

◆ _context_ptrs

std::map<ReporterName, std::unique_ptr<ReporterContextBase> > ReporterData::_context_ptrs
private

The ReporterContext objects are created when a value is declared.

The context objects include a reference to the associated ReporterState values. This container stores the context object for each Reporter value.

Definition at line 331 of file ReporterData.h.

Referenced by copyValuesBack(), declareReporterValue(), finalize(), getAllRealReporterFullNames(), getAllRealReporterValues(), getPostprocessorNames(), getReporterContextBase(), getReporterContextBase(), getReporterNames(), hasReporterValue(), hasReporterWithMode(), and restoreState().

◆ _states

std::map<ReporterName, ReporterStateBase *> ReporterData::_states
mutableprivate

Map from ReporterName -> Reporter state.

We need to keep track of all of the states that are created so that we can check them after Reporter declaration to make sure all states have a producer (are delcared). We cannot check _context_ptrs, because a context is only defined for Reporters that have been declared. This is mutable so that it can be inserted into when requesting Reporter values.

Definition at line 326 of file ReporterData.h.

Referenced by check(), declareReporterValue(), getReporterInfo(), getReporterStateBase(), getReporterStateBase(), getReporterStateHelper(), and hasReporterState().


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