Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4QSSDriver.icc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // Authors: Lucio Santi, Rodrigo Castro (Univ. Buenos Aires), 2018-2021
0027 // --------------------------------------------------------------------
0028 
0029 template <class T>
0030 G4QSSDriver<T>::G4QSSDriver(T* pStepper) : G4InterpolationDriver<T, true>(0, pStepper)
0031 {
0032   // TODO: Remove additional stepper instances - should be a separate Driver class
0033   this->fSteppers.resize(1);
0034 }
0035 
0036 template <class T>
0037 void G4QSSDriver<T>::OnStartTracking()
0038 {
0039   Base::OnStartTracking();
0040   if (! initializedOnFirstRun)
0041   {
0042     G4double dqRel = G4QSSMessenger::instance()->Get_dQRel();
0043     G4double dQMin = G4QSSMessenger::instance()->Get_dQMin();
0044     if (dqRel == 0) { dqRel = 0.001; }
0045     if (dQMin == 0) { dQMin = 0.0001; }
0046     this->SetPrecision(dqRel, dQMin);
0047 
0048     initializedOnFirstRun = true;
0049   }
0050 }
0051 
0052 template <class T>
0053 void G4QSSDriver<T>::OnComputeStep(const G4FieldTrack* track)
0054 {
0055   Base::OnComputeStep(track);
0056 }
0057 
0058 template <class T>
0059 void G4QSSDriver<T>::SetPrecision(G4double dq_rel, G4double dq_min)
0060 {
0061   G4cout << "Setting QSS precision parameters: "
0062          << "dQRel = " << dq_rel << " - "
0063          << "dQMin = " << dq_min << G4endl;
0064 
0065   for (const auto& item : this->fSteppers)
0066   {
0067     item.stepper->SetPrecision(dq_rel, dq_min);
0068   }
0069 }
0070 
0071 template <class T>
0072 G4double G4QSSDriver<T>::AdvanceChordLimited(
0073   G4FieldTrack& track, G4double hstep, G4double epsStep, G4double chordDistance)
0074 {
0075   // For now, just extract functionality that we don't use from G4InterpolationDriver
0076   // We should probably end up making  a custom G4QSSDriver separated from it
0077   ++this->fTotalStepsForTrack;
0078   this->fLastStepper = this->fSteppers.begin();
0079 
0080   const G4double preCurveLength = track.GetCurveLength();
0081   G4double postCurveLength = preCurveLength;
0082   auto it = this->fSteppers.begin();
0083 
0084   it->stepper->reset(const_cast<const G4FieldTrack*>(&track));
0085 
0086   field_utils::State yBegin, y;
0087   track.DumpToArray(yBegin);
0088   track.DumpToArray(y);
0089 
0090   G4double hdid = OneGoodStep(it, y, this->fdydx, hstep, epsStep, preCurveLength, &track);
0091   postCurveLength += hdid;
0092 
0093   G4double dChordStep = this->DistChord(yBegin, preCurveLength, y, postCurveLength);
0094 
0095   // update chord step estimate
0096   hdid = this->FindNextChord(
0097     yBegin, preCurveLength, y, postCurveLength, dChordStep, chordDistance);
0098 
0099   track.LoadFromArray(y, this->fSteppers[0].stepper->GetNumberOfVariables());
0100   track.SetCurveLength(preCurveLength + hdid);
0101 
0102   return hdid;
0103 }
0104 
0105 template <class T>
0106 G4double G4QSSDriver<T>::OneGoodStep(typename G4InterpolationDriver<T, true>::StepperIterator it,
0107   field_utils::State& y, field_utils::State& dydx, G4double& hstep, G4double /*epsStep*/,
0108   G4double curveLength, G4FieldTrack* /*track*/)
0109 {
0110   G4double yerr[G4FieldTrack::ncompSVEC], ytemp[G4FieldTrack::ncompSVEC];
0111   it->stepper->Stepper(y, dydx, hstep, ytemp, yerr);
0112   G4double h = it->stepper->GetLastStepLength();
0113 
0114   // set interpolation interval
0115   it->begin = curveLength;
0116   it->end = curveLength + h;
0117   it->inverseLength = 1. / h;
0118 
0119   field_utils::copy(y, ytemp);
0120 
0121   return h;
0122 }