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.11 2003/11/05 16:31:48 japost Exp $ >> 25 // GEANT4 tag $Name: geant4-06-00-patch-01 $ >> 26 // 29 // ------------------------------------------- 27 // ------------------------------------------------------------------- 30 28 31 #include "G4ClassicalRK4.hh" 29 #include "G4ClassicalRK4.hh" 32 #include "G4ThreeVector.hh" 30 #include "G4ThreeVector.hh" 33 31 34 ////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////// 35 // 33 // 36 // Constructor sets the number of variables (d 34 // Constructor sets the number of variables (default = 6) 37 // << 35 38 G4ClassicalRK4:: << 36 G4ClassicalRK4::G4ClassicalRK4(G4EquationOfMotion* EqRhs, G4int numberOfVariables) 39 G4ClassicalRK4(G4EquationOfMotion* EqRhs, G4in << 40 : G4MagErrorStepper(EqRhs, numberOfVariables 37 : G4MagErrorStepper(EqRhs, numberOfVariables) >> 38 // fNumberOfVariables(numberOfVariables) 41 { 39 { 42 unsigned int noVariables= std::max(numberOf 40 unsigned int noVariables= std::max(numberOfVariables,8); // For Time .. 7+1 43 41 44 dydxm = new G4double[noVariables]; 42 dydxm = new G4double[noVariables]; 45 dydxt = new G4double[noVariables]; 43 dydxt = new G4double[noVariables]; 46 yt = new G4double[noVariables]; 44 yt = new G4double[noVariables]; 47 } 45 } 48 46 49 ////////////////////////////////////////////// 47 //////////////////////////////////////////////////////////////// 50 // 48 // 51 // Destructor 49 // Destructor 52 // << 50 53 G4ClassicalRK4::~G4ClassicalRK4() 51 G4ClassicalRK4::~G4ClassicalRK4() 54 { 52 { 55 delete [] dydxm; << 53 delete[] dydxm; 56 delete [] dydxt; << 54 delete[] dydxt; 57 delete [] yt; << 55 delete[] yt; 58 } 56 } 59 57 60 ////////////////////////////////////////////// 58 ////////////////////////////////////////////////////////////////////// 61 // 59 // 62 // Given values for the variables y[0,..,n-1] 60 // Given values for the variables y[0,..,n-1] and their derivatives 63 // dydx[0,...,n-1] known at x, use the classic 61 // dydx[0,...,n-1] known at x, use the classical 4th Runge-Kutta 64 // method to advance the solution over an inte 62 // method to advance the solution over an interval h and return the 65 // incremented variables as yout[0,...,n-1], w 63 // incremented variables as yout[0,...,n-1], which not be a distinct 66 // array from y. The user supplies the routine 64 // array from y. The user supplies the routine RightHandSide(x,y,dydx), 67 // which returns derivatives dydx at x. The so 65 // which returns derivatives dydx at x. The source is routine rk4 from 68 // NRC p. 712-713 . 66 // NRC p. 712-713 . 69 // << 67 70 void 68 void 71 G4ClassicalRK4::DumbStepper( const G4double yI << 69 G4ClassicalRK4::DumbStepper( const G4double yIn[], 72 const G4double dy << 70 const G4double dydx[], 73 G4double h, << 71 G4double h, 74 G4double yO << 72 G4double yOut[]) 75 { 73 { 76 const G4int nvar = GetNumberOfVariables(); << 74 const G4int nvar = this->GetNumberOfVariables(); // fNumberOfVariables(); 77 G4int i; 75 G4int i; 78 G4double hh = h*0.5, h6 = h/6.0; << 76 G4double hh = h*0.5 , h6 = h/6.0 ; 79 77 80 // Initialise time to t0, needed when it is 78 // Initialise time to t0, needed when it is not updated by the integration. 81 // [ Note: Only for time dependent fi 79 // [ Note: Only for time dependent fields (usually electric) 82 // is it neccessary to inte 80 // is it neccessary to integrate the time.] 83 yt[7] = yIn[7]; 81 yt[7] = yIn[7]; 84 yOut[7] = yIn[7]; 82 yOut[7] = yIn[7]; 85 83 86 for(i=0; i<nvar; ++i) << 84 for(i=0;i<nvar;i++) 87 { 85 { 88 yt[i] = yIn[i] + hh*dydx[i] ; 86 yt[i] = yIn[i] + hh*dydx[i] ; // 1st Step K1=h*dydx 89 } 87 } 90 RightHandSide(yt,dydxt) ; 88 RightHandSide(yt,dydxt) ; // 2nd Step K2=h*dydxt 91 89 92 for(i=0; i<nvar; ++i) << 90 for(i=0;i<nvar;i++) 93 { 91 { 94 yt[i] = yIn[i] + hh*dydxt[i] ; 92 yt[i] = yIn[i] + hh*dydxt[i] ; 95 } 93 } 96 RightHandSide(yt,dydxm) ; 94 RightHandSide(yt,dydxm) ; // 3rd Step K3=h*dydxm 97 95 98 for(i=0; i<nvar; ++i) << 96 for(i=0;i<nvar;i++) 99 { 97 { 100 yt[i] = yIn[i] + h*dydxm[i] ; << 98 yt[i] = yIn[i] + h*dydxm[i] ; 101 dydxm[i] += dydxt[i] ; 99 dydxm[i] += dydxt[i] ; // now dydxm=(K2+K3)/h 102 } 100 } 103 RightHandSide(yt,dydxt) ; 101 RightHandSide(yt,dydxt) ; // 4th Step K4=h*dydxt 104 102 105 for(i=0; i<nvar; ++i) // Final RK4 output << 103 for(i=0;i<nvar;i++) // Final RK4 output 106 { 104 { 107 yOut[i] = yIn[i]+h6*(dydx[i]+dydxt[i]+2.0* 105 yOut[i] = yIn[i]+h6*(dydx[i]+dydxt[i]+2.0*dydxm[i]); //+K1/6+K4/6+(K2+K3)/3 108 } 106 } 109 if ( nvar == 12 ) { NormalisePolarizationVe << 107 // NormaliseTangentVector( yOut ); 110 108 111 } // end of DumbStepper ..................... 109 } // end of DumbStepper .................................................... 112 110 113 ////////////////////////////////////////////// 111 //////////////////////////////////////////////////////////////////// 114 // 112 // 115 // StepWithEst 113 // StepWithEst 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()", << 125 G4Exception("G4ClassicalRK4::StepWithEst()", "ObsoleteMethod", 128 FatalException, "Method no longe 126 FatalException, "Method no longer used."); 129 127 130 } // end of StepWithEst ..................... 128 } // end of StepWithEst ...................................................... >> 129 131 130