diff --git a/doc/handbook/tutorial-coupled.tex b/doc/handbook/tutorial-coupled.tex index bc91752fe89452e970d47899156b864a9a7b75ce..37aa108afef2b0979b55b481a875ac6ba1f87d14 100644 --- a/doc/handbook/tutorial-coupled.tex +++ b/doc/handbook/tutorial-coupled.tex @@ -209,8 +209,10 @@ parse the time when the simulation ends and the initial time step size. After this, a grid is created in line \ref{tutorial-coupled:create-grid} and the problem is instantiated for its leaf grid view in line \ref{tutorial-coupled:instantiate-problem}. -Finally, on line \ref{tutorial-coupled:begin-restart} a state written to -disk by a previous simulation run is restored if requested by the user. +Finally, on line \ref{tutorial-coupled:initTimeManager} the time +manager is created with the parsed starting parameters. If requested by +the user, a state written to disk by a previous simulation run can be +restored if via the restart flag. The simulation procedure is started in line \ref{tutorial-coupled:execute}. diff --git a/doc/handbook/tutorial-decoupled.tex b/doc/handbook/tutorial-decoupled.tex index 1d1f762ef0fd7aca367187d611d1e3331866d9fe..ffab4f3c6d6ba34e6e62f5478de59c68bed67fd9 100644 --- a/doc/handbook/tutorial-decoupled.tex +++ b/doc/handbook/tutorial-decoupled.tex @@ -70,13 +70,14 @@ parse the time when the simulation ends. As the maximum time-step in the sequential model is strictly bound by a CFL-criterion, the first time-step size is initialized with the simulation time. -After this, a grid is created in line \ref{tutorial-decoupled:create-grid} -and the time manager controlling the simulation run is instantiated -with the start parameters in line \ref{tutorial-decoupled:initTimeManager}. +After this, a grid is created in line \ref{tutorial-decoupled:create-grid}. The problem is instantiated with the time manager and information about the grid (via its leaf grid view) on line \ref{tutorial-decoupled:instantiate-problem}. -If demanded, on line \ref{tutorial-decoupled:mainRestart} a state written to -disk by a previous simulation run is restored on request by the user. +The time manager controlling the simulation run is instantiated +with the start parameters in line \ref{tutorial-decoupled:initTimeManager}. +If demanded, the time manager also restarts a state written to +disk by a previous simulation run via the last flag, using the appropriate +starting time (which has to be the same as the restart file). Finally, the simulation proceedure is started by the time manager in line \ref{tutorial-decoupled:execute}. @@ -150,7 +151,7 @@ subsection \label{decoupled-problem:boundary}), the problem class also contains general information about the current simulation. First, the name used by the \texttt{VTK-writer} to generate output is defined in the method of line \ref{tutorial-decoupled:name}, and line \ref{tutorial-decoupled:restart} indicates -weather restart files are written. As decoupled schemes usually feature small +wether restart files are written. As decoupled schemes usually feature small timesteps, the method controlling the output in line \ref{tutorial-decoupled:output} is very useful. The divisor of the modulo operation defines after how many timesteps output should be written out -- the default ``1'' resembles output after each diff --git a/dumux/common/start.hh b/dumux/common/start.hh index ff60b2e8461a6060ea212c0703a6ba0126c8ebfc..13de33e3c42d870a1c05bbb54afcb045c1c6fda1 100644 --- a/dumux/common/start.hh +++ b/dumux/common/start.hh @@ -114,12 +114,12 @@ int startFromDGF(int argc, char **argv) // deal with the restart stuff int argIdx = 1; bool restart = false; - double restartTime = 0; + double startTime = 0; if (std::string("--restart") == argv[argIdx]) { restart = true; ++argIdx; - std::istringstream(argv[argIdx++]) >> restartTime; + std::istringstream(argv[argIdx++]) >> startTime; } if (argc - argIdx != 3) { @@ -145,13 +145,11 @@ int startFromDGF(int argc, char **argv) // instantiate and run the concrete problem TimeManager timeManager; Problem problem(timeManager, gridPtr->leafView()); - timeManager.init(problem, 0, dt, tEnd, !restart); + timeManager.init(problem, startTime, dt, tEnd, restart); // print all properties Dumux::Properties::print<TypeTag>(); - if (restart) - problem.restart(restartTime); timeManager.run(); return 0; @@ -200,12 +198,12 @@ int startWithGrid(const typename GET_PROP_TYPE(TypeTag, PTAG(Grid)) &grid, // deal with the restart stuff int argIdx = 1; bool restart = false; - double restartTime = 0; + double startTime = 0; if (std::string("--restart") == argv[argIdx]) { restart = true; ++argIdx; - std::istringstream(argv[argIdx++]) >> restartTime; + std::istringstream(argv[argIdx++]) >> startTime; } if (argc - argIdx != 2) { @@ -219,13 +217,11 @@ int startWithGrid(const typename GET_PROP_TYPE(TypeTag, PTAG(Grid)) &grid, // instantiate and run the concrete problem TimeManager timeManager; Problem problem(timeManager, grid.leafView()); - timeManager.init(problem, 0, dt, tEnd, !restart); + timeManager.init(problem, startTime, dt, tEnd, restart); // print all properties Dumux::Properties::print<TypeTag>(); - if (restart) - problem.restart(restartTime); timeManager.run(); return 0; @@ -277,12 +273,12 @@ int startFromInputFile(int argc, char **argv) // deal with the restart stuff int argIdx = 1; bool restart = false; - double restartTime = 0; + double startTime = 0; if (std::string("--restart") == argv[argIdx]) { restart = true; ++argIdx; - std::istringstream(argv[argIdx++]) >> restartTime; + std::istringstream(argv[argIdx++]) >> startTime; } if (argc - argIdx != 1) { @@ -330,13 +326,11 @@ int startFromInputFile(int argc, char **argv) Problem problem(timeManager, gridPtr->leafView(), Params::tree()); - timeManager.init(problem, 0, dt, tEnd, !restart); + timeManager.init(problem, startTime, dt, tEnd, restart); // print all properties Dumux::Properties::print<TypeTag>(); - if (restart) - problem.restart(restartTime); timeManager.run(); return 0; diff --git a/dumux/common/timemanager.hh b/dumux/common/timemanager.hh index 1bbf74c58004eb4382ac52ccd333ae44eac5bb05..649408699594ca6a64f09c4241554459c1d6abea 100644 --- a/dumux/common/timemanager.hh +++ b/dumux/common/timemanager.hh @@ -100,14 +100,13 @@ public: * \param tStart The start time \f$\mathrm{[s]}\f$ of the simulation (typically 0) * \param dtInitial The initial time step size \f$\mathrm{[s]}\f$ * \param tEnd The time at which the simulation is finished \f$\mathrm{[s]}\f$ - * \param writeInitialSol Specifies whether the initial condition - * should be written to disk + * \param restart Specifies whether the initial condition should be written to disk */ void init(Problem &problem, Scalar tStart, Scalar dtInitial, Scalar tEnd, - bool writeInitialSol = true) + bool restart = false) { problem_ = &problem; time_ = tStart; @@ -120,12 +119,17 @@ public: // initialize the problem problem_->init(); - // write initial condition (if requested) - if (writeInitialSol) { + // restart problem if necessary + if(restart) + problem_->restart(tStart); + else + { + // write initial condition (if problem is not restarted) time_ -= timeStepSize_; problem_->writeOutput(); time_ += timeStepSize_; } + } /*! diff --git a/dumux/decoupled/common/impetproblem.hh b/dumux/decoupled/common/impetproblem.hh index fd87754aa03f5e7730fff32cdc8bf6a682ac3c8c..169324822ec36cce09335a68885b63c3045cd1e7 100644 --- a/dumux/decoupled/common/impetproblem.hh +++ b/dumux/decoupled/common/impetproblem.hh @@ -733,7 +733,7 @@ public: std::cerr << "Serialize to file " << res.fileName() << "\n"; timeManager().serialize(res); - resultWriter_->serialize(res); + resultWriter().serialize(res); model().serialize(res); res.serializeEnd(); @@ -744,21 +744,25 @@ public: * from disk. * * It is the inverse of the serialize() method. + * @param tRestart Restart time */ - void deserialize(double t) + void restart(double tRestart) { typedef Dumux::Restart Restarter; Restarter res; - res.deserializeBegin(asImp_(), t); + res.deserializeBegin(asImp_(), tRestart); std::cerr << "Deserialize from file " << res.fileName() << "\n"; timeManager().deserialize(res); - resultWriter_->deserialize(res); + resultWriter().deserialize(res); model().deserialize(res); res.deserializeEnd(); }; + //! Use restart() function instead! + void deserialize(double tRestart) DUNE_DEPRECATED + { restart(tRestart);} // \} void addOutputVtkFields() diff --git a/test/boxmodels/2p/test_2p.cc b/test/boxmodels/2p/test_2p.cc index 871ff00b3351647c1c2adf427ded554cdd46ef89..b9c591f8a7f0371f25d1b61fd74581d5fbfceefe 100644 --- a/test/boxmodels/2p/test_2p.cc +++ b/test/boxmodels/2p/test_2p.cc @@ -175,12 +175,12 @@ int main(int argc, char** argv) // deal with the restart stuff int argPos = 1; bool restart = false; - double restartTime = 0; + double startTime = 0; if (std::string("--restart") == argv[argPos]) { restart = true; ++argPos; - std::istringstream(argv[argPos++]) >> restartTime; + std::istringstream(argv[argPos++]) >> startTime; } if (argc - argPos != 2) { @@ -246,9 +246,7 @@ int main(int argc, char** argv) // instantiate and run the concrete problem TimeManager timeManager; Problem problem(timeManager, grid->leafView(), lowerLeftLens, upperRightLens); - timeManager.init(problem, 0, dt, tEnd, !restart); - if (restart) - problem.restart(restartTime); + timeManager.init(problem, startTime, dt, tEnd, restart); timeManager.run(); return 0; #ifdef NDEBUG diff --git a/test/boxmodels/richards/test_richards.cc b/test/boxmodels/richards/test_richards.cc index 974e8c16070b741030f20bc219c0fc47b4a47082..e835b5372d5beac0d48c5c0df64d469c731e5ff5 100644 --- a/test/boxmodels/richards/test_richards.cc +++ b/test/boxmodels/richards/test_richards.cc @@ -62,12 +62,12 @@ int main(int argc, char** argv) // deal with the restart stuff int argPos = 1; bool restart = false; - double restartTime = 0; + double startTime = 0; if (std::string("--restart") == argv[argPos]) { restart = true; ++argPos; - std::istringstream(argv[argPos++]) >> restartTime; + std::istringstream(argv[argPos++]) >> startTime; } if (argc - argPos != 3) { @@ -97,9 +97,7 @@ int main(int argc, char** argv) // instantiate and run the concrete problem TimeManager timeManager; Problem problem(timeManager, gridPtr->leafView(), lowerLeftLens, upperRightLens); - timeManager.init(problem, 0, dt, tEnd, !restart); - if (restart) - problem.restart(restartTime); + timeManager.init(problem, startTime, dt, tEnd, restart); timeManager.run(); return 0; } diff --git a/test/common/generalproblem/test_generalproblem_2p.cc b/test/common/generalproblem/test_generalproblem_2p.cc index 0538a323243985c5600f70d5d7a469d2a78f2f99..30048bf6799dd5988d457a85cb979a66d82bb6c7 100644 --- a/test/common/generalproblem/test_generalproblem_2p.cc +++ b/test/common/generalproblem/test_generalproblem_2p.cc @@ -74,7 +74,6 @@ int main(int argc, char** argv) if (argc < 4) usage(argv[0]); - // deal with the restart stuff int argPos = 1; bool useBoxModel = false; bool useDecoupledModel = false; @@ -133,7 +132,7 @@ int main(int argc, char** argv) BoxTimeManager timeManager; Dumux::GeneralLensProblem<BoxTypeTag> problem(timeManager, grid->leafView(), lowerLeftLens, upperRightLens); problem.setName("generallens_box"); - timeManager.init(problem, 0, dt, tEnd, true); + timeManager.init(problem, 0, dt, tEnd, false); timeManager.run(); return 0; } @@ -142,7 +141,7 @@ int main(int argc, char** argv) DecoupledTimeManager timeManager; Dumux::GeneralLensProblem<DecoupledTypeTag> problem(timeManager, grid->leafView(), lowerLeftLens, upperRightLens); problem.setName("generallens_decoupled"); - timeManager.init(problem, 0, dt, tEnd, true); + timeManager.init(problem, 0, dt, tEnd, false); timeManager.run(); return 0; } diff --git a/test/decoupled/2p/test_impes.cc b/test/decoupled/2p/test_impes.cc index e1acad1a056b80b224a8217134ccc29feb7479f6..9b66a14449e915374a1475dde656281ef2961e03 100644 --- a/test/decoupled/2p/test_impes.cc +++ b/test/decoupled/2p/test_impes.cc @@ -110,11 +110,8 @@ int main(int argc, char** argv) TimeManager timeManager; Problem problem(timeManager, grid.leafView()); - // load restart file if necessarry - if (restart) - problem.deserialize(restartTime); - - timeManager.init(problem, 0, dt, tEnd, !restart); + // use restart file if necessarry + timeManager.init(problem, restartTime, dt, tEnd, restart); timeManager.run(); return 0; } diff --git a/test/decoupled/2p/test_transport.cc b/test/decoupled/2p/test_transport.cc index 90f19e76cc7791773afe33b176d61ca17cbf910b..f996ca14bc50545ee99f06d3634c4757100d42aa 100644 --- a/test/decoupled/2p/test_transport.cc +++ b/test/decoupled/2p/test_transport.cc @@ -97,10 +97,8 @@ int main(int argc, char** argv) TimeManager timeManager; Problem problem(timeManager, gridPtr->leafView()); - // load restart file if necessarry - if (restart) - problem.deserialize(restartTime); - timeManager.init(problem, 0, dt, tEnd, !restart); + // use restart file if necessarry + timeManager.init(problem, restartTime, dt, tEnd, restart); timeManager.run(); return 0; diff --git a/test/decoupled/2p2c/test_dec2p2c.cc b/test/decoupled/2p2c/test_dec2p2c.cc index 99fd5619a9f4872b1e94e76dd17f37ef68744834..81dc53f8276eff4d2324f73017f9904fedbec66b 100644 --- a/test/decoupled/2p2c/test_dec2p2c.cc +++ b/test/decoupled/2p2c/test_dec2p2c.cc @@ -68,7 +68,7 @@ int main(int argc, char** argv) // deal with the restart stuff int argPos = 1; bool restart = false; - double restartTime = 0; + double startTime = 0; // deal with start parameters double tEnd= 3e3; double firstDt = 200; @@ -79,7 +79,7 @@ int main(int argc, char** argv) restart = true; ++argPos; - std::istringstream(argv[argPos++]) >> restartTime; + std::istringstream(argv[argPos++]) >> startTime; } if (argc - argPos == 2) { @@ -116,12 +116,8 @@ int main(int argc, char** argv) TimeManager timeManager; Problem problem(timeManager, grid.leafView(), L, H); - // load restart file if necessarry - if (restart) - problem.deserialize(restartTime); - // initialize the simulation - timeManager.init(problem, 0, firstDt, tEnd, !restart); + timeManager.init(problem, startTime, firstDt, tEnd, restart); // run the simulation timeManager.run(); return 0; diff --git a/test/decoupled/2p2c/test_multiphysics2p2c.cc b/test/decoupled/2p2c/test_multiphysics2p2c.cc index 3c047a685b8b26f74717c96ff334c11bf911b585..ee49f5aeaffaae265ab056eaf8f4ce82261d7008 100644 --- a/test/decoupled/2p2c/test_multiphysics2p2c.cc +++ b/test/decoupled/2p2c/test_multiphysics2p2c.cc @@ -67,7 +67,7 @@ int main(int argc, char** argv) // deal with the restart stuff int argPos = 1; bool restart = false; - double restartTime = 0; + double startTime = 0; // deal with start parameters double tEnd= 3e3; double firstDt = 200; @@ -78,7 +78,7 @@ int main(int argc, char** argv) restart = true; ++argPos; - std::istringstream(argv[argPos++]) >> restartTime; + std::istringstream(argv[argPos++]) >> startTime; } if (argc - argPos == 2) { @@ -109,12 +109,8 @@ int main(int argc, char** argv) TimeManager timeManager; Problem problem(timeManager, grid.leafView(), L, H); - // load restart file if necessarry - if (restart) - problem.deserialize(restartTime); - // initialize the simulation - timeManager.init(problem, 0, firstDt, tEnd, !restart); + timeManager.init(problem, startTime, firstDt, tEnd, !restart); // run the simulation timeManager.run(); return 0; diff --git a/test/decoupled/2padaptive/test_impes_adaptive.cc b/test/decoupled/2padaptive/test_impes_adaptive.cc index 64c2b9028dbaccaa1ee295438bd59ceb070e925d..d19d9c0d3b76b7a9fb0c683143e30bd562ca0394 100644 --- a/test/decoupled/2padaptive/test_impes_adaptive.cc +++ b/test/decoupled/2padaptive/test_impes_adaptive.cc @@ -77,12 +77,12 @@ int main(int argc, char** argv) // deal with the restart stuff int argPos = 1; bool restart = false; - double restartTime = 0; + double startTime = 0; if (std::string("--restart") == argv[argPos]) { restart = true; ++argPos; - std::istringstream(argv[argPos++]) >> restartTime; + std::istringstream(argv[argPos++]) >> startTime; } if (argc - argPos != 1) { @@ -136,11 +136,7 @@ int main(int argc, char** argv) problem.setGrid(*gridPtr); problem.gridAdapt().setLevels(Params::tree().get<int>("levelMin"), Params::tree().get<int>("levelMax")); - // load restart file if necessarry - if (restart) - problem.deserialize(restartTime); - - timeManager.init(problem, 0, dt, tEnd, !restart); + timeManager.init(problem, startTime, dt, tEnd, !restart); timeManager.run(); return 0; } diff --git a/tutorial/tutorial_coupled.cc b/tutorial/tutorial_coupled.cc index a480304819e54eaf6fd655564c3c3f8d8cc753cf..6180582823246e18ca4d8bead94cf0ab1c97ab67 100644 --- a/tutorial/tutorial_coupled.cc +++ b/tutorial/tutorial_coupled.cc @@ -54,12 +54,12 @@ int main(int argc, char** argv) // parse restart time if restart is requested int argPos = 1; bool restart = false; - double restartTime = 0; + double startTime = 0; if (std::string("--restart") == argv[argPos]) { restart = true; ++argPos; - - std::istringstream(argv[argPos++]) >> restartTime; + // use restart time as start time + std::istringstream(argv[argPos++]) >> startTime; } // read the initial time step and the end time @@ -78,10 +78,7 @@ int main(int argc, char** argv) // instantiate the problem on the leaf grid Problem problem(timeManager, gridPtr->leafView()); /*@\label{tutorial-coupled:instantiate-problem}@*/ - timeManager.init(problem, 0, dt, tEnd, !restart); - // load some previously saved state from disk - if (restart) - problem.restart(restartTime); /*@\label{tutorial-coupled:begin-restart}@*/ + timeManager.init(problem, startTime, dt, tEnd, restart); /*@\label{tutorial-coupled:initTimeManager}@*/ // run the simulation timeManager.run(); /*@\label{tutorial-coupled:execute}@*/ return 0; diff --git a/tutorial/tutorial_decoupled.cc b/tutorial/tutorial_decoupled.cc index 68eab2cd969a34cfeecac95424035ad97b01da20..0a9034799281d4d5633178d8e48fdee9db4ea78d 100644 --- a/tutorial/tutorial_decoupled.cc +++ b/tutorial/tutorial_decoupled.cc @@ -71,12 +71,12 @@ int main(int argc, char** argv) // deal with the restart stuff int argPos = 1; bool restart = false; - double restartTime = 0; + double startTime = 0.; if (std::string("--restart") == argv[argPos]) { restart = true; ++argPos; - - std::istringstream(argv[argPos++]) >> restartTime; + // use restart time as start time + std::istringstream(argv[argPos++]) >> startTime; } // output in case of wrong numbers of input parameters if (argc - argPos != 1) { @@ -100,11 +100,7 @@ int main(int argc, char** argv) Problem problem(timeManager, gridPtr->leafView()); /*@\label{tutorial-decoupled:instantiate-problem}@*/ // define simulation parameters - timeManager.init(problem, 0, dt, tEnd, !restart); /*@\label{tutorial-decoupled:initTimeManager}@*/ - - // load restart file if necessary - if (restart) /*@\label{tutorial-decoupled:mainRestart}@*/ - problem.deserialize(restartTime); + timeManager.init(problem, startTime, dt, tEnd, restart); /*@\label{tutorial-decoupled:initTimeManager}@*/ // run the simulation timeManager.run(); /*@\label{tutorial-decoupled:execute}@*/