https://mooseframework.inl.gov
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. More...
 
bool hasReporterValue (const ReporterName &reporter_name) const
 Return True if a Reporter value with any type exists with the given name. More...
 
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. More...
 
std::set< std::string > getPostprocessorNames () const
 Return a list of all postprocessor names. More...
 
DenseVector< RealgetAllRealReporterValues () const
 Get all real reporter values including postprocessor and vector postprocessor values into a dense vector. More...
 
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'. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
const ReporterProducerEnumgetReporterMode (const ReporterName &reporter_name) const
 Return the ReporterProducerEnum for an existing ReporterValue. More...
 
std::string getReporterInfo (const ReporterName &reporter_name) const
 Gets information pertaining to the Reporter with name reporter_name. More...
 
std::string getReporterInfo () const
 Gets information about all declared/requested Reporters. More...
 
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. More...
 
void finalize (const std::string &object_name)
 Helper function for performing post calculation actions via the ReporterContext objects. More...
 
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. More...
 
void restoreState (bool verbose=false)
 When a time step fails, this method is called to revert the current reporter values to their old state. More...
 
void check () const
 Perform integrity check for get/declare calls. More...
 
bool hasReporterWithMode (const std::string &obj_name, const ReporterMode &mode) const
 Return true if the supplied mode exists in the produced Reporter values. More...
 
const ReporterContextBasegetReporterContextBase (const ReporterName &reporter_name) const
 
ReporterContextBasegetReporterContextBase (const ReporterName &reporter_name)
 
const ReporterStateBasegetReporterStateBase (const ReporterName &reporter_name) const
 The ReporterStateBase associated with the Reporter with name reporter_name. More...
 
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. More...
 

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. More...
 
RestartableDataValuegetRestartableDataHelper (std::unique_ptr< RestartableDataValue > data_ptr, bool declare) const
 Helper for registering data with the MooseApp to avoid cyclic includes. More...
 
void restoreReporterStateIfAvailable (RestartableDataValue &state) const
 Helper for restoring state from the checkpoint reader if available. More...
 

Private Attributes

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

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.
Definition: ReporterData.h:293

Member Function Documentation

◆ check()

void ReporterData::check ( ) const

Perform integrity check for get/declare calls.

Definition at line 162 of file ReporterData.C.

Referenced by FEProblemBase::initialSetup().

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 }
std::map< ReporterName, ReporterStateBase * > _states
Map from ReporterName -> Reporter state.
Definition: ReporterData.h:326
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
std::string getReporterInfo() const
Gets information about all declared/requested Reporters.
Definition: ReporterData.C:253
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
Definition: ReporterData.h:458

◆ 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.

Referenced by FEProblemBase::advanceState().

18 {
19  for (const auto & name_context_pair : _context_ptrs)
20  name_context_pair.second->copyValuesBack();
21 }
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
Definition: ReporterData.h:331

◆ 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.

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

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 }
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
Definition: ReporterData.h:331
std::map< ReporterName, ReporterStateBase * > _states
Map from ReporterName -> Reporter state.
Definition: ReporterData.h:326
void restoreReporterStateIfAvailable(RestartableDataValue &state) const
Helper for restoring state from the checkpoint reader if available.
Definition: ReporterData.C:181
MooseApp & _app
For accessing the restart/recover system, which is where Reporter values are stored.
Definition: ReporterData.h:293

◆ 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.

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

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 }
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
Definition: ReporterData.h:331

◆ 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.

Referenced by FEProblemBase::execute().

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 }
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
Definition: ReporterData.h:331
const std::string getCombinedName() const
Return the name of the object and data as object_name/data_name.
Definition: ReporterName.C:53
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
Definition: ReporterData.h:458
The Reporter system is comprised of objects that can contain any number of data values.
Definition: ReporterName.h:30

◆ 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.

Referenced by FEProblemBase::execute().

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 }
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
Definition: ReporterData.h:331
const std::string getCombinedName() const
Return the name of the object and data as object_name/data_name.
Definition: ReporterName.C:53
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
Definition: ReporterData.h:458
The Reporter system is comprised of objects that can contain any number of data values.
Definition: ReporterName.h:30

◆ getPostprocessorNames()

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

Return a list of all postprocessor names.

Definition at line 71 of file ReporterData.C.

Referenced by FEProblemBase::checkDuplicatePostprocessorVariableNames().

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 }
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
Definition: ReporterData.h:331

◆ getReporterContextBase() [1/2]

