Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #include "ChangeOverTimePostprocessor.h" 11 : 12 : registerMooseObject("MooseApp", ChangeOverTimePostprocessor); 13 : 14 : InputParameters 15 28682 : ChangeOverTimePostprocessor::validParams() 16 : { 17 28682 : InputParameters params = GeneralPostprocessor::validParams(); 18 : 19 28682 : params.addRequiredParam<PostprocessorName>("postprocessor", "The name of the postprocessor"); 20 86046 : params.addParam<bool>("change_with_respect_to_initial", 21 57364 : false, 22 : "Compute change with respect to initial value instead of previous value"); 23 86046 : params.addParam<bool>( 24 57364 : "compute_relative_change", false, "Compute magnitude of relative change instead of change"); 25 28682 : params.addParam<bool>("take_absolute_value", false, "Option to take absolute value of change"); 26 : 27 28682 : params.addClassDescription("Computes the change or relative change in a post-processor value " 28 : "over a timestep or the entire transient"); 29 : 30 28682 : return params; 31 0 : } 32 : 33 80 : ChangeOverTimePostprocessor::ChangeOverTimePostprocessor(const InputParameters & parameters) 34 : : GeneralPostprocessor(parameters), 35 80 : _change_with_respect_to_initial(getParam<bool>("change_with_respect_to_initial")), 36 80 : _compute_relative_change(getParam<bool>("compute_relative_change")), 37 80 : _take_absolute_value(getParam<bool>("take_absolute_value")), 38 80 : _pps_value(getPostprocessorValue("postprocessor")), 39 80 : _pps_value_old(getPostprocessorValueOld("postprocessor")), 40 80 : _pps_value_initial(declareRestartableData<Real>("pps_value_initial")), 41 80 : _value(0.0) 42 : { 43 80 : if (_change_with_respect_to_initial) 44 : { 45 : // ensure dependent post-processor is executed on initial 46 68 : const PostprocessorName & pp_name = getParam<PostprocessorName>("postprocessor"); 47 68 : const UserObject & pp = _fe_problem.getUserObject<UserObject>(pp_name); 48 68 : if (!pp.getExecuteOnEnum().isValueSet(EXEC_INITIAL)) 49 4 : mooseError("When 'change_with_respect_to_initial' is specified to be true, 'execute_on' for " 50 4 : "the dependent post-processor ('" + 51 4 : pp_name + "') must include 'initial'"); 52 : 53 : // ensure THIS post-processor is executed on initial 54 64 : if (!_execute_enum.isValueSet(EXEC_INITIAL)) 55 4 : mooseError("When 'change_with_respect_to_initial' is specified to be true, 'execute_on' for " 56 4 : "the ChangeOverTimePostprocessor ('" + 57 8 : name() + "') must include 'initial'"); 58 : } 59 72 : } 60 : 61 : void 62 550 : ChangeOverTimePostprocessor::initialize() 63 : { 64 550 : } 65 : 66 : void 67 550 : ChangeOverTimePostprocessor::execute() 68 : { 69 550 : } 70 : 71 : void 72 550 : ChangeOverTimePostprocessor::finalize() 73 : { 74 : // copy initial value in case difference is measured against initial value 75 550 : if (_t_step == 0) 76 66 : _pps_value_initial = _pps_value; 77 : 78 : // determine value which change is measured against 79 : Real base_value; 80 550 : if (_change_with_respect_to_initial) 81 517 : base_value = _pps_value_initial; 82 : else 83 : { 84 : // Currently post-processors do not copy the values to old and older; 85 : // _pps_value_old will therefore always be zero for _t_step = 0. 86 33 : if (_t_step == 0) 87 11 : base_value = _pps_value; 88 : else 89 22 : base_value = _pps_value_old; 90 : } 91 : 92 : Real change; 93 550 : if (_compute_relative_change) 94 0 : change = (_pps_value - base_value) / base_value; 95 : else 96 550 : change = _pps_value - base_value; 97 : 98 550 : if (_take_absolute_value) 99 0 : _value = std::fabs(change); 100 : else 101 550 : _value = change; 102 550 : } 103 : 104 : Real 105 550 : ChangeOverTimePostprocessor::getValue() const 106 : { 107 550 : return _value; 108 : }