https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CompositeFunction.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 "CompositeFunction.h"
11
13
16{
18 params.addParam<std::vector<FunctionName>>("functions",
19 "The functions to be multiplied together.");
20 params.addParam<Real>("scale_factor", 1.0, "Scale factor to be applied to the ordinate values");
21 params.addClassDescription("Multiplies an arbitrary set of functions together");
22 return params;
23}
24
26 : Function(parameters), FunctionInterface(this), _scale_factor(getParam<Real>("scale_factor"))
27{
28
29 const std::vector<FunctionName> & names = getParam<std::vector<FunctionName>>("functions");
30 const unsigned int len = names.size();
31 if (len == 0)
32 mooseError("A composite function must reference at least one other function");
33
34 _f.resize(len);
35
36 for (unsigned i = 0; i < len; ++i)
37 {
38 if (name() == names[i])
39 mooseError("A composite function must not reference itself");
40
41 const Function * f = &getFunctionByName(names[i]);
42 if (!f)
43 {
44 std::string msg("Error in composite function ");
45 msg += name();
46 msg += ". Function ";
47 msg += names[i];
48 msg += " referenced but not found.";
49 mooseError(msg);
50 }
51 _f[i] = f;
52 }
53}
54
55Real
56CompositeFunction::value(Real t, const Point & p) const
57{
58 Real val = _scale_factor;
59
60 for (const auto & func : _f)
61 val *= func->value(t, p);
62
63 return val;
64}
65
67CompositeFunction::value(const ADReal & t, const ADPoint & p) const
68{
70
71 for (const auto & func : _f)
72 val *= func->value(t, p);
73
74 return val;
75}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("MooseApp", CompositeFunction)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Base class for function objects.
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,...
std::vector< const Function * > _f
static InputParameters validParams()
CompositeFunction(const InputParameters &parameters)
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 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.
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.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103