00001 // RK2TMover.cpp: implementation of the CRK2TMover class. 00002 // 00004 00005 #include "RK2TMover.h" 00006 00008 // Construction/Destruction 00010 00011 CRK2TMover::CRK2TMover() 00012 { 00013 00014 } 00015 00016 CRK2TMover::CRK2TMover(double frequency, double stepSize) 00017 :CRungeKuttaMover(frequency,stepSize) 00018 { 00019 00020 } 00021 00022 CRK2TMover::~CRK2TMover() 00023 { 00024 00025 } 00026 00028 // This function takes a second-order trapezoidal RK step. 00030 00031 void CRK2TMover::RungeKuttaStep(int nRHS, double *y, double *dydt) 00032 { 00033 int i; 00034 double *yTemp = new double[nRHS]; 00035 double *dydtTemp = new double[nRHS]; 00036 double halfStep = 0.5*m_dStepSize; 00037 00038 // beginning of interval 00039 ComputeDerivatives(y,dydt); 00040 for(i = 0; i < nRHS; i++) 00041 { 00042 yTemp[i] = y[i] + halfStep*dydt[i]; 00043 } 00044 00045 // step forward 00046 ComputeDerivatives(yTemp,dydtTemp); 00047 00048 // update y(t) to y(t+h) 00049 for(i = 0; i < nRHS; i++) 00050 { 00051 y[i] = y[i] + halfStep*(dydt[i] + dydtTemp[i]); 00052 } 00053 00054 // free memory 00055 delete [] yTemp; 00056 delete [] dydtTemp; 00057 }