forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created PostprocessorComparison post-processor
Closes idaholab#11910
- Loading branch information
1 parent
c4cca6a
commit 5f9fdbb
Showing
7 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
framework/doc/content/source/postprocessors/PostprocessorComparison.md
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,27 @@ | ||
# PostprocessorComparison | ||
|
||
!syntax description /Postprocessors/PostprocessorComparison | ||
|
||
This post-processor is used to compare two post-processor (or constant) values. | ||
It returns a value of "+1" for "true" and "-1" for "false". There are a number of | ||
different options for the parameter `comparison_type`. Denoting the first | ||
value as `a` and the second as `b`, these options are as follows: | ||
|
||
| Value | Test | | ||
|-----------------------|-----------| | ||
| `equals` | `a == b`? | | ||
| `greater_than` | `a > b`? | | ||
| `greater_than_equals` | `a >= b`? | | ||
| `less_than` | `a < b`? | | ||
| `less_than_equals` | `a <= b`? | | ||
|
||
All tests use a "fuzzy" comparison; see the corresponding functions in | ||
[moose_utils.md]. | ||
|
||
!syntax parameters /Postprocessors/PostprocessorComparison | ||
|
||
!syntax inputs /Postprocessors/PostprocessorComparison | ||
|
||
!syntax children /Postprocessors/PostprocessorComparison | ||
|
||
!bibtex bibliography |
55 changes: 55 additions & 0 deletions
55
framework/include/postprocessors/PostprocessorComparison.h
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,55 @@ | ||
//* 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 | ||
|
||
#ifndef POSTPROCESSORCOMPARISON_H | ||
#define POSTPROCESSORCOMPARISON_H | ||
|
||
#include "ComparisonPostprocessor.h" | ||
|
||
class PostprocessorComparison; | ||
|
||
template <> | ||
InputParameters validParams<PostprocessorComparison>(); | ||
|
||
/** | ||
* Compares two post-processors and produces a boolean value | ||
* | ||
* This post-processor implements a number of different comparisons between | ||
* post-processor \c a and post-processor \c b: | ||
* \li <b>equals</b>: <tt>a == b</tt>? | ||
* \li <b>greater_than</b>: <tt>a > b</tt>? | ||
* \li <b>greater_than_equals</b>: <tt>a >= b</tt>? | ||
* \li <b>less_than</b>: <tt>a < b</tt>? | ||
* \li <b>less_than_equals</b>: <tt>a <= b</tt>? | ||
* | ||
* For all comparisons, a "fuzzy" comparison is made via the corresponding | ||
* function in \c MooseUtils. | ||
* If the comparison condition is true, then a value of "+1" is output; | ||
* otherwise, a value of "-1" is output. | ||
*/ | ||
class PostprocessorComparison : public ComparisonPostprocessor | ||
{ | ||
public: | ||
PostprocessorComparison(const InputParameters & parameters); | ||
|
||
virtual void initialize() override; | ||
virtual void execute() override; | ||
virtual PostprocessorValue getValue() override; | ||
|
||
protected: | ||
/// First post-processor to compare | ||
const PostprocessorValue & _value_a; | ||
/// Second post-processor to compare | ||
const PostprocessorValue & _value_b; | ||
|
||
/// The comparison value; "+1" for true and "-1" for false | ||
PostprocessorValue _comparison_value; | ||
}; | ||
|
||
#endif |
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,56 @@ | ||
//* 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 "PostprocessorComparison.h" | ||
|
||
registerMooseObject("MooseApp", PostprocessorComparison); | ||
|
||
template <> | ||
InputParameters | ||
validParams<PostprocessorComparison>() | ||
{ | ||
InputParameters params = validParams<ComparisonPostprocessor>(); | ||
|
||
params.addRequiredParam<PostprocessorName>("value_a", | ||
"The first post-processor or value in the comparison"); | ||
params.addRequiredParam<PostprocessorName>( | ||
"value_b", "The second post-processor or value in the comparison"); | ||
|
||
params.addClassDescription("Compares two post-processors and produces a boolean value"); | ||
|
||
return params; | ||
} | ||
|
||
PostprocessorComparison::PostprocessorComparison(const InputParameters & parameters) | ||
: ComparisonPostprocessor(parameters), | ||
|
||
_value_a(getPostprocessorValue("value_a")), | ||
_value_b(getPostprocessorValue("value_b")), | ||
|
||
_comparison_value(0.0) | ||
{ | ||
} | ||
|
||
void | ||
PostprocessorComparison::initialize() | ||
{ | ||
_comparison_value = 0.0; | ||
} | ||
|
||
void | ||
PostprocessorComparison::execute() | ||
{ | ||
_comparison_value = boolToReal(comparisonIsTrue(_value_a, _value_b)); | ||
} | ||
|
||
PostprocessorValue | ||
PostprocessorComparison::getValue() | ||
{ | ||
return _comparison_value; | ||
} |
2 changes: 2 additions & 0 deletions
2
test/tests/postprocessors/postprocessor_comparison/gold/greater_than.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 @@ | ||
time,pp_comparison | ||
0,-1 |
2 changes: 2 additions & 0 deletions
2
test/tests/postprocessors/postprocessor_comparison/gold/less_than.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 @@ | ||
time,pp_comparison | ||
0,1 |
41 changes: 41 additions & 0 deletions
41
test/tests/postprocessors/postprocessor_comparison/postprocessor_comparison.i
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,41 @@ | ||
# This tests the PostprocessorComparison post-processor, which compares two | ||
# post-processors. | ||
|
||
[Mesh] | ||
type = GeneratedMesh | ||
dim = 1 | ||
nx = 1 | ||
xmin = 0 | ||
xmax = 1 | ||
[] | ||
|
||
[Postprocessors] | ||
[./pp_to_compare] | ||
type = LinearCombinationPostprocessor | ||
pp_names = '' | ||
pp_coefs = '' | ||
b = 1 | ||
[../] | ||
[./pp_comparison] | ||
type = PostprocessorComparison | ||
postprocessor_a = pp_to_compare | ||
postprocessor_b = 2 | ||
comparison_type = greater_than | ||
execute_on = 'initial' | ||
[../] | ||
[] | ||
|
||
[Problem] | ||
solve = false | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
[] | ||
|
||
[Outputs] | ||
file_base = greater_than | ||
csv = true | ||
show = 'pp_comparison' | ||
execute_on = 'initial' | ||
[] |
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,15 @@ | ||
[Tests] | ||
[./greater_than] | ||
type = 'CSVDiff' | ||
input = 'postprocessor_comparison.i' | ||
csvdiff = 'greater_than.csv' | ||
[../] | ||
[./less_than] | ||
type = 'CSVDiff' | ||
input = 'postprocessor_comparison.i' | ||
cli_args = ' | ||
Postprocessors/pp_comparison/comparison_type=less_than | ||
Outputs/file_base=less_than' | ||
csvdiff = 'less_than.csv' | ||
[../] | ||
[] |