My Project
Loading...
Searching...
No Matches
CartesianIndexMapper.hpp
1#ifndef OPM_CPGRIDCARTESIANINDEXMAPPER_HEADER
2#define OPM_CPGRIDCARTESIANINDEXMAPPER_HEADER
3
4#include <array>
5#include <cassert>
6#include <stdexcept>
7
8#include <opm/grid/common/CartesianIndexMapper.hpp>
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
23 int computeCartesianSize() const
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 return grid_.logicalCartesianSize();
41 }
42
43 int cartesianSize() const
44 {
45 return cartesianSize_;
46 }
47
48 int compressedSize() const
49 {
50 return grid_.globalCell().size();
51 }
52
53 int compressedLevelZeroSize() const
54 {
55 return (*grid_.currentData()[0]).size(0);
56 }
57
58 int cartesianIndex( const int compressedElementIndex ) const
59 {
60 assert( compressedElementIndex >= 0 && compressedElementIndex < compressedSize() );
61 return grid_.globalCell()[ compressedElementIndex ];
62 }
63
64 void cartesianCoordinate(const int compressedElementIndex, std::array<int,dimension>& coords) const
65 {
66 grid_.getIJK( compressedElementIndex, coords );
67 }
68
69 void cartesianCoordinateLevel(const int compressedElementIndexOnLevel, std::array<int,dimension>& coordsOnLevel, int level) const
70 {
71 if ((level < 0) || (level > grid_.maxLevel())) {
72 throw std::invalid_argument("Invalid level.\n");
73 }
74 (*grid_.currentData()[level]).getIJK( compressedElementIndexOnLevel, coordsOnLevel);
75 }
76 };
77
78} // end namespace Opm
79#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:53
int compressedLevelZeroSize() const
return number of cells in the active level zero 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:59
void cartesianCoordinateLevel(const int, std::array< int, dimension > &, int) const
return Cartesian coordinate, i.e.
Definition CartesianIndexMapper.hpp:64
[ provides Dune::Grid ]
Definition CpGrid.hpp:201
const std::vector< std::shared_ptr< Dune::cpgrid::CpGridData > > & currentData() const
Returns either data_ or distributed_data_(if non empty).
Definition CpGrid.cpp:619
const std::vector< int > & globalCell() const
Retrieve mapping from internal ("compressed") active grid cells to external ("uncompressed") cells.
Definition CpGrid.cpp:629
int maxLevel() const
Return maximum level defined in this grid. Levels are 0 and 1, maxlevel = 1 (not counting leafview),...
Definition CpGrid.cpp:702
const std::array< int, 3 > & logicalCartesianSize() const
The logical cartesian size of the global grid.
Definition CpGrid.cpp:612
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:682
Copyright 2019 Equinor AS.
Definition CartesianIndexMapper.hpp:10