Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4ImplicitEuler implementation << 26 // >> 27 // $Id: G4ImplicitEuler.cc,v 1.9 2006-06-29 18:24:11 gunter Exp $ >> 28 // GEANT4 tag $Name: not supported by cvs2svn $ >> 29 // 27 // 30 // 28 // Implicit Euler: 31 // Implicit Euler: 29 // 32 // 30 // x_1 = x_0 + h/2 * ( dx(t_0,x_0) + dx 33 // x_1 = x_0 + h/2 * ( dx(t_0,x_0) + dx(t_0+h,x_0+h*dx(t_0,x_0) ) ) 31 // 34 // 32 // Second order solver. 35 // Second order solver. 33 // Take the current derivative and add it to t 36 // Take the current derivative and add it to the current position. 34 // Take the output and its derivative. Add the 37 // Take the output and its derivative. Add the mean of both derivatives 35 // to form the final output. 38 // to form the final output. 36 // 39 // 37 // Author: W. Wander <wwc@mit.edu>, 12.09.1997 << 40 // W.Wander <wwc@mit.edu> 12/09/97 >> 41 // 38 // ------------------------------------------- 42 // -------------------------------------------------------------------- 39 43 40 #include "G4ImplicitEuler.hh" 44 #include "G4ImplicitEuler.hh" 41 #include "G4ThreeVector.hh" 45 #include "G4ThreeVector.hh" 42 46 43 ////////////////////////////////////////////// 47 ///////////////////////////////////////////////////////////////////////// 44 // 48 // 45 // Constructor 49 // Constructor 46 50 47 G4ImplicitEuler::G4ImplicitEuler(G4EquationOfM << 51 G4ImplicitEuler::G4ImplicitEuler(G4EquationOfMotion *EqRhs, 48 G4int numberO << 52 G4int numberOfVariables): 49 : G4MagErrorStepper(EqRhs, numberOfVariables << 53 G4MagErrorStepper(EqRhs, numberOfVariables) 50 { 54 { 51 unsigned int noVariables = std::max(numberOf << 55 unsigned int noVariables= std::max(numberOfVariables,8); // For Time .. 7+1 52 dydxTemp = new G4double[noVariables] ; 56 dydxTemp = new G4double[noVariables] ; 53 yTemp = new G4double[noVariables] ; 57 yTemp = new G4double[noVariables] ; 54 } 58 } 55 59 56 60 57 ////////////////////////////////////////////// 61 //////////////////////////////////////////////////////////////////////// 58 // 62 // 59 // Destructor 63 // Destructor 60 // << 64 61 G4ImplicitEuler::~G4ImplicitEuler() 65 G4ImplicitEuler::~G4ImplicitEuler() 62 { 66 { 63 delete [] dydxTemp; << 67 delete[] dydxTemp; 64 delete [] yTemp; << 68 delete[] yTemp; 65 } 69 } 66 70 67 ////////////////////////////////////////////// 71 ////////////////////////////////////////////////////////////////////// 68 // 72 // 69 // DumbStepper << 70 // 73 // >> 74 71 void 75 void 72 G4ImplicitEuler::DumbStepper( const G4double y << 76 G4ImplicitEuler::DumbStepper( const G4double yIn[], 73 const G4double d << 77 const G4double dydx[], 74 G4double h << 78 G4double h, 75 G4double y << 79 G4double yOut[]) 76 { 80 { 77 const G4int numberOfVariables = GetNumberOfV << 81 G4int i; >> 82 const G4int numberOfVariables= GetNumberOfVariables(); 78 83 79 // Initialise time to t0, needed when it is 84 // Initialise time to t0, needed when it is not updated by the integration. 80 // << 81 yTemp[7] = yOut[7] = yIn[7]; // Better to 85 yTemp[7] = yOut[7] = yIn[7]; // Better to set it to NaN; // TODO 82 86 83 for( G4int i = 0; i < numberOfVariables; ++i << 87 for( i = 0; i < numberOfVariables; i++ ) 84 { 88 { 85 yTemp[i] = yIn[i] + h*dydx[i] ; 89 yTemp[i] = yIn[i] + h*dydx[i] ; 86 } 90 } 87 91 88 RightHandSide(yTemp,dydxTemp); 92 RightHandSide(yTemp,dydxTemp); 89 93 90 for( G4int i = 0; i < numberOfVariables; ++i << 94 for( i = 0; i < numberOfVariables; i++ ) 91 { 95 { 92 yOut[i] = yIn[i] + 0.5 * h * ( dydx[i] + d 96 yOut[i] = yIn[i] + 0.5 * h * ( dydx[i] + dydxTemp[i] ); 93 } 97 } 94 98 95 return; << 99 return ; 96 } 100 } 97 101