opm-common
Loading...
Searching...
No Matches
OutputStream.hpp
1/*
2 Copyright (c) 2019 Equinor ASA
3 Copyroght (c) 2026 OPM-OP AS
4
5 This file is part of the Open Porous Media project (OPM).
6
7 OPM is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 OPM is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with OPM. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef OPM_IO_OUTPUTSTREAM_HPP_INCLUDED
22#define OPM_IO_OUTPUTSTREAM_HPP_INCLUDED
23
24#include <opm/io/eclipse/PaddedOutputString.hpp>
25#include <opm/common/utility/TimeService.hpp>
26
27#include <array>
28#include <chrono>
29#include <ios>
30#include <memory>
31#include <string>
32#include <vector>
33
34namespace Opm { namespace EclIO {
35
36 class EclOutput;
37
38}} // namespace Opm::EclIO
39
40namespace Opm { namespace EclIO { namespace OutputStream {
41
42 struct Formatted { bool set; };
43 struct Unified { bool set; };
44
46 struct ResultSet
47 {
49 std::string outputDir;
50
52 std::string baseName;
53 };
54
56 class Init
57 {
58 public:
66 explicit Init(const ResultSet& rset,
67 const Formatted& fmt);
68
69 ~Init();
70
71 Init(const Init& rhs) = delete;
72 Init(Init&& rhs);
73
74 Init& operator=(const Init& rhs) = delete;
75 Init& operator=(Init&& rhs);
76
82 void write(const std::string& kw,
83 const std::vector<int>& data);
84
90 void write(const std::string& kw,
91 const std::vector<bool>& data);
92
99 void write(const std::string& kw,
100 const std::vector<float>& data);
101
108 void write(const std::string& kw,
109 const std::vector<double>& data);
110
117 void write(const std::string& kw,
118 const std::vector<PaddedOutputString<8>>& data);
119
120
122 void message(const std::string& msg);
123
124 private:
126 std::unique_ptr<EclOutput> stream_;
127
136 void open(const std::string& fname,
137 const bool formatted);
138
140 EclOutput& stream();
141
143 template <typename T>
144 void writeImpl(const std::string& kw,
145 const std::vector<T>& data);
146 };
147
150 {
151 public:
169 explicit Restart(const ResultSet& rset,
170 const int seqnum,
171 const Formatted& fmt,
172 const Unified& unif);
173
174 ~Restart();
175
176 Restart(const Restart& rhs) = delete;
177 Restart(Restart&& rhs);
178
179 Restart& operator=(const Restart& rhs) = delete;
180 Restart& operator=(Restart&& rhs);
181
186 void message(const std::string& msg);
187
193 void write(const std::string& kw,
194 const std::vector<int>& data);
195
201 void write(const std::string& kw,
202 const std::vector<bool>& data);
203
210 void write(const std::string& kw,
211 const std::vector<float>& data);
212
219 void write(const std::string& kw,
220 const std::vector<double>& data);
221
227 void write(const std::string& kw,
228 const std::vector<std::string>& data);
229
236 void write(const std::string& kw,
237 const std::vector<PaddedOutputString<8>>& data);
238
239 private:
241 std::unique_ptr<EclOutput> stream_;
242
255 void openUnified(const std::string& fname,
256 const bool formatted,
257 const int seqnum);
258
268 void openNew(const std::string& fname,
269 const bool formatted);
270
281 void openExisting(const std::string& fname,
282 const bool formatted,
283 const std::streampos writePos);
284
288 EclOutput& stream();
289
291 template <typename T>
292 void writeImpl(const std::string& kw,
293 const std::vector<T>& data);
294 };
295
297 class RFT
298 {
299 public:
300 struct OpenExisting { bool set; };
301
311 explicit RFT(const ResultSet& rset,
312 const Formatted& fmt,
313 const OpenExisting& existing);
314
315 ~RFT();
316
317 RFT(const RFT& rhs) = delete;
318 RFT(RFT&& rhs);
319
320 RFT& operator=(const RFT& rhs) = delete;
321 RFT& operator=(RFT&& rhs);
322
328 void write(const std::string& kw,
329 const std::vector<int>& data);
330
337 void write(const std::string& kw,
338 const std::vector<float>& data);
339
346 void write(const std::string& kw,
347 const std::vector<PaddedOutputString<8>>& data);
348
349 private:
351 std::unique_ptr<EclOutput> stream_;
352
364 void open(const std::string& fname,
365 const bool formatted,
366 const bool existing);
367
369 EclOutput& stream();
370
372 template <typename T>
373 void writeImpl(const std::string& kw,
374 const std::vector<T>& data);
375 };
376
377 class SummarySpecification
378 {
379 public:
380 using StartTime = time_point;
381
382 enum class UnitConvention
383 {
384 Metric = 1,
385 Field = 2,
386 Lab = 3,
387 Pvt_M = 4,
388 };
389
391 {
392 std::string root;
393 int step;
394 };
395
397 {
398 public:
399 void add(const std::string& keyword,
400 const std::string& wgname,
401 const int num,
402 const std::string& unit);
403
404 friend class SummarySpecification;
405
406 private:
407 std::vector<PaddedOutputString<8>> keywords{};
408 std::vector<PaddedOutputString<8>> wgnames{};
409 std::vector<int> nums{};
410 std::vector<PaddedOutputString<8>> units{};
411 };
412
413 explicit SummarySpecification(const ResultSet& rset,
414 const Formatted& fmt,
415 const UnitConvention uconv,
416 const std::array<int,3>& cartDims,
417 const RestartSpecification& restart,
418 const StartTime start,
419 const StartTime computeStart);
420
421 ~SummarySpecification();
422
423 SummarySpecification(const SummarySpecification& rhs) = delete;
424 SummarySpecification(SummarySpecification&& rhs);
425
426 SummarySpecification& operator=(const SummarySpecification& rhs) = delete;
427 SummarySpecification& operator=(SummarySpecification&& rhs);
428
435 void write(const Parameters& params, const bool simulationFinished,
436 const int currentStep, const int basic);
437
438 private:
439 int unit_;
440 int restartStep_;
441 std::array<int,3> cartDims_;
442 StartTime startDate_;
444 StartTime computeStart_;
445 std::vector<PaddedOutputString<8>> restart_;
446
448 std::unique_ptr<EclOutput> stream_;
449
450 void rewindStream();
451 void flushStream();
452
453 EclOutput& stream();
454 };
455
456 std::unique_ptr<EclOutput>
457 createSummaryFile(const ResultSet& rset,
458 const int seqnum,
459 const Formatted& fmt,
460 const Unified& unif);
461
475 std::string outputFileName(const ResultSet& rsetDescriptor,
476 const std::string& ext);
477
478}}} // namespace Opm::EclIO::OutputStream
479
480#endif // OPM_IO_OUTPUTSTREAM_HPP_INCLUDED
Definition EclOutput.hpp:39
void write(const std::string &kw, const std::vector< int > &data)
Write integer data to underlying output stream.
Definition OutputStream.cpp:238
void message(const std::string &msg)
Definition OutputStream.cpp:272
Init(const ResultSet &rset, const Formatted &fmt)
Constructor.
Definition OutputStream.cpp:213
void write(const std::string &kw, const std::vector< int > &data)
Write integer data to underlying output stream.
Definition OutputStream.cpp:517
RFT(const ResultSet &rset, const Formatted &fmt, const OpenExisting &existing)
Constructor.
Definition OutputStream.cpp:491
Restart(const ResultSet &rset, const int seqnum, const Formatted &fmt, const Unified &unif)
Constructor.
Definition OutputStream.cpp:305
void message(const std::string &msg)
Generate a message string (keyword type 'MESS') in underlying output stream.
Definition OutputStream.cpp:344
void write(const std::string &kw, const std::vector< int > &data)
Write integer data to underlying output stream.
Definition OutputStream.cpp:351
void write(const Parameters &params, const bool simulationFinished, const int currentStep, const int basic)
Write SMSPEC file.
Definition OutputStream.cpp:806
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:42
Definition OutputStream.hpp:300
Abstract representation of an ECLIPSE-style result set.
Definition OutputStream.hpp:47
std::string baseName
Base name of simulation run.
Definition OutputStream.hpp:52
std::string outputDir
Output directory. Commonly "." or location of run's .DATA file.
Definition OutputStream.hpp:49
Definition OutputStream.hpp:43