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

[dt] Added creator functions for two time steppers

parent 6b93850e
No related branches found
No related tags found
No related merge requests found
/**
* \copyright
* Copyright (c) 2012-2017, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* \file CreateEvolutionaryPIDcontroller.cpp
* Created on June 26, 2017, 4:43 PM
*/
#include "CreateEvolutionaryPIDcontroller.h"
#include "BaseLib/ConfigTree.h"
#include "EvolutionaryPIDcontroller.h"
#include "TimeStepAlgorithm.h"
namespace NumLib
{
class TimeStepAlgorithm;
std::unique_ptr<TimeStepAlgorithm> createEvolutionaryPIDcontroller(
BaseLib::ConfigTree const& config)
{
//! \ogs_file_param{prj__time_loop__time_stepping__type}
config.checkConfigParameter("type", "EvolutionaryPIDcontroller");
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__t_initial}
auto const t0 = config.getConfigParameter<double>("t_initial");
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__t_end}
auto const t_end = config.getConfigParameter<double>("t_end");
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__dt_guess}
auto const h0 = config.getConfigParameter<double>("dt_guess");
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__dt_min}
auto const h_min = config.getConfigParameter<double>("dt_min");
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__dt_max}
auto const h_max = config.getConfigParameter<double>("dt_max");
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__rel_dt_min}
auto const rel_h_min = config.getConfigParameter<double>("rel_dt_min");
//! \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 =
//! \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)
{
// 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());
}
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__tol}
auto const tol = config.getConfigParameter<double>("tol");
auto const norm_type_opt =
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__norm_type}
config.getConfigParameterOptional<std::string>("norm_type");
const MathLib::VecNormType norm_type =
(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));
}
} // end of namespace NumLib
/**
* \copyright
* Copyright (c) 2012-2017, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* \file CreateEvolutionaryPIDcontroller.h
* Created on June 26, 2017, 4:43 PM
*/
#pragma once
#include <memory>
namespace BaseLib
{
class ConfigTree;
}
namespace NumLib
{
class TimeStepAlgorithm;
/// Create an EvolutionaryPIDcontroller time stepper from the given
/// configuration
std::unique_ptr<TimeStepAlgorithm> createEvolutionaryPIDcontroller(
BaseLib::ConfigTree const& config);
} // end of namespace NumLib
/**
* \copyright
* Copyright (c) 2012-2017, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* \file CreateFixedTimeStepping.cpp
* Created on June 26, 2017, 5:03 PM
*/
#include "CreateFixedTimeStepping.h"
#include <string>
#include "BaseLib/ConfigTree.h"
#include "BaseLib/Error.h"
#include "FixedTimeStepping.h"
#include "TimeStepAlgorithm.h"
namespace NumLib
{
class TimeStepAlgorithm;
std::unique_ptr<TimeStepAlgorithm> createFixedTimeStepping(
BaseLib::ConfigTree const& config)
{
//! \ogs_file_param{prj__time_loop__time_stepping__type}
config.checkConfigParameter("type", "FixedTimeStepping");
//! \ogs_file_param{prj__time_loop__time_stepping__FixedTimeStepping__t_initial}
auto const t_initial = config.getConfigParameter<double>("t_initial");
//! \ogs_file_param{prj__time_loop__time_stepping__FixedTimeStepping__t_end}
auto const t_end = config.getConfigParameter<double>("t_end");
//! \ogs_file_param{prj__time_loop__time_stepping__FixedTimeStepping__timesteps}
auto const delta_ts = config.getConfigSubtree("timesteps");
std::vector<double> timesteps;
double t_curr = t_initial;
double delta_t = 0.0;
// TODO: consider adding call "listNonEmpty" to config tree
//! \ogs_file_param{prj__time_loop__time_stepping__FixedTimeStepping__timesteps__pair}
auto const range = delta_ts.getConfigSubtreeList("pair");
if (range.begin() == range.end())
{
OGS_FATAL("no timesteps have been given");
}
for (auto const pair : range)
{
//! \ogs_file_param{prj__time_loop__time_stepping__FixedTimeStepping__timesteps__pair__repeat}
auto const repeat = pair.getConfigParameter<std::size_t>("repeat");
//! \ogs_file_param{prj__time_loop__time_stepping__FixedTimeStepping__timesteps__pair__delta_t}
delta_t = pair.getConfigParameter<double>("delta_t");
if (repeat == 0)
{
OGS_FATAL("<repeat> is zero.");
}
if (delta_t <= 0.0)
{
OGS_FATAL("timestep <delta_t> is <= 0.0.");
}
if (t_curr <= t_end)
{
timesteps.resize(timesteps.size() + repeat, delta_t);
t_curr += repeat * delta_t;
}
}
// append last delta_t until t_end is reached
if (t_curr <= t_end)
{
auto const repeat =
static_cast<std::size_t>(std::ceil((t_end - t_curr) / delta_t));
timesteps.resize(timesteps.size() + repeat, delta_t);
}
return std::make_unique<FixedTimeStepping>(t_initial, t_end, timesteps);
}
} // end of namespace NumLib
/**
* \copyright
* Copyright (c) 2012-2017, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* \file CreateFixedTimeStepping.h
* Created on June 26, 2017, 5:02 PM
*/
#pragma once
#include <memory>
namespace BaseLib
{
class ConfigTree;
}
namespace NumLib
{
class TimeStepAlgorithm;
/// Create a FixedTimeStepping time stepper from the given
/// configuration
std::unique_ptr<TimeStepAlgorithm> createFixedTimeStepping(
BaseLib::ConfigTree const& config);
} // end of namespace NumLib
...@@ -12,14 +12,10 @@ ...@@ -12,14 +12,10 @@
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <limits> #include <limits>
#include <string>
#include <vector> #include <vector>
#include "EvolutionaryPIDcontroller.h" #include "EvolutionaryPIDcontroller.h"
#include "BaseLib/ConfigTree.h"
#include "TimeStepAlgorithm.h"
namespace NumLib namespace NumLib
{ {
bool EvolutionaryPIDcontroller::next(const double solution_error) bool EvolutionaryPIDcontroller::next(const double solution_error)
...@@ -108,68 +104,4 @@ double EvolutionaryPIDcontroller::checkSpecificTimeReached(const double h_new) ...@@ -108,68 +104,4 @@ double EvolutionaryPIDcontroller::checkSpecificTimeReached(const double h_new)
return h_new; return h_new;
} }
/// Create an EvolutionaryPIDcontroller time stepper from the given
/// configuration
std::unique_ptr<TimeStepAlgorithm> createEvolutionaryPIDcontroller(
BaseLib::ConfigTree const& config)
{
//! \ogs_file_param{prj__time_loop__time_stepping__type}
config.checkConfigParameter("type", "EvolutionaryPIDcontroller");
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__t_initial}
auto const t0 = config.getConfigParameter<double>("t_initial");
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__t_end}
auto const t_end = config.getConfigParameter<double>("t_end");
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__dt_guess}
auto const h0 = config.getConfigParameter<double>("dt_guess");
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__dt_min}
auto const h_min = config.getConfigParameter<double>("dt_min");
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__dt_max}
auto const h_max = config.getConfigParameter<double>("dt_max");
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__rel_dt_min}
auto const rel_h_min = config.getConfigParameter<double>("rel_dt_min");
//! \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 =
//! \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)
{
// 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());
}
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__tol}
auto const tol = config.getConfigParameter<double>("tol");
auto const norm_type_opt =
//! \ogs_file_param{prj__time_loop__time_stepping__EvolutionaryPIDcontroller__norm_type}
config.getConfigParameterOptional<std::string>("norm_type");
const MathLib::VecNormType norm_type =
(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));
}
} // end of namespace NumLib } // end of namespace NumLib
...@@ -16,11 +16,6 @@ ...@@ -16,11 +16,6 @@
#include <limits> #include <limits>
#include <cassert> #include <cassert>
#include <logog/include/logog.hpp>
#include "BaseLib/ConfigTree.h"
#include "BaseLib/Error.h"
namespace NumLib namespace NumLib
{ {
FixedTimeStepping::FixedTimeStepping(double t0, FixedTimeStepping::FixedTimeStepping(double t0,
...@@ -35,65 +30,6 @@ FixedTimeStepping::FixedTimeStepping(double t0, double tn, double dt) ...@@ -35,65 +30,6 @@ FixedTimeStepping::FixedTimeStepping(double t0, double tn, double dt)
{ {
} }
std::unique_ptr<TimeStepAlgorithm> FixedTimeStepping::newInstance(
BaseLib::ConfigTree const& config)
{
//! \ogs_file_param{prj__time_loop__time_stepping__type}
config.checkConfigParameter("type", "FixedTimeStepping");
//! \ogs_file_param{prj__time_loop__time_stepping__FixedTimeStepping__t_initial}
auto const t_initial = config.getConfigParameter<double>("t_initial");
//! \ogs_file_param{prj__time_loop__time_stepping__FixedTimeStepping__t_end}
auto const t_end = config.getConfigParameter<double>("t_end");
//! \ogs_file_param{prj__time_loop__time_stepping__FixedTimeStepping__timesteps}
auto const delta_ts = config.getConfigSubtree("timesteps");
std::vector<double> timesteps;
double t_curr = t_initial;
double delta_t = 0.0;
// TODO: consider adding call "listNonEmpty" to config tree
//! \ogs_file_param{prj__time_loop__time_stepping__FixedTimeStepping__timesteps__pair}
auto const range = delta_ts.getConfigSubtreeList("pair");
if (range.begin() == range.end())
{
OGS_FATAL("no timesteps have been given");
}
for (auto const pair : range)
{
//! \ogs_file_param{prj__time_loop__time_stepping__FixedTimeStepping__timesteps__pair__repeat}
auto const repeat = pair.getConfigParameter<std::size_t>("repeat");
//! \ogs_file_param{prj__time_loop__time_stepping__FixedTimeStepping__timesteps__pair__delta_t}
delta_t = pair.getConfigParameter<double>("delta_t");
if (repeat == 0)
{
OGS_FATAL("<repeat> is zero.");
}
if (delta_t <= 0.0)
{
OGS_FATAL("timestep <delta_t> is <= 0.0.");
}
if (t_curr <= t_end)
{
timesteps.resize(timesteps.size() + repeat, delta_t);
t_curr += repeat * delta_t;
}
}
// append last delta_t until t_end is reached
if (t_curr <= t_end)
{
auto const repeat =
static_cast<std::size_t>(std::ceil((t_end - t_curr) / delta_t));
timesteps.resize(timesteps.size() + repeat, delta_t);
}
return std::make_unique<FixedTimeStepping>(t_initial, t_end, timesteps);
}
bool FixedTimeStepping::next(const double /*solution_error*/) bool FixedTimeStepping::next(const double /*solution_error*/)
{ {
// check if last time step // check if last time step
......
...@@ -16,11 +16,6 @@ ...@@ -16,11 +16,6 @@
#include "TimeStepAlgorithm.h" #include "TimeStepAlgorithm.h"
namespace BaseLib
{
class ConfigTree;
}
namespace NumLib namespace NumLib
{ {
/** /**
...@@ -62,10 +57,6 @@ public: ...@@ -62,10 +57,6 @@ public:
FixedTimeStepping(double t_initial, double t_end, FixedTimeStepping(double t_initial, double t_end,
const std::vector<double>& vec_all_dt); const std::vector<double>& vec_all_dt);
/// Create timestepper from the given configuration
static std::unique_ptr<TimeStepAlgorithm> newInstance(
BaseLib::ConfigTree const& config);
/// move to the next time step /// move to the next time step
bool next(const double solution_error) override; bool next(const double solution_error) override;
......
...@@ -11,10 +11,14 @@ ...@@ -11,10 +11,14 @@
#include "CreateTimeStepper.h" #include "CreateTimeStepper.h"
#include <string>
#include "BaseLib/ConfigTree.h" #include "BaseLib/ConfigTree.h"
#include "BaseLib/Error.h"
#include "NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.h"
#include "NumLib/TimeStepping/Algorithms/FixedTimeStepping.h" #include "NumLib/TimeStepping/Algorithms/FixedTimeStepping.h"
#include "NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.h" #include "NumLib/TimeStepping/Algorithms/CreateEvolutionaryPIDcontroller.h"
namespace NumLib namespace NumLib
{ {
...@@ -34,7 +38,7 @@ std::unique_ptr<TimeStepAlgorithm> createTimeStepper( ...@@ -34,7 +38,7 @@ std::unique_ptr<TimeStepAlgorithm> createTimeStepper(
} }
else if (type == "FixedTimeStepping") else if (type == "FixedTimeStepping")
{ {
timestepper = NumLib::FixedTimeStepping::newInstance(config); timestepper = NumLib::createFixedTimeStepping(config);
} }
else if (type == "EvolutionaryPIDcontroller") else if (type == "EvolutionaryPIDcontroller")
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment