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 "AverageNodalVariableValue.h" 11 : #include "MooseMesh.h" 12 : #include "SubProblem.h" 13 : 14 : registerMooseObject("MooseApp", AverageNodalVariableValue); 15 : 16 : InputParameters 17 14440 : AverageNodalVariableValue::validParams() 18 : { 19 14440 : InputParameters params = NodalVariablePostprocessor::validParams(); 20 : 21 14440 : params.addClassDescription("Computes the average value of a field by sampling all nodal " 22 : "solutions on the domain or within a subdomain"); 23 14440 : return params; 24 0 : } 25 : 26 91 : AverageNodalVariableValue::AverageNodalVariableValue(const InputParameters & parameters) 27 91 : : NodalVariablePostprocessor(parameters), _sum(0), _n(0) 28 : { 29 91 : } 30 : 31 : // doco-init-start 32 : void 33 612 : AverageNodalVariableValue::initialize() 34 : { 35 612 : _sum = 0; 36 612 : _n = 0; 37 612 : } 38 : // doco-init-end 39 : 40 : // doco-execute-get-start 41 : void 42 5304 : AverageNodalVariableValue::execute() 43 : { 44 5304 : _sum += _u[_qp]; 45 5304 : _n++; 46 5304 : } 47 : 48 : Real 49 561 : AverageNodalVariableValue::getValue() const 50 : { 51 561 : return _sum / _n; 52 : } 53 : // doco-execute-get-end 54 : 55 : // doco-final-start 56 : void 57 561 : AverageNodalVariableValue::finalize() 58 : { 59 561 : gatherSum(_sum); 60 561 : gatherSum(_n); 61 561 : } 62 : // doco-final-end 63 : 64 : // doco-thread-start 65 : void 66 51 : AverageNodalVariableValue::threadJoin(const UserObject & y) 67 : { 68 51 : const auto & pps = static_cast<const AverageNodalVariableValue &>(y); 69 51 : _sum += pps._sum; 70 51 : _n += pps._n; 71 51 : } 72 : // doco-thread-end