Skip to content

Commit

Permalink
Add test case from PR4255 and 'translate it into CpGrid'
Browse files Browse the repository at this point in the history
  • Loading branch information
aritorto committed Nov 5, 2024
1 parent 82b62ba commit bf6bd6a
Showing 1 changed file with 236 additions and 8 deletions.
244 changes: 236 additions & 8 deletions tests/cpgrid/coord_zcorn_lgr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand All @@ -111,8 +110,7 @@ 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& 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);
Expand Down Expand Up @@ -254,14 +252,14 @@ BOOST_AUTO_TEST_CASE(inactiveCells_in_lgrs)

Opm::Parser parser;
const auto deck = parser.parseString(deckString);
Opm::EclipseState es(deck);
Opm::EclipseState ecl_state(deck);

Dune::CpGrid grid;
grid.processEclipseFormat(&es.getInputGrid(), &es, false, false, false); // CARFIN ignore!
grid.processEclipseFormat(&ecl_state.getInputGrid(), &ecl_state, false, false, false); // CARFIN ignore!

Dune::CpGrid lgr1_grid;
Opm::LgrCollection lgrs = es.getLgrs();
const auto& lgr1 = es.getLgrs().getLgr("LGR1");
Opm::LgrCollection lgrs = ecl_state.getLgrs();
const auto& lgr1 = ecl_state.getLgrs().getLgr("LGR1");
BOOST_CHECK_EQUAL(lgr1.NAME(), "LGR1");


Expand All @@ -275,3 +273,233 @@ BOOST_AUTO_TEST_CASE(inactiveCells_in_lgrs)

checkGlobalCellLgr(grid);
}


BOOST_AUTO_TEST_CASE(TestLgrNeighbor) {

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
CARFIN
-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ
'LGR2' 2 2 1 1 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
The title
START
16 JUN 1988 /
PROPS
REGIONS
SOLUTION
SCHEDULE
)";

Opm::Parser parser;
const auto deck = parser.parseString(deck_string);
Opm::EclipseState ecl_state(deck);
Opm::EclipseGrid eclipse_grid = ecl_state.getInputGrid();

Dune::CpGrid grid;
grid.processEclipseFormat(&eclipse_grid, &ecl_state, false, false, false); // CARFIN ignore!

// "Translation from CARFIN block to CpGrid"
// CARFIN
// -- NAME I1-I2 J1-J2 K1-K2 NX NY NZ
// 'LGR1' 2 2 2 2 1 1 3 3 /
// ENDFIN
//
// CpGrid:
// Each parent cell from LGR1-block-to-be-refined will be refined into 3x3x1 child cells in each direction x-,y-,
// and z- respect.
// Block of parent cells for LGR1 starts at {1,1,0} 'ijk' from the global CpGrid (or {2,2,1} in
// deck).
// Block of parent cells for LGR1 ends at {2,2,1} 'ijk' from the global CpGrid (or {2,2,1} in deck).
// Block of parent cell global indices for LGR1 = {4}
// LGR1 dim = {3,3,1} refined cells in each direction. (Block of parent cells dim = {1,1,1} - only one parent cell).

// "Translation from CARFIN block to CpGrid"
// CARFIN
//-- NAME I1-I2 J1-J2 K1-K2 NX NY NZ
//'LGR2' 2 2 1 1 1 1 3 3 /
//ENDFIN
//
// CpGrid:
// Each parent cell from LGR2-block-to-be-refined will be refined into 3x3x1 child cells in each direction x-,y-,
// and z- respect.
// Block of parent cells for LGR2 starts at {1,0,0} 'ijk' from the global CpGrid (or {2,2,1} in
// deck).
// Block of parent cells for LGR2 ends at {2,1,1} 'ijk' from the global CpGrid (or {2,1,1} in deck).
// Block of parent cell glboal indices for LGR2 = {1}
// LGR2 dim = {3,3,1} refined cells in each direction. (Block of parent cells dim = {1,1,1} - only one parent cell).

const std::vector<std::array<int,3>> cells_per_dim_vec = {{3,3,1}, {3,3,1}};
const std::vector<std::array<int,3>> startIJK_vec = {{1,1,0}, {1,0,0}};
const std::vector<std::array<int,3>> endIJK_vec = {{2,2,1}, {2,1,1}};
// LGR1 parent cell indices = {4}, LGR2 parent cell indices = {1}.
const std::vector<std::string> 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<Dune::CpGrid> 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<int,3> 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<int,3> 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<int,3> 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<int,3> 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<int,3> 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);

}

0 comments on commit bf6bd6a

Please sign in to comment.