From 9f8624938637acf723a9875d07fe15b182305f0e Mon Sep 17 00:00:00 2001 From: Logan Harbour Date: Wed, 14 Apr 2021 10:05:29 -0600 Subject: [PATCH] Add object for outputting Reporter debug information refs #17605 --- .../source/outputs/ReporterDebugOutput.md | 15 ++++++ .../doc/content/syntax/Reporters/index.md | 3 ++ .../include/outputs/ReporterDebugOutput.h | 26 +++++++++++ framework/include/reporters/ReporterData.h | 5 ++ framework/src/actions/SetupDebugAction.C | 10 ++++ framework/src/outputs/ReporterDebugOutput.C | 35 ++++++++++++++ framework/src/reporters/ReporterData.C | 12 +++-- .../debug_show_reporters.i | 46 +++++++++++++++++++ test/tests/actions/debug_show_reporters/tests | 9 ++++ 9 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 framework/doc/content/source/outputs/ReporterDebugOutput.md create mode 100644 framework/include/outputs/ReporterDebugOutput.h create mode 100644 framework/src/outputs/ReporterDebugOutput.C create mode 100644 test/tests/actions/debug_show_reporters/debug_show_reporters.i create mode 100644 test/tests/actions/debug_show_reporters/tests diff --git a/framework/doc/content/source/outputs/ReporterDebugOutput.md b/framework/doc/content/source/outputs/ReporterDebugOutput.md new file mode 100644 index 000000000000..acc3d6fb0e6d --- /dev/null +++ b/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 diff --git a/framework/doc/content/syntax/Reporters/index.md b/framework/doc/content/syntax/Reporters/index.md index b400fe48228a..9e46d0c4bfe3 100644 --- a/framework/doc/content/syntax/Reporters/index.md +++ b/framework/doc/content/syntax/Reporters/index.md @@ -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 diff --git a/framework/include/outputs/ReporterDebugOutput.h b/framework/include/outputs/ReporterDebugOutput.h new file mode 100644 index 000000000000..0a0eb184a23e --- /dev/null +++ b/framework/include/outputs/ReporterDebugOutput.h @@ -0,0 +1,26 @@ +//* 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: + void output(const ExecFlagType & type) override; +}; diff --git a/framework/include/reporters/ReporterData.h b/framework/include/reporters/ReporterData.h index 468be3f9d374..4abf14eb80ed 100644 --- a/framework/include/reporters/ReporterData.h +++ b/framework/include/reporters/ReporterData.h @@ -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; diff --git a/framework/src/actions/SetupDebugAction.C b/framework/src/actions/SetupDebugAction.C index f7b8c94810cb..6252cf7e6604 100644 --- a/framework/src/actions/SetupDebugAction.C +++ b/framework/src/actions/SetupDebugAction.C @@ -39,6 +39,8 @@ SetupDebugAction::validParams() false, "Print out the material properties supplied for each block, face, neighbor, and/or sideset"); params.addParam("show_mesh_meta_data", false, "Print out the available mesh meta data"); + params.addParam( + "show_reporters", false, "Print out information about the declared and requested Reporters"); params.addParam( "pid_aux", false, @@ -94,6 +96,14 @@ SetupDebugAction::act() _console << " " << pair.first << std::endl; } + // Print Reporter information + if (getParam("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("pid_aux")) { diff --git a/framework/src/outputs/ReporterDebugOutput.C b/framework/src/outputs/ReporterDebugOutput.C new file mode 100644 index 000000000000..e546aa26863b --- /dev/null +++ b/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("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"; +} diff --git a/framework/src/reporters/ReporterData.C b/framework/src/reporters/ReporterData.C index ee85013cbaa1..9875bb608747 100644 --- a/framework/src/reporters/ReporterData.C +++ b/framework/src/reporters/ReporterData.C @@ -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); @@ -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; +} diff --git a/test/tests/actions/debug_show_reporters/debug_show_reporters.i b/test/tests/actions/debug_show_reporters/debug_show_reporters.i new file mode 100644 index 000000000000..545bb4457ed9 --- /dev/null +++ b/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 +[] diff --git a/test/tests/actions/debug_show_reporters/tests b/test/tests/actions/debug_show_reporters/tests new file mode 100644 index 000000000000..2b47d990a783 --- /dev/null +++ b/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.*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.' + [] +[]