From 04f9d46c10fd52b9e1274ec0b13a692433982e26 Mon Sep 17 00:00:00 2001 From: "Jostein R. Natvig" Date: Wed, 14 Dec 2011 09:30:25 +0100 Subject: [PATCH] Add tensor grid constructors. --- opm/core/utility/cart_grid.c | 86 +++++++++++++++++++++++++++++++++--- opm/core/utility/cart_grid.h | 16 ++++--- 2 files changed, 90 insertions(+), 12 deletions(-) diff --git a/opm/core/utility/cart_grid.c b/opm/core/utility/cart_grid.c index 34e95b46..678d44c2 100644 --- a/opm/core/utility/cart_grid.c +++ b/opm/core/utility/cart_grid.c @@ -43,11 +43,15 @@ create_cart_grid_3d(int nx, int ny, int nz) struct UnstructuredGrid *G; G = allocate_cart_grid_3d(nx, ny, nz); - if (G != NULL) + if (G == NULL) { - fill_cart_topology_3d(G, nx, ny, nz); - fill_cart_geometry_3d(G, nx, ny, nz); + fprintf(stderr, "Cannot allocate space for grid.\n"); + exit(EXIT_FAILURE); } + + fill_cart_topology_3d(G, nx, ny, nz); + fill_cart_geometry_3d(G, nx, ny, nz); + return G; } @@ -63,11 +67,80 @@ create_cart_grid_2d(int nx, int ny) struct UnstructuredGrid *G; G = allocate_cart_grid_2d(nx, ny); - if (G != NULL) + if (G == NULL) { - fill_cart_topology_2d(G, nx, ny); - fill_cart_geometry_2d(G, nx, ny); + fprintf(stderr, "Cannot allocate space for grid.\n"); + exit(EXIT_FAILURE); } + + fill_cart_topology_2d(G, nx, ny); + fill_cart_geometry_2d(G, nx, ny); + + return G; +} + +/* --------------------------------------------------------------------- */ + +struct UnstructuredGrid * +create_tensor_grid_2d(int nx, int ny, double x[], double y[]) +{ + int i,j; + + double *coord; + struct UnstructuredGrid *G; + + G = allocate_cart_grid_2d(nx, ny); + + if (G == NULL) + { + fprintf(stderr, "Cannot allocate space for grid.\n"); + exit(EXIT_FAILURE); + } + + fill_cart_topology_2d(G, nx, ny); + + coord = G->node_coordinates; + for (j=0; jnode_coordinates; + for (k=0; k -void -destroy_cart_grid(grid_t *G); +void destroy_cart_grid(grid_t *G); -struct UnstructuredGrid* -create_cart_grid(int nx, int ny, int nz); +struct UnstructuredGrid *create_cart_grid(int nx, int ny, int nz); + +struct UnstructuredGrid *create_cart_grid_2d(int nx, int ny); +struct UnstructuredGrid *create_cart_grid_3d(int nx, int ny, int nz); + +struct UnstructuredGrid *create_tensor_grid_2d(int nx, int ny, + double x[], double y[]); +struct UnstructuredGrid *create_tensor_grid_3d(int nx, int ny, int nz, + double x[], double y[], double z[]); -struct UnstructuredGrid* -create_cart_grid_2d(int nx, int ny); #ifdef __cplusplus }