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