G4MagErrorStepper Class Reference

#include <G4MagErrorStepper.hh>

Inheritance diagram for G4MagErrorStepper:

G4MagIntegratorStepper G4ClassicalRK4 G4ConstRK4 G4ExplicitEuler G4ImplicitEuler G4SimpleHeum G4SimpleRunge

Public Member Functions

 G4MagErrorStepper (G4EquationOfMotion *EqRhs, G4int numberOfVariables, G4int numStateVariables=12)
virtual ~G4MagErrorStepper ()
void Stepper (const G4double y[], const G4double dydx[], G4double h, G4double yout[], G4double yerr[])
virtual void DumbStepper (const G4double y[], const G4double dydx[], G4double h, G4double yout[])=0
G4double DistChord () const

Detailed Description

Definition at line 49 of file G4MagErrorStepper.hh.


Constructor & Destructor Documentation

G4MagErrorStepper::G4MagErrorStepper ( G4EquationOfMotion EqRhs,
G4int  numberOfVariables,
G4int  numStateVariables = 12 
) [inline]

Definition at line 32 of file G4MagErrorStepper.icc.

00035      : G4MagIntegratorStepper(EquationRhs,numberOfVariables,numStateVariables)
00036   {
00037       G4int nvar = std::max(this->GetNumberOfVariables(), 8);
00038       yMiddle=     new G4double[nvar]; 
00039       dydxMid=     new G4double[nvar];
00040       yInitial=    new G4double[nvar];
00041       yOneStep= new G4double[nvar];
00042   }

G4MagErrorStepper::~G4MagErrorStepper (  )  [virtual]

Definition at line 34 of file G4MagErrorStepper.cc.

00035 {
00036    delete[] yMiddle;
00037    delete[] dydxMid;
00038    delete[] yInitial;
00039    delete[] yOneStep;
00040 }


Member Function Documentation

G4double G4MagErrorStepper::DistChord (  )  const [virtual]

Implements G4MagIntegratorStepper.

Reimplemented in G4ConstRK4.

Definition at line 96 of file G4MagErrorStepper.cc.

References G4LineSection::Distline().

00097 {
00098   // Estimate the maximum distance from the curve to the chord
00099   //
00100   //  We estimate this using the distance of the midpoint to 
00101   //  chord (the line between 
00102   // 
00103   //  Method below is good only for angle deviations < 2 pi, 
00104   //   This restriction should not a problem for the Runge cutta methods, 
00105   //   which generally cannot integrate accurately for large angle deviations.
00106   G4double distLine, distChord; 
00107 
00108   if (fInitialPoint != fFinalPoint) {
00109      distLine= G4LineSection::Distline( fMidPoint, fInitialPoint, fFinalPoint );
00110      // This is a class method that gives distance of Mid 
00111      //  from the Chord between the Initial and Final points.
00112 
00113      distChord = distLine;
00114   }else{
00115      distChord = (fMidPoint-fInitialPoint).mag();
00116   }
00117 
00118   return distChord;
00119 }

virtual void G4MagErrorStepper::DumbStepper ( const G4double  y[],
const G4double  dydx[],
G4double  h,
G4double  yout[] 
) [pure virtual]

Implemented in G4ClassicalRK4, G4ConstRK4, G4ExplicitEuler, G4ImplicitEuler, G4SimpleHeum, and G4SimpleRunge.

Referenced by Stepper().

void G4MagErrorStepper::Stepper ( const G4double  y[],
const G4double  dydx[],
G4double  h,
G4double  yout[],
G4double  yerr[] 
) [virtual]

Implements G4MagIntegratorStepper.

Reimplemented in G4ConstRK4.

Definition at line 43 of file G4MagErrorStepper.cc.

References DumbStepper(), G4MagIntegratorStepper::GetNumberOfStateVariables(), G4MagIntegratorStepper::GetNumberOfVariables(), G4MagIntegratorStepper::IntegratorOrder(), and G4MagIntegratorStepper::RightHandSide().

00048 {  
00049    const G4int nvar = this->GetNumberOfVariables() ;
00050    const G4int maxvar= GetNumberOfStateVariables();
00051 
00052    G4int i;
00053    // correction for Richardson Extrapolation.
00054    G4double  correction = 1. / ( (1 << IntegratorOrder()) -1 );
00055    
00056    //  Saving yInput because yInput and yOutput can be aliases for same array
00057 
00058    for(i=0;i<nvar;i++) yInitial[i]=yInput[i];
00059    yInitial[7]= yInput[7];    // Copy the time in case ... even if not really needed
00060    yMiddle[7] = yInput[7];  // Copy the time from initial value 
00061    yOneStep[7] = yInput[7]; // As it contributes to final value of yOutput ?
00062    // yOutput[7] = yInput[7];  // -> dumb stepper does it too for RK4
00063    for(i=nvar;i<maxvar;i++) yOutput[i]=yInput[i];
00064    // yError[7] = 0.0;         
00065 
00066    G4double halfStep = hstep * 0.5; 
00067 
00068    // Do two half steps
00069 
00070    DumbStepper  (yInitial,  dydx,   halfStep, yMiddle);
00071    RightHandSide(yMiddle, dydxMid);    
00072    DumbStepper  (yMiddle, dydxMid, halfStep, yOutput); 
00073 
00074    // Store midpoint, chord calculation
00075 
00076    fMidPoint = G4ThreeVector( yMiddle[0],  yMiddle[1],  yMiddle[2]); 
00077 
00078    // Do a full Step
00079    DumbStepper(yInitial, dydx, hstep, yOneStep);
00080    for(i=0;i<nvar;i++) {
00081       yError [i] = yOutput[i] - yOneStep[i] ;
00082       yOutput[i] += yError[i]*correction ;  // Provides accuracy increased
00083                                             // by 1 order via the 
00084                                             // Richardson Extrapolation  
00085    }
00086 
00087    fInitialPoint = G4ThreeVector( yInitial[0], yInitial[1], yInitial[2]); 
00088    fFinalPoint   = G4ThreeVector( yOutput[0],  yOutput[1],  yOutput[2]); 
00089 
00090    return ;
00091 }


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:52:27 2013 for Geant4 by  doxygen 1.4.7