96 G4bool& recalculatedEndPoint,
103 G4bool found_approximate_intersection =
false;
104 G4bool there_is_no_intersection =
false;
106 G4FieldTrack CurrentA_PointVelocity = CurveStartPointVelocity;
107 G4FieldTrack CurrentB_PointVelocity = CurveEndPointVelocity;
109 G4bool validNormalAtE =
false;
112 G4FieldTrack ApproxIntersecPointV(CurveEndPointVelocity);
114 G4bool last_AF_intersection =
false;
118 G4bool first_section =
true;
119 recalculatedEndPoint =
false;
121 G4bool restoredFullEndpoint =
false;
124 G4int substep_no = 0;
128 const G4int max_substeps= 10000;
129 const G4int warn_substeps= 1000;
149 const G4int param_substeps = 50;
153 G4bool Second_half =
false;
168 if( (TrialPoint - StartPosition).mag() < tolerance * CLHEP::mm )
170 G4Exception(
"G4BrentLocator::EstimateIntersectionPoint()",
172 "Intersection point F is exactly at start point A." );
180 *ptrInterMedFT[0] = CurveEndPointVelocity;
181 for (
auto idepth=1; idepth<max_depth+1; ++idepth )
183 *ptrInterMedFT[idepth] = CurveStartPointVelocity;
187 G4bool fin_section_depth[max_depth];
188 for (
bool & idepth : fin_section_depth)
195 G4FieldTrack SubStart_PointVelocity = CurveStartPointVelocity;
199 G4int substep_no_p = 0;
200 G4bool sub_final_section =
false;
202 SubStart_PointVelocity = CurrentA_PointVelocity;
216 CurrentB_PointVelocity,
225 G4Exception(
"G4BrentLocator::EstimateIntersectionPoint()",
227 "Intermediate F point is past end B point" );
236 G4ThreeVector ChordEF_Vector = CurrentF_Point - CurrentE_Point;
238 G4double MomDir_dot_Norm = NewMomentumDir.
dot( NormalAtEntry ) ;
244 ChordEF_Vector, NewMomentumDir, NormalAtEntry, validNormalAtE );
248 adequate_angle = ( MomDir_dot_Norm >= 0.0 )
249 || (! validNormalAtE );
254 found_approximate_intersection =
true;
258 IntersectedOrRecalculatedFT = ApproxIntersecPointV;
259 IntersectedOrRecalculatedFT.
SetPosition( CurrentE_Point );
268 CurrentE_Point, CurrentF_Point, MomentumDir,
269 last_AF_intersection, IP, NewSafety,
271 if ( goodCorrection )
273 IntersectedOrRecalculatedFT = ApproxIntersecPointV;
296 G4bool usedNavigatorAF =
false;
303 last_AF_intersection = Intersects_AF;
314 CurrentA_PointVelocity, CurrentB_PointVelocity,
315 EndPoint,CurrentE_Point, CurrentF_Point,PointG,
317 CurrentB_PointVelocity = EndPoint;
318 CurrentE_Point = PointG;
326 validNormalAtE = validNormalLast;
331 fin_section_depth[depth] =
false;
335 G4cout <<
"G4PiF::LI> Investigating intermediate point"
337 <<
" on way to full s="
352 G4bool usedNavigatorFB =
false;
379 CurrentA_PointVelocity,CurrentB_PointVelocity,
380 InterMed,CurrentE_Point,CurrentF_Point,PointH,
382 CurrentA_PointVelocity = InterMed;
383 CurrentE_Point = PointH;
389 validNormalAtE = validNormalLast;
395 if( fin_section_depth[depth] )
405 if( ((Second_half)&&(depth==0)) || (first_section) )
407 there_is_no_intersection =
true;
414 substep_no_p = param_substeps+2;
420 sub_final_section =
true;
429 CurrentA_PointVelocity = CurrentB_PointVelocity;
430 CurrentB_PointVelocity = CurveEndPointVelocity;
431 SubStart_PointVelocity = CurrentA_PointVelocity;
434 CurrentB_PointVelocity,
438 restoredFullEndpoint =
true;
445 CurrentA_PointVelocity = CurrentB_PointVelocity;
446 CurrentB_PointVelocity = *ptrInterMedFT[depth];
447 SubStart_PointVelocity = CurrentA_PointVelocity;
450 CurrentB_PointVelocity,
453 restoredFullEndpoint =
true;
477 CurrentB_PointVelocity,
481 CurrentB_PointVelocity = newEndPointFT;
483 if ( (fin_section_depth[depth])
484 &&( first_section || ((Second_half)&&(depth==0)) ) )
486 recalculatedEndPoint =
true;
487 IntersectedOrRecalculatedFT = newEndPointFT;
491 if( curveDist < 0.0 )
494 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
495 -1.0, NewSafety, substep_no );
496 std::ostringstream message;
497 message <<
"Error in advancing propagation." <<
G4endl
498 <<
" Error in advancing propagation." <<
G4endl
499 <<
" Point A (start) is " << CurrentA_PointVelocity
501 <<
" Point B (end) is " << CurrentB_PointVelocity
503 <<
" Curve distance is " << curveDist <<
G4endl
505 <<
"The final curve point is not further along"
506 <<
" than the original!" <<
G4endl;
508 if( recalculatedEndPoint )
510 message <<
"Recalculation of EndPoint was called with fEpsStep= "
513 oldprc =
G4cerr.precision(20);
514 message <<
" Point A (Curve start) is " << CurveStartPointVelocity
516 <<
" Point B (Curve end) is " << CurveEndPointVelocity
518 <<
" Point A (Current start) is " << CurrentA_PointVelocity
520 <<
" Point B (Current end) is " << CurrentB_PointVelocity
522 <<
" Point S (Sub start) is " << SubStart_PointVelocity
524 <<
" Point E (Trial Point) is " << CurrentE_Point
526 <<
" Old Point F(Intersection) is " << CurrentF_Point
528 <<
" New Point F(Intersection) is " << ApproxIntersecPointV
530 <<
" LocateIntersection parameters are : Substep no= "
532 <<
" Substep depth no= "<< substep_no_p <<
" Depth= "
534 <<
" Restarted no= "<< restartB <<
" Epsilon= "
537 G4cerr.precision( oldprc );
539 G4Exception(
"G4BrentLocator::EstimateIntersectionPoint()",
543 if( restoredFullEndpoint )
545 fin_section_depth[depth] = restoredFullEndpoint;
546 restoredFullEndpoint =
false;
551#ifdef G4DEBUG_LOCATE_INTERSECTION
552 G4int trigger_substepno_print= warn_substeps - 20 ;
554 if( substep_no >= trigger_substepno_print )
556 G4cout <<
"Difficulty in converging in "
557 <<
"G4BrentLocator::EstimateIntersectionPoint()"
559 <<
" Substep no = " << substep_no <<
G4endl;
560 if( substep_no == trigger_substepno_print )
562 printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
565 G4cout <<
" State of point A: ";
566 printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
567 -1.0, NewSafety, substep_no-1, 0);
568 G4cout <<
" State of point B: ";
569 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
570 -1.0, NewSafety, substep_no);
576 }
while ( ( ! found_approximate_intersection )
577 && ( ! there_is_no_intersection )
578 && ( substep_no_p <= param_substeps) );
580 first_section =
false;
582 if( (!found_approximate_intersection) && (!there_is_no_intersection) )
595 if ( ( did_len < fraction_done*all_len )
596 && (depth < max_depth) && (!sub_final_section) )
601 G4double Sub_len = (all_len-did_len)/(2.);
606 *ptrInterMedFT[depth] = start;
607 CurrentB_PointVelocity = *ptrInterMedFT[depth];
611 SubStart_PointVelocity = CurrentA_PointVelocity;
625 last_AF_intersection = Intersects_AB;
626 CurrentE_Point = PointGe;
627 fin_section_depth[depth] =
true;
633 validNormalAtE = validNormalAB;
644 if( (Second_half)&&(depth!=0) )
653 SubStart_PointVelocity = *ptrInterMedFT[depth];
654 CurrentA_PointVelocity = *ptrInterMedFT[depth];
655 CurrentB_PointVelocity = *ptrInterMedFT[depth-1];
670 CurrentB_PointVelocity,
674 CurrentB_PointVelocity = newEndPointFT;
677 recalculatedEndPoint =
true;
678 IntersectedOrRecalculatedFT = newEndPointFT;
692 last_AF_intersection = Intersects_AB;
693 CurrentE_Point = PointGe;
697 validNormalAtE = validNormalAB;
701 fin_section_depth[depth]=
true;
705 }
while ( ( ! found_approximate_intersection )
706 && ( ! there_is_no_intersection )
707 && ( substep_no <= max_substeps) );
709 if( substep_no > max_no_seen )
711 max_no_seen = substep_no;
712#ifdef G4DEBUG_LOCATE_INTERSECTION
713 if( max_no_seen > warn_substeps )
715 trigger_substepno_print = max_no_seen-20;
720 if( ( substep_no >= max_substeps)
721 && !there_is_no_intersection
722 && !found_approximate_intersection )
724 G4cout <<
"ERROR - G4BrentLocator::EstimateIntersectionPoint()" <<
G4endl
725 <<
" Start and end-point of requested Step:" <<
G4endl;
726 printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
728 G4cout <<
" Start and end-point of current Sub-Step:" <<
G4endl;
729 printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
730 -1.0, NewSafety, substep_no-1);
731 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
732 -1.0, NewSafety, substep_no);
733 std::ostringstream message;
734 message <<
"Too many substeps!" <<
G4endl
735 <<
" Convergence is requiring too many substeps: "
737 <<
" Abandoning effort to intersect. " <<
G4endl
738 <<
" Found intersection = "
739 << found_approximate_intersection <<
G4endl
740 <<
" Intersection exists = "
741 << !there_is_no_intersection <<
G4endl;
742 oldprc =
G4cout.precision( 10 );
745 message <<
" Undertaken only length: " << done_len
746 <<
" out of " << full_len <<
" required." <<
G4endl
747 <<
" Remaining length = " << full_len - done_len;
748 G4cout.precision( oldprc );
750 G4Exception(
"G4BrentLocator::EstimateIntersectionPoint()",
753 else if( substep_no >= warn_substeps )
755 oldprc =
G4cout.precision( 10 );
756 std::ostringstream message;
757 message <<
"Many substeps while trying to locate intersection."
759 <<
" Undertaken length: "
761 <<
" - Needed: " << substep_no <<
" substeps." <<
G4endl
762 <<
" Warning level = " << warn_substeps
763 <<
" and maximum substeps = " << max_substeps;
764 G4Exception(
"G4BrentLocator::EstimateIntersectionPoint()",
766 G4cout.precision( oldprc );
768 return !there_is_no_intersection;