Geant4  10.02.p02
F02ElectricFieldSetup.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: F02ElectricFieldSetup.cc 77123 2013-11-21 16:13:28Z gcosmo $
31 //
32 // User Field class implementation.
33 //
34 //
35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
37 
38 #include "F02ElectricFieldSetup.hh"
39 #include "F02FieldMessenger.hh"
40 
42 #include "G4UniformMagField.hh"
43 #include "G4MagneticField.hh"
44 #include "G4FieldManager.hh"
46 #include "G4EquationOfMotion.hh"
47 #include "G4EqMagElectricField.hh"
48 #include "G4Mag_UsualEqRhs.hh"
50 #include "G4MagIntegratorDriver.hh"
51 #include "G4ChordFinder.hh"
52 
53 #include "G4ExplicitEuler.hh"
54 #include "G4ImplicitEuler.hh"
55 #include "G4SimpleRunge.hh"
56 #include "G4SimpleHeum.hh"
57 #include "G4ClassicalRK4.hh"
58 #include "G4HelixExplicitEuler.hh"
59 #include "G4HelixImplicitEuler.hh"
60 #include "G4HelixSimpleRunge.hh"
61 #include "G4CashKarpRKF45.hh"
62 #include "G4RKG3_Stepper.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  fEMfield(0),
76  fElFieldValue(),
77  fStepper(0),
78  fIntgrDriver(0),
79  fStepperType(4), // ClassicalRK4 -- the default stepper
80  fMinStep(0.010*mm) // minimal step of 10 microns
81 {
83  G4ThreeVector(0.0,100000.0*kilovolt/cm,0.0));
85 
88  UpdateField();
89 }
90 
91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92 
94  : fFieldManager(0),
95  fChordFinder(0),
96  fEquation(0),
97  fEMfield(0),
98  fElFieldValue(),
99  fStepper(0),
100  fIntgrDriver(0),
101  fStepperType(4), // ClassicalRK4 -- the default stepper
102  fMinStep(0.010*mm) // minimal step of 10 microns
103 {
104  fEMfield = new G4UniformElectricField(fieldVector);
106 
109 
110  UpdateField();
111 }
112 
113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
114 
116 {
117  delete fChordFinder;
118  delete fStepper;
119  delete fEquation;
120  delete fEMfield;
121  delete fFieldMessenger;
122 }
123 
124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
125 
127 {
128 // Register this field to 'global' Field Manager and
129 // Create Stepper and Chord Finder with predefined type, minstep (resp.)
130 
131  SetStepper();
132 
133  G4cout<<"The minimal step is equal to "<<fMinStep/mm<<" mm"<<G4endl;
134 
136 
137  if (fChordFinder) delete fChordFinder;
138 
140  fStepper,
142 
144 
145  fFieldManager->SetChordFinder(fChordFinder);
146 }
147 
148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
149 
151 {
152 // Set stepper according to the stepper type
153 
154  G4int nvar = 8;
155 
156  if (fStepper) delete fStepper;
157 
158  switch ( fStepperType )
159  {
160  case 0:
161  fStepper = new G4ExplicitEuler( fEquation, nvar );
162  G4cout<<"G4ExplicitEuler is calledS"<<G4endl;
163  break;
164  case 1:
165  fStepper = new G4ImplicitEuler( fEquation, nvar );
166  G4cout<<"G4ImplicitEuler is called"<<G4endl;
167  break;
168  case 2:
169  fStepper = new G4SimpleRunge( fEquation, nvar );
170  G4cout<<"G4SimpleRunge is called"<<G4endl;
171  break;
172  case 3:
173  fStepper = new G4SimpleHeum( fEquation, nvar );
174  G4cout<<"G4SimpleHeum is called"<<G4endl;
175  break;
176  case 4:
177  fStepper = new G4ClassicalRK4( fEquation, nvar );
178  G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
179  break;
180  case 5:
181  fStepper = new G4CashKarpRKF45( fEquation, nvar );
182  G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
183  break;
184  case 6:
185  fStepper = 0; // new G4RKG3_Stepper( fEquation, nvar );
186  G4cout<<"G4RKG3_Stepper is not currently working for Electric Field"
187  <<G4endl;
188  break;
189  case 7:
190  fStepper = 0; // new G4HelixExplicitEuler( fEquation );
191  G4cout<<"G4HelixExplicitEuler is not valid for Electric Field"<<G4endl;
192  break;
193  case 8:
194  fStepper = 0; // new G4HelixImplicitEuler( fEquation );
195  G4cout<<"G4HelixImplicitEuler is not valid for Electric Field"<<G4endl;
196  break;
197  case 9:
198  fStepper = 0; // new G4HelixSimpleRunge( fEquation );
199  G4cout<<"G4HelixSimpleRunge is not valid for Electric Field"<<G4endl;
200  break;
201  default: fStepper = 0;
202  }
203 }
204 
205 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
206 
208 {
209  // Set the value of the Global Field to fieldValue along Z
210 
211  G4ThreeVector fieldVector( 0.0, 0.0, fieldValue );
212 
213  SetFieldValue( fieldVector );
214 }
215 
216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
217 
219 {
220  if (fEMfield) delete fEMfield;
221 
222  // Set the value of the Global Field value to fieldVector
223 
224  // Find the Field Manager for the global field
226 
227  if (fieldVector != G4ThreeVector(0.,0.,0.))
228  {
229  fEMfield = new G4UniformElectricField(fieldVector);
230  }
231  else
232  {
233  // If the new field's value is Zero, then it is best to
234  // insure that it is not used for propagation.
235  fEMfield = 0;
236  }
237  fieldMgr->SetDetectorField(fEMfield);
238  fEquation->SetFieldObj(fEMfield); // must now point to the new field
239 }
240 
241 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
242 
244 {
245 // Utility method
246 
248  ->GetFieldManager();
249 }
250 
251 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
static const double cm
Definition: G4SIunits.hh:118
Definition of the F02ElectricFieldSetup class.
G4MagIntegratorStepper * fStepper
G4MagInt_Driver * fIntgrDriver
CLHEP::Hep3Vector G4ThreeVector
G4bool SetDetectorField(G4Field *detectorField)
Definition of the F02FieldMessenger class.
G4FieldManager * GetGlobalFieldManager()
G4FieldManager * fFieldManager
void SetFieldValue(G4ThreeVector fieldVector)
void SetChordFinder(G4ChordFinder *aChordFinder)
int G4int
Definition: G4Types.hh:78
G4int GetNumberOfVariables() const
G4GLOB_DLL std::ostream G4cout
G4EqMagElectricField * fEquation
F02FieldMessenger * fFieldMessenger
static G4TransportationManager * GetTransportationManager()
#define fMinStep
static const double kilovolt
Definition: G4SIunits.hh:240
G4FieldManager * GetFieldManager() const
void SetFieldObj(G4Field *pField)
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
static const double mm
Definition: G4SIunits.hh:114