LCOV - code coverage report
Current view: top level - src/auxkernels - WeightedAverageAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #30301 (3b550b) with base 2ad78d Lines: 19 21 90.5 %
Date: 2025-07-30 13:02:48 Functions: 3 3 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 "WeightedAverageAux.h"
      11             : 
      12             : registerMooseObject("ThermalHydraulicsApp", WeightedAverageAux);
      13             : 
      14             : InputParameters
      15          41 : WeightedAverageAux::validParams()
      16             : {
      17          41 :   InputParameters params = AuxKernel::validParams();
      18             : 
      19          41 :   params.addClassDescription("Weighted average of variables using other variables as weights");
      20             : 
      21          82 :   params.addRequiredCoupledVar("values", "Vector of values to average");
      22          82 :   params.addRequiredCoupledVar("weights", "Vector of weights for each value");
      23             : 
      24          41 :   return params;
      25           0 : }
      26             : 
      27          22 : WeightedAverageAux::WeightedAverageAux(const InputParameters & parameters)
      28          22 :   : AuxKernel(parameters), _n_values(coupledComponents("values"))
      29             : {
      30             :   // make sure that number of weights equals the number of values
      31          22 :   if (coupledComponents("weights") != _n_values)
      32           0 :     mooseError(name(), ": The number of weights must equal the number of values");
      33             : 
      34             :   // get all of the variable values
      35          66 :   for (unsigned int i = 0; i < _n_values; i++)
      36             :   {
      37          44 :     _values.push_back(&coupledValue("values", i));
      38          88 :     _weights.push_back(&coupledValue("weights", i));
      39             :   }
      40          22 : }
      41             : 
      42             : Real
      43          36 : WeightedAverageAux::computeValue()
      44             : {
      45             :   Real weight_total = 0;
      46         108 :   for (unsigned int i = 0; i < _n_values; i++)
      47          72 :     weight_total += (*(_weights[i]))[_qp];
      48             : 
      49             :   Real weighted_sum = 0;
      50         108 :   for (unsigned int i = 0; i < _n_values; i++)
      51          72 :     weighted_sum += (*(_weights[i]))[_qp] * (*(_values[i]))[_qp];
      52             : 
      53          36 :   return weighted_sum / weight_total;
      54             : }

Generated by: LCOV version 1.14