Reporter System

The Reporter system may be considered a generalization of the Postprocessor and VectorPostprocessor systems. Each Reporter object may declare any number of values with any types. By contrast, post-processors each declare a single, scalar, Real value, and while vector post-processors declare any number of values, they must all be of type std::vector<Real>. Reporters can declare both scalar and vector data of any type, including complex data and arbitrary classes/structs. The only requirement on the data type is that the types must have associated dataLoad and dataStore specializations (see DataIO).

The reporter system uses a producer/consumer relationship: reporter objects "produce" data values, which then may be "consumed" by other objects.

Producing Reporter Data

As noted above, Reporter objects declare any number of values of any type. Note that these values are automatically registered as restartable. For complex types, data serialization routines might be needed; see DataIO for more information.

In the Reporter header file, Reporter values are declared as non-const reference members of the desired types, for example:

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

These references are initialized using the declareValue and declareValueByName methods. Note that 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 declareValueByName method uses the supplied string directly as the value name, while the declareValue method gets the value name from the supplied ReporterValueName parameter declared in validParams. For example, in validParams,

  params.addParam<ReporterValueName>("int_name", "int", "The name of the integer data");
(moose/test/src/reporters/TestReporter.C)

Then the Reporter data can be declared using declareValue:

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

Note that in this example, an initial value is supplied for the data.

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

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;
  }
}
(moose/test/src/reporters/TestReporter.C)

Consuming Reporter Data

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 int & _int;
(moose/test/include/reporters/TestReporter.h)

In the initialization list, the getReporterValue or getReporterValueByName method is used to initialize the reference:

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

Similarly to declareValue and declareValueByName, getReporterValue uses the provided string for the value name, whereas getReporterValueByName gets the value name from the parameter named by the provided string. In the example above, the following appears in validParams:

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

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. In the input file, the ReporterName is provided as follows, where "a" is the name of the 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/declareValueByName method of that object:

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

Outputting Reporter Data

Reporter values may be output in two formats: comma-separated values (CSV) and JSON. CSV output is limited to Reporter values with a type of Real or std::vector<Real>. JSON output will work for any type that 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 produced or consumed in any of the prescribed modes. When consumed, the mode of production is checked against the mode of 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")), 
(moose/test/src/reporters/TestReporter.C)

ReporterBroadcastContext
Automatically performs an MPI broadcast 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.
  • ElementVariableStatisticsElement reporter to get statistics for a coupled variable. This can be transfered to other apps.
  • 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 mesh information, such as the number of elements, nodes, and degrees of freedom.
  • MeshMetaDataReporterReports the mesh meta data.
  • NodalVariableStatisticsNodal reporter to get statistics for a coupled variable. This can be transfered to other apps.
  • PerfGraphReporterReports the full performance graph from the PerfGraph.
  • RestartableDataReporterReports restartable data and restartable meta data.
  • SolutionInvalidityReporterReports the Summary Table of Solution Invalid Counts.

Available Actions