source: trunk/source/geometry/magneticfield/test/field03/src/F03ElectroMagneticField.cc @ 1202

Last change on this file since 1202 was 1199, checked in by garnier, 15 years ago

nvx fichiers dans CVS

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