cartesianindexmapper.hh
Go to the documentation of this file.
1#ifndef OPM_POLYHEDRALCARTESIANINDEXMAPPER_HEADER
2#define OPM_POLYHEDRALCARTESIANINDEXMAPPER_HEADER
3
6
7namespace Dune
8{
9 template< int dim, int dimworld, typename coord_t >
10 class CartesianIndexMapper< PolyhedralGrid< dim, dimworld, coord_t > >
11 {
13
14 const Grid& grid_;
15 const int cartesianSize_;
16
17 int computeCartesianSize() const
18 {
19 int size = cartesianDimensions()[ 0 ];
20 for( int d=1; d<dim; ++d )
21 size *= cartesianDimensions()[ d ];
22 return size ;
23 }
24 public:
25 static const int dimension = Grid :: dimension ;
26
27 explicit CartesianIndexMapper( const Grid& grid )
28 : grid_( grid ),
29 cartesianSize_( computeCartesianSize() )
30 {}
31
32 const std::array<int, dimension>& cartesianDimensions() const
33 {
34 return grid_.logicalCartesianSize();
35 }
36
37 int cartesianSize() const
38 {
39 return cartesianSize_;
40 }
41
42 int compressedSize() const
43 {
44 return grid_.size( 0 );
45 }
46
47 // Only for unifying calls with CartesianIndexMapper<CpGrid> where levels are relevant.
49 {
50 return grid_.size( 0 );
51 }
52
53 int cartesianIndex( const int compressedElementIndex ) const
54 {
55 assert( compressedElementIndex >= 0 && compressedElementIndex < compressedSize() );
56 return grid_.globalCell()[ compressedElementIndex ];
57 }
58
59 void cartesianCoordinate(const int compressedElementIndex, std::array<int,dimension>& coords) const
60 {
61 int gc = cartesianIndex( compressedElementIndex );
62 if( dimension >=2 )
63 {
64 for( int d=0; d<dimension-2; ++d )
65 {
66 coords[d] = gc % cartesianDimensions()[d]; gc /= cartesianDimensions()[d];
67 }
68
69 coords[dimension-2] = gc % cartesianDimensions()[dimension-2];
70 coords[dimension-1] = gc / cartesianDimensions()[dimension-1];
71 }
72 else
73 coords[ 0 ] = gc ;
74 }
75
76 // Only for unifying calls with CartesianIndexMapper<CpGrid> where levels are relevant.
77 void cartesianCoordinateLevel(const int compressedElementIndexOnLevel, std::array<int,dimension>& coordsOnLevel, int level) const
78 {
79 if (level) {
80 throw std::invalid_argument("Invalid level.\n");
81 }
82 cartesianCoordinate(compressedElementIndexOnLevel, coordsOnLevel);
83 }
84 };
85
86} // end namespace Opm
87#endif
int cartesianSize() const
Definition: cartesianindexmapper.hh:37
int compressedSize() const
Definition: cartesianindexmapper.hh:42
CartesianIndexMapper(const Grid &grid)
Definition: cartesianindexmapper.hh:27
int cartesianIndex(const int compressedElementIndex) const
Definition: cartesianindexmapper.hh:53
void cartesianCoordinate(const int compressedElementIndex, std::array< int, dimension > &coords) const
Definition: cartesianindexmapper.hh:59
int compressedLevelZeroSize() const
Definition: cartesianindexmapper.hh:48
const std::array< int, dimension > & cartesianDimensions() const
Definition: cartesianindexmapper.hh:32
void cartesianCoordinateLevel(const int compressedElementIndexOnLevel, std::array< int, dimension > &coordsOnLevel, int level) const
Definition: cartesianindexmapper.hh:77
Interface class to access the logical Cartesian grid as used in industry standard simulator decks.
Definition: common/CartesianIndexMapper.hpp:16
int cartesianIndex(const int) const
return index of the cells in the logical Cartesian grid
Definition: common/CartesianIndexMapper.hpp:53
int compressedSize() const
return number of cells in the active grid
Definition: common/CartesianIndexMapper.hpp:41
const std::array< int, dimension > & cartesianDimensions() const
return Cartesian dimensions, i.e. number of cells in each direction
Definition: common/CartesianIndexMapper.hpp:28
static const int dimension
dimension of the grid
Definition: common/CartesianIndexMapper.hpp:19
void cartesianCoordinate(const int, std::array< int, dimension > &) const
return Cartesian coordinate, i.e. IJK, for a given cell
Definition: common/CartesianIndexMapper.hpp:59
identical grid wrapper
Definition: grid.hh:159
int size(int, int codim) const
obtain number of entites on a level
Definition: grid.hh:427
const std::array< int, 3 > & logicalCartesianSize() const
Definition: grid.hh:844
const int * globalCell() const
Definition: grid.hh:849
The namespace Dune is the main namespace for all Dune code.
Definition: common/CartesianIndexMapper.hpp:10