RestartConfig.hpp
Go to the documentation of this file.
1/*
2 Copyright 2015 Statoil ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef OPM_RESTART_CONFIG_HPP
21#define OPM_RESTART_CONFIG_HPP
22
23#include <vector>
24#include <set>
28
29/*
30 The RestartConfig class internalizes information of when (at which
31 report steps) we should save restart files, and which properties
32 should be included in the restart files. The configuration of this
33 immensely complex, and this code is unfortunately also way too
34 complex.
35
36 The most basic question to disentangle is the "When to write restart
37 files" versus "What data to store write in the restart file". As
38 expressed in the deck keywords this completely entangled, in this
39 implementation we have tried to disentangle it:
40
41 Keywords involved
42 -----------------
43
44 RPTRST: This is the main keyword for configuring restart output; it
45 can be used to configure bothe when to write the files and which
46 properties should be included in the restart files.
47
48
49 RPTSCHED: The main purpose of the RPTSCHED keyword is to configure
50 output from the SCHEDULE section to the PRINT file. However the
51 mneomnic RESTART=n can be used to turn writing of restart files
52 on, and also for values > 2 to some configuration of what is
53 written to the restart file:
54
55 RESTART=1 : As RPTRST,BASIC=1
56 RESTART>1 : As RPTRST,BASIC=2
57 RESTART>2 : Flow is added to restart file
58 RESTART>3 : Fluid in place is added to restart file
59 RESTART=6 : Restart file for every timestep.
60
61
62
63 RPTSOL: The RPTSOL keyword is very similar to the RPTCHED keyword,
64 it configures output from the SOLUTION section to the PRINT file,
65 but just as the RPTSCHED keyword it accepts a RESTART=n mnenonic
66 which can be used similarly to the BASIC=n mnenonic of the RPTRST
67 keyword. In particular the writing of an initial restart files
68 with initial equilibrium solution is controlled by the RPTSOL
69 keyword. If the restart mneonic is greater than 2 that can be
70 used to configure FLOWS and FIP keywords in the restart file.
71
72 RESTART=1 : As RPTRST,BASIC=1
73 RESTART>1 : As RPTRST,BASIC=2
74 RESTART>2 : Flow is added to restart file
75 RESTART>3 : Fluid in place is added to restart file
76
77
78 The basic rule in ECLIPSE is generally that the 'last keyword wins',
79 but for the RPTRST RPTSHCED combination a BASIC setting with n >= 3
80 will override consecutive RESTART=n settings from RPTSCHED.
81
82
83 When to write restart files:
84 ----------------------------
85
86 When to write the restart file is governed by the BASIC=n setting in
87 the RPTRST keyword and the RESTART=n settings in the RPTSOL and
88 RPTSCHED keywords. The most common setting is 'ON' - i.e. BASIC=2
89 which means write a restart file for every report step, that can be
90 turned off again with BASIC=0. For BASIC>2 there are varietes of
91 every n'th report step, and the first report step in every month and
92 every year.
93
94
95 Old style / new style
96 ---------------------
97
98 All of the relevant keywords can be specified using a new style
99 based on string mneomnics and alternatively an old style represented
100 with a *strictly ordered* list of integers. For instance both of
101 these keywords request restart files written for every report step;
102 in addition to the fields required to actually restart the files
103 should contain the relative permeabilities KRO, KRW, KRG:
104
105 RPTRST
106 BASIC=2 KRG KRW KRO /
107
108
109 RPTRST
110 2 9*0 3*1 17*0
111
112 Integer controls and string mneomnics can not be mixed in the same
113 keyword, but they can be mixed in the same deck - and that is
114 actually quite common.
115
116
117 What is written to the restart file
118 -----------------------------------
119
120 The BASIC=n mneonics request the writing of a restart file which
121 should contain 'all properties required to restart', in addition you
122 can configure extra keywords to be added to the restart file. This
123 is configured by just adding a list as:
124
125 RPTRST
126 BASIC=2 KRG KRW KRO /
127
128 It is really *not clear* what is the correct persistence semantics
129 for these keywords, consider for insance the following series of keywords:
130
131 -- Request restart file at every report step, the restart files
132 -- should contain additional properties KRO, KRG and KRW.
133 RPTRST
134 BASIC=2 KRG KRW KRO /
135
136 -- Advance the simulator forward with TSTEP / DATES
137 TSTEP / DATES / WCONxxx
138
139 -- Turn writing of restart files OFF using integer controls.
140 RPTRST
141 0 /
142
143 -- Advance the simulator forward with TSTEP / DATES
144 TSTEP / DATES / WCONxxx
145
146 -- Turn writing of restart files ON using integer controls.
147 RPTRST
148 2 /
149
150 When writing of restart files is turned on again with the last
151 RPTRST keyword, should still the relative permeabilites KRO, KRW and
152 KRG be added to the restart files? The model we have implemented is:
153
154 - The list of keywords written to the restart file is persisted
155 independtly of the BASIC=n setting.
156
157 - Using string based mnonics you can *only add* kewyords to be
158 written to the files. To stop writing a keyword you must use an
159 integer control with value 0.
160
161 Based on this best guess heuristic the final restart files will
162 still contain KRO, KRW and KRG.
163
164
165
166 What is required to restart?
167 ----------------------------
168
169 A restart capable files is requested with the 'BASIC' mneomnic, but
170 exactly which properties the 'BASIC' keyword is expanded to is the
171 responsability of the simulator; i.e. for a black oil simulation you
172 will at the very least need the expansion:
173
174 BASIC -> PRESSURE, SWAT, SGAS, RS, RV
175
176 But this class just carries the boolean information: Yes - restart
177 is requested - expanding as illustrated is the responsability of the
178 simulator.
179
180
181
182
183 What is not supported?
184 ----------------------
185
186 The SAVE keyword is not supported in OPM at all, this implies that
187 the SAVE and SFREQ mneomics are not supported.
188*/
189
190
191
192namespace Opm {
193
194 template< typename > class DynamicState;
195
196 class Deck;
197 class DeckKeyword;
198 class GRIDSection;
199 class RUNSPECSection;
200 class SCHEDULESection;
201 class SOLUTIONSection;
202 class Schedule;
203 class ParseContext;
204 class ErrorGuard;
205
206 /*The IOConfig class holds data about input / ouput configurations
207
208 Amongst these configuration settings, a IOConfig object knows if
209 a restart file should be written for a specific report step
210
211 The write of restart files is governed by several eclipse keywords.
212 These keywords are all described in the eclipse manual, but some
213 of them are rather porly described there.
214 To have equal sets of restart files written from Eclipse and Flow for various
215 configurations, we have made a qualified guess on the behaviour
216 for some of the keywords (by running eclipse for different configurations,
217 and looked at which restart files that have been written).
218
219
220 ------ RPTSOL RESTART (solution section) ------
221 If RPTSOL RESTART > 1 initial restart file is written.
222
223
224 ------ RPTRST (solution section) ------
225 Eclipse manual states that the initial restart file is to be written
226 if RPTSOL RESTART > 1. But - due to that the initial restart file
227 is written from Eclipse for data where RPTSOL RESTART is not set, - we
228 have made a guess that when RPTRST is set in SOLUTION (no basic though...),
229 it means that the initial restart file should be written.
230 Running of eclipse with different settings have proven this to be a qualified guess.
231
232
233 ------ RPTRST BASIC=0 (solution or schedule section) ------
234 No restart files are written
235
236
237 ------ RPTRST BASIC=1 or RPTRST BASIC=2 (solution or schedule section) ------
238 Restart files are written for every timestep, from timestep 1 to number of timesteps.
239 (Write of inital timestep is governed by a separate setting)
240
241 Notice! Eclipse simulator RPTRST BASIC=1 writes restart files for every
242 report step, but only keeps the last one written. This functionality is
243 not supported in Flow; so to compare Eclipse results with Flow results
244 for every report step, set RPTRST BASIC=2 for the eclipse run
245
246
247 ------ RPTRST BASIC=3 FREQ=n (solution or schedule section) ------
248 Restart files are created every nth report time. Default frequency is 1 (every report step)
249
250 If a frequency higher than 1 is given:
251 start_rs = report step the setting was given.
252 write report step rstep if (rstep >= start_rs) && ((rstep % frequency) == 0).
253
254
255 ------ RPTRST BASIC=4 FREQ=n or RPTRST BASIC=5 FREQ=n (solution or schedule section) ------
256 For the settings BASIC 4 or BASIC 5, - first report step of every new year(4) or new month(5),
257 the first report step is compared with report step 0 (start), and then every report step is
258 compared with the previous one to see if year/month has changed.
259
260 This leaves us with a set of timesteps.
261 All timesteps in the set that are higher or equal to the timestep the RPTRST keyword was set on is written.
262
263 If in addition FREQUENCY is given (higher than 1), every n'the value of this set are to be written.
264
265 If the setting BASIC=4 or BASIC=5 is set on a timestep that is a member of the set "first timestep of
266 each year" / "First timestep of each month", then the timestep that is freq-1 timesteps (within the set) from
267 this start timestep will be written, and then every n'the timestep (within the set) from this one will be written.
268
269 If the setting BASIC=4 or BASIC=5 is set on a timestep that is not a member of the list "first timestep of
270 each year" / "First timestep of each month", then the list is searched for the closest timestep that are
271 larger than the timestep that introduced the setting, and then; same as above - the timestep that is freq-1
272 timesteps from this one (within the set) will be written, and then every n'the timestep (within the set) from
273 this one will be written.
274
275
276 ------ RPTRST BASIC=6 (solution or schedule section) ------
277 Not supported in Flow
278
279
280 ------ Default ------
281 If no keywords for config of writing restart files have been handled; no restart files are written.
282
283 */
284
285 //namespace {
286
288 /*
289 The content of this struct is logically divided in two; either the
290 restart behaviour is governed by { timestep , basic , frequency }, or
291 alternatively by { rptshec_restart_set , rptsched_restart }.
292
293 The former triplet is mainly governed by the RPTRST keyword and the
294 latter pair by the RPTSCHED keyword.
295 */
296 public:
297
298 RestartSchedule() = default;
299 explicit RestartSchedule( size_t sched_restart);
300 RestartSchedule( size_t step, size_t b, size_t freq);
301
303
304 bool writeRestartFile( size_t timestep , const TimeMap& timemap) const;
305 bool operator!=(const RestartSchedule& rhs) const;
306 bool operator==( const RestartSchedule& rhs ) const;
307
308 template<class Serializer>
309 void serializeOp(Serializer& serializer)
310 {
311 serializer(timestep);
312 serializer(basic);
313 serializer(frequency);
314 serializer(rptsched_restart_set);
315 serializer(rptsched_restart);
316 }
317
318 //private:
319 size_t timestep = 0;
320 size_t basic = 0;
321 size_t frequency = 0;
324 };
325 // }
327
328 public:
329
330 RestartConfig() = default;
331
332 template<typename T>
333 RestartConfig( const TimeMap& time_map, const Deck&, const ParseContext& parseContext, T&& errors );
334 RestartConfig( const TimeMap& time_map, const Deck&, const ParseContext& parseContext, ErrorGuard& errors );
335 RestartConfig( const TimeMap& time_map, const Deck& );
336
338
340 bool getWriteRestartFile(size_t timestep, bool log=true) const;
341 const std::map< std::string, int >& getRestartKeywords( size_t timestep ) const;
342 int getKeyword( const std::string& keyword, size_t timeStep) const;
343
344 void overrideRestartWriteInterval(size_t interval);
345 void handleSolutionSection(const SOLUTIONSection& solutionSection, const ParseContext& parseContext, ErrorGuard& errors);
346 void setWriteInitialRestartFile(bool writeInitialRestartFile);
347
348 RestartSchedule getNode( size_t timestep ) const;
349 static std::string getRestartFileName(const std::string& restart_base, int report_step, bool unified, bool fmt_file);
350
351 bool operator==(const RestartConfig& data) const;
352
353 template<class Serializer>
354 void serializeOp(Serializer& serializer)
355 {
356 m_timemap.serializeOp(serializer);
357 serializer(m_first_restart_step);
358 serializer(m_write_initial_RST_file);
359 restart_schedule.serializeOp(serializer);
360 restart_keywords.serializeOp<Serializer, false>(serializer);
361 serializer(save_keywords);
362 }
363
364 private:
370 void initFirstOutput( );
371
372 bool getWriteRestartFileFrequency(size_t timestep,
373 size_t start_timestep,
374 size_t frequency,
375 bool years = false,
376 bool months = false) const;
377 void handleRPTSOL( const DeckKeyword& keyword);
378 void handleScheduleSection( const SCHEDULESection& schedule, const ParseContext& parseContext, ErrorGuard& errors);
379 void update( size_t step, const RestartSchedule& rs);
380 static RestartSchedule rptsched( const DeckKeyword& );
381
382 TimeMap m_timemap;
383 int m_first_restart_step = 1;
384 bool m_write_initial_RST_file = false;
385
386 DynamicState< RestartSchedule > restart_schedule;
388 std::vector< bool > save_keywords;
389 };
390} //namespace Opm
391
392
393
394#endif
const cJSON *const b
Definition: cJSON.h:251
const char *const string
Definition: cJSON.h:170
Definition: DeckKeyword.hpp:38
Definition: Deck.hpp:115
Definition: DynamicState.hpp:58
void serializeOp(Serializer &serializer)
Definition: DynamicState.hpp:235
Definition: ErrorGuard.hpp:29
Definition: ParseContext.hpp:84
Definition: RestartConfig.hpp:326
void overrideRestartWriteInterval(size_t interval)
void serializeOp(Serializer &serializer)
Definition: RestartConfig.hpp:354
int getFirstRestartStep() const
RestartConfig(const TimeMap &time_map, const Deck &)
const std::map< std::string, int > & getRestartKeywords(size_t timestep) const
RestartSchedule getNode(size_t timestep) const
bool operator==(const RestartConfig &data) const
static std::string getRestartFileName(const std::string &restart_base, int report_step, bool unified, bool fmt_file)
RestartConfig()=default
RestartConfig(const TimeMap &time_map, const Deck &, const ParseContext &parseContext, ErrorGuard &errors)
void handleSolutionSection(const SOLUTIONSection &solutionSection, const ParseContext &parseContext, ErrorGuard &errors)
static RestartConfig serializeObject()
int getKeyword(const std::string &keyword, size_t timeStep) const
bool getWriteRestartFile(size_t timestep, bool log=true) const
RestartConfig(const TimeMap &time_map, const Deck &, const ParseContext &parseContext, T &&errors)
void setWriteInitialRestartFile(bool writeInitialRestartFile)
Definition: RestartConfig.hpp:287
bool rptsched_restart_set
Definition: RestartConfig.hpp:322
size_t timestep
Definition: RestartConfig.hpp:319
bool operator==(const RestartSchedule &rhs) const
size_t frequency
Definition: RestartConfig.hpp:321
RestartSchedule()=default
bool operator!=(const RestartSchedule &rhs) const
void serializeOp(Serializer &serializer)
Definition: RestartConfig.hpp:309
RestartSchedule(size_t step, size_t b, size_t freq)
size_t basic
Definition: RestartConfig.hpp:320
static RestartSchedule serializeObject()
bool writeRestartFile(size_t timestep, const TimeMap &timemap) const
size_t rptsched_restart
Definition: RestartConfig.hpp:323
RestartSchedule(size_t sched_restart)
Definition: DeckSection.hpp:115
Definition: DeckSection.hpp:103
Definition: Serializer.hpp:38
Definition: TimeMap.hpp:40
void serializeOp(Serializer &serializer)
Definition: TimeMap.hpp:81
UDAKeyword keyword(UDAControl control)
Definition: A.hpp:4
static std::string data()
Definition: exprtk.hpp:40022