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 "ElementStatistics.h" 11 : 12 : InputParameters 13 14290 : ElementStatistics::validParams() 14 : { 15 14290 : InputParameters params = ElementReporter::validParams(); 16 14290 : params.addParam<std::string>("base_name", "Name to append to reporters."); 17 14290 : return params; 18 0 : } 19 : 20 13 : ElementStatistics::ElementStatistics(const InputParameters & parameters) 21 : : ElementReporter(parameters), 22 13 : _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""), 23 13 : _max(declareValueByName<Real>(_base_name + "max")), 24 13 : _min(declareValueByName<Real>(_base_name + "min")), 25 13 : _average(declareValueByName<Real>(_base_name + "average")), 26 13 : _integral(declareValueByName<Real>(_base_name + "integral")), 27 26 : _number_elements(declareValueByName<int>(_base_name + "number_elements")) 28 : { 29 13 : } 30 : 31 : void 32 12 : ElementStatistics::initialize() 33 : { 34 12 : _max = std::numeric_limits<Real>::min(); 35 12 : _min = std::numeric_limits<Real>::max(); 36 12 : _average = 0; 37 12 : _integral = 0; 38 12 : _number_elements = 0; 39 12 : } 40 : 41 : void 42 800 : ElementStatistics::execute() 43 : { 44 : // Get value to to update statistics 45 800 : Real value = computeValue(); 46 : 47 800 : if (_max < value) 48 117 : _max = value; 49 : 50 800 : if (_min > value) 51 39 : _min = value; 52 : 53 800 : _integral += value * _current_elem_volume; 54 : 55 : // Update the total and the number to get the average when "finalizing" 56 800 : _average += value; 57 800 : _number_elements++; 58 800 : } 59 : 60 : void 61 1 : ElementStatistics::threadJoin(const UserObject & uo) 62 : { 63 1 : const ElementStatistics & ele_uo = static_cast<const ElementStatistics &>(uo); 64 1 : _max = std::max(_max, ele_uo._max); 65 1 : _min = std::min(_min, ele_uo._min); 66 1 : _integral += ele_uo._integral; 67 1 : _average += ele_uo._average; 68 1 : _number_elements += ele_uo._number_elements; 69 1 : } 70 : 71 : void 72 11 : ElementStatistics::finalize() 73 : { 74 11 : _communicator.max(_max); 75 11 : _communicator.min(_min); 76 11 : _communicator.sum(_integral); 77 11 : _communicator.sum(_average); 78 11 : _communicator.sum(_number_elements); 79 : 80 : // Compute the average; 81 11 : _average /= _number_elements; 82 11 : }