Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
F01FieldSetup.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 //
29 //
30 // $Id: F01FieldSetup.cc 100688 2016-10-31 11:21:51Z gcosmo $
31 //
32 // User Field setup class implementation.
33 //
34 //
35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
37 
38 #include "F01FieldSetup.hh"
39 #include "F01FieldMessenger.hh"
40 
41 #include "G4MagneticField.hh"
42 #include "G4UniformMagField.hh"
43 #include "G4FieldManager.hh"
45 #include "G4Mag_UsualEqRhs.hh"
47 #include "G4ChordFinder.hh"
48 
49 #include "G4ExplicitEuler.hh"
50 #include "G4ImplicitEuler.hh"
51 #include "G4SimpleRunge.hh"
52 #include "G4SimpleHeum.hh"
53 #include "G4ClassicalRK4.hh"
54 #include "G4HelixExplicitEuler.hh"
55 #include "G4HelixImplicitEuler.hh"
56 #include "G4HelixSimpleRunge.hh"
57 #include "G4CashKarpRKF45.hh"
58 #include "G4RKG3_Stepper.hh"
59 #include "G4ConstRK4.hh"
60 #include "G4NystromRK4.hh"
61 #include "G4HelixMixedStepper.hh"
62 #include "G4ExactHelixStepper.hh"
63 
64 // Newest steppers - from Release 10.3-beta (June 2013)
65 #include "G4BogackiShampine23.hh"
66 #include "G4BogackiShampine45.hh"
67 #include "G4DormandPrince745.hh"
68 
69 #include "G4PhysicalConstants.hh"
70 #include "G4SystemOfUnits.hh"
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
74 // Constructors:
75 
77  : fFieldManager(0),
78  fChordFinder(0),
79  fEquation(0),
80  fMagneticField(new G4UniformMagField(fieldVector)),
81  fStepper(0),
82  fStepperType(0),
83  fMinStep(0.),
84  fFieldMessenger(0)
85 {
86  G4cout << " F01FieldSetup: magnetic field set to Uniform( "
87  << fieldVector << " ) " << G4endl;
88  InitialiseAll();
89 }
90 
91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92 
94  : fFieldManager(0),
95  fChordFinder(0),
96  fEquation(0),
97  fMagneticField(new G4UniformMagField(G4ThreeVector())),
98  fStepper(0),
99  fStepperType(0),
100  fMinStep(0.),
101  fFieldMessenger(0)
102 {
103  G4cout << " F01FieldSetup: magnetic field set to Uniform( 0.0, 0, 0 ) "
104  << G4endl;
105  InitialiseAll();
106 }
107 
108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
109 
111 {
113 
115 
116  fMinStep = 1.0*mm; // minimal step of 1 mm is default
117 
118  fStepperType = 4; // ClassicalRK4 is default stepper
119 
121  ->GetFieldManager();
123 }
124 
125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
126 
128 {
129  delete fMagneticField;
130  delete fChordFinder;
131  delete fStepper;
132  delete fFieldMessenger;
133 }
134 
135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
136 
138 {
139  // Update field
140 
141  G4cout<< " F01FieldSetup::CreateStepperAndChordFinder() called "
142  << " to reset Stepper." << G4endl;
143 
144  SetStepper();
145  G4cout<<"The minimal step is equal to "<<fMinStep/mm<<" mm"<<G4endl;
146 
148 
149  if (fChordFinder) delete fChordFinder;
150 
152 
154 }
155 
156 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
157 
159 {
160 // Set stepper according to the stepper type
161 
162  if (fStepper) delete fStepper;
163 
164  switch ( fStepperType )
165  {
166  case 0:
168  G4cout<<"G4ExplicitEuler is chosen."<<G4endl;
169  break;
170  case 1:
172  G4cout<<"G4ImplicitEuler is chosen"<<G4endl;
173  break;
174  case 2:
176  G4cout<<"G4SimpleRunge is chosen"<<G4endl;
177  break;
178  case 3:
180  G4cout<<"G4SimpleHeum is chosen"<<G4endl;
181  break;
182  case 4:
184  G4cout<<"G4ClassicalRK4 (default) is chosen"<<G4endl;
185  break;
186  case 5:
188  G4cout<<"G4HelixExplicitEuler is chosen"<<G4endl;
189  break;
190  case 6:
192  G4cout<<"G4HelixImplicitEuler is chosen"<<G4endl;
193  break;
194  case 7:
196  G4cout<<"G4HelixSimpleRunge is chosen"<<G4endl;
197  break;
198  case 8:
200  G4cout<<"G4CashKarpRKF45 is chosen"<<G4endl;
201  break;
202  case 9:
204  G4cout<<"G4RKG3_Stepper is chosen"<<G4endl;
205  break;
206  case 10:
208  G4cout<<"G4ExactHelixStepper is chosen"<<G4endl;
209  break;
210  case 11:
212  G4cout<<"G4HelixMixedStepper is chosen"<<G4endl;
213  break;
214  case 12:
215  fStepper = new G4ConstRK4( fEquation );
216  G4cout<<"G4ConstRK4 Stepper is chosen"<<G4endl;
217  break;
218  case 13:
220  G4cout<<" G4NystromRK4 Stepper is chosen"<<G4endl;
221  break;
222  case 14:
223  case 23:
225  G4cout<<"G4BogackiShampine23 Stepper is chosen"<<G4endl;
226  break;
227  case 15:
228  case 45:
230  G4cout<<"G4BogackiShampine45 Stepper is chosen"<<G4endl;
231  break;
232  case 457:
233  case 745:
235  G4cout<<"G4DormandPrince745 Stepper is chosen"<<G4endl;
236  break;
237  default:
239  G4cout<<"G4ClassicalRK4 Stepper (default) is chosen"<<G4endl;
240  // fStepper = new G4DormandPrince745( fEquation );
241  // G4cout<<"G4DormandPrince745 (default) Stepper is chosen"<<G4endl;
242  break;
243  }
244 }
245 
246 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
247 
249 {
250  // Set the value of the Global Field to fieldValue along Z
251 
252 #ifdef G4VERBOSE
253  G4cout << "Setting Field strength to "
254  << fieldStrength / gauss << " Gauss."; // << G4endl;
255 #endif
256 
257  G4ThreeVector fieldSetVec(0.0, 0.0, fieldStrength);
258  this->SetFieldValue( fieldSetVec );
259 
260 #ifdef G4VERBOSE
261  G4double fieldValue[6], position[4];
262  position[0] = position[1] = position[2] = position[3] = 0.0;
263  if ( fieldStrength != 0.0 ) {
264  fMagneticField->GetFieldValue( position, fieldValue);
265  G4ThreeVector fieldVec(fieldValue[0], fieldValue[1], fieldValue[2]);
266  // G4cout << " fMagneticField is now " << fMagneticField
267  G4cout << " Magnetic field vector is "
268  << fieldVec / gauss << " G " << G4endl;
269  } else {
270  if ( fMagneticField == 0 )
271  G4cout << " Magnetic field pointer is null." << G4endl;
272  else
273  G4Exception("F01FieldSetup::SetFieldValue(double)",
274  "IncorrectForZeroField",
276  "fMagneticField ptr should be set to 0 for no field.");
277  }
278 #endif
279 }
280 
281 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
282 
284 {
285  // Set the value of the Global Field
286 
287  if (fMagneticField) delete fMagneticField;
288 
289  if (fieldVector != G4ThreeVector(0.,0.,0.))
290  {
291  fMagneticField = new G4UniformMagField(fieldVector);
292  }
293  else
294  {
295  // If the new field's value is Zero, signal it as below
296  // so that it is not used for propagation.
297  fMagneticField = 0;
298  }
299 
300  // Set this as the field of the global Field Manager
302 
303  // Now notify equation of new field
305 
306 }
307 
308 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
309 
311 {
312  // Utility method
313 
315  ->GetFieldManager();
316 }
317 
318 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
static constexpr double mm
Definition: G4SIunits.hh:115
G4FieldManager * GetGlobalFieldManager()
G4double fMinStep
CLHEP::Hep3Vector G4ThreeVector
G4bool SetDetectorField(G4Field *detectorField)
Definition of the F01FieldMessenger class.
G4Mag_UsualEqRhs * fEquation
G4FieldManager * fFieldManager
G4ChordFinder * fChordFinder
virtual void GetFieldValue(const G4double Point[4], G4double *Bfield) const =0
void SetChordFinder(G4ChordFinder *aChordFinder)
G4GLOB_DLL std::ostream G4cout
Definition of the F01FieldSetup class.
G4MagIntegratorStepper * fStepper
static constexpr double gauss
Definition: G4SIunits.hh:270
F01FieldMessenger * fFieldMessenger
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4TransportationManager * GetTransportationManager()
#define fMinStep
G4FieldManager * GetFieldManager() const
void CreateStepperAndChordFinder()
void SetFieldObj(G4Field *pField)
#define G4endl
Definition: G4ios.hh:61
virtual ~F01FieldSetup()
double G4double
Definition: G4Types.hh:76
void SetFieldValue(G4ThreeVector fieldVector)
G4MagneticField * fMagneticField
void InitialiseAll()