From 4b8d06eaf3759712f4b9a36f92075518b25f1001 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Tue, 19 Nov 2024 09:11:19 +0000 Subject: [PATCH 01/60] rebased code --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 96d3c2a36d6..a2be2e26319 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -160,7 +160,11 @@ EclipseGrid::EclipseGrid(const GridDims& gd) } +<<<<<<< HEAD EclipseGrid::EclipseGrid(std::size_t nx, std::size_t ny , std::size_t nz, +======= +EclipseGrid::EclipseGrid(size_t nx, std::size_t ny , std::size_t nz, +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) double dx, double dy, double dz, double top) : GridDims(nx, ny, nz), m_minpvMode(MinpvMode::Inactive), @@ -556,12 +560,20 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) } +<<<<<<< HEAD std::size_t EclipseGrid::activeIndex(std::size_t i, std::size_t j, std::size_t k) const { +======= + std::size_t EclipseGrid::activeIndex(size_t i, std::size_t j, std::size_t k) const { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) return activeIndex( getGlobalIndex( i,j,k )); } +<<<<<<< HEAD std::size_t EclipseGrid::activeIndex(std::size_t globalIndex) const { +======= + std::size_t EclipseGrid::activeIndex(size_t globalIndex) const { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) if (m_global_to_active.empty()) { return globalIndex; } @@ -578,7 +590,11 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) [0,num_active). */ +<<<<<<< HEAD std::size_t EclipseGrid::getGlobalIndex(std::size_t active_index) const { +======= + std::size_t EclipseGrid::getGlobalIndex(size_t active_index) const { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) return m_active_to_global.at(active_index); } @@ -1405,7 +1421,11 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) std::size_t initialTOPSize = TOPS.size(); TOPS.resize( volume ); +<<<<<<< HEAD for (std::size_t targetIndex = area; targetIndex < volume; targetIndex++) { +======= + for (size_t targetIndex = area; targetIndex < volume; targetIndex++) { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) std::size_t sourceIndex = targetIndex - area; double nextValue = TOPS[sourceIndex] + DZ[sourceIndex]; @@ -1442,7 +1462,11 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st */ std::size_t initialDSize = D.size(); D.resize( volume ); +<<<<<<< HEAD for (std::size_t targetIndex = initialDSize; targetIndex < volume; targetIndex++) { +======= + for (size_t targetIndex = initialDSize; targetIndex < volume; targetIndex++) { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) std::size_t sourceIndex = targetIndex - area; D[targetIndex] = D[sourceIndex]; } @@ -2093,7 +2117,11 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st for (std::size_t index = 0; index < lgr_input.size(); index++) { const auto lgr_cell = lgr_input.getLgr(index); +<<<<<<< HEAD if (this->lgr_label == lgr_cell.PARENT_NAME()) { +======= + if (this->lgr_label.compare(lgr_cell.PARENT_NAME()) == 0) { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) lgr_grid = true; // auto [i_list, j_list, k_list] = lgr_cell.parent_cellsIJK(); auto [i_list, j_list, k_list] = parent_cellsIJK(lgr_cell); @@ -2244,12 +2272,15 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } } +<<<<<<< HEAD const std::optional& EclipseGrid::getMapAxes() const { return this->m_mapaxes; } +======= +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) ZcornMapper::ZcornMapper(std::size_t nx , std::size_t ny, std::size_t nz) : dims( {{nx,ny,nz}} ), stride( {{2 , 4*nx, 8*nx*ny}} ), @@ -2276,7 +2307,11 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return dims[0] * dims[1] * dims[2] * 8; } +<<<<<<< HEAD std::size_t ZcornMapper::index(std::size_t g, int c) const { +======= + std::size_t ZcornMapper::index(size_t g, int c) const { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) int k = g / (dims[0] * dims[1]); g -= k * dims[0] * dims[1]; From 264efa5ee77155b91d65cb26a09e5f8d637a3d53 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Wed, 23 Oct 2024 15:42:51 +0000 Subject: [PATCH 02/60] rebased code -set up LgrOutput as a Test environment for the developtment of the save method for the LGR EclipseGrid - EclipseGrid object and children are initialized from .EGRID file generated on standard simulator --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 5 + .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 8 +- opm/io/eclipse/EGrid.hpp | 7 + tests/parser/LgrOutputTests.cpp | 365 +++++++++++++++++- 4 files changed, 378 insertions(+), 7 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index a2be2e26319..30eea594708 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -2423,6 +2423,11 @@ namespace Opm { lgr_label= self_label; lgr_level = father_lgr_level + 1 ; } + void EclipseGridLGR::set_lgr_refinement(std::vector coord, std::vector zcorn) + { + m_coord = coord; + m_zcorn = zcorn; + } void EclipseGridLGR::init_father_global() { std::sort(father_global.begin(),father_global.end()); diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 168ee3d3f83..51b56873623 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -266,6 +266,9 @@ namespace Opm { std::vector lgr_level_active_map; std::vector all_lgr_labels; std::map, std::size_t> num_lgr_children_cells; + std::vector m_zcorn; + std::vector m_coord; + private: std::vector m_minpvVector; @@ -290,8 +293,6 @@ namespace Opm { mutable std::optional> m_input_zcorn; mutable std::optional> m_input_coord; - std::vector m_zcorn; - std::vector m_coord; std::vector m_actnum; @@ -373,7 +374,8 @@ namespace Opm { } const vec_size_t& get_father_global() const{ return father_global; - } + } + void set_lgr_refinement(std::vector,std::vector); private: void init_father_global(); std::string father_label; diff --git a/opm/io/eclipse/EGrid.hpp b/opm/io/eclipse/EGrid.hpp index 693237e9129..a30621eae45 100644 --- a/opm/io/eclipse/EGrid.hpp +++ b/opm/io/eclipse/EGrid.hpp @@ -67,6 +67,13 @@ class EGrid : public EclFile const std::vector& get_mapaxes() const { return m_mapaxes; } const std::string& get_mapunits() const { return m_mapunits; } + + const std::vector& get_coord() const { return coord_array; } + const std::vector& get_zcorn() const { return zcorn_array; } + + + + private: std::filesystem::path inputFileName, initFileName; std::string m_grid_name; diff --git a/tests/parser/LgrOutputTests.cpp b/tests/parser/LgrOutputTests.cpp index c41f7c1b07b..fc70abafda7 100644 --- a/tests/parser/LgrOutputTests.cpp +++ b/tests/parser/LgrOutputTests.cpp @@ -13,6 +13,7 @@ along with OPM. If not, see . */ +#include #define BOOST_TEST_MODULE LgrOutputTests #include @@ -21,15 +22,371 @@ #include #include #include +#include #include #include -#include #include - #include using namespace Opm; +LgrCollection read_lgr(const std::string& deck_string, std::size_t nx, std::size_t ny, std::size_t nz){ + Opm::Parser parser; + Opm::EclipseGrid eclipse_grid(GridDims(nx,ny,nz)); + Opm::Deck deck = parser.parseString(deck_string); + const Opm::GRIDSection gridSection ( deck ); + return LgrCollection(gridSection, eclipse_grid); +} + +std::pair, std::vector> read_cpg_from_egrid(const std::string& file_path, const std::string& lgr_label){ + Opm::EclIO::EGrid egrid_global(file_path, lgr_label); + egrid_global.load_grid_data(); + auto global_coord = egrid_global.get_coord(); + auto global_zcorn = egrid_global.get_zcorn(); + std::vector coord_g(global_coord.begin(), global_coord.end()); + std::vector zcorn_g(global_zcorn.begin(), global_zcorn.end()); + return std::make_pair(coord_g, zcorn_g); +} + + BOOST_AUTO_TEST_CASE(TestLgrOutput) { - // Placeholder test for a functionality that will be released in upcoming PRs. - } + const std::string deck_string = R"( +RUNSPEC + +DIMENS + 3 3 1 / + +GRID + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +'LGR1' 2 2 2 2 1 1 3 3 / +ENDFIN + +DX + 9*1000 / +DY + 9*1000 / +DZ + 9*20 / + +TOPS + 9*8325 / + +PORO + 9*0.15 / + +PERMX + 9*1 / + +COPY + PERMX PERMZ / + PERMX PERMY / +/ + +EDIT + +OIL +GAS + +TITLE +Opm-the-best-open-source-simulator + +START +16 JUN 1988 / + +PROPS + +REGIONS + +SOLUTION + +SCHEDULE +)"; +\ + std::array global_grid_dim = {3,3,1}; + LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); + auto [coord_g, zcorn_g] = read_cpg_from_egrid("CARFIN5.EGRID", "global"); + Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); + eclipse_grid_file.init_lgr_cells(lgr_col); + auto [coord_l, zcorn_l] = read_cpg_from_egrid("CARFIN5.EGRID", "LGR1"); + eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l,zcorn_l); + + auto index = 1; + + + // Opm::EclipseGrid eclipse_grid = state.getInputGrid(); + + + + // Opm::EclIO::EGrid egrid_global("CARFIN5.EGRID"); + // egrid_global.load_grid_data(); + // auto global_coord = egrid_global.get_coord(); + // auto global_zcorn = egrid_global.get_zcorn(); + + // std::vector coord_g(global_coord.begin(), global_coord.end()); + // std::vector zcorn_g(global_zcorn.begin(), global_zcorn.end()); + // std::array dims = {3,3, 1}; + + // Opm::EclipseGrid eclipse_grid_file(dims, coord_g, zcorn_g); + + + + + // Opm::EclIO::EGrid egrid_lgr1("CARFIN5.EGRID","LGR1"); + // egrid_lgr1.load_grid_data(); + // BOOST_CHECK_EQUAL( eclipse_grid.getTotalActiveLGR() , 21U ); + // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 8U ); + // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[1].getTotalActiveLGR() , 8U ); + + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0,0,0), 0U); + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",1,3,0), 7U); + + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",1,0,0), 8U); + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",1,1,0), 17U); + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",2,2,0), 20U); + + + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",0,0,0), 9U); + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",1,3,0), 16U); + } + + + + + +BOOST_AUTO_TEST_CASE(TestLgrNested) { + const std::string deck_string = R"( +RUNSPEC + +DIMENS + 3 3 1 / + +GRID + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +LGR1 2 2 2 2 1 1 3 3 1 1* GLOBAL/ +ENDFIN + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +LGR2 2 2 2 2 1 1 3 3 1 1* LGR1/ +ENDFIN + + +DX + 9*1000 / +DY + 9*1000 / +DZ + 9*20 / + +TOPS + 9*8325 / + +PORO + 9*0.15 / + +PERMX + 9*1 / + +COPY + PERMX PERMZ / + PERMX PERMY / +/ + +EDIT + +OIL +GAS + +TITLE +The title + +START +16 JUN 1988 / + +PROPS + +REGIONS + +SOLUTION + +SCHEDULE +)"; +\ + Opm::Parser parser; + Opm::Deck deck = parser.parseString(deck_string); + Opm::EclipseState state(deck); + Opm::EclipseGrid eclipse_grid = state.getInputGrid(); + + BOOST_CHECK_EQUAL( eclipse_grid.getTotalActiveLGR() , 25U ); + BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 17U ); + BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].lgr_children_cells[0].getTotalActiveLGR() , 9U ); + + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0,0,0), 0U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",2,2,0), 24U); + + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0,0,0), 4U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",2,2,0), 20U); + + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",0,0,0), 8U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",2,2,0), 16U); + + BOOST_CHECK_THROW(eclipse_grid.getActiveIndexLGR("GLOBAL",1,1,0), std::invalid_argument); + BOOST_CHECK_THROW(eclipse_grid.getActiveIndexLGR("LGR1",1,1,0), std::invalid_argument); + BOOST_CHECK_THROW(eclipse_grid.getActiveIndexLGR("LGR3",1,1,0), std::invalid_argument); +} +BOOST_AUTO_TEST_CASE(TestGLOBALinactivecells) { + const std::string deck_string = R"( +RUNSPEC + +DIMENS + 3 3 1 / + +GRID + +ACTNUM +1 0 1 +1 1 1 +1 1 1 +/ + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +'LGR1' 2 2 2 2 1 1 3 3 1/ +ENDFIN + + +DX + 9*1000 / +DY + 9*1000 / +DZ + 9*20 / + +TOPS + 9*8325 / + +PORO + 9*0.15 / + +PERMX + 9*1 / + +COPY + PERMX PERMZ / + PERMX PERMY / +/ + +EDIT + +OIL +GAS + +TITLE +The title + +START +16 JUN 1988 / + +PROPS + +REGIONS + +SOLUTION + +SCHEDULE +)"; +\ + Opm::Parser parser; + Opm::Deck deck = parser.parseString(deck_string); + Opm::EclipseState state(deck); + Opm::EclipseGrid eclipse_grid = state.getInputGrid(); + + BOOST_CHECK_EQUAL( eclipse_grid.getTotalActiveLGR() , 16U ); + BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 9U ); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0,0,0), 0U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",2,2,0), 15U); + + + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0U), 0U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",8U), 15U); + + + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0,0,0), 3U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",2,2,0), 11U); + + + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0), 3U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",8), 11U); + +} + +BOOST_AUTO_TEST_CASE(TestLGRinactivecells) { + const std::string deck_string = R"( +RUNSPEC + +DIMENS + 3 3 1 / + +GRID + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +'LGR1' 2 2 2 2 1 1 3 3 1/ +ACTNUM +1 0 1 +1 1 1 +1 1 1 +/ +ENDFIN + +DX + 9*1000 / +DY + 9*1000 / +DZ + 9*20 / + +TOPS + 9*8325 / + +PORO + 9*0.15 / + +PERMX + 9*1 / + +COPY + PERMX PERMZ / + PERMX PERMY / +/ + +EDIT + +OIL +GAS + +TITLE +The title + +START +16 JUN 1988 / + +PROPS + +REGIONS + +SOLUTION + +SCHEDULE +)"; +\ + Opm::Parser parser; + Opm::Deck deck = parser.parseString(deck_string); + Opm::EclipseState state(deck); + Opm::LgrCollection lgrs = state.getLgrs(); + // LGR Inactive Cells Not yet Implemented +} From 9e3ed03861c4c2e7b2e7812a876d998eb55eda49 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Tue, 19 Nov 2024 09:18:23 +0000 Subject: [PATCH 03/60] part1 - rebase EGrid.hpp seems to contain a bug where get(COORD) cannot catpure the global COORD in EGRIDs, EclipseGrid has been enhaced with functions to output .EGRIDS for LGR - unfinished work - devising a mechanism to define HOSTCE --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 254 ++++++++++++++---- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 15 +- opm/io/eclipse/EGrid.hpp | 2 - tests/parser/LgrOutputTests.cpp | 14 +- 4 files changed, 231 insertions(+), 54 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 30eea594708..1a4eb45dca4 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -17,8 +17,12 @@ along with OPM. If not, see . */ +#include "opm/io/eclipse/PaddedOutputString.hpp" #include +#include +#include #include +#include #include #define _USE_MATH_DEFINES @@ -34,7 +38,7 @@ #include #include -#include + #include #include @@ -160,11 +164,7 @@ EclipseGrid::EclipseGrid(const GridDims& gd) } -<<<<<<< HEAD EclipseGrid::EclipseGrid(std::size_t nx, std::size_t ny , std::size_t nz, -======= -EclipseGrid::EclipseGrid(size_t nx, std::size_t ny , std::size_t nz, ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) double dx, double dy, double dz, double top) : GridDims(nx, ny, nz), m_minpvMode(MinpvMode::Inactive), @@ -560,20 +560,12 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) } -<<<<<<< HEAD std::size_t EclipseGrid::activeIndex(std::size_t i, std::size_t j, std::size_t k) const { -======= - std::size_t EclipseGrid::activeIndex(size_t i, std::size_t j, std::size_t k) const { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) return activeIndex( getGlobalIndex( i,j,k )); } -<<<<<<< HEAD std::size_t EclipseGrid::activeIndex(std::size_t globalIndex) const { -======= - std::size_t EclipseGrid::activeIndex(size_t globalIndex) const { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) if (m_global_to_active.empty()) { return globalIndex; } @@ -590,11 +582,7 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) [0,num_active). */ -<<<<<<< HEAD std::size_t EclipseGrid::getGlobalIndex(std::size_t active_index) const { -======= - std::size_t EclipseGrid::getGlobalIndex(size_t active_index) const { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) return m_active_to_global.at(active_index); } @@ -1421,11 +1409,7 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) std::size_t initialTOPSize = TOPS.size(); TOPS.resize( volume ); -<<<<<<< HEAD for (std::size_t targetIndex = area; targetIndex < volume; targetIndex++) { -======= - for (size_t targetIndex = area; targetIndex < volume; targetIndex++) { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) std::size_t sourceIndex = targetIndex - area; double nextValue = TOPS[sourceIndex] + DZ[sourceIndex]; @@ -1462,11 +1446,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st */ std::size_t initialDSize = D.size(); D.resize( volume ); -<<<<<<< HEAD for (std::size_t targetIndex = initialDSize; targetIndex < volume; targetIndex++) { -======= - for (size_t targetIndex = initialDSize; targetIndex < volume; targetIndex++) { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) std::size_t sourceIndex = targetIndex - area; D[targetIndex] = D[sourceIndex]; } @@ -1925,7 +1905,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st gridhead[1] = dims[0]; // nI gridhead[2] = dims[1]; // nJ gridhead[3] = dims[2]; // nK - gridhead[24] = 1; // corner point grid + gridhead[24] = 1; // NUMRES std::vector nnchead(10, 0); std::vector nnc1; @@ -1979,14 +1959,90 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st egridfile.write("ACTNUM", m_actnum); egridfile.write("ENDGRID", endgrid); + + for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { + lgr_cell.save(egridfile, nnc, units); + } if (nnc1.size() > 0){ egridfile.write("NNCHEAD", nnchead); egridfile.write("NNC1", nnc1); - egridfile.write("NNC2", nnc2); + egridfile.write("NNC2", nnc2); + // for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { + // lgr_cell.save_nnc(egridfile); + // } + } } + void EclipseGrid::init_children_host_cells(){ + auto get_all_cell_centers = [](const auto& cell, const auto& global_list){ + std::vector> cell_centers(global_list.size()); + for (std::size_t index = 0; index < global_list.size(); index++) { + cell_centers[index] = cell.getCellCenter(global_list[index]); + //cell_centers[index] = this->getActiveIndex(i_list[index],j_list[index],k_list[index]); + } + return cell_centers; + }; + auto tetra_vol = [](const auto& x, const auto& y, const auto& z){ + auto det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] + - x[1]*y[2]*z[0] - x[2]*y[0]*z[1] + x[2]*y[1]*z[0] + + x[0]*y[1]*z[3] - x[0]*y[3]*z[1] - x[1]*y[0]*z[3] + + x[1]*y[3]*z[0] + x[3]*y[0]*z[1] - x[3]*y[1]*z[0] + - x[0]*y[2]*z[3] + x[0]*y[3]*z[2] + x[2]*y[0]*z[3] + - x[2]*y[3]*z[0] - x[3]*y[0]*z[2] + x[3]*y[2]*z[0] + + x[1]*y[2]*z[3] - x[1]*y[3]*z[2] - x[2]*y[1]*z[3] + + x[2]*y[3]*z[1] + x[3]*y[1]*z[2] - x[3]*y[2]*z[1]; + return std::abs(det)/6; + }; + auto get_nodes = [](std::array X, std::array ind){ + std::array filtered_vector; + for (std::size_t index = 0; index < ind.size(); index++) { + filtered_vector[index] = X[ind[index]]; + } + return filtered_vector; + }; + auto get_all_cell_corners = [this](const auto& father_list){ + std::vector> X(father_list.size()); + std::vector> Y(father_list.size()); + std::vector> Z(father_list.size()); + for (std::size_t index = 0; index < father_list.size(); index++) { + getCellCorners(father_list[index],X[index],Y[index],Z[index]); + } + return std::make_tuple(X, Y,Z); + }; + auto is_inside = [get_nodes,tetra_vol](std::vector> centers, std::vector>& X, + std::vector>& Y,std::vector>& Z){ + std::array tet_1 = {1,2,3,4}; + + + for (std::size_t index = 0; index < X.size(); index) { + double cX = std::accumulate(X[index].begin(), X[index].end(), 0.0)/8; + double cY = std::accumulate(Y[index].begin(), Y[index].end(), 0.0)/8; + double cZ = std::accumulate(Z[index].begin(), Z[index].end(), 0.0)/8; + auto test = get_nodes(X[index],{1,2,3,4}); + auto vol12= tetra_vol(test,test,test); + + auto in33dex = 10; + + } + //auto test = get_nodes(X,{1,2,3,4}); + return 0; + }; + for (EclipseGridLGR& lgr_cell : lgr_children_cells) { + //EclipseGridLGR::vec_size_t father_host = lgr_cell.get_father_global(); + auto center_lgr_cells = get_all_cell_centers(lgr_cell, lgr_cell.getActiveMap()); + auto [host_cellX, host_cellY, host_cellZ] = get_all_cell_corners(lgr_cell.get_father_global()); + auto test = is_inside(center_lgr_cells, host_cellX,host_cellY,host_cellZ); + // getCellCorners(father_host[0],X,Y,Z); + // auto index = 1; + } + + } + + + + const std::vector& EclipseGrid::getActiveMap() const { return m_active_to_global; } @@ -2084,11 +2140,11 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st if (!(i_list.size() == j_list.size()) && (j_list.size() == k_list.size()) ){ throw std::invalid_argument("Sizes are not compatible."); } - std::vector global_ind(i_list.size()); + std::vector global_ind_active(i_list.size()); for (std::size_t index = 0; index < i_list.size(); index++) { - global_ind[index] = this->getActiveIndex(i_list[index],j_list[index],k_list[index]); + global_ind_active[index] = this->getActiveIndex(i_list[index],j_list[index],k_list[index]); } - return global_ind; + return global_ind_active; }; auto parent_cellsIJK = [](const auto& lgr_cell){ std::vector i_list; @@ -2116,19 +2172,21 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st }; for (std::size_t index = 0; index < lgr_input.size(); index++) { - const auto lgr_cell = lgr_input.getLgr(index); -<<<<<<< HEAD - if (this->lgr_label == lgr_cell.PARENT_NAME()) { -======= - if (this->lgr_label.compare(lgr_cell.PARENT_NAME()) == 0) { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) + const auto& lgr_cell = lgr_input.getLgr(index); + if (this->lgr_label == lgr_cell.PARENT_NAME()){ lgr_grid = true; // auto [i_list, j_list, k_list] = lgr_cell.parent_cellsIJK(); auto [i_list, j_list, k_list] = parent_cellsIJK(lgr_cell); auto father_lgr_index = IJK_global(i_list, j_list, k_list); + + std::array lowIJK = {lgr_cell.I1(), lgr_cell.J1(),lgr_cell.K1()}; + std::array upIJK = {lgr_cell.I2(), lgr_cell.J2(),lgr_cell.K2()}; + + lgr_children_cells.emplace_back(lgr_cell.NAME(), this->lgr_label, this->lgr_level, - lgr_cell.NX(), lgr_cell.NY(), lgr_cell.NZ(), father_lgr_index); + lgr_cell.NX(), lgr_cell.NY(), lgr_cell.NZ(), father_lgr_index, + lowIJK,upIJK); lgr_children_cells.back().create_lgr_cells_tree(lgr_input); } @@ -2272,15 +2330,12 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } } -<<<<<<< HEAD const std::optional& EclipseGrid::getMapAxes() const { return this->m_mapaxes; } -======= ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) ZcornMapper::ZcornMapper(std::size_t nx , std::size_t ny, std::size_t nz) : dims( {{nx,ny,nz}} ), stride( {{2 , 4*nx, 8*nx*ny}} ), @@ -2303,15 +2358,11 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return i*stride[0] + j*stride[1] + k*stride[2] + cell_shift[c]; } - std::size_t ZcornMapper::size() const { + std::size_t ZcornMapper::size() const { return dims[0] * dims[1] * dims[2] * 8; } -<<<<<<< HEAD std::size_t ZcornMapper::index(std::size_t g, int c) const { -======= - std::size_t ZcornMapper::index(size_t g, int c) const { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) int k = g / (dims[0] * dims[1]); g -= k * dims[0] * dims[1]; @@ -2437,4 +2488,117 @@ namespace Opm { { return father_global; } + void EclipseGridLGR::save(Opm::EclIO::EclOutput& egridfile, const std::vector& nnc, const Opm::UnitSystem& units) const { + const auto lgr_name_label = std::vector{ Opm::EclIO::PaddedOutputString<8>{ lgr_label }}; + egridfile.write("LGR",lgr_name_label); + //std::vector> lgr_father_name_label; + std::vector lgr_father_name_label; + if (lgr_level == 1){ + lgr_father_name_label.push_back(""); + } + else { + lgr_father_name_label.push_back(father_label); + } + egridfile.write("LGRPARNT", lgr_father_name_label); + + Opm::UnitSystem::UnitType unitSystemType = units.getType(); + constexpr auto length = ::Opm::UnitSystem::measure::length; + + const std::array dims = getNXYZ(); + + // Preparing vectors to be saved + + // create coord vector of floats with input units, converted from SI + std::vector coord_f; + coord_f.resize(m_coord.size()); + + auto convert_length = [&units](const double x) { return static_cast(units.from_si(length, x)); }; + + if (m_input_coord.has_value()) { + std::transform(m_input_coord.value().begin(), m_input_coord.value().end(), coord_f.begin(), convert_length); + } else { + std::transform(m_coord.begin(), m_coord.end(), coord_f.begin(), convert_length); + } + + // create zcorn vector of floats with input units, converted from SI + std::vector zcorn_f; + zcorn_f.resize(m_zcorn.size()); + + if (m_input_zcorn.has_value()) { + std::transform(m_input_zcorn.value().begin(), m_input_zcorn.value().end(), zcorn_f.begin(), convert_length); + } else { + std::transform(m_zcorn.begin(), m_zcorn.end(), zcorn_f.begin(), convert_length); + } + + m_input_coord.reset(); + m_input_zcorn.reset(); + + // corner point grid + + std::vector gridhead(100,0); + // GLOBAL and LGR Gridhead + gridhead[0] = 1; // corner point grid + gridhead[1] = dims[0]; // nI + gridhead[2] = dims[1]; // nJ + gridhead[3] = dims[2]; // nK + gridhead[4] = lgr_level; // LGR index + + // LGR Exclusive Gridhead + gridhead[24] = 1; // number of reservoirs + gridhead[25] = 1; // number of coordinate line seg + gridhead[26] = 0; // NTHETA =0 non-radial + gridhead[27] = low_fahterIJK[0] + 1;// Lower I-index-host + gridhead[28] = low_fahterIJK[1] + 1;// Lower J-index-host + gridhead[29] = low_fahterIJK[2] + 1;// Lower K-index-host + gridhead[30] = up_fahterIJK[0] + 1; // Upper I-index-host + gridhead[31] = up_fahterIJK[1] + 1; // Upper J-index-host + gridhead[32] = up_fahterIJK[2] + 1; // Upper K-index-host + + std::vector nnchead(10, 0); + std::vector nnc1; + std::vector nnc2; + + for (const NNCdata& n : nnc ) { + nnc1.push_back(n.cell1 + 1); + nnc2.push_back(n.cell2 + 1); + } + + nnchead[0] = nnc1.size(); + + std::vector endgrid = {}; + + // Writing vectors to egrid file + + egridfile.write("GRIDHEAD", gridhead); + + egridfile.write("COORD", coord_f); + egridfile.write("ZCORN", zcorn_f); + + egridfile.write("ACTNUM", m_actnum); + egridfile.write("HOSTNUM", m_actnum); + egridfile.write("ENDGRID", endgrid); + egridfile.write("ENDLGR", endgrid); + for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { + lgr_cell.save(egridfile, nnc, units); + } + } + + void EclipseGridLGR::save_nnc(Opm::EclIO::EclOutput& egridfile) const{ + + std::vector nnchead(10, 0); + std::vector nnc1; + std::vector nnc2; + + /* to be implemented based on how the NNC is input */ + // for (const NNCdata& n : nnc ) { + // nnc1.push_back(n.cell1 + 1); + // nnc2.push_back(n.cell2 + 1); + // } + egridfile.write("NNCL", nnc1); + egridfile.write("NNCG", nnc2); + nnchead[0] = nnc1.size(); + + } + + } diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 51b56873623..9de7e976aef 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace Opm { @@ -119,6 +120,8 @@ namespace Opm { from an active index to a global index must be implemented in the current class. */ + void init_children_host_cells(void); + using GridDims::getGlobalIndex; size_t getGlobalIndex(size_t active_index) const; @@ -268,7 +271,11 @@ namespace Opm { std::map, std::size_t> num_lgr_children_cells; std::vector m_zcorn; std::vector m_coord; + std::vector m_actnum; + // Input grid data. + mutable std::optional> m_input_zcorn; + mutable std::optional> m_input_coord; private: std::vector m_minpvVector; @@ -289,13 +296,7 @@ namespace Opm { size_t zcorn_fixed = 0; bool m_useActnumFromGdfile = false; - // Input grid data. - mutable std::optional> m_input_zcorn; - mutable std::optional> m_input_coord; - - - std::vector m_actnum; std::optional m_mapaxes; // Mapping to/from active cells. @@ -381,6 +382,8 @@ namespace Opm { std::string father_label; // references global on the father label vec_size_t father_global; + std::array low_fahterIJK; + std::array up_fahterIJK; }; diff --git a/opm/io/eclipse/EGrid.hpp b/opm/io/eclipse/EGrid.hpp index a30621eae45..3fefd7260fd 100644 --- a/opm/io/eclipse/EGrid.hpp +++ b/opm/io/eclipse/EGrid.hpp @@ -66,8 +66,6 @@ class EGrid : public EclFile const std::vector& get_mapaxes() const { return m_mapaxes; } const std::string& get_mapunits() const { return m_mapunits; } - - const std::vector& get_coord() const { return coord_array; } const std::vector& get_zcorn() const { return zcorn_array; } diff --git a/tests/parser/LgrOutputTests.cpp b/tests/parser/LgrOutputTests.cpp index fc70abafda7..3dea91b23f3 100644 --- a/tests/parser/LgrOutputTests.cpp +++ b/tests/parser/LgrOutputTests.cpp @@ -13,6 +13,7 @@ along with OPM. If not, see . */ +#include #include #define BOOST_TEST_MODULE LgrOutputTests @@ -40,9 +41,12 @@ LgrCollection read_lgr(const std::string& deck_string, std::size_t nx, std::size std::pair, std::vector> read_cpg_from_egrid(const std::string& file_path, const std::string& lgr_label){ Opm::EclIO::EGrid egrid_global(file_path, lgr_label); + // Opm::EclIO::EGrid egrid_global(file_path); egrid_global.load_grid_data(); + // auto global_coord = egrid_global.get("COORD"); + // auto global_zcorn = egrid_global.get("ZCORN"); auto global_coord = egrid_global.get_coord(); - auto global_zcorn = egrid_global.get_zcorn(); + auto global_zcorn = egrid_global.get_zcorn(); std::vector coord_g(global_coord.begin(), global_coord.end()); std::vector zcorn_g(global_zcorn.begin(), global_zcorn.end()); return std::make_pair(coord_g, zcorn_g); @@ -104,14 +108,22 @@ SOLUTION SCHEDULE )"; \ + Opm::UnitSystem units(1); + std::vector vecNNC; std::array global_grid_dim = {3,3,1}; LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); auto [coord_g, zcorn_g] = read_cpg_from_egrid("CARFIN5.EGRID", "global"); Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); + + eclipse_grid_file.init_lgr_cells(lgr_col); + eclipse_grid_file.init_children_host_cells(); + auto [coord_l, zcorn_l] = read_cpg_from_egrid("CARFIN5.EGRID", "LGR1"); eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l,zcorn_l); + //eclipse_grid_file.save("output.FEGRID",true,std::nullopt); + eclipse_grid_file.save("output.FEGRID",true,vecNNC,units); auto index = 1; From 724bd57973f6a6ce1dba72529989cb04dcf787ab Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Mon, 28 Oct 2024 14:45:40 +0000 Subject: [PATCH 04/60] test to check if LGR cell is insded host cell created, contain bugs and lacks tests --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 174 ++++++++++++++---- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 2 + tests/parser/LgrOutputTests.cpp | 4 +- 3 files changed, 145 insertions(+), 35 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 1a4eb45dca4..7e2f24cb9ed 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -1977,12 +1977,17 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st void EclipseGrid::init_children_host_cells(){ auto get_all_cell_centers = [](const auto& cell, const auto& global_list){ - std::vector> cell_centers(global_list.size()); + std::vector cell_centersX(global_list.size()); + std::vector cell_centersY(global_list.size()); + std::vector cell_centersZ(global_list.size()); + // std::vector value; for (std::size_t index = 0; index < global_list.size(); index++) { - cell_centers[index] = cell.getCellCenter(global_list[index]); - //cell_centers[index] = this->getActiveIndex(i_list[index],j_list[index],k_list[index]); + auto value = cell.getCellCenter(global_list[index]); + cell_centersX[index] = value[0]; + cell_centersY[index] = value[1]; + cell_centersZ[index] = value[2]; } - return cell_centers; + return std::make_tuple(cell_centersX,cell_centersY,cell_centersZ); }; auto tetra_vol = [](const auto& x, const auto& y, const auto& z){ auto det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] @@ -1995,13 +2000,97 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st + x[2]*y[3]*z[1] + x[3]*y[1]*z[2] - x[3]*y[2]*z[1]; return std::abs(det)/6; }; - auto get_nodes = [](std::array X, std::array ind){ - std::array filtered_vector; + + auto append_node = [](const std::array& X, const std::array& Y, const std::array& Z, + const double& xc, const double& yc, const double& zc ){ + std::array tX; + std::array tY; + std::array tZ; + std::copy(X.begin(), X.end(), tX.begin()); + tX[3]= xc; + std::copy(Y.begin(), Y.end(), tY.begin()); + tY[3]= yc; + std::copy(Z.begin(), Z.end(), tZ.begin()); + tZ[3]= zc; + return std::make_tuple(tX,tY,tZ); + }; + auto get_nodes = [](const std::array& X, const std::array& Y, const std::array& Z, + const std::array& ind){ + std::array filtered_vectorX; + std::array filtered_vectorY; + std::array filtered_vectorZ; for (std::size_t index = 0; index < ind.size(); index++) { - filtered_vector[index] = X[ind[index]]; + filtered_vectorX[index] = X[ind[index]]; + filtered_vectorY[index] = Y[ind[index]]; + filtered_vectorZ[index] = Z[ind[index]]; } - return filtered_vector; + return std::make_tuple(filtered_vectorX,filtered_vectorY,filtered_vectorZ); + }; + auto calc_vol = [get_nodes,append_node, tetra_vol] + (const auto& x, const auto& y, const auto& z, + const auto& pcX, const auto& pcY, const auto& pcZ ){ + // node order of each face + // Face 0 = {0,1,5,6} + std::array fc0_0 = {0,1,5}; + std::array fc0_1 = {1,5,6}; + // Face 1 = {0,4,6,2} + std::array fc1_0 = {0,4,6}; + std::array fc1_1 = {4,6,2}; + // Face 2 = {2,3,7,6} + std::array fc2_0 = {2,3,7}; + std::array fc2_1 = {3,7,6}; + // Face 3 = {1,3,7,5} + std::array fc3_0 = {1,3,7}; + std::array fc3_1 = {3,7,5}; + // Face 4 = {0,1,3,2} + std::array fc4_0 = {0,1,3}; + std::array fc4_1 = {1,3,2}; + // Face 5 = {4,5,7,6} + std::array fc5_0 = {4,5,7}; + std::array fc5_1 = {5,7,6}; + + std::array f0,f1,f2; + // note: some CPG grids may have collapsed faces that are not planar, therefore + // the volume of the tetrhadron was used. + // calculating the volume of the pyramid with F0 as base and pc as center + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc0_0); + auto tetraFO = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc0_1); + tetraFO = tetraFO + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + + // calculating the volume of the pyramid with F1 as base and pc as center + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc1_0); + auto tetraF1 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc1_1); + tetraF1 = tetraF1 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + + + // calculating the volume of the pyramid with F2 as base and pc as center + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc2_0); + auto tetraF2 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc2_1); + tetraF2 = tetraF2 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + + // calculating the volume of the pyramid with F3 as base and pc as center + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc3_0); + auto tetraF3 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc3_1); + tetraF3 = tetraF3 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + + // calculating the volume of the pyramid with F4 as base and pc as center + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc4_0); + auto tetraF4 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc4_1); + tetraF4 = tetraF4 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + + // calculating the volume of the pyramid with F5 as base and pc as center + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc5_0); + auto tetraF5 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc5_1); + tetraF5 = tetraF5 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + return tetraFO + tetraF1 + tetraF2 + tetraF3 + tetraF4 + tetraF5; }; + auto get_all_cell_corners = [this](const auto& father_list){ std::vector> X(father_list.size()); std::vector> Y(father_list.size()); @@ -2011,31 +2100,46 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } return std::make_tuple(X, Y,Z); }; - auto is_inside = [get_nodes,tetra_vol](std::vector> centers, std::vector>& X, - std::vector>& Y,std::vector>& Z){ - std::array tet_1 = {1,2,3,4}; - - - for (std::size_t index = 0; index < X.size(); index) { - double cX = std::accumulate(X[index].begin(), X[index].end(), 0.0)/8; - double cY = std::accumulate(Y[index].begin(), Y[index].end(), 0.0)/8; - double cZ = std::accumulate(Z[index].begin(), Z[index].end(), 0.0)/8; - auto test = get_nodes(X[index],{1,2,3,4}); - auto vol12= tetra_vol(test,test,test); - - auto in33dex = 10; - + auto is_inside = [calc_vol](const std::vector& tpX, const std::vector& tpY, const std::vector& tpZ, + const std::vector>& X, const std::vector>& Y, + const std::vector>& Z){ + std::vector in_elements(tpX.size(),0); + // check if it is insde or outside boundary box + double minX, minY, minZ, maxX, maxY, maxZ; + double pcX, pcY, pcZ, element_volume, test_element_volume; + bool flag; + for (std::size_t outerIndex = 0; outerIndex < X.size(); outerIndex++) { + minX = *std::min_element(X[outerIndex].begin(), X[outerIndex].end()); + minY = *std::min_element(Y[outerIndex].begin(), Y[outerIndex].end()); + minZ = *std::min_element(Z[outerIndex].begin(), Z[outerIndex].end()); + maxX = *std::max_element(X[outerIndex].begin(), X[outerIndex].end()); + maxY = *std::max_element(Y[outerIndex].begin(), Y[outerIndex].end()); + maxZ = *std::max_element(Z[outerIndex].begin(), Z[outerIndex].end()); + pcX = std::accumulate(X[outerIndex].begin(), X[outerIndex].end(), 0.0)/8; + pcY = std::accumulate(Y[outerIndex].begin(), Y[outerIndex].end(), 0.0)/8; + pcZ = std::accumulate(Z[outerIndex].begin(), Z[outerIndex].end(), 0.0)/8; + element_volume = calc_vol(X[outerIndex],Y[outerIndex],Z[outerIndex], pcX, pcY,pcZ); + for (size_t innerIndex = 0; innerIndex < tpX.size(); innerIndex++) + { + flag = (minX < tpX[outerIndex]) && (maxX > tpX[innerIndex]) && + (minY < tpY[outerIndex]) && (maxY > tpY[innerIndex]) && + (minZ < tpZ[outerIndex]) && (maxZ > tpZ[innerIndex]); + if (flag) { + test_element_volume = calc_vol(X[outerIndex],Y[outerIndex],Z[outerIndex], + tpX[innerIndex], tpY[innerIndex],tpZ[innerIndex]); + if (test_element_volume <= element_volume) {in_elements[innerIndex] = outerIndex;} + } + } } - //auto test = get_nodes(X,{1,2,3,4}); - return 0; + return in_elements; }; - for (EclipseGridLGR& lgr_cell : lgr_children_cells) { - //EclipseGridLGR::vec_size_t father_host = lgr_cell.get_father_global(); - auto center_lgr_cells = get_all_cell_centers(lgr_cell, lgr_cell.getActiveMap()); - auto [host_cellX, host_cellY, host_cellZ] = get_all_cell_corners(lgr_cell.get_father_global()); - auto test = is_inside(center_lgr_cells, host_cellX,host_cellY,host_cellZ); - // getCellCorners(father_host[0],X,Y,Z); - // auto index = 1; + for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { + //EclipseGridLGR::vec_size_t father_host = lgr_cell.get_father_global(); + auto test = lgr_cell.getActiveMap(); + auto indexx = 1; + // auto [cell_centerX, cell_centerY,cell_centerZ] = get_all_cell_centers(lgr_cell, lgr_cell.getActiveMap()); + // auto [host_cellX, host_cellY, host_cellZ] = get_all_cell_corners(lgr_cell.get_father_global()); + // lgr_cell.set_hostnum(is_inside(cell_centerX,cell_centerY, cell_centerZ, host_cellX, host_cellY, host_cellZ)); } } @@ -2474,6 +2578,10 @@ namespace Opm { lgr_label= self_label; lgr_level = father_lgr_level + 1 ; } + void EclipseGridLGR::set_hostnum(const std::vector hostnum) + { + m_hostnum = hostnum; + } void EclipseGridLGR::set_lgr_refinement(std::vector coord, std::vector zcorn) { m_coord = coord; @@ -2543,7 +2651,7 @@ namespace Opm { gridhead[3] = dims[2]; // nK gridhead[4] = lgr_level; // LGR index - // LGR Exclusive Gridhead + // LGR Exclusive Gridhead Flags gridhead[24] = 1; // number of reservoirs gridhead[25] = 1; // number of coordinate line seg gridhead[26] = 0; // NTHETA =0 non-radial @@ -2575,7 +2683,7 @@ namespace Opm { egridfile.write("ZCORN", zcorn_f); egridfile.write("ACTNUM", m_actnum); - egridfile.write("HOSTNUM", m_actnum); + egridfile.write("HOSTNUM", m_hostnum); egridfile.write("ENDGRID", endgrid); egridfile.write("ENDLGR", endgrid); for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 9de7e976aef..3b460ff642e 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -376,6 +376,7 @@ namespace Opm { const vec_size_t& get_father_global() const{ return father_global; } + void set_hostnum(const std::vector); void set_lgr_refinement(std::vector,std::vector); private: void init_father_global(); @@ -384,6 +385,7 @@ namespace Opm { vec_size_t father_global; std::array low_fahterIJK; std::array up_fahterIJK; + std::vector m_hostnum; }; diff --git a/tests/parser/LgrOutputTests.cpp b/tests/parser/LgrOutputTests.cpp index 3dea91b23f3..0d5ea8e6b70 100644 --- a/tests/parser/LgrOutputTests.cpp +++ b/tests/parser/LgrOutputTests.cpp @@ -114,13 +114,13 @@ SCHEDULE LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); auto [coord_g, zcorn_g] = read_cpg_from_egrid("CARFIN5.EGRID", "global"); Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); - eclipse_grid_file.init_lgr_cells(lgr_col); - eclipse_grid_file.init_children_host_cells(); auto [coord_l, zcorn_l] = read_cpg_from_egrid("CARFIN5.EGRID", "LGR1"); eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l,zcorn_l); + eclipse_grid_file.init_children_host_cells(); + //eclipse_grid_file.save("output.FEGRID",true,std::nullopt); eclipse_grid_file.save("output.FEGRID",true,vecNNC,units); From 5a41eafcb34eaa52aa30999cd974a8a96d98414f Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Tue, 29 Oct 2024 07:53:55 +0000 Subject: [PATCH 05/60] EclipseGrid is capable of initializing EclipseGridLGR hostcells. --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 89 +++++++++++++------ .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 2 +- 2 files changed, 62 insertions(+), 29 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 7e2f24cb9ed..66f54f8e54a 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -1980,15 +1980,26 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector cell_centersX(global_list.size()); std::vector cell_centersY(global_list.size()); std::vector cell_centersZ(global_list.size()); - // std::vector value; + std::array value = {0,0,0}; for (std::size_t index = 0; index < global_list.size(); index++) { - auto value = cell.getCellCenter(global_list[index]); + value = cell.getCellCenter(global_list[index]); cell_centersX[index] = value[0]; cell_centersY[index] = value[1]; cell_centersZ[index] = value[2]; } return std::make_tuple(cell_centersX,cell_centersY,cell_centersZ); }; + + auto get_all_cell_corners = [this](const auto& father_list){ + std::vector> X(father_list.size()); + std::vector> Y(father_list.size()); + std::vector> Z(father_list.size()); + for (std::size_t index = 0; index < father_list.size(); index++) { + getCellCorners(father_list[index],X[index],Y[index],Z[index]); + } + return std::make_tuple(X, Y,Z); + }; + auto tetra_vol = [](const auto& x, const auto& y, const auto& z){ auto det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] - x[1]*y[2]*z[0] - x[2]*y[0]*z[1] + x[2]*y[1]*z[0] @@ -2014,6 +2025,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st tZ[3]= zc; return std::make_tuple(tX,tY,tZ); }; + auto get_nodes = [](const std::array& X, const std::array& Y, const std::array& Z, const std::array& ind){ std::array filtered_vectorX; @@ -2026,6 +2038,15 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } return std::make_tuple(filtered_vectorX,filtered_vectorY,filtered_vectorZ); }; + + auto filter_array = [](const std::vector& X, const std::vector& ind){ + std::vector filtered_vectorX(ind.size(),0); + for (std::size_t index = 0; index < ind.size(); index++) { + filtered_vectorX[index] = X[ind[index]]; + } + return filtered_vectorX; + }; + auto calc_vol = [get_nodes,append_node, tetra_vol] (const auto& x, const auto& y, const auto& z, const auto& pcX, const auto& pcY, const auto& pcZ ){ @@ -2091,15 +2112,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return tetraFO + tetraF1 + tetraF2 + tetraF3 + tetraF4 + tetraF5; }; - auto get_all_cell_corners = [this](const auto& father_list){ - std::vector> X(father_list.size()); - std::vector> Y(father_list.size()); - std::vector> Z(father_list.size()); - for (std::size_t index = 0; index < father_list.size(); index++) { - getCellCorners(father_list[index],X[index],Y[index],Z[index]); - } - return std::make_tuple(X, Y,Z); - }; + auto is_inside = [calc_vol](const std::vector& tpX, const std::vector& tpY, const std::vector& tpZ, const std::vector>& X, const std::vector>& Y, const std::vector>& Z){ @@ -2119,28 +2132,47 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st pcY = std::accumulate(Y[outerIndex].begin(), Y[outerIndex].end(), 0.0)/8; pcZ = std::accumulate(Z[outerIndex].begin(), Z[outerIndex].end(), 0.0)/8; element_volume = calc_vol(X[outerIndex],Y[outerIndex],Z[outerIndex], pcX, pcY,pcZ); - for (size_t innerIndex = 0; innerIndex < tpX.size(); innerIndex++) - { - flag = (minX < tpX[outerIndex]) && (maxX > tpX[innerIndex]) && - (minY < tpY[outerIndex]) && (maxY > tpY[innerIndex]) && - (minZ < tpZ[outerIndex]) && (maxZ > tpZ[innerIndex]); - if (flag) { + for (size_t innerIndex = 0; innerIndex < tpX.size(); innerIndex++){ + // check if center of refined volume is outside the boundary box of a coarse volume. + // Only computes volumed base test is this condition is met. + flag = (minX < tpX[innerIndex]) && (maxX > tpX[innerIndex]) && + (minY < tpY[innerIndex]) && (maxY > tpY[innerIndex]) && + (minZ < tpZ[innerIndex]) && (maxZ > tpZ[innerIndex]); + if (flag && (in_elements[innerIndex] == 0)) { test_element_volume = calc_vol(X[outerIndex],Y[outerIndex],Z[outerIndex], tpX[innerIndex], tpY[innerIndex],tpZ[innerIndex]); - if (test_element_volume <= element_volume) {in_elements[innerIndex] = outerIndex;} + if (test_element_volume <= element_volume){ + in_elements[innerIndex] = static_cast(outerIndex); + } } } } return in_elements; }; - for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { - //EclipseGridLGR::vec_size_t father_host = lgr_cell.get_father_global(); - auto test = lgr_cell.getActiveMap(); - auto indexx = 1; - // auto [cell_centerX, cell_centerY,cell_centerZ] = get_all_cell_centers(lgr_cell, lgr_cell.getActiveMap()); - // auto [host_cellX, host_cellY, host_cellZ] = get_all_cell_corners(lgr_cell.get_father_global()); - // lgr_cell.set_hostnum(is_inside(cell_centerX,cell_centerY, cell_centerZ, host_cellX, host_cellY, host_cellZ)); - } + + std::vector element_centerX, element_centerY, element_centerZ; + for (EclipseGridLGR& lgr_cell : lgr_children_cells) { + std::tie(element_centerX, element_centerY,element_centerZ) = get_all_cell_centers(lgr_cell, lgr_cell.getActiveMap()); + auto [host_cellX, host_cellY, host_cellZ] = get_all_cell_corners(lgr_cell.get_father_global()); + auto inside_el = is_inside(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); + auto host_cells_global_ref = filter_array(lgr_cell.get_father_global(), inside_el); + lgr_cell.set_hostnum(host_cells_global_ref); + std::cout< hostnum) - { + void EclipseGridLGR::set_hostnum(std::vector& hostnum) + { + std::transform(hostnum.begin(),hostnum.end(), hostnum.begin(), [](int a){return a+1;}); m_hostnum = hostnum; } void EclipseGridLGR::set_lgr_refinement(std::vector coord, std::vector zcorn) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 3b460ff642e..551f506b604 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -376,7 +376,7 @@ namespace Opm { const vec_size_t& get_father_global() const{ return father_global; } - void set_hostnum(const std::vector); + void set_hostnum(std::vector&); void set_lgr_refinement(std::vector,std::vector); private: void init_father_global(); From f3c2b7bc3d931c4eded7ecc106e88d32f17121b8 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Tue, 29 Oct 2024 10:26:06 +0000 Subject: [PATCH 06/60] fixed a bug in calc_vol - the order of the associated first pyramid was incorrect --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 28 +- tests/parser/LgrOutputTests.cpp | 315 +++++------------- 2 files changed, 90 insertions(+), 253 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 66f54f8e54a..f0f40dc66fa 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -2051,9 +2051,9 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st (const auto& x, const auto& y, const auto& z, const auto& pcX, const auto& pcY, const auto& pcZ ){ // node order of each face - // Face 0 = {0,1,5,6} + // Face 0 = {0,1,5,4} std::array fc0_0 = {0,1,5}; - std::array fc0_1 = {1,5,6}; + std::array fc0_1 = {1,5,4}; // Face 1 = {0,4,6,2} std::array fc1_0 = {0,4,6}; std::array fc1_1 = {4,6,2}; @@ -2072,12 +2072,12 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::array f0,f1,f2; // note: some CPG grids may have collapsed faces that are not planar, therefore - // the volume of the tetrhadron was used. + // the hexadron is subdivided in terahedrons. // calculating the volume of the pyramid with F0 as base and pc as center std::tie(f0,f1,f2) = get_nodes(x,y,z,fc0_0); - auto tetraFO = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + auto tetraF0 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); std::tie(f0,f1,f2) = get_nodes(x,y,z,fc0_1); - tetraFO = tetraFO + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + tetraF0 = tetraF0 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); // calculating the volume of the pyramid with F1 as base and pc as center std::tie(f0,f1,f2) = get_nodes(x,y,z,fc1_0); @@ -2109,7 +2109,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st auto tetraF5 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); std::tie(f0,f1,f2) = get_nodes(x,y,z,fc5_1); tetraF5 = tetraF5 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - return tetraFO + tetraF1 + tetraF2 + tetraF3 + tetraF4 + tetraF5; + return tetraF0 + tetraF1 + tetraF2 + tetraF3 + tetraF4 + tetraF5; }; @@ -2157,23 +2157,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st auto inside_el = is_inside(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); auto host_cells_global_ref = filter_array(lgr_cell.get_father_global(), inside_el); lgr_cell.set_hostnum(host_cells_global_ref); - std::cout<. */ +#include #include +#include #include #define BOOST_TEST_MODULE LgrOutputTests @@ -53,7 +55,7 @@ std::pair, std::vector> read_cpg_from_egrid(const st } -BOOST_AUTO_TEST_CASE(TestLgrOutput) { +BOOST_AUTO_TEST_CASE(TestLgrOutputBasicLGR) { const std::string deck_string = R"( RUNSPEC @@ -111,63 +113,50 @@ SCHEDULE Opm::UnitSystem units(1); std::vector vecNNC; std::array global_grid_dim = {3,3,1}; + std::vector coord_g, zcorn_g, coord_l, zcorn_l, coord_g_opm, zcorn_g_opm, coord_l_opm, zcorn_l_opm; + // Intialize LgrCollection from string. LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); - auto [coord_g, zcorn_g] = read_cpg_from_egrid("CARFIN5.EGRID", "global"); + // Read global COORD and ZCORN from reference simulator output. + std::tie(coord_g, zcorn_g) = read_cpg_from_egrid("CARFIN5.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l, zcorn_l) = read_cpg_from_egrid("CARFIN5.EGRID", "LGR1"); + // Eclipse Grid is intialzied with COORD and ZCORN. Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); - + // LgrCollection is used to initalize LGR Cells in the Eclipse Grid. eclipse_grid_file.init_lgr_cells(lgr_col); - - auto [coord_l, zcorn_l] = read_cpg_from_egrid("CARFIN5.EGRID", "LGR1"); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l,zcorn_l); + // Intialize host_cell numbering. eclipse_grid_file.init_children_host_cells(); - - //eclipse_grid_file.save("output.FEGRID",true,std::nullopt); - - eclipse_grid_file.save("output.FEGRID",true,vecNNC,units); - auto index = 1; - - - // Opm::EclipseGrid eclipse_grid = state.getInputGrid(); - - - - // Opm::EclIO::EGrid egrid_global("CARFIN5.EGRID"); - // egrid_global.load_grid_data(); - // auto global_coord = egrid_global.get_coord(); - // auto global_zcorn = egrid_global.get_zcorn(); - - // std::vector coord_g(global_coord.begin(), global_coord.end()); - // std::vector zcorn_g(global_zcorn.begin(), global_zcorn.end()); - // std::array dims = {3,3, 1}; - - // Opm::EclipseGrid eclipse_grid_file(dims, coord_g, zcorn_g); - - - - - // Opm::EclIO::EGrid egrid_lgr1("CARFIN5.EGRID","LGR1"); - // egrid_lgr1.load_grid_data(); - // BOOST_CHECK_EQUAL( eclipse_grid.getTotalActiveLGR() , 21U ); - // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 8U ); - // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[1].getTotalActiveLGR() , 8U ); - - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0,0,0), 0U); - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",1,3,0), 7U); - - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",1,0,0), 8U); - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",1,1,0), 17U); - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",2,2,0), 20U); - - - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",0,0,0), 9U); - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",1,3,0), 16U); + // Save EclipseGrid. + eclipse_grid_file.save("OPMCARFIN5.EGRID",false,vecNNC,units); + // Once the new EGRID is saved, another EclipseGrid Object is created for the sake of comparison. + std::tie(coord_g_opm, zcorn_g_opm) = read_cpg_from_egrid("OPMCARFIN5.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l_opm, zcorn_l_opm) = read_cpg_from_egrid("OPMCARFIN5.EGRID", "LGR1"); + // Eclipse Grid is intialzied with COORD and ZCORN. + Opm::EclipseGrid eclipse_grid_OPM(global_grid_dim, coord_g_opm, zcorn_g_opm); +// LgrCollection is used to initalize LGR Cells in the Eclipse Grid. + eclipse_grid_OPM.init_lgr_cells(lgr_col); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) + eclipse_grid_OPM.lgr_children_cells[0].set_lgr_refinement(coord_l_opm,zcorn_l_opm); + // Intialize host_cell numbering. + eclipse_grid_OPM.init_children_host_cells(); + BOOST_CHECK_EQUAL( coord_g_opm.size() , coord_g.size()); + BOOST_CHECK_EQUAL( zcorn_g_opm.size() , zcorn_g.size()); + BOOST_CHECK_EQUAL( coord_l_opm.size() , coord_l.size()); + BOOST_CHECK_EQUAL( zcorn_l_opm.size() , zcorn_l.size()); + std::size_t index ; + for (index = 0; index < coord_g.size(); index++) { + BOOST_CHECK_EQUAL( coord_g_opm[index] , coord_g[index]); + } + for (index = 0; index < zcorn_g.size(); index++) { + BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); + } } - - - -BOOST_AUTO_TEST_CASE(TestLgrNested) { +BOOST_AUTO_TEST_CASE(TestLgrOutputColumnLGR) { const std::string deck_string = R"( RUNSPEC @@ -178,15 +167,9 @@ GRID CARFIN -- NAME I1-I2 J1-J2 K1-K2 NX NY NZ -LGR1 2 2 2 2 1 1 3 3 1 1* GLOBAL/ +'LGR1' 1 1 1 2 1 1 2 4 1/ ENDFIN -CARFIN --- NAME I1-I2 J1-J2 K1-K2 NX NY NZ -LGR2 2 2 2 2 1 1 3 3 1 1* LGR1/ -ENDFIN - - DX 9*1000 / DY @@ -228,177 +211,47 @@ SOLUTION SCHEDULE )"; \ - Opm::Parser parser; - Opm::Deck deck = parser.parseString(deck_string); - Opm::EclipseState state(deck); - Opm::EclipseGrid eclipse_grid = state.getInputGrid(); - - BOOST_CHECK_EQUAL( eclipse_grid.getTotalActiveLGR() , 25U ); - BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 17U ); - BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].lgr_children_cells[0].getTotalActiveLGR() , 9U ); - - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0,0,0), 0U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",2,2,0), 24U); - - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0,0,0), 4U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",2,2,0), 20U); - - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",0,0,0), 8U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",2,2,0), 16U); - - BOOST_CHECK_THROW(eclipse_grid.getActiveIndexLGR("GLOBAL",1,1,0), std::invalid_argument); - BOOST_CHECK_THROW(eclipse_grid.getActiveIndexLGR("LGR1",1,1,0), std::invalid_argument); - BOOST_CHECK_THROW(eclipse_grid.getActiveIndexLGR("LGR3",1,1,0), std::invalid_argument); -} -BOOST_AUTO_TEST_CASE(TestGLOBALinactivecells) { - const std::string deck_string = R"( -RUNSPEC - -DIMENS - 3 3 1 / - -GRID - -ACTNUM -1 0 1 -1 1 1 -1 1 1 -/ - -CARFIN --- NAME I1-I2 J1-J2 K1-K2 NX NY NZ -'LGR1' 2 2 2 2 1 1 3 3 1/ -ENDFIN - - -DX - 9*1000 / -DY - 9*1000 / -DZ - 9*20 / - -TOPS - 9*8325 / - -PORO - 9*0.15 / - -PERMX - 9*1 / - -COPY - PERMX PERMZ / - PERMX PERMY / -/ - -EDIT - -OIL -GAS - -TITLE -The title - -START -16 JUN 1988 / - -PROPS - -REGIONS - -SOLUTION - -SCHEDULE -)"; -\ - Opm::Parser parser; - Opm::Deck deck = parser.parseString(deck_string); - Opm::EclipseState state(deck); - Opm::EclipseGrid eclipse_grid = state.getInputGrid(); - - BOOST_CHECK_EQUAL( eclipse_grid.getTotalActiveLGR() , 16U ); - BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 9U ); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0,0,0), 0U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",2,2,0), 15U); - - - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0U), 0U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",8U), 15U); - - - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0,0,0), 3U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",2,2,0), 11U); - - - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0), 3U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",8), 11U); - -} - -BOOST_AUTO_TEST_CASE(TestLGRinactivecells) { - const std::string deck_string = R"( -RUNSPEC - -DIMENS - 3 3 1 / - -GRID - -CARFIN --- NAME I1-I2 J1-J2 K1-K2 NX NY NZ -'LGR1' 2 2 2 2 1 1 3 3 1/ -ACTNUM -1 0 1 -1 1 1 -1 1 1 -/ -ENDFIN - -DX - 9*1000 / -DY - 9*1000 / -DZ - 9*20 / - -TOPS - 9*8325 / - -PORO - 9*0.15 / - -PERMX - 9*1 / - -COPY - PERMX PERMZ / - PERMX PERMY / -/ - -EDIT - -OIL -GAS - -TITLE -The title - -START -16 JUN 1988 / - -PROPS - -REGIONS - -SOLUTION - -SCHEDULE -)"; -\ - Opm::Parser parser; - Opm::Deck deck = parser.parseString(deck_string); - Opm::EclipseState state(deck); - Opm::LgrCollection lgrs = state.getLgrs(); - // LGR Inactive Cells Not yet Implemented -} + Opm::UnitSystem units(1); + std::vector vecNNC; + std::array global_grid_dim = {3,3,1}; + std::vector coord_g, zcorn_g, coord_l, zcorn_l, coord_g_opm, zcorn_g_opm, coord_l_opm, zcorn_l_opm; + // Intialize LgrCollection from string. + LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); + // Read global COORD and ZCORN from reference simulator output. + std::tie(coord_g, zcorn_g) = read_cpg_from_egrid("CARFIN-COLUMN.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l, zcorn_l) = read_cpg_from_egrid("CARFIN-COLUMN.EGRID", "LGR1"); + // Eclipse Grid is intialzied with COORD and ZCORN. + Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); + // LgrCollection is used to initalize LGR Cells in the Eclipse Grid. + eclipse_grid_file.init_lgr_cells(lgr_col); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) + eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l,zcorn_l); + // Intialize host_cell numbering. + eclipse_grid_file.init_children_host_cells(); + // Save EclipseGrid. + eclipse_grid_file.save("OPMCARFIN-COLUMN.EGRID",false,vecNNC,units); + // Once the new EGRID is saved, another EclipseGrid Object is created for the sake of comparison. + std::tie(coord_g_opm, zcorn_g_opm) = read_cpg_from_egrid("OPMCARFIN-COLUMN.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l_opm, zcorn_l_opm) = read_cpg_from_egrid("OPMCARFIN-COLUMN.EGRID", "LGR1"); + // Eclipse Grid is intialzied with COORD and ZCORN. + Opm::EclipseGrid eclipse_grid_OPM(global_grid_dim, coord_g_opm, zcorn_g_opm); +// LgrCollection is used to initalize LGR Cells in the Eclipse Grid. + eclipse_grid_OPM.init_lgr_cells(lgr_col); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) + eclipse_grid_OPM.lgr_children_cells[0].set_lgr_refinement(coord_l_opm,zcorn_l_opm); + // Intialize host_cell numbering. + eclipse_grid_OPM.init_children_host_cells(); + BOOST_CHECK_EQUAL( coord_g_opm.size() , coord_g.size()); + BOOST_CHECK_EQUAL( zcorn_g_opm.size() , zcorn_g.size()); + BOOST_CHECK_EQUAL( coord_l_opm.size() , coord_l.size()); + BOOST_CHECK_EQUAL( zcorn_l_opm.size() , zcorn_l.size()); + std::size_t index ; + for (index = 0; index < coord_g.size(); index++) { + BOOST_CHECK_EQUAL( coord_g_opm[index] , coord_g[index]); + } + for (index = 0; index < zcorn_g.size(); index++) { + BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); + } + } From a588eff0ec2af2e22ea8568fa4022268d3c7d8a4 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Tue, 29 Oct 2024 10:59:29 +0000 Subject: [PATCH 07/60] EclipseGrid::init_children_host_cells refactored --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 141 +++++++----------- 1 file changed, 54 insertions(+), 87 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index f0f40dc66fa..671de084ba8 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -1976,7 +1976,34 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } void EclipseGrid::init_children_host_cells(){ - auto get_all_cell_centers = [](const auto& cell, const auto& global_list){ + constexpr std::array, 12> faceConfigurations{ + std::array{0, 1, 5}, + {1, 5, 4}, // Face 0 + {0, 4, 6}, + {4, 6, 2}, // Face 1 + {2, 3, 7}, + {3, 7, 6}, // Face 2 + {1, 3, 7}, + {3, 7, 5}, // Face 3 + {0, 1, 3}, + {1, 3, 2}, // Face 4 + {4, 5, 7}, + {5, 7, 6} // Face 5 + }; + constexpr double epslon = 1e-6; + auto calcTetraVol = [](const auto& x, const auto& y, const auto& z){ + auto det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] + - x[1]*y[2]*z[0] - x[2]*y[0]*z[1] + x[2]*y[1]*z[0] + + x[0]*y[1]*z[3] - x[0]*y[3]*z[1] - x[1]*y[0]*z[3] + + x[1]*y[3]*z[0] + x[3]*y[0]*z[1] - x[3]*y[1]*z[0] + - x[0]*y[2]*z[3] + x[0]*y[3]*z[2] + x[2]*y[0]*z[3] + - x[2]*y[3]*z[0] - x[3]*y[0]*z[2] + x[3]*y[2]*z[0] + + x[1]*y[2]*z[3] - x[1]*y[3]*z[2] - x[2]*y[1]*z[3] + + x[2]*y[3]*z[1] + x[3]*y[1]*z[2] - x[3]*y[2]*z[1]; + return std::abs(det)/6; + }; + + auto getAllCellCenters = [](const auto& cell, const auto& global_list){ std::vector cell_centersX(global_list.size()); std::vector cell_centersY(global_list.size()); std::vector cell_centersZ(global_list.size()); @@ -1990,7 +2017,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return std::make_tuple(cell_centersX,cell_centersY,cell_centersZ); }; - auto get_all_cell_corners = [this](const auto& father_list){ + auto getAllCellCorners = [this](const auto& father_list){ std::vector> X(father_list.size()); std::vector> Y(father_list.size()); std::vector> Z(father_list.size()); @@ -2000,19 +2027,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return std::make_tuple(X, Y,Z); }; - auto tetra_vol = [](const auto& x, const auto& y, const auto& z){ - auto det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] - - x[1]*y[2]*z[0] - x[2]*y[0]*z[1] + x[2]*y[1]*z[0] - + x[0]*y[1]*z[3] - x[0]*y[3]*z[1] - x[1]*y[0]*z[3] - + x[1]*y[3]*z[0] + x[3]*y[0]*z[1] - x[3]*y[1]*z[0] - - x[0]*y[2]*z[3] + x[0]*y[3]*z[2] + x[2]*y[0]*z[3] - - x[2]*y[3]*z[0] - x[3]*y[0]*z[2] + x[3]*y[2]*z[0] - + x[1]*y[2]*z[3] - x[1]*y[3]*z[2] - x[2]*y[1]*z[3] - + x[2]*y[3]*z[1] + x[3]*y[1]*z[2] - x[3]*y[2]*z[1]; - return std::abs(det)/6; - }; - - auto append_node = [](const std::array& X, const std::array& Y, const std::array& Z, + auto appendNode = [](const std::array& X, const std::array& Y, const std::array& Z, const double& xc, const double& yc, const double& zc ){ std::array tX; std::array tY; @@ -2026,7 +2041,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return std::make_tuple(tX,tY,tZ); }; - auto get_nodes = [](const std::array& X, const std::array& Y, const std::array& Z, + auto getNodes = [](const std::array& X, const std::array& Y, const std::array& Z, const std::array& ind){ std::array filtered_vectorX; std::array filtered_vectorY; @@ -2039,7 +2054,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return std::make_tuple(filtered_vectorX,filtered_vectorY,filtered_vectorZ); }; - auto filter_array = [](const std::vector& X, const std::vector& ind){ + auto filterArray = [](const std::vector& X, const std::vector& ind){ std::vector filtered_vectorX(ind.size(),0); for (std::size_t index = 0; index < ind.size(); index++) { filtered_vectorX[index] = X[ind[index]]; @@ -2047,75 +2062,27 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return filtered_vectorX; }; - auto calc_vol = [get_nodes,append_node, tetra_vol] + auto calcHexaVol = [getNodes, appendNode, calcTetraVol, faceConfigurations] (const auto& x, const auto& y, const auto& z, - const auto& pcX, const auto& pcY, const auto& pcZ ){ - // node order of each face - // Face 0 = {0,1,5,4} - std::array fc0_0 = {0,1,5}; - std::array fc0_1 = {1,5,4}; - // Face 1 = {0,4,6,2} - std::array fc1_0 = {0,4,6}; - std::array fc1_1 = {4,6,2}; - // Face 2 = {2,3,7,6} - std::array fc2_0 = {2,3,7}; - std::array fc2_1 = {3,7,6}; - // Face 3 = {1,3,7,5} - std::array fc3_0 = {1,3,7}; - std::array fc3_1 = {3,7,5}; - // Face 4 = {0,1,3,2} - std::array fc4_0 = {0,1,3}; - std::array fc4_1 = {1,3,2}; - // Face 5 = {4,5,7,6} - std::array fc5_0 = {4,5,7}; - std::array fc5_1 = {5,7,6}; - - std::array f0,f1,f2; + const auto& cx, const auto& cy, const auto& cz ){ // note: some CPG grids may have collapsed faces that are not planar, therefore // the hexadron is subdivided in terahedrons. - // calculating the volume of the pyramid with F0 as base and pc as center - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc0_0); - auto tetraF0 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc0_1); - tetraF0 = tetraF0 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - - // calculating the volume of the pyramid with F1 as base and pc as center - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc1_0); - auto tetraF1 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc1_1); - tetraF1 = tetraF1 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - - - // calculating the volume of the pyramid with F2 as base and pc as center - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc2_0); - auto tetraF2 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc2_1); - tetraF2 = tetraF2 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - - // calculating the volume of the pyramid with F3 as base and pc as center - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc3_0); - auto tetraF3 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc3_1); - tetraF3 = tetraF3 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - - // calculating the volume of the pyramid with F4 as base and pc as center - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc4_0); - auto tetraF4 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc4_1); - tetraF4 = tetraF4 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - - // calculating the volume of the pyramid with F5 as base and pc as center - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc5_0); - auto tetraF5 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc5_1); - tetraF5 = tetraF5 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - return tetraF0 + tetraF1 + tetraF2 + tetraF3 + tetraF4 + tetraF5; + // calculating the volume of the pyramid with F0 as base and pc as center + double totalVolume = 0.0; + for (size_t i = 0; i < faceConfigurations.size(); i += 2) { + auto [fX0, fY0, fZ0] = getNodes(x, y, z, faceConfigurations[i]); + totalVolume += std::apply(calcTetraVol, appendNode(fX0, fY0, fZ0, cx, cy, cz)); + + auto [fX1, fY1, fZ1] = getNodes(x, y, z, faceConfigurations[i + 1]); + totalVolume += std::apply(calcTetraVol, appendNode(fX1, fY1, fZ1, cx, cy, cz)); + } + return totalVolume; }; - auto is_inside = [calc_vol](const std::vector& tpX, const std::vector& tpY, const std::vector& tpZ, - const std::vector>& X, const std::vector>& Y, - const std::vector>& Z){ + auto isInsideElement = [calcHexaVol](const std::vector& tpX, const std::vector& tpY, const std::vector& tpZ, + const std::vector>& X, const std::vector>& Y, + const std::vector>& Z){ std::vector in_elements(tpX.size(),0); // check if it is insde or outside boundary box double minX, minY, minZ, maxX, maxY, maxZ; @@ -2131,7 +2098,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st pcX = std::accumulate(X[outerIndex].begin(), X[outerIndex].end(), 0.0)/8; pcY = std::accumulate(Y[outerIndex].begin(), Y[outerIndex].end(), 0.0)/8; pcZ = std::accumulate(Z[outerIndex].begin(), Z[outerIndex].end(), 0.0)/8; - element_volume = calc_vol(X[outerIndex],Y[outerIndex],Z[outerIndex], pcX, pcY,pcZ); + element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex], pcX, pcY,pcZ); for (size_t innerIndex = 0; innerIndex < tpX.size(); innerIndex++){ // check if center of refined volume is outside the boundary box of a coarse volume. // Only computes volumed base test is this condition is met. @@ -2139,9 +2106,9 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st (minY < tpY[innerIndex]) && (maxY > tpY[innerIndex]) && (minZ < tpZ[innerIndex]) && (maxZ > tpZ[innerIndex]); if (flag && (in_elements[innerIndex] == 0)) { - test_element_volume = calc_vol(X[outerIndex],Y[outerIndex],Z[outerIndex], + test_element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex], tpX[innerIndex], tpY[innerIndex],tpZ[innerIndex]); - if (test_element_volume <= element_volume){ + if (std::abs(test_element_volume - element_volume) < epslon){ in_elements[innerIndex] = static_cast(outerIndex); } } @@ -2152,10 +2119,10 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector element_centerX, element_centerY, element_centerZ; for (EclipseGridLGR& lgr_cell : lgr_children_cells) { - std::tie(element_centerX, element_centerY,element_centerZ) = get_all_cell_centers(lgr_cell, lgr_cell.getActiveMap()); - auto [host_cellX, host_cellY, host_cellZ] = get_all_cell_corners(lgr_cell.get_father_global()); - auto inside_el = is_inside(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); - auto host_cells_global_ref = filter_array(lgr_cell.get_father_global(), inside_el); + std::tie(element_centerX, element_centerY,element_centerZ) = getAllCellCenters(lgr_cell, lgr_cell.getActiveMap()); + auto [host_cellX, host_cellY, host_cellZ] = getAllCellCorners(lgr_cell.get_father_global()); + auto inside_el = isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); + auto host_cells_global_ref = filterArray(lgr_cell.get_father_global(), inside_el); lgr_cell.set_hostnum(host_cells_global_ref); } } From 6f2f02c5d7eebff475bbb2840c1c880d3e1308eb Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Wed, 30 Oct 2024 12:32:57 +0000 Subject: [PATCH 08/60] EGRID of two LGR cells working --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 62 +++++++--- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 16 ++- tests/parser/LgrOutputTests.cpp | 115 ++++++++++++++++++ 3 files changed, 172 insertions(+), 21 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 671de084ba8..7173e5c96d5 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -1898,7 +1898,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector filehead(100,0); filehead[0] = 3; // version number filehead[1] = 2007; // release year - filehead[6] = 1; // corner point grid + filehead[6] = 2; // corner point grid std::vector gridhead(100,0); gridhead[0] = 1; // corner point grid @@ -1906,7 +1906,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st gridhead[2] = dims[1]; // nJ gridhead[3] = dims[2]; // nK gridhead[24] = 1; // NUMRES - + gridhead[25] = 1; std::vector nnchead(10, 0); std::vector nnc1; std::vector nnc2; @@ -1960,8 +1960,8 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st egridfile.write("ACTNUM", m_actnum); egridfile.write("ENDGRID", endgrid); - for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { - lgr_cell.save(egridfile, nnc, units); + for (std::size_t index : m_print_order_lgr_cells) { + lgr_children_cells[index].save(egridfile, nnc, units); } if (nnc1.size() > 0){ @@ -2210,10 +2210,32 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st void EclipseGrid::init_lgr_cells(const LgrCollection& lgr_input) { save_all_lgr_labels(lgr_input); create_lgr_cells_tree(lgr_input); - init_lgr_cells_index(); - init_lgr_global_cells_index(); + //initialize LGRObjbect Indices + initializeLGRObjectIndices(0); + //parse fatherLGRObjbect Indices to children + propagateParentIndicesToLGRChildren(0); + // initialize the LGR tree indices for each refined cell. + initializeLGRTreeIndices(); + // parse the reference indices to object in the global level. + parseGlobalReferenceToChildren(); } + void EclipseGrid::propagateParentIndicesToLGRChildren(int index){ + lgr_level_father = index; + for (auto& cell : lgr_children_cells) { + cell.propagateParentIndicesToLGRChildren(lgr_level); + } + } + + int EclipseGrid::initializeLGRObjectIndices(int num){ + lgr_level = num; + num++; + for (std::size_t index :m_print_order_lgr_cells) { + num = lgr_children_cells[index].initializeLGRObjectIndices(num); + } + return num; + } + void EclipseGrid::save_all_lgr_labels(const LgrCollection& lgr_input) { all_lgr_labels.reserve(lgr_input.size()+1); all_lgr_labels.push_back("GLOBAL"); @@ -2270,8 +2292,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::array lowIJK = {lgr_cell.I1(), lgr_cell.J1(),lgr_cell.K1()}; std::array upIJK = {lgr_cell.I2(), lgr_cell.J2(),lgr_cell.K2()}; - - lgr_children_cells.emplace_back(lgr_cell.NAME(), this->lgr_label, this->lgr_level, + lgr_children_cells.emplace_back(lgr_cell.NAME(), this->lgr_label, lgr_cell.NX(), lgr_cell.NY(), lgr_cell.NZ(), father_lgr_index, lowIJK,upIJK); @@ -2289,7 +2310,8 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st lgr_active_index.resize(lgr_children_cells.size(),0); } - void EclipseGrid::init_lgr_cells_index(){ + void EclipseGrid::initializeLGRTreeIndices(){ + // initialize the LGR tree indices for each refined cell. auto set_map_scalar = [&](const auto& vec, const auto& value){ num_lgr_children_cells[vec] = value; }; @@ -2318,16 +2340,21 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st lgr_level_active_map.reserve(lgr_level_active_map.size()+1); lgr_level_active_map.insert(lgr_level_active_map.begin(),0); for (auto& lgr_cell : lgr_children_cells) { - lgr_cell.init_lgr_cells_index(); + lgr_cell.initializeLGRTreeIndices(); } } - void EclipseGrid::init_lgr_global_cells_index(){ + void EclipseGrid::parseGlobalReferenceToChildren(){ for (std::size_t index = 0; index < lgr_children_cells.size(); index++) { +<<<<<<< HEAD lgr_children_cells[index].set_lgr_global_counter(lgr_level_active_map[lgr_active_index[index]] + this->lgr_global_counter); lgr_children_cells[index].init_lgr_global_cells_index(); +======= + lgr_children_cells[index].set_lgr_global_counter(lgr_level_active_map[lgr_active_index[index]] + this->lgr_global_counter); + lgr_children_cells[index].parseGlobalReferenceToChildren(); +>>>>>>> 91119edcd (EGRID of two LGR cells working) } } @@ -2393,7 +2420,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } void EclipseGrid::updateNumericalAquiferCells(const Deck& deck) { - using AQUNUM =ParserKeywords::AQUNUM; + using AQUNUM = ParserKeywords::AQUNUM; if ( !deck.hasKeyword() ) { return; } @@ -2559,7 +2586,6 @@ namespace Opm { { init_father_global(); lgr_label= self_label; - lgr_level = father_lgr_level + 1 ; } void EclipseGridLGR::set_hostnum(std::vector& hostnum) { @@ -2570,7 +2596,8 @@ namespace Opm { { m_coord = coord; m_zcorn = zcorn; - } + } + void EclipseGridLGR::init_father_global() { std::sort(father_global.begin(),father_global.end()); @@ -2585,7 +2612,7 @@ namespace Opm { egridfile.write("LGR",lgr_name_label); //std::vector> lgr_father_name_label; std::vector lgr_father_name_label; - if (lgr_level == 1){ + if (lgr_level_father == 0){ lgr_father_name_label.push_back(""); } else { @@ -2670,11 +2697,12 @@ namespace Opm { egridfile.write("HOSTNUM", m_hostnum); egridfile.write("ENDGRID", endgrid); egridfile.write("ENDLGR", endgrid); - for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { - lgr_cell.save(egridfile, nnc, units); + for (std::size_t index: m_print_order_lgr_cells ){ + lgr_children_cells[index].save(egridfile, nnc, units); } } + void EclipseGridLGR::save_nnc(Opm::EclIO::EclOutput& egridfile) const{ std::vector nnchead(10, 0); diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 551f506b604..0122d6f1856 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -181,8 +181,6 @@ namespace Opm { void init_lgr_cells(const LgrCollection& lgr_input); void create_lgr_cells_tree(const LgrCollection& ); - void init_lgr_global_cells_index(); - void init_lgr_cells_index(); /// \brief get cell center, and center and normal of bottom face std::tuple,std::array,std::array> getCellAndBottomCenterNormal(size_t globalIndex) const; @@ -264,6 +262,7 @@ namespace Opm { std::size_t lgr_global_counter = 0; std::string lgr_label = "GLOBAL"; int lgr_level = 0; + int lgr_level_father = 0; std::vector lgr_children_labels; std::vector lgr_active_index; std::vector lgr_level_active_map; @@ -272,7 +271,7 @@ namespace Opm { std::vector m_zcorn; std::vector m_coord; std::vector m_actnum; - + std::vector m_print_order_lgr_cells; // Input grid data. mutable std::optional> m_input_zcorn; mutable std::optional> m_input_coord; @@ -312,7 +311,10 @@ namespace Opm { // Radial grids need this for volume calculations. std::optional> m_thetav; std::optional> m_rv; - + void parseGlobalReferenceToChildren(void); + int initializeLGRObjectIndices(int); + void initializeLGRTreeIndices(void); + void propagateParentIndicesToLGRChildren(int); void updateNumericalAquiferCells(const Deck&); double computeCellGeometricDepth(size_t globalIndex) const; @@ -366,8 +368,14 @@ namespace Opm { using vec_size_t = std::vector; EclipseGridLGR() = default; EclipseGridLGR(const std::string& self_label, const std::string& father_label_, +<<<<<<< HEAD int father_lgr_level, size_t nx, size_t ny, size_t nz, const vec_size_t& father_lgr_index); +======= + size_t nx, size_t ny, size_t nz, + vec_size_t father_lgr_index, std::array low_fahterIJK_, + std::array up_fahterIJK_); +>>>>>>> 91119edcd (EGRID of two LGR cells working) ~EclipseGridLGR() = default; const vec_size_t& getFatherGlobalID() const; void set_lgr_global_counter(std::size_t counter){ diff --git a/tests/parser/LgrOutputTests.cpp b/tests/parser/LgrOutputTests.cpp index 1a21619e720..a3db079e442 100644 --- a/tests/parser/LgrOutputTests.cpp +++ b/tests/parser/LgrOutputTests.cpp @@ -255,3 +255,118 @@ SCHEDULE BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); } } + + +BOOST_AUTO_TEST_CASE(TestLgrOutputDoubleLGR) { + const std::string deck_string = R"( +RUNSPEC + +DIMENS + 3 3 1 / + +GRID + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +'LGR1' 2 2 2 2 1 1 2 2 1 / +ENDFIN + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +'LGR2' 2 2 1 1 1 1 2 2 1 / +ENDFIN + +DX + 9*1000 / +DY + 9*1000 / +DZ + 9*20 / + +TOPS + 9*8325 / + +PORO + 9*0.15 / + +PERMX + 9*1 / + +COPY + PERMX PERMZ / + PERMX PERMY / +/ + +EDIT + +OIL +GAS + +TITLE +The title + +START +16 JUN 1988 / + +PROPS + +REGIONS + +SOLUTION + +SCHEDULE +)"; +\ + Opm::UnitSystem units(1); + std::vector vecNNC; + std::array global_grid_dim = {3,3,1}; + std::vector coord_g, zcorn_g, coord_l1, zcorn_l1, coord_l2, zcorn_l2, + coord_g_opm, zcorn_g_opm, coord_l1_opm, zcorn_l1_opm, coord_l2_opm, zcorn_l2_opm; + // Intialize LgrCollection from string. + LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); + // Read global COORD and ZCORN from reference simulator output. + std::tie(coord_g, zcorn_g) = read_cpg_from_egrid("CARFIN-DOUBLE.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l1, zcorn_l1) = read_cpg_from_egrid("CARFIN-DOUBLE.EGRID", "LGR1"); + std::tie(coord_l2, zcorn_l2) = read_cpg_from_egrid("CARFIN-DOUBLE.EGRID", "LGR2"); + + // Eclipse Grid is intialzied with COORD and ZCORN. + Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); + // LgrCollection is used to initalize LGR Cells in the Eclipse Grid. + eclipse_grid_file.init_lgr_cells(lgr_col); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) + eclipse_grid_file.lgr_children_cells[1].set_lgr_refinement(coord_l1,zcorn_l1); + eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l2,zcorn_l2); + // Intialize host_cell numbering. + eclipse_grid_file.init_children_host_cells(); + // Save EclipseGrid. + eclipse_grid_file.save("OPMCARFIN-DOUBLE.EGRID",false,vecNNC,units); + // Once the new EGRID is saved, another EclipseGrid Object is created for the sake of comparison. + std::tie(coord_g_opm, zcorn_g_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l1_opm, zcorn_l1_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "LGR1"); + std::tie(coord_l2_opm, zcorn_l2_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "LGR2"); + // Eclipse Grid is intialzied with COORD and ZCORN. + Opm::EclipseGrid eclipse_grid_OPM(global_grid_dim, coord_g_opm, zcorn_g_opm); +// LgrCollection is used to initalize LGR Cells in the Eclipse Grid. + eclipse_grid_OPM.init_lgr_cells(lgr_col); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) + eclipse_grid_OPM.lgr_children_cells[1].set_lgr_refinement(coord_l1_opm,zcorn_l1_opm); + eclipse_grid_OPM.lgr_children_cells[0].set_lgr_refinement(coord_l2_opm,zcorn_l2_opm); + + // Intialize host_cell numbering. + eclipse_grid_OPM.init_children_host_cells(); + BOOST_CHECK_EQUAL( coord_g_opm.size() , coord_g.size()); + BOOST_CHECK_EQUAL( zcorn_g_opm.size() , zcorn_g.size()); + BOOST_CHECK_EQUAL( coord_l1_opm.size() , coord_l1.size()); + BOOST_CHECK_EQUAL( zcorn_l1_opm.size() , zcorn_l1.size()); + BOOST_CHECK_EQUAL( coord_l2_opm.size() , coord_l2.size()); + BOOST_CHECK_EQUAL( zcorn_l2_opm.size() , zcorn_l2.size()); + std::size_t index ; + for (index = 0; index < coord_g.size(); index++) { + BOOST_CHECK_EQUAL( coord_g_opm[index] , coord_g[index]); + } + for (index = 0; index < zcorn_g.size(); index++) { + BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); + } + } From 6a5d1493c2c51e683b6580aeebc45468bca0a4d5 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Fri, 15 Nov 2024 10:23:34 +0000 Subject: [PATCH 09/60] add tests to LgrOutputTests --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 1 + opm/io/eclipse/EGrid.cpp | 2 +- tests/parser/LgrOutputTests.cpp | 116 ++++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 7173e5c96d5..678548bda8a 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -2124,6 +2124,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st auto inside_el = isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); auto host_cells_global_ref = filterArray(lgr_cell.get_father_global(), inside_el); lgr_cell.set_hostnum(host_cells_global_ref); + lgr_cell.init_children_host_cells(); } } diff --git a/opm/io/eclipse/EGrid.cpp b/opm/io/eclipse/EGrid.cpp index 926d0183d58..39552c61ca1 100644 --- a/opm/io/eclipse/EGrid.cpp +++ b/opm/io/eclipse/EGrid.cpp @@ -474,7 +474,7 @@ std::vector> EGrid::getXYZ_layer(int layer, bool bottom) } -std::vector EGrid::get_zcorn_from_disk(int layer, bool bottom) +std::vector EGrid:: get_zcorn_from_disk(int layer, bool bottom) { if (formatted) throw std::invalid_argument("partial loading of zcorn arrays not possible when using formatted input"); diff --git a/tests/parser/LgrOutputTests.cpp b/tests/parser/LgrOutputTests.cpp index a3db079e442..262ea1cc8b9 100644 --- a/tests/parser/LgrOutputTests.cpp +++ b/tests/parser/LgrOutputTests.cpp @@ -370,3 +370,119 @@ SCHEDULE BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); } } + + + +BOOST_AUTO_TEST_CASE(TestLgrOutputNESTED) { + const std::string deck_string = R"( +RUNSPEC + +DIMENS + 3 3 1 / + +GRID + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +LGR1 2 2 2 2 1 1 3 3 1 1* GLOBAL/ +ENDFIN + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +LGR2 2 2 2 2 1 1 3 3 1 1* LGR1/ +ENDFIN + +DX + 9*1000 / +DY + 9*1000 / +DZ + 9*20 / + +TOPS + 9*8325 / + +PORO + 9*0.15 / + +PERMX + 9*1 / + +COPY + PERMX PERMZ / + PERMX PERMY / +/ + +EDIT + +OIL +GAS + +TITLE +The title + +START +16 JUN 1988 / + +PROPS + +REGIONS + +SOLUTION + +SCHEDULE +)"; +\ + Opm::UnitSystem units(1); + std::vector vecNNC; + std::array global_grid_dim = {3,3,1}; + std::vector coord_g, zcorn_g, coord_l1, zcorn_l1, coord_l2, zcorn_l2, + coord_g_opm, zcorn_g_opm, coord_l1_opm, zcorn_l1_opm, coord_l2_opm, zcorn_l2_opm; + // Intialize LgrCollection from string. + LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); + // Read global COORD and ZCORN from reference simulator output. + std::tie(coord_g, zcorn_g) = read_cpg_from_egrid("CARFIN-NESTED.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l1, zcorn_l1) = read_cpg_from_egrid("CARFIN-NESTED.EGRID", "LGR1"); + std::tie(coord_l2, zcorn_l2) = read_cpg_from_egrid("CARFIN-NESTED.EGRID", "LGR2"); + + // Eclipse Grid is intialzied with COORD and ZCORN. + Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); + // LgrCollection is used to initalize LGR Cells in the Eclipse Grid. + eclipse_grid_file.init_lgr_cells(lgr_col); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) + eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l1,zcorn_l1); + eclipse_grid_file.lgr_children_cells[0].lgr_children_cells[0].set_lgr_refinement(coord_l2,zcorn_l2); + // Intialize host_cell numbering. + eclipse_grid_file.init_children_host_cells(); + // Save EclipseGrid. + eclipse_grid_file.save("OPMCARFIN-NESTED.EGRID",false,vecNNC,units); +// // Once the new EGRID is saved, another EclipseGrid Object is created for the sake of comparison. +// std::tie(coord_g_opm, zcorn_g_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "global"); +// // Read LGR CELL COORD and ZCORN from reference simulator output. +// std::tie(coord_l1_opm, zcorn_l1_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "LGR1"); +// std::tie(coord_l2_opm, zcorn_l2_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "LGR2"); +// // Eclipse Grid is intialzied with COORD and ZCORN. +// Opm::EclipseGrid eclipse_grid_OPM(global_grid_dim, coord_g_opm, zcorn_g_opm); +// // LgrCollection is used to initalize LGR Cells in the Eclipse Grid. +// eclipse_grid_OPM.init_lgr_cells(lgr_col); +// // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) +// eclipse_grid_OPM.lgr_children_cells[1].set_lgr_refinement(coord_l1_opm,zcorn_l1_opm); +// eclipse_grid_OPM.lgr_children_cells[0].set_lgr_refinement(coord_l2_opm,zcorn_l2_opm); + +// // Intialize host_cell numbering. +// eclipse_grid_OPM.init_children_host_cells(); +// BOOST_CHECK_EQUAL( coord_g_opm.size() , coord_g.size()); +// BOOST_CHECK_EQUAL( zcorn_g_opm.size() , zcorn_g.size()); +// BOOST_CHECK_EQUAL( coord_l1_opm.size() , coord_l1.size()); +// BOOST_CHECK_EQUAL( zcorn_l1_opm.size() , zcorn_l1.size()); +// BOOST_CHECK_EQUAL( coord_l2_opm.size() , coord_l2.size()); +// BOOST_CHECK_EQUAL( zcorn_l2_opm.size() , zcorn_l2.size()); +// std::size_t index ; +// for (index = 0; index < coord_g.size(); index++) { +// BOOST_CHECK_EQUAL( coord_g_opm[index] , coord_g[index]); +// } +// for (index = 0; index < zcorn_g.size(); index++) { +// BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); +// } + } From c2292c8adfd7a5520f1b4d3127bcaa7a38920df5 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 21 Nov 2024 13:40:32 +0000 Subject: [PATCH 10/60] Development of the routines for exporting EGRID compartible with LGR --- tests/CARFIN-COLUMN.EGRID | Bin 0 -> 3412 bytes tests/CARFIN-DOUBLE.EGRID | Bin 0 -> 4540 bytes tests/CARFIN-NESTED.EGRID | Bin 0 -> 5308 bytes tests/CARFIN5.EGRID | Bin 0 -> 3524 bytes tests/parser/LgrOutputTests.cpp | 34 ++------------------------------ 5 files changed, 2 insertions(+), 32 deletions(-) create mode 100644 tests/CARFIN-COLUMN.EGRID create mode 100644 tests/CARFIN-DOUBLE.EGRID create mode 100644 tests/CARFIN-NESTED.EGRID create mode 100644 tests/CARFIN5.EGRID diff --git a/tests/CARFIN-COLUMN.EGRID b/tests/CARFIN-COLUMN.EGRID new file mode 100644 index 0000000000000000000000000000000000000000..d7c0fcc70fad0fcc796dc928c6b8bd7f4f9b2801 GIT binary patch literal 3412 zcmeHJv2qhJ5S0x{94ZwQDP2&wg_ee!yUX3p7+pp#JX5xb9~p^KW(zQbB?AVZ2Y}g zHjJd+} znh$7*P2!G7QJk@`f`ty`uC;l{B_X1k#y{Etn*je(7ah>LYI@X>f IV;$|{Cw{peLI3~& literal 0 HcmV?d00001 diff --git a/tests/CARFIN-DOUBLE.EGRID b/tests/CARFIN-DOUBLE.EGRID new file mode 100644 index 0000000000000000000000000000000000000000..ebbd03fbb74da08c83e7fcb57136d755f6cf43d1 GIT binary patch literal 4540 zcmeHKJ#*7Q5IvhD7%CMMlrAXJLP0~NkrZ1qMq-3B%urF}S5WyU@PGIt>G>B_ytle{ z-iSEPV1;o8Zsun9-tNA=58X-%A!HZzs#;cg8A7>-@UzBZER}KA7o&R~=6y`mYW&5e2p{o~5 z5+d%LT+F-UIhnwYXT>`8u^Txbf_LnB9tmInoD^-_mHqjB>8gB%$?;xqZkuHJH3W7w z>4yIl3ZJMGuikBvLAsBV(Kz5QNnE-~a8eo`b&km?T)M`Z$1p}X{ir7iJ^4o5I3q4y z{2Z(K+`{RXaBw6%>aq)`lz%*f>~qm}ylBX?bmud_n7#>*n&k z?ccNQdn>$xP4(g~Nx!UWN|rV91;>%C79CE;xF@b=&Vav;_>A!wf5S)b#`aE7AE!pEI`mJ`p-QLY`ZS@3qpG~^S@7r2cM%{4K14{FcdWwUe z;jpI|#tM&m;t@_B+8D=H%;o35dCGop|%Wb%OVI%%*)Kr>{j`A2Z)0 z=h|Nm9)ZfvB$Gd9dsGC1x3pb`No`mCmCmi;KM_oLWDIaw4Bz#a)5)K~o z?c@KoI-&QZrSY}eXsePOfZknign_#8#Vui?%3zt5xw>2Bx{;BU)S$VTcisdj^FFc z-yJf)2!UNq*!Uk}k>i+r@$52A2zS?M(ln5-NM6_?G#QO|%rP~^3u~-%^w)@I9&wDo zG1qz1bY58c9IJKr7SFuMLnHEzH7}k~`CfzMb=I`}qG6wTr#`c@>BF#F{T%1nosRqC zoh50utXI$N{*HhBZiPpflV5C#%u9+or>#*hbTpDh*`hM0J?VJn5%|Z>A8|d#FVfb$ z^-7*CUaz;jExeOw9<%8VsL9`Lc5+>e;l8bJV6%6cpWwUCCT#J;$4`vLJ2w8?Y883M z#=|Ef@7Q=~x{1kX83&F@Ax&}8?X&|rnPqr(9!et72gLhfA8}P_x%T*eNTPQ zyNHL5>EC)saS!;|=lFb1%ry!2DX-C^mb#vu8L6dCEp_Q_x|bopDSvt|+&9H}`t{(R WTht>}Jx03URCVm@>24VZ-S1B&gg%%6 literal 0 HcmV?d00001 diff --git a/tests/CARFIN5.EGRID b/tests/CARFIN5.EGRID new file mode 100644 index 0000000000000000000000000000000000000000..a1d5a0e9c406a4fb27027fcc44a885f6111b3f1e GIT binary patch literal 3524 zcmeHJF^<$g5S(2&?hX++-~k&DTzHTYS+>u%w2YD26%rA_z2c&K0xz#++)*hR#_9@*2CC0k@Y88{Y4)utDfh2cpEt|_H9Q& z%)6i#*S+UCSzsK`iUsk$8#Vuh?!NbVAbQhtQVqjcPxtqJY|1q@$M^d7u1(fAAu!a0 zjsGSVHIB(QFK^R;a6V6irh$58^1_y($!xr1_NggeSbgndK1V$3h*Jhmwa%NS^TN_+ zUoBr-JnIqT8v8k%!1?jain7|o?JGOK z^B>=>@C;+}i(Q#@MH6e<8udb^QLNh$H)Gn1%rnoxKX?9&^U;4@j^?dD)!F1}zSaGK zcXH4BY&rvK^1IC-mt%B~Z90M7-f4baB{Fm)E@s5p$PbA*4@zAI- z-*g-sPfhWTji;t~$Hr4ryyK*gx}>i?QB%C*q%WSes;8!S$4MXkq|dRNX)no}sV|;- zs&{Pl92f7H{LwrA&WHEuo!#)p3>cR(_umt6zlxpy3tu)1=8fmR9Am{_&=u&%8PESy zw%_qi` vecNNC; std::array global_grid_dim = {3,3,1}; @@ -210,7 +210,7 @@ SOLUTION SCHEDULE )"; -\ + Opm::UnitSystem units(1); std::vector vecNNC; std::array global_grid_dim = {3,3,1}; @@ -316,7 +316,6 @@ SOLUTION SCHEDULE )"; -\ Opm::UnitSystem units(1); std::vector vecNNC; std::array global_grid_dim = {3,3,1}; @@ -432,7 +431,6 @@ SOLUTION SCHEDULE )"; -\ Opm::UnitSystem units(1); std::vector vecNNC; std::array global_grid_dim = {3,3,1}; @@ -457,32 +455,4 @@ SCHEDULE eclipse_grid_file.init_children_host_cells(); // Save EclipseGrid. eclipse_grid_file.save("OPMCARFIN-NESTED.EGRID",false,vecNNC,units); -// // Once the new EGRID is saved, another EclipseGrid Object is created for the sake of comparison. -// std::tie(coord_g_opm, zcorn_g_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "global"); -// // Read LGR CELL COORD and ZCORN from reference simulator output. -// std::tie(coord_l1_opm, zcorn_l1_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "LGR1"); -// std::tie(coord_l2_opm, zcorn_l2_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "LGR2"); -// // Eclipse Grid is intialzied with COORD and ZCORN. -// Opm::EclipseGrid eclipse_grid_OPM(global_grid_dim, coord_g_opm, zcorn_g_opm); -// // LgrCollection is used to initalize LGR Cells in the Eclipse Grid. -// eclipse_grid_OPM.init_lgr_cells(lgr_col); -// // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) -// eclipse_grid_OPM.lgr_children_cells[1].set_lgr_refinement(coord_l1_opm,zcorn_l1_opm); -// eclipse_grid_OPM.lgr_children_cells[0].set_lgr_refinement(coord_l2_opm,zcorn_l2_opm); - -// // Intialize host_cell numbering. -// eclipse_grid_OPM.init_children_host_cells(); -// BOOST_CHECK_EQUAL( coord_g_opm.size() , coord_g.size()); -// BOOST_CHECK_EQUAL( zcorn_g_opm.size() , zcorn_g.size()); -// BOOST_CHECK_EQUAL( coord_l1_opm.size() , coord_l1.size()); -// BOOST_CHECK_EQUAL( zcorn_l1_opm.size() , zcorn_l1.size()); -// BOOST_CHECK_EQUAL( coord_l2_opm.size() , coord_l2.size()); -// BOOST_CHECK_EQUAL( zcorn_l2_opm.size() , zcorn_l2.size()); -// std::size_t index ; -// for (index = 0; index < coord_g.size(); index++) { -// BOOST_CHECK_EQUAL( coord_g_opm[index] , coord_g[index]); -// } -// for (index = 0; index < zcorn_g.size(); index++) { -// BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); -// } } From 4b9c3a42f36c8d1ab82d2368ff7688c1e121e90b Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Wed, 4 Dec 2024 14:43:13 +0000 Subject: [PATCH 11/60] fixed merging problems from previous rebase --- opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp | 10 +++------- opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp | 7 ++----- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 678548bda8a..6bc4db5ac57 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -2348,14 +2348,9 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st void EclipseGrid::parseGlobalReferenceToChildren(){ for (std::size_t index = 0; index < lgr_children_cells.size(); index++) { -<<<<<<< HEAD lgr_children_cells[index].set_lgr_global_counter(lgr_level_active_map[lgr_active_index[index]] + this->lgr_global_counter); - lgr_children_cells[index].init_lgr_global_cells_index(); -======= - lgr_children_cells[index].set_lgr_global_counter(lgr_level_active_map[lgr_active_index[index]] + this->lgr_global_counter); lgr_children_cells[index].parseGlobalReferenceToChildren(); ->>>>>>> 91119edcd (EGRID of two LGR cells working) } } @@ -2581,8 +2576,9 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st namespace Opm { EclipseGridLGR::EclipseGridLGR(const std::string& self_label, const std::string& father_label_, - int father_lgr_level, std::size_t nx, std::size_t ny, - std::size_t nz, const vec_size_t& father_lgr_index) + std::size_t nx, std::size_t ny, std::size_t nz, + vec_size_t father_lgr_index, std::array low_fahterIJK_, + std::array up_fahterIJK_) : EclipseGrid(nx,ny,nz), father_label(father_label_), father_global(father_lgr_index) { init_father_global(); diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 0122d6f1856..4308c373c39 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -368,16 +368,13 @@ namespace Opm { using vec_size_t = std::vector; EclipseGridLGR() = default; EclipseGridLGR(const std::string& self_label, const std::string& father_label_, -<<<<<<< HEAD - int father_lgr_level, size_t nx, size_t ny, size_t nz, - const vec_size_t& father_lgr_index); -======= size_t nx, size_t ny, size_t nz, vec_size_t father_lgr_index, std::array low_fahterIJK_, std::array up_fahterIJK_); ->>>>>>> 91119edcd (EGRID of two LGR cells working) ~EclipseGridLGR() = default; const vec_size_t& getFatherGlobalID() const; + void save(Opm::EclIO::EclOutput&, const std::vector&, const Opm::UnitSystem&) const; + void save_nnc(Opm::EclIO::EclOutput&) const; void set_lgr_global_counter(std::size_t counter){ lgr_global_counter = counter; } From 197ab9ae1696c12c9a7e5ebf937f5bf407e7900b Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 5 Dec 2024 08:34:14 +0000 Subject: [PATCH 12/60] EclipseGrid::save outputs EGRIDs for meshes with LGR --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 6bc4db5ac57..8ce5fd0bf80 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -2300,14 +2300,24 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st lgr_children_cells.back().create_lgr_cells_tree(lgr_input); } } - std::sort(lgr_children_cells.begin(), lgr_children_cells.end(), - [](const EclipseGridLGR& a, const EclipseGridLGR& b) { - return a.get_father_global()[0] < b.get_father_global()[0]; // Sort by another property - }); + EclipseGridLGR::vec_size_t father_label_sorting(lgr_children_cells.size(),0); + m_print_order_lgr_cells.resize(lgr_children_cells.size()); + std::iota(m_print_order_lgr_cells.begin(), m_print_order_lgr_cells.end(), 0); // + std::transform(lgr_children_cells.begin(), lgr_children_cells.end(), father_label_sorting.begin(), + [](const auto& cell){return cell.get_father_global()[0];}); + + std::sort(m_print_order_lgr_cells.begin(), m_print_order_lgr_cells.end(), [&](std::size_t i1, std::size_t i2) { + return father_label_sorting[i1] < father_label_sorting[i2]; // + }); + + std::sort(lgr_children_cells.begin(), lgr_children_cells.end(),[](const EclipseGridLGR& a, const EclipseGridLGR& b) { + return a.get_father_global()[0] < b.get_father_global()[0]; // + }); + lgr_children_labels.reserve(lgr_children_cells.size()); - std::transform(lgr_children_cells.begin(), lgr_children_cells.end(), - std::back_inserter(lgr_children_labels), - [](const auto& lgr_cell) { return lgr_cell.lgr_label; }); + for (auto lgr_cell : lgr_children_cells) { + lgr_children_labels.emplace_back(lgr_cell.lgr_label); + } lgr_active_index.resize(lgr_children_cells.size(),0); } From 487691b1dcb9b0cda1a23d7108a3d5f10e9fa06d Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Fri, 13 Dec 2024 09:47:04 +0000 Subject: [PATCH 13/60] fixed minor performance bugs --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 27 ++++++++++--------- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 13 +++++---- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 8ce5fd0bf80..07367ba6a72 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -17,12 +17,11 @@ along with OPM. If not, see . */ -#include "opm/io/eclipse/PaddedOutputString.hpp" +#include #include #include #include #include -#include #include #define _USE_MATH_DEFINES @@ -38,7 +37,7 @@ #include #include - +#include #include #include @@ -1898,14 +1897,14 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector filehead(100,0); filehead[0] = 3; // version number filehead[1] = 2007; // release year - filehead[6] = 2; // corner point grid + filehead[6] = 1; // corner point grid std::vector gridhead(100,0); gridhead[0] = 1; // corner point grid gridhead[1] = dims[0]; // nI gridhead[2] = dims[1]; // nJ gridhead[3] = dims[2]; // nK - gridhead[24] = 1; // NUMRES + gridhead[24] = 1; // NUMRES (number of reservoirs) gridhead[25] = 1; std::vector nnchead(10, 0); std::vector nnc1; @@ -1959,7 +1958,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st egridfile.write("ACTNUM", m_actnum); egridfile.write("ENDGRID", endgrid); - + // nnc for LGR is not currently supported. for (std::size_t index : m_print_order_lgr_cells) { lgr_children_cells[index].save(egridfile, nnc, units); } @@ -1967,7 +1966,9 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st if (nnc1.size() > 0){ egridfile.write("NNCHEAD", nnchead); egridfile.write("NNC1", nnc1); - egridfile.write("NNC2", nnc2); + egridfile.write("NNC2", nnc2); + // Placeholder the method that handles LGR nnc + // nnc in LGR is currently not supportd // for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { // lgr_cell.save_nnc(egridfile); // } @@ -2587,8 +2588,8 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st namespace Opm { EclipseGridLGR::EclipseGridLGR(const std::string& self_label, const std::string& father_label_, std::size_t nx, std::size_t ny, std::size_t nz, - vec_size_t father_lgr_index, std::array low_fahterIJK_, - std::array up_fahterIJK_) + vec_size_t father_lgr_index, const std::array& low_fahterIJK_, + const std::array& up_fahterIJK_) : EclipseGrid(nx,ny,nz), father_label(father_label_), father_global(father_lgr_index) { init_father_global(); @@ -2599,7 +2600,7 @@ namespace Opm { std::transform(hostnum.begin(),hostnum.end(), hostnum.begin(), [](int a){return a+1;}); m_hostnum = hostnum; } - void EclipseGridLGR::set_lgr_refinement(std::vector coord, std::vector zcorn) + void EclipseGridLGR::set_lgr_refinement(const std::vector& coord, const std::vector& zcorn) { m_coord = coord; m_zcorn = zcorn; @@ -2680,9 +2681,9 @@ namespace Opm { gridhead[31] = up_fahterIJK[1] + 1; // Upper J-index-host gridhead[32] = up_fahterIJK[2] + 1; // Upper K-index-host - std::vector nnchead(10, 0); - std::vector nnc1; - std::vector nnc2; + [[maybe_unused]] std::vector nnchead(10, 0); + [[maybe_unused]] std::vector nnc1; + [[maybe_unused]] std::vector nnc2; for (const NNCdata& n : nnc ) { nnc1.push_back(n.cell1 + 1); diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 4308c373c39..4c9cefe8079 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -33,12 +33,15 @@ #include #include #include -#include + namespace Opm { class Deck; - namespace EclIO { class EclFile; } + namespace EclIO { + class EclFile; + class EclOutput; + } struct NNCdata; class UnitSystem; class ZcornMapper; @@ -369,8 +372,8 @@ namespace Opm { EclipseGridLGR() = default; EclipseGridLGR(const std::string& self_label, const std::string& father_label_, size_t nx, size_t ny, size_t nz, - vec_size_t father_lgr_index, std::array low_fahterIJK_, - std::array up_fahterIJK_); + vec_size_t father_lgr_index, const std::array& low_fahterIJK_, + const std::array& up_fahterIJK_); ~EclipseGridLGR() = default; const vec_size_t& getFatherGlobalID() const; void save(Opm::EclIO::EclOutput&, const std::vector&, const Opm::UnitSystem&) const; @@ -382,7 +385,7 @@ namespace Opm { return father_global; } void set_hostnum(std::vector&); - void set_lgr_refinement(std::vector,std::vector); + void set_lgr_refinement(const std::vector&, const std::vector &); private: void init_father_global(); std::string father_label; From 6e38504e0a4f836f0fb0ee5872c2268625c106b5 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Fri, 13 Dec 2024 13:07:04 +0000 Subject: [PATCH 14/60] Test Files for LgrOutputTest added and registered at CMakeLists_files --- CMakeLists_files.cmake | 5 ++++- tests/OPMCARFIN-COLUMN.EGRID | Bin 0 -> 3108 bytes tests/OPMCARFIN-DOUBLE.EGRID | Bin 0 -> 3868 bytes tests/OPMCARFIN-NESTED.EGRID | Bin 0 -> 4604 bytes tests/OPMCARFIN5.EGRID | Bin 0 -> 3172 bytes 5 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/OPMCARFIN-COLUMN.EGRID create mode 100644 tests/OPMCARFIN-DOUBLE.EGRID create mode 100644 tests/OPMCARFIN-NESTED.EGRID create mode 100644 tests/OPMCARFIN5.EGRID diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index bb6eed25a99..14ce38d5e59 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -737,7 +737,10 @@ if(ENABLE_ECL_OUTPUT) tests/msim/action_count_no_run_function.py tests/msim/open_well_past.py tests/msim/open_well_too_late.py - tests/VFP_CASE.DATA) + tests/CARFIN-COLUMN.EGRID + tests/CARFIN-DOUBLE.EGRID + tests/CARFIN-NESTED.EGRID + tests/CARFIN5.EGRID) endif() list (APPEND EXAMPLE_SOURCE_FILES diff --git a/tests/OPMCARFIN-COLUMN.EGRID b/tests/OPMCARFIN-COLUMN.EGRID new file mode 100644 index 0000000000000000000000000000000000000000..bfd9b6bd4ef2e8e2d9f8b60386eff7312f1858ad GIT binary patch literal 3108 zcmeHIJ5Iwu6nqItgl-ECkb(1n$E@xJxQ#o_Cgw`89k3 z;z_GFJMUwAUv^?<;dC~yr*%=8+0Cq3*6_h>a1Xy@w)Y6%w?Uuy-+#vm_)Nm2omH33 zY>6ih%W2WVV_p`{>SbGBjFX9H{u}e<95G{GUolhm{EEJ4`xmX7Z@E~s6{d(Uyl(4a z4$u3zf`4Jvof(%**!i_s)JZa&j&KI7Bjfo<2i!TW5_ z!ugFcn^2U?=JL#c-}}%1H+G1a^x{3wyihk4WsUtT>k;OY*7XncAk)SX_#+0ukFc0` zUbGE0bR*A;v%C+qbBOv~_J|Aa(=6{P-1ndMu;1V4g?3(Lck}kO@8exBaqnfqbVfK#8yd!NXAUF3!7Y0_Zf)MxGC z?puMqj_(wC-$x!-foGj-DL%%*T3WaJ#)fzap58g{82si RDPLaymVSbF2}MoP)hB^50+av% literal 0 HcmV?d00001 diff --git a/tests/OPMCARFIN-DOUBLE.EGRID b/tests/OPMCARFIN-DOUBLE.EGRID new file mode 100644 index 0000000000000000000000000000000000000000..593978980fc1aee4f608738b3640862f3a765449 GIT binary patch literal 3868 zcmeHJL2eU45NsO|;kHOTzz0462QHjeyPMdOy+#}7!U+jmAPz`Ggaao(f&cIj@)k~1 zwWr#{Mj@cYC<3=M>YnQA-u1MnY%?nkC(~x!l(m^HC+(tvFU$sC;P05-{|4W;K_A%f z|HcXUOp2p!QlGSw1)eyp#$^YOd08=Q7F}~Z3KLHLCG+JRF=Jo5m??YiqA%M1i?*3> zHJ^7irif4Ys%y$AJn!Qg{({w?&A4QW9se#AoD>spp06XJIImOEdw?%bT(Nufq<1{U z+_R@}#oFsV`ZdDIV;mlFa1-u56RueOxtHb77EWH^=n;5|l^0Ggewsn?vYL18WKj4v?nwFem~g$-q>U0q!+*PcCc$mQQ>#{OSsJU@1kz`oDF z2P|LCzf2E+yCk6IcXi_Fj&*{1ag(O=V^5yT@a)6u;c|8Q4pR3J`@K%^WWui22~m0P zXu6l1-R6!4p6;seQ|x@yR@t7h`UH;q9XRrVr&xXH<9UeHC-9!81dcw=-PHeYI-%cY I`9Ic)A94*%MF0Q* literal 0 HcmV?d00001 diff --git a/tests/OPMCARFIN-NESTED.EGRID b/tests/OPMCARFIN-NESTED.EGRID new file mode 100644 index 0000000000000000000000000000000000000000..8735a7e8cb305c2ecabb178161d09cc37e5a3649 GIT binary patch literal 4604 zcmeH}F>ez=6ol7CD52X(6i8_-M3Vw3p+i)b?_yhWY;>_DL`9K5kT#WD8U!VO03@i8 z_yshyL;{7MK~2TX^P9(Egp+`Sk|--}-rTou=gznBBq^o5-5->_vR$N<_WHwdiJDVt zJV(8j(#jF){AkRBtLy*q2JB37x9S&@VSkJ}Haop`g^Ke^d8Zs#-)559_Uvkm$nK|R^zUDO;2%YUF$jK_lUEPIx2MZIyX<}((>oEM*ZI6>StgZ#KNs)n=k>DA7swcWg#&ez<-^PHcF_t(PNfQV_$ns*9=59?GxV1}+g$5AMRxL;mpSwf(zm;} zzO1jMmBWqvH6LxPZRW$R{CWM|GH-VAy%uMu66FtRUhrc*`)lW}x*Wr)r@aNjW>{%k4 z=`T({^}Duyu8X@S$JcC%A6MD=mwAl$*W&wIMt1f_yB5Iko6q0tV8_jc`HNh(2!_u| zbNSv$a(O<#Pm#+_KFbnE<@o>$zPmIoSx#Y!(W{K>Zd>Y!k>HOFV0?ZR&m$i nFHV21(TD!H4u7u6U!4Bp+$Zij{KeVp{a3mCZ~q@(_fD~MSn#ziuI8x#u$7!f2a*9+r0;iyW%g}KbD*m6$UyKn! zpacb!m6rMYcKp5UB$E(AG8m2XB2Tjr!eUg`Ibsq*=MM2Wgwtol_UN?1Vf`C7U^PjG z)hL^nqZ)5K>KAE+h%}3?{7>r3I-?R29+A7&zBr@uy#~ome_EC6`V@`&^ae-gVZY`A z=h>f$`|F`LN!qW=`NTfoXK%kZ;R1W=7n>sUlDy2=*60@+9?5uES^op>GQU*pG34J>K6odS@}6Sp$Y&yZ@emeKj}s NU-V^b!SIQF`4!#$H;w=R literal 0 HcmV?d00001 From 6c41b333e43c528b6669842d7269e42781314359 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Fri, 13 Dec 2024 13:38:04 +0000 Subject: [PATCH 15/60] registering tests/VFP_CASE.DATA back - previous commit it the line that register it was mistakenly removed --- CMakeLists_files.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 14ce38d5e59..8273d2c121f 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -737,6 +737,7 @@ if(ENABLE_ECL_OUTPUT) tests/msim/action_count_no_run_function.py tests/msim/open_well_past.py tests/msim/open_well_too_late.py + tests/VFP_CASE.DATA tests/CARFIN-COLUMN.EGRID tests/CARFIN-DOUBLE.EGRID tests/CARFIN-NESTED.EGRID From 22f837acfb532ff6e03aa526b5016a573f6a1dbc Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 10:17:43 +0000 Subject: [PATCH 16/60] created VectorUtil and GeometricUtil libraries converting lambda functions used in EclipseGrid::init_children_host_cells --- CMakeLists_files.cmake | 4 + .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 142 +----------------- 2 files changed, 11 insertions(+), 135 deletions(-) diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 8273d2c121f..8205235741b 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -44,6 +44,8 @@ list (APPEND MAIN_SOURCE_FILES opm/common/utility/parameters/ParameterRequirement.cpp opm/common/utility/parameters/ParameterTools.cpp opm/common/utility/numeric/calculateCellVol.cpp + opm/common/utility/numeric/GeometryUtil.cpp + opm/common/utility/numeric/VectorUtil.cpp opm/common/utility/numeric/MonotCubicInterpolator.cpp opm/common/utility/numeric/RootFinders.cpp opm/material/common/Spline.cpp @@ -830,6 +832,8 @@ list( APPEND PUBLIC_HEADER_FILES opm/common/utility/numeric/cmp.hpp opm/common/utility/numeric/blas_lapack.h opm/common/utility/numeric/calculateCellVol.hpp + opm/common/utility/numeric/GeometryUtil.hpp + opm/common/utility/numeric/VectorUtil.hpp opm/common/utility/numeric/buildUniformMonotoneTable.hpp opm/common/utility/numeric/linearInterpolation.hpp opm/common/utility/numeric/MonotCubicInterpolator.hpp diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 07367ba6a72..fe055fda0d3 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -17,6 +17,7 @@ along with OPM. If not, see . */ +#include #include #include #include @@ -47,6 +48,8 @@ #include #include #include +#include +#include #include @@ -69,6 +72,7 @@ #include #include #include +#include #include #include @@ -1977,47 +1981,6 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } void EclipseGrid::init_children_host_cells(){ - constexpr std::array, 12> faceConfigurations{ - std::array{0, 1, 5}, - {1, 5, 4}, // Face 0 - {0, 4, 6}, - {4, 6, 2}, // Face 1 - {2, 3, 7}, - {3, 7, 6}, // Face 2 - {1, 3, 7}, - {3, 7, 5}, // Face 3 - {0, 1, 3}, - {1, 3, 2}, // Face 4 - {4, 5, 7}, - {5, 7, 6} // Face 5 - }; - constexpr double epslon = 1e-6; - auto calcTetraVol = [](const auto& x, const auto& y, const auto& z){ - auto det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] - - x[1]*y[2]*z[0] - x[2]*y[0]*z[1] + x[2]*y[1]*z[0] - + x[0]*y[1]*z[3] - x[0]*y[3]*z[1] - x[1]*y[0]*z[3] - + x[1]*y[3]*z[0] + x[3]*y[0]*z[1] - x[3]*y[1]*z[0] - - x[0]*y[2]*z[3] + x[0]*y[3]*z[2] + x[2]*y[0]*z[3] - - x[2]*y[3]*z[0] - x[3]*y[0]*z[2] + x[3]*y[2]*z[0] - + x[1]*y[2]*z[3] - x[1]*y[3]*z[2] - x[2]*y[1]*z[3] - + x[2]*y[3]*z[1] + x[3]*y[1]*z[2] - x[3]*y[2]*z[1]; - return std::abs(det)/6; - }; - - auto getAllCellCenters = [](const auto& cell, const auto& global_list){ - std::vector cell_centersX(global_list.size()); - std::vector cell_centersY(global_list.size()); - std::vector cell_centersZ(global_list.size()); - std::array value = {0,0,0}; - for (std::size_t index = 0; index < global_list.size(); index++) { - value = cell.getCellCenter(global_list[index]); - cell_centersX[index] = value[0]; - cell_centersY[index] = value[1]; - cell_centersZ[index] = value[2]; - } - return std::make_tuple(cell_centersX,cell_centersY,cell_centersZ); - }; - auto getAllCellCorners = [this](const auto& father_list){ std::vector> X(father_list.size()); std::vector> Y(father_list.size()); @@ -2028,102 +1991,12 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return std::make_tuple(X, Y,Z); }; - auto appendNode = [](const std::array& X, const std::array& Y, const std::array& Z, - const double& xc, const double& yc, const double& zc ){ - std::array tX; - std::array tY; - std::array tZ; - std::copy(X.begin(), X.end(), tX.begin()); - tX[3]= xc; - std::copy(Y.begin(), Y.end(), tY.begin()); - tY[3]= yc; - std::copy(Z.begin(), Z.end(), tZ.begin()); - tZ[3]= zc; - return std::make_tuple(tX,tY,tZ); - }; - - auto getNodes = [](const std::array& X, const std::array& Y, const std::array& Z, - const std::array& ind){ - std::array filtered_vectorX; - std::array filtered_vectorY; - std::array filtered_vectorZ; - for (std::size_t index = 0; index < ind.size(); index++) { - filtered_vectorX[index] = X[ind[index]]; - filtered_vectorY[index] = Y[ind[index]]; - filtered_vectorZ[index] = Z[ind[index]]; - } - return std::make_tuple(filtered_vectorX,filtered_vectorY,filtered_vectorZ); - }; - - auto filterArray = [](const std::vector& X, const std::vector& ind){ - std::vector filtered_vectorX(ind.size(),0); - for (std::size_t index = 0; index < ind.size(); index++) { - filtered_vectorX[index] = X[ind[index]]; - } - return filtered_vectorX; - }; - - auto calcHexaVol = [getNodes, appendNode, calcTetraVol, faceConfigurations] - (const auto& x, const auto& y, const auto& z, - const auto& cx, const auto& cy, const auto& cz ){ - // note: some CPG grids may have collapsed faces that are not planar, therefore - // the hexadron is subdivided in terahedrons. - // calculating the volume of the pyramid with F0 as base and pc as center - double totalVolume = 0.0; - for (size_t i = 0; i < faceConfigurations.size(); i += 2) { - auto [fX0, fY0, fZ0] = getNodes(x, y, z, faceConfigurations[i]); - totalVolume += std::apply(calcTetraVol, appendNode(fX0, fY0, fZ0, cx, cy, cz)); - - auto [fX1, fY1, fZ1] = getNodes(x, y, z, faceConfigurations[i + 1]); - totalVolume += std::apply(calcTetraVol, appendNode(fX1, fY1, fZ1, cx, cy, cz)); - } - return totalVolume; - }; - - - auto isInsideElement = [calcHexaVol](const std::vector& tpX, const std::vector& tpY, const std::vector& tpZ, - const std::vector>& X, const std::vector>& Y, - const std::vector>& Z){ - std::vector in_elements(tpX.size(),0); - // check if it is insde or outside boundary box - double minX, minY, minZ, maxX, maxY, maxZ; - double pcX, pcY, pcZ, element_volume, test_element_volume; - bool flag; - for (std::size_t outerIndex = 0; outerIndex < X.size(); outerIndex++) { - minX = *std::min_element(X[outerIndex].begin(), X[outerIndex].end()); - minY = *std::min_element(Y[outerIndex].begin(), Y[outerIndex].end()); - minZ = *std::min_element(Z[outerIndex].begin(), Z[outerIndex].end()); - maxX = *std::max_element(X[outerIndex].begin(), X[outerIndex].end()); - maxY = *std::max_element(Y[outerIndex].begin(), Y[outerIndex].end()); - maxZ = *std::max_element(Z[outerIndex].begin(), Z[outerIndex].end()); - pcX = std::accumulate(X[outerIndex].begin(), X[outerIndex].end(), 0.0)/8; - pcY = std::accumulate(Y[outerIndex].begin(), Y[outerIndex].end(), 0.0)/8; - pcZ = std::accumulate(Z[outerIndex].begin(), Z[outerIndex].end(), 0.0)/8; - element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex], pcX, pcY,pcZ); - for (size_t innerIndex = 0; innerIndex < tpX.size(); innerIndex++){ - // check if center of refined volume is outside the boundary box of a coarse volume. - // Only computes volumed base test is this condition is met. - flag = (minX < tpX[innerIndex]) && (maxX > tpX[innerIndex]) && - (minY < tpY[innerIndex]) && (maxY > tpY[innerIndex]) && - (minZ < tpZ[innerIndex]) && (maxZ > tpZ[innerIndex]); - if (flag && (in_elements[innerIndex] == 0)) { - test_element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex], - tpX[innerIndex], tpY[innerIndex],tpZ[innerIndex]); - if (std::abs(test_element_volume - element_volume) < epslon){ - in_elements[innerIndex] = static_cast(outerIndex); - } - } - } - } - return in_elements; - }; - std::vector element_centerX, element_centerY, element_centerZ; for (EclipseGridLGR& lgr_cell : lgr_children_cells) { - std::tie(element_centerX, element_centerY,element_centerZ) = getAllCellCenters(lgr_cell, lgr_cell.getActiveMap()); + std::tie(element_centerX, element_centerY,element_centerZ) = VectorUtil::callMethodForEachInputOnObjectXYZ, int,std::array (EclipseGridLGR::*)(size_t) const>(lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); auto [host_cellX, host_cellY, host_cellZ] = getAllCellCorners(lgr_cell.get_father_global()); - auto inside_el = isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); - auto host_cells_global_ref = filterArray(lgr_cell.get_father_global(), inside_el); + auto inside_el = GeometryUtil::isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); + std::vector host_cells_global_ref = VectorUtil::filterArray(lgr_cell.get_father_global(), inside_el); lgr_cell.set_hostnum(host_cells_global_ref); lgr_cell.init_children_host_cells(); } @@ -2628,7 +2501,6 @@ namespace Opm { } egridfile.write("LGRPARNT", lgr_father_name_label); - Opm::UnitSystem::UnitType unitSystemType = units.getType(); constexpr auto length = ::Opm::UnitSystem::measure::length; const std::array dims = getNXYZ(); From 19a75a37fe75ce2dc884f03f7373db02471241f7 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 10:22:07 +0000 Subject: [PATCH 17/60] refactor EclipseGrid:: init_children_host_cells --- opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index fe055fda0d3..8ca4a890770 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -1993,7 +1993,9 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector element_centerX, element_centerY, element_centerZ; for (EclipseGridLGR& lgr_cell : lgr_children_cells) { - std::tie(element_centerX, element_centerY,element_centerZ) = VectorUtil::callMethodForEachInputOnObjectXYZ, int,std::array (EclipseGridLGR::*)(size_t) const>(lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); + std::tie(element_centerX, element_centerY,element_centerZ) = + VectorUtil::callMethodForEachInputOnObjectXYZ, int,std::array (EclipseGridLGR::*)(size_t) const> + (lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); auto [host_cellX, host_cellY, host_cellZ] = getAllCellCorners(lgr_cell.get_father_global()); auto inside_el = GeometryUtil::isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); std::vector host_cells_global_ref = VectorUtil::filterArray(lgr_cell.get_father_global(), inside_el); @@ -2003,8 +2005,6 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } - - const std::vector& EclipseGrid::getActiveMap() const { return m_active_to_global; } From abb631387cc13e3cb3970d1d58392520cfa7a3ed Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 10:25:23 +0000 Subject: [PATCH 18/60] added template functions to utility libraries --- opm/common/utility/numeric/GeometryUtil.cpp | 5 + opm/common/utility/numeric/GeometryUtil.hpp | 116 ++++++++++++++++++++ opm/common/utility/numeric/VectorUtil.cpp | 24 ++++ opm/common/utility/numeric/VectorUtil.hpp | 94 ++++++++++++++++ 4 files changed, 239 insertions(+) create mode 100644 opm/common/utility/numeric/GeometryUtil.cpp create mode 100644 opm/common/utility/numeric/GeometryUtil.hpp create mode 100644 opm/common/utility/numeric/VectorUtil.cpp create mode 100644 opm/common/utility/numeric/VectorUtil.hpp diff --git a/opm/common/utility/numeric/GeometryUtil.cpp b/opm/common/utility/numeric/GeometryUtil.cpp new file mode 100644 index 00000000000..da146db0b6e --- /dev/null +++ b/opm/common/utility/numeric/GeometryUtil.cpp @@ -0,0 +1,5 @@ +#include + +namespace GeometryUtil { + +} // namespace GeometryUtils diff --git a/opm/common/utility/numeric/GeometryUtil.hpp b/opm/common/utility/numeric/GeometryUtil.hpp new file mode 100644 index 00000000000..f930fab4f1f --- /dev/null +++ b/opm/common/utility/numeric/GeometryUtil.hpp @@ -0,0 +1,116 @@ +#ifndef GEOMETRYUTIL_H +#define GEOMETRYUTIL_H + +#include +#include +#include +#include +namespace GeometryUtil { + +constexpr double epslon = 1e-6; +// A simple utility function to calculate area of a rectangle +double calculateRectangleArea(double width, double height); + +template +T calcTetraVol(const std::array& x, const std::array& y, const std::array& z ){ + T det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] + - x[1]*y[2]*z[0] - x[2]*y[0]*z[1] + x[2]*y[1]*z[0] + + x[0]*y[1]*z[3] - x[0]*y[3]*z[1] - x[1]*y[0]*z[3] + + x[1]*y[3]*z[0] + x[3]*y[0]*z[1] - x[3]*y[1]*z[0] + - x[0]*y[2]*z[3] + x[0]*y[3]*z[2] + x[2]*y[0]*z[3] + - x[2]*y[3]*z[0] - x[3]*y[0]*z[2] + x[3]*y[2]*z[0] + + x[1]*y[2]*z[3] - x[1]*y[3]*z[2] - x[2]*y[1]*z[3] + + x[2]*y[3]*z[1] + x[3]*y[1]*z[2] - x[3]*y[2]*z[1]; + return std::abs(det)/6; +} + +template +T calcHexaVol(const std::array& x, const std::array& y, const std::array& z, + const T& cx, const T& cy, const T& cz ) +{ + constexpr std::array, 12> faceConfigurations + { + std::array{0, 1, 5}, + {1, 5, 4}, // Face 0 + {0, 4, 6}, + {4, 6, 2}, // Face 1 + {2, 3, 7}, + {3, 7, 6}, // Face 2 + {1, 3, 7}, + {3, 7, 5}, // Face 3 + {0, 1, 3}, + {1, 3, 2}, // Face 4 + {4, 5, 7}, + {5, 7, 6} // Face 5 + }; + auto getNodes = [](const std::array& X, const std::array& Y, const std::array& Z, + const std::array& ind){ + std::array filtered_vectorX; + std::array filtered_vectorY; + std::array filtered_vectorZ; + for (std::size_t index = 0; index < ind.size(); index++) { + filtered_vectorX[index] = X[ind[index]]; + filtered_vectorY[index] = Y[ind[index]]; + filtered_vectorZ[index] = Z[ind[index]]; + } + return std::make_tuple(filtered_vectorX,filtered_vectorY,filtered_vectorZ); + }; + // note: some CPG grids may have collapsed faces that are not planar, therefore + // the hexadron is subdivided in terahedrons. + // calculating the volume of the pyramid with F0 as base and pc as center + T totalVolume = 0.0; + for (size_t i = 0; i < faceConfigurations.size(); i += 2) { + auto [fX0, fY0, fZ0] = getNodes(x, y, z, faceConfigurations[i]); + totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX0, fY0, fZ0, cx, cy, cz)); + + auto [fX1, fY1, fZ1] = getNodes(x, y, z, faceConfigurations[i + 1]); + totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX1, fY1, fZ1, cx, cy, cz)); + } + return totalVolume; +}; + +template +std::vector isInsideElement(const std::vector& tpX, const std::vector& tpY, const std::vector& tpZ, + const std::vector>& X, const std::vector>& Y, + const std::vector>& Z) +{ + std::vector in_elements(tpX.size(),0); + // check if it is insde or outside boundary box + T minX, minY, minZ, maxX, maxY, maxZ; + T pcX, pcY, pcZ, element_volume, test_element_volume; + bool flag; + for (std::size_t outerIndex = 0; outerIndex < X.size(); outerIndex++) { + minX = *std::min_element(X[outerIndex].begin(), X[outerIndex].end()); + minY = *std::min_element(Y[outerIndex].begin(), Y[outerIndex].end()); + minZ = *std::min_element(Z[outerIndex].begin(), Z[outerIndex].end()); + maxX = *std::max_element(X[outerIndex].begin(), X[outerIndex].end()); + maxY = *std::max_element(Y[outerIndex].begin(), Y[outerIndex].end()); + maxZ = *std::max_element(Z[outerIndex].begin(), Z[outerIndex].end()); + pcX = std::accumulate(X[outerIndex].begin(), X[outerIndex].end(), 0.0)/8; + pcY = std::accumulate(Y[outerIndex].begin(), Y[outerIndex].end(), 0.0)/8; + pcZ = std::accumulate(Z[outerIndex].begin(), Z[outerIndex].end(), 0.0)/8; + element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex], pcX, pcY,pcZ); + for (size_t innerIndex = 0; innerIndex < tpX.size(); innerIndex++){ + // check if center of refined volume is outside the boundary box of a coarse volume. + // Only computes volumed base test is this condition is met. + flag = (minX < tpX[innerIndex]) && (maxX > tpX[innerIndex]) && + (minY < tpY[innerIndex]) && (maxY > tpY[innerIndex]) && + (minZ < tpZ[innerIndex]) && (maxZ > tpZ[innerIndex]); + if (flag && (in_elements[innerIndex] == 0)) { + test_element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex], + tpX[innerIndex], tpY[innerIndex],tpZ[innerIndex]); + if (std::abs(test_element_volume - element_volume) < epslon){ + in_elements[innerIndex] = static_cast(outerIndex); + } + } + } + } + return in_elements; +}; + + +// Example for other utilities... + +} // namespace GeometryUtils + +#endif // GEOMETRY_UTILS_H diff --git a/opm/common/utility/numeric/VectorUtil.cpp b/opm/common/utility/numeric/VectorUtil.cpp new file mode 100644 index 00000000000..71241382046 --- /dev/null +++ b/opm/common/utility/numeric/VectorUtil.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +namespace VectorUtil { + +std::tuple, std::array, std::array> +appendNode(const std::array& X, const std::array& Y, + const std::array& Z, const double& xc, const double& yc, + const double& zc) +{ + std::array tX; + std::array tY; + std::array tZ; + std::copy(X.begin(), X.end(), tX.begin()); + tX[3]= xc; + std::copy(Y.begin(), Y.end(), tY.begin()); + tY[3]= yc; + std::copy(Z.begin(), Z.end(), tZ.begin()); + tZ[3]= zc; + return std::make_tuple(tX,tY,tZ); +} + +} // namespace VectorUtil diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp new file mode 100644 index 00000000000..5dd2ecebc60 --- /dev/null +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -0,0 +1,94 @@ +#ifndef VECTORUTIL_H +#define VECTORUTIL_H + +#include +#include +#include +#include +#include + +namespace VectorUtil { + +// Implementation of generation General Operation between two vectors of the same type +template +std::vector vectorOperation(const std::vector& vecA, const std::vector& vecB, Operation op) { + if (vecA.size() != vecB.size()) { + throw std::invalid_argument("Error: Vectors must have the same size!"); // Throwing exception + } + std::vector result; + result.reserve(vecA.size()); + // Use std::transform with the passed operation + std::transform(vecA.begin(), vecA.end(), vecB.begin(), std::back_inserter(result), op); + return result; +} + + +// A simple utility function to calculate area of a rectangle +std::tuple, std::array, std::array> +appendNode(const std::array&, const std::array&, + const std::array&, const double&, const double&, + const double&); +template +std::vector filterArray(const std::vector& X, const std::vector& ind){ + std::vector filtered_vectorX(ind.size(),0); + for (std::size_t index = 0; index < ind.size(); index++) { + filtered_vectorX[index] = X[ind[index]]; + } + return filtered_vectorX; +}; + +// T type of the object +// Rout type of the object output +// Method type of method +template +std::vector callMethodForEachInputOnObject(const T& obj, Method mtd, const std::vector& input_vector, Args&&... args) { + std::vector result; + // Reserve space for each vector in the tuple + result.reserve(input_vector.size()); + // Iterate over the input_vector and fill the tuple's vectors + for (const auto& element : input_vector) { + Rout value = (obj.*mtd)(element, std::forward(args)...); + result.push_back(std::move(value)); + } + return result; +} + + + +template +std::tuple,std::vector, std::vector> splitXYZ(std::vector>& input_vector ){ +std::vector X, Y, Z; + X.reserve(input_vector.size()); + Y.reserve(input_vector.size()); + Z.reserve(input_vector.size()); + for (auto& element : input_vector) { + X.push_back(std::move(element[0])); // Add to first vector + Y.push_back(std::move(element[1])); // Add to second vector + Z.push_back(std::move(element[2])); // Add to third vector + } + return std::make_tuple(X,Y,Z); +} + + +template +auto callMethodForEachInputOnObjectXYZ(const T& obj, Method mtd, const std::vector& input_vector, Args&&... args) { + using X = typename Rout::value_type; + auto result = callMethodForEachInputOnObject(obj, mtd, input_vector, std::forward(args)...); + return splitXYZ(result); +} + +template + void test(std::vector vec){ + std::size_t index = 1; + for (T el : vec){ + index++; + } +} + + + +// Example for other utilities... + +} // namespace VectorUtil + +#endif // VECTORUTIL_H From 50725f8366a2b40b46b503a7d0202913e2aeeb03 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 11:00:39 +0000 Subject: [PATCH 19/60] fixed missing header bug --- opm/common/utility/numeric/GeometryUtil.hpp | 6 ++--- opm/common/utility/numeric/VectorUtil.cpp | 18 --------------- opm/common/utility/numeric/VectorUtil.hpp | 22 ++++++++++++++++++- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 4 ++-- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 2 +- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/opm/common/utility/numeric/GeometryUtil.hpp b/opm/common/utility/numeric/GeometryUtil.hpp index f930fab4f1f..7f26f5e9157 100644 --- a/opm/common/utility/numeric/GeometryUtil.hpp +++ b/opm/common/utility/numeric/GeometryUtil.hpp @@ -41,7 +41,7 @@ T calcHexaVol(const std::array& x, const std::array& y, const std::arr {0, 1, 3}, {1, 3, 2}, // Face 4 {4, 5, 7}, - {5, 7, 6} // Face 5 + {5, 7, 6} // Face 5 }; auto getNodes = [](const std::array& X, const std::array& Y, const std::array& Z, const std::array& ind){ @@ -61,10 +61,10 @@ T calcHexaVol(const std::array& x, const std::array& y, const std::arr T totalVolume = 0.0; for (size_t i = 0; i < faceConfigurations.size(); i += 2) { auto [fX0, fY0, fZ0] = getNodes(x, y, z, faceConfigurations[i]); - totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX0, fY0, fZ0, cx, cy, cz)); + totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX0, fY0, fZ0, cx, cy, cz)); auto [fX1, fY1, fZ1] = getNodes(x, y, z, faceConfigurations[i + 1]); - totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX1, fY1, fZ1, cx, cy, cz)); + totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX1, fY1, fZ1, cx, cy, cz)); } return totalVolume; }; diff --git a/opm/common/utility/numeric/VectorUtil.cpp b/opm/common/utility/numeric/VectorUtil.cpp index 71241382046..25a1a4be553 100644 --- a/opm/common/utility/numeric/VectorUtil.cpp +++ b/opm/common/utility/numeric/VectorUtil.cpp @@ -1,24 +1,6 @@ #include -#include -#include namespace VectorUtil { -std::tuple, std::array, std::array> -appendNode(const std::array& X, const std::array& Y, - const std::array& Z, const double& xc, const double& yc, - const double& zc) -{ - std::array tX; - std::array tY; - std::array tZ; - std::copy(X.begin(), X.end(), tX.begin()); - tX[3]= xc; - std::copy(Y.begin(), Y.end(), tY.begin()); - tY[3]= yc; - std::copy(Z.begin(), Z.end(), tZ.begin()); - tZ[3]= zc; - return std::make_tuple(tX,tY,tZ); -} } // namespace VectorUtil diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp index 5dd2ecebc60..2115b2cf354 100644 --- a/opm/common/utility/numeric/VectorUtil.hpp +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -5,10 +5,30 @@ #include #include #include -#include +#include +#include + namespace VectorUtil { + +template +std::tuple, std::array, std::array> +appendNode(const std::array& X, const std::array& Y, const std::array& Z, + const T& xc, const T& yc, const T& zc) +{ + std::array tX; + std::array tY; + std::array tZ; + std::copy(X.begin(), X.end(), tX.begin()); + tX[3]= xc; + std::copy(Y.begin(), Y.end(), tY.begin()); + tY[3]= yc; + std::copy(Z.begin(), Z.end(), tZ.begin()); + tZ[3]= zc; + return std::make_tuple(tX,tY,tZ); +} + // Implementation of generation General Operation between two vectors of the same type template std::vector vectorOperation(const std::vector& vecA, const std::vector& vecB, Operation op) { diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 8ca4a890770..da3330088ec 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -2461,8 +2461,8 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st namespace Opm { EclipseGridLGR::EclipseGridLGR(const std::string& self_label, const std::string& father_label_, std::size_t nx, std::size_t ny, std::size_t nz, - vec_size_t father_lgr_index, const std::array& low_fahterIJK_, - const std::array& up_fahterIJK_) + const vec_size_t& father_lgr_index, [[maybe_unused]] const std::array& low_fahterIJK_, + [[maybe_unused]] const std::array& up_fahterIJK_) : EclipseGrid(nx,ny,nz), father_label(father_label_), father_global(father_lgr_index) { init_father_global(); diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 4c9cefe8079..cd2baa462c0 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -372,7 +372,7 @@ namespace Opm { EclipseGridLGR() = default; EclipseGridLGR(const std::string& self_label, const std::string& father_label_, size_t nx, size_t ny, size_t nz, - vec_size_t father_lgr_index, const std::array& low_fahterIJK_, + const vec_size_t& father_lgr_index, const std::array& low_fahterIJK_, const std::array& up_fahterIJK_); ~EclipseGridLGR() = default; const vec_size_t& getFatherGlobalID() const; From e5584d43dd6db8ba31233ab3980a9327a757e938 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 12:04:49 +0000 Subject: [PATCH 20/60] header incuded --- opm/common/utility/numeric/VectorUtil.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp index 2115b2cf354..59b6cdcc657 100644 --- a/opm/common/utility/numeric/VectorUtil.hpp +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include From 51f6d9e5b52565834c1d580c8c3f923c57fa479d Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 15:01:11 +0000 Subject: [PATCH 21/60] refactor to improve template deduction --- opm/common/utility/numeric/VectorUtil.hpp | 24 ++++-------------- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 5 ++-- tests/OPMCARFIN-COLUMN.EGRID | Bin 3108 -> 3108 bytes tests/OPMCARFIN-DOUBLE.EGRID | Bin 3868 -> 3868 bytes tests/OPMCARFIN-NESTED.EGRID | Bin 4604 -> 4604 bytes tests/OPMCARFIN5.EGRID | Bin 3172 -> 3172 bytes 6 files changed, 7 insertions(+), 22 deletions(-) diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp index 59b6cdcc657..0382e702588 100644 --- a/opm/common/utility/numeric/VectorUtil.hpp +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -11,7 +11,6 @@ namespace VectorUtil { - template std::tuple, std::array, std::array> appendNode(const std::array& X, const std::array& Y, const std::array& Z, @@ -60,14 +59,14 @@ std::vector filterArray(const std::vector& X, const std::vector< // T type of the object // Rout type of the object output // Method type of method -template +template std::vector callMethodForEachInputOnObject(const T& obj, Method mtd, const std::vector& input_vector, Args&&... args) { std::vector result; // Reserve space for each vector in the tuple result.reserve(input_vector.size()); // Iterate over the input_vector and fill the tuple's vectors for (const auto& element : input_vector) { - Rout value = (obj.*mtd)(element, std::forward(args)...); + Rout value = (obj.*mtd)(element, args...); result.push_back(std::move(value)); } return result; @@ -90,25 +89,12 @@ std::vector X, Y, Z; } -template +template auto callMethodForEachInputOnObjectXYZ(const T& obj, Method mtd, const std::vector& input_vector, Args&&... args) { - using X = typename Rout::value_type; - auto result = callMethodForEachInputOnObject(obj, mtd, input_vector, std::forward(args)...); - return splitXYZ(result); -} - -template - void test(std::vector vec){ - std::size_t index = 1; - for (T el : vec){ - index++; - } + auto result = callMethodForEachInputOnObject< Rout,T, Rin, Method, Args...>(obj, mtd, input_vector, std::forward(args)...); + return splitXYZ(result); } - - -// Example for other utilities... - } // namespace VectorUtil #endif // VECTORUTIL_H diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index da3330088ec..0afb17fc79f 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -17,7 +17,6 @@ along with OPM. If not, see . */ -#include #include #include #include @@ -1994,8 +1993,8 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector element_centerX, element_centerY, element_centerZ; for (EclipseGridLGR& lgr_cell : lgr_children_cells) { std::tie(element_centerX, element_centerY,element_centerZ) = - VectorUtil::callMethodForEachInputOnObjectXYZ, int,std::array (EclipseGridLGR::*)(size_t) const> - (lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); + VectorUtil::callMethodForEachInputOnObjectXYZ,EclipseGridLGR, int,std::array (EclipseGridLGR::*)(size_t) const> + (lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); auto [host_cellX, host_cellY, host_cellZ] = getAllCellCorners(lgr_cell.get_father_global()); auto inside_el = GeometryUtil::isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); std::vector host_cells_global_ref = VectorUtil::filterArray(lgr_cell.get_father_global(), inside_el); diff --git a/tests/OPMCARFIN-COLUMN.EGRID b/tests/OPMCARFIN-COLUMN.EGRID index bfd9b6bd4ef2e8e2d9f8b60386eff7312f1858ad..43b59847bc4e12bd00bba577b0d28208c6edf1db 100644 GIT binary patch delta 45 xcmZ1?u|#6S5_X9&t?Gpg4548R3=Bp<%ot|6h!Mo!=*Y)7xsO?J^KA}KW&jL>3s(RD delta 25 hcmZ1?u|#6S686ax*rYe7GjTIc?qe3*e4E3Q831+{2v-0A diff --git a/tests/OPMCARFIN-DOUBLE.EGRID b/tests/OPMCARFIN-DOUBLE.EGRID index 593978980fc1aee4f608738b3640862f3a765449..2bce629e15d618203d43e7e52da37fb2c5b006b0 100644 GIT binary patch delta 43 xcmbOuH%D&65_X<2rbUbl4548R3=E8$H?YgF@PwJqS_l#;Elg(Ie1qGC836tN3$p+K delta 43 xcmbOuH%D&65_X>Syj0&3hKy2%)S|M@8`x!7co-NMSb>%9smFU delta 25 hcmaDN@kC<7686ax*rYe7GjTIc?qinQ{DPx~832O+2_ygj From 401f7a0479e73071d90eb1999a3535f0c20d7a57 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 15:10:40 +0000 Subject: [PATCH 22/60] "improved deduction of template functions" --- opm/common/utility/numeric/VectorUtil.hpp | 6 +++--- opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp index 0382e702588..2bee986e1d0 100644 --- a/opm/common/utility/numeric/VectorUtil.hpp +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -59,7 +59,7 @@ std::vector filterArray(const std::vector& X, const std::vector< // T type of the object // Rout type of the object output // Method type of method -template +template std::vector callMethodForEachInputOnObject(const T& obj, Method mtd, const std::vector& input_vector, Args&&... args) { std::vector result; // Reserve space for each vector in the tuple @@ -89,9 +89,9 @@ std::vector X, Y, Z; } -template +template auto callMethodForEachInputOnObjectXYZ(const T& obj, Method mtd, const std::vector& input_vector, Args&&... args) { - auto result = callMethodForEachInputOnObject< Rout,T, Rin, Method, Args...>(obj, mtd, input_vector, std::forward(args)...); + auto result = callMethodForEachInputOnObject< Rout, Method, T, Rin,Args...>(obj, mtd, input_vector, std::forward(args)...); return splitXYZ(result); } diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 0afb17fc79f..88bde4a80d5 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -1991,10 +1991,10 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st }; std::vector element_centerX, element_centerY, element_centerZ; - for (EclipseGridLGR& lgr_cell : lgr_children_cells) { + for (EclipseGridLGR& lgr_cell : lgr_children_cells) { std::tie(element_centerX, element_centerY,element_centerZ) = - VectorUtil::callMethodForEachInputOnObjectXYZ,EclipseGridLGR, int,std::array (EclipseGridLGR::*)(size_t) const> - (lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); + VectorUtil::callMethodForEachInputOnObjectXYZ, std::array (EclipseGridLGR::*)(size_t) const> + (lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); auto [host_cellX, host_cellY, host_cellZ] = getAllCellCorners(lgr_cell.get_father_global()); auto inside_el = GeometryUtil::isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); std::vector host_cells_global_ref = VectorUtil::filterArray(lgr_cell.get_father_global(), inside_el); From 6eed42bf9d21f6a809d583f72ea3d90dcbcf77c0 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 15:23:51 +0000 Subject: [PATCH 23/60] splitXYZ, return argument is created by moving X, Y and Z into the make_tuple --- opm/common/utility/numeric/VectorUtil.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp index 2bee986e1d0..b4bb583b04e 100644 --- a/opm/common/utility/numeric/VectorUtil.hpp +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -81,11 +81,11 @@ std::vector X, Y, Z; Y.reserve(input_vector.size()); Z.reserve(input_vector.size()); for (auto& element : input_vector) { - X.push_back(std::move(element[0])); // Add to first vector - Y.push_back(std::move(element[1])); // Add to second vector - Z.push_back(std::move(element[2])); // Add to third vector + X.push_back(element[0]); // Add to first vector + Y.push_back(element[1]); // Add to second vector + Z.push_back(element[2]); // Add to third vector } - return std::make_tuple(X,Y,Z); + return std::make_tuple(std::move(X),std::move(Y),std::move(Z)); } From 03f2e9ae21b4e9c966c29ef07c0ba4759b974d4e Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Tue, 19 Nov 2024 09:11:19 +0000 Subject: [PATCH 24/60] rebased code --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 4702f2a0831..406a8133140 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -160,7 +160,11 @@ EclipseGrid::EclipseGrid(const GridDims& gd) } +<<<<<<< HEAD EclipseGrid::EclipseGrid(std::size_t nx, std::size_t ny , std::size_t nz, +======= +EclipseGrid::EclipseGrid(size_t nx, std::size_t ny , std::size_t nz, +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) double dx, double dy, double dz, double top) : GridDims(nx, ny, nz), m_minpvMode(MinpvMode::Inactive), @@ -556,12 +560,20 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) } +<<<<<<< HEAD std::size_t EclipseGrid::activeIndex(std::size_t i, std::size_t j, std::size_t k) const { +======= + std::size_t EclipseGrid::activeIndex(size_t i, std::size_t j, std::size_t k) const { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) return activeIndex( getGlobalIndex( i,j,k )); } +<<<<<<< HEAD std::size_t EclipseGrid::activeIndex(std::size_t globalIndex) const { +======= + std::size_t EclipseGrid::activeIndex(size_t globalIndex) const { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) if (m_global_to_active.empty()) { return globalIndex; } @@ -578,7 +590,11 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) [0,num_active). */ +<<<<<<< HEAD std::size_t EclipseGrid::getGlobalIndex(std::size_t active_index) const { +======= + std::size_t EclipseGrid::getGlobalIndex(size_t active_index) const { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) return m_active_to_global.at(active_index); } @@ -1405,7 +1421,11 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) std::size_t initialTOPSize = TOPS.size(); TOPS.resize( volume ); +<<<<<<< HEAD for (std::size_t targetIndex = area; targetIndex < volume; targetIndex++) { +======= + for (size_t targetIndex = area; targetIndex < volume; targetIndex++) { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) std::size_t sourceIndex = targetIndex - area; double nextValue = TOPS[sourceIndex] + DZ[sourceIndex]; @@ -1442,7 +1462,11 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st */ std::size_t initialDSize = D.size(); D.resize( volume ); +<<<<<<< HEAD for (std::size_t targetIndex = initialDSize; targetIndex < volume; targetIndex++) { +======= + for (size_t targetIndex = initialDSize; targetIndex < volume; targetIndex++) { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) std::size_t sourceIndex = targetIndex - area; D[targetIndex] = D[sourceIndex]; } @@ -2093,7 +2117,11 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st for (std::size_t index = 0; index < lgr_input.size(); index++) { const auto lgr_cell = lgr_input.getLgr(index); +<<<<<<< HEAD if (this->lgr_label == lgr_cell.PARENT_NAME()) { +======= + if (this->lgr_label.compare(lgr_cell.PARENT_NAME()) == 0) { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) lgr_grid = true; // auto [i_list, j_list, k_list] = lgr_cell.parent_cellsIJK(); auto [i_list, j_list, k_list] = parent_cellsIJK(lgr_cell); @@ -2244,12 +2272,15 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } } +<<<<<<< HEAD const std::optional& EclipseGrid::getMapAxes() const { return this->m_mapaxes; } +======= +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) ZcornMapper::ZcornMapper(std::size_t nx , std::size_t ny, std::size_t nz) : dims( {{nx,ny,nz}} ), stride( {{2 , 4*nx, 8*nx*ny}} ), @@ -2276,7 +2307,11 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return dims[0] * dims[1] * dims[2] * 8; } +<<<<<<< HEAD std::size_t ZcornMapper::index(std::size_t g, int c) const { +======= + std::size_t ZcornMapper::index(size_t g, int c) const { +>>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) int k = g / (dims[0] * dims[1]); g -= k * dims[0] * dims[1]; From a534bce00895bd8092abf92c54284ef0cf4be99e Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Wed, 23 Oct 2024 15:42:51 +0000 Subject: [PATCH 25/60] rebased code -set up LgrOutput as a Test environment for the developtment of the save method for the LGR EclipseGrid - EclipseGrid object and children are initialized from .EGRID file generated on standard simulator --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 5 + .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 8 +- opm/io/eclipse/EGrid.hpp | 7 + tests/parser/LgrOutputTests.cpp | 365 +++++++++++++++++- 4 files changed, 378 insertions(+), 7 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 406a8133140..7eec2dfde00 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -2423,6 +2423,11 @@ namespace Opm { lgr_label= self_label; lgr_level = father_lgr_level + 1 ; } + void EclipseGridLGR::set_lgr_refinement(std::vector coord, std::vector zcorn) + { + m_coord = coord; + m_zcorn = zcorn; + } void EclipseGridLGR::init_father_global() { std::sort(father_global.begin(),father_global.end()); diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 168ee3d3f83..51b56873623 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -266,6 +266,9 @@ namespace Opm { std::vector lgr_level_active_map; std::vector all_lgr_labels; std::map, std::size_t> num_lgr_children_cells; + std::vector m_zcorn; + std::vector m_coord; + private: std::vector m_minpvVector; @@ -290,8 +293,6 @@ namespace Opm { mutable std::optional> m_input_zcorn; mutable std::optional> m_input_coord; - std::vector m_zcorn; - std::vector m_coord; std::vector m_actnum; @@ -373,7 +374,8 @@ namespace Opm { } const vec_size_t& get_father_global() const{ return father_global; - } + } + void set_lgr_refinement(std::vector,std::vector); private: void init_father_global(); std::string father_label; diff --git a/opm/io/eclipse/EGrid.hpp b/opm/io/eclipse/EGrid.hpp index 342c7fc924d..92794589660 100644 --- a/opm/io/eclipse/EGrid.hpp +++ b/opm/io/eclipse/EGrid.hpp @@ -69,6 +69,13 @@ class EGrid : public EclFile const std::array& get_mapaxes() const { return m_mapaxes; } const std::string& get_mapunits() const { return m_mapunits; } + + const std::vector& get_coord() const { return coord_array; } + const std::vector& get_zcorn() const { return zcorn_array; } + + + + private: std::filesystem::path inputFileName, initFileName; std::string m_grid_name; diff --git a/tests/parser/LgrOutputTests.cpp b/tests/parser/LgrOutputTests.cpp index c41f7c1b07b..fc70abafda7 100644 --- a/tests/parser/LgrOutputTests.cpp +++ b/tests/parser/LgrOutputTests.cpp @@ -13,6 +13,7 @@ along with OPM. If not, see . */ +#include #define BOOST_TEST_MODULE LgrOutputTests #include @@ -21,15 +22,371 @@ #include #include #include +#include #include #include -#include #include - #include using namespace Opm; +LgrCollection read_lgr(const std::string& deck_string, std::size_t nx, std::size_t ny, std::size_t nz){ + Opm::Parser parser; + Opm::EclipseGrid eclipse_grid(GridDims(nx,ny,nz)); + Opm::Deck deck = parser.parseString(deck_string); + const Opm::GRIDSection gridSection ( deck ); + return LgrCollection(gridSection, eclipse_grid); +} + +std::pair, std::vector> read_cpg_from_egrid(const std::string& file_path, const std::string& lgr_label){ + Opm::EclIO::EGrid egrid_global(file_path, lgr_label); + egrid_global.load_grid_data(); + auto global_coord = egrid_global.get_coord(); + auto global_zcorn = egrid_global.get_zcorn(); + std::vector coord_g(global_coord.begin(), global_coord.end()); + std::vector zcorn_g(global_zcorn.begin(), global_zcorn.end()); + return std::make_pair(coord_g, zcorn_g); +} + + BOOST_AUTO_TEST_CASE(TestLgrOutput) { - // Placeholder test for a functionality that will be released in upcoming PRs. - } + const std::string deck_string = R"( +RUNSPEC + +DIMENS + 3 3 1 / + +GRID + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +'LGR1' 2 2 2 2 1 1 3 3 / +ENDFIN + +DX + 9*1000 / +DY + 9*1000 / +DZ + 9*20 / + +TOPS + 9*8325 / + +PORO + 9*0.15 / + +PERMX + 9*1 / + +COPY + PERMX PERMZ / + PERMX PERMY / +/ + +EDIT + +OIL +GAS + +TITLE +Opm-the-best-open-source-simulator + +START +16 JUN 1988 / + +PROPS + +REGIONS + +SOLUTION + +SCHEDULE +)"; +\ + std::array global_grid_dim = {3,3,1}; + LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); + auto [coord_g, zcorn_g] = read_cpg_from_egrid("CARFIN5.EGRID", "global"); + Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); + eclipse_grid_file.init_lgr_cells(lgr_col); + auto [coord_l, zcorn_l] = read_cpg_from_egrid("CARFIN5.EGRID", "LGR1"); + eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l,zcorn_l); + + auto index = 1; + + + // Opm::EclipseGrid eclipse_grid = state.getInputGrid(); + + + + // Opm::EclIO::EGrid egrid_global("CARFIN5.EGRID"); + // egrid_global.load_grid_data(); + // auto global_coord = egrid_global.get_coord(); + // auto global_zcorn = egrid_global.get_zcorn(); + + // std::vector coord_g(global_coord.begin(), global_coord.end()); + // std::vector zcorn_g(global_zcorn.begin(), global_zcorn.end()); + // std::array dims = {3,3, 1}; + + // Opm::EclipseGrid eclipse_grid_file(dims, coord_g, zcorn_g); + + + + + // Opm::EclIO::EGrid egrid_lgr1("CARFIN5.EGRID","LGR1"); + // egrid_lgr1.load_grid_data(); + // BOOST_CHECK_EQUAL( eclipse_grid.getTotalActiveLGR() , 21U ); + // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 8U ); + // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[1].getTotalActiveLGR() , 8U ); + + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0,0,0), 0U); + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",1,3,0), 7U); + + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",1,0,0), 8U); + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",1,1,0), 17U); + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",2,2,0), 20U); + + + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",0,0,0), 9U); + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",1,3,0), 16U); + } + + + + + +BOOST_AUTO_TEST_CASE(TestLgrNested) { + const std::string deck_string = R"( +RUNSPEC + +DIMENS + 3 3 1 / + +GRID + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +LGR1 2 2 2 2 1 1 3 3 1 1* GLOBAL/ +ENDFIN + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +LGR2 2 2 2 2 1 1 3 3 1 1* LGR1/ +ENDFIN + + +DX + 9*1000 / +DY + 9*1000 / +DZ + 9*20 / + +TOPS + 9*8325 / + +PORO + 9*0.15 / + +PERMX + 9*1 / + +COPY + PERMX PERMZ / + PERMX PERMY / +/ + +EDIT + +OIL +GAS + +TITLE +The title + +START +16 JUN 1988 / + +PROPS + +REGIONS + +SOLUTION + +SCHEDULE +)"; +\ + Opm::Parser parser; + Opm::Deck deck = parser.parseString(deck_string); + Opm::EclipseState state(deck); + Opm::EclipseGrid eclipse_grid = state.getInputGrid(); + + BOOST_CHECK_EQUAL( eclipse_grid.getTotalActiveLGR() , 25U ); + BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 17U ); + BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].lgr_children_cells[0].getTotalActiveLGR() , 9U ); + + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0,0,0), 0U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",2,2,0), 24U); + + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0,0,0), 4U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",2,2,0), 20U); + + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",0,0,0), 8U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",2,2,0), 16U); + + BOOST_CHECK_THROW(eclipse_grid.getActiveIndexLGR("GLOBAL",1,1,0), std::invalid_argument); + BOOST_CHECK_THROW(eclipse_grid.getActiveIndexLGR("LGR1",1,1,0), std::invalid_argument); + BOOST_CHECK_THROW(eclipse_grid.getActiveIndexLGR("LGR3",1,1,0), std::invalid_argument); +} +BOOST_AUTO_TEST_CASE(TestGLOBALinactivecells) { + const std::string deck_string = R"( +RUNSPEC + +DIMENS + 3 3 1 / + +GRID + +ACTNUM +1 0 1 +1 1 1 +1 1 1 +/ + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +'LGR1' 2 2 2 2 1 1 3 3 1/ +ENDFIN + + +DX + 9*1000 / +DY + 9*1000 / +DZ + 9*20 / + +TOPS + 9*8325 / + +PORO + 9*0.15 / + +PERMX + 9*1 / + +COPY + PERMX PERMZ / + PERMX PERMY / +/ + +EDIT + +OIL +GAS + +TITLE +The title + +START +16 JUN 1988 / + +PROPS + +REGIONS + +SOLUTION + +SCHEDULE +)"; +\ + Opm::Parser parser; + Opm::Deck deck = parser.parseString(deck_string); + Opm::EclipseState state(deck); + Opm::EclipseGrid eclipse_grid = state.getInputGrid(); + + BOOST_CHECK_EQUAL( eclipse_grid.getTotalActiveLGR() , 16U ); + BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 9U ); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0,0,0), 0U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",2,2,0), 15U); + + + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0U), 0U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",8U), 15U); + + + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0,0,0), 3U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",2,2,0), 11U); + + + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0), 3U); + BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",8), 11U); + +} + +BOOST_AUTO_TEST_CASE(TestLGRinactivecells) { + const std::string deck_string = R"( +RUNSPEC + +DIMENS + 3 3 1 / + +GRID + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +'LGR1' 2 2 2 2 1 1 3 3 1/ +ACTNUM +1 0 1 +1 1 1 +1 1 1 +/ +ENDFIN + +DX + 9*1000 / +DY + 9*1000 / +DZ + 9*20 / + +TOPS + 9*8325 / + +PORO + 9*0.15 / + +PERMX + 9*1 / + +COPY + PERMX PERMZ / + PERMX PERMY / +/ + +EDIT + +OIL +GAS + +TITLE +The title + +START +16 JUN 1988 / + +PROPS + +REGIONS + +SOLUTION + +SCHEDULE +)"; +\ + Opm::Parser parser; + Opm::Deck deck = parser.parseString(deck_string); + Opm::EclipseState state(deck); + Opm::LgrCollection lgrs = state.getLgrs(); + // LGR Inactive Cells Not yet Implemented +} From 606d9d21fc3f215fff7ec1136180cde54c8b40b5 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Tue, 19 Nov 2024 09:18:23 +0000 Subject: [PATCH 26/60] part1 - rebase EGrid.hpp seems to contain a bug where get(COORD) cannot catpure the global COORD in EGRIDs, EclipseGrid has been enhaced with functions to output .EGRIDS for LGR - unfinished work - devising a mechanism to define HOSTCE --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 260 +++++++++++++++--- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 15 +- opm/io/eclipse/EGrid.hpp | 2 - tests/parser/LgrOutputTests.cpp | 14 +- 4 files changed, 237 insertions(+), 54 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 7eec2dfde00..7391e8f22b2 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -17,6 +17,16 @@ along with OPM. If not, see . */ +<<<<<<< HEAD +======= +#include "opm/io/eclipse/PaddedOutputString.hpp" +#include +#include +#include +#include +#include +#include +>>>>>>> 9e3ed0386 (part1 - rebase) #define _USE_MATH_DEFINES #include @@ -31,7 +41,7 @@ #include #include -#include + #include #include @@ -160,11 +170,7 @@ EclipseGrid::EclipseGrid(const GridDims& gd) } -<<<<<<< HEAD EclipseGrid::EclipseGrid(std::size_t nx, std::size_t ny , std::size_t nz, -======= -EclipseGrid::EclipseGrid(size_t nx, std::size_t ny , std::size_t nz, ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) double dx, double dy, double dz, double top) : GridDims(nx, ny, nz), m_minpvMode(MinpvMode::Inactive), @@ -560,20 +566,12 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) } -<<<<<<< HEAD std::size_t EclipseGrid::activeIndex(std::size_t i, std::size_t j, std::size_t k) const { -======= - std::size_t EclipseGrid::activeIndex(size_t i, std::size_t j, std::size_t k) const { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) return activeIndex( getGlobalIndex( i,j,k )); } -<<<<<<< HEAD std::size_t EclipseGrid::activeIndex(std::size_t globalIndex) const { -======= - std::size_t EclipseGrid::activeIndex(size_t globalIndex) const { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) if (m_global_to_active.empty()) { return globalIndex; } @@ -590,11 +588,7 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) [0,num_active). */ -<<<<<<< HEAD std::size_t EclipseGrid::getGlobalIndex(std::size_t active_index) const { -======= - std::size_t EclipseGrid::getGlobalIndex(size_t active_index) const { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) return m_active_to_global.at(active_index); } @@ -1421,11 +1415,7 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) std::size_t initialTOPSize = TOPS.size(); TOPS.resize( volume ); -<<<<<<< HEAD for (std::size_t targetIndex = area; targetIndex < volume; targetIndex++) { -======= - for (size_t targetIndex = area; targetIndex < volume; targetIndex++) { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) std::size_t sourceIndex = targetIndex - area; double nextValue = TOPS[sourceIndex] + DZ[sourceIndex]; @@ -1462,11 +1452,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st */ std::size_t initialDSize = D.size(); D.resize( volume ); -<<<<<<< HEAD for (std::size_t targetIndex = initialDSize; targetIndex < volume; targetIndex++) { -======= - for (size_t targetIndex = initialDSize; targetIndex < volume; targetIndex++) { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) std::size_t sourceIndex = targetIndex - area; D[targetIndex] = D[sourceIndex]; } @@ -1925,7 +1911,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st gridhead[1] = dims[0]; // nI gridhead[2] = dims[1]; // nJ gridhead[3] = dims[2]; // nK - gridhead[24] = 1; // corner point grid + gridhead[24] = 1; // NUMRES std::vector nnchead(10, 0); std::vector nnc1; @@ -1979,14 +1965,90 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st egridfile.write("ACTNUM", m_actnum); egridfile.write("ENDGRID", endgrid); + + for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { + lgr_cell.save(egridfile, nnc, units); + } if (nnc1.size() > 0){ egridfile.write("NNCHEAD", nnchead); egridfile.write("NNC1", nnc1); - egridfile.write("NNC2", nnc2); + egridfile.write("NNC2", nnc2); + // for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { + // lgr_cell.save_nnc(egridfile); + // } + + } + } + + void EclipseGrid::init_children_host_cells(){ + auto get_all_cell_centers = [](const auto& cell, const auto& global_list){ + std::vector> cell_centers(global_list.size()); + for (std::size_t index = 0; index < global_list.size(); index++) { + cell_centers[index] = cell.getCellCenter(global_list[index]); + //cell_centers[index] = this->getActiveIndex(i_list[index],j_list[index],k_list[index]); + } + return cell_centers; + }; + auto tetra_vol = [](const auto& x, const auto& y, const auto& z){ + auto det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] + - x[1]*y[2]*z[0] - x[2]*y[0]*z[1] + x[2]*y[1]*z[0] + + x[0]*y[1]*z[3] - x[0]*y[3]*z[1] - x[1]*y[0]*z[3] + + x[1]*y[3]*z[0] + x[3]*y[0]*z[1] - x[3]*y[1]*z[0] + - x[0]*y[2]*z[3] + x[0]*y[3]*z[2] + x[2]*y[0]*z[3] + - x[2]*y[3]*z[0] - x[3]*y[0]*z[2] + x[3]*y[2]*z[0] + + x[1]*y[2]*z[3] - x[1]*y[3]*z[2] - x[2]*y[1]*z[3] + + x[2]*y[3]*z[1] + x[3]*y[1]*z[2] - x[3]*y[2]*z[1]; + return std::abs(det)/6; + }; + auto get_nodes = [](std::array X, std::array ind){ + std::array filtered_vector; + for (std::size_t index = 0; index < ind.size(); index++) { + filtered_vector[index] = X[ind[index]]; + } + return filtered_vector; + }; + auto get_all_cell_corners = [this](const auto& father_list){ + std::vector> X(father_list.size()); + std::vector> Y(father_list.size()); + std::vector> Z(father_list.size()); + for (std::size_t index = 0; index < father_list.size(); index++) { + getCellCorners(father_list[index],X[index],Y[index],Z[index]); + } + return std::make_tuple(X, Y,Z); + }; + auto is_inside = [get_nodes,tetra_vol](std::vector> centers, std::vector>& X, + std::vector>& Y,std::vector>& Z){ + std::array tet_1 = {1,2,3,4}; + + + for (std::size_t index = 0; index < X.size(); index) { + double cX = std::accumulate(X[index].begin(), X[index].end(), 0.0)/8; + double cY = std::accumulate(Y[index].begin(), Y[index].end(), 0.0)/8; + double cZ = std::accumulate(Z[index].begin(), Z[index].end(), 0.0)/8; + auto test = get_nodes(X[index],{1,2,3,4}); + auto vol12= tetra_vol(test,test,test); + + auto in33dex = 10; + + } + //auto test = get_nodes(X,{1,2,3,4}); + return 0; + }; + for (EclipseGridLGR& lgr_cell : lgr_children_cells) { + //EclipseGridLGR::vec_size_t father_host = lgr_cell.get_father_global(); + auto center_lgr_cells = get_all_cell_centers(lgr_cell, lgr_cell.getActiveMap()); + auto [host_cellX, host_cellY, host_cellZ] = get_all_cell_corners(lgr_cell.get_father_global()); + auto test = is_inside(center_lgr_cells, host_cellX,host_cellY,host_cellZ); + // getCellCorners(father_host[0],X,Y,Z); + // auto index = 1; } + } + + + const std::vector& EclipseGrid::getActiveMap() const { return m_active_to_global; } @@ -2084,11 +2146,11 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st if (!(i_list.size() == j_list.size()) && (j_list.size() == k_list.size()) ){ throw std::invalid_argument("Sizes are not compatible."); } - std::vector global_ind(i_list.size()); + std::vector global_ind_active(i_list.size()); for (std::size_t index = 0; index < i_list.size(); index++) { - global_ind[index] = this->getActiveIndex(i_list[index],j_list[index],k_list[index]); + global_ind_active[index] = this->getActiveIndex(i_list[index],j_list[index],k_list[index]); } - return global_ind; + return global_ind_active; }; auto parent_cellsIJK = [](const auto& lgr_cell){ std::vector i_list; @@ -2116,19 +2178,21 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st }; for (std::size_t index = 0; index < lgr_input.size(); index++) { - const auto lgr_cell = lgr_input.getLgr(index); -<<<<<<< HEAD - if (this->lgr_label == lgr_cell.PARENT_NAME()) { -======= - if (this->lgr_label.compare(lgr_cell.PARENT_NAME()) == 0) { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) + const auto& lgr_cell = lgr_input.getLgr(index); + if (this->lgr_label == lgr_cell.PARENT_NAME()){ lgr_grid = true; // auto [i_list, j_list, k_list] = lgr_cell.parent_cellsIJK(); auto [i_list, j_list, k_list] = parent_cellsIJK(lgr_cell); auto father_lgr_index = IJK_global(i_list, j_list, k_list); + + std::array lowIJK = {lgr_cell.I1(), lgr_cell.J1(),lgr_cell.K1()}; + std::array upIJK = {lgr_cell.I2(), lgr_cell.J2(),lgr_cell.K2()}; + + lgr_children_cells.emplace_back(lgr_cell.NAME(), this->lgr_label, this->lgr_level, - lgr_cell.NX(), lgr_cell.NY(), lgr_cell.NZ(), father_lgr_index); + lgr_cell.NX(), lgr_cell.NY(), lgr_cell.NZ(), father_lgr_index, + lowIJK,upIJK); lgr_children_cells.back().create_lgr_cells_tree(lgr_input); } @@ -2272,15 +2336,12 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } } -<<<<<<< HEAD const std::optional& EclipseGrid::getMapAxes() const { return this->m_mapaxes; } -======= ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) ZcornMapper::ZcornMapper(std::size_t nx , std::size_t ny, std::size_t nz) : dims( {{nx,ny,nz}} ), stride( {{2 , 4*nx, 8*nx*ny}} ), @@ -2303,15 +2364,11 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return i*stride[0] + j*stride[1] + k*stride[2] + cell_shift[c]; } - std::size_t ZcornMapper::size() const { + std::size_t ZcornMapper::size() const { return dims[0] * dims[1] * dims[2] * 8; } -<<<<<<< HEAD std::size_t ZcornMapper::index(std::size_t g, int c) const { -======= - std::size_t ZcornMapper::index(size_t g, int c) const { ->>>>>>> 91fad0554 (all types size_t in clipseGrid.cpp were change to std::size_t, ActiveIndexLGR renamed activeIndexLGR) int k = g / (dims[0] * dims[1]); g -= k * dims[0] * dims[1]; @@ -2437,4 +2494,117 @@ namespace Opm { { return father_global; } + void EclipseGridLGR::save(Opm::EclIO::EclOutput& egridfile, const std::vector& nnc, const Opm::UnitSystem& units) const { + const auto lgr_name_label = std::vector{ Opm::EclIO::PaddedOutputString<8>{ lgr_label }}; + egridfile.write("LGR",lgr_name_label); + //std::vector> lgr_father_name_label; + std::vector lgr_father_name_label; + if (lgr_level == 1){ + lgr_father_name_label.push_back(""); + } + else { + lgr_father_name_label.push_back(father_label); + } + egridfile.write("LGRPARNT", lgr_father_name_label); + + Opm::UnitSystem::UnitType unitSystemType = units.getType(); + constexpr auto length = ::Opm::UnitSystem::measure::length; + + const std::array dims = getNXYZ(); + + // Preparing vectors to be saved + + // create coord vector of floats with input units, converted from SI + std::vector coord_f; + coord_f.resize(m_coord.size()); + + auto convert_length = [&units](const double x) { return static_cast(units.from_si(length, x)); }; + + if (m_input_coord.has_value()) { + std::transform(m_input_coord.value().begin(), m_input_coord.value().end(), coord_f.begin(), convert_length); + } else { + std::transform(m_coord.begin(), m_coord.end(), coord_f.begin(), convert_length); + } + + // create zcorn vector of floats with input units, converted from SI + std::vector zcorn_f; + zcorn_f.resize(m_zcorn.size()); + + if (m_input_zcorn.has_value()) { + std::transform(m_input_zcorn.value().begin(), m_input_zcorn.value().end(), zcorn_f.begin(), convert_length); + } else { + std::transform(m_zcorn.begin(), m_zcorn.end(), zcorn_f.begin(), convert_length); + } + + m_input_coord.reset(); + m_input_zcorn.reset(); + + // corner point grid + + std::vector gridhead(100,0); + // GLOBAL and LGR Gridhead + gridhead[0] = 1; // corner point grid + gridhead[1] = dims[0]; // nI + gridhead[2] = dims[1]; // nJ + gridhead[3] = dims[2]; // nK + gridhead[4] = lgr_level; // LGR index + + // LGR Exclusive Gridhead + gridhead[24] = 1; // number of reservoirs + gridhead[25] = 1; // number of coordinate line seg + gridhead[26] = 0; // NTHETA =0 non-radial + gridhead[27] = low_fahterIJK[0] + 1;// Lower I-index-host + gridhead[28] = low_fahterIJK[1] + 1;// Lower J-index-host + gridhead[29] = low_fahterIJK[2] + 1;// Lower K-index-host + gridhead[30] = up_fahterIJK[0] + 1; // Upper I-index-host + gridhead[31] = up_fahterIJK[1] + 1; // Upper J-index-host + gridhead[32] = up_fahterIJK[2] + 1; // Upper K-index-host + + std::vector nnchead(10, 0); + std::vector nnc1; + std::vector nnc2; + + for (const NNCdata& n : nnc ) { + nnc1.push_back(n.cell1 + 1); + nnc2.push_back(n.cell2 + 1); + } + + nnchead[0] = nnc1.size(); + + std::vector endgrid = {}; + + // Writing vectors to egrid file + + egridfile.write("GRIDHEAD", gridhead); + + egridfile.write("COORD", coord_f); + egridfile.write("ZCORN", zcorn_f); + + egridfile.write("ACTNUM", m_actnum); + egridfile.write("HOSTNUM", m_actnum); + egridfile.write("ENDGRID", endgrid); + egridfile.write("ENDLGR", endgrid); + for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { + lgr_cell.save(egridfile, nnc, units); + } + } + + void EclipseGridLGR::save_nnc(Opm::EclIO::EclOutput& egridfile) const{ + + std::vector nnchead(10, 0); + std::vector nnc1; + std::vector nnc2; + + /* to be implemented based on how the NNC is input */ + // for (const NNCdata& n : nnc ) { + // nnc1.push_back(n.cell1 + 1); + // nnc2.push_back(n.cell2 + 1); + // } + egridfile.write("NNCL", nnc1); + egridfile.write("NNCG", nnc2); + nnchead[0] = nnc1.size(); + + } + + } diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 51b56873623..9de7e976aef 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace Opm { @@ -119,6 +120,8 @@ namespace Opm { from an active index to a global index must be implemented in the current class. */ + void init_children_host_cells(void); + using GridDims::getGlobalIndex; size_t getGlobalIndex(size_t active_index) const; @@ -268,7 +271,11 @@ namespace Opm { std::map, std::size_t> num_lgr_children_cells; std::vector m_zcorn; std::vector m_coord; + std::vector m_actnum; + // Input grid data. + mutable std::optional> m_input_zcorn; + mutable std::optional> m_input_coord; private: std::vector m_minpvVector; @@ -289,13 +296,7 @@ namespace Opm { size_t zcorn_fixed = 0; bool m_useActnumFromGdfile = false; - // Input grid data. - mutable std::optional> m_input_zcorn; - mutable std::optional> m_input_coord; - - - std::vector m_actnum; std::optional m_mapaxes; // Mapping to/from active cells. @@ -381,6 +382,8 @@ namespace Opm { std::string father_label; // references global on the father label vec_size_t father_global; + std::array low_fahterIJK; + std::array up_fahterIJK; }; diff --git a/opm/io/eclipse/EGrid.hpp b/opm/io/eclipse/EGrid.hpp index 92794589660..f748eac8a67 100644 --- a/opm/io/eclipse/EGrid.hpp +++ b/opm/io/eclipse/EGrid.hpp @@ -68,8 +68,6 @@ class EGrid : public EclFile const std::array& get_mapaxes() const { return m_mapaxes; } const std::string& get_mapunits() const { return m_mapunits; } - - const std::vector& get_coord() const { return coord_array; } const std::vector& get_zcorn() const { return zcorn_array; } diff --git a/tests/parser/LgrOutputTests.cpp b/tests/parser/LgrOutputTests.cpp index fc70abafda7..3dea91b23f3 100644 --- a/tests/parser/LgrOutputTests.cpp +++ b/tests/parser/LgrOutputTests.cpp @@ -13,6 +13,7 @@ along with OPM. If not, see . */ +#include #include #define BOOST_TEST_MODULE LgrOutputTests @@ -40,9 +41,12 @@ LgrCollection read_lgr(const std::string& deck_string, std::size_t nx, std::size std::pair, std::vector> read_cpg_from_egrid(const std::string& file_path, const std::string& lgr_label){ Opm::EclIO::EGrid egrid_global(file_path, lgr_label); + // Opm::EclIO::EGrid egrid_global(file_path); egrid_global.load_grid_data(); + // auto global_coord = egrid_global.get("COORD"); + // auto global_zcorn = egrid_global.get("ZCORN"); auto global_coord = egrid_global.get_coord(); - auto global_zcorn = egrid_global.get_zcorn(); + auto global_zcorn = egrid_global.get_zcorn(); std::vector coord_g(global_coord.begin(), global_coord.end()); std::vector zcorn_g(global_zcorn.begin(), global_zcorn.end()); return std::make_pair(coord_g, zcorn_g); @@ -104,14 +108,22 @@ SOLUTION SCHEDULE )"; \ + Opm::UnitSystem units(1); + std::vector vecNNC; std::array global_grid_dim = {3,3,1}; LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); auto [coord_g, zcorn_g] = read_cpg_from_egrid("CARFIN5.EGRID", "global"); Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); + + eclipse_grid_file.init_lgr_cells(lgr_col); + eclipse_grid_file.init_children_host_cells(); + auto [coord_l, zcorn_l] = read_cpg_from_egrid("CARFIN5.EGRID", "LGR1"); eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l,zcorn_l); + //eclipse_grid_file.save("output.FEGRID",true,std::nullopt); + eclipse_grid_file.save("output.FEGRID",true,vecNNC,units); auto index = 1; From 05d8fe5c82e7c1c185d8b450e1ea3f140bfdabd9 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Mon, 28 Oct 2024 14:45:40 +0000 Subject: [PATCH 27/60] test to check if LGR cell is insded host cell created, contain bugs and lacks tests --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 174 ++++++++++++++---- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 2 + tests/parser/LgrOutputTests.cpp | 4 +- 3 files changed, 145 insertions(+), 35 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 7391e8f22b2..baf08ff9afd 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -1983,12 +1983,17 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st void EclipseGrid::init_children_host_cells(){ auto get_all_cell_centers = [](const auto& cell, const auto& global_list){ - std::vector> cell_centers(global_list.size()); + std::vector cell_centersX(global_list.size()); + std::vector cell_centersY(global_list.size()); + std::vector cell_centersZ(global_list.size()); + // std::vector value; for (std::size_t index = 0; index < global_list.size(); index++) { - cell_centers[index] = cell.getCellCenter(global_list[index]); - //cell_centers[index] = this->getActiveIndex(i_list[index],j_list[index],k_list[index]); + auto value = cell.getCellCenter(global_list[index]); + cell_centersX[index] = value[0]; + cell_centersY[index] = value[1]; + cell_centersZ[index] = value[2]; } - return cell_centers; + return std::make_tuple(cell_centersX,cell_centersY,cell_centersZ); }; auto tetra_vol = [](const auto& x, const auto& y, const auto& z){ auto det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] @@ -2001,13 +2006,97 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st + x[2]*y[3]*z[1] + x[3]*y[1]*z[2] - x[3]*y[2]*z[1]; return std::abs(det)/6; }; - auto get_nodes = [](std::array X, std::array ind){ - std::array filtered_vector; + + auto append_node = [](const std::array& X, const std::array& Y, const std::array& Z, + const double& xc, const double& yc, const double& zc ){ + std::array tX; + std::array tY; + std::array tZ; + std::copy(X.begin(), X.end(), tX.begin()); + tX[3]= xc; + std::copy(Y.begin(), Y.end(), tY.begin()); + tY[3]= yc; + std::copy(Z.begin(), Z.end(), tZ.begin()); + tZ[3]= zc; + return std::make_tuple(tX,tY,tZ); + }; + auto get_nodes = [](const std::array& X, const std::array& Y, const std::array& Z, + const std::array& ind){ + std::array filtered_vectorX; + std::array filtered_vectorY; + std::array filtered_vectorZ; for (std::size_t index = 0; index < ind.size(); index++) { - filtered_vector[index] = X[ind[index]]; + filtered_vectorX[index] = X[ind[index]]; + filtered_vectorY[index] = Y[ind[index]]; + filtered_vectorZ[index] = Z[ind[index]]; } - return filtered_vector; + return std::make_tuple(filtered_vectorX,filtered_vectorY,filtered_vectorZ); + }; + auto calc_vol = [get_nodes,append_node, tetra_vol] + (const auto& x, const auto& y, const auto& z, + const auto& pcX, const auto& pcY, const auto& pcZ ){ + // node order of each face + // Face 0 = {0,1,5,6} + std::array fc0_0 = {0,1,5}; + std::array fc0_1 = {1,5,6}; + // Face 1 = {0,4,6,2} + std::array fc1_0 = {0,4,6}; + std::array fc1_1 = {4,6,2}; + // Face 2 = {2,3,7,6} + std::array fc2_0 = {2,3,7}; + std::array fc2_1 = {3,7,6}; + // Face 3 = {1,3,7,5} + std::array fc3_0 = {1,3,7}; + std::array fc3_1 = {3,7,5}; + // Face 4 = {0,1,3,2} + std::array fc4_0 = {0,1,3}; + std::array fc4_1 = {1,3,2}; + // Face 5 = {4,5,7,6} + std::array fc5_0 = {4,5,7}; + std::array fc5_1 = {5,7,6}; + + std::array f0,f1,f2; + // note: some CPG grids may have collapsed faces that are not planar, therefore + // the volume of the tetrhadron was used. + // calculating the volume of the pyramid with F0 as base and pc as center + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc0_0); + auto tetraFO = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc0_1); + tetraFO = tetraFO + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + + // calculating the volume of the pyramid with F1 as base and pc as center + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc1_0); + auto tetraF1 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc1_1); + tetraF1 = tetraF1 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + + + // calculating the volume of the pyramid with F2 as base and pc as center + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc2_0); + auto tetraF2 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc2_1); + tetraF2 = tetraF2 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + + // calculating the volume of the pyramid with F3 as base and pc as center + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc3_0); + auto tetraF3 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc3_1); + tetraF3 = tetraF3 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + + // calculating the volume of the pyramid with F4 as base and pc as center + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc4_0); + auto tetraF4 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc4_1); + tetraF4 = tetraF4 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + + // calculating the volume of the pyramid with F5 as base and pc as center + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc5_0); + auto tetraF5 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + std::tie(f0,f1,f2) = get_nodes(x,y,z,fc5_1); + tetraF5 = tetraF5 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + return tetraFO + tetraF1 + tetraF2 + tetraF3 + tetraF4 + tetraF5; }; + auto get_all_cell_corners = [this](const auto& father_list){ std::vector> X(father_list.size()); std::vector> Y(father_list.size()); @@ -2017,31 +2106,46 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } return std::make_tuple(X, Y,Z); }; - auto is_inside = [get_nodes,tetra_vol](std::vector> centers, std::vector>& X, - std::vector>& Y,std::vector>& Z){ - std::array tet_1 = {1,2,3,4}; - - - for (std::size_t index = 0; index < X.size(); index) { - double cX = std::accumulate(X[index].begin(), X[index].end(), 0.0)/8; - double cY = std::accumulate(Y[index].begin(), Y[index].end(), 0.0)/8; - double cZ = std::accumulate(Z[index].begin(), Z[index].end(), 0.0)/8; - auto test = get_nodes(X[index],{1,2,3,4}); - auto vol12= tetra_vol(test,test,test); - - auto in33dex = 10; - + auto is_inside = [calc_vol](const std::vector& tpX, const std::vector& tpY, const std::vector& tpZ, + const std::vector>& X, const std::vector>& Y, + const std::vector>& Z){ + std::vector in_elements(tpX.size(),0); + // check if it is insde or outside boundary box + double minX, minY, minZ, maxX, maxY, maxZ; + double pcX, pcY, pcZ, element_volume, test_element_volume; + bool flag; + for (std::size_t outerIndex = 0; outerIndex < X.size(); outerIndex++) { + minX = *std::min_element(X[outerIndex].begin(), X[outerIndex].end()); + minY = *std::min_element(Y[outerIndex].begin(), Y[outerIndex].end()); + minZ = *std::min_element(Z[outerIndex].begin(), Z[outerIndex].end()); + maxX = *std::max_element(X[outerIndex].begin(), X[outerIndex].end()); + maxY = *std::max_element(Y[outerIndex].begin(), Y[outerIndex].end()); + maxZ = *std::max_element(Z[outerIndex].begin(), Z[outerIndex].end()); + pcX = std::accumulate(X[outerIndex].begin(), X[outerIndex].end(), 0.0)/8; + pcY = std::accumulate(Y[outerIndex].begin(), Y[outerIndex].end(), 0.0)/8; + pcZ = std::accumulate(Z[outerIndex].begin(), Z[outerIndex].end(), 0.0)/8; + element_volume = calc_vol(X[outerIndex],Y[outerIndex],Z[outerIndex], pcX, pcY,pcZ); + for (size_t innerIndex = 0; innerIndex < tpX.size(); innerIndex++) + { + flag = (minX < tpX[outerIndex]) && (maxX > tpX[innerIndex]) && + (minY < tpY[outerIndex]) && (maxY > tpY[innerIndex]) && + (minZ < tpZ[outerIndex]) && (maxZ > tpZ[innerIndex]); + if (flag) { + test_element_volume = calc_vol(X[outerIndex],Y[outerIndex],Z[outerIndex], + tpX[innerIndex], tpY[innerIndex],tpZ[innerIndex]); + if (test_element_volume <= element_volume) {in_elements[innerIndex] = outerIndex;} + } + } } - //auto test = get_nodes(X,{1,2,3,4}); - return 0; + return in_elements; }; - for (EclipseGridLGR& lgr_cell : lgr_children_cells) { - //EclipseGridLGR::vec_size_t father_host = lgr_cell.get_father_global(); - auto center_lgr_cells = get_all_cell_centers(lgr_cell, lgr_cell.getActiveMap()); - auto [host_cellX, host_cellY, host_cellZ] = get_all_cell_corners(lgr_cell.get_father_global()); - auto test = is_inside(center_lgr_cells, host_cellX,host_cellY,host_cellZ); - // getCellCorners(father_host[0],X,Y,Z); - // auto index = 1; + for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { + //EclipseGridLGR::vec_size_t father_host = lgr_cell.get_father_global(); + auto test = lgr_cell.getActiveMap(); + auto indexx = 1; + // auto [cell_centerX, cell_centerY,cell_centerZ] = get_all_cell_centers(lgr_cell, lgr_cell.getActiveMap()); + // auto [host_cellX, host_cellY, host_cellZ] = get_all_cell_corners(lgr_cell.get_father_global()); + // lgr_cell.set_hostnum(is_inside(cell_centerX,cell_centerY, cell_centerZ, host_cellX, host_cellY, host_cellZ)); } } @@ -2480,6 +2584,10 @@ namespace Opm { lgr_label= self_label; lgr_level = father_lgr_level + 1 ; } + void EclipseGridLGR::set_hostnum(const std::vector hostnum) + { + m_hostnum = hostnum; + } void EclipseGridLGR::set_lgr_refinement(std::vector coord, std::vector zcorn) { m_coord = coord; @@ -2549,7 +2657,7 @@ namespace Opm { gridhead[3] = dims[2]; // nK gridhead[4] = lgr_level; // LGR index - // LGR Exclusive Gridhead + // LGR Exclusive Gridhead Flags gridhead[24] = 1; // number of reservoirs gridhead[25] = 1; // number of coordinate line seg gridhead[26] = 0; // NTHETA =0 non-radial @@ -2581,7 +2689,7 @@ namespace Opm { egridfile.write("ZCORN", zcorn_f); egridfile.write("ACTNUM", m_actnum); - egridfile.write("HOSTNUM", m_actnum); + egridfile.write("HOSTNUM", m_hostnum); egridfile.write("ENDGRID", endgrid); egridfile.write("ENDLGR", endgrid); for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 9de7e976aef..3b460ff642e 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -376,6 +376,7 @@ namespace Opm { const vec_size_t& get_father_global() const{ return father_global; } + void set_hostnum(const std::vector); void set_lgr_refinement(std::vector,std::vector); private: void init_father_global(); @@ -384,6 +385,7 @@ namespace Opm { vec_size_t father_global; std::array low_fahterIJK; std::array up_fahterIJK; + std::vector m_hostnum; }; diff --git a/tests/parser/LgrOutputTests.cpp b/tests/parser/LgrOutputTests.cpp index 3dea91b23f3..0d5ea8e6b70 100644 --- a/tests/parser/LgrOutputTests.cpp +++ b/tests/parser/LgrOutputTests.cpp @@ -114,13 +114,13 @@ SCHEDULE LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); auto [coord_g, zcorn_g] = read_cpg_from_egrid("CARFIN5.EGRID", "global"); Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); - eclipse_grid_file.init_lgr_cells(lgr_col); - eclipse_grid_file.init_children_host_cells(); auto [coord_l, zcorn_l] = read_cpg_from_egrid("CARFIN5.EGRID", "LGR1"); eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l,zcorn_l); + eclipse_grid_file.init_children_host_cells(); + //eclipse_grid_file.save("output.FEGRID",true,std::nullopt); eclipse_grid_file.save("output.FEGRID",true,vecNNC,units); From 9d788474aa9487965f68cb876ac35a81ca473b45 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Tue, 29 Oct 2024 07:53:55 +0000 Subject: [PATCH 28/60] EclipseGrid is capable of initializing EclipseGridLGR hostcells. --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 89 +++++++++++++------ .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 2 +- 2 files changed, 62 insertions(+), 29 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index baf08ff9afd..142b1049468 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -1986,15 +1986,26 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector cell_centersX(global_list.size()); std::vector cell_centersY(global_list.size()); std::vector cell_centersZ(global_list.size()); - // std::vector value; + std::array value = {0,0,0}; for (std::size_t index = 0; index < global_list.size(); index++) { - auto value = cell.getCellCenter(global_list[index]); + value = cell.getCellCenter(global_list[index]); cell_centersX[index] = value[0]; cell_centersY[index] = value[1]; cell_centersZ[index] = value[2]; } return std::make_tuple(cell_centersX,cell_centersY,cell_centersZ); }; + + auto get_all_cell_corners = [this](const auto& father_list){ + std::vector> X(father_list.size()); + std::vector> Y(father_list.size()); + std::vector> Z(father_list.size()); + for (std::size_t index = 0; index < father_list.size(); index++) { + getCellCorners(father_list[index],X[index],Y[index],Z[index]); + } + return std::make_tuple(X, Y,Z); + }; + auto tetra_vol = [](const auto& x, const auto& y, const auto& z){ auto det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] - x[1]*y[2]*z[0] - x[2]*y[0]*z[1] + x[2]*y[1]*z[0] @@ -2020,6 +2031,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st tZ[3]= zc; return std::make_tuple(tX,tY,tZ); }; + auto get_nodes = [](const std::array& X, const std::array& Y, const std::array& Z, const std::array& ind){ std::array filtered_vectorX; @@ -2032,6 +2044,15 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } return std::make_tuple(filtered_vectorX,filtered_vectorY,filtered_vectorZ); }; + + auto filter_array = [](const std::vector& X, const std::vector& ind){ + std::vector filtered_vectorX(ind.size(),0); + for (std::size_t index = 0; index < ind.size(); index++) { + filtered_vectorX[index] = X[ind[index]]; + } + return filtered_vectorX; + }; + auto calc_vol = [get_nodes,append_node, tetra_vol] (const auto& x, const auto& y, const auto& z, const auto& pcX, const auto& pcY, const auto& pcZ ){ @@ -2097,15 +2118,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return tetraFO + tetraF1 + tetraF2 + tetraF3 + tetraF4 + tetraF5; }; - auto get_all_cell_corners = [this](const auto& father_list){ - std::vector> X(father_list.size()); - std::vector> Y(father_list.size()); - std::vector> Z(father_list.size()); - for (std::size_t index = 0; index < father_list.size(); index++) { - getCellCorners(father_list[index],X[index],Y[index],Z[index]); - } - return std::make_tuple(X, Y,Z); - }; + auto is_inside = [calc_vol](const std::vector& tpX, const std::vector& tpY, const std::vector& tpZ, const std::vector>& X, const std::vector>& Y, const std::vector>& Z){ @@ -2125,28 +2138,47 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st pcY = std::accumulate(Y[outerIndex].begin(), Y[outerIndex].end(), 0.0)/8; pcZ = std::accumulate(Z[outerIndex].begin(), Z[outerIndex].end(), 0.0)/8; element_volume = calc_vol(X[outerIndex],Y[outerIndex],Z[outerIndex], pcX, pcY,pcZ); - for (size_t innerIndex = 0; innerIndex < tpX.size(); innerIndex++) - { - flag = (minX < tpX[outerIndex]) && (maxX > tpX[innerIndex]) && - (minY < tpY[outerIndex]) && (maxY > tpY[innerIndex]) && - (minZ < tpZ[outerIndex]) && (maxZ > tpZ[innerIndex]); - if (flag) { + for (size_t innerIndex = 0; innerIndex < tpX.size(); innerIndex++){ + // check if center of refined volume is outside the boundary box of a coarse volume. + // Only computes volumed base test is this condition is met. + flag = (minX < tpX[innerIndex]) && (maxX > tpX[innerIndex]) && + (minY < tpY[innerIndex]) && (maxY > tpY[innerIndex]) && + (minZ < tpZ[innerIndex]) && (maxZ > tpZ[innerIndex]); + if (flag && (in_elements[innerIndex] == 0)) { test_element_volume = calc_vol(X[outerIndex],Y[outerIndex],Z[outerIndex], tpX[innerIndex], tpY[innerIndex],tpZ[innerIndex]); - if (test_element_volume <= element_volume) {in_elements[innerIndex] = outerIndex;} + if (test_element_volume <= element_volume){ + in_elements[innerIndex] = static_cast(outerIndex); + } } } } return in_elements; }; - for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { - //EclipseGridLGR::vec_size_t father_host = lgr_cell.get_father_global(); - auto test = lgr_cell.getActiveMap(); - auto indexx = 1; - // auto [cell_centerX, cell_centerY,cell_centerZ] = get_all_cell_centers(lgr_cell, lgr_cell.getActiveMap()); - // auto [host_cellX, host_cellY, host_cellZ] = get_all_cell_corners(lgr_cell.get_father_global()); - // lgr_cell.set_hostnum(is_inside(cell_centerX,cell_centerY, cell_centerZ, host_cellX, host_cellY, host_cellZ)); - } + + std::vector element_centerX, element_centerY, element_centerZ; + for (EclipseGridLGR& lgr_cell : lgr_children_cells) { + std::tie(element_centerX, element_centerY,element_centerZ) = get_all_cell_centers(lgr_cell, lgr_cell.getActiveMap()); + auto [host_cellX, host_cellY, host_cellZ] = get_all_cell_corners(lgr_cell.get_father_global()); + auto inside_el = is_inside(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); + auto host_cells_global_ref = filter_array(lgr_cell.get_father_global(), inside_el); + lgr_cell.set_hostnum(host_cells_global_ref); + std::cout< hostnum) - { + void EclipseGridLGR::set_hostnum(std::vector& hostnum) + { + std::transform(hostnum.begin(),hostnum.end(), hostnum.begin(), [](int a){return a+1;}); m_hostnum = hostnum; } void EclipseGridLGR::set_lgr_refinement(std::vector coord, std::vector zcorn) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 3b460ff642e..551f506b604 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -376,7 +376,7 @@ namespace Opm { const vec_size_t& get_father_global() const{ return father_global; } - void set_hostnum(const std::vector); + void set_hostnum(std::vector&); void set_lgr_refinement(std::vector,std::vector); private: void init_father_global(); From 17959451d24ff3f3761063dcd1b273167b74d283 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Tue, 29 Oct 2024 10:26:06 +0000 Subject: [PATCH 29/60] fixed a bug in calc_vol - the order of the associated first pyramid was incorrect --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 28 +- tests/parser/LgrOutputTests.cpp | 315 +++++------------- 2 files changed, 90 insertions(+), 253 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 142b1049468..7875350f300 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -2057,9 +2057,9 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st (const auto& x, const auto& y, const auto& z, const auto& pcX, const auto& pcY, const auto& pcZ ){ // node order of each face - // Face 0 = {0,1,5,6} + // Face 0 = {0,1,5,4} std::array fc0_0 = {0,1,5}; - std::array fc0_1 = {1,5,6}; + std::array fc0_1 = {1,5,4}; // Face 1 = {0,4,6,2} std::array fc1_0 = {0,4,6}; std::array fc1_1 = {4,6,2}; @@ -2078,12 +2078,12 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::array f0,f1,f2; // note: some CPG grids may have collapsed faces that are not planar, therefore - // the volume of the tetrhadron was used. + // the hexadron is subdivided in terahedrons. // calculating the volume of the pyramid with F0 as base and pc as center std::tie(f0,f1,f2) = get_nodes(x,y,z,fc0_0); - auto tetraFO = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + auto tetraF0 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); std::tie(f0,f1,f2) = get_nodes(x,y,z,fc0_1); - tetraFO = tetraFO + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); + tetraF0 = tetraF0 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); // calculating the volume of the pyramid with F1 as base and pc as center std::tie(f0,f1,f2) = get_nodes(x,y,z,fc1_0); @@ -2115,7 +2115,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st auto tetraF5 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); std::tie(f0,f1,f2) = get_nodes(x,y,z,fc5_1); tetraF5 = tetraF5 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - return tetraFO + tetraF1 + tetraF2 + tetraF3 + tetraF4 + tetraF5; + return tetraF0 + tetraF1 + tetraF2 + tetraF3 + tetraF4 + tetraF5; }; @@ -2163,23 +2163,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st auto inside_el = is_inside(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); auto host_cells_global_ref = filter_array(lgr_cell.get_father_global(), inside_el); lgr_cell.set_hostnum(host_cells_global_ref); - std::cout<. */ +#include #include +#include #include #define BOOST_TEST_MODULE LgrOutputTests @@ -53,7 +55,7 @@ std::pair, std::vector> read_cpg_from_egrid(const st } -BOOST_AUTO_TEST_CASE(TestLgrOutput) { +BOOST_AUTO_TEST_CASE(TestLgrOutputBasicLGR) { const std::string deck_string = R"( RUNSPEC @@ -111,63 +113,50 @@ SCHEDULE Opm::UnitSystem units(1); std::vector vecNNC; std::array global_grid_dim = {3,3,1}; + std::vector coord_g, zcorn_g, coord_l, zcorn_l, coord_g_opm, zcorn_g_opm, coord_l_opm, zcorn_l_opm; + // Intialize LgrCollection from string. LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); - auto [coord_g, zcorn_g] = read_cpg_from_egrid("CARFIN5.EGRID", "global"); + // Read global COORD and ZCORN from reference simulator output. + std::tie(coord_g, zcorn_g) = read_cpg_from_egrid("CARFIN5.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l, zcorn_l) = read_cpg_from_egrid("CARFIN5.EGRID", "LGR1"); + // Eclipse Grid is intialzied with COORD and ZCORN. Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); - + // LgrCollection is used to initalize LGR Cells in the Eclipse Grid. eclipse_grid_file.init_lgr_cells(lgr_col); - - auto [coord_l, zcorn_l] = read_cpg_from_egrid("CARFIN5.EGRID", "LGR1"); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l,zcorn_l); + // Intialize host_cell numbering. eclipse_grid_file.init_children_host_cells(); - - //eclipse_grid_file.save("output.FEGRID",true,std::nullopt); - - eclipse_grid_file.save("output.FEGRID",true,vecNNC,units); - auto index = 1; - - - // Opm::EclipseGrid eclipse_grid = state.getInputGrid(); - - - - // Opm::EclIO::EGrid egrid_global("CARFIN5.EGRID"); - // egrid_global.load_grid_data(); - // auto global_coord = egrid_global.get_coord(); - // auto global_zcorn = egrid_global.get_zcorn(); - - // std::vector coord_g(global_coord.begin(), global_coord.end()); - // std::vector zcorn_g(global_zcorn.begin(), global_zcorn.end()); - // std::array dims = {3,3, 1}; - - // Opm::EclipseGrid eclipse_grid_file(dims, coord_g, zcorn_g); - - - - - // Opm::EclIO::EGrid egrid_lgr1("CARFIN5.EGRID","LGR1"); - // egrid_lgr1.load_grid_data(); - // BOOST_CHECK_EQUAL( eclipse_grid.getTotalActiveLGR() , 21U ); - // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 8U ); - // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[1].getTotalActiveLGR() , 8U ); - - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0,0,0), 0U); - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",1,3,0), 7U); - - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",1,0,0), 8U); - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",1,1,0), 17U); - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",2,2,0), 20U); - - - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",0,0,0), 9U); - // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",1,3,0), 16U); + // Save EclipseGrid. + eclipse_grid_file.save("OPMCARFIN5.EGRID",false,vecNNC,units); + // Once the new EGRID is saved, another EclipseGrid Object is created for the sake of comparison. + std::tie(coord_g_opm, zcorn_g_opm) = read_cpg_from_egrid("OPMCARFIN5.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l_opm, zcorn_l_opm) = read_cpg_from_egrid("OPMCARFIN5.EGRID", "LGR1"); + // Eclipse Grid is intialzied with COORD and ZCORN. + Opm::EclipseGrid eclipse_grid_OPM(global_grid_dim, coord_g_opm, zcorn_g_opm); +// LgrCollection is used to initalize LGR Cells in the Eclipse Grid. + eclipse_grid_OPM.init_lgr_cells(lgr_col); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) + eclipse_grid_OPM.lgr_children_cells[0].set_lgr_refinement(coord_l_opm,zcorn_l_opm); + // Intialize host_cell numbering. + eclipse_grid_OPM.init_children_host_cells(); + BOOST_CHECK_EQUAL( coord_g_opm.size() , coord_g.size()); + BOOST_CHECK_EQUAL( zcorn_g_opm.size() , zcorn_g.size()); + BOOST_CHECK_EQUAL( coord_l_opm.size() , coord_l.size()); + BOOST_CHECK_EQUAL( zcorn_l_opm.size() , zcorn_l.size()); + std::size_t index ; + for (index = 0; index < coord_g.size(); index++) { + BOOST_CHECK_EQUAL( coord_g_opm[index] , coord_g[index]); + } + for (index = 0; index < zcorn_g.size(); index++) { + BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); + } } - - - -BOOST_AUTO_TEST_CASE(TestLgrNested) { +BOOST_AUTO_TEST_CASE(TestLgrOutputColumnLGR) { const std::string deck_string = R"( RUNSPEC @@ -178,15 +167,9 @@ GRID CARFIN -- NAME I1-I2 J1-J2 K1-K2 NX NY NZ -LGR1 2 2 2 2 1 1 3 3 1 1* GLOBAL/ +'LGR1' 1 1 1 2 1 1 2 4 1/ ENDFIN -CARFIN --- NAME I1-I2 J1-J2 K1-K2 NX NY NZ -LGR2 2 2 2 2 1 1 3 3 1 1* LGR1/ -ENDFIN - - DX 9*1000 / DY @@ -228,177 +211,47 @@ SOLUTION SCHEDULE )"; \ - Opm::Parser parser; - Opm::Deck deck = parser.parseString(deck_string); - Opm::EclipseState state(deck); - Opm::EclipseGrid eclipse_grid = state.getInputGrid(); - - BOOST_CHECK_EQUAL( eclipse_grid.getTotalActiveLGR() , 25U ); - BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 17U ); - BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].lgr_children_cells[0].getTotalActiveLGR() , 9U ); - - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0,0,0), 0U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",2,2,0), 24U); - - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0,0,0), 4U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",2,2,0), 20U); - - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",0,0,0), 8U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",2,2,0), 16U); - - BOOST_CHECK_THROW(eclipse_grid.getActiveIndexLGR("GLOBAL",1,1,0), std::invalid_argument); - BOOST_CHECK_THROW(eclipse_grid.getActiveIndexLGR("LGR1",1,1,0), std::invalid_argument); - BOOST_CHECK_THROW(eclipse_grid.getActiveIndexLGR("LGR3",1,1,0), std::invalid_argument); -} -BOOST_AUTO_TEST_CASE(TestGLOBALinactivecells) { - const std::string deck_string = R"( -RUNSPEC - -DIMENS - 3 3 1 / - -GRID - -ACTNUM -1 0 1 -1 1 1 -1 1 1 -/ - -CARFIN --- NAME I1-I2 J1-J2 K1-K2 NX NY NZ -'LGR1' 2 2 2 2 1 1 3 3 1/ -ENDFIN - - -DX - 9*1000 / -DY - 9*1000 / -DZ - 9*20 / - -TOPS - 9*8325 / - -PORO - 9*0.15 / - -PERMX - 9*1 / - -COPY - PERMX PERMZ / - PERMX PERMY / -/ - -EDIT - -OIL -GAS - -TITLE -The title - -START -16 JUN 1988 / - -PROPS - -REGIONS - -SOLUTION - -SCHEDULE -)"; -\ - Opm::Parser parser; - Opm::Deck deck = parser.parseString(deck_string); - Opm::EclipseState state(deck); - Opm::EclipseGrid eclipse_grid = state.getInputGrid(); - - BOOST_CHECK_EQUAL( eclipse_grid.getTotalActiveLGR() , 16U ); - BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 9U ); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0,0,0), 0U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",2,2,0), 15U); - - - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0U), 0U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",8U), 15U); - - - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0,0,0), 3U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",2,2,0), 11U); - - - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0), 3U); - BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",8), 11U); - -} - -BOOST_AUTO_TEST_CASE(TestLGRinactivecells) { - const std::string deck_string = R"( -RUNSPEC - -DIMENS - 3 3 1 / - -GRID - -CARFIN --- NAME I1-I2 J1-J2 K1-K2 NX NY NZ -'LGR1' 2 2 2 2 1 1 3 3 1/ -ACTNUM -1 0 1 -1 1 1 -1 1 1 -/ -ENDFIN - -DX - 9*1000 / -DY - 9*1000 / -DZ - 9*20 / - -TOPS - 9*8325 / - -PORO - 9*0.15 / - -PERMX - 9*1 / - -COPY - PERMX PERMZ / - PERMX PERMY / -/ - -EDIT - -OIL -GAS - -TITLE -The title - -START -16 JUN 1988 / - -PROPS - -REGIONS - -SOLUTION - -SCHEDULE -)"; -\ - Opm::Parser parser; - Opm::Deck deck = parser.parseString(deck_string); - Opm::EclipseState state(deck); - Opm::LgrCollection lgrs = state.getLgrs(); - // LGR Inactive Cells Not yet Implemented -} + Opm::UnitSystem units(1); + std::vector vecNNC; + std::array global_grid_dim = {3,3,1}; + std::vector coord_g, zcorn_g, coord_l, zcorn_l, coord_g_opm, zcorn_g_opm, coord_l_opm, zcorn_l_opm; + // Intialize LgrCollection from string. + LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); + // Read global COORD and ZCORN from reference simulator output. + std::tie(coord_g, zcorn_g) = read_cpg_from_egrid("CARFIN-COLUMN.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l, zcorn_l) = read_cpg_from_egrid("CARFIN-COLUMN.EGRID", "LGR1"); + // Eclipse Grid is intialzied with COORD and ZCORN. + Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); + // LgrCollection is used to initalize LGR Cells in the Eclipse Grid. + eclipse_grid_file.init_lgr_cells(lgr_col); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) + eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l,zcorn_l); + // Intialize host_cell numbering. + eclipse_grid_file.init_children_host_cells(); + // Save EclipseGrid. + eclipse_grid_file.save("OPMCARFIN-COLUMN.EGRID",false,vecNNC,units); + // Once the new EGRID is saved, another EclipseGrid Object is created for the sake of comparison. + std::tie(coord_g_opm, zcorn_g_opm) = read_cpg_from_egrid("OPMCARFIN-COLUMN.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l_opm, zcorn_l_opm) = read_cpg_from_egrid("OPMCARFIN-COLUMN.EGRID", "LGR1"); + // Eclipse Grid is intialzied with COORD and ZCORN. + Opm::EclipseGrid eclipse_grid_OPM(global_grid_dim, coord_g_opm, zcorn_g_opm); +// LgrCollection is used to initalize LGR Cells in the Eclipse Grid. + eclipse_grid_OPM.init_lgr_cells(lgr_col); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) + eclipse_grid_OPM.lgr_children_cells[0].set_lgr_refinement(coord_l_opm,zcorn_l_opm); + // Intialize host_cell numbering. + eclipse_grid_OPM.init_children_host_cells(); + BOOST_CHECK_EQUAL( coord_g_opm.size() , coord_g.size()); + BOOST_CHECK_EQUAL( zcorn_g_opm.size() , zcorn_g.size()); + BOOST_CHECK_EQUAL( coord_l_opm.size() , coord_l.size()); + BOOST_CHECK_EQUAL( zcorn_l_opm.size() , zcorn_l.size()); + std::size_t index ; + for (index = 0; index < coord_g.size(); index++) { + BOOST_CHECK_EQUAL( coord_g_opm[index] , coord_g[index]); + } + for (index = 0; index < zcorn_g.size(); index++) { + BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); + } + } From 2245ddefdaf5f53ddd4d8bda584215cc411f2c34 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Tue, 29 Oct 2024 10:59:29 +0000 Subject: [PATCH 30/60] EclipseGrid::init_children_host_cells refactored --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 141 +++++++----------- 1 file changed, 54 insertions(+), 87 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 7875350f300..751a7689f74 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -1982,7 +1982,34 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } void EclipseGrid::init_children_host_cells(){ - auto get_all_cell_centers = [](const auto& cell, const auto& global_list){ + constexpr std::array, 12> faceConfigurations{ + std::array{0, 1, 5}, + {1, 5, 4}, // Face 0 + {0, 4, 6}, + {4, 6, 2}, // Face 1 + {2, 3, 7}, + {3, 7, 6}, // Face 2 + {1, 3, 7}, + {3, 7, 5}, // Face 3 + {0, 1, 3}, + {1, 3, 2}, // Face 4 + {4, 5, 7}, + {5, 7, 6} // Face 5 + }; + constexpr double epslon = 1e-6; + auto calcTetraVol = [](const auto& x, const auto& y, const auto& z){ + auto det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] + - x[1]*y[2]*z[0] - x[2]*y[0]*z[1] + x[2]*y[1]*z[0] + + x[0]*y[1]*z[3] - x[0]*y[3]*z[1] - x[1]*y[0]*z[3] + + x[1]*y[3]*z[0] + x[3]*y[0]*z[1] - x[3]*y[1]*z[0] + - x[0]*y[2]*z[3] + x[0]*y[3]*z[2] + x[2]*y[0]*z[3] + - x[2]*y[3]*z[0] - x[3]*y[0]*z[2] + x[3]*y[2]*z[0] + + x[1]*y[2]*z[3] - x[1]*y[3]*z[2] - x[2]*y[1]*z[3] + + x[2]*y[3]*z[1] + x[3]*y[1]*z[2] - x[3]*y[2]*z[1]; + return std::abs(det)/6; + }; + + auto getAllCellCenters = [](const auto& cell, const auto& global_list){ std::vector cell_centersX(global_list.size()); std::vector cell_centersY(global_list.size()); std::vector cell_centersZ(global_list.size()); @@ -1996,7 +2023,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return std::make_tuple(cell_centersX,cell_centersY,cell_centersZ); }; - auto get_all_cell_corners = [this](const auto& father_list){ + auto getAllCellCorners = [this](const auto& father_list){ std::vector> X(father_list.size()); std::vector> Y(father_list.size()); std::vector> Z(father_list.size()); @@ -2006,19 +2033,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return std::make_tuple(X, Y,Z); }; - auto tetra_vol = [](const auto& x, const auto& y, const auto& z){ - auto det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] - - x[1]*y[2]*z[0] - x[2]*y[0]*z[1] + x[2]*y[1]*z[0] - + x[0]*y[1]*z[3] - x[0]*y[3]*z[1] - x[1]*y[0]*z[3] - + x[1]*y[3]*z[0] + x[3]*y[0]*z[1] - x[3]*y[1]*z[0] - - x[0]*y[2]*z[3] + x[0]*y[3]*z[2] + x[2]*y[0]*z[3] - - x[2]*y[3]*z[0] - x[3]*y[0]*z[2] + x[3]*y[2]*z[0] - + x[1]*y[2]*z[3] - x[1]*y[3]*z[2] - x[2]*y[1]*z[3] - + x[2]*y[3]*z[1] + x[3]*y[1]*z[2] - x[3]*y[2]*z[1]; - return std::abs(det)/6; - }; - - auto append_node = [](const std::array& X, const std::array& Y, const std::array& Z, + auto appendNode = [](const std::array& X, const std::array& Y, const std::array& Z, const double& xc, const double& yc, const double& zc ){ std::array tX; std::array tY; @@ -2032,7 +2047,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return std::make_tuple(tX,tY,tZ); }; - auto get_nodes = [](const std::array& X, const std::array& Y, const std::array& Z, + auto getNodes = [](const std::array& X, const std::array& Y, const std::array& Z, const std::array& ind){ std::array filtered_vectorX; std::array filtered_vectorY; @@ -2045,7 +2060,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return std::make_tuple(filtered_vectorX,filtered_vectorY,filtered_vectorZ); }; - auto filter_array = [](const std::vector& X, const std::vector& ind){ + auto filterArray = [](const std::vector& X, const std::vector& ind){ std::vector filtered_vectorX(ind.size(),0); for (std::size_t index = 0; index < ind.size(); index++) { filtered_vectorX[index] = X[ind[index]]; @@ -2053,75 +2068,27 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return filtered_vectorX; }; - auto calc_vol = [get_nodes,append_node, tetra_vol] + auto calcHexaVol = [getNodes, appendNode, calcTetraVol, faceConfigurations] (const auto& x, const auto& y, const auto& z, - const auto& pcX, const auto& pcY, const auto& pcZ ){ - // node order of each face - // Face 0 = {0,1,5,4} - std::array fc0_0 = {0,1,5}; - std::array fc0_1 = {1,5,4}; - // Face 1 = {0,4,6,2} - std::array fc1_0 = {0,4,6}; - std::array fc1_1 = {4,6,2}; - // Face 2 = {2,3,7,6} - std::array fc2_0 = {2,3,7}; - std::array fc2_1 = {3,7,6}; - // Face 3 = {1,3,7,5} - std::array fc3_0 = {1,3,7}; - std::array fc3_1 = {3,7,5}; - // Face 4 = {0,1,3,2} - std::array fc4_0 = {0,1,3}; - std::array fc4_1 = {1,3,2}; - // Face 5 = {4,5,7,6} - std::array fc5_0 = {4,5,7}; - std::array fc5_1 = {5,7,6}; - - std::array f0,f1,f2; + const auto& cx, const auto& cy, const auto& cz ){ // note: some CPG grids may have collapsed faces that are not planar, therefore // the hexadron is subdivided in terahedrons. - // calculating the volume of the pyramid with F0 as base and pc as center - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc0_0); - auto tetraF0 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc0_1); - tetraF0 = tetraF0 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - - // calculating the volume of the pyramid with F1 as base and pc as center - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc1_0); - auto tetraF1 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc1_1); - tetraF1 = tetraF1 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - - - // calculating the volume of the pyramid with F2 as base and pc as center - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc2_0); - auto tetraF2 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc2_1); - tetraF2 = tetraF2 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - - // calculating the volume of the pyramid with F3 as base and pc as center - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc3_0); - auto tetraF3 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc3_1); - tetraF3 = tetraF3 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - - // calculating the volume of the pyramid with F4 as base and pc as center - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc4_0); - auto tetraF4 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc4_1); - tetraF4 = tetraF4 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - - // calculating the volume of the pyramid with F5 as base and pc as center - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc5_0); - auto tetraF5 = std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - std::tie(f0,f1,f2) = get_nodes(x,y,z,fc5_1); - tetraF5 = tetraF5 + std::apply(tetra_vol, append_node(f0,f1,f2,pcX,pcY,pcZ)); - return tetraF0 + tetraF1 + tetraF2 + tetraF3 + tetraF4 + tetraF5; + // calculating the volume of the pyramid with F0 as base and pc as center + double totalVolume = 0.0; + for (size_t i = 0; i < faceConfigurations.size(); i += 2) { + auto [fX0, fY0, fZ0] = getNodes(x, y, z, faceConfigurations[i]); + totalVolume += std::apply(calcTetraVol, appendNode(fX0, fY0, fZ0, cx, cy, cz)); + + auto [fX1, fY1, fZ1] = getNodes(x, y, z, faceConfigurations[i + 1]); + totalVolume += std::apply(calcTetraVol, appendNode(fX1, fY1, fZ1, cx, cy, cz)); + } + return totalVolume; }; - auto is_inside = [calc_vol](const std::vector& tpX, const std::vector& tpY, const std::vector& tpZ, - const std::vector>& X, const std::vector>& Y, - const std::vector>& Z){ + auto isInsideElement = [calcHexaVol](const std::vector& tpX, const std::vector& tpY, const std::vector& tpZ, + const std::vector>& X, const std::vector>& Y, + const std::vector>& Z){ std::vector in_elements(tpX.size(),0); // check if it is insde or outside boundary box double minX, minY, minZ, maxX, maxY, maxZ; @@ -2137,7 +2104,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st pcX = std::accumulate(X[outerIndex].begin(), X[outerIndex].end(), 0.0)/8; pcY = std::accumulate(Y[outerIndex].begin(), Y[outerIndex].end(), 0.0)/8; pcZ = std::accumulate(Z[outerIndex].begin(), Z[outerIndex].end(), 0.0)/8; - element_volume = calc_vol(X[outerIndex],Y[outerIndex],Z[outerIndex], pcX, pcY,pcZ); + element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex], pcX, pcY,pcZ); for (size_t innerIndex = 0; innerIndex < tpX.size(); innerIndex++){ // check if center of refined volume is outside the boundary box of a coarse volume. // Only computes volumed base test is this condition is met. @@ -2145,9 +2112,9 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st (minY < tpY[innerIndex]) && (maxY > tpY[innerIndex]) && (minZ < tpZ[innerIndex]) && (maxZ > tpZ[innerIndex]); if (flag && (in_elements[innerIndex] == 0)) { - test_element_volume = calc_vol(X[outerIndex],Y[outerIndex],Z[outerIndex], + test_element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex], tpX[innerIndex], tpY[innerIndex],tpZ[innerIndex]); - if (test_element_volume <= element_volume){ + if (std::abs(test_element_volume - element_volume) < epslon){ in_elements[innerIndex] = static_cast(outerIndex); } } @@ -2158,10 +2125,10 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector element_centerX, element_centerY, element_centerZ; for (EclipseGridLGR& lgr_cell : lgr_children_cells) { - std::tie(element_centerX, element_centerY,element_centerZ) = get_all_cell_centers(lgr_cell, lgr_cell.getActiveMap()); - auto [host_cellX, host_cellY, host_cellZ] = get_all_cell_corners(lgr_cell.get_father_global()); - auto inside_el = is_inside(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); - auto host_cells_global_ref = filter_array(lgr_cell.get_father_global(), inside_el); + std::tie(element_centerX, element_centerY,element_centerZ) = getAllCellCenters(lgr_cell, lgr_cell.getActiveMap()); + auto [host_cellX, host_cellY, host_cellZ] = getAllCellCorners(lgr_cell.get_father_global()); + auto inside_el = isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); + auto host_cells_global_ref = filterArray(lgr_cell.get_father_global(), inside_el); lgr_cell.set_hostnum(host_cells_global_ref); } } From 0a9cb02d98700b52670fe3a09bcea1cee844e8d1 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Wed, 30 Oct 2024 12:32:57 +0000 Subject: [PATCH 31/60] EGRID of two LGR cells working --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 62 +++++++--- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 16 ++- tests/parser/LgrOutputTests.cpp | 115 ++++++++++++++++++ 3 files changed, 172 insertions(+), 21 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 751a7689f74..09b71576708 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -1904,7 +1904,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector filehead(100,0); filehead[0] = 3; // version number filehead[1] = 2007; // release year - filehead[6] = 1; // corner point grid + filehead[6] = 2; // corner point grid std::vector gridhead(100,0); gridhead[0] = 1; // corner point grid @@ -1912,7 +1912,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st gridhead[2] = dims[1]; // nJ gridhead[3] = dims[2]; // nK gridhead[24] = 1; // NUMRES - + gridhead[25] = 1; std::vector nnchead(10, 0); std::vector nnc1; std::vector nnc2; @@ -1966,8 +1966,8 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st egridfile.write("ACTNUM", m_actnum); egridfile.write("ENDGRID", endgrid); - for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { - lgr_cell.save(egridfile, nnc, units); + for (std::size_t index : m_print_order_lgr_cells) { + lgr_children_cells[index].save(egridfile, nnc, units); } if (nnc1.size() > 0){ @@ -2216,10 +2216,32 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st void EclipseGrid::init_lgr_cells(const LgrCollection& lgr_input) { save_all_lgr_labels(lgr_input); create_lgr_cells_tree(lgr_input); - init_lgr_cells_index(); - init_lgr_global_cells_index(); + //initialize LGRObjbect Indices + initializeLGRObjectIndices(0); + //parse fatherLGRObjbect Indices to children + propagateParentIndicesToLGRChildren(0); + // initialize the LGR tree indices for each refined cell. + initializeLGRTreeIndices(); + // parse the reference indices to object in the global level. + parseGlobalReferenceToChildren(); } + void EclipseGrid::propagateParentIndicesToLGRChildren(int index){ + lgr_level_father = index; + for (auto& cell : lgr_children_cells) { + cell.propagateParentIndicesToLGRChildren(lgr_level); + } + } + + int EclipseGrid::initializeLGRObjectIndices(int num){ + lgr_level = num; + num++; + for (std::size_t index :m_print_order_lgr_cells) { + num = lgr_children_cells[index].initializeLGRObjectIndices(num); + } + return num; + } + void EclipseGrid::save_all_lgr_labels(const LgrCollection& lgr_input) { all_lgr_labels.reserve(lgr_input.size()+1); all_lgr_labels.push_back("GLOBAL"); @@ -2276,8 +2298,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::array lowIJK = {lgr_cell.I1(), lgr_cell.J1(),lgr_cell.K1()}; std::array upIJK = {lgr_cell.I2(), lgr_cell.J2(),lgr_cell.K2()}; - - lgr_children_cells.emplace_back(lgr_cell.NAME(), this->lgr_label, this->lgr_level, + lgr_children_cells.emplace_back(lgr_cell.NAME(), this->lgr_label, lgr_cell.NX(), lgr_cell.NY(), lgr_cell.NZ(), father_lgr_index, lowIJK,upIJK); @@ -2295,7 +2316,8 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st lgr_active_index.resize(lgr_children_cells.size(),0); } - void EclipseGrid::init_lgr_cells_index(){ + void EclipseGrid::initializeLGRTreeIndices(){ + // initialize the LGR tree indices for each refined cell. auto set_map_scalar = [&](const auto& vec, const auto& value){ num_lgr_children_cells[vec] = value; }; @@ -2324,16 +2346,21 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st lgr_level_active_map.reserve(lgr_level_active_map.size()+1); lgr_level_active_map.insert(lgr_level_active_map.begin(),0); for (auto& lgr_cell : lgr_children_cells) { - lgr_cell.init_lgr_cells_index(); + lgr_cell.initializeLGRTreeIndices(); } } - void EclipseGrid::init_lgr_global_cells_index(){ + void EclipseGrid::parseGlobalReferenceToChildren(){ for (std::size_t index = 0; index < lgr_children_cells.size(); index++) { +<<<<<<< HEAD lgr_children_cells[index].set_lgr_global_counter(lgr_level_active_map[lgr_active_index[index]] + this->lgr_global_counter); lgr_children_cells[index].init_lgr_global_cells_index(); +======= + lgr_children_cells[index].set_lgr_global_counter(lgr_level_active_map[lgr_active_index[index]] + this->lgr_global_counter); + lgr_children_cells[index].parseGlobalReferenceToChildren(); +>>>>>>> 91119edcd (EGRID of two LGR cells working) } } @@ -2399,7 +2426,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } void EclipseGrid::updateNumericalAquiferCells(const Deck& deck) { - using AQUNUM =ParserKeywords::AQUNUM; + using AQUNUM = ParserKeywords::AQUNUM; if ( !deck.hasKeyword() ) { return; } @@ -2565,7 +2592,6 @@ namespace Opm { { init_father_global(); lgr_label= self_label; - lgr_level = father_lgr_level + 1 ; } void EclipseGridLGR::set_hostnum(std::vector& hostnum) { @@ -2576,7 +2602,8 @@ namespace Opm { { m_coord = coord; m_zcorn = zcorn; - } + } + void EclipseGridLGR::init_father_global() { std::sort(father_global.begin(),father_global.end()); @@ -2591,7 +2618,7 @@ namespace Opm { egridfile.write("LGR",lgr_name_label); //std::vector> lgr_father_name_label; std::vector lgr_father_name_label; - if (lgr_level == 1){ + if (lgr_level_father == 0){ lgr_father_name_label.push_back(""); } else { @@ -2676,11 +2703,12 @@ namespace Opm { egridfile.write("HOSTNUM", m_hostnum); egridfile.write("ENDGRID", endgrid); egridfile.write("ENDLGR", endgrid); - for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { - lgr_cell.save(egridfile, nnc, units); + for (std::size_t index: m_print_order_lgr_cells ){ + lgr_children_cells[index].save(egridfile, nnc, units); } } + void EclipseGridLGR::save_nnc(Opm::EclIO::EclOutput& egridfile) const{ std::vector nnchead(10, 0); diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 551f506b604..0122d6f1856 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -181,8 +181,6 @@ namespace Opm { void init_lgr_cells(const LgrCollection& lgr_input); void create_lgr_cells_tree(const LgrCollection& ); - void init_lgr_global_cells_index(); - void init_lgr_cells_index(); /// \brief get cell center, and center and normal of bottom face std::tuple,std::array,std::array> getCellAndBottomCenterNormal(size_t globalIndex) const; @@ -264,6 +262,7 @@ namespace Opm { std::size_t lgr_global_counter = 0; std::string lgr_label = "GLOBAL"; int lgr_level = 0; + int lgr_level_father = 0; std::vector lgr_children_labels; std::vector lgr_active_index; std::vector lgr_level_active_map; @@ -272,7 +271,7 @@ namespace Opm { std::vector m_zcorn; std::vector m_coord; std::vector m_actnum; - + std::vector m_print_order_lgr_cells; // Input grid data. mutable std::optional> m_input_zcorn; mutable std::optional> m_input_coord; @@ -312,7 +311,10 @@ namespace Opm { // Radial grids need this for volume calculations. std::optional> m_thetav; std::optional> m_rv; - + void parseGlobalReferenceToChildren(void); + int initializeLGRObjectIndices(int); + void initializeLGRTreeIndices(void); + void propagateParentIndicesToLGRChildren(int); void updateNumericalAquiferCells(const Deck&); double computeCellGeometricDepth(size_t globalIndex) const; @@ -366,8 +368,14 @@ namespace Opm { using vec_size_t = std::vector; EclipseGridLGR() = default; EclipseGridLGR(const std::string& self_label, const std::string& father_label_, +<<<<<<< HEAD int father_lgr_level, size_t nx, size_t ny, size_t nz, const vec_size_t& father_lgr_index); +======= + size_t nx, size_t ny, size_t nz, + vec_size_t father_lgr_index, std::array low_fahterIJK_, + std::array up_fahterIJK_); +>>>>>>> 91119edcd (EGRID of two LGR cells working) ~EclipseGridLGR() = default; const vec_size_t& getFatherGlobalID() const; void set_lgr_global_counter(std::size_t counter){ diff --git a/tests/parser/LgrOutputTests.cpp b/tests/parser/LgrOutputTests.cpp index 1a21619e720..a3db079e442 100644 --- a/tests/parser/LgrOutputTests.cpp +++ b/tests/parser/LgrOutputTests.cpp @@ -255,3 +255,118 @@ SCHEDULE BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); } } + + +BOOST_AUTO_TEST_CASE(TestLgrOutputDoubleLGR) { + const std::string deck_string = R"( +RUNSPEC + +DIMENS + 3 3 1 / + +GRID + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +'LGR1' 2 2 2 2 1 1 2 2 1 / +ENDFIN + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +'LGR2' 2 2 1 1 1 1 2 2 1 / +ENDFIN + +DX + 9*1000 / +DY + 9*1000 / +DZ + 9*20 / + +TOPS + 9*8325 / + +PORO + 9*0.15 / + +PERMX + 9*1 / + +COPY + PERMX PERMZ / + PERMX PERMY / +/ + +EDIT + +OIL +GAS + +TITLE +The title + +START +16 JUN 1988 / + +PROPS + +REGIONS + +SOLUTION + +SCHEDULE +)"; +\ + Opm::UnitSystem units(1); + std::vector vecNNC; + std::array global_grid_dim = {3,3,1}; + std::vector coord_g, zcorn_g, coord_l1, zcorn_l1, coord_l2, zcorn_l2, + coord_g_opm, zcorn_g_opm, coord_l1_opm, zcorn_l1_opm, coord_l2_opm, zcorn_l2_opm; + // Intialize LgrCollection from string. + LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); + // Read global COORD and ZCORN from reference simulator output. + std::tie(coord_g, zcorn_g) = read_cpg_from_egrid("CARFIN-DOUBLE.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l1, zcorn_l1) = read_cpg_from_egrid("CARFIN-DOUBLE.EGRID", "LGR1"); + std::tie(coord_l2, zcorn_l2) = read_cpg_from_egrid("CARFIN-DOUBLE.EGRID", "LGR2"); + + // Eclipse Grid is intialzied with COORD and ZCORN. + Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); + // LgrCollection is used to initalize LGR Cells in the Eclipse Grid. + eclipse_grid_file.init_lgr_cells(lgr_col); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) + eclipse_grid_file.lgr_children_cells[1].set_lgr_refinement(coord_l1,zcorn_l1); + eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l2,zcorn_l2); + // Intialize host_cell numbering. + eclipse_grid_file.init_children_host_cells(); + // Save EclipseGrid. + eclipse_grid_file.save("OPMCARFIN-DOUBLE.EGRID",false,vecNNC,units); + // Once the new EGRID is saved, another EclipseGrid Object is created for the sake of comparison. + std::tie(coord_g_opm, zcorn_g_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l1_opm, zcorn_l1_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "LGR1"); + std::tie(coord_l2_opm, zcorn_l2_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "LGR2"); + // Eclipse Grid is intialzied with COORD and ZCORN. + Opm::EclipseGrid eclipse_grid_OPM(global_grid_dim, coord_g_opm, zcorn_g_opm); +// LgrCollection is used to initalize LGR Cells in the Eclipse Grid. + eclipse_grid_OPM.init_lgr_cells(lgr_col); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) + eclipse_grid_OPM.lgr_children_cells[1].set_lgr_refinement(coord_l1_opm,zcorn_l1_opm); + eclipse_grid_OPM.lgr_children_cells[0].set_lgr_refinement(coord_l2_opm,zcorn_l2_opm); + + // Intialize host_cell numbering. + eclipse_grid_OPM.init_children_host_cells(); + BOOST_CHECK_EQUAL( coord_g_opm.size() , coord_g.size()); + BOOST_CHECK_EQUAL( zcorn_g_opm.size() , zcorn_g.size()); + BOOST_CHECK_EQUAL( coord_l1_opm.size() , coord_l1.size()); + BOOST_CHECK_EQUAL( zcorn_l1_opm.size() , zcorn_l1.size()); + BOOST_CHECK_EQUAL( coord_l2_opm.size() , coord_l2.size()); + BOOST_CHECK_EQUAL( zcorn_l2_opm.size() , zcorn_l2.size()); + std::size_t index ; + for (index = 0; index < coord_g.size(); index++) { + BOOST_CHECK_EQUAL( coord_g_opm[index] , coord_g[index]); + } + for (index = 0; index < zcorn_g.size(); index++) { + BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); + } + } From 9052a02d20100325b2f71aed385ae17f5ba4e98e Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Fri, 15 Nov 2024 10:23:34 +0000 Subject: [PATCH 32/60] add tests to LgrOutputTests --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 1 + opm/io/eclipse/EGrid.cpp | 2 +- tests/parser/LgrOutputTests.cpp | 116 ++++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 09b71576708..c0aaa9f7fee 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -2130,6 +2130,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st auto inside_el = isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); auto host_cells_global_ref = filterArray(lgr_cell.get_father_global(), inside_el); lgr_cell.set_hostnum(host_cells_global_ref); + lgr_cell.init_children_host_cells(); } } diff --git a/opm/io/eclipse/EGrid.cpp b/opm/io/eclipse/EGrid.cpp index af86cffcd24..a23e822b8d2 100644 --- a/opm/io/eclipse/EGrid.cpp +++ b/opm/io/eclipse/EGrid.cpp @@ -510,7 +510,7 @@ std::vector> EGrid::getXYZ_layer(int layer, bool bottom) } -std::vector EGrid::get_zcorn_from_disk(int layer, bool bottom) +std::vector EGrid:: get_zcorn_from_disk(int layer, bool bottom) { if (formatted) throw std::invalid_argument("partial loading of zcorn arrays not possible when using formatted input"); diff --git a/tests/parser/LgrOutputTests.cpp b/tests/parser/LgrOutputTests.cpp index a3db079e442..262ea1cc8b9 100644 --- a/tests/parser/LgrOutputTests.cpp +++ b/tests/parser/LgrOutputTests.cpp @@ -370,3 +370,119 @@ SCHEDULE BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); } } + + + +BOOST_AUTO_TEST_CASE(TestLgrOutputNESTED) { + const std::string deck_string = R"( +RUNSPEC + +DIMENS + 3 3 1 / + +GRID + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +LGR1 2 2 2 2 1 1 3 3 1 1* GLOBAL/ +ENDFIN + +CARFIN +-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ +LGR2 2 2 2 2 1 1 3 3 1 1* LGR1/ +ENDFIN + +DX + 9*1000 / +DY + 9*1000 / +DZ + 9*20 / + +TOPS + 9*8325 / + +PORO + 9*0.15 / + +PERMX + 9*1 / + +COPY + PERMX PERMZ / + PERMX PERMY / +/ + +EDIT + +OIL +GAS + +TITLE +The title + +START +16 JUN 1988 / + +PROPS + +REGIONS + +SOLUTION + +SCHEDULE +)"; +\ + Opm::UnitSystem units(1); + std::vector vecNNC; + std::array global_grid_dim = {3,3,1}; + std::vector coord_g, zcorn_g, coord_l1, zcorn_l1, coord_l2, zcorn_l2, + coord_g_opm, zcorn_g_opm, coord_l1_opm, zcorn_l1_opm, coord_l2_opm, zcorn_l2_opm; + // Intialize LgrCollection from string. + LgrCollection lgr_col = read_lgr(deck_string,global_grid_dim[0],global_grid_dim[1],global_grid_dim[2]); + // Read global COORD and ZCORN from reference simulator output. + std::tie(coord_g, zcorn_g) = read_cpg_from_egrid("CARFIN-NESTED.EGRID", "global"); + // Read LGR CELL COORD and ZCORN from reference simulator output. + std::tie(coord_l1, zcorn_l1) = read_cpg_from_egrid("CARFIN-NESTED.EGRID", "LGR1"); + std::tie(coord_l2, zcorn_l2) = read_cpg_from_egrid("CARFIN-NESTED.EGRID", "LGR2"); + + // Eclipse Grid is intialzied with COORD and ZCORN. + Opm::EclipseGrid eclipse_grid_file(global_grid_dim, coord_g, zcorn_g); + // LgrCollection is used to initalize LGR Cells in the Eclipse Grid. + eclipse_grid_file.init_lgr_cells(lgr_col); + // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) + eclipse_grid_file.lgr_children_cells[0].set_lgr_refinement(coord_l1,zcorn_l1); + eclipse_grid_file.lgr_children_cells[0].lgr_children_cells[0].set_lgr_refinement(coord_l2,zcorn_l2); + // Intialize host_cell numbering. + eclipse_grid_file.init_children_host_cells(); + // Save EclipseGrid. + eclipse_grid_file.save("OPMCARFIN-NESTED.EGRID",false,vecNNC,units); +// // Once the new EGRID is saved, another EclipseGrid Object is created for the sake of comparison. +// std::tie(coord_g_opm, zcorn_g_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "global"); +// // Read LGR CELL COORD and ZCORN from reference simulator output. +// std::tie(coord_l1_opm, zcorn_l1_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "LGR1"); +// std::tie(coord_l2_opm, zcorn_l2_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "LGR2"); +// // Eclipse Grid is intialzied with COORD and ZCORN. +// Opm::EclipseGrid eclipse_grid_OPM(global_grid_dim, coord_g_opm, zcorn_g_opm); +// // LgrCollection is used to initalize LGR Cells in the Eclipse Grid. +// eclipse_grid_OPM.init_lgr_cells(lgr_col); +// // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) +// eclipse_grid_OPM.lgr_children_cells[1].set_lgr_refinement(coord_l1_opm,zcorn_l1_opm); +// eclipse_grid_OPM.lgr_children_cells[0].set_lgr_refinement(coord_l2_opm,zcorn_l2_opm); + +// // Intialize host_cell numbering. +// eclipse_grid_OPM.init_children_host_cells(); +// BOOST_CHECK_EQUAL( coord_g_opm.size() , coord_g.size()); +// BOOST_CHECK_EQUAL( zcorn_g_opm.size() , zcorn_g.size()); +// BOOST_CHECK_EQUAL( coord_l1_opm.size() , coord_l1.size()); +// BOOST_CHECK_EQUAL( zcorn_l1_opm.size() , zcorn_l1.size()); +// BOOST_CHECK_EQUAL( coord_l2_opm.size() , coord_l2.size()); +// BOOST_CHECK_EQUAL( zcorn_l2_opm.size() , zcorn_l2.size()); +// std::size_t index ; +// for (index = 0; index < coord_g.size(); index++) { +// BOOST_CHECK_EQUAL( coord_g_opm[index] , coord_g[index]); +// } +// for (index = 0; index < zcorn_g.size(); index++) { +// BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); +// } + } From bff9047a883fcd4090a826b22432480dd5c0a755 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 21 Nov 2024 13:40:32 +0000 Subject: [PATCH 33/60] Development of the routines for exporting EGRID compartible with LGR --- tests/CARFIN-COLUMN.EGRID | Bin 0 -> 3412 bytes tests/CARFIN-DOUBLE.EGRID | Bin 0 -> 4540 bytes tests/CARFIN-NESTED.EGRID | Bin 0 -> 5308 bytes tests/CARFIN5.EGRID | Bin 0 -> 3524 bytes tests/parser/LgrOutputTests.cpp | 34 ++------------------------------ 5 files changed, 2 insertions(+), 32 deletions(-) create mode 100644 tests/CARFIN-COLUMN.EGRID create mode 100644 tests/CARFIN-DOUBLE.EGRID create mode 100644 tests/CARFIN-NESTED.EGRID create mode 100644 tests/CARFIN5.EGRID diff --git a/tests/CARFIN-COLUMN.EGRID b/tests/CARFIN-COLUMN.EGRID new file mode 100644 index 0000000000000000000000000000000000000000..d7c0fcc70fad0fcc796dc928c6b8bd7f4f9b2801 GIT binary patch literal 3412 zcmeHJv2qhJ5S0x{94ZwQDP2&wg_ee!yUX3p7+pp#JX5xb9~p^KW(zQbB?AVZ2Y}g zHjJd+} znh$7*P2!G7QJk@`f`ty`uC;l{B_X1k#y{Etn*je(7ah>LYI@X>f IV;$|{Cw{peLI3~& literal 0 HcmV?d00001 diff --git a/tests/CARFIN-DOUBLE.EGRID b/tests/CARFIN-DOUBLE.EGRID new file mode 100644 index 0000000000000000000000000000000000000000..ebbd03fbb74da08c83e7fcb57136d755f6cf43d1 GIT binary patch literal 4540 zcmeHKJ#*7Q5IvhD7%CMMlrAXJLP0~NkrZ1qMq-3B%urF}S5WyU@PGIt>G>B_ytle{ z-iSEPV1;o8Zsun9-tNA=58X-%A!HZzs#;cg8A7>-@UzBZER}KA7o&R~=6y`mYW&5e2p{o~5 z5+d%LT+F-UIhnwYXT>`8u^Txbf_LnB9tmInoD^-_mHqjB>8gB%$?;xqZkuHJH3W7w z>4yIl3ZJMGuikBvLAsBV(Kz5QNnE-~a8eo`b&km?T)M`Z$1p}X{ir7iJ^4o5I3q4y z{2Z(K+`{RXaBw6%>aq)`lz%*f>~qm}ylBX?bmud_n7#>*n&k z?ccNQdn>$xP4(g~Nx!UWN|rV91;>%C79CE;xF@b=&Vav;_>A!wf5S)b#`aE7AE!pEI`mJ`p-QLY`ZS@3qpG~^S@7r2cM%{4K14{FcdWwUe z;jpI|#tM&m;t@_B+8D=H%;o35dCGop|%Wb%OVI%%*)Kr>{j`A2Z)0 z=h|Nm9)ZfvB$Gd9dsGC1x3pb`No`mCmCmi;KM_oLWDIaw4Bz#a)5)K~o z?c@KoI-&QZrSY}eXsePOfZknign_#8#Vui?%3zt5xw>2Bx{;BU)S$VTcisdj^FFc z-yJf)2!UNq*!Uk}k>i+r@$52A2zS?M(ln5-NM6_?G#QO|%rP~^3u~-%^w)@I9&wDo zG1qz1bY58c9IJKr7SFuMLnHEzH7}k~`CfzMb=I`}qG6wTr#`c@>BF#F{T%1nosRqC zoh50utXI$N{*HhBZiPpflV5C#%u9+or>#*hbTpDh*`hM0J?VJn5%|Z>A8|d#FVfb$ z^-7*CUaz;jExeOw9<%8VsL9`Lc5+>e;l8bJV6%6cpWwUCCT#J;$4`vLJ2w8?Y883M z#=|Ef@7Q=~x{1kX83&F@Ax&}8?X&|rnPqr(9!et72gLhfA8}P_x%T*eNTPQ zyNHL5>EC)saS!;|=lFb1%ry!2DX-C^mb#vu8L6dCEp_Q_x|bopDSvt|+&9H}`t{(R WTht>}Jx03URCVm@>24VZ-S1B&gg%%6 literal 0 HcmV?d00001 diff --git a/tests/CARFIN5.EGRID b/tests/CARFIN5.EGRID new file mode 100644 index 0000000000000000000000000000000000000000..a1d5a0e9c406a4fb27027fcc44a885f6111b3f1e GIT binary patch literal 3524 zcmeHJF^<$g5S(2&?hX++-~k&DTzHTYS+>u%w2YD26%rA_z2c&K0xz#++)*hR#_9@*2CC0k@Y88{Y4)utDfh2cpEt|_H9Q& z%)6i#*S+UCSzsK`iUsk$8#Vuh?!NbVAbQhtQVqjcPxtqJY|1q@$M^d7u1(fAAu!a0 zjsGSVHIB(QFK^R;a6V6irh$58^1_y($!xr1_NggeSbgndK1V$3h*Jhmwa%NS^TN_+ zUoBr-JnIqT8v8k%!1?jain7|o?JGOK z^B>=>@C;+}i(Q#@MH6e<8udb^QLNh$H)Gn1%rnoxKX?9&^U;4@j^?dD)!F1}zSaGK zcXH4BY&rvK^1IC-mt%B~Z90M7-f4baB{Fm)E@s5p$PbA*4@zAI- z-*g-sPfhWTji;t~$Hr4ryyK*gx}>i?QB%C*q%WSes;8!S$4MXkq|dRNX)no}sV|;- zs&{Pl92f7H{LwrA&WHEuo!#)p3>cR(_umt6zlxpy3tu)1=8fmR9Am{_&=u&%8PESy zw%_qi` vecNNC; std::array global_grid_dim = {3,3,1}; @@ -210,7 +210,7 @@ SOLUTION SCHEDULE )"; -\ + Opm::UnitSystem units(1); std::vector vecNNC; std::array global_grid_dim = {3,3,1}; @@ -316,7 +316,6 @@ SOLUTION SCHEDULE )"; -\ Opm::UnitSystem units(1); std::vector vecNNC; std::array global_grid_dim = {3,3,1}; @@ -432,7 +431,6 @@ SOLUTION SCHEDULE )"; -\ Opm::UnitSystem units(1); std::vector vecNNC; std::array global_grid_dim = {3,3,1}; @@ -457,32 +455,4 @@ SCHEDULE eclipse_grid_file.init_children_host_cells(); // Save EclipseGrid. eclipse_grid_file.save("OPMCARFIN-NESTED.EGRID",false,vecNNC,units); -// // Once the new EGRID is saved, another EclipseGrid Object is created for the sake of comparison. -// std::tie(coord_g_opm, zcorn_g_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "global"); -// // Read LGR CELL COORD and ZCORN from reference simulator output. -// std::tie(coord_l1_opm, zcorn_l1_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "LGR1"); -// std::tie(coord_l2_opm, zcorn_l2_opm) = read_cpg_from_egrid("OPMCARFIN-DOUBLE.EGRID", "LGR2"); -// // Eclipse Grid is intialzied with COORD and ZCORN. -// Opm::EclipseGrid eclipse_grid_OPM(global_grid_dim, coord_g_opm, zcorn_g_opm); -// // LgrCollection is used to initalize LGR Cells in the Eclipse Grid. -// eclipse_grid_OPM.init_lgr_cells(lgr_col); -// // LGR COORD and ZCORN is parsed to EclipseGridLGR children cell. (Simulates the process of recieving the LGR refinement.) -// eclipse_grid_OPM.lgr_children_cells[1].set_lgr_refinement(coord_l1_opm,zcorn_l1_opm); -// eclipse_grid_OPM.lgr_children_cells[0].set_lgr_refinement(coord_l2_opm,zcorn_l2_opm); - -// // Intialize host_cell numbering. -// eclipse_grid_OPM.init_children_host_cells(); -// BOOST_CHECK_EQUAL( coord_g_opm.size() , coord_g.size()); -// BOOST_CHECK_EQUAL( zcorn_g_opm.size() , zcorn_g.size()); -// BOOST_CHECK_EQUAL( coord_l1_opm.size() , coord_l1.size()); -// BOOST_CHECK_EQUAL( zcorn_l1_opm.size() , zcorn_l1.size()); -// BOOST_CHECK_EQUAL( coord_l2_opm.size() , coord_l2.size()); -// BOOST_CHECK_EQUAL( zcorn_l2_opm.size() , zcorn_l2.size()); -// std::size_t index ; -// for (index = 0; index < coord_g.size(); index++) { -// BOOST_CHECK_EQUAL( coord_g_opm[index] , coord_g[index]); -// } -// for (index = 0; index < zcorn_g.size(); index++) { -// BOOST_CHECK_EQUAL( zcorn_g_opm[index] , zcorn_g[index]); -// } } From 9ec357be26e57402d5e20e9b33a25103d4721ed4 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Wed, 4 Dec 2024 14:43:13 +0000 Subject: [PATCH 34/60] fixed merging problems from previous rebase --- opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp | 10 +++------- opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp | 7 ++----- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index c0aaa9f7fee..640d38e4cd7 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -2354,14 +2354,9 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st void EclipseGrid::parseGlobalReferenceToChildren(){ for (std::size_t index = 0; index < lgr_children_cells.size(); index++) { -<<<<<<< HEAD lgr_children_cells[index].set_lgr_global_counter(lgr_level_active_map[lgr_active_index[index]] + this->lgr_global_counter); - lgr_children_cells[index].init_lgr_global_cells_index(); -======= - lgr_children_cells[index].set_lgr_global_counter(lgr_level_active_map[lgr_active_index[index]] + this->lgr_global_counter); lgr_children_cells[index].parseGlobalReferenceToChildren(); ->>>>>>> 91119edcd (EGRID of two LGR cells working) } } @@ -2587,8 +2582,9 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st namespace Opm { EclipseGridLGR::EclipseGridLGR(const std::string& self_label, const std::string& father_label_, - int father_lgr_level, std::size_t nx, std::size_t ny, - std::size_t nz, const vec_size_t& father_lgr_index) + std::size_t nx, std::size_t ny, std::size_t nz, + vec_size_t father_lgr_index, std::array low_fahterIJK_, + std::array up_fahterIJK_) : EclipseGrid(nx,ny,nz), father_label(father_label_), father_global(father_lgr_index) { init_father_global(); diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 0122d6f1856..4308c373c39 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -368,16 +368,13 @@ namespace Opm { using vec_size_t = std::vector; EclipseGridLGR() = default; EclipseGridLGR(const std::string& self_label, const std::string& father_label_, -<<<<<<< HEAD - int father_lgr_level, size_t nx, size_t ny, size_t nz, - const vec_size_t& father_lgr_index); -======= size_t nx, size_t ny, size_t nz, vec_size_t father_lgr_index, std::array low_fahterIJK_, std::array up_fahterIJK_); ->>>>>>> 91119edcd (EGRID of two LGR cells working) ~EclipseGridLGR() = default; const vec_size_t& getFatherGlobalID() const; + void save(Opm::EclIO::EclOutput&, const std::vector&, const Opm::UnitSystem&) const; + void save_nnc(Opm::EclIO::EclOutput&) const; void set_lgr_global_counter(std::size_t counter){ lgr_global_counter = counter; } From 28246bd4b0954b2048bf718950c327c0b097b6c6 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 5 Dec 2024 08:34:14 +0000 Subject: [PATCH 35/60] EclipseGrid::save outputs EGRIDs for meshes with LGR --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 640d38e4cd7..44792cc2410 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -2306,14 +2306,24 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st lgr_children_cells.back().create_lgr_cells_tree(lgr_input); } } - std::sort(lgr_children_cells.begin(), lgr_children_cells.end(), - [](const EclipseGridLGR& a, const EclipseGridLGR& b) { - return a.get_father_global()[0] < b.get_father_global()[0]; // Sort by another property - }); + EclipseGridLGR::vec_size_t father_label_sorting(lgr_children_cells.size(),0); + m_print_order_lgr_cells.resize(lgr_children_cells.size()); + std::iota(m_print_order_lgr_cells.begin(), m_print_order_lgr_cells.end(), 0); // + std::transform(lgr_children_cells.begin(), lgr_children_cells.end(), father_label_sorting.begin(), + [](const auto& cell){return cell.get_father_global()[0];}); + + std::sort(m_print_order_lgr_cells.begin(), m_print_order_lgr_cells.end(), [&](std::size_t i1, std::size_t i2) { + return father_label_sorting[i1] < father_label_sorting[i2]; // + }); + + std::sort(lgr_children_cells.begin(), lgr_children_cells.end(),[](const EclipseGridLGR& a, const EclipseGridLGR& b) { + return a.get_father_global()[0] < b.get_father_global()[0]; // + }); + lgr_children_labels.reserve(lgr_children_cells.size()); - std::transform(lgr_children_cells.begin(), lgr_children_cells.end(), - std::back_inserter(lgr_children_labels), - [](const auto& lgr_cell) { return lgr_cell.lgr_label; }); + for (auto lgr_cell : lgr_children_cells) { + lgr_children_labels.emplace_back(lgr_cell.lgr_label); + } lgr_active_index.resize(lgr_children_cells.size(),0); } From bbe29383981b4c5a32f753944db87712aa1edeaf Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Fri, 13 Dec 2024 09:47:04 +0000 Subject: [PATCH 36/60] fixed minor performance bugs --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 30 +++++++++---------- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 13 ++++---- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 44792cc2410..599bd90f458 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -17,16 +17,12 @@ along with OPM. If not, see . */ -<<<<<<< HEAD -======= -#include "opm/io/eclipse/PaddedOutputString.hpp" +#include #include #include #include #include -#include #include ->>>>>>> 9e3ed0386 (part1 - rebase) #define _USE_MATH_DEFINES #include @@ -41,7 +37,7 @@ #include #include - +#include #include #include @@ -1904,14 +1900,14 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector filehead(100,0); filehead[0] = 3; // version number filehead[1] = 2007; // release year - filehead[6] = 2; // corner point grid + filehead[6] = 1; // corner point grid std::vector gridhead(100,0); gridhead[0] = 1; // corner point grid gridhead[1] = dims[0]; // nI gridhead[2] = dims[1]; // nJ gridhead[3] = dims[2]; // nK - gridhead[24] = 1; // NUMRES + gridhead[24] = 1; // NUMRES (number of reservoirs) gridhead[25] = 1; std::vector nnchead(10, 0); std::vector nnc1; @@ -1965,7 +1961,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st egridfile.write("ACTNUM", m_actnum); egridfile.write("ENDGRID", endgrid); - + // nnc for LGR is not currently supported. for (std::size_t index : m_print_order_lgr_cells) { lgr_children_cells[index].save(egridfile, nnc, units); } @@ -1973,7 +1969,9 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st if (nnc1.size() > 0){ egridfile.write("NNCHEAD", nnchead); egridfile.write("NNC1", nnc1); - egridfile.write("NNC2", nnc2); + egridfile.write("NNC2", nnc2); + // Placeholder the method that handles LGR nnc + // nnc in LGR is currently not supportd // for (const EclipseGridLGR& lgr_cell : lgr_children_cells) { // lgr_cell.save_nnc(egridfile); // } @@ -2593,8 +2591,8 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st namespace Opm { EclipseGridLGR::EclipseGridLGR(const std::string& self_label, const std::string& father_label_, std::size_t nx, std::size_t ny, std::size_t nz, - vec_size_t father_lgr_index, std::array low_fahterIJK_, - std::array up_fahterIJK_) + vec_size_t father_lgr_index, const std::array& low_fahterIJK_, + const std::array& up_fahterIJK_) : EclipseGrid(nx,ny,nz), father_label(father_label_), father_global(father_lgr_index) { init_father_global(); @@ -2605,7 +2603,7 @@ namespace Opm { std::transform(hostnum.begin(),hostnum.end(), hostnum.begin(), [](int a){return a+1;}); m_hostnum = hostnum; } - void EclipseGridLGR::set_lgr_refinement(std::vector coord, std::vector zcorn) + void EclipseGridLGR::set_lgr_refinement(const std::vector& coord, const std::vector& zcorn) { m_coord = coord; m_zcorn = zcorn; @@ -2686,9 +2684,9 @@ namespace Opm { gridhead[31] = up_fahterIJK[1] + 1; // Upper J-index-host gridhead[32] = up_fahterIJK[2] + 1; // Upper K-index-host - std::vector nnchead(10, 0); - std::vector nnc1; - std::vector nnc2; + [[maybe_unused]] std::vector nnchead(10, 0); + [[maybe_unused]] std::vector nnc1; + [[maybe_unused]] std::vector nnc2; for (const NNCdata& n : nnc ) { nnc1.push_back(n.cell1 + 1); diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 4308c373c39..4c9cefe8079 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -33,12 +33,15 @@ #include #include #include -#include + namespace Opm { class Deck; - namespace EclIO { class EclFile; } + namespace EclIO { + class EclFile; + class EclOutput; + } struct NNCdata; class UnitSystem; class ZcornMapper; @@ -369,8 +372,8 @@ namespace Opm { EclipseGridLGR() = default; EclipseGridLGR(const std::string& self_label, const std::string& father_label_, size_t nx, size_t ny, size_t nz, - vec_size_t father_lgr_index, std::array low_fahterIJK_, - std::array up_fahterIJK_); + vec_size_t father_lgr_index, const std::array& low_fahterIJK_, + const std::array& up_fahterIJK_); ~EclipseGridLGR() = default; const vec_size_t& getFatherGlobalID() const; void save(Opm::EclIO::EclOutput&, const std::vector&, const Opm::UnitSystem&) const; @@ -382,7 +385,7 @@ namespace Opm { return father_global; } void set_hostnum(std::vector&); - void set_lgr_refinement(std::vector,std::vector); + void set_lgr_refinement(const std::vector&, const std::vector &); private: void init_father_global(); std::string father_label; From d2a3e00c1c9709322c73d7590424883444c6cf7b Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Fri, 13 Dec 2024 13:07:04 +0000 Subject: [PATCH 37/60] Test Files for LgrOutputTest added and registered at CMakeLists_files --- CMakeLists_files.cmake | 5 ++++- tests/OPMCARFIN-COLUMN.EGRID | Bin 0 -> 3108 bytes tests/OPMCARFIN-DOUBLE.EGRID | Bin 0 -> 3868 bytes tests/OPMCARFIN-NESTED.EGRID | Bin 0 -> 4604 bytes tests/OPMCARFIN5.EGRID | Bin 0 -> 3172 bytes 5 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/OPMCARFIN-COLUMN.EGRID create mode 100644 tests/OPMCARFIN-DOUBLE.EGRID create mode 100644 tests/OPMCARFIN-NESTED.EGRID create mode 100644 tests/OPMCARFIN5.EGRID diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index aea135c48bb..ee7c79feef7 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -738,7 +738,10 @@ if(ENABLE_ECL_OUTPUT) tests/msim/action_count_no_run_function.py tests/msim/open_well_past.py tests/msim/open_well_too_late.py - tests/VFP_CASE.DATA) + tests/CARFIN-COLUMN.EGRID + tests/CARFIN-DOUBLE.EGRID + tests/CARFIN-NESTED.EGRID + tests/CARFIN5.EGRID) endif() list (APPEND EXAMPLE_SOURCE_FILES diff --git a/tests/OPMCARFIN-COLUMN.EGRID b/tests/OPMCARFIN-COLUMN.EGRID new file mode 100644 index 0000000000000000000000000000000000000000..bfd9b6bd4ef2e8e2d9f8b60386eff7312f1858ad GIT binary patch literal 3108 zcmeHIJ5Iwu6nqItgl-ECkb(1n$E@xJxQ#o_Cgw`89k3 z;z_GFJMUwAUv^?<;dC~yr*%=8+0Cq3*6_h>a1Xy@w)Y6%w?Uuy-+#vm_)Nm2omH33 zY>6ih%W2WVV_p`{>SbGBjFX9H{u}e<95G{GUolhm{EEJ4`xmX7Z@E~s6{d(Uyl(4a z4$u3zf`4Jvof(%**!i_s)JZa&j&KI7Bjfo<2i!TW5_ z!ugFcn^2U?=JL#c-}}%1H+G1a^x{3wyihk4WsUtT>k;OY*7XncAk)SX_#+0ukFc0` zUbGE0bR*A;v%C+qbBOv~_J|Aa(=6{P-1ndMu;1V4g?3(Lck}kO@8exBaqnfqbVfK#8yd!NXAUF3!7Y0_Zf)MxGC z?puMqj_(wC-$x!-foGj-DL%%*T3WaJ#)fzap58g{82si RDPLaymVSbF2}MoP)hB^50+av% literal 0 HcmV?d00001 diff --git a/tests/OPMCARFIN-DOUBLE.EGRID b/tests/OPMCARFIN-DOUBLE.EGRID new file mode 100644 index 0000000000000000000000000000000000000000..593978980fc1aee4f608738b3640862f3a765449 GIT binary patch literal 3868 zcmeHJL2eU45NsO|;kHOTzz0462QHjeyPMdOy+#}7!U+jmAPz`Ggaao(f&cIj@)k~1 zwWr#{Mj@cYC<3=M>YnQA-u1MnY%?nkC(~x!l(m^HC+(tvFU$sC;P05-{|4W;K_A%f z|HcXUOp2p!QlGSw1)eyp#$^YOd08=Q7F}~Z3KLHLCG+JRF=Jo5m??YiqA%M1i?*3> zHJ^7irif4Ys%y$AJn!Qg{({w?&A4QW9se#AoD>spp06XJIImOEdw?%bT(Nufq<1{U z+_R@}#oFsV`ZdDIV;mlFa1-u56RueOxtHb77EWH^=n;5|l^0Ggewsn?vYL18WKj4v?nwFem~g$-q>U0q!+*PcCc$mQQ>#{OSsJU@1kz`oDF z2P|LCzf2E+yCk6IcXi_Fj&*{1ag(O=V^5yT@a)6u;c|8Q4pR3J`@K%^WWui22~m0P zXu6l1-R6!4p6;seQ|x@yR@t7h`UH;q9XRrVr&xXH<9UeHC-9!81dcw=-PHeYI-%cY I`9Ic)A94*%MF0Q* literal 0 HcmV?d00001 diff --git a/tests/OPMCARFIN-NESTED.EGRID b/tests/OPMCARFIN-NESTED.EGRID new file mode 100644 index 0000000000000000000000000000000000000000..8735a7e8cb305c2ecabb178161d09cc37e5a3649 GIT binary patch literal 4604 zcmeH}F>ez=6ol7CD52X(6i8_-M3Vw3p+i)b?_yhWY;>_DL`9K5kT#WD8U!VO03@i8 z_yshyL;{7MK~2TX^P9(Egp+`Sk|--}-rTou=gznBBq^o5-5->_vR$N<_WHwdiJDVt zJV(8j(#jF){AkRBtLy*q2JB37x9S&@VSkJ}Haop`g^Ke^d8Zs#-)559_Uvkm$nK|R^zUDO;2%YUF$jK_lUEPIx2MZIyX<}((>oEM*ZI6>StgZ#KNs)n=k>DA7swcWg#&ez<-^PHcF_t(PNfQV_$ns*9=59?GxV1}+g$5AMRxL;mpSwf(zm;} zzO1jMmBWqvH6LxPZRW$R{CWM|GH-VAy%uMu66FtRUhrc*`)lW}x*Wr)r@aNjW>{%k4 z=`T({^}Duyu8X@S$JcC%A6MD=mwAl$*W&wIMt1f_yB5Iko6q0tV8_jc`HNh(2!_u| zbNSv$a(O<#Pm#+_KFbnE<@o>$zPmIoSx#Y!(W{K>Zd>Y!k>HOFV0?ZR&m$i nFHV21(TD!H4u7u6U!4Bp+$Zij{KeVp{a3mCZ~q@(_fD~MSn#ziuI8x#u$7!f2a*9+r0;iyW%g}KbD*m6$UyKn! zpacb!m6rMYcKp5UB$E(AG8m2XB2Tjr!eUg`Ibsq*=MM2Wgwtol_UN?1Vf`C7U^PjG z)hL^nqZ)5K>KAE+h%}3?{7>r3I-?R29+A7&zBr@uy#~ome_EC6`V@`&^ae-gVZY`A z=h>f$`|F`LN!qW=`NTfoXK%kZ;R1W=7n>sUlDy2=*60@+9?5uES^op>GQU*pG34J>K6odS@}6Sp$Y&yZ@emeKj}s NU-V^b!SIQF`4!#$H;w=R literal 0 HcmV?d00001 From cede34cc1ad4379a95f9246bdaed5d65e06f104f Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Fri, 13 Dec 2024 13:38:04 +0000 Subject: [PATCH 38/60] registering tests/VFP_CASE.DATA back - previous commit it the line that register it was mistakenly removed --- CMakeLists_files.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index ee7c79feef7..1aebfb0ab6f 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -738,6 +738,7 @@ if(ENABLE_ECL_OUTPUT) tests/msim/action_count_no_run_function.py tests/msim/open_well_past.py tests/msim/open_well_too_late.py + tests/VFP_CASE.DATA tests/CARFIN-COLUMN.EGRID tests/CARFIN-DOUBLE.EGRID tests/CARFIN-NESTED.EGRID From c7a295778acd1edbe907d5013c0ea934bcc95bde Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 10:17:43 +0000 Subject: [PATCH 39/60] created VectorUtil and GeometricUtil libraries converting lambda functions used in EclipseGrid::init_children_host_cells --- CMakeLists_files.cmake | 4 + .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 143 +----------------- 2 files changed, 12 insertions(+), 135 deletions(-) diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 1aebfb0ab6f..f243cef45b1 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -44,6 +44,8 @@ list (APPEND MAIN_SOURCE_FILES opm/common/utility/parameters/ParameterRequirement.cpp opm/common/utility/parameters/ParameterTools.cpp opm/common/utility/numeric/calculateCellVol.cpp + opm/common/utility/numeric/GeometryUtil.cpp + opm/common/utility/numeric/VectorUtil.cpp opm/common/utility/numeric/MonotCubicInterpolator.cpp opm/common/utility/numeric/RootFinders.cpp opm/material/common/Spline.cpp @@ -831,6 +833,8 @@ list( APPEND PUBLIC_HEADER_FILES opm/common/utility/numeric/cmp.hpp opm/common/utility/numeric/blas_lapack.h opm/common/utility/numeric/calculateCellVol.hpp + opm/common/utility/numeric/GeometryUtil.hpp + opm/common/utility/numeric/VectorUtil.hpp opm/common/utility/numeric/buildUniformMonotoneTable.hpp opm/common/utility/numeric/linearInterpolation.hpp opm/common/utility/numeric/MonotCubicInterpolator.hpp diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 599bd90f458..e41cd39374a 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -17,6 +17,7 @@ along with OPM. If not, see . */ +#include #include #include #include @@ -47,6 +48,8 @@ #include #include #include +#include +#include #include @@ -73,6 +76,8 @@ #include #include #include +#include +#include #include @@ -1980,47 +1985,6 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } void EclipseGrid::init_children_host_cells(){ - constexpr std::array, 12> faceConfigurations{ - std::array{0, 1, 5}, - {1, 5, 4}, // Face 0 - {0, 4, 6}, - {4, 6, 2}, // Face 1 - {2, 3, 7}, - {3, 7, 6}, // Face 2 - {1, 3, 7}, - {3, 7, 5}, // Face 3 - {0, 1, 3}, - {1, 3, 2}, // Face 4 - {4, 5, 7}, - {5, 7, 6} // Face 5 - }; - constexpr double epslon = 1e-6; - auto calcTetraVol = [](const auto& x, const auto& y, const auto& z){ - auto det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] - - x[1]*y[2]*z[0] - x[2]*y[0]*z[1] + x[2]*y[1]*z[0] - + x[0]*y[1]*z[3] - x[0]*y[3]*z[1] - x[1]*y[0]*z[3] - + x[1]*y[3]*z[0] + x[3]*y[0]*z[1] - x[3]*y[1]*z[0] - - x[0]*y[2]*z[3] + x[0]*y[3]*z[2] + x[2]*y[0]*z[3] - - x[2]*y[3]*z[0] - x[3]*y[0]*z[2] + x[3]*y[2]*z[0] - + x[1]*y[2]*z[3] - x[1]*y[3]*z[2] - x[2]*y[1]*z[3] - + x[2]*y[3]*z[1] + x[3]*y[1]*z[2] - x[3]*y[2]*z[1]; - return std::abs(det)/6; - }; - - auto getAllCellCenters = [](const auto& cell, const auto& global_list){ - std::vector cell_centersX(global_list.size()); - std::vector cell_centersY(global_list.size()); - std::vector cell_centersZ(global_list.size()); - std::array value = {0,0,0}; - for (std::size_t index = 0; index < global_list.size(); index++) { - value = cell.getCellCenter(global_list[index]); - cell_centersX[index] = value[0]; - cell_centersY[index] = value[1]; - cell_centersZ[index] = value[2]; - } - return std::make_tuple(cell_centersX,cell_centersY,cell_centersZ); - }; - auto getAllCellCorners = [this](const auto& father_list){ std::vector> X(father_list.size()); std::vector> Y(father_list.size()); @@ -2031,102 +1995,12 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return std::make_tuple(X, Y,Z); }; - auto appendNode = [](const std::array& X, const std::array& Y, const std::array& Z, - const double& xc, const double& yc, const double& zc ){ - std::array tX; - std::array tY; - std::array tZ; - std::copy(X.begin(), X.end(), tX.begin()); - tX[3]= xc; - std::copy(Y.begin(), Y.end(), tY.begin()); - tY[3]= yc; - std::copy(Z.begin(), Z.end(), tZ.begin()); - tZ[3]= zc; - return std::make_tuple(tX,tY,tZ); - }; - - auto getNodes = [](const std::array& X, const std::array& Y, const std::array& Z, - const std::array& ind){ - std::array filtered_vectorX; - std::array filtered_vectorY; - std::array filtered_vectorZ; - for (std::size_t index = 0; index < ind.size(); index++) { - filtered_vectorX[index] = X[ind[index]]; - filtered_vectorY[index] = Y[ind[index]]; - filtered_vectorZ[index] = Z[ind[index]]; - } - return std::make_tuple(filtered_vectorX,filtered_vectorY,filtered_vectorZ); - }; - - auto filterArray = [](const std::vector& X, const std::vector& ind){ - std::vector filtered_vectorX(ind.size(),0); - for (std::size_t index = 0; index < ind.size(); index++) { - filtered_vectorX[index] = X[ind[index]]; - } - return filtered_vectorX; - }; - - auto calcHexaVol = [getNodes, appendNode, calcTetraVol, faceConfigurations] - (const auto& x, const auto& y, const auto& z, - const auto& cx, const auto& cy, const auto& cz ){ - // note: some CPG grids may have collapsed faces that are not planar, therefore - // the hexadron is subdivided in terahedrons. - // calculating the volume of the pyramid with F0 as base and pc as center - double totalVolume = 0.0; - for (size_t i = 0; i < faceConfigurations.size(); i += 2) { - auto [fX0, fY0, fZ0] = getNodes(x, y, z, faceConfigurations[i]); - totalVolume += std::apply(calcTetraVol, appendNode(fX0, fY0, fZ0, cx, cy, cz)); - - auto [fX1, fY1, fZ1] = getNodes(x, y, z, faceConfigurations[i + 1]); - totalVolume += std::apply(calcTetraVol, appendNode(fX1, fY1, fZ1, cx, cy, cz)); - } - return totalVolume; - }; - - - auto isInsideElement = [calcHexaVol](const std::vector& tpX, const std::vector& tpY, const std::vector& tpZ, - const std::vector>& X, const std::vector>& Y, - const std::vector>& Z){ - std::vector in_elements(tpX.size(),0); - // check if it is insde or outside boundary box - double minX, minY, minZ, maxX, maxY, maxZ; - double pcX, pcY, pcZ, element_volume, test_element_volume; - bool flag; - for (std::size_t outerIndex = 0; outerIndex < X.size(); outerIndex++) { - minX = *std::min_element(X[outerIndex].begin(), X[outerIndex].end()); - minY = *std::min_element(Y[outerIndex].begin(), Y[outerIndex].end()); - minZ = *std::min_element(Z[outerIndex].begin(), Z[outerIndex].end()); - maxX = *std::max_element(X[outerIndex].begin(), X[outerIndex].end()); - maxY = *std::max_element(Y[outerIndex].begin(), Y[outerIndex].end()); - maxZ = *std::max_element(Z[outerIndex].begin(), Z[outerIndex].end()); - pcX = std::accumulate(X[outerIndex].begin(), X[outerIndex].end(), 0.0)/8; - pcY = std::accumulate(Y[outerIndex].begin(), Y[outerIndex].end(), 0.0)/8; - pcZ = std::accumulate(Z[outerIndex].begin(), Z[outerIndex].end(), 0.0)/8; - element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex], pcX, pcY,pcZ); - for (size_t innerIndex = 0; innerIndex < tpX.size(); innerIndex++){ - // check if center of refined volume is outside the boundary box of a coarse volume. - // Only computes volumed base test is this condition is met. - flag = (minX < tpX[innerIndex]) && (maxX > tpX[innerIndex]) && - (minY < tpY[innerIndex]) && (maxY > tpY[innerIndex]) && - (minZ < tpZ[innerIndex]) && (maxZ > tpZ[innerIndex]); - if (flag && (in_elements[innerIndex] == 0)) { - test_element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex], - tpX[innerIndex], tpY[innerIndex],tpZ[innerIndex]); - if (std::abs(test_element_volume - element_volume) < epslon){ - in_elements[innerIndex] = static_cast(outerIndex); - } - } - } - } - return in_elements; - }; - std::vector element_centerX, element_centerY, element_centerZ; for (EclipseGridLGR& lgr_cell : lgr_children_cells) { - std::tie(element_centerX, element_centerY,element_centerZ) = getAllCellCenters(lgr_cell, lgr_cell.getActiveMap()); + std::tie(element_centerX, element_centerY,element_centerZ) = VectorUtil::callMethodForEachInputOnObjectXYZ, int,std::array (EclipseGridLGR::*)(size_t) const>(lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); auto [host_cellX, host_cellY, host_cellZ] = getAllCellCorners(lgr_cell.get_father_global()); - auto inside_el = isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); - auto host_cells_global_ref = filterArray(lgr_cell.get_father_global(), inside_el); + auto inside_el = GeometryUtil::isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); + std::vector host_cells_global_ref = VectorUtil::filterArray(lgr_cell.get_father_global(), inside_el); lgr_cell.set_hostnum(host_cells_global_ref); lgr_cell.init_children_host_cells(); } @@ -2631,7 +2505,6 @@ namespace Opm { } egridfile.write("LGRPARNT", lgr_father_name_label); - Opm::UnitSystem::UnitType unitSystemType = units.getType(); constexpr auto length = ::Opm::UnitSystem::measure::length; const std::array dims = getNXYZ(); From edf2f9e1a7028067e0fecacc45d822cb23eca0a7 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 10:22:07 +0000 Subject: [PATCH 40/60] refactor EclipseGrid:: init_children_host_cells --- opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index e41cd39374a..b5a2bac45b3 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -1997,7 +1997,9 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector element_centerX, element_centerY, element_centerZ; for (EclipseGridLGR& lgr_cell : lgr_children_cells) { - std::tie(element_centerX, element_centerY,element_centerZ) = VectorUtil::callMethodForEachInputOnObjectXYZ, int,std::array (EclipseGridLGR::*)(size_t) const>(lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); + std::tie(element_centerX, element_centerY,element_centerZ) = + VectorUtil::callMethodForEachInputOnObjectXYZ, int,std::array (EclipseGridLGR::*)(size_t) const> + (lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); auto [host_cellX, host_cellY, host_cellZ] = getAllCellCorners(lgr_cell.get_father_global()); auto inside_el = GeometryUtil::isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); std::vector host_cells_global_ref = VectorUtil::filterArray(lgr_cell.get_father_global(), inside_el); @@ -2007,8 +2009,6 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st } - - const std::vector& EclipseGrid::getActiveMap() const { return m_active_to_global; } From ee66191b40493abfcc1dc2dded6d34698bbb5f6d Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 10:25:23 +0000 Subject: [PATCH 41/60] added template functions to utility libraries --- opm/common/utility/numeric/GeometryUtil.cpp | 5 + opm/common/utility/numeric/GeometryUtil.hpp | 116 ++++++++++++++++++++ opm/common/utility/numeric/VectorUtil.cpp | 24 ++++ opm/common/utility/numeric/VectorUtil.hpp | 94 ++++++++++++++++ 4 files changed, 239 insertions(+) create mode 100644 opm/common/utility/numeric/GeometryUtil.cpp create mode 100644 opm/common/utility/numeric/GeometryUtil.hpp create mode 100644 opm/common/utility/numeric/VectorUtil.cpp create mode 100644 opm/common/utility/numeric/VectorUtil.hpp diff --git a/opm/common/utility/numeric/GeometryUtil.cpp b/opm/common/utility/numeric/GeometryUtil.cpp new file mode 100644 index 00000000000..da146db0b6e --- /dev/null +++ b/opm/common/utility/numeric/GeometryUtil.cpp @@ -0,0 +1,5 @@ +#include + +namespace GeometryUtil { + +} // namespace GeometryUtils diff --git a/opm/common/utility/numeric/GeometryUtil.hpp b/opm/common/utility/numeric/GeometryUtil.hpp new file mode 100644 index 00000000000..f930fab4f1f --- /dev/null +++ b/opm/common/utility/numeric/GeometryUtil.hpp @@ -0,0 +1,116 @@ +#ifndef GEOMETRYUTIL_H +#define GEOMETRYUTIL_H + +#include +#include +#include +#include +namespace GeometryUtil { + +constexpr double epslon = 1e-6; +// A simple utility function to calculate area of a rectangle +double calculateRectangleArea(double width, double height); + +template +T calcTetraVol(const std::array& x, const std::array& y, const std::array& z ){ + T det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2] + - x[1]*y[2]*z[0] - x[2]*y[0]*z[1] + x[2]*y[1]*z[0] + + x[0]*y[1]*z[3] - x[0]*y[3]*z[1] - x[1]*y[0]*z[3] + + x[1]*y[3]*z[0] + x[3]*y[0]*z[1] - x[3]*y[1]*z[0] + - x[0]*y[2]*z[3] + x[0]*y[3]*z[2] + x[2]*y[0]*z[3] + - x[2]*y[3]*z[0] - x[3]*y[0]*z[2] + x[3]*y[2]*z[0] + + x[1]*y[2]*z[3] - x[1]*y[3]*z[2] - x[2]*y[1]*z[3] + + x[2]*y[3]*z[1] + x[3]*y[1]*z[2] - x[3]*y[2]*z[1]; + return std::abs(det)/6; +} + +template +T calcHexaVol(const std::array& x, const std::array& y, const std::array& z, + const T& cx, const T& cy, const T& cz ) +{ + constexpr std::array, 12> faceConfigurations + { + std::array{0, 1, 5}, + {1, 5, 4}, // Face 0 + {0, 4, 6}, + {4, 6, 2}, // Face 1 + {2, 3, 7}, + {3, 7, 6}, // Face 2 + {1, 3, 7}, + {3, 7, 5}, // Face 3 + {0, 1, 3}, + {1, 3, 2}, // Face 4 + {4, 5, 7}, + {5, 7, 6} // Face 5 + }; + auto getNodes = [](const std::array& X, const std::array& Y, const std::array& Z, + const std::array& ind){ + std::array filtered_vectorX; + std::array filtered_vectorY; + std::array filtered_vectorZ; + for (std::size_t index = 0; index < ind.size(); index++) { + filtered_vectorX[index] = X[ind[index]]; + filtered_vectorY[index] = Y[ind[index]]; + filtered_vectorZ[index] = Z[ind[index]]; + } + return std::make_tuple(filtered_vectorX,filtered_vectorY,filtered_vectorZ); + }; + // note: some CPG grids may have collapsed faces that are not planar, therefore + // the hexadron is subdivided in terahedrons. + // calculating the volume of the pyramid with F0 as base and pc as center + T totalVolume = 0.0; + for (size_t i = 0; i < faceConfigurations.size(); i += 2) { + auto [fX0, fY0, fZ0] = getNodes(x, y, z, faceConfigurations[i]); + totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX0, fY0, fZ0, cx, cy, cz)); + + auto [fX1, fY1, fZ1] = getNodes(x, y, z, faceConfigurations[i + 1]); + totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX1, fY1, fZ1, cx, cy, cz)); + } + return totalVolume; +}; + +template +std::vector isInsideElement(const std::vector& tpX, const std::vector& tpY, const std::vector& tpZ, + const std::vector>& X, const std::vector>& Y, + const std::vector>& Z) +{ + std::vector in_elements(tpX.size(),0); + // check if it is insde or outside boundary box + T minX, minY, minZ, maxX, maxY, maxZ; + T pcX, pcY, pcZ, element_volume, test_element_volume; + bool flag; + for (std::size_t outerIndex = 0; outerIndex < X.size(); outerIndex++) { + minX = *std::min_element(X[outerIndex].begin(), X[outerIndex].end()); + minY = *std::min_element(Y[outerIndex].begin(), Y[outerIndex].end()); + minZ = *std::min_element(Z[outerIndex].begin(), Z[outerIndex].end()); + maxX = *std::max_element(X[outerIndex].begin(), X[outerIndex].end()); + maxY = *std::max_element(Y[outerIndex].begin(), Y[outerIndex].end()); + maxZ = *std::max_element(Z[outerIndex].begin(), Z[outerIndex].end()); + pcX = std::accumulate(X[outerIndex].begin(), X[outerIndex].end(), 0.0)/8; + pcY = std::accumulate(Y[outerIndex].begin(), Y[outerIndex].end(), 0.0)/8; + pcZ = std::accumulate(Z[outerIndex].begin(), Z[outerIndex].end(), 0.0)/8; + element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex], pcX, pcY,pcZ); + for (size_t innerIndex = 0; innerIndex < tpX.size(); innerIndex++){ + // check if center of refined volume is outside the boundary box of a coarse volume. + // Only computes volumed base test is this condition is met. + flag = (minX < tpX[innerIndex]) && (maxX > tpX[innerIndex]) && + (minY < tpY[innerIndex]) && (maxY > tpY[innerIndex]) && + (minZ < tpZ[innerIndex]) && (maxZ > tpZ[innerIndex]); + if (flag && (in_elements[innerIndex] == 0)) { + test_element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex], + tpX[innerIndex], tpY[innerIndex],tpZ[innerIndex]); + if (std::abs(test_element_volume - element_volume) < epslon){ + in_elements[innerIndex] = static_cast(outerIndex); + } + } + } + } + return in_elements; +}; + + +// Example for other utilities... + +} // namespace GeometryUtils + +#endif // GEOMETRY_UTILS_H diff --git a/opm/common/utility/numeric/VectorUtil.cpp b/opm/common/utility/numeric/VectorUtil.cpp new file mode 100644 index 00000000000..71241382046 --- /dev/null +++ b/opm/common/utility/numeric/VectorUtil.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +namespace VectorUtil { + +std::tuple, std::array, std::array> +appendNode(const std::array& X, const std::array& Y, + const std::array& Z, const double& xc, const double& yc, + const double& zc) +{ + std::array tX; + std::array tY; + std::array tZ; + std::copy(X.begin(), X.end(), tX.begin()); + tX[3]= xc; + std::copy(Y.begin(), Y.end(), tY.begin()); + tY[3]= yc; + std::copy(Z.begin(), Z.end(), tZ.begin()); + tZ[3]= zc; + return std::make_tuple(tX,tY,tZ); +} + +} // namespace VectorUtil diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp new file mode 100644 index 00000000000..5dd2ecebc60 --- /dev/null +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -0,0 +1,94 @@ +#ifndef VECTORUTIL_H +#define VECTORUTIL_H + +#include +#include +#include +#include +#include + +namespace VectorUtil { + +// Implementation of generation General Operation between two vectors of the same type +template +std::vector vectorOperation(const std::vector& vecA, const std::vector& vecB, Operation op) { + if (vecA.size() != vecB.size()) { + throw std::invalid_argument("Error: Vectors must have the same size!"); // Throwing exception + } + std::vector result; + result.reserve(vecA.size()); + // Use std::transform with the passed operation + std::transform(vecA.begin(), vecA.end(), vecB.begin(), std::back_inserter(result), op); + return result; +} + + +// A simple utility function to calculate area of a rectangle +std::tuple, std::array, std::array> +appendNode(const std::array&, const std::array&, + const std::array&, const double&, const double&, + const double&); +template +std::vector filterArray(const std::vector& X, const std::vector& ind){ + std::vector filtered_vectorX(ind.size(),0); + for (std::size_t index = 0; index < ind.size(); index++) { + filtered_vectorX[index] = X[ind[index]]; + } + return filtered_vectorX; +}; + +// T type of the object +// Rout type of the object output +// Method type of method +template +std::vector callMethodForEachInputOnObject(const T& obj, Method mtd, const std::vector& input_vector, Args&&... args) { + std::vector result; + // Reserve space for each vector in the tuple + result.reserve(input_vector.size()); + // Iterate over the input_vector and fill the tuple's vectors + for (const auto& element : input_vector) { + Rout value = (obj.*mtd)(element, std::forward(args)...); + result.push_back(std::move(value)); + } + return result; +} + + + +template +std::tuple,std::vector, std::vector> splitXYZ(std::vector>& input_vector ){ +std::vector X, Y, Z; + X.reserve(input_vector.size()); + Y.reserve(input_vector.size()); + Z.reserve(input_vector.size()); + for (auto& element : input_vector) { + X.push_back(std::move(element[0])); // Add to first vector + Y.push_back(std::move(element[1])); // Add to second vector + Z.push_back(std::move(element[2])); // Add to third vector + } + return std::make_tuple(X,Y,Z); +} + + +template +auto callMethodForEachInputOnObjectXYZ(const T& obj, Method mtd, const std::vector& input_vector, Args&&... args) { + using X = typename Rout::value_type; + auto result = callMethodForEachInputOnObject(obj, mtd, input_vector, std::forward(args)...); + return splitXYZ(result); +} + +template + void test(std::vector vec){ + std::size_t index = 1; + for (T el : vec){ + index++; + } +} + + + +// Example for other utilities... + +} // namespace VectorUtil + +#endif // VECTORUTIL_H From 68c80d1860e3e21e6a3ca69a27b63cda40d701de Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 11:00:39 +0000 Subject: [PATCH 42/60] fixed missing header bug --- opm/common/utility/numeric/GeometryUtil.hpp | 6 ++--- opm/common/utility/numeric/VectorUtil.cpp | 18 --------------- opm/common/utility/numeric/VectorUtil.hpp | 22 ++++++++++++++++++- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 4 ++-- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 2 +- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/opm/common/utility/numeric/GeometryUtil.hpp b/opm/common/utility/numeric/GeometryUtil.hpp index f930fab4f1f..7f26f5e9157 100644 --- a/opm/common/utility/numeric/GeometryUtil.hpp +++ b/opm/common/utility/numeric/GeometryUtil.hpp @@ -41,7 +41,7 @@ T calcHexaVol(const std::array& x, const std::array& y, const std::arr {0, 1, 3}, {1, 3, 2}, // Face 4 {4, 5, 7}, - {5, 7, 6} // Face 5 + {5, 7, 6} // Face 5 }; auto getNodes = [](const std::array& X, const std::array& Y, const std::array& Z, const std::array& ind){ @@ -61,10 +61,10 @@ T calcHexaVol(const std::array& x, const std::array& y, const std::arr T totalVolume = 0.0; for (size_t i = 0; i < faceConfigurations.size(); i += 2) { auto [fX0, fY0, fZ0] = getNodes(x, y, z, faceConfigurations[i]); - totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX0, fY0, fZ0, cx, cy, cz)); + totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX0, fY0, fZ0, cx, cy, cz)); auto [fX1, fY1, fZ1] = getNodes(x, y, z, faceConfigurations[i + 1]); - totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX1, fY1, fZ1, cx, cy, cz)); + totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX1, fY1, fZ1, cx, cy, cz)); } return totalVolume; }; diff --git a/opm/common/utility/numeric/VectorUtil.cpp b/opm/common/utility/numeric/VectorUtil.cpp index 71241382046..25a1a4be553 100644 --- a/opm/common/utility/numeric/VectorUtil.cpp +++ b/opm/common/utility/numeric/VectorUtil.cpp @@ -1,24 +1,6 @@ #include -#include -#include namespace VectorUtil { -std::tuple, std::array, std::array> -appendNode(const std::array& X, const std::array& Y, - const std::array& Z, const double& xc, const double& yc, - const double& zc) -{ - std::array tX; - std::array tY; - std::array tZ; - std::copy(X.begin(), X.end(), tX.begin()); - tX[3]= xc; - std::copy(Y.begin(), Y.end(), tY.begin()); - tY[3]= yc; - std::copy(Z.begin(), Z.end(), tZ.begin()); - tZ[3]= zc; - return std::make_tuple(tX,tY,tZ); -} } // namespace VectorUtil diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp index 5dd2ecebc60..2115b2cf354 100644 --- a/opm/common/utility/numeric/VectorUtil.hpp +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -5,10 +5,30 @@ #include #include #include -#include +#include +#include + namespace VectorUtil { + +template +std::tuple, std::array, std::array> +appendNode(const std::array& X, const std::array& Y, const std::array& Z, + const T& xc, const T& yc, const T& zc) +{ + std::array tX; + std::array tY; + std::array tZ; + std::copy(X.begin(), X.end(), tX.begin()); + tX[3]= xc; + std::copy(Y.begin(), Y.end(), tY.begin()); + tY[3]= yc; + std::copy(Z.begin(), Z.end(), tZ.begin()); + tZ[3]= zc; + return std::make_tuple(tX,tY,tZ); +} + // Implementation of generation General Operation between two vectors of the same type template std::vector vectorOperation(const std::vector& vecA, const std::vector& vecB, Operation op) { diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index b5a2bac45b3..33bc026da35 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -2465,8 +2465,8 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st namespace Opm { EclipseGridLGR::EclipseGridLGR(const std::string& self_label, const std::string& father_label_, std::size_t nx, std::size_t ny, std::size_t nz, - vec_size_t father_lgr_index, const std::array& low_fahterIJK_, - const std::array& up_fahterIJK_) + const vec_size_t& father_lgr_index, [[maybe_unused]] const std::array& low_fahterIJK_, + [[maybe_unused]] const std::array& up_fahterIJK_) : EclipseGrid(nx,ny,nz), father_label(father_label_), father_global(father_lgr_index) { init_father_global(); diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 4c9cefe8079..cd2baa462c0 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -372,7 +372,7 @@ namespace Opm { EclipseGridLGR() = default; EclipseGridLGR(const std::string& self_label, const std::string& father_label_, size_t nx, size_t ny, size_t nz, - vec_size_t father_lgr_index, const std::array& low_fahterIJK_, + const vec_size_t& father_lgr_index, const std::array& low_fahterIJK_, const std::array& up_fahterIJK_); ~EclipseGridLGR() = default; const vec_size_t& getFatherGlobalID() const; From 3e93458b0c3307ef958f8d35ac361e1e585959d1 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 12:04:49 +0000 Subject: [PATCH 43/60] header incuded --- opm/common/utility/numeric/VectorUtil.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp index 2115b2cf354..59b6cdcc657 100644 --- a/opm/common/utility/numeric/VectorUtil.hpp +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include From db83e2a7795f8e449f4f7f2226809cac48a2bc6d Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 15:01:11 +0000 Subject: [PATCH 44/60] refactor to improve template deduction --- opm/common/utility/numeric/VectorUtil.hpp | 24 ++++-------------- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 5 ++-- tests/OPMCARFIN-COLUMN.EGRID | Bin 3108 -> 3108 bytes tests/OPMCARFIN-DOUBLE.EGRID | Bin 3868 -> 3868 bytes tests/OPMCARFIN-NESTED.EGRID | Bin 4604 -> 4604 bytes tests/OPMCARFIN5.EGRID | Bin 3172 -> 3172 bytes 6 files changed, 7 insertions(+), 22 deletions(-) diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp index 59b6cdcc657..0382e702588 100644 --- a/opm/common/utility/numeric/VectorUtil.hpp +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -11,7 +11,6 @@ namespace VectorUtil { - template std::tuple, std::array, std::array> appendNode(const std::array& X, const std::array& Y, const std::array& Z, @@ -60,14 +59,14 @@ std::vector filterArray(const std::vector& X, const std::vector< // T type of the object // Rout type of the object output // Method type of method -template +template std::vector callMethodForEachInputOnObject(const T& obj, Method mtd, const std::vector& input_vector, Args&&... args) { std::vector result; // Reserve space for each vector in the tuple result.reserve(input_vector.size()); // Iterate over the input_vector and fill the tuple's vectors for (const auto& element : input_vector) { - Rout value = (obj.*mtd)(element, std::forward(args)...); + Rout value = (obj.*mtd)(element, args...); result.push_back(std::move(value)); } return result; @@ -90,25 +89,12 @@ std::vector X, Y, Z; } -template +template auto callMethodForEachInputOnObjectXYZ(const T& obj, Method mtd, const std::vector& input_vector, Args&&... args) { - using X = typename Rout::value_type; - auto result = callMethodForEachInputOnObject(obj, mtd, input_vector, std::forward(args)...); - return splitXYZ(result); -} - -template - void test(std::vector vec){ - std::size_t index = 1; - for (T el : vec){ - index++; - } + auto result = callMethodForEachInputOnObject< Rout,T, Rin, Method, Args...>(obj, mtd, input_vector, std::forward(args)...); + return splitXYZ(result); } - - -// Example for other utilities... - } // namespace VectorUtil #endif // VECTORUTIL_H diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 33bc026da35..ca09d2e3953 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -17,7 +17,6 @@ along with OPM. If not, see . */ -#include #include #include #include @@ -1998,8 +1997,8 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector element_centerX, element_centerY, element_centerZ; for (EclipseGridLGR& lgr_cell : lgr_children_cells) { std::tie(element_centerX, element_centerY,element_centerZ) = - VectorUtil::callMethodForEachInputOnObjectXYZ, int,std::array (EclipseGridLGR::*)(size_t) const> - (lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); + VectorUtil::callMethodForEachInputOnObjectXYZ,EclipseGridLGR, int,std::array (EclipseGridLGR::*)(size_t) const> + (lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); auto [host_cellX, host_cellY, host_cellZ] = getAllCellCorners(lgr_cell.get_father_global()); auto inside_el = GeometryUtil::isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); std::vector host_cells_global_ref = VectorUtil::filterArray(lgr_cell.get_father_global(), inside_el); diff --git a/tests/OPMCARFIN-COLUMN.EGRID b/tests/OPMCARFIN-COLUMN.EGRID index bfd9b6bd4ef2e8e2d9f8b60386eff7312f1858ad..43b59847bc4e12bd00bba577b0d28208c6edf1db 100644 GIT binary patch delta 45 xcmZ1?u|#6S5_X9&t?Gpg4548R3=Bp<%ot|6h!Mo!=*Y)7xsO?J^KA}KW&jL>3s(RD delta 25 hcmZ1?u|#6S686ax*rYe7GjTIc?qe3*e4E3Q831+{2v-0A diff --git a/tests/OPMCARFIN-DOUBLE.EGRID b/tests/OPMCARFIN-DOUBLE.EGRID index 593978980fc1aee4f608738b3640862f3a765449..2bce629e15d618203d43e7e52da37fb2c5b006b0 100644 GIT binary patch delta 43 xcmbOuH%D&65_X<2rbUbl4548R3=E8$H?YgF@PwJqS_l#;Elg(Ie1qGC836tN3$p+K delta 43 xcmbOuH%D&65_X>Syj0&3hKy2%)S|M@8`x!7co-NMSb>%9smFU delta 25 hcmaDN@kC<7686ax*rYe7GjTIc?qinQ{DPx~832O+2_ygj From 773d4597c10db41e1ba4fcff8c215c894a63f9ae Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 15:10:40 +0000 Subject: [PATCH 45/60] "improved deduction of template functions" --- opm/common/utility/numeric/VectorUtil.hpp | 6 +++--- opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp index 0382e702588..2bee986e1d0 100644 --- a/opm/common/utility/numeric/VectorUtil.hpp +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -59,7 +59,7 @@ std::vector filterArray(const std::vector& X, const std::vector< // T type of the object // Rout type of the object output // Method type of method -template +template std::vector callMethodForEachInputOnObject(const T& obj, Method mtd, const std::vector& input_vector, Args&&... args) { std::vector result; // Reserve space for each vector in the tuple @@ -89,9 +89,9 @@ std::vector X, Y, Z; } -template +template auto callMethodForEachInputOnObjectXYZ(const T& obj, Method mtd, const std::vector& input_vector, Args&&... args) { - auto result = callMethodForEachInputOnObject< Rout,T, Rin, Method, Args...>(obj, mtd, input_vector, std::forward(args)...); + auto result = callMethodForEachInputOnObject< Rout, Method, T, Rin,Args...>(obj, mtd, input_vector, std::forward(args)...); return splitXYZ(result); } diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index ca09d2e3953..20f6bc8ab19 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -1995,10 +1995,10 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st }; std::vector element_centerX, element_centerY, element_centerZ; - for (EclipseGridLGR& lgr_cell : lgr_children_cells) { + for (EclipseGridLGR& lgr_cell : lgr_children_cells) { std::tie(element_centerX, element_centerY,element_centerZ) = - VectorUtil::callMethodForEachInputOnObjectXYZ,EclipseGridLGR, int,std::array (EclipseGridLGR::*)(size_t) const> - (lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); + VectorUtil::callMethodForEachInputOnObjectXYZ, std::array (EclipseGridLGR::*)(size_t) const> + (lgr_cell, &EclipseGridLGR::getCellCenter, lgr_cell.getActiveMap()); auto [host_cellX, host_cellY, host_cellZ] = getAllCellCorners(lgr_cell.get_father_global()); auto inside_el = GeometryUtil::isInsideElement(element_centerX, element_centerY, element_centerZ, host_cellX, host_cellY, host_cellZ); std::vector host_cells_global_ref = VectorUtil::filterArray(lgr_cell.get_father_global(), inside_el); From 6c5fc59e7fd4fc70503a99c29968b5b4a74c2dd2 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 15:23:51 +0000 Subject: [PATCH 46/60] splitXYZ, return argument is created by moving X, Y and Z into the make_tuple --- opm/common/utility/numeric/VectorUtil.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp index 2bee986e1d0..b4bb583b04e 100644 --- a/opm/common/utility/numeric/VectorUtil.hpp +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -81,11 +81,11 @@ std::vector X, Y, Z; Y.reserve(input_vector.size()); Z.reserve(input_vector.size()); for (auto& element : input_vector) { - X.push_back(std::move(element[0])); // Add to first vector - Y.push_back(std::move(element[1])); // Add to second vector - Z.push_back(std::move(element[2])); // Add to third vector + X.push_back(element[0]); // Add to first vector + Y.push_back(element[1]); // Add to second vector + Z.push_back(element[2]); // Add to third vector } - return std::make_tuple(X,Y,Z); + return std::make_tuple(std::move(X),std::move(Y),std::move(Z)); } From 54b89b6dc4956f0474e35463b68f34cd91b530ae Mon Sep 17 00:00:00 2001 From: David Landa Marban Date: Fri, 11 Oct 2024 17:21:38 +0200 Subject: [PATCH 47/60] Handle MAPAXES and MAPUNITS --- opm/io/eclipse/EGrid.cpp | 62 ++++++++++++++---- opm/io/eclipse/EGrid.hpp | 20 ++++-- python/cxx/eclipse_io.cpp | 43 ++++++++++--- python/opm_embedded/__init__.pyi | 9 ++- python/tests/data/MAPAXES.EGRID | Bin 0 -> 1632 bytes python/tests/test_egrid.py | 105 +++++++++++++++++++------------ 6 files changed, 173 insertions(+), 66 deletions(-) create mode 100644 python/tests/data/MAPAXES.EGRID diff --git a/opm/io/eclipse/EGrid.cpp b/opm/io/eclipse/EGrid.cpp index 39552c61ca1..f3cf45af890 100644 --- a/opm/io/eclipse/EGrid.cpp +++ b/opm/io/eclipse/EGrid.cpp @@ -35,7 +35,7 @@ namespace Opm { namespace EclIO { -using NNCentry = std::tuple; +using NNCentry = std::tuple; EGrid::EGrid(const std::string& filename, const std::string& grid_name) : EclFile(filename), inputFileName { filename }, m_grid_name {grid_name} @@ -55,6 +55,8 @@ EGrid::EGrid(const std::string& filename, const std::string& grid_name) nnc2_array_index = -1; coordsys_array_index = -1; m_radial = false; + m_mapaxes_loaded = false; + double length_factor = 1.0; int hostnum_index = -1; @@ -81,10 +83,25 @@ EGrid::EGrid(const std::string& filename, const std::string& grid_name) if (array_name[n] == "MAPUNITS"){ auto mapunits = this->get(n); m_mapunits = mapunits[0]; + if (m_mapunits == "METRES") + length_factor = 1.0; + else if (m_mapunits == "FEET") + length_factor = 0.3048; + else if (m_mapunits == "CM") + length_factor = 0.01; + else{ + std::string message = "Unit system " + m_mapunits + " not supported for MAPUNITS"; + OPM_THROW(std::invalid_argument, message); + } } - if (array_name[n] == "MAPAXES") - m_mapaxes = this->get(n); + if (array_name[n] == "MAPAXES"){ + const auto& mapAx = this->get(n); + std::transform(mapAx.begin(), mapAx.end(), this->m_mapaxes.begin(), + [length_factor](const float elm) { return elm * length_factor; }); + mapaxes_init(); + m_mapaxes_loaded = true; + } if (lgrname == grid_name) { if (array_name[n] == "GRIDHEAD") { @@ -322,11 +339,31 @@ std::array EGrid::ijk_from_global_index(int globInd) const return result; } +void EGrid::mapaxes_transform(double& x, double& y) const { + double tmpx = x; + x = origin[0] + tmpx * unit_x[0] + y * unit_y[0]; + y = origin[1] + tmpx * unit_x[1] + y * unit_y[1]; +} + +void EGrid::mapaxes_init() +{ + origin = {m_mapaxes[2], m_mapaxes[3]}; + unit_x = {m_mapaxes[4] - m_mapaxes[2], m_mapaxes[5] - m_mapaxes[3]}; + unit_y = {m_mapaxes[0] - m_mapaxes[2], m_mapaxes[1] - m_mapaxes[3]}; + + auto norm_x = 1.0 / std::hypot(unit_x[0], unit_x[1]); + auto norm_y = 1.0 / std::hypot(unit_y[0], unit_y[1]); + + unit_x[0] *= norm_x; + unit_x[1] *= norm_x; + unit_y[0] *= norm_y; + unit_y[1] *= norm_y; +} void EGrid::getCellCorners(const std::array& ijk, - std::array& X, - std::array& Y, - std::array& Z) + std::array& X, + std::array& Y, + std::array& Z) { if (coord_array.empty()) load_grid_data(); @@ -351,7 +388,7 @@ void EGrid::getCellCorners(const std::array& ijk, for (int n = 0; n < 4; n++) zind.push_back(zind[n] + nijk[0]*nijk[1]*4); - for (int n = 0; n< 8; n++) + for (int n = 0; n < 8; n++) Z[n] = zcorn_array[zind[n]]; for (int n = 0; n < 4; n++) { @@ -366,8 +403,8 @@ void EGrid::getCellCorners(const std::array& ijk, if (m_radial) { xt = coord_array[pind[n]] * cos(coord_array[pind[n] + 1] / 180.0 * M_PI); yt = coord_array[pind[n]] * sin(coord_array[pind[n] + 1] / 180.0 * M_PI); - xb = coord_array[pind[n]+3] * cos(coord_array[pind[n] + 4] / 180.0 * M_PI); - yb = coord_array[pind[n]+3] * sin(coord_array[pind[n] + 4] / 180.0 * M_PI); + xb = coord_array[pind[n] + 3] * cos(coord_array[pind[n] + 4] / 180.0 * M_PI); + yb = coord_array[pind[n] + 3] * sin(coord_array[pind[n] + 4] / 180.0 * M_PI); } else { xt = coord_array[pind[n]]; yt = coord_array[pind[n] + 1]; @@ -390,11 +427,10 @@ void EGrid::getCellCorners(const std::array& ijk, } - -void EGrid::getCellCorners(int globindex, std::array& X, - std::array& Y, std::array& Z) +void EGrid::getCellCorners(int globindex, std::array& X, + std::array& Y, std::array& Z) { - return getCellCorners(ijk_from_global_index(globindex),X,Y,Z); + return getCellCorners(ijk_from_global_index(globindex), X, Y, Z); } diff --git a/opm/io/eclipse/EGrid.hpp b/opm/io/eclipse/EGrid.hpp index 3fefd7260fd..f748eac8a67 100644 --- a/opm/io/eclipse/EGrid.hpp +++ b/opm/io/eclipse/EGrid.hpp @@ -42,8 +42,8 @@ class EGrid : public EclFile std::array ijk_from_active_index(int actInd) const; std::array ijk_from_global_index(int globInd) const; - void getCellCorners(int globindex, std::array& X, std::array& Y, std::array& Z); - void getCellCorners(const std::array& ijk, std::array& X, std::array& Y, std::array& Z); + void getCellCorners(int globindex, std::array& X, std::array& Y, std::array& Z); + void getCellCorners(const std::array& ijk, std::array& X, std::array& Y, std::array& Z); std::vector> getXYZ_layer(int layer, bool bottom=false); std::vector> getXYZ_layer(int layer, const std::array& box, bool bottom=false); @@ -53,18 +53,20 @@ class EGrid : public EclFile void load_grid_data(); void load_nnc_data(); + bool with_mapaxes() const { return m_mapaxes_loaded; } + void mapaxes_transform(double& x, double& y) const; bool is_radial() const { return m_radial; } const std::vector& hostCellsGlobalIndex() const { return host_cells; } std::vector> hostCellsIJK(); - // zero based: i1, j1,k1, i2,j2,k2, transmisibility + // zero based: i1,j1,k1, i2,j2,k2, transmisibility using NNCentry = std::tuple; std::vector get_nnc_ijk(); const std::vector& list_of_lgrs() const { return lgr_names; } - const std::vector& get_mapaxes() const { return m_mapaxes; } + const std::array& get_mapaxes() const { return m_mapaxes; } const std::string& get_mapunits() const { return m_mapunits; } const std::vector& get_coord() const { return coord_array; } const std::vector& get_zcorn() const { return zcorn_array; } @@ -77,8 +79,12 @@ class EGrid : public EclFile std::string m_grid_name; bool m_radial; - std::vector m_mapaxes; + std::array m_mapaxes; std::string m_mapunits; + bool m_mapaxes_loaded; + std::array origin; + std::array unit_x; + std::array unit_y; std::array nijk; std::array host_nijk; @@ -112,8 +118,10 @@ class EGrid : public EclFile std::vector get_zcorn_from_disk(int layer, bool bottom); void getCellCorners(const std::array& ijk, const std::vector& zcorn_layer, - std::array& X, std::array& Y, std::array& Z); + std::array& X, std::array& Y, std::array& Z); + void mapaxes_init(); + }; }} // namespace Opm::EclIO diff --git a/python/cxx/eclipse_io.cpp b/python/cxx/eclipse_io.cpp index 8c724dcf31a..64ad9a87635 100644 --- a/python/cxx/eclipse_io.cpp +++ b/python/cxx/eclipse_io.cpp @@ -156,7 +156,7 @@ class EclOutputBind { public: - EclOutputBind(const std::string& filename,const bool formatted, const bool append) + EclOutputBind(const std::string& filename, const bool formatted, const bool append) { if (append == true) m_output = std::make_unique(filename, formatted, std::ios::app); @@ -292,26 +292,51 @@ npArray get_erst_vector(Opm::EclIO::ERst * file_ptr, const std::string& key, siz return get_erst_by_index(file_ptr, array_index, rstep); } - std::tuple, std::array, std::array> -get_xyz_from_ijk(Opm::EclIO::EGrid * file_ptr,int i, int j, int k) +get_xyz_from_ijk(Opm::EclIO::EGrid * file_ptr, int i, int j, int k) { std::array X = {0.0}; std::array Y = {0.0}; std::array Z = {0.0}; - std::array ijk = {i, j, k }; + std::array ijk = {i, j, k}; file_ptr->getCellCorners(ijk, X, Y, Z); - return std::make_tuple( X, Y, Z); + return std::make_tuple(X, Y, Z); +} + +std::tuple, std::array, std::array> +get_xyz_from_ijk_mapaxes(Opm::EclIO::EGrid * file_ptr, int i, int j, int k, bool mapaxes) +{ + auto xyz = get_xyz_from_ijk(file_ptr, i, j, k); + + if (file_ptr->with_mapaxes() && mapaxes){ + for (int n = 0; n < 8; n++) + file_ptr->mapaxes_transform(std::get<0>(xyz)[n], std::get<1>(xyz)[n]); + } + + return xyz; } std::tuple, std::array, std::array> get_xyz_from_active_index(Opm::EclIO::EGrid * file_ptr, int actIndex) { std::array ijk = file_ptr->ijk_from_active_index(actIndex); - return get_xyz_from_ijk(file_ptr,ijk[0], ijk[1], ijk[2]); + return get_xyz_from_ijk(file_ptr, ijk[0], ijk[1], ijk[2]); +} + +std::tuple, std::array, std::array> +get_xyz_from_active_index_mapaxes(Opm::EclIO::EGrid * file_ptr, int actIndex, bool mapaxes) +{ + auto xyz = get_xyz_from_active_index(file_ptr, actIndex); + + if (file_ptr->with_mapaxes() && mapaxes){ + for (int n = 0; n < 8; n++) + file_ptr->mapaxes_transform(std::get<0>(xyz)[n], std::get<1>(xyz)[n]); + } + + return xyz; } py::array get_cellvolumes_mask(Opm::EclIO::EGrid * file_ptr, std::vector mask) @@ -463,15 +488,19 @@ void python::common::export_IO(py::module& m) { .def("units", &ESmryBind::units); py::class_(m, "EGrid") - .def(py::init()) + .def(py::init(), py::arg("filename"), + py::arg("grid_name") = "global") .def_property_readonly("active_cells", &Opm::EclIO::EGrid::activeCells) .def_property_readonly("dimension", &Opm::EclIO::EGrid::dimension) .def("ijk_from_global_index", &Opm::EclIO::EGrid::ijk_from_global_index) .def("ijk_from_active_index", &Opm::EclIO::EGrid::ijk_from_active_index) .def("active_index", &Opm::EclIO::EGrid::active_index) .def("global_index", &Opm::EclIO::EGrid::global_index) + .def("export_mapaxes", &Opm::EclIO::EGrid::get_mapaxes) .def("xyz_from_ijk", &get_xyz_from_ijk) + .def("xyz_from_ijk", &get_xyz_from_ijk_mapaxes) .def("xyz_from_active_index", &get_xyz_from_active_index) + .def("xyz_from_active_index", &get_xyz_from_active_index_mapaxes) .def("cellvolumes", &get_cellvolumes) .def("cellvolumes", &get_cellvolumes_mask); diff --git a/python/opm_embedded/__init__.pyi b/python/opm_embedded/__init__.pyi index 913628e6a93..1ae0b237bd8 100644 --- a/python/opm_embedded/__init__.pyi +++ b/python/opm_embedded/__init__.pyi @@ -2480,17 +2480,24 @@ class Dimension: def scaling(self) -> float: ... class EGrid: - def __init__(self, arg0: str) -> None: ... + def __init__(self, filename: str, grid_name: str) -> None: ... def active_index(self, arg0: int, arg1: int, arg2: int) -> int: ... @overload def cellvolumes(self) -> numpy.ndarray: ... @overload def cellvolumes(self, arg0: List[int]) -> numpy.ndarray: ... + def export_mapaxes(self) -> numpy.ndarray: ... def global_index(self, arg0: int, arg1: int, arg2: int) -> int: ... def ijk_from_active_index(self, arg0: int) -> List[int[3]]: ... def ijk_from_global_index(self, arg0: int) -> List[int[3]]: ... + @overload def xyz_from_active_index(self, arg0: int) -> Tuple[List[float[8]], List[float[8]], List[float[8]]]: ... + @overload + def xyz_from_active_index(self, arg0: int, apply_mapaxes: bool) -> Tuple[List[float[8]], List[float[8]], List[float[8]]]: ... + @overload def xyz_from_ijk(self, arg0: int, arg1: int, arg2: int) -> Tuple[List[float[8]], List[float[8]], List[float[8]]]: ... + @overload + def xyz_from_ijk(self, arg0: int, arg1: int, arg2: int, apply_mapaxes: bool) -> Tuple[List[float[8]], List[float[8]], List[float[8]]]: ... @property def active_cells(self) -> int: ... @property diff --git a/python/tests/data/MAPAXES.EGRID b/python/tests/data/MAPAXES.EGRID new file mode 100644 index 0000000000000000000000000000000000000000..53d152b2d6c7bd70a5ba1b82a902819f96608899 GIT binary patch literal 1632 zcmeH|K~BRk5Je|Nf-b#enNzUEmhI9=je}fQLaaFjs~&;-^dRLdtoT1+ny8`+R0Nxj zH2Kdz6GxMb5)m#K>tom>mE0$DQn!Z z@=KSYcwaJK#8_$snI7ugQ(SX>ougaPL*9m05&t1V4ZE!bGL+|#<{>wMHvrEj`Qb<8UA|SxaRoTd*eZ!1NI8%{==qr=f2<_I>^cX)ph!7R{ZL_>5o& fG0vB?Y3mw1AO8cwH4FNp6U-VDQ{bnAEPDMXXxLkG literal 0 HcmV?d00001 diff --git a/python/tests/test_egrid.py b/python/tests/test_egrid.py index d0e09e0e1c7..4083e4a3b89 100755 --- a/python/tests/test_egrid.py +++ b/python/tests/test_egrid.py @@ -1,7 +1,5 @@ import unittest -import sys import numpy as np -import datetime from opm.io.ecl import EGrid try: @@ -22,67 +20,96 @@ def test_ijk_active_and_global_indices(self): self.assertEqual(grid1.active_cells, 2794) - nI,nJ,nK = grid1.dimension - tot_ant_cells = nI*nJ*nK + nI, nJ, nK = grid1.dimension + tot_ant_cells = nI * nJ * nK - self.assertEqual( nI, 13) - self.assertEqual( nJ, 22) - self.assertEqual( nK, 11) + self.assertEqual(nI, 13) + self.assertEqual(nJ, 22) + self.assertEqual(nK, 11) - i,j,k = grid1.ijk_from_global_index(0) + i, j, k = grid1.ijk_from_global_index(0) - self.assertEqual( i, 0) - self.assertEqual( j, 0) - self.assertEqual( k, 0) + self.assertEqual(i, 0) + self.assertEqual(j, 0) + self.assertEqual(k, 0) - i,j,k = grid1.ijk_from_global_index(1000) + i, j, k = grid1.ijk_from_global_index(1000) - self.assertEqual( i, 12) - self.assertEqual( j, 10) - self.assertEqual( k, 3) + self.assertEqual(i, 12) + self.assertEqual(j, 10) + self.assertEqual(k, 3) - self.assertEqual( grid1.global_index(12, 10, 3), 1000 ) + self.assertEqual(grid1.global_index(12, 10, 3), 1000) - i,j,k = grid1.ijk_from_global_index(tot_ant_cells - 1) + i, j, k = grid1.ijk_from_global_index(tot_ant_cells - 1) - self.assertEqual( i, nI -1 ) - self.assertEqual( j, nJ -1 ) - self.assertEqual( k, nK -1 ) + self.assertEqual(i, nI - 1) + self.assertEqual(j, nJ - 1) + self.assertEqual(k, nK - 1) with self.assertRaises(ValueError): i,j,k = grid1.ijk_from_global_index(tot_ant_cells) - i,j,k = grid1.ijk_from_active_index( 1000 ) + i,j,k = grid1.ijk_from_active_index(1000) - self.assertEqual( i, 1 ) - self.assertEqual( j, 15 ) - self.assertEqual( k, 3 ) + self.assertEqual(i, 1) + self.assertEqual(j, 15) + self.assertEqual(k, 3) - self.assertEqual( grid1.active_index(1, 15, 3), 1000 ) + self.assertEqual( grid1.active_index(1, 15, 3), 1000) + + + def test_mapaxes(self): + + axsref = [304.8, 152.4, 304.8, 457.2, 609.6, 457.2] + X1ref = [304.8, 305.8, 304.8, 305.8, 304.8, 305.8, 304.8, 305.8] + Y1ref = [457.2, 457.2, 456.2, 456.2, 457.2, 457.2, 456.2, 456.2] + + grid1 = EGrid(test_path("data/MAPAXES.EGRID")) + + X1, Y1, _ = grid1.xyz_from_ijk(0, 0, 0, True) + + for n in range(0, 8): + self.assertAlmostEqual(X1ref[n], X1[n], 8) + self.assertAlmostEqual(Y1ref[n], Y1[n], 8) + + axs = grid1.export_mapaxes() + + for n in range(0, 6): + self.assertAlmostEqual(axsref[n], axs[n], 8) + + X2ref = [0., 1., 0., 1., 0., 1., 0., 1.] + Y2ref = [0., 0., 1., 1., 0., 0., 1., 1.] + + X2, Y2, _ = grid1.xyz_from_ijk(0, 0, 0) + + for n in range(0, 8): + self.assertAlmostEqual(X2ref[n], X2[n], 8) + self.assertAlmostEqual(Y2ref[n], Y2[n], 8) def test_coordinates(self): - Xref=[2899.45166015625, 2999.390869140625, 2899.45166015625, 2999.390869140625, - 2899.4176237656716, 2999.3568089317187, 2899.417623015281, 2999.356808099622] - Yref=[2699.973388671875, 2699.973388671875, 2799.969482421875, 2799.969482421875, - 2699.9818918149376, 2699.9818918149376, 2799.978009571257, 2799.9780095915808] - Zref=[2565.301025390625, 2568.791015625, 2564.42822265625, 2567.918212890625, - 2575.29443359375, 2578.784423828125, 2574.421875, 2577.911865234375] + Xref = [2899.45166015625, 2999.390869140625, 2899.45166015625, 2999.390869140625, + 2899.4176237656716, 2999.3568089317187, 2899.417623015281, 2999.356808099622] + Yref = [2699.973388671875, 2699.973388671875, 2799.969482421875, 2799.969482421875, + 2699.9818918149376, 2699.9818918149376, 2799.978009571257, 2799.9780095915808] + Zref = [2565.301025390625, 2568.791015625, 2564.42822265625, 2567.918212890625, + 2575.29443359375, 2578.784423828125, 2574.421875, 2577.911865234375] grid1 = EGrid(test_path("data/9_EDITNNC.EGRID")) X1, Y1, Z1 = grid1.xyz_from_ijk(9, 7, 0) - for n in range(0,8): + for n in range(0, 8): self.assertAlmostEqual(Xref[n], X1[n], 8) self.assertAlmostEqual(Yref[n], Y1[n], 8) self.assertAlmostEqual(Zref[n], Z1[n], 8) - actInd = grid1.active_index(9, 7, 0); + actInd = grid1.active_index(9, 7, 0) X2, Y2, Z2 = grid1.xyz_from_active_index(actInd) - for n in range(0,8): + for n in range(0, 8): self.assertAlmostEqual(Xref[n], X2[n], 8) self.assertAlmostEqual(Yref[n], Y2[n], 8) self.assertAlmostEqual(Zref[n], Z2[n], 8) @@ -92,8 +119,8 @@ def test_cell_volume(self): grid1 = EGrid(test_path("data/9_EDITNNC.EGRID")) - nI,nJ,nK = grid1.dimension - tot_ant_cells = nI*nJ*nK + nI, nJ, nK = grid1.dimension + tot_ant_cells = nI * nJ * nK celVolAll = grid1.cellvolumes() @@ -102,16 +129,16 @@ def test_cell_volume(self): self.assertTrue(min(celVolAll) > 0.0) - mask =[0]*tot_ant_cells + mask =[0] * tot_ant_cells for k in range(nK): - globInd=grid1.global_index(0,0,k) + globInd = grid1.global_index(0, 0, k) mask[globInd] = 1 celVol = grid1.cellvolumes(mask) self.assertTrue(min(celVol) == 0.0) - self.assertEqual(np.count_nonzero(celVol) , nK) + self.assertEqual(np.count_nonzero(celVol), nK) if __name__ == "__main__": From fbcdbe6a4be9a4a019e1f7ff4ccc2d64a11c470f Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 19 Dec 2024 14:04:12 +0100 Subject: [PATCH 48/60] changed: use signed loop variable in OpenMP loop prior to OpenMP 3.0, unsigned loop variables is unsupported. --- opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 88bde4a80d5..e8ff6ae4df8 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -66,13 +66,17 @@ #include #include +#include #include +#include #include #include #include #include #include #include +#include +#include #include @@ -1555,7 +1559,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector volume(this->m_nactive); #pragma omp parallel for schedule(static) - for (std::size_t active_index = 0; active_index < this->m_active_to_global.size(); active_index++) { + for (std::int64_t active_index = 0; active_index < static_cast(this->m_active_to_global.size()); active_index++) { std::array X; std::array Y; std::array Z; From 58d568dde22a7649dff7c09a3eee6e74194f7624 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Tue, 19 Nov 2024 09:11:19 +0000 Subject: [PATCH 49/60] rebased code --- opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index e8ff6ae4df8..588124c494b 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -565,9 +565,7 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) return indKeyw < indGdfile; } - std::size_t EclipseGrid::activeIndex(std::size_t i, std::size_t j, std::size_t k) const { - return activeIndex( getGlobalIndex( i,j,k )); } @@ -1414,7 +1412,6 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) if (TOPS.size() >= area) { std::size_t initialTOPSize = TOPS.size(); TOPS.resize( volume ); - for (std::size_t targetIndex = area; targetIndex < volume; targetIndex++) { std::size_t sourceIndex = targetIndex - area; double nextValue = TOPS[sourceIndex] + DZ[sourceIndex]; @@ -2332,7 +2329,6 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st return this->m_mapaxes; } - ZcornMapper::ZcornMapper(std::size_t nx , std::size_t ny, std::size_t nz) : dims( {{nx,ny,nz}} ), stride( {{2 , 4*nx, 8*nx*ny}} ), From 7c610711942acc36a5b4fb6d5f7ddb6f25700495 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Wed, 23 Oct 2024 15:42:51 +0000 Subject: [PATCH 50/60] rebased code -set up LgrOutput as a Test environment for the developtment of the save method for the LGR EclipseGrid - EclipseGrid object and children are initialized from .EGRID file generated on standard simulator --- opm/io/eclipse/EGrid.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/opm/io/eclipse/EGrid.hpp b/opm/io/eclipse/EGrid.hpp index f748eac8a67..16e236cfa9c 100644 --- a/opm/io/eclipse/EGrid.hpp +++ b/opm/io/eclipse/EGrid.hpp @@ -74,6 +74,13 @@ class EGrid : public EclFile + + const std::vector& get_coord() const { return coord_array; } + const std::vector& get_zcorn() const { return zcorn_array; } + + + + private: std::filesystem::path inputFileName, initFileName; std::string m_grid_name; From 2d00c9ba2e6f20eb1aeeab36ca0c065f105507a1 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Tue, 19 Nov 2024 09:18:23 +0000 Subject: [PATCH 51/60] part1 - rebase EGrid.hpp seems to contain a bug where get(COORD) cannot catpure the global COORD in EGRIDs, EclipseGrid has been enhaced with functions to output .EGRIDS for LGR - unfinished work - devising a mechanism to define HOSTCE --- opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp | 2 +- opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp | 1 + opm/io/eclipse/EGrid.hpp | 8 -------- tests/parser/LgrOutputTests.cpp | 1 - 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 588124c494b..cd69825c485 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -37,7 +37,7 @@ #include #include -#include + #include #include diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index cd2baa462c0..6dad1dafd6e 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace Opm { diff --git a/opm/io/eclipse/EGrid.hpp b/opm/io/eclipse/EGrid.hpp index 16e236cfa9c..1c8168749ac 100644 --- a/opm/io/eclipse/EGrid.hpp +++ b/opm/io/eclipse/EGrid.hpp @@ -73,14 +73,6 @@ class EGrid : public EclFile - - - const std::vector& get_coord() const { return coord_array; } - const std::vector& get_zcorn() const { return zcorn_array; } - - - - private: std::filesystem::path inputFileName, initFileName; std::string m_grid_name; diff --git a/tests/parser/LgrOutputTests.cpp b/tests/parser/LgrOutputTests.cpp index 72dcfd29c3f..18c27e1f3f3 100644 --- a/tests/parser/LgrOutputTests.cpp +++ b/tests/parser/LgrOutputTests.cpp @@ -109,7 +109,6 @@ SOLUTION SCHEDULE )"; - Opm::UnitSystem units(1); std::vector vecNNC; std::array global_grid_dim = {3,3,1}; From 31ea5ff50aa4fbb0b504c8faab8912020472da97 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Tue, 29 Oct 2024 07:53:55 +0000 Subject: [PATCH 52/60] EclipseGrid is capable of initializing EclipseGridLGR hostcells. --- opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 6dad1dafd6e..18cfe62dfdb 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -386,7 +386,11 @@ namespace Opm { return father_global; } void set_hostnum(std::vector&); +<<<<<<< HEAD void set_lgr_refinement(const std::vector&, const std::vector &); +======= + void set_lgr_refinement(std::vector,std::vector); +>>>>>>> 9d788474a (EclipseGrid is capable of initializing EclipseGridLGR hostcells.) private: void init_father_global(); std::string father_label; From 7eed0686041847e7798d996548ed89544f1ed711 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Wed, 30 Oct 2024 12:32:57 +0000 Subject: [PATCH 53/60] EGRID of two LGR cells working --- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 15 +++++++-------- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 15 ++++++--------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index cd69825c485..e0a72b255ef 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -1901,7 +1901,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector filehead(100,0); filehead[0] = 3; // version number filehead[1] = 2007; // release year - filehead[6] = 1; // corner point grid + filehead[6] = 2; // corner point grid std::vector gridhead(100,0); gridhead[0] = 1; // corner point grid @@ -2090,9 +2090,9 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st //parse fatherLGRObjbect Indices to children propagateParentIndicesToLGRChildren(0); // initialize the LGR tree indices for each refined cell. - initializeLGRTreeIndices(); + init_lgr_cells_index(); // parse the reference indices to object in the global level. - parseGlobalReferenceToChildren(); + init_lgr_global_cells_index(); } void EclipseGrid::propagateParentIndicesToLGRChildren(int index){ @@ -2195,7 +2195,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st lgr_active_index.resize(lgr_children_cells.size(),0); } - void EclipseGrid::initializeLGRTreeIndices(){ + void EclipseGrid::init_lgr_cells_index(){ // initialize the LGR tree indices for each refined cell. auto set_map_scalar = [&](const auto& vec, const auto& value){ num_lgr_children_cells[vec] = value; @@ -2225,20 +2225,19 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st lgr_level_active_map.reserve(lgr_level_active_map.size()+1); lgr_level_active_map.insert(lgr_level_active_map.begin(),0); for (auto& lgr_cell : lgr_children_cells) { - lgr_cell.initializeLGRTreeIndices(); + lgr_cell.init_lgr_cells_index(); } } - void EclipseGrid::parseGlobalReferenceToChildren(){ + void EclipseGrid::init_lgr_global_cells_index(){ for (std::size_t index = 0; index < lgr_children_cells.size(); index++) { lgr_children_cells[index].set_lgr_global_counter(lgr_level_active_map[lgr_active_index[index]] + this->lgr_global_counter); - lgr_children_cells[index].parseGlobalReferenceToChildren(); + lgr_children_cells[index].init_lgr_global_cells_index(); } } - void EclipseGrid::resetACTNUM() { std::size_t global_size = this->getCartesianSize(); this->m_actnum.assign(global_size, 1); diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 18cfe62dfdb..12656af6459 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -315,9 +315,9 @@ namespace Opm { // Radial grids need this for volume calculations. std::optional> m_thetav; std::optional> m_rv; - void parseGlobalReferenceToChildren(void); + void init_lgr_global_cells_index(void); int initializeLGRObjectIndices(int); - void initializeLGRTreeIndices(void); + void init_lgr_cells_index(void); void propagateParentIndicesToLGRChildren(int); void updateNumericalAquiferCells(const Deck&); double computeCellGeometricDepth(size_t globalIndex) const; @@ -372,9 +372,10 @@ namespace Opm { using vec_size_t = std::vector; EclipseGridLGR() = default; EclipseGridLGR(const std::string& self_label, const std::string& father_label_, - size_t nx, size_t ny, size_t nz, - const vec_size_t& father_lgr_index, const std::array& low_fahterIJK_, - const std::array& up_fahterIJK_); + std::size_t nx, std::size_t ny, std::size_t nz, + const vec_size_t& father_lgr_index, [[maybe_unused]] const std::array& low_fahterIJK_, + [[maybe_unused]] const std::array& up_fahterIJK_); + ~EclipseGridLGR() = default; const vec_size_t& getFatherGlobalID() const; void save(Opm::EclIO::EclOutput&, const std::vector&, const Opm::UnitSystem&) const; @@ -386,11 +387,7 @@ namespace Opm { return father_global; } void set_hostnum(std::vector&); -<<<<<<< HEAD void set_lgr_refinement(const std::vector&, const std::vector &); -======= - void set_lgr_refinement(std::vector,std::vector); ->>>>>>> 9d788474a (EclipseGrid is capable of initializing EclipseGridLGR hostcells.) private: void init_father_global(); std::string father_label; From a18cbc457f41a1336d8403ccad8f65a1d7a30d55 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 21 Nov 2024 13:40:32 +0000 Subject: [PATCH 54/60] Development of the routines for exporting EGRID compartible with LGR --- tests/parser/LgrOutputTests.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/parser/LgrOutputTests.cpp b/tests/parser/LgrOutputTests.cpp index 18c27e1f3f3..6095d4927a1 100644 --- a/tests/parser/LgrOutputTests.cpp +++ b/tests/parser/LgrOutputTests.cpp @@ -109,6 +109,10 @@ SOLUTION SCHEDULE )"; +<<<<<<< HEAD +======= + +>>>>>>> bff9047a8 (Development of the routines for exporting EGRID compartible with LGR) Opm::UnitSystem units(1); std::vector vecNNC; std::array global_grid_dim = {3,3,1}; From 1cbfcc654c71ed6055c6abb5c8bc1f9a3b02c47c Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Fri, 13 Dec 2024 09:47:04 +0000 Subject: [PATCH 55/60] fixed minor performance bugs --- opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp | 9 +++++++-- opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index e0a72b255ef..d7bbbd20316 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -37,7 +37,7 @@ #include #include - +#include #include #include @@ -1901,7 +1901,7 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st std::vector filehead(100,0); filehead[0] = 3; // version number filehead[1] = 2007; // release year - filehead[6] = 2; // corner point grid + filehead[6] = 1; // corner point grid std::vector gridhead(100,0); gridhead[0] = 1; // corner point grid @@ -2459,8 +2459,13 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st namespace Opm { EclipseGridLGR::EclipseGridLGR(const std::string& self_label, const std::string& father_label_, std::size_t nx, std::size_t ny, std::size_t nz, +<<<<<<< HEAD const vec_size_t& father_lgr_index, [[maybe_unused]] const std::array& low_fahterIJK_, [[maybe_unused]] const std::array& up_fahterIJK_) +======= + vec_size_t father_lgr_index, const std::array& low_fahterIJK_, + const std::array& up_fahterIJK_) +>>>>>>> bbe293839 (fixed minor performance bugs) : EclipseGrid(nx,ny,nz), father_label(father_label_), father_global(father_lgr_index) { init_father_global(); diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp index 12656af6459..27f4d7faf1f 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -33,7 +33,7 @@ #include #include #include -#include + namespace Opm { From bf8c13c0ffd227b301d0444cf0d671a63c88e410 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Fri, 13 Dec 2024 13:07:04 +0000 Subject: [PATCH 56/60] Test Files for LgrOutputTest added and registered at CMakeLists_files --- opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp | 5 ----- tests/parser/LgrOutputTests.cpp | 4 ---- 2 files changed, 9 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index d7bbbd20316..274145e6c41 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -2459,13 +2459,8 @@ std::vector EclipseGrid::createDVector(const std::array& dims, st namespace Opm { EclipseGridLGR::EclipseGridLGR(const std::string& self_label, const std::string& father_label_, std::size_t nx, std::size_t ny, std::size_t nz, -<<<<<<< HEAD const vec_size_t& father_lgr_index, [[maybe_unused]] const std::array& low_fahterIJK_, [[maybe_unused]] const std::array& up_fahterIJK_) -======= - vec_size_t father_lgr_index, const std::array& low_fahterIJK_, - const std::array& up_fahterIJK_) ->>>>>>> bbe293839 (fixed minor performance bugs) : EclipseGrid(nx,ny,nz), father_label(father_label_), father_global(father_lgr_index) { init_father_global(); diff --git a/tests/parser/LgrOutputTests.cpp b/tests/parser/LgrOutputTests.cpp index 6095d4927a1..18c27e1f3f3 100644 --- a/tests/parser/LgrOutputTests.cpp +++ b/tests/parser/LgrOutputTests.cpp @@ -109,10 +109,6 @@ SOLUTION SCHEDULE )"; -<<<<<<< HEAD -======= - ->>>>>>> bff9047a8 (Development of the routines for exporting EGRID compartible with LGR) Opm::UnitSystem units(1); std::vector vecNNC; std::array global_grid_dim = {3,3,1}; From 5124dedd15da2cc8d7409ada9938f0fb16d100d4 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 10:17:43 +0000 Subject: [PATCH 57/60] created VectorUtil and GeometricUtil libraries converting lambda functions used in EclipseGrid::init_children_host_cells --- opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 274145e6c41..ca2db5501e7 100644 --- a/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -75,8 +75,7 @@ #include #include #include -#include -#include + #include From bce1eb41bc2c97ea8c2ec50f5093306c6c5e0d05 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 10:25:23 +0000 Subject: [PATCH 58/60] added template functions to utility libraries --- opm/common/utility/numeric/GeometryUtil.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/opm/common/utility/numeric/GeometryUtil.hpp b/opm/common/utility/numeric/GeometryUtil.hpp index 7f26f5e9157..3cda7de2f82 100644 --- a/opm/common/utility/numeric/GeometryUtil.hpp +++ b/opm/common/utility/numeric/GeometryUtil.hpp @@ -41,7 +41,11 @@ T calcHexaVol(const std::array& x, const std::array& y, const std::arr {0, 1, 3}, {1, 3, 2}, // Face 4 {4, 5, 7}, +<<<<<<< HEAD {5, 7, 6} // Face 5 +======= + {5, 7, 6} // Face 5 +>>>>>>> ee66191b4 (added template functions to utility libraries) }; auto getNodes = [](const std::array& X, const std::array& Y, const std::array& Z, const std::array& ind){ @@ -61,10 +65,17 @@ T calcHexaVol(const std::array& x, const std::array& y, const std::arr T totalVolume = 0.0; for (size_t i = 0; i < faceConfigurations.size(); i += 2) { auto [fX0, fY0, fZ0] = getNodes(x, y, z, faceConfigurations[i]); +<<<<<<< HEAD totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX0, fY0, fZ0, cx, cy, cz)); auto [fX1, fY1, fZ1] = getNodes(x, y, z, faceConfigurations[i + 1]); totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX1, fY1, fZ1, cx, cy, cz)); +======= + totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX0, fY0, fZ0, cx, cy, cz)); + + auto [fX1, fY1, fZ1] = getNodes(x, y, z, faceConfigurations[i + 1]); + totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX1, fY1, fZ1, cx, cy, cz)); +>>>>>>> ee66191b4 (added template functions to utility libraries) } return totalVolume; }; From 6f955a559e9e676b48715da416075a1a5d74ddf5 Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 11:00:39 +0000 Subject: [PATCH 59/60] fixed missing header bug --- opm/common/utility/numeric/GeometryUtil.hpp | 12 ------------ opm/common/utility/numeric/VectorUtil.hpp | 4 ++++ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/opm/common/utility/numeric/GeometryUtil.hpp b/opm/common/utility/numeric/GeometryUtil.hpp index 3cda7de2f82..2477a71d1d6 100644 --- a/opm/common/utility/numeric/GeometryUtil.hpp +++ b/opm/common/utility/numeric/GeometryUtil.hpp @@ -41,11 +41,7 @@ T calcHexaVol(const std::array& x, const std::array& y, const std::arr {0, 1, 3}, {1, 3, 2}, // Face 4 {4, 5, 7}, -<<<<<<< HEAD - {5, 7, 6} // Face 5 -======= {5, 7, 6} // Face 5 ->>>>>>> ee66191b4 (added template functions to utility libraries) }; auto getNodes = [](const std::array& X, const std::array& Y, const std::array& Z, const std::array& ind){ @@ -65,17 +61,9 @@ T calcHexaVol(const std::array& x, const std::array& y, const std::arr T totalVolume = 0.0; for (size_t i = 0; i < faceConfigurations.size(); i += 2) { auto [fX0, fY0, fZ0] = getNodes(x, y, z, faceConfigurations[i]); -<<<<<<< HEAD totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX0, fY0, fZ0, cx, cy, cz)); - auto [fX1, fY1, fZ1] = getNodes(x, y, z, faceConfigurations[i + 1]); totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX1, fY1, fZ1, cx, cy, cz)); -======= - totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX0, fY0, fZ0, cx, cy, cz)); - - auto [fX1, fY1, fZ1] = getNodes(x, y, z, faceConfigurations[i + 1]); - totalVolume += std::apply(calcTetraVol, VectorUtil::appendNode(fX1, fY1, fZ1, cx, cy, cz)); ->>>>>>> ee66191b4 (added template functions to utility libraries) } return totalVolume; }; diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp index b4bb583b04e..63ced4b65b2 100644 --- a/opm/common/utility/numeric/VectorUtil.hpp +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -11,6 +11,10 @@ namespace VectorUtil { +<<<<<<< HEAD +======= + +>>>>>>> 68c80d186 (fixed missing header bug) template std::tuple, std::array, std::array> appendNode(const std::array& X, const std::array& Y, const std::array& Z, From 6c472ed967f8168c716a447ec718867883b2912a Mon Sep 17 00:00:00 2001 From: Artur Castiel Date: Thu, 19 Dec 2024 15:01:11 +0000 Subject: [PATCH 60/60] refactor to improve template deduction --- opm/common/utility/numeric/VectorUtil.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/opm/common/utility/numeric/VectorUtil.hpp b/opm/common/utility/numeric/VectorUtil.hpp index 63ced4b65b2..b4993c10340 100644 --- a/opm/common/utility/numeric/VectorUtil.hpp +++ b/opm/common/utility/numeric/VectorUtil.hpp @@ -11,10 +11,7 @@ namespace VectorUtil { -<<<<<<< HEAD -======= ->>>>>>> 68c80d186 (fixed missing header bug) template std::tuple, std::array, std::array> appendNode(const std::array& X, const std::array& Y, const std::array& Z,