Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4HelixMixedStepper Class Reference

G4HelixMixedStepper is a concrete class for particle motion in magnetic field which splits the method used for Integration in two: if the stepping angle ( h / R_curve) is less than pi/3, use a RK stepper for small step, else use G4HelixExplicitEuler stepper. Like other helix steppers, it is only applicable in pure magnetic field. More...

#include <G4HelixMixedStepper.hh>

Inheritance diagram for G4HelixMixedStepper:

Public Member Functions

 G4HelixMixedStepper (G4Mag_EqRhs *EqRhs, G4int StepperNumber=-1, G4double Angle_threshold=-1.0)
 ~G4HelixMixedStepper () override
void Stepper (const G4double y[], const G4double dydx[], G4double h, G4double yout[], G4double yerr[]) override
void DumbStepper (const G4double y[], G4ThreeVector Bfld, G4double h, G4double yout[]) override
G4double DistChord () const override
void SetVerbose (G4int newvalue)
void SetAngleThreshold (G4double val)
G4double GetAngleThreshold ()
G4int IntegratorOrder () const override
G4StepperType StepperType () const override
void PrintCalls ()
G4MagIntegratorStepperSetupStepper (G4Mag_EqRhs *EqRhs, G4int StepperName)
Public Member Functions inherited from G4MagHelicalStepper
 G4MagHelicalStepper (G4Mag_EqRhs *EqRhs)
 ~G4MagHelicalStepper () override=default
 G4MagHelicalStepper (const G4MagHelicalStepper &)=delete
G4MagHelicalStepperoperator= (const G4MagHelicalStepper &)=delete
void Stepper (const G4double y[], const G4double dydx[], G4double h, G4double yout[], G4double yerr[]) override
G4double DistChord () 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 G4MagHelicalStepper
void LinearStep (const G4double yIn[], G4double h, G4double yHelix[]) const
void AdvanceHelix (const G4double yIn[], const G4ThreeVector &Bfld, G4double h, G4double yHelix[], G4double yHelix2[]=nullptr)
void MagFieldEvaluate (const G4double y[], G4ThreeVector &Bfield)
G4double GetInverseCurve (const G4double Momentum, const G4double Bmag)
void SetAngCurve (const G4double Ang)
G4double GetAngCurve () const
void SetCurve (const G4double Curve)
G4double GetCurve () const
void SetRadHelix (const G4double Rad)
G4double GetRadHelix () const
Protected Member Functions inherited from G4MagIntegratorStepper
void SetIntegrationOrder (G4int order)
void SetFSAL (G4bool flag=true)

Detailed Description

G4HelixMixedStepper is a concrete class for particle motion in magnetic field which splits the method used for Integration in two: if the stepping angle ( h / R_curve) is less than pi/3, use a RK stepper for small step, else use G4HelixExplicitEuler stepper. Like other helix steppers, it is only applicable in pure magnetic field.

Definition at line 70 of file G4HelixMixedStepper.hh.

Constructor & Destructor Documentation

◆ G4HelixMixedStepper()

G4HelixMixedStepper::G4HelixMixedStepper ( G4Mag_EqRhs * EqRhs,
G4int StepperNumber = -1,
G4double Angle_threshold = -1.0 )

Constructor for G4ExactHelixStepper.

Parameters
[in]EqRhsPointer to the standard equation of motion.
[in]StepperNumberIdentified for selecting the stepper type; default (-1) is DormandPrince745.
[in]Angle_thresholdThe stepping angle threshold; default (-1) is (1/3)*pi.

Definition at line 65 of file G4HelixMixedStepper.cc.

69 : G4MagHelicalStepper(EqRhs)
70{
71 if( angleThreshold < 0.0 )
72 {
73 fAngle_threshold = (1.0/3.0)*pi;
74 }
75 else
76 {
77 fAngle_threshold = angleThreshold;
78 }
79
80 if(stepperNumber<0)
81 {
82 // stepperNumber = 4; // Default is RK4 (original)
83 stepperNumber = 745; // Default is DormandPrince745 (ie DoPri5)
84 // stepperNumber = 8; // Default is CashKarp
85 }
86
87 fStepperNumber = stepperNumber; // Store the choice
88 fRK4Stepper = SetupStepper(EqRhs, fStepperNumber);
89}
G4MagIntegratorStepper * SetupStepper(G4Mag_EqRhs *EqRhs, G4int StepperName)
G4MagHelicalStepper(G4Mag_EqRhs *EqRhs)