const ReporterContextBase & ReporterData::getReporterContextBase ( const ReporterName reporter_name) const
Returns
The ReporterContextBase associated with the Reporter with name reporter_name.

Definition at line 130 of file ReporterData.C.

Referenced by ReporterTransferInterface::clearVectorReporter(), ReporterTransferInterface::declareClone(), AccumulateReporter::declareLateValues(), ReporterTransferInterface::declareVectorClone(), ReporterInterface::getReporterContextBaseByName(), getReporterInfo(), getReporterMode(), VectorPostprocessorInterface::getVectorPostprocessorContextByNameHelper(), hasReporterValue(), JSONOutput::outputReporters(), ReporterTransferInterface::resizeReporter(), ReporterTransferInterface::sumVectorReporter(), ReporterTransferInterface::transferFromVectorReporter(), ReporterTransferInterface::transferReporter(), and ReporterTransferInterface::transferToVectorReporter().

131 {
132  if (!hasReporterValue(reporter_name))
133  mooseError("Unable to locate Reporter context with name: ", reporter_name);
134  return *_context_ptrs.at(reporter_name);
135 }
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
Definition: ReporterData.h:331
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
Definition: ReporterData.h:458

◆ getReporterContextBase() [2/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 }
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
Definition: ReporterData.h:331
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
Definition: ReporterData.h:458

◆ getReporterInfo() [1/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.

Referenced by ReporterDebugOutput::output().

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 }
std::string name(const ElemQuality q)
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...
Definition: ReporterState.h:56
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
const ReporterName & getReporterName() const
Return the ReporterName that this state is associated with.
Definition: ReporterState.h:41
virtual std::string contextType() const =0
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:93
virtual std::string valueType() const =0
std::string typeAndName() const
Get the class&#39;s combined type and name; useful in error handling.
Definition: MooseBase.C:57
const MooseObject & getProducer() const
Return the MooseObject that produces this Reporter.
MooseEnumItem that automatically creates the ID and doesn&#39;t allow the ID to be assigned.
Definition: ReporterMode.h:45

◆ 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
The ReporterStateBase associated with the Reporter with name reporter_name.
Definition: ReporterData.C:146
std::string getReporterInfo() const
Gets information about all declared/requested Reporters.
Definition: ReporterData.C:253
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
Definition: ReporterData.h:458
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
Definition: ReporterData.C:130

◆ getReporterInfo() [3/3]

std::string ReporterData::getReporterInfo ( ) const

Gets information about all declared/requested Reporters.

Definition at line 253 of file ReporterData.C.

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

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::map< ReporterName, ReporterStateBase * > _states
Map from ReporterName -> Reporter state.
Definition: ReporterData.h:326
std::set< ReporterName > getReporterNames() const
Return a list of all reporter names.
Definition: ReporterData.C:62
std::string getReporterInfo() const
Gets information about all declared/requested Reporters.
Definition: ReporterData.C:253
OStreamProxy out

◆ 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.

Referenced by AccumulateReporter::declareAccumulateHelper().

198 {
199  return getReporterContextBase(reporter_name).getProducerModeEnum();
200 }
const ReporterProducerEnum & getProducerModeEnum() const
Return the Reporter value produced mode.
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
Definition: ReporterData.C:130

◆ getReporterNames()

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

Return a list of all reporter names.

Definition at line 62 of file ReporterData.C.

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

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 }
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
Definition: ReporterData.h:331

◆ getReporterStateBase() [1/2]

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

The ReporterStateBase associated with the Reporter with name reporter_name.

Definition at line 146 of file ReporterData.C.

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

147 {
148  if (!hasReporterState(reporter_name))
149  mooseError("Unable to locate Reporter state with name: ", reporter_name);
150  return *_states.at(reporter_name);
151 }
std::map< ReporterName, ReporterStateBase * > _states
Map from ReporterName -> Reporter state.
Definition: ReporterData.h:326
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
bool hasReporterState(const ReporterName &reporter_name) const
Definition: ReporterData.h:467

◆ getReporterStateBase() [2/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 }
std::map< ReporterName, ReporterStateBase * > _states
Map from ReporterName -> Reporter state.
Definition: ReporterData.h:326
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
bool hasReporterState(const ReporterName &reporter_name) const
Definition: ReporterData.h:467

