Skip to content

Commit

Permalink
Add ElementExtremeValue PP... also add a missing intermediate base-cl…
Browse files Browse the repository at this point in the history
…ass so there is symmetry with nodal PPs closes idaholab#2776
  • Loading branch information
friedmud committed Apr 29, 2014
1 parent 397c5c2 commit a7f06e0
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 1 deletion.
52 changes: 52 additions & 0 deletions framework/include/postprocessors/ElementExtremeValue.h
@@ -0,0 +1,52 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#ifndef ELEMENTEXTREMEVALUE_H
#define ELEMENTEXTREMEVALUE_H

#include "ElementVariablePostprocessor.h"

//Forward Declarations
class ElementExtremeValue;

// Input parameters
template<>
InputParameters validParams<ElementExtremeValue>();

/// A postprocessor for collecting the nodal min or max value
class ElementExtremeValue : public ElementVariablePostprocessor
{
public:
/**
* Class constructor
* @param name The name of the postprocessor
* @param parameters The input parameters
*/
ElementExtremeValue(const std::string & name, InputParameters parameters);
virtual void initialize();
virtual Real getValue();
virtual void threadJoin(const UserObject & y);

protected:
/// Get the extreme value at each quadrature point
virtual void computeQpValue();

/// The extreme value type ("min" or "max")
int _type;

This comment has been minimized.

Copy link
@permcody

permcody Apr 29, 2014

You should document which 'int' is which, or at the very least (since this is a base class) why not use a class enum or const to disambiguate min and max?

static const int MAX = 0; static const int MIN = 1;


/// The extreme value
Real _value;
};

#endif
60 changes: 60 additions & 0 deletions framework/include/postprocessors/ElementVariablePostprocessor.h
@@ -0,0 +1,60 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#ifndef ELEMENTVARIABLEPOSTPROCESSOR_H
#define ELEMENTVARIABLEPOSTPROCESSOR_H

#include "ElementPostprocessor.h"
#include "MooseVariableInterface.h"

class MooseVariable;

//Forward Declarations
class ElementVariablePostprocessor;

template<>
InputParameters validParams<ElementVariablePostprocessor>();

class ElementVariablePostprocessor :
public ElementPostprocessor,
public MooseVariableInterface
{
public:
ElementVariablePostprocessor(const std::string & name, InputParameters parameters);

/// Just does a loop over "qp" calling computeQpValue()
virtual void execute();

protected:

/// This is what derived classes should override to do something on every quadrature point on every element
virtual void computeQpValue() = 0;

/// The MooseVariable the object is acting on
MooseVariable & _var;

/// Holds the solution at current quadrature points
VariableValue & _u;

/// Holds the solution gradient at the current quadrature points
VariableGradient & _grad_u;

/// Holds the solution derivative at the current quadrature points
VariableValue & _u_dot;

/// The current quadrature point
unsigned int _qp;
};

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

// user objects
#include "LayeredIntegral.h"
Expand Down Expand Up @@ -495,6 +496,7 @@ registerObjects(Factory & factory)
registerPostprocessor(AreaPostprocessor);
registerPostprocessor(PointValue);
registerPostprocessor(NodalExtremeValue);
registerPostprocessor(ElementExtremeValue);

// user objects
registerUserObject(LayeredIntegral);
Expand Down
100 changes: 100 additions & 0 deletions framework/src/postprocessors/ElementExtremeValue.C
@@ -0,0 +1,100 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#include "ElementExtremeValue.h"

#include <algorithm>
#include <limits>

template<>
InputParameters validParams<ElementExtremeValue>()
{
// Define the min/max enumeration
MooseEnum type_options("max=0, min=1", "max");

// Define the parameters
InputParameters params = validParams<ElementVariablePostprocessor>();

params.addParam<MooseEnum>("value_type", type_options, "Type of extreme value to return. 'max' returns the maximum value. 'min' returns the minimum value.");

This comment has been minimized.

Copy link
@permcody

permcody Apr 29, 2014

You're already using a MooseEnum in validParams, you could even use that as the _type class member...


return params;
}

