Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4TCashKarpRKF45< T_Equation, N > Class Template Reference

G4TCashKarpRKF45 is a templated version of Cash-Karp 4th/5th order embedded stepper. More...

#include <G4TCashKarpRKF45.hh>

Inheritance diagram for G4TCashKarpRKF45< T_Equation, N >:

Public Member Functions

 G4TCashKarpRKF45 (T_Equation *EqRhs, G4bool primary=true)
virtual ~G4TCashKarpRKF45 ()
 G4TCashKarpRKF45 (const G4TCashKarpRKF45 &)=delete
G4TCashKarpRKF45operator= (const G4TCashKarpRKF45 &)=delete
void StepWithError (const G4double yInput[], const G4double dydx[], G4double Step, G4double yOut[], G4double yErr[])
virtual void Stepper (const G4double yInput[], const G4double dydx[], G4double hstep, G4double yOutput[], G4double yError[]) override final
void RightHandSideInl (const G4double y[], G4double dydx[])
G4double DistChord () const override
G4int IntegratorOrder () const override
G4StepperType StepperType () const override
Public Member Functions inherited from G4MagIntegratorStepper
 G4MagIntegratorStepper (G4EquationOfMotion *Equation, G4int numIntegrationVariables, G4int numStateVariables=12, G4bool isFSAL=false)
virtual ~G4MagIntegratorStepper ()=default
 G4MagIntegratorStepper (const G4MagIntegratorStepper &)=delete
G4MagIntegratorStepperoperator= (const G4MagIntegratorStepper &)=delete
void NormaliseTangentVector (G4double vec[6])
void NormalisePolarizationVector (G4double vec[12])
void RightHandSide (const G4double y[], G4double dydx[]) const
void RightHandSide (const G4double y[], G4double dydx[], G4double field[]) const
G4int GetNumberOfVariables () const
G4int GetNumberOfStateVariables () const
G4int IntegrationOrder ()
G4EquationOfMotionGetEquationOfMotion ()
const G4EquationOfMotionGetEquationOfMotion () const
void SetEquationOfMotion (G4EquationOfMotion *newEquation)
unsigned long GetfNoRHSCalls ()
void ResetfNORHSCalls ()
G4bool IsFSAL () const
G4bool isQSS () const
void SetIsQSS (G4bool val)

Additional Inherited Members

Protected Member Functions inherited from G4MagIntegratorStepper
void SetIntegrationOrder (G4int order)
void SetFSAL (G4bool flag=true)

Detailed Description

template<class T_Equation, unsigned int N = 6>
class G4TCashKarpRKF45< T_Equation, N >

G4TCashKarpRKF45 is a templated version of Cash-Karp 4th/5th order embedded stepper.

Definition at line 67 of file G4TCashKarpRKF45.hh.

Constructor & Destructor Documentation

◆ G4TCashKarpRKF45() [1/2]

template<class T_Equation, unsigned int N>
G4TCashKarpRKF45< T_Equation, N >::G4TCashKarpRKF45 ( T_Equation * EqRhs,
G4bool primary = true )

Definition at line 128 of file G4TCashKarpRKF45.hh.

131 , fEquation_Rhs(EqRhs)
132{
133 if( dynamic_cast<G4EquationOfMotion*>(EqRhs) == nullptr )
134 {
135 G4Exception("G4TCashKarpRKF45: constructor", "GeomField0001",
136 FatalException, "Equation is not an G4EquationOfMotion.");
137 }
138
139 fLastInitialVector = new G4double[N];
140 fLastFinalVector = new G4double[N];
141 fLastDyDx = new G4double[N];
142
143 fMidVector = new G4double[N];
144 fMidError = new G4double[N];
145
146 if(primary)
147 {
148 fAuxStepper = new G4TCashKarpRKF45<T_Equation, N> (EqRhs, !primary);
149 }
150}
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4MagIntegratorStepper(G4EquationOfMotion *Equation, G4int numIntegrationVariables, G4int numStateVariables=12, G4bool isFSAL=false)
G4TCashKarpRKF45 is a templated version of Cash-Karp 4th/5th order embedded stepper.
G4TCashKarpRKF45(T_Equation *EqRhs, G4bool primary=true)

Referenced by G4TCashKarpRKF45(), G4TCashKarpRKF45(), and operator=().

◆ ~G4TCashKarpRKF45()

template<class T_Equation, unsigned int N>
G4TCashKarpRKF45< T_Equation, N >::~G4TCashKarpRKF45 ( )
virtual

Definition at line 153 of file G4TCashKarpRKF45.hh.

