opm-simulators
Loading...
Searching...
No Matches
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#include <opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp>
26
27#include <string>
28#include <vector>
29
30namespace Opm
31{
32 enum class TimeStepControlType {
33 SimpleIterationCount,
34 PID,
35 PIDAndIterationCount,
36 HardCodedTimeStep,
37 General3rdOrder,
38 };
39
40 enum class ToleranceTestVersions {
41 Standard,
42 ControlErrorFiltering,
43 };
44
45 enum class InternalControlVersions {
46 IController,
47 General3rdOrder,
48 };
49
53 //
55 class SimpleIterationCountTimeStepControl : public TimeStepControlInterface
56 {
57 public:
58 static constexpr TimeStepControlType Type = TimeStepControlType::SimpleIterationCount;
59
60 SimpleIterationCountTimeStepControl() = default;
61
67 SimpleIterationCountTimeStepControl(const int target_iterations,
68 const double decayrate,
69 const double growthrate,
70 const bool verbose);
71
72 static SimpleIterationCountTimeStepControl serializationTestObject();
73
75 double computeTimeStepSize(const double dt,
76 const int iterations,
77 const RelativeChangeInterface& /* relativeChange */,
78 const AdaptiveSimulatorTimer& /* substepTimer */ ) const override;
79
80 bool timeStepAccepted(const double /* error */,
81 const double /* timeStepJustCompleted */) const override { return true; }
82
83 template<class Serializer>
84 void serializeOp(Serializer& serializer)
85 {
86 serializer(target_iterations_);
87 serializer(decayrate_);
88 serializer(growthrate_);
89 serializer(verbose_);
90 }
91
92 bool operator==(const SimpleIterationCountTimeStepControl&) const;
93
94 protected:
95 const int target_iterations_ = 0;
96 const double decayrate_ = 0.0;
97 const double growthrate_ = 0.0;
98 const bool verbose_ = false;
99 };
100
115 class PIDTimeStepControl : public TimeStepControlInterface
116 {
117 public:
118 static constexpr TimeStepControlType Type = TimeStepControlType::PID;
119
120 PIDTimeStepControl() = default;
121
126 PIDTimeStepControl(const double tol,
127 const bool verbose);
128
129 static PIDTimeStepControl serializationTestObject();
130
134 double computeTimeStepSize(const double dt,
135 const int /* iterations */,
136 const RelativeChangeInterface& relativeChange,
137 const AdaptiveSimulatorTimer& /* substepTimer */ ) const override;
138
139 bool timeStepAccepted(const double /* error */,
140 const double /* timeStepJustCompleted */) const override { return true; }
141
142 template<class Serializer>
143 void serializeOp(Serializer& serializer)
144 {
145 serializer(tol_);
146 serializer(errors_);
147 serializer(verbose_);
148 }
149
150 bool operator==(const PIDTimeStepControl&) const;
151
152 protected:
153 const double tol_ = 0.1;
154 mutable std::vector< double > errors_{};
155 const bool verbose_ = false;
156 };
157
162 //
164 class PIDAndIterationCountTimeStepControl : public PIDTimeStepControl
165 {
166 typedef PIDTimeStepControl BaseType;
167 public:
168 static constexpr TimeStepControlType Type = TimeStepControlType::PIDAndIterationCount;
169
170 PIDAndIterationCountTimeStepControl() = default;
171
180 PIDAndIterationCountTimeStepControl(const int target_iterations,
181 const double decayDampingFactor,
182 const double growthDampingFactor,
183 const double tol,
184 const double minTimeStepBasedOnIterations,
185 const bool verbose);
186
187 static PIDAndIterationCountTimeStepControl serializationTestObject();
188
193 double computeTimeStepSize(const double dt,
194 const int iterations,
195 const RelativeChangeInterface& relativeChange,
196 const AdaptiveSimulatorTimer& /* substepTimer */ ) const override;
197
198 bool timeStepAccepted(const double /* error */,
199 const double /* timeStepJustCompleted */) const override { return true; }
200
201 template<class Serializer>
202 void serializeOp(Serializer& serializer)
203 {
204 serializer(static_cast<PIDTimeStepControl&>(*this));
205 serializer(target_iterations_);
206 serializer(decayDampingFactor_);
207 serializer(growthDampingFactor_);
208 serializer(minTimeStepBasedOnIterations_);
209 serializer(verbose_);
210 }
211
212 bool operator==(const PIDAndIterationCountTimeStepControl&) const;
213
214 protected:
215 const int target_iterations_ = 8;
216 const double decayDampingFactor_ = 1.0;
217 const double growthDampingFactor_ = 3.2;
218 const double minTimeStepBasedOnIterations_ = 0.0;
219 const bool verbose_ = false;
220 };
221
227 class General3rdOrderController : public TimeStepControlInterface
228 {
229 public:
230 static constexpr TimeStepControlType Type = TimeStepControlType::General3rdOrder;
231
232 General3rdOrderController() = default;
233
244 General3rdOrderController(const double tolerance,
245 const double safetyFactor,
246 const bool rejectCompletedStep,
247 const std::string& toleranceTestVersion,
248 const double maxReductionTimeStep,
249 const std::string& parameters,
250 const bool verbose);
251
252 static General3rdOrderController serializationTestObject();
253
254 double computeTimeStepSize(const double dt,
255 const int /* iterations */,
256 const RelativeChangeInterface& /* relativeChange */,
257 const AdaptiveSimulatorTimer& substepTimer) const override;
258
259 double timeStepFactor(const std::array<double, 3>& errors, const std::array<double, 3>& timeSteps) const;
260
261 bool timeStepAccepted(const double error,
262 const double timeStepJustCompleted) const override;
263
264 template<class Serializer>
265 void serializeOp(Serializer& serializer)
266 {
267 serializer(tolerance_);
268 serializer(safetyFactor_);
269 serializer(rejectCompletedStep_);
270 serializer(errors_);
271 serializer(timeSteps_);
272 serializer(beta_);
273 serializer(alpha_);
274 serializer(controllerVersion_);
275 serializer(toleranceTestVersion_);
276 serializer(maxReductionTimeStep_);
277 serializer(verbose_);
278 }
279
280 bool operator==(const General3rdOrderController&) const;
281
282
283 protected:
284 const double tolerance_ = 0.1;
285 const double safetyFactor_ = 0.8;
286 const bool rejectCompletedStep_ = false;
287 mutable std::array<double, 3> errors_{};
288 mutable std::array<double, 3> timeSteps_{};
289 mutable std::array<double, 3> beta_{0.125, 0.25, 0.125};
290 mutable std::array<double, 2> alpha_{0.75, 0.25};
291 mutable InternalControlVersions controllerVersion_{InternalControlVersions::IController};
292 ToleranceTestVersions toleranceTestVersion_{ToleranceTestVersions::Standard};
293 const double maxReductionTimeStep_ = 0.1;
294 const bool verbose_ = false;
295 };
296
306 class HardcodedTimeStepControl : public TimeStepControlInterface
307 {
308 public:
309 static constexpr TimeStepControlType Type = TimeStepControlType::HardCodedTimeStep;
310
311 HardcodedTimeStepControl() = default;
312
315 explicit HardcodedTimeStepControl(const std::string& filename);
316
317 static HardcodedTimeStepControl serializationTestObject();
318
322 double computeTimeStepSize(const double dt,
323 const int /* iterations */,
324 const RelativeChangeInterface& /*relativeChange */,
325 const AdaptiveSimulatorTimer& substepTimer) const override;
326
327 bool timeStepAccepted(const double /* error */,
328 const double /* timeStepJustCompleted */) const override { return true; }
329
330 template<class Serializer>
331 void serializeOp(Serializer& serializer)
332 {
333 serializer(subStepTime_);
334 }
335
336 bool operator==(const HardcodedTimeStepControl&) const;
337
338 protected:
339 // store the time (in days) of the substeps the simulator should use
340 std::vector<double> subStepTime_;
341 };
342
343
344} // end namespace Opm
345#endif
Simulation timer for adaptive time stepping.
Definition AdaptiveSimulatorTimer.hpp:41
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
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
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
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
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
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
PID controller based adaptive time step control as suggested in: Turek and Kuzmin.
Definition TimeStepControl.hpp:116
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
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
RelativeChangeInterface.
Definition TimeStepControlInterface.hpp:34
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
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
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43