Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

SynchronizedCashKarpMover.cpp

Go to the documentation of this file.
00001 // SynchronizedCashKarpMover.cpp: implementation of the CSynchronizedCashKarpMover class.
00002 //
00004 
00005 #include "SynchronizedCashKarpMover.h"
00006 
00008 // Construction/Destruction
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         // do a couple of checks on the integration interval
00026         double xInterval = xFinal-xInitial;
00027         if(this->MoveTimeIsZero(xInterval)) {return;}
00028         if(m_dInitialStepSize > xInterval) {m_dInitialStepSize = xInterval;}
00029         // set min step size to be equal to xInterval at start and max to zero
00030         this->SetMinStepSize(xInterval);
00031         this->SetMaxStepSize(0.0);
00032         m_iTotalStepsTaken = 0;
00033 
00034         // set the member pointer equal to the pointer passed in
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         // fill chem[] with starting chemical concentrations
00048         for(i = 0; i < nChem; i++)
00049         {
00050                 chem[i] = m_pReactionNetwork->GetChemical(i)->GetAmount();
00051         }
00052 
00053         // the first call of Move() sets the series of stepsizes, and all subsequent calls
00054         // use those stepsizes
00055         int stepCounter = 0;
00056 
00057         while(m_dTime < xFinal)
00058         {
00059                 // run until xFinal
00060                 while(m_dTime < nextTime)
00061                 {
00062                         if((m_bSyncFlag == false) || (m_vdSteps.size() == 0))
00063                         {
00064                                 // get initial derivatives
00065                                 ComputeDerivatives(chem,dChemdt);
00066                                 // compute scaling vector
00067                                 // __max is to ensure chemicals that start at ~ 0 don't get
00068                                 // huge scaling factors, which screws up the stepper
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                                 // don't run over
00075                                 if( ((m_dTime + m_dNextStep) - nextTime) > 0.0 )        
00076                                 {
00077                                         m_dNextStep = nextTime-m_dTime;
00078                                 }
00079                         
00080                                 // call the stepper
00081                                 Stepper(nChem,chem,dChemdt);
00082                                 // put size of successful step onto list
00083                                 m_vdSteps.push_back(m_dLastStep);
00084 
00085                                 // record largest/smallest/numsteps info
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                 // ensure synchrony with chem and network
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         // returning after first integration sets this flag to true; 
00118         // subsequent integrations don't affect this
00119         m_bSyncFlag = true;
00120 }

Generated on Mon Nov 3 09:38:17 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002