Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 // $Id: F02ElectricFieldSetup.cc 109871 2018-05-09 12:40:14Z 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  : fMinStep(0.010*mm), // minimal step of 10 microns
73  fFieldManager(0),
74  fChordFinder(0),
75  fEquation(0),
76  fEMfield(0),
77  fElFieldValue(),
78  fStepper(0),
79  fIntgrDriver(0),
80  fStepperType(4), // ClassicalRK4 -- the default stepper
81  fFieldMessenger(nullptr)
82 {
84  G4ThreeVector(0.0,100000.0*kilovolt/cm,0.0));
86 
88 
91 }
92 
93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
94 
96  : fMinStep(0.010*mm), // minimal step of 10 microns
97  fFieldManager(0),
98  fChordFinder(0),
99  fEquation(0),
100  fEMfield(0),
101  fElFieldValue(),
102  fStepper(0),
103  fIntgrDriver(0),
104  fStepperType(4), // ClassicalRK4 -- the default stepper
105  fFieldMessenger(nullptr)
106 {
107  fEMfield = new G4UniformElectricField(fieldVector);
109 
112 
114 }
115 
116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
117 
119 {
120  // G4cout << " F02ElectricFieldSetup - dtor called. " << G4endl;
121 
122  delete fFieldMessenger; fFieldMessenger= nullptr;
123  // Delete the messenger first, to avoid messages to deleted classes!
124 
125  delete fChordFinder; fChordFinder= nullptr;
126  delete fStepper; fStepper = nullptr;
127  delete fEquation; fEquation = nullptr;
128  delete fEMfield; fEMfield = nullptr;
129 }
130 
131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
132 
134 {
135  // Register this field to 'global' Field Manager and
136  // Create Stepper and Chord Finder with predefined type, minstep (resp.)
137 
138  // It must be possible to call 'again' after an alternative stepper
139  // has been chosen, or other changes have been made
140  assert(fEquation!=nullptr);
141 
142  G4cout<< " F02ElectricFieldSetup: The minimal step is equal to "
143  << fMinStep/mm << " mm" << G4endl;
144 
145  if (fChordFinder) {
146  delete fChordFinder;
147  fChordFinder= nullptr;
148  // The chord-finder's destructor deletes the driver
149  fIntgrDriver= nullptr;
150  }
151 
152  // Currently driver does not 'own' stepper ( 17.05.2017 J.A. )
153  // -- so this stepper is still a valid object after this
154 
155  if( fStepper ) {
156  delete fStepper;
157  fStepper = nullptr;
158  }
159 
160  // Create the new objects, in turn for all relevant classes
161  // -- Careful to call this after all old objects are destroyed, and
162  // pointers nullified.
163  CreateStepper(); // Note that this method deleted the existing Stepper!
164  // G4cout << "F02ElectricFieldSetup::UpdateIntegrator> "
165  // << "New value of stepper ptr= " << fStepper << G4endl;
166  assert(fStepper != nullptr);
167 
168  if( fStepper ) {
170  fStepper,
172  if( fIntgrDriver ){
174  }
175  }
176 
179 }
180 
181 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
182 
184 {
185  // Deletes the existing stepper
186  // and creates a new stepper object of the chosen stepper type
187 
188  const G4int nvar = 8;
189 
190  auto oldStepper= fStepper;
191 
192  switch ( fStepperType )
193  {
194  case 0:
195  fStepper = new G4ExplicitEuler( fEquation, nvar );
196  G4cout<<"G4ExplicitEuler is calledS"<<G4endl;
197  break;
198  case 1:
199  fStepper = new G4ImplicitEuler( fEquation, nvar );
200  G4cout<<"G4ImplicitEuler is called"<<G4endl;
201  break;
202  case 2:
203  fStepper = new G4SimpleRunge( fEquation, nvar );
204  G4cout<<"G4SimpleRunge is called"<<G4endl;
205  break;
206  case 3:
207  fStepper = new G4SimpleHeum( fEquation, nvar );
208  G4cout<<"G4SimpleHeum is called"<<G4endl;
209  break;
210  case 4:
211  fStepper = new G4ClassicalRK4( fEquation, nvar );
212  G4cout<<"G4ClassicalRK4 is called"<<G4endl;
213  break;
214  case 5:
215  fStepper = new G4CashKarpRKF45( fEquation, nvar );
216  G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
217  break;
218  case 6:
219  fStepper = 0; // new G4RKG3_Stepper( fEquation, nvar );
220  G4cout<<"G4RKG3_Stepper is not currently working for Electric Field"
221  <<G4endl;
222  break;
223  case 7:
224  fStepper = 0; // new G4HelixExplicitEuler( fEquation );
225  G4cout<<"G4HelixExplicitEuler is not valid for Electric Field"<<G4endl;
226  break;
227  case 8:
228  fStepper = 0; // new G4HelixImplicitEuler( fEquation );
229  G4cout<<"G4HelixImplicitEuler is not valid for Electric Field"<<G4endl;
230  break;
231  case 9:
232  fStepper = 0; // new G4HelixSimpleRunge( fEquation );
233  G4cout<<"G4HelixSimpleRunge is not valid for Electric Field"<<G4endl;
234  break;
235  default: /* fStepper = 0; // Older code */
236  fStepper = new G4ClassicalRK4( fEquation, nvar );
237  G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
238  break;
239  }
240 
241  delete oldStepper;
242  // Now must make sure it is 'stripped' from the dependent object(s)
243  // ... but the next line does this anyway - by informing
244  // the driver (if it exists) about the new stepper.
245 
246  // Always inform the (existing) driver about the new stepper
247  if( fIntgrDriver )
249 }
250 
251 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
252 
254 {
255  // Set the value of the Global Field to fieldValue along Z
256 
257  G4ThreeVector fieldVector( 0.0, 0.0, fieldValue );
258 
259  SetFieldValue( fieldVector );
260 }
261 
262 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
263 
265 {
266  if (fEMfield) delete fEMfield;
267 
268  // Set the value of the Global Field value to fieldVector
269 
270  // Find the Field Manager for the global field
272 
273  if (fieldVector != G4ThreeVector(0.,0.,0.))
274  {
275  fEMfield = new G4UniformElectricField(fieldVector);
276  }
277  else
278  {
279  // If the new field's value is Zero, then it is best to
280  // insure that it is not used for propagation.
281  fEMfield = 0;
282  }
283  fieldMgr->SetDetectorField(fEMfield);
284  fEquation->SetFieldObj(fEMfield); // must now point to the new field
285 }
286 
287 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
288 
290 {
291 // Utility method
292 
294  ->GetFieldManager();
295 }
296 
297 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
CLHEP::Hep3Vector G4ThreeVector
static constexpr double mm
Definition: G4SIunits.hh:115
#define G4endl
Definition: G4ios.hh:61
#define fMinStep
void SetFieldValue(G4ThreeVector fieldVector)
G4EqMagElectricField * fEquation
void SetFieldObj(G4Field *pField)
G4bool SetDetectorField(G4Field *detectorField, int failMode=0)
double G4double
Definition: G4Types.hh:76
Definition of the F02ElectricFieldSetup class.
G4FieldManager * GetFieldManager() const
G4FieldManager * fFieldManager
G4MagInt_Driver * fIntgrDriver
static G4TransportationManager * GetTransportationManager()
static constexpr double kilovolt
Definition: G4SIunits.hh:243
F02FieldMessenger * fFieldMessenger
void SetChordFinder(G4ChordFinder *aChordFinder)
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
static constexpr double cm
Definition: G4SIunits.hh:119
G4FieldManager * GetGlobalFieldManager()
G4int GetNumberOfVariables() const
Definition of the F02FieldMessenger class.
G4MagIntegratorStepper * fStepper
virtual void RenewStepperAndAdjust(G4MagIntegratorStepper *pItsStepper) override