source: trunk/source/geometry/magneticfield/test/field02/src/F02ElectroMagneticField.cc @ 1347

Last change on this file since 1347 was 1347, checked in by garnier, 13 years ago

geant4 tag 9.4

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