Added then allocate_grid in grid and updated documentation in vag.hpp and grid.h

This commit is contained in:
Halvor M. Nilsen
2012-06-11 10:34:40 +02:00
parent efc3cc3324
commit 6287f53b2f
3 changed files with 115 additions and 57 deletions

View File

@@ -19,26 +19,28 @@
#include <opm/core/grid.h>
#include <stdlib.h>
#include <stdio.h>
void destroy_grid(struct UnstructuredGrid *g)
void
destroy_grid(struct UnstructuredGrid *g)
{
if (g!=NULL)
{
free(g->face_nodes);
free(g->face_nodepos);
free(g->face_cells);
free(g->cell_facepos);
free(g->cell_faces);
free(g->face_nodes);
free(g->face_nodepos);
free(g->face_cells);
free(g->cell_facepos);
free(g->cell_faces);
free(g->node_coordinates);
free(g->face_centroids);
free(g->face_areas);
free(g->face_normals);
free(g->cell_centroids);
free(g->cell_volumes);
free(g->node_coordinates);
free(g->face_centroids);
free(g->face_areas);
free(g->face_normals);
free(g->cell_centroids);
free(g->cell_volumes);
free(g->global_cell);
free(g->cell_facetag);
free(g->global_cell);
free(g->cell_facetag);
}
free(g);
@@ -53,82 +55,80 @@ create_grid_empty(void)
G = malloc(1 * sizeof *G);
if (G != NULL) {
*G = g;
*G = g;
}
return G;
}
struct UnstructuredGrid *
allocate_grid(size_t ndims ,
size_t ncells,
size_t nfaces,
allocate_grid(size_t ndims ,
size_t ncells ,
size_t nfaces ,
size_t nfacenodes,
size_t ncellfaces,
size_t nnodes)
size_t nnodes )
{
size_t nel;
struct UnstructuredGrid *G;
G = create_grid_empty();
if (G != NULL) {
/* Node fields ---------------------------------------- */
nel = nnodes * ndims;
G->node_coordinates = malloc(nel * sizeof *G->node_coordinates);
G->node_coordinates = malloc(nel * sizeof *G->node_coordinates);
/* Face fields ---------------------------------------- */
nel = nfacenodes;
G->face_nodes = malloc(nel * sizeof *G->face_nodes);
nel = nfaces + 1;
G->face_nodepos = malloc(nel * sizeof *G->face_nodepos);
nel = 2 * nfaces;
G->face_cells = malloc(nel * sizeof *G->face_cells);
nel = nfaces * ndims;
G->face_centroids = malloc(nel * sizeof *G->face_centroids);
nel = nfaces * ndims;
G->face_normals = malloc(nel * sizeof *G->face_normals);
nel = nfaces * 1;
G->face_areas = malloc(nel * sizeof *G->face_areas);
/* Cell fields ---------------------------------------- */
nel = ncellfaces;
G->cell_faces = malloc(nel * sizeof *G->cell_faces);
nel = ncells + 1;
G->cell_facepos = malloc(nel * sizeof *G->cell_facepos);
nel = ncells * ndims;
G->cell_centroids = malloc(nel * sizeof *G->cell_centroids);
nel = ncells * 1;
G->cell_volumes = malloc(nel * sizeof *G->cell_volumes);
if ((G->node_coordinates == NULL) ||
(G->face_nodes == NULL) ||
(G->face_nodepos == NULL) ||
(G->face_cells == NULL) ||
(G->face_cells == NULL) ||
(G->face_centroids == NULL) ||
(G->face_normals == NULL) ||
(G->face_areas == NULL) ||
(G->cell_faces == NULL) ||
(G->cell_facepos == NULL) ||
(G->cell_centroids == NULL) ||
(G->cell_centroids == NULL) ||
(G->cell_volumes == NULL) )
{
destroy_grid(G);
G = NULL;
}
}
return G;
}

View File

