Skip to content

Commit

Permalink
Take into account inactive cells, change name local->lgrIjk, add test…
Browse files Browse the repository at this point in the history
… lgr with inac cell
  • Loading branch information
aritorto committed Feb 3, 2025
1 parent 5b01e0a commit 789e2ae
Show file tree
Hide file tree
Showing 5 changed files with 625 additions and 390 deletions.
2 changes: 1 addition & 1 deletion CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ if(Boost_VERSION_STRING VERSION_GREATER 1.53)
tests/cpgrid/grid_lgr_test.cpp
tests/cpgrid/inactiveCell_lgr_test.cpp
tests/cpgrid/lgr_cartesian_idx_test.cpp
tests/cpgrid/localIJK_test.cpp
tests/cpgrid/lgrIJK_test.cpp
tests/cpgrid/lookUpCellCentroid_cpgrid_test.cpp
tests/cpgrid/lookupdataCpGrid_test.cpp
tests/cpgrid/replace_lgr1_corner_idx_by_lgr2_corner_idx_test.cpp
Expand Down
40 changes: 28 additions & 12 deletions opm/grid/cpgrid/CpGridUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace Opm {

std::vector<std::array<int,3>> localIJK(const Dune::CpGrid& grid, const std::string& lgr_name)
std::vector<std::array<int,3>> lgrIJK(const Dune::CpGrid& grid, const std::string& lgr_name)
{
// Check lgr_name exists in lgr_names_
const auto& lgr_names = grid.getLgrNameToLevel();
Expand All @@ -35,23 +35,39 @@ std::vector<std::array<int,3>> localIJK(const Dune::CpGrid& grid, const std::str
OPM_THROW(std::runtime_error, "LGR name not found: " + lgr_name);
}

const Opm::LevelCartesianIndexMapper<Dune::CpGrid> levelCartMapp(grid);
const Opm::LevelCartesianIndexMapper<Dune::CpGrid> levelCartMapper(grid);
const auto& level = it->second;

std::vector<std::array<int, 3>> localIJK;
localIJK.resize(grid.levelGridView(level).size(0));
// Determine the logical Cartesian size of the LGR and total cells (including inactive ones)
const auto lgr_dim = grid.currentData()[level]->logicalCartesianSize();
const int lgr_cells = lgr_dim[0] * lgr_dim[1] * lgr_dim[2]; // (including inactive ones)
// Actual size is given by grid.levelGridView(level).size(0)

// To be improved
const auto& leaf_to_lgr_idx = grid.mapLeafIndexSetToLocalCartesianIndexSets();
// Initialize level IJKs with inactive values
static constexpr std::array<int, 3> inactiveIJK = { -1, -1, -1 };
std::vector<std::array<int, 3>> lgrIJK(lgr_cells);
lgrIJK.assign(lgr_cells, inactiveIJK); // Ensures all elements are set to inactive

// Iterate over active elements in the grid. Rewrite ijks at the specified refined level active cells.
//
// Note: to avoid go over all the leaf elements and replace this approach with the
// corresponding grid.levelGridView(level), a map relating level_to_lgr_idx is needed.
for (const auto& element : Dune::elements(grid.leafGridView())) {
if (element.level() == level)
{
std::array<int, 3> local_ijk;
levelCartMapp.cartesianCoordinate( element.getLevelElem().index(), local_ijk, level);
localIJK[ leaf_to_lgr_idx[element.index()][1] ] = local_ijk;
if (element.level() != level) {
continue;
}

std::array<int, 3> ijk;
levelCartMapper.cartesianCoordinate(element.getLevelElem().index(), ijk, level);
// In general, element.getLevelElem().index() != element.getLevelCartesianIdx().
// - element.getLevelElem().index() : integer between 0 and "total active cells - 1" on the level grid.
// - element.getLevelCartesianIdx() : integer between 0 and "lgr_cells - 1", representing an index of
// the underlying Cartesian grid for the level (with/without INACTIVE cells).

const int lgr_cart_index = element.getLevelCartesianIdx();
lgrIJK[lgr_cart_index] = ijk;
}
return localIJK;
return lgrIJK;
}

}
8 changes: 5 additions & 3 deletions opm/grid/cpgrid/CpGridUtilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
namespace Opm
{

/// @brief Retrieves the local IJKs of cells within a specified LGR.
/// @brief Retrieves the local grid refinement (LGR) IJKs of cells.
///
/// This method returns a vector of IJK indices corresponding to underlying Cartesian grid of the local
/// grid refinement (LGR) specified by its name. If the specified LGR name is not found, it throws.
/// grid refinement (LGR) specified by its name. If the specified name is not found, an exception is thrown.
/// For inactive cells—i.e., non-existing child cells of inactive coarse cells defined by the CARFIN keyword—
/// the corresponding IJK index is set to {-1, -1, -1}.
///
/// @param lgr_name The name of the LGR whose local IJK coordinates are requested.
/// @return std::vector<std::array<int, 3>> A list of (i, j, k)'s for each cell in the LGR.
std::vector<std::array<int,3>> localIJK(const Dune::CpGrid& grid, const std::string& lgr_name);
std::vector<std::array<int,3>> lgrIJK(const Dune::CpGrid& grid, const std::string& lgr_name);

}

Expand Down
Loading

0 comments on commit 789e2ae

Please sign in to comment.