ElementExtremeValue::ElementExtremeValue(const std::string & name, InputParameters parameters) :
ElementVariablePostprocessor(name, parameters),
_type(parameters.get<MooseEnum>("value_type")),
_value(_type == 0 ? -std::numeric_limits<Real>::max() : std::numeric_limits<Real>::max())
{}

void
ElementExtremeValue::initialize()
{
switch (_type)
{
case 0:
_value = -std::numeric_limits<Real>::max(); // start w/ the min
break;

case 1:
_value = std::numeric_limits<Real>::max(); // start w/ the max
break;
}
}

void
ElementExtremeValue::computeQpValue()
{
switch (_type)
{
case 0:
_value = std::max(_value, _u[_qp]);
break;

case 1:
_value = std::min(_value, _u[_qp]);
break;
}
}

Real
ElementExtremeValue::getValue()
{
switch (_type)
{
case 0:
gatherMax(_value);
break;
case 1:
gatherMin(_value);
break;
}

return _value;
}

void
ElementExtremeValue::threadJoin(const UserObject & y)
{
const ElementExtremeValue & pps = static_cast<const ElementExtremeValue &>(y);

switch (_type)
{
case 0:
_value = std::max(_value, pps._value);
break;
case 1:
_value = std::min(_value, pps._value);
break;
}
}
45 changes: 45 additions & 0 deletions framework/src/postprocessors/ElementVariablePostprocessor.C
@@ -0,0 +1,45 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#include "ElementVariablePostprocessor.h"
#include "MooseVariable.h"
#include "SubProblem.h"
#include "MooseTypes.h"

template<>
InputParameters validParams<ElementVariablePostprocessor>()
{
InputParameters params = validParams<ElementPostprocessor>();
params.addRequiredParam<VariableName>("variable", "The name of the variable that this postprocessor operates on");
return params;
}

ElementVariablePostprocessor::ElementVariablePostprocessor(const std::string & name, InputParameters parameters) :
ElementPostprocessor(name, parameters),
MooseVariableInterface(parameters, false),
_var(_subproblem.getVariable(_tid, parameters.get<VariableName>("variable"))),
_u(_var.sln()),
_grad_u(_var.gradSln()),
_u_dot(_var.uDot()),
_qp(0)
{
addMooseVariableDependency(mooseVariable());
}

void
ElementVariablePostprocessor::execute()
{
for (_qp=0; _qp<_qrule->n_points(); _qp++)
computeQpValue();
}
2 changes: 1 addition & 1 deletion framework/src/postprocessors/NodalExtremeValue.C
Expand Up @@ -25,7 +25,7 @@ InputParameters validParams<NodalExtremeValue>()

// Define the parameters
InputParameters params = validParams<NodalVariablePostprocessor>();
params.addParam<MooseEnum>("value_type", type_options, "Type of extreme value to return. 'max' returns the maximum value. 'min' returns the minimu value.");
params.addParam<MooseEnum>("value_type", type_options, "Type of extreme value to return. 'max' returns the maximum value. 'min' returns the minimum value.");
return params;
}

Expand Down
@@ -0,0 +1,64 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 10
ny = 10
[]

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

[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]
[./max]
type = ElementExtremeValue
variable = u
[../]
[./min]
type = ElementExtremeValue
variable = u
value_type = min
[../]
[]

[Executioner]
# Preconditioned JFNK (default)
type = Steady
solve_type = PJFNK
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[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/element_extreme_value/tests
@@ -0,0 +1,7 @@
[Tests]
[./test]
type = 'Exodiff'
input = 'element_extreme_value.i'
exodiff = 'element_extreme_value_out.e'
[../]
[]

0 comments on commit a7f06e0

Please sign in to comment.