Sequencer Class Reference

#include <sequencer.h>

Collaboration diagram for Sequencer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Sequencer (MonitorWells &)
virtual ~Sequencer ()
void testDynamicModule (DynamicBase &dynMod, TransportBase &transMod)
void testTransport (DynamicBase &dynMod, TransportBase &transMod, double tEnd, double nOutputs)
void alternateIteration (DynamicBase &dynMod, TransportBase &transMod, DiffusiveStep *pDiff, double tEnd, unsigned nDynIterations, unsigned nOutputsPerDynIt)
void alternateIteration (DynamicBase &dynMod, ConservativeMethodForSystem &transMod, FlashBase &flashMod, DiffusiveStep *diff, double tEnd, double nDynIterations, double nOutputs)
void alternateIterationProportionControl (CompressibleDynamic &dynMod, ConservativeMethodForSystem &transMod, FlashBase &flashMod, DiffusiveStep *diff, double tEnd, int maxTransSteps, int maxTransStepsTol, double initialDynDt, double nOutputs)
void diffusiveStepTest (DiffusiveStep &diff, unsigned nIt, double tEnd, unsigned nOutputs)

Private Attributes

MonitorWells_monitor_wells

Detailed Description

This class is responsible for the iteration alghorithms between the Pression module and the transport module

Definition at line 17 of file sequencer.h.


Constructor & Destructor Documentation

Sequencer::Sequencer ( MonitorWells monitor_wells  ) 

Definition at line 19 of file sequencer.cpp.

00020  :_monitor_wells(monitor_wells)
00021 {
00022 }

Sequencer::~Sequencer (  )  [virtual]

Definition at line 25 of file sequencer.cpp.

00026 {
00027         // TODO Auto-generated destructor stub
00028 }


Member Function Documentation

void Sequencer::alternateIteration ( DynamicBase dynMod,
ConservativeMethodForSystem transMod,
FlashBase flashMod,
DiffusiveStep diff,
double  tEnd,
double  nDynIterations,
double  nOutputs 
)

Definition at line 155 of file sequencer.cpp.

00156 {
00157   double dtToPlot = tEnd/nOutputs;
00158   double dt = tEnd/nDynIterations;
00159   double t=0.0;
00160   double timeToPlot = dtToPlot;
00161   flashMod.setTransport(transMod);
00162   flashMod.setDynamic(dynMod);
00163   Timer timer(PROCESSOR_TIME);
00164 
00165 
00166   //Set the current time for the output classes attributes
00167   //sprintf(str,"Simulation Time %lf",t);
00168   //GnuPlotAnim::getGnuPlotAnim().setTitle(str);
00169   HDF5OrthoWriter &hdf5 = HDF5OrthoWriter::getHDF5OrthoWriter();
00170   hdf5.setVariable("Time",0);
00171 
00172  
00173  
00174   
00175   //For each iteration of the dynamic module
00176   for (unsigned i=0;i<nDynIterations;i++)
00177   {
00178     
00179     //Advances the dynamic module
00180     dynMod.iterate(transMod);
00181     //Update the other modules with the information
00182     //of the dynamic module
00183     transMod.updateVelocities(dynMod);
00184     //if (bIsCompressible)
00185     //  transMod.updateBoundaryValues(dynMod,flashMod);
00186 
00187 
00188     //compute the default time step for
00189     //the transport. This computation usually depends
00190     //of the dynamic module data already updated for
00191     //the transport modules.
00192     double dtTrans = transMod.getDt(t,t+dt);
00193     unsigned nIt = round(dt/dtTrans); //number of iterations
00194 
00195     assert( fabs(nIt*dtTrans - dt) < 1.e-10);
00196     printf("Transport Proportion %d\n",nIt);
00197     //For each iteration of the transport
00198     //do one flash calculation
00199     for (unsigned j=0;j<nIt;j++)
00200     {
00201       timer.start();
00202       transMod.iterateN(1,dtTrans);
00203       timer.end();
00204 
00205       
00206       //print Monitor well data
00207       _monitor_wells.outputData(t+dtTrans*(j+1),dynMod,transMod);
00208       
00209       //printf("Transport Time: %s\n",timer.printTime().c_str());
00210       timer.reset();
00211       flashMod.execute();
00212     }
00213 
00214     transMod.updateDataForDynamicModule();
00215     t+=dt;
00216     if (t >= timeToPlot)
00217     {
00218       timeToPlot+=dtToPlot;
00219       printf("Time: %g\n",t);
00220       hdf5.setVariable("Time",t);
00221       dynMod.printOutput();
00222       transMod.printOutput();
00223       flashMod.printOutput();
00224       if (diff)
00225         diff->printOutput();
00226     }
00227     if (diff)
00228     {
00229       diff->iterate(dt);
00230       flashMod.execute();
00231     }
00232   }
00233 }

