Loading...
Searching...
No Matches
cartesianindexmapper.hh
#ifndef OPM_POLYHEDRALCARTESIANINDEXMAPPER_HEADER
#define OPM_POLYHEDRALCARTESIANINDEXMAPPER_HEADER
#include <opm/grid/common/CartesianIndexMapper.hpp>
#include <opm/grid/polyhedralgrid.hh>
namespace Dune
{
template< int dim, int dimworld, typename coord_t >
class CartesianIndexMapper< PolyhedralGrid< dim, dimworld, coord_t > >
{
typedef PolyhedralGrid< dim, dimworld, coord_t > Grid;
const Grid& grid_;
const int cartesianSize_;
int computeCartesianSize() const
{
int size = cartesianDimensions()[ 0 ];
for( int d=1; d<dim; ++d )
size *= cartesianDimensions()[ d ];
return size ;
}
public:
static const int dimension = Grid :: dimension ;
explicit CartesianIndexMapper( const Grid& grid )
: grid_( grid ),
cartesianSize_( computeCartesianSize() )
{}
const std::array<int, dimension>& cartesianDimensions() const
{
return grid_.logicalCartesianSize();
}
int cartesianSize() const
{
return cartesianSize_;
}
int compressedSize() const
{
return grid_.size( 0 );
}
int cartesianIndex( const int compressedElementIndex ) const
{
assert( compressedElementIndex >= 0 && compressedElementIndex < compressedSize() );
return grid_.globalCell()[ compressedElementIndex ];
}
void cartesianCoordinate(const int compressedElementIndex, std::array<int,dimension>& coords) const
{
int gc = cartesianIndex( compressedElementIndex );
if( dimension >=2 )
{
for( int d=0; d<dimension-2; ++d )
{
coords[d] = gc % cartesianDimensions()[d]; gc /= cartesianDimensions()[d];
}
coords[dimension-2] = gc % cartesianDimensions()[dimension-2];
coords[dimension-1] = gc / cartesianDimensions()[dimension-1];
}
else
coords[ 0 ] = gc ;
}
};
} // end namespace Opm
#endif
Dune::CartesianIndexMapper::cartesianIndex
int cartesianIndex(const int) const
return index of the cells in the logical Cartesian grid
Definition CartesianIndexMapper.hpp:47
Dune::CartesianIndexMapper::compressedSize
int compressedSize() const
return number of cells in the active grid
Definition CartesianIndexMapper.hpp:41
Dune::CartesianIndexMapper::cartesianDimensions
const std::array< int, dimension > & cartesianDimensions() const
return Cartesian dimensions, i.e.
Definition CartesianIndexMapper.hpp:28
Dune::CartesianIndexMapper::CartesianIndexMapper
CartesianIndexMapper(const Grid &)
constructor taking grid
Definition CartesianIndexMapper.hpp:22
Dune::CartesianIndexMapper::cartesianSize
int cartesianSize() const
return total number of cells in the logical Cartesian grid
Definition CartesianIndexMapper.hpp:35
Dune::CartesianIndexMapper::cartesianCoordinate
void cartesianCoordinate(const int, std::array< int, dimension > &) const
return Cartesian coordinate, i.e.
Definition CartesianIndexMapper.hpp:53
Dune::PolyhedralGrid
identical grid wrapper
Definition grid.hh:159
Dune
The namespace Dune is the main namespace for all Dune code.
Definition CartesianIndexMapper.hpp:10