ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
F02ElectricFieldSetup.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file F02ElectricFieldSetup.cc
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 //
31 // User Field class implementation.
32 //
33 //
34 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36 
37 #include "F02ElectricFieldSetup.hh"
38 #include "F02FieldMessenger.hh"
39 
41 #include "G4UniformMagField.hh"
42 #include "G4MagneticField.hh"
43 #include "G4FieldManager.hh"
45 #include "G4EquationOfMotion.hh"
46 #include "G4EqMagElectricField.hh"
47 #include "G4Mag_UsualEqRhs.hh"
49 #include "G4MagIntegratorDriver.hh"
50 #include "G4ChordFinder.hh"
51 
52 #include "G4ExplicitEuler.hh"
53 #include "G4ImplicitEuler.hh"
54 #include "G4SimpleRunge.hh"
55 #include "G4SimpleHeum.hh"
56 #include "G4ClassicalRK4.hh"
57 #include "G4HelixExplicitEuler.hh"
58 #include "G4HelixImplicitEuler.hh"
59 #include "G4HelixSimpleRunge.hh"
60 #include "G4CashKarpRKF45.hh"
61 #include "G4RKG3_Stepper.hh"
62 
63 #include "G4PhysicalConstants.hh"
64 #include "G4SystemOfUnits.hh"
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
68 // Constructors:
69 
71  : fMinStep(0.010*mm), // minimal step of 10 microns
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  fFieldMessenger(nullptr)
81 {
83  G4ThreeVector(0.0,100000.0*kilovolt/cm,0.0));
85 
87 
90 }
91 
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93 
95  : fMinStep(0.010*mm), // minimal step of 10 microns
96  fFieldManager(0),
97  fChordFinder(0),
98  fEquation(0),
99  fEMfield(0),
100  fElFieldValue(),
101  fStepper(0),
102  fIntgrDriver(0),
103  fStepperType(4), // ClassicalRK4 -- the default stepper
104  fFieldMessenger(nullptr)
105 {
106  fEMfield = new G4UniformElectricField(fieldVector);
108 
111 
113 }
114 
115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
116 
118 {
119  // G4cout << " F02ElectricFieldSetup - dtor called. " << G4endl;
120 
121  delete fFieldMessenger; fFieldMessenger= nullptr;
122  // Delete the messenger first, to avoid messages to deleted classes!
123 
124  delete fChordFinder; fChordFinder= nullptr;
125  delete fStepper; fStepper = nullptr;
126  delete fEquation; fEquation = nullptr;
127  delete fEMfield; fEMfield = nullptr;
128 }
129 
130 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
131 
133 {
134  // Register this field to 'global' Field Manager and
135  // Create Stepper and Chord Finder with predefined type, minstep (resp.)
136 
137  // It must be possible to call 'again' after an alternative stepper
138  // has been chosen, or other changes have been made
139  assert(fEquation!=nullptr);
140 
141  G4cout<< " F02ElectricFieldSetup: The minimal step is equal to "
142  << fMinStep/mm << " mm" << G4endl;
143 
144  if (fChordFinder) {
145  delete fChordFinder;
146  fChordFinder= nullptr;
147  // The chord-finder's destructor deletes the driver
148  fIntgrDriver= nullptr;
149  }
150 
151  // Currently driver does not 'own' stepper ( 17.05.2017 J.A. )
152  // -- so this stepper is still a valid object after this
153 
154  if( fStepper ) {
155  delete fStepper;
156  fStepper = nullptr;
157  }
158 
159  // Create the new objects, in turn for all relevant classes
160  // -- Careful to call this after all old objects are destroyed, and
161  // pointers nullified.
162  CreateStepper(); // Note that this method deleted the existing Stepper!
163  // G4cout << "F02ElectricFieldSetup::UpdateIntegrator> "
164  // << "New value of stepper ptr= " << fStepper << G4endl;
165  assert(fStepper != nullptr);
166 
167  if( fStepper ) {
169  fStepper,
171  if( fIntgrDriver ){
173  }
174  }
175 
178 }
179 
180 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
181 
183 {
184  // Deletes the existing stepper
185  // and creates a new stepper object of the chosen stepper type
186 
187  const G4int nvar = 8;
188 
189  auto oldStepper= fStepper;
190 
191  switch ( fStepperType )
192  {
193  case 0:
194  fStepper = new G4ExplicitEuler( fEquation, nvar );
195  G4cout<<"G4ExplicitEuler is calledS"<<G4endl;
196  break;
197  case 1:
198  fStepper = new G4ImplicitEuler( fEquation, nvar );
199  G4cout<<"G4ImplicitEuler is called"<<G4endl;
200  break;
201  case 2:
202  fStepper = new G4SimpleRunge( fEquation, nvar );
203  G4cout<<"G4SimpleRunge is called"<<G4endl;
204  break;
205  case 3:
206  fStepper = new G4SimpleHeum( fEquation, nvar );
207  G4cout<<"G4SimpleHeum is called"<<G4endl;
208  break;
209  case 4:
210  fStepper = new G4ClassicalRK4( fEquation, nvar );
211  G4cout<<"G4ClassicalRK4 is called"<<G4endl;
212  break;
213  case 5:
214  fStepper = new G4CashKarpRKF45( fEquation, nvar );
215  G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
216  break;
217  case 6:
218  fStepper = 0; // new G4RKG3_Stepper( fEquation, nvar );
219  G4cout<<"G4RKG3_Stepper is not currently working for Electric Field"
220  <<G4endl;
221  break;
222  case 7:
223  fStepper = 0; // new G4HelixExplicitEuler( fEquation );
224  G4cout<<"G4HelixExplicitEuler is not valid for Electric Field"<<G4endl;
225  break;
226  case 8:
227  fStepper = 0; // new G4HelixImplicitEuler( fEquation );
228  G4cout<<"G4HelixImplicitEuler is not valid for Electric Field"<<G4endl;
229  break;
230  case 9:
231  fStepper = 0; // new G4HelixSimpleRunge( fEquation );
232  G4cout<<"G4HelixSimpleRunge is not valid for Electric Field"<<G4endl;
233  break;
234  default: /* fStepper = 0; // Older code */
235  fStepper = new G4ClassicalRK4( fEquation, nvar );
236  G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
237  break;
238  }
239 
240  delete oldStepper;
241  // Now must make sure it is 'stripped' from the dependent object(s)
242  // ... but the next line does this anyway - by informing
243  // the driver (if it exists) about the new stepper.
244 
245  // Always inform the (existing) driver about the new stepper
246  if( fIntgrDriver )
248 }
249 
250 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
251 
253 {
254  // Set the value of the Global Field to fieldValue along Z
255 
256  G4ThreeVector fieldVector( 0.0, 0.0, fieldValue );
257 
258  SetFieldValue( fieldVector );
259 }
260 
261 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
262 
264 {
265  if (fEMfield) delete fEMfield;
266 
267  // Set the value of the Global Field value to fieldVector
268 
269  // Find the Field Manager for the global field
271 
272  if (fieldVector != G4ThreeVector(0.,0.,0.))
273  {
274  fEMfield = new G4UniformElectricField(fieldVector);
275  }
276  else
277  {
278  // If the new field's value is Zero, then it is best to
279  // insure that it is not used for propagation.
280  fEMfield = 0;
281  }
282  fieldMgr->SetDetectorField(fEMfield);
283  fEquation->SetFieldObj(fEMfield); // must now point to the new field
284 }
285 
286 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
287 
289 {
290 // Utility method
291 
293  ->GetFieldManager();
294 }
295 
296 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......