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 
14 template <>
17 {
19  params.addParam<std::vector<FunctionName>>("functions",
20  "The functions to be multiplied together.");
21  params.addParam<Real>("scale_factor", 1.0, "Scale factor to be applied to the ordinate values");
22  params.addClassDescription("Multiplies an arbitrary set of functions together");
23  return params;
24 }
25 
27  : Function(parameters), FunctionInterface(this), _scale_factor(getParam<Real>("scale_factor"))
28 {
29 
30  const std::vector<FunctionName> & names = getParam<std::vector<FunctionName>>("functions");
31  const unsigned int len = names.size();
32  if (len == 0)
33  mooseError("A composite function must reference at least one other function");
34 
35  _f.resize(len);
36 
37  for (unsigned i = 0; i < len; ++i)
38  {
39  if (name() == names[i])
40  mooseError("A composite function must not reference itself");
41 
42  Function * const f = &getFunctionByName(names[i]);
43  if (!f)
44  {
45  std::string msg("Error in composite function ");
46  msg += name();
47  msg += ". Function ";
48  msg += names[i];
49  msg += " referenced but not found.";
50  mooseError(msg);
51  }
52  _f[i] = f;
53  }
54 }
55 
56 Real
57 CompositeFunction::value(Real t, const Point & p)
58 {
59  Real val = _scale_factor;
60 
61  for (const auto & func : _f)
62  val *= func->value(t, p);
63 
64  return val;
65 }
Base class for function objects.
Definition: Function.h:40
std::vector< Function * > _f
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
virtual Real value(Real t, const Point &pt) override
Override this to evaluate the scalar function at point (t,x,y,z), by default this returns zero...
Base class for function objects.
CompositeFunction(const InputParameters &parameters)
registerMooseObject("MooseApp", CompositeFunction)
InputParameters validParams< CompositeFunction >()
Function & getFunctionByName(const FunctionName &name)
Get a function with a given name.
const Real _scale_factor
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
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...
InputParameters validParams< Function >()
Definition: Function.C:14
Interface for objects that need to use functions.