Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // class G4BrentLocator implementation << 26 // $Id: G4BrentLocator.cc 66872 2013-01-15 01:25:57Z japost $ >> 27 // >> 28 // Class G4BrentLocator implementation 27 // 29 // 28 // 27.10.08 - Tatiana Nikitina. 30 // 27.10.08 - Tatiana Nikitina. 29 // 04.10.11 - John Apostolakis, revised conver 31 // 04.10.11 - John Apostolakis, revised convergence to use Surface Normal 30 // ------------------------------------------- 32 // --------------------------------------------------------------------------- 31 33 32 #include <iomanip> << 33 << 34 #include "G4BrentLocator.hh" 34 #include "G4BrentLocator.hh" 35 #include "G4ios.hh" 35 #include "G4ios.hh" >> 36 #include <iomanip> 36 37 37 G4BrentLocator::G4BrentLocator(G4Navigator *th 38 G4BrentLocator::G4BrentLocator(G4Navigator *theNavigator) 38 : G4VIntersectionLocator(theNavigator) << 39 : G4VIntersectionLocator(theNavigator) 39 { 40 { 40 // In case of too slow progress in finding I 41 // In case of too slow progress in finding Intersection Point 41 // intermediates Points on the Track must be 42 // intermediates Points on the Track must be stored. 42 // Initialise the array of Pointers [max_dep 43 // Initialise the array of Pointers [max_depth+1] to do this 43 44 44 G4ThreeVector zeroV(0.0,0.0,0.0); 45 G4ThreeVector zeroV(0.0,0.0,0.0); 45 for (auto & idepth : ptrInterMedFT) << 46 for (G4int idepth=0; idepth<max_depth+1; idepth++ ) 46 { 47 { 47 idepth = new G4FieldTrack( zeroV, zeroV, 0 << 48 ptrInterMedFT[ idepth ] = new G4FieldTrack( zeroV, zeroV, 0., 0., 0., 0.); 48 } 49 } >> 50 >> 51 // Counters for Locator >> 52 >> 53 // Counter for Maximum Number Of Trial before Intersection Found >> 54 // >> 55 maxNumberOfStepsForIntersection=0; >> 56 >> 57 // Counter for Number Of Calls to ReIntegrationEndPoint Method >> 58 // >> 59 maxNumberOfCallsToReIntegration=0; >> 60 maxNumberOfCallsToReIntegration_depth=0; 49 } 61 } 50 62 51 G4BrentLocator::~G4BrentLocator() 63 G4BrentLocator::~G4BrentLocator() 52 { 64 { 53 for (auto & idepth : ptrInterMedFT) << 65 for ( G4int idepth=0; idepth<max_depth+1; idepth++) 54 { 66 { 55 delete idepth; << 67 delete ptrInterMedFT[idepth]; 56 } 68 } >> 69 #ifdef G4DEBUG_FIELD >> 70 if(fVerboseLevel>0) >> 71 { >> 72 G4cout << "G4BrentLocator::Location with Max Number of Steps=" >> 73 << maxNumberOfStepsForIntersection<<G4endl; >> 74 G4cout << "G4BrentLocator::ReIntegrateEndPoint was called " >> 75 << maxNumberOfCallsToReIntegration >> 76 << " times and for depth algorithm " >> 77 << maxNumberOfCallsToReIntegration_depth << " times." << G4endl; >> 78 } >> 79 #endif 57 } 80 } 58 81 59 // ------------------------------------------- 82 // -------------------------------------------------------------------------- 60 // G4bool G4PropagatorInField::LocateIntersect 83 // G4bool G4PropagatorInField::LocateIntersectionPoint( 61 // const G4FieldTrack& CurveStart 84 // const G4FieldTrack& CurveStartPointVelocity, // A 62 // const G4FieldTrack& CurveEndPo 85 // const G4FieldTrack& CurveEndPointVelocity, // B 63 // const G4ThreeVector& TrialPoint 86 // const G4ThreeVector& TrialPoint, // E 64 // G4FieldTrack& Intersecte 87 // G4FieldTrack& IntersectedOrRecalculated // Output 65 // G4bool& recalculat 88 // G4bool& recalculated) // Out 66 // ------------------------------------------- 89 // -------------------------------------------------------------------------- 67 // 90 // 68 // Function that returns the intersection of t 91 // Function that returns the intersection of the true path with the surface 69 // of the current volume (either the external 92 // of the current volume (either the external one or the inner one with one 70 // of the daughters: 93 // of the daughters: 71 // 94 // 72 // A = Initial point 95 // A = Initial point 73 // B = another point 96 // B = another point 74 // 97 // 75 // Both A and B are assumed to be on the true 98 // Both A and B are assumed to be on the true path: 76 // 99 // 77 // E is the first point of intersection of 100 // E is the first point of intersection of the chord AB with 78 // a volume other than A (on the surface 101 // a volume other than A (on the surface of A or of a daughter) 79 // 102 // 80 // Convention of Use : 103 // Convention of Use : 81 // i) If it returns "true", then Intersect 104 // i) If it returns "true", then IntersectionPointVelocity is set 82 // to the approximate intersection poin 105 // to the approximate intersection point. 83 // ii) If it returns "false", no intersecti 106 // ii) If it returns "false", no intersection was found. 84 // The validity of IntersectedOrRecalcu 107 // The validity of IntersectedOrRecalculated depends on 'recalculated' 85 // a) if latter is false, then Intersec 108 // a) if latter is false, then IntersectedOrRecalculated is invalid. 86 // b) if latter is true, then Intersec 109 // b) if latter is true, then IntersectedOrRecalculated is 87 // the new endpoint, due to a re-int 110 // the new endpoint, due to a re-integration. 88 // ------------------------------------------- 111 // -------------------------------------------------------------------------- 89 // NOTE: implementation taken from G4Propagato 112 // NOTE: implementation taken from G4PropagatorInField 90 // New second order locator is added 113 // New second order locator is added 91 // 114 // 92 G4bool G4BrentLocator::EstimateIntersectionPoi 115 G4bool G4BrentLocator::EstimateIntersectionPoint( 93 const G4FieldTrack& CurveStart 116 const G4FieldTrack& CurveStartPointVelocity, // A 94 const G4FieldTrack& CurveEndPo 117 const G4FieldTrack& CurveEndPointVelocity, // B 95 const G4ThreeVector& TrialPoint 118 const G4ThreeVector& TrialPoint, // E 96 G4FieldTrack& Intersecte 119 G4FieldTrack& IntersectedOrRecalculatedFT, // Output 97 G4bool& recalculat 120 G4bool& recalculatedEndPoint, // Out 98 G4double& fPreviousS 121 G4double& fPreviousSafety, // In/Out 99 G4ThreeVector& fPreviousS 122 G4ThreeVector& fPreviousSftOrigin) // In/Out 100 123 101 { 124 { 102 // Find Intersection Point ( A, B, E ) of t 125 // Find Intersection Point ( A, B, E ) of true path AB - start at E. 103 126 104 G4bool found_approximate_intersection = fals 127 G4bool found_approximate_intersection = false; 105 G4bool there_is_no_intersection = fals 128 G4bool there_is_no_intersection = false; 106 129 107 G4FieldTrack CurrentA_PointVelocity = Curve 130 G4FieldTrack CurrentA_PointVelocity = CurveStartPointVelocity; 108 G4FieldTrack CurrentB_PointVelocity = Curve 131 G4FieldTrack CurrentB_PointVelocity = CurveEndPointVelocity; 109 G4ThreeVector CurrentE_Point = TrialPoint; 132 G4ThreeVector CurrentE_Point = TrialPoint; 110 G4bool validNormalAtE = false; 133 G4bool validNormalAtE = false; 111 G4ThreeVector NormalAtEntry; 134 G4ThreeVector NormalAtEntry; 112 135 113 G4FieldTrack ApproxIntersecPointV(CurveEndP 136 G4FieldTrack ApproxIntersecPointV(CurveEndPointVelocity); // FT-Def-Construct 114 G4double NewSafety = 0.0; 137 G4double NewSafety = 0.0; 115 G4bool last_AF_intersection = false; 138 G4bool last_AF_intersection = false; 116 139 117 // G4bool final_section= true; // Shows whe 140 // G4bool final_section= true; // Shows whether current section is last 118 // (i.e. B=f 141 // (i.e. B=full end) 119 G4bool first_section = true; 142 G4bool first_section = true; 120 recalculatedEndPoint = false; 143 recalculatedEndPoint = false; 121 144 122 G4bool restoredFullEndpoint = false; 145 G4bool restoredFullEndpoint = false; 123 146 124 G4long oldprc; // cout, cerr precision << 147 G4int oldprc; // cout, cerr precision 125 G4int substep_no = 0; 148 G4int substep_no = 0; 126 149 127 // Limits for substep number 150 // Limits for substep number 128 // 151 // 129 const G4int max_substeps= 10000; // Test 152 const G4int max_substeps= 10000; // Test 120 (old value 100 ) 130 const G4int warn_substeps= 1000; // 153 const G4int warn_substeps= 1000; // 100 131 154 132 // Statistics for substeps 155 // Statistics for substeps 133 // 156 // 134 static G4ThreadLocal G4int max_no_seen= -1; 157 static G4ThreadLocal G4int max_no_seen= -1; 135 158 136 // Counter for restarting Bintermed 159 // Counter for restarting Bintermed 137 // 160 // 138 G4int restartB = 0; 161 G4int restartB = 0; 139 162 140 //------------------------------------------ 163 //-------------------------------------------------------------------------- 141 // Algorithm for the case if progress in fo 164 // Algorithm for the case if progress in founding intersection is too slow. 142 // Process is defined too slow if after N=p 165 // Process is defined too slow if after N=param_substeps advances on the 143 // path, it will be only 'fraction_done' of 166 // path, it will be only 'fraction_done' of the total length. 144 // In this case the remaining length is div 167 // In this case the remaining length is divided in two half and 145 // the loop is restarted for each half. 168 // the loop is restarted for each half. 146 // If progress is still too slow, the divis 169 // If progress is still too slow, the division in two halfs continue 147 // until 'max_depth'. 170 // until 'max_depth'. 148 //------------------------------------------ 171 //-------------------------------------------------------------------------- 149 172 150 const G4int param_substeps = 50; // Test val << 173 const G4int param_substeps=50; // Test value for the maximum number 151 // of subst << 174 // of substeps 152 const G4double fraction_done = 0.3; << 175 const G4double fraction_done=0.3; 153 176 154 G4bool Second_half = false; // First hal 177 G4bool Second_half = false; // First half or second half of divided step 155 178 156 NormalAtEntry = GetSurfaceNormal(CurrentE_Po 179 NormalAtEntry = GetSurfaceNormal(CurrentE_Point, validNormalAtE); 157 180 158 // We need to know this for the 'final_secti 181 // We need to know this for the 'final_section': 159 // real 'final_section' or first half 'final 182 // real 'final_section' or first half 'final_section' 160 // In algorithm it is considered that the 'S 183 // In algorithm it is considered that the 'Second_half' is true 161 // and it becomes false only if we are in th 184 // and it becomes false only if we are in the first-half of level 162 // depthness or if we are in the first secti 185 // depthness or if we are in the first section 163 186 164 G4int depth = 0; // Depth counts how many su << 187 G4int depth=0; // Depth counts how many subdivisions of initial step made 165 188 166 #ifdef G4DEBUG_FIELD 189 #ifdef G4DEBUG_FIELD 167 const G4double tolerance = 1.0e-8; << 190 static G4double tolerance= 1.0e-8; 168 G4ThreeVector StartPosition = CurveStartPoi << 191 G4ThreeVector StartPosition= CurveStartPointVelocity.GetPosition(); 169 if( (TrialPoint - StartPosition).mag() < tol << 192 if( (TrialPoint - StartPosition).mag() < tolerance * mm ) 170 { 193 { 171 G4Exception("G4BrentLocator::EstimateInte 194 G4Exception("G4BrentLocator::EstimateIntersectionPoint()", 172 "GeomNav1002", JustWarning, 195 "GeomNav1002", JustWarning, 173 "Intersection point F is exac 196 "Intersection point F is exactly at start point A." ); 174 } 197 } 175 #endif 198 #endif 176 199 177 // Intermediates Points on the Track = Subdi 200 // Intermediates Points on the Track = Subdivided Points must be stored. 178 // Give the initial values to 'InterMedFt' 201 // Give the initial values to 'InterMedFt' 179 // Important is 'ptrInterMedFT[0]', it saves 202 // Important is 'ptrInterMedFT[0]', it saves the 'EndCurvePoint' 180 // 203 // 181 *ptrInterMedFT[0] = CurveEndPointVelocity; 204 *ptrInterMedFT[0] = CurveEndPointVelocity; 182 for (auto idepth=1; idepth<max_depth+1; ++id << 205 for (G4int idepth=1; idepth<max_depth+1; idepth++ ) 183 { 206 { 184 *ptrInterMedFT[idepth] = CurveStartPointVe << 207 *ptrInterMedFT[idepth]=CurveStartPointVelocity; 185 } 208 } 186 209 187 //Final_section boolean store 210 //Final_section boolean store 188 G4bool fin_section_depth[max_depth]; 211 G4bool fin_section_depth[max_depth]; 189 for (bool & idepth : fin_section_depth) << 212 for (G4int idepth=0; idepth<max_depth; idepth++ ) 190 { 213 { 191 idepth = true; << 214 fin_section_depth[idepth]=true; 192 } 215 } 193 216 194 // 'SubStartPoint' is needed to calculate th 217 // 'SubStartPoint' is needed to calculate the length of the divided step 195 // 218 // 196 G4FieldTrack SubStart_PointVelocity = CurveS 219 G4FieldTrack SubStart_PointVelocity = CurveStartPointVelocity; 197 220 198 do // Loop checking, 07.10.2016, J.Apostol << 221 do 199 { 222 { 200 G4int substep_no_p = 0; 223 G4int substep_no_p = 0; 201 G4bool sub_final_section = false; // the s 224 G4bool sub_final_section = false; // the same as final_section, 202 // but f 225 // but for 'sub_section' 203 SubStart_PointVelocity = CurrentA_PointVel 226 SubStart_PointVelocity = CurrentA_PointVelocity; 204 << 227 do // REPEAT param 205 do // Loop checking, 07.10.2016, J.Apost << 228 { 206 { // REPEAT param << 207 G4ThreeVector Point_A = CurrentA_PointVe 229 G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition(); 208 G4ThreeVector Point_B = CurrentB_PointVe 230 G4ThreeVector Point_B = CurrentB_PointVelocity.GetPosition(); 209 231 210 // F = a point on true AB path close to 232 // F = a point on true AB path close to point E 211 // (the closest if possible) 233 // (the closest if possible) 212 // 234 // 213 if(substep_no_p==0) 235 if(substep_no_p==0) 214 { 236 { 215 ApproxIntersecPointV = GetChordFinderF 237 ApproxIntersecPointV = GetChordFinderFor() 216 ->ApproxCurvePo 238 ->ApproxCurvePointV( CurrentA_PointVelocity, 217 239 CurrentB_PointVelocity, 218 240 CurrentE_Point, 219 241 GetEpsilonStepFor()); 220 // The above method is the key & mo 242 // The above method is the key & most intuitive part ... 221 } 243 } 222 #ifdef G4DEBUG_FIELD 244 #ifdef G4DEBUG_FIELD 223 if( ApproxIntersecPointV.GetCurveLength( 245 if( ApproxIntersecPointV.GetCurveLength() > 224 CurrentB_PointVelocity.GetCurveLengt 246 CurrentB_PointVelocity.GetCurveLength() * (1.0 + tolerance) ) 225 { 247 { 226 G4Exception("G4BrentLocator::EstimateI 248 G4Exception("G4BrentLocator::EstimateIntersectionPoint()", 227 "GeomNav0003", FatalExcept 249 "GeomNav0003", FatalException, 228 "Intermediate F point is p 250 "Intermediate F point is past end B point" ); 229 } 251 } 230 #endif 252 #endif 231 253 232 G4ThreeVector CurrentF_Point = ApproxInt << 254 G4ThreeVector CurrentF_Point= ApproxIntersecPointV.GetPosition(); 233 255 234 // First check whether EF is small - the 256 // First check whether EF is small - then F is a good approx. point 235 // Calculate the length and direction of 257 // Calculate the length and direction of the chord AF 236 // 258 // 237 G4ThreeVector ChordEF_Vector = CurrentF 259 G4ThreeVector ChordEF_Vector = CurrentF_Point - CurrentE_Point; 238 G4ThreeVector NewMomentumDir = ApproxIn << 260 G4ThreeVector NewMomentumDir= ApproxIntersecPointV.GetMomentumDir(); 239 G4double MomDir_dot_Norm = NewMome << 261 G4double MomDir_dot_Norm= NewMomentumDir.dot( NormalAtEntry ) ; 240 262 241 #ifdef G4DEBUG_FIELD 263 #ifdef G4DEBUG_FIELD 242 G4ThreeVector ChordAB = Point_B - Point 264 G4ThreeVector ChordAB = Point_B - Point_A; 243 265 244 G4VIntersectionLocator::ReportTrialStep( 266 G4VIntersectionLocator::ReportTrialStep( substep_no, ChordAB, 245 ChordEF_Vector, NewMomentumDir, 267 ChordEF_Vector, NewMomentumDir, NormalAtEntry, validNormalAtE ); 246 #endif 268 #endif 247 269 248 G4bool adequate_angle; 270 G4bool adequate_angle; 249 adequate_angle = ( MomDir_dot_Norm >= 0 271 adequate_angle = ( MomDir_dot_Norm >= 0.0 ) // Can use -epsilon instead. 250 || (! validNormalAtE ); 272 || (! validNormalAtE ); // Makes criterion invalid 251 G4double EF_dist2 = ChordEF_Vector.mag2( 273 G4double EF_dist2 = ChordEF_Vector.mag2(); 252 if ( ( EF_dist2 <= sqr(fiDeltaIntersecti 274 if ( ( EF_dist2 <= sqr(fiDeltaIntersection) && ( adequate_angle ) ) 253 || ( EF_dist2 <= kCarTolerance*kCarTol 275 || ( EF_dist2 <= kCarTolerance*kCarTolerance ) ) 254 { 276 { 255 found_approximate_intersection = true; 277 found_approximate_intersection = true; 256 278 257 // Create the "point" return value 279 // Create the "point" return value 258 // 280 // 259 IntersectedOrRecalculatedFT = ApproxIn 281 IntersectedOrRecalculatedFT = ApproxIntersecPointV; 260 IntersectedOrRecalculatedFT.SetPositio 282 IntersectedOrRecalculatedFT.SetPosition( CurrentE_Point ); 261 283 262 if ( GetAdjustementOfFoundIntersection 284 if ( GetAdjustementOfFoundIntersection() ) 263 { 285 { 264 // Try to Get Correction of Intersec 286 // Try to Get Correction of IntersectionPoint using SurfaceNormal() 265 // 287 // 266 G4ThreeVector IP; 288 G4ThreeVector IP; 267 G4ThreeVector MomentumDir=ApproxInte 289 G4ThreeVector MomentumDir=ApproxIntersecPointV.GetMomentumDirection(); 268 G4bool goodCorrection = AdjustmentOf 290 G4bool goodCorrection = AdjustmentOfFoundIntersection( Point_A, 269 CurrentE_P 291 CurrentE_Point, CurrentF_Point, MomentumDir, 270 last_AF_in 292 last_AF_intersection, IP, NewSafety, 271 fPreviousS 293 fPreviousSafety, fPreviousSftOrigin ); 272 if ( goodCorrection ) 294 if ( goodCorrection ) 273 { 295 { 274 IntersectedOrRecalculatedFT = Appr 296 IntersectedOrRecalculatedFT = ApproxIntersecPointV; 275 IntersectedOrRecalculatedFT.SetPos 297 IntersectedOrRecalculatedFT.SetPosition(IP); 276 } 298 } 277 } 299 } 278 300 279 // Note: in order to return a point on 301 // Note: in order to return a point on the boundary, 280 // we must return E. But it is F 302 // we must return E. But it is F on the curve. 281 // So we must "cheat": we are us 303 // So we must "cheat": we are using the position at point E 282 // and the velocity at point F ! 304 // and the velocity at point F !!! 283 // 305 // 284 // This must limit the length we can a 306 // This must limit the length we can allow for displacement! 285 } 307 } 286 else // E is NOT close enough to the cu 308 else // E is NOT close enough to the curve (ie point F) 287 { 309 { 288 // Check whether any volumes are encou 310 // Check whether any volumes are encountered by the chord AF 289 // ----------------------------------- 311 // --------------------------------------------------------- 290 // First relocate to restore any Voxel 312 // First relocate to restore any Voxel etc information 291 // in the Navigator before calling Com 313 // in the Navigator before calling ComputeStep() 292 // 314 // 293 GetNavigatorFor()->LocateGlobalPointWi 315 GetNavigatorFor()->LocateGlobalPointWithinVolume( Point_A ); 294 316 295 G4ThreeVector PointG; // Candidate i 317 G4ThreeVector PointG; // Candidate intersection point 296 G4double stepLengthAF; 318 G4double stepLengthAF; 297 G4bool usedNavigatorAF = false; 319 G4bool usedNavigatorAF = false; 298 G4bool Intersects_AF = IntersectChord( 320 G4bool Intersects_AF = IntersectChord( Point_A, CurrentF_Point, 299 321 NewSafety,fPreviousSafety, 300 322 fPreviousSftOrigin, 301 323 stepLengthAF, 302 324 PointG, 303 325 &usedNavigatorAF); 304 last_AF_intersection = Intersects_AF; 326 last_AF_intersection = Intersects_AF; 305 if( Intersects_AF ) 327 if( Intersects_AF ) 306 { 328 { 307 // G is our new Candidate for the in 329 // G is our new Candidate for the intersection point. 308 // It replaces "E" and we will repe 330 // It replaces "E" and we will repeat the test to see if 309 // it is a good enough approximate p 331 // it is a good enough approximate point for us. 310 // B <- F 332 // B <- F 311 // E <- G 333 // E <- G 312 // 334 // 313 G4FieldTrack EndPoint = ApproxInters 335 G4FieldTrack EndPoint = ApproxIntersecPointV; 314 ApproxIntersecPointV = GetChordFinde 336 ApproxIntersecPointV = GetChordFinderFor()->ApproxCurvePointS( 315 CurrentA_Poin 337 CurrentA_PointVelocity, CurrentB_PointVelocity, 316 EndPoint,Curr 338 EndPoint,CurrentE_Point, CurrentF_Point,PointG, 317 true, GetEpsi 339 true, GetEpsilonStepFor() ); 318 CurrentB_PointVelocity = EndPoint; 340 CurrentB_PointVelocity = EndPoint; 319 CurrentE_Point = PointG; 341 CurrentE_Point = PointG; 320 342 321 // Need to recalculate the Exit Norm 343 // Need to recalculate the Exit Normal at the new PointG 322 // Know that a call was made to Navi 344 // Know that a call was made to Navigator::ComputeStep in 323 // IntersectChord above. 345 // IntersectChord above. 324 // 346 // 325 G4bool validNormalLast; 347 G4bool validNormalLast; 326 NormalAtEntry = GetSurfaceNormal( P 348 NormalAtEntry = GetSurfaceNormal( PointG, validNormalLast ); 327 validNormalAtE = validNormalLast; 349 validNormalAtE = validNormalLast; 328 350 329 // By moving point B, must take care 351 // By moving point B, must take care if current 330 // AF has no intersection to try cur 352 // AF has no intersection to try current FB!! 331 // 353 // 332 fin_section_depth[depth] = false; 354 fin_section_depth[depth] = false; 333 #ifdef G4VERBOSE 355 #ifdef G4VERBOSE 334 if( fVerboseLevel > 3 ) 356 if( fVerboseLevel > 3 ) 335 { 357 { 336 G4cout << "G4PiF::LI> Investigatin 358 G4cout << "G4PiF::LI> Investigating intermediate point" 337 << " at s=" << ApproxInters 359 << " at s=" << ApproxIntersecPointV.GetCurveLength() 338 << " on way to full s=" 360 << " on way to full s=" 339 << CurveEndPointVelocity.Ge 361 << CurveEndPointVelocity.GetCurveLength() << G4endl; 340 } 362 } 341 #endif 363 #endif 342 } 364 } 343 else // not Intersects_AF 365 else // not Intersects_AF 344 { 366 { 345 // In this case: 367 // In this case: 346 // There is NO intersection of AF wi 368 // There is NO intersection of AF with a volume boundary. 347 // We must continue the search in th 369 // We must continue the search in the segment FB! 348 // 370 // 349 GetNavigatorFor()->LocateGlobalPoint 371 GetNavigatorFor()->LocateGlobalPointWithinVolume( CurrentF_Point ); 350 372 351 G4double stepLengthFB; 373 G4double stepLengthFB; 352 G4ThreeVector PointH; 374 G4ThreeVector PointH; 353 G4bool usedNavigatorFB = false; 375 G4bool usedNavigatorFB = false; 354 376 355 // Check whether any volumes are enc 377 // Check whether any volumes are encountered by the chord FB 356 // --------------------------------- 378 // --------------------------------------------------------- 357 379 358 G4bool Intersects_FB = IntersectChor 380 G4bool Intersects_FB = IntersectChord( CurrentF_Point, Point_B, 359 381 NewSafety,fPreviousSafety, 360 382 fPreviousSftOrigin, 361 383 stepLengthFB, 362 384 PointH, 363 385 &usedNavigatorFB); 364 if( Intersects_FB ) 386 if( Intersects_FB ) 365 { 387 { 366 // There is an intersection of FB 388 // There is an intersection of FB with a volume boundary 367 // H <- First Intersection of Chor 389 // H <- First Intersection of Chord FB 368 390 369 // H is our new Candidate for the 391 // H is our new Candidate for the intersection point. 370 // It replaces "E" and we will re 392 // It replaces "E" and we will repeat the test to see if 371 // it is a good enough approximate 393 // it is a good enough approximate point for us. 372 394 373 // Note that F must be in volume v 395 // Note that F must be in volume volA (the same as A) 374 // (otherwise AF would meet a volu 396 // (otherwise AF would meet a volume boundary!) 375 // A <- F 397 // A <- F 376 // E <- H 398 // E <- H 377 // 399 // 378 G4FieldTrack InterMed = ApproxInte << 400 G4FieldTrack InterMed=ApproxIntersecPointV; 379 ApproxIntersecPointV = GetChordFin 401 ApproxIntersecPointV = GetChordFinderFor()->ApproxCurvePointS( 380 CurrentA_PointVeloci 402 CurrentA_PointVelocity,CurrentB_PointVelocity, 381 InterMed,CurrentE_Po 403 InterMed,CurrentE_Point,CurrentF_Point,PointH, 382 false,GetEpsilonStep 404 false,GetEpsilonStepFor()); 383 CurrentA_PointVelocity = InterMed; 405 CurrentA_PointVelocity = InterMed; 384 CurrentE_Point = PointH; 406 CurrentE_Point = PointH; 385 407 386 // Need to recalculate the Exit No 408 // Need to recalculate the Exit Normal at the new PointG 387 // 409 // 388 G4bool validNormalLast; 410 G4bool validNormalLast; 389 NormalAtEntry = GetSurfaceNormal( 411 NormalAtEntry = GetSurfaceNormal( PointH, validNormalLast ); 390 validNormalAtE = validNormalLast; << 412 validNormalAtE= validNormalLast; 391 } 413 } 392 else // not Intersects_FB 414 else // not Intersects_FB 393 { 415 { 394 // There is NO intersection of FB 416 // There is NO intersection of FB with a volume boundary 395 417 396 if( fin_section_depth[depth] ) 418 if( fin_section_depth[depth] ) 397 { 419 { 398 // If B is the original endpoint 420 // If B is the original endpoint, this means that whatever 399 // volume(s) intersected the ori 421 // volume(s) intersected the original chord, none touch the 400 // smaller chords we have used. 422 // smaller chords we have used. 401 // The value of 'IntersectedOrRe 423 // The value of 'IntersectedOrRecalculatedFT' returned is 402 // likely not valid 424 // likely not valid 403 425 404 // Check on real final_section o 426 // Check on real final_section or SubEndSection 405 // 427 // 406 if( ((Second_half)&&(depth==0)) 428 if( ((Second_half)&&(depth==0)) || (first_section) ) 407 { 429 { 408 there_is_no_intersection = tru 430 there_is_no_intersection = true; // real final_section 409 } 431 } 410 else 432 else 411 { 433 { 412 // end of subsection, not real 434 // end of subsection, not real final section 413 // exit from the and go to the 435 // exit from the and go to the depth-1 level 414 436 415 substep_no_p = param_substeps+ 437 substep_no_p = param_substeps+2; // exit from the loop 416 438 417 // but 'Second_half' is still 439 // but 'Second_half' is still true because we need to find 418 // the 'CurrentE_point' for th 440 // the 'CurrentE_point' for the next loop 419 // 441 // 420 Second_half = true; 442 Second_half = true; 421 sub_final_section = true; 443 sub_final_section = true; 422 } 444 } 423 } 445 } 424 else 446 else 425 { 447 { 426 if( depth==0 ) << 448 if(depth==0) 427 { 449 { 428 // We must restore the origina 450 // We must restore the original endpoint 429 // 451 // 430 CurrentA_PointVelocity = Curre 452 CurrentA_PointVelocity = CurrentB_PointVelocity; // Got to B 431 CurrentB_PointVelocity = Curve 453 CurrentB_PointVelocity = CurveEndPointVelocity; 432 SubStart_PointVelocity = Curre 454 SubStart_PointVelocity = CurrentA_PointVelocity; 433 ApproxIntersecPointV = GetChor 455 ApproxIntersecPointV = GetChordFinderFor() 434 ->ApproxCurvePo 456 ->ApproxCurvePointV( CurrentA_PointVelocity, 435 457 CurrentB_PointVelocity, 436 458 CurrentE_Point, 437 459 GetEpsilonStepFor()); 438 460 439 restoredFullEndpoint = true; 461 restoredFullEndpoint = true; 440 ++restartB; // counter << 462 restartB++; // counter 441 } 463 } 442 else 464 else 443 { 465 { 444 // We must restore the depth e 466 // We must restore the depth endpoint 445 // 467 // 446 CurrentA_PointVelocity = Curre 468 CurrentA_PointVelocity = CurrentB_PointVelocity; // Got to B 447 CurrentB_PointVelocity = *ptr 469 CurrentB_PointVelocity = *ptrInterMedFT[depth]; 448 SubStart_PointVelocity = Curre 470 SubStart_PointVelocity = CurrentA_PointVelocity; 449 ApproxIntersecPointV = GetChor 471 ApproxIntersecPointV = GetChordFinderFor() 450 ->ApproxCurvePo 472 ->ApproxCurvePointV( CurrentA_PointVelocity, 451 473 CurrentB_PointVelocity, 452 474 CurrentE_Point, 453 475 GetEpsilonStepFor()); 454 restoredFullEndpoint = true; 476 restoredFullEndpoint = true; 455 ++restartB; // counter << 477 restartB++; // counter 456 } 478 } 457 } 479 } 458 } // Endif (Intersects_FB) 480 } // Endif (Intersects_FB) 459 } // Endif (Intersects_AF) 481 } // Endif (Intersects_AF) 460 482 461 // Ensure that the new endpoints are n 483 // Ensure that the new endpoints are not further apart in space 462 // than on the curve due to different 484 // than on the curve due to different errors in the integration 463 // 485 // 464 G4double linDistSq, curveDist; 486 G4double linDistSq, curveDist; 465 linDistSq = ( CurrentB_PointVelocity.G 487 linDistSq = ( CurrentB_PointVelocity.GetPosition() 466 - CurrentA_PointVelocity.G 488 - CurrentA_PointVelocity.GetPosition() ).mag2(); 467 curveDist = CurrentB_PointVelocity.Get 489 curveDist = CurrentB_PointVelocity.GetCurveLength() 468 - CurrentA_PointVelocity.G 490 - CurrentA_PointVelocity.GetCurveLength(); 469 491 470 // Change this condition for very stri 492 // Change this condition for very strict parameters of propagation 471 // 493 // 472 if( curveDist*curveDist*(1+2* GetEpsil 494 if( curveDist*curveDist*(1+2* GetEpsilonStepFor()) < linDistSq ) 473 { 495 { 474 // Re-integrate to obtain a new B 496 // Re-integrate to obtain a new B 475 // 497 // 476 G4FieldTrack newEndPointFT= 498 G4FieldTrack newEndPointFT= 477 ReEstimateEndpoint( CurrentA 499 ReEstimateEndpoint( CurrentA_PointVelocity, 478 CurrentB 500 CurrentB_PointVelocity, 479 linDistS 501 linDistSq, // to avoid recalculation 480 curveDis 502 curveDist ); 481 G4FieldTrack oldPointVelB = CurrentB 503 G4FieldTrack oldPointVelB = CurrentB_PointVelocity; 482 CurrentB_PointVelocity = newEndPoint 504 CurrentB_PointVelocity = newEndPointFT; 483 505 484 if ( (fin_section_depth[depth]) 506 if ( (fin_section_depth[depth]) // real final section 485 &&( first_section || ((Second_ha 507 &&( first_section || ((Second_half)&&(depth==0)) ) ) 486 { 508 { 487 recalculatedEndPoint = true; 509 recalculatedEndPoint = true; 488 IntersectedOrRecalculatedFT = newE 510 IntersectedOrRecalculatedFT = newEndPointFT; 489 // So that we can return it, if 511 // So that we can return it, if it is the endpoint! 490 } 512 } 491 } 513 } 492 if( curveDist < 0.0 ) 514 if( curveDist < 0.0 ) 493 { 515 { 494 fVerboseLevel = 5; // Print out a ma 516 fVerboseLevel = 5; // Print out a maximum of information 495 printStatus( CurrentA_PointVelocity, 517 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity, 496 -1.0, NewSafety, subst 518 -1.0, NewSafety, substep_no ); 497 std::ostringstream message; 519 std::ostringstream message; 498 message << "Error in advancing propa 520 message << "Error in advancing propagation." << G4endl 499 << " Error in advanci 521 << " Error in advancing propagation." << G4endl 500 << " Point A (start) 522 << " Point A (start) is " << CurrentA_PointVelocity 501 << G4endl 523 << G4endl 502 << " Point B (end) 524 << " Point B (end) is " << CurrentB_PointVelocity 503 << G4endl 525 << G4endl 504 << " Curve distance i 526 << " Curve distance is " << curveDist << G4endl 505 << G4endl 527 << G4endl 506 << "The final curve point is 528 << "The final curve point is not further along" 507 << " than the original!" << 529 << " than the original!" << G4endl; 508 530 509 if( recalculatedEndPoint ) 531 if( recalculatedEndPoint ) 510 { 532 { 511 message << "Recalculation of EndPo 533 message << "Recalculation of EndPoint was called with fEpsStep= " 512 << GetEpsilonStepFor() << 534 << GetEpsilonStepFor() << G4endl; 513 } 535 } 514 oldprc = G4cerr.precision(20); 536 oldprc = G4cerr.precision(20); 515 message << " Point A (Curve start) 537 message << " Point A (Curve start) is " << CurveStartPointVelocity 516 << G4endl 538 << G4endl 517 << " Point B (Curve end) 539 << " Point B (Curve end) is " << CurveEndPointVelocity 518 << G4endl 540 << G4endl 519 << " Point A (Current start) 541 << " Point A (Current start) is " << CurrentA_PointVelocity 520 << G4endl 542 << G4endl 521 << " Point B (Current end) 543 << " Point B (Current end) is " << CurrentB_PointVelocity 522 << G4endl 544 << G4endl 523 << " Point S (Sub start) 545 << " Point S (Sub start) is " << SubStart_PointVelocity 524 << G4endl 546 << G4endl 525 << " Point E (Trial Point) 547 << " Point E (Trial Point) is " << CurrentE_Point 526 << G4endl 548 << G4endl 527 << " Old Point F(Intersectio 549 << " Old Point F(Intersection) is " << CurrentF_Point 528 << G4endl 550 << G4endl 529 << " New Point F(Intersectio 551 << " New Point F(Intersection) is " << ApproxIntersecPointV 530 << G4endl 552 << G4endl 531 << " LocateIntersecti 553 << " LocateIntersection parameters are : Substep no= " 532 << substep_no << G4endl 554 << substep_no << G4endl 533 << " Substep depth no 555 << " Substep depth no= "<< substep_no_p << " Depth= " 534 << depth << G4endl 556 << depth << G4endl 535 << " Restarted no= "< 557 << " Restarted no= "<< restartB << " Epsilon= " 536 << GetEpsilonStepFor() <<" D 558 << GetEpsilonStepFor() <<" DeltaInters= " 537 << GetDeltaIntersectionFor() 559 << GetDeltaIntersectionFor(); 538 G4cerr.precision( oldprc ); 560 G4cerr.precision( oldprc ); 539 561 540 G4Exception("G4BrentLocator::Estimat 562 G4Exception("G4BrentLocator::EstimateIntersectionPoint()", 541 "GeomNav0003", FatalExce 563 "GeomNav0003", FatalException, message); 542 } 564 } 543 565 544 if( restoredFullEndpoint ) << 566 if(restoredFullEndpoint) 545 { 567 { 546 fin_section_depth[depth] = restoredF 568 fin_section_depth[depth] = restoredFullEndpoint; 547 restoredFullEndpoint = false; 569 restoredFullEndpoint = false; 548 } 570 } 549 } // EndIf ( E is close enough to the cu 571 } // EndIf ( E is close enough to the curve, ie point F. ) 550 // tests ChordAF_Vector.mag() <= maxim 572 // tests ChordAF_Vector.mag() <= maximum_lateral_displacement 551 573 552 #ifdef G4DEBUG_LOCATE_INTERSECTION 574 #ifdef G4DEBUG_LOCATE_INTERSECTION 553 G4int trigger_substepno_print= warn_subs << 575 static G4int trigger_substepno_print= warn_substeps - 20 ; 554 576 555 if( substep_no >= trigger_substepno_prin 577 if( substep_no >= trigger_substepno_print ) 556 { 578 { 557 G4cout << "Difficulty in converging in 579 G4cout << "Difficulty in converging in " 558 << "G4BrentLocator::EstimateInt 580 << "G4BrentLocator::EstimateIntersectionPoint()" 559 << G4endl 581 << G4endl 560 << " Substep no = " << subst 582 << " Substep no = " << substep_no << G4endl; 561 if( substep_no == trigger_substepno_pr 583 if( substep_no == trigger_substepno_print ) 562 { 584 { 563 printStatus( CurveStartPointVelocity 585 printStatus( CurveStartPointVelocity, CurveEndPointVelocity, 564 -1.0, NewSafety, 0); 586 -1.0, NewSafety, 0); 565 } 587 } 566 G4cout << " State of point A: "; 588 G4cout << " State of point A: "; 567 printStatus( CurrentA_PointVelocity, C 589 printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity, 568 -1.0, NewSafety, substep_ 590 -1.0, NewSafety, substep_no-1, 0); 569 G4cout << " State of point B: "; 591 G4cout << " State of point B: "; 570 printStatus( CurrentA_PointVelocity, C 592 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity, 571 -1.0, NewSafety, substep_ 593 -1.0, NewSafety, substep_no); 572 } 594 } 573 #endif 595 #endif 574 ++substep_no; << 596 substep_no++; 575 ++substep_no_p; << 597 substep_no_p++; 576 598 577 } while ( ( ! found_approximate_intersect 599 } while ( ( ! found_approximate_intersection ) 578 && ( ! there_is_no_intersection ) 600 && ( ! there_is_no_intersection ) 579 && ( substep_no_p <= param_substep 601 && ( substep_no_p <= param_substeps) ); // UNTIL found or 580 602 // failed param substep 581 first_section = false; 603 first_section = false; 582 604 583 if( (!found_approximate_intersection) && ( 605 if( (!found_approximate_intersection) && (!there_is_no_intersection) ) 584 { 606 { 585 G4double did_len = std::abs( CurrentA_Po 607 G4double did_len = std::abs( CurrentA_PointVelocity.GetCurveLength() 586 - SubStart_PointVelocit 608 - SubStart_PointVelocity.GetCurveLength()); 587 G4double all_len = std::abs( CurrentB_Po 609 G4double all_len = std::abs( CurrentB_PointVelocity.GetCurveLength() 588 - SubStart_PointVelocit 610 - SubStart_PointVelocity.GetCurveLength()); 589 611 590 G4double stepLengthAB; 612 G4double stepLengthAB; 591 G4ThreeVector PointGe; 613 G4ThreeVector PointGe; 592 614 593 // Check if progress is too slow and if 615 // Check if progress is too slow and if it possible to go deeper, 594 // then halve the step if so 616 // then halve the step if so 595 // 617 // 596 if ( ( did_len < fraction_done*all_len ) 618 if ( ( did_len < fraction_done*all_len ) 597 && (depth < max_depth) && (!sub_final_ << 619 && (depth<max_depth) && (!sub_final_section) ) 598 { 620 { 599 Second_half=false; 621 Second_half=false; 600 ++depth; << 622 depth++; 601 623 602 G4double Sub_len = (all_len-did_len)/( 624 G4double Sub_len = (all_len-did_len)/(2.); 603 G4FieldTrack start = CurrentA_PointVel 625 G4FieldTrack start = CurrentA_PointVelocity; 604 auto integrDriver = << 626 G4MagInt_Driver* integrDriver = 605 GetChordFinderFor()-> 627 GetChordFinderFor()->GetIntegrationDriver(); 606 integrDriver->AccurateAdvance(start, S 628 integrDriver->AccurateAdvance(start, Sub_len, GetEpsilonStepFor()); 607 *ptrInterMedFT[depth] = start; 629 *ptrInterMedFT[depth] = start; 608 CurrentB_PointVelocity = *ptrInterMedF 630 CurrentB_PointVelocity = *ptrInterMedFT[depth]; 609 631 610 // Adjust 'SubStartPoint' to calculate 632 // Adjust 'SubStartPoint' to calculate the 'did_length' in next loop 611 // 633 // 612 SubStart_PointVelocity = CurrentA_Poin 634 SubStart_PointVelocity = CurrentA_PointVelocity; 613 635 614 // Find new trial intersection point n 636 // Find new trial intersection point needed at start of the loop 615 // 637 // 616 G4ThreeVector Point_A = CurrentA_Point 638 G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition(); 617 G4ThreeVector SubE_point = CurrentB_Po 639 G4ThreeVector SubE_point = CurrentB_PointVelocity.GetPosition(); 618 640 619 GetNavigatorFor()->LocateGlobalPointWi 641 GetNavigatorFor()->LocateGlobalPointWithinVolume(Point_A); 620 G4bool Intersects_AB = IntersectChord( 642 G4bool Intersects_AB = IntersectChord(Point_A, SubE_point, 621 643 NewSafety, fPreviousSafety, 622 644 fPreviousSftOrigin,stepLengthAB, 623 645 PointGe); 624 if( Intersects_AB ) 646 if( Intersects_AB ) 625 { 647 { 626 last_AF_intersection = Intersects_AB 648 last_AF_intersection = Intersects_AB; 627 CurrentE_Point = PointGe; 649 CurrentE_Point = PointGe; 628 fin_section_depth[depth] = true; << 650 fin_section_depth[depth]=true; 629 651 630 // Need to recalculate the Exit Norm 652 // Need to recalculate the Exit Normal at the new PointG 631 // 653 // 632 G4bool validNormalAB; 654 G4bool validNormalAB; 633 NormalAtEntry = GetSurfaceNormal( Po 655 NormalAtEntry = GetSurfaceNormal( PointGe, validNormalAB ); 634 validNormalAtE = validNormalAB; << 656 validNormalAtE= validNormalAB; 635 } 657 } 636 else 658 else 637 { 659 { 638 // No intersection found for first p 660 // No intersection found for first part of curve 639 // (CurrentA,InterMedPoint[depth]). 661 // (CurrentA,InterMedPoint[depth]). Go to the second part 640 // 662 // 641 Second_half = true; 663 Second_half = true; 642 } 664 } 643 } // if did_len 665 } // if did_len 644 666 645 if( (Second_half)&&(depth!=0) ) 667 if( (Second_half)&&(depth!=0) ) 646 { 668 { 647 // Second part of curve (InterMed[dept 669 // Second part of curve (InterMed[depth],Intermed[depth-1]) ) 648 // On the depth-1 level normally we ar 670 // On the depth-1 level normally we are on the 'second_half' 649 671 650 Second_half = true; 672 Second_half = true; 651 673 652 // Find new trial intersection point 674 // Find new trial intersection point needed at start of the loop 653 // 675 // 654 SubStart_PointVelocity = *ptrInterMedF 676 SubStart_PointVelocity = *ptrInterMedFT[depth]; 655 CurrentA_PointVelocity = *ptrInterMedF 677 CurrentA_PointVelocity = *ptrInterMedFT[depth]; 656 CurrentB_PointVelocity = *ptrInterMedF 678 CurrentB_PointVelocity = *ptrInterMedFT[depth-1]; 657 // Ensure that the new endpoints are 679 // Ensure that the new endpoints are not further apart in space 658 // than on the curve due to different 680 // than on the curve due to different errors in the integration 659 // 681 // 660 G4double linDistSq, curveDist; 682 G4double linDistSq, curveDist; 661 linDistSq = ( CurrentB_PointVelocity.G 683 linDistSq = ( CurrentB_PointVelocity.GetPosition() 662 - CurrentA_PointVelocity.G 684 - CurrentA_PointVelocity.GetPosition() ).mag2(); 663 curveDist = CurrentB_PointVelocity.Get 685 curveDist = CurrentB_PointVelocity.GetCurveLength() 664 - CurrentA_PointVelocity.G 686 - CurrentA_PointVelocity.GetCurveLength(); 665 if( curveDist*curveDist*(1+2*GetEpsilo 687 if( curveDist*curveDist*(1+2*GetEpsilonStepFor() ) < linDistSq ) 666 { 688 { 667 // Re-integrate to obtain a new B 689 // Re-integrate to obtain a new B 668 // 690 // 669 G4FieldTrack newEndPointFT = << 691 G4FieldTrack newEndPointFT= 670 ReEstimateEndpoint( CurrentA 692 ReEstimateEndpoint( CurrentA_PointVelocity, 671 CurrentB 693 CurrentB_PointVelocity, 672 linDistS 694 linDistSq, // to avoid recalculation 673 curveDis 695 curveDist ); 674 G4FieldTrack oldPointVelB = CurrentB 696 G4FieldTrack oldPointVelB = CurrentB_PointVelocity; 675 CurrentB_PointVelocity = newEndPoint 697 CurrentB_PointVelocity = newEndPointFT; 676 if ( depth==1 ) << 698 if (depth==1) 677 { 699 { 678 recalculatedEndPoint = true; 700 recalculatedEndPoint = true; 679 IntersectedOrRecalculatedFT = newE 701 IntersectedOrRecalculatedFT = newEndPointFT; 680 // So that we can return it, if it 702 // So that we can return it, if it is the endpoint! 681 } 703 } 682 } 704 } 683 705 684 706 685 G4ThreeVector Point_A = CurrentA_Po 707 G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition(); 686 G4ThreeVector SubE_point = CurrentB_Po 708 G4ThreeVector SubE_point = CurrentB_PointVelocity.GetPosition(); 687 GetNavigatorFor()->LocateGlobalPointWi 709 GetNavigatorFor()->LocateGlobalPointWithinVolume(Point_A); 688 G4bool Intersects_AB = IntersectChord( 710 G4bool Intersects_AB = IntersectChord(Point_A, SubE_point, NewSafety, 689 711 fPreviousSafety, 690 712 fPreviousSftOrigin,stepLengthAB, PointGe); 691 if( Intersects_AB ) 713 if( Intersects_AB ) 692 { 714 { 693 last_AF_intersection = Intersects_AB 715 last_AF_intersection = Intersects_AB; 694 CurrentE_Point = PointGe; 716 CurrentE_Point = PointGe; 695 717 696 G4bool validNormalAB; 718 G4bool validNormalAB; 697 NormalAtEntry = GetSurfaceNormal( P 719 NormalAtEntry = GetSurfaceNormal( PointGe, validNormalAB ); 698 validNormalAtE = validNormalAB; 720 validNormalAtE = validNormalAB; 699 } 721 } 700 722 701 depth--; 723 depth--; 702 fin_section_depth[depth]=true; 724 fin_section_depth[depth]=true; 703 } 725 } 704 } // if(!found_aproximate_intersection) 726 } // if(!found_aproximate_intersection) 705 727 706 } while ( ( ! found_approximate_intersection 728 } while ( ( ! found_approximate_intersection ) 707 && ( ! there_is_no_intersection ) 729 && ( ! there_is_no_intersection ) 708 && ( substep_no <= max_substeps) ) 730 && ( substep_no <= max_substeps) ); // UNTIL found or failed 709 731 710 if( substep_no > max_no_seen ) 732 if( substep_no > max_no_seen ) 711 { 733 { 712 max_no_seen = substep_no; 734 max_no_seen = substep_no; 713 #ifdef G4DEBUG_LOCATE_INTERSECTION 735 #ifdef G4DEBUG_LOCATE_INTERSECTION 714 if( max_no_seen > warn_substeps ) 736 if( max_no_seen > warn_substeps ) 715 { 737 { 716 trigger_substepno_print = max_no_seen-20 738 trigger_substepno_print = max_no_seen-20; // Want to see last 20 steps 717 } 739 } 718 #endif 740 #endif 719 } 741 } 720 742 721 if( ( substep_no >= max_substeps) 743 if( ( substep_no >= max_substeps) 722 && !there_is_no_intersection 744 && !there_is_no_intersection 723 && !found_approximate_intersection ) 745 && !found_approximate_intersection ) 724 { 746 { 725 G4cout << "ERROR - G4BrentLocator::Estimat 747 G4cout << "ERROR - G4BrentLocator::EstimateIntersectionPoint()" << G4endl 726 << " Start and end-point of 748 << " Start and end-point of requested Step:" << G4endl; 727 printStatus( CurveStartPointVelocity, Curv 749 printStatus( CurveStartPointVelocity, CurveEndPointVelocity, 728 -1.0, NewSafety, 0); 750 -1.0, NewSafety, 0); 729 G4cout << " Start and end-point of 751 G4cout << " Start and end-point of current Sub-Step:" << G4endl; 730 printStatus( CurrentA_PointVelocity, Curre 752 printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity, 731 -1.0, NewSafety, substep_no-1 753 -1.0, NewSafety, substep_no-1); 732 printStatus( CurrentA_PointVelocity, Curre 754 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity, 733 -1.0, NewSafety, substep_no); 755 -1.0, NewSafety, substep_no); 734 std::ostringstream message; 756 std::ostringstream message; 735 message << "Too many substeps!" << G4endl 757 message << "Too many substeps!" << G4endl 736 << " Convergence is requi 758 << " Convergence is requiring too many substeps: " 737 << substep_no << G4endl 759 << substep_no << G4endl 738 << " Abandoning effort to 760 << " Abandoning effort to intersect. " << G4endl 739 << " Found intersection = 761 << " Found intersection = " 740 << found_approximate_intersection 762 << found_approximate_intersection << G4endl 741 << " Intersection exists 763 << " Intersection exists = " 742 << !there_is_no_intersection << G4 764 << !there_is_no_intersection << G4endl; 743 oldprc = G4cout.precision( 10 ); 765 oldprc = G4cout.precision( 10 ); 744 G4double done_len = CurrentA_PointVelocity 766 G4double done_len = CurrentA_PointVelocity.GetCurveLength(); 745 G4double full_len = CurveEndPointVelocity. 767 G4double full_len = CurveEndPointVelocity.GetCurveLength(); 746 message << " Undertaken only length 768 message << " Undertaken only length: " << done_len 747 << " out of " << full_len << " req 769 << " out of " << full_len << " required." << G4endl 748 << " Remaining length = " < 770 << " Remaining length = " << full_len - done_len; 749 G4cout.precision( oldprc ); 771 G4cout.precision( oldprc ); 750 772 751 G4Exception("G4BrentLocator::EstimateInter 773 G4Exception("G4BrentLocator::EstimateIntersectionPoint()", 752 "GeomNav0003", FatalException, 774 "GeomNav0003", FatalException, message); 753 } 775 } 754 else if( substep_no >= warn_substeps ) 776 else if( substep_no >= warn_substeps ) 755 { 777 { 756 oldprc = G4cout.precision( 10 ); << 778 oldprc= G4cout.precision( 10 ); 757 std::ostringstream message; 779 std::ostringstream message; 758 message << "Many substeps while trying to 780 message << "Many substeps while trying to locate intersection." 759 << G4endl 781 << G4endl 760 << " Undertaken length: " 782 << " Undertaken length: " 761 << CurrentB_PointVelocity.GetCurve 783 << CurrentB_PointVelocity.GetCurveLength() 762 << " - Needed: " << substep_no << 784 << " - Needed: " << substep_no << " substeps." << G4endl 763 << " Warning level = " << 785 << " Warning level = " << warn_substeps 764 << " and maximum substeps = " << m 786 << " and maximum substeps = " << max_substeps; 765 G4Exception("G4BrentLocator::EstimateInter 787 G4Exception("G4BrentLocator::EstimateIntersectionPoint()", 766 "GeomNav1002", JustWarning, me 788 "GeomNav1002", JustWarning, message); 767 G4cout.precision( oldprc ); 789 G4cout.precision( oldprc ); 768 } 790 } 769 return !there_is_no_intersection; // Succe 791 return !there_is_no_intersection; // Success or failure 770 } 792 } 771 793