00001
00002
00003
00004
00005
00006
00007
00008 #include "sequencer.h"
00009 #include "exception.h"
00010 #include "hdf5dealwriter.h"
00011 #include "conservativemethodforsystem.h"
00012 #include "hdf5orthowriter.h"
00013 #include "timer.h"
00014 #include "timer.h"
00015 #include <math.h>
00016 #include "diffusivestep.h"
00017 #include "flashcompositional.h"
00018
00019 Sequencer::Sequencer(MonitorWells &monitor_wells)
00020 :_monitor_wells(monitor_wells)
00021 {
00022 }
00023
00024
00025 Sequencer::~Sequencer()
00026 {
00027
00028 }
00029
00040 void Sequencer::testTransport(DynamicBase &dynMod,TransportBase &transMod,double tEnd,double nOutputs)
00041 {
00042 char str[500];
00043 double dt = tEnd/nOutputs;
00044 double t=0.0;
00045
00046
00047
00048
00049 dynMod.iterate(transMod);
00050 transMod.updateVelocities(dynMod);
00051 dynMod.printOutput();
00052
00053
00054
00055
00056
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);
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
00071 sprintf(str,"Simulation Time %lf",t);
00072 HDF5OrthoWriter &hdf5 = HDF5OrthoWriter::getHDF5OrthoWriter();
00073
00074 hdf5.setVariable("Time",t);
00075
00076 transMod.printOutput();
00077 }
00078 }
00079
00091 void Sequencer::alternateIteration(DynamicBase &dynMod,TransportBase &transMod,DiffusiveStep *pDiff,double tEnd,unsigned nDynIterations,unsigned nOutputs)
00092 {
00093
00094 Timer timer(CALENDAR_TIME);
00095 double dt = tEnd/nDynIterations;
00096 double dtToPlot = tEnd/nOutputs;
00097 double timeToPlot = dtToPlot;
00098 double t=0.0;
00099
00100
00101
00102
00103
00104
00105
00106 HDF5OrthoWriter &hdf5 = HDF5OrthoWriter::getHDF5OrthoWriter();
00107
00108 hdf5.setVariable("Time",0);
00109
00110
00111
00112
00113 for (unsigned i=0;i<nDynIterations;i++)
00114 {
00115
00116 timer.start();
00117
00118 dynMod.iterate(transMod);
00119
00120 timer.end();
00121 printf("Dyn Mod Time: %s\n",timer.printTime().c_str());
00122
00123
00124
00125
00126 transMod.updateVelocities(dynMod);
00127
00128 timer.start();
00129 double dtTrans = transMod.getDt(t,t+dt);
00130 unsigned nIt = round(dt/dtTrans);
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
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 }
00153
00154
00155 void Sequencer::alternateIteration(DynamicBase &dynMod,ConservativeMethodForSystem &transMod,FlashBase &flashMod,DiffusiveStep *diff,double tEnd,double nDynIterations,double nOutputs)
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
00167
00168
00169 HDF5OrthoWriter &hdf5 = HDF5OrthoWriter::getHDF5OrthoWriter();
00170 hdf5.setVariable("Time",0);
00171
00172
00173
00174
00175
00176 for (unsigned i=0;i<nDynIterations;i++)
00177 {
00178
00179
00180 dynMod.iterate(transMod);
00181
00182
00183 transMod.updateVelocities(dynMod);
00184
00185
00186
00187
00188
00189
00190
00191
00192 double dtTrans = transMod.getDt(t,t+dt);
00193 unsigned nIt = round(dt/dtTrans);
00194
00195 assert( fabs(nIt*dtTrans - dt) < 1.e-10);
00196 printf("Transport Proportion %d\n",nIt);
00197
00198
00199 for (unsigned j=0;j<nIt;j++)
00200 {
00201 timer.start();
00202 transMod.iterateN(1,dtTrans);
00203 timer.end();
00204
00205
00206
00207 _monitor_wells.outputData(t+dtTrans*(j+1),dynMod,transMod);
00208
00209
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 }
00234
00235
00236 void Sequencer::testDynamicModule(DynamicBase &dynMod,TransportBase &transMod)
00237 {
00238
00239
00240
00241 HDF5OrthoWriter &hdf5 = HDF5OrthoWriter::getHDF5OrthoWriter();
00242 hdf5.setVariable("Time",0);
00243
00244
00245
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 }
00259
00286 void Sequencer::alternateIterationProportionControl(CompressibleDynamic &dynMod,ConservativeMethodForSystem &transMod,FlashBase &flashMod,DiffusiveStep *diff,double tEnd,int maxTransSteps, int maxTransStepsTol, double initialDynDt,double nOutputs)
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
00295
00296
00297 HDF5OrthoWriter &hdf5 = HDF5OrthoWriter::getHDF5OrthoWriter();
00298 hdf5.setVariable("Time",0);
00299 int transSteps=0;
00300 double dtTrans;
00301 unsigned nTries=0;
00302
00303
00304
00305 while (t < tEnd)
00306 {
00307
00308
00309 while(1)
00310 {
00311
00312 dynMod.setDt(dtDyn);
00313 dynMod.iterate(transMod);
00314
00315
00316
00317
00318
00319 transMod.updateVelocities(dynMod);
00320
00321
00322
00323
00324
00325
00326
00327
00328 double dtCFL = transMod.getDt(t,INFINITY);
00329
00330
00331
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
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
00351
00352
00353 nTries=0;
00354 break;
00355 }
00356 else
00357 {
00358
00359 dynMod.rollback();
00360 dtDyn=dtCFL*maxTransSteps;
00361
00362 nTries++;
00363 }
00364 }
00365
00366
00367
00368
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 }
00392
00393
00394
00395 void Sequencer::diffusiveStepTest(DiffusiveStep &diff,unsigned nIt,double tEnd,unsigned nOutputs)
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
00403
00404
00405 HDF5OrthoWriter &hdf5 = HDF5OrthoWriter::getHDF5OrthoWriter();
00406
00407 hdf5.setVariable("Time",0);
00408
00409
00410
00411
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 }