61 class EclipseGrid :
public GridDims {
64 explicit EclipseGrid(
const std::string& filename);
70 EclipseGrid(
const EclipseGrid& src,
const std::vector<int>& actnum);
71 EclipseGrid(
const EclipseGrid& src,
const double* zcorn,
const std::vector<int>& actnum);
73 EclipseGrid(
size_t nx,
size_t ny,
size_t nz,
74 double dx = 1.0,
double dy = 1.0,
double dz = 1.0,
76 explicit EclipseGrid(
const GridDims& gd);
78 EclipseGrid(
const std::array<int, 3>& dims ,
79 const std::vector<double>& coord ,
80 const std::vector<double>& zcorn ,
81 const int * actnum =
nullptr);
83 virtual ~EclipseGrid() =
default;
87 explicit EclipseGrid(
const Deck& deck,
const int * actnum =
nullptr);
89 static bool hasGDFILE(
const Deck& deck);
90 static bool hasRadialKeywords(
const Deck& deck);
91 static bool hasSpiderKeywords(
const Deck& deck);
92 static bool hasCylindricalKeywords(
const Deck& deck);
93 static bool hasCornerPointKeywords(
const Deck&);
94 static bool hasCartesianKeywords(
const Deck&);
95 size_t getNumActive( )
const;
96 bool allActive()
const;
98 size_t activeIndex(
size_t i,
size_t j,
size_t k)
const;
99 size_t activeIndex(
size_t globalIndex)
const;
101 size_t getTotalActiveLGR()
const;
102 size_t getActiveIndexLGR(
const std::string& label,
size_t i,
size_t j,
size_t k)
const;
103 size_t getActiveIndexLGR(
const std::string& label,
size_t localIndex)
const;
105 size_t activeIndexLGR(
const std::string& label,
size_t i,
size_t j,
size_t k)
const;
106 size_t activeIndexLGR(
const std::string& label,
size_t localIndex)
const;
108 size_t getActiveIndex(
size_t i,
size_t j,
size_t k)
const {
109 return activeIndex(i, j, k);
111 const std::vector<std::size_t>& get_print_order_lgr ()
const {
112 return m_print_order_lgr_cells;
115 size_t get_lgr_cell_index(
const std::string& lgr_tag)
const {
116 const auto& labels = get_all_lgr_labels();
118 if (labels.empty()) {
119 throw std::runtime_error(
"No LGR labels available.");
122 auto it = std::find(labels.begin(), labels.end(), lgr_tag);
123 if (it == labels.end()) {
124 throw std::runtime_error(
"LGR tag not found: " + lgr_tag);
127 return static_cast<size_t>(std::distance(labels.begin(), it));
130 size_t getActiveIndex(
size_t globalIndex)
const {
131 return activeIndex(globalIndex);
134 std::vector<std::string> get_all_lgr_labels()
const
136 if (this->all_lgr_labels.empty()) {
139 return {this->all_lgr_labels.begin() + 1, this->all_lgr_labels.end()};
143 const std::string& get_lgr_labels_by_number(std::size_t num)
const
145 return all_lgr_labels[num];
148 const std::vector<std::string>& get_all_labels()
const
150 return this->all_lgr_labels;
153 const std::string& get_lgr_tag()
const {
154 return this->lgr_label;
157 std::vector<GridDims> get_lgr_children_gridim()
const;
160 void assertIndexLGR(
size_t localIndex)
const;
162 void assertLabelLGR(
const std::string& label)
const;
164 void save(
const std::string& filename,
bool formatted,
const std::vector<Opm::NNCdata>& nnc,
const Opm::UnitSystem& units)
const;
171 void init_children_host_cells(
bool logical =
true);
172 void init_children_host_cells_logical(
void);
173 void init_children_host_cells_geometrical(
void);
174 std::array<int,3> getCellSubdivisionRatioLGR(
const std::string& lgr_tag,
175 std::array<int,3> acum = {1,1,1})
const;
176 using GridDims::getGlobalIndex;
186 bool isPinchActive()
const;
187 double getPinchThresholdThickness()
const;
188 PinchMode getPinchOption()
const;
189 PinchMode getMultzOption()
const;
190 PinchMode getPinchGapMode()
const;
191 double getPinchMaxEmptyGap()
const;
192 MinpvMode getMinpvMode()
const;
193 const std::vector<double>& getMinpvVector( )
const;
209 std::vector<T> compressedVector(
const std::vector<T>& input_vector)
const {
210 if( input_vector.size() == this->getNumActive() ) {
214 if (input_vector.size() != getCartesianSize())
215 throw std::invalid_argument(
"Input vector must have full size");
218 std::vector<T> compressed_vector( this->getNumActive() );
221 for (
size_t i = 0; i < this->getNumActive(); ++i)
222 compressed_vector[i] = input_vector[ active_map[i] ];
224 return compressed_vector;
236 std::tuple<std::array<double, 3>,std::array<double, 3>,std::array<double, 3>>
238 std::array<double, 3> getCellCenter(
size_t i,
size_t j,
size_t k)
const;
239 std::array<double, 3> getCellCenter(
size_t globalIndex)
const;
240 std::array<double, 3> getCornerPos(
size_t i,
size_t j,
size_t k,
size_t corner_index)
const;
241 const std::vector<double>& activeVolume()
const;
242 double getCellVolume(
size_t globalIndex)
const;
243 double getCellVolume(
size_t i ,
size_t j ,
size_t k)
const;
244 double getCellThickness(
size_t globalIndex)
const;
245 double getCellThickness(
size_t i ,
size_t j ,
size_t k)
const;
246 std::array<double, 3> getCellDims(
size_t i,
size_t j,
size_t k)
const;
247 std::array<double, 3> getCellDims(
size_t globalIndex)
const;
248 bool cellActive(
size_t globalIndex )
const;
249 bool cellActive(
size_t i ,
size_t j,
size_t k )
const;
250 bool cellActiveAfterMINPV(
size_t i ,
size_t j ,
size_t k,
double cell_porv )
const;
251 bool is_lgr()
const {
return lgr_grid;};
252 std::array<double, 3> getCellDimensions(
size_t i,
size_t j,
size_t k)
const {
253 return getCellDims(i, j, k);
258 const std::string& lgr_tag)
const;
259 double getCellDepthLGR(
size_t i,
size_t j,
size_t k,
const std::string& lgr_tag)
const;
262 bool isCellActive(
size_t i,
size_t j,
size_t k)
const {
263 return cellActive(i, j, k);
274 double getCellDepth(
size_t i,
size_t j,
size_t k)
const;
275 double getCellDepth(
size_t globalIndex)
const;
278 const std::vector<double>& getCOORD()
const;
279 const std::vector<double>& getZCORN()
const;
280 const std::vector<int>& getACTNUM( )
const;
282 const std::optional<MapAxes>& getMapAxes()
const;
284 const std::map<size_t, std::array<int,2>>& getAquiferCellTabnums()
const;
294 size_t getZcornFixed() {
return zcorn_fixed; };
299 void resetACTNUM(
const std::vector<int>& actnum);
302 void setMINPVV(
const std::vector<double>& minpvv);
304 bool equal(
const EclipseGrid& other)
const;
305 static bool hasDVDEPTHZKeywords(
const Deck&);
314 static bool hasEqualDVDEPTHZ(
const Deck&);
315 static bool allEqual(
const std::vector<double> &v);
318 const EclipseGridLGR& getLGRCell(
const std::string& lgr_tag)
const;
319 int getLGR_global_father(std::size_t global_index,
const std::string& lgr_tag)
const;
320 int getLGR_father(std::size_t i, std::size_t j, std::size_t k,
const std::string& lgr_tag)
const;
321 int getLGR_father(std::size_t global_index,
const std::string& lgr_tag)
const;
322 std::array<int,3> getLGR_fatherIJK(std::size_t i, std::size_t j, std::size_t k,
const std::string& lgr_tag)
const;
323 std::vector<EclipseGridLGR> lgr_children_cells;
331 virtual void set_lgr_refinement(
const std::string& lgr_tag,
const std::vector<double>& coords,
const std::vector<double>& zcorn);
334 std::size_t lgr_global_counter = 0;
335 std::string lgr_label =
"GLOBAL";
337 int lgr_level_father = 0;
338 std::vector<std::string> lgr_children_labels;
339 std::vector<std::size_t> lgr_active_index;
340 std::vector<std::size_t> lgr_level_active_map;
341 std::vector<std::string> all_lgr_labels;
342 std::map<std::vector<std::size_t>, std::size_t> num_lgr_children_cells;
343 std::vector<double> m_zcorn;
344 std::vector<double> m_coord;
345 std::vector<int> m_actnum;
346 std::vector<std::size_t> m_print_order_lgr_cells;
348 mutable std::optional<std::vector<double>> m_input_zcorn;
349 mutable std::optional<std::vector<double>> m_input_coord;
352 std::vector<double> m_minpvVector;
353 MinpvMode m_minpvMode;
354 std::optional<double> m_pinch;
357 PinchMode m_pinchoutMode;
359 PinchMode m_multzMode;
361 PinchMode m_pinchGapMode;
362 double m_pinchMaxEmptyGap;
363 bool lgr_grid =
false;
364 mutable std::optional<std::vector<double>> active_volume;
366 bool m_circle =
false;
367 size_t zcorn_fixed = 0;
368 bool m_useActnumFromGdfile =
false;
370 std::optional<MapAxes> m_mapaxes;
374 std::vector<int> m_active_to_global;
375 std::vector<int> m_global_to_active;
377 std::unordered_set<size_t> m_aquifer_cells;
379 std::map<size_t, double> m_aquifer_cell_depths;
380 std::map<size_t, std::array<int,2>> m_aquifer_cell_tabnums;
383 std::optional<std::vector<double>> m_thetav;
384 std::optional<std::vector<double>> m_rv;
385 void parseGlobalReferenceToChildren(
void);
386 int initializeLGRObjectIndices(
int);
387 void initializeLGRTreeIndices(
void);
388 void propagateParentIndicesToLGRChildren(
int);
389 void updateNumericalAquiferCells(
const Deck&);
390 double computeCellGeometricDepth(
size_t globalIndex)
const;
393 const std::string& fileName);
394 void resetACTNUM(
const int* actnum);
396 void initBinaryGrid(
const Deck& deck);
398 void initCornerPointGrid(
const std::vector<double>& coord ,
399 const std::vector<double>& zcorn ,
402 bool keywInputBeforeGdfile(
const Deck& deck,
const std::string& keyword)
const;
404 void initCylindricalGrid(
const Deck&);
405 void initSpiderwebGrid(
const Deck&);
406 void initSpiderwebOrCylindricalGrid(
const Deck&,
const bool);
407 void initCartesianGrid(
const Deck&);
408 void initDTOPSGrid(
const Deck&);
409 void initDVDEPTHZGrid(
const Deck&);
410 void initGrid(
const Deck&,
const int* actnum);
411 void initCornerPointGrid(
const Deck&);
412 void assertCornerPointKeywords(
const Deck&);
414 static bool hasDTOPSKeywords(
const Deck&);
415 static void assertVectorSize(
const std::vector<double>& vector,
size_t expectedSize,
const std::string& msg);
417 static std::vector<double> createTOPSVector(
const std::array<int, 3>& dims,
const std::vector<double>& DZ,
const Deck&);
418 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&);
419 static void scatterDim(
const std::array<int, 3>& dims ,
size_t dim ,
const std::vector<double>& DV , std::vector<double>& D);
422 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;
423 std::vector<double> makeZcornDzTops(
const std::vector<double>& dz,
const std::vector<double>& tops)
const ;
424 std::vector<double> makeZcornDzvDepthz(
const std::vector<double>& dzv,
const std::vector<double>& depthz)
const;
425 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;
427 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;
428 void getCellCorners(
const std::size_t globalIndex,
429 std::array<double,8>& X,
430 std::array<double,8>& Y,
431 std::array<double,8>& Z)
const;
436 class EclipseGridLGR :
public EclipseGrid
439 using vec_size_t = std::vector<std::size_t>;
440 EclipseGridLGR() =
default;
441 EclipseGridLGR(
const std::string& self_label,
442 const std::string& father_label_,
446 const vec_size_t& father_lgr_index,
447 const std::array<int, 3>& low_fatherIJK_,
448 const std::array<int, 3>& up_fatherIJK_);
449 const vec_size_t& getFatherGlobalID()
const;
452 void set_lgr_global_counter(std::size_t counter)
454 lgr_global_counter = counter;
456 const vec_size_t& get_father_global()
const
458 return father_global;
460 std::optional<std::reference_wrapper<EclipseGridLGR>>
461 get_child_LGR_cell(
const std::string& lgr_tag)
const;
462 std::vector<int> save_hostnum(
void)
const;
463 int get_hostnum(std::size_t global_index)
const {
return(m_hostnum[global_index]);};
466 std::vector<int> getLGRCell_global_father(
const EclipseGrid& father_grid)
const;
467 std::vector<double> getLGRCell_all_depth (
const EclipseGrid& father_grid)
const;
469 void get_label_child_to_top_father(std::vector<std::reference_wrapper<const std::string>>& list)
const;
470 void get_global_index_child_to_top_father(std::vector<std::size_t> & list,
471 std::size_t i, std::size_t j, std::size_t k)
const;
472 void get_global_index_child_to_top_father(std::vector<std::size_t> & list, std::size_t global_ind)
const;
474 void set_hostnum(
const std::vector<int>&);
475 const std::array<int,3>& get_low_fatherIJK()
const{
476 return low_fatherIJK;
478 const std::string& get_father_label()
const{
482 const std::array<int,3>& get_up_fatherIJK()
const{
495 const std::vector<double>& coord,
496 const std::vector<double>& zcorn)
override;
501 void init_father_global();
502 std::string father_label;
504 vec_size_t father_global;
505 std::array<int, 3> low_fatherIJK {};
506 std::array<int, 3> up_fatherIJK {};
507 std::vector<int> m_hostnum;