//=========================================================================== // // File: AluGridLevelCartesianIndexMapper.hpp // // Created: Tue October 01 09:44:00 2024 // // Author(s): Antonella Ritorto // // // $Date$ // // $Revision$ // //=========================================================================== /* Copyright 2024 Equinor ASA. This file is part of The Open Porous Media project (OPM). OPM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OPM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OPM. If not, see . */ #ifndef OPM_ALUGRIDLEVELCARTESIANINDEXMAPPER_HPP #define OPM_ALUGRIDLEVELCARTESIANINDEXMAPPER_HPP #include #include #include #include #include namespace Opm { template<> class LevelCartesianIndexMapper> { #if HAVE_MPI using Grid = Dune::ALUGrid<3, 3, Dune::cube, Dune::nonconforming, Dune::ALUGridMPIComm>; #else using Grid = Dune::ALUGrid<3, 3, Dune::cube, Dune::nonconforming, Dune::ALUGridNoComm>; #endif //HAVE_MPI public: static constexpr int dimension = 3 ; LevelCartesianIndexMapper(const Grid& grid, const Dune::CartesianIndexMapper& cartesianIndexMapper) : grid_{&grid} , cartesianIndexMapper_{std::make_unique>(cartesianIndexMapper)} {} const std::array& cartesianDimensions(int level) const { throwIfLevelPositive(level); return cartesianIndexMapper_ ->cartesianDimensions(); } int cartesianSize(int level) const { throwIfLevelPositive(level); return cartesianIndexMapper_->cartesianSize(); } int compressedSize(int level) const { throwIfLevelPositive(level); return cartesianIndexMapper_-> compressedSize(); } int cartesianIndex( const int compressedElementIndex, const int level) const { throwIfLevelPositive(level);; return cartesianIndexMapper_->cartesianIndex(compressedElementIndex); } void cartesianCoordinate(const int compressedElementIndex, std::array& coords, int level) const { throwIfLevelPositive(level); cartesianIndexMapper_->cartesianCoordinate(compressedElementIndex, coords); } private: [[maybe_unused]] const Grid* grid_; std::unique_ptr> cartesianIndexMapper_; void throwIfLevelPositive(int level) const { if (level) { throw std::invalid_argument("Invalid level.\n"); } } }; } #endif