Skip to content
Snippets Groups Projects
Commit 59156fb1 authored by wenqing's avatar wenqing
Browse files

[dt] Some changes and corrections accoording to Dima's comments

parent e2be6ee3
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@
#include "CreateEvolutionaryPIDcontroller.h"
#include "BaseLib/ConfigTree.h"
#include "BaseLib/makeVectorUnique.h"
#include "EvolutionaryPIDcontroller.h"
#include "TimeStepAlgorithm.h"
......@@ -41,22 +42,18 @@ std::unique_ptr<TimeStepAlgorithm> createEvolutionaryPIDcontroller(
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__rel_dt_max}
auto const rel_h_max = config.getConfigParameter<double>("rel_dt_max");
auto specific_times_opt =
auto specific_times =
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__specific_times}
config.getConfigParameterOptional<std::vector<double>>(
"specific_times");
std::vector<double> dummy_vector;
std::vector<double>& specific_times =
(specific_times_opt) ? *specific_times_opt : dummy_vector;
if (specific_times.size() > 0)
config.getConfigParameter<std::vector<double>>(
"specific_times", std::vector<double>{});
if (!specific_times.empty())
{
// Sort in descending order.
std::sort(specific_times.begin(),
specific_times.end(),
std::greater<double>());
// Remove possible duplicated elements.
auto last = std::unique(specific_times.begin(), specific_times.end());
specific_times.erase(last, specific_times.end());
BaseLib::makeVectorUnique(specific_times);
}
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__tol}
......@@ -68,16 +65,8 @@ std::unique_ptr<TimeStepAlgorithm> createEvolutionaryPIDcontroller(
(norm_type_opt) ? MathLib::convertStringToVecNormType(*norm_type_opt)
: MathLib::VecNormType::NORM2;
return std::unique_ptr<TimeStepAlgorithm>(
new EvolutionaryPIDcontroller(t0,
t_end,
h0,
h_min,
h_max,
rel_h_min,
rel_h_max,
std::move(specific_times),
tol,
norm_type));
return std::make_unique<EvolutionaryPIDcontroller>(
t0, t_end, h0, h_min, h_max, rel_h_min, rel_h_max,
std::move(specific_times), tol, norm_type);
}
} // end of namespace NumLib
......@@ -57,15 +57,18 @@ bool EvolutionaryPIDcontroller::next(const double solution_error)
if (_e_n_minus1 > zero_threshlod)
{
if (_e_n_minus2 > zero_threshlod)
{
h_new = std::pow(_e_n_minus1 / e_n, _kP) *
std::pow(_tol / e_n, _kI) *
std::pow(
_e_n_minus1 * _e_n_minus1 / (e_n * _e_n_minus2),
_kD) *
h_n;
_kD) * h_n;
}
else
{
h_new = std::pow(_e_n_minus1 / e_n, _kP) *
std::pow(_tol / e_n, _kI) * h_n;
}
}
else
{
......@@ -74,11 +77,11 @@ bool EvolutionaryPIDcontroller::next(const double solution_error)
}
h_new = limitStepSize(h_new, h_n);
const double checked_h_new = checkSpecificTimeReached(h_new);
_dt_vector.push_back(checked_h_new);
h_new = checkSpecificTimeReached(h_new);
_dt_vector.push_back(h_new);
_ts_prev = _ts_current;
_ts_current += checked_h_new;
_ts_current += h_new;
_e_n_minus2 = _e_n_minus1;
_e_n_minus1 = e_n;
......@@ -93,9 +96,9 @@ double EvolutionaryPIDcontroller::checkSpecificTimeReached(const double h_new)
return h_new;
const double specific_time = _specific_times.back();
const double zero_threshlod = std::numeric_limits<double>::epsilon();
const double zero_threshold = std::numeric_limits<double>::epsilon();
if ((specific_time > _ts_current.current()) &&
(_ts_current.current() + h_new - specific_time > zero_threshlod))
(_ts_current.current() + h_new - specific_time > zero_threshold))
{
_specific_times.pop_back();
return specific_time - _ts_current.current();
......@@ -103,5 +106,4 @@ double EvolutionaryPIDcontroller::checkSpecificTimeReached(const double h_new)
return h_new;
}
} // end of namespace NumLib
......@@ -92,9 +92,9 @@ public:
}
private:
const double _kP = 0.075; ///< Paramter. \see EvolutionaryPIDcontroller
const double _kI = 0.175; ///< Paramter. \see EvolutionaryPIDcontroller
const double _kD = 0.01; ///< Paramter. \see EvolutionaryPIDcontroller
const double _kP = 0.075; ///< Parameter. \see EvolutionaryPIDcontroller
const double _kI = 0.175; ///< Parameter. \see EvolutionaryPIDcontroller
const double _kD = 0.01; ///< Parameter. \see EvolutionaryPIDcontroller
const double _h0; ///< initial time step size.
const double _h_min; ///< minimum step size.
......
......@@ -11,6 +11,7 @@
#include "CreateTimeStepper.h"
#include <memory>
#include <string>
#include "BaseLib/ConfigTree.h"
......@@ -34,7 +35,8 @@ std::unique_ptr<TimeStepAlgorithm> createTimeStepper(
{
//! \ogs_file_param_special{prj__time_loop__time_stepping__SingleStep}
config.ignoreConfigParameter("type");
timestepper.reset(new NumLib::FixedTimeStepping(0.0, 1.0, 1.0));
timestepper =
std::make_unique<NumLib::FixedTimeStepping>(0.0, 1.0, 1.0);
}
else if (type == "FixedTimeStepping")
{
......
......@@ -117,7 +117,12 @@ private:
* Find the minimum time step size among the predicted step sizes of
* processes and step it as common time step size.
*
* @param t Current time
* @param prev_dt Previous time step size.
* @param t Current time.
* @param accepted_steps Accepted time steps that are counted in this
* function.
* @param rejected_steps Rejected time steps that are counted in this
* function.
*/
double computeTimeStepping(const double prev_dt, double& t,
std::size_t& accepted_steps,
......
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