Loading...
Searching...
No Matches
F03FieldSetup.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/field03/src/F03FieldSetup.cc
27/// \brief Implementation of the F03FieldSetup class
28//
29//
30//
31//
32// Field Setup class implementation.
33//
34//
35//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
37
38#include "F03FieldSetup.hh"
39#include "F03FieldMessenger.hh"
40
41#include "G4MagneticField.hh"
42#include "G4UniformMagField.hh"
43#include "G4FieldManager.hh"
44#include "G4TransportationManager.hh"
45#include "G4Mag_UsualEqRhs.hh"
46#include "G4MagIntegratorStepper.hh"
47#include "G4ChordFinder.hh"
48
49#include "G4ExplicitEuler.hh"
50#include "G4ImplicitEuler.hh"
51#include "G4SimpleRunge.hh"
52#include "G4SimpleHeum.hh"
53#include "G4ClassicalRK4.hh"
54#include "G4HelixExplicitEuler.hh"
55#include "G4HelixImplicitEuler.hh"
56#include "G4HelixSimpleRunge.hh"
57#include "G4CashKarpRKF45.hh"
58#include "G4RKG3_Stepper.hh"
59
60#include "G4PhysicalConstants.hh"
61#include "G4SystemOfUnits.hh"
62
63//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64
66{
67 fMagneticField = new G4UniformMagField(G4ThreeVector(3.3*tesla,
68 0.0, // 0.5*tesla,
69 0.0));
70 fLocalMagneticField = new G4UniformMagField(G4ThreeVector(3.3*tesla,
71 0.0, // 0.5*tesla,
72 0.0));
73
75
78
81
83}
84
85//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86
88{
89 delete fMagneticField;
90 delete fChordFinder;
91 delete fStepper;
92 delete fFieldMessenger;
93}
94
95//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
96
98{
99 // It must be possible to call 'again' - e.g. to choose an alternative stepper
100 // has been chosen, or in case other changes have been made.
101
102 // 1. First clean up previous state.
103 delete fChordFinder;
104 fChordFinder= nullptr;
105 delete fLocalChordFinder;
106 fLocalChordFinder= nullptr;
107
108 G4cout<<"F03FieldSetup::UpdateField> The minimal step is equal to "
109 << fMinStep/mm <<" mm"<<G4endl;
110 G4cout<<" Stepper Type chosen = " << fStepperType
111 << G4endl;
112
113 // 2. Create the steppers ( Note: this also deletes the previous ones. )
115
116
117 // 3. Create the chord finder(s)
121
122 fFieldManager->SetChordFinder(fChordFinder);
123 fLocalFieldManager->SetChordFinder(fLocalChordFinder);
124
125 // 4. Ensure that the field is updated (in Field manager & equation)
126 fFieldManager->SetDetectorField(fMagneticField);
127 fLocalFieldManager->SetDetectorField(fLocalMagneticField);
128}
129
130//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
131
133{
134 delete fStepper;
135 fStepper= nullptr;
136
137 delete fLocalStepper;
138 fLocalStepper= nullptr;
139
140 switch ( fStepperType )
141 {
142 case 0:
145 G4cout<<"G4ExplicitEuler is called"<<G4endl;
146 break;
147 case 1:
150 G4cout<<"G4ImplicitEuler is called"<<G4endl;
151 break;
152 case 2:
155 G4cout<<"G4SimpleRunge is called"<<G4endl;
156 break;
157 case 3:
160 G4cout<<"G4SimpleHeum is called"<<G4endl;
161 break;
162 case 4:
165 G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
166 break;
167 case 5:
170 G4cout<<"G4HelixExplicitEuler is called"<<G4endl;
171 break;
172 case 6:
175 G4cout<<"G4HelixImplicitEuler is called"<<G4endl;
176 break;
177 case 7:
180 G4cout<<"G4HelixSimpleRunge is called"<<G4endl;
181 break;
182 case 8:
185 G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
186 break;
187 case 9:
190 G4cout<<"G4RKG3_Stepper is called"<<G4endl;
191 break;
192 default: fStepper = nullptr;
193 }
194}
195
196//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
197
198void F03FieldSetup::SetFieldZValue(G4double fieldStrength)
199{
200 G4ThreeVector fieldSetVec(0.0, 0.0, fieldStrength);
201 SetFieldValue( fieldSetVec );
202}
203
204//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
205
206void F03FieldSetup::SetFieldValue(G4ThreeVector fieldVector)
207{
208 delete fMagneticField;
209
210 if(fieldVector != G4ThreeVector(0.,0.,0.))
211 {
212 fMagneticField = new G4UniformMagField(fieldVector);
213 }
214 else
215 {
216 // If the new field's value is Zero, then
217 // setting the pointer to zero ensures
218 // that it is not used for propagation.
219 fMagneticField = nullptr;
220 }
221
222 // Either
223 // - UpdateField() to reset all (ChordFinder, Equation);
224 // UpdateField();
225 // or simply update the field manager & equation of motion
226 // with pointer to new field
227 GetGlobalFieldManager()->SetDetectorField(fMagneticField);
228 fEquation->SetFieldObj( fMagneticField );
229
230}
231
232//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
233
234void F03FieldSetup::SetLocalFieldValue(G4ThreeVector fieldVector)
235{
236 delete fLocalMagneticField;
237
238 if(fieldVector != G4ThreeVector(0.,0.,0.))
239 {
240 fLocalMagneticField = new G4UniformMagField(fieldVector);
241 }
242 else
243 {
244 // If the new field's value is Zero, then
245 // setting the pointer to zero ensures
246 // that it is not used for propagation.
247 fLocalMagneticField = nullptr;
248 }
249
250 // Either
251 // - UpdateField() to reset all (ChordFinder, Equation);
252 // UpdateField();
253 // or simply update the field manager & equation of motion
254 // with pointer to new field
255 GetLocalFieldManager()->SetDetectorField(fLocalMagneticField);
256 fEquation->SetFieldObj( fLocalMagneticField );
257}
258
259//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
260
262{
263 return G4TransportationManager::GetTransportationManager()
264 ->GetFieldManager();
265}
266
267//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
268
269G4ThreeVector F03FieldSetup::GetConstantFieldValue(G4MagneticField* magneticField) const
270{
271 if ( ! magneticField ) return G4ThreeVector();
272
273 static G4double fieldValue[6], position[4];
274 position[0] = position[1] = position[2] = position[3] = 0.0;
275
276 magneticField->GetFieldValue( position, fieldValue);
277 G4ThreeVector fieldVec(fieldValue[0], fieldValue[1], fieldValue[2]);
278
279 return fieldVec;
280}
281
282//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Definition of the F03FieldMessenger class.
Definition of the F03FieldSetup class.
virtual ~F03FieldSetup()
F03FieldMessenger * fFieldMessenger
G4Mag_UsualEqRhs * fLocalEquation
G4MagIntegratorStepper * fLocalStepper
G4double fMinStep
G4FieldManager * fFieldManager
G4ThreeVector GetConstantFieldValue(G4MagneticField *magneticField) const
G4FieldManager * GetLocalFieldManager()
void SetFieldValue(G4ThreeVector fieldVector)
G4MagneticField * fMagneticField
void SetLocalFieldValue(G4ThreeVector fieldVector)
G4FieldManager * GetGlobalFieldManager()
G4Mag_UsualEqRhs * fEquation
G4ChordFinder * fChordFinder
G4ChordFinder * fLocalChordFinder
G4FieldManager * fLocalFieldManager
G4MagIntegratorStepper * fStepper
G4MagneticField * fLocalMagneticField
void SetFieldZValue(G4double fieldValue)

Applications | User Support | Publications | Collaboration