My Project
CartesianIndexMapper.hpp
1#ifndef OPM_CPGRIDCARTESIANINDEXMAPPER_HEADER
2#define OPM_CPGRIDCARTESIANINDEXMAPPER_HEADER
3
4#include <array>
5#include <cassert>
6
7#include <opm/grid/common/CartesianIndexMapper.hpp>
8#include <opm/grid/CpGrid.hpp>
9
10namespace Dune
11{
12 template<>
14 {
15 public:
16 static const int dimension = 3 ;
17 protected:
18 typedef CpGrid Grid;
19 const Grid& grid_;
20 const int cartesianSize_;
21
22 int computeCartesianSize() const
23 {
24 int size = cartesianDimensions()[ 0 ];
25 for( int d=1; d<dimension; ++d )
26 size *= cartesianDimensions()[ d ];
27 return size ;
28 }
29
30 public:
31 explicit CartesianIndexMapper( const Grid& grid )
32 : grid_( grid ),
33 cartesianSize_( computeCartesianSize() )
34 {
35 }
36
37 const std::array<int, dimension>& cartesianDimensions() const
38 {
39 return grid_.logicalCartesianSize();
40 }
41
42 int cartesianSize() const
43 {
44 return cartesianSize_;
45 }
46
47 int compressedSize() const
48 {
49 return grid_.globalCell().size();
50 }
51
52 int cartesianIndex( const int compressedElementIndex ) const
53 {
54 assert( compressedElementIndex >= 0 && compressedElementIndex < compressedSize() );
55 return grid_.globalCell()[ compressedElementIndex ];
56 }
57
58 void cartesianCoordinate(const int compressedElementIndex, std::array<int,dimension>& coords) const
59 {
60 grid_.getIJK( compressedElementIndex, coords );
61 }
62 };
63
64} // end namespace Opm
65#endif
Interface class to access the logical Cartesian grid as used in industry standard simulator decks.
Definition: CartesianIndexMapper.hpp:16
int cartesianIndex(const int) const
return index of the cells in the logical Cartesian grid
Definition: CartesianIndexMapper.hpp:47
int compressedSize() const
return number of cells in the active grid
Definition: CartesianIndexMapper.hpp:41
const std::array< int, dimension > & cartesianDimensions() const
return Cartesian dimensions, i.e.
Definition: CartesianIndexMapper.hpp:28
static const int dimension
dimension of the grid
Definition: CartesianIndexMapper.hpp:19
CartesianIndexMapper(const Grid &)
constructor taking grid
Definition: CartesianIndexMapper.hpp:22
int cartesianSize() const
return total number of cells in the logical Cartesian grid
Definition: CartesianIndexMapper.hpp:35
void cartesianCoordinate(const int, std::array< int, dimension > &) const
return Cartesian coordinate, i.e.
Definition: CartesianIndexMapper.hpp:53
[ provides Dune::Grid ]
Definition: CpGrid.hpp:214
const std::vector< int > & globalCell() const
Retrieve mapping from internal ("compressed") active grid cells to external ("uncompressed") cells.
Definition: CpGrid.cpp:564
const std::array< int, 3 > & logicalCartesianSize() const
The logical cartesian size of the global grid.
Definition: CpGrid.cpp:559
void getIJK(const int c, std::array< int, 3 > &ijk) const
Extract Cartesian index triplet (i,j,k) of an active cell.
Definition: CpGrid.cpp:569
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10