LCOV - code coverage report
Current view: top level - src/materials - WeightedAverageMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #30301 (3b550b) with base 2ad78d Lines: 0 25 0.0 %
Date: 2025-07-30 13:02:48 Functions: 0 3 0.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 "WeightedAverageMaterial.h"
      11             : 
      12             : registerMooseObject("ThermalHydraulicsApp", WeightedAverageMaterial);
      13             : 
      14             : InputParameters
      15           0 : WeightedAverageMaterial::validParams()
      16             : {
      17           0 :   InputParameters params = Material::validParams();
      18             : 
      19           0 :   params.addClassDescription("Weighted average of material properties using variables as weights");
      20             : 
      21           0 :   params.addRequiredParam<MaterialPropertyName>(
      22             :       "prop_name", "The name of the material property where the average is stored");
      23           0 :   params.addRequiredParam<std::vector<MaterialPropertyName>>("values",
      24             :                                                              "Vector of values to average");
      25           0 :   params.addRequiredCoupledVar("weights", "Vector of weights for each value");
      26             : 
      27           0 :   return params;
      28           0 : }
      29             : 
      30           0 : WeightedAverageMaterial::WeightedAverageMaterial(const InputParameters & parameters)
      31             :   : Material(parameters),
      32           0 :     _prop(declareProperty<Real>(getParam<MaterialPropertyName>("prop_name"))),
      33           0 :     _n_values(getParam<std::vector<MaterialPropertyName>>("values").size())
      34             : {
      35             :   // make sure that number of weights equals the number of values
      36           0 :   if (coupledComponents("weights") != _n_values)
      37           0 :     mooseError(name(), ": The number of weights must equal the number of values");
      38             : 
      39             :   // get all of the variable values
      40             :   const std::vector<MaterialPropertyName> & prop_names =
      41           0 :       getParam<std::vector<MaterialPropertyName>>("values");
      42           0 :   for (unsigned int i = 0; i < _n_values; i++)
      43             :   {
      44           0 :     _values.push_back(&getMaterialPropertyByName<Real>(prop_names[i]));
      45           0 :     _weights.push_back(&coupledValue("weights", i));
      46             :   }
      47           0 : }
      48             : 
      49             : void
      50           0 : WeightedAverageMaterial::computeQpProperties()
      51             : {
      52             :   Real weight_total = 0;
      53           0 :   for (unsigned int i = 0; i < _n_values; i++)
      54           0 :     weight_total += (*(_weights[i]))[_qp];
      55             : 
      56             :   Real weighted_sum = 0;
      57           0 :   for (unsigned int i = 0; i < _n_values; i++)
      58           0 :     weighted_sum += (*(_weights[i]))[_qp] * (*(_values[i]))[_qp];
      59             : 
      60           0 :   _prop[_qp] = weighted_sum / weight_total;
      61           0 : }

Generated by: LCOV version 1.14