Geant4  10.02.p01
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 90341 2015-05-26 08:38:36Z 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 #include "G4PhysicalConstants.hh"
65 #include "G4SystemOfUnits.hh"
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 
69 // Constructors:
70 
72  : fFieldManager(0),
73  fChordFinder(0),
74  fEquation(0),
75  fMagneticField(new G4UniformMagField(fieldVector)),
76  fStepper(0),
77  fStepperType(0),
78  fMinStep(0.),
79  fFieldMessenger(0)
80 {
81  G4cout << " F01FieldSetup: magnetic field set to Uniform( "
82  << fieldVector << " ) " << G4endl;
83  InitialiseAll();
84 }
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
87 
89  : fFieldManager(0),
90  fChordFinder(0),
91  fEquation(0),
92  fMagneticField(new G4UniformMagField(G4ThreeVector())),
93  fStepper(0),
94  fStepperType(0),
95  fMinStep(0.),
96  fFieldMessenger(0)
97 {
98  G4cout << " F01FieldSetup: magnetic field set to Uniform( 0.0, 0, 0 ) "
99  << G4endl;
100  InitialiseAll();
101 }
102 
103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
104 
106 {
108 
110 
111  fMinStep = 1.0*mm; // minimal step of 1 mm is default
112 
113  fStepperType = 4; // ClassicalRK4 is default stepper
114 
116  ->GetFieldManager();
118 }
119 
120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
121 
123 {
124  delete fMagneticField;
125  delete fChordFinder;
126  delete fStepper;
127  delete fFieldMessenger;
128 }
129 
130 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
131 
133 {
134  // Update field
135 
136  G4cout<< " F01FieldSetup::CreateStepperAndChordFinder() called "
137  << " to reset Stepper." << G4endl;
138 
139  SetStepper();
140  G4cout<<"The minimal step is equal to "<<fMinStep/mm<<" mm"<<G4endl;
141 
143 
144  if (fChordFinder) delete fChordFinder;
145 
147 
149 }
150 
151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
152 
154 {
155 // Set stepper according to the stepper type
156 
157  if (fStepper) delete fStepper;
158 
159  switch ( fStepperType )
160  {
161  case 0:
163  G4cout<<"G4ExplicitEuler is chosen."<<G4endl;
164  break;
165  case 1:
167  G4cout<<"G4ImplicitEuler is chosen"<<G4endl;
168  break;
169  case 2:
171  G4cout<<"G4SimpleRunge is chosen"<<G4endl;
172  break;
173  case 3:
175  G4cout<<"G4SimpleHeum is chosen"<<G4endl;
176  break;
177  case 4:
179  G4cout<<"G4ClassicalRK4 (default) is chosen"<<G4endl;
180  break;
181  case 5:
183  G4cout<<"G4HelixExplicitEuler is chosen"<<G4endl;
184  break;
185  case 6:
187  G4cout<<"G4HelixImplicitEuler is chosen"<<G4endl;
188  break;
189  case 7:
191  G4cout<<"G4HelixSimpleRunge is chosen"<<G4endl;
192  break;
193  case 8:
195  G4cout<<"G4CashKarpRKF45 is chosen"<<G4endl;
196  break;
197  case 9:
199  G4cout<<"G4RKG3_Stepper is chosen"<<G4endl;
200  break;
201  case 10:
203  G4cout<<"G4ExactHelixStepper is chosen"<<G4endl;
204  break;
205  case 11:
207  G4cout<<"G4HelixMixedStepper is chosen"<<G4endl;
208  break;
209  case 12:
210  fStepper = new G4ConstRK4( fEquation );
211  G4cout<<"G4ConstRK4 Stepper is chosen"<<G4endl;
212  break;
213  case 13:
215  G4cout<<" G4NystromRK4 Stepper is chosen"<<G4endl;
216  break;
217  default: // fStepper = 4;
219  G4cout<<"G4ClassicalRK4 Stepper (default) is chosen"<<G4endl;
220  break;
221  }
222 }
223 
224 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
225 
227 {
228  // Set the value of the Global Field to fieldValue along Z
229 
230 #ifdef G4VERBOSE
231  G4cout << "Setting Field strength to "
232  << fieldStrength / gauss << " Gauss."; // << G4endl;
233 #endif
234 
235  G4ThreeVector fieldSetVec(0.0, 0.0, fieldStrength);
236  this->SetFieldValue( fieldSetVec );
237 
238 #ifdef G4VERBOSE
239  G4double fieldValue[6], position[4];
240  position[0] = position[1] = position[2] = position[3] = 0.0;
241  if ( fieldStrength != 0.0 ) {
242  fMagneticField->GetFieldValue( position, fieldValue);
243  G4ThreeVector fieldVec(fieldValue[0], fieldValue[1], fieldValue[2]);
244  // G4cout << " fMagneticField is now " << fMagneticField
245  G4cout << " Magnetic field vector is "
246  << fieldVec / gauss << " G " << G4endl;
247  } else {
248  if ( fMagneticField == 0 )
249  G4cout << " Magnetic field pointer is null." << G4endl;
250  else
251  G4Exception("F01FieldSetup::SetFieldValue(double)",
252  "IncorrectForZeroField",
254  "fMagneticField ptr should be set to 0 for no field.");
255  }
256 #endif
257 }
258 
259 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
260 
262 {
263  // Set the value of the Global Field
264 
265  if (fMagneticField) delete fMagneticField;
266 
267  if (fieldVector != G4ThreeVector(0.,0.,0.))
268  {
269  fMagneticField = new G4UniformMagField(fieldVector);
270  }
271  else
272  {
273  // If the new field's value is Zero, signal it as below
274  // so that it is not used for propagation.
275  fMagneticField = 0;
276  }
277 
278  // Set this as the field of the global Field Manager
280 
281  // Now notify equation of new field
283 
284 }
285 
286 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
287 
289 {
290  // Utility method
291 
293  ->GetFieldManager();
294 }
295 
296 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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)
#define position
Definition: xmlparse.cc:622
G4GLOB_DLL std::ostream G4cout
Definition of the F01FieldSetup class.
G4MagIntegratorStepper * fStepper
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
static const double gauss
Definition: G4SIunits.hh:267
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
static const double mm
Definition: G4SIunits.hh:114
void InitialiseAll()