My Project
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 
33 namespace Opm { namespace EclIO {
34 
35  class EclOutput;
36 
37 }} // namespace Opm::EclIO
38 
39 namespace 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 
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 
135  class Restart
136  {
137  public:
155  explicit Restart(const ResultSet& rset,
156  const int seqnum,
157  const Formatted& fmt,
158  const Unified& unif);
159 
160  ~Restart();
161 
162  Restart(const Restart& rhs) = delete;
163  Restart(Restart&& rhs);
164 
165  Restart& operator=(const Restart& rhs) = delete;
166  Restart& operator=(Restart&& rhs);
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 
301  ~RFT();
302 
303  RFT(const RFT& rhs) = delete;
304  RFT(RFT&& rhs);
305 
306  RFT& operator=(const RFT& rhs) = delete;
307  RFT& operator=(RFT&& rhs);
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:
366  using StartTime = time_point;
367 
368  enum class UnitConvention
369  {
370  Metric = 1,
371  Field = 2,
372  Lab = 3,
373  Pvt_M = 4,
374  };
375 
377  {
378  std::string root;
379  int step;
380  };
381 
383  {
384  public:
385  void add(const std::string& keyword,
386  const std::string& wgname,
387  const int num,
388  const std::string& unit);
389 
390  friend class SummarySpecification;
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 
408  SummarySpecification(const SummarySpecification& rhs) = delete;
410 
411  SummarySpecification& operator=(const SummarySpecification& rhs) = delete;
412  SummarySpecification& operator=(SummarySpecification&& rhs);
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>
433  createSummaryFile(const ResultSet& rset,
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
Definition: EclOutput.hpp:39
File manager for "init" output streams.
Definition: OutputStream.hpp:56
void write(const std::string &kw, const std::vector< int > &data)
Write integer data to underlying output stream.
Init(const ResultSet &rset, const Formatted &fmt)
Constructor.
void write(const std::string &kw, const std::vector< float > &data)
Write single precision floating point data to underlying output stream.
void write(const std::string &kw, const std::vector< double > &data)
Write double precision floating point data to underlying output stream.
void write(const std::string &kw, const std::vector< bool > &data)
Write boolean data to underlying output stream.
File manager for RFT output streams.
Definition: OutputStream.hpp:284
void write(const std::string &kw, const std::vector< int > &data)
Write integer data to underlying output stream.
RFT(const ResultSet &rset, const Formatted &fmt, const OpenExisting &existing)
Constructor.
void write(const std::string &kw, const std::vector< float > &data)
Write single precision floating point data to underlying output stream.
void write(const std::string &kw, const std::vector< PaddedOutputString< 8 >> &data)
Write padded character data (8 characters per string) to underlying output stream.
File manager for restart output streams.
Definition: OutputStream.hpp:136
void write(const std::string &kw, const std::vector< float > &data)
Write single precision floating point data to underlying output stream.
void write(const std::string &kw, const std::vector< PaddedOutputString< 8 >> &data)
Write padded character data (8 characters per string) to underlying output stream.
Restart(const ResultSet &rset, const int seqnum, const Formatted &fmt, const Unified &unif)
Constructor.
void write(const std::string &kw, const std::vector< std::string > &data)
Write unpadded string data to underlying output stream.
void write(const std::string &kw, const std::vector< double > &data)
Write double precision floating point data to underlying output stream.
void message(const std::string &msg)
Generate a message string (keyword type 'MESS') in underlying output stream.
void write(const std::string &kw, const std::vector< bool > &data)
Write boolean data to underlying output stream.
void write(const std::string &kw, const std::vector< int > &data)
Write integer data to underlying output stream.
Definition: OutputStream.hpp:364
Null-terminated, left adjusted, space padded array of N characters.
Definition: PaddedOutputString.hpp:40
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29
Definition: OutputStream.hpp:41
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