00001
00002
00004
00005 #include "SynchronizedCashKarpMover.h"
00006
00008
00010
00011 CSynchronizedCashKarpMover::CSynchronizedCashKarpMover(double frequency, double stepSize, double eps)
00012 :CQualityControlCashKarpMover(frequency,stepSize,eps)
00013 {
00014 m_bSyncFlag = false;
00015 }
00016
00017 CSynchronizedCashKarpMover::~CSynchronizedCashKarpMover()
00018 {
00019
00020 }
00021
00022 void CSynchronizedCashKarpMover::Move(double xInitial, double xFinal, ReactionNetwork *pReactionNetwork)
00023 {
00024 int i;
00025
00026 double xInterval = xFinal-xInitial;
00027 if(this->MoveTimeIsZero(xInterval)) {return;}
00028 if(m_dInitialStepSize > xInterval) {m_dInitialStepSize = xInterval;}
00029
00030 this->SetMinStepSize(xInterval);
00031 this->SetMaxStepSize(0.0);
00032 m_iTotalStepsTaken = 0;
00033
00034
00035 m_pReactionNetwork = pReactionNetwork;
00036 m_dTime = xInitial;
00037 m_iCount = (int) xInitial;
00038 m_dStepSize = m_dLastStep = m_dNextStep = m_dInitialStepSize;
00039
00040 double nextTime = m_dTime;
00041 int nChem = m_pReactionNetwork->GetNumberOfChemicals();
00042 double *chem = new double[nChem];
00043 double *dChemdt = new double[nChem];
00044 m_pdScale = new double[nChem];
00045 m_pdError = new double[nChem];
00046
00047
00048 for(i = 0; i < nChem; i++)
00049 {
00050 chem[i] = m_pReactionNetwork->GetChemical(i)->GetAmount();
00051 }
00052
00053
00054
00055 int stepCounter = 0;
00056
00057 while(m_dTime < xFinal)
00058 {
00059
00060 while(m_dTime < nextTime)
00061 {
00062 if((m_bSyncFlag == false) || (m_vdSteps.size() == 0))
00063 {
00064
00065 ComputeDerivatives(chem,dChemdt);
00066
00067
00068
00069 for(i = 0; i < nChem; i++)
00070 {
00071 m_pdScale[i] = fabs(chem[i]) + fabs(m_dStepSize*dChemdt[i]) + m_scdTINY;
00072 }
00073
00074
00075 if( ((m_dTime + m_dNextStep) - nextTime) > 0.0 )
00076 {
00077 m_dNextStep = nextTime-m_dTime;
00078 }
00079
00080
00081 Stepper(nChem,chem,dChemdt);
00082
00083 m_vdSteps.push_back(m_dLastStep);
00084
00085
00086 if(m_dLastStep < this->GetMinStepSize()) {this->SetMinStepSize(m_dLastStep);}
00087 if(m_dLastStep > this->GetMaxStepSize()) {this->SetMaxStepSize(m_dLastStep);}
00088 this->IncrementTotalSteps();
00089 }
00090 else
00091 {
00092 ComputeDerivatives(chem,dChemdt);
00093 m_dStepSize = m_vdSteps[stepCounter];
00094 stepCounter++;
00095 CashKarpStep(nChem,chem,dChemdt);
00096 m_dTime += m_dStepSize;
00097 }
00098 }
00099
00100
00101 for(int i = 0; i < nChem; i++)
00102 {
00103 m_pReactionNetwork->GetChemical(i)->SetAmount(chem[i]);
00104 }
00105
00106 m_iCount++;
00107 Notify();
00108 nextTime += 1.0;
00109
00110 }
00111
00112 delete [] chem;
00113 delete [] dChemdt;
00114 delete [] m_pdScale;
00115 delete [] m_pdError;
00116
00117
00118
00119 m_bSyncFlag = true;
00120 }