Loading...
Searching...
No Matches
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//
26/// \file field/field02/src/F02ElectricFieldSetup.cc
27/// \brief Implementation of the F02ElectricFieldSetup class
28//
29//
30//
31// User Field class implementation.
32//
33//
34//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
35//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36
38#include "F02FieldMessenger.hh"
39
40#include "G4UniformElectricField.hh"
41#include "G4UniformMagField.hh"
42#include "G4MagneticField.hh"
43#include "G4FieldManager.hh"
44#include "G4TransportationManager.hh"
45#include "G4EquationOfMotion.hh"
46#include "G4EqMagElectricField.hh"
47#include "G4Mag_UsualEqRhs.hh"
48#include "G4MagIntegratorStepper.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
81
82//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
83
94
95//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
96
98{
99 // G4cout << " F02ElectricFieldSetup - dtor called. " << G4endl;
100
101 delete fFieldMessenger; fFieldMessenger= nullptr;
102 // Delete the messenger first, to avoid messages to deleted classes!
103
104 delete fChordFinder; fChordFinder= nullptr;
105 delete fStepper; fStepper = nullptr;
106 delete fEquation; fEquation = nullptr;
107 delete fEMfield; fEMfield = nullptr;
108}
109
110//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
111
113{
114 // Register this field to 'global' Field Manager and
115 // Create Stepper and Chord Finder with predefined type, minstep (resp.)
116
117 // It must be possible to call 'again' after an alternative stepper
118 // has been chosen, or other changes have been made
119 assert(fEquation!=nullptr);
120
121 G4cout<< " F02ElectricFieldSetup: The minimal step is equal to "
122 << fMinStep/mm << " mm" << G4endl;
123
124 if (fChordFinder) {
125 delete fChordFinder;
126 fChordFinder= nullptr;
127 // The chord-finder's destructor deletes the driver
128 fIntgrDriver= nullptr;
129 }
130
131 // Currently driver does not 'own' stepper ( 17.05.2017 J.A. )
132 // -- so this stepper is still a valid object after this
133
134 if( fStepper ) {
135 delete fStepper;
136 fStepper = nullptr;
137 }
138
139 // Create the new objects, in turn for all relevant classes
140 // -- Careful to call this after all old objects are destroyed, and
141 // pointers nullified.
142 CreateStepper(); // Note that this method deleted the existing Stepper!
143 // G4cout << "F02ElectricFieldSetup::UpdateIntegrator> "
144 // << "New value of stepper ptr= " << fStepper << G4endl;
145 assert(fStepper != nullptr);
146
147 if( fStepper ) {
149 fStepper,
150 fStepper->GetNumberOfVariables());
151 if( fIntgrDriver ){
153 }
154 }
155
156 fFieldManager->SetChordFinder(fChordFinder);
157 fFieldManager->SetDetectorField(fEMfield);
158}
159
160//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
161
163{
164 // Deletes the existing stepper
165 // and creates a new stepper object of the chosen stepper type
166
167 const G4int nvar = 8;
168
169 auto oldStepper= fStepper;
170
171 switch ( fStepperType )
172 {
173 case 0:
174 fStepper = new G4ExplicitEuler( fEquation, nvar );
175 G4cout<<"G4ExplicitEuler is calledS"<<G4endl;
176 break;
177 case 1:
178 fStepper = new G4ImplicitEuler( fEquation, nvar );
179 G4cout<<"G4ImplicitEuler is called"<<G4endl;
180 break;
181 case 2:
182 fStepper = new G4SimpleRunge( fEquation, nvar );
183 G4cout<<"G4SimpleRunge is called"<<G4endl;
184 break;
185 case 3:
186 fStepper = new G4SimpleHeum( fEquation, nvar );
187 G4cout<<"G4SimpleHeum is called"<<G4endl;
188 break;
189 case 4:
190 fStepper = new G4ClassicalRK4( fEquation, nvar );
191 G4cout<<"G4ClassicalRK4 is called"<<G4endl;
192 break;
193 case 5:
194 fStepper = new G4CashKarpRKF45( fEquation, nvar );
195 G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
196 break;
197 case 6:
198 fStepper = nullptr; // new G4RKG3_Stepper( fEquation, nvar );
199 G4cout<<"G4RKG3_Stepper is not currently working for Electric Field"
200 <<G4endl;
201 break;
202 case 7:
203 fStepper = nullptr; // new G4HelixExplicitEuler( fEquation );
204 G4cout<<"G4HelixExplicitEuler is not valid for Electric Field"<<G4endl;
205 break;
206 case 8:
207 fStepper = nullptr; // new G4HelixImplicitEuler( fEquation );
208 G4cout<<"G4HelixImplicitEuler is not valid for Electric Field"<<G4endl;
209 break;
210 case 9:
211 fStepper = nullptr; // new G4HelixSimpleRunge( fEquation );
212 G4cout<<"G4HelixSimpleRunge is not valid for Electric Field"<<G4endl;
213 break;
214 default: /* fStepper = 0; // Older code */
215 fStepper = new G4ClassicalRK4( fEquation, nvar );
216 G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
217 break;
218 }
219
220 delete oldStepper;
221 // Now must make sure it is 'stripped' from the dependent object(s)
222 // ... but the next line does this anyway - by informing
223 // the driver (if it exists) about the new stepper.
224
225 // Always inform the (existing) driver about the new stepper
226 if( fIntgrDriver )
227 fIntgrDriver->RenewStepperAndAdjust( fStepper );
228}
229
230//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
231
233{
234 // Set the value of the Global Field to fieldValue along Z
235
236 G4ThreeVector fieldVector( 0.0, 0.0, fieldValue );
237
238 SetFieldValue( fieldVector );
239}
240
241//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
242
243void F02ElectricFieldSetup::SetFieldValue(G4ThreeVector fieldVector)
244{
245 delete fEMfield;
246
247 // Set the value of the Global Field value to fieldVector
248
249 // Find the Field Manager for the global field
251
252 if (fieldVector != G4ThreeVector(0.,0.,0.))
253 {
254 fEMfield = new G4UniformElectricField(fieldVector);
255 }
256 else
257 {
258 // If the new field's value is Zero, then it is best to
259 // insure that it is not used for propagation.
260 fEMfield = nullptr;
261 }
262 fieldMgr->SetDetectorField(fEMfield);
263 fEquation->SetFieldObj(fEMfield); // must now point to the new field
264}
265
266//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
267
269{
270// Utility method
271
272 return G4TransportationManager::GetTransportationManager()
273 ->GetFieldManager();
274}
275
276//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Definition of the F02ElectricFieldSetup class.
Definition of the F02FieldMessenger class.
F02FieldMessenger * fFieldMessenger
G4EqMagElectricField * fEquation
G4FieldManager * GetGlobalFieldManager()
void SetFieldValue(G4ThreeVector fieldVector)
void SetFieldZValue(G4double fieldValue)
G4MagIntegratorStepper * fStepper

Applications | User Support | Publications | Collaboration