LCOV - code coverage report
Current view: top level - src/auxkernels - ArrayVarReductionAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 33 35 94.3 %
Date: 2025-07-17 01:28:37 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 "ArrayVarReductionAux.h"
      11             : 
      12             : registerMooseObject("MooseApp", ArrayVarReductionAux);
      13             : 
      14             : InputParameters
      15       14541 : ArrayVarReductionAux::validParams()
      16             : {
      17       14541 :   InputParameters params = AuxKernel::validParams();
      18       14541 :   params.addRequiredCoupledVar("array_variable", "Array variable to process.");
      19       43623 :   params.addParam<MooseEnum>(
      20             :       "value_type",
      21       29082 :       MooseEnum("max=0 min=1 sum=2 average=3", "sum"),
      22             :       "Type of reduction operation. Options are max, min, sum, and average.");
      23       14541 :   params.addParam<RealEigenVector>(
      24             :       "weights",
      25             :       "Relevant when 'value_type' is sum or average. When computing an average, these are the "
      26             :       "weights for a weighted average and when computing a sum, these weight scale each variable "
      27             :       "component in the summation.");
      28       14541 :   params.addClassDescription("Takes an array variable and performs a reduction operation on it "
      29             :                              "(max, min, sum, average) and stores as a standard variable.");
      30       14541 :   return params;
      31           0 : }
      32             : 
      33         140 : ArrayVarReductionAux::ArrayVarReductionAux(const InputParameters & parameters)
      34             :   : AuxKernel(parameters),
      35         140 :     _array_variable(coupledArrayValue("array_variable")),
      36         140 :     _value_type(getParam<MooseEnum>("value_type")),
      37         420 :     _weights(isParamValid("weights")
      38         140 :                  ? getParam<RealEigenVector>("weights")
      39         386 :                  : RealEigenVector::Ones(getArrayVar("array_variable", 0)->count()))
      40             : {
      41         140 :   const auto array_comps = getArrayVar("array_variable", 0)->count();
      42         140 :   if (_weights.size() != array_comps)
      43           4 :     paramError(
      44             :         "weights",
      45           4 :         "The number of values provided is " + std::to_string(_weights.size()) +
      46           4 :             " but the number of components for the variable provided by 'array_variable' is " +
      47           4 :             std::to_string(array_comps));
      48         136 :   if (isParamValid("weights") && !(_value_type == "average" || _value_type == "sum"))
      49           4 :     paramError("weights", "Is only meant to be be used when 'value_type' is average or sum");
      50         132 : }
      51             : 
      52             : Real
      53         344 : ArrayVarReductionAux::computeValue()
      54             : {
      55         344 :   switch (_value_type)
      56             :   {
      57          64 :     case 0:
      58          64 :       return _array_variable[_qp].maxCoeff();
      59             : 
      60          64 :     case 1:
      61          64 :       return _array_variable[_qp].minCoeff();
      62             : 
      63         152 :     case 2:
      64         152 :       return _weights.cwiseProduct(_array_variable[_qp]).sum();
      65             : 
      66          64 :     case 3:
      67          64 :       return _weights.cwiseProduct(_array_variable[_qp]).sum() / _weights.sum();
      68             :   }
      69             : 
      70           0 :   return 0.0;
      71             : }

Generated by: LCOV version 1.14