Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4ClassicalRK4 implementation << 27 // 23 // 28 // Created: J.Apostolakis, V.Grichine - 30.01. << 24 // $Id: G4ClassicalRK4.cc,v 1.8 2003/06/16 16:51:11 gunter Exp $ 29 // ------------------------------------------- << 25 // GEANT4 tag $Name: geant4-05-02-patch-01 $ 30 << 26 // 31 #include "G4ClassicalRK4.hh" 27 #include "G4ClassicalRK4.hh" 32 #include "G4ThreeVector.hh" 28 #include "G4ThreeVector.hh" 33 29 >> 30 34 ////////////////////////////////////////////// 31 ////////////////////////////////////////////////////////////////// 35 // 32 // 36 // Constructor sets the number of variables (d 33 // Constructor sets the number of variables (default = 6) 37 // << 34 38 G4ClassicalRK4:: << 35 G4ClassicalRK4::G4ClassicalRK4(G4Mag_EqRhs *EqRhs, G4int numberOfVariables) 39 G4ClassicalRK4(G4EquationOfMotion* EqRhs, G4in << 40 : G4MagErrorStepper(EqRhs, numberOfVariables 36 : G4MagErrorStepper(EqRhs, numberOfVariables) >> 37 // fNumberOfVariables(numberOfVariables) 41 { 38 { 42 unsigned int noVariables= std::max(numberOf 39 unsigned int noVariables= std::max(numberOfVariables,8); // For Time .. 7+1 43 40 44 dydxm = new G4double[noVariables]; 41 dydxm = new G4double[noVariables]; 45 dydxt = new G4double[noVariables]; 42 dydxt = new G4double[noVariables]; 46 yt = new G4double[noVariables]; 43 yt = new G4double[noVariables]; 47 } 44 } 48 45 49 ////////////////////////////////////////////// 46 //////////////////////////////////////////////////////////////// 50 // 47 // 51 // Destructor 48 // Destructor 52 // << 49 53 G4ClassicalRK4::~G4ClassicalRK4() 50 G4ClassicalRK4::~G4ClassicalRK4() 54 { 51 { 55 delete [] dydxm; << 52 delete[] dydxm; 56 delete [] dydxt; << 53 delete[] dydxt; 57 delete [] yt; << 54 delete[] yt; 58 } 55 } 59 56 60 ////////////////////////////////////////////// 57 ////////////////////////////////////////////////////////////////////// 61 // 58 // 62 // Given values for the variables y[0,..,n-1] 59 // Given values for the variables y[0,..,n-1] and their derivatives 63 // dydx[0,...,n-1] known at x, use the classic 60 // dydx[0,...,n-1] known at x, use the classical 4th Runge-Kutta 64 // method to advance the solution over an inte 61 // method to advance the solution over an interval h and return the 65 // incremented variables as yout[0,...,n-1], w 62 // incremented variables as yout[0,...,n-1], which not be a distinct 66 // array from y. The user supplies the routine 63 // array from y. The user supplies the routine RightHandSide(x,y,dydx), 67 // which returns derivatives dydx at x. The so 64 // which returns derivatives dydx at x. The source is routine rk4 from 68 // NRC p. 712-713 . 65 // NRC p. 712-713 . 69 // << 66 70 void 67 void 71 G4ClassicalRK4::DumbStepper( const G4double yI << 68 G4ClassicalRK4::DumbStepper( const G4double yIn[], 72 const G4double dy << 69 const G4double dydx[], 73 G4double h, << 70 G4double h, 74 G4double yO << 71 G4double yOut[]) 75 { 72 { 76 const G4int nvar = GetNumberOfVariables(); << 73 const G4int nvar = this->GetNumberOfVariables(); // fNumberOfVariables(); 77 G4int i; 74 G4int i; 78 G4double hh = h*0.5, h6 = h/6.0; << 75 G4double hh = h*0.5 , h6 = h/6.0 ; 79 76 80 // Initialise time to t0, needed when it is 77 // Initialise time to t0, needed when it is not updated by the integration. 81 // [ Note: Only for time dependent fi 78 // [ Note: Only for time dependent fields (usually electric) 82 // is it neccessary to inte 79 // is it neccessary to integrate the time.] 83 yt[7] = yIn[7]; 80 yt[7] = yIn[7]; 84 yOut[7] = yIn[7]; 81 yOut[7] = yIn[7]; 85 82 86 for(i=0; i<nvar; ++i) << 83 for(i=0;i<nvar;i++) 87 { 84 { 88 yt[i] = yIn[i] + hh*dydx[i] ; 85 yt[i] = yIn[i] + hh*dydx[i] ; // 1st Step K1=h*dydx 89 } 86 } 90 RightHandSide(yt,dydxt) ; 87 RightHandSide(yt,dydxt) ; // 2nd Step K2=h*dydxt 91 88 92 for(i=0; i<nvar; ++i) << 89 for(i=0;i<nvar;i++) 93 { 90 { 94 yt[i] = yIn[i] + hh*dydxt[i] ; 91 yt[i] = yIn[i] + hh*dydxt[i] ; 95 } 92 } 96 RightHandSide(yt,dydxm) ; 93 RightHandSide(yt,dydxm) ; // 3rd Step K3=h*dydxm 97 94 98 for(i=0; i<nvar; ++i) << 95 for(i=0;i<nvar;i++) 99 { 96 { 100 yt[i] = yIn[i] + h*dydxm[i] ; << 97 yt[i] = yIn[i] + h*dydxm[i] ; 101 dydxm[i] += dydxt[i] ; 98 dydxm[i] += dydxt[i] ; // now dydxm=(K2+K3)/h 102 } 99 } 103 RightHandSide(yt,dydxt) ; 100 RightHandSide(yt,dydxt) ; // 4th Step K4=h*dydxt 104 101 105 for(i=0; i<nvar; ++i) // Final RK4 output << 102 for(i=0;i<nvar;i++) // Final RK4 output 106 { 103 { 107 yOut[i] = yIn[i]+h6*(dydx[i]+dydxt[i]+2.0* 104 yOut[i] = yIn[i]+h6*(dydx[i]+dydxt[i]+2.0*dydxm[i]); //+K1/6+K4/6+(K2+K3)/3 108 } 105 } 109 if ( nvar == 12 ) { NormalisePolarizationVe << 106 // NormaliseTangentVector( yOut ); 110 107 >> 108 return ; 111 } // end of DumbStepper ..................... 109 } // end of DumbStepper .................................................... 112 110 113 ////////////////////////////////////////////// 111 //////////////////////////////////////////////////////////////////// 114 // 112 // 115 // StepWithEst << 113 // 116 114 117 void 115 void 118 G4ClassicalRK4::StepWithEst( const G4double*, 116 G4ClassicalRK4::StepWithEst( const G4double*, 119 const G4double*, 117 const G4double*, 120 G4double, 118 G4double, 121 G4double*, 119 G4double*, 122 G4double&, 120 G4double&, 123 G4double&, 121 G4double&, 124 const G4double*, 122 const G4double*, 125 G4double* 123 G4double* ) 126 { 124 { 127 G4Exception("G4ClassicalRK4::StepWithEst()", << 128 FatalException, "Method no longe << 129 125 >> 126 G4Exception("ERROR - G4ClassicalRK4::StepWithEst(): method no longer used."); >> 127 >> 128 return ; 130 } // end of StepWithEst ..................... 129 } // end of StepWithEst ...................................................... 131 130