opm-common
Loading...
Searching...
No Matches
OutputStream.hpp
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
23#include <opm/io/eclipse/PaddedOutputString.hpp>
24#include <opm/common/utility/TimeService.hpp>
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 {
48 std::string outputDir;
49
51 std::string baseName;
52 };
53
55 class Init
56 {
57 public:
65 explicit Init(const ResultSet& rset,
66 const Formatted& fmt);
67
68 ~Init();
69
70 Init(const Init& rhs) = delete;
71 Init(Init&& rhs);
72
73 Init& operator=(const Init& rhs) = delete;
74 Init& operator=(Init&& rhs);
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
116 void write(const std::string& kw,
117 const std::vector<PaddedOutputString<8>>& data);
118
119
121 void message(const std::string& msg);
122
123 private:
125 std::unique_ptr<EclOutput> stream_;
126
135 void open(const std::string& fname,
136 const bool formatted);
137
139 EclOutput& stream();
140
142 template <typename T>
143 void writeImpl(const std::string& kw,
144 const std::vector<T>& data);
145 };
146
149 {
150 public:
168 explicit Restart(const ResultSet& rset,
169 const int seqnum,
170 const Formatted& fmt,
171 const Unified& unif);
172
173 ~Restart();
174
175 Restart(const Restart& rhs) = delete;
176 Restart(Restart&& rhs);
177
178 Restart& operator=(const Restart& rhs) = delete;
179 Restart& operator=(Restart&& rhs);
180
185 void message(const std::string& msg);
186
192 void write(const std::string& kw,
193 const std::vector<int>& data);
194
200 void write(const std::string& kw,
201 const std::vector<bool>& data);
202
209 void write(const std::string& kw,
210 const std::vector<float>& data);
211
218 void write(const std::string& kw,
219 const std::vector<double>& data);
220
226 void write(const std::string& kw,
227 const std::vector<std::string>& data);
228
235 void write(const std::string& kw,
236 const std::vector<PaddedOutputString<8>>& data);
237
238 private:
240 std::unique_ptr<EclOutput> stream_;
241
254 void openUnified(const std::string& fname,
255 const bool formatted,
256 const int seqnum);
257
267 void openNew(const std::string& fname,
268 const bool formatted);
269
280 void openExisting(const std::string& fname,
281 const bool formatted,
282 const std::streampos writePos);
283
287 EclOutput& stream();
288
290 template <typename T>
291 void writeImpl(const std::string& kw,
292 const std::vector<T>& data);
293 };
294
296 class RFT
297 {
298 public:
299 struct OpenExisting { bool set; };
300
310 explicit RFT(const ResultSet& rset,
311 const Formatted& fmt,
312 const OpenExisting& existing);
313
314 ~RFT();
315
316 RFT(const RFT& rhs) = delete;
317 RFT(RFT&& rhs);
318
319 RFT& operator=(const RFT& rhs) = delete;
320 RFT& operator=(RFT&& rhs);
321
327 void write(const std::string& kw,
328 const std::vector<int>& data);
329
336 void write(const std::string& kw,
337 const std::vector<float>& data);
338
345 void write(const std::string& kw,
346 const std::vector<PaddedOutputString<8>>& data);
347
348 private:
350 std::unique_ptr<EclOutput> stream_;
351
363 void open(const std::string& fname,
364 const bool formatted,
365 const bool existing);
366
368 EclOutput& stream();
369
371 template <typename T>
372 void writeImpl(const std::string& kw,
373 const std::vector<T>& data);
374 };
375
376 class SummarySpecification
377 {
378 public:
379 using StartTime = time_point;
380
381 enum class UnitConvention
382 {
383 Metric = 1,
384 Field = 2,
385 Lab = 3,
386 Pvt_M = 4,
387 };
388
390 {
391 std::string root;
392 int step;
393 };
394
396 {
397 public:
398 void add(const std::string& keyword,
399 const std::string& wgname,
400 const int num,
401 const std::string& unit);
402
403 friend class SummarySpecification;
404
405 private:
406 std::vector<PaddedOutputString<8>> keywords{};
407 std::vector<PaddedOutputString<8>> wgnames{};
408 std::vector<int> nums{};
409 std::vector<PaddedOutputString<8>> units{};
410 };
411
412 explicit SummarySpecification(const ResultSet& rset,
413 const Formatted& fmt,
414 const UnitConvention uconv,
415 const std::array<int,3>& cartDims,
416 const RestartSpecification& restart,
417 const StartTime start);
418
419 ~SummarySpecification();
420
421 SummarySpecification(const SummarySpecification& rhs) = delete;
422 SummarySpecification(SummarySpecification&& rhs);
423
424 SummarySpecification& operator=(const SummarySpecification& rhs) = delete;
425 SummarySpecification& operator=(SummarySpecification&& rhs);
426
427 void write(const Parameters& params);
428
429 private:
430 int unit_;
431 int restartStep_;
432 std::array<int,3> cartDims_;
433 StartTime startDate_;
434 std::vector<PaddedOutputString<8>> restart_;
435
437 std::unique_ptr<EclOutput> stream_;
438
439 void rewindStream();
440 void flushStream();
441
442 EclOutput& stream();
443 };
444
445 std::unique_ptr<EclOutput>
446 createSummaryFile(const ResultSet& rset,
447 const int seqnum,
448 const Formatted& fmt,
449 const Unified& unif);
450
464 std::string outputFileName(const ResultSet& rsetDescriptor,
465 const std::string& ext);
466
467}}} // namespace Opm::EclIO::OutputStream
468
469#endif // OPM_IO_OUTPUTSTREAM_HPP_INCLUDED
Definition EclOutput.hpp:38
void write(const std::string &kw, const std::vector< int > &data)
Write integer data to underlying output stream.
Definition OutputStream.cpp:237
void message(const std::string &msg)
Definition OutputStream.cpp:271
Init(const ResultSet &rset, const Formatted &fmt)
Constructor.
Definition OutputStream.cpp:212
void write(const std::string &kw, const std::vector< int > &data)
Write integer data to underlying output stream.
Definition OutputStream.cpp:516
RFT(const ResultSet &rset, const Formatted &fmt, const OpenExisting &existing)
Constructor.
Definition OutputStream.cpp:490
Restart(const ResultSet &rset, const int seqnum, const Formatted &fmt, const Unified &unif)
Constructor.
Definition OutputStream.cpp:304
void message(const std::string &msg)
Generate a message string (keyword type 'MESS') in underlying output stream.
Definition OutputStream.cpp:343
void write(const std::string &kw, const std::vector< int > &data)
Write integer data to underlying output stream.
Definition OutputStream.cpp:350
Null-terminated, left adjusted, space padded array of N characters.
Definition PaddedOutputString.hpp:40
Definition of various units.
Definition Units.hpp:84
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition OutputStream.hpp:41
Definition OutputStream.hpp:299
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