My Project
Loading...
Searching...
No Matches
EclOutput.hpp
1/*
2 Copyright 2019 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 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 OPM is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with OPM. If not, see <http://www.gnu.org/licenses/>.
17 */
18#ifndef OPM_IO_ECLOUTPUT_HPP
19#define OPM_IO_ECLOUTPUT_HPP
20
21#include <fstream>
22#include <ios>
23#include <string>
24#include <typeinfo>
25#include <vector>
26
27#include <opm/io/eclipse/EclIOdata.hpp>
28#include <opm/io/eclipse/PaddedOutputString.hpp>
29
30namespace Opm { namespace EclIO { namespace OutputStream {
31 class Restart;
32 class SummarySpecification;
33}}}
34
35namespace Opm { namespace EclIO {
36
38{
39public:
40 EclOutput(const std::string& filename,
41 const bool formatted,
42 const std::ios_base::openmode mode = std::ios::out);
43
44 template<typename T>
45 void write(const std::string& name,
46 const std::vector<T>& data)
47 {
48 eclArrType arrType = MESS;
49 int element_size = 4;
50
51 if (typeid(T) == typeid(int))
52 arrType = INTE;
53 else if (typeid(T) == typeid(float))
54 arrType = REAL;
55 else if (typeid(T) == typeid(double)){
56 arrType = DOUB;
57 element_size = 8;
58 } else if (typeid(T) == typeid(bool))
59 arrType = LOGI;
60 else if (typeid(T) == typeid(char))
61 arrType = MESS;
62
63 if (isFormatted)
64 {
65 writeFormattedHeader(name, data.size(), arrType, element_size);
66 if (arrType != MESS)
67 writeFormattedArray(data);
68 }
69 else
70 {
71 writeBinaryHeader(name, data.size(), arrType, element_size);
72 if (arrType != MESS)
73 writeBinaryArray(data);
74 }
75 }
76
77 // when this function is used array type will be assumed C0NN (not CHAR).
78 // Also in cases where element size is 8 or less, element size will be 8.
79
80 void write(const std::string& name, const std::vector<std::string>& data, int element_size);
81
82 void message(const std::string& msg);
83 void flushStream();
84
85 void set_ix() { ix_standard = true; }
86
87 friend class OutputStream::Restart;
89
90private:
91 void writeBinaryHeader(const std::string& arrName, int64_t size, eclArrType arrType, int element_size);
92
93 template <typename T>
94 void writeBinaryArray(const std::vector<T>& data);
95
96 void writeBinaryCharArray(const std::vector<std::string>& data, int element_size);
97 void writeBinaryCharArray(const std::vector<PaddedOutputString<8>>& data);
98
99 void writeFormattedHeader(const std::string& arrName, int size, eclArrType arrType, int element_size);
100
101 template <typename T>
102 void writeFormattedArray(const std::vector<T>& data);
103
104 void writeFormattedCharArray(const std::vector<std::string>& data, int element_size);
105 void writeFormattedCharArray(const std::vector<PaddedOutputString<8>>& data);
106
107 void writeArrayType(const eclArrType arrType);
108 std::string make_real_string_ecl(float value) const;
109 std::string make_real_string_ix(float value) const;
110 std::string make_doub_string_ecl(double value) const;
111 std::string make_doub_string_ix(double value) const;
112
113 bool isFormatted, ix_standard;
114 std::ofstream ofileH;
115};
116
117
118template<>
119void EclOutput::write<std::string>(const std::string& name,
120 const std::vector<std::string>& data);
121
122template <>
123void EclOutput::write<PaddedOutputString<8>>
124 (const std::string& name,
125 const std::vector<PaddedOutputString<8>>& data);
126
127}} // namespace Opm::EclIO
128
129#endif // OPM_IO_ECLOUTPUT_HPP
Definition EclOutput.hpp:38
File manager for restart output streams.
Definition OutputStream.hpp:136
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:30