My Project
TimeStepControl.hpp
1/*
2 Copyright 2014 IRIS AS
3 Copyright 2015 Dr. Blatt - HPC-Simulation-Software & Services
4 Copyright 2015 Statoil AS
5
6 This file is part of the Open Porous Media project (OPM).
7
8 OPM is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 OPM is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with OPM. If not, see <http://www.gnu.org/licenses/>.
20*/
21#ifndef OPM_TIMESTEPCONTROL_HEADER_INCLUDED
22#define OPM_TIMESTEPCONTROL_HEADER_INCLUDED
23
24#include <opm/simulators/timestepping/TimeStepControlInterface.hpp>
25
26#include <string>
27#include <vector>
28
29namespace Opm
30{
31 enum class TimeStepControlType {
32 SimpleIterationCount,
33 PID,
34 PIDAndIterationCount,
35 HardCodedTimeStep
36 };
37
41 //
44 {
45 public:
46 static constexpr TimeStepControlType Type = TimeStepControlType::SimpleIterationCount;
48
51 // \param decayrate decayrate of time step when target iterations are not met (should be <= 1)
52 // \param growthrate growthrate of time step when target iterations are not met (should be >= 1)
54 SimpleIterationCountTimeStepControl( const int target_iterations,
55 const double decayrate,
56 const double growthrate,
57 const bool verbose = false);
58
59 static SimpleIterationCountTimeStepControl serializationTestObject();
60
62 double computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& /* relativeChange */, const double /*simulationTimeElapsed */ ) const;
63
64 template<class Serializer>
65 void serializeOp(Serializer& serializer)
66 {
67 serializer(target_iterations_);
68 serializer(decayrate_);
69 serializer(growthrate_);
70 serializer(verbose_);
71 }
72
73 bool operator==(const SimpleIterationCountTimeStepControl&) const;
74
75 protected:
76 const int target_iterations_ = 0;
77 const double decayrate_ = 0.0;
78 const double growthrate_ = 0.0;
79 const bool verbose_ = false;
80 };
81
97 {
98 public:
99 static constexpr TimeStepControlType Type = TimeStepControlType::PID;
104 PIDTimeStepControl( const double tol = 1e-3,
105 const bool verbose = false );
106
107 static PIDTimeStepControl serializationTestObject();
108
110 double computeTimeStepSize( const double dt, const int /* iterations */, const RelativeChangeInterface& relativeChange, const double /*simulationTimeElapsed */ ) const;
111
112 template<class Serializer>
113 void serializeOp(Serializer& serializer)
114 {
115 serializer(tol_);
116 serializer(errors_);
117 serializer(verbose_);
118 }
119
120 bool operator==(const PIDTimeStepControl&) const;
121
122 protected:
123 const double tol_ = 1e-3;
124 mutable std::vector< double > errors_{};
125
126 const bool verbose_ = false;
127 };
128
133 //
136 {
138 public:
139 static constexpr TimeStepControlType Type = TimeStepControlType::PIDAndIterationCount;
140
146 PIDAndIterationCountTimeStepControl( const int target_iterations = 20,
147 const double decayDampingFactor = 1.0,
148 const double growthDampingFactor = 1.0/1.2,
149 const double tol = 1e-3,
150 const double minTimeStepBasedOnIterations = 0.,
151 const bool verbose = false);
152
153 static PIDAndIterationCountTimeStepControl serializationTestObject();
154
156 double computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& relativeChange, const double /*simulationTimeElapsed */ ) const;
157
158 template<class Serializer>
159 void serializeOp(Serializer& serializer)
160 {
161 serializer(static_cast<PIDTimeStepControl&>(*this));
162 serializer(target_iterations_);
163 serializer(decayDampingFactor_);
164 serializer(growthDampingFactor_);
165 serializer(minTimeStepBasedOnIterations_);
166 }
167
168 bool operator==(const PIDAndIterationCountTimeStepControl&) const;
169
170 protected:
171 const int target_iterations_;
172 const double decayDampingFactor_;
173 const double growthDampingFactor_;
174 const double minTimeStepBasedOnIterations_;
175 };
176
187 {
188 public:
189 static constexpr TimeStepControlType Type = TimeStepControlType::HardCodedTimeStep;
190 HardcodedTimeStepControl() = default;
191
194 explicit HardcodedTimeStepControl( const std::string& filename);
195
196 static HardcodedTimeStepControl serializationTestObject();
197
199 double computeTimeStepSize( const double dt, const int /* iterations */, const RelativeChangeInterface& /*relativeChange */, const double simulationTimeElapsed) const;
200
201 template<class Serializer>
202 void serializeOp(Serializer& serializer)
203 {
204 serializer(subStepTime_);
205 }
206
207 bool operator==(const HardcodedTimeStepControl&) const;
208
209 protected:
210 // store the time (in days) of the substeps the simulator should use
211 std::vector<double> subStepTime_;
212 };
213
214
215} // end namespace Opm
216#endif
217
HardcodedTimeStepControl Input generated from summary file using the ert application:
Definition: TimeStepControl.hpp:187
double computeTimeStepSize(const double dt, const int, const RelativeChangeInterface &, const double simulationTimeElapsed) const
compute new time step size suggestions based on the PID controller
Definition: TimeStepControl.cpp:137
PID controller based adaptive time step control as above that also takes an target iteration into acc...
Definition: TimeStepControl.hpp:136
PIDAndIterationCountTimeStepControl(const int target_iterations=20, const double decayDampingFactor=1.0, const double growthDampingFactor=1.0/1.2, const double tol=1e-3, const double minTimeStepBasedOnIterations=0., const bool verbose=false)
constructor
Definition: TimeStepControl.cpp:232
double computeTimeStepSize(const double dt, const int iterations, const RelativeChangeInterface &relativeChange, const double) const
compute new time step size suggestions based on the PID controller
Definition: TimeStepControl.cpp:252
PID controller based adaptive time step control as suggested in: Turek and Kuzmin.
Definition: TimeStepControl.hpp:97
PIDTimeStepControl(const double tol=1e-3, const bool verbose=false)
constructor
Definition: TimeStepControl.cpp:156
double computeTimeStepSize(const double dt, const int, const RelativeChangeInterface &relativeChange, const double) const
compute new time step size suggestions based on the PID controller
Definition: TimeStepControl.cpp:173
RelativeChangeInterface.
Definition: TimeStepControlInterface.hpp:32
A simple iteration count based adaptive time step control.
Definition: TimeStepControl.hpp:44
double computeTimeStepSize(const double dt, const int iterations, const RelativeChangeInterface &, const double) const
compute new time step size suggestions based on the PID controller
Definition: TimeStepControl.cpp:76
TimeStepControlInterface.
Definition: TimeStepControlInterface.hpp:49
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27