void Sequencer::alternateIteration ( DynamicBase dynMod,
TransportBase transMod,
DiffusiveStep pDiff,
double  tEnd,
unsigned  nDynIterations,
unsigned  nOutputs 
)

This method alternates sequentially the dynamic, transport and diffusive module. The later is optional. Note that for diffusive step we pass a pointer. If such pointer is NULL the method will not run the Diffusive step. The diffusive step has the same time step as the dynamic module.

Parameters:
dynMod The dynamic module
transMod The module responsible for the transport equation
pDiff The module responsible for diffusive step
tEnd The end time of the simulation. (The time always starts at 0)
nDynIterations Number of dynamic iterations through all the simulation
nOutputs Number of time, the simulator will output data.
Returns:

Definition at line 91 of file sequencer.cpp.

00092 {
00093   
00094   Timer timer(CALENDAR_TIME);      //Lets measure the execution time
00095   double dt = tEnd/nDynIterations; //Get the time step of the dynamic module
00096   double dtToPlot = tEnd/nOutputs; //Defines the time step from plot to plot. 
00097   double timeToPlot = dtToPlot;    //When its time to plot
00098   double t=0.0;
00099   //printf("dt=%g\ndt2=%g\n",dt,dtToPlot);
00100   //Set the current time for the output classes attributes
00101   //sprintf(str,"Simulation Time %lf",t);
00102   //GnuPlotAnim::getGnuPlotAnim().setTitle(str);
00103 
00104 
00105   //Get the HDF5 class to print to hdf file. 
00106   HDF5OrthoWriter &hdf5 = HDF5OrthoWriter::getHDF5OrthoWriter();
00107   //Set the time to plot
00108   hdf5.setVariable("Time",0);
00109 
00110  
00111   
00112   //Iterate the dynamic module
00113   for (unsigned i=0;i<nDynIterations;i++)
00114   {
00115 
00116     timer.start(); //Start to count the time
00117 
00118     dynMod.iterate(transMod); //Advance the dynamic module
00119 
00120     timer.end();  //Plot the time
00121     printf("Dyn Mod Time: %s\n",timer.printTime().c_str());
00122 
00123 
00124     //Now advande the transport module
00125     //First get the velocities from the dynamic module
00126     transMod.updateVelocities(dynMod);
00127 
00128     timer.start();
00129     double dtTrans = transMod.getDt(t,t+dt);
00130     unsigned nIt = round(dt/dtTrans); //number of iterations
00131     transMod.iterateN(nIt,dtTrans);
00132     timer.end();
00133     printf("Transport Time: %s\n",timer.printTime().c_str());
00134     printf("Transport Proportion: %u\n",nIt);
00135     if(pDiff)
00136       pDiff->iterate(dt);
00137 
00138     t+=dt;
00139 
00140     if (t >= timeToPlot)
00141     {
00142       hdf5.setVariable("Time",t);
00143       //Advances the dynamic module
00144       printf("Time Before plot %g\n",t);
00145       transMod.printOutput();
00146       dynMod.printOutput();
00147       if(pDiff)
00148         pDiff->printOutput();
00149       timeToPlot+=dtToPlot;
00150     }
00151   }
00152 }

void Sequencer::alternateIterationProportionControl ( CompressibleDynamic dynMod,
ConservativeMethodForSystem transMod,
FlashBase flashMod,
DiffusiveStep diff,
double  tEnd,
int  maxTransSteps,
int  maxTransStepsTol,
double  initialDynDt,
double  nOutputs 
)

