diff --git a/NumLib/TimeStepping/Algorithms/CreateEvolutionaryPIDcontroller.cpp b/NumLib/TimeStepping/Algorithms/CreateEvolutionaryPIDcontroller.cpp new file mode 100644 index 0000000000000000000000000000000000000000..38134401e09bd445b3363eeae5dd7c33e30e6657 --- /dev/null +++ b/NumLib/TimeStepping/Algorithms/CreateEvolutionaryPIDcontroller.cpp @@ -0,0 +1,83 @@ +/** + * \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 diff --git a/NumLib/TimeStepping/Algorithms/CreateEvolutionaryPIDcontroller.h b/NumLib/TimeStepping/Algorithms/CreateEvolutionaryPIDcontroller.h new file mode 100644 index 0000000000000000000000000000000000000000..84c35364026d0440df1925d00daaac17012c5ca2 --- /dev/null +++ b/NumLib/TimeStepping/Algorithms/CreateEvolutionaryPIDcontroller.h @@ -0,0 +1,29 @@ +/** + * \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 diff --git a/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.cpp b/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.cpp new file mode 100644 index 0000000000000000000000000000000000000000..edc2085f479ec4d408b3cce8f888cfa0d6dcd58e --- /dev/null +++ b/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.cpp @@ -0,0 +1,82 @@ +/** + * \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 diff --git a/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.h b/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.h new file mode 100644 index 0000000000000000000000000000000000000000..ff7e066a04390579652187a4f41ab99db3dd9955 --- /dev/null +++ b/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.h @@ -0,0 +1,29 @@ +/** + * \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 diff --git a/NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.cpp b/NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.cpp index a531a0a8ca076054425399fd2be5d0d7a534cacf..68a5600fc79539f3cfacb2b1df389d1230671b38 100644 --- a/NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.cpp +++ b/NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.cpp @@ -12,14 +12,10 @@ #include <algorithm> #include <functional> #include <limits> -#include <string> #include <vector> #include "EvolutionaryPIDcontroller.h" -#include "BaseLib/ConfigTree.h" -#include "TimeStepAlgorithm.h" - namespace NumLib { bool EvolutionaryPIDcontroller::next(const double solution_error) @@ -108,68 +104,4 @@ double EvolutionaryPIDcontroller::checkSpecificTimeReached(const double 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 diff --git a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp index 15ff6a62389d66d4d891f4f2862dea3c132690ab..63fb6da19973272e151e3460eb632286906ee2fc 100644 --- a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp +++ b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp @@ -16,11 +16,6 @@ #include <limits> #include <cassert> -#include <logog/include/logog.hpp> - -#include "BaseLib/ConfigTree.h" -#include "BaseLib/Error.h" - namespace NumLib { FixedTimeStepping::FixedTimeStepping(double t0, @@ -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*/) { // check if last time step diff --git a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.h b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.h index 7f1d26fb605d55e117fcdf8d6d5f501a65ef326b..8cdffd4250737599ca62bd4635841099594bf8fb 100644 --- a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.h +++ b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.h @@ -16,11 +16,6 @@ #include "TimeStepAlgorithm.h" -namespace BaseLib -{ -class ConfigTree; -} - namespace NumLib { /** @@ -62,10 +57,6 @@ public: FixedTimeStepping(double t_initial, double t_end, 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 bool next(const double solution_error) override; diff --git a/NumLib/TimeStepping/CreateTimeStepper.cpp b/NumLib/TimeStepping/CreateTimeStepper.cpp index e9f1d460eb4a4eed3fe92341c38b50834d52e014..a48fc55351e1409ec5cbdca2a2dd788b10751640 100644 --- a/NumLib/TimeStepping/CreateTimeStepper.cpp +++ b/NumLib/TimeStepping/CreateTimeStepper.cpp @@ -11,10 +11,14 @@ #include "CreateTimeStepper.h" +#include <string> + #include "BaseLib/ConfigTree.h" +#include "BaseLib/Error.h" +#include "NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.h" #include "NumLib/TimeStepping/Algorithms/FixedTimeStepping.h" -#include "NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.h" +#include "NumLib/TimeStepping/Algorithms/CreateEvolutionaryPIDcontroller.h" namespace NumLib { @@ -34,7 +38,7 @@ std::unique_ptr<TimeStepAlgorithm> createTimeStepper( } else if (type == "FixedTimeStepping") { - timestepper = NumLib::FixedTimeStepping::newInstance(config); + timestepper = NumLib::createFixedTimeStepping(config); } else if (type == "EvolutionaryPIDcontroller") {