EDepSimEMFieldSetup.cc
Go to the documentation of this file.
1 // ********************************************************************
2 // * License and Disclaimer *
3 // * *
4 // * The Geant4 software is copyright of the Copyright Holders of *
5 // * the Geant4 Collaboration. It is provided under the terms and *
6 // * conditions of the Geant4 Software License, included in the file *
7 // * LICENSE and available at http://cern.ch/geant4/license . These *
8 // * include a list of copyright holders. *
9 // * *
10 // * Neither the authors of this software system, nor their employing *
11 // * institutes,nor the agencies providing financial support for this *
12 // * work make any representation or warranty, express or implied, *
13 // * regarding this software system or assume any liability for its *
14 // * use. Please see the license in the file LICENSE and URL above *
15 // * for the full disclaimer and the limitation of liability. *
16 // * *
17 // * This code implementation is the result of the scientific and *
18 // * technical work of the GEANT4 collaboration. *
19 // * By using, copying, modifying or distributing the software (or *
20 // * any work based on the software) you agree to acknowledge its *
21 // * use in resulting scientific publications, and indicate your *
22 // * acceptance of all terms of the Geant4 Software license. *
23 // ********************************************************************
24 //
25 /// \file field/field02/src/EDepSimElectricFieldSetup.cc
26 /// \brief Implementation of the EDepSim::ElectricFieldSetup class
27 //
28 //
29 // $Id: EDepSimEMFieldSetup.cc 77123 2013-11-21 16:13:28Z gcosmo $
30 //
31 // User Field class implementation.
32 //
33 // History:
34 // - 2017.03.15 C.McGrew adapted for EDepSim
35 //
36 //
37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
39 
40 #include "EDepSimEMFieldSetup.hh"
41 
42 #include "G4UniformElectricField.hh"
43 #include "G4UniformMagField.hh"
44 #include "G4MagneticField.hh"
45 #include "G4FieldManager.hh"
46 #include "G4TransportationManager.hh"
47 #include "G4EquationOfMotion.hh"
48 #include "G4EqMagElectricField.hh"
49 #include "G4Mag_UsualEqRhs.hh"
50 #include "G4MagIntegratorStepper.hh"
51 #include "G4MagIntegratorDriver.hh"
52 #include "G4ChordFinder.hh"
53 
54 #include "G4ExplicitEuler.hh"
55 #include "G4ImplicitEuler.hh"
56 #include "G4SimpleRunge.hh"
57 #include "G4SimpleHeum.hh"
58 #include "G4ClassicalRK4.hh"
59 #include "G4HelixExplicitEuler.hh"
60 #include "G4HelixImplicitEuler.hh"
61 #include "G4HelixSimpleRunge.hh"
62 #include "G4CashKarpRKF45.hh"
63 #include "G4RKG3_Stepper.hh"
64 
65 #include "G4PhysicalConstants.hh"
66 #include "G4SystemOfUnits.hh"
67 
68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
69 
70 // Constructors:
71 
72 EDepSim::EMFieldSetup::EMFieldSetup(G4FieldManager* fieldManager)
73  : fFieldManager(fieldManager),
74  fChordFinder(0),
75  fEquation(0),
76  fEMfield(0),
77  fStepper(0),
78  fIntgrDriver(0),
79  fStepperType(4), // ClassicalRK4 -- the default stepper
80  fMinStep(0.010*mm) // minimal step of 10 microns
81 {
82  fEMfield = new G4UniformElectricField(G4ThreeVector(0.0,500.0*volt/cm,0.0));
83  fEquation = new G4EqMagElectricField(fEMfield);
84 
85  UpdateField();
86 }
87 
88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
89 
90 EDepSim::EMFieldSetup::EMFieldSetup(G4ElectroMagneticField* field,
91  G4FieldManager* fieldManager)
92  : fFieldManager(fieldManager),
93  fChordFinder(0),
94  fEquation(0),
95  fEMfield(field),
96  fStepper(0),
97  fIntgrDriver(0),
98  fStepperType(4), // ClassicalRK4 -- the default stepper
99  fMinStep(0.010*mm) // minimal step of 10 microns
100 {
101  fEquation = new G4EqMagElectricField(fEMfield);
102 
103  UpdateField();
104 }
105 
106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
107 
109 {
110  delete fChordFinder;
111  delete fStepper;
112  delete fEquation;
113  delete fEMfield;
114 }
115 
116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
117 
119 {
120  // Register this field to 'global' Field Manager and
121  // Create Stepper and Chord Finder with predefined type, minstep (resp.)
122 
124 
125  SetStepper();
126 
127  G4cout<<"The minimal step is equal to "<<fMinStep/mm<<" mm"<<G4endl;
128 
129  fFieldManager->SetDetectorField(fEMfield);
130 
131  if (fChordFinder) delete fChordFinder;
132 
133  fIntgrDriver = new G4MagInt_Driver(fMinStep,
134  fStepper,
135  fStepper->GetNumberOfVariables());
136 
137  fChordFinder = new G4ChordFinder(fIntgrDriver);
138 
139  fFieldManager->SetChordFinder(fChordFinder);
140 }
141 
142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
143 
145 {
146 // Set stepper according to the stepper type
147 
148  G4int nvar = 8;
149 
150  if (fStepper) delete fStepper;
151 
152  switch ( fStepperType )
153  {
154  case 0:
155  fStepper = new G4ExplicitEuler( fEquation, nvar );
156  G4cout<<"G4ExplicitEuler is calledS"<<G4endl;
157  break;
158  case 1:
159  fStepper = new G4ImplicitEuler( fEquation, nvar );
160  G4cout<<"G4ImplicitEuler is called"<<G4endl;
161  break;
162  case 2:
163  fStepper = new G4SimpleRunge( fEquation, nvar );
164  G4cout<<"G4SimpleRunge is called"<<G4endl;
165  break;
166  case 3:
167  fStepper = new G4SimpleHeum( fEquation, nvar );
168  G4cout<<"G4SimpleHeum is called"<<G4endl;
169  break;
170  case 4:
171  fStepper = new G4ClassicalRK4( fEquation, nvar );
172  G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
173  break;
174  case 5:
175  fStepper = new G4CashKarpRKF45( fEquation, nvar );
176  G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
177  break;
178  case 6:
179  fStepper = 0; // new G4RKG3_Stepper( fEquation, nvar );
180  G4cout<<"G4RKG3_Stepper is not currently working for Electric Field"
181  <<G4endl;
182  break;
183  case 7:
184  fStepper = 0; // new G4HelixExplicitEuler( fEquation );
185  G4cout<<"G4HelixExplicitEuler is not valid for Electric Field"<<G4endl;
186  break;
187  case 8:
188  fStepper = 0; // new G4HelixImplicitEuler( fEquation );
189  G4cout<<"G4HelixImplicitEuler is not valid for Electric Field"<<G4endl;
190  break;
191  case 9:
192  fStepper = 0; // new G4HelixSimpleRunge( fEquation );
193  G4cout<<"G4HelixSimpleRunge is not valid for Electric Field"<<G4endl;
194  break;
195  default: fStepper = 0;
196  }
197 }
198 
199 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
200 
202 {
203 // Utility method
204 
205  return G4TransportationManager::GetTransportationManager()
206  ->GetFieldManager();
207 }
208 
209 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
static constexpr double cm
Definition: Units.h:68
G4EqMagElectricField * fEquation
EMFieldSetup(G4ElectroMagneticField *field, G4FieldManager *m=0)
G4ChordFinder * fChordFinder
volt_as<> volt
Type of potential stored in volts, in double precision.
G4FieldManager * fFieldManager
G4MagIntegratorStepper * fStepper
G4MagInt_Driver * fIntgrDriver
G4ElectroMagneticField * fEMfield
static constexpr double mm
Definition: Units.h:65
G4FieldManager * GetGlobalFieldManager()