45 for (
auto idepth=0; idepth<
max_depth+1; ++idepth )
53 for (
auto idepth=0; idepth<
max_depth+1; ++idepth )
97 G4bool& recalculatedEndPoint,
104 G4bool found_approximate_intersection =
false;
105 G4bool there_is_no_intersection =
false;
107 G4FieldTrack CurrentA_PointVelocity = CurveStartPointVelocity;
108 G4FieldTrack CurrentB_PointVelocity = CurveEndPointVelocity;
110 G4bool validNormalAtE =
false;
113 G4FieldTrack ApproxIntersecPointV(CurveEndPointVelocity);
115 G4bool last_AF_intersection =
false;
119 G4bool first_section =
true;
120 recalculatedEndPoint =
false;
122 G4bool restoredFullEndpoint =
false;
125 G4int substep_no = 0;
129 const G4int max_substeps= 10000;
130 const G4int warn_substeps= 1000;
150 const G4int param_substeps = 50;
154 G4bool Second_half =
false;
169 if( (TrialPoint - StartPosition).mag() < tolerance *
CLHEP::mm )
171 G4Exception(
"G4BrentLocator::EstimateIntersectionPoint()",
173 "Intersection point F is exactly at start point A." );
182 for (
auto idepth=1; idepth<
max_depth+1; ++idepth )
189 for (
auto idepth=0; idepth<
max_depth; ++idepth )
191 fin_section_depth[idepth] =
true;
196 G4FieldTrack SubStart_PointVelocity = CurveStartPointVelocity;
200 G4int substep_no_p = 0;
201 G4bool sub_final_section =
false;
203 SubStart_PointVelocity = CurrentA_PointVelocity;
217 CurrentB_PointVelocity,
226 G4Exception(
"G4BrentLocator::EstimateIntersectionPoint()",
228 "Intermediate F point is past end B point" );
237 G4ThreeVector ChordEF_Vector = CurrentF_Point - CurrentE_Point;
239 G4double MomDir_dot_Norm = NewMomentumDir.
dot( NormalAtEntry ) ;
245 ChordEF_Vector, NewMomentumDir, NormalAtEntry, validNormalAtE );
249 adequate_angle = ( MomDir_dot_Norm >= 0.0 )
250 || (! validNormalAtE );
255 found_approximate_intersection =
true;
259 IntersectedOrRecalculatedFT = ApproxIntersecPointV;
260 IntersectedOrRecalculatedFT.
SetPosition( CurrentE_Point );
269 CurrentE_Point, CurrentF_Point, MomentumDir,
270 last_AF_intersection, IP, NewSafety,
271 fPreviousSafety, fPreviousSftOrigin );
272 if ( goodCorrection )
274 IntersectedOrRecalculatedFT = ApproxIntersecPointV;
297 G4bool usedNavigatorAF =
false;
299 NewSafety,fPreviousSafety,
304 last_AF_intersection = Intersects_AF;
315 CurrentA_PointVelocity, CurrentB_PointVelocity,
316 EndPoint,CurrentE_Point, CurrentF_Point,PointG,
318 CurrentB_PointVelocity = EndPoint;
319 CurrentE_Point = PointG;
327 validNormalAtE = validNormalLast;
332 fin_section_depth[depth] =
false;
336 G4cout <<
"G4PiF::LI> Investigating intermediate point"
338 <<
" on way to full s="
353 G4bool usedNavigatorFB =
false;
359 NewSafety,fPreviousSafety,
380 CurrentA_PointVelocity,CurrentB_PointVelocity,
381 InterMed,CurrentE_Point,CurrentF_Point,PointH,
383 CurrentA_PointVelocity = InterMed;
384 CurrentE_Point = PointH;
390 validNormalAtE = validNormalLast;
396 if( fin_section_depth[depth] )
406 if( ((Second_half)&&(depth==0)) || (first_section) )
408 there_is_no_intersection =
true;
415 substep_no_p = param_substeps+2;
421 sub_final_section =
true;
430 CurrentA_PointVelocity = CurrentB_PointVelocity;
431 CurrentB_PointVelocity = CurveEndPointVelocity;
432 SubStart_PointVelocity = CurrentA_PointVelocity;
435 CurrentB_PointVelocity,
439 restoredFullEndpoint =
true;
446 CurrentA_PointVelocity = CurrentB_PointVelocity;
448 SubStart_PointVelocity = CurrentA_PointVelocity;
451 CurrentB_PointVelocity,
454 restoredFullEndpoint =
true;
478 CurrentB_PointVelocity,
482 CurrentB_PointVelocity = newEndPointFT;
484 if ( (fin_section_depth[depth])
485 &&( first_section || ((Second_half)&&(depth==0)) ) )
487 recalculatedEndPoint =
true;
488 IntersectedOrRecalculatedFT = newEndPointFT;
492 if( curveDist < 0.0 )
495 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
496 -1.0, NewSafety, substep_no );
498 message <<
"Error in advancing propagation." <<
G4endl
499 <<
" Error in advancing propagation." <<
G4endl
500 <<
" Point A (start) is " << CurrentA_PointVelocity
502 <<
" Point B (end) is " << CurrentB_PointVelocity
504 <<
" Curve distance is " << curveDist <<
G4endl
506 <<
"The final curve point is not further along"
507 <<
" than the original!" <<
G4endl;
509 if( recalculatedEndPoint )
511 message <<
"Recalculation of EndPoint was called with fEpsStep= "
514 oldprc =
G4cerr.precision(20);
515 message <<
" Point A (Curve start) is " << CurveStartPointVelocity
517 <<
" Point B (Curve end) is " << CurveEndPointVelocity
519 <<
" Point A (Current start) is " << CurrentA_PointVelocity
521 <<
" Point B (Current end) is " << CurrentB_PointVelocity
523 <<
" Point S (Sub start) is " << SubStart_PointVelocity
525 <<
" Point E (Trial Point) is " << CurrentE_Point
527 <<
" Old Point F(Intersection) is " << CurrentF_Point
529 <<
" New Point F(Intersection) is " << ApproxIntersecPointV
531 <<
" LocateIntersection parameters are : Substep no= "
532 << substep_no << G4endl
533 <<
" Substep depth no= "<< substep_no_p <<
" Depth= "
535 <<
" Restarted no= "<< restartB <<
" Epsilon= "
538 G4cerr.precision( oldprc );
540 G4Exception(
"G4BrentLocator::EstimateIntersectionPoint()",
544 if( restoredFullEndpoint )
546 fin_section_depth[depth] = restoredFullEndpoint;
547 restoredFullEndpoint =
false;
552 #ifdef G4DEBUG_LOCATE_INTERSECTION
553 G4int trigger_substepno_print= warn_substeps - 20 ;
555 if( substep_no >= trigger_substepno_print )
557 G4cout <<
"Difficulty in converging in "
558 <<
"G4BrentLocator::EstimateIntersectionPoint()"
560 <<
" Substep no = " << substep_no <<
G4endl;
561 if( substep_no == trigger_substepno_print )
563 printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
566 G4cout <<
" State of point A: ";
567 printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
568 -1.0, NewSafety, substep_no-1, 0);
569 G4cout <<
" State of point B: ";
570 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
571 -1.0, NewSafety, substep_no);
577 }
while ( ( ! found_approximate_intersection )
578 && ( ! there_is_no_intersection )
579 && ( substep_no_p <= param_substeps) );
581 first_section =
false;
583 if( (!found_approximate_intersection) && (!there_is_no_intersection) )
596 if ( ( did_len < fraction_done*all_len )
597 && (depth <
max_depth) && (!sub_final_section) )
602 G4double Sub_len = (all_len-did_len)/(2.);
612 SubStart_PointVelocity = CurrentA_PointVelocity;
621 NewSafety, fPreviousSafety,
622 fPreviousSftOrigin,stepLengthAB,
626 last_AF_intersection = Intersects_AB;
627 CurrentE_Point = PointGe;
628 fin_section_depth[depth] =
true;
634 validNormalAtE = validNormalAB;
645 if( (Second_half)&&(depth!=0) )
671 CurrentB_PointVelocity,
675 CurrentB_PointVelocity = newEndPointFT;
678 recalculatedEndPoint =
true;
679 IntersectedOrRecalculatedFT = newEndPointFT;
690 fPreviousSftOrigin,stepLengthAB, PointGe);
693 last_AF_intersection = Intersects_AB;
694 CurrentE_Point = PointGe;
698 validNormalAtE = validNormalAB;
702 fin_section_depth[depth]=
true;
706 }
while ( ( ! found_approximate_intersection )
707 && ( ! there_is_no_intersection )
708 && ( substep_no <= max_substeps) );
710 if( substep_no > max_no_seen )
712 max_no_seen = substep_no;
713 #ifdef G4DEBUG_LOCATE_INTERSECTION
714 if( max_no_seen > warn_substeps )
716 trigger_substepno_print = max_no_seen-20;
721 if( ( substep_no >= max_substeps)
722 && !there_is_no_intersection
723 && !found_approximate_intersection )
725 G4cout <<
"ERROR - G4BrentLocator::EstimateIntersectionPoint()" <<
G4endl
726 <<
" Start and end-point of requested Step:" <<
G4endl;
727 printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
729 G4cout <<
" Start and end-point of current Sub-Step:" <<
G4endl;
730 printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
731 -1.0, NewSafety, substep_no-1);
732 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
733 -1.0, NewSafety, substep_no);
735 message <<
"Too many substeps!" << G4endl
736 <<
" Convergence is requiring too many substeps: "
737 << substep_no << G4endl
738 <<
" Abandoning effort to intersect. " << G4endl
739 <<
" Found intersection = "
740 << found_approximate_intersection << G4endl
741 <<
" Intersection exists = "
742 << !there_is_no_intersection <<
G4endl;
743 oldprc =
G4cout.precision( 10 );
746 message <<
" Undertaken only length: " << done_len
747 <<
" out of " << full_len <<
" required." << G4endl
748 <<
" Remaining length = " << full_len - done_len;
749 G4cout.precision( oldprc );
751 G4Exception(
"G4BrentLocator::EstimateIntersectionPoint()",
754 else if( substep_no >= warn_substeps )
756 oldprc=
G4cout.precision( 10 );
758 message <<
"Many substeps while trying to locate intersection."
760 <<
" Undertaken length: "
762 <<
" - Needed: " << substep_no <<
" substeps." <<
G4endl
763 <<
" Warning level = " << warn_substeps
764 <<
" and maximum substeps = " << max_substeps;
765 G4Exception(
"G4BrentLocator::EstimateIntersectionPoint()",
767 G4cout.precision( oldprc );
769 return !there_is_no_intersection;