Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //
28 //
29 //
30 // $Id$
31 //
32 //
33 // Field Setup class implementation.
34 //
35 
36 #include "F03FieldSetup.hh"
37 #include "F03FieldMessenger.hh"
38 
39 #include "G4UniformMagField.hh"
40 #include "G4MagneticField.hh"
41 #include "G4FieldManager.hh"
43 #include "G4Mag_UsualEqRhs.hh"
45 #include "G4ChordFinder.hh"
46 
47 #include "G4ExplicitEuler.hh"
48 #include "G4ImplicitEuler.hh"
49 #include "G4SimpleRunge.hh"
50 #include "G4SimpleHeum.hh"
51 #include "G4ClassicalRK4.hh"
52 #include "G4HelixExplicitEuler.hh"
53 #include "G4HelixImplicitEuler.hh"
54 #include "G4HelixSimpleRunge.hh"
55 #include "G4CashKarpRKF45.hh"
56 #include "G4RKG3_Stepper.hh"
57 #include "G4SystemOfUnits.hh"
58 
60 //
61 // Constructors:
62 
64  : fChordFinder(0), fLocalChordFinder(0), fStepper(0)
65 {
67  G4ThreeVector(3.3*tesla,
68  0.0, // 0.5*tesla,
69  0.0 ));
71  G4ThreeVector(3.3*tesla,
72  0.0, // 0.5*tesla,
73  0.0 ));
74 
75  fFieldMessenger = new F03FieldMessenger(this) ;
76 
79 
80  fMinStep = 0.25*mm ; // minimal step of 1 mm is default
81  fStepperType = 4 ; // ClassicalRK4 is default stepper
82 
85 
86  UpdateField();
87 }
88 
90 
92 {
93  fMagneticField = new G4UniformMagField(fieldVector);
95 }
96 
98 
100 {
101  if(fMagneticField) delete fMagneticField;
102  if(fChordFinder) delete fChordFinder;
103  if(fStepper) delete fStepper;
104 }
105 
107 //
108 // Update field
109 //
110 
112 {
113  SetStepper();
114  G4cout<<"The minimal step is equal to "<<fMinStep/mm<<" mm"<<G4endl ;
115 
118 
119  if(fChordFinder) delete fChordFinder;
121 
125 
128 }
129 
131 //
132 // Set stepper according to the stepper type
133 //
134 
136 {
137  if(fStepper) delete fStepper;
138 
139  switch ( fStepperType )
140  {
141  case 0:
144  G4cout<<"G4ExplicitEuler is calledS"<<G4endl;
145  break;
146  case 1:
149  G4cout<<"G4ImplicitEuler is called"<<G4endl;
150  break;
151  case 2:
152  fStepper = new G4SimpleRunge( fEquation );
154  G4cout<<"G4SimpleRunge is called"<<G4endl;
155  break;
156  case 3:
157  fStepper = new G4SimpleHeum( fEquation );
159  G4cout<<"G4SimpleHeum is called"<<G4endl;
160  break;
161  case 4:
164  G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
165  break;
166  case 5:
169  G4cout<<"G4HelixExplicitEuler is called"<<G4endl;
170  break;
171  case 6:
174  G4cout<<"G4HelixImplicitEuler is called"<<G4endl;
175  break;
176  case 7:
179  G4cout<<"G4HelixSimpleRunge is called"<<G4endl;
180  break;
181  case 8:
184  G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
185  break;
186  case 9:
189  G4cout<<"G4RKG3_Stepper is called"<<G4endl;
190  break;
191  default: fStepper = 0;
192  }
193 }
194 
196 //
197 // Set the value of the Global Field to fieldValue along Z
198 //
199 
201 {
202  G4ThreeVector fieldSetVec(0.0, 0.0, fieldStrength);
203  this->SetFieldValue( fieldSetVec );
204  // *************
205 
206 }
207 
209 //
210 // Set the value of the Global Field
211 //
212 
214 {
215  if(fMagneticField) delete fMagneticField;
216 
217  if(fieldVector != G4ThreeVector(0.,0.,0.))
218  {
219  fMagneticField = new G4UniformMagField(fieldVector);
220  }
221  else
222  {
223  // If the new field's value is Zero, then
224  // setting the pointer to zero ensures
225  // that it is not used for propagation.
226  fMagneticField = 0;
227  }
228 
229  // Either
230  // - UpdateField() to reset all (ChordFinder, Equation);
231  // UpdateField();
232  // or simply update the field manager & equation of motion
233  // with pointer to new field
236 
237 }
238 
240 //
241 // Utility method
242 
244 {
246  ->GetFieldManager();
247 }
248 
249 
250 // In place of G4UniformField::GetConstantFieldValue ...
251 //
253 {
254  static G4double fieldValue[6], position[4];
255  position[0] = position[1] = position[2] = position[3] = 0.0;
256 
257  fMagneticField->GetFieldValue( position, fieldValue);
258  G4ThreeVector fieldVec(fieldValue[0], fieldValue[1], fieldValue[2]);
259 
260  return fieldVec;
261 }