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.
Producer Mode | Consumer Mode | Operation |
---|---|---|
ROOT | ROOT | Do nothing |
REPLICATED | ROOT | Do nothing |
REPLICATED | REPLICATED | Do nothing |
DISTRIBUTED | DISTRIBUTED | Do nothing |
ROOT | REPLICATED | MPI Broadcast |
ROOT | DISTRIBUTED | Error |
REPLICATED | DISTRIBUTED | Error |
DISTRIBUTED | ROOT | Error |
DISTRIBUTED | REPLICATED | Error |
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
- Moose App
- AddReporterActionAdd a Reporter object to the simulation.
(../../../SoftwareDownloads/moose/test/include/reporters/TestReporter.h)
// This file is part of the MOOSE framework
// https://www.mooseframework.org
//
// All rights reserved, see COPYRIGHT for full restrictions
// https://github.com/idaholab/moose/blob/master/COPYRIGHT
//
// Licensed under LGPL 2.1, please see LICENSE for details
// https://www.gnu.org/licenses/lgpl-2.1.html
#pragma once
#include "GeneralReporter.h"
class TestDeclareReporter : public GeneralReporter
{
public:
static InputParameters validParams();
TestDeclareReporter(const InputParameters & parameters);
virtual void initialize() override {}
virtual void finalize() override {}
virtual void execute() override;
protected:
int & _int; // MooseDocs:producer
Real & _real;
std::vector<Real> & _vector;
std::string & _string;
Real & _bcast_value;
std::vector<dof_id_type> _values_to_scatter;
dof_id_type & _scatter_value;
std::vector<dof_id_type> _values_to_gather;
std::vector<dof_id_type> & _gather_value;
std::vector<dof_id_type> * _distributed_vector;
};
class TestGetReporter : public GeneralReporter
{
public:
static InputParameters validParams();
TestGetReporter(const InputParameters & parameters);
virtual void initialize() override {}
virtual void finalize() override {}
virtual void execute() override;
protected:
const int & _int;
const int & _int_old;
const Real & _real;
const std::vector<Real> & _vector; // MooseDocs:consumer
const std::string & _string;
const Real & _bcast_value;
const dof_id_type & _scatter_value;
const std::vector<dof_id_type> & _gather_value;
};
class TestDeclareInitialSetupReporter : public GeneralReporter
{
public:
static InputParameters validParams();
TestDeclareInitialSetupReporter(const InputParameters & parameters);
virtual void initialSetup() override;
virtual void initialize() override {}
virtual void finalize() override {}
virtual void execute() override {}
};
class TestGetReporterDeclaredInInitialSetupReporter : public GeneralReporter
{
public:
static InputParameters validParams();
TestGetReporterDeclaredInInitialSetupReporter(const InputParameters & parameters);
virtual void initialize() override {}
virtual void finalize() override {}
virtual void execute() override;
protected:
const Real & _value_declared_in_initial_setup;
Real & _the_value_of_the_reporter;
};
class TestDeclareErrorsReporter : public GeneralReporter
{
public:
static InputParameters validParams();
TestDeclareErrorsReporter(const InputParameters & parameters);
virtual void initialize() override {}
virtual void finalize() override {}
virtual void execute() override {}
};
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)
// This file is part of the MOOSE framework
// https://www.mooseframework.org
//
// All rights reserved, see COPYRIGHT for full restrictions
// https://github.com/idaholab/moose/blob/master/COPYRIGHT
//
// Licensed under LGPL 2.1, please see LICENSE for details
// https://www.gnu.org/licenses/lgpl-2.1.html
#include "TestReporter.h"
registerMooseObject("MooseTestApp", TestDeclareReporter);
registerMooseObject("MooseTestApp", TestGetReporter);
registerMooseObject("MooseTestApp", TestDeclareInitialSetupReporter);
registerMooseObject("MooseTestApp", TestGetReporterDeclaredInInitialSetupReporter);
registerMooseObject("MooseTestApp", TestDeclareErrorsReporter);
InputParameters
TestDeclareReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addParam<ReporterValueName>(
"int_name", "int", "The name of the interger data"); // MooseDocs:data
params.addParam<ReporterValueName>("distributed_vector_name",
"Distributed vector reporter to produce.");
return params;
}
TestDeclareReporter::TestDeclareReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(declareValue<int>("int_name", 1980)), // MooseDocs:producer
_real(declareValueByName<Real>("real")),
_vector(declareValueByName<std::vector<Real>>("vector")),
_string(declareValueByName<std::string>("string")),
_bcast_value(declareValueByName<Real, ReporterBroadcastContext>("broadcast")),
_scatter_value(
declareValueByName<dof_id_type, ReporterScatterContext>("scatter", _values_to_scatter)),
_gather_value(declareValueByName<std::vector<dof_id_type>, ReporterGatherContext>(
"gather")), // MooseDocs:gather
_distributed_vector(isParamValid("distributed_vector_name")
? &declareValue<std::vector<dof_id_type>>("distributed_vector_name",
REPORTER_MODE_DISTRIBUTED)
: nullptr)
{
if (processor_id() == 0)
for (dof_id_type rank = 0; rank < n_processors(); ++rank)
_values_to_scatter.push_back(rank);
}
// MooseDocs:execute_begin
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;
}
}
// MooseDocs:execute_end
InputParameters
TestGetReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("int_reporter", "'int' reporter name");
params.addRequiredParam<ReporterName>("real_reporter", "'real' reporter name");
params.addRequiredParam<ReporterName>("vector_reporter", "'vector' reporter name");
params.addRequiredParam<ReporterName>("string_reporter", "'string' reporter name");
params.addRequiredParam<ReporterName>("broadcast_reporter", "'broadcast' reporter name");
params.addRequiredParam<ReporterName>("scatter_reporter", "'scatter' reporter name");
params.addRequiredParam<ReporterName>("gather_reporter", "'gather' reporter name");
return params;
}
TestGetReporter::TestGetReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(getReporterValue<int>("int_reporter")),
_int_old(getReporterValue<int>("int_reporter", 1)),
_real(getReporterValue<Real>("real_reporter")),
_vector(getReporterValue<std::vector<Real>>("vector_reporter")), // MooseDocs:consumer
_string(getReporterValue<std::string>("string_reporter")),
_bcast_value(getReporterValue<Real>("broadcast_reporter")),
_scatter_value(getReporterValue<dof_id_type>("scatter_reporter")),
_gather_value(getReporterValue<std::vector<dof_id_type>>("gather_reporter"))
{
}
void
TestGetReporter::execute()
{
if (_int != 1980 + _t_step)
mooseError("int reporter test failed: ", _int, " != ", 1980 + _t_step);
if (_real != 1.2345)
mooseError("Real reporter test failed");
if (_vector != std::vector<Real>({1., 1.1, 1.2}))
mooseError("std::vector<Real> reporter test failed");
if (_string != "string")
mooseError("std::string reporter test failed");
if (_t_step == 0 && _int_old != 1980)
mooseError("int_old on timestep 0 failed: ", _int_old, " != ", 1980);
if (_t_step > 0 && _int_old != 1980 + (_t_step - 1))
mooseError(
"int_old on timestep ", _t_step, " failed: ", _int_old, " != ", 1980 + (_t_step - 1));
if (_bcast_value != 42)
mooseError("Broadcast reporter test failed");
if (_scatter_value != processor_id())
mooseError("Scatter reporter test failed");
if (processor_id() == 0)
{
std::vector<dof_id_type> gold;
for (dof_id_type id = 0; id < n_processors(); ++id)
gold.push_back(id);
if (_gather_value != gold)
mooseError("Gather reporter test failed!");
}
}
InputParameters
TestDeclareInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<Real>("value", "The value to report.");
return params;
}
TestDeclareInitialSetupReporter::TestDeclareInitialSetupReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
}
void
TestDeclareInitialSetupReporter::initialSetup()
{
Real & value = declareValueByName<Real>("value");
value = getParam<Real>("value");
}
InputParameters
TestGetReporterDeclaredInInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("other_reporter",
"The reporter name that was declared in initialSetup");
return params;
}
TestGetReporterDeclaredInInitialSetupReporter::TestGetReporterDeclaredInInitialSetupReporter(
const InputParameters & parameters)
: GeneralReporter(parameters),
_value_declared_in_initial_setup(getReporterValue<Real>("other_reporter")),
_the_value_of_the_reporter(declareValueByName<Real>("other_value"))
{
}
void
TestGetReporterDeclaredInInitialSetupReporter::execute()
{
_the_value_of_the_reporter = _value_declared_in_initial_setup;
}
InputParameters
TestDeclareErrorsReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterValueName>("value", "A reporter value name");
params.addParam<bool>("missing_param", false, "True to test the error for a missing parameter");
params.addParam<bool>("bad_param", false, "True to test the error for a bad parameter type");
params.addParam<bool>("already_declared", false, "Test declaring a value multiple times");
params.addParam<bool>("requested_different_type",
false,
"Test declaring a value that has been requested with a differentt type");
return params;
}
TestDeclareErrorsReporter::TestDeclareErrorsReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
if (getParam<bool>("missing_param"))
declareValue<int>("some_missing_parm");
if (getParam<bool>("bad_param"))
declareValue<int>("bad_param");
if (getParam<bool>("already_declared"))
{
declareValueByName<int>("value_name");
declareValueByName<Real>("value_name");
}
if (getParam<bool>("requested_different_type"))
{
getReporterValueByName<int>(name() + "/value_name");
declareValueByName<Real>("value_name");
}
}
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)
// This file is part of the MOOSE framework
// https://www.mooseframework.org
//
// All rights reserved, see COPYRIGHT for full restrictions
// https://github.com/idaholab/moose/blob/master/COPYRIGHT
//
// Licensed under LGPL 2.1, please see LICENSE for details
// https://www.gnu.org/licenses/lgpl-2.1.html
#include "TestReporter.h"
registerMooseObject("MooseTestApp", TestDeclareReporter);
registerMooseObject("MooseTestApp", TestGetReporter);
registerMooseObject("MooseTestApp", TestDeclareInitialSetupReporter);
registerMooseObject("MooseTestApp", TestGetReporterDeclaredInInitialSetupReporter);
registerMooseObject("MooseTestApp", TestDeclareErrorsReporter);
InputParameters
TestDeclareReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addParam<ReporterValueName>(
"int_name", "int", "The name of the interger data"); // MooseDocs:data
params.addParam<ReporterValueName>("distributed_vector_name",
"Distributed vector reporter to produce.");
return params;
}
TestDeclareReporter::TestDeclareReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(declareValue<int>("int_name", 1980)), // MooseDocs:producer
_real(declareValueByName<Real>("real")),
_vector(declareValueByName<std::vector<Real>>("vector")),
_string(declareValueByName<std::string>("string")),
_bcast_value(declareValueByName<Real, ReporterBroadcastContext>("broadcast")),
_scatter_value(
declareValueByName<dof_id_type, ReporterScatterContext>("scatter", _values_to_scatter)),
_gather_value(declareValueByName<std::vector<dof_id_type>, ReporterGatherContext>(
"gather")), // MooseDocs:gather
_distributed_vector(isParamValid("distributed_vector_name")
? &declareValue<std::vector<dof_id_type>>("distributed_vector_name",
REPORTER_MODE_DISTRIBUTED)
: nullptr)
{
if (processor_id() == 0)
for (dof_id_type rank = 0; rank < n_processors(); ++rank)
_values_to_scatter.push_back(rank);
}
// MooseDocs:execute_begin
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;
}
}
// MooseDocs:execute_end
InputParameters
TestGetReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("int_reporter", "'int' reporter name");
params.addRequiredParam<ReporterName>("real_reporter", "'real' reporter name");
params.addRequiredParam<ReporterName>("vector_reporter", "'vector' reporter name");
params.addRequiredParam<ReporterName>("string_reporter", "'string' reporter name");
params.addRequiredParam<ReporterName>("broadcast_reporter", "'broadcast' reporter name");
params.addRequiredParam<ReporterName>("scatter_reporter", "'scatter' reporter name");
params.addRequiredParam<ReporterName>("gather_reporter", "'gather' reporter name");
return params;
}
TestGetReporter::TestGetReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(getReporterValue<int>("int_reporter")),
_int_old(getReporterValue<int>("int_reporter", 1)),
_real(getReporterValue<Real>("real_reporter")),
_vector(getReporterValue<std::vector<Real>>("vector_reporter")), // MooseDocs:consumer
_string(getReporterValue<std::string>("string_reporter")),
_bcast_value(getReporterValue<Real>("broadcast_reporter")),
_scatter_value(getReporterValue<dof_id_type>("scatter_reporter")),
_gather_value(getReporterValue<std::vector<dof_id_type>>("gather_reporter"))
{
}
void
TestGetReporter::execute()
{
if (_int != 1980 + _t_step)
mooseError("int reporter test failed: ", _int, " != ", 1980 + _t_step);
if (_real != 1.2345)
mooseError("Real reporter test failed");
if (_vector != std::vector<Real>({1., 1.1, 1.2}))
mooseError("std::vector<Real> reporter test failed");
if (_string != "string")
mooseError("std::string reporter test failed");
if (_t_step == 0 && _int_old != 1980)
mooseError("int_old on timestep 0 failed: ", _int_old, " != ", 1980);
if (_t_step > 0 && _int_old != 1980 + (_t_step - 1))
mooseError(
"int_old on timestep ", _t_step, " failed: ", _int_old, " != ", 1980 + (_t_step - 1));
if (_bcast_value != 42)
mooseError("Broadcast reporter test failed");
if (_scatter_value != processor_id())
mooseError("Scatter reporter test failed");
if (processor_id() == 0)
{
std::vector<dof_id_type> gold;
for (dof_id_type id = 0; id < n_processors(); ++id)
gold.push_back(id);
if (_gather_value != gold)
mooseError("Gather reporter test failed!");
}
}
InputParameters
TestDeclareInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<Real>("value", "The value to report.");
return params;
}
TestDeclareInitialSetupReporter::TestDeclareInitialSetupReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
}
void
TestDeclareInitialSetupReporter::initialSetup()
{
Real & value = declareValueByName<Real>("value");
value = getParam<Real>("value");
}
InputParameters
TestGetReporterDeclaredInInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("other_reporter",
"The reporter name that was declared in initialSetup");
return params;
}
TestGetReporterDeclaredInInitialSetupReporter::TestGetReporterDeclaredInInitialSetupReporter(
const InputParameters & parameters)
: GeneralReporter(parameters),
_value_declared_in_initial_setup(getReporterValue<Real>("other_reporter")),
_the_value_of_the_reporter(declareValueByName<Real>("other_value"))
{
}
void
TestGetReporterDeclaredInInitialSetupReporter::execute()
{
_the_value_of_the_reporter = _value_declared_in_initial_setup;
}
InputParameters
TestDeclareErrorsReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterValueName>("value", "A reporter value name");
params.addParam<bool>("missing_param", false, "True to test the error for a missing parameter");
params.addParam<bool>("bad_param", false, "True to test the error for a bad parameter type");
params.addParam<bool>("already_declared", false, "Test declaring a value multiple times");
params.addParam<bool>("requested_different_type",
false,
"Test declaring a value that has been requested with a differentt type");
return params;
}
TestDeclareErrorsReporter::TestDeclareErrorsReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
if (getParam<bool>("missing_param"))
declareValue<int>("some_missing_parm");
if (getParam<bool>("bad_param"))
declareValue<int>("bad_param");
if (getParam<bool>("already_declared"))
{
declareValueByName<int>("value_name");
declareValueByName<Real>("value_name");
}
if (getParam<bool>("requested_different_type"))
{
getReporterValueByName<int>(name() + "/value_name");
declareValueByName<Real>("value_name");
}
}
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)
// This file is part of the MOOSE framework
// https://www.mooseframework.org
//
// All rights reserved, see COPYRIGHT for full restrictions
// https://github.com/idaholab/moose/blob/master/COPYRIGHT
//
// Licensed under LGPL 2.1, please see LICENSE for details
// https://www.gnu.org/licenses/lgpl-2.1.html
#include "TestReporter.h"
registerMooseObject("MooseTestApp", TestDeclareReporter);
registerMooseObject("MooseTestApp", TestGetReporter);
registerMooseObject("MooseTestApp", TestDeclareInitialSetupReporter);
registerMooseObject("MooseTestApp", TestGetReporterDeclaredInInitialSetupReporter);
registerMooseObject("MooseTestApp", TestDeclareErrorsReporter);
InputParameters
TestDeclareReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addParam<ReporterValueName>(
"int_name", "int", "The name of the interger data"); // MooseDocs:data
params.addParam<ReporterValueName>("distributed_vector_name",
"Distributed vector reporter to produce.");
return params;
}
TestDeclareReporter::TestDeclareReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(declareValue<int>("int_name", 1980)), // MooseDocs:producer
_real(declareValueByName<Real>("real")),
_vector(declareValueByName<std::vector<Real>>("vector")),
_string(declareValueByName<std::string>("string")),
_bcast_value(declareValueByName<Real, ReporterBroadcastContext>("broadcast")),
_scatter_value(
declareValueByName<dof_id_type, ReporterScatterContext>("scatter", _values_to_scatter)),
_gather_value(declareValueByName<std::vector<dof_id_type>, ReporterGatherContext>(
"gather")), // MooseDocs:gather
_distributed_vector(isParamValid("distributed_vector_name")
? &declareValue<std::vector<dof_id_type>>("distributed_vector_name",
REPORTER_MODE_DISTRIBUTED)
: nullptr)
{
if (processor_id() == 0)
for (dof_id_type rank = 0; rank < n_processors(); ++rank)
_values_to_scatter.push_back(rank);
}
// MooseDocs:execute_begin
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;
}
}
// MooseDocs:execute_end
InputParameters
TestGetReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("int_reporter", "'int' reporter name");
params.addRequiredParam<ReporterName>("real_reporter", "'real' reporter name");
params.addRequiredParam<ReporterName>("vector_reporter", "'vector' reporter name");
params.addRequiredParam<ReporterName>("string_reporter", "'string' reporter name");
params.addRequiredParam<ReporterName>("broadcast_reporter", "'broadcast' reporter name");
params.addRequiredParam<ReporterName>("scatter_reporter", "'scatter' reporter name");
params.addRequiredParam<ReporterName>("gather_reporter", "'gather' reporter name");
return params;
}
TestGetReporter::TestGetReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(getReporterValue<int>("int_reporter")),
_int_old(getReporterValue<int>("int_reporter", 1)),
_real(getReporterValue<Real>("real_reporter")),
_vector(getReporterValue<std::vector<Real>>("vector_reporter")), // MooseDocs:consumer
_string(getReporterValue<std::string>("string_reporter")),
_bcast_value(getReporterValue<Real>("broadcast_reporter")),
_scatter_value(getReporterValue<dof_id_type>("scatter_reporter")),
_gather_value(getReporterValue<std::vector<dof_id_type>>("gather_reporter"))
{
}
void
TestGetReporter::execute()
{
if (_int != 1980 + _t_step)
mooseError("int reporter test failed: ", _int, " != ", 1980 + _t_step);
if (_real != 1.2345)
mooseError("Real reporter test failed");
if (_vector != std::vector<Real>({1., 1.1, 1.2}))
mooseError("std::vector<Real> reporter test failed");
if (_string != "string")
mooseError("std::string reporter test failed");
if (_t_step == 0 && _int_old != 1980)
mooseError("int_old on timestep 0 failed: ", _int_old, " != ", 1980);
if (_t_step > 0 && _int_old != 1980 + (_t_step - 1))
mooseError(
"int_old on timestep ", _t_step, " failed: ", _int_old, " != ", 1980 + (_t_step - 1));
if (_bcast_value != 42)
mooseError("Broadcast reporter test failed");
if (_scatter_value != processor_id())
mooseError("Scatter reporter test failed");
if (processor_id() == 0)
{
std::vector<dof_id_type> gold;
for (dof_id_type id = 0; id < n_processors(); ++id)
gold.push_back(id);
if (_gather_value != gold)
mooseError("Gather reporter test failed!");
}
}
InputParameters
TestDeclareInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<Real>("value", "The value to report.");
return params;
}
TestDeclareInitialSetupReporter::TestDeclareInitialSetupReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
}
void
TestDeclareInitialSetupReporter::initialSetup()
{
Real & value = declareValueByName<Real>("value");
value = getParam<Real>("value");
}
InputParameters
TestGetReporterDeclaredInInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("other_reporter",
"The reporter name that was declared in initialSetup");
return params;
}
TestGetReporterDeclaredInInitialSetupReporter::TestGetReporterDeclaredInInitialSetupReporter(
const InputParameters & parameters)
: GeneralReporter(parameters),
_value_declared_in_initial_setup(getReporterValue<Real>("other_reporter")),
_the_value_of_the_reporter(declareValueByName<Real>("other_value"))
{
}
void
TestGetReporterDeclaredInInitialSetupReporter::execute()
{
_the_value_of_the_reporter = _value_declared_in_initial_setup;
}
InputParameters
TestDeclareErrorsReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterValueName>("value", "A reporter value name");
params.addParam<bool>("missing_param", false, "True to test the error for a missing parameter");
params.addParam<bool>("bad_param", false, "True to test the error for a bad parameter type");
params.addParam<bool>("already_declared", false, "Test declaring a value multiple times");
params.addParam<bool>("requested_different_type",
false,
"Test declaring a value that has been requested with a differentt type");
return params;
}
TestDeclareErrorsReporter::TestDeclareErrorsReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
if (getParam<bool>("missing_param"))
declareValue<int>("some_missing_parm");
if (getParam<bool>("bad_param"))
declareValue<int>("bad_param");
if (getParam<bool>("already_declared"))
{
declareValueByName<int>("value_name");
declareValueByName<Real>("value_name");
}
if (getParam<bool>("requested_different_type"))
{
getReporterValueByName<int>(name() + "/value_name");
declareValueByName<Real>("value_name");
}
}
(../../../SoftwareDownloads/moose/test/include/reporters/TestReporter.h)
// This file is part of the MOOSE framework
// https://www.mooseframework.org
//
// All rights reserved, see COPYRIGHT for full restrictions
// https://github.com/idaholab/moose/blob/master/COPYRIGHT
//
// Licensed under LGPL 2.1, please see LICENSE for details
// https://www.gnu.org/licenses/lgpl-2.1.html
#pragma once
#include "GeneralReporter.h"
class TestDeclareReporter : public GeneralReporter
{
public:
static InputParameters validParams();
TestDeclareReporter(const InputParameters & parameters);
virtual void initialize() override {}
virtual void finalize() override {}
virtual void execute() override;
protected:
int & _int; // MooseDocs:producer
Real & _real;
std::vector<Real> & _vector;
std::string & _string;
Real & _bcast_value;
std::vector<dof_id_type> _values_to_scatter;
dof_id_type & _scatter_value;
std::vector<dof_id_type> _values_to_gather;
std::vector<dof_id_type> & _gather_value;
std::vector<dof_id_type> * _distributed_vector;
};
class TestGetReporter : public GeneralReporter
{
public:
static InputParameters validParams();
TestGetReporter(const InputParameters & parameters);
virtual void initialize() override {}
virtual void finalize() override {}
virtual void execute() override;
protected:
const int & _int;
const int & _int_old;
const Real & _real;
const std::vector<Real> & _vector; // MooseDocs:consumer
const std::string & _string;
const Real & _bcast_value;
const dof_id_type & _scatter_value;
const std::vector<dof_id_type> & _gather_value;
};
class TestDeclareInitialSetupReporter : public GeneralReporter
{
public:
static InputParameters validParams();
TestDeclareInitialSetupReporter(const InputParameters & parameters);
virtual void initialSetup() override;
virtual void initialize() override {}
virtual void finalize() override {}
virtual void execute() override {}
};
class TestGetReporterDeclaredInInitialSetupReporter : public GeneralReporter
{
public:
static InputParameters validParams();
TestGetReporterDeclaredInInitialSetupReporter(const InputParameters & parameters);
virtual void initialize() override {}
virtual void finalize() override {}
virtual void execute() override;
protected:
const Real & _value_declared_in_initial_setup;
Real & _the_value_of_the_reporter;
};
class TestDeclareErrorsReporter : public GeneralReporter
{
public:
static InputParameters validParams();
TestDeclareErrorsReporter(const InputParameters & parameters);
virtual void initialize() override {}
virtual void finalize() override {}
virtual void execute() override {}
};
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)
// This file is part of the MOOSE framework
// https://www.mooseframework.org
//
// All rights reserved, see COPYRIGHT for full restrictions
// https://github.com/idaholab/moose/blob/master/COPYRIGHT
//
// Licensed under LGPL 2.1, please see LICENSE for details
// https://www.gnu.org/licenses/lgpl-2.1.html
#include "TestReporter.h"
registerMooseObject("MooseTestApp", TestDeclareReporter);
registerMooseObject("MooseTestApp", TestGetReporter);
registerMooseObject("MooseTestApp", TestDeclareInitialSetupReporter);
registerMooseObject("MooseTestApp", TestGetReporterDeclaredInInitialSetupReporter);
registerMooseObject("MooseTestApp", TestDeclareErrorsReporter);
InputParameters
TestDeclareReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addParam<ReporterValueName>(
"int_name", "int", "The name of the interger data"); // MooseDocs:data
params.addParam<ReporterValueName>("distributed_vector_name",
"Distributed vector reporter to produce.");
return params;
}
TestDeclareReporter::TestDeclareReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(declareValue<int>("int_name", 1980)), // MooseDocs:producer
_real(declareValueByName<Real>("real")),
_vector(declareValueByName<std::vector<Real>>("vector")),
_string(declareValueByName<std::string>("string")),
_bcast_value(declareValueByName<Real, ReporterBroadcastContext>("broadcast")),
_scatter_value(
declareValueByName<dof_id_type, ReporterScatterContext>("scatter", _values_to_scatter)),
_gather_value(declareValueByName<std::vector<dof_id_type>, ReporterGatherContext>(
"gather")), // MooseDocs:gather
_distributed_vector(isParamValid("distributed_vector_name")
? &declareValue<std::vector<dof_id_type>>("distributed_vector_name",
REPORTER_MODE_DISTRIBUTED)
: nullptr)
{
if (processor_id() == 0)
for (dof_id_type rank = 0; rank < n_processors(); ++rank)
_values_to_scatter.push_back(rank);
}
// MooseDocs:execute_begin
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;
}
}
// MooseDocs:execute_end
InputParameters
TestGetReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("int_reporter", "'int' reporter name");
params.addRequiredParam<ReporterName>("real_reporter", "'real' reporter name");
params.addRequiredParam<ReporterName>("vector_reporter", "'vector' reporter name");
params.addRequiredParam<ReporterName>("string_reporter", "'string' reporter name");
params.addRequiredParam<ReporterName>("broadcast_reporter", "'broadcast' reporter name");
params.addRequiredParam<ReporterName>("scatter_reporter", "'scatter' reporter name");
params.addRequiredParam<ReporterName>("gather_reporter", "'gather' reporter name");
return params;
}
TestGetReporter::TestGetReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(getReporterValue<int>("int_reporter")),
_int_old(getReporterValue<int>("int_reporter", 1)),
_real(getReporterValue<Real>("real_reporter")),
_vector(getReporterValue<std::vector<Real>>("vector_reporter")), // MooseDocs:consumer
_string(getReporterValue<std::string>("string_reporter")),
_bcast_value(getReporterValue<Real>("broadcast_reporter")),
_scatter_value(getReporterValue<dof_id_type>("scatter_reporter")),
_gather_value(getReporterValue<std::vector<dof_id_type>>("gather_reporter"))
{
}
void
TestGetReporter::execute()
{
if (_int != 1980 + _t_step)
mooseError("int reporter test failed: ", _int, " != ", 1980 + _t_step);
if (_real != 1.2345)
mooseError("Real reporter test failed");
if (_vector != std::vector<Real>({1., 1.1, 1.2}))
mooseError("std::vector<Real> reporter test failed");
if (_string != "string")
mooseError("std::string reporter test failed");
if (_t_step == 0 && _int_old != 1980)
mooseError("int_old on timestep 0 failed: ", _int_old, " != ", 1980);
if (_t_step > 0 && _int_old != 1980 + (_t_step - 1))
mooseError(
"int_old on timestep ", _t_step, " failed: ", _int_old, " != ", 1980 + (_t_step - 1));
if (_bcast_value != 42)
mooseError("Broadcast reporter test failed");
if (_scatter_value != processor_id())
mooseError("Scatter reporter test failed");
if (processor_id() == 0)
{
std::vector<dof_id_type> gold;
for (dof_id_type id = 0; id < n_processors(); ++id)
gold.push_back(id);
if (_gather_value != gold)
mooseError("Gather reporter test failed!");
}
}
InputParameters
TestDeclareInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<Real>("value", "The value to report.");
return params;
}
TestDeclareInitialSetupReporter::TestDeclareInitialSetupReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
}
void
TestDeclareInitialSetupReporter::initialSetup()
{
Real & value = declareValueByName<Real>("value");
value = getParam<Real>("value");
}
InputParameters
TestGetReporterDeclaredInInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("other_reporter",
"The reporter name that was declared in initialSetup");
return params;
}
TestGetReporterDeclaredInInitialSetupReporter::TestGetReporterDeclaredInInitialSetupReporter(
const InputParameters & parameters)
: GeneralReporter(parameters),
_value_declared_in_initial_setup(getReporterValue<Real>("other_reporter")),
_the_value_of_the_reporter(declareValueByName<Real>("other_value"))
{
}
void
TestGetReporterDeclaredInInitialSetupReporter::execute()
{
_the_value_of_the_reporter = _value_declared_in_initial_setup;
}
InputParameters
TestDeclareErrorsReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterValueName>("value", "A reporter value name");
params.addParam<bool>("missing_param", false, "True to test the error for a missing parameter");
params.addParam<bool>("bad_param", false, "True to test the error for a bad parameter type");
params.addParam<bool>("already_declared", false, "Test declaring a value multiple times");
params.addParam<bool>("requested_different_type",
false,
"Test declaring a value that has been requested with a differentt type");
return params;
}
TestDeclareErrorsReporter::TestDeclareErrorsReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
if (getParam<bool>("missing_param"))
declareValue<int>("some_missing_parm");
if (getParam<bool>("bad_param"))
declareValue<int>("bad_param");
if (getParam<bool>("already_declared"))
{
declareValueByName<int>("value_name");
declareValueByName<Real>("value_name");
}
if (getParam<bool>("requested_different_type"))
{
getReporterValueByName<int>(name() + "/value_name");
declareValueByName<Real>("value_name");
}
}
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)
// This file is part of the MOOSE framework
// https://www.mooseframework.org
//
// All rights reserved, see COPYRIGHT for full restrictions
// https://github.com/idaholab/moose/blob/master/COPYRIGHT
//
// Licensed under LGPL 2.1, please see LICENSE for details
// https://www.gnu.org/licenses/lgpl-2.1.html
#include "TestReporter.h"
registerMooseObject("MooseTestApp", TestDeclareReporter);
registerMooseObject("MooseTestApp", TestGetReporter);
registerMooseObject("MooseTestApp", TestDeclareInitialSetupReporter);
registerMooseObject("MooseTestApp", TestGetReporterDeclaredInInitialSetupReporter);
registerMooseObject("MooseTestApp", TestDeclareErrorsReporter);
InputParameters
TestDeclareReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addParam<ReporterValueName>(
"int_name", "int", "The name of the interger data"); // MooseDocs:data
params.addParam<ReporterValueName>("distributed_vector_name",
"Distributed vector reporter to produce.");
return params;
}
TestDeclareReporter::TestDeclareReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(declareValue<int>("int_name", 1980)), // MooseDocs:producer
_real(declareValueByName<Real>("real")),
_vector(declareValueByName<std::vector<Real>>("vector")),
_string(declareValueByName<std::string>("string")),
_bcast_value(declareValueByName<Real, ReporterBroadcastContext>("broadcast")),
_scatter_value(
declareValueByName<dof_id_type, ReporterScatterContext>("scatter", _values_to_scatter)),
_gather_value(declareValueByName<std::vector<dof_id_type>, ReporterGatherContext>(
"gather")), // MooseDocs:gather
_distributed_vector(isParamValid("distributed_vector_name")
? &declareValue<std::vector<dof_id_type>>("distributed_vector_name",
REPORTER_MODE_DISTRIBUTED)
: nullptr)
{
if (processor_id() == 0)
for (dof_id_type rank = 0; rank < n_processors(); ++rank)
_values_to_scatter.push_back(rank);
}
// MooseDocs:execute_begin
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;
}
}
// MooseDocs:execute_end
InputParameters
TestGetReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("int_reporter", "'int' reporter name");
params.addRequiredParam<ReporterName>("real_reporter", "'real' reporter name");
params.addRequiredParam<ReporterName>("vector_reporter", "'vector' reporter name");
params.addRequiredParam<ReporterName>("string_reporter", "'string' reporter name");
params.addRequiredParam<ReporterName>("broadcast_reporter", "'broadcast' reporter name");
params.addRequiredParam<ReporterName>("scatter_reporter", "'scatter' reporter name");
params.addRequiredParam<ReporterName>("gather_reporter", "'gather' reporter name");
return params;
}
TestGetReporter::TestGetReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(getReporterValue<int>("int_reporter")),
_int_old(getReporterValue<int>("int_reporter", 1)),
_real(getReporterValue<Real>("real_reporter")),
_vector(getReporterValue<std::vector<Real>>("vector_reporter")), // MooseDocs:consumer
_string(getReporterValue<std::string>("string_reporter")),
_bcast_value(getReporterValue<Real>("broadcast_reporter")),
_scatter_value(getReporterValue<dof_id_type>("scatter_reporter")),
_gather_value(getReporterValue<std::vector<dof_id_type>>("gather_reporter"))
{
}
void
TestGetReporter::execute()
{
if (_int != 1980 + _t_step)
mooseError("int reporter test failed: ", _int, " != ", 1980 + _t_step);
if (_real != 1.2345)
mooseError("Real reporter test failed");
if (_vector != std::vector<Real>({1., 1.1, 1.2}))
mooseError("std::vector<Real> reporter test failed");
if (_string != "string")
mooseError("std::string reporter test failed");
if (_t_step == 0 && _int_old != 1980)
mooseError("int_old on timestep 0 failed: ", _int_old, " != ", 1980);
if (_t_step > 0 && _int_old != 1980 + (_t_step - 1))
mooseError(
"int_old on timestep ", _t_step, " failed: ", _int_old, " != ", 1980 + (_t_step - 1));
if (_bcast_value != 42)
mooseError("Broadcast reporter test failed");
if (_scatter_value != processor_id())
mooseError("Scatter reporter test failed");
if (processor_id() == 0)
{
std::vector<dof_id_type> gold;
for (dof_id_type id = 0; id < n_processors(); ++id)
gold.push_back(id);
if (_gather_value != gold)
mooseError("Gather reporter test failed!");
}
}
InputParameters
TestDeclareInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<Real>("value", "The value to report.");
return params;
}
TestDeclareInitialSetupReporter::TestDeclareInitialSetupReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
}
void
TestDeclareInitialSetupReporter::initialSetup()
{
Real & value = declareValueByName<Real>("value");
value = getParam<Real>("value");
}
InputParameters
TestGetReporterDeclaredInInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("other_reporter",
"The reporter name that was declared in initialSetup");
return params;
}
TestGetReporterDeclaredInInitialSetupReporter::TestGetReporterDeclaredInInitialSetupReporter(
const InputParameters & parameters)
: GeneralReporter(parameters),
_value_declared_in_initial_setup(getReporterValue<Real>("other_reporter")),
_the_value_of_the_reporter(declareValueByName<Real>("other_value"))
{
}
void
TestGetReporterDeclaredInInitialSetupReporter::execute()
{
_the_value_of_the_reporter = _value_declared_in_initial_setup;
}
InputParameters
TestDeclareErrorsReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterValueName>("value", "A reporter value name");
params.addParam<bool>("missing_param", false, "True to test the error for a missing parameter");
params.addParam<bool>("bad_param", false, "True to test the error for a bad parameter type");
params.addParam<bool>("already_declared", false, "Test declaring a value multiple times");
params.addParam<bool>("requested_different_type",
false,
"Test declaring a value that has been requested with a differentt type");
return params;
}
TestDeclareErrorsReporter::TestDeclareErrorsReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
if (getParam<bool>("missing_param"))
declareValue<int>("some_missing_parm");
if (getParam<bool>("bad_param"))
declareValue<int>("bad_param");
if (getParam<bool>("already_declared"))
{
declareValueByName<int>("value_name");
declareValueByName<Real>("value_name");
}
if (getParam<bool>("requested_different_type"))
{
getReporterValueByName<int>(name() + "/value_name");
declareValueByName<Real>("value_name");
}
}
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)
// This file is part of the MOOSE framework
// https://www.mooseframework.org
//
// All rights reserved, see COPYRIGHT for full restrictions
// https://github.com/idaholab/moose/blob/master/COPYRIGHT
//
// Licensed under LGPL 2.1, please see LICENSE for details
// https://www.gnu.org/licenses/lgpl-2.1.html
#include "TestReporter.h"
registerMooseObject("MooseTestApp", TestDeclareReporter);
registerMooseObject("MooseTestApp", TestGetReporter);
registerMooseObject("MooseTestApp", TestDeclareInitialSetupReporter);
registerMooseObject("MooseTestApp", TestGetReporterDeclaredInInitialSetupReporter);
registerMooseObject("MooseTestApp", TestDeclareErrorsReporter);
InputParameters
TestDeclareReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addParam<ReporterValueName>(
"int_name", "int", "The name of the interger data"); // MooseDocs:data
params.addParam<ReporterValueName>("distributed_vector_name",
"Distributed vector reporter to produce.");
return params;
}
TestDeclareReporter::TestDeclareReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(declareValue<int>("int_name", 1980)), // MooseDocs:producer
_real(declareValueByName<Real>("real")),
_vector(declareValueByName<std::vector<Real>>("vector")),
_string(declareValueByName<std::string>("string")),
_bcast_value(declareValueByName<Real, ReporterBroadcastContext>("broadcast")),
_scatter_value(
declareValueByName<dof_id_type, ReporterScatterContext>("scatter", _values_to_scatter)),
_gather_value(declareValueByName<std::vector<dof_id_type>, ReporterGatherContext>(
"gather")), // MooseDocs:gather
_distributed_vector(isParamValid("distributed_vector_name")
? &declareValue<std::vector<dof_id_type>>("distributed_vector_name",
REPORTER_MODE_DISTRIBUTED)
: nullptr)
{
if (processor_id() == 0)
for (dof_id_type rank = 0; rank < n_processors(); ++rank)
_values_to_scatter.push_back(rank);
}
// MooseDocs:execute_begin
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;
}
}
// MooseDocs:execute_end
InputParameters
TestGetReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("int_reporter", "'int' reporter name");
params.addRequiredParam<ReporterName>("real_reporter", "'real' reporter name");
params.addRequiredParam<ReporterName>("vector_reporter", "'vector' reporter name");
params.addRequiredParam<ReporterName>("string_reporter", "'string' reporter name");
params.addRequiredParam<ReporterName>("broadcast_reporter", "'broadcast' reporter name");
params.addRequiredParam<ReporterName>("scatter_reporter", "'scatter' reporter name");
params.addRequiredParam<ReporterName>("gather_reporter", "'gather' reporter name");
return params;
}
TestGetReporter::TestGetReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(getReporterValue<int>("int_reporter")),
_int_old(getReporterValue<int>("int_reporter", 1)),
_real(getReporterValue<Real>("real_reporter")),
_vector(getReporterValue<std::vector<Real>>("vector_reporter")), // MooseDocs:consumer
_string(getReporterValue<std::string>("string_reporter")),
_bcast_value(getReporterValue<Real>("broadcast_reporter")),
_scatter_value(getReporterValue<dof_id_type>("scatter_reporter")),
_gather_value(getReporterValue<std::vector<dof_id_type>>("gather_reporter"))
{
}
void
TestGetReporter::execute()
{
if (_int != 1980 + _t_step)
mooseError("int reporter test failed: ", _int, " != ", 1980 + _t_step);
if (_real != 1.2345)
mooseError("Real reporter test failed");
if (_vector != std::vector<Real>({1., 1.1, 1.2}))
mooseError("std::vector<Real> reporter test failed");
if (_string != "string")
mooseError("std::string reporter test failed");
if (_t_step == 0 && _int_old != 1980)
mooseError("int_old on timestep 0 failed: ", _int_old, " != ", 1980);
if (_t_step > 0 && _int_old != 1980 + (_t_step - 1))
mooseError(
"int_old on timestep ", _t_step, " failed: ", _int_old, " != ", 1980 + (_t_step - 1));
if (_bcast_value != 42)
mooseError("Broadcast reporter test failed");
if (_scatter_value != processor_id())
mooseError("Scatter reporter test failed");
if (processor_id() == 0)
{
std::vector<dof_id_type> gold;
for (dof_id_type id = 0; id < n_processors(); ++id)
gold.push_back(id);
if (_gather_value != gold)
mooseError("Gather reporter test failed!");
}
}
InputParameters
TestDeclareInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<Real>("value", "The value to report.");
return params;
}
TestDeclareInitialSetupReporter::TestDeclareInitialSetupReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
}
void
TestDeclareInitialSetupReporter::initialSetup()
{
Real & value = declareValueByName<Real>("value");
value = getParam<Real>("value");
}
InputParameters
TestGetReporterDeclaredInInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("other_reporter",
"The reporter name that was declared in initialSetup");
return params;
}
TestGetReporterDeclaredInInitialSetupReporter::TestGetReporterDeclaredInInitialSetupReporter(
const InputParameters & parameters)
: GeneralReporter(parameters),
_value_declared_in_initial_setup(getReporterValue<Real>("other_reporter")),
_the_value_of_the_reporter(declareValueByName<Real>("other_value"))
{
}
void
TestGetReporterDeclaredInInitialSetupReporter::execute()
{
_the_value_of_the_reporter = _value_declared_in_initial_setup;
}
InputParameters
TestDeclareErrorsReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterValueName>("value", "A reporter value name");
params.addParam<bool>("missing_param", false, "True to test the error for a missing parameter");
params.addParam<bool>("bad_param", false, "True to test the error for a bad parameter type");
params.addParam<bool>("already_declared", false, "Test declaring a value multiple times");
params.addParam<bool>("requested_different_type",
false,
"Test declaring a value that has been requested with a differentt type");
return params;
}
TestDeclareErrorsReporter::TestDeclareErrorsReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
if (getParam<bool>("missing_param"))
declareValue<int>("some_missing_parm");
if (getParam<bool>("bad_param"))
declareValue<int>("bad_param");
if (getParam<bool>("already_declared"))
{
declareValueByName<int>("value_name");
declareValueByName<Real>("value_name");
}
if (getParam<bool>("requested_different_type"))
{
getReporterValueByName<int>(name() + "/value_name");
declareValueByName<Real>("value_name");
}
}
(../../../SoftwareDownloads/moose/test/tests/reporters/base/base.i)
[Mesh]
type = GeneratedMesh
dim = 1
[]
[Variables/u]
[]
[Problem]
solve = false
kernel_coverage_check = false
[]
[Reporters]
[b]
type = TestGetReporter
int_reporter = a/int
real_reporter = a/real
vector_reporter = a/vector
string_reporter = a/string
broadcast_reporter = a/broadcast
scatter_reporter = a/scatter
gather_reporter = a/gather
[]
[a]
type = TestDeclareReporter
[]
[]
[Executioner]
type = Transient
num_steps = 3
[]
(../../../SoftwareDownloads/moose/test/src/reporters/TestReporter.C)
// This file is part of the MOOSE framework
// https://www.mooseframework.org
//
// All rights reserved, see COPYRIGHT for full restrictions
// https://github.com/idaholab/moose/blob/master/COPYRIGHT
//
// Licensed under LGPL 2.1, please see LICENSE for details
// https://www.gnu.org/licenses/lgpl-2.1.html
#include "TestReporter.h"
registerMooseObject("MooseTestApp", TestDeclareReporter);
registerMooseObject("MooseTestApp", TestGetReporter);
registerMooseObject("MooseTestApp", TestDeclareInitialSetupReporter);
registerMooseObject("MooseTestApp", TestGetReporterDeclaredInInitialSetupReporter);
registerMooseObject("MooseTestApp", TestDeclareErrorsReporter);
InputParameters
TestDeclareReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addParam<ReporterValueName>(
"int_name", "int", "The name of the interger data"); // MooseDocs:data
params.addParam<ReporterValueName>("distributed_vector_name",
"Distributed vector reporter to produce.");
return params;
}
TestDeclareReporter::TestDeclareReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(declareValue<int>("int_name", 1980)), // MooseDocs:producer
_real(declareValueByName<Real>("real")),
_vector(declareValueByName<std::vector<Real>>("vector")),
_string(declareValueByName<std::string>("string")),
_bcast_value(declareValueByName<Real, ReporterBroadcastContext>("broadcast")),
_scatter_value(
declareValueByName<dof_id_type, ReporterScatterContext>("scatter", _values_to_scatter)),
_gather_value(declareValueByName<std::vector<dof_id_type>, ReporterGatherContext>(
"gather")), // MooseDocs:gather
_distributed_vector(isParamValid("distributed_vector_name")
? &declareValue<std::vector<dof_id_type>>("distributed_vector_name",
REPORTER_MODE_DISTRIBUTED)
: nullptr)
{
if (processor_id() == 0)
for (dof_id_type rank = 0; rank < n_processors(); ++rank)
_values_to_scatter.push_back(rank);
}
// MooseDocs:execute_begin
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;
}
}
// MooseDocs:execute_end
InputParameters
TestGetReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("int_reporter", "'int' reporter name");
params.addRequiredParam<ReporterName>("real_reporter", "'real' reporter name");
params.addRequiredParam<ReporterName>("vector_reporter", "'vector' reporter name");
params.addRequiredParam<ReporterName>("string_reporter", "'string' reporter name");
params.addRequiredParam<ReporterName>("broadcast_reporter", "'broadcast' reporter name");
params.addRequiredParam<ReporterName>("scatter_reporter", "'scatter' reporter name");
params.addRequiredParam<ReporterName>("gather_reporter", "'gather' reporter name");
return params;
}
TestGetReporter::TestGetReporter(const InputParameters & parameters)
: GeneralReporter(parameters),
_int(getReporterValue<int>("int_reporter")),
_int_old(getReporterValue<int>("int_reporter", 1)),
_real(getReporterValue<Real>("real_reporter")),
_vector(getReporterValue<std::vector<Real>>("vector_reporter")), // MooseDocs:consumer
_string(getReporterValue<std::string>("string_reporter")),
_bcast_value(getReporterValue<Real>("broadcast_reporter")),
_scatter_value(getReporterValue<dof_id_type>("scatter_reporter")),
_gather_value(getReporterValue<std::vector<dof_id_type>>("gather_reporter"))
{
}
void
TestGetReporter::execute()
{
if (_int != 1980 + _t_step)
mooseError("int reporter test failed: ", _int, " != ", 1980 + _t_step);
if (_real != 1.2345)
mooseError("Real reporter test failed");
if (_vector != std::vector<Real>({1., 1.1, 1.2}))
mooseError("std::vector<Real> reporter test failed");
if (_string != "string")
mooseError("std::string reporter test failed");
if (_t_step == 0 && _int_old != 1980)
mooseError("int_old on timestep 0 failed: ", _int_old, " != ", 1980);
if (_t_step > 0 && _int_old != 1980 + (_t_step - 1))
mooseError(
"int_old on timestep ", _t_step, " failed: ", _int_old, " != ", 1980 + (_t_step - 1));
if (_bcast_value != 42)
mooseError("Broadcast reporter test failed");
if (_scatter_value != processor_id())
mooseError("Scatter reporter test failed");
if (processor_id() == 0)
{
std::vector<dof_id_type> gold;
for (dof_id_type id = 0; id < n_processors(); ++id)
gold.push_back(id);
if (_gather_value != gold)
mooseError("Gather reporter test failed!");
}
}
InputParameters
TestDeclareInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<Real>("value", "The value to report.");
return params;
}
TestDeclareInitialSetupReporter::TestDeclareInitialSetupReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
}
void
TestDeclareInitialSetupReporter::initialSetup()
{
Real & value = declareValueByName<Real>("value");
value = getParam<Real>("value");
}
InputParameters
TestGetReporterDeclaredInInitialSetupReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterName>("other_reporter",
"The reporter name that was declared in initialSetup");
return params;
}
TestGetReporterDeclaredInInitialSetupReporter::TestGetReporterDeclaredInInitialSetupReporter(
const InputParameters & parameters)
: GeneralReporter(parameters),
_value_declared_in_initial_setup(getReporterValue<Real>("other_reporter")),
_the_value_of_the_reporter(declareValueByName<Real>("other_value"))
{
}
void
TestGetReporterDeclaredInInitialSetupReporter::execute()
{
_the_value_of_the_reporter = _value_declared_in_initial_setup;
}
InputParameters
TestDeclareErrorsReporter::validParams()
{
InputParameters params = GeneralReporter::validParams();
params.addRequiredParam<ReporterValueName>("value", "A reporter value name");
params.addParam<bool>("missing_param", false, "True to test the error for a missing parameter");
params.addParam<bool>("bad_param", false, "True to test the error for a bad parameter type");
params.addParam<bool>("already_declared", false, "Test declaring a value multiple times");
params.addParam<bool>("requested_different_type",
false,
"Test declaring a value that has been requested with a differentt type");
return params;
}
TestDeclareErrorsReporter::TestDeclareErrorsReporter(const InputParameters & parameters)
: GeneralReporter(parameters)
{
if (getParam<bool>("missing_param"))
declareValue<int>("some_missing_parm");
if (getParam<bool>("bad_param"))
declareValue<int>("bad_param");
if (getParam<bool>("already_declared"))
{
declareValueByName<int>("value_name");
declareValueByName<Real>("value_name");
}
if (getParam<bool>("requested_different_type"))
{
getReporterValueByName<int>(name() + "/value_name");
declareValueByName<Real>("value_name");
}
}