www.mooseframework.org
CompositeFunction.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "CompositeFunction.h"
16 
17 template <>
20 {
22  params.addParam<std::vector<FunctionName>>("functions",
23  "The functions to be multiplied together.");
24  params.addParam<Real>("scale_factor", 1.0, "Scale factor to be applied to the ordinate values");
25  params.addClassDescription("Multiplies an arbitrary set of functions together");
26  return params;
27 }
28 
30  : Function(parameters), FunctionInterface(this), _scale_factor(getParam<Real>("scale_factor"))
31 {
32 
33  const std::vector<FunctionName> & names = getParam<std::vector<FunctionName>>("functions");
34  const unsigned int len = names.size();
35  if (len == 0)
36  mooseError("A composite function must reference at least one other function");
37 
38  _f.resize(len);
39 
40  for (unsigned i = 0; i < len; ++i)
41  {
42  if (name() == names[i])
43  mooseError("A composite function must not reference itself");
44 
45  Function * const f = &getFunctionByName(names[i]);
46  if (!f)
47  {
48  std::string msg("Error in composite function ");
49  msg += name();
50  msg += ". Function ";
51  msg += names[i];
52  msg += " referenced but not found.";
53  mooseError(msg);
54  }
55  _f[i] = f;
56  }
57 }
58 
59 Real
60 CompositeFunction::value(Real t, const Point & p)
61 {
62  Real val = _scale_factor;
63 
64  for (const auto & func : _f)
65  val *= func->value(t, p);
66 
67  return val;
68 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
Base class for function objects.
Definition: Function.h:46
std::vector< Function * > _f
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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...
CompositeFunction(const InputParameters &parameters)
InputParameters validParams< CompositeFunction >()
Function & getFunctionByName(const FunctionName &name)
Get a function with a given name.
const Real _scale_factor
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
InputParameters validParams< Function >()
Definition: Function.C:19
Interface for objects that need to use functions.