Commit bb1e203e authored by Kilian Weishaupt's avatar Kilian Weishaupt
Browse files

Merge branch 'fix/issue-928' into 'master'

[common] make sure dt != 0 in timeloop

Closes #928

See merge request !2237
parents 5bf89b0c bff85733
......@@ -256,6 +256,12 @@ public:
{
using std::min;
timeStepSize_ = min(dt, maxTimeStepSize());
if (!finished() && Dune::FloatCmp::le(timeStepSize_, 0.0, 1e-14*endTime_))
{
std::cerr << "You have set a very small timestep size (dt = "
<< timeStepSize_ << "). This might lead to numerical problems!"
<< std::endl;
}
}
/*!
......@@ -590,7 +596,7 @@ private:
//! Adds a check point to the queue
void setCheckPoint_(Scalar t)
{
if (t < this->time())
if (Dune::FloatCmp::le(t - this->time(), 0.0, this->timeStepSize()*1e-7))
{
if (this->verbose())
std::cerr << "Couldn't insert checkpoint at t = " << t
......
......@@ -61,7 +61,6 @@ int main(int argc, char* argv[]) try
DUNE_THROW(Dune::InvalidStateException, "Ended with wrong end time!");
}
// check point timeLoop
{
if (mpiHelper.rank() == 0) std::cout << std::endl << "------- Test check point time loop ----------" << std::endl;
......@@ -160,6 +159,44 @@ int main(int argc, char* argv[]) try
timeLoop.reportTimeStep();
}
// check if setting the checkpoint at the current time shows error message
{
// redirect std::cerr
std::stringstream cerrBuffer;
std::streambuf* cerrOriginal = std::cerr.rdbuf(cerrBuffer.rdbuf());
Dumux::CheckPointTimeLoop<double> timeLoop(tStart, dt, tEnd);
timeLoop.setCheckPoint(tStart);
// get result and reset buffer
const auto result = cerrBuffer.str();
std::cerr.rdbuf(cerrOriginal);
std::cout << "Setting check point at the current time printed '" << result << "' to std::cerr" << std::endl;
if (result.empty())
DUNE_THROW(Dune::Exception, "Setting a checkpoint at the current time should print a warning to std::cerr");
if (Dune::FloatCmp::eq(timeLoop.timeStepSize(), 0.0, 1e-10*tEnd))
DUNE_THROW(Dune::Exception, "Time Loop reduced time step size to 0!");
}
// check if setting timestep to zero shows error message
{
// redirect std::cerr
std::stringstream cerrBuffer;
std::streambuf* cerrOriginal = std::cerr.rdbuf(cerrBuffer.rdbuf());
Dumux::TimeLoop<double> timeLoop(tStart, dt, tEnd);
timeLoop.setTimeStepSize(0.0);
// get result and reset buffer
const auto result = cerrBuffer.str();
std::cerr.rdbuf(cerrOriginal);
std::cout << "Setting zero time step printed '" << result << "' to std::cerr" << std::endl;
if (result.empty())
DUNE_THROW(Dune::Exception, "Setting a zero timeStepSize should print a warning to std::cerr");
}
return 0;
}
// //////////////////////////////////
......
Supports Markdown
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