Skip to content

Commit

Permalink
Add object for outputting Reporter debug information
Browse files Browse the repository at this point in the history
  • Loading branch information
loganharbour committed Apr 14, 2021
1 parent 686a234 commit 3bbc7d7
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 3 deletions.
15 changes: 15 additions & 0 deletions framework/doc/content/source/outputs/ReporterDebugOutput.md
@@ -0,0 +1,15 @@
# ReporterDebugOutput

!syntax description /Outputs/ReporterDebugOutput

## Overview

The ReporterDebugOutput object is, as the name suggests, designed to write out material
property information for debugging purposes. Please refer to the [Debug/index.md] for
more information.

!syntax parameters /Outputs/ReporterDebugOutput

!syntax inputs /Outputs/ReporterDebugOutput

!syntax children /Outputs/ReporterDebugOutput
3 changes: 3 additions & 0 deletions framework/doc/content/syntax/Reporters/index.md
Expand Up @@ -139,6 +139,9 @@ Automatically performs an MPI scatter of a vector of data on the root processor
`ReporterGatherContext`\\
Automatically performs an MPI gather to a vector of data on the root processor from all processors.

## Reporter Debug Output

The [ReporterDebugOutput.md] 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.

!syntax list /Reporters objects=True actions=False subsystems=False

Expand Down
30 changes: 30 additions & 0 deletions framework/include/outputs/ReporterDebugOutput.h
@@ -0,0 +1,30 @@
//* 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

// MOOSE includes
#include "Output.h"

/**
* Produces debug output for displaying Reporter information
*/
class ReporterDebugOutput : public Output
{
public:
static InputParameters validParams();
ReporterDebugOutput(const InputParameters & parameters);

protected:
/**
* Perform the debugging output
* For this object this is empty; the output is preformed in the constructor
*/
void output(const ExecFlagType & type) override;
};
5 changes: 5 additions & 0 deletions framework/include/reporters/ReporterData.h
Expand Up @@ -237,6 +237,11 @@ class ReporterData
*/
std::string getReporterInfo(const ReporterName & reporter_name) const;

/**
* Gets information about all declared/requested Reporters.
*/
std::string getReporterInfo() const;

private:
/// For accessing the restart/recover system, which is where Reporter values are stored
MooseApp & _app;
Expand Down
10 changes: 10 additions & 0 deletions framework/src/actions/SetupDebugAction.C
Expand Up @@ -39,6 +39,8 @@ SetupDebugAction::validParams()
false,
"Print out the material properties supplied for each block, face, neighbor, and/or sideset");
params.addParam<bool>("show_mesh_meta_data", false, "Print out the available mesh meta data");
params.addParam<bool>(
"show_reporters", false, "Print out information about the declared and requested Reporters");
params.addParam<bool>(
"pid_aux",
false,
Expand Down Expand Up @@ -94,6 +96,14 @@ SetupDebugAction::act()
_console << " " << pair.first << std::endl;
}

// Print Reporter information
if (getParam<bool>("show_reporters"))
{
const std::string type = "ReporterDebugOutput";
auto params = _factory.getValidParams(type);
_problem->addOutput(type, "_moose_reporter_debug_output", params);
}

// Add pid aux
if (getParam<bool>("pid_aux"))
{
Expand Down
35 changes: 35 additions & 0 deletions framework/src/outputs/ReporterDebugOutput.C
@@ -0,0 +1,35 @@
//* 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 "ReporterDebugOutput.h"

// MOOSE includes
#include "FEProblemBase.h"

registerMooseObject("MooseApp", ReporterDebugOutput);

InputParameters
ReporterDebugOutput::validParams()
{
InputParameters params = Output::validParams();
params.addClassDescription("Debug output object for displaying Reporter information.");
params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL;
return params;
}

ReporterDebugOutput::ReporterDebugOutput(const InputParameters & parameters) : Output(parameters) {}

void
ReporterDebugOutput::output(const ExecFlagType & /*type*/)
{
_console << "\nDeclared/requested Reporter Information:\n\n "
<< MooseUtils::replaceAll(
_problem_ptr->getReporterData().getReporterInfo(), "\n", "\n ")
<< "\n";
}
12 changes: 9 additions & 3 deletions framework/src/reporters/ReporterData.C
Expand Up @@ -79,11 +79,8 @@ ReporterData::check() const
{
std::string missing;
for (const auto & name_state_pair : _states)
{
std::cerr << getReporterInfo(name_state_pair.first) << std::endl;
if (!name_state_pair.second->hasProducer())
missing += getReporterInfo(name_state_pair.first) + "\n";
}

if (missing.size())
mooseError("The following Reporter(s) were not declared:\n\n", missing);
Expand Down Expand Up @@ -127,3 +124,12 @@ ReporterData::getReporterInfo(const ReporterName & reporter_name) const
hasReporterValue(reporter_name) ? &getReporterContextBase(reporter_name) : nullptr;
return getReporterStateBase(reporter_name).getInfo(context);
}

std::string
ReporterData::getReporterInfo() const
{
std::string out = _states.empty() ? "No reporters were requested or declared." : "";
for (const auto & name : getReporterNames())
out += getReporterInfo(name) + "\n";
return out;
}
46 changes: 46 additions & 0 deletions test/tests/actions/debug_show_reporters/debug_show_reporters.i
@@ -0,0 +1,46 @@
[Mesh]
[gmg]
type = GeneratedMeshGenerator
dim = 1
[]
[]

[Postprocessors]
[scale]
type = ScalePostprocessor
value = function
scaling_factor = 2
[]
[function]
type = FunctionValuePostprocessor
function = 1
[]
[]

[VectorPostprocessors/constant_vpp]
type = ConstantVectorPostprocessor
vector_names = 'value1 value2'
value = '1; 2'
[]

[Reporters/constant_reporter]
type = ConstantReporter
integer_names = integer
integer_values = 1
real_names = real
real_values = 2
string_names = string
string_values = 'funny'
[]

[Debug]
show_reporters = true
[]

[Problem]
solve = false
[]

[Executioner]
type = Steady
[]
9 changes: 9 additions & 0 deletions test/tests/actions/debug_show_reporters/tests
@@ -0,0 +1,9 @@
[Tests]
[test]
type = RunApp
input = 'debug_show_reporters.i'
expect_out = 'Reporter "constant_reporter/integer":.*ReporterGeneralContext<std::string>.*VectorPostprocessor "constant_vpp/value1":.*Postprocessor "function":.*ScalePostprocessor "scale" \(mode: ROOT\)'

requirement = 'The system shall support the detailed on-screen output of all of the Reporters that were declared and requested, including type, producer, context, and consumers.'
[]
[]

0 comments on commit 3bbc7d7

Please sign in to comment.