Added convert function from vag grid to opm::unstructed. In the process it was added a convenience function to allocate unstructured grid in grid.h. Compute geometry is used to calculate the new geometry.

This commit is contained in:
Halvor M. Nilsen committed 2012-06-08 20:50:41 +02:00
1 parent 839920fab2
commit efc3cc3324
5 files changed
+144 -8

No files matched your search

+75 -1
View File
@@ -19,7 +19,7 @@
#include <opm/core/grid.h>
#include <stdlib.h>
#include <stdio.h>
void destroy_grid(struct UnstructuredGrid *g)
{
if (g!=NULL)
@@ -58,3 +58,77 @@ create_grid_empty(void)
return G;
}
struct UnstructuredGrid *
allocate_grid(size_t ndims ,
size_t ncells,
size_t nfaces,
size_t nfacenodes,
size_t ncellfaces,
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);
/* 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_centroids == NULL) ||
(G->face_normals == NULL) ||
(G->face_areas == NULL) ||
(G->cell_faces == NULL) ||
(G->cell_facepos == NULL) ||
(G->cell_centroids == NULL) ||
(G->cell_volumes == NULL) )
{
destroy_grid(G);
G = NULL;
}
}
return G;
}
+9 -1
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
@@ -238,6 +238,14 @@ void destroy_grid(struct UnstructuredGrid *g);
*/
struct UnstructuredGrid *
create_grid_empty(void);
struct UnstructuredGrid *
allocate_grid(size_t ndims ,
size_t ncells,
size_t nfaces,
size_t nfacenodes,
size_t ncellfaces,
size_t nnodes);
#ifdef __cplusplus
}
+45 -3
View File
@@ -34,9 +34,11 @@
*/
#include <opm/core/vag_format/vag.hpp>
#include <opm/core/grid/cornerpoint_grid.h>
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
namespace OPM
{
void readPosStruct(std::istream& is,int n,PosStruct& pos_struct){
@@ -57,12 +59,12 @@ namespace OPM
}
//cout << endl;
}
if(!(pos_struct.value.size()==pos_struct.pos[n])){
if(!(int(pos_struct.value.size())==pos_struct.pos[n])){
cerr << "Failed to read pos structure" << endl;
cerr << "pos_struct.value.size()" << pos_struct.value.size() << endl;
cerr << "pos_struct.pos[n+1]" << pos_struct.pos[n] << endl;
}
};
}
void readVagGrid(std::istream& is,OPM::VAG& vag_grid){
using namespace std;
using namespace OPM;
@@ -166,5 +168,45 @@ namespace OPM
//cout << "Found" << keyword << "Number of " << number << endl;
}
}
};
}
void vagToUnstructuredGrid(OPM::VAG& vag_grid,UnstructuredGrid& grid){
using namespace std;
using namespace OPM;
cout << "Converting grid" << endl;
grid.dimensions=3;
grid.number_of_cells=vag_grid.number_of_volumes;
grid.number_of_faces=vag_grid.number_of_faces;
grid.number_of_faces=vag_grid.number_of_faces;
// fill face_nodes
for(int i=0;i< int(vag_grid.faces_to_vertices.pos.size());++i){
grid.face_nodepos[i] = vag_grid.faces_to_vertices.pos[i];
}
for(int i=0;i< int(vag_grid.faces_to_vertices.value.size());++i){
grid.face_nodes[i] = vag_grid.faces_to_vertices.value[i]-1;
}
// fill cell_face
for(int i=0;i< int(vag_grid.volumes_to_faces.pos.size());++i){
grid.cell_facepos[i] = vag_grid.volumes_to_faces.pos[i];
}
for(int i=0;i< int(vag_grid.volumes_to_faces.value.size());++i){
grid.cell_faces[i] = vag_grid.volumes_to_faces.value[i]-1;
}
// fill face_cells
for(int i=0;i< int(vag_grid.faces_to_volumes.size());++i){
grid.face_cells[i] = vag_grid.faces_to_volumes[i]-1;
}
// fill node_cordinates. This is the only geometry given in the vag
for(int i=0;i< int(vag_grid.vertices.size());++i){
grid.node_coordinates[i] = vag_grid.vertices[i];
}
// informations in edges, faces_to_eges, faces_to_vertices, volume_to_vertices and materials
// is not used
cout << "Computing geometry" << endl;
compute_geometry(&grid);
}
}
+4 -3
View File
@@ -38,7 +38,7 @@
#include <opm/core/grid.h>
#include <iostream>
#include <fstream>
#include <string>
@@ -81,13 +81,14 @@ namespace OPM
template <typename T>
void readVector(std::istream& is,std::vector<T>& vec){
using namespace std;
for(int i=0;i< vec.size();++i){
for(int i=0;i< int(vec.size());++i){
is >> vec[i];
}
}
//PosStruct readPosStruct(std::istream& is,int n){
void readPosStruct(std::istream& is,int n,PosStruct& pos_struct);
void readPosStruct(std::istream& is,int n,PosStruct& pos_struct);
void vagToUnstructuredGrid(OPM::VAG& vag_grid,UnstructuredGrid& grid);
}
#endif /* OPM_VAG_HPP_HEADER */
+11
View File
@@ -37,6 +37,7 @@
#include <string>
#include <cstdlib>
#include <opm/core/vag_format/vag.hpp>
#include <opm/core/grid.h>
//#include "../config.h"
/* test reading of vag grid format */
int main(int argc, char** argv)
@@ -55,4 +56,14 @@ int main(int argc, char** argv)
//std::ofstream is("");
VAG vag_grid;
readVagGrid(is,vag_grid);
UnstructuredGrid *grid;// make a pointer, can it be avoided??
grid = allocate_grid(3,
vag_grid.number_of_volumes,
vag_grid.number_of_faces,
vag_grid.faces_to_vertices.value.size(),
vag_grid.volumes_to_faces.value.size(),
vag_grid.number_of_vertices);
vagToUnstructuredGrid(vag_grid,*grid);
destroy_grid(grid);
}