Loading...
Searching...
No Matches
TimeStepControl.hpp
/*
Copyright 2014 IRIS AS
Copyright 2015 Dr. Blatt - HPC-Simulation-Software & Services
Copyright 2015 Statoil AS
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_TIMESTEPCONTROL_HEADER_INCLUDED
#define OPM_TIMESTEPCONTROL_HEADER_INCLUDED
#include <opm/simulators/timestepping/TimeStepControlInterface.hpp>
#include <opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp>
#include <string>
#include <vector>
namespace Opm
{
enum class TimeStepControlType {
SimpleIterationCount,
PID,
PIDAndIterationCount,
HardCodedTimeStep,
General3rdOrder,
};
enum class ToleranceTestVersions {
Standard,
ControlErrorFiltering,
};
enum class InternalControlVersions {
IController,
General3rdOrder,
};
//
class SimpleIterationCountTimeStepControl : public TimeStepControlInterface
{
public:
static constexpr TimeStepControlType Type = TimeStepControlType::SimpleIterationCount;
SimpleIterationCountTimeStepControl() = default;
SimpleIterationCountTimeStepControl(const int target_iterations,
const double decayrate,
const double growthrate,
const bool verbose);
static SimpleIterationCountTimeStepControl serializationTestObject();
double computeTimeStepSize(const double dt,
const int iterations,
const RelativeChangeInterface& /* relativeChange */,
const AdaptiveSimulatorTimer& /* substepTimer */ ) const override;
bool timeStepAccepted(const double /* error */,
const double /* timeStepJustCompleted */) const override { return true; }
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(target_iterations_);
serializer(decayrate_);
serializer(growthrate_);
serializer(verbose_);
}
bool operator==(const SimpleIterationCountTimeStepControl&) const;
protected:
const int target_iterations_ = 0;
const double decayrate_ = 0.0;
const double growthrate_ = 0.0;
const bool verbose_ = false;
};
class PIDTimeStepControl : public TimeStepControlInterface
{
public:
static constexpr TimeStepControlType Type = TimeStepControlType::PID;
PIDTimeStepControl() = default;
PIDTimeStepControl(const double tol,
const bool verbose);
static PIDTimeStepControl serializationTestObject();
double computeTimeStepSize(const double dt,
const int /* iterations */,
const RelativeChangeInterface& relativeChange,
const AdaptiveSimulatorTimer& /* substepTimer */ ) const override;
bool timeStepAccepted(const double /* error */,
const double /* timeStepJustCompleted */) const override { return true; }
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(tol_);
serializer(errors_);
serializer(verbose_);
}
bool operator==(const PIDTimeStepControl&) const;
protected:
const double tol_ = 0.1;
mutable std::vector< double > errors_{};
const bool verbose_ = false;
};
//
class PIDAndIterationCountTimeStepControl : public PIDTimeStepControl
{
typedef PIDTimeStepControl BaseType;
public:
static constexpr TimeStepControlType Type = TimeStepControlType::PIDAndIterationCount;
PIDAndIterationCountTimeStepControl() = default;
PIDAndIterationCountTimeStepControl(const int target_iterations,
const double decayDampingFactor,
const double growthDampingFactor,
const double tol,
const double minTimeStepBasedOnIterations,
const bool verbose);
static PIDAndIterationCountTimeStepControl serializationTestObject();
double computeTimeStepSize(const double dt,
const int iterations,
const RelativeChangeInterface& relativeChange,
const AdaptiveSimulatorTimer& /* substepTimer */ ) const override;
bool timeStepAccepted(const double /* error */,
const double /* timeStepJustCompleted */) const override { return true; }
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(static_cast<PIDTimeStepControl&>(*this));
serializer(target_iterations_);
serializer(decayDampingFactor_);
serializer(growthDampingFactor_);
serializer(minTimeStepBasedOnIterations_);
serializer(verbose_);
}
bool operator==(const PIDAndIterationCountTimeStepControl&) const;
protected:
const int target_iterations_ = 8;
const double decayDampingFactor_ = 1.0;
const double growthDampingFactor_ = 3.2;
const double minTimeStepBasedOnIterations_ = 0.0;
const bool verbose_ = false;
};
class General3rdOrderController : public TimeStepControlInterface
{
public:
static constexpr TimeStepControlType Type = TimeStepControlType::General3rdOrder;
General3rdOrderController() = default;
General3rdOrderController(const double tolerance,
const double safetyFactor,
const bool rejectCompletedStep,
const std::string& toleranceTestVersion,
const double maxReductionTimeStep,
const std::string& parameters,
const bool verbose);
static General3rdOrderController serializationTestObject();
double computeTimeStepSize(const double dt,
const int /* iterations */,
const RelativeChangeInterface& /* relativeChange */,
const AdaptiveSimulatorTimer& substepTimer) const override;
double timeStepFactor(const std::array<double, 3>& errors, const std::array<double, 3>& timeSteps) const;
bool timeStepAccepted(const double error,
const double timeStepJustCompleted) const override;
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(tolerance_);
serializer(safetyFactor_);
serializer(rejectCompletedStep_);
serializer(errors_);
serializer(timeSteps_);
serializer(beta_);
serializer(alpha_);
serializer(controllerVersion_);
serializer(toleranceTestVersion_);
serializer(maxReductionTimeStep_);
serializer(verbose_);
}
bool operator==(const General3rdOrderController&) const;
protected:
const double tolerance_ = 0.1;
const double safetyFactor_ = 0.8;
const bool rejectCompletedStep_ = false;
mutable std::array<double, 3> errors_{};
mutable std::array<double, 3> timeSteps_{};
mutable std::array<double, 3> beta_{0.125, 0.25, 0.125};
mutable std::array<double, 2> alpha_{0.75, 0.25};
mutable InternalControlVersions controllerVersion_{InternalControlVersions::IController};
ToleranceTestVersions toleranceTestVersion_{ToleranceTestVersions::Standard};
const double maxReductionTimeStep_ = 0.1;
const bool verbose_ = false;
};
class HardcodedTimeStepControl : public TimeStepControlInterface
{
public:
static constexpr TimeStepControlType Type = TimeStepControlType::HardCodedTimeStep;
HardcodedTimeStepControl() = default;
explicit HardcodedTimeStepControl(const std::string& filename);
static HardcodedTimeStepControl serializationTestObject();
double computeTimeStepSize(const double dt,
const int /* iterations */,
const RelativeChangeInterface& /*relativeChange */,
const AdaptiveSimulatorTimer& substepTimer) const override;
bool timeStepAccepted(const double /* error */,
const double /* timeStepJustCompleted */) const override { return true; }
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(subStepTime_);
}
bool operator==(const HardcodedTimeStepControl&) const;
protected:
// store the time (in days) of the substeps the simulator should use
std::vector<double> subStepTime_;
};
} // end namespace Opm
#endif
Opm::AdaptiveSimulatorTimer
Simulation timer for adaptive time stepping.
Definition AdaptiveSimulatorTimer.hpp:41
Opm::General3rdOrderController::computeTimeStepSize
double computeTimeStepSize(const double dt, const int, const RelativeChangeInterface &, const AdaptiveSimulatorTimer &substepTimer) const override
compute new time step size suggestions based on the PID controller
Definition TimeStepControl.cpp:373
Opm::General3rdOrderController::timeStepAccepted
bool timeStepAccepted(const double error, const double timeStepJustCompleted) const override
For the general 3rd order controller, the internal shifting of errors and time steps happens here,...
Definition TimeStepControl.cpp:446
Opm::HardcodedTimeStepControl::computeTimeStepSize
double computeTimeStepSize(const double dt, const int, const RelativeChangeInterface &, const AdaptiveSimulatorTimer &substepTimer) const override
compute new time step size suggestions based on the PID controller
Definition TimeStepControl.cpp:148
Opm::HardcodedTimeStepControl::timeStepAccepted
bool timeStepAccepted(const double, const double) const override
For the general 3rd order controller, the internal shifting of errors and time steps happens here,...
Definition TimeStepControl.hpp:327
Opm::PIDAndIterationCountTimeStepControl::timeStepAccepted
bool timeStepAccepted(const double, const double) const override
For the general 3rd order controller, the internal shifting of errors and time steps happens here,...
Definition TimeStepControl.hpp:198
Opm::PIDAndIterationCountTimeStepControl::computeTimeStepSize
double computeTimeStepSize(const double dt, const int iterations, const RelativeChangeInterface &relativeChange, const AdaptiveSimulatorTimer &) const override
compute new time step size suggestions based on the PID controller
Definition TimeStepControl.cpp:274
Opm::PIDTimeStepControl
PID controller based adaptive time step control as suggested in: Turek and Kuzmin.
Definition TimeStepControl.hpp:116
Opm::PIDTimeStepControl::timeStepAccepted
bool timeStepAccepted(const double, const double) const override
For the general 3rd order controller, the internal shifting of errors and time steps happens here,...
Definition TimeStepControl.hpp:139
Opm::PIDTimeStepControl::computeTimeStepSize
double computeTimeStepSize(const double dt, const int, const RelativeChangeInterface &relativeChange, const AdaptiveSimulatorTimer &) const override
compute new time step size suggestions based on the PID controller
Definition TimeStepControl.cpp:188
Opm::RelativeChangeInterface
RelativeChangeInterface.
Definition TimeStepControlInterface.hpp:34
Opm::SimpleIterationCountTimeStepControl::timeStepAccepted
bool timeStepAccepted(const double, const double) const override
For the general 3rd order controller, the internal shifting of errors and time steps happens here,...
Definition TimeStepControl.hpp:80
Opm::SimpleIterationCountTimeStepControl::computeTimeStepSize
double computeTimeStepSize(const double dt, const int iterations, const RelativeChangeInterface &, const AdaptiveSimulatorTimer &) const override
compute new time step size suggestions based on the PID controller
Definition TimeStepControl.cpp:79
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43