154{
155 delete[] fLastInitialVector;
156 delete[] fLastFinalVector;
157 delete[] fLastDyDx;
158 delete[] fMidVector;
159 delete[] fMidError;
160
161 delete fAuxStepper;
162}

◆ G4TCashKarpRKF45() [2/2]

template<class T_Equation, unsigned int N = 6>
G4TCashKarpRKF45< T_Equation, N >::G4TCashKarpRKF45 ( const G4TCashKarpRKF45< T_Equation, N > & )
delete

Member Function Documentation

◆ DistChord()

template<class T_Equation, unsigned int N>
G4double G4TCashKarpRKF45< T_Equation, N >::DistChord ( ) const
inlineoverridevirtual

Estimates the maximum distance of a chord from the true path over the segment last integrated.

Implements G4MagIntegratorStepper.

Definition at line 275 of file G4TCashKarpRKF45.hh.

276{
279
280 // Store last initial and final points (they will be overwritten in
281 // self-Stepper call!)
282 initialPoint = G4ThreeVector(fLastInitialVector[0], fLastInitialVector[1],
283 fLastInitialVector[2]);
284 finalPoint = G4ThreeVector(fLastFinalVector[0], fLastFinalVector[1],
285 fLastFinalVector[2]);
286
287 // Do half a step using StepNoErr
288
289 fAuxStepper->G4TCashKarpRKF45::Stepper(fLastInitialVector, fLastDyDx,
290 0.5 * fLastStepLength, fMidVector,
291 fMidError);
292
293 midPoint = G4ThreeVector(fMidVector[0], fMidVector[1], fMidVector[2]);
294
295 // Use stored values of Initial and Endpoint + new Midpoint to evaluate
296 // distance of Chord
297
299 {
302 }
303 else
304 {
306 }
307 return distChord;
308}
CLHEP::Hep3Vector G4ThreeVector
static G4double Distline(const G4ThreeVector &OtherPnt, const G4ThreeVector &LinePntA, const G4ThreeVector &LinePntB)

◆ IntegratorOrder()

template<class T_Equation, unsigned int N = 6>
G4int G4TCashKarpRKF45< T_Equation, N >::IntegratorOrder ( ) const
inlineoverridevirtual

Returns the order of the integrator, i.e. its error behaviour is of the order O(h^order).

Implements G4MagIntegratorStepper.

Definition at line 101 of file G4TCashKarpRKF45.hh.

101{ return 4; }

◆ operator=()

template<class T_Equation, unsigned int N = 6>
G4TCashKarpRKF45 & G4TCashKarpRKF45< T_Equation, N >::operator= ( const G4TCashKarpRKF45< T_Equation, N > & )
delete

◆ RightHandSideInl()

template<class T_Equation, unsigned int N = 6>
void G4TCashKarpRKF45< T_Equation, N >::RightHandSideInl ( const G4double y[],
G4double dydx[] )
inline

Definition at line 93 of file G4TCashKarpRKF45.hh.

95 {
96 fEquation_Rhs->T_Equation::RightHandSide(y, dydx);
97 }

Referenced by StepWithError().

◆ Stepper()

template<class T_Equation, unsigned int N>
void G4TCashKarpRKF45< T_Equation, N >::Stepper ( const G4double y[],
const G4double dydx[],
G4double h,
G4double yout[],
G4double yerr[] )
inlinefinaloverridevirtual

The stepper for the Runge Kutta integration. The stepsize is fixed, with the step size given by 'h'. Integrates ODE starting values y[0 to 6]. Outputs yout[] and its estimated error yerr[].

Parameters
[in]yStarting values array of integration variables.
[in]dydxDerivatives array.
[in]hThe given step size.
[out]youtIntegration output.
[out]yerrThe estimated error.

Implements G4MagIntegratorStepper.

Definition at line 312 of file G4TCashKarpRKF45.hh.

317{
318 assert( yOutput != yInput );
319 assert( yError != yInput );
320
322}
void StepWithError(const G4double yInput[], const G4double dydx[], G4double Step, G4double yOut[], G4double yErr[])

◆ StepperType()

template<class T_Equation, unsigned int N = 6>
G4StepperType G4TCashKarpRKF45< T_Equation, N >::StepperType ( ) const
inlineoverridevirtual

Returns the stepper type ID ('kUserStepper'). This function should be overriden in derived classes.

Reimplemented from G4MagIntegratorStepper.

Definition at line 103 of file G4TCashKarpRKF45.hh.

103{ return kTCashKarpRKF45; }

◆ StepWithError()