@@ -26,7 +26,7 @@
* Main OPM-Core grid data structure along with destructor and default
* constructor.
*/
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
@@ -58,6 +58,14 @@ struct UnstructuredGrid
void destroy_grid(struct UnstructuredGrid *g);
struct UnstructuredGrid *
allocate_grid(size_t ndims ,
size_t ncells ,
size_t nfaces ,
size_t nfacenodes,
size_t ncellfaces,
size_t nnodes );
---- end of synopsis of grid.h ----
*/
@@ -238,14 +246,28 @@ void destroy_grid(struct UnstructuredGrid *g);
*/
struct UnstructuredGrid *
create_grid_empty(void);
/**
Allocate and initialise an UnstructuredGrid where pointers are set to
location with correct size.
\param[in] ndims Number of physical dimensions.
\param[in] ncells Number of cells.
\param[in] nfaces Number of faces.
\param[in] nfacenodes Size of mapping from faces to nodes.
\param[in] ncellfaces Size of mapping from cells to faces.(i.e Number of halffaces)
\param[in] nnodes Number of Nodes
\return Fully formed UnstructuredGrid with all fields allocated, but not filled with
usefull numbers.
<code>NULL</code> in case of allocation failure.
*/
struct UnstructuredGrid *
allocate_grid(size_t ndims ,
size_t ncells,
size_t nfaces,
size_t nfacenodes,
size_t ncellfaces,
size_t nnodes);
allocate_grid(size_t ndims ,
size_t ncells ,
size_t nfaces ,
size_t nfacenodes,
size_t ncellfaces,
size_t nnodes );
#ifdef __cplusplus
}

View File

@@ -45,7 +45,8 @@
#include <vector>
namespace OPM
{
/* Struct to hold maping from the natural number less than pos.size()-1 to
/**
Struct to hold maping from the natural number less than pos.size()-1 to
a set of integers. value(pos(i):pos(i+1)-1) hold the integers corresponding to i.
pos(end)-1==value.size();
*/
@@ -53,31 +54,56 @@ namespace OPM
std::vector<int> pos;
std::vector<int> value;
};
/* Structure to represent the unstructured vag grid format
/**
Structure to represent the unstructured vag grid format. The format is only for
3D grids.
*/
struct VAG{
int number_of_vertices;
int number_of_vertices;
int number_of_volumes;
int number_of_faces;
int number_of_edges;
/** Vertices. The coordinates of vertice i is [vetices[3*i:3*i+2]*/
std::vector<double> vertices;
/** Mapping from volumes to faces */
PosStruct volumes_to_faces;
/** Mapping from volumes to vertices */
PosStruct volumes_to_vertices;
/** Mapping from faces to edges */
PosStruct faces_to_edges;
/** Mapping from faces to vertices */
PosStruct faces_to_vertices;
/** The edge i is given by the nodes edges[2*i:2*i+1] */
std::vector<int> edges;
/** The two neigbours of the face i is faces_to_volumes[2*i:2*i+1] */
std::vector<int> faces_to_volumes;
/** A vector containing information of each volume. The size is n*number_of_volumes.
For each i this is the information:
material[n*i] is the volume number and should be transformed to integer
material[n*i+1] is a tag and should be transformed to integer
material[n*i+2:n*(i+1)-1] represent propertices.
*/
std::vector<double> material;
};
/* Function the vag grid format and make a vag_grid struct. This structure
is intended to be converted to a grid*/
/**
Function the vag grid format and make a vag_grid struct. This structure
is intended to be converted to a grid.
\param[in] is is stream of the file.
\param[out] is a reference to a vag_grid struct.
*/
void readVagGrid(std::istream& is,OPM::VAG& vag_grid);
/*
/** Function to write vag format.
*/
void writeVagFormat(std::ostream& os){
using namespace std;
os << "File in the Vag grid format" << endl;
};
*/
/**
Function to read of some type from a stream.
\param[in] is is stream of the file.
\param[out] is a resized and filled vector containing the quantiy read.
*/
template <typename T>
void readVector(std::istream& is,std::vector<T>& vec){
using namespace std;
@@ -86,8 +112,18 @@ namespace OPM
}
}
//PosStruct readPosStruct(std::istream& is,int n){
/**
Read pos struct type mapping from a stream
\param[in] stream
\param[in] number of lines to read
\param[out] reference to PosStruct
*/
void readPosStruct(std::istream& is,int n,PosStruct& pos_struct);
/**
Fill a UnstructuredGrid from a vag_grid.
\param[in] a valid vag_grid struct.
\param[out] a grid with have allocated correct size to each pointer.
*/
void vagToUnstructuredGrid(OPM::VAG& vag_grid,UnstructuredGrid& grid);
}
#endif /* OPM_VAG_HPP_HEADER */