| [807] | 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: F02ElectricFieldSetup.cc,v 1.2.2.1 2008/05/05 09:23:52 gcosmo Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-01-patch-02 $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // User Field class implementation.
|
|---|
| 32 | //
|
|---|
| 33 |
|
|---|
| 34 | #include "F02ElectricFieldSetup.hh"
|
|---|
| 35 | #include "F02FieldMessenger.hh"
|
|---|
| 36 |
|
|---|
| 37 | #include "G4UniformElectricField.hh"
|
|---|
| 38 | #include "G4UniformMagField.hh"
|
|---|
| 39 | #include "G4MagneticField.hh"
|
|---|
| 40 | #include "G4FieldManager.hh"
|
|---|
| 41 | #include "G4TransportationManager.hh"
|
|---|
| 42 | #include "G4EquationOfMotion.hh"
|
|---|
| 43 | #include "G4EqMagElectricField.hh"
|
|---|
| 44 | #include "G4Mag_UsualEqRhs.hh"
|
|---|
| 45 | #include "G4MagIntegratorStepper.hh"
|
|---|
| 46 | #include "G4MagIntegratorDriver.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 |
|
|---|
| 64 | F02ElectricFieldSetup::F02ElectricFieldSetup()
|
|---|
| 65 | : fChordFinder(0), fStepper(0), fIntgrDriver(0)
|
|---|
| 66 | {
|
|---|
| 67 | fEMfield = new G4UniformElectricField(
|
|---|
| 68 | G4ThreeVector(0.0,100000.0*kilovolt/cm,0.0));
|
|---|
| 69 | fFieldMessenger = new F02FieldMessenger(this) ;
|
|---|
| 70 | fEquation = new G4EqMagElectricField(fEMfield);
|
|---|
| 71 | fMinStep = 0.010*mm ; // minimal step of 10 microns
|
|---|
| 72 | fStepperType = 4 ; // ClassicalRK4 -- the default stepper
|
|---|
| 73 |
|
|---|
| 74 | fFieldManager = GetGlobalFieldManager();
|
|---|
| 75 | UpdateField();
|
|---|
| 76 |
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | /////////////////////////////////////////////////////////////////////////////////
|
|---|
| 80 |
|
|---|
| 81 | F02ElectricFieldSetup::F02ElectricFieldSetup(G4ThreeVector pFV)
|
|---|
| 82 | : fChordFinder(0),
|
|---|
| 83 | fStepper(0),
|
|---|
| 84 | fIntgrDriver(0)
|
|---|
| 85 | {
|
|---|
| 86 | fEMfield = new G4UniformElectricField(pFV);
|
|---|
| 87 | // GetGlobalFieldManager()->CreateChordFinder(this);
|
|---|
| 88 |
|
|---|
| 89 | fFieldMessenger = new F02FieldMessenger(this) ;
|
|---|
| 90 | fEquation = new G4EqMagElectricField(fEMfield);
|
|---|
| 91 | fMinStep = 0.010*mm ; // minimal step of 10 microns
|
|---|
| 92 | fStepperType = 4 ; // ClassicalRK4 -- the default stepper
|
|---|
| 93 |
|
|---|
| 94 | fFieldManager = GetGlobalFieldManager();
|
|---|
| 95 | UpdateField();
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 99 |
|
|---|
| 100 | F02ElectricFieldSetup::~F02ElectricFieldSetup()
|
|---|
| 101 | {
|
|---|
| 102 | if(fChordFinder) delete fChordFinder;
|
|---|
| 103 | if(fStepper) delete fStepper;
|
|---|
| 104 | if(fEquation) delete fEquation;
|
|---|
| 105 | if(fEMfield) delete fEMfield;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 109 | //
|
|---|
| 110 | // Register this field to 'global' Field Manager and
|
|---|
| 111 | // Create Stepper and Chord Finder with predefined type, minstep (resp.)
|
|---|
| 112 | //
|
|---|
| 113 |
|
|---|
| 114 | void F02ElectricFieldSetup::UpdateField()
|
|---|
| 115 | {
|
|---|
| 116 | SetStepper();
|
|---|
| 117 |
|
|---|
| 118 | G4cout<<"The minimal step is equal to "<<fMinStep/mm<<" mm"<<G4endl ;
|
|---|
| 119 |
|
|---|
| 120 | fFieldManager->SetDetectorField(fEMfield );
|
|---|
| 121 |
|
|---|
| 122 | if(fChordFinder) delete fChordFinder;
|
|---|
| 123 | // fChordFinder = new G4ChordFinder( fEMfield, fMinStep, fStepper);
|
|---|
| 124 |
|
|---|
| 125 | fIntgrDriver = new G4MagInt_Driver(fMinStep,
|
|---|
| 126 | fStepper,
|
|---|
| 127 | fStepper->GetNumberOfVariables() );
|
|---|
| 128 |
|
|---|
| 129 | fChordFinder = new G4ChordFinder(fIntgrDriver);
|
|---|
| 130 |
|
|---|
| 131 | fFieldManager->SetChordFinder( fChordFinder );
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 135 | //
|
|---|
| 136 | // Set stepper according to the stepper type
|
|---|
| 137 | //
|
|---|
| 138 |
|
|---|
| 139 | void F02ElectricFieldSetup::SetStepper()
|
|---|
| 140 | {
|
|---|
| 141 | G4int nvar = 8;
|
|---|
| 142 |
|
|---|
| 143 | if(fStepper) delete fStepper;
|
|---|
| 144 |
|
|---|
| 145 | switch ( fStepperType )
|
|---|
| 146 | {
|
|---|
| 147 | case 0:
|
|---|
| 148 | fStepper = new G4ExplicitEuler( fEquation, nvar );
|
|---|
| 149 | G4cout<<"G4ExplicitEuler is calledS"<<G4endl;
|
|---|
| 150 | break;
|
|---|
| 151 | case 1:
|
|---|
| 152 | fStepper = new G4ImplicitEuler( fEquation, nvar );
|
|---|
| 153 | G4cout<<"G4ImplicitEuler is called"<<G4endl;
|
|---|
| 154 | break;
|
|---|
| 155 | case 2:
|
|---|
| 156 | fStepper = new G4SimpleRunge( fEquation, nvar );
|
|---|
| 157 | G4cout<<"G4SimpleRunge is called"<<G4endl;
|
|---|
| 158 | break;
|
|---|
| 159 | case 3:
|
|---|
| 160 | fStepper = new G4SimpleHeum( fEquation, nvar );
|
|---|
| 161 | G4cout<<"G4SimpleHeum is called"<<G4endl;
|
|---|
| 162 | break;
|
|---|
| 163 | case 4:
|
|---|
| 164 | fStepper = new G4ClassicalRK4( fEquation, nvar );
|
|---|
| 165 | G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
|
|---|
| 166 | break;
|
|---|
| 167 | case 5:
|
|---|
| 168 | fStepper = new G4CashKarpRKF45( fEquation, nvar );
|
|---|
| 169 | G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
|
|---|
| 170 | break;
|
|---|
| 171 | case 6:
|
|---|
| 172 | fStepper = 0; // new G4RKG3_Stepper( fEquation, nvar );
|
|---|
| 173 | G4cout<<"G4RKG3_Stepper is not currently working for Electric Field"<<G4endl;
|
|---|
| 174 | break;
|
|---|
| 175 | case 7:
|
|---|
| 176 | fStepper = 0; // new G4HelixExplicitEuler( fEquation );
|
|---|
| 177 | G4cout<<"G4HelixExplicitEuler is not valid for Electric Field"<<G4endl;
|
|---|
| 178 | break;
|
|---|
| 179 | case 8:
|
|---|
| 180 | fStepper = 0; // new G4HelixImplicitEuler( fEquation );
|
|---|
| 181 | G4cout<<"G4HelixImplicitEuler is not valid for Electric Field"<<G4endl;
|
|---|
| 182 | break;
|
|---|
| 183 | case 9:
|
|---|
| 184 | fStepper = 0; // new G4HelixSimpleRunge( fEquation );
|
|---|
| 185 | G4cout<<"G4HelixSimpleRunge is not valid for Electric Field"<<G4endl;
|
|---|
| 186 | break;
|
|---|
| 187 | default: fStepper = 0;
|
|---|
| 188 | }
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 192 | //
|
|---|
| 193 | // Set the value of the Global Field to fieldValue along Z
|
|---|
| 194 | //
|
|---|
| 195 |
|
|---|
| 196 | void F02ElectricFieldSetup::SetFieldValue(G4double fieldValue)
|
|---|
| 197 | {
|
|---|
| 198 | G4ThreeVector fieldVector( 0.0, 0.0, fieldValue*volt/mm );
|
|---|
| 199 |
|
|---|
| 200 | SetFieldValue( fieldVector );
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | ///////////////////////////////////////////////////////////////////////////////
|
|---|
| 204 | //
|
|---|
| 205 | // Set the value of the Global Field value to fieldVector
|
|---|
| 206 | //
|
|---|
| 207 |
|
|---|
| 208 | void F02ElectricFieldSetup::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 | fEquation->SetFieldObj(fEMfield); // must now point to the new field
|
|---|
| 219 |
|
|---|
| 220 | // UpdateField();
|
|---|
| 221 |
|
|---|
| 222 | fieldMgr->SetDetectorField(fEMfield);
|
|---|
| 223 | }
|
|---|
| 224 | else
|
|---|
| 225 | {
|
|---|
| 226 | // If the new field's value is Zero, then it is best to
|
|---|
| 227 | // insure that it is not used for propagation.
|
|---|
| 228 | if(fEMfield) delete fEMfield;
|
|---|
| 229 | fEMfield = 0;
|
|---|
| 230 | fEquation->SetFieldObj(fEMfield); // As a double check ...
|
|---|
| 231 |
|
|---|
| 232 | G4MagneticField* fEMfield = 0;
|
|---|
| 233 | fieldMgr->SetDetectorField(fEMfield);
|
|---|
| 234 | }
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 238 | //
|
|---|
| 239 | // Utility method
|
|---|
| 240 |
|
|---|
| 241 | G4FieldManager* F02ElectricFieldSetup::GetGlobalFieldManager()
|
|---|
| 242 | {
|
|---|
| 243 | return G4TransportationManager::GetTransportationManager()
|
|---|
| 244 | ->GetFieldManager();
|
|---|
| 245 | }
|
|---|