This method do basically the same staggered alghorithm then the alternateIteration method. The only difference is that now this sequencer try to control how many transport steps we iterate per Dynamic Iteration. Note that the transport module set the time step according to the CFL condition and the former is controlled by the Dynamic Module. So we dont know how much dynamic iterations we will have through the simulation before hand. The solution is a tentative and error approach. We start with a dynamic time step (initialDynDt) and then calculate the transport time step. If the number of iterations is greater than maxTransSteps + maxTransStepsTol we rollback by recalculating the dynamic step such that we might have maxTransSteps per iteration.

Parameters:
dynMod Dynamic Module
transMod Transport Module
flashMod Flash Module
tEnd End Time
maxTransSteps Number of transport steps for each dynamic step
maxTransStepsTol Tolerance for maximum transport steps per dynamic step.
initialDynDt Initial time step to try for the Dynamic Module
bIsCompressible If the model is compressible
nOutputs Number of time the program outputs data

Definition at line 286 of file sequencer.cpp.

00287 {
00288   double dtToPlot = tEnd/nOutputs;
00289   double t=0.0;
00290   double timeToPlot = dtToPlot;
00291   flashMod.setTransport(transMod);
00292   flashMod.setDynamic(dynMod);
00293   double dtDyn = initialDynDt;
00294   //Set the current time for the output classes attributes
00295   //sprintf(str,"Simulation Time %lf",t);
00296   //GnuPlotAnim::getGnuPlotAnim().setTitle(str);
00297   HDF5OrthoWriter &hdf5 = HDF5OrthoWriter::getHDF5OrthoWriter();
00298   hdf5.setVariable("Time",0);
00299   int transSteps=0;
00300   double dtTrans;
00301   unsigned nTries=0;
00302   
00303   
00304   //For each iteration of the dynamic module
00305   while (t < tEnd)
00306   {
00307     
00308 
00309     while(1)
00310     {
00311       //Advances the dynamic module
00312       dynMod.setDt(dtDyn);
00313       dynMod.iterate(transMod);
00314 
00315 
00316 
00317       //Update the other modules with the information
00318       //of the dynamic module
00319       transMod.updateVelocities(dynMod);
00320 
00321     
00322     
00323     
00324       //compute the default time step for
00325       //the transport. This computation usually depends
00326       //of the dynamic module data already updated for
00327       //the transport modules.
00328       double dtCFL = transMod.getDt(t,INFINITY);
00329 
00330 
00331       //Get how many transport iterations we need
00332       int nRealTransSteps = ceil(dtDyn/dtCFL);
00333 
00334 
00335       printf("Sequencer Alghorithm\n");
00336       printf("\tdtDyn = %g, dtCFL = %g\n",dtDyn,dtCFL);
00337       printf("\tWe need %d transport steps",nRealTransSteps);
00338       
00339       
00340       
00341       if (nRealTransSteps <= maxTransSteps+maxTransStepsTol)
00342       {
00343         //Ok time to iterate the transport
00344         transSteps=nRealTransSteps;
00345         dtTrans=dtDyn/transSteps;
00346         assert(dtTrans<=dtCFL);
00347         dtDyn=dtCFL*maxTransSteps;
00348         printf("\tAproved in %d tentatives\n",nTries); 
00349         printf("\tdtTrans adjusted to %g\n",dtTrans);
00350         //dynMod.printOutput();
00351         //transMod.printOutput();
00352         //printf("\tNext dtDyn is %g\n",dtDyn);
00353         nTries=0;
00354         break;
00355       }
00356       else //rollback and calculate pressure equation again
00357       {
00358         //printf("\tNot Aproved\n");
00359         dynMod.rollback();
00360         dtDyn=dtCFL*maxTransSteps;
00361         //printf("\tNext dtDyn is %g\n",dtDyn);
00362         nTries++;
00363       }
00364     }      
00365     
00366     
00367     //For each iteration of the transport
00368     //do one flash calculation
00369     for (int j=0;j<transSteps;j++)
00370     {
00371       transMod.iterateN(1,dtTrans);
00372       flashMod.execute();
00373       t+=dtTrans;
00374       if (t >= timeToPlot)
00375       {
00376         timeToPlot+=dtToPlot;
00377         printf("Time: %g\n",t);
00378         hdf5.setVariable("Time",t);
00379         dynMod.printOutput();
00380         transMod.printOutput();
00381         flashMod.printOutput();
00382       }
00383     }
00384     if (diff)
00385     {
00386       diff->iterate(dtDyn);
00387       flashMod.execute();
00388     }
00389     transMod.updateDataForDynamicModule();
00390   }
00391 }

