110 G4int no_warnings = 0;
111 static G4int dbg = 1;
112 static G4int nStpPr = 50;
117 G4double y[
G4FieldTrack::ncompSVEC] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
118 G4double dydx[
G4FieldTrack::ncompSVEC] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
119 G4double ystart[
G4FieldTrack::ncompSVEC] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
120 G4double yEnd[
G4FieldTrack::ncompSVEC] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
126 const G4int nvar = fNoVars;
136 std::ostringstream message;
137 message <<
"Proposed step is zero; hstep = " << hstep <<
" !";
143 std::ostringstream message;
144 message <<
"Invalid run condition." <<
G4endl
145 <<
"Proposed step is negative; hstep = " << hstep <<
"." <<
G4endl
146 <<
"Requested step cannot be negative! Aborting event.";
155 x1= startCurveLength;
158 if ( (hinitial > 0.0) && (hinitial < hstep)
159 && (hinitial > perMillion * hstep) )
170 for ( i=0; i<nvar; ++i) { y[i] = ystart[i]; }
181 for (i=0; i<nvar; ++i) { ySubStepStart[i] = y[i]; }
186 pIntStepper->RightHandSide( y, dydx );
191 if( h > fMinimumStep )
207 G4double dchord_step, dyerr, dyerr_len;
211 QuickAdvance( yFldTrk, dydx, h, dchord_step, dyerr_len );
218 if ( dyerr_len > fDyerr_max ) { fDyerr_max = dyerr_len; }
219 fDyerrPos_smTot += dyerr_len;
221 if (nstp==1) { ++fNoInitialSmallSteps; }
226 if(fNoSmallSteps<2) {
PrintStatus(ySubStepStart, x1, y, x, h, -nstp); }
227 G4cout <<
"Another sub-min step, no " << fNoSmallSteps
228 <<
" of " << fNoTotalSteps <<
" this time " << nstp <<
G4endl;
230 G4cout <<
" dyerr= " << dyerr_len <<
" relative = " << dyerr_len / h
231 <<
" epsilon= " << eps <<
" hstep= " << hstep
232 <<
" h= " << h <<
" hmin= " << fMinimumStep <<
G4endl;
239 "Integration Step became Zero!");
241 dyerr = dyerr_len / h;
252 if( (dbg>0) && (dbg<=2) && (nstp>nStpPr))
254 if( nstp==nStpPr ) {
G4cout <<
"***** Many steps ****" <<
G4endl; }
256 G4cout <<
"hdid=" << std::setw(12) << hdid <<
" "
257 <<
"hnext=" << std::setw(12) << hnext <<
" "
258 <<
"hstep=" << std::setw(12) << hstep <<
" (requested) "
260 PrintStatus( ystart, x1, y, x, h, (nstp==nStpPr) ? -nstp: nstp);
265 G4double endPointDist= (EndPos-StartPos).mag();
266 if ( endPointDist >= hdid*(1.+perMillion) )
272 if ( endPointDist >= hdid*(1.+perThousand) )
278 G4cerr <<
" Total steps: bad " << fNoBadSteps
279 <<
" current h= " << hdid <<
G4endl;
280 PrintStatus( ystart, x1, y, x, hstep, no_warnings?nstp:-nstp);
288 if( (h < eps * hstep) || (h < fSmallestFraction * startCurveLength) )
296 if(std::fabs(hnext) <=
Hmin())
300 if( (x < x2 * (1-eps) ) &&
301 (std::fabs(hstep) >
Hmin()) )
306 PrintStatus( ystart, x1, y, x, hstep, no_warnings?nstp:-nstp);
332 int prec=
G4cout.precision(12);
333 G4cout <<
"Warning: G4MagIntegratorDriver::AccurateAdvance"
335 <<
" Integration step 'h' became "
336 << h <<
" due to roundoff. " <<
G4endl
337 <<
" Calculated as difference of x2= "<< x2 <<
" and x=" << x
338 <<
" Forcing termination of advance." <<
G4endl;
344 }
while ( ((++nstp)<=fMaxNoSteps) && (x < x2) && (!lastStep) );
352 for (i=0; i<nvar; ++i) { yEnd[i] = y[i]; }
358 if(nstp > fMaxNoSteps)
372 if( dbg && no_warnings )
374 G4cerr <<
"G4MagIntegratorDriver exit status: no-steps " << nstp <<
G4endl;
499 G4double inv_eps_vel_sq = 1.0 / (eps_rel_max*eps_rel_max);
505 const G4int max_trials=100;
509 G4bool hasSpin = (spin_mag2 > 0.0);
511 for (
G4int iter=0; iter<max_trials; ++iter)
513 pIntStepper-> Stepper(y,dydx,h,ytemp,yerr);
515 G4double eps_pos = eps_rel_max * std::max(h, fMinimumStep);
516 G4double inv_eps_pos_sq = 1.0 / (eps_pos*eps_pos);
520 errpos_sq =
sqr(yerr[0]) +
sqr(yerr[1]) +
sqr(yerr[2]) ;
521 errpos_sq *= inv_eps_pos_sq;
526 if( magvel_sq > 0.0 )
528 errvel_sq = sumerr_sq / magvel_sq;
532 std::ostringstream message;
533 message <<
"Found case of zero momentum." <<
G4endl
534 <<
"- iteration= " << iter <<
"; h= " << h;
537 errvel_sq = sumerr_sq;
539 errvel_sq *= inv_eps_vel_sq;
540 errmax_sq = std::max( errpos_sq, errvel_sq );
545 errspin_sq = (
sqr(yerr[9]) +
sqr(yerr[10]) +
sqr(yerr[11]) )
547 errspin_sq *= inv_eps_vel_sq;
548 errmax_sq = std::max( errmax_sq, errspin_sq );
551 if ( errmax_sq <= 1.0 ) {
break; }
556 if (htemp >= 0.1*h) { h = htemp; }
562 std::ostringstream message;
563 message <<
"Stepsize underflow in Stepper !" <<
G4endl
564 <<
"- Step's start x=" << x <<
" and end x= " << xnew
565 <<
" are equal !! " <<
G4endl
566 <<
" Due to step-size= " << h
567 <<
". Note that input step was " << htry;
575 if (errmax_sq > errcon*errcon)
585 for(
G4int k=0; k<fNoIntegrationVariables; ++k) { y[k] = ytemp[k]; }
619 G4double dyerr_pos_sq, dyerr_mom_rel_sq;
623 G4double dyerr_mom_sq, vel_mag_sq, inv_vel_mag_sq;
630 pIntStepper-> Stepper(yarrin, dydx, hstep, yarrout, yerr_vec) ;
633 dchord_step= pIntStepper-> DistChord();
643 PrintStatus( yarrin, s_start, yarrout, s_start+hstep, hstep, 1);
649 vel_mag_sq = (
sqr(yarrout[3])+
sqr(yarrout[4])+
sqr(yarrout[5]) );
650 inv_vel_mag_sq = 1.0 / vel_mag_sq;
651 dyerr_pos_sq = (
sqr(yerr_vec[0])+
sqr(yerr_vec[1])+
sqr(yerr_vec[2]));
652 dyerr_mom_sq = (
sqr(yerr_vec[3])+
sqr(yerr_vec[4])+
sqr(yerr_vec[5]));
653 dyerr_mom_rel_sq = dyerr_mom_sq * inv_vel_mag_sq;
659#ifdef RETURN_A_NEW_STEP_LENGTH
661 dyerr_len = std::sqrt( dyerr_len_sq );
662 dyerr_len_sq /= eps ;
671 if( dyerr_pos_sq > ( dyerr_mom_rel_sq *
sqr(hstep) ) )
673 dyerr = std::sqrt(dyerr_pos_sq);
678 dyerr = std::sqrt(dyerr_mom_rel_sq) * hstep;
883 G4cout << std::setw( 5) << subStepNo <<
" ";
887 G4cout << std::setw( 5) <<
"Start" <<
" ";
890 G4cout << std::setw( 7) << curveLen;
891 G4cout << std::setw( 9) << Position.x() <<
" "
892 << std::setw( 9) << Position.y() <<
" "
893 << std::setw( 9) << Position.z() <<
" "
894 << std::setw( 8) << UnitVelocity.
x() <<
" "
895 << std::setw( 8) << UnitVelocity.
y() <<
" "
896 << std::setw( 8) << UnitVelocity.
z() <<
" ";
898 G4cout << std::setw( 8) << UnitVelocity.
mag2()-1.0 <<
" ";
900 G4cout << std::setw(10) << dotVeloc_StartCurr <<
" ";
901 G4cout.precision(oldprec);
903 G4cout << std::setw(12) << step_len <<
" ";
910 if( curveLen > oldCurveLength )
912 subStep_len= curveLen - oldCurveLength;
914 else if (subStepNo == oldSubStepNo)
916 subStep_len= oldSubStepLength;
918 oldCurveLength= curveLen;
919 oldSubStepLength= subStep_len;
921 G4cout << std::setw(12) << subStep_len <<
" ";
922 G4cout << std::setw(12) << subStepSize <<
" ";
923 if( requestStep != -1.0 )
925 G4cout << std::setw( 9) << requestStep <<
" ";
929 G4cout << std::setw( 9) <<
" InitialStep " <<
" ";