EclipseGrid.hpp
Go to the documentation of this file.
1/*
2 Copyright 2014 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
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
21#ifndef OPM_PARSER_ECLIPSE_GRID_HPP
22#define OPM_PARSER_ECLIPSE_GRID_HPP
23
24
30
32
33#include <array>
34#include <memory>
35#include <vector>
36
37namespace Opm {
38
39 class Deck;
40 class ZcornMapper;
41 class NNC;
42
54 class EclipseGrid : public GridDims {
55 public:
56 EclipseGrid() = default;
57 explicit EclipseGrid(const std::string& filename);
58
59 /*
60 These constructors will make a copy of the src grid, with
61 zcorn and or actnum have been adjustments.
62 */
63 EclipseGrid(const EclipseGrid& src) = default;
64 EclipseGrid(const EclipseGrid& src, const std::vector<int>& actnum);
65 EclipseGrid(const EclipseGrid& src, const double* zcorn, const std::vector<int>& actnum);
66
67 EclipseGrid(size_t nx, size_t ny, size_t nz,
68 double dx = 1.0, double dy = 1.0, double dz = 1.0);
69
70 EclipseGrid(std::array<int, 3>& dims ,
71 const std::vector<double>& coord ,
72 const std::vector<double>& zcorn ,
73 const int * actnum = nullptr,
74 const double * mapaxes = nullptr);
75
76
79 EclipseGrid(const Deck& deck, const int * actnum = nullptr);
80
81 static bool hasGDFILE(const Deck& deck);
82 static bool hasCylindricalKeywords(const Deck& deck);
83 static bool hasCornerPointKeywords(const Deck&);
84 static bool hasCartesianKeywords(const Deck&);
85 size_t getNumActive( ) const;
86 bool allActive() const;
87
88 size_t activeIndex(size_t i, size_t j, size_t k) const;
89 size_t activeIndex(size_t globalIndex) const;
90
91 void save(const std::string& filename, bool formatted, const Opm::NNC& nnc, const Opm::UnitSystem& units) const;
92 /*
93 Observe that the there is a getGlobalIndex(i,j,k)
94 implementation in the base class. This method - translating
95 from an active index to a global index must be implemented
96 in the current class.
97 */
98 size_t getGlobalIndex(size_t active_index) const;
99 size_t getGlobalIndex(size_t i, size_t j, size_t k) const;
100
101 /*
102 For RADIAL grids you can *optionally* use the keyword
103 'CIRCLE' to denote that period boundary conditions should be
104 applied in the 'THETA' direction; this will only apply if
105 the theta keywords entered sum up to exactly 360 degrees!
106 */
107
108 bool circle( ) const;
109 bool isPinchActive( ) const;
113
115 const std::vector<double>& getMinpvVector( ) const;
116
117 /*
118 Will return a vector of nactive elements. The method will
119 behave differently depending on the lenght of the
120 input_vector:
121
122 nx*ny*nz: only the values corresponding to active cells
123 are copied out.
124
125 nactive: The input vector is copied straight out again.
126
127 ??? : Exception.
128 */
129
130 template<typename T>
131 std::vector<T> compressedVector(const std::vector<T>& input_vector) const {
132 if( input_vector.size() == this->getNumActive() ) {
133 return input_vector;
134 }
135
136 if (input_vector.size() != getCartesianSize())
137 throw std::invalid_argument("Input vector must have full size");
138
139 {
140 std::vector<T> compressed_vector( this->getNumActive() );
141 const auto& active_map = this->getActiveMap( );
142
143 for (size_t i = 0; i < this->getNumActive(); ++i)
144 compressed_vector[i] = input_vector[ active_map[i] ];
145
146 return compressed_vector;
147 }
148 }
149
150
153 const std::vector<int>& getActiveMap() const;
154 std::array<double, 3> getCellCenter(size_t i,size_t j, size_t k) const;
155 std::array<double, 3> getCellCenter(size_t globalIndex) const;
156 std::array<double, 3> getCornerPos(size_t i,size_t j, size_t k, size_t corner_index) const;
157 std::vector<double> activeVolume() const;
158 double getCellVolume(size_t globalIndex) const;
159 double getCellVolume(size_t i , size_t j , size_t k) const;
160 double getCellThickness(size_t globalIndex) const;
161 double getCellThickness(size_t i , size_t j , size_t k) const;
162 std::array<double, 3> getCellDims(size_t i,size_t j, size_t k) const;
163 std::array<double, 3> getCellDims(size_t globalIndex) const;
164 bool cellActive( size_t globalIndex ) const;
165 bool cellActive( size_t i , size_t j, size_t k ) const;
166 double getCellDepth(size_t i,size_t j, size_t k) const;
167 double getCellDepth(size_t globalIndex) const;
169
170 const std::vector<double>& getCOORD() const;
171 const std::vector<double>& getZCORN() const;
172 const std::vector<int>& getACTNUM( ) const;
173 const std::vector<double>& getMAPAXES() const;
174 const std::string& getMAPUNITS() const { return m_mapunits; } ;
175
176 /*
177 The fixupZCORN method is run as part of constructiong the grid. This will adjust the
178 z-coordinates to ensure that cells do not overlap. The return value is the number of
179 points which have been adjusted. The number of zcorn nodes that has ben fixed is
180 stored in private member zcorn_fixed.
181 */
182
183 size_t fixupZCORN();
184 size_t getZcornFixed() { return zcorn_fixed; };
185
186 // resetACTNUM with no arguments will make all cells in the grid active.
187
189 void resetACTNUM( const std::vector<int>& actnum);
190
191 bool equal(const EclipseGrid& other) const;
192
193 private:
194 std::vector<double> m_minpvVector;
195 MinpvMode::ModeEnum m_minpvMode;
196 Value<double> m_pinch;
197 PinchMode::ModeEnum m_pinchoutMode;
198 PinchMode::ModeEnum m_multzMode;
199
200 bool m_circle = false;
201
202 size_t zcorn_fixed = 0;
203 bool m_useActnumFromGdfile = false;
204
205 // Input grid data.
206 std::vector<double> m_zcorn;
207 std::vector<double> m_coord;
208 std::vector<double> m_mapaxes;
209 std::vector<int> m_actnum;
210 std::string m_mapunits;
211
212 // Mapping to/from active cells.
213 int m_nactive;
214 std::vector<int> m_active_to_global;
215 std::vector<int> m_global_to_active;
216
217 void initGridFromEGridFile(Opm::EclIO::EclFile& egridfile, std::string fileName);
218 void resetACTNUM( const int* actnum);
219
220 void initBinaryGrid(const Deck& deck);
221
222 void initCornerPointGrid(const std::vector<double>& coord ,
223 const std::vector<double>& zcorn ,
224 const int * actnum,
225 const double * mapaxes);
226
227 bool keywInputBeforeGdfile(const Deck& deck, const std::string keyword) const;
228
229 void initCylindricalGrid(const Deck&);
230 void initCartesianGrid(const Deck&);
231 void initDTOPSGrid(const Deck&);
232 void initDVDEPTHZGrid(const Deck&);
233 void initGrid(const Deck&);
234 void initCornerPointGrid(const Deck&);
235 void assertCornerPointKeywords(const Deck&);
236
237 static bool hasDVDEPTHZKeywords(const Deck&);
238 static bool hasDTOPSKeywords(const Deck&);
239 static void assertVectorSize(const std::vector<double>& vector, size_t expectedSize, const std::string& msg);
240
241 static std::vector<double> createTOPSVector(const std::array<int, 3>& dims, const std::vector<double>& DZ, const Deck&);
242 static std::vector<double> createDVector(const std::array<int, 3>& dims, std::size_t dim, const std::string& DKey, const std::string& DVKey, const Deck&);
243 static void scatterDim(const std::array<int, 3>& dims , size_t dim , const std::vector<double>& DV , std::vector<double>& D);
244
245
246 std::vector<double> makeCoordDxDyDzTops(const std::vector<double>& dx, const std::vector<double>& dy, const std::vector<double>& dz, const std::vector<double>& tops) const;
247 std::vector<double> makeZcornDzTops(const std::vector<double>& dz, const std::vector<double>& tops) const ;
248 std::vector<double> makeZcornDzvDepthz(const std::vector<double>& dzv, const std::vector<double>& depthz) const;
249 std::vector<double> makeCoordDxvDyvDzvDepthz(const std::vector<double>& dxv, const std::vector<double>& dyv, const std::vector<double>& dzv, const std::vector<double>& depthz) const;
250
251 void getCellCorners(const std::array<int, 3>& ijk, const std::array<int, 3>& dims, std::array<double,8>& X, std::array<double,8>& Y, std::array<double,8>& Z) const;
252 void getCellCorners(const std::size_t globalIndex,
253 std::array<double,8>& X,
254 std::array<double,8>& Y,
255 std::array<double,8>& Z) const;
256
257 };
258
260 public:
261 CoordMapper(size_t nx, size_t ny);
262 size_t size() const;
263
264
265 /*
266 dim = 0,1,2 for x, y and z coordinate respectively.
267 layer = 0,1 for k=0 and k=nz layers respectively.
268 */
269
270 size_t index(size_t i, size_t j, size_t dim, size_t layer) const;
271 private:
272 size_t nx;
273 size_t ny;
274 };
275
276
277
279 public:
280 ZcornMapper(size_t nx, size_t ny, size_t nz);
281 size_t index(size_t i, size_t j, size_t k, int c) const;
282 size_t index(size_t g, int c) const;
283 size_t size() const;
284
285 /*
286 The fixupZCORN method will take a zcorn vector as input and
287 run through it. If the following situation is detected:
288
289 /| /|
290 / | / |
291 / | / |
292 / | / |
293 / | ==> / |
294 / | / |
295 ---/------x /---------x
296 | /
297 |/
298
299 */
300 size_t fixupZCORN( std::vector<double>& zcorn);
301 bool validZCORN( const std::vector<double>& zcorn) const;
302 private:
303 std::array<size_t,3> dims;
304 std::array<size_t,3> stride;
305 std::array<size_t,8> cell_shift;
306 };
307}
308
309
310
311
312#endif // OPM_PARSER_ECLIPSE_GRID_HPP
const char *const string
Definition: cJSON.h:170
Definition: EclipseGrid.hpp:259
size_t index(size_t i, size_t j, size_t dim, size_t layer) const
CoordMapper(size_t nx, size_t ny)
size_t size() const
Definition: Deck.hpp:115
Definition: EclFile.hpp:36
Definition: EclipseGrid.hpp:54
const std::vector< double > & getZCORN() const
std::vector< T > compressedVector(const std::vector< T > &input_vector) const
Definition: EclipseGrid.hpp:131
double getCellThickness(size_t i, size_t j, size_t k) const
double getCellVolume(size_t globalIndex) const
std::array< double, 3 > getCellCenter(size_t i, size_t j, size_t k) const
size_t getZcornFixed()
Definition: EclipseGrid.hpp:184
size_t fixupZCORN()
size_t activeIndex(size_t globalIndex) const
double getCellVolume(size_t i, size_t j, size_t k) const
EclipseGrid(const std::string &filename)
PinchMode::ModeEnum getMultzOption() const
const std::string & getMAPUNITS() const
Definition: EclipseGrid.hpp:174
static bool hasCylindricalKeywords(const Deck &deck)
bool equal(const EclipseGrid &other) const
const std::vector< double > & getMinpvVector() const
EclipseGrid(const EclipseGrid &src, const double *zcorn, const std::vector< int > &actnum)
size_t activeIndex(size_t i, size_t j, size_t k) const
size_t getGlobalIndex(size_t active_index) const
double getPinchThresholdThickness() const
EclipseGrid(const EclipseGrid &src)=default
std::vector< double > activeVolume() const
double getCellThickness(size_t globalIndex) const
void resetACTNUM(const std::vector< int > &actnum)
PinchMode::ModeEnum getPinchOption() const
EclipseGrid(const Deck &deck, const int *actnum=nullptr)
std::array< double, 3 > getCornerPos(size_t i, size_t j, size_t k, size_t corner_index) const
double getCellDepth(size_t globalIndex) const
const std::vector< double > & getMAPAXES() const
const std::vector< int > & getActiveMap() const
EclipseGrid(std::array< int, 3 > &dims, const std::vector< double > &coord, const std::vector< double > &zcorn, const int *actnum=nullptr, const double *mapaxes=nullptr)
bool allActive() const
static bool hasCartesianKeywords(const Deck &)
const std::vector< int > & getACTNUM() const
EclipseGrid(const EclipseGrid &src, const std::vector< int > &actnum)
std::array< double, 3 > getCellDims(size_t i, size_t j, size_t k) const
EclipseGrid()=default
EclipseGrid(size_t nx, size_t ny, size_t nz, double dx=1.0, double dy=1.0, double dz=1.0)
const std::vector< double > & getCOORD() const
MinpvMode::ModeEnum getMinpvMode() const
ZcornMapper zcornMapper() const
bool isPinchActive() const
static bool hasCornerPointKeywords(const Deck &)
bool circle() const
bool cellActive(size_t i, size_t j, size_t k) const
std::array< double, 3 > getCellCenter(size_t globalIndex) const
size_t getNumActive() const
std::array< double, 3 > getCellDims(size_t globalIndex) const
void save(const std::string &filename, bool formatted, const Opm::NNC &nnc, const Opm::UnitSystem &units) const
bool cellActive(size_t globalIndex) const
size_t getGlobalIndex(size_t i, size_t j, size_t k) const
static bool hasGDFILE(const Deck &deck)
double getCellDepth(size_t i, size_t j, size_t k) const
Definition: GridDims.hpp:32
size_t getCartesianSize() const
Definition: NNC.hpp:61
Definition: UnitSystem.hpp:32
Definition: EclipseGrid.hpp:278
size_t index(size_t i, size_t j, size_t k, int c) const
ZcornMapper(size_t nx, size_t ny, size_t nz)
size_t index(size_t g, int c) const
bool validZCORN(const std::vector< double > &zcorn) const
size_t size() const
size_t fixupZCORN(std::vector< double > &zcorn)
@ NNC
Definition: MULTREGTScanner.hpp:40
ModeEnum
Definition: MinpvMode.hpp:28
ModeEnum
Definition: PinchMode.hpp:28
UDAKeyword keyword(UDAControl control)
Definition: A.hpp:4