CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
Genfun::AdaptiveRKStepper Class Reference

#include <AdaptiveRKStepper.hh>

+ Inheritance diagram for Genfun::AdaptiveRKStepper:

Classes

class  EEStepper
 

Public Member Functions

 AdaptiveRKStepper (const EEStepper *eeStepper=NULL)
 
 AdaptiveRKStepper (const AdaptiveRKStepper &right)
 
virtual ~AdaptiveRKStepper ()
 
virtual void step (const RKIntegrator::RKData *data, const RKIntegrator::RKData::Data &sdata, RKIntegrator::RKData::Data &ddata, double timeLimit) const
 
virtual AdaptiveRKStepperclone () const
 
doubletolerance ()
 
const doubletolerance () const
 
doublestartingStepsize ()
 
const doublestartingStepsize () const
 
doublesafetyFactor ()
 
const doublesafetyFactor () const
 
doublermin ()
 
const doublermin () const
 
doublermax ()
 
const doublermax () const
 
- Public Member Functions inherited from Genfun::RKIntegrator::RKStepper
virtual ~RKStepper ()
 
virtual void step (const RKIntegrator::RKData *data, const RKIntegrator::RKData::Data &sdata, RKIntegrator::RKData::Data &ddata, double timeLimit=0) const =0
 
virtual RKStepperclone () const =0
 

Detailed Description

Definition at line 10 of file AdaptiveRKStepper.hh.

Constructor & Destructor Documentation

◆ AdaptiveRKStepper() [1/2]

Genfun::AdaptiveRKStepper::AdaptiveRKStepper ( const EEStepper eeStepper = NULL)

Definition at line 10 of file AdaptiveRKStepper.cc.

10 :
11 eeStepper(stepper ? stepper->clone():new EmbeddedRKStepper()),
12 T(1.0E-6),
13 sStepsize(0.01),
14 S(0.9),
15 Rmin(0.0),
16 Rmax(5.0),
17 stepsize(sStepsize)
18 {
19 }

◆ AdaptiveRKStepper() [2/2]

Genfun::AdaptiveRKStepper::AdaptiveRKStepper ( const AdaptiveRKStepper right)

Definition at line 21 of file AdaptiveRKStepper.cc.

21 :
22 RKStepper(right),
23 eeStepper(right.eeStepper->clone()),
24 T(right.T),
25 sStepsize(right.sStepsize),
26 S(right.S),
27 Rmin(right.Rmin),
28 Rmax(right.Rmax),
29 stepsize(right.sStepsize)
30 {
31 }

◆ ~AdaptiveRKStepper()

Genfun::AdaptiveRKStepper::~AdaptiveRKStepper ( )
virtual

Definition at line 97 of file AdaptiveRKStepper.cc.

97 {
98 delete eeStepper;
99 }

Member Function Documentation

◆ clone()

AdaptiveRKStepper * Genfun::AdaptiveRKStepper::clone ( ) const
virtual

Implements Genfun::RKIntegrator::RKStepper.

Definition at line 101 of file AdaptiveRKStepper.cc.

101 {
102 return new AdaptiveRKStepper(*this);
103 }
AdaptiveRKStepper(const EEStepper *eeStepper=NULL)

◆ rmax() [1/2]

double & Genfun::AdaptiveRKStepper::rmax ( )

Definition at line 138 of file AdaptiveRKStepper.cc.

138 {
139 return Rmax;
140 }

◆ rmax() [2/2]

const double & Genfun::AdaptiveRKStepper::rmax ( ) const

Definition at line 141 of file AdaptiveRKStepper.cc.

141 {
142 return Rmax;
143 }

◆ rmin() [1/2]

double & Genfun::AdaptiveRKStepper::rmin ( )

Definition at line 131 of file AdaptiveRKStepper.cc.

131 {
132 return Rmin;
133 }

◆ rmin() [2/2]

const double & Genfun::AdaptiveRKStepper::rmin ( ) const

