www.mooseframework.org
CompositeFunction.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 
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 
55 Real
56 CompositeFunction::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 
66 ADReal
67 CompositeFunction::value(const ADReal & t, const ADPoint & p) const
68 {
69  ADReal val = _scale_factor;
70 
71  for (const auto & func : _f)
72  val *= func->value(t, p);
73 
74  return val;
75 }
static InputParameters validParams()
Base class for function objects.
Definition: Function.h:37
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
Base class for function objects.
CompositeFunction(const InputParameters &parameters)
registerMooseObject("MooseApp", CompositeFunction)
DualReal ADReal
Definition: ADRealForward.h:14
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...
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.
const Real _scale_factor
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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 option parameter and a documentation string to the InputParameters object...
static InputParameters validParams()
Class constructor.
Definition: Function.C:15
Interface for objects that need to use functions.
std::vector< const Function * > _f