62 class EclipseGrid :
public GridDims {
65 explicit EclipseGrid(
const std::string& filename);
71 EclipseGrid(
const EclipseGrid& src,
const std::vector<int>& actnum);
72 EclipseGrid(
const EclipseGrid& src,
const double* zcorn,
const std::vector<int>& actnum);
74 EclipseGrid(
size_t nx,
size_t ny,
size_t nz,
75 double dx = 1.0,
double dy = 1.0,
double dz = 1.0,
77 explicit EclipseGrid(
const GridDims& gd);
79 EclipseGrid(
const std::array<int, 3>& dims ,
80 const std::vector<double>& coord ,
81 const std::vector<double>& zcorn ,
82 const int * actnum =
nullptr);
84 virtual ~EclipseGrid() =
default;
88 explicit EclipseGrid(
const Deck& deck,
const int * actnum =
nullptr);
90 static bool hasGDFILE(
const Deck& deck);
91 static bool hasRadialKeywords(
const Deck& deck);
92 static bool hasSpiderKeywords(
const Deck& deck);
93 static bool hasCylindricalKeywords(
const Deck& deck);
94 static bool hasCornerPointKeywords(
const Deck&);
95 static bool hasCartesianKeywords(
const Deck&);
96 size_t getNumActive( )
const;
97 bool allActive()
const;
99 size_t activeIndex(
size_t i,
size_t j,
size_t k)
const;
100 size_t activeIndex(
size_t globalIndex)
const;
102 size_t getTotalActiveLGR()
const;
103 size_t getActiveIndexLGR(
const std::string& label,
size_t i,
size_t j,
size_t k)
const;
104 size_t getActiveIndexLGR(
const std::string& label,
size_t localIndex)
const;
106 size_t activeIndexLGR(
const std::string& label,
size_t i,
size_t j,
size_t k)
const;
107 size_t activeIndexLGR(
const std::string& label,
size_t localIndex)
const;
109 size_t getActiveIndex(
size_t i,
size_t j,
size_t k)
const {
110 return activeIndex(i, j, k);
112 const std::vector<std::size_t>& get_print_order_lgr ()
const {
113 return m_print_order_lgr_cells;
116 std::size_t get_lgr_cell_index(
const std::string& lgr_tag)
const
118 const auto& labels = get_all_lgr_labels();
120 if (labels.empty()) {
121 throw std::runtime_error(
"No LGR labels available.");
124 const auto it = std::ranges::find(labels, lgr_tag);
125 if (it == labels.end()) {
126 throw std::runtime_error(
"LGR tag not found: " + lgr_tag);
129 return static_cast<size_t>(std::distance(labels.begin(), it));
132 size_t getActiveIndex(
size_t globalIndex)
const {
133 return activeIndex(globalIndex);
136 std::vector<std::string> get_all_lgr_labels()
const
138 if (this->all_lgr_labels.empty()) {
141 return {this->all_lgr_labels.begin() + 1, this->all_lgr_labels.end()};
145 const std::string& get_lgr_labels_by_number(std::size_t num)
const
147 return all_lgr_labels[num];
150 const std::vector<std::string>& get_all_labels()
const
152 return this->all_lgr_labels;
155 const std::string& get_lgr_tag()
const {
156 return this->lgr_label;
159 std::vector<GridDims> get_lgr_children_gridim()
const;
162 void assertIndexLGR(
size_t localIndex)
const;
164 void assertLabelLGR(
const std::string& label)
const;
166 void save(
const std::string& filename,
bool formatted,
const std::vector<Opm::NNCdata>& nnc,
const Opm::UnitSystem& units)
const;
175 void init_children_host_cells(
bool logical =
true);
176 void init_children_host_cells_logical(
void);
177 void init_children_host_cells_geometrical(
void);
178 std::array<int,3> getCellSubdivisionRatioLGR(
const std::string& lgr_tag,
179 std::array<int,3> acum = {1,1,1})
const;
181 void perform_refinement();
183 using GridDims::getGlobalIndex;
193 bool isPinchActive()
const;
194 double getPinchThresholdThickness()
const;
195 PinchMode getPinchOption()
const;
196 PinchMode getMultzOption()
const;
197 PinchMode getPinchGapMode()
const;
198 double getPinchMaxEmptyGap()
const;
199 MinpvMode getMinpvMode()
const;
200 const std::vector<double>& getMinpvVector( )
const;
216 std::vector<T> compressedVector(
const std::vector<T>& input_vector)
const {
217 if( input_vector.size() == this->getNumActive() ) {
221 if (input_vector.size() != getCartesianSize())
222 throw std::invalid_argument(
"Input vector must have full size");
225 std::vector<T> compressed_vector( this->getNumActive() );
228 for (
size_t i = 0; i < this->getNumActive(); ++i)
229 compressed_vector[i] = input_vector[ active_map[i] ];
231 return compressed_vector;
243 std::tuple<std::array<double, 3>,std::array<double, 3>,std::array<double, 3>>
245 std::array<double, 3> getCellCenter(
size_t i,
size_t j,
size_t k)
const;
246 std::array<double, 3> getCellCenter(
size_t globalIndex)
const;
247 std::array<double, 3> getCornerPos(
size_t i,
size_t j,
size_t k,
size_t corner_index)
const;
248 const std::vector<double>& activeVolume()
const;
249 double getCellVolume(
size_t globalIndex)
const;
250 double getCellVolume(
size_t i ,
size_t j ,
size_t k)
const;
251 double getCellThickness(
size_t globalIndex)
const;
252 double getCellThickness(
size_t i ,
size_t j ,
size_t k)
const;
253 std::array<double, 3> getCellDims(
size_t i,
size_t j,
size_t k)
const;
254 std::array<double, 3> getCellDims(
size_t globalIndex)
const;
255 bool cellActive(
size_t globalIndex )
const;
256 bool cellActive(
size_t i ,
size_t j,
size_t k )
const;
257 bool cellActiveAfterMINPV(
size_t i ,
size_t j ,
size_t k,
double cell_porv )
const;
258 bool is_lgr()
const {
return lgr_grid;};
259 std::array<double, 3> getCellDimensions(
size_t i,
size_t j,
size_t k)
const {
260 return getCellDims(i, j, k);
264 bool isCellActive(
size_t i,
size_t j,
size_t k)
const {
265 return cellActive(i, j, k);
276 double getCellDepth(
size_t i,
size_t j,
size_t k)
const;
277 double getCellDepth(
size_t globalIndex)
const;
280 const std::vector<double>& getCOORD()
const;
281 const std::vector<double>& getZCORN()
const;
282 const std::vector<int>& getACTNUM( )
const;
284 const std::optional<MapAxes>& getMapAxes()
const;
286 const std::map<size_t, std::array<int,2>>& getAquiferCellTabnums()
const;
296 size_t getZcornFixed() {
return zcorn_fixed; };
301 void resetACTNUM(
const std::vector<int>& actnum);
304 void setMINPVV(
const std::vector<double>& minpvv);
306 bool equal(
const EclipseGrid& other)
const;
307 static bool hasDVDEPTHZKeywords(
const Deck&);
316 static bool hasEqualDVDEPTHZ(
const Deck&);
317 static bool allEqual(
const std::vector<double> &v);
320 const EclipseGridLGR& getLGRCell(
const std::string& lgr_tag)
const;
321 int getLGR_global_father(std::size_t global_index,
const std::string& lgr_tag)
const;
322 int getLGR_father(std::size_t i, std::size_t j, std::size_t k,
const std::string& lgr_tag)
const;
323 int getLGR_father(std::size_t global_index,
const std::string& lgr_tag)
const;
324 std::array<int,3> getLGR_fatherIJK(std::size_t i, std::size_t j, std::size_t k,
const std::string& lgr_tag)
const;
325 std::vector<EclipseGridLGR> lgr_children_cells;
333 virtual void set_lgr_refinement(
const std::string& lgr_tag,
const std::vector<double>& coords,
const std::vector<double>& zcorn);
336 std::size_t lgr_global_counter = 0;
337 std::string lgr_label =
"GLOBAL";
339 int lgr_level_father = 0;
340 std::vector<std::string> lgr_children_labels;
341 std::vector<std::size_t> lgr_active_index;
342 std::vector<std::size_t> lgr_level_active_map;
343 std::vector<std::string> all_lgr_labels;
344 std::map<std::vector<std::size_t>, std::size_t> num_lgr_children_cells;
345 std::vector<double> m_zcorn;
346 std::vector<double> m_coord;
347 std::vector<int> m_actnum;
348 std::vector<std::size_t> m_print_order_lgr_cells;
350 mutable std::optional<std::vector<double>> m_input_zcorn;
351 mutable std::optional<std::vector<double>> m_input_coord;
356 std::vector<double> m_minpvVector;
357 MinpvMode m_minpvMode;
358 std::optional<double> m_pinch;
361 PinchMode m_pinchoutMode;
363 PinchMode m_multzMode;
365 PinchMode m_pinchGapMode;
366 double m_pinchMaxEmptyGap;
367 bool lgr_grid =
false;
368 mutable std::optional<std::vector<double>> active_volume;
370 bool m_circle =
false;
371 size_t zcorn_fixed = 0;
372 bool m_useActnumFromGdfile =
false;
374 std::optional<MapAxes> m_mapaxes;
378 std::vector<int> m_active_to_global;
379 std::vector<int> m_global_to_active;
381 std::unordered_set<size_t> m_aquifer_cells;
383 std::map<size_t, double> m_aquifer_cell_depths;
384 std::map<size_t, std::array<int,2>> m_aquifer_cell_tabnums;
387 std::optional<std::vector<double>> m_thetav;
388 std::optional<std::vector<double>> m_rv;
389 void parseGlobalReferenceToChildren(
void);
390 int initializeLGRObjectIndices(
int);
391 void initializeLGRTreeIndices(
void);
392 void propagateParentIndicesToLGRChildren(
int);
393 void updateNumericalAquiferCells(
const Deck&);
394 double computeCellGeometricDepth(
size_t globalIndex)
const;
397 const std::string& fileName);
398 void resetACTNUM(
const int* actnum);
400 void initBinaryGrid(
const Deck& deck);
402 void initCornerPointGrid(
const std::vector<double>& coord ,
403 const std::vector<double>& zcorn ,
406 bool keywInputBeforeGdfile(
const Deck& deck,
const std::string& keyword)
const;
408 void initCylindricalGrid(
const Deck&);
409 void initSpiderwebGrid(
const Deck&);
410 void initSpiderwebOrCylindricalGrid(
const Deck&,
const bool);
411 void initCartesianGrid(
const Deck&);
412 void initDTOPSGrid(
const Deck&);
413 void initDVDEPTHZGrid(
const Deck&);
414 void initGrid(
const Deck&,
const int* actnum);
415 void initCornerPointGrid(
const Deck&);
416 void assertCornerPointKeywords(
const Deck&);
418 static bool hasDTOPSKeywords(
const Deck&);
419 static void assertVectorSize(
const std::vector<double>& vector,
size_t expectedSize,
const std::string& msg);
421 static std::vector<double> createTOPSVector(
const std::array<int, 3>& dims,
const std::vector<double>& DZ,
const Deck&);
422 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&);
423 static void scatterDim(
const std::array<int, 3>& dims ,
size_t dim ,
const std::vector<double>& DV , std::vector<double>& D);
426 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;
427 std::vector<double> makeZcornDzTops(
const std::vector<double>& dz,
const std::vector<double>& tops)
const ;
428 std::vector<double> makeZcornDzvDepthz(
const std::vector<double>& dzv,
const std::vector<double>& depthz)
const;
429 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;
431 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;
432 void getCellCorners(
const std::size_t globalIndex,
433 std::array<double,8>& X,
434 std::array<double,8>& Y,
435 std::array<double,8>& Z)
const;
440 void save_nnc_same_grid(
Opm::EclIO::EclOutput& egridfile,
const std::vector<Opm::NNCdata>& nnc, std::size_t grid_num = 0)
const;
441 void save_nnc_local_global(
Opm::EclIO::EclOutput& egridfile,
const std::vector<Opm::NNCdata>& nnc, std::size_t grid_num, std::size_t num_nnc)
const;
442 void save_nna(
Opm::EclIO::EclOutput& egridfile,
const std::vector<Opm::NNCdata>& nnc, std::size_t grid1, std::size_t grid2)
const;
448 class EclipseGridLGR :
public EclipseGrid
451 using vec_size_t = std::vector<std::size_t>;
452 EclipseGridLGR() =
default;
453 EclipseGridLGR(
const std::string& self_label,
454 const std::string& father_label_,
458 const vec_size_t& father_lgr_index,
459 const std::array<int, 3>& low_fatherIJK_,
460 const std::array<int, 3>& up_fatherIJK_);
461 const vec_size_t& getFatherGlobalID()
const;
465 void set_lgr_global_counter(std::size_t counter)
467 lgr_global_counter = counter;
469 const vec_size_t& get_father_global()
const
471 return father_global;
473 std::optional<std::reference_wrapper<EclipseGridLGR>>
474 get_child_LGR_cell(
const std::string& lgr_tag)
const;
475 std::vector<int> save_hostnum(
void)
const;
476 int get_hostnum(std::size_t global_index)
const {
return(m_hostnum[global_index]);};
479 std::vector<int> getLGRCell_global_father(
const EclipseGrid& father_grid)
const;
480 std::vector<double> getLGRCell_all_depth (
const EclipseGrid& father_grid)
const;
482 void get_label_child_to_top_father(std::vector<std::reference_wrapper<const std::string>>& list)
const;
483 void get_global_index_child_to_top_father(std::vector<std::size_t> & list,
484 std::size_t i, std::size_t j, std::size_t k)
const;
485 void get_global_index_child_to_top_father(std::vector<std::size_t> & list, std::size_t global_ind)
const;
487 void set_hostnum(
const std::vector<int>&);
488 const std::array<int,3>& get_low_fatherIJK()
const{
489 return low_fatherIJK;
491 const std::string& get_father_label()
const{
495 const std::array<int,3>& get_up_fatherIJK()
const{
508 const std::vector<double>& coord,
509 const std::vector<double>& zcorn)
override;
512 void perform_refinement(
const std::vector<double>& coord,
513 const std::vector<double>& zcorn,
514 const std::array<int,3>& parent_nxyz);
518 void init_father_global();
521 std::string father_label;
523 vec_size_t father_global;
524 std::array<int, 3> low_fatherIJK {};
525 std::array<int, 3> up_fatherIJK {};
526 std::vector<int> m_hostnum;
528 std::vector<double> generate_refined_coord(
const std::vector<double>& ,
529 const std::array<int,3>&);
531 std::vector<double> generate_refined_zcorn(
const std::vector<double>& zcorn_h,
532 const std::array<int,3>& parent_nxyz);