www.mooseframework.org
LinearCombinationFunction.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
13 
16 {
18  params.addRequiredParam<std::vector<FunctionName>>(
19  "functions", "This function will return Sum_over_i(w_i * functions_i)");
20  params.addRequiredParam<std::vector<Real>>(
21  "w", "This function will return Sum_over_i(w_i * functions_i)");
22  params.addClassDescription("Returns the linear combination of the functions");
23  return params;
24 }
25 
27  : Function(parameters), FunctionInterface(this)
28 {
29  const auto fname_w = getParam<FunctionName, Real>("functions", "w");
30 
31  for (const auto & fw : fname_w)
32  {
33  if (name() == fw.first)
34  paramError("functions", "A LinearCombinationFunction must not reference itself");
35 
36  _fw.emplace_back(&getFunctionByName(fw.first), fw.second);
37  }
38 }
39 
40 Real
41 LinearCombinationFunction::value(Real t, const Point & p) const
42 {
43  Real val = 0;
44  for (const auto & fw : _fw)
45  val += fw.first->value(t, p) * fw.second;
46  return val;
47 }
48 
49 ADReal
50 LinearCombinationFunction::value(const ADReal & t, const ADPoint & p) const
51 {
52  ADReal val = 0.0;
53  for (const auto & fw : _fw)
54  val += fw.first->value(t, p) * fw.second;
55  return val;
56 }
57 
59 LinearCombinationFunction::gradient(Real t, const Point & p) const
60 {
61  RealGradient g;
62  for (const auto & fw : _fw)
63  g += fw.first->gradient(t, p) * fw.second;
64  return g;
65 }
66 
68 LinearCombinationFunction::vectorValue(Real t, const Point & p) const
69 {
71  for (const auto & fw : _fw)
72  v += fw.first->vectorValue(t, p) * fw.second;
73  return v;
74 }
Sum_over_i (w_i * functions_i)
Base class for function objects.
Definition: Function.h:37
registerMooseObject("MooseApp", LinearCombinationFunction)
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual RealVectorValue vectorValue(Real t, const Point &p) const override
Override this to evaluate the vector function at a point (t,x,y,z), by default this returns a zero ve...
LinearCombinationFunction(const InputParameters &parameters)
std::vector< std::pair< const Function *, Real > > _fw
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
DualReal ADReal
Definition: ADRealForward.h:14
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 ...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Function & getFunctionByName(const FunctionName &name) const
Get a function with a given name.
virtual Real value(Real t, const Point &pt) const override
Override this to evaluate the scalar function at point (t,x,y,z), by default this returns zero...
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...
virtual RealGradient gradient(Real t, const Point &p) const override
Function objects can optionally provide a gradient at a point.
static InputParameters validParams()
Class constructor.
Definition: Function.C:15
Interface for objects that need to use functions.