source: trunk/examples/extended/field/field01/src/F01FieldSetup.cc @ 1337

Last change on this file since 1337 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 8.0 KB
Line 
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//
27// $Id: F01FieldSetup.cc,v 1.7 2006/06/29 17:16:36 gunter Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
29//
30//   User Field setup class implementation.
31//
32
33#include "F01FieldSetup.hh"
34#include "F01FieldMessenger.hh"
35
36#include "G4MagneticField.hh"
37#include "G4UniformMagField.hh"
38#include "G4FieldManager.hh"
39#include "G4TransportationManager.hh"
40#include "G4Mag_UsualEqRhs.hh"
41#include "G4MagIntegratorStepper.hh"
42#include "G4ChordFinder.hh"
43
44#include "G4ExplicitEuler.hh"
45#include "G4ImplicitEuler.hh"
46#include "G4SimpleRunge.hh"
47#include "G4SimpleHeum.hh"
48#include "G4ClassicalRK4.hh"
49#include "G4HelixExplicitEuler.hh"
50#include "G4HelixImplicitEuler.hh"
51#include "G4HelixSimpleRunge.hh"
52#include "G4CashKarpRKF45.hh"
53#include "G4RKG3_Stepper.hh"
54
55// #include "G4SIunits.hh"
56
57//////////////////////////////////////////////////////////////////////////
58//
59//  Constructors:
60
61F01FieldSetup::F01FieldSetup(G4ThreeVector fieldVector)
62  : fChordFinder(0), fStepper(0)
63{
64  fMagneticField = new G4UniformMagField( fieldVector ); 
65    // G4ThreeVector(3.3*tesla, 0.0, 0.0 ));
66  G4cout << " F01FieldSetup: magnetic field set to Uniform( "
67         << fieldVector << " ) " << G4endl;
68  InitialiseAll();
69}
70
71F01FieldSetup::F01FieldSetup()
72  : fChordFinder(0), fStepper(0)
73{
74  fMagneticField = new G4UniformMagField( G4ThreeVector(0.0, 0.0, 0.0 ) );
75  G4cout << " F01FieldSetup: magnetic field set to Uniform( 0.0, 0, 0 ) " << G4endl;
76  InitialiseAll();
77}
78
79void
80F01FieldSetup::InitialiseAll()
81{
82  fFieldMessenger = new F01FieldMessenger(this) ; 
83 
84  fEquation = new G4Mag_UsualEqRhs(fMagneticField); 
85 
86  fMinStep     = 1.0*mm ; // minimal step of 1 mm is default
87
88  fStepperType = 4 ;      // ClassicalRK4 is default stepper
89
90  fFieldManager = G4TransportationManager::GetTransportationManager()
91                                         ->GetFieldManager();
92  CreateStepperAndChordFinder();
93}
94
95////////////////////////////////////////////////////////////////////////////////
96
97F01FieldSetup::~F01FieldSetup()
98{
99  // GetGlobalFieldManager()->SetDetectorField(0);
100
101  if(fMagneticField) delete fMagneticField;
102  if(fChordFinder)   delete fChordFinder;
103  if(fStepper)       delete fStepper;
104}
105
106/////////////////////////////////////////////////////////////////////////////
107//
108// Update field
109//
110
111void F01FieldSetup::CreateStepperAndChordFinder()
112{
113  SetStepper();
114  G4cout<<"The minimal step is equal to "<<fMinStep/mm<<" mm"<<G4endl ;
115
116  fFieldManager->SetDetectorField(fMagneticField );
117
118  if(fChordFinder) delete fChordFinder;
119
120  fChordFinder = new G4ChordFinder( fMagneticField, fMinStep,fStepper);
121
122  fFieldManager->SetChordFinder( fChordFinder );
123
124  return;
125}
126
127/////////////////////////////////////////////////////////////////////////////
128//
129// Set stepper according to the stepper type
130//
131
132void F01FieldSetup::SetStepper()
133{
134  if(fStepper) delete fStepper;
135
136  switch ( fStepperType ) 
137  {
138    case 0: 
139      fStepper = new G4ExplicitEuler( fEquation ); 
140      G4cout<<"G4ExplicitEuler is calledS"<<G4endl;     
141      break;
142    case 1: 
143      fStepper = new G4ImplicitEuler( fEquation );     
144      G4cout<<"G4ImplicitEuler is called"<<G4endl;     
145      break;
146    case 2: 
147      fStepper = new G4SimpleRunge( fEquation );       
148      G4cout<<"G4SimpleRunge is called"<<G4endl;     
149      break;
150    case 3: 
151      fStepper = new G4SimpleHeum( fEquation );         
152      G4cout<<"G4SimpleHeum is called"<<G4endl;     
153      break;
154    case 4: 
155      fStepper = new G4ClassicalRK4( fEquation );       
156      G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;     
157      break;
158    case 5: 
159      fStepper = new G4HelixExplicitEuler( fEquation ); 
160      G4cout<<"G4HelixExplicitEuler is called"<<G4endl;     
161      break;
162    case 6: 
163      fStepper = new G4HelixImplicitEuler( fEquation ); 
164      G4cout<<"G4HelixImplicitEuler is called"<<G4endl;     
165      break;
166    case 7: 
167      fStepper = new G4HelixSimpleRunge( fEquation );   
168      G4cout<<"G4HelixSimpleRunge is called"<<G4endl;     
169      break;
170    case 8: 
171      fStepper = new G4CashKarpRKF45( fEquation );     
172      G4cout<<"G4CashKarpRKF45 is called"<<G4endl;     
173      break;
174    case 9: 
175      fStepper = new G4RKG3_Stepper( fEquation );       
176      G4cout<<"G4RKG3_Stepper is called"<<G4endl;     
177      break;
178    default: fStepper = 0;
179  }
180  return; 
181}
182
183/////////////////////////////////////////////////////////////////////////////
184//
185// Set the value of the Global Field to fieldValue along Z
186//
187
188void F01FieldSetup::SetFieldValue(G4double fieldStrength)
189{
190#ifdef G4VERBOSE
191  G4cout << "Setting Field strength to " 
192         << fieldStrength / gauss  << " Gauss."; // << G4endl;
193#endif
194
195  G4ThreeVector fieldSetVec(0.0, 0.0, fieldStrength);
196  this->SetFieldValue( fieldSetVec ); 
197  //    *************
198
199#ifdef G4VERBOSE
200  G4double fieldValue[6],  position[4]; 
201  position[0] = position[1] = position[2] = position[3] = 0.0; 
202  if( fieldStrength != 0.0 ){
203    fMagneticField->GetFieldValue( position, fieldValue);
204    G4ThreeVector fieldVec(fieldValue[0], fieldValue[1], fieldValue[2]); 
205    // G4cout << " fMagneticField is now " << fMagneticField
206    G4cout << " Magnetic field vector is " 
207           << fieldVec / gauss << " G " << G4endl; 
208  }else{
209    if( fMagneticField == 0 )
210      G4cout << " Magnetic field pointer is null." << G4endl;
211    else
212      G4Exception("F01FieldSetup::SetFieldValue(double)",
213                  "IncorrectForZeroField",
214                  FatalException,
215                  "fMagneticField ptr should be set to 0 for no field."); 
216  }
217#endif
218}
219
220///////////////////////////////////////////////////////////////////////////////
221//
222// Set the value of the Global Field
223//
224
225void F01FieldSetup::SetFieldValue(G4ThreeVector fieldVector)
226{
227  if(fMagneticField) delete fMagneticField;
228   
229  if(fieldVector != G4ThreeVector(0.,0.,0.))
230  { 
231    fMagneticField = new  G4UniformMagField(fieldVector);
232    // CreateStepperAndChordFinder();
233  }
234  else 
235  {
236    // If the new field's value is Zero, signal it as below
237    //   so that it is not used for propagation.
238    fMagneticField = 0;
239  }
240
241  //  Set this as the field of the global Field Manager
242  GetGlobalFieldManager()->SetDetectorField(fMagneticField);
243
244  // Now notify equation of new field
245  fEquation->SetFieldObj( fMagneticField ); 
246
247}
248
249////////////////////////////////////////////////////////////////////////////////
250//
251//  Utility method
252
253G4FieldManager*  F01FieldSetup::GetGlobalFieldManager()
254{
255  return G4TransportationManager::GetTransportationManager()
256                                ->GetFieldManager();
257}
Note: See TracBrowser for help on using the repository browser.