CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
EmbeddedRKStepper.cc
Go to the documentation of this file.
1#include "CLHEP/GenericFunctions/EmbeddedRKStepper.hh"
2#include "CLHEP/GenericFunctions/ExtendedButcherTableau.hh"
3#include <stdexcept>
4#include <vector>
5
6namespace Genfun {
7
8
10 tableau(mtableau){
11 }
12
14 }
15
19 std::vector<double> & errors) const {
20
21 // First step:
22 double h = d.time - s.time;
23 if (h<=0) throw std::runtime_error ("Runtime error in RKIntegrator (zero or negative stepsize)");
24 unsigned int nvar = (unsigned int)s.variable.size();
25
26 // Compute all of the k's..:
27 //
28 std::vector<std::vector<double> >k(tableau.nSteps());
29 for (unsigned int i=0;i<tableau.nSteps();i++) {
30 k[i].resize(nvar,0);
31 Argument arg(nvar);
32 for (unsigned int v=0;v<nvar;v++) arg[v]=s.variable[v];
33 for (unsigned int j=0;j<i;j++) {
34 for (unsigned int v=0;v<nvar;v++) arg[v] += h*tableau.A(i,j)*k[j][v];
35 }
36 for (unsigned int v=0;v<nvar;v++) k[i][v]=(*data->_diffEqn[v])(arg);
37 }
38 //
39 // Final result.
40 //
41 for (unsigned int v=0;v<nvar;v++) d.firstDerivative[v] = 0;
42 for (unsigned int i=0;i<tableau.nSteps();i++) {
43 for (unsigned int v=0;v<nvar;v++) d.firstDerivative[v] += tableau.b(i)*k[i][v];
44 }
45 for (unsigned int v=0;v<nvar;v++) d.variable[v] =s.variable[v]+h*d.firstDerivative[v];
46 //
47 //
48 //
49 errors.resize(nvar);
50 for (unsigned int v=0;v<nvar;v++) errors[v] = 0;
51 for (unsigned int i=0;i<tableau.nSteps();i++) {
52 for (unsigned int v=0;v<nvar;v++) errors[v] += (h*(tableau.bHat(i)-tableau.b(i))*k[i][v]);
53 }
54 return;
55 }
56
58 return new EmbeddedRKStepper(*this);
59 }
60
61 unsigned int EmbeddedRKStepper::order() const {
62 return tableau.order();
63 }
64}
EmbeddedRKStepper(const ExtendedButcherTableau &tableau=CashKarpXtTableau())
virtual unsigned int order() const
virtual void step(const RKIntegrator::RKData *data, const RKIntegrator::RKData::Data &sdata, RKIntegrator::RKData::Data &ddata, std::vector< double > &errors) const
virtual EmbeddedRKStepper * clone() const
unsigned int nSteps() const
double & A(unsigned int i, unsigned int j)
double & bHat(unsigned int i)
unsigned int order() const
double & b(unsigned int i)
std::vector< const AbsFunction * > _diffEqn
Definition: Abs.hh:14
std::vector< double > firstDerivative
std::vector< double > variable