OutputStream.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2019 Equinor 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_IO_OUTPUTSTREAM_HPP_INCLUDED
21#define OPM_IO_OUTPUTSTREAM_HPP_INCLUDED
22
25
26#include <array>
27#include <chrono>
28#include <ios>
29#include <memory>
30#include <string>
31#include <vector>
32
33namespace Opm { namespace EclIO {
34
35 class EclOutput;
36
37}} // namespace Opm::EclIO
38
39namespace Opm { namespace EclIO { namespace OutputStream {
40
41 struct Formatted { bool set; };
42 struct Unified { bool set; };
43
45 struct ResultSet
46 {
49
52 };
53
55 class Init
56 {
57 public:
65 explicit Init(const ResultSet& rset,
66 const Formatted& fmt);
67
69
70 Init(const Init& rhs) = delete;
71 Init(Init&& rhs);
72
73 Init& operator=(const Init& rhs) = delete;
75
81 void write(const std::string& kw,
82 const std::vector<int>& data);
83
89 void write(const std::string& kw,
90 const std::vector<bool>& data);
91
98 void write(const std::string& kw,
99 const std::vector<float>& data);
100
107 void write(const std::string& kw,
108 const std::vector<double>& data);
109
110 private:
112 std::unique_ptr<EclOutput> stream_;
113
122 void open(const std::string& fname,
123 const bool formatted);
124
126 EclOutput& stream();
127
129 template <typename T>
130 void writeImpl(const std::string& kw,
131 const std::vector<T>& data);
132 };
133
136 {
137 public:
155 explicit Restart(const ResultSet& rset,
156 const int seqnum,
157 const Formatted& fmt,
158 const Unified& unif);
159
161
162 Restart(const Restart& rhs) = delete;
164
165 Restart& operator=(const Restart& rhs) = delete;
167
172 void message(const std::string& msg);
173
179 void write(const std::string& kw,
180 const std::vector<int>& data);
181
187 void write(const std::string& kw,
188 const std::vector<bool>& data);
189
196 void write(const std::string& kw,
197 const std::vector<float>& data);
198
205 void write(const std::string& kw,
206 const std::vector<double>& data);
207
213 void write(const std::string& kw,
214 const std::vector<std::string>& data);
215
222 void write(const std::string& kw,
223 const std::vector<PaddedOutputString<8>>& data);
224
225 private:
227 std::unique_ptr<EclOutput> stream_;
228
241 void openUnified(const std::string& fname,
242 const bool formatted,
243 const int seqnum);
244
254 void openNew(const std::string& fname,
255 const bool formatted);
256
267 void openExisting(const std::string& fname,
268 const bool formatted,
269 const std::streampos writePos);
270
274 EclOutput& stream();
275
277 template <typename T>
278 void writeImpl(const std::string& kw,
279 const std::vector<T>& data);
280 };
281
283 class RFT
284 {
285 public:
286 struct OpenExisting { bool set; };
287
297 explicit RFT(const ResultSet& rset,
298 const Formatted& fmt,
299 const OpenExisting& existing);
300
302
303 RFT(const RFT& rhs) = delete;
304 RFT(RFT&& rhs);
305
306 RFT& operator=(const RFT& rhs) = delete;
308
314 void write(const std::string& kw,
315 const std::vector<int>& data);
316
323 void write(const std::string& kw,
324 const std::vector<float>& data);
325
332 void write(const std::string& kw,
333 const std::vector<PaddedOutputString<8>>& data);
334
335 private:
337 std::unique_ptr<EclOutput> stream_;
338
350 void open(const std::string& fname,
351 const bool formatted,
352 const bool existing);
353
355 EclOutput& stream();
356
358 template <typename T>
359 void writeImpl(const std::string& kw,
360 const std::vector<T>& data);
361 };
362
364 {
365 public:
367
368 enum class UnitConvention
369 {
370 Metric = 1,
371 Field = 2,
372 Lab = 3,
373 Pvt_M = 4,
374 };
375
377 {
379 int step;
380 };
381
383 {
384 public:
386 const std::string& wgname,
387 const int num,
388 const std::string& unit);
389
391
392 private:
393 std::vector<PaddedOutputString<8>> keywords{};
394 std::vector<PaddedOutputString<8>> wgnames{};
395 std::vector<int> nums{};
396 std::vector<PaddedOutputString<8>> units{};
397 };
398
399 explicit SummarySpecification(const ResultSet& rset,
400 const Formatted& fmt,
401 const UnitConvention uconv,
402 const std::array<int,3>& cartDims,
403 const RestartSpecification& restart,
404 const StartTime start);
405
407
410
413
414 void write(const Parameters& params);
415
416 private:
417 int unit_;
418 int restartStep_;
419 std::array<int,3> cartDims_;
420 StartTime startDate_;
421 std::vector<PaddedOutputString<8>> restart_;
422
424 std::unique_ptr<EclOutput> stream_;
425
426 void rewindStream();
427 void flushStream();
428
429 EclOutput& stream();
430 };
431
432 std::unique_ptr<EclOutput>
434 const int seqnum,
435 const Formatted& fmt,
436 const Unified& unif);
437
451 std::string outputFileName(const ResultSet& rsetDescriptor,
452 const std::string& ext);
453
454}}} // namespace Opm::EclIO::OutputStream
455
456#endif // OPM_IO_OUTPUTSTREAM_HPP_INCLUDED
int cJSON_bool fmt
Definition: cJSON.h:158
const char *const string
Definition: cJSON.h:170
Definition: EclOutput.hpp:39
File manager for "init" output streams.
Definition: OutputStream.hpp:56
Init & operator=(Init &&rhs)
void write(const std::string &kw, const std::vector< int > &data)
Init(const ResultSet &rset, const Formatted &fmt)
void write(const std::string &kw, const std::vector< float > &data)
void write(const std::string &kw, const std::vector< double > &data)
Init(const Init &rhs)=delete
Init & operator=(const Init &rhs)=delete
void write(const std::string &kw, const std::vector< bool > &data)
File manager for RFT output streams.
Definition: OutputStream.hpp:284
RFT(const RFT &rhs)=delete
void write(const std::string &kw, const std::vector< int > &data)
RFT(const ResultSet &rset, const Formatted &fmt, const OpenExisting &existing)
void write(const std::string &kw, const std::vector< float > &data)
RFT & operator=(const RFT &rhs)=delete
void write(const std::string &kw, const std::vector< PaddedOutputString< 8 > > &data)
File manager for restart output streams.
Definition: OutputStream.hpp:136
void write(const std::string &kw, const std::vector< float > &data)
Restart & operator=(Restart &&rhs)
Restart(const ResultSet &rset, const int seqnum, const Formatted &fmt, const Unified &unif)
void write(const std::string &kw, const std::vector< PaddedOutputString< 8 > > &data)
Restart & operator=(const Restart &rhs)=delete
void write(const std::string &kw, const std::vector< std::string > &data)
void write(const std::string &kw, const std::vector< double > &data)
void message(const std::string &msg)
void write(const std::string &kw, const std::vector< bool > &data)
Restart(const Restart &rhs)=delete
void write(const std::string &kw, const std::vector< int > &data)
void add(const std::string &keyword, const std::string &wgname, const int num, const std::string &unit)
Definition: OutputStream.hpp:364
SummarySpecification & operator=(SummarySpecification &&rhs)
SummarySpecification & operator=(const SummarySpecification &rhs)=delete
void write(const Parameters &params)
SummarySpecification(SummarySpecification &&rhs)
time_point StartTime
Definition: OutputStream.hpp:366
SummarySpecification(const ResultSet &rset, const Formatted &fmt, const UnitConvention uconv, const std::array< int, 3 > &cartDims, const RestartSpecification &restart, const StartTime start)
UnitConvention
Definition: OutputStream.hpp:369
SummarySpecification(const SummarySpecification &rhs)=delete
std::string outputFileName(const ResultSet &rsetDescriptor, const std::string &ext)
std::unique_ptr< EclOutput > createSummaryFile(const ResultSet &rset, const int seqnum, const Formatted &fmt, const Unified &unif)
UDAKeyword keyword(UDAControl control)
Definition: A.hpp:4
std::chrono::time_point< std::chrono::system_clock, std::chrono::duration< int64_t, std::ratio< 1, 1000 > > > time_point
Definition: TimeService.hpp:31
static std::string data()
Definition: exprtk.hpp:40022
Definition: OutputStream.hpp:41
bool set
Definition: OutputStream.hpp:41
Definition: OutputStream.hpp:286
bool set
Definition: OutputStream.hpp:286
Abstract representation of an ECLIPSE-style result set.
Definition: OutputStream.hpp:46
std::string baseName
Base name of simulation run.
Definition: OutputStream.hpp:51
std::string outputDir
Output directory. Commonly "." or location of run's .DATA file.
Definition: OutputStream.hpp:48
Definition: OutputStream.hpp:42
bool set
Definition: OutputStream.hpp:42