From ebf35b0d22d873ef88c04c662ce2e5c2c81b1e05 Mon Sep 17 00:00:00 2001 From: Logan Harbour Date: Tue, 13 Apr 2021 14:34:33 -0600 Subject: [PATCH] Add more tests for Reporter and ReporterInterface refs #17512 #17605 --- test/include/reporters/TestReporter.h | 10 +++ .../userobjects/ReporterInterfaceErrorTest.h | 29 ++++++++ .../userobjects/ReporterSpecialTypeTest.h | 34 +++++++++ test/src/reporters/TestReporter.C | 36 +++++++++ .../userobjects/ReporterInterfaceErrorTest.C | 66 +++++++++++++++++ .../src/userobjects/ReporterSpecialTypeTest.C | 67 +++++++++++++++++ .../interfaces/reporterinterface/ri_errors.i | 21 ++++++ test/tests/interfaces/reporterinterface/tests | 74 +++++++++++++++++++ test/tests/reporters/base/errors.i | 19 +++++ .../reporters/base/gold/special_types_out.csv | 2 + .../base/gold/special_types_out_vpp_0001.csv | 2 + test/tests/reporters/base/special_types.i | 36 +++++++++ test/tests/reporters/base/tests | 50 +++++++++++++ 13 files changed, 446 insertions(+) create mode 100644 test/include/userobjects/ReporterInterfaceErrorTest.h create mode 100644 test/include/userobjects/ReporterSpecialTypeTest.h create mode 100644 test/src/userobjects/ReporterInterfaceErrorTest.C create mode 100644 test/src/userobjects/ReporterSpecialTypeTest.C create mode 100644 test/tests/interfaces/reporterinterface/ri_errors.i create mode 100644 test/tests/interfaces/reporterinterface/tests create mode 100644 test/tests/reporters/base/errors.i create mode 100644 test/tests/reporters/base/gold/special_types_out.csv create mode 100644 test/tests/reporters/base/gold/special_types_out_vpp_0001.csv create mode 100644 test/tests/reporters/base/special_types.i diff --git a/test/include/reporters/TestReporter.h b/test/include/reporters/TestReporter.h index 464aedf18e70..2d6d45cb696d 100644 --- a/test/include/reporters/TestReporter.h +++ b/test/include/reporters/TestReporter.h @@ -81,3 +81,13 @@ class TestGetReporterDeclaredInInitialSetupReporter : public GeneralReporter 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 {} +}; diff --git a/test/include/userobjects/ReporterInterfaceErrorTest.h b/test/include/userobjects/ReporterInterfaceErrorTest.h new file mode 100644 index 000000000000..467e6ccd7e28 --- /dev/null +++ b/test/include/userobjects/ReporterInterfaceErrorTest.h @@ -0,0 +1,29 @@ +//* 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 "GeneralUserObject.h" + +/** + * A UserObject that tests errors produced by the ReporterInterface. + */ +class ReporterInterfaceErrorTest : public GeneralUserObject +{ +public: + static InputParameters validParams(); + + ReporterInterfaceErrorTest(const InputParameters & params); + + void initialSetup() override; + + void initialize() override {}; + void execute() override {}; + void finalize()override{}; +}; diff --git a/test/include/userobjects/ReporterSpecialTypeTest.h b/test/include/userobjects/ReporterSpecialTypeTest.h new file mode 100644 index 000000000000..6b759a51ad53 --- /dev/null +++ b/test/include/userobjects/ReporterSpecialTypeTest.h @@ -0,0 +1,34 @@ +//* 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 "GeneralUserObject.h" + +/** + * A UserObject that tests the requesting of Reporter values + * that are actually declared later to be Postprocessor + * and VectorPostprocessor values. + */ +class ReporterSpecialTypeTest : public GeneralUserObject +{ +public: + static InputParameters validParams(); + + ReporterSpecialTypeTest(const InputParameters & params); + + void initialSetup() override; + void initialize() override{}; + void execute() override{}; + void finalize() override{}; + +private: + bool isPostprocessor(const std::string & param_name) const; + bool isVectorPostprocessor(const std::string & param_name) const; +}; diff --git a/test/src/reporters/TestReporter.C b/test/src/reporters/TestReporter.C index d31f1d59123e..b83d6b918c34 100644 --- a/test/src/reporters/TestReporter.C +++ b/test/src/reporters/TestReporter.C @@ -13,6 +13,7 @@ registerMooseObject("MooseTestApp", TestDeclareReporter); registerMooseObject("MooseTestApp", TestGetReporter); registerMooseObject("MooseTestApp", TestDeclareInitialSetupReporter); registerMooseObject("MooseTestApp", TestGetReporterDeclaredInInitialSetupReporter); +registerMooseObject("MooseTestApp", TestDeclareErrorsReporter); InputParameters TestDeclareReporter::validParams() @@ -173,3 +174,38 @@ TestGetReporterDeclaredInInitialSetupReporter::execute() { _the_value_of_the_reporter = _value_declared_in_initial_setup; } + +InputParameters +TestDeclareErrorsReporter::validParams() +{ + InputParameters params = GeneralReporter::validParams(); + params.addRequiredParam("value", "A reporter value name"); + + params.addParam("missing_param", false, "True to test the error for a missing parameter"); + params.addParam("bad_param", false, "True to test the error for a bad parameter type"); + params.addParam("already_declared", false, "Test declaring a value multiple times"); + params.addParam("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("missing_param")) + declareValue("some_missing_parm"); + if (getParam("bad_param")) + declareValue("bad_param"); + if (getParam("already_declared")) + { + declareValueByName("value_name"); + declareValueByName("value_name"); + } + if (getParam("requested_different_type")) + { + getReporterValueByName(name() + "/value_name"); + declareValueByName("value_name"); + } +} diff --git a/test/src/userobjects/ReporterInterfaceErrorTest.C b/test/src/userobjects/ReporterInterfaceErrorTest.C new file mode 100644 index 000000000000..6b9abd9c604f --- /dev/null +++ b/test/src/userobjects/ReporterInterfaceErrorTest.C @@ -0,0 +1,66 @@ +//* 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 "ReporterInterfaceErrorTest.h" + +registerMooseObject("MooseTestApp", ReporterInterfaceErrorTest); + +InputParameters +ReporterInterfaceErrorTest::validParams() +{ + InputParameters params = GeneralUserObject::validParams(); + + params.addParam("reporter", "Test parameter for a ReporterName"); + + params.addParam("missing_parameter", false, "Test the error for a missing parameter"); + params.addParam("bad_parameter_type", false, "Test the error for a bad parameter type"); + params.addParam( + "other_type_requested", + false, + "True to test the error for the Reporter value being registered with another type"); + params.addParam("missing", + false, + "Test the error after reporters are added and requesting a reporter value " + "that does not exist"); + params.addParam("missing_by_name", + false, + "Test the error after reporters are added and requesting a reporter value " + "by name that does not exist"); + params.addParam("has_early", false, "Test the error for seeing if a Reporter exists too early"); + params.addParam( + "has_early_by_name", false, "Test the error for seeing if a Reporter exists by name too early"); + return params; +} + +ReporterInterfaceErrorTest::ReporterInterfaceErrorTest(const InputParameters & params) + : GeneralUserObject(params) +{ + if (getParam("missing_parameter")) + getReporterValue("bad_param"); + if (getParam("bad_parameter_type")) + getReporterValue("missing_parameter"); + if (getParam("other_type_requested")) + { + getReporterValueByName("some_reporter/some_value"); + getReporterValueByName("some_reporter/some_value"); + } + if (getParam("has_early")) + hasReporterValue("reporter"); + if (getParam("has_early_by_name")) + hasReporterValueByName("some_reporter/some_value"); +} + +void +ReporterInterfaceErrorTest::initialSetup() +{ + if (getParam("missing")) + getReporterValue("reporter"); + if (getParam("missing_by_name")) + getReporterValueByName("some_reporter/some_value"); +} diff --git a/test/src/userobjects/ReporterSpecialTypeTest.C b/test/src/userobjects/ReporterSpecialTypeTest.C new file mode 100644 index 000000000000..d14f48aef14c --- /dev/null +++ b/test/src/userobjects/ReporterSpecialTypeTest.C @@ -0,0 +1,67 @@ +//* 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 "ReporterSpecialTypeTest.h" + +registerMooseObject("MooseTestApp", ReporterSpecialTypeTest); + +InputParameters +ReporterSpecialTypeTest::validParams() +{ + InputParameters params = GeneralUserObject::validParams(); + + params.addRequiredParam( + "pp_reporter", "Test parameter that should represent a Postprocessor value"); + params.addRequiredParam( + "vpp_reporter", "Test parameter that should represent a VectorPostprocessor value"); + + return params; +} + +ReporterSpecialTypeTest::ReporterSpecialTypeTest(const InputParameters & params) + : GeneralUserObject(params) +{ + getReporterValue("pp_reporter"); + getReporterValue("vpp_reporter"); + + for (const std::string & name : {"pp_reporter", "vpp_reporter"}) + if (isPostprocessor(name) || isVectorPostprocessor(name)) + mooseError("Is a special type"); +} + +void +ReporterSpecialTypeTest::initialSetup() +{ + if (!hasUserObjectByName(getReporterName("pp_reporter").getObjectName())) + mooseError("Is not a pp"); + if (!hasUserObjectByName(getReporterName("vpp_reporter").getObjectName())) + mooseError("Is not a vpp"); + if (!isPostprocessor("pp_reporter")) + mooseError("Not a pp special type"); + if (!isVectorPostprocessor("vpp_reporter")) + mooseError("Not a vpp special type"); +} + +bool +ReporterSpecialTypeTest::isPostprocessor(const std::string & param_name) const +{ + return _fe_problem.getReporterData() + .getReporterStateBase(getReporterName(param_name)) + .getReporterName() + .isPostprocessor(); +} + +bool +ReporterSpecialTypeTest::isVectorPostprocessor(const std::string & param_name) const +{ + return _fe_problem.getReporterData() + .getReporterStateBase(getReporterName(param_name)) + .getReporterName() + .isVectorPostprocessor(); +} diff --git a/test/tests/interfaces/reporterinterface/ri_errors.i b/test/tests/interfaces/reporterinterface/ri_errors.i new file mode 100644 index 000000000000..f69be7fe22dc --- /dev/null +++ b/test/tests/interfaces/reporterinterface/ri_errors.i @@ -0,0 +1,21 @@ +[Mesh] + [gmg] + type = GeneratedMeshGenerator + dim = 1 + [] +[] + +[UserObjects] + [error_test] + type = ReporterInterfaceErrorTest + reporter = dummy/value + [] +[] + +[Problem] + solve = false +[] + +[Executioner] + type = Steady +[] diff --git a/test/tests/interfaces/reporterinterface/tests b/test/tests/interfaces/reporterinterface/tests new file mode 100644 index 000000000000..c83e046d6c63 --- /dev/null +++ b/test/tests/interfaces/reporterinterface/tests @@ -0,0 +1,74 @@ +[Tests] + design = 'ReporterInterface.md' + issues = '#17512' + + [param_errors] + requirement = 'The system shall report a reasonable error when requesting a Reporter value from a parameter when' + + [missing_parameter] + type = RunException + input = 'ri_errors.i' + cli_args = 'UserObjects/error_test/missing_parameter=true' + expect_err = 'When getting a Reporter, failed to get a parameter with the name "bad_param".' + + detail = 'the parameter is not found and' + [] + [bad_parameter_type] + type = RunException + input = 'ri_errors.i' + cli_args = 'UserObjects/error_test/bad_parameter_type=true' + expect_err = 'Supplied parameter with name "missing_parameter" of type "bool" is not an expected type for getting a Reporter.' + + detail = 'the parameter does not represent a Reporter' + [] + [] + + [other_type_requested_error] + type = RunException + input = 'ri_errors.i' + cli_args = 'UserObjects/error_test/other_type_requested=true' + expect_err = 'While requesting a Reporter value with the name "some_value" and type "int",.*a Reporter with the same name has been requested with a different type.' + + requirement = 'The system shall report a reasonable error when requesting a Reporter value when a Reporter with the same name exists with a different type.' + [] + + [missing_errors] + requirement = 'The system shall report a reasonable error when requesting a Reporter value' + [param] + type = RunException + input = 'ri_errors.i' + cli_args = 'UserObjects/error_test/missing=true' + expect_err = 'reporter\)\:(.*)A Reporter value with the name "dummy/value" and type "int" was not found..' + + detail = 'by parameter and the Reporter value does not exist and' + [] + [name] + type = RunException + input = 'ri_errors.i' + cli_args = 'UserObjects/error_test/missing_by_name=true' + expect_err = 'A Reporter value with the name "some_reporter/some_value" and type "int" was not found.' + + detail = 'by Reporter name and the Reporter value does not exist.' + [] + [] + + [has_errors] + requirement = 'The system shall report a reasonable error when it is too early to request if a Reporter value exists' + [param] + type = RunException + input = 'ri_errors.i' + cli_args = 'UserObjects/error_test/has_early=true' + expect_err = 'Cannot call hasReporterValue\(\) until all Reporters have been constructed.' + + detail = 'by parameter name and' + [] + [name] + type = RunException + input = 'ri_errors.i' + cli_args = 'UserObjects/error_test/has_early_by_name=true' + expect_err = 'Cannot call hasReporterValueByName\(\) until all Reporters have been constructed.' + + detail = 'by Reporter name.' + [] + [] +[] diff --git a/test/tests/reporters/base/errors.i b/test/tests/reporters/base/errors.i new file mode 100644 index 000000000000..4595c6b3272e --- /dev/null +++ b/test/tests/reporters/base/errors.i @@ -0,0 +1,19 @@ +[Mesh] + [gmg] + type = GeneratedMeshGenerator + dim = 1 + [] +[] + +[Reporters/error_test] + type = TestDeclareErrorsReporter + value = value_name +[] + +[Problem] + solve = false +[] + +[Executioner] + type = Steady +[] diff --git a/test/tests/reporters/base/gold/special_types_out.csv b/test/tests/reporters/base/gold/special_types_out.csv new file mode 100644 index 000000000000..893bf66bef4a --- /dev/null +++ b/test/tests/reporters/base/gold/special_types_out.csv @@ -0,0 +1,2 @@ +time,pp +1,1 diff --git a/test/tests/reporters/base/gold/special_types_out_vpp_0001.csv b/test/tests/reporters/base/gold/special_types_out_vpp_0001.csv new file mode 100644 index 000000000000..6a903fe90d44 --- /dev/null +++ b/test/tests/reporters/base/gold/special_types_out_vpp_0001.csv @@ -0,0 +1,2 @@ +value +2 diff --git a/test/tests/reporters/base/special_types.i b/test/tests/reporters/base/special_types.i new file mode 100644 index 000000000000..a482b3a1330e --- /dev/null +++ b/test/tests/reporters/base/special_types.i @@ -0,0 +1,36 @@ +[Mesh] + [gmg] + type = GeneratedMeshGenerator + dim = 1 + [] +[] + +[UserObjects/special_type_test] + type = ReporterSpecialTypeTest + pp_reporter = "pp/value" + vpp_reporter = "vpp/value" +[] + +[Postprocessors/pp] + type = FunctionValuePostprocessor + function = 1 +[] + +[VectorPostprocessors/vpp] + type = ConstantVectorPostprocessor + vector_names = 'value' + value = '2' +[] + +[Problem] + solve = false +[] + +[Executioner] + type = Steady +[] + +[Outputs] + csv = true + execute_on = timestep_end +[] diff --git a/test/tests/reporters/base/tests b/test/tests/reporters/base/tests index 59b3e16c0864..dceafbfebf4a 100644 --- a/test/tests/reporters/base/tests +++ b/test/tests/reporters/base/tests @@ -19,4 +19,54 @@ requirement = "The system shall error if an invalid name is provided when retrieving aggregate value." [] + + [errors] + requirement = 'The system shall report a reasonable error when declaring a Reporter value and' + + [missing_param] + type = RunException + input = errors.i + allow_test_objects = true + cli_args = 'Reporters/error_test/missing_param=true' + expect_err = 'When getting a ReporterValueName, failed to get a parameter with the name "some_missing_parm".' + + detail = 'the parameter that contains the name was not found,' + [] + [bad_param] + type = RunException + input = errors.i + allow_test_objects = true + cli_args = 'Reporters/error_test/bad_param=true' + expect_err = 'Supplied parameter with name "bad_param" of type "bool" is not an expected type for getting a Reporter value.' + + detail = 'the parameter that contains the name is not of the correct type,' + [] + [already_declared] + type = RunException + input = errors.i + allow_test_objects = true + cli_args = 'Reporters/error_test/already_declared=true' + expect_err = 'While declaring a Reporter value with the name "value_name" and type "double",.*a Reporter with the same name has already been declared.' + + detail = 'a Reporter with the same name has already been declared, and' + [] + [requested_different_type] + type = RunException + input = errors.i + allow_test_objects = true + cli_args = 'Reporters/error_test/requested_different_type=true' + expect_err = 'While declaring a Reporter value with the name "value_name" and type "double",.*a Reporter with the same name has been requested with a different type.' + + detail = 'a Reporter with the same name but a different type has been requested.' + [] + [] + + [special_types] + type = CSVDiff + input = special_types.i + csvdiff = 'special_types_out.csv special_types_out_vpp_0001.csv' + allow_test_objects = true + + requirement = 'The system shall support the mixing of computing and retreiving aggregate values of arbitrary types with the Postprocessor and VectorPostprocessor system.' + [] []