https://mooseframework.inl.gov
Loading...
Searching...
No Matches
WeightedAverageAux.C
Go to the documentation of this file.
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
12registerMooseObject("ThermalHydraulicsApp", WeightedAverageAux);
13
16{
18
19 params.addClassDescription("Weighted average of variables using other variables as weights");
20
21 params.addRequiredCoupledVar("values", "Vector of values to average");
22 params.addRequiredCoupledVar("weights", "Vector of weights for each value");
23
24 return params;
25}
26
28 : AuxKernel(parameters), _n_values(coupledComponents("values"))
29{
30 // make sure that number of weights equals the number of values
31 if (coupledComponents("weights") != _n_values)
32 mooseError(name(), ": The number of weights must equal the number of values");
33
34 // get all of the variable values
35 for (unsigned int i = 0; i < _n_values; i++)
36 {
37 _values.push_back(&coupledValue("values", i));
38 _weights.push_back(&coupledValue("weights", i));
39 }
40}
41
42Real
44{
45 Real weight_total = 0;
46 for (unsigned int i = 0; i < _n_values; i++)
47 weight_total += (*(_weights[i]))[_qp];
48
49 Real weighted_sum = 0;
50 for (unsigned int i = 0; i < _n_values; i++)
51 weighted_sum += (*(_weights[i]))[_qp] * (*(_values[i]))[_qp];
52
53 return weighted_sum / weight_total;
54}
registerMooseObject("ThermalHydraulicsApp", WeightedAverageAux)
static InputParameters validParams()
virtual const VariableValue & coupledValue(const std::string &var_name, unsigned int comp=0) const
unsigned int coupledComponents(const std::string &var_name) const
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
const std::string & name() const
void mooseError(Args &&... args) const
Weighted average of an aux variable using another aux variable as the weights.
std::vector< const VariableValue * > _values
const unsigned int _n_values
virtual Real computeValue()
static InputParameters validParams()
std::vector< const VariableValue * > _weights
WeightedAverageAux(const InputParameters &parameters)