Skip to content

Commit

Permalink
Adding DifferencePostprocessor (closes idaholab#3268)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrsd authored and aeslaughter committed Jun 3, 2014
1 parent eaa07b6 commit d11771a
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 0 deletions.
33 changes: 33 additions & 0 deletions framework/include/postprocessors/DifferencePostprocessor.h
@@ -0,0 +1,33 @@
#ifndef DIFFERENCEPOSTPROCESSOR_H
#define DIFFERENCEPOSTPROCESSOR_H

#include "GeneralPostprocessor.h"

class DifferencePostprocessor;

template<>
InputParameters validParams<DifferencePostprocessor>();

/**
* Computes the difference between two postprocessors
*
* result = value1 - value2
*/
class DifferencePostprocessor : public GeneralPostprocessor
{
public:
DifferencePostprocessor(const std::string & name, InputParameters parameters);
virtual ~DifferencePostprocessor();

virtual void initialize();
virtual void execute();
virtual PostprocessorValue getValue();
virtual void threadJoin(const UserObject & uo);

protected:
const PostprocessorValue & _value1;
const PostprocessorValue & _value2;
};


#endif /* DIFFERENCEPOSTPROCESSOR_H */
2 changes: 2 additions & 0 deletions framework/src/base/Moose.C
Expand Up @@ -176,6 +176,7 @@
#include "PointValue.h"
#include "NodalExtremeValue.h"
#include "ElementExtremeValue.h"
#include "DifferencePostprocessor.h"

// vector PPS
#include "ConstantVectorPostprocessor.h"
Expand Down Expand Up @@ -516,6 +517,7 @@ registerObjects(Factory & factory)
registerPostprocessor(PointValue);
registerPostprocessor(NodalExtremeValue);
registerPostprocessor(ElementExtremeValue);
registerPostprocessor(DifferencePostprocessor);

// vector PPS
registerVectorPostprocessor(ConstantVectorPostprocessor);
Expand Down
44 changes: 44 additions & 0 deletions framework/src/postprocessors/DifferencePostprocessor.C
@@ -0,0 +1,44 @@
#include "DifferencePostprocessor.h"

template<>
InputParameters validParams<DifferencePostprocessor>()
{
InputParameters params = validParams<GeneralPostprocessor>();
params.addRequiredParam<PostprocessorName>("value1", "First value");
params.addRequiredParam<PostprocessorName>("value2", "Second value");

return params;
}

DifferencePostprocessor::DifferencePostprocessor(const std::string & name, InputParameters parameters) :
GeneralPostprocessor(name, parameters),
_value1(getPostprocessorValue("value1")),
_value2(getPostprocessorValue("value2"))
{
}

DifferencePostprocessor::~DifferencePostprocessor()
{
}

void
DifferencePostprocessor::initialize()
{
}

void
DifferencePostprocessor::execute()
{
}

PostprocessorValue
DifferencePostprocessor::getValue()
{
return _value1 - _value2;
}

void
DifferencePostprocessor::threadJoin(const UserObject & /*uo*/)
{
// nothing to do here, general PPS do not run threaded
}
90 changes: 90 additions & 0 deletions test/tests/postprocessors/difference_pps/difference_pps.i
@@ -0,0 +1,90 @@
[Mesh]
type = GeneratedMesh
dim = 2
xmin = 0
xmax = 1
ymin = 0
ymax = 1
nx = 2
ny = 2
[]

[AuxVariables]
[./v]
[../]
[]

[Variables]
[./u]
[../]
[]

[ICs]
[./u_ic]
type = ConstantIC
variable = u
value = 2
[../]
[]

[AuxKernels]
[./one]
type = ConstantAux
variable = v
value = 1
[../]
[]

[Kernels]
[./diff]
type = Diffusion
variable = u
[../]
[]

[BCs]
[./left]
type = DirichletBC
variable = u
boundary = left
value = 0
[../]
[./right]
type = DirichletBC
variable = u
boundary = right
value = 1
[../]
[]

[Postprocessors]
[./u_avg]
type = ElementAverageValue
variable = u
[../]

[./v_avg]
type = ElementAverageValue
variable = v
[../]

[./diff]
type = DifferencePostprocessor
value1 = v_avg
value2 = u_avg
[../]
[]

[Executioner]
type = Steady
[]

[Outputs]
output_initial = true
exodus = true
[./console]
type = Console
perf_log = true
linear_residuals = true
[../]
[]
Binary file not shown.
7 changes: 7 additions & 0 deletions test/tests/postprocessors/difference_pps/tests
@@ -0,0 +1,7 @@
[Tests]
[./test]
type = 'Exodiff'
input = 'difference_pps.i'
exodiff = 'difference_pps_out.e'
[../]
[]

0 comments on commit d11771a

Please sign in to comment.