From 8716bc5c4189ede407d1ae1809387b29766fcea4 Mon Sep 17 00:00:00 2001 From: Antonella Ritorto Date: Tue, 5 Nov 2024 16:56:22 +0100 Subject: [PATCH] Add test case from PR4255 and 'translate it into CpGrid' --- tests/cpgrid/coord_zcorn_lgr_test.cpp | 269 ++++++++++++++++++++++++-- 1 file changed, 256 insertions(+), 13 deletions(-) diff --git a/tests/cpgrid/coord_zcorn_lgr_test.cpp b/tests/cpgrid/coord_zcorn_lgr_test.cpp index f1f3fc903..f6d448b05 100644 --- a/tests/cpgrid/coord_zcorn_lgr_test.cpp +++ b/tests/cpgrid/coord_zcorn_lgr_test.cpp @@ -98,8 +98,7 @@ checkGlobalCellLgr(Dune::CpGrid& grid) // belongs to a refined level grid). This default Cartesian Index for leaf cells coincide with the globalCell // values. const auto& cartesian_idx_from_leaf_elem = mapper.cartesianIndex(element.index()); - const auto& global_cell_idx_leaf - = grid.globalCell()[element.index()]; // parent cell index when the cell is a refined one. + const auto& global_cell_idx_leaf = grid.globalCell()[element.index()]; // parent cell index when the cell is a refined one. BOOST_CHECK_EQUAL(cartesian_idx_from_leaf_elem, global_cell_idx_leaf); // global_ijk represents the ijk values of the equivalent cell on the level zero, or parent cell if the leaf // cell is a refined one. Notice that all the refined cells of a same parent cell will get the same global_cell_ @@ -111,10 +110,8 @@ checkGlobalCellLgr(Dune::CpGrid& grid) // Each LGR can be seen as a Cartesian Grid itself, with its own (local) logical_cartesian_size and its own // (local) Cartesian indices. Given a leaf cell, via the CartesianIndexMapper and its method // cartesianIndexLevel(...), we get the local-Cartesian-index. - const auto& cartesian_idx_from_level_elem - = levelCartMapp.cartesianIndex(element.getEquivLevelElem().index(), element.level()); - const auto& global_cell_idx_level - = grid.currentData()[element.level()]->globalCell()[element.getEquivLevelElem().index()]; + const auto& cartesian_idx_from_level_elem = levelCartMapp.cartesianIndex(element.getEquivLevelElem().index(), element.level()); + const auto& global_cell_idx_level = grid.currentData()[element.level()]->globalCell()[element.getEquivLevelElem().index()]; BOOST_CHECK_EQUAL(cartesian_idx_from_level_elem, global_cell_idx_level); // local_ijk represents the ijk values of the equivalent cell on the level its was born. std::array local_ijk = {0, 0, 0}; @@ -154,14 +151,17 @@ checkGlobalCellLgr(Dune::CpGrid& grid) // lines are entered with I cycling fastest then J. // // For each LGR, we collect the coordinates of the vertices. Attention: pillar ordering not guaranteed. + std::cout<< " Point local index and xyz values for points of refined level grids " <> xyz_coord(grid.currentData()[level]->size(3)); // NOT ORDERED IN A 'PILLAR' WAY for(const auto& point : vertices(grid.levelGridView(level))) { for(int i = 0; i<3; ++i) { xyz_coord[point.index()][i] = point.geometry().center()[i]; } - std::cout<< "level: " << level << " x: " << xyz_coord[point.index()][0] << " y: "<< xyz_coord[point.index()][1] << " z: "<< xyz_coord[point.index()][2] << std::endl; + std::cout<< "level: " << level << " point local index:" << point.index()<< + " x: " << xyz_coord[point.index()][0] << " y: "<< xyz_coord[point.index()][1] << " z: "<< xyz_coord[point.index()][2] << std::endl; + std::cout<>> xyz_for_zcorn(grid.currentData()[level]->size(0)); // size total amount of cells in the level refined grid. for (const auto& element : elements(grid.levelGridView(level))) { xyz_for_zcorn[element.index()].reserve(8); @@ -185,11 +188,21 @@ checkGlobalCellLgr(Dune::CpGrid& grid) std::array xyz = {0., 0., 0.}; for(int i = 0; i<3; ++i) { xyz[i] = point.geometry().center()[i]; - std::cout<< "level: " << level << " x: " << xyz[0] << " y: "<< xyz[1] << " z: "<< xyz[2] << std::endl; } + // Global element index (index of the equivalent element on the leaf grid view). + const auto& global_cell_idx_leaf = grid.globalCell()[element.index()]; + // Local element index is computeed by element.index() + // Local-ijk represents the Cartesian index with respect to the LGR. + std::array local_ijk = {0, 0, 0}; + levelCartMapp.cartesianCoordinate(element.index(), local_ijk, level); + std::cout<< "level: " << level << " element global index: "<< global_cell_idx_leaf << " element local index: " << element.index() + << " local ijk-index: " << local_ijk[0] << " " << local_ijk[1] << " " << local_ijk[2] << " " + << " x: " << xyz[0] << " y: "<< xyz[1] << " z: "<< xyz[2] << std::endl; xyz_for_zcorn[element.index()].push_back(xyz); } + std::cout<> cells_per_dim_vec = {{3,3,1}, {3,3,1}}; + const std::vector> startIJK_vec = {{1,1,0}, {1,0,0}}; + const std::vector> endIJK_vec = {{2,2,1}, {2,1,1}}; + // LGR1 parent cell indices = {4}, LGR2 parent cell indices = {1}. + const std::vector lgr_name_vec = {"LGR1", "LGR2"}; + + grid.addLgrsUpdateLeafView(cells_per_dim_vec, startIJK_vec, endIJK_vec, lgr_name_vec); + + // BOOST_CHECK_EQUAL( eclipse_grid.getTotalActiveLGR() , 25U ); + // CpGrid equivalent check: + BOOST_CHECK_EQUAL( grid.leafGridView().size(0), 25 ); + + // Similar to CartesianIndexMapper but suitable for Level Grids + const Opm::LevelCartesianIndexMapper levelCartMapp(grid); + + // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 9U ); + // CpGrid equivalent check: + BOOST_CHECK_EQUAL(grid.levelGridView(1).size(0), 9); + BOOST_CHECK_EQUAL( levelCartMapp.compressedSize(1/*level LGR1*/), 9); + + // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[1].getTotalActiveLGR() , 9U ); + // CpGrid equivalent check: + BOOST_CHECK_EQUAL(grid.levelGridView(1).size(0), 9); + BOOST_CHECK_EQUAL( levelCartMapp.compressedSize(2/*level LGR2*/), 9); + + // To get the level of an LGR: + // 1. Get the map with all lgr names, including "GLOBAL". It maps std::string lgr_name to the (int) level_grid_idx. + const auto& lgr_name_to_level = grid.getLgrNameToLevel(); + // 2. Get the level_grid_idx of "LGR1" and "LGR2" grids. + const auto& lgr1_level_index = lgr_name_to_level.at("LGR1"); + const auto& lgr2_level_index = lgr_name_to_level.at("LGR2"); + // Rewrite the checks using previous indices: + BOOST_CHECK_EQUAL( grid.levelGridView( lgr1_level_index ).size(0), 9); // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 9U ); + BOOST_CHECK_EQUAL( levelCartMapp.compressedSize( lgr1_level_index ), 9); // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[0].getTotalActiveLGR() , 9U ); + BOOST_CHECK_EQUAL( grid.levelGridView( lgr2_level_index ).size(0), 9); // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[1].getTotalActiveLGR() , 9U ); + BOOST_CHECK_EQUAL( levelCartMapp.compressedSize( lgr2_level_index ), 9); // BOOST_CHECK_EQUAL( eclipse_grid.lgr_children_cells[1].getTotalActiveLGR() , 9U ); + + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0,0,0), 0U); + // CpGrid equivalent check: + // Get the level_grid_idx of "GLOBAL" grid. + const auto& global_grid_level_index = lgr_name_to_level.at("GLOBAL"); + // + // (A) "getActiveIndexLGR("GLOBAL",0,0,0)" is equivalent to global_cell_level: + const auto& global_cell_level = grid.currentData()[ 0 /*level*/]->globalCell()[0 /*element.index()*/]; + BOOST_CHECK_EQUAL( global_cell_level, 0 ); // equivalent to BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0,0,0), 0U); + // + // (B) "getActiveIndexLGR("GLOBAL",0,0,0)" is equivalent to: + const auto& localCartesianIdxSets_to_leafIdx = grid.mapLocalCartesianIndexSetsToLeafIndexSet(); + + const auto& leaf_idx = localCartesianIdxSets_to_leafIdx[ global_grid_level_index /*level*/].at(global_cell_level); + BOOST_CHECK_EQUAL( leaf_idx, 0); // equivalent to BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",0,0,0), 0U); + + // Map from leaf grid view cell indices to locel cartesian index set. + // leaf_cell_index -> {level where the cell was born, cell index in that level } + const auto& leafIdx_to_localCartesianIdxSets = grid.mapLeafIndexSetToLocalCartesianIndexSets(); + + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("GLOBAL",2,2,0), 24U); + // CpGrid equivalent check: + // 1. Get the local index of leaf grid view cell with index 24 + const auto& local_index_of_leaf_cell_24 = leafIdx_to_localCartesianIdxSets[24]; // {level of the LGR, local index of the equivalent cell in that level} + // 2. Get level of "GLOBAL" grid (It's zero). -> global_grid_level_index + // Check levels coincide: + BOOST_CHECK_EQUAL(local_index_of_leaf_cell_24[0], global_grid_level_index ); + // 3. Get the ijk of the local_index_of_leaf_cell_24 + std::array local_ijk_of_leaf_cell_24; + levelCartMapp.cartesianCoordinate(local_index_of_leaf_cell_24[1] /*local index*/, local_ijk_of_leaf_cell_24, global_grid_level_index /*level*/ ); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_24[0], 2); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_24[1], 2); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_24[2], 0); + + + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",0,0,0), 12U); + // CpGrid equivalent check: + // 1. Get the local index of leaf grid view cell with index 12 + const auto& local_index_of_leaf_cell_12 = leafIdx_to_localCartesianIdxSets[12]; // {level of the LGR, local index of the equivalent cell in that level} + // 2. Get level of "LGR1" grid -> lgr1_level_index + // Check levels coincide: + BOOST_CHECK_EQUAL(local_index_of_leaf_cell_12[0], lgr1_level_index ); + // 3. Get the ijk of the local_index_of_leaf_cell_12 + std::array local_ijk_of_leaf_cell_12; + levelCartMapp.cartesianCoordinate(local_index_of_leaf_cell_12[1] /*local index*/, local_ijk_of_leaf_cell_12, lgr1_level_index /*level*/ ); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_12[0], 0); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_12[1], 0); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_12[2], 0); + + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR1",2,2,0), 20U); + // CpGrid equivalent check: + // 1. Get the local index of leaf grid view cell with index 20 + const auto& local_index_of_leaf_cell_20 = leafIdx_to_localCartesianIdxSets[20]; // {level of the LGR, local index of the equivalent cell in that level} + // 2. Get level of "LGR1" grid -> lgr1_level_index + // Check levels coincide: + BOOST_CHECK_EQUAL(local_index_of_leaf_cell_20[0], lgr1_level_index ); + // 3. Get the ijk of the local_index_of_leaf_cell_20 + std::array local_ijk_of_leaf_cell_20; + levelCartMapp.cartesianCoordinate(local_index_of_leaf_cell_20[1] /*local index*/, local_ijk_of_leaf_cell_20, lgr1_level_index /*level*/ ); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_20[0], 2); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_20[1], 2); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_20[2], 0); + + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",0,0,0), 1U); + // CpGrid equivalent check: + // 1. Get the local index of leaf grid view cell with index 12 + const auto& local_index_of_leaf_cell_1 = leafIdx_to_localCartesianIdxSets[1]; // {level of the LGR, local index of the equivalent cell in that level} + // 2. Get level of "LGR2" grid -> lgr2_level_index + // Check levels coincide: + BOOST_CHECK_EQUAL(local_index_of_leaf_cell_1[0], lgr2_level_index ); + // 3. Get the ijk of the local_index_of_leaf_cell_1 + std::array local_ijk_of_leaf_cell_1; + levelCartMapp.cartesianCoordinate(local_index_of_leaf_cell_1[1] /*local index*/, local_ijk_of_leaf_cell_1, lgr2_level_index /*level*/ ); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_1[0], 0); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_1[1], 0); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_1[2], 0); + + // BOOST_CHECK_EQUAL(eclipse_grid.getActiveIndexLGR("LGR2",2,2,0), 9U); + // CpGrid equivalent check: + // 1. Get the local index of leaf grid view cell with index 9 + const auto& local_index_of_leaf_cell_9 = leafIdx_to_localCartesianIdxSets[9]; // {level of the LGR, local index of the equivalent cell in that level} + // 2. Get level of "LGR2" grid -> lgr2_level_index + // Check levels coincide: + BOOST_CHECK_EQUAL(local_index_of_leaf_cell_9[0], lgr2_level_index ); + // 3. Get the ijk of the local_index_of_leaf_cell_9 + std::array local_ijk_of_leaf_cell_9; + levelCartMapp.cartesianCoordinate(local_index_of_leaf_cell_9[1] /*local index*/, local_ijk_of_leaf_cell_9, lgr2_level_index /*level*/ ); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_9[0], 2); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_9[1], 2); + BOOST_CHECK_EQUAL( local_ijk_of_leaf_cell_9[2], 0); + +}