20 #ifndef OPM_GRIDADAPTER_HEADER_INCLUDED 21 #define OPM_GRIDADAPTER_HEADER_INCLUDED 25 #include <opm/grid/CpGrid.hpp> 37 void init(
const Grid& grid)
41 buildGlobalCell(grid);
60 enum { dimension = 3 };
64 explicit Vector(
const double* source)
66 for (
int i = 0; i < dimension; ++i) {
70 double& operator[] (
const int ix)
74 double operator[] (
const int ix)
const 78 double data[dimension];
90 int numVertices()
const 95 int numCellFaces(
int cell)
const 97 return cell_facepos_[cell + 1] - cell_facepos_[cell];
99 int cellFace(
int cell,
int local_index)
const 101 return cell_faces_[cell_facepos_[cell] + local_index];
103 int faceCell(
int face,
int local_index)
const 105 return face_cells_[2*face + local_index];
107 int numFaceVertices(
int face)
const 109 return face_nodepos_[face + 1] - face_nodepos_[face];
111 int faceVertex(
int face,
int local_index)
const 113 return face_nodes_[face_nodepos_[face] + local_index];
117 Vector vertexPosition(
int vertex)
const 119 return Vector(&node_coordinates_[g_.
dimensions*vertex]);
121 double faceArea(
int face)
const 123 return face_areas_[face];
125 Vector faceCentroid(
int face)
const 127 return Vector(&face_centroids_[g_.
dimensions*face]);
129 Vector faceNormal(
int face)
const 131 Vector fn(&face_normals_[g_.
dimensions*face]);
134 double invfa = 1.0 / faceArea(face);
135 for (
int i = 0; i < dimension; ++i) {
140 double cellVolume(
int cell)
const 142 return cell_volumes_[cell];
144 Vector cellCentroid(
int cell)
const 146 return Vector(&cell_centroids_[g_.
dimensions*cell]);
151 return face_nodes_ == other.face_nodes_
152 && face_nodepos_ == other.face_nodepos_
153 && face_cells_ == other.face_cells_
154 && cell_faces_ == other.cell_faces_
155 && cell_facepos_ == other.cell_facepos_
156 && node_coordinates_ == other.node_coordinates_
157 && face_centroids_ == other.face_centroids_
158 && face_areas_ == other.face_areas_
159 && face_normals_ == other.face_normals_
160 && cell_centroids_ == other.cell_centroids_
161 && cell_volumes_ == other.cell_volumes_;
165 void makeQPeriodic(
const std::vector<int>& hf_ind,
const std::vector<int>& periodic_cells){
166 for(
int i=0; i<int(hf_ind.size());++i){
168 int& cell0=face_cells_[2*cell_faces_[ hf_ind[i] ]+0];
169 int& cell1=face_cells_[2*cell_faces_[ hf_ind[i] ]+1];
170 assert(periodic_cells[2*i+1]>=0);
171 if(periodic_cells[2*i+0] == cell0){
173 cell1=periodic_cells[2*i+1];
175 assert(periodic_cells[2*i+0] == cell1);
177 cell0=periodic_cells[2*i+1];
184 std::vector<int> face_nodes_;
185 std::vector<unsigned> face_nodepos_;
186 std::vector<int> face_cells_;
187 std::vector<int> cell_faces_;
188 std::vector<unsigned> cell_facepos_;
190 std::vector<double> node_coordinates_;
191 std::vector<double> face_centroids_;
192 std::vector<double> face_areas_;
193 std::vector<double> face_normals_;
194 std::vector<double> cell_centroids_;
195 std::vector<double> cell_volumes_;
197 std::vector<int> global_cell_;
201 bool all_active=
true;
203 global_cell_.resize(grid.
numCells());
204 for(
int c=0; c<grid.
numCells(); ++c)
206 int new_cell=global_cell_[c]=grid.
globalCell()[c];
207 all_active = all_active && (new_cell==old_cell+1);
213 std::vector<int>().swap(global_cell_);
220 void buildGlobalCell(
const Grid& )
227 for(
int i=0; i<3; ++i)
231 template <
class Gr
id>
232 void copyCartDims(
const Grid& )
235 template <
class Gr
id>
236 void buildTopology(
const Grid& grid)
239 int num_cells = grid.numCells();
240 int num_faces = grid.numFaces();
241 face_nodepos_.resize(num_faces + 1);
242 int facenodecount = 0;
243 for (
int f = 0; f < num_faces; ++f) {
244 face_nodepos_[f] = facenodecount;
245 facenodecount += grid.numFaceVertices(f);
247 face_nodepos_.back() = facenodecount;
248 face_nodes_.resize(facenodecount);
249 for (
int f = 0; f < num_faces; ++f) {
250 for (
int local = 0; local < grid.numFaceVertices(f); ++local) {
251 face_nodes_[face_nodepos_[f] + local] = grid.faceVertex(f, local);
254 face_cells_.resize(2*num_faces);
255 for (
int f = 0; f < num_faces; ++f) {
256 face_cells_[2*f] = grid.faceCell(f, 0);
257 face_cells_[2*f + 1] = grid.faceCell(f, 1);
261 int cellfacecount = 0;
262 cell_facepos_.resize(num_cells + 1);
263 for (
int c = 0; c < num_cells; ++c) {
264 cell_facepos_[c] = cellfacecount;
265 cellfacecount += grid.numCellFaces(c);
267 cell_facepos_.back() = cellfacecount;
268 cell_faces_.resize(cellfacecount);
269 for (
int c = 0; c < num_cells; ++c) {
270 for (
int local = 0; local < grid.numCellFaces(c); ++local) {
271 cell_faces_[cell_facepos_[c] + local] = grid.cellFace(c, local);
290 template <
class Gr
id>
291 void buildGeometry(
const Grid& grid)
294 int num_cells = grid.numCells();
295 int num_nodes = grid.numVertices();
296 int num_faces = grid.numFaces();
297 int dim = Grid::dimension;
298 node_coordinates_.resize(dim*num_nodes);
299 for (
int n = 0; n < num_nodes; ++n) {
300 for (
int dd = 0; dd < dim; ++dd) {
301 node_coordinates_[dim*n + dd] = grid.vertexPosition(n)[dd];
306 face_centroids_.resize(dim*num_faces);
307 face_areas_.resize(num_faces);
308 face_normals_.resize(dim*num_faces);
309 for (
int f = 0; f < num_faces; ++f) {
310 face_areas_[f] = grid.faceArea(f);
311 for (
int dd = 0; dd < dim; ++dd) {
312 face_centroids_[dim*f + dd] = grid.faceCentroid(f)[dd];
313 face_normals_[dim*f + dd] = grid.faceNormal(f)[dd]*face_areas_[f];
318 cell_centroids_.resize(dim*num_cells);
319 cell_volumes_.resize(num_cells);
320 for (
int c = 0; c < num_cells; ++c) {
321 cell_volumes_[c] = grid.cellVolume(c);
322 for (
int dd = 0; dd < dim; ++dd) {
323 cell_centroids_[dim*c + dd] = grid.cellCentroid(c)[dd];
338 #endif // OPM_GRIDADAPTER_HEADER_INCLUDED int * global_cell
If non-null, this array contains the logical cartesian indices (in a lexicographic ordering) of each ...
Definition: UnstructuredGrid.h:216
double * cell_volumes
Exact or approximate cell volumes.
Definition: UnstructuredGrid.h:199
double * node_coordinates
Node coordinates, stored consecutively for each node.
Definition: UnstructuredGrid.h:162
double * face_centroids
Exact or approximate face centroids, stored consecutively for each face.
Definition: UnstructuredGrid.h:170
Definition: GridAdapter.hpp:29
void init(const Grid &grid)
Initialize the grid.
Definition: GridAdapter.hpp:37
int number_of_cells
The number of cells in the grid.
Definition: UnstructuredGrid.h:111
Main OPM-Core grid data structure along with helper functions for construction, destruction and readi...
const std::vector< int > & globalCell() const
Retrieve mapping from internal ("compressed") active grid cells to external ("uncompressed") cells...
Definition: CpGrid.cpp:681
double * cell_centroids
Exact or approximate cell centroids, stored consecutively for each cell.
Definition: UnstructuredGrid.h:194
[ provides Dune::Grid ]
Definition: CpGrid.hpp:201
double * face_normals
Exact or approximate face normals, stored consecutively for each face.
Definition: UnstructuredGrid.h:186
int number_of_faces
The number of faces in the grid.
Definition: UnstructuredGrid.h:113
int numCells(int level=-1) const
Get the number of cells.
Definition: CpGrid.cpp:1148
grid_size_t * cell_facepos
For a cell c, cell_facepos[c] contains the starting index for c's faces in the cell_faces array...
Definition: UnstructuredGrid.h:154
int dimensions
The topological and geometrical dimensionality of the grid.
Definition: UnstructuredGrid.h:108
Definition: GridAdapter.hpp:62
const UnstructuredGrid * c_grid() const
Access the underlying C grid.
Definition: GridAdapter.hpp:50
const std::array< int, 3 > & logicalCartesianSize() const
The logical cartesian size of the global grid.
Definition: CpGrid.cpp:655
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: UnstructuredGrid.h:140
int * cell_faces
Contains for each cell, the indices of its adjacent faces.
Definition: UnstructuredGrid.h:148
double * face_areas
Exact or approximate face areas.
Definition: UnstructuredGrid.h:175
int * face_nodes
Contains for each face, the indices of its adjacent nodes.
Definition: UnstructuredGrid.h:123
Data structure for an unstructured grid, unstructured meaning that any cell may have an arbitrary num...
Definition: UnstructuredGrid.h:100
int number_of_nodes
The number of nodes in the grid.
Definition: UnstructuredGrid.h:115
grid_size_t * face_nodepos
For a face f, face_nodepos[f] contains the starting index for f's nodes in the face_nodes array...
Definition: UnstructuredGrid.h:129
int cartdims[3]
Contains the size of the logical cartesian structure (if any) of the grid.
Definition: UnstructuredGrid.h:229