This commit is contained in:
Kjetil Olsen Lye committed 2012-06-11 13:19:51 +02:00
commit ed87f6dde9
8 files changed
+544 -79

No files matched your search

+4 -3
View File
@@ -118,7 +118,8 @@ opm/core/transport/reorder/TransportModelCompressibleTwophase.cpp \
opm/core/transport/reorder/TransportModelTwophase.cpp \
opm/core/transport/reorder/reordersequence.cpp \
opm/core/transport/reorder/nlsolvers.c \
opm/core/transport/reorder/tarjan.c
opm/core/transport/reorder/tarjan.c \
opm/core/vag_format/vag.cpp
nobase_include_HEADERS = \
opm/core/eclipse/CornerpointChopper.hpp \
@@ -250,8 +251,8 @@ opm/core/transport/reorder/TransportModelCompressibleTwophase.hpp \
opm/core/transport/reorder/TransportModelTwophase.hpp \
opm/core/transport/reorder/nlsolvers.h \
opm/core/transport/reorder/reordersequence.h \
opm/core/transport/reorder/tarjan.h
opm/core/transport/reorder/tarjan.h \
opm/core/vag_format/vag.hpp
# ----------------------------------------------------------------------
# Optional library constituents.
+89 -15
View File
@@ -20,25 +20,27 @@
#include <opm/core/grid.h>
#include <stdlib.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,7 +55,79 @@ 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 ,
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;
+32
View File
@@ -20,6 +20,8 @@
#ifndef OPM_GRID_HEADER_INCLUDED
#define OPM_GRID_HEADER_INCLUDED
#include <stddef.h>
/**
* \file
*
@@ -58,6 +60,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 ----
*/
@@ -239,6 +249,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 );
#ifdef __cplusplus
}
#endif
+5 -60
View File
@@ -170,68 +170,13 @@ allocate_cart_grid(size_t ndims ,
size_t nfaces,
size_t nnodes)
{
size_t nel;
struct UnstructuredGrid *G;
size_t nfacenodes, ncellfaces;
G = create_grid_empty();
nfacenodes = nfaces * (2 * (ndims - 1));
ncellfaces = ncells * (2 * ndims);
if (G != NULL) {
/* Node fields ---------------------------------------- */
nel = nnodes * ndims;
G->node_coordinates = malloc(nel * sizeof *G->node_coordinates);
/* Face fields ---------------------------------------- */
nel = nfaces * (2 * (ndims - 1));
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 = ncells * (2 * ndims);
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;
return allocate_grid(ndims, ncells, nfaces,
nfacenodes, ncellfaces, nnodes);
}
+212
View File
@@ -0,0 +1,212 @@
/*===========================================================================
//
// File: vag.cpp
//
// Created: 2012-06-08 15:45:53+0200
//
// Authors: Knut-Andreas Lie <Knut-Andreas.Lie@sintef.no>
// Halvor M. Nilsen <HalvorMoll.Nilsen@sintef.no>
// Atgeirr F. Rasmussen <atgeirr@sintef.no>
// Xavier Raynaud <Xavier.Raynaud@sintef.no>
// Bård Skaflestad <Bard.Skaflestad@sintef.no>
//
//==========================================================================*/
/*
Copyright 2012 SINTEF ICT, Applied Mathematics.
Copyright 2012 Statoil ASA.
This file is part of the Open Porous Media Project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#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){
using namespace std;
//PosStruct pos_struct;
pos_struct.pos.resize(n+1);
pos_struct.pos[0]=0;
for(int i=0;i< n;++i){
int number;
is >> number ;
//cout <<number << endl;
pos_struct.pos[i+1]=pos_struct.pos[i]+number;
for(int j=0;j< number;++j){
int value;
is >> value;
// cout << value << " ";
pos_struct.value.push_back(value);
}
//cout << endl;
}
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;
while (!is.eof()) {
string keyword;
is >> keyword;
//cout << keyword<< endl;
if(keyword == "Number"){
string stmp;
is >> stmp;
if(stmp == "of"){
string entity;
is >> entity;
getline(is,stmp);
int number;
is >> number;
if(entity=="vertices"){
vag_grid.number_of_vertices=number;
}else if((entity=="volumes") || (entity=="control")){
vag_grid.number_of_volumes=number;
}else if(entity=="faces"){
vag_grid.number_of_faces=number;
}else if(entity=="edges"){
vag_grid.number_of_edges=number;
}
cout << "Found Number of: " << entity <<" " << number << endl;
} else {
cerr << "Wrong format: Not of after Number" << endl;
return;
}
}else{
// read geometry defined by vertices
if(keyword=="Vertices"){
int number;
is >> number;
vag_grid.vertices.resize(3*number);// assume 3d data
readVector(is,vag_grid.vertices);
}
// here starts the reding of all pos structures
else if(keyword=="Volumes->Faces" || keyword=="Volumes->faces"){
//vag_grid.volumes_to_faces=
int number;
is >> number;
readPosStruct(is,number,vag_grid.volumes_to_faces);
cout << "Volumes->Faces: Number of " << number << endl;
}else if(keyword=="Faces->edges" || keyword=="Faces->Edges" || keyword=="Faces->Edgess"){
int number;
is >> number;
//vag_grid.volumes_to_faces=
readPosStruct(is,number,vag_grid.faces_to_edges);
cout << "Faces->edges: Number of " << number << endl;
}else if(keyword=="Faces->Vertices" || keyword=="Faces->vertices"){
int number;
is >> number;
//vag_grid.volumes_to_faces=
readPosStruct(is,number,vag_grid.faces_to_vertices);
cout << "Faces->Vertices: Number of " << number << endl;
}else if(keyword=="Volumes->Vertices" || keyword=="Volumes->Verticess"){
int number;
is >> number;
//vag_grid.volumes_to_faces=
readPosStruct(is,number,vag_grid.volumes_to_vertices);
cout << "Volumes->Vertices: Number of " << number << endl;
}
// read simple mappings
else if(keyword=="Edge" || keyword=="Edges"){
int number;
is >> number;
vag_grid.edges.resize(2*number);
readVector(is,vag_grid.edges);
cout << "Edges: Number of " << number << endl;
}else if(keyword=="Faces->Volumes" || keyword=="Faces->Control"){
int number;
if(keyword=="Faces->Control"){
string vol;
is >> vol;
}
is >> number;
vag_grid.faces_to_volumes.resize(2*number);
readVector(is,vag_grid.faces_to_volumes);
cout << "Faces->Volumes: Number of " << number << endl;
}
// read material
else if(keyword=="Material"){
string snum;
is >> snum;
int number;
is >> number;
cout << "Material number " << number << endl;
// we read all the rest into doubles
while(!is.eof()){
double value;
is >> value;
//cout << value << endl;
vag_grid.material.push_back(value);
}
}else{
//cout << "keyword;
}
//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);
}
}
+129
View File
@@ -0,0 +1,129 @@
/*===========================================================================
//
// File: vag.hpp
//
// Created: 2012-06-08 15:46:23+0200
//
// Authors: Knut-Andreas Lie <Knut-Andreas.Lie@sintef.no>
// Halvor M. Nilsen <HalvorMoll.Nilsen@sintef.no>
// Atgeirr F. Rasmussen <atgeirr@sintef.no>
// Xavier Raynaud <Xavier.Raynaud@sintef.no>
// Bård Skaflestad <Bard.Skaflestad@sintef.no>
//
//==========================================================================*/
/*
Copyright 2012 SINTEF ICT, Applied Mathematics.
Copyright 2012 Statoil ASA.
This file is part of the Open Porous Media Project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_VAG_HPP_HEADER
#define OPM_VAG_HPP_HEADER
#include <opm/core/grid.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
namespace OPM
{
/**
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();
*/
struct PosStruct{
std::vector<int> pos;
std::vector<int> value;
};
/**
Structure to represent the unstructured vag grid format. The format is only for
3D grids.
*/
struct VAG{
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.
\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;
for(int i=0;i< int(vec.size());++i){
is >> vec[i];
}
}
/**
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 */
+4 -1
View File
@@ -21,7 +21,8 @@ test_readpolymer \
test_readvector \
test_sf2p \
test_writeVtkData \
unit_test
unit_test \
test_read_vag
bo_resprop_test_SOURCES = bo_resprop_test.cpp
monotcubicinterpolator_test_SOURCES = monotcubicinterpolator_test.cpp
@@ -41,6 +42,8 @@ test_readvector_SOURCES = test_readvector.cpp
test_sf2p_SOURCES = test_sf2p.cpp
test_writeVtkData_SOURCES = test_writeVtkData.cpp
unit_test_SOURCES = unit_test.cpp
test_read_vag_SOURCES = test_read_vag.cpp
test_read_vag_LDADD = $(LDADD)
if UMFPACK
noinst_PROGRAMS += test_cfs_tpfa
+69
View File
@@ -0,0 +1,69 @@
/*===========================================================================
//
// File: test_read_vag.cpp
//
// Created: 2012-06-08 15:44:43+0200
//
// Authors: Knut-Andreas Lie <Knut-Andreas.Lie@sintef.no>
// Halvor M. Nilsen <HalvorMoll.Nilsen@sintef.no>
// Atgeirr F. Rasmussen <atgeirr@sintef.no>
// Xavier Raynaud <Xavier.Raynaud@sintef.no>
// Bård Skaflestad <Bard.Skaflestad@sintef.no>
//
//==========================================================================*/
/*
Copyright 2012 SINTEF ICT, Applied Mathematics.
Copyright 2012 Statoil ASA.
This file is part of the Open Porous Media Project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <fstream>
#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)
{
using namespace std;
using namespace OPM;
std::string filename;
if (argc == 2) {
filename = argv[1];
} else {
std::cout << "\nUsage: test_read_vag filename\n";
exit( 1 );
}
ifstream is(filename.c_str());//"/home/hnil/heim/SVN/simmatlab/projects/clastic/utils/unstructuredgrids/data/3x3_w_layered-vag.dat");
//ifstream is("/home/hnil/heim/SVN/simmatlab/projects/clastic/utils/unstructuredgrids/data/test.txt");
//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);
}