Reporter System

A Reporter object in MOOSE is a C++ object that computes a single value with an arbitrary type. The value computed is some sort of aggregation of data from a simulation. For example, the MeshInfo object reports various quantities regarding the mesh such as the number of nodes, elements, and degrees-of-freedom.

The system relies on a producer/consumer relationship. The Reporter object produces any number of aggregation values and other objects consume these values.

Producer (Reporter objects)

The Reporter system builds from MOOSE's UserObject system. Each Reporter contains the full interface of a UserObject but is also expected to declare one or more values that to be produced by the Reporter object. Generally, there are no restrictions on the supported types for the Reporter values. All values declared are automatically registered as restartable. For complex types data serialization routines might be needed, see Reporter Value Types.

Values to be computed are stored via a reference to the desired type, for example:

int & _int;
(../../../SoftwareDownloads/moose/test/include/reporters/TestReporter.h)

The references are initialized using the declareValue and declareValueByName methods. It is possible to indicate how the value is to be computed, with respect to parallelism, by setting the calculation mode, see Reporter Context and Modes for more information. The declareValue method works in conjunction with the validParams function to allow the input file to dictate the name of the data being produced. To use this method first define an input parameter for the data name.

"int_name", "int", "The name of the interger data");
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)

Then initialize the previously created reference by providing the input parameter name. In this example the initial value is also supplied.

_int(declareValue<int>("int_name", 1980)),
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)

The declareValueByName method works in the same manner except it does not query the parameter system for the name, it uses the name supplied to specifying the name directly. As such, this name cannot be modified without recompiling .

The calculation of the value(s) occurs by overriding the execute method and updating the values for references.

void
TestDeclareReporter::execute()
{
  _int += 1;
  _real = 1.2345;
  _vector = {1, 1.1, 1.2};
  _string = "string";

  if (processor_id() == 0)
    _bcast_value = 42;

  _gather_value.resize(1, processor_id());

  if (_distributed_vector)
  {
    _distributed_vector->resize(_vector.size());
    (*_distributed_vector)[0] = processor_id();
    for (unsigned int i = 1; i < _distributed_vector->size(); ++i)
      (*_distributed_vector)[i] = (*_distributed_vector)[i - 1] * 10;
  }
}
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)

Consumer (other objects)

Any object that inherits from the ReporterInterface may consume a value produced by a Reporter. Values are retrieved in a similar fashion as declared, but use a constant reference. For example, values to be consumed should create a reference in the class definition.

const std::vector<Real> & _vector;
(../../../SoftwareDownloads/moose/test/include/reporters/TestReporter.h)

In the class declaration the getReporterValue method is used to initialize the reference.

_vector(getReporterValue<std::vector<Real>>("vector_reporter")),
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)

The getReporterValue method automatically checks for an input parameter by the given name and the name specified in the parameter will be used. To retrieve a Reporter value directly by name use the getReporterValueByName method.

The get methods accept a ReporterName object, which is simply the combination of the name of the producing Reporter object and the name of the reporter value. It is possible to request a ReporterName in the validParams function of the consumer. For example, in the validParams function a parameter with a type of ReporterName is specified.

  params.addRequiredParam<ReporterName>("int_reporter", "'int' reporter name");
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)

Then in the initialization list a reference to the desired value is initialized by supplying the name of the parameter containing the ReporterValue.

    _int(getReporterValue<int>("int_reporter")),
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)

In the input file, the ReporterName is provide as follows where "a" is the name of the producer Reporter object in the [Reporters] block of the input file that is producing data with the name "int", which is the name given to the data within the declareValue metho of that object.

    int_reporter = a/int
(../../../SoftwareDownloads/moose/test/tests/reporters/base/base.i)

Reporter Value Types

As stated above, Reporter values may be of an type. This includes arbitrary classes or structs. However, the types must have an associated dataLoad and dataStore function specialization, please refer to DataIO for more information on these functions.

Reporter Output

Reporter values are outputted in two forms CSV or JSON files. CSV output is limited to Reporter values with a type of Real or std::vector<Real>. JSON output will work for arbitrary types, if the type has a to_json function, see JSON for more details.

Reporter Context and Modes

Reporter values use a context system for performing parallel operations automatically. The default context allows Reporter values to be produced and consumed in various modes. Depending on the mode produced/consumed parallel operations will be performed automatically. The following modes exist for the default context.

  • REPORTER_MODE_ROOT: Values exist only on the root processor.

  • REPORTER_MODE_REPLICATED: Values exist and are identical on all processors.

  • REPORTER_MODE_DISTRIBUTED: Values exist and are different across processors.

Values can be computed or consumed in any of the prescribed modes. When consumed the mode of production is checked against the mode consumption. Table 1 details the actions taken by the various possible modes of production and consumption for a Reporter value.

Table 1: Default operations for the default context that occur for Reporter values depending on the modes of production and consumption. The prefix REPORTER_MODE_ is omitted for clarity.

Producer ModeConsumer ModeOperation
ROOTROOTDo nothing
REPLICATEDROOTDo nothing
REPLICATEDREPLICATEDDo nothing
DISTRIBUTEDDISTRIBUTEDDo nothing
ROOTREPLICATEDMPI Broadcast
ROOTDISTRIBUTEDError
REPLICATEDDISTRIBUTEDError
DISTRIBUTEDROOTError
DISTRIBUTEDREPLICATEDError

The declareValue and declareValueByName methods allow for non-default context to be defined. For example, the following line declares a Reporter value to use the gather context object. A list of available contexts follows the code snippet.

_gather_value(declareValueByName<std::vector<dof_id_type>, ReporterGatherContext>("gather")), 
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)

ReporterBroadcastContext
Automatically performs an MPI scatter of a specified value on the root processor to all processors.

ReporterScatterContext
Automatically performs an MPI scatter of a vector of data on the root processor to all processors.

ReporterGatherContext
Automatically performs an MPI gather to a vector of data on the root processor from all processors.

Reporter Debug Output

The ReporterDebugOutput output can be added to output to screen all of the Reporter values that were declared and requested, along with their types, producers, contexts, consumers, and consumer modes. This debug output can also be enabled with the Debug/show_reporters parameter.

Available Objects

  • Moose App
  • AccumulateReporterReporter which accumulates the value of a inputted reporter value over time into a vector reporter value of the same type.
  • ConstantReporterReporter with constant values to be accessed by other objects, can be modified using transfers.
  • ExtraIDIntegralReporterThis ExtraIDIntegralReporter source code is to integrate variables based on parsed extra IDs based on reporter system.
  • IterationInfoReport the time and iteration information for the simulation.
  • MeshInfoReport the time and iteration information for the simulation.
  • PerfGraphReporterReports the full performance graph from the PerfGraph.

Available Actions