Geant4  10.00.p02
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 77115 2013-11-21 15:06:37Z 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 
60 #include "G4PhysicalConstants.hh"
61 #include "G4SystemOfUnits.hh"
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 
65 // Constructors:
66 
68  : fFieldManager(0),
69  fChordFinder(0),
70  fEquation(0),
71  fMagneticField(new G4UniformMagField(fieldVector)),
72  fStepper(0),
73  fStepperType(0),
74  fMinStep(0.),
75  fFieldMessenger(0)
76 {
77  G4cout << " F01FieldSetup: magnetic field set to Uniform( "
78  << fieldVector << " ) " << G4endl;
79  InitialiseAll();
80 }
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
83 
85  : fFieldManager(0),
86  fChordFinder(0),
87  fEquation(0),
88  fMagneticField(new G4UniformMagField(G4ThreeVector())),
89  fStepper(0),
90  fStepperType(0),
91  fMinStep(0.),
92  fFieldMessenger(0)
93 {
94  G4cout << " F01FieldSetup: magnetic field set to Uniform( 0.0, 0, 0 ) "
95  << G4endl;
96  InitialiseAll();
97 }
98 
99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
100 
102 {
104 
106 
107  fMinStep = 1.0*mm; // minimal step of 1 mm is default
108 
109  fStepperType = 4; // ClassicalRK4 is default stepper
110 
112  ->GetFieldManager();
114 }
115 
116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
117 
119 {
120  delete fMagneticField;
121  delete fChordFinder;
122  delete fStepper;
123  delete fFieldMessenger;
124 }
125 
126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
127 
129 {
130  // Update field
131 
132  SetStepper();
133  G4cout<<"The minimal step is equal to "<<fMinStep/mm<<" mm"<<G4endl;
134 
136 
137  if (fChordFinder) delete fChordFinder;
138 
140 
142 }
143 
144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
145 
147 {
148 // Set stepper according to the stepper type
149 
150  if (fStepper) delete fStepper;
151 
152  switch ( fStepperType )
153  {
154  case 0:
156  G4cout<<"G4ExplicitEuler is calledS"<<G4endl;
157  break;
158  case 1:
160  G4cout<<"G4ImplicitEuler is called"<<G4endl;
161  break;
162  case 2:
164  G4cout<<"G4SimpleRunge is called"<<G4endl;
165  break;
166  case 3:
168  G4cout<<"G4SimpleHeum is called"<<G4endl;
169  break;
170  case 4:
172  G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
173  break;
174  case 5:
176  G4cout<<"G4HelixExplicitEuler is called"<<G4endl;
177  break;
178  case 6:
180  G4cout<<"G4HelixImplicitEuler is called"<<G4endl;
181  break;
182  case 7:
184  G4cout<<"G4HelixSimpleRunge is called"<<G4endl;
185  break;
186  case 8:
188  G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
189  break;
190  case 9:
192  G4cout<<"G4RKG3_Stepper is called"<<G4endl;
193  break;
194  default: fStepper = 0;
195  }
196 }
197 
198 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
199 
201 {
202  // Set the value of the Global Field to fieldValue along Z
203 
204 #ifdef G4VERBOSE
205  G4cout << "Setting Field strength to "
206  << fieldStrength / gauss << " Gauss."; // << G4endl;
207 #endif
208 
209  G4ThreeVector fieldSetVec(0.0, 0.0, fieldStrength);
210  this->SetFieldValue( fieldSetVec );
211 
212 #ifdef G4VERBOSE
213  G4double fieldValue[6], position[4];
214  position[0] = position[1] = position[2] = position[3] = 0.0;
215  if ( fieldStrength != 0.0 ) {
216  fMagneticField->GetFieldValue( position, fieldValue);
217  G4ThreeVector fieldVec(fieldValue[0], fieldValue[1], fieldValue[2]);
218  // G4cout << " fMagneticField is now " << fMagneticField
219  G4cout << " Magnetic field vector is "
220  << fieldVec / gauss << " G " << G4endl;
221  } else {
222  if ( fMagneticField == 0 )
223  G4cout << " Magnetic field pointer is null." << G4endl;
224  else
225  G4Exception("F01FieldSetup::SetFieldValue(double)",
226  "IncorrectForZeroField",
228  "fMagneticField ptr should be set to 0 for no field.");
229  }
230 #endif
231 }
232 
233 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
234 
236 {
237  // Set the value of the Global Field
238 
239  if (fMagneticField) delete fMagneticField;
240 
241  if (fieldVector != G4ThreeVector(0.,0.,0.))
242  {
243  fMagneticField = new G4UniformMagField(fieldVector);
244  }
245  else
246  {
247  // If the new field's value is Zero, signal it as below
248  // so that it is not used for propagation.
249  fMagneticField = 0;
250  }
251 
252  // Set this as the field of the global Field Manager
254 
255  // Now notify equation of new field
257 
258 }
259 
260 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
261 
263 {
264  // Utility method
265 
267  ->GetFieldManager();
268 }
269 
270 //....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)
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()
G4FieldManager * GetFieldManager() const
static const double gauss
Definition: G4SIunits.hh:249
int position
Definition: filter.cc:7
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:102
void InitialiseAll()