From a3cb09ea6e7c78ef737038dd69baf3e37137890c Mon Sep 17 00:00:00 2001 From: Tom Fischer <thomas.fischer@ufz.de> Date: Fri, 26 Apr 2024 10:53:27 +0200 Subject: [PATCH] [NL/TimeStepping] Name tuple<size_t, double> as RepeatDtPair Using std::pair wasn't possible because the unit unit test for FixedTimeStepping (implemented using autocheck) doesn't compile --- .../TimeStepping/Algorithms/CreateFixedTimeStepping.cpp | 2 +- NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp | 5 ++--- NumLib/TimeStepping/Algorithms/FixedTimeStepping.h | 9 +++++---- Tests/NumLib/TestTimeSteppingFixed.cpp | 7 +++---- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.cpp b/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.cpp index 71bcf23d7fc..16a4cec42f9 100644 --- a/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.cpp +++ b/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.cpp @@ -40,7 +40,7 @@ std::unique_ptr<TimeStepAlgorithm> createFixedTimeStepping( OGS_FATAL("no timesteps have been given"); } - std::vector<std::pair<std::size_t, double>> repeat_dt_pairs; + std::vector<RepeatDtPair> repeat_dt_pairs; for (auto const pair : range) { repeat_dt_pairs.emplace_back( diff --git a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp index 55899e6c0db..b9e53ca8fcc 100644 --- a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp +++ b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp @@ -141,8 +141,7 @@ void incorporateFixedTimesForOutput( } FixedTimeStepping::FixedTimeStepping( - double t0, double tn, - std::vector<std::pair<std::size_t, double>> const& repeat_dt_pairs, + double t0, double tn, std::vector<RepeatDtPair> const& repeat_dt_pairs, std::vector<double> const& fixed_times_for_output) : TimeStepAlgorithm(t0, tn) { @@ -168,7 +167,7 @@ FixedTimeStepping::FixedTimeStepping( // append last delta_t until t_end is reached if (t_curr <= _t_end) { - auto const delta_t = repeat_dt_pairs.back().second; + 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)); addTimeIncrement(_dt_vector, repeat, delta_t, t_curr); diff --git a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.h b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.h index 89f4588bec3..3c0972294e3 100644 --- a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.h +++ b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.h @@ -19,6 +19,8 @@ namespace NumLib { +using RepeatDtPair = std::tuple<std::size_t, double>; + /** * \brief Fixed time stepping algorithm * @@ -46,10 +48,9 @@ public: * Constructor with user-specified time step sizes including additional time * steps for output. */ - FixedTimeStepping( - double t0, double tn, - std::vector<std::pair<std::size_t, double>> const& repeat_dt_pairs, - std::vector<double> const& fixed_times_for_output); + FixedTimeStepping(double t0, double tn, + std::vector<RepeatDtPair> const& repeat_dt_pairs, + std::vector<double> const& fixed_times_for_output); std::tuple<bool, double> next(double solution_error, int number_iterations, NumLib::TimeStep& ts_previous, diff --git a/Tests/NumLib/TestTimeSteppingFixed.cpp b/Tests/NumLib/TestTimeSteppingFixed.cpp index 67aa712c392..9d4bbe69691 100644 --- a/Tests/NumLib/TestTimeSteppingFixed.cpp +++ b/Tests/NumLib/TestTimeSteppingFixed.cpp @@ -99,7 +99,7 @@ TEST_F(NumLibTimeSteppingFixed_TimeSteps, HomogeneousDt) TEST_F(NumLibTimeSteppingFixed_TimeSteps, DtVectorEqualSum) { - std::vector<std::pair<std::size_t, double>> const repeat_dt = {{3, 10}}; + std::vector<NumLib::RepeatDtPair> const repeat_dt = {{3, 10}}; NumLib::FixedTimeStepping algorithm(1, 31, repeat_dt, {}); checkExpectedTimes(algorithm, {1, 11, 21, 31}); @@ -107,7 +107,7 @@ TEST_F(NumLibTimeSteppingFixed_TimeSteps, DtVectorEqualSum) TEST_F(NumLibTimeSteppingFixed_TimeSteps, DtVectorLessThanSum) { - std::vector<std::pair<std::size_t, double>> const repeat_dt = { + std::vector<NumLib::RepeatDtPair> const repeat_dt = { {1, 5}, {1, 10}, {1, 20}}; NumLib::FixedTimeStepping algorithm(1, 31, repeat_dt, {}); @@ -116,8 +116,7 @@ TEST_F(NumLibTimeSteppingFixed_TimeSteps, DtVectorLessThanSum) TEST_F(NumLibTimeSteppingFixed_TimeSteps, DtVectorGreaterThanSum) { - std::vector<std::pair<std::size_t, double>> const repeat_dt = {{1, 5}, - {3, 10}}; + std::vector<NumLib::RepeatDtPair> const repeat_dt = {{1, 5}, {3, 10}}; NumLib::FixedTimeStepping algorithm(1, 31, repeat_dt, {}); checkExpectedTimes(algorithm, {1, 6, 16, 26, 31}); -- GitLab