LCOV - code coverage report
Current view: top level - src/reporters - ElementStatistics.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 45 46 97.8 %
Date: 2025-08-08 20:01:16 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14