Skip to content

Commit

Permalink
Added post-processor to compare other post-processors
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahansel committed Jul 26, 2018
1 parent 8bb1b31 commit cd3cbc3
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 0 deletions.
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 framework/include/postprocessors/PostprocessorComparison.h
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
56 changes: 56 additions & 0 deletions framework/src/postprocessors/PostprocessorComparison.C
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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
time,pp_comparison
0,-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
time,pp_comparison
0,1
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
value_a = pp_to_compare
value_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'
[]
15 changes: 15 additions & 0 deletions test/tests/postprocessors/postprocessor_comparison/tests
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'
[../]
[]

0 comments on commit cd3cbc3

Please sign in to comment.