2011-12-04 16:21:24 +01:00
|
|
|
/*===========================================================================
|
|
|
|
|
//
|
|
|
|
|
// File: cgridinterface.c
|
|
|
|
|
//
|
|
|
|
|
// Author: Jostein R. Natvig <Jostein.R.Natvig@sintef.no>
|
|
|
|
|
//
|
|
|
|
|
//==========================================================================*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Copyright 2011 SINTEF ICT, Applied Mathematics.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-11-30 12:41:29 +01:00
|
|
|
#include <assert.h>
|
2010-08-30 08:37:37 +00:00
|
|
|
#include <stdlib.h>
|
2011-11-30 11:08:32 +01:00
|
|
|
|
2011-11-30 12:41:29 +01:00
|
|
|
#include "geometry.h"
|
2011-11-30 11:08:32 +01:00
|
|
|
#include "cgridinterface.h"
|
2010-08-30 08:37:37 +00:00
|
|
|
|
2011-11-30 12:41:29 +01:00
|
|
|
|
2011-11-30 13:36:31 +01:00
|
|
|
static int
|
|
|
|
|
fill_cell_topology(struct processed_grid *pg,
|
|
|
|
|
struct CornerpointGrid *G )
|
|
|
|
|
{
|
2011-11-30 23:48:16 +01:00
|
|
|
int f, c1, c2, tag;
|
2011-11-30 13:36:31 +01:00
|
|
|
size_t c, nc, nhf;
|
|
|
|
|
|
|
|
|
|
struct UnstructuredGrid *g;
|
|
|
|
|
|
|
|
|
|
g = (struct UnstructuredGrid *) G;
|
|
|
|
|
|
|
|
|
|
nc = g->number_of_cells;
|
|
|
|
|
|
|
|
|
|
g->cell_facepos = malloc((nc + 1) * sizeof *g->cell_facepos);
|
|
|
|
|
|
|
|
|
|
if (g->cell_facepos != NULL) {
|
|
|
|
|
for (c = 0; c < nc + 1; c++) { g->cell_facepos[c] = 0; }
|
|
|
|
|
|
|
|
|
|
for (f = 0; f < g->number_of_faces; f++) {
|
|
|
|
|
c1 = g->face_cells[2*f + 0];
|
|
|
|
|
c2 = g->face_cells[2*f + 1];
|
|
|
|
|
|
|
|
|
|
if (c1 >= 0) { g->cell_facepos[c1 + 1] += 1; }
|
|
|
|
|
if (c2 >= 0) { g->cell_facepos[c2 + 1] += 1; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (c = 1; c <= nc; c++) {
|
|
|
|
|
g->cell_facepos[0] += g->cell_facepos[c];
|
|
|
|
|
g->cell_facepos[c] = g->cell_facepos[0] - g->cell_facepos[c];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nhf = g->cell_facepos[0];
|
|
|
|
|
g->cell_facepos[0] = 0;
|
|
|
|
|
|
|
|
|
|
g->cell_faces = malloc(nhf * sizeof *g->cell_faces);
|
|
|
|
|
|
|
|
|
|
/* struct CornerpointGrid member */
|
|
|
|
|
G->cface_tag = malloc(nhf * sizeof *G->cface_tag );
|
|
|
|
|
|
|
|
|
|
if ((g->cell_faces == NULL) || (G->cface_tag == NULL)) {
|
|
|
|
|
free(G->cface_tag); G->cface_tag = NULL;
|
|
|
|
|
free(g->cell_faces); g->cell_faces = NULL;
|
|
|
|
|
free(g->cell_facepos); g->cell_facepos = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (g->cell_facepos != NULL) {
|
|
|
|
|
for (f = 0; f < g->number_of_faces; f++) {
|
|
|
|
|
tag = 2 * pg->face_tag[f]; /* [0, 2, 4] */
|
|
|
|
|
c1 = g->face_cells[2*f + 0];
|
|
|
|
|
c2 = g->face_cells[2*f + 1];
|
|
|
|
|
|
|
|
|
|
if (c1 >= 0) {
|
|
|
|
|
g->cell_faces[ g->cell_facepos[c1 + 1] ] = f;
|
|
|
|
|
|
|
|
|
|
/* struct CornerpointGrid member (!) */
|
|
|
|
|
G->cface_tag [ g->cell_facepos[c1 + 1] ] = tag + 1;
|
|
|
|
|
|
|
|
|
|
g->cell_facepos[c1 + 1] += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c2 >= 0) {
|
|
|
|
|
g->cell_faces[ g->cell_facepos[c2 + 1] ] = f;
|
|
|
|
|
|
|
|
|
|
/* struct CornerpointGrid member (!) */
|
|
|
|
|
G->cface_tag [ g->cell_facepos[c2 + 1] ] = tag + 0;
|
|
|
|
|
|
|
|
|
|
g->cell_facepos[c2 + 1] += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-12-02 10:38:07 +01:00
|
|
|
|
|
|
|
|
return g->cell_facepos != NULL;
|
2011-11-30 13:36:31 +01:00
|
|
|
}
|
2010-08-30 08:37:37 +00:00
|
|
|
|
2011-12-14 10:48:23 +01:00
|
|
|
static int
|
|
|
|
|
allocate_geometry(struct UnstructuredGrid *g)
|
|
|
|
|
{
|
|
|
|
|
int ok;
|
|
|
|
|
size_t nc, nf, nd;
|
|
|
|
|
|
|
|
|
|
assert (g->dimensions == 3);
|
|
|
|
|
|
|
|
|
|
nc = g->number_of_cells;
|
|
|
|
|
nf = g->number_of_faces;
|
|
|
|
|
nd = 3;
|
|
|
|
|
|
|
|
|
|
g->face_areas = malloc(nf * 1 * sizeof *g->face_areas);
|
|
|
|
|
g->face_centroids = malloc(nf * nd * sizeof *g->face_centroids);
|
|
|
|
|
g->face_normals = malloc(nf * nd * sizeof *g->face_normals);
|
|
|
|
|
|
|
|
|
|
g->cell_volumes = malloc(nc * 1 * sizeof *g->cell_volumes);
|
|
|
|
|
g->cell_centroids = malloc(nc * nd * sizeof *g->cell_centroids);
|
|
|
|
|
|
|
|
|
|
ok = g->face_areas != NULL;
|
|
|
|
|
ok += g->face_centroids != NULL;
|
|
|
|
|
ok += g->face_normals != NULL;
|
|
|
|
|
|
|
|
|
|
ok += g->cell_volumes != NULL;
|
|
|
|
|
ok += g->cell_centroids != NULL;
|
|
|
|
|
|
|
|
|
|
return ok == 5;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-30 12:41:29 +01:00
|
|
|
void preprocess (const struct grdecl *in,
|
|
|
|
|
double tol,
|
2011-11-30 11:08:32 +01:00
|
|
|
struct CornerpointGrid *G)
|
2010-08-30 08:37:37 +00:00
|
|
|
{
|
2011-12-14 10:48:23 +01:00
|
|
|
int ok;
|
2011-11-30 11:08:32 +01:00
|
|
|
struct processed_grid pg;
|
|
|
|
|
struct UnstructuredGrid *base;
|
|
|
|
|
|
|
|
|
|
base = (struct UnstructuredGrid *) G;
|
|
|
|
|
|
2010-08-30 08:37:37 +00:00
|
|
|
process_grdecl(in, tol, &pg);
|
|
|
|
|
|
2011-11-30 12:41:29 +01:00
|
|
|
/*
|
|
|
|
|
* General grid interface
|
2010-08-30 08:37:37 +00:00
|
|
|
*/
|
2011-11-30 11:08:32 +01:00
|
|
|
base->dimensions = 3;
|
2010-08-30 08:37:37 +00:00
|
|
|
|
2011-11-30 11:08:32 +01:00
|
|
|
base->number_of_nodes = pg.number_of_nodes;
|
|
|
|
|
base->number_of_faces = pg.number_of_faces;
|
|
|
|
|
base->number_of_cells = pg.number_of_cells;
|
2010-08-30 08:37:37 +00:00
|
|
|
|
2011-11-30 11:08:32 +01:00
|
|
|
base->node_coordinates = pg.node_coordinates;
|
2010-08-30 08:37:37 +00:00
|
|
|
|
2011-11-30 11:08:32 +01:00
|
|
|
base->face_nodes = pg.face_nodes;
|
|
|
|
|
base->face_nodepos = pg.face_ptr;
|
|
|
|
|
base->face_cells = pg.face_neighbors;
|
2011-11-30 12:41:29 +01:00
|
|
|
|
2011-11-30 11:08:32 +01:00
|
|
|
base->face_centroids = NULL;
|
|
|
|
|
base->face_normals = NULL;
|
|
|
|
|
base->face_areas = NULL;
|
2011-11-30 12:41:29 +01:00
|
|
|
|
2011-11-30 13:36:31 +01:00
|
|
|
fill_cell_topology(&pg, G);
|
|
|
|
|
|
2011-11-30 11:08:32 +01:00
|
|
|
base->cell_centroids = NULL;
|
|
|
|
|
base->cell_volumes = NULL;
|
2010-08-30 08:37:37 +00:00
|
|
|
|
2011-12-19 13:27:54 +01:00
|
|
|
ok = allocate_geometry(base);
|
2010-08-30 08:37:37 +00:00
|
|
|
|
2011-11-30 12:41:29 +01:00
|
|
|
/*
|
|
|
|
|
* Cornerpoint grid interface
|
2010-08-30 08:37:37 +00:00
|
|
|
*/
|
2011-11-30 11:08:32 +01:00
|
|
|
G->cartdims[0] = pg.dimensions[0];
|
|
|
|
|
G->cartdims[1] = pg.dimensions[1];
|
|
|
|
|
G->cartdims[2] = pg.dimensions[2];
|
2010-08-30 08:37:37 +00:00
|
|
|
|
2011-11-30 11:08:32 +01:00
|
|
|
free(pg.face_tag);
|
|
|
|
|
|
|
|
|
|
G->index_map = pg.local_cell_index;
|
2010-08-30 08:37:37 +00:00
|
|
|
}
|
2011-11-30 12:41:29 +01:00
|
|
|
|
2011-11-30 11:08:32 +01:00
|
|
|
void free_cornerpoint_grid(struct CornerpointGrid *G)
|
2010-08-30 08:37:37 +00:00
|
|
|
{
|
2011-11-30 11:08:32 +01:00
|
|
|
free(G->grid.face_nodes);
|
|
|
|
|
free(G->grid.face_nodepos);
|
|
|
|
|
free(G->grid.face_cells);
|
|
|
|
|
free(G->grid.cell_facepos);
|
|
|
|
|
free(G->grid.cell_faces);
|
|
|
|
|
|
|
|
|
|
free(G->grid.node_coordinates);
|
|
|
|
|
free(G->grid.face_centroids);
|
|
|
|
|
free(G->grid.face_areas);
|
|
|
|
|
free(G->grid.face_normals);
|
|
|
|
|
free(G->grid.cell_centroids);
|
|
|
|
|
free(G->grid.cell_volumes);
|
|
|
|
|
|
|
|
|
|
free(G->index_map);
|
2011-11-30 13:36:31 +01:00
|
|
|
free(G->cface_tag);
|
2010-08-30 08:37:37 +00:00
|
|
|
}
|
2011-11-30 12:41:29 +01:00
|
|
|
|
2011-11-30 13:36:31 +01:00
|
|
|
void compute_geometry(struct CornerpointGrid *G)
|
2011-11-30 12:41:29 +01:00
|
|
|
{
|
2011-11-30 13:36:31 +01:00
|
|
|
struct UnstructuredGrid *g;
|
|
|
|
|
|
2011-12-14 10:48:23 +01:00
|
|
|
assert (G != NULL);
|
2011-11-30 13:36:31 +01:00
|
|
|
|
2011-12-14 10:48:23 +01:00
|
|
|
g = (struct UnstructuredGrid *) G;
|
2011-11-30 12:41:29 +01:00
|
|
|
|
2011-12-14 10:48:23 +01:00
|
|
|
assert (g->dimensions == 3);
|
2011-11-30 13:36:31 +01:00
|
|
|
|
2011-12-14 10:48:23 +01:00
|
|
|
assert (g->face_centroids != NULL);
|
|
|
|
|
assert (g->face_normals != NULL);
|
|
|
|
|
assert (g->face_areas != NULL);
|
|
|
|
|
assert (g->cell_centroids != NULL);
|
|
|
|
|
assert (g->cell_volumes != NULL);
|
|
|
|
|
|
|
|
|
|
compute_face_geometry(g->dimensions , g->node_coordinates,
|
|
|
|
|
g->number_of_faces, g->face_nodepos,
|
|
|
|
|
g->face_nodes, g->face_normals,
|
|
|
|
|
g->face_centroids, g->face_areas);
|
|
|
|
|
|
|
|
|
|
compute_cell_geometry(g->dimensions, g->node_coordinates,
|
|
|
|
|
g->face_nodepos, g->face_nodes,
|
|
|
|
|
g->face_cells, g->face_normals,
|
|
|
|
|
g->face_centroids, g->number_of_cells,
|
|
|
|
|
g->cell_facepos, g->cell_faces,
|
|
|
|
|
g->cell_centroids, g->cell_volumes);
|
2011-11-30 12:41:29 +01:00
|
|
|
}
|