|
|
|||
File indexing completed on 2026-09-22 08:51:24
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 // G4InterpolationDriver 0027 // 0028 // Class description: 0029 // 0030 // Driver class which uses Runge-Kutta stepper with interpolation property 0031 // to integrate track with error control 0032 0033 // Author: Dmitry Sorokin (CERN), 26.09.2018 0034 // -------------------------------------------------------------------- 0035 #ifndef G4INTERPOLATION_DRIVER_HH 0036 #define G4INTERPOLATION_DRIVER_HH 0037 0038 #include "G4FieldUtils.hh" 0039 #include "G4RKIntegrationDriver.hh" 0040 #include "globals.hh" 0041 0042 #include <memory> 0043 #include <vector> 0044 0045 /** 0046 * @brief G4InterpolationDriver is a templated driver class which uses 0047 * Runge-Kutta stepper with interpolation property to integrate track with 0048 * error control. 0049 */ 0050 0051 template <class T, G4bool StepperCachesDchord = true> 0052 class G4InterpolationDriver : public G4RKIntegrationDriver<T> 0053 { 0054 public: 0055 0056 /** 0057 * Constructor for G4IntegrationDriver. 0058 * @param[in] hminimum Minimum allowed step. 0059 * @param[in] stepper Pointer to the stepper algorithm. 0060 * @param[in] numberOfComponents The number of integration variables, 0061 * if not matching stepper's number of variables, issue exception. 0062 * @param[in] statisticsVerbosity Verbosity level. 0063 */ 0064 G4InterpolationDriver(G4double hminimum, 0065 T* stepper, 0066 G4int numberOfComponents = 6, 0067 G4int statisticsVerbosity = 0); 0068 0069 /** 0070 * Destructor. Provides statistics if verbosity level is greater than zero. 0071 */ 0072 ~G4InterpolationDriver() override; 0073 0074 /** 0075 * Copy constructor and assignment operator not allowed. 0076 */ 0077 G4InterpolationDriver(const G4InterpolationDriver&) = delete; 0078 const G4InterpolationDriver& operator=(const G4InterpolationDriver&) = delete; 0079 0080 /** 0081 * Computes the step to take, based on chord limits. 0082 * @param[in,out] track The current track in field. 0083 * @param[in] hstep Proposed step length. 0084 * @param[in] eps Requested accuracy, y_err/hstep. 0085 * @param[in] chordDistance Maximum sagitta distance. 0086 * @returns The length of step taken. 0087 */ 0088 G4double AdvanceChordLimited(G4FieldTrack& track, 0089 G4double hstep, 0090 G4double eps, 0091 G4double chordDistance) override; 0092 0093 /** 0094 * Dispatch interface method for initialisation/reset of driver. 0095 */ 0096 void OnStartTracking() override; 0097 0098 /** 0099 * Dispatch interface method for computing step. Does nothing here. 0100 */ 0101 void OnComputeStep(const G4FieldTrack* /*track*/ = nullptr) override; 0102 0103 /** 0104 * The driver does not implement re-integration. Returns false. 0105 */ 0106 G4bool DoesReIntegrate() const override { return false; } 0107 0108 /** 0109 * Advances integration accurately by relative accuracy better than 'eps'. 0110 * On output the track is replaced by the value at the end of interval. 0111 * @param[in,out] track The current track in field. 0112 * @param[in] hstep Proposed step length. 0113 * @param[in] eps Requested accuracy, y_err/hstep. 0114 * @param[in] hinitial Initial minimum integration step. 0115 * @returns true if integration succeeds. 0116 */ 0117 G4bool AccurateAdvance(G4FieldTrack& track, 0118 G4double hstep, 0119 G4double eps, // Requested y_err/hstep 0120 G4double hinitial = 0) override; 0121 0122 /** 0123 * Setter and getter for verbosity. 0124 */ 0125 void SetVerboseLevel(G4int level) override; 0126 G4int GetVerboseLevel() const override; 0127 0128 /** 0129 * Writes out to stream the parameters/state of the driver. 0130 */ 0131 void StreamInfo(std::ostream& os) const override; 0132 0133 protected: 0134 0135 struct InterpStepper 0136 { 0137 std::unique_ptr<T> stepper; 0138 G4double begin; 0139 G4double end; 0140 G4double inverseLength; 0141 }; 0142 0143 using StepperIterator = typename std::vector<InterpStepper>::iterator; 0144 using ConstStepperIterator = typename std::vector<InterpStepper>::const_iterator; 0145 0146 /** 0147 * Takes one Step that is as large as possible while satisfying the 0148 * accuracy criterion. 0149 * @param[in] it Stepper iterator. 0150 * @param[in,out] y The current track state, y. 0151 * @param[in] dydx dydx array. 0152 * @param[in,out] hstep Step to attempt. 0153 * @param[in] eps The relative accuracy. 0154 * @param[in] curveLength Step start, x. 0155 * @param[in,out] track Pointer to the Field track. Not used. 0156 * @returns The step achieved. 0157 */ 0158 virtual G4double OneGoodStep(StepperIterator it, 0159 field_utils::State& y, 0160 field_utils::State& dydx, 0161 G4double& hstep, 0162 G4double eps, 0163 G4double curveLength, 0164 G4FieldTrack* track = nullptr); 0165 0166 /** 0167 * Track interpolation. 0168 * @param[in] curveLength Step start, x. 0169 * @param[in,out] y The current track state, y. 0170 */ 0171 void Interpolate(G4double curveLength, field_utils::State& y) const; 0172 0173 /** 0174 * Wrapper method for interpolation. 0175 */ 0176 void InterpolateImpl(G4double curveLength, 0177 ConstStepperIterator it, 0178 field_utils::State& y) const; 0179 0180 /** 0181 * Methods for calculation of chord step and distance. 0182 */ 0183 G4double DistChord(const field_utils::State& yBegin, 0184 G4double curveLengthBegin, 0185 const field_utils::State& yEnd, 0186 G4double curveLengthEnd) const; 0187 G4double FindNextChord(const field_utils::State& yBegin, 0188 G4double curveLengthBegin, 0189 field_utils::State& yEnd, 0190 G4double curveLengthEnd, 0191 G4double dChord, 0192 G4double maxChordDistance); 0193 G4double CalcChordStep(G4double stepTrialOld, 0194 G4double dChordStep, 0195 G4double fDeltaChord); 0196 0197 0198 /** 0199 * Internal methods for printing/checking the state. 0200 */ 0201 void PrintState() const; 0202 void CheckState() const; 0203 0204 /** 0205 * Increments number of trials and calls. 0206 */ 0207 void AccumulateStatistics(G4int noTrials); 0208 0209 protected: 0210 0211 std::vector<InterpStepper> fSteppers; 0212 StepperIterator fLastStepper; 0213 G4bool fKeepLastStepper = false; 0214 0215 /** Memory of last good step size for integration. */ 0216 G4double fhnext = DBL_MAX; 0217 0218 /** Minimum Step allowed (in units of length). */ 0219 G4double fMinimumStep; 0220 0221 G4double fChordStepEstimate = DBL_MAX; 0222 const G4double fFractionNextEstimate = 0.98; // Constant 0223 const G4double fSmallestCurveFraction = 0.01; // Constant 0224 0225 G4int fVerboseLevel; // Parameter 0226 0227 field_utils::State fdydx; 0228 G4bool fFirstStep = true; 0229 0230 G4int fMaxTrials = 100; // Constant 0231 G4int fTotalStepsForTrack = 0; 0232 0233 /** Statistics. */ 0234 G4int fTotalNoTrials = 0; 0235 G4int fNoCalls = 0; 0236 G4int fmaxTrials = 0; 0237 0238 using Base = G4RKIntegrationDriver<T>; 0239 }; 0240 0241 #include "G4InterpolationDriver.icc" 0242 0243 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|