54#ifndef G4T_CASH_KARP_RKF45_HH
55#define G4T_CASH_KARP_RKF45_HH
62template <
class T_Equation,
unsigned int N = 6 >
89 fEquation_Rhs->T_Equation::RightHandSide(y, dydx);
102 G4double ak2[N], ak3[N], ak4[N], ak5[N], ak6[N], ak7[N], yTemp[N], yIn[N];
115 T_Equation* fEquation_Rhs;
122template <
class T_Equation,
unsigned int N >
126 , fEquation_Rhs(EqRhs)
130 G4Exception(
"G4TCashKarpRKF45: constructor",
"GeomField0001",
134 fLastInitialVector =
new G4double[N];
147template <
class T_Equation,
unsigned int N >
150 delete[] fLastInitialVector;
151 delete[] fLastFinalVector;
169template <
class T_Equation,
unsigned int N >
179 const G4double b21 = 0.2, b31 = 3.0 / 40.0, b32 = 9.0 / 40.0, b41 = 0.3,
180 b42 = -0.9, b43 = 1.2,
182 b51 = -11.0 / 54.0, b52 = 2.5, b53 = -70.0 / 27.0,
185 b61 = 1631.0 / 55296.0, b62 = 175.0 / 512.0,
186 b63 = 575.0 / 13824.0, b64 = 44275.0 / 110592.0,
187 b65 = 253.0 / 4096.0,
189 c1 = 37.0 / 378.0, c3 = 250.0 / 621.0, c4 = 125.0 / 594.0,
190 c6 = 512.0 / 1771.0, dc5 = -277.0 / 14336.0;
192 const G4double dc1 = c1 - 2825.0 / 27648.0, dc3 = c3 - 18575.0 / 48384.0,
193 dc4 = c4 - 13525.0 / 55296.0, dc6 = c6 - 0.25;
201 for(
unsigned int i = 0; i < N; ++i)
207 for(
unsigned int i = 0; i < N; ++i)
209 yTemp[i] = yIn[i] + b21 * Step * dydx[i];
211 this->RightHandSideInl(yTemp, ak2);
213 for(
unsigned int i = 0; i < N; ++i)
215 yTemp[i] = yIn[i] + Step * (b31 * dydx[i] + b32 * ak2[i]);
217 this->RightHandSideInl(yTemp, ak3);
219 for(
unsigned int i = 0; i < N; ++i)
221 yTemp[i] = yIn[i] + Step * (b41 * dydx[i] + b42 * ak2[i] + b43 * ak3[i]);
223 this->RightHandSideInl(yTemp, ak4);
225 for(
unsigned int i = 0; i < N; ++i)
227 yTemp[i] = yIn[i] + Step * (b51 * dydx[i] + b52 * ak2[i] + b53 * ak3[i] +
230 this->RightHandSideInl(yTemp, ak5);
232 for(
unsigned int i = 0; i < N; ++i)
234 yTemp[i] = yIn[i] + Step * (b61 * dydx[i] + b62 * ak2[i] + b63 * ak3[i] +
235 b64 * ak4[i] + b65 * ak5[i]);
237 this->RightHandSideInl(yTemp, ak6);
239 for(
unsigned int i = 0; i < N; ++i)
244 Step * (c1 * dydx[i] + c3 * ak3[i] + c4 * ak4[i] + c6 * ak6[i]);
246 for(
unsigned int i = 0; i < N; ++i)
251 yErr[i] = Step * (dc1 * dydx[i] + dc3 * ak3[i] + dc4 * ak4[i] +
252 dc5 * ak5[i] + dc6 * ak6[i]);
254 for(
unsigned int i = 0; i < N; ++i)
257 fLastInitialVector[i] = yIn[i];
258 fLastFinalVector[i] = yOut[i];
259 fLastDyDx[i] = dydx[i];
263 fLastStepLength = Step;
268template <
class T_Equation,
unsigned int N >
277 initialPoint =
G4ThreeVector(fLastInitialVector[0], fLastInitialVector[1],
278 fLastInitialVector[2]);
279 finalPoint =
G4ThreeVector(fLastFinalVector[0], fLastFinalVector[1],
280 fLastFinalVector[2]);
284 fAuxStepper->G4TCashKarpRKF45::Stepper(fLastInitialVector, fLastDyDx,
285 0.5 * fLastStepLength, fMidVector,
288 midPoint =
G4ThreeVector(fMidVector[0], fMidVector[1], fMidVector[2]);
293 if(initialPoint != finalPoint)
296 distChord = distLine;
300 distChord = (midPoint - initialPoint).mag();
305template <
class T_Equation,
unsigned int N >
313 assert( yOutput != yInput );
314 assert( yError != yInput );
316 StepWithError( yInput, dydx, Step, yOutput, yError);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::Hep3Vector G4ThreeVector
static G4double Distline(const G4ThreeVector &OtherPnt, const G4ThreeVector &LinePntA, const G4ThreeVector &LinePntB)
G4int IntegratorOrder() const override
G4TCashKarpRKF45(T_Equation *EqRhs, G4bool primary=true)
G4double DistChord() const override
void RightHandSideInl(const G4double y[], G4double dydx[])
void StepWithError(const G4double yInput[], const G4double dydx[], G4double Step, G4double yOut[], G4double yErr[])
virtual ~G4TCashKarpRKF45()
virtual void Stepper(const G4double yInput[], const G4double dydx[], G4double hstep, G4double yOutput[], G4double yError[]) override final