// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // /// \file field/field02/src/F02ElectricFieldSetup.cc /// \brief Implementation of the F02ElectricFieldSetup class // // // // User Field class implementation. // // //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... #include "F02ElectricFieldSetup.hh" #include "F02FieldMessenger.hh" #include "G4UniformElectricField.hh" #include "G4UniformMagField.hh" #include "G4MagneticField.hh" #include "G4FieldManager.hh" #include "G4TransportationManager.hh" #include "G4EquationOfMotion.hh" #include "G4EqMagElectricField.hh" #include "G4Mag_UsualEqRhs.hh" #include "G4MagIntegratorStepper.hh" #include "G4MagIntegratorDriver.hh" #include "G4ChordFinder.hh" #include "G4ExplicitEuler.hh" #include "G4ImplicitEuler.hh" #include "G4SimpleRunge.hh" #include "G4SimpleHeum.hh" #include "G4ClassicalRK4.hh" #include "G4HelixExplicitEuler.hh" #include "G4HelixImplicitEuler.hh" #include "G4HelixSimpleRunge.hh" #include "G4CashKarpRKF45.hh" #include "G4RKG3_Stepper.hh" #include "G4PhysicalConstants.hh" #include "G4SystemOfUnits.hh" //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... // Constructors: F02ElectricFieldSetup::F02ElectricFieldSetup() { G4float Total_Field = 15.0; G4float Angle_Degs = 34.75; //13.69; G4float Angle_Rads = Angle_Degs*(3.14158/180); //convert degs to degrees /*fEMfield = new G4UniformElectricField(G4ThreeVector(0.0,-(Total_Field*sin(Angle_Rads))*kilovolt/cm,-(Total_Field*cos(Angle_Rads))*kilovolt/cm));*/ //Field grid in A9.TABLE. File must be in accessible from run urn directory. fEMfield = new F02TabulatedField3D("PurgMag3D.TABLE", 4.4*mm); fEquation = new G4EqMagElectricField(fEMfield); fFieldManager = GetGlobalFieldManager(); UpdateIntegrator(); fFieldMessenger = new F02FieldMessenger(this); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... F02ElectricFieldSetup::F02ElectricFieldSetup(G4ThreeVector fieldVector) { fEMfield = new G4UniformElectricField(fieldVector); fEquation = new G4EqMagElectricField(fEMfield); fFieldManager = GetGlobalFieldManager(); UpdateIntegrator(); fFieldMessenger = new F02FieldMessenger(this); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... F02ElectricFieldSetup::~F02ElectricFieldSetup() { // G4cout << " F02ElectricFieldSetup - dtor called. " << G4endl; delete fFieldMessenger; fFieldMessenger= nullptr; // Delete the messenger first, to avoid messages to deleted classes! delete fChordFinder; fChordFinder= nullptr; delete fStepper; fStepper = nullptr; delete fEquation; fEquation = nullptr; delete fEMfield; fEMfield = nullptr; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void F02ElectricFieldSetup::UpdateIntegrator() { // Register this field to 'global' Field Manager and // Create Stepper and Chord Finder with predefined type, minstep (resp.) // It must be possible to call 'again' after an alternative stepper // has been chosen, or other changes have been made assert(fEquation!=nullptr); G4cout<< " F02ElectricFieldSetup: The minimal step is equal to " << fMinStep/mm << " mm" << G4endl; if (fChordFinder) { delete fChordFinder; fChordFinder= nullptr; // The chord-finder's destructor deletes the driver fIntgrDriver= nullptr; } // Currently driver does not 'own' stepper ( 17.05.2017 J.A. ) // -- so this stepper is still a valid object after this if( fStepper ) { delete fStepper; fStepper = nullptr; } // Create the new objects, in turn for all relevant classes // -- Careful to call this after all old objects are destroyed, and // pointers nullified. CreateStepper(); // Note that this method deleted the existing Stepper! // G4cout << "F02ElectricFieldSetup::UpdateIntegrator> " // << "New value of stepper ptr= " << fStepper << G4endl; assert(fStepper != nullptr); if( fStepper ) { fIntgrDriver = new G4MagInt_Driver(fMinStep, fStepper, fStepper->GetNumberOfVariables()); if( fIntgrDriver ){ fChordFinder = new G4ChordFinder(fIntgrDriver); } } fFieldManager->SetChordFinder(fChordFinder); fFieldManager->SetDetectorField(fEMfield); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void F02ElectricFieldSetup::CreateStepper() { // Deletes the existing stepper // and creates a new stepper object of the chosen stepper type const G4int nvar = 8; auto oldStepper= fStepper; switch ( fStepperType ) { case 0: fStepper = new G4ExplicitEuler( fEquation, nvar ); G4cout<<"G4ExplicitEuler is calledS"<RenewStepperAndAdjust( fStepper ); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void F02ElectricFieldSetup::SetFieldZValue(G4double fieldValue) { // Set the value of the Global Field to fieldValue along Z G4ThreeVector fieldVector( 0.0, 0.0, fieldValue ); SetFieldValue( fieldVector ); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void F02ElectricFieldSetup::SetFieldValue(G4ThreeVector fieldVector) { delete fEMfield; // Set the value of the Global Field value to fieldVector // Find the Field Manager for the global field G4FieldManager* fieldMgr= GetGlobalFieldManager(); if (fieldVector != G4ThreeVector(0.,0.,0.)) { fEMfield = new G4UniformElectricField(fieldVector); } else { // If the new field's value is Zero, then it is best to // insure that it is not used for propagation. fEMfield = nullptr; } fieldMgr->SetDetectorField(fEMfield); fEquation->SetFieldObj(fEMfield); // must now point to the new field } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... G4FieldManager* F02ElectricFieldSetup::GetGlobalFieldManager() { // Utility method return G4TransportationManager::GetTransportationManager() ->GetFieldManager(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......