Skip to content

Commit

Permalink
Created NodalExtremeValue postprocessor for getting the min or max va…
Browse files Browse the repository at this point in the history
…lue (closes-#2026)

r19794
  • Loading branch information
aeslaughter authored and permcody committed Feb 14, 2014
1 parent 2c1866e commit c33b91c
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 0 deletions.
50 changes: 50 additions & 0 deletions framework/include/postprocessors/NodalExtremeValue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/****************************************************************/
/* 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 NODALEXTREMEVALUE_H
#define NODALEXTREMEVALUE_H

#include "NodalVariablePostprocessor.h"

//Forward Declarations
class NodalExtremeValue;

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

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

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

/// The extreme value
Real _value;
};

#endif
6 changes: 6 additions & 0 deletions framework/include/userobject/UserObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ class UserObject :
Parallel::max(value);
}

template <typename T>
void gatherMin(T & value)
{
Parallel::min(value);
}

template <typename T1, typename T2>
void gatherProxyValueMax(T1 & value, T2 & proxy)
{
Expand Down
2 changes: 2 additions & 0 deletions framework/src/base/Moose.C
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
#include "VolumePostprocessor.h"
#include "AreaPostprocessor.h"
#include "PointValue.h"
#include "NodalExtremeValue.h"

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

// user objects
registerUserObject(LayeredIntegral);
Expand Down
98 changes: 98 additions & 0 deletions framework/src/postprocessors/NodalExtremeValue.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/****************************************************************/
/* 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 "NodalExtremeValue.h"

#include <algorithm>
#include <limits>

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

// 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.");
return params;
}

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

void
NodalExtremeValue::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
NodalExtremeValue::execute()
{
switch (_type)
{
case 0:
_value = std::max(_value, _u[_qp]);
break;

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

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

return _value;
}

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

switch (_type)
{
case 0:
_value = std::max(_value, pps._value);
break;
case 1:
_value = std::min(_value, pps._value);
break;
}
}
Binary file not shown.
91 changes: 91 additions & 0 deletions test/tests/postprocessors/nodal_pps/nodal_extreme_pps_test.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
[Mesh]
type = FileMesh
file = trapezoid.e
uniform_refine = 1
[]

[Functions]
[./tr_x]
type = ParsedFunction
value = -x*cos(pi/3)
[../]
[./tr_y]
type = ParsedFunction
value = x*sin(pi/3)
[../]
[./itr_x]
type = ParsedFunction
value = -x/cos(pi/3)
[../]
[./itr_y]
type = ParsedFunction
value = 0
[../]
[]

[Variables]
[./u]
order = FIRST
family = LAGRANGE
[../]
[]

[Kernels]
[./diff]
type = Diffusion
variable = u
[../]
[./forcing]
type = GaussContForcing
variable = u
x_center = 2
y_center = -1
x_spread = 0.25
y_spread = 0.5
[../]
[./dot]
type = TimeDerivative
variable = u
[../]
[]

[BCs]
# active = ' '
[./Periodic]
[./x]
primary = 1
secondary = 4
transform_func = 'tr_x tr_y'
inv_transform_func = 'itr_x itr_y'
[../]
[../]
[]

[Postprocessors]
[./max_nodal_pps]
type = NodalExtremeValue
variable = u
[../]
[./max_node_id]
type = NodalProxyMaxValue
variable = u
[../]
[./min_nodal_pps]
type = NodalExtremeValue
variable = u
value_type = min
[../]
[]

[Executioner]
type = Transient
dt = 0.5
num_steps = 6
[]

[Output]
interval = 1
exodus = true
perf_log = true
[]

8 changes: 8 additions & 0 deletions test/tests/postprocessors/nodal_pps/tests
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
exodiff = 'nodal_nodeset_pps_test_out.e'
[../]

[./nodal_extreme]
type = 'Exodiff'
input = 'nodal_extreme_pps_test.i'
exodiff = 'nodal_extreme_pps_test_out.e'
group = 'periodic'
mesh_mode = 'SERIAL'
[../]

[./testnodalpps]
type = 'Exodiff'
input = 'nodal_max_pps_test.i'
Expand Down

0 comments on commit c33b91c

Please sign in to comment.