forked from idaholab/moose
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests for Reporter and ReporterInterface
- Loading branch information
1 parent
dc411b5
commit ebf35b0
Showing
13 changed files
with
446 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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{}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ReporterName>("reporter", "Test parameter for a ReporterName"); | ||
|
||
params.addParam<bool>("missing_parameter", false, "Test the error for a missing parameter"); | ||
params.addParam<bool>("bad_parameter_type", false, "Test the error for a bad parameter type"); | ||
params.addParam<bool>( | ||
"other_type_requested", | ||
false, | ||
"True to test the error for the Reporter value being registered with another type"); | ||
params.addParam<bool>("missing", | ||
false, | ||
"Test the error after reporters are added and requesting a reporter value " | ||
"that does not exist"); | ||
params.addParam<bool>("missing_by_name", | ||
false, | ||
"Test the error after reporters are added and requesting a reporter value " | ||
"by name that does not exist"); | ||
params.addParam<bool>("has_early", false, "Test the error for seeing if a Reporter exists too early"); | ||
params.addParam<bool>( | ||
"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<bool>("missing_parameter")) | ||
getReporterValue<int>("bad_param"); | ||
if (getParam<bool>("bad_parameter_type")) | ||
getReporterValue<int>("missing_parameter"); | ||
if (getParam<bool>("other_type_requested")) | ||
{ | ||
getReporterValueByName<Real>("some_reporter/some_value"); | ||
getReporterValueByName<int>("some_reporter/some_value"); | ||
} | ||
if (getParam<bool>("has_early")) | ||
hasReporterValue<Real>("reporter"); | ||
if (getParam<bool>("has_early_by_name")) | ||
hasReporterValueByName<Real>("some_reporter/some_value"); | ||
} | ||
|
||
void | ||
ReporterInterfaceErrorTest::initialSetup() | ||
{ | ||
if (getParam<bool>("missing")) | ||
getReporterValue<int>("reporter"); | ||
if (getParam<bool>("missing_by_name")) | ||
getReporterValueByName<int>("some_reporter/some_value"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ReporterName>( | ||
"pp_reporter", "Test parameter that should represent a Postprocessor value"); | ||
params.addRequiredParam<ReporterName>( | ||
"vpp_reporter", "Test parameter that should represent a VectorPostprocessor value"); | ||
|
||
return params; | ||
} | ||
|
||
ReporterSpecialTypeTest::ReporterSpecialTypeTest(const InputParameters & params) | ||
: GeneralUserObject(params) | ||
{ | ||
getReporterValue<Real>("pp_reporter"); | ||
getReporterValue<VectorPostprocessorValue>("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<Postprocessor>(getReporterName("pp_reporter").getObjectName())) | ||
mooseError("Is not a pp"); | ||
if (!hasUserObjectByName<VectorPostprocessor>(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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[Mesh] | ||
[gmg] | ||
type = GeneratedMeshGenerator | ||
dim = 1 | ||
[] | ||
[] | ||
|
||
[UserObjects] | ||
[error_test] | ||
type = ReporterInterfaceErrorTest | ||
reporter = dummy/value | ||
[] | ||
[] | ||
|
||
[Problem] | ||
solve = false | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.' | ||
[] | ||
[] | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[Mesh] | ||
[gmg] | ||
type = GeneratedMeshGenerator | ||
dim = 1 | ||
[] | ||
[] | ||
|
||
[Reporters/error_test] | ||
type = TestDeclareErrorsReporter | ||
value = value_name | ||
[] | ||
|
||
[Problem] | ||
solve = false | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
time,pp | ||
1,1 |
2 changes: 2 additions & 0 deletions
2
test/tests/reporters/base/gold/special_types_out_vpp_0001.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
value | ||
2 |
Oops, something went wrong.