CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
SimpleRKStepper.cc
Go to the documentation of this file.
1#include "CLHEP/GenericFunctions/SimpleRKStepper.hh"
2#include <cmath>
3#include <stdexcept>
4#include <vector>
5
6namespace Genfun {
7 SimpleRKStepper::SimpleRKStepper(const ButcherTableau & mtableau,double xstepsize):
8 tableau(mtableau),
9 stepsize(xstepsize)
10 {
11 }
12
16 double timeLimit ) const {
17 const double h = timeLimit==0 ? stepsize : timeLimit - s.time;
18 if (h<=0) throw std::runtime_error ("SimpleRKStepper: negative stepsize");
19 const unsigned int nvar = (unsigned int)s.variable.size();
20 // Compute all of the k's..:
21 //
22 std::vector<std::vector<double> >k(tableau.nSteps());
23 for (unsigned int i=0;i<tableau.nSteps();i++) {
24 k[i].resize(nvar,0);
25 Argument arg(nvar);
26 for (unsigned int v=0;v<nvar;v++) arg[v]=s.variable[v];
27 for (unsigned int j=0;j<i;j++) {
28 for (unsigned int v=0;v<nvar;v++) arg[v] += h*tableau.A(i,j)*k[j][v];
29 }
30 for (unsigned int v=0;v<nvar;v++) k[i][v]=(*data->_diffEqn[v])(arg);
31 }
32 //
33 // Final result.
34 //
35 for (unsigned int v=0;v<nvar;v++) d.firstDerivative[v] = 0;
36 for (unsigned int i=0;i<tableau.nSteps();i++) {
37 for (unsigned int v=0;v<nvar;v++) d.firstDerivative[v] += tableau.b(i)*k[i][v];
38 }
39 for (unsigned int v=0;v<nvar;v++) d.variable[v] =s.variable[v]+h*d.firstDerivative[v];
40 d.time = timeLimit==0 ? s.time + h : timeLimit;
41
42 }
43
45
47 return new SimpleRKStepper(*this);
48 }
49}
unsigned int nSteps() const
double & A(unsigned int i, unsigned int j)
double & b(unsigned int i)
std::vector< const AbsFunction * > _diffEqn
SimpleRKStepper(const ButcherTableau &tableau, double stepsize)
virtual void step(const RKIntegrator::RKData *data, const RKIntegrator::RKData::Data &sdata, RKIntegrator::RKData::Data &ddata, double timeLimit) const
virtual SimpleRKStepper * clone() const
Definition: Abs.hh:14
std::vector< double > firstDerivative
std::vector< double > variable