cpgrid/CartesianIndexMapper.hpp
Go to the documentation of this file.
1#ifndef OPM_CPGRIDCARTESIANINDEXMAPPER_HEADER
2#define OPM_CPGRIDCARTESIANINDEXMAPPER_HEADER
3
4#include <array>
5#include <cassert>
6#include <stdexcept>
7
9#include <opm/grid/CpGrid.hpp>
10
11namespace Dune
12{
13 template<>
15 {
16 public:
17 static const int dimension = 3 ;
18 protected:
19 typedef CpGrid Grid;
20 const Grid& grid_;
21 const int cartesianSize_;
22
24 {
25 int size = cartesianDimensions()[ 0 ];
26 for( int d=1; d<dimension; ++d )
27 size *= cartesianDimensions()[ d ];
28 return size;
29 }
30
31 public:
32 explicit CartesianIndexMapper( const Grid& grid )
33 : grid_( grid ),
34 cartesianSize_( computeCartesianSize() )
35 {
36 }
37
38 const std::array<int, dimension>& cartesianDimensions() const
39 {
40 // For now, return the level-zero logical Cartesian size.
41 // Note: grid_.logicalCartesianSize() can vary depending on how refinement was applied
42 // (e.g., via addLgrsUpdateLeafView(...), adapt(), or globalRefine()).
43 // This includes cases where all elements of the level-zero grid have been refined.
44 return grid_.currentData().front()->logicalCartesianSize();
45 }
46
47 int cartesianSize() const
48 {
49 return cartesianSize_;
50 }
51
52 int compressedSize() const
53 {
54 return grid_.globalCell().size();
55 }
56
57 int cartesianIndex( const int compressedElementIndex ) const
58 {
59 assert( compressedElementIndex >= 0 && compressedElementIndex < compressedSize() );
60 return grid_.globalCell()[ compressedElementIndex ];
61 }
62
63 void cartesianCoordinate(const int compressedElementIndex, std::array<int,dimension>& coords) const
64 {
65 grid_.getIJK( compressedElementIndex, coords );
66 }
67 };
68
69} // end namespace Opm
70#endif
const int cartesianSize_
Definition: cpgrid/CartesianIndexMapper.hpp:21
const Grid & grid_
Definition: cpgrid/CartesianIndexMapper.hpp:20
int cartesianSize() const
Definition: cpgrid/CartesianIndexMapper.hpp:47
int compressedSize() const
Definition: cpgrid/CartesianIndexMapper.hpp:52
const std::array< int, dimension > & cartesianDimensions() const
Definition: cpgrid/CartesianIndexMapper.hpp:38
CpGrid Grid
Definition: cpgrid/CartesianIndexMapper.hpp:19
int computeCartesianSize() const
Definition: cpgrid/CartesianIndexMapper.hpp:23
CartesianIndexMapper(const Grid &grid)
Definition: cpgrid/CartesianIndexMapper.hpp:32
void cartesianCoordinate(const int compressedElementIndex, std::array< int, dimension > &coords) const
Definition: cpgrid/CartesianIndexMapper.hpp:63
int cartesianIndex(const int compressedElementIndex) const
Definition: cpgrid/CartesianIndexMapper.hpp:57
Interface class to access the logical Cartesian grid as used in industry standard simulator decks.
Definition: common/CartesianIndexMapper.hpp:16
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
[ 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).
const std::vector< int > & globalCell() const
void getIJK(const int c, std::array< int, 3 > &ijk) const
Extract Cartesian index triplet (i,j,k) of an active cell.
The namespace Dune is the main namespace for all Dune code.
Definition: common/CartesianIndexMapper.hpp:10