diff --git a/dumux/implicit/problem.hh b/dumux/implicit/problem.hh index 28ce5c6b31c8daa8bf219290a2c37ceb20be0bcb..f1da19bcdbf725df559eaef6c5bd2a47a5bbe2a2 100644 --- a/dumux/implicit/problem.hh +++ b/dumux/implicit/problem.hh @@ -637,11 +637,29 @@ public: << nextDt << " seconds\n"; } + // if the simulation run is about to abort, write restart files for the current and previous time steps: + // write restart file for the current time step + serialize(); + + //write restart file for the previous time step: + //set the time manager and the solution vector to the previous time step + const Scalar time = timeManager().time(); + timeManager().setTime(time - timeManager().previousTimeStepSize()); + const auto curSol = model_.curSol(); + model_.curSol() = model_.prevSol(); + //write restart file + serialize(); + //reset time manager and solution vector + model_.curSol() = curSol; + timeManager().setTime(time); + DUNE_THROW(Dune::MathError, "Newton solver didn't converge after " << maxFails << " time-step divisions. dt=" - << timeManager().timeStepSize()); + << timeManager().timeStepSize() + << ".\nThe solutions of the current and the previous time steps " + << "have been saved to restart files."); } /*!