00001 // RungeKuttaMover.cpp: implementation of the CRungeKuttaMover class. 00002 // 00004 00005 #include "RungeKuttaMover.h" 00006 00008 // Construction/Destruction 00010 00011 CRungeKuttaMover::CRungeKuttaMover() 00012 { 00013 00014 } 00015 00016 CRungeKuttaMover::CRungeKuttaMover(double frequency,double stepSize) 00017 :CDifferentialEquationMover(frequency,stepSize) 00018 { 00019 00020 } 00021 00022 CRungeKuttaMover::~CRungeKuttaMover() 00023 { 00024 00025 } 00026 00027 void CRungeKuttaMover::Move(double xInitial, double xFinal, ReactionNetwork *pReactionNetwork) 00028 { 00029 double xInterval = xFinal-xInitial; 00030 if(this->MoveTimeIsZero(xInterval)) {return;} 00031 if(m_dStepSize > xInterval) {m_dStepSize = xInterval;} 00032 00033 // set the member pointer to the network pointer passed in 00034 this->m_pReactionNetwork = pReactionNetwork; 00035 00036 int dataCnt=0; 00037 int nChem = m_pReactionNetwork->GetNumberOfChemicals(); 00038 double *chem = new double[nChem]; 00039 double *dChemdt = new double[nChem]; 00040 int freq = 1/m_dStepSize; 00041 00042 double nextTime = xInitial; 00043 00044 m_dTime = xInitial; 00045 // may be unsafe if xInitial has a fractional part! Most likely the storage of time 00046 // series data will be altered before this is a problem. 00047 m_iCount = (int) xInitial; 00048 00049 for (int cNum = 0; cNum < nChem; cNum++) 00050 { 00051 chem[cNum] = m_pReactionNetwork->GetChemical(cNum)->GetAmount(); 00052 } 00053 00054 while(m_dTime < xFinal) 00055 { 00056 while(m_dTime < nextTime) 00057 { 00058 RungeKuttaStep(nChem,chem,dChemdt); 00059 m_dTime += m_dStepSize; 00060 } 00061 00062 //dataCnt++; 00063 00064 //if ( ((dataCnt-1) % freq) == 0 ) 00065 //if(m_dTime == nextTime) 00066 //{ 00067 m_iCount++; 00068 // before notification, make sure chemical conc. are current 00069 for(int i = 0; i < nChem; i++) 00070 { 00071 m_pReactionNetwork->GetChemical(i)->SetAmount(chem[i]); 00072 } 00073 Notify(); // Notify observers of end of time step 00074 nextTime += 1.0; 00075 //} 00076 00077 //RungeKuttaStep(nChem,chem,dChemdt); 00078 //m_dTime += m_dStepSize; 00079 } 00080 00081 00082 // free memory 00083 00084 delete [] chem; 00085 delete [] dChemdt; 00086 }