ERst.hpp
Go to the documentation of this file.
1/*
2 Copyright 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 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
19#ifndef OPM_IO_ERST_HPP
20#define OPM_IO_ERST_HPP
21
23
24#include <ios>
25#include <map>
26#include <string>
27#include <unordered_map>
28#include <vector>
29
30
31namespace Opm { namespace EclIO { namespace OutputStream {
32 class Restart;
33}}}
34
35namespace Opm { namespace EclIO {
36
37class ERst : public EclFile
38{
39public:
40 explicit ERst(const std::string& filename);
41
42 bool hasReportStepNumber(int number) const;
43 bool hasLGR(const std::string& gridname, int reportStepNumber) const;
44
45 void loadReportStepNumber(int number);
46
47 template <typename T>
48 const std::vector<T>& getRestartData(const std::string& name, int reportStepNumber)
49 {
50 return getRestartData<T>(name,reportStepNumber, 0);
51 }
52
53 template <typename T>
54 const std::vector<T>& getRestartData(const std::string& name, int reportStepNumber, int occurrence);
55
56 template <typename T>
57 const std::vector<T>& getRestartData(const std::string& name, int reportStepNumber, const std::string& lgr_name);
58
59 template <typename T>
60 const std::vector<T>& getRestartData(int index, int reportStepNumber)
61 {
62 auto indRange = this->getIndexRange(reportStepNumber);
63 return this->get<T>(index + std::get<0>(indRange));
64 }
65
66 template <typename T>
67 const std::vector<T>& getRestartData(int index, int reportStepNumber, const std::string& lgr_name)
68 {
69 auto indRange = this->getIndexRange(reportStepNumber);
70
71 if ((std::get<0>(indRange) + index) > std::get<1>(indRange))
72 OPM_THROW(std::invalid_argument, "getRestartData, index out of range");
73
74 int start_ind = get_start_index_lgrname(reportStepNumber, lgr_name);
75 return this->get<T>(index + start_ind);
76 }
77
78 int occurrence_count(const std::string& name, int reportStepNumber) const;
79 size_t numberOfReportSteps() const { return seqnum.size(); };
80
81 const std::vector<int>& listOfReportStepNumbers() const { return seqnum; }
82
83 std::vector<EclEntry> listOfRstArrays(int reportStepNumber);
84 std::vector<EclEntry> listOfRstArrays(int reportStepNumber, const std::string& lgr_name);
85
87
88private:
89 int nReports;
90 std::vector<int> seqnum; // report step numbers, from SEQNUM array in restart file
91 mutable std::unordered_map<int,bool> reportLoaded;
92 std::map<int, std::pair<int,int>> arrIndexRange; // mapping report step number to array indeces (start and end)
93 std::vector<std::vector<std::string>> lgr_names; // report step numbers, from SEQNUM array in restart file
94
95 void initUnified();
96 void initSeparate(const int number);
97
98 int get_start_index_lgrname(int number, const std::string& lgr_name);
99
100 int getArrayIndex(const std::string& name, int seqnum, int occurrence);
101 int getArrayIndex(const std::string& name, int number, const std::string& lgr_name);
102
103 std::tuple<int,int> getIndexRange(int reportStepNumber) const;
104
105 std::streampos
106 restartStepWritePosition(const int seqnumValue) const;
107
108};
109
110}} // namespace Opm::EclIO
111
112#endif // OPM_IO_ERST_HPP
#define OPM_THROW(Exception, message)
Definition: ErrorMacros.hpp:52
const char *const const double number
Definition: cJSON.h:262
const char *const name
Definition: cJSON.h:258
int index
Definition: cJSON.h:168
const char *const string
Definition: cJSON.h:170
Definition: ERst.hpp:38
const std::vector< int > & listOfReportStepNumbers() const
Definition: ERst.hpp:81
std::vector< EclEntry > listOfRstArrays(int reportStepNumber, const std::string &lgr_name)
std::vector< EclEntry > listOfRstArrays(int reportStepNumber)
bool hasLGR(const std::string &gridname, int reportStepNumber) const
const std::vector< T > & getRestartData(const std::string &name, int reportStepNumber, int occurrence)
const std::vector< T > & getRestartData(int index, int reportStepNumber)
Definition: ERst.hpp:60
const std::vector< T > & getRestartData(int index, int reportStepNumber, const std::string &lgr_name)
Definition: ERst.hpp:67
ERst(const std::string &filename)
size_t numberOfReportSteps() const
Definition: ERst.hpp:79
void loadReportStepNumber(int number)
const std::vector< T > & getRestartData(const std::string &name, int reportStepNumber, const std::string &lgr_name)
const std::vector< T > & getRestartData(const std::string &name, int reportStepNumber)
Definition: ERst.hpp:48
bool hasReportStepNumber(int number) const
int occurrence_count(const std::string &name, int reportStepNumber) const
Definition: EclFile.hpp:36
File manager for restart output streams.
Definition: OutputStream.hpp:136
Definition: A.hpp:4