Geant4 11.1.1
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//
33// Author: Divyansh Tiwari, Google Summer of Code 2022
34// Supervision: John Apostolakis,Renee Fatemi, Soon Yung Jun
35// --------------------------------------------------------------------
36#ifndef G4BORIS_DRIVER_HH
37#define G4BORIS_DRIVER_HH
38
40#include "G4BorisScheme.hh"
42
43
46 public G4ChordFinderDelegate<G4BorisDriver>
47{
48 public:
49
50 G4BorisDriver( G4double hminimum,
51 G4BorisScheme* Boris,
52 G4int numberOfComponents = 6,
53 bool verbosity = false);
54
55 inline ~G4BorisDriver() = default;
56
57 inline G4BorisDriver(const G4BorisDriver&) = delete;
58 inline G4BorisDriver& operator=(const G4BorisDriver&) = delete;
59
60 // 1. Core methods that advance the integration
61 virtual G4bool AccurateAdvance( G4FieldTrack& track,
62 G4double stepLen,
64 G4double beginStep = 0) override;
65 // Advance integration accurately - by relative accuracy better than 'epsilon'
66
67 virtual G4bool QuickAdvance( G4FieldTrack& y_val, // In/Out
68 const G4double dydx[],
69 G4double hstep,
70 G4double& missDist, // Out: estimated sagitta
71 G4double& dyerr ) override;
72 // Attempt one integration step, and return estimated error 'dyerr'
73
74 void OneGoodStep(G4double yCurrentState[], // In/Out: state ('y')
75 G4double& curveLength, // In/Out: 'x'
76 G4double htry, // step to attempt
77 G4double epsilon_rel, // relative accuracy
78 G4double restMass,
79 G4double charge,
80 G4double& hdid, // Out: step achieved
81 G4double& hnext); // Out: proposed next step
82 // Method to implement Accurate Advance
83
84 // 2. Methods needed to co-work with G4ChordFinder
86 G4double hstep,
87 G4double eps,
88 G4double chordDistance) override
89 {
91 AdvanceChordLimitedImpl(track, hstep, eps, chordDistance);
92 }
93
94 virtual void OnStartTracking() override {
96 }
97
98 virtual void OnComputeStep() override {};
99
100
101
102 // 3. Does the method redo integrations when called to obtain values
103 // for internal, smaller intervals ?
104 // (when needed to identify an intersection.)
105 virtual G4bool DoesReIntegrate() const override { return true; }
106 // It would be no if it just used interpolation to provide a result.
107
108 // 4. Relevant for calculating a new step size to achieve required accuracy
110 G4double errMaxNorm, // normalised error
111 G4double hstepCurrent) override; // current step size
112
113 G4double ShrinkStepSize2(G4double h, G4double error2) const;
114 G4double GrowStepSize2(G4double h, G4double error2) const;
115 // Calculate the next step size given the square of the relative error
116
117 // 5. Auxiliary Methods ...
118 virtual void GetDerivatives( const G4FieldTrack& track,
119 G4double dydx[]) const override;
120
121 virtual void GetDerivatives( const G4FieldTrack& track,
122 G4double dydx[],
123 G4double field[]) const override;
124
125 inline virtual void SetVerboseLevel(G4int level) override;
126 inline virtual G4int GetVerboseLevel() const override;
127
128 inline virtual G4EquationOfMotion* GetEquationOfMotion() override;
130 virtual void SetEquationOfMotion(G4EquationOfMotion* equation) override;
131
132 virtual void StreamInfo( std::ostream& os ) const override;
133 // Write out the parameters / state of the driver
134
135 // 6. Not relevant for Boris and other non-RK methods
136 inline virtual const G4MagIntegratorStepper* GetStepper() const override;
137 inline virtual G4MagIntegratorStepper* GetStepper() override;
138
139 private:
140 inline G4int GetNumberOfVariables() const;
141
142 inline void CheckStep(const G4ThreeVector& posIn,
143 const G4ThreeVector& posOut,
144 G4double hdid) const;
145
146 private:
147 // INVARIANTS -- remain unchanged during tracking / integration
148 // Parameters
149 G4double fMinimumStep;
150 bool fVerbosity;
151
152 // State -- The core stepping algorithm
153 G4BorisScheme* boris;
154
155 // STATE -- intermediate state (to avoid creation / churn )
160
162
163 // - Unused 2022.11.03:
164 // G4double derivs[2][6][G4FieldTrack::ncompSVEC];
165 // const G4int interval_sequence[2];
166
167 // INVARIANTS -- Parameters for ensuring that one call has finite number of integration steps
168 static constexpr int fMaxNoSteps = 300;
169 static constexpr G4double fSmallestFraction= 1e-12; // To avoid FP underflow ! ( 1.e-6 for single prec)
170
171 static constexpr G4int fIntegratorOrder= 2; // 2nd order method -- needed for error control
172 static constexpr G4double fSafetyFactor = 0.9; //
173
174 static constexpr G4double fMaxSteppingIncrease= 10.0; // Increase no more than 10x
175 static constexpr G4double fMaxSteppingDecrease= 0.1; // Reduce no more than 10x
176 static constexpr G4double fPowerShrink = -1.0 / fIntegratorOrder;
177 static constexpr G4double fPowerGrow = -1.0 / (1.0 + fIntegratorOrder);
178
179 static const G4double fErrorConstraintShrink;
180 static const G4double fErrorConstraintGrow;
181
182 using ChordFinderDelegate =
184};
185
186#include "G4BorisDriver.icc"
187
188#endif
G4double epsilon(G4double density, G4double temperature)
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
void OneGoodStep(G4double yCurrentState[], G4double &curveLength, G4double htry, G4double epsilon_rel, G4double restMass, G4double charge, G4double &hdid, G4double &hnext)
virtual void StreamInfo(std::ostream &os) const override
G4double ShrinkStepSize2(G4double h, G4double error2) const
virtual void GetDerivatives(const G4FieldTrack &track, G4double dydx[]) const override
~G4BorisDriver()=default
virtual void SetVerboseLevel(G4int level) override
virtual G4double AdvanceChordLimited(G4FieldTrack &track, G4double hstep, G4double eps, G4double chordDistance) override
virtual void SetEquationOfMotion(G4EquationOfMotion *equation) override
virtual void OnComputeStep() override
virtual G4bool DoesReIntegrate() const override
virtual G4int GetVerboseLevel() const override
virtual G4double ComputeNewStepSize(G4double errMaxNorm, G4double hstepCurrent) override
virtual G4MagIntegratorStepper * GetStepper() override
virtual void OnStartTracking() override
virtual G4bool AccurateAdvance(G4FieldTrack &track, G4double stepLen, G4double epsilon, G4double beginStep=0) override
virtual G4EquationOfMotion * GetEquationOfMotion() override
virtual G4bool QuickAdvance(G4FieldTrack &y_val, const G4double dydx[], G4double hstep, G4double &missDist, G4double &dyerr) override
const G4EquationOfMotion * GetEquationOfMotion() const
virtual const G4MagIntegratorStepper * GetStepper() const override
G4BorisDriver(const G4BorisDriver &)=delete
G4BorisDriver & operator=(const G4BorisDriver &)=delete
G4double GrowStepSize2(G4double h, G4double error2) const
G4double AdvanceChordLimitedImpl(G4FieldTrack &track, G4double hstep, G4double eps, G4double chordDistance)