opm-simulators
simulator.hh
Go to the documentation of this file.
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 /*
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 2 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 
19  Consult the COPYING file in the top-level source directory of this
20  module for the precise wording of the license and the list of
21  copyright holders.
22 */
28 #ifndef EWOMS_SIMULATOR_HH
29 #define EWOMS_SIMULATOR_HH
30 
31 #if HAVE_MPI
32 #define RESERVOIR_COUPLING_ENABLED
33 #endif
34 #ifdef RESERVOIR_COUPLING_ENABLED
35 #include <opm/simulators/flow/rescoup/ReservoirCouplingMaster.hpp>
36 #include <opm/simulators/flow/rescoup/ReservoirCouplingSlave.hpp>
37 #endif
38 
39 #include <dune/common/parallel/mpihelper.hh>
40 
42 
44 
48 #include <opm/models/utils/simulatorutils.hpp>
51 
52 #include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
53 
54 #include <algorithm>
55 #include <cassert>
56 #include <iostream>
57 #include <limits>
58 #include <memory>
59 #include <string>
60 #include <vector>
61 
62 namespace Opm {
63 
64  // required as std::max is not constexpr for float128 / quads.
65  template <typename T>
66  static constexpr T constexpr_max(T a, T b) {
67  return (a > b) ? a : b;
68  }
69 
82 template <class TypeTag>
83 class Simulator
84 {
90 
91  using MPIComm = typename Dune::MPIHelper::MPICommunicator;
92  using Communication = Dune::Communication<MPIComm>;
93 
94  // \Note: too small eps can not rule out confusion from the rounding errors, as we use 1.e-9 as a minimum.
95  static constexpr Scalar eps =
96  constexpr_max(std::numeric_limits<Scalar>::epsilon(), static_cast<Scalar>(1.0e-9));
97 
98 public:
99  // do not allow to copy simulators around
100  Simulator(const Simulator&) = delete;
101 
102  explicit Simulator(bool verbose = true)
103  : Simulator(Communication(), verbose)
104  {
105  }
106 
107  explicit Simulator(Communication comm, bool verbose = true)
108  {
109  TimerGuard setupTimerGuard(setupTimer_);
110 
111  setupTimer_.start();
112 
113  verbose_ = verbose && comm.rank() == 0;
114 
115  timeStepIdx_ = 0;
116  startTime_ = 0.0;
117  time_ = 0.0;
118  endTime_ = Parameters::Get<Parameters::EndTime<Scalar>>();
119  timeStepSize_ = Parameters::Get<Parameters::InitialTimeStepSize<Scalar>>();
120  assert(timeStepSize_ > 0);
121  const std::string& predetTimeStepFile =
122  Parameters::Get<Parameters::PredeterminedTimeStepsFile>();
123  if (!predetTimeStepFile.empty()) {
124  forcedTimeSteps_ = readTimeStepFile<Scalar>(predetTimeStepFile);
125  }
126  truncateTimeStepToFloat_ = Parameters::Get<Parameters::TruncateTimeStepToFloat>();
127 
128  episodeIdx_ = 0;
129  episodeStartTime_ = 0;
130  episodeLength_ = std::numeric_limits<Scalar>::max();
131 
132  finished_ = false;
133 
134  if (verbose_) {
135  std::cout << "Allocating the simulation vanguard\n" << std::flush;
136  }
137 
138  {
139  OPM_BEGIN_PARALLEL_TRY_CATCH();
140  vanguard_ = std::make_unique<Vanguard>(*this);
141  OPM_END_PARALLEL_TRY_CATCH("Allocating the simulation vanguard failed: ", comm);
142  }
143 
144  if (verbose_) {
145  std::cout << "Distributing the vanguard's data\n" << std::flush;
146  }
147 
148  {
149  OPM_BEGIN_PARALLEL_TRY_CATCH();
150  vanguard_->loadBalance();
151  OPM_END_PARALLEL_TRY_CATCH("Could not distribute the vanguard data: ", comm);
152  }
153 
154  // Only relevant for CpGrid and serial runs.
155  if (verbose_) {
156  std::cout << "Adding LGRs, if any, in serial run\n" << std::flush;
157  }
158 
159  {
160  OPM_BEGIN_PARALLEL_TRY_CATCH();
161  vanguard_->addLgrs();
162  OPM_END_PARALLEL_TRY_CATCH("Adding LGRs to the simulation vanguard in serial run failed: ", comm);
163  }
164 
165  if (verbose_) {
166  std::cout << "Allocating the model\n" << std::flush;
167  }
168 
169  {
170  OPM_BEGIN_PARALLEL_TRY_CATCH();
171  model_ = std::make_unique<Model>(*this);
172  OPM_END_PARALLEL_TRY_CATCH("Could not allocate model: ", comm);
173  }
174 
175  if (verbose_) {
176  std::cout << "Allocating the problem\n" << std::flush;
177  }
178 
179  {
180  OPM_BEGIN_PARALLEL_TRY_CATCH();
181  problem_ = std::make_unique<Problem>(*this);
182  OPM_END_PARALLEL_TRY_CATCH("Could not allocate the problem: ", comm);
183  }
184 
185  if (verbose_) {
186  std::cout << "Initializing the model\n" << std::flush;
187  }
188 
189  {
190  OPM_BEGIN_PARALLEL_TRY_CATCH();
191  model_->finishInit();
192  OPM_END_PARALLEL_TRY_CATCH("Could not initialize the model: ", comm);
193  }
194 
195  if (verbose_) {
196  std::cout << "Initializing the problem\n" << std::flush;
197  }
198 
199  {
200  OPM_BEGIN_PARALLEL_TRY_CATCH();
201  problem_->finishInit();
202  OPM_END_PARALLEL_TRY_CATCH("Could not initialize the problem: ", comm);
203  }
204 
205  setupTimer_.stop();
206 
207  if (verbose_) {
208  std::cout << "Simulator successfully set up\n" << std::flush;
209  }
210  }
211 
215  static void registerParameters()
216  {
217  Parameters::Register<Parameters::EndTime<Scalar>>
218  ("The simulation time at which the simulation is finished [s]");
219  Parameters::Register<Parameters::InitialTimeStepSize<Scalar>>
220  ("The size of the initial time step [s]");
221  Parameters::Register<Parameters::RestartTime<Scalar>>
222  ("The simulation time at which a restart should be attempted [s]");
223  Parameters::Register<Parameters::PredeterminedTimeStepsFile>
224  ("A file with a list of predetermined time step sizes "
225  "(one time step per line)");
226  Parameters::Register<Parameters::TruncateTimeStepToFloat>
227  ("Truncate the time step size to float precision. Only used to make "
228  "time steps reproducible for the timestep-replay regression test; "
229  "do not enable for production runs.");
230 
231  Vanguard::registerParameters();
232  Model::registerParameters();
233  Problem::registerParameters();
234  }
235 
239  Vanguard& vanguard()
240  { return *vanguard_; }
241 
245  const Vanguard& vanguard() const
246  { return *vanguard_; }
247 
251  const GridView& gridView() const
252  { return vanguard_->gridView(); }
253 
257  Model& model()
258  { return *model_; }
259 
263  const Model& model() const
264  { return *model_; }
265 
270  Problem& problem()
271  { return *problem_; }
272 
277  const Problem& problem() const
278  { return *problem_; }
279 
285  void setStartTime(Scalar t)
286  { startTime_ = t; }
287 
291  Scalar startTime() const
292  { return startTime_; }
293 
300  void setTime(Scalar t)
301  { time_ = t; }
302 
309  void setTime(Scalar t, unsigned stepIdx)
310  {
311  time_ = t;
312  timeStepIdx_ = stepIdx;
313  }
314 
322  Scalar time() const
323  { return time_; }
324 
330  void setEndTime(Scalar t)
331  { endTime_ = t; }
332 
337  Scalar endTime() const
338  { return endTime_; }
339 
344  const Timer& setupTimer() const
345  { return setupTimer_; }
346 
351  const Timer& executionTimer() const
352  { return executionTimer_; }
353 
355  { return executionTimer_; }
356 
361  const Timer& prePostProcessTimer() const
362  { return prePostProcessTimer_; }
363 
368  const Timer& linearizeTimer() const
369  { return linearizeTimer_; }
370 
375  const Timer& solveTimer() const
376  { return solveTimer_; }
377 
382  const Timer& updateTimer() const
383  { return updateTimer_; }
384 
389  const Timer& writeTimer() const
390  { return writeTimer_; }
391 
402  void setTimeStepSize(Scalar value)
403  { timeStepSize_ = truncateTimeStepToFloat_ ? static_cast<Scalar>(float(value)) : value; }
404 
410  void setTimeStepIndex(unsigned value)
411  { timeStepIdx_ = value; }
412 
418  Scalar timeStepSize() const
419  { return timeStepSize_; }
420 
425  int timeStepIndex() const
426  { return timeStepIdx_; }
427 
435  void setFinished(bool yesno = true)
436  { finished_ = yesno; }
437 
444  bool finished() const
445  {
446  assert(timeStepSize_ >= 0.0);
447  return finished_ || (this->time() * (1.0 + eps) >= endTime());
448  }
449 
454  bool willBeFinished() const
455  {
456  return finished_ || (this->time() + timeStepSize_) * (1.0 + eps) >= endTime();
457  }
458 
463  Scalar maxTimeStepSize() const
464  {
465  if (finished()) {
466  return 0.0;
467  }
468 
469  return std::min(episodeMaxTimeStepSize(),
470  std::max<Scalar>(0.0, endTime() - this->time()));
471  }
472 
480  {
481  ++episodeIdx_;
482  episodeStartTime_ = episodeStartTime;
483  episodeLength_ = episodeLength;
484  }
485 
493  void startNextEpisode(Scalar len = std::numeric_limits<Scalar>::max())
494  {
495  ++episodeIdx_;
496  episodeStartTime_ = startTime_ + time_;
497  episodeLength_ = len;
498  }
499 
505  void setEpisodeIndex(int episodeIdx)
506  { episodeIdx_ = episodeIdx; }
507 
513  int episodeIndex() const
514  { return episodeIdx_; }
515 
520  Scalar episodeStartTime() const
521  { return episodeStartTime_; }
522 
528  void setEpisodeLength(Scalar dt)
529  { episodeLength_ = dt; }
530 
535  Scalar episodeLength() const
536  { return episodeLength_; }
537 
542  bool episodeStarts() const
543  {
544  return this->time() <= (episodeStartTime_ - startTime()) * (1 + eps);
545  }
546 
551  bool episodeIsOver() const
552  {
553  return this->time() >= (episodeStartTime_ - startTime() + episodeLength()) * (1 - eps);
554  }
555 
560  bool episodeWillBeOver() const
561  {
562  return this->time() + timeStepSize()
563  >= (episodeStartTime_ - startTime() + episodeLength()) * (1 - eps);
564  }
565 
570  Scalar episodeMaxTimeStepSize() const
571  {
572  // if the current episode is over and the simulation
573  // wants to give it some extra time, we will return
574  // the time step size it suggested instead of trying
575  // to align it to the end of the episode.
576  if (episodeIsOver()) {
577  return 0.0;
578  }
579 
580  // make sure that we don't exceed the end of the
581  // current episode.
582  return std::max<Scalar>(0.0,
584  (this->time() + this->startTime()));
585  }
586 
587  /*
588  * \}
589  */
590 
597  void run()
598  {
599  // create TimerGuard objects to hedge for exceptions
600  TimerGuard setupTimerGuard(setupTimer_);
601  TimerGuard executionTimerGuard(executionTimer_);
602  TimerGuard prePostProcessTimerGuard(prePostProcessTimer_);
603  TimerGuard writeTimerGuard(writeTimer_);
604 
605  setupTimer_.start();
606  const Scalar restartTime = Parameters::Get<Parameters::RestartTime<Scalar>>();
607  if (restartTime > -1e30) {
608  // try to restart a previous simulation
609  time_ = restartTime;
610 
611  OPM_BEGIN_PARALLEL_TRY_CATCH();
612  Restart res;
613  res.deserializeBegin(*this, time_);
614 
615  if (verbose_) {
616  std::cout << "Deserialize from file '" << res.fileName() << "'\n" << std::flush;
617  }
618 
619  this->deserialize(res);
620  problem_->deserialize(res);
621  model_->deserialize(res);
622  res.deserializeEnd();
623  OPM_END_PARALLEL_TRY_CATCH("Deserialization failed: ",
624  Dune::MPIHelper::getCommunication());
625  if (verbose_) {
626  std::cout << "Deserialization done."
627  << " Simulator time: " << time() << humanReadableTime(time())
628  << " Time step index: " << timeStepIndex()
629  << " Episode index: " << episodeIndex()
630  << "\n" << std::flush;
631  }
632  }
633  else {
634  // if no restart is done, apply the initial solution
635  if (verbose_) {
636  std::cout << "Applying the initial solution of the \"" << problem_->name()
637  << "\" problem\n" << std::flush;
638  }
639 
640  const Scalar oldTimeStepSize = timeStepSize_;
641  const int oldTimeStepIdx = timeStepIdx_;
642  timeStepSize_ = 0.0;
643  timeStepIdx_ = -1;
644 
645  {
646  OPM_BEGIN_PARALLEL_TRY_CATCH();
647  model_->applyInitialSolution();
648  OPM_END_PARALLEL_TRY_CATCH("Apply initial solution failed: ",
649  Dune::MPIHelper::getCommunication());
650  }
651 
652  // write initial condition
653  if (problem_->shouldWriteOutput()) {
654  OPM_BEGIN_PARALLEL_TRY_CATCH();
655  problem_->writeOutput(true);
656  OPM_END_PARALLEL_TRY_CATCH("Write output failed: ",
657  Dune::MPIHelper::getCommunication());
658  }
659 
660  timeStepSize_ = oldTimeStepSize;
661  timeStepIdx_ = oldTimeStepIdx;
662  }
663  setupTimer_.stop();
664 
665  executionTimer_.start();
666  bool episodeBegins = episodeIsOver() || (timeStepIdx_ == 0);
667  // do the time steps
668  while (!finished()) {
669  prePostProcessTimer_.start();
670  if (episodeBegins) {
671  // notify the problem that a new episode has just been
672  // started.
673  {
674  OPM_BEGIN_PARALLEL_TRY_CATCH();
675  problem_->beginEpisode();
676  OPM_END_PARALLEL_TRY_CATCH("Begin episode failed: ",
677  Dune::MPIHelper::getCommunication());
678  }
679 
680  if (finished()) {
681  // the problem can chose to terminate the simulation in
682  // beginEpisode(), so we have handle this case.
683  OPM_BEGIN_PARALLEL_TRY_CATCH();
684  problem_->endEpisode();
685  OPM_END_PARALLEL_TRY_CATCH("End episode failed: ",
686  Dune::MPIHelper::getCommunication());
687  prePostProcessTimer_.stop();
688 
689  break;
690  }
691  }
692  episodeBegins = false;
693 
694  if (verbose_) {
695  std::cout << "Begin time step " << timeStepIndex() + 1 << ". "
696  << "Start time: " << this->time() << " seconds" << humanReadableTime(this->time())
697  << ", step size: " << timeStepSize() << " seconds" << humanReadableTime(timeStepSize())
698  << "\n";
699  }
700 
701  // pre-process the current solution
702  {
703  OPM_BEGIN_PARALLEL_TRY_CATCH();
704  problem_->beginTimeStep();
705  OPM_END_PARALLEL_TRY_CATCH("Begin timestep failed: ",
706  Dune::MPIHelper::getCommunication());
707  }
708 
709  if (finished()) {
710  // the problem can choose to terminate the simulation in
711  // beginTimeStep(), so we have handle this case.
712  OPM_BEGIN_PARALLEL_TRY_CATCH();
713  problem_->endTimeStep();
714  problem_->endEpisode();
715  OPM_END_PARALLEL_TRY_CATCH("Finish failed: ",
716  Dune::MPIHelper::getCommunication());
717  prePostProcessTimer_.stop();
718 
719  break;
720  }
721  prePostProcessTimer_.stop();
722 
723  try {
724  // execute the time integration scheme
725  problem_->timeIntegration();
726  }
727  catch (...) {
728  // exceptions in the time integration might be recoverable. clean up in
729  // case they are
730  const auto& pmodel = problem_->model();
731  prePostProcessTimer_ += pmodel.prePostProcessTimer();
732  linearizeTimer_ += pmodel.linearizeTimer();
733  solveTimer_ += pmodel.solveTimer();
734  updateTimer_ += pmodel.updateTimer();
735 
736  throw;
737  }
738 
739  const auto& pmodel = problem_->model();
740  prePostProcessTimer_ += pmodel.prePostProcessTimer();
741  linearizeTimer_ += pmodel.linearizeTimer();
742  solveTimer_ += pmodel.solveTimer();
743  updateTimer_ += pmodel.updateTimer();
744 
745  // post-process the current solution
746  prePostProcessTimer_.start();
747  {
748  OPM_BEGIN_PARALLEL_TRY_CATCH();
749  problem_->endTimeStep();
750  OPM_END_PARALLEL_TRY_CATCH("End timestep failed: ",
751  Dune::MPIHelper::getCommunication());
752  }
753  prePostProcessTimer_.stop();
754 
755  // write the result to disk
756  writeTimer_.start();
757  if (problem_->shouldWriteOutput()) {
758  OPM_BEGIN_PARALLEL_TRY_CATCH();
759  problem_->writeOutput(true);
760  OPM_END_PARALLEL_TRY_CATCH("Write output failed: ",
761  Dune::MPIHelper::getCommunication());
762  }
763  writeTimer_.stop();
764 
765  // do the next time integration
766  const Scalar oldDt = timeStepSize();
767  {
768  OPM_BEGIN_PARALLEL_TRY_CATCH();
769  problem_->advanceTimeLevel();
770  OPM_END_PARALLEL_TRY_CATCH("Advance time level failed: ",
771  Dune::MPIHelper::getCommunication());
772  }
773 
774  if (verbose_) {
775  std::cout << "Time step " << timeStepIndex() + 1 << " done. "
776  << "CPU time: " << executionTimer_.realTimeElapsed()
777  << " seconds" << humanReadableTime(executionTimer_.realTimeElapsed())
778  << ", end time: " << this->time() + oldDt << " seconds"
779  << humanReadableTime(this->time() + oldDt)
780  << ", step size: " << oldDt << " seconds" << humanReadableTime(oldDt)
781  << "\n" << std::flush;
782  }
783 
784  // advance the simulated time by the current time step size
785  time_ += oldDt;
786  ++timeStepIdx_;
787 
788  prePostProcessTimer_.start();
789  // notify the problem if an episode is finished
790  if (episodeIsOver()) {
791  // Notify the problem about the end of the current episode...
792  OPM_BEGIN_PARALLEL_TRY_CATCH();
793  problem_->endEpisode();
794  OPM_END_PARALLEL_TRY_CATCH("End episode failed: ",
795  Dune::MPIHelper::getCommunication());
796  episodeBegins = true;
797  }
798  else {
799  Scalar dt;
800  if (timeStepIdx_ < static_cast<int>(forcedTimeSteps_.size())) {
801  // use the next time step size from the input file
802  dt = forcedTimeSteps_[timeStepIdx_];
803  }
804  else {
805  // ask the problem to provide the next time step size
806  dt = std::min(maxTimeStepSize(), problem_->nextTimeStepSize());
807  }
808  assert(finished() || dt > 0);
809  setTimeStepSize(dt);
810  }
811  prePostProcessTimer_.stop();
812 
813  // write restart file if mandated by the problem
814  writeTimer_.start();
815  if (problem_->shouldWriteRestartFile()) {
816  OPM_BEGIN_PARALLEL_TRY_CATCH();
817  serialize();
818  OPM_END_PARALLEL_TRY_CATCH("Serialize failed: ",
819  Dune::MPIHelper::getCommunication());
820  }
821  writeTimer_.stop();
822  }
823  executionTimer_.stop();
824 
825  {
826  OPM_BEGIN_PARALLEL_TRY_CATCH();
827  problem_->finalize();
828  OPM_END_PARALLEL_TRY_CATCH("Finalize failed: ",
829  Dune::MPIHelper::getCommunication());
830  }
831  }
832 
833 #ifdef RESERVOIR_COUPLING_ENABLED
834  ReservoirCouplingMaster<Scalar>* reservoirCouplingMaster() const
835  {
836  return reservoirCouplingMaster_;
837  }
838  ReservoirCouplingSlave<Scalar>* reservoirCouplingSlave() const
839  {
840  return reservoirCouplingSlave_;
841  }
842  void setReservoirCouplingMaster(ReservoirCouplingMaster<Scalar> *reservoirCouplingMaster)
843  {
844  this->reservoirCouplingMaster_ = reservoirCouplingMaster;
845  }
846  void setReservoirCouplingSlave(ReservoirCouplingSlave<Scalar> *reservoirCouplingSlave)
847  {
848  this->reservoirCouplingSlave_ = reservoirCouplingSlave;
849  }
850 #endif
851 
866  void serialize()
867  {
868  using Restarter = Restart;
869  Restarter res;
870  res.serializeBegin(*this);
871  if (gridView().comm().rank() == 0) {
872  std::cout << "Serialize to file '" << res.fileName() << "'"
873  << ", next time step size: " << timeStepSize()
874  << "\n" << std::flush;
875  }
876 
877  this->serialize(res);
878  problem_->serialize(res);
879  model_->serialize(res);
880  res.serializeEnd();
881  }
882 
890  template <class Restarter>
891  void serialize(Restarter& restarter)
892  {
893  restarter.serializeSectionBegin("Simulator");
894  restarter.serializeStream()
895  << episodeIdx_ << " "
896  << episodeStartTime_ << " "
897  << episodeLength_ << " "
898  << startTime_ << " "
899  << time_ << " "
900  << timeStepIdx_ << " ";
901  restarter.serializeSectionEnd();
902  }
903 
911  template <class Restarter>
912  void deserialize(Restarter& restarter)
913  {
914  restarter.deserializeSectionBegin("Simulator");
915  restarter.deserializeStream()
916  >> episodeIdx_
917  >> episodeStartTime_
918  >> episodeLength_
919  >> startTime_
920  >> time_
921  >> timeStepIdx_;
922  restarter.deserializeSectionEnd();
923  }
924 
925  template<class Serializer>
926  void serializeOp(Serializer& serializer)
927  {
928  serializer(*vanguard_);
929  serializer(*model_);
930  serializer(*problem_);
931  serializer(episodeIdx_);
932  serializer(episodeStartTime_);
933  serializer(episodeLength_);
934  serializer(startTime_);
935  serializer(time_);
936  serializer(timeStepIdx_);
937  }
938 
939 private:
940  std::unique_ptr<Vanguard> vanguard_;
941  std::unique_ptr<Model> model_;
942  std::unique_ptr<Problem> problem_;
943 
944  int episodeIdx_;
945  Scalar episodeStartTime_;
946  Scalar episodeLength_;
947 
948  Timer setupTimer_;
949  Timer executionTimer_;
950  Timer prePostProcessTimer_;
951  Timer linearizeTimer_;
952  Timer solveTimer_;
953  Timer updateTimer_;
954  Timer writeTimer_;
955 
956  std::vector<Scalar> forcedTimeSteps_;
957  Scalar startTime_;
958  Scalar time_;
959  Scalar endTime_;
960 
961  Scalar timeStepSize_;
962  int timeStepIdx_;
963 
964  bool finished_;
965  bool verbose_;
966  bool truncateTimeStepToFloat_ = false;
967 
968 #ifdef RESERVOIR_COUPLING_ENABLED
969  ReservoirCouplingMaster<Scalar> *reservoirCouplingMaster_ = nullptr;
970  ReservoirCouplingSlave<Scalar> *reservoirCouplingSlave_ = nullptr;
971 #endif
972 
973 };
974 
975 namespace Properties {
976 template<class TypeTag>
977 struct Simulator<TypeTag, TTag::NumericModel>
978 { using type = ::Opm::Simulator<TypeTag>; };
979 }
980 
981 } // namespace Opm
982 
983 #endif
const Vanguard & vanguard() const
Return a reference to the grid manager of simulation.
Definition: simulator.hh:245
const Timer & solveTimer() const
Returns a reference to the timer object which measures the time needed by the solver.
Definition: simulator.hh:375
void startNextEpisode(Scalar len=std::numeric_limits< Scalar >::max())
Start the next episode, but don&#39;t change the episode identifier.
Definition: simulator.hh:493
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(...))
Definition: propertysystem.hh:233
Scalar endTime() const
Returns the number of (simulated) seconds which the simulation runs.
Definition: simulator.hh:337
const GridView & gridView() const
Return the grid view for which the simulation is done.
Definition: simulator.hh:251
Scalar startTime() const
Return the time of the start of the simulation.
Definition: simulator.hh:291
Model & model()
Return the physical model used in the simulation.
Definition: simulator.hh:257
void serialize()
This method writes the complete state of the simulation to the harddisk.
Definition: simulator.hh:866
Problem & problem()
Return the object which specifies the pysical setup of the simulation.
Definition: simulator.hh:270
void run()
Runs the simulation using a given problem class.
Definition: simulator.hh:597
void start()
Start counting the time resources used by the simulation.
Definition: timer.cpp:46
bool finished() const
Returns true if the simulation is finished.
Definition: simulator.hh:444
This file provides the infrastructure to retrieve run-time parameters.
const Timer & prePostProcessTimer() const
Returns a reference to the timer object which measures the time needed for pre- and postprocessing of...
Definition: simulator.hh:361
Scalar episodeMaxTimeStepSize() const
Aligns the time step size to the episode boundary if the current time step crosses the boundary of th...
Definition: simulator.hh:570
void deserializeEnd()
Stop reading the restart file.
Definition: restart.cpp:80
bool episodeStarts() const
Returns true if the current episode has just been started at the current time.
Definition: simulator.hh:542
Scalar maxTimeStepSize() const
Aligns the time step size to the episode boundary and to the end time of the simulation.
Definition: simulator.hh:463
int episodeIndex() const
Returns the index of the current episode.
Definition: simulator.hh:513
Load or save a state of a problem to/from the harddisk.
Load or save a state of a problem to/from the harddisk.
Definition: restart.hpp:44
static void registerParameters()
Registers all runtime parameters used by the simulation.
Definition: simulator.hh:215
void setTime(Scalar t)
Set the current simulated time, don&#39;t change the current time step index.
Definition: simulator.hh:300
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Scalar timeStepSize() const
Returns the time step length so that we don&#39;t miss the beginning of the next episode or cross the en...
Definition: simulator.hh:418
const Timer & executionTimer() const
Returns a reference to the timer object which measures the time needed to run the simulation...
Definition: simulator.hh:351
void setStartTime(Scalar t)
Set the time of the start of the simulation.
Definition: simulator.hh:285
Declare the properties used by the infrastructure code of the finite volume discretizations.
void serialize(Restarter &restarter)
Write the time manager&#39;s state to a restart file.
Definition: simulator.hh:891
int timeStepIndex() const
Returns number of time steps which have been executed since the beginning of the simulation.
Definition: simulator.hh:425
const Timer & updateTimer() const
Returns a reference to the timer object which measures the time needed to the solutions of the non-li...
Definition: simulator.hh:382
const Model & model() const
Return the physical model used in the simulation.
Definition: simulator.hh:263
std::string humanReadableTime(double timeInSeconds, bool isAmendment)
Given a time step size in seconds, return it in a format which is more easily parsable by humans...
Definition: simulatorutils.cpp:45
void setEndTime(Scalar t)
Set the time of simulated seconds at which the simulation runs.
Definition: simulator.hh:330
bool episodeWillBeOver() const
Returns true if the current episode will be finished after the current time step. ...
Definition: simulator.hh:560
const std::string & fileName() const
Returns the name of the file which is (de-)serialized.
Definition: restart.hpp:85
double realTimeElapsed() const
Return the real time [s] elapsed during the periods the timer was active since the last reset...
Definition: timer.cpp:90
void setFinished(bool yesno=true)
Specify whether the simulation is finished.
Definition: simulator.hh:435
void setEpisodeIndex(int episodeIdx)
Sets the index of the current episode.
Definition: simulator.hh:505
void deserializeBegin(Simulator &simulator, Scalar t)
Start reading a restart file at a certain simulated time.
Definition: restart.hpp:147
Scalar episodeStartTime() const
Returns the absolute time when the current episode started .
Definition: simulator.hh:520
A simple class which makes sure that a timer gets stopped if an exception is thrown.
Definition: timerguard.hh:41
Provides an encapsulation to measure the system time.
Definition: timer.hpp:45
const Problem & problem() const
Return the object which specifies the pysical setup of the simulation.
Definition: simulator.hh:277
bool willBeFinished() const
Returns true if the simulation is finished after the time level is incremented by the current time st...
Definition: simulator.hh:454
bool episodeIsOver() const
Returns true if the current episode is finished at the current time.
Definition: simulator.hh:551
const Timer & setupTimer() const
Returns a reference to the timer object which measures the time needed to set up and initialize the s...
Definition: simulator.hh:344
Provides an encapsulation to measure the system time.
Definition: ReservoirCouplingMaster.hpp:38
The Opm property system, traits with inheritance.
void setTime(Scalar t, unsigned stepIdx)
Set the current simulated time and the time step index.
Definition: simulator.hh:309
A simple class which makes sure that a timer gets stopped if an exception is thrown.
const Timer & linearizeTimer() const
Returns a reference to the timer object which measures the time needed for linarizing the solutions...
Definition: simulator.hh:368
Manages the simulation time.
Definition: basicproperties.hh:120
void deserialize(Restarter &restarter)
Read the time manager&#39;s state from a restart file.
Definition: simulator.hh:912
void setTimeStepIndex(unsigned value)
Set the current time step index to a given value.
Definition: simulator.hh:410
void serializeBegin(Simulator &simulator)
Write the current state of the model to disk.
Definition: restart.hpp:92
void setEpisodeLength(Scalar dt)
Sets the length in seconds of the current episode.
Definition: simulator.hh:528
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:83
double stop()
Stop counting the time resources.
Definition: timer.cpp:52
Scalar episodeLength() const
Returns the length of the current episode in simulated time .
Definition: simulator.hh:535
Defines a type tags and some fundamental properties all models.
void startNextEpisode(Scalar episodeStartTime, Scalar episodeLength)
Change the current episode of the simulation.
Definition: simulator.hh:479
const Timer & writeTimer() const
Returns a reference to the timer object which measures the time needed to write the visualization out...
Definition: simulator.hh:389
Scalar time() const
Return the number of seconds of simulated time which have elapsed since the start time...
Definition: simulator.hh:322
void setTimeStepSize(Scalar value)
Set the current time step size to a given value.
Definition: simulator.hh:402
Vanguard & vanguard()
Return a reference to the grid manager of simulation.
Definition: simulator.hh:239