Definition at line 134 of file AdaptiveRKStepper.cc.

134 {
135 return Rmin;
136 }

◆ safetyFactor() [1/2]

double & Genfun::AdaptiveRKStepper::safetyFactor ( )

Definition at line 123 of file AdaptiveRKStepper.cc.

123 {
124 return S;
125 }

◆ safetyFactor() [2/2]

const double & Genfun::AdaptiveRKStepper::safetyFactor ( ) const

Definition at line 127 of file AdaptiveRKStepper.cc.

127 {
128 return S;
129 }

◆ startingStepsize() [1/2]

double & Genfun::AdaptiveRKStepper::startingStepsize ( )

Definition at line 116 of file AdaptiveRKStepper.cc.

116 {
117 return sStepsize;
118 }

◆ startingStepsize() [2/2]

const double & Genfun::AdaptiveRKStepper::startingStepsize ( ) const

Definition at line 119 of file AdaptiveRKStepper.cc.

119 {
120 return sStepsize;
121 }

◆ step()

void Genfun::AdaptiveRKStepper::step ( const RKIntegrator::RKData data,
const RKIntegrator::RKData::Data sdata,
RKIntegrator::RKData::Data ddata,
double  timeLimit 
) const
virtual

Implements Genfun::RKIntegrator::RKStepper.

Definition at line 34 of file AdaptiveRKStepper.cc.

37 {
38 //
39 // Adaptive stepsize control
40 //
41 if (s.time==0.0) {
42 stepsize=sStepsize;
43 }
44 const unsigned int p = eeStepper->order(); // Order of the stepper
45 const double deltaMax = T*std::pow(S/Rmax, (int)(p+1)); // Maximum error 4 adjustment.
46 const double TINY = 1.0E-30; // Denominator regularization
47 double hnext;
48 //
49 // Time limited step ?
50 //
51 d.time= timeLimit==0? s.time+stepsize : timeLimit;
52
53 //--------------------------------------//
54 // Take one step, from s to d: //
55 //--------------------------------------//
56 double h = d.time-s.time;
57 while (1) {
58 std::vector<double> errors;
59 eeStepper->step(data, s, d, errors);
60 if (timeLimit!=0.0) return;
61
62 // Take absolute value:
63 for (size_t e=0;e<errors.size();e++) errors[e] = fabs(errors[e]);
64
65 // Select the largest:
66 double delta = (*std::max_element(errors.begin(),errors.end()));
67 if (delta > T) {
68 //
69 // Bail out and try a smaller step.
70 //
71 h = std::max(S*h*std::pow(T/(delta + TINY), 1.0/(p+1)),Rmin*h);
72 if (!(((double) (s.time+h) - (double) s.time) > 0) ) {
73 throw std::runtime_error("Warning, RK Integrator step underflow");
74 }
75 d.time = s.time+h;
76 hnext=h;
77 continue;
78 }
79 else {
80 if (delta < deltaMax) {
81 hnext = S*h*std::pow(T/(delta + TINY),1.0/(p+1));
82 // stepsize is supposed to increase;
83 if (hnext<h) hnext=h;
84 }
85 else {
86 hnext = Rmax*h;
87 }
88 }
89 break;
90 }
91 stepsize=hnext;
92 return;
93 }
virtual void step(const RKIntegrator::RKData *data, const RKIntegrator::RKData::Data &sdata, RKIntegrator::RKData::Data &ddata, std::vector< double > &errors) const =0
virtual unsigned int order() const =0

◆ tolerance() [1/2]

double & Genfun::AdaptiveRKStepper::tolerance ( )

Definition at line 108 of file AdaptiveRKStepper.cc.

108 {
109 return T;
110 }

◆ tolerance() [2/2]

const double & Genfun::AdaptiveRKStepper::tolerance ( ) const

Definition at line 112 of file AdaptiveRKStepper.cc.

112 {
113 return T;
114 }

The documentation for this class was generated from the following files: