My Project
Loading...
Searching...
No Matches
LevelCartesianIndexMapper.hpp
1//===========================================================================
2//
3// File: LevelCartesianIndexMapper.hpp
4//
5// Created: Tue October 01 09:44:00 2024
6//
7// Author(s): Antonella Ritorto <antonella.ritorto@opm-op.com>
8//
9//
10// $Date$
11//
12// $Revision$
13//
14//===========================================================================
15
16/*
17 Copyright 2024 Equinor ASA.
18
19 This file is part of The Open Porous Media project (OPM).
20
21 OPM is free software: you can redistribute it and/or modify
22 it under the terms of the GNU General Public License as published by
23 the Free Software Foundation, either version 3 of the License, or
24 (at your option) any later version.
25
26 OPM is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 GNU General Public License for more details.
30
31 You should have received a copy of the GNU General Public License
32 along with OPM. If not, see <http://www.gnu.org/licenses/>.
33*/
34#ifndef OPM_CPGRIDLEVELCARTESIANINDEXMAPPER_HH
35#define OPM_CPGRIDLEVELCARTESIANINDEXMAPPER_HH
36
37#include <opm/grid/common/LevelCartesianIndexMapper.hpp>
38#include <opm/grid/CpGrid.hpp>
39
40namespace Dune
41{
42class CpGrid;
43}
44
45namespace Opm
46{
47// Interface class to access the local Cartesian grid of each level grid (when refinement).
48// Further documentation in opm/grid/common/LevelCartesianIndexMapper.hpp
49//
50// Specialization for CpGrid
51template<>
53{
54public:
55 static constexpr int dimension = 3 ;
56
57 explicit LevelCartesianIndexMapper(const Dune::CpGrid& grid) : grid_{ &grid }
58 {}
59
60 const std::array<int,3>& cartesianDimensions(int level) const
61 {
62 return grid_->currentData()[level]->logicalCartesianSize();
63 }
64
65 int cartesianSize(int level) const
66 {
67 return computeCartesianSize(level);
68 }
69
70 int compressedSize(int level) const
71 {
72 validLevel(level);
73 return grid_->currentData()[level]->size(0);
74 }
75
76 int cartesianIndex( const int compressedElementIndex, const int level) const
77 {
78 validLevel(level);
79 assert( compressedElementIndex >= 0 && compressedElementIndex < grid_->currentData()[level]->size(0) );
80 return grid_->currentData()[level]->globalCell()[compressedElementIndex];
81 }
82
83 void cartesianCoordinate(const int compressedElementIndexOnLevel, std::array<int,dimension>& coordsOnLevel, int level) const
84 {
85 validLevel(level);
86 grid_->currentData()[level]->getIJK( compressedElementIndexOnLevel, coordsOnLevel);
87 }
88
89private:
90 const Dune::CpGrid* grid_;
91
92 int computeCartesianSize(int level) const
93 {
94 int size = cartesianDimensions(level)[ 0 ];
95 for( int d=1; d<dimension; ++d )
96 size *= cartesianDimensions(level)[ d ];
97 return size;
98 }
99
100 void validLevel(int level) const
101 {
102 if ((level < 0) || (level > grid_->maxLevel())) {
103 throw std::invalid_argument("Invalid level.\n");
104 }
105 }
106};
107
108}
109
110#endif
[ provides Dune::Grid ]
Definition CpGrid.hpp:198
const std::vector< std::shared_ptr< Dune::cpgrid::CpGridData > > & currentData() const
Returns either data_ or distributed_data_(if non empty).
Definition CpGrid.cpp:662
int maxLevel() const
Return maximum level defined in this grid. Levels are 0 and 1, maxlevel = 1 (not counting leafview),...
Definition CpGrid.cpp:764
Definition LevelCartesianIndexMapper.hpp:45
The namespace Dune is the main namespace for all Dune code.
Definition CartesianIndexMapper.hpp:10
Holds the implementation of the CpGrid as a pimple.
Definition CellQuadrature.cpp:68