https://mooseframework.inl.gov
ArrayVarReductionAux.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 "ArrayVarReductionAux.h"
11 
13 
16 {
18  params.addRequiredCoupledVar("array_variable", "Array variable to process.");
19  params.addParam<MooseEnum>(
20  "value_type",
21  MooseEnum("max=0 min=1 sum=2 average=3", "sum"),
22  "Type of reduction operation. Options are max, min, sum, and average.");
23  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  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  return params;
31 }
32 
34  : AuxKernel(parameters),
35  _array_variable(coupledArrayValue("array_variable")),
36  _value_type(getParam<MooseEnum>("value_type")),
37  _weights(isParamValid("weights")
38  ? getParam<RealEigenVector>("weights")
39  : RealEigenVector::Ones(getArrayVar("array_variable", 0)->count()))
40 {
41  const auto array_comps = getArrayVar("array_variable", 0)->count();
42  if (_weights.size() != array_comps)
43  paramError(
44  "weights",
45  "The number of values provided is " + std::to_string(_weights.size()) +
46  " but the number of components for the variable provided by 'array_variable' is " +
47  std::to_string(array_comps));
48  if (isParamValid("weights") && !(_value_type == "average" || _value_type == "sum"))
49  paramError("weights", "Is only meant to be be used when 'value_type' is average or sum");
50 }
51 
52 Real
54 {
55  switch (_value_type)
56  {
57  case 0:
58  return _array_variable[_qp].maxCoeff();
59 
60  case 1:
61  return _array_variable[_qp].minCoeff();
62 
63  case 2:
64  return _weights.cwiseProduct(_array_variable[_qp]).sum();
65 
66  case 3:
67  return _weights.cwiseProduct(_array_variable[_qp]).sum() / _weights.sum();
68  }
69 
70  return 0.0;
71 }
const RealEigenVector _weights
values specified by the weights parameter or 1 otherwise
Real computeValue() override
Compute and return the value of the aux variable.
unsigned int count() const
Get the number of components Note: For standard and vector variables, the number is one...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
registerMooseObject("MooseApp", ArrayVarReductionAux)
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
static InputParameters validParams()
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
const MooseEnum _value_type
The type of reduction operation performed on the array variable.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
const ArrayVariableValue & _array_variable
the array variable value we will perform the reduction on
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
ArrayVarReductionAux(const InputParameters &parameters)
ArrayMooseVariable * getArrayVar(const std::string &var_name, unsigned int comp)
Extract pointer to a coupled array variable.
Definition: Coupleable.C:306
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:230
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
static InputParameters validParams()
Definition: AuxKernel.C:27
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealEigenVector
Definition: MooseTypes.h:146
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:36