diff --git a/NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.cpp b/NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.cpp index 405d87d3a563cda75e7df08724feeb0f5f6abc09..8daf20de7d3cb915c75b3b05b4c91e06a4996b4d 100644 --- a/NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.cpp +++ b/NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.cpp @@ -142,25 +142,26 @@ double EvolutionaryPIDcontroller::limitStepSize( return limited_h; } - // find first fixed timestep for output larger than the current time, i.e., + // find first fixed output time larger than the current time, i.e., // current time < fixed output time auto fixed_output_time_it = std::find_if( std::begin(_fixed_times_for_output), std::end(_fixed_times_for_output), [×tep_current](auto const fixed_output_time) - { return timestep_current.current() < fixed_output_time; }); + { return timestep_current.current() < Time{fixed_output_time}; }); if (fixed_output_time_it != _fixed_times_for_output.end()) { // check if the fixed output time is in the interval // (current time, current time + limited_h) - if (*fixed_output_time_it < timestep_current.current() + limited_h) + if (Time{*fixed_output_time_it} < + timestep_current.current() + limited_h) { // check if the potential adjusted time step is larger than zero - if (std::abs(*fixed_output_time_it - timestep_current.current()) > + if (std::abs(*fixed_output_time_it - timestep_current.current()()) > std::numeric_limits<double>::epsilon() * - timestep_current.current()) + timestep_current.current()()) { - return *fixed_output_time_it - timestep_current.current(); + return *fixed_output_time_it - timestep_current.current()(); } } } diff --git a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp index 4d4cec4cb1737ed744fe8718997da923b529c0d3..cd4ce7d795a5102f6139273ab78e4224ac4373e4 100644 --- a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp +++ b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp @@ -17,11 +17,14 @@ #include <limits> #include <numeric> +#include "NumLib/TimeStepping/Time.h" + namespace { /// Returns sum of the newly added time increments. -double addTimeIncrement(std::vector<double>& delta_ts, std::size_t const repeat, - double const delta_t, double const t_curr) +NumLib::Time addTimeIncrement(std::vector<double>& delta_ts, + std::size_t const repeat, double const delta_t, + NumLib::Time const t_curr) { auto const new_size = delta_ts.size() + repeat; try @@ -48,7 +51,7 @@ double addTimeIncrement(std::vector<double>& delta_ts, std::size_t const repeat, namespace NumLib { -std::size_t findDeltatInterval(double const t_initial, +std::size_t findDeltatInterval(NumLib::Time const t_initial, std::vector<double> const& delta_ts, double const fixed_output_time) { @@ -72,7 +75,8 @@ std::size_t findDeltatInterval(double const t_initial, } void incorporateFixedTimesForOutput( - double const t_initial, double const t_end, std::vector<double>& delta_ts, + NumLib::Time const t_initial, NumLib::Time const t_end, + std::vector<double>& delta_ts, std::vector<double> const& fixed_times_for_output) { if (fixed_times_for_output.empty()) @@ -89,18 +93,19 @@ void incorporateFixedTimesForOutput( "Request for output at times {}, but the simulation's start time " "is {}. Output will be skipped.", fmt::join(begin(fixed_times_for_output), lower_bound, ", "), - t_initial); + t_initial()); } - if (auto upper_bound = std::upper_bound(begin(fixed_times_for_output), - end(fixed_times_for_output), t_end); + if (auto upper_bound = + std::upper_bound(begin(fixed_times_for_output), + end(fixed_times_for_output), t_end()); upper_bound != end(fixed_times_for_output)) { WARN( "Request for output at times {}, but simulation's end time is {}. " "Output will be skipped.", fmt::join(upper_bound, end(fixed_times_for_output), ", "), - t_end); + t_end()); } if (delta_ts.empty()) @@ -120,23 +125,23 @@ void incorporateFixedTimesForOutput( fixed_time_for_output); continue; } + auto const lower_bound = std::accumulate( begin(delta_ts), begin(delta_ts) + interval_number, t_initial); auto const upper_bound = lower_bound + delta_ts[interval_number]; - if (fixed_time_for_output - lower_bound <= - TimeStep::minimalTimeStepSize) + // in order to use the comparison from struct Time + if (NumLib::Time(fixed_time_for_output) == lower_bound) { continue; } - if (upper_bound - fixed_time_for_output <= - TimeStep::minimalTimeStepSize) + if (upper_bound == NumLib::Time(fixed_time_for_output)) { continue; } - delta_ts[interval_number] = fixed_time_for_output - lower_bound; + delta_ts[interval_number] = fixed_time_for_output - lower_bound(); delta_ts.insert(delta_ts.begin() + interval_number + 1, - upper_bound - fixed_time_for_output); + upper_bound() - fixed_time_for_output); } } @@ -145,7 +150,7 @@ FixedTimeStepping::FixedTimeStepping( std::vector<double> const& fixed_times_for_output) : TimeStepAlgorithm(t0, tn) { - double t_curr = _t_initial; + Time t_curr = _t_initial; if (!areRepeatDtPairsValid(repeat_dt_pairs)) { @@ -163,8 +168,8 @@ FixedTimeStepping::FixedTimeStepping( if (t_curr <= _t_end) { auto const delta_t = std::get<1>(repeat_dt_pairs.back()); - auto const repeat = - static_cast<std::size_t>(std::ceil((_t_end - t_curr) / delta_t)); + auto const repeat = static_cast<std::size_t>( + std::ceil((_t_end() - t_curr()) / delta_t)); addTimeIncrement(_dt_vector, repeat, delta_t, t_curr); } @@ -210,16 +215,15 @@ std::tuple<bool, double> FixedTimeStepping::next( { // check if last time step if (ts_current.timeStepNumber() == _dt_vector.size() || - std::abs(ts_current.current() - end()) < - std::numeric_limits<double>::epsilon()) + ts_current.current() >= end()) { return std::make_tuple(true, 0.0); } double dt = _dt_vector[ts_current.timeStepNumber()]; - if (ts_current.current() + dt > end()) + if (ts_current.current()() + dt > end()) { // upper bound by t_end - dt = end() - ts_current.current(); + dt = end() - ts_current.current()(); } return std::make_tuple(true, dt); diff --git a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.h b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.h index d12bade3295902aeabb1e186a2b16815ba6401d1..f340248f928f4e65321dbe0c492b7867987a73e6 100644 --- a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.h +++ b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.h @@ -64,7 +64,7 @@ private: std::vector<double> _dt_vector; }; -std::size_t findDeltatInterval(double const t_initial, +std::size_t findDeltatInterval(NumLib::Time const t_initial, std::vector<double> const& delta_ts, double const fixed_output_time); } // namespace NumLib diff --git a/NumLib/TimeStepping/Algorithms/IterationNumberBasedTimeStepping.cpp b/NumLib/TimeStepping/Algorithms/IterationNumberBasedTimeStepping.cpp index ef3fc7fd793bf39402556077e16e4e23e4c3620d..4724f86a2940c9c0b077e59601f02fad4dd1f97c 100644 --- a/NumLib/TimeStepping/Algorithms/IterationNumberBasedTimeStepping.cpp +++ b/NumLib/TimeStepping/Algorithms/IterationNumberBasedTimeStepping.cpp @@ -147,19 +147,19 @@ double IterationNumberBasedTimeStepping::getNextTimeStepSize( auto fixed_output_time_it = std::find_if( std::begin(_fixed_times_for_output), std::end(_fixed_times_for_output), [&ts_current](auto const fixed_output_time) - { return ts_current.current() < fixed_output_time; }); + { return ts_current.current()() < fixed_output_time; }); if (fixed_output_time_it != _fixed_times_for_output.end()) { // check if the fixed output time is in the interval // (current time, current time + dt) - if (*fixed_output_time_it < ts_current.current() + dt) + if (*fixed_output_time_it < ts_current.current()() + dt) { // check if the potential adjusted time step is larger than zero - if (std::abs(*fixed_output_time_it - ts_current.current()) > - std::numeric_limits<double>::epsilon() * ts_current.current()) + if (std::abs(*fixed_output_time_it - ts_current.current()()) > + std::numeric_limits<double>::epsilon() * ts_current.current()()) { - return *fixed_output_time_it - ts_current.current(); + return *fixed_output_time_it - ts_current.current()(); } } } diff --git a/NumLib/TimeStepping/Algorithms/TimeStepAlgorithm.cpp b/NumLib/TimeStepping/Algorithms/TimeStepAlgorithm.cpp index 66faa70dca391d404528343a90b63d04662f4329..36e86846c382ee05ace43aa0b90683c7a01c4f4a 100644 --- a/NumLib/TimeStepping/Algorithms/TimeStepAlgorithm.cpp +++ b/NumLib/TimeStepping/Algorithms/TimeStepAlgorithm.cpp @@ -12,24 +12,25 @@ #include <algorithm> #include <limits> +#include "NumLib/TimeStepping/Time.h" + namespace NumLib { double possiblyClampDtToNextFixedTime( - double const t, double const dt, + Time const& t, double const dt, std::vector<double> const& fixed_output_times) { auto const specific_time = std::upper_bound( - std::cbegin(fixed_output_times), std::cend(fixed_output_times), t); + std::cbegin(fixed_output_times), std::cend(fixed_output_times), t()); if (specific_time == std::cend(fixed_output_times)) { return dt; } - double const t_to_specific_time = *specific_time - t; - if ((t_to_specific_time > std::numeric_limits<double>::epsilon()) && - (t + dt - *specific_time > 0.0)) + if ((t < *specific_time) && t + dt > *specific_time) { + double const t_to_specific_time = *specific_time - t(); return t_to_specific_time; } diff --git a/NumLib/TimeStepping/Algorithms/TimeStepAlgorithm.h b/NumLib/TimeStepping/Algorithms/TimeStepAlgorithm.h index c8eff99450c566e0dd8c35209eb00bcd127b7512..736652b53b63b8106d6ff59263a620169c8e77fb 100644 --- a/NumLib/TimeStepping/Algorithms/TimeStepAlgorithm.h +++ b/NumLib/TimeStepping/Algorithms/TimeStepAlgorithm.h @@ -21,6 +21,8 @@ namespace NumLib { +struct Time; + /** * \brief Interface of time stepping algorithms */ @@ -35,9 +37,9 @@ public: virtual ~TimeStepAlgorithm() = default; /// return the beginning of time steps - double begin() const { return _t_initial; } + double begin() const { return _t_initial(); } /// return the end of time steps - double end() const { return _t_end; } + double end() const { return _t_end(); } /// reset the current step size from the previous time virtual void resetCurrentTimeStep(const double /*dt*/, TimeStep& /*ts_previous*/, @@ -73,9 +75,9 @@ public: protected: /// initial time - const double _t_initial; + const Time _t_initial; /// end time - const double _t_end; + const Time _t_end; }; /// If any of the fixed times will be reached with given time increment, it will @@ -85,7 +87,7 @@ protected: /// \param dt Suggested time increment. /// \param fixed_output_times Sorted list of times which are to be reached. double possiblyClampDtToNextFixedTime( - double const t, double const dt, + Time const& t, double const dt, std::vector<double> const& fixed_output_times); bool canReduceTimestepSize(TimeStep const& timestep_previous, diff --git a/NumLib/TimeStepping/TimeStep.h b/NumLib/TimeStepping/TimeStep.h index ce975f36f9181dae34588c95fa12dc2833376ad9..f05c8d1d4fd1da2bf4094e5c83fd84acb153e6cb 100644 --- a/NumLib/TimeStepping/TimeStep.h +++ b/NumLib/TimeStepping/TimeStep.h @@ -15,6 +15,8 @@ #include <cstddef> #include <limits> +#include "Time.h" + namespace NumLib { /** @@ -32,10 +34,10 @@ public: * Initialize a time step * @param current_time current time */ - explicit TimeStep(double current_time) + explicit TimeStep(Time const& current_time) : _previous(current_time), _current(current_time), - _dt(_current - _previous), + _dt(0.0), _time_step_number(0) { } @@ -46,10 +48,10 @@ public: * @param current_time current time * @param n the number of time steps */ - TimeStep(double previous_time, double current_time, std::size_t n) + TimeStep(Time const& previous_time, Time const& current_time, std::size_t n) : _previous(previous_time), _current(current_time), - _dt(_current - _previous), + _dt(_current() - _previous()), _time_step_number(n) { } @@ -83,12 +85,12 @@ public: /// compare current time bool operator==(TimeStep const& ts) const { - return (_current == ts._current); + return _current == ts._current; } /// return previous time step - double previous() const { return _previous; } + Time previous() const { return _previous; } /// return current time step - double current() const { return _current; } + Time current() const { return _current; } /// time step size from _previous double dt() const { return _dt; } /// the time step number @@ -97,14 +99,11 @@ public: void setAccepted(bool const accepted) { _is_accepted = accepted; } bool isAccepted() const { return _is_accepted; } - static constexpr double minimalTimeStepSize = - 1000 * std::numeric_limits<double>::epsilon(); - private: /// previous time step - double _previous; + Time _previous; /// current time step - double _current; + Time _current; /// time step size double _dt; /// the number of time steps diff --git a/Tests/NumLib/TestFixedTimeStepping.cpp b/Tests/NumLib/TestFixedTimeStepping.cpp index 08813926e3a97f8d3c9469bde64146cb25059906..cb5d24f868e5a3061e4708ebbd431550d4bfb7d7 100644 --- a/Tests/NumLib/TestFixedTimeStepping.cpp +++ b/Tests/NumLib/TestFixedTimeStepping.cpp @@ -117,9 +117,8 @@ TEST_F(NumLibFixedTimeStepping, next) // expected time is larger than the minimal time step size then the // step size should be larger // if next is true then the step - if (is_next && std::abs((ts_current.current() + step_size) - - expected_time_point) > - NumLib::TimeStep::minimalTimeStepSize) + if (is_next && + (ts_current.current() + step_size) != expected_time_point) { return false; } @@ -185,9 +184,8 @@ TEST_F(NumLibFixedTimeStepping, next_StaticTest) // expected time is larger than the minimal time step size then the // step size should be larger // if next is true then the step - ASSERT_FALSE(is_next && std::abs((ts_current.current() + step_size) - - expected_time_point) > - NumLib::TimeStep::minimalTimeStepSize); + ASSERT_FALSE(is_next && + (ts_current.current() + step_size) != expected_time_point); // if next is true then the step size should be larger than zero ASSERT_FALSE(is_next && step_size == 0.0); diff --git a/Tests/NumLib/TestTimeStep.cpp b/Tests/NumLib/TestTimeStep.cpp index cdded6c3cdb02547cf677f0bc86e6f7fa2177b92..5664ca4546eb0083cc49fa8fdbba0541b5f43786 100644 --- a/Tests/NumLib/TestTimeStep.cpp +++ b/Tests/NumLib/TestTimeStep.cpp @@ -17,22 +17,22 @@ TEST(NumLib, TimeStep) { // initial - NumLib::TimeStep t1(1.); - ASSERT_EQ(1., t1.current()); - ASSERT_EQ(1., t1.previous()); + NumLib::TimeStep t1{NumLib::Time{1.}}; + ASSERT_EQ(1., t1.current()()); + ASSERT_EQ(1., t1.previous()()); ASSERT_EQ(.0, t1.dt()); ASSERT_EQ(0u, t1.timeStepNumber()); - NumLib::TimeStep t2(0., 1., 1); - ASSERT_EQ(1., t2.current()); - ASSERT_EQ(0., t2.previous()); + NumLib::TimeStep t2{NumLib::Time{0.}, NumLib::Time{1.}, 1}; + ASSERT_EQ(1., t2.current()()); + ASSERT_EQ(0., t2.previous()()); ASSERT_EQ(1., t2.dt()); ASSERT_EQ(1u, t2.timeStepNumber()); // copy const NumLib::TimeStep& t3(t2); - ASSERT_EQ(1., t3.current()); - ASSERT_EQ(0., t3.previous()); + ASSERT_EQ(1., t3.current()()); + ASSERT_EQ(0., t3.previous()()); ASSERT_EQ(1., t3.dt()); ASSERT_EQ(1u, t3.timeStepNumber()); diff --git a/Tests/NumLib/TestTimeSteppingEvolutionaryPIDcontroller.cpp b/Tests/NumLib/TestTimeSteppingEvolutionaryPIDcontroller.cpp index fbe24893f8949ab962e6737a713cd811abd2984c..65c84714ec09bfa45dc11e34ba8b003329f1bd05 100644 --- a/Tests/NumLib/TestTimeSteppingEvolutionaryPIDcontroller.cpp +++ b/Tests/NumLib/TestTimeSteppingEvolutionaryPIDcontroller.cpp @@ -66,8 +66,8 @@ TEST(NumLibTimeStepping, testEvolutionaryPIDcontroller) double h_new = 0.01; double t_previous = 0.; ASSERT_EQ(1u, current_timestep.timeStepNumber()); - ASSERT_EQ(t_previous, current_timestep.previous()); - ASSERT_EQ(t_previous + h_new, current_timestep.current()); + ASSERT_EQ(t_previous, current_timestep.previous()()); + ASSERT_EQ(t_previous + h_new, current_timestep.current()()); ASSERT_EQ(h_new, current_timestep.dt()); ASSERT_TRUE(current_timestep.isAccepted()); t_previous += h_new; @@ -85,8 +85,8 @@ TEST(NumLibTimeStepping, testEvolutionaryPIDcontroller) h_new = current_timestep.dt(); ASSERT_EQ(2u, current_timestep.timeStepNumber()); const double tol = 1.e-16; - ASSERT_NEAR(t_previous, current_timestep.previous(), tol); - ASSERT_NEAR(t_previous + h_new, current_timestep.current(), tol); + ASSERT_NEAR(t_previous, current_timestep.previous()(), tol); + ASSERT_NEAR(t_previous + h_new, current_timestep.current()(), tol); ASSERT_TRUE(current_timestep.isAccepted()); t_previous += h_new; @@ -102,8 +102,8 @@ TEST(NumLibTimeStepping, testEvolutionaryPIDcontroller) /// ts = PIDStepper->getTimeStep(); h_new = current_timestep.dt(); ASSERT_EQ(3u, current_timestep.timeStepNumber()); - ASSERT_NEAR(t_previous, current_timestep.previous(), tol); - ASSERT_NEAR(t_previous + h_new, current_timestep.current(), tol); + ASSERT_NEAR(t_previous, current_timestep.previous()(), tol); + ASSERT_NEAR(t_previous + h_new, current_timestep.current()(), tol); ASSERT_TRUE(current_timestep.isAccepted()); // If error > solution_error, step is rejected and new step size is @@ -118,8 +118,8 @@ TEST(NumLibTimeStepping, testEvolutionaryPIDcontroller) ASSERT_EQ(3u, current_timestep.timeStepNumber()); // No change in current_timestep.previous(), which is the same as that of // the previous step. - ASSERT_NEAR(t_previous, current_timestep.previous(), tol); - ASSERT_NEAR(t_previous + h_new, current_timestep.current(), tol); + ASSERT_NEAR(t_previous, current_timestep.previous()(), tol); + ASSERT_NEAR(t_previous + h_new, current_timestep.current()(), tol); ASSERT_FALSE(current_timestep.isAccepted()); t_previous += h_new; @@ -135,7 +135,7 @@ TEST(NumLibTimeStepping, testEvolutionaryPIDcontroller) /// ts = PIDStepper->getTimeStep(); h_new = current_timestep.dt(); ASSERT_EQ(4u, current_timestep.timeStepNumber()); - ASSERT_NEAR(t_previous, current_timestep.previous(), tol); - ASSERT_NEAR(t_previous + h_new, current_timestep.current(), tol); + ASSERT_NEAR(t_previous, current_timestep.previous()(), tol); + ASSERT_NEAR(t_previous + h_new, current_timestep.current()(), tol); ASSERT_TRUE(current_timestep.isAccepted()); } diff --git a/Tests/NumLib/TestTimeSteppingFixed.cpp b/Tests/NumLib/TestTimeSteppingFixed.cpp index 9d4bbe696914fb5d65ad498c51f5f0d3b15f51ff..5a2ec24c58df02442949614b59e68d1365710625 100644 --- a/Tests/NumLib/TestTimeSteppingFixed.cpp +++ b/Tests/NumLib/TestTimeSteppingFixed.cpp @@ -24,7 +24,8 @@ namespace NumLib { extern void incorporateFixedTimesForOutput( - double t_initial, double t_end, std::vector<double>& timesteps, + NumLib::Time const t_initial, NumLib::Time const t_end, + std::vector<double>& timesteps, std::vector<double> const& fixed_times_for_output); } diff --git a/Tests/NumLib/TestTimeSteppingIterationNumber.cpp b/Tests/NumLib/TestTimeSteppingIterationNumber.cpp index 2463d623bcf38b8f5d98737f8832e41e83fffbde..c2b979b82e0f73cbfa89f622c4700cf7069bd869 100644 --- a/Tests/NumLib/TestTimeSteppingIterationNumber.cpp +++ b/Tests/NumLib/TestTimeSteppingIterationNumber.cpp @@ -36,25 +36,26 @@ TEST(NumLib, TimeSteppingIterationNumberBased1) auto [step_accepted, timestepper_dt] = alg.next(solution_error, 1, previous_timestep, current_timestep); ASSERT_TRUE(step_accepted); - timestepper_dt = (current_timestep.current() + timestepper_dt > end_time) - ? end_time - current_timestep.current() + timestepper_dt = (current_timestep.current()() + timestepper_dt > end_time) + ? end_time - current_timestep.current()() : timestepper_dt; NumLib::updateTimeSteps(timestepper_dt, previous_timestep, current_timestep); alg.resetCurrentTimeStep(timestepper_dt, previous_timestep, current_timestep); ASSERT_EQ(1u, current_timestep.timeStepNumber()); - ASSERT_EQ(1., current_timestep.previous()); - ASSERT_EQ(2., current_timestep.current()); + ASSERT_EQ(1., current_timestep.previous()()); + ASSERT_EQ(2., current_timestep.current()()); ASSERT_EQ(1., current_timestep.dt()); ASSERT_TRUE(current_timestep.isAccepted()); auto [step_accepted1, timestepper_dt1] = alg.next(solution_error, 1, previous_timestep, current_timestep); ASSERT_TRUE(step_accepted1); - timestepper_dt1 = (current_timestep.current() + timestepper_dt1 > end_time) - ? end_time - current_timestep.current() - : timestepper_dt1; + timestepper_dt1 = + (current_timestep.current()() + timestepper_dt1 > end_time) + ? end_time - current_timestep.current()() + : timestepper_dt1; NumLib::updateTimeSteps(timestepper_dt1, previous_timestep, current_timestep); alg.resetCurrentTimeStep(timestepper_dt1, previous_timestep, @@ -63,64 +64,68 @@ TEST(NumLib, TimeSteppingIterationNumberBased1) auto [step_accepted2, timestepper_dt2] = alg.next(solution_error, 3, previous_timestep, current_timestep); ASSERT_TRUE(step_accepted2); - timestepper_dt2 = (current_timestep.current() + timestepper_dt2 > end_time) - ? end_time - current_timestep.current() - : timestepper_dt2; + timestepper_dt2 = + (current_timestep.current()() + timestepper_dt2 > end_time) + ? end_time - current_timestep.current()() + : timestepper_dt2; NumLib::updateTimeSteps(timestepper_dt2, previous_timestep, current_timestep); alg.resetCurrentTimeStep(timestepper_dt2, previous_timestep, current_timestep); ASSERT_EQ(3u, current_timestep.timeStepNumber()); - ASSERT_EQ(4., current_timestep.previous()); - ASSERT_EQ(6., current_timestep.current()); + ASSERT_EQ(4., current_timestep.previous()()); + ASSERT_EQ(6., current_timestep.current()()); ASSERT_EQ(2., current_timestep.dt()); ASSERT_TRUE(current_timestep.isAccepted()); auto [step_accepted3, timestepper_dt3] = alg.next(solution_error, 5, previous_timestep, current_timestep); ASSERT_TRUE(step_accepted3); - timestepper_dt3 = (current_timestep.current() + timestepper_dt3 > end_time) - ? end_time - current_timestep.current() - : timestepper_dt3; + timestepper_dt3 = + (current_timestep.current()() + timestepper_dt3 > end_time) + ? end_time - current_timestep.current()() + : timestepper_dt3; NumLib::updateTimeSteps(timestepper_dt3, previous_timestep, current_timestep); alg.resetCurrentTimeStep(timestepper_dt3, previous_timestep, current_timestep); ASSERT_EQ(4u, current_timestep.timeStepNumber()); - ASSERT_EQ(6., current_timestep.previous()); - ASSERT_EQ(7., current_timestep.current()); + ASSERT_EQ(6., current_timestep.previous()()); + ASSERT_EQ(7., current_timestep.current()()); ASSERT_EQ(1., current_timestep.dt()); ASSERT_TRUE(current_timestep.isAccepted()); auto [step_accepted4, timestepper_dt4] = alg.next(solution_error, 7, previous_timestep, current_timestep); ASSERT_TRUE(step_accepted4); - timestepper_dt4 = (current_timestep.current() + timestepper_dt4 > end_time) - ? end_time - current_timestep.current() - : timestepper_dt4; + timestepper_dt4 = + (current_timestep.current()() + timestepper_dt4 > end_time) + ? end_time - current_timestep.current()() + : timestepper_dt4; NumLib::updateTimeSteps(timestepper_dt4, previous_timestep, current_timestep); alg.resetCurrentTimeStep(timestepper_dt4, previous_timestep, current_timestep); ASSERT_EQ(5u, current_timestep.timeStepNumber()); - ASSERT_EQ(7., current_timestep.previous()); - ASSERT_EQ(8., current_timestep.current()); + ASSERT_EQ(7., current_timestep.previous()()); + ASSERT_EQ(8., current_timestep.current()()); ASSERT_EQ(1., current_timestep.dt()); ASSERT_TRUE(current_timestep.isAccepted()); auto [step_accepted5, timestepper_dt5] = alg.next(solution_error, 8, previous_timestep, current_timestep); ASSERT_TRUE(step_accepted5); - timestepper_dt5 = (current_timestep.current() + timestepper_dt5 > end_time) - ? end_time - current_timestep.current() - : timestepper_dt5; + timestepper_dt5 = + (current_timestep.current()() + timestepper_dt5 > end_time) + ? end_time - current_timestep.current()() + : timestepper_dt5; NumLib::updateTimeSteps(timestepper_dt5, previous_timestep, current_timestep); alg.resetCurrentTimeStep(timestepper_dt5, previous_timestep, current_timestep); ASSERT_EQ(6u, current_timestep.timeStepNumber()); - ASSERT_EQ(8., current_timestep.previous()); - ASSERT_EQ(9, current_timestep.current()); + ASSERT_EQ(8., current_timestep.previous()()); + ASSERT_EQ(9, current_timestep.current()()); ASSERT_EQ(1., current_timestep.dt()); ASSERT_TRUE(current_timestep.isAccepted()); @@ -129,14 +134,15 @@ TEST(NumLib, TimeSteppingIterationNumberBased1) ASSERT_TRUE(step_accepted6); NumLib::updateTimeSteps(timestepper_dt6, previous_timestep, current_timestep); - timestepper_dt6 = (current_timestep.current() + timestepper_dt6 > end_time) - ? end_time - current_timestep.current() - : timestepper_dt6; + timestepper_dt6 = + (current_timestep.current()() + timestepper_dt6 > end_time) + ? end_time - current_timestep.current()() + : timestepper_dt6; alg.resetCurrentTimeStep(timestepper_dt6, previous_timestep, current_timestep); ASSERT_EQ(7u, current_timestep.timeStepNumber()); - ASSERT_EQ(9., current_timestep.previous()); - ASSERT_EQ(10, current_timestep.current()); + ASSERT_EQ(9., current_timestep.previous()()); + ASSERT_EQ(10, current_timestep.current()()); ASSERT_EQ(1., current_timestep.dt()); ASSERT_TRUE(current_timestep.isAccepted()); } diff --git a/Tests/NumLib/TimeSteppingTestingTools.h b/Tests/NumLib/TimeSteppingTestingTools.h index 85ef2f33fae6a3f61b2d60c57c8f271e30315e4a..fdf8bb4d808634aa79a5ba8bff9527dba5799d63 100644 --- a/Tests/NumLib/TimeSteppingTestingTools.h +++ b/Tests/NumLib/TimeSteppingTestingTools.h @@ -58,8 +58,8 @@ std::vector<double> timeStepping(T_TIME_STEPPING& algorithm, } timestepper_dt = - (current_timestep.current() + timestepper_dt > end_time) - ? end_time - current_timestep.current() + (current_timestep.current()() + timestepper_dt > end_time) + ? end_time - current_timestep.current()() : timestepper_dt; NumLib::updateTimeSteps(timestepper_dt, previous_timestep, @@ -73,7 +73,7 @@ std::vector<double> timeStepping(T_TIME_STEPPING& algorithm, } if (current_timestep.isAccepted()) { - vec_t.push_back(current_timestep.current()); + vec_t.push_back(current_timestep.current()()); } else {