template<class T_Equation, unsigned int N = 6>
void G4TCashKarpRKF45< T_Equation, N >::StepWithError ( const G4double yInput[],
const G4double dydx[],
G4double Step,
G4double yOut[],
G4double yErr[] )
inline

Definition at line 176 of file G4TCashKarpRKF45.hh.

181{
182 // const G4double a2 = 0.2 , a3 = 0.3 , a4 = 0.6 , a5 = 1.0 , a6 = 0.875;
183
184 const G4double b21 = 0.2, b31 = 3.0 / 40.0, b32 = 9.0 / 40.0, b41 = 0.3,
185 b42 = -0.9, b43 = 1.2,
186
187 b51 = -11.0 / 54.0, b52 = 2.5, b53 = -70.0 / 27.0,
188 b54 = 35.0 / 27.0,
189
190 b61 = 1631.0 / 55296.0, b62 = 175.0 / 512.0,
191 b63 = 575.0 / 13824.0, b64 = 44275.0 / 110592.0,
192 b65 = 253.0 / 4096.0,
193
194 c1 = 37.0 / 378.0, c3 = 250.0 / 621.0, c4 = 125.0 / 594.0,
195 c6 = 512.0 / 1771.0, dc5 = -277.0 / 14336.0;
196
197 const G4double dc1 = c1 - 2825.0 / 27648.0, dc3 = c3 - 18575.0 / 48384.0,
198 dc4 = c4 - 13525.0 / 55296.0, dc6 = c6 - 0.25;
199
200 // Initialise time to t0, needed when it is not updated by the integration.
201 // [ Note: Only for time dependent fields (usually electric)
202 // is it neccessary to integrate the time.]
203 // yOut[7] = yTemp[7] = yIn[7];
204
205 // Saving yInput because yInput and yOut can be aliases for same array
206 for(unsigned int i = 0; i < N; ++i)
207 {
208 yIn[i] = yInput[i];
209 }
210 // RightHandSideInl(yIn, dydx) ; // 1st Step
211
212 for(unsigned int i = 0; i < N; ++i)
213 {
214 yTemp[i] = yIn[i] + b21 * Step * dydx[i];
215 }
216 this->RightHandSideInl(yTemp, ak2); // 2nd Step
217
218 for(unsigned int i = 0; i < N; ++i)
219 {
220 yTemp[i] = yIn[i] + Step * (b31 * dydx[i] + b32 * ak2[i]);
221 }
222 this->RightHandSideInl(yTemp, ak3); // 3rd Step
223
224 for(unsigned int i = 0; i < N; ++i)
225 {
226 yTemp[i] = yIn[i] + Step * (b41 * dydx[i] + b42 * ak2[i] + b43 * ak3[i]);
227 }
228 this->RightHandSideInl(yTemp, ak4); // 4th Step
229
230 for(unsigned int i = 0; i < N; ++i)
231 {
232 yTemp[i] = yIn[i] + Step * (b51 * dydx[i] + b52 * ak2[i] + b53 * ak3[i] +
233 b54 * ak4[i]);
234 }
235 this->RightHandSideInl(yTemp, ak5); // 5th Step
236
237 for(unsigned int i = 0; i < N; ++i)
238 {
239 yTemp[i] = yIn[i] + Step * (b61 * dydx[i] + b62 * ak2[i] + b63 * ak3[i] +
240 b64 * ak4[i] + b65 * ak5[i]);
241 }
242 this->RightHandSideInl(yTemp, ak6); // 6th Step
243
244 for(unsigned int i = 0; i < N; ++i)
245 {
246 // Accumulate increments with proper weights
247
248 yOut[i] = yIn[i] +
249 Step * (c1 * dydx[i] + c3 * ak3[i] + c4 * ak4[i] + c6 * ak6[i]);
250 }
251 for(unsigned int i = 0; i < N; ++i)
252 {
253 // Estimate error as difference between 4th and
254 // 5th order methods
255
256 yErr[i] = Step * (dc1 * dydx[i] + dc3 * ak3[i] + dc4 * ak4[i] +
257 dc5 * ak5[i] + dc6 * ak6[i]);
258 }
259 for(unsigned int i = 0; i < N; ++i)
260 {
261 // Store Input and Final values, for possible use in calculating chord
262 fLastInitialVector[i] = yIn[i];
263 fLastFinalVector[i] = yOut[i];
264 fLastDyDx[i] = dydx[i];
265 }
266 // NormaliseTangentVector( yOut ); // Not wanted
267
268 fLastStepLength = Step;
269
270 return;
271}
void RightHandSideInl(const G4double y[], G4double dydx[])

Referenced by Stepper().


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