From 885866ae8f362937b28dabe548923eb19d2d1ce1 Mon Sep 17 00:00:00 2001 From: Cody Permann Date: Wed, 4 May 2016 14:11:16 -0600 Subject: [PATCH] Adding TimeExtremeValue Postprocessor closes #6902 --- .../include/postprocessors/TimeExtremeValue.h | 57 +++++++++++++ framework/src/base/Moose.C | 2 + .../src/postprocessors/TimeExtremeValue.C | 62 ++++++++++++++ .../gold/time_extreme_value_out.csv | 13 +++ .../postprocessors/time_extreme_value/tests | 8 ++ .../time_extreme_value/time_extreme_value.i | 82 +++++++++++++++++++ 6 files changed, 224 insertions(+) create mode 100644 framework/include/postprocessors/TimeExtremeValue.h create mode 100644 framework/src/postprocessors/TimeExtremeValue.C create mode 100644 test/tests/postprocessors/time_extreme_value/gold/time_extreme_value_out.csv create mode 100644 test/tests/postprocessors/time_extreme_value/tests create mode 100644 test/tests/postprocessors/time_extreme_value/time_extreme_value.i diff --git a/framework/include/postprocessors/TimeExtremeValue.h b/framework/include/postprocessors/TimeExtremeValue.h new file mode 100644 index 000000000000..8213d2e2ee4c --- /dev/null +++ b/framework/include/postprocessors/TimeExtremeValue.h @@ -0,0 +1,57 @@ +/****************************************************************/ +/* 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 TIMEEXTREMEVALUE_H +#define TIMEEXTREMEVALUE_H + +#include "GeneralPostprocessor.h" + +//Forward Declarations +class TimeExtremeValue; + +// Input parameters +template<> +InputParameters validParams(); + +/// A postprocessor for reporting the max/min value of another postprocessor over time +class TimeExtremeValue : public GeneralPostprocessor +{ +public: + /// What type of extreme value we are going to compute + enum ExtremeType + { + MAX, + MIN + }; + + /** + * Class constructor + * @param parameters The input parameters + */ + TimeExtremeValue(const InputParameters & parameters); + virtual void initialize() {} + virtual void execute(); + virtual Real getValue(); + +protected: + const PostprocessorValue & _postprocessor; + + /// The extreme value type ("min" or "max") + ExtremeType _type; + + /// The extreme value + Real _value; +}; + +#endif diff --git a/framework/src/base/Moose.C b/framework/src/base/Moose.C index 4ba9e24b1a53..0fc0476d56e7 100644 --- a/framework/src/base/Moose.C +++ b/framework/src/base/Moose.C @@ -208,6 +208,7 @@ #include "ExecutionerAttributeReporter.h" #include "PercentChangePostprocessor.h" #include "ElementL2Difference.h" +#include "TimeExtremeValue.h" // vector PPS #include "ConstantVectorPostprocessor.h" @@ -618,6 +619,7 @@ registerObjects(Factory & factory) registerPostprocessor(ExecutionerAttributeReporter); registerPostprocessor(PercentChangePostprocessor); registerPostprocessor(ElementL2Difference); + registerPostprocessor(TimeExtremeValue); // vector PPS registerVectorPostprocessor(ConstantVectorPostprocessor); diff --git a/framework/src/postprocessors/TimeExtremeValue.C b/framework/src/postprocessors/TimeExtremeValue.C new file mode 100644 index 000000000000..380ab8c98d08 --- /dev/null +++ b/framework/src/postprocessors/TimeExtremeValue.C @@ -0,0 +1,62 @@ +/****************************************************************/ +/* 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 "TimeExtremeValue.h" + +#include +#include + +template<> +InputParameters validParams() +{ + // Define the min/max enumeration + MooseEnum type_options("max=0 min=1", "max"); + + // Define the parameters + InputParameters params = validParams(); + params.addParam("value_type", type_options, "Type of extreme value to return. 'max' returns the maximum value. 'min' returns the minimum value."); + params.addRequiredParam("postprocessor", "The name of the postprocessor used for reporting time extreme values"); + params.addClassDescription("A postprocessor for reporting the max/min value of another postprocessor over time."); + + return params; +} + +TimeExtremeValue::TimeExtremeValue(const InputParameters & parameters) : + GeneralPostprocessor(parameters), + _postprocessor(getPostprocessorValue("postprocessor")), + _type((ExtremeType)(int)parameters.get("value_type")), + _value(_type == 0 ? -std::numeric_limits::max() : std::numeric_limits::max()) +{ +} + +void +TimeExtremeValue::execute() +{ + switch (_type) + { + case MAX: + _value = std::max(_value, _postprocessor); + break; + + case MIN: + _value = std::min(_value, _postprocessor); + break; + } +} + +Real +TimeExtremeValue::getValue() +{ + return _value; +} diff --git a/test/tests/postprocessors/time_extreme_value/gold/time_extreme_value_out.csv b/test/tests/postprocessors/time_extreme_value/gold/time_extreme_value_out.csv new file mode 100644 index 000000000000..5131368b619c --- /dev/null +++ b/test/tests/postprocessors/time_extreme_value/gold/time_extreme_value_out.csv @@ -0,0 +1,13 @@ +time,max_nl_dofs,nl_dofs +0,9,9 +0.1,9,9 +0.2,25,25 +0.3,72,72 +0.4,72,72 +0.5,72,72 +0.6,72,59 +0.7,72,59 +0.8,72,25 +0.9,72,9 +1,72,9 + diff --git a/test/tests/postprocessors/time_extreme_value/tests b/test/tests/postprocessors/time_extreme_value/tests new file mode 100644 index 000000000000..e7aef31ca325 --- /dev/null +++ b/test/tests/postprocessors/time_extreme_value/tests @@ -0,0 +1,8 @@ +[Tests] + [./time_extreme_pps] + type = 'CSVDiff' + input = 'time_extreme_value.i' + csvdiff = 'time_extreme_value_out.csv' + max_parallel = 4 # Only four elements + [../] +[] diff --git a/test/tests/postprocessors/time_extreme_value/time_extreme_value.i b/test/tests/postprocessors/time_extreme_value/time_extreme_value.i new file mode 100644 index 000000000000..e1a4329608c0 --- /dev/null +++ b/test/tests/postprocessors/time_extreme_value/time_extreme_value.i @@ -0,0 +1,82 @@ +[Mesh] + type = GeneratedMesh + dim = 2 + nx = 2 + ny = 2 +[] + +[Variables] + [./u] + [../] +[] + +[Kernels] + [./diff] + type = Diffusion + variable = u + [../] + [./time] + type = TimeDerivative + variable = u + [../] +[] + +[BCs] + [./left] + type = FunctionDirichletBC + variable = u + boundary = left + function = 'if(t<1.0,t,1.0)' + [../] + [./right] + type = FunctionDirichletBC + variable = u + boundary = right + function = 'if(t<1.0,2.0-t,1.0)' + [../] +[] + +[Executioner] + type = Transient + num_steps = 10 + dt = 0.1 + solve_type = PJFNK + petsc_options_iname = '-pc_type -pc_hypre_type' + petsc_options_value = 'hypre boomeramg' + +[] + +[Postprocessors] + [./max_nl_dofs] + type = TimeExtremeValue + value_type = max + postprocessor = nl_dofs + execute_on = 'initial timestep_end' + [../] + + [./nl_dofs] + type = NumDOFs + system = NL + execute_on = 'initial timestep_end' + [../] +[] + +[Adaptivity] + marker = marker + max_h_level = 2 + [./Markers] + [./marker] + type = ValueRangeMarker + lower_bound = 0.7 + upper_bound = 1.3 + buffer_size = 0.2 + variable = u + invert = true + third_state = DO_NOTHING + [../] + [../] +[] + +[Outputs] + csv = true +[]