void Sequencer::diffusiveStepTest ( DiffusiveStep diff,
unsigned  nIt,
double  tEnd,
unsigned  nOutputs 
)

Definition at line 395 of file sequencer.cpp.

00396 {
00397   double dt = tEnd/nIt;
00398   double dtToPlot = tEnd/nOutputs;
00399   double timeToPlot = dtToPlot;
00400   double t=0.0;
00401   printf("dt=%g\ndt2=%g\n",dt,dtToPlot);
00402   //Set the current time for the output classes attributes
00403   //sprintf(str,"Simulation Time %lf",t);
00404   //GnuPlotAnim::getGnuPlotAnim().setTitle(str);
00405   HDF5OrthoWriter &hdf5 = HDF5OrthoWriter::getHDF5OrthoWriter();
00406 
00407   hdf5.setVariable("Time",0);
00408 
00409  
00410   
00411   //Iterate the dynamic module
00412   for (unsigned i=0;i<nIt;i++)
00413   {
00414     diff.iterate(dt);
00415     
00416     
00417     t+=dt;
00418 
00419     if (t >= timeToPlot)
00420     {
00421       hdf5.setVariable("Time",t);
00422       diff.printOutput();
00423     }
00424   }
00425   
00426 }

void Sequencer::testDynamicModule ( DynamicBase dynMod,
TransportBase transMod 
)

Definition at line 236 of file sequencer.cpp.

00237 {
00238   //Set the current time for the output classes attributes
00239   //sprintf(str,"Simulation Time %lf",t);
00240   //GnuPlotAnim::getGnuPlotAnim().setTitle(str);
00241   HDF5OrthoWriter &hdf5 = HDF5OrthoWriter::getHDF5OrthoWriter();
00242   hdf5.setVariable("Time",0);
00243 
00244   //GnuPlotAnim &plot = GnuPlotAnim::getGnuPlotAnim();
00245   //plot.setTitle("Time = 0");
00246   Timer time(CALENDAR_TIME);
00247 
00248   time.start();
00249   dynMod.iterate(transMod);
00250   time.end();
00251   printf("Time spent in the Dynamic Module: %s\n",time.printTime().c_str());
00252 
00253   
00254   dynMod.printOutput();
00255   
00256   return;
00257   
00258 }

void Sequencer::testTransport ( DynamicBase dynMod,
TransportBase transMod,
double  tEnd,
double  nOutputs 
)

This method is used mainly to test the transport. It runs the DynamicModule just once to get a velocity field, then it iterates the transport module until the end of the simulation using this velocity field freezed in the time step 0.

Parameters:
tEnd Final time
nOutputs Number of data outputs of the transport module
dynMod Dynamic Module to be runned
transMod Transport Module to be runned
Returns:

Definition at line 40 of file sequencer.cpp.

00041 {
00042   char str[500];
00043   double dt = tEnd/nOutputs;
00044   double t=0.0;
00045 
00046   //dynMod.printOutput();
00047   //throw new Exception("FIM");
00048   //Advances the dynamic module
00049   dynMod.iterate(transMod);
00050   transMod.updateVelocities(dynMod);
00051   dynMod.printOutput();
00052   
00053 
00054  
00055   
00056   //Iterate the transport
00057   for (unsigned i=0;i<nOutputs;i++)
00058   {
00059     Timer time(PROCESSOR_TIME);
00060     time.start();
00061     double dtTrans = transMod.getDt(t,t+dt);
00062     unsigned nIt = round(dt/dtTrans); //number of iterations
00063     transMod.iterateN(nIt,dtTrans);
00064     time.end();
00065     printf("Time spent in the transport: %s\n",time.printTime().c_str());
00066 
00067 
00068     t+=dt;
00069 
00070     //Set the current time for the output classes attributes
00071     sprintf(str,"Simulation Time %lf",t);
00072     HDF5OrthoWriter &hdf5 = HDF5OrthoWriter::getHDF5OrthoWriter();
00073 
00074     hdf5.setVariable("Time",t);
00075 
00076     transMod.printOutput();
00077   }
00078 }


Member Data Documentation

Definition at line 20 of file sequencer.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Sun Apr 8 23:13:29 2012 for CO2INJECTION by  doxygen 1.6.3