Commit ab4be264 authored by Martin Beck's avatar Martin Beck
Browse files

Merge branch 'fix/restartAndEpisodes' into 'master'

Fix/restart and episodes

For me it would be more intuitive to first advance the time level and then do all the processing and file writing. However this is more complicated, therefore I shifted the restart stuff to the same level as the vtk output stuff.

See merge request !310
parent 3eba4bac
......@@ -17,6 +17,10 @@ Differences Between DuMuX 2.10 and DuMuX 2.11
* IMPROVEMENTS and ENHANCEMENTS:
* IMMEDIATE INTERFACE CHANGES not allowing/requiring a deprecation period:
- shouldWriteRestartFile() is now, as shouldWriteOutput() already was,
called before the time level is advanced. So it might be necessary to use
...WillBeFinished instead of ...IsFinished for writing restart files at
the correct time.
- In the ZeroEq models, the properties BBoxMinIsWall and BBoxMaxIsWall have
been replaced by the functions bBoxMaxIsWall() and bBoxMaxIsWall() in the
problem file.
......
......@@ -337,16 +337,32 @@ public:
* \brief Returns true if the current episode is finished at the
* current time.
*/
bool episodeIsOver() const
bool episodeIsFinished() const
{ return time() >= episodeStartTime_ + episodeLength(); }
/*!
* \brief Returns true if the current episode will be finished
* after the current time step.
*/
bool episodeWillBeOver() const
bool episodeWillBeFinished() const
{ return time() + timeStepSize() >= episodeStartTime_ + episodeLength(); }
/*!
* \brief Returns true if the current episode is finished at the
* current time.
*/
DUNE_DEPRECATED_MSG("episodeIsOver() is deprecated and has been replaced by episodeIsFinished() instead.")
bool episodeIsOver() const
{ return episodeIsFinished(); }
/*!
* \brief Returns true if the current episode will be finished
* after the current time step.
*/
DUNE_DEPRECATED_MSG("episodeWillBeOver() is deprecated and has been replaced by episodeWillBeFinished() instead.")
bool episodeWillBeOver() const
{ return episodeWillBeFinished(); }
/*!
* \brief Aligns the time step size to the episode boundary if the
......@@ -358,7 +374,7 @@ public:
// wants to give it some extra time, we will return
// the time step size it suggested instead of trying
// to align it to the end of the episode.
if (episodeIsOver())
if (episodeIsFinished())
return 0.0;
// make sure that we don't exceed the end of the
......@@ -401,6 +417,10 @@ public:
// prepare the model for the next time integration
problem_->advanceTimeLevel();
// write restart file if mandated by the problem
if (problem_->shouldWriteRestartFile())
problem_->serialize();
// advance the simulated time by the current time step size
time_ += dt;
++timeStepIdx_;
......@@ -414,12 +434,8 @@ public:
<<"\n";
}
// write restart file if mandated by the problem
if (problem_->shouldWriteRestartFile())
problem_->serialize();
// notify the problem if an episode is finished
if (episodeIsOver()) {
if (episodeIsFinished()) {
//define what to do at the end of an episode in the problem
problem_->episodeEnd();
......@@ -469,8 +485,8 @@ public:
res.serializeStream() << episodeIndex_ << " "
<< episodeStartTime_ << " "
<< episodeLength_ << " "
<< time_ << " "
<< timeStepIdx_ << " ";
<< time_ + timeStepSize() << " "
<< timeStepIdx_ + 1 << " ";
res.serializeSectionEnd();
}
......
......@@ -105,12 +105,11 @@ public:
#if HAVE_DUNE_ALUGRID
Dune::BackupRestoreFacility<Grid>::backup(problem.grid(), gridName);
#else
double time = problem.timeManager().time();
problem.grid().template writeGrid
#if ! DUNE_VERSION_NEWER(DUNE_COMMON, 2, 5)
<Dune::xdr>
#endif // Dune < 3.0
(gridName, time);
(gridName, problem.timeManager().time() + problem.timeManager().timeStepSize());
#endif
}
......@@ -139,7 +138,8 @@ private:
std::cerr << "Be sure to provide a parameter Problem.Name if you want to restart." << std::endl;
oss << problem.name();
}
oss << "_time=" << problem.timeManager().time() << "_rank=" << rank << ".grs";
oss << "_time=" << problem.timeManager().time() + problem.timeManager().timeStepSize()
<< "_rank=" << rank << ".grs";
return oss.str();
}
};
......
......@@ -93,7 +93,7 @@ public:
const std::string magicCookie = magicRestartCookie_(problem.gridView());
fileName_ = restartFileName_(problem.gridView(),
problem.name(),
problem.timeManager().time());
problem.timeManager().time()+problem.timeManager().timeStepSize());
// open output file and write magic cookie
outStream_.open(fileName_.c_str());
......
......@@ -286,7 +286,7 @@ void FVPressure2P2C<TypeTag>::getStorage(Dune::FieldVector<Scalar, 2>& storageEn
// Abort error damping if there will be a possibly tiny timestep compared with last one
// This might be the case if the episode or simulation comes to an end.
if( problem().timeManager().episodeWillBeOver()
if( problem().timeManager().episodeWillBeFinished()
|| problem().timeManager().willBeFinished())
{
problem().variables().cellData(eIdxGlobalI).errorCorrection() = 0.;
......
......@@ -453,7 +453,7 @@ void FVPressure2P2CMultiPhysics<TypeTag>::get1pStorage(Dune::FieldVector<Scalar,
// Abort error damping if there will be a possibly tiny timestep compared with last one
// This might be the case if the episode or simulation comes to an end.
if( problem().timeManager().episodeWillBeOver()
if( problem().timeManager().episodeWillBeFinished()
|| problem().timeManager().willBeFinished())
{
problem().variables().cellData(eIdxGlobalI).errorCorrection() = 0.;
......@@ -876,7 +876,7 @@ void FVPressure2P2CMultiPhysics<TypeTag>::updateMaterialLaws(bool postTimeStep)
timer_.stop();
if(problem().timeManager().willBeFinished() or problem().timeManager().episodeWillBeOver())
if(problem().timeManager().willBeFinished() or problem().timeManager().episodeWillBeFinished())
Dune::dinfo << "Subdomain routines took " << timer_.elapsed() << " seconds" << std::endl;
return;
......
......@@ -500,13 +500,13 @@ public:
{
if (timeManager().timeStepIndex() % outputInterval_ == 0
|| timeManager().willBeFinished()
|| timeManager().episodeWillBeOver())
|| timeManager().episodeWillBeFinished())
{
return true;
}
}
else if (timeManager().willBeFinished()
|| timeManager().episodeWillBeOver() || timeManager().timeStepIndex() == 0)
|| timeManager().episodeWillBeFinished() || timeManager().timeStepIndex() == 0)
{
return true;
}
......
......@@ -434,13 +434,13 @@ public:
{
if (timeManager().timeStepIndex() % outputInterval_ == 0
|| timeManager().willBeFinished()
|| timeManager().episodeWillBeOver())
|| timeManager().episodeWillBeFinished())
{
return true;
}
}
else if (timeManager().willBeFinished()
|| timeManager().episodeWillBeOver() || timeManager().timeStepIndex() == 0)
|| timeManager().episodeWillBeFinished() || timeManager().timeStepIndex() == 0)
{
return true;
}
......
......@@ -222,7 +222,7 @@ public:
{
if (this->timeManager().time() < eps_ ||
this->timeManager().willBeFinished() ||
this->timeManager().episodeWillBeOver())
this->timeManager().episodeWillBeFinished())
{
return true;
}
......
......@@ -221,7 +221,7 @@ public:
bool shouldWriteRestartFile() const
{
return (this->timeManager().timeStepIndex() % freqRestart_ == 0
|| this->timeManager().episodeWillBeOver()
|| this->timeManager().episodeWillBeFinished()
|| this->timeManager().willBeFinished());
}
......@@ -236,7 +236,7 @@ public:
bool shouldWriteOutput() const
{
return (this->timeManager().timeStepIndex() % freqOutput_ == 0
|| this->timeManager().episodeWillBeOver()
|| this->timeManager().episodeWillBeFinished()
|| this->timeManager().willBeFinished());
}
......
......@@ -360,7 +360,7 @@ public:
if (this->gridView().comm().rank() == 0)
{
if (this->timeManager().timeStepIndex() % freqMassOutput_ == 0
|| this->timeManager().episodeWillBeOver())
|| this->timeManager().episodeWillBeFinished())
{
PrimaryVariables storageChange(0.);
storageChange = storageLastTimestep_ - storage;
......
......@@ -185,7 +185,7 @@ public:
{
return (((this->timeManager().timeStepIndex() > 0)
&& (this->timeManager().timeStepIndex() % freqRestart_ == 0))
|| this->timeManager().episodeWillBeOver()
|| this->timeManager().episodeWillBeFinished()
|| this->timeManager().willBeFinished());
}
......@@ -193,7 +193,7 @@ public:
bool shouldWriteOutput() const
{
return (this->timeManager().timeStepIndex() % freqOutput_ == 0
|| this->timeManager().episodeWillBeOver()
|| this->timeManager().episodeWillBeFinished()
|| this->timeManager().willBeFinished());
}
......
......@@ -308,7 +308,7 @@ public:
if (this->gridView().comm().rank() == 0)
{
if (this->timeManager().timeStepIndex() % freqMassOutput_ == 0
|| this->timeManager().episodeWillBeOver())
|| this->timeManager().episodeWillBeFinished())
{
PrimaryVariables storageChange(0.);
storageChange = storageLastTimestep_ - storage;
......
......@@ -220,7 +220,7 @@ public:
bool shouldWriteRestartFile() const
{
return (this->timeManager().timeStepIndex() % freqRestart_ == 0
|| this->timeManager().episodeWillBeOver()
|| this->timeManager().episodeWillBeFinished()
|| this->timeManager().willBeFinished());
}
......@@ -235,7 +235,7 @@ public:
bool shouldWriteOutput() const
{
return (this->timeManager().timeStepIndex() % freqOutput_ == 0
|| this->timeManager().episodeWillBeOver()
|| this->timeManager().episodeWillBeFinished()
|| this->timeManager().willBeFinished());
}
......
......@@ -337,7 +337,7 @@ public:
if (this->gridView().comm().rank() == 0)
{
if (this->timeManager().timeStepIndex() % freqMassOutput_ == 0
|| this->timeManager().episodeWillBeOver())
|| this->timeManager().episodeWillBeFinished())
{
PrimaryVariables storageChange(0.);
storageChange = storageLastTimestep_ - storage;
......
......@@ -188,7 +188,7 @@ public:
return ( ((this->timeManager().timeStepIndex() > 0)
&& (this->timeManager().timeStepIndex() % freqRestart_ == 0))
// also write a restart file at the end of each episode
|| this->timeManager().episodeWillBeOver()
|| this->timeManager().episodeWillBeFinished()
|| this->timeManager().willBeFinished());
}
......@@ -196,7 +196,7 @@ public:
bool shouldWriteOutput() const
{
return (this->timeManager().timeStepIndex() % freqOutput_ == 0
|| this->timeManager().episodeWillBeOver()
|| this->timeManager().episodeWillBeFinished()
|| this->timeManager().willBeFinished());
}
......
......@@ -303,7 +303,7 @@ public:
if (this->gridView().comm().rank() == 0)
{
if (this->timeManager().timeStepIndex() % freqMassOutput_ == 0
|| this->timeManager().episodeWillBeOver())
|| this->timeManager().episodeWillBeFinished())
{
PrimaryVariables storageChange(0.);
storageChange = storageLastTimestep_ - storage;
......
......@@ -150,7 +150,7 @@ public:
return
this->timeManager().timeStepIndex() == 0 ||
this->timeManager().timeStepIndex() % outputInterval_ == 0 ||
this->timeManager().episodeWillBeOver() ||
this->timeManager().episodeWillBeFinished() ||
this->timeManager().willBeFinished();
}
......
......@@ -157,7 +157,7 @@ public:
return
this->timeManager().timeStepIndex() == 0 ||
this->timeManager().timeStepIndex() % outputInterval_ == 0 ||
this->timeManager().episodeWillBeOver() ||
this->timeManager().episodeWillBeFinished() ||
this->timeManager().willBeFinished();
}
......
......@@ -158,7 +158,7 @@ public:
return
this->timeManager().timeStepIndex() == 0 ||
this->timeManager().timeStepIndex() % outputInterval_ == 0 ||
this->timeManager().episodeWillBeOver() ||
this->timeManager().episodeWillBeFinished() ||
this->timeManager().willBeFinished();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment