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

EnsembleRunDirector.cpp

Go to the documentation of this file.
00001 // EnsembleRunDirector.cpp: implementation of the CEnsembleRunDirector class.
00002 //
00004 
00005 #include "EnsembleRunDirector.h"
00006 
00008 // Construction/Destruction
00010 
00011 CEnsembleRunDirector::CEnsembleRunDirector(int ensembleSize)
00012 {
00013         m_iEnsembleSize = ensembleSize;
00014 }
00015 
00016 CEnsembleRunDirector::~CEnsembleRunDirector()
00017 {
00018         int i;
00019         for(i = 0; i < m_vpdEnsembleParameters.size(); i++)
00020         {
00021                 delete [] m_vpdEnsembleParameters[i];
00022         }
00023         for(i = 0; i < m_vpdSumC.size(); i++)
00024         {
00025                 delete [] m_vpdSumC[i][0];
00026                 delete [] m_vpdSumC[i];
00027                 delete [] m_vpdSumCSqr[i][0];
00028                 delete [] m_vpdSumCSqr[i];
00029         }
00030         for(i = 0; i < m_vpEnsemblePlotters.size(); i++)
00031         {
00032                 delete m_vpEnsemblePlotters[i];
00033         }
00034 }
00035 
00036 void CEnsembleRunDirector::SumAllocate()
00037 {
00038         // runnables
00039         for(int i = 0; i < m_vpRunnables.size(); i++)
00040         {
00041                 int nSteps = m_vpRunnables[i]->GetCellObserver()->GetNumberOfTimeSteps();
00042                 int nChem = m_vpRunnables[i]->GetReactionNetwork()->GetNumberOfChemicals();
00043                 m_vpdSumC.push_back(new double *[nChem]);
00044                 m_vpdSumCSqr.push_back(new double *[nChem]);
00045                 m_vpdSumC[i][0] = new double[nChem*nSteps];
00046                 m_vpdSumCSqr[i][0] = new double[nChem*nSteps];
00047                 for(int chem = 1; chem < nChem; chem++)
00048                 {
00049                         m_vpdSumC[i][chem] = &(m_vpdSumC[i][0][chem*nSteps]);
00050                         m_vpdSumCSqr[i][chem] = &(m_vpdSumCSqr[i][0][chem*nSteps]);
00051                 }
00052                 // zero the array just created
00053                 for(int l = 0; l < nChem; l++)
00054                 {
00055                         for(int m = 0; m < nSteps; m++)
00056                         {
00057                                 m_vpdSumC[i][l][m] = 0;
00058                                 m_vpdSumCSqr[i][l][m] = 0;
00059                         }
00060                 }
00061         }
00062 }
00063 
00064 void CEnsembleRunDirector::LoadEnsembleInfo(std::string parameterFile)
00065 {
00066         // read in the vectors of parameters
00067         int nRC = m_vpRunnables[0]->GetReactionNetwork()->GetNumberOfRateConstants();
00068         ParameterReader *pEnsReader = new ParameterReader(parameterFile.c_str());
00069         for(int i = 0; i < m_iEnsembleSize; i++)
00070         {
00071                 m_vpdEnsembleParameters.push_back(new double[nRC]);
00072                 for(int j = 0; j < nRC; j++)
00073                 {
00074                         double parameter = pEnsReader->ReadParameter();
00075                         m_vpdEnsembleParameters[i][j] = parameter;
00076                 }
00077         }
00078         delete pEnsReader;
00079 
00080         return;
00081 }
00082 
00083 void CEnsembleRunDirector::Execute()
00084 {
00085         // run over all runnables for each ensemble member
00086         for(int eCount = 0; eCount < m_iEnsembleSize; eCount++)
00087         {
00088                 // run all the runnables
00089                 for(int i = 0; i < m_vpRunnables.size(); i++)
00090                 {
00091                         // set the parameters to the correct ensemble parameters
00092                         int nRC = m_vpRunnables[i]->GetReactionNetwork()->GetNumberOfRateConstants();
00093                         for(int j = 0; j < nRC; j++)
00094                         {
00095                                 double rate = m_vpdEnsembleParameters[eCount][j];
00096                                 m_vpRunnables[i]->GetReactionNetwork()->GetRateConstant(j)->SetRateConstant(rate);
00097                         }
00098                 
00099                         // run the simulation
00100                         m_vpRunnables[i]->Run();
00101                         
00102                         // now increment the statistical arrays; each curve is normalized so 
00103                         // so that C(tmax) = 1.0
00104                         int nChem = m_vpRunnables[i]->GetReactionNetwork()->GetNumberOfChemicals();
00105                         int nSteps = m_vpRunnables[i]->GetCellObserver()->GetNumberOfTimeSteps();
00106                         for(int cCount = 0; cCount < nChem; cCount++)
00107                         {
00108                                 double norm = m_vpRunnables[i]->GetCellObserver()->GetAverageConcentration()[cCount][nSteps-1];
00109                                 for(int sCount = 0; sCount < nSteps; sCount++)
00110                                 {
00111                                         double conc = m_vpRunnables[i]->GetCellObserver()->GetAverageConcentration()[cCount][sCount];
00112                                         m_vpdSumC[i][cCount][sCount] += conc/norm;
00113                                         m_vpdSumCSqr[i][cCount][sCount] += (conc/norm)*(conc/norm);
00114                                 }
00115                         }
00116                 }
00117                 // XXX debug
00118                 cout << "Ensemble member " << eCount << " run." << endl;
00119         }
00120 
00121         // convert the sums/squared sums to average/std. dev.
00122         ConvertToStatistics();
00123         // Notify observers
00124         Notify();
00125 
00126         return;
00127 }
00128 
00129 void CEnsembleRunDirector::ConvertToStatistics()
00130 {
00131         // now convert all the arrays
00132         for(int i = 0; i < m_vpRunnables.size(); i++)
00133         {
00134                 int nChem = m_vpRunnables[i]->GetReactionNetwork()->GetNumberOfChemicals();
00135                 int nSteps = m_vpRunnables[i]->GetCellObserver()->GetNumberOfTimeSteps();
00136                 for(int chem = 0; chem < nChem; chem++)
00137                 {
00138                         for(int step = 0; step < nSteps; step++)
00139                         {
00140                                 // find averages
00141                                 m_vpdSumC[i][chem][step] = m_vpdSumC[i][chem][step]/m_iEnsembleSize;
00142                                 m_vpdSumCSqr[i][chem][step] = m_vpdSumCSqr[i][chem][step]/m_iEnsembleSize;
00143                                 // convert sum(C^2) to sigma
00144                                 m_vpdSumCSqr[i][chem][step] -= m_vpdSumC[i][chem][step]*m_vpdSumC[i][chem][step];
00145                                 m_vpdSumCSqr[i][chem][step] = sqrt(m_vpdSumCSqr[i][chem][step]);
00146                         }
00147                 }
00148         }
00149         
00150         cout << "Sum arrays converted to <C> and sigma(C)" << endl;
00151 }

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