https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LinearCombinationFunction.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
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
40Real
41LinearCombinationFunction::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
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
58RealGradient
59LinearCombinationFunction::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
67RealVectorValue
68LinearCombinationFunction::vectorValue(Real t, const Point & p) const
69{
70 RealVectorValue v;
71 for (const auto & fw : _fw)
72 v += fw.first->vectorValue(t, p) * fw.second;
73 return v;
74}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("MooseApp", LinearCombinationFunction)
Interface for objects that need to use functions.
const Function & getFunctionByName(const FunctionName &name) const
Get a function with a given name.
Base class for function objects.
Definition Function.h:30
static InputParameters validParams()
Class constructor.
Definition Function.C:16
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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...
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.
Sum_over_i (w_i * functions_i)
static InputParameters validParams()
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)
virtual RealGradient gradient(Real t, const Point &p) const override
Function objects can optionally provide a gradient at a point.
std::vector< std::pair< const Function *, Real > > _fw
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,...
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
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 ...
Definition MooseBase.h:457