https://mooseframework.inl.gov
ADWeightedAverageMaterial.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 
11 
12 registerMooseObject("ThermalHydraulicsApp", ADWeightedAverageMaterial);
13 
16 {
18 
19  params.addClassDescription("Weighted average of material properties using variables as weights");
20 
21  params.addRequiredParam<MaterialPropertyName>(
22  "prop_name", "The name of the material property where the average is stored");
23  params.addRequiredParam<std::vector<MaterialPropertyName>>("values",
24  "Vector of values to average");
25  params.addRequiredCoupledVar("weights", "Vector of weights for each value");
26 
27  return params;
28 }
29 
31  : Material(parameters),
32  _prop(declareADProperty<Real>(getParam<MaterialPropertyName>("prop_name"))),
33  _n_values(getParam<std::vector<MaterialPropertyName>>("values").size())
34 {
35  // make sure that number of weights equals the number of values
36  if (coupledComponents("weights") != _n_values)
37  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  getParam<std::vector<MaterialPropertyName>>("values");
42  for (unsigned int i = 0; i < _n_values; i++)
43  {
44  _values.push_back(&getADMaterialPropertyByName<Real>(prop_names[i]));
45  _weights.push_back(&adCoupledValue("weights", i));
46  }
47 }
48 
49 void
51 {
52  ADReal weight_total = 0;
53  for (unsigned int i = 0; i < _n_values; i++)
54  weight_total += (*(_weights[i]))[_qp];
55 
56  ADReal weighted_sum = 0;
57  for (unsigned int i = 0; i < _n_values; i++)
58  weighted_sum += (*(_weights[i]))[_qp] * (*(_values[i]))[_qp];
59 
60  _prop[_qp] = weighted_sum / weight_total;
61 }
static InputParameters validParams()
const ADVariableValue & adCoupledValue(const std::string &var_name, unsigned int comp=0) const
ADWeightedAverageMaterial(const InputParameters &parameters)
Weighted average of material properties using aux variables as the weights
virtual const std::string & name() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
const unsigned int _n_values
Number of components (i.e. values and weights)
unsigned int _qp
std::vector< const ADVariableValue * > _weights
Weights of the values.
static InputParameters validParams()
std::vector< const ADMaterialProperty< Real > * > _values
Values to average.
registerMooseObject("ThermalHydraulicsApp", ADWeightedAverageMaterial)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
unsigned int coupledComponents(const std::string &var_name) const
ADMaterialProperty< Real > & _prop
The material property where the weighted average is stored.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)