All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
GridHelpers.hpp
1 /*
2  Copyright 2014, 2015 Dr. Markus Blatt - HPC-Simulation-Software & Services
3  Copyright 2014 Statoil AS
4  Copyright 2015
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #ifndef OPM_CORE_GRIDHELPERS_HEADER_INCLUDED
22 #define OPM_CORE_GRIDHELPERS_HEADER_INCLUDED
23 
24 #include <dune/common/fvector.hh>
25 
26 #include <opm/core/grid.h>
27 
28 #include <opm/grid/utility/OpmParserIncludes.hpp>
29 
30 #include <opm/grid/utility/platform_dependent/disable_warnings.h>
31 #include <boost/range/iterator_range.hpp>
32 #include <opm/grid/utility/platform_dependent/reenable_warnings.h>
33 
34 
35 namespace Opm
36 {
37 namespace UgGridHelpers
38 {
39 
46 {
47 public:
48  class IntRange : public boost::iterator_range<const int*>
49  {
50  public:
51  typedef boost::iterator_range<const int*> BaseRowType;
52  typedef BaseRowType::size_type size_type;
53  typedef int value_type;
54 
55  IntRange(const int* start_arg, const int* end_arg)
56  : BaseRowType(start_arg, end_arg)
57  {}
58  };
60  typedef boost::iterator_range<const int*> row_type;
61 
67  SparseTableView(int* data, int *offset, std::size_t size_arg)
68  : data_(data), offset_(offset), size_(size_arg)
69  {}
70 
74  row_type operator[](std::size_t row) const
75  {
76  assert(row<=size());
77  return row_type(data_ + offset_[row], data_ + offset_[row+1]);
78  }
79 
82  std::size_t size() const
83  {
84  return size_;
85  }
86 
88  std::size_t noEntries() const
89  {
90  return offset_[size_];
91  }
92 
93 private:
95  const int* data_;
99  const int* offset_;
101  std::size_t size_;
102 };
103 
105 int numCells(const UnstructuredGrid& grid);
106 
108 int numFaces(const UnstructuredGrid& grid);
109 
111 int dimensions(const UnstructuredGrid& grid);
112 
114 int numCellFaces(const UnstructuredGrid& grid);
115 
117 const int* cartDims(const UnstructuredGrid& grid);
118 
123 const int* globalCell(const UnstructuredGrid& grid);
124 
130 template<class G>
132 {
133 };
134 
135 template<>
137 {
138  typedef const double* IteratorType;
139  typedef const double* ValueType;
140 };
141 
147 beginCellCentroids(const UnstructuredGrid& grid);
148 
149 
153 double cellCenterDepth(const UnstructuredGrid& grid, int cell_index);
154 
160 Dune::FieldVector<double,3> faceCenterEcl(const UnstructuredGrid& grid, int cell_index, int face_tag);
161 
168 Dune::FieldVector<double,3> faceAreaNormalEcl(const UnstructuredGrid& grid, int face_index);
169 
170 
175 double cellCentroidCoordinate(const UnstructuredGrid& grid, int cell_index,
176  int coordinate);
177 
178 
182 const double* cellCentroid(const UnstructuredGrid& grid, int cell_index);
183 
184 
188 double cellVolume(const UnstructuredGrid& grid, int cell_index);
189 
195 template<class T>
197 {
198 };
199 
200 template<>
202 {
203  typedef const double* IteratorType;
204 };
205 
226 #if HAVE_OPM_PARSER
227 Opm::EclipseGrid createEclipseGrid(const UnstructuredGrid& grid, const Opm::EclipseGrid& inputGrid );
230 #endif
231 
233 const double* beginCellVolumes(const UnstructuredGrid& grid);
234 
236 const double* endCellVolumes(const UnstructuredGrid& grid);
237 
238 
239 
245 template<class G>
247 {
248 };
249 
250 template<>
252 {
253  typedef const double* IteratorType;
254  typedef const double* ValueType;
255 };
256 
259 beginFaceCentroids(const UnstructuredGrid& grid);
260 
265 faceCentroid(const UnstructuredGrid& grid, int face_index);
266 
270 const double* faceNormal(const UnstructuredGrid& grid, int face_index);
271 
275 double faceArea(const UnstructuredGrid& grid, int face_index);
276 
281 int faceTag(const UnstructuredGrid& grid, boost::iterator_range<const int*>::const_iterator cell_face);
282 
287 template<class T>
289 {
290 };
291 
292 template<>
294 {
295  typedef SparseTableView Type;
296 };
297 
302 template<class T>
304 {
305 };
306 
307 template<>
309 {
310  typedef SparseTableView Type;
311 };
312 
315 cell2Faces(const UnstructuredGrid& grid);
316 
319 face2Vertices(const UnstructuredGrid& grid);
320 
324 const double* vertexCoordinates(const UnstructuredGrid& grid, int index);
325 
327 {
328 public:
329  FaceCellsProxy(const UnstructuredGrid& grid)
330  : face_cells_(grid.face_cells)
331  {}
332  int operator()(int face_index, int local_index) const
333  {
334  return face_cells_[2*face_index+local_index];
335  }
336 private:
337  const int* face_cells_;
338 };
339 
344 template<class T>
346 {};
347 
348 template<>
350 {
351  typedef FaceCellsProxy Type;
352 };
353 
356 
362 template<class T>
363 T* increment(T* cc, int i, int dim)
364 {
365  return cc+(i*dim);
366 }
371 template<class T>
372 T increment(const T& t, int i, int)
373 {
374  return t+i;
375 }
376 
381 template<class T>
382 double getCoordinate(T* cc, int i)
383 {
384  return cc[i];
385 }
386 
392 template<class T>
393 double getCoordinate(T t, int i)
394 {
395  return (*t)[i];
396 }
397 
398 } // end namespace UGGridHelpers
399 } // end namespace OPM
400 #endif
row_type operator[](std::size_t row) const
Get a row of the the table.
Definition: GridHelpers.hpp:74
SparseTableView(int *data, int *offset, std::size_t size_arg)
Creates a sparse table view.
Definition: GridHelpers.hpp:67
Definition: GridHelpers.hpp:48
std::size_t noEntries() const
Get the number of non-zero entries.
Definition: GridHelpers.hpp:88
Traits of the cell centroids of a grid.
Definition: GridHelpers.hpp:131
Allows viewing a sparse table consisting out of C-array.
Definition: GridHelpers.hpp:45
Traits of the face to attached cell mappping of a grid.
Definition: GridHelpers.hpp:345
Main OPM-Core grid data structure along with helper functions for construction, destruction and readi...
int * face_cells
For a face f, face_cells[2*f] and face_cells[2*f + 1] contain the cell indices of the cells adjacent ...
Definition: grid.h:138
Maps the grid type to the associated type of the cell to faces mapping.
Definition: GridHelpers.hpp:288
Maps the grid type to the associated type of the face to vertices mapping.
Definition: GridHelpers.hpp:303
face_tag
Connection taxonomy.
Definition: preprocess.h:67
std::size_t size() const
Get the size of the table.
Definition: GridHelpers.hpp:82
Traits of the face centroids of a grid.
Definition: GridHelpers.hpp:246
Data structure for an unstructured grid, unstructured meaning that any cell may have an arbitrary num...
Definition: grid.h:98
Definition: GridHelpers.hpp:326
The mapping of the grid type to type of the iterator over the cell volumes.
Definition: GridHelpers.hpp:196
boost::iterator_range< const int * > row_type
The type of the roww.
Definition: GridHelpers.hpp:60