File indexing completed on 2025-12-15 10:11:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifndef RKIntegrator_h
0030 #define RKIntegrator_h 1
0031 #include "CLHEP/GenericFunctions/AbsFunction.hh"
0032 #include "CLHEP/GenericFunctions/Parameter.hh"
0033 #include "CLHEP/GenericFunctions/RCBase.hh"
0034 #include <vector>
0035 #include <set>
0036 namespace Genfun {
0037
0038
0039
0040
0041
0042
0043 class RKIntegrator {
0044
0045 public:
0046
0047
0048 class RKFunction;
0049 class RKData;
0050 class RKStepper;
0051
0052
0053 RKIntegrator(const RKStepper *stepper=NULL);
0054
0055
0056 virtual ~RKIntegrator();
0057
0058
0059
0060
0061
0062 Parameter * addDiffEquation (const AbsFunction * diffEquation,
0063 const std::string & variableName="anon",
0064 double defStartingValue=0.0,
0065 double startingValueMin=0.0,
0066 double startingValueMax=0.0);
0067
0068
0069
0070
0071 Parameter *createControlParameter (const std::string & variableName="anon",
0072 double defStartingValue=0.0,
0073 double startingValueMin=0.0,
0074 double startingValueMax=0.0);
0075
0076
0077
0078
0079 const RKFunction *getFunction(unsigned int i) const;
0080
0081
0082 private:
0083
0084
0085 const RKIntegrator & operator=(const RKIntegrator &right);
0086
0087
0088 RKIntegrator(const RKIntegrator &right);
0089
0090
0091
0092 RKData *_data;
0093
0094
0095
0096 std::vector<const RKFunction *> _fcn;
0097
0098
0099 };
0100
0101
0102 class RKIntegrator::RKData : public Genfun::RCBase {
0103
0104
0105 public:
0106
0107
0108 struct Data{
0109
0110 std::vector<double> variable;
0111 mutable std::vector<double> firstDerivative;
0112 double time;
0113
0114 Data(int size): variable(size), firstDerivative(size), time(0) {}
0115 bool operator < (const Data & right) const { return time < right.time; }
0116 bool operator == (const Data & right) const { return time==right.time; }
0117 };
0118
0119 RKData();
0120 void lock();
0121 void recache();
0122
0123 std::vector<Parameter *> _startingValParameter;
0124 std::vector<double> _startingValParameterCache;
0125
0126 std::vector <Parameter *> _controlParameter;
0127 std::vector <double> _controlParameterCache;
0128
0129 std::vector<const AbsFunction *> _diffEqn;
0130 std::set<Data > _fx;
0131 bool _locked;
0132 const RKStepper *_stepper;
0133 private:
0134
0135 ~RKData();
0136 friend class ImaginaryFriend;
0137
0138 };
0139
0140 class RKIntegrator::RKFunction : public AbsFunction {
0141
0142 FUNCTION_OBJECT_DEF(RKFunction)
0143
0144 public:
0145
0146
0147 RKFunction(RKData *data, unsigned int index);
0148
0149
0150 virtual ~RKFunction();
0151
0152
0153 RKFunction(const RKFunction &right);
0154
0155
0156 virtual double operator ()(double argument) const override;
0157 virtual double operator ()(const Argument & a) const override {return operator() (a[0]);}
0158
0159 private:
0160
0161
0162 const RKFunction & operator=(const RKFunction &right);
0163
0164
0165 RKData *_data;
0166 const unsigned int _index;
0167
0168 };
0169
0170
0171
0172 class RKIntegrator::RKStepper {
0173 public:
0174
0175 virtual ~RKStepper();
0176 virtual void step (const RKIntegrator::RKData *data,
0177 const RKIntegrator::RKData::Data & sdata,
0178 RKIntegrator::RKData::Data & ddata,
0179 double timeLimit=0) const =0;
0180 virtual RKStepper *clone() const=0;
0181
0182 };
0183
0184 }
0185
0186 #endif