diff --git a/NumLib/TimeStepping/Algorithms/IterationNumberBasedTimeStepping.cpp b/NumLib/TimeStepping/Algorithms/IterationNumberBasedTimeStepping.cpp index 497757b294c65ab5e3b763e1ea9c20a0bae38201..b240bca0a67fb2db8a7050de71670b90533a6d07 100644 --- a/NumLib/TimeStepping/Algorithms/IterationNumberBasedTimeStepping.cpp +++ b/NumLib/TimeStepping/Algorithms/IterationNumberBasedTimeStepping.cpp @@ -52,9 +52,9 @@ IterationNumberBasedTimeStepping::IterationNumberBasedTimeStepping( { OGS_FATAL("Vector of iteration numbers must be sorted."); } - // - // Remove possible duplicated elements and sort in descending order. - BaseLib::makeVectorUnique(_fixed_output_times, std::greater<double>()); + + // Remove possible duplicated elements. Result will be sorted. + BaseLib::makeVectorUnique(_fixed_output_times); } bool IterationNumberBasedTimeStepping::next(double const /*solution_error*/, @@ -79,7 +79,7 @@ bool IterationNumberBasedTimeStepping::next(double const /*solution_error*/, // prepare the next time step info _ts_current = _ts_prev; - _ts_current += checkSpecificTimeReached(getNextTimeStepSize()); + _ts_current += possiblyClampToNextFixedTime(getNextTimeStepSize()); return true; } @@ -133,19 +133,22 @@ double IterationNumberBasedTimeStepping::getNextTimeStepSize() const return dt; } -double IterationNumberBasedTimeStepping::checkSpecificTimeReached(const double h_new) +double IterationNumberBasedTimeStepping::possiblyClampToNextFixedTime( + const double h_new) const { - if (_fixed_output_times.empty()) + auto const specific_time = + std::upper_bound(std::cbegin(_fixed_output_times), + std::cend(_fixed_output_times), _ts_current.current()); + + if (specific_time == std::cend(_fixed_output_times)) { return h_new; } - const double specific_time = _fixed_output_times.back(); - if ((specific_time > _ts_current.current()) && - (_ts_current.current() + h_new - specific_time > 0.0)) + if ((*specific_time > _ts_current.current()) && + (_ts_current.current() + h_new - *specific_time > 0.0)) { - _fixed_output_times.pop_back(); - return specific_time - _ts_current.current(); + return *specific_time - _ts_current.current(); } return h_new; @@ -158,8 +161,8 @@ void IterationNumberBasedTimeStepping::addFixedOutputTimes( extra_fixed_output_times.begin(), extra_fixed_output_times.end()); - // Remove possible duplicated elements and sort in descending order. - BaseLib::makeVectorUnique(_fixed_output_times, std::greater<double>()); + // Remove possible duplicated elements. Result will be sorted. + BaseLib::makeVectorUnique(_fixed_output_times); } bool IterationNumberBasedTimeStepping::accepted() const diff --git a/NumLib/TimeStepping/Algorithms/IterationNumberBasedTimeStepping.h b/NumLib/TimeStepping/Algorithms/IterationNumberBasedTimeStepping.h index 2bca95f977ee3e381c19a58fe9382f490d6bb8b7..f911e773d12a6579f2b7156696c1597bf1d12060 100644 --- a/NumLib/TimeStepping/Algorithms/IterationNumberBasedTimeStepping.h +++ b/NumLib/TimeStepping/Algorithms/IterationNumberBasedTimeStepping.h @@ -116,7 +116,9 @@ private: /// Find a multiplier for the given number of iterations. double findMultiplier(int number_iterations) const; - double checkSpecificTimeReached(const double h_new); + /// If any time will be reached with given time increment, it will be + /// reduced, otherwise the input will be returned. + double possiblyClampToNextFixedTime(const double h_new) const; /// This vector stores the number of iterations to which the respective /// multiplier coefficient will be applied.