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 "AverageVariableChange.h" 11 : #include "MooseUtils.h" 12 : 13 : registerMooseObject("MooseApp", AverageVariableChange); 14 : 15 : InputParameters 16 3253 : AverageVariableChange::validParams() 17 : { 18 3253 : InputParameters params = ElementIntegralVariablePostprocessor::validParams(); 19 : 20 6506 : params.addClassDescription("Computes the volume-weighted L1 or L2 norm of the change of a " 21 : "variable over a time step or between nonlinear iterations."); 22 : 23 13012 : MooseEnum change_over("time_step nonlinear_iteration"); 24 13012 : params.addRequiredParam<MooseEnum>( 25 : "change_over", change_over, "Interval over which to compute the change"); 26 : 27 13012 : MooseEnum norm("L1 L2"); 28 9759 : params.addRequiredParam<MooseEnum>("norm", norm, "Type of norm to compute"); 29 : 30 6506 : return params; 31 3253 : } 32 : 33 100 : AverageVariableChange::AverageVariableChange(const InputParameters & parameters) 34 : : ElementIntegralVariablePostprocessor(parameters), 35 100 : _change_over(getParam<MooseEnum>("change_over")), 36 224 : _u_change_old(_change_over == "time_step" ? coupledValueOld("variable") 37 252 : : coupledValuePreviousNL("variable")), 38 200 : _norm(getParam<MooseEnum>("norm")), 39 100 : _norm_exponent(_norm == "L1" ? 1 : 2), 40 100 : _volume(0) 41 : { 42 100 : } 43 : 44 : void 45 624 : AverageVariableChange::initialize() 46 : { 47 624 : ElementIntegralVariablePostprocessor::initialize(); 48 624 : _volume = 0; 49 624 : } 50 : 51 : void 52 40400 : AverageVariableChange::execute() 53 : { 54 40400 : ElementIntegralVariablePostprocessor::execute(); 55 40400 : _volume += _current_elem_volume; 56 40400 : } 57 : 58 : void 59 55 : AverageVariableChange::threadJoin(const UserObject & y) 60 : { 61 55 : ElementIntegralVariablePostprocessor::threadJoin(y); 62 55 : const auto & pps = static_cast<const AverageVariableChange &>(y); 63 55 : _volume += pps._volume; 64 55 : } 65 : 66 : void 67 569 : AverageVariableChange::finalize() 68 : { 69 569 : gatherSum(_volume); 70 569 : gatherSum(_integral_value); 71 569 : } 72 : 73 : Real 74 569 : AverageVariableChange::getValue() const 75 : { 76 : mooseAssert(!MooseUtils::absoluteFuzzyEqual(_volume, 0.0), "Volume must be nonzero."); 77 569 : return std::pow(_integral_value / _volume, 1.0 / _norm_exponent); 78 : } 79 : 80 : Real 81 161600 : AverageVariableChange::computeQpIntegral() 82 : { 83 161600 : return std::pow(std::abs(_u[_qp] - _u_change_old[_qp]), _norm_exponent); 84 : }