◆ 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 }
A special version of RestartableData to aid in storing Reporter values.
std::map< ReporterName, ReporterStateBase * > _states
Map from ReporterName -> Reporter state.
Definition: ReporterData.h:326
bool isVectorPostprocessor() const
Definition: ReporterName.h:98
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
RestartableDataValue & getRestartableDataHelper(std::unique_ptr< RestartableDataValue > data_ptr, bool declare) const
Helper for registering data with the MooseApp to avoid cyclic includes.
Definition: ReporterData.C:174
std::string specialTypeToName() const
Converts the special type to a usable name for error reporting.
Definition: ReporterName.C:89
bool hasReporterState(const ReporterName &reporter_name) const
Definition: ReporterData.h:467
bool isPostprocessor() const
Definition: ReporterName.h:94
std::string getReporterInfo() const
Gets information about all declared/requested Reporters.
Definition: ReporterData.C:253
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
Definition: ReporterData.h:458
const std::string & getValueName() const
Return the data name for the Reporter value.
Definition: ReporterName.C:47

◆ 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.

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

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

◆ 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 }
A special version of RestartableData to aid in storing Reporter values.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
T & value(const std::size_t time_index=0)
Return a reference to the current value or one of the old values.

◆ 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.

Referenced by getReporterStateHelper().

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:2176
MooseApp & _app
For accessing the restart/recover system, which is where Reporter values are stored.
Definition: ReporterData.h:293

◆ 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.

Referenced by getReporterStateBase(), and getReporterStateHelper().

468 {
469  if (!hasReporterState(reporter_name))
470  return false;
471  return dynamic_cast<const ReporterState<T> *>(&getReporterStateBase(reporter_name));
472 }
A special version of RestartableData to aid in storing Reporter values.
const ReporterStateBase & getReporterStateBase(const ReporterName &reporter_name) const
The ReporterStateBase associated with the Reporter with name reporter_name.
Definition: ReporterData.C:146
bool hasReporterState(const ReporterName &reporter_name) const
Definition: ReporterData.h:467

◆ 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 }
std::map< ReporterName, ReporterStateBase * > _states
Map from ReporterName -> Reporter state.
Definition: ReporterData.h:326

◆ hasReporterValue() [1/2]

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

Return True if a Reporter value with the given type and name have been created.

Definition at line 458 of file ReporterData.h.

Referenced by check(), ReporterTransferInterface::checkHasReporterValue(), AccumulateReporter::declareAccumulateHelper(), AccumulateReporter::declareLateValues(), getAllRealReporterFullNames(), getAllRealReporterValues(), getReporterContextBase(), getReporterInfo(), getReporterStateHelper(), PostprocessorInterface::hasPostprocessorByName(), FEProblemBase::hasPostprocessorValueByName(), ReporterInterface::hasReporterValueByName(), VectorPostprocessorInterface::hasVectorPostprocessorByName(), MooseParsedFunctionWrapper::initialize(), ParsedConvergence::initializeSymbols(), JSONOutput::initialSetup(), PostprocessorInterface::isDefaultPostprocessorValueByName(), TableOutput::outputReporter(), Exodus::outputReporters(), XMLOutput::outputVectorPostprocessors(), and TableOutput::outputVectorPostprocessors().

459 {
460  if (!hasReporterValue(reporter_name))
461  return false;
462  return dynamic_cast<const ReporterContext<T> *>(&getReporterContextBase(reporter_name));
463 }
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
Definition: ReporterData.h:458
General context that is called by all Reporter values to manage the old values.
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
Definition: ReporterData.C:130

◆ 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 }
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
Definition: ReporterData.h:331

◆ 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.

Referenced by CSV::output(), and JSONOutput::outputReporters().

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 }
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
Definition: ReporterData.h:331

◆ 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.

Referenced by Receiver::Receiver().

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 }
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ 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.

Referenced by declareReporterValue().

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:813
MooseApp & _app
For accessing the restart/recover system, which is where Reporter values are stored.
Definition: ReporterData.h:293

◆ 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.

Referenced by FEProblemBase::restoreSolutions().

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 }
std::map< ReporterName, std::unique_ptr< ReporterContextBase > > _context_ptrs
The ReporterContext objects are created when a value is declared.
Definition: ReporterData.h:331
A class for "pretty printing" a table of data.
Definition: PerfGraph.h:34
void mooseInfo(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
Definition: MooseError.h:401
void addRow(Ts... entries)
Add a row of data.
Definition: VariadicTable.h:92

◆ 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.

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

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 }
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

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(), 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(), getReporterStateHelper(), and hasReporterState().


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