Skip to content
Snippets Groups Projects
Commit fbc91638 authored by Dmitri Naumov's avatar Dmitri Naumov Committed by Dmitri Naumov
Browse files

[NL/TS] EPIDTS; Rewrite fixed time output clamping

Same as IterationNumberBasedTimeStepping.
The new function does not modify anything.
parent 78208c82
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ bool EvolutionaryPIDcontroller::next(double const solution_error, ...@@ -36,7 +36,7 @@ bool EvolutionaryPIDcontroller::next(double const solution_error,
: 0.5 * _ts_current.dt(); : 0.5 * _ts_current.dt();
h_new = limitStepSize(h_new, is_previous_step_accepted); h_new = limitStepSize(h_new, is_previous_step_accepted);
h_new = checkSpecificTimeReached(h_new); h_new = possiblyClampToNextFixedTime(h_new);
_ts_current = _ts_prev; _ts_current = _ts_prev;
_ts_current += h_new; _ts_current += h_new;
...@@ -96,7 +96,7 @@ bool EvolutionaryPIDcontroller::next(double const solution_error, ...@@ -96,7 +96,7 @@ bool EvolutionaryPIDcontroller::next(double const solution_error,
} }
h_new = limitStepSize(h_new, is_previous_step_accepted); h_new = limitStepSize(h_new, is_previous_step_accepted);
h_new = checkSpecificTimeReached(h_new); h_new = possiblyClampToNextFixedTime(h_new);
_dt_vector.push_back(h_new); _dt_vector.push_back(h_new);
_ts_prev = _ts_current; _ts_prev = _ts_current;
...@@ -145,19 +145,22 @@ double EvolutionaryPIDcontroller::limitStepSize( ...@@ -145,19 +145,22 @@ double EvolutionaryPIDcontroller::limitStepSize(
return limited_h; return limited_h;
} }
double EvolutionaryPIDcontroller::checkSpecificTimeReached(const double h_new) double EvolutionaryPIDcontroller::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; return h_new;
} }
const double specific_time = _fixed_output_times.back(); if ((*specific_time > _ts_current.current()) &&
if ((specific_time > _ts_current.current()) && (_ts_current.current() + h_new - *specific_time > 0.0))
(_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; return h_new;
...@@ -170,8 +173,8 @@ void EvolutionaryPIDcontroller::addFixedOutputTimes( ...@@ -170,8 +173,8 @@ void EvolutionaryPIDcontroller::addFixedOutputTimes(
extra_fixed_output_times.begin(), extra_fixed_output_times.begin(),
extra_fixed_output_times.end()); extra_fixed_output_times.end());
// Remove possible duplicated elements and sort in descending order. // Remove possible duplicated elements. Result will be sorted.
BaseLib::makeVectorUnique(_fixed_output_times, std::greater<double>()); BaseLib::makeVectorUnique(_fixed_output_times);
} }
bool EvolutionaryPIDcontroller::canReduceTimestepSize() const bool EvolutionaryPIDcontroller::canReduceTimestepSize() const
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <vector> #include <vector>
#include "TimeStepAlgorithm.h" #include "TimeStepAlgorithm.h"
#include "BaseLib/Algorithm.h"
namespace BaseLib namespace BaseLib
{ {
...@@ -69,6 +70,8 @@ public: ...@@ -69,6 +70,8 @@ public:
_e_n_minus2(0.), _e_n_minus2(0.),
_is_accepted(true) _is_accepted(true)
{ {
// Remove possible duplicated elements. Result will be sorted.
BaseLib::makeVectorUnique(_fixed_output_times);
} }
bool next(double solution_error, int number_iterations) override; bool next(double solution_error, int number_iterations) override;
...@@ -125,7 +128,9 @@ private: ...@@ -125,7 +128,9 @@ private:
double limitStepSize(const double h_new, double limitStepSize(const double h_new,
const bool previous_step_accepted) const; const bool previous_step_accepted) 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;
}; };
/// Create an EvolutionaryPIDcontroller time stepper from the given /// Create an EvolutionaryPIDcontroller time stepper from the given
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment