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 "WeightedVariableAverage.h" 11 : 12 : registerMooseObject("PhaseFieldApp", WeightedVariableAverage); 13 : 14 : InputParameters 15 23 : WeightedVariableAverage::validParams() 16 : { 17 23 : InputParameters params = ElementPostprocessor::validParams(); 18 23 : params.addClassDescription( 19 : "Average a variable value using a weight mask given by a material property."); 20 46 : params.addCoupledVar("v", "Variable to perform weighted average on."); 21 46 : params.addRequiredParam<MaterialPropertyName>("weight", 22 : "Weight material property for averaging."); 23 23 : return params; 24 0 : } 25 : 26 12 : WeightedVariableAverage::WeightedVariableAverage(const InputParameters & parameters) 27 24 : : ElementPostprocessor(parameters), _v(coupledValue("v")), _w(getMaterialProperty<Real>("weight")) 28 : { 29 12 : } 30 : 31 : void 32 9 : WeightedVariableAverage::initialize() 33 : { 34 9 : _var_integral = 0.0; 35 9 : _weight_integral = 0.0; 36 9 : } 37 : 38 : void 39 60 : WeightedVariableAverage::execute() 40 : { 41 180 : for (unsigned int qp = 0; qp < _qrule->n_points(); qp++) 42 : { 43 120 : auto j = _JxW[qp] * _coord[qp]; 44 120 : _var_integral += j * _v[qp] * _w[qp]; 45 120 : _weight_integral += j * _w[qp]; 46 : } 47 60 : } 48 : 49 : void 50 8 : WeightedVariableAverage::finalize() 51 : { 52 8 : gatherSum(_var_integral); 53 8 : gatherSum(_weight_integral); 54 8 : } 55 : 56 : PostprocessorValue 57 8 : WeightedVariableAverage::getValue() const 58 : { 59 8 : if (_weight_integral == 0.0) 60 : return 0.0; 61 : 62 8 : return _var_integral / _weight_integral; 63 : } 64 : 65 : void 66 1 : WeightedVariableAverage::threadJoin(const UserObject & y) 67 : { 68 : const auto & pp = static_cast<const WeightedVariableAverage &>(y); 69 1 : _var_integral += pp._var_integral; 70 1 : _weight_integral += pp._weight_integral; 71 1 : }