CYCLUS
symbolic_function_factories.h
Go to the documentation of this file.
1 #ifndef CYCLUS_SRC_TOOLKIT_SYMBOLIC_FUNCTION_FACTORIES_H_
2 #define CYCLUS_SRC_TOOLKIT_SYMBOLIC_FUNCTION_FACTORIES_H_
3 
4 #include <string>
5 #include <map>
6 #include <sstream>
7 
8 #include "symbolic_functions.h"
9 
10 namespace cyclus {
11 namespace toolkit {
12 
13 
14 /// An abstract factory for pointers to symbolic functions
16  public:
17  /// Virtual destructor for an abstract base class
18  virtual ~SymbFunctionFactory() {}
19 
20  /// A virtual function that must be defined by derived classes
21  /// @param params a string of required parameters for the function
22  /// @return a FunctionPtr to the constructed function
23  virtual SymFunction::Ptr GetFunctionPtr(std::string params) = 0;
24 };
25 
26 /// A concrete factory for linear functions
28  public:
29  /// Return a function pointer to a linear function
30  ///
31  /// @param params a string of space-separated values for m and b in the equation
32  /// \f[
33  /// y = mx + b
34  /// \f]
35  ///
36  /// @return the linear function
37  ///
38  /// \b Example
39  /// @code
40  /// SymFunction::Ptr func = fac.GetFunctionPtr("2.5 5"); // y = 2.5x + 5
41  /// @endcode
42  virtual SymFunction::Ptr GetFunctionPtr(std::string params);
43 };
44 
45 /// A concrete factory for exponential functions
47  public:
48  /// Return a function pointer to a exponential function
49  ///
50  /// @param params a string of space-separated values for c, a, and b in the
51  /// equation
52  /// \f[
53  /// y = ce^{ax} + b
54  /// \f]
55  ///
56  /// @return the exponential function
57  ///
58  /// \b Example
59  /// @code
60  /// SymFunction::Ptr func = fac.GetFunctionPtr("2.5 0.1 5"); // y = 2.5exp(0.1x) + 5
61  /// @endcode
62  virtual SymFunction::Ptr GetFunctionPtr(std::string params);
63 };
64 
65 /// A concrete factory for piecewise functions
67  public:
68  /// Constructor
70 
71  /// Return a function pointer to a piecewise function
72  /// @param params an empty string by default. if this is not empty,
73  /// an error is thrown
74  /// @return the piecewise function
75  virtual SymFunction::Ptr GetFunctionPtr(std::string params = "");
76 
77  /// Add a function to the piecewise function being constructed
78  /// @param function the function to append
79  /// @param starting_coord the x coordinate to begin this function
80  /// @param continuous if true, the added function and previous
81  /// function will be continuous, if false, discontinuous
82  void AddFunction(SymFunction::Ptr function, double starting_coord = 0.0,
83  bool continuous = true);
84 
85  private:
86  /// The piecewise function to construct
87  boost::shared_ptr<PiecewiseFunction> function_;
88 };
89 
90 /// A concrete factory that can provide access to basic symbolic
91 /// functions.
93  public:
94  /// The type of functions this factory can provide
95  enum FunctionType {
96  /// See cyclus::toolkit::LinFunctionFactory for a description of function
97  /// parameters
98  LIN,
99  /// See cyclus::toolkit::ExpFunctionFactory for a description of function
100  /// parameters
101  EXP
102  };
103 
104  /// Constructor sets up the enum names map
106 
107  /// Return a function pointer to a registered function type
108  /// @param type the function type, see BasicFunctionFactory::FunctionType for
109  /// supported function types. For each supported function type, either the
110  /// full name or the first three letters are acceptable. For example, for a
111  /// "linear" function, either "linear" or "lin" are acceptable.
112  /// @param params the function parameters
113  /// @return the function
114  SymFunction::Ptr GetFunctionPtr(std::string type, std::string params);
115 
116  private:
117  /// A map between enums and names
118  static std::map<std::string, BasicFunctionFactory::FunctionType> enum_names_;
119 };
120 
121 } // namespace toolkit
122 } // namespace cyclus
123 
124 #endif // CYCLUS_SRC_TOOLKIT_SYMBOLIC_FUNCTION_FACTORIES_H_
virtual SymFunction::Ptr GetFunctionPtr(std::string params)=0
A virtual function that must be defined by derived classes.
A concrete factory for exponential functions.
See cyclus::toolkit::LinFunctionFactory for a description of function parameters. ...
An abstract factory for pointers to symbolic functions.
virtual ~SymbFunctionFactory()
Virtual destructor for an abstract base class.
A concrete factory that can provide access to basic symbolic functions.
A concrete factory for linear functions.
A concrete factory for piecewise functions.
FunctionType
The type of functions this factory can provide.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
boost::shared_ptr< SymFunction > Ptr