diff --git a/makefile b/makefile new file mode 100644 index 00000000..9664f7bc --- /dev/null +++ b/makefile @@ -0,0 +1,39 @@ +PEDANTIC=-W -Wall -pedantic # -W -Wformat-nonliteral \ + #-Wcast-align -Wpointer-arith -Wbad-function-cast \ + #-Wmissing-prototypes -Wstrict-prototypes \ + #-Wmissing-declarations -Winline -Wundef -Wnested-externs\ + #-Wcast-qual -Wshadow -Wconversion -Wwrite-strings\ + #-Wno-conversion -Wchar-subscripts -Wredundant-decls\ + + + +GCC = gcc -fPIC +CC = $(GCC) +INC = -I. + +#rememeber export LD_LIBRARY_PATH=/home/jrn/devel/c/repo/preprocess +LIB = -L. +CFLAGS = -g $(INC) -Wall $(PEDANTIC) +SHELL = /bin/bash +DEFAULT_LIB_INSTALL_PATH = /home/jrn/devel/c/repo/opm-gridprocessing +all: tags depend libpreprocess + +OBJ = preprocess.o uniquepoints.o facetopology.o sparsetable.o newinterface.o ../reorder-utils/grid.o + +libpreprocess: libpreprocess.so.1.0.1 +libpreprocess.so.1.0.1: $(OBJ) + $(CC) -shared -Wl,-soname,libpreprocess.so.1,\ + -rpath,$(DEFAULT_LIB_INSTALL_PATH) -o $@ $(OBJ) -lc $(LIB) + ln -s libpreprocess.so.1.0.1 libpreprocess.so.1 + ln -s libpreprocess.so.1 libpreprocess.so +.PHONY: clean depend all + +clean:; rm -f *~ $(OBJ) libpreprocess.so.1.0.1 libpreprocess.so.1 \ + libpreprocess.so TAGS; makedepend + +tags : $(OBJ:.o=.c) $(wildcard *.h) + etags *.c *.h + +depend :; makedepend $(INC) -f makefile *.c 2>/dev/null + +# DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/newinterface.c b/newinterface.c new file mode 100644 index 00000000..6cbb81dd --- /dev/null +++ b/newinterface.c @@ -0,0 +1,114 @@ +#include +#include "newinterface.h" + + + +static int *compute_cell_facepos(grid_t *g) +{ + int i,j,k; + int *facepos = malloc((g->number_of_cells + 1) * sizeof *facepos); + int *fcells = g->face_cells; + + for (i=0; inumber_of_cells; ++i) { + facepos [i] = 0; + } + + for (i=0; i<2*g->number_of_faces; ++i) { + if (*fcells != -1) { + (facepos[*fcells])++; + } + fcells++; + } + + /* cumsum */ + j=0; + for (i=0; inumber_of_cells; ++i) { + k = j + facepos[i]; + facepos[i] = j; + j = k; + } + facepos[i] = j; + + return facepos; +} + + +static int *compute_cell_faces(grid_t *g) +{ + int *cfaces = malloc(g->cell_facepos[g->number_of_cells] * sizeof *cfaces); + int *work = malloc(g->number_of_cells * sizeof *work); + int *fcells = g->face_cells; + int i,k,cell; + for(i=0; inumber_of_cells; ++i) { + work[i] = 0; + } + + for (i=0; inumber_of_faces; ++i) { + for (k=0;k<2; ++k) { + + if (*fcells != -1) { + cell = *fcells; + cfaces[g->cell_facepos[cell] + work[cell]] = i; + work[cell]++; + } + fcells++; + } + } + free(work); + + return cfaces; +} + +void preprocess (const struct grdecl *in, + double tol, + cornerpoint_grid_t *out) +{ + struct processed_grid pg; + process_grdecl(in, tol, &pg); + + /* + * General grid interface + */ + out->dimensions = 3; + + out->number_of_nodes = pg.number_of_nodes; + out->number_of_faces = pg.number_of_faces; + out->number_of_cells = pg.number_of_cells; + + out->node_coordinates = pg.node_coordinates; + + out->face_nodes = pg.face_nodes; + out->face_nodepos = pg.face_ptr; + out->face_cells = pg.face_neighbors; + + out->face_centroids = NULL; + out->face_normals = NULL; + out->face_areas = NULL; + + /* NB: compute_cell_facepos must be called before compute_cell_faces */ + out->cell_facepos = compute_cell_facepos((grid_t*) out); + out->cell_faces = compute_cell_faces ((grid_t*) out); + out->cell_centroids = NULL; + out->cell_volumes = NULL; + + + /* + * Cornerpoint grid interface + */ + out->cartdims[0] = pg.dimensions[0]; + out->cartdims[1] = pg.dimensions[1]; + out->cartdims[2] = pg.dimensions[2]; + + out->face_tag = pg.face_tag; + out->number_of_nodes_on_pillars = pg.number_of_nodes_on_pillars; + out->cartesian_cell_index = pg.local_cell_index; +} + +void free_cornerpoint_grid(cornerpoint_grid_t *g) +{ + free_grid((grid_t*) g); + + free(g->face_tag); + free(g->cartesian_cell_index); +} + diff --git a/newinterface.h b/newinterface.h new file mode 100644 index 00000000..dbc2ea42 --- /dev/null +++ b/newinterface.h @@ -0,0 +1,56 @@ +/*=========================================================================== +// +// File: preprocess.h +// +// Created: Fri Jun 19 08:43:04 2009 +// +// Author: Jostein R. Natvig +// +// $Date: 2010-08-27 19:12:16 +0200 (Fri, 27 Aug 2010) $ +// +// $Revision: 930 $ +// +//==========================================================================*/ + +/* + Copyright 2010 SINTEF ICT, Applied Mathematics. +*/ + +#ifndef NEWINTERFACE_H +#define NEWINTERFACE_H +#include "preprocess.h" +#include "../reorder-utils/grid.h" + +#ifdef __cplusplus +extern "C" { +#endif + + typedef struct { + /* + * Common grid definitions + */ + GRID_TOPOLOGY + GRID_GEOMETRY + + /* + * Special cornerpoint definitions + */ + int cartdims[3]; + enum face_tag *face_tag; + int number_of_nodes_on_pillars; + int *cartesian_cell_index; + + } cornerpoint_grid_t; + + + void preprocess (const struct grdecl *in, + double tol, + cornerpoint_grid_t *out); + + void free_cornerpoint_grid(cornerpoint_grid_t *g); + +#ifdef __cplusplus +} +#endif + +#endif