![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsODESolverRungeKutta4.cpp 00003 ******************************************************************************/ 00007 /****************************************************************************** 00008 SUKITTI PUNAK (07/10/2005) 00009 UPDATE (08/18/2010) 00010 ******************************************************************************/ 00011 #include "TAPsODESolverRungeKutta4.hpp" 00012 // Using Inclusion Model (i.e. definitions are included in declarations) 00013 // (this name.cpp is included in name.hpp) 00014 // Each friend is defined directly inside its declaration. 00015 00016 00017 BEGIN_NAMESPACE_TAPs__Simulation 00018 //============================================================================= 00019 //----------------------------------------------------------------------------- 00020 template <typename T, typename T_SET> 00021 ODESolverRungeKutta4<T, T_SET>::ODESolverRungeKutta4 () : ODESolver<T, T_SET>() {} 00022 //------------------------------------------------------------------- 00023 template <typename T, typename T_SET> 00024 ODESolverRungeKutta4<T, T_SET>::~ODESolverRungeKutta4 () {} 00025 //------------------------------------------------------------------- 00026 template <typename T, typename T_SET> 00027 void ODESolverRungeKutta4<T, T_SET>::SetSize ( int vectorSize ) 00028 { 00029 vK1.resize( vectorSize ); 00030 vK2.resize( vectorSize ); 00031 vK3.resize( vectorSize ); 00032 vK4.resize( vectorSize ); 00033 } 00034 //------------------------------------------------------------------- 00035 template <typename T, typename T_SET> 00036 void ODESolverRungeKutta4<T, T_SET>::Solve ( 00037 VectorSet<T_SET> &x0, // i/p: x(t_0) an initial state vector 00038 VectorSet<T_SET> &xEnd, // o/p: x(t_1) an end state vector 00039 T t0, T t1, // i/p: starting and ending times 00040 DerivFunc dxdt, // i/p: a derivative function 00041 void *userData // o/p: array of user data 00042 ) 00043 { 00044 bool restartNotRequired = true; 00045 T h = t1 - t0; 00046 T half = static_cast<T>( 0.5 ); 00047 // Runge-Kutta of Order 4 00048 restartNotRequired = dxdt( t0, x0, vK1, userData ); 00049 vK1 *= h; 00050 assert( restartNotRequired ); 00051 restartNotRequired = dxdt( t0 + h*half, x0 + vK1*half, vK2, userData ); 00052 vK2 *= h; 00053 assert( restartNotRequired ); 00054 restartNotRequired = dxdt( t0 + h*half, x0 + vK2*half, vK3, userData ); 00055 vK3 *= h; 00056 assert( restartNotRequired ); 00057 restartNotRequired = dxdt( t0 + h, x0 + vK3, vK4, userData ); 00058 vK4 *= h; 00059 assert( restartNotRequired ); 00060 // Update the state 00061 xEnd = x0 + vK1/static_cast<T>(6) 00062 + vK2/static_cast<T>(3) 00063 + vK3/static_cast<T>(3) 00064 + vK4/static_cast<T>(6); 00065 } 00066 //------------------------------------------------------------------- 00067 //template <typename T, typename T_SET> 00068 //void ODESolverRungeKutta4<T, T_SET>::Solve_ForPtrData ( 00069 // VectorSetPtr<T_SET,T> &x0, // i/p: x(t_0) an initial state vector 00070 // VectorSetPtr<T_SET,T> &xEnd, // o/p: x(t_1) an end state vector 00071 // T t0, T t1, // i/p: starting and ending times 00072 // DerivFunc_ForPtrData dxdt, // i/p: a derivative function 00073 // void *userData // o/p: array of user data 00074 //) 00075 //{ 00076 //} 00077 //----------------------------------------------------------------------------- 00078 //============================================================================= 00079 END_NAMESPACE_TAPs__Simulation 00080 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00081 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----