Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4BorisDriver.hh
Go to the documentation of this file.
1// ********************************************************************
2// * License and Disclaimer *
3// * *
4// * The Geant4 software is copyright of the Copyright Holders of *
5// * the Geant4 Collaboration. It is provided under the terms and *
6// * conditions of the Geant4 Software License, included in the file *
7// * LICENSE and available at http://cern.ch/geant4/license . These *
8// * include a list of copyright holders. *
9// * *
10// * Neither the authors of this software system, nor their employing *
11// * institutes,nor the agencies providing financial support for this *
12// * work make any representation or warranty, express or implied, *
13// * regarding this software system or assume any liability for its *
14// * use. Please see the license in the file LICENSE and URL above *
15// * for the full disclaimer and the limitation of liability. *
16// * *
17// * This code implementation is the result of the scientific and *
18// * technical work of the GEANT4 collaboration. *
19// * By using, copying, modifying or distributing the software (or *
20// * any work based on the software) you agree to acknowledge its *
21// * use in resulting scientific publications, and indicate your *
22// * acceptance of all terms of the Geant4 Software license. *
23// ********************************************************************
24//
25// G4BorisDriver
26//
27// Class description:
28//
29// G4BorisDriver is a driver class using the second order Boris
30// method to integrate the equation of motion.
31
32// Author: Divyansh Tiwari (CERN, Google Summer of Code 2022), 05.11.2022
33// Supervision: John Apostolakis (CERN), Renee Fatemi, Soon Yung Jun (FNAL)
34// --------------------------------------------------------------------
35#ifndef G4BORIS_DRIVER_HH
36#define G4BORIS_DRIVER_HH
37
39#include "G4BorisScheme.hh"
41
42/**
43 * @brief G4BorisDriver is a driver class using the second order Boris
44 * method to integrate the equation of motion.
45 */
46
48 public G4ChordFinderDelegate<G4BorisDriver>
49{
50 public:
51
52 /**
53 * Constructor for G4BorisDriver.
54 * @param[in] hminimum The minumum allowed step.
55 * @param[in] Boris Pointer to the Boris motion algorithm.
56 * @param[in] numberOfComponents The number of integration variables.
57 * @param[in] verbosity Flag for verbosity.
58 */
59 G4BorisDriver( G4double hminimum,
60 G4BorisScheme* Boris,
61 G4int numberOfComponents = 6,
62 G4bool verbosity = false);
63
64 /**
65 * Default Destructor.
66 */
67 ~G4BorisDriver() override = default;
68
69 /**
70 * Copy constructor and assignment operator not allowed.
71 */
72 G4BorisDriver(const G4BorisDriver&) = delete;
74
75 // 1. Core methods that advance the integration
76
77 /**
78 * Advances integration accurately by relative accuracy better than 'eps'.
79 * @param[in,out] track The current track in field.
80 * @param[in] stepLen Proposed step length.
81 * @param[in] epsilon Requested accuracy, y_err/hstep.
82 * @param[in] beginStep Initial minimum integration step.
83 * @returns true if integration succeeds.
84 */
86 G4double stepLen,
87 G4double eps,
88 G4double beginStep = 0) override;
89
90 /**
91 * Attempts one integration step, and returns estimated error 'dyerr'.
92 * It does not ensure accuracy.
93 * @param[in,out] y_val The current track in field.
94 * @param[in] dydx dydx array.
95 * @param[in] hstep Proposed step length.
96 * @param[out] missDist Estimated sagitta distance.
97 * @param[out] dyerr Estimated error.
98 * @returns true if integration succeeds.
99 */
100 G4bool QuickAdvance(G4FieldTrack& y_val, // In/Out
101 const G4double dydx[],
102 G4double hstep,
103 G4double& missDist, // Out: estimated sagitta
104 G4double& dyerr) override;
105 /**
106 * Takes one Step that is as large as possible while satisfying the
107 * accuracy criterion.
108 * @param[in,out] yCurrentState The current track state, y.
109 * @param[in,out] curveLength Step start, x.
110 * @param[in] htry Step to attempt.
111 * @param[in] epsilon_rel The relative accuracy.
112 * @param[in] restMass Mass value for computing velocity.
113 * @param[in] charge Charge value for computing momentum.
114 * @param[out] hdid Step achieved.
115 * @param[out] hnext Proposed next step.
116 * @returns true if integration succeeds.
117 */
118 void OneGoodStep(G4double yCurrentState[], // In/Out: state ('y')
119 G4double& curveLength, // In/Out: 'x'
120 G4double htry, // step to attempt
121 G4double epsilon_rel, // relative accuracy
122 G4double restMass,
123 G4double charge,
124 G4double& hdid, // Out: step achieved
125 G4double& hnext); // Out: proposed next step
126
127 // 2. Methods needed to co-work with G4ChordFinder
128
129 /**
130 * Computes the step to take, based on chord limits.
131 * @param[in,out] track The current track in field.
132 * @param[in] hstep Proposed step length.
133 * @param[in] eps Requested accuracy, y_err/hstep.
134 * @param[in] chordDistance Maximum sagitta distance.
135 * @returns The length of step taken.
136 */
138 G4double hstep,
139 G4double eps,
140 G4double chordDistance) override;
141 /**
142 * Dispatch interface method for initialisation/reset of driver.
143 */
144 inline void OnStartTracking() override;
145
146 /**
147 * Dispatch interface method for computing step. Does nothing here.
148 */
149 inline void OnComputeStep(const G4FieldTrack*) override;
150
151 // 3. Does the method redo integrations when called to obtain values for
152 // internal, smaller intervals? (when needed to identify an intersection)
153
154 /**
155 * The driver implements re-integration. Returns true.
156 * It would be false if it just used interpolation to provide a result.
157 */
158 inline G4bool DoesReIntegrate() const override;
159
160 // 4. Relevant for calculating a new step size to achieve required accuracy
161
162 /**
163 * Computes a step size for the next step, taking the last step's
164 * normalised error 'errMaxNorm'.
165 * @param[in] errMaxNorm The normalised error on last step.
166 * @param[in] hstepCurrent The current proposed step.
167 * @returns The step size for the next step.
168 */
170 G4double hstepCurrent) override;
171
172 /**
173 * Methods to calculate the next step size given the square of the
174 * relative error.
175 */
176 G4double ShrinkStepSize2(G4double h, G4double error2) const;
177 G4double GrowStepSize2(G4double h, G4double error2) const;
178
179 // 5. Auxiliary Methods ...
180
181 /**
182 * Getters for derivatives.
183 */
184 void GetDerivatives( const G4FieldTrack& track,
185 G4double dydx[] ) const override;
186 void GetDerivatives( const G4FieldTrack& track,
187 G4double dydx[],
188 G4double field[] ) const override;
189
190 /**
191 * Setter and getter for verbosity.
192 */
193 inline void SetVerboseLevel(G4int level) override;
194 inline G4int GetVerboseLevel() const override;
195
196 /**
197 * Getters for the equation of motion.
198 */
201
202 /**
203 * Setter for the equation of motion. Issues an exception, as not
204 * foreseen to change equation of motion for the Boris stepper.
205 */
206 void SetEquationOfMotion(G4EquationOfMotion* equation) override;
207
208 /**
209 * Writes out to stream the parameters/state of the driver.
210 */
211 void StreamInfo( std::ostream& os ) const override;
212
213 /**
214 * Accessors for stepper. Not relevant for Boris and other non-RK methods.
215 */
216 inline const G4MagIntegratorStepper* GetStepper() const override;
218
219 private:
220
221 inline G4int GetNumberOfVariables() const;
222
223 inline void CheckStep(const G4ThreeVector& posIn,
224 const G4ThreeVector& posOut,
225 G4double hdid) const;
226
227 private:
228
229 // INVARIANTS -- remain unchanged during tracking / integration
230 // Parameters
231 G4double fMinimumStep;
232 G4bool fVerbosity;
233
234 // State -- The core stepping algorithm
235 G4BorisScheme* boris;
236
237 // STATE -- intermediate state (to avoid creation / churn )
242
244
245 // - Unused 2022.11.03:
246 // G4double derivs[2][6][G4FieldTrack::ncompSVEC];
247 // const G4int interval_sequence[2];
248
249 // INVARIANTS -- Parameters for ensuring that one call has finite number of integration steps
250 static constexpr G4int fMaxNoSteps = 300;
251 static constexpr G4double fSmallestFraction= 1e-12; // To avoid FP underflow ! ( 1.e-6 for single prec)
252
253 static constexpr G4int fIntegratorOrder= 2; // 2nd order method -- needed for error control
254 static constexpr G4double fSafetyFactor = 0.9; //
255
256 static constexpr G4double fMaxSteppingIncrease= 10.0; // Increase no more than 10x
257 static constexpr G4double fMaxSteppingDecrease= 0.1; // Reduce no more than 10x
258 static constexpr G4double fPowerShrink = -1.0 / fIntegratorOrder;
259 static constexpr G4double fPowerGrow = -1.0 / (1.0 + fIntegratorOrder);
260
261 static const G4double fErrorConstraintShrink;
262 static const G4double fErrorConstraintGrow;
263
264 using ChordFinderDelegate = G4ChordFinderDelegate<G4BorisDriver>;
265};
266
267#include "G4BorisDriver.icc"
268
269#endif
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4MagIntegratorStepper * GetStepper() override
void OneGoodStep(G4double yCurrentState[], G4double &curveLength, G4double htry, G4double epsilon_rel, G4double restMass, G4double charge, G4double &hdid, G4double &hnext)
G4EquationOfMotion * GetEquationOfMotion() override
void StreamInfo(std::ostream &os) const override
G4double ShrinkStepSize2(G4double h, G4double error2) const
void GetDerivatives(const G4FieldTrack &track, G4double dydx[]) const override
G4BorisDriver(G4double hminimum, G4BorisScheme *Boris, G4int numberOfComponents=6, G4bool verbosity=false)
void SetEquationOfMotion(G4EquationOfMotion *equation) override
G4double AdvanceChordLimited(G4FieldTrack &track, G4double hstep, G4double eps, G4double chordDistance) override
void OnComputeStep(const G4FieldTrack *) override
G4double ComputeNewStepSize(G4double errMaxNorm, G4double hstepCurrent) override
G4bool AccurateAdvance(G4FieldTrack &track, G4double stepLen, G4double eps, G4double beginStep=0) override
void SetVerboseLevel(G4int level) override
G4int GetVerboseLevel() const override
~G4BorisDriver() override=default
G4bool DoesReIntegrate() const override
G4bool QuickAdvance(G4FieldTrack &y_val, const G4double dydx[], G4double hstep, G4double &missDist, G4double &dyerr) override
const G4EquationOfMotion * GetEquationOfMotion() const
void OnStartTracking() override
G4BorisDriver(const G4BorisDriver &)=delete
const G4MagIntegratorStepper * GetStepper() const override
G4BorisDriver & operator=(const G4BorisDriver &)=delete
G4double GrowStepSize2(G4double h, G4double error2) const
The G4BorisScheme class implements of the Boris algorithm for advancing charged particles in an elect...
G4ChordFinderDelegate is a templated class for a common algorithm of finding step size with distance ...
G4EquationOfMotion is the abstract base class for the right hand size of the equation of motion of a ...
G4FieldTrack defines a data structure bringing together a magnetic track's state (position,...
G4MagIntegratorStepper is an abstract base class for integrator of particle's equation of motion,...