Loading...
Searching...
No Matches
GridHelpers.hpp
/*
Copyright 2014, 2015 Dr. Markus Blatt - HPC-Simulation-Software & Services.
Copyright 2014 Statoil AS
Copyright 2015 NTNU
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DUNE_CORNERPOINT_GRIDHELPERS_HEADER_INCLUDED
#define DUNE_CORNERPOINT_GRIDHELPERS_HEADER_INCLUDED
#include <functional>
#include <opm/grid/GridHelpers.hpp>
#include <opm/grid/utility/platform_dependent/disable_warnings.h>
#include <opm/grid/CpGrid.hpp>
#include <dune/common/iteratorfacades.hh>
#include <opm/grid/utility/platform_dependent/reenable_warnings.h>
namespace Dune
{
namespace cpgrid
{
class FaceCellsProxy
{
public:
FaceCellsProxy(const Dune::CpGrid* grid, int cell_index)
: grid_(grid), cell_index_(cell_index)
{}
int operator[](int local_index)
{
return grid_->faceCell(cell_index_, local_index);
}
private:
const Dune::CpGrid* grid_;
int cell_index_;
};
class FaceCellsContainerProxy
{
public:
typedef FaceCellsProxy row_type;
explicit FaceCellsContainerProxy(const Dune::CpGrid* grid)
: grid_(grid)
{}
FaceCellsProxy operator[](int cell_index) const
{
return FaceCellsProxy(grid_, cell_index);
}
int operator()(int cell_index, int local_index) const
{
return grid_->faceCell(cell_index, local_index);
}
private:
const Dune::CpGrid* grid_;
};
class IndexIterator
{
public:
explicit IndexIterator(int index)
: index_(index)
{}
void increment()
{
++index_;
}
void decrement()
{
--index_;
}
void advance(int n)
{
index_+=n;
}
int distanceTo(const IndexIterator& o)const
{
return o.index_-index_;
}
bool equals(const IndexIterator& o) const
{
return index_==o.index_;
}
protected:
int index_;
};
template<int (Dune::CpGrid::*AccessMethod)(int,int)const,
int (Dune::CpGrid::*SizeMethod)(int)const>
class LocalIndexProxy
{
public:
class iterator
: public Dune::RandomAccessIteratorFacade<iterator,int, int, int>,
public IndexIterator
{
public:
iterator(const Dune::CpGrid* grid, int outer_index, int inner_index)
: IndexIterator(inner_index), grid_(grid), outer_index_(outer_index)
{}
int dereference() const
{
return std::mem_fn(AccessMethod)(*grid_, outer_index_, this->index_);
}
int elementAt(int n) const
{
return std::mem_fn(AccessMethod)(*grid_, outer_index_, n);
}
private:
const Dune::CpGrid* grid_;
int outer_index_;
};
typedef iterator const_iterator;
LocalIndexProxy(const Dune::CpGrid* grid, int cell_index)
: grid_(grid), cell_index_(cell_index)
{}
int operator[](int local_index)
{
return std::mem_fn(AccessMethod)(*grid_, cell_index_, local_index);
}
const_iterator begin()
{
return const_iterator(grid_, cell_index_, 0);
}
const_iterator end()
{
return const_iterator(grid_, cell_index_,
std::mem_fn(SizeMethod)(*grid_, cell_index_));
}
private:
const Dune::CpGrid* grid_;
int cell_index_;
};
template<int (Dune::CpGrid::*AccessMethod)(int,int)const,
int (Dune::CpGrid::*SizeMethod)(int)const>
class LocalIndexContainerProxy
{
public:
typedef LocalIndexProxy<AccessMethod, SizeMethod> row_type;
explicit LocalIndexContainerProxy(const Dune::CpGrid* grid)
: grid_(grid)
{}
row_type operator[](int cell_index) const
{
return row_type(grid_, cell_index);
}
int operator()(int cell_index, int local_index) const
{
return std::mem_fn(AccessMethod)(*grid_, cell_index, local_index);
}
private:
const Dune::CpGrid* grid_;
};
class FaceVerticesContainerProxy
: public LocalIndexContainerProxy<&Dune::CpGrid::faceVertex, &Dune::CpGrid::numFaceVertices>
{
public:
explicit FaceVerticesContainerProxy(const Dune::CpGrid* grid)
: LocalIndexContainerProxy<&Dune::CpGrid::faceVertex, &Dune::CpGrid::numFaceVertices>(grid)
{}
};
class Cell2FacesRow
{
public:
class iterator
: public Dune::RandomAccessIteratorFacade<iterator,int, int, int>,
public IndexIterator
{
public:
iterator(const Dune::cpgrid::OrientedEntityTable<0,1>::row_type& row,
int index, int cell_index)
: IndexIterator(index), row_(row), cell_index_(cell_index)
{}
int dereference() const
{
return row_[this->index_].index();
}
int elementAt(int n) const
{
return row_[n].index();
}
int getCellIndex()const
{
return cell_index_;
}
private:
// Note that row_ is a Opm::iterator_range returned by Opm::SparseTable.
// and stored in CellFacesRow. It is a temporary object that only lives
// as long as there is a reference to it e.g. by storing the Cell2FacesRow.
// Therefore it needs to be copied. As it is rather light weight this
// should be fast anyway. A const reference would mean that the iterator
// is not assignable.
const Dune::cpgrid::OrientedEntityTable<0,1>::row_type row_;
int cell_index_;
};
typedef iterator const_iterator;
Cell2FacesRow(const Dune::cpgrid::OrientedEntityTable<0,1>::row_type& row,
const int cell_index)
: row_(row), cell_index_(cell_index)
{}
const_iterator begin() const
{
return const_iterator(row_, 0, cell_index_);
}
const_iterator end() const
{
return const_iterator(row_, row_.size(), cell_index_);
}
private:
// Note that row_ is a Opm::iterator_range returned by Opm::SparseTable.
// and stored in CellFacesRow. It is a temporary object that only lives
// as long as there is a reference to it e.g. by storing the Cell2FacesRow.
// Therefore it needs to be copied. As it is rather light weight this
// should be fast anyway. A const reference would mean that the row
// is not assignable.
const Dune::cpgrid::OrientedEntityTable<0,1>::row_type row_;
const int cell_index_;
};
class Cell2FacesContainer
{
public:
typedef Cell2FacesRow row_type;
explicit Cell2FacesContainer(const Dune::CpGrid* grid)
: grid_(grid)
{};
Cell2FacesRow operator[](int cell_index) const
{
const auto& row = grid_->cellFaceRow(cell_index);
return Cell2FacesRow(row, cell_index);
}
std::size_t noEntries() const
{
return grid_->numCellFaces();
}
private:
const Dune::CpGrid* grid_;
};
} // end namespace cpgrid
} // end namespace Dune
namespace Opm
{
namespace UgGridHelpers
{
template<>
struct Cell2FacesTraits<Dune::CpGrid>
{
typedef Dune::cpgrid::Cell2FacesContainer Type;
};
template<const Dune::FieldVector<double, 3>& (Dune::CpGrid::*Method)(int)const>
class CpGridCentroidIterator
: public Dune::RandomAccessIteratorFacade<CpGridCentroidIterator<Method>, Dune::FieldVector<double, 3>,
const Dune::FieldVector<double, 3>&, int>
{
public:
CpGridCentroidIterator(const Dune::CpGrid& grid, int cell_index)
: grid_(&grid), cell_index_(cell_index)
{}
const Dune::FieldVector<double, 3>& dereference() const
{
return std::mem_fn(Method)(*grid_, cell_index_);
}
void increment()
{
++cell_index_;
}
const Dune::FieldVector<double, 3>& elementAt(int n) const
{
return std::mem_fn(Method)(*grid_, n);
}
void advance(int n)
{
cell_index_+=n;
}
void decrement()
{
--cell_index_;
}
int distanceTo(const CpGridCentroidIterator& o) const
{
return o.cell_index_-cell_index_;
}
bool equals(const CpGridCentroidIterator& o) const
{
return o.grid_==grid_ && o.cell_index_==cell_index_;
}
private:
const Dune::CpGrid* grid_;
int cell_index_;
};
template<>
struct CellCentroidTraits<Dune::CpGrid>
{
typedef CpGridCentroidIterator<&Dune::CpGrid::cellCentroid> IteratorType;
typedef const double* ValueType;
};
typedef Dune::FieldVector<double, 3> Vector;
int numCells(const Dune::CpGrid& grid);
int numFaces(const Dune::CpGrid& grid);
int dimensions(const Dune::CpGrid& grid);
int numCellFaces(const Dune::CpGrid& grid);
const int* cartDims(const Dune::CpGrid& grid);
const int* globalCell(const Dune::CpGrid&);
#if HAVE_ECL_INPUT
std::vector<int> createACTNUM(const Dune::CpGrid& grid);
EclipseGrid createEclipseGrid(const Dune::CpGrid& grid, const EclipseGrid& inputGrid);
#endif
CellCentroidTraits<Dune::CpGrid>::IteratorType
beginCellCentroids(const Dune::CpGrid& grid);
double cellCentroidCoordinate(const Dune::CpGrid& grid, int cell_index,
int coordinate);
const double* cellCentroid(const Dune::CpGrid& grid, int cell_index);
double cellCenterDepth(const Dune::CpGrid& grid, int cell_index);
Vector faceCenterEcl(const Dune::CpGrid& grid, int cell_index, int face_tag);
Vector faceAreaNormalEcl(const Dune::CpGrid& grid, int face_index);
double cellVolume(const Dune::CpGrid& grid, int cell_index);
class CellVolumeIterator
: public Dune::RandomAccessIteratorFacade<CellVolumeIterator, double, double, int>
{
public:
CellVolumeIterator(const Dune::CpGrid& grid, int cell_index)
: grid_(&grid), cell_index_(cell_index)
{}
double dereference() const
{
return grid_->cellVolume(cell_index_);
}
void increment()
{
++cell_index_;
}
double elementAt(int n) const
{
return grid_->cellVolume(n);
}
void advance(int n)
{
cell_index_+=n;
}
void decrement()
{
--cell_index_;
}
int distanceTo(const CellVolumeIterator& o) const
{
return o.cell_index_-cell_index_;
}
bool equals(const CellVolumeIterator& o) const
{
return o.grid_==grid_ && o.cell_index_==cell_index_;
}
private:
const Dune::CpGrid* grid_;
int cell_index_;
};
template<>
struct CellVolumeIteratorTraits<Dune::CpGrid>
{
typedef CellVolumeIterator IteratorType;
};
CellVolumeIterator beginCellVolumes(const Dune::CpGrid& grid);
CellVolumeIterator endCellVolumes(const Dune::CpGrid& grid);
template<>
struct FaceCentroidTraits<Dune::CpGrid>
{
typedef CpGridCentroidIterator<&Dune::CpGrid::faceCentroid> IteratorType;
typedef const Dune::CpGrid::Vector ValueType;
};
FaceCentroidTraits<Dune::CpGrid>::IteratorType
beginFaceCentroids(const Dune::CpGrid& grid);
const FaceCentroidTraits<Dune::CpGrid>::ValueType&
faceCentroid(const Dune::CpGrid& grid, int face_index);
template<>
struct FaceCellTraits<Dune::CpGrid>
{
typedef Dune::cpgrid::FaceCellsContainerProxy Type;
};
Dune::cpgrid::Cell2FacesContainer cell2Faces(const Dune::CpGrid& grid);
FaceCellTraits<Dune::CpGrid>::Type
faceCells(const Dune::CpGrid& grid);
template<>
struct Face2VerticesTraits<Dune::CpGrid>
{
typedef Dune::cpgrid::FaceVerticesContainerProxy Type;
};
Face2VerticesTraits<Dune::CpGrid>::Type
face2Vertices(const Dune::CpGrid& grid);
const double* vertexCoordinates(const Dune::CpGrid& grid, int index);
const double* faceNormal(const Dune::CpGrid& grid, int face_index);
double faceArea(const Dune::CpGrid& grid, int face_index);
int faceTag(const Dune::CpGrid& grid,
const Dune::cpgrid::Cell2FacesRow::iterator& cell_face);
} // end namespace UgGridHelpers
} // end namespace Opm
#endif
Dune::CpGrid
[ provides Dune::Grid ]
Definition CpGrid.hpp:203
Dune::cpgrid::Cell2FacesContainer
Definition GridHelpers.hpp:295
Dune::cpgrid::Cell2FacesContainer::noEntries
std::size_t noEntries() const
Get the number of non-zero entries.
Definition GridHelpers.hpp:310
Dune::cpgrid::Cell2FacesRow::iterator
Definition GridHelpers.hpp:235
Dune::cpgrid::Cell2FacesRow
Definition GridHelpers.hpp:230
Dune::cpgrid::FaceCellsContainerProxy
A class representing the face to cells mapping similar to the way done in UnstructuredGrid.
Definition GridHelpers.hpp:62
Dune::cpgrid::FaceCellsContainerProxy::FaceCellsContainerProxy
FaceCellsContainerProxy(const Dune::CpGrid *grid)
Constructor.
Definition GridHelpers.hpp:68
Dune::cpgrid::FaceCellsContainerProxy::operator()
int operator()(int cell_index, int local_index) const
Get a face associated with a cell.
Definition GridHelpers.hpp:82
Dune::cpgrid::FaceCellsContainerProxy::operator[]
FaceCellsProxy operator[](int cell_index) const
Get the mapping for a cell.
Definition GridHelpers.hpp:73
Dune::cpgrid::FaceCellsProxy
A proxy class representing a row of FaceCellsContainer.
Definition GridHelpers.hpp:41
Dune::cpgrid::FaceCellsProxy::FaceCellsProxy
FaceCellsProxy(const Dune::CpGrid *grid, int cell_index)
Constructor.
Definition GridHelpers.hpp:46
Dune::cpgrid::FaceCellsProxy::operator[]
int operator[](int local_index)
Get the index of the cell associated with a local_index.
Definition GridHelpers.hpp:50
Dune::cpgrid::FaceVerticesContainerProxy
A class representing the face to vertices mapping similar to the way done in UnstructuredGrid.
Definition GridHelpers.hpp:220
Dune::cpgrid::FaceVerticesContainerProxy::FaceVerticesContainerProxy
FaceVerticesContainerProxy(const Dune::CpGrid *grid)
Constructor.
Definition GridHelpers.hpp:224
Dune::cpgrid::LocalIndexContainerProxy::LocalIndexContainerProxy
LocalIndexContainerProxy(const Dune::CpGrid *grid)
Constructor.
Definition GridHelpers.hpp:194
Dune::cpgrid::LocalIndexContainerProxy::operator[]
row_type operator[](int cell_index) const
Get the mapping for a cell.
Definition GridHelpers.hpp:199
Dune::cpgrid::LocalIndexContainerProxy::operator()
int operator()(int cell_index, int local_index) const
Get a face associated with a cell.
Definition GridHelpers.hpp:208
Dune::cpgrid::LocalIndexProxy::iterator
Definition GridHelpers.hpp:136
Dune::cpgrid::LocalIndexProxy
A proxy class representing a row of LocalIndexContainerProxy.
Definition GridHelpers.hpp:131
Dune::cpgrid::LocalIndexProxy::LocalIndexProxy
LocalIndexProxy(const Dune::CpGrid *grid, int cell_index)
Constructor.
Definition GridHelpers.hpp:159
Dune::cpgrid::LocalIndexProxy::operator[]
int operator[](int local_index)
Get the index of the cell associated with a local_index.
Definition GridHelpers.hpp:163
Opm::UgGridHelpers::CellVolumeIterator
An iterator over the cell volumes.
Definition GridHelpers.hpp:464
Opm::UgGridHelpers::CellVolumeIterator::CellVolumeIterator
CellVolumeIterator(const Dune::CpGrid &grid, int cell_index)
Creates an iterator.
Definition GridHelpers.hpp:469
Opm::UgGridHelpers::CpGridCentroidIterator
An iterator over the cell volumes.
Definition GridHelpers.hpp:335
Opm::UgGridHelpers::CpGridCentroidIterator::CpGridCentroidIterator
CpGridCentroidIterator(const Dune::CpGrid &grid, int cell_index)
Creates an iterator.
Definition GridHelpers.hpp:340
Dune::cpgrid
Copyright 2019 Equinor AS.
Definition GridPartitioning.cpp:673
Dune
The namespace Dune is the main namespace for all Dune code.
Definition CartesianIndexMapper.hpp:10
Opm
Holds the implementation of the CpGrid as a pimple.
Definition CellQuadrature.cpp:68
face_tag
face_tag
Connection taxonomy.
Definition preprocess.h:66
Opm::UgGridHelpers::Cell2FacesTraits
Maps the grid type to the associated type of the cell to faces mapping.
Definition GridHelpers.hpp:280
Opm::UgGridHelpers::CellCentroidTraits
Traits of the cell centroids of a grid.
Definition GridHelpers.hpp:129
Opm::UgGridHelpers::CellVolumeIteratorTraits
The mapping of the grid type to type of the iterator over the cell volumes.
Definition GridHelpers.hpp:194
Opm::UgGridHelpers::Face2VerticesTraits
Maps the grid type to the associated type of the face to vertices mapping.
Definition GridHelpers.hpp:295
Opm::UgGridHelpers::FaceCellTraits
Traits of the face to attached cell mappping of a grid.
Definition GridHelpers.hpp:337
Opm::UgGridHelpers::FaceCentroidTraits
Traits of the face centroids of a grid.
Definition GridHelpers.hpp:244