Skip to content

Commit

Permalink
Free localIJK in CpGridUtilities (new) header
Browse files Browse the repository at this point in the history
  • Loading branch information
aritorto committed Jan 30, 2025
1 parent c116617 commit 57114b2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 40 deletions.
2 changes: 2 additions & 0 deletions CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ list (APPEND MAIN_SOURCE_FILES
opm/grid/cpgrid/Iterators.cpp
opm/grid/cpgrid/Indexsets.cpp
opm/grid/cpgrid/PartitionTypeIndicator.cpp
opm/grid/cpgrid/CpGridUtilities.cpp
opm/grid/cpgrid/processEclipseFormat.cpp
opm/grid/common/GeometryHelpers.cpp
opm/grid/common/GridPartitioning.cpp
Expand Down Expand Up @@ -191,6 +192,7 @@ list (APPEND PUBLIC_HEADER_FILES
opm/grid/cpgrid/CartesianIndexMapper.hpp
opm/grid/cpgrid/CpGridData.hpp
opm/grid/cpgrid/CpGridDataTraits.hpp
opm/grid/cpgrid/CpGridUtilities.hpp
opm/grid/cpgrid/DataHandleWrappers.hpp
opm/grid/cpgrid/DefaultGeometryPolicy.hpp
opm/grid/cpgrid/dgfparser.hh
Expand Down
9 changes: 0 additions & 9 deletions opm/grid/CpGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,15 +1194,6 @@ namespace Dune
/// @brief Reverse map: from leaf index cell to { level, local/level Cartesian index of the cell }
std::vector<std::array<int,2>> mapLeafIndexSetToLocalCartesianIndexSets() const;

/// @brief Retrieves the local IJKs of cells within a specified LGR.
///
/// 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.
///
/// @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 std::string& lgr_name) const;

/// \brief Size of the overlap on the leaf level
unsigned int overlapSize(int) const;

Expand Down
25 changes: 0 additions & 25 deletions opm/grid/cpgrid/CpGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
#include "ParentToChildCellToPointGlobalIdHandle.hpp"
#include <opm/grid/common/MetisPartition.hpp>
#include <opm/grid/common/ZoltanPartition.hpp>
#include <opm/grid/cpgrid/LevelCartesianIndexMapper.hpp>
#include <opm/grid/GraphOfGridWrappers.hpp>
//#include <opm/grid/common/ZoltanGraphFunctions.hpp>
#include <opm/grid/common/GridPartitioning.hpp>
Expand Down Expand Up @@ -714,30 +713,6 @@ std::vector<std::array<int,2>> CpGrid::mapLeafIndexSetToLocalCartesianIndexSets(
return leafIdx_to_localCartesianIdxSets;
}

std::vector<std::array<int,3>> CpGrid::localIJK(const std::string& lgr_name) const
{
// Check lgr_name exists in lgr_names_
auto it = lgr_names_.find(lgr_name);
if (it == lgr_names_.end()) {
OPM_THROW(std::runtime_error, "LGR name not found: " + lgr_name);
}

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

std::vector<std::array<int, 3>> localIJK;
localIJK.reserve(levelGridView(level).size(0));

for (const auto& element : elements(levelGridView(level))) {
std::array<int, 3> local_ijk;
levelCartMapp.cartesianCoordinate(element.index(), local_ijk, level);
localIJK.emplace_back(local_ijk);
}

return localIJK;
}


void CpGrid::getIJK(const int c, std::array<int,3>& ijk) const
{
current_view_data_->getIJK(c, ijk);
Expand Down
10 changes: 4 additions & 6 deletions tests/cpgrid/localIJK_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@
#endif


#include <opm/grid/CpGrid.hpp>
#include <opm/grid/cpgrid/CpGridUtilities.hpp>

#include <dune/common/version.hh>
#include <dune/grid/common/mcmgmapper.hh>
#include <opm/input/eclipse/Deck/Deck.hpp>
#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
#include <opm/input/eclipse/Parser/Parser.hpp>
//#include <opm/input/eclipse/EclipseState/Grid/LgrCollection.hpp>
//#include <opm/input/eclipse/EclipseState/Grid/Carfin.hpp>

#include <array>
#include <stdexcept>
Expand Down Expand Up @@ -147,8 +145,8 @@ BOOST_AUTO_TEST_CASE(localIJK_in_allActiveCellLGRs)
const int lgr2_level = lgr_name_to_level.at("LGR2");

// Get vector of local ijk for each LGR
std::vector<std::array<int, 3>> ijk_lgr1 = grid.localIJK("LGR1");
std::vector<std::array<int, 3>> ijk_lgr2 = grid.localIJK("LGR2");
std::vector<std::array<int, 3>> ijk_lgr1 = Opm::localIJK(grid, "LGR1");
std::vector<std::array<int, 3>> ijk_lgr2 = Opm::localIJK(grid, "LGR2");

// Ensure it's not empty
BOOST_TEST(!ijk_lgr1.empty()); // 2 active parent cell refined into 2x2x2 refined cells
Expand All @@ -170,7 +168,7 @@ BOOST_AUTO_TEST_CASE(localIJK_in_allActiveCellLGRs)
}

// Invalid LGR should throw an exception
BOOST_CHECK_THROW(grid.localIJK("LGR3DOESNOTEXIST"), std::runtime_error);
BOOST_CHECK_THROW(Opm::localIJK(grid, "LGR3DOESNOTEXIST"), std::runtime_error);

// LGR1 Dimension: 2x2x4 (Width x Height x Depth)
// Visual representation of local cell indices per k-layer:
Expand Down

0 comments on commit 57114b2

Please sign in to comment.