◆ ~G4HelixMixedStepper()

G4HelixMixedStepper::~G4HelixMixedStepper ( )
override

Default Destructor.

Definition at line 92 of file G4HelixMixedStepper.cc.

93{
94 delete fRK4Stepper;
95 if (fVerbose>0) { PrintCalls(); }
96}

Member Function Documentation

◆ DistChord()

G4double G4HelixMixedStepper::DistChord ( ) const
overridevirtual

Estimates the maximum distance of curved solution and chord.

Implements G4MagIntegratorStepper.

Definition at line 179 of file G4HelixMixedStepper.cc.

180{
181 // Implementation : must check whether h/R > 2 pi !!
182 // If( h/R < pi) use G4LineSection::DistLine
183 // Else DistChord=R_helix
184 //
185 G4double distChord;
186 G4double Ang_curve=GetAngCurve();
187
188 if(Ang_curve<=pi)
189 {
190 distChord=GetRadHelix()*(1-std::cos(0.5*Ang_curve));
191 }
192 else
193 {
194 if(Ang_curve<twopi)
195 {
196 distChord=GetRadHelix()*(1+std::cos(0.5*(twopi-Ang_curve)));
197 }
198 else
199 {
200 distChord=2.*GetRadHelix();
201 }
202 }
203
204 return distChord;
205}
double G4double
Definition G4Types.hh:83
G4double GetRadHelix() const
G4double GetAngCurve() const

◆ DumbStepper()

void G4HelixMixedStepper::DumbStepper ( const G4double y[],
G4ThreeVector Bfld,
G4double h,
G4double yout[] )
overridevirtual

Same as Stepper() function above, but should perform a 'dump' step without error calculation. Assuming a constant field, the solution is a helix.

Parameters
[in]yStarting values array of integration variables.
[in]BfldThe field vector.
[in]hThe given step size.
[out]youtIntegration output.

Implements G4MagHelicalStepper.

Definition at line 170 of file G4HelixMixedStepper.cc.

174{
175 AdvanceHelix(yIn, Bfld, h, yOut);
176}
void AdvanceHelix(const G4double yIn[], const G4ThreeVector &Bfld, G4double h, G4double yHelix[], G4double yHelix2[]=nullptr)

◆ GetAngleThreshold()

G4double G4HelixMixedStepper::GetAngleThreshold ( )
inline

Definition at line 137 of file G4HelixMixedStepper.hh.

137{ return fAngle_threshold; }

◆ IntegratorOrder()

G4int G4HelixMixedStepper::IntegratorOrder ( ) const
inlineoverridevirtual

Returns the order, 4, of integration.

Implements G4MagIntegratorStepper.

Definition at line 142 of file G4HelixMixedStepper.hh.

142{ return 4; }

◆ PrintCalls()

void G4HelixMixedStepper::PrintCalls ( )

Logger function for the number of calls.

Definition at line 208 of file G4HelixMixedStepper.cc.

209{
210 G4cout << "In HelixMixedStepper::Number of calls to smallStepStepper = "
211 << fNumCallsRK4
212 << " and Number of calls to Helix = " << fNumCallsHelix << G4endl;
213}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout

Referenced by ~G4HelixMixedStepper().

◆ SetAngleThreshold()

void G4HelixMixedStepper::SetAngleThreshold ( G4double val)
inline

Setter and getter for the stepping angle threshold.

Definition at line 136 of file G4HelixMixedStepper.hh.

136{ fAngle_threshold = val; }

◆ SetupStepper()

G4MagIntegratorStepper * G4HelixMixedStepper::SetupStepper ( G4Mag_EqRhs * EqRhs,
G4int StepperName )

Sets the chosen stepper and equation of motion.

Definition at line 217 of file G4HelixMixedStepper.cc.

218{
219 G4MagIntegratorStepper* pStepper;
220 if (fVerbose>0) { G4cout << " G4HelixMixedStepper: ";
221}
222 switch ( StepperNumber )
223 {
224 // Robust, classic method
225 case 4:
226 pStepper = new G4ClassicalRK4( pE );
227 if (fVerbose>0) { G4cout << "G4ClassicalRK4"; }
228 break;
229
230 // Steppers with embedded estimation of error
231 case 8:
232 pStepper = new G4CashKarpRKF45( pE );
233 if (fVerbose>0) { G4cout << "G4CashKarpRKF45"; }
234 break;
235 case 13:
236 pStepper = new G4NystromRK4( pE );
237 if (fVerbose>0) { G4cout << "G4NystromRK4"; }
238 break;
239
240 // Lowest order RK Stepper - experimental
241 case 1:
242 pStepper = new G4ImplicitEuler( pE );
243 if (fVerbose>0) { G4cout << "G4ImplicitEuler"; }
244 break;
245
246 // Lower order RK Steppers - ok overall, good for uneven fields
247 case 2:
248 pStepper = new G4SimpleRunge( pE );
249 if (fVerbose>0) { G4cout << "G4SimpleRunge"; }
250 break;
251 case 3:
252 pStepper = new G4SimpleHeum( pE );
253 if (fVerbose>0) { G4cout << "G4SimpleHeum"; }
254 break;
255 case 23:
256 pStepper = new G4BogackiShampine23( pE );
257 if (fVerbose>0) { G4cout << "G4BogackiShampine23"; }
258 break;
259
260 // Higher order RK Steppers
261 // for smoother fields and high accuracy requirements
262 case 45:
263 pStepper = new G4BogackiShampine45( pE );
264 if (fVerbose>0) { G4cout << "G4BogackiShampine45"; }
265 break;
266 case 145:
267 pStepper = new G4TsitourasRK45( pE );
268 if (fVerbose>0) { G4cout << "G4TsitourasRK45"; }
269 break;
270 case 745:
271 pStepper = new G4DormandPrince745( pE );
272 if (fVerbose>0) { G4cout << "G4DormandPrince745"; }
273 break;
274
275 // Helical Steppers
276 case 6:
277 pStepper = new G4HelixImplicitEuler( pE );
278 if (fVerbose>0) { G4cout << "G4HelixImplicitEuler"; }
279 break;
280 case 7:
281 pStepper = new G4HelixSimpleRunge( pE );
282 if (fVerbose>0) { G4cout << "G4HelixSimpleRunge"; }
283 break;
284 case 5:
285 pStepper = new G4HelixExplicitEuler( pE );
286 if (fVerbose>0) { G4cout << "G4HelixExplicitEuler"; }
287 break; // Since Helix Explicit is used for long steps,
288 // this is useful only to measure overhead.
289 // Exact Helix - likely good only for cases of
290 // i) uniform field (potentially over small distances)
291 // ii) segmented uniform field (maybe)
292 case 9:
293 pStepper = new G4ExactHelixStepper( pE );
294 if (fVerbose>0) { G4cout << "G4ExactHelixStepper"; }
295 break;
296 case 10:
297 pStepper = new G4RKG3_Stepper( pE );
298 if (fVerbose>0) { G4cout << "G4RKG3_Stepper"; }
299 break;
300
301 // Low Order Steppers - not good except for very weak fields
302 case 11:
303 pStepper = new G4ExplicitEuler( pE );
304 if (fVerbose>0) { G4cout << "G4ExplicitEuler"; }
305 break;
306 case 12:
307 pStepper = new G4ImplicitEuler( pE );
308 if (fVerbose>0) { G4cout << "G4ImplicitEuler"; }
309 break;
310
311 case 0:
312 case -1:
313 default:
314 pStepper = new G4DormandPrince745( pE ); // Was G4ClassicalRK4( pE );
315 if (fVerbose>0) { G4cout << "G4DormandPrince745 (Default)"; }
316 break;
317 }
318
319 if(fVerbose>0)
320 {
321 G4cout << " chosen as stepper for small steps in G4HelixMixedStepper."
322 << G4endl;
323 }
324
325 return pStepper;
326}
G4MagIntegratorStepper(G4EquationOfMotion *Equation, G4int numIntegrationVariables, G4int numStateVariables=12, G4bool isFSAL=false)

Referenced by G4HelixMixedStepper().

◆ SetVerbose()

void G4HelixMixedStepper::SetVerbose ( G4int newvalue)
inline

Sets the verbosity level.

Definition at line 131 of file G4HelixMixedStepper.hh.

131{ fVerbose = newvalue; }

◆ Stepper()

void G4HelixMixedStepper::Stepper ( const G4double y[],
const G4double dydx[],
G4double h,
G4double yout[],
G4double yerr[] )
overridevirtual

The integration stepper. The stepsize is fixed, with the step size given by 'hstep'. Integrates ODE starting values yInput[0 to 6]. Outputs yout[] and its estimated error yerr[]. If SteppingAngle = h/R_curve < pi/3, uses default RK stepper else use Helix fast method.

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 99 of file G4HelixMixedStepper.cc.

104{
105 // Estimation of the Stepping Angle
106 //
107 G4ThreeVector Bfld;
108 MagFieldEvaluate(yInput, Bfld);
109
110 G4double Bmag = Bfld.mag();
111 const G4double* pIn = yInput+3;
112 G4ThreeVector initVelocity = G4ThreeVector( pIn[0], pIn[1], pIn[2] );
113 G4double velocityVal = initVelocity.mag();
114
115 const G4double R_1 = std::abs(GetInverseCurve(velocityVal,Bmag));
116 // curv = inverse Radius
117 G4double Ang_curve = R_1 * Step;
118 // SetAngCurve(Ang_curve);
119 // SetCurve(std::abs(1/R_1));
120
121 if(Ang_curve < fAngle_threshold)
122 {
123 ++fNumCallsRK4;
124 fRK4Stepper->Stepper(yInput,dydx,Step,yOut,yErr);
125 }
126 else
127 {
128 constexpr G4int nvar = 6 ;
129 constexpr G4int nvarMax = 8 ;
130 G4double yTemp[nvarMax], yIn[nvarMax], yTemp2[nvarMax];
131 G4ThreeVector Bfld_midpoint;
132
133 SetAngCurve(Ang_curve);
134 SetCurve(std::abs(1.0/R_1));
135 ++fNumCallsHelix;
136
137 // Saving yInput because yInput and yOut can be aliases for same array
138 //
139 for(G4int i=0; i<nvar; ++i)
140 {
141 yIn[i]=yInput[i];
142 }
143
144 G4double halfS = Step * 0.5;
145
146 // 1. Do first half step and full step
147 //
148 AdvanceHelix(yIn, Bfld, halfS, yTemp, yTemp2); // yTemp2 for s=2*h (halfS)
149
150 MagFieldEvaluate(yTemp, Bfld_midpoint) ;
151
152 // 2. Do second half step - with revised field
153 // NOTE: Could avoid this call if 'Bfld_midpoint == Bfld'
154 // or diff 'almost' zero
155 //
156 AdvanceHelix(yTemp, Bfld_midpoint, halfS, yOut);
157 // Not requesting y at s=2*h (halfS)
158
159 // 3. Estimate the integration error
160 // should be (nearly) zero if Bfield= constant
161 //
162 for(G4int i=0; i<nvar; ++i)
163 {
164 yErr[i] = yOut[i] - yTemp2[i];
165 }
166 }
167}
CLHEP::Hep3Vector G4ThreeVector
int G4int
Definition G4Types.hh:85
double mag() const
void SetCurve(const G4double Curve)
void MagFieldEvaluate(const G4double y[], G4ThreeVector &Bfield)
G4double GetInverseCurve(const G4double Momentum, const G4double Bmag)
void SetAngCurve(const G4double Ang)

◆ StepperType()

G4StepperType G4HelixMixedStepper::StepperType ( ) const
inlineoverridevirtual

Returns the stepper type-ID, "kHelixMixedStepper".

Reimplemented from G4MagIntegratorStepper.

Definition at line 147 of file G4HelixMixedStepper.hh.

147{ return kHelixMixedStepper; }
@ kHelixMixedStepper
G4HelixMixedStepper.

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