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
33
40
41#include <dune/common/parallel/mpihelper.hh>
42
43#include <iostream>
44#include <fstream>
45#include <iomanip>
46#include <vector>
47#include <string>
48#include <memory>
49
50namespace Opm
51{
52namespace detail
53{
55{
56 return Dune::MPIHelper::getCommunication();
57}
58} // end namespace detail
59} // end namespace Opm
60
61#define EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(code) \
62 { \
63 const auto& comm = ::Opm::detail::getMPIHelperCommunication(); \
64 bool exceptionThrown = false; \
65 try { code; } \
66 catch (const Dune::Exception& e) { \
67 exceptionThrown = true; \
68 std::cerr << "Process " << comm.rank() << " threw a fatal exception: " \
69 << e.what() << ". Abort!" << std::endl; \
70 } \
71 catch (const std::exception& e) { \
72 exceptionThrown = true; \
73 std::cerr << "Process " << comm.rank() << " threw a fatal exception: " \
74 << e.what() << ". Abort!" << std::endl; \
75 } \
76 catch (...) { \
77 exceptionThrown = true; \
78 std::cerr << "Process " << comm.rank() << " threw a fatal exception. " \
79 <<" Abort!" << std::endl; \
80 } \
81 \
82 if (comm.max(exceptionThrown)) \
83 std::abort(); \
84 }
85
86namespace Opm {
87
100template <class TypeTag>
102{
108
109 using MPIComm = typename Dune::MPIHelper::MPICommunicator;
110 using Communication = Dune::Communication<MPIComm>;
111
112public:
113 // do not allow to copy simulators around
114 Simulator(const Simulator& ) = delete;
115
116 Simulator(bool verbose = true)
117 :Simulator(Communication(), verbose)
118 {
119 }
120
121 Simulator(Communication comm, bool verbose = true)
122 {
123 TimerGuard setupTimerGuard(setupTimer_);
124
125 setupTimer_.start();
126
127 verbose_ = verbose && comm.rank() == 0;
128
129 timeStepIdx_ = 0;
130 startTime_ = 0.0;
131 time_ = 0.0;
132 endTime_ = Parameters::get<TypeTag, Properties::EndTime>();
133 timeStepSize_ = Parameters::get<TypeTag, Properties::InitialTimeStepSize>();
134 assert(timeStepSize_ > 0);
135 const std::string& predetTimeStepFile =
136 Parameters::get<TypeTag, Properties::PredeterminedTimeStepsFile>();
137 if (!predetTimeStepFile.empty()) {
138 std::ifstream is(predetTimeStepFile);
139 while (!is.eof()) {
140 Scalar dt;
141 is >> dt;
142 forcedTimeSteps_.push_back(dt);
143 }
144 }
145
146 episodeIdx_ = 0;
147 episodeStartTime_ = 0;
148 episodeLength_ = std::numeric_limits<Scalar>::max();
149
150 finished_ = false;
151
152 if (verbose_)
153 std::cout << "Allocating the simulation vanguard\n" << std::flush;
154
155 int exceptionThrown = 0;
156 std::string what;
157
158 auto catchAction =
159 [&exceptionThrown, &what, comm](const std::exception& e,
160 bool doPrint) {
161 exceptionThrown = 1;
162 what = e.what();
163 if (comm.size() > 1) {
164 what += " (on rank " + std::to_string(comm.rank()) + ")";
165 }
166 if (doPrint)
167 std::cerr << "Rank " << comm.rank() << " threw an exception: " << e.what() << std::endl;
168 };
169
170 auto checkParallelException =
171 [comm](const std::string& prefix,
172 int exceptionThrown_,
173 const std::string& what_)
174 {
175 if (comm.max(exceptionThrown_)) {
176 auto all_what = gatherStrings(what_);
177 assert(!all_what.empty());
178 throw std::runtime_error(prefix + all_what.front());
179 }
180 };
181
182 try
183 { vanguard_.reset(new Vanguard(*this)); }
184 catch (const std::exception& e) {
185 catchAction(e, verbose_);
186 }
187 checkParallelException("Allocating the simulation vanguard failed: ",
188 exceptionThrown, what);
189
190 if (verbose_)
191 std::cout << "Distributing the vanguard's data\n" << std::flush;
192
193 try
194 { vanguard_->loadBalance(); }
195 catch (const std::exception& e) {
196 catchAction(e, verbose_);
197 }
198 checkParallelException("Could not distribute the vanguard data: ",
199 exceptionThrown, what);
200
201 if (verbose_)
202 std::cout << "Allocating the model\n" << std::flush;
203 try {
204 model_.reset(new Model(*this));
205 }
206 catch (const std::exception& e) {
207 catchAction(e, verbose_);
208 }
209 checkParallelException("Could not allocate model: ",
210 exceptionThrown, what);
211
212 if (verbose_)
213 std::cout << "Allocating the problem\n" << std::flush;
214
215 try {
216 problem_.reset(new Problem(*this));
217 }
218 catch (const std::exception& e) {
219 catchAction(e, verbose_);
220 }
221 checkParallelException("Could not allocate the problem: ",
222 exceptionThrown, what);
223
224 if (verbose_)
225 std::cout << "Initializing the model\n" << std::flush;
226
227 try
228 { model_->finishInit(); }
229 catch (const std::exception& e) {
230 catchAction(e, verbose_);
231 }
232 checkParallelException("Could not initialize the model: ",
233 exceptionThrown, what);
234
235 if (verbose_)
236 std::cout << "Initializing the problem\n" << std::flush;
237
238 try
239 { problem_->finishInit(); }
240 catch (const std::exception& e) {
241 catchAction(e, verbose_);
242 }
243 checkParallelException("Could not initialize the problem: ",
244 exceptionThrown, what);
245
246 setupTimer_.stop();
247
248 if (verbose_)
249 std::cout << "Simulator successfully set up\n" << std::flush;
250 }
251
255 static void registerParameters()
256 {
257 Parameters::registerParam<TypeTag, Properties::EndTime>
258 ("The simulation time at which the simulation is finished [s]");
259 Parameters::registerParam<TypeTag, Properties::InitialTimeStepSize>
260 ("The size of the initial time step [s]");
261 Parameters::registerParam<TypeTag, Properties::RestartTime>
262 ("The simulation time at which a restart should be attempted [s]");
263 Parameters::registerParam<TypeTag, Properties::PredeterminedTimeStepsFile>
264 ("A file with a list of predetermined time step sizes (one "
265 "time step per line)");
266
267 Vanguard::registerParameters();
268 Model::registerParameters();
269 Problem::registerParameters();
270 }
271
275 Vanguard& vanguard()
276 { return *vanguard_; }
277
281 const Vanguard& vanguard() const
282 { return *vanguard_; }
283
287 const GridView& gridView() const
288 { return vanguard_->gridView(); }
289
293 Model& model()
294 { return *model_; }
295
299 const Model& model() const
300 { return *model_; }
301
306 Problem& problem()
307 { return *problem_; }
308
313 const Problem& problem() const
314 { return *problem_; }
315
321 void setStartTime(Scalar t)
322 { startTime_ = t; }
323
327 Scalar startTime() const
328 { return startTime_; }
329
336 void setTime(Scalar t)
337 { time_ = t; }
338
345 void setTime(Scalar t, unsigned stepIdx)
346 {
347 time_ = t;
348 timeStepIdx_ = stepIdx;
349 }
350
358 Scalar time() const
359 { return time_; }
360
366 void setEndTime(Scalar t)
367 { endTime_ = t; }
368
373 Scalar endTime() const
374 { return endTime_; }
375
380 const Timer& setupTimer() const
381 { return setupTimer_; }
382
387 const Timer& executionTimer() const
388 { return executionTimer_; }
390 { return executionTimer_; }
391
397 { return prePostProcessTimer_; }
398
403 const Timer& linearizeTimer() const
404 { return linearizeTimer_; }
405
410 const Timer& solveTimer() const
411 { return solveTimer_; }
412
417 const Timer& updateTimer() const
418 { return updateTimer_; }
419
424 const Timer& writeTimer() const
425 { return writeTimer_; }
426
437 void setTimeStepSize(Scalar value)
438 {
439 timeStepSize_ = value;
440 }
441
447 void setTimeStepIndex(unsigned value)
448 { timeStepIdx_ = value; }
449
455 Scalar timeStepSize() const
456 { return timeStepSize_; }
457
462 int timeStepIndex() const
463 { return timeStepIdx_; }
464
472 void setFinished(bool yesno = true)
473 { finished_ = yesno; }
474
481 bool finished() const
482 {
483 assert(timeStepSize_ >= 0.0);
484 Scalar eps =
485 std::max(Scalar(std::abs(this->time())), timeStepSize())
486 *std::numeric_limits<Scalar>::epsilon()*1e3;
487 return finished_ || (this->time()*(1.0 + eps) >= endTime());
488 }
489
494 bool willBeFinished() const
495 {
496 static const Scalar eps = std::numeric_limits<Scalar>::epsilon()*1e3;
497
498 return finished_ || (this->time() + timeStepSize_)*(1.0 + eps) >= endTime();
499 }
500
505 Scalar maxTimeStepSize() const
506 {
507 if (finished())
508 return 0.0;
509
510 return std::min(episodeMaxTimeStepSize(),
511 std::max<Scalar>(0.0, endTime() - this->time()));
512 }
513
521 {
522 ++episodeIdx_;
523 episodeStartTime_ = episodeStartTime;
524 episodeLength_ = episodeLength;
525 }
526
534 void startNextEpisode(Scalar len = std::numeric_limits<Scalar>::max())
535 {
536 ++episodeIdx_;
537 episodeStartTime_ = startTime_ + time_;
538 episodeLength_ = len;
539 }
540
546 void setEpisodeIndex(int episodeIdx)
547 { episodeIdx_ = episodeIdx; }
548
554 int episodeIndex() const
555 { return episodeIdx_; }
556
561 Scalar episodeStartTime() const
562 { return episodeStartTime_; }
563
569 void setEpisodeLength(Scalar dt)
570 { episodeLength_ = dt; }
571
576 Scalar episodeLength() const
577 { return episodeLength_; }
578
583 bool episodeStarts() const
584 {
585 static const Scalar eps = std::numeric_limits<Scalar>::epsilon()*1e3;
586
587 return this->time() <= (episodeStartTime_ - startTime())*(1 + eps);
588 }
589
594 bool episodeIsOver() const
595 {
596 static const Scalar eps = std::numeric_limits<Scalar>::epsilon()*1e3;
597
598 return this->time() >= (episodeStartTime_ - startTime() + episodeLength())*(1 - eps);
599 }
600
605 bool episodeWillBeOver() const
606 {
607 static const Scalar eps = std::numeric_limits<Scalar>::epsilon()*1e3;
608
609 return this->time() + timeStepSize()
610 >= (episodeStartTime_ - startTime() + episodeLength())*(1 - eps);
611 }
612
618 {
619 // if the current episode is over and the simulation
620 // wants to give it some extra time, we will return
621 // the time step size it suggested instead of trying
622 // to align it to the end of the episode.
623 if (episodeIsOver())
624 return 0.0;
625
626 // make sure that we don't exceed the end of the
627 // current episode.
628 return std::max<Scalar>(0.0,
630 - (this->time() + this->startTime()));
631 }
632
633 /*
634 * \}
635 */
636
643 void run()
644 {
645 // create TimerGuard objects to hedge for exceptions
646 TimerGuard setupTimerGuard(setupTimer_);
647 TimerGuard executionTimerGuard(executionTimer_);
648 TimerGuard prePostProcessTimerGuard(prePostProcessTimer_);
649 TimerGuard writeTimerGuard(writeTimer_);
650
651 setupTimer_.start();
652 Scalar restartTime = Parameters::get<TypeTag, Properties::RestartTime>();
653 if (restartTime > -1e30) {
654 // try to restart a previous simulation
655 time_ = restartTime;
656
657 Restart res;
659 if (verbose_)
660 std::cout << "Deserialize from file '" << res.fileName() << "'\n" << std::flush;
662 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(problem_->deserialize(res));
663 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(model_->deserialize(res));
665 if (verbose_)
666 std::cout << "Deserialization done."
667 << " Simulator time: " << time() << humanReadableTime(time())
668 << " Time step index: " << timeStepIndex()
669 << " Episode index: " << episodeIndex()
670 << "\n" << std::flush;
671 }
672 else {
673 // if no restart is done, apply the initial solution
674 if (verbose_)
675 std::cout << "Applying the initial solution of the \"" << problem_->name()
676 << "\" problem\n" << std::flush;
677
678 Scalar oldTimeStepSize = timeStepSize_;
679 int oldTimeStepIdx = timeStepIdx_;
680 timeStepSize_ = 0.0;
681 timeStepIdx_ = -1;
682
683 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(model_->applyInitialSolution());
684
685 // write initial condition
686 if (problem_->shouldWriteOutput())
687 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(problem_->writeOutput());
688
689 timeStepSize_ = oldTimeStepSize;
690 timeStepIdx_ = oldTimeStepIdx;
691 }
692 setupTimer_.stop();
693
694 executionTimer_.start();
695 bool episodeBegins = episodeIsOver() || (timeStepIdx_ == 0);
696 // do the time steps
697 while (!finished()) {
698 prePostProcessTimer_.start();
699 if (episodeBegins) {
700 // notify the problem that a new episode has just been
701 // started.
702 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(problem_->beginEpisode());
703
704 if (finished()) {
705 // the problem can chose to terminate the simulation in
706 // beginEpisode(), so we have handle this case.
707 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(problem_->endEpisode());
708 prePostProcessTimer_.stop();
709
710 break;
711 }
712 }
713 episodeBegins = false;
714
715 if (verbose_) {
716 std::cout << "Begin time step " << timeStepIndex() + 1 << ". "
717 << "Start time: " << this->time() << " seconds" << humanReadableTime(this->time())
718 << ", step size: " << timeStepSize() << " seconds" << humanReadableTime(timeStepSize())
719 << "\n";
720 }
721
722 // pre-process the current solution
723 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(problem_->beginTimeStep());
724
725 if (finished()) {
726 // the problem can chose to terminate the simulation in
727 // beginTimeStep(), so we have handle this case.
728 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(problem_->endTimeStep());
729 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(problem_->endEpisode());
730 prePostProcessTimer_.stop();
731
732 break;
733 }
734 prePostProcessTimer_.stop();
735
736 try {
737 // execute the time integration scheme
738 problem_->timeIntegration();
739 }
740 catch (...) {
741 // exceptions in the time integration might be recoverable. clean up in
742 // case they are
743 const auto& model = problem_->model();
744 prePostProcessTimer_ += model.prePostProcessTimer();
745 linearizeTimer_ += model.linearizeTimer();
746 solveTimer_ += model.solveTimer();
747 updateTimer_ += model.updateTimer();
748
749 throw;
750 }
751
752 const auto& model = problem_->model();
753 prePostProcessTimer_ += model.prePostProcessTimer();
754 linearizeTimer_ += model.linearizeTimer();
755 solveTimer_ += model.solveTimer();
756 updateTimer_ += model.updateTimer();
757
758 // post-process the current solution
759 prePostProcessTimer_.start();
760 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(problem_->endTimeStep());
761 prePostProcessTimer_.stop();
762
763 // write the result to disk
764 writeTimer_.start();
765 if (problem_->shouldWriteOutput())
766 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(problem_->writeOutput());
767 writeTimer_.stop();
768
769 // do the next time integration
770 Scalar oldDt = timeStepSize();
771 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(problem_->advanceTimeLevel());
772
773 if (verbose_) {
774 std::cout << "Time step " << timeStepIndex() + 1 << " done. "
775 << "CPU time: " << executionTimer_.realTimeElapsed() << " seconds" << humanReadableTime(executionTimer_.realTimeElapsed())
776 << ", end time: " << this->time() + oldDt << " seconds" << humanReadableTime(this->time() + oldDt)
777 << ", step size: " << oldDt << " seconds" << humanReadableTime(oldDt)
778 << "\n" << std::flush;
779 }
780
781 // advance the simulated time by the current time step size
782 time_ += oldDt;
783 ++timeStepIdx_;
784
785 prePostProcessTimer_.start();
786 // notify the problem if an episode is finished
787 if (episodeIsOver()) {
788 // Notify the problem about the end of the current episode...
789 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(problem_->endEpisode());
790 episodeBegins = true;
791 }
792 else {
793 Scalar dt;
794 if (timeStepIdx_ < static_cast<int>(forcedTimeSteps_.size()))
795 // use the next time step size from the input file
796 dt = forcedTimeSteps_[timeStepIdx_];
797 else
798 // ask the problem to provide the next time step size
799 dt = std::min(maxTimeStepSize(), problem_->nextTimeStepSize());
800 assert(finished() || dt > 0);
801 setTimeStepSize(dt);
802 }
803 prePostProcessTimer_.stop();
804
805 // write restart file if mandated by the problem
806 writeTimer_.start();
807 if (problem_->shouldWriteRestartFile())
809 writeTimer_.stop();
810 }
811 executionTimer_.stop();
812
813 EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(problem_->finalize());
814 }
815
822 static std::string humanReadableTime(Scalar timeInSeconds, bool isAmendment=true)
823 {
824 std::ostringstream oss;
825 oss << std::setprecision(4);
826 if (isAmendment)
827 oss << " (";
828 if (timeInSeconds >= 365.25*24*60*60) {
829 int years = static_cast<int>(timeInSeconds/(365.25*24*60*60));
830 int days = static_cast<int>((timeInSeconds - years*(365.25*24*60*60))/(24*60*60));
831
832 double accuracy = 1e-2;
833 double hours =
834 std::round(1.0/accuracy*
835 (timeInSeconds
836 - years*(365.25*24*60*60)
837 - days*(24*60*60))/(60*60))
838 *accuracy;
839
840 oss << years << " years, " << days << " days, " << hours << " hours";
841 }
842 else if (timeInSeconds >= 24.0*60*60) {
843 int days = static_cast<int>(timeInSeconds/(24*60*60));
844 int hours = static_cast<int>((timeInSeconds - days*(24*60*60))/(60*60));
845
846 double accuracy = 1e-2;
847 double minutes =
848 std::round(1.0/accuracy*
849 (timeInSeconds
850 - days*(24*60*60)
851 - hours*(60*60))/60)
852 *accuracy;
853
854 oss << days << " days, " << hours << " hours, " << minutes << " minutes";
855 }
856 else if (timeInSeconds >= 60.0*60) {
857 int hours = static_cast<int>(timeInSeconds/(60*60));
858 int minutes = static_cast<int>((timeInSeconds - hours*(60*60))/60);
859
860 double accuracy = 1e-2;
861 double seconds =
862 std::round(1.0/accuracy*
863 (timeInSeconds
864 - hours*(60*60)
865 - minutes*60))
866 *accuracy;
867
868 oss << hours << " hours, " << minutes << " minutes, " << seconds << " seconds";
869 }
870 else if (timeInSeconds >= 60.0) {
871 int minutes = static_cast<int>(timeInSeconds/60);
872
873 double accuracy = 1e-3;
874 double seconds =
875 std::round(1.0/accuracy*
876 (timeInSeconds
877 - minutes*60))
878 *accuracy;
879
880 oss << minutes << " minutes, " << seconds << " seconds";
881 }
882 else if (!isAmendment)
883 oss << timeInSeconds << " seconds";
884 else
885 return "";
886 if (isAmendment)
887 oss << ")";
888
889 return oss.str();
890 }
891
907 {
908 using Restarter = Restart;
909 Restarter res;
910 res.serializeBegin(*this);
911 if (gridView().comm().rank() == 0)
912 std::cout << "Serialize to file '" << res.fileName() << "'"
913 << ", next time step size: " << timeStepSize()
914 << "\n" << std::flush;
915
916 this->serialize(res);
917 problem_->serialize(res);
918 model_->serialize(res);
919 res.serializeEnd();
920 }
921
929 template <class Restarter>
930 void serialize(Restarter& restarter)
931 {
932 restarter.serializeSectionBegin("Simulator");
933 restarter.serializeStream()
934 << episodeIdx_ << " "
935 << episodeStartTime_ << " "
936 << episodeLength_ << " "
937 << startTime_ << " "
938 << time_ << " "
939 << timeStepIdx_ << " ";
940 restarter.serializeSectionEnd();
941 }
942
950 template <class Restarter>
951 void deserialize(Restarter& restarter)
952 {
953 restarter.deserializeSectionBegin("Simulator");
954 restarter.deserializeStream()
955 >> episodeIdx_
956 >> episodeStartTime_
957 >> episodeLength_
958 >> startTime_
959 >> time_
960 >> timeStepIdx_;
961 restarter.deserializeSectionEnd();
962 }
963
964 template<class Serializer>
965 void serializeOp(Serializer& serializer)
966 {
967 serializer(*vanguard_);
968 serializer(*model_);
969 serializer(*problem_);
970 serializer(episodeIdx_);
971 serializer(episodeStartTime_);
972 serializer(episodeLength_);
973 serializer(startTime_);
974 serializer(time_);
975 serializer(timeStepIdx_);
976 }
977
978private:
979 std::unique_ptr<Vanguard> vanguard_;
980 std::unique_ptr<Model> model_;
981 std::unique_ptr<Problem> problem_;
982
983 int episodeIdx_;
984 Scalar episodeStartTime_;
985 Scalar episodeLength_;
986
987 Timer setupTimer_;
988 Timer executionTimer_;
989 Timer prePostProcessTimer_;
990 Timer linearizeTimer_;
991 Timer solveTimer_;
992 Timer updateTimer_;
993 Timer writeTimer_;
994
995 std::vector<Scalar> forcedTimeSteps_;
996 Scalar startTime_;
997 Scalar time_;
998 Scalar endTime_;
999
1000 Scalar timeStepSize_;
1001 int timeStepIdx_;
1002
1003 bool finished_;
1004 bool verbose_;
1005};
1006
1007namespace Properties {
1008template<class TypeTag>
1009struct Simulator<TypeTag, TTag::NumericModel> { using type = ::Opm::Simulator<TypeTag>; };
1010}
1011
1012} // namespace Opm
1013
1014#endif
Defines a type tags and some fundamental properties all models.
Load or save a state of a problem to/from the harddisk.
Definition: restart.hh:41
void serializeBegin(Simulator &simulator)
Write the current state of the model to disk.
Definition: restart.hh:101
const std::string & fileName() const
Returns the name of the file which is (de-)serialized.
Definition: restart.hh:94
void deserializeBegin(Simulator &simulator, Scalar t)
Start reading a restart file at a certain simulated time.
Definition: restart.hh:172
void deserializeEnd()
Stop reading the restart file.
Definition: restart.hh:265
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:102
const Timer & writeTimer() const
Returns a reference to the timer object which measures the time needed to write the visualization out...
Definition: simulator.hh:424
Scalar timeStepSize() const
Returns the time step length so that we don't miss the beginning of the next episode or cross the en...
Definition: simulator.hh:455
Scalar startTime() const
Return the time of the start of the simulation.
Definition: simulator.hh:327
int timeStepIndex() const
Returns number of time steps which have been executed since the beginning of the simulation.
Definition: simulator.hh:462
void serialize()
This method writes the complete state of the simulation to the harddisk.
Definition: simulator.hh:906
Timer & executionTimer()
Definition: simulator.hh:389
Scalar episodeLength() const
Returns the length of the current episode in simulated time .
Definition: simulator.hh:576
const Timer & prePostProcessTimer() const
Returns a reference to the timer object which measures the time needed for pre- and postprocessing of...
Definition: simulator.hh:396
const Timer & solveTimer() const
Returns a reference to the timer object which measures the time needed by the solver.
Definition: simulator.hh:410
void startNextEpisode(Scalar len=std::numeric_limits< Scalar >::max())
Start the next episode, but don't change the episode identifier.
Definition: simulator.hh:534
void serializeOp(Serializer &serializer)
Definition: simulator.hh:965
const Vanguard & vanguard() const
Return a reference to the grid manager of simulation.
Definition: simulator.hh:281
void serialize(Restarter &restarter)
Write the time manager's state to a restart file.
Definition: simulator.hh:930
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:417
const Timer & executionTimer() const
Returns a reference to the timer object which measures the time needed to run the simulation.
Definition: simulator.hh:387
void startNextEpisode(Scalar episodeStartTime, Scalar episodeLength)
Change the current episode of the simulation.
Definition: simulator.hh:520
void setEndTime(Scalar t)
Set the time of simulated seconds at which the simulation runs.
Definition: simulator.hh:366
const Timer & linearizeTimer() const
Returns a reference to the timer object which measures the time needed for linarizing the solutions.
Definition: simulator.hh:403
void setStartTime(Scalar t)
Set the time of the start of the simulation.
Definition: simulator.hh:321
void deserialize(Restarter &restarter)
Read the time manager's state from a restart file.
Definition: simulator.hh:951
Simulator(Communication comm, bool verbose=true)
Definition: simulator.hh:121
void setTimeStepSize(Scalar value)
Set the current time step size to a given value.
Definition: simulator.hh:437
bool episodeStarts() const
Returns true if the current episode has just been started at the current time.
Definition: simulator.hh:583
void run()
Runs the simulation using a given problem class.
Definition: simulator.hh:643
Vanguard & vanguard()
Return a reference to the grid manager of simulation.
Definition: simulator.hh:275
int episodeIndex() const
Returns the index of the current episode.
Definition: simulator.hh:554
void setTimeStepIndex(unsigned value)
Set the current time step index to a given value.
Definition: simulator.hh:447
void setFinished(bool yesno=true)
Specify whether the simulation is finished.
Definition: simulator.hh:472
Problem & problem()
Return the object which specifies the pysical setup of the simulation.
Definition: simulator.hh:306
static void registerParameters()
Registers all runtime parameters used by the simulation.
Definition: simulator.hh:255
void setTime(Scalar t)
Set the current simulated time, don't change the current time step index.
Definition: simulator.hh:336
bool willBeFinished() const
Returns true if the simulation is finished after the time level is incremented by the current time st...
Definition: simulator.hh:494
bool finished() const
Returns true if the simulation is finished.
Definition: simulator.hh:481
Scalar maxTimeStepSize() const
Aligns the time step size to the episode boundary and to the end time of the simulation.
Definition: simulator.hh:505
const Model & model() const
Return the physical model used in the simulation.
Definition: simulator.hh:299
Simulator(bool verbose=true)
Definition: simulator.hh:116
void setTime(Scalar t, unsigned stepIdx)
Set the current simulated time and the time step index.
Definition: simulator.hh:345
bool episodeIsOver() const
Returns true if the current episode is finished at the current time.
Definition: simulator.hh:594
Scalar endTime() const
Returns the number of (simulated) seconds which the simulation runs.
Definition: simulator.hh:373
Simulator(const Simulator &)=delete
bool episodeWillBeOver() const
Returns true if the current episode will be finished after the current time step.
Definition: simulator.hh:605
const GridView & gridView() const
Return the grid view for which the simulation is done.
Definition: simulator.hh:287
static std::string humanReadableTime(Scalar timeInSeconds, bool isAmendment=true)
Given a time step size in seconds, return it in a format which is more easily parsable by humans.
Definition: simulator.hh:822
void setEpisodeIndex(int episodeIdx)
Sets the index of the current episode.
Definition: simulator.hh:546
Scalar time() const
Return the number of seconds of simulated time which have elapsed since the start time.
Definition: simulator.hh:358
void setEpisodeLength(Scalar dt)
Sets the length in seconds of the current episode.
Definition: simulator.hh:569
const Problem & problem() const
Return the object which specifies the pysical setup of the simulation.
Definition: simulator.hh:313
Model & model()
Return the physical model used in the simulation.
Definition: simulator.hh:293
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:617
Scalar episodeStartTime() const
Returns the absolute time when the current episode started .
Definition: simulator.hh:561
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:380
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.hh:49
void start()
Start counting the time resources used by the simulation.
Definition: timer.hh:62
double realTimeElapsed() const
Return the real time [s] elapsed during the periods the timer was active since the last reset.
Definition: timer.hh:121
double stop()
Stop counting the time resources.
Definition: timer.hh:73
Declare the properties used by the infrastructure code of the finite volume discretizations.
auto getMPIHelperCommunication()
Definition: simulator.hh:54
Definition: blackoilboundaryratevector.hh:37
std::vector< std::string > gatherStrings(const std::string &local_string)
From each rank, gather its string (if not empty) into a vector.
Definition: mpiutil.hh:153
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:242
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.
#define EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(code)
Definition: simulator.hh:61
Manages the simulation time.
Definition: basicproperties.hh:173