This commit is contained in:
Atgeirr Flø Rasmussen
2012-06-13 10:39:51 +02:00
4 changed files with 297 additions and 39 deletions

View File

@@ -39,6 +39,11 @@
#include <fstream>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <cassert>
#include <set>
#include <vector>
#include <map>
namespace OPM
{
void readPosStruct(std::istream& is,int n,PosStruct& pos_struct){
@@ -65,6 +70,24 @@ namespace OPM
cerr << "pos_struct.pos[n+1]" << pos_struct.pos[n] << endl;
}
}
void writePosStruct(std::ostream& os,PosStruct& pos_struct){
using namespace std;
//PosStruct pos_struct;
if(pos_struct.pos.size()==0){
return;
}
int n=pos_struct.pos.size()-1;
pos_struct.pos.resize(n+1);
pos_struct.pos[0]=0;
for(int i=0;i< n;++i){
int number=pos_struct.pos[i+1]-pos_struct.pos[i];
os << number << " ";
for(int j=0;j< number;++j){
os << pos_struct.value[pos_struct.pos[i]+j] << " ";
}
os << endl;
}
}
void readVagGrid(std::istream& is,OPM::VAG& vag_grid){
using namespace std;
using namespace OPM;
@@ -173,10 +196,13 @@ namespace OPM
using namespace std;
using namespace OPM;
cout << "Converting grid" << endl;
cout << "Warning:: orignial grid may not be edge confomal" << endl;
cout << " inverse mappings from edges will be wrong" << 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;
grid.number_of_nodes=vag_grid.number_of_vertices;
// 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];
@@ -205,8 +231,177 @@ namespace OPM
cout << "Computing geometry" << endl;
compute_geometry(&grid);
}
void unstructuredGridToVag(UnstructuredGrid& grid,OPM::VAG& vag_grid){
using namespace std;
using namespace OPM;
cout << "Converting grid" << endl;
// grid.dimensions=3;
vag_grid.number_of_volumes=grid.number_of_cells;
vag_grid.number_of_faces=grid.number_of_faces;
vag_grid.number_of_vertices=grid.number_of_nodes;
// resizing vectors
vag_grid.vertices.resize(grid.number_of_nodes*3);
vag_grid.faces_to_vertices.pos.resize(grid.number_of_faces+1);
vag_grid.faces_to_vertices.value.resize(grid.face_nodepos[grid.number_of_faces]);
vag_grid.faces_to_volumes.resize(2*grid.number_of_faces);
vag_grid.volumes_to_faces.pos.resize(grid.number_of_cells+1);
vag_grid.volumes_to_faces.value.resize(grid.cell_facepos[grid.number_of_cells]);//not known
// fill face_nodes
for(int i=0;i< int(vag_grid.faces_to_vertices.pos.size());++i){
vag_grid.faces_to_vertices.pos[i] = grid.face_nodepos[i];
}
for(int i=0;i< int(vag_grid.faces_to_vertices.value.size());++i){
vag_grid.faces_to_vertices.value[i] = grid.face_nodes[i] +1;
}
// fill cell_face
for(int i=0;i< int(vag_grid.volumes_to_faces.pos.size());++i){
vag_grid.volumes_to_faces.pos[i] = grid.cell_facepos[i];
}
for(int i=0;i< int(vag_grid.volumes_to_faces.value.size());++i){
vag_grid.volumes_to_faces.value[i] = grid.cell_faces[i] +1;
}
// fill face_cells
for(int i=0;i< int(vag_grid.faces_to_volumes.size());++i){
vag_grid.faces_to_volumes[i] = grid.face_cells[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){
vag_grid.vertices[i] = grid.node_coordinates[i];
}
// The missing field need to be constructed
// gennerate volume to vertice mapping
std::vector< std::set<int> > volumes_to_vertices(grid.number_of_cells);
for(int i=0;i < grid.number_of_cells; ++i){
int nlf=grid.cell_facepos[i+1]-grid.cell_facepos[i];
std::set<int> nodes;
for(int j=0; j < nlf; ++j){
int face = grid.cell_faces[grid.cell_facepos[i]+j];
int nlv = grid.face_nodepos[face+1]-grid.face_nodepos[face];
for(int k=0; k< nlv; ++k){
int node = grid.face_nodes[grid.face_nodepos[face]+k]+1;
nodes.insert(node);
}
}
volumes_to_vertices[i]=nodes;
}
// fill volume to vertice map
vag_grid.volumes_to_vertices.pos.resize(grid.number_of_cells+1);
vag_grid.volumes_to_vertices.value.resize(0);
vag_grid.volumes_to_vertices.pos[0]=0;
for(int i=0;i < grid.number_of_cells;++i){
int nv=volumes_to_vertices[i].size();
vag_grid.volumes_to_vertices.pos[i+1]=vag_grid.volumes_to_vertices.pos[i]+nv;
std::set<int>::iterator it;
for(it=volumes_to_vertices[i].begin();it!=volumes_to_vertices[i].end();++it){
vag_grid.volumes_to_vertices.value.push_back(*it);
}
}
std::set< std::set<int> > edges;
std::vector< std::vector< std::set<int> > > faces_spares;
int nfe=0;
faces_spares.resize(grid.number_of_faces);
for(int i=0;i < grid.number_of_faces;++i){
int ne=grid.face_nodepos[i+1]-grid.face_nodepos[i];
nfe=nfe+ne;
for(int j=0; j < ne-1;++j){
int node1=grid.face_nodes[grid.face_nodepos[i]+j]+1;
int node2=grid.face_nodes[grid.face_nodepos[i]+j+1]+1;
std::set<int> spair;
spair.insert(node1);
spair.insert(node2);
edges.insert(spair);
faces_spares[i].push_back(spair);
}
// add end segment
{
std::set<int> spair;
int node1=grid.face_nodes[grid.face_nodepos[i]+ne-1]+1;
int node2=grid.face_nodes[grid.face_nodepos[i]]+1;
spair.insert(node1);
spair.insert(node2);
edges.insert(spair);
faces_spares[i].push_back(spair);
}
}
// make edge numbering and fill edges
std::map<std::set<int>, int> edge_map;
std::set< std::set<int> >::iterator it;
vag_grid.edges.resize(0);
int k=0;
for(it=edges.begin(); it!=edges.end();++it){
edge_map.insert(std::pair< std::set<int> , int >(*it,k));
k=k+1;
std::set<int>::iterator sit;
for(sit=(*it).begin();sit!=(*it).end();++sit){
vag_grid.edges.push_back(*sit);
}
}
// fill face_to_egdes
vag_grid.number_of_edges=edges.size();
vag_grid.faces_to_edges.pos.resize(vag_grid.number_of_faces+1);
for(int i=0;i < grid.number_of_faces;++i){
int ne=grid.face_nodepos[i+1]-grid.face_nodepos[i];
vag_grid.faces_to_edges.pos[i+1]=vag_grid.faces_to_edges.pos[i]+ne;
for(int j=0;j<faces_spares[i].size();++j){
int edge_num=edge_map[faces_spares[i][j]];
vag_grid.faces_to_edges.value.push_back(edge_num+1);
}
}
// vag_grid.edges(0);//not known
// vag_grid.faces_to_edges// not known
// material // can not be extracted from the grid
}
void writeVagFormat(std::ostream& os,OPM::VAG& vag_grid){
using namespace std;
os << "File in the Vag grid format\n";
os << "Number of vertices " ;
os << vag_grid.number_of_vertices << endl;;
os <<"Number of control volume ";
os << vag_grid.number_of_volumes << endl;
os <<"Number of faces " ;
os << vag_grid.number_of_faces << endl;
os <<"Number of edges " ;
os << vag_grid.number_of_edges << endl;
os <<"Vertices " << vag_grid.vertices.size() << endl;
writeVector(os, vag_grid.vertices,3);
os << "Volumes->faces " << vag_grid.volumes_to_faces.pos.size()-1 << endl;
writePosStruct(os, vag_grid.volumes_to_faces);
os << "Volumes->Vertices " << vag_grid.volumes_to_vertices.pos.size()-1 << endl;
writePosStruct(os, vag_grid.volumes_to_vertices);
os << "Faces->edges " << vag_grid.faces_to_edges.pos.size()-1 << endl;
writePosStruct(os, vag_grid.faces_to_edges);
os << "Faces->vertices " << vag_grid.faces_to_vertices.pos.size()-1 << endl;
writePosStruct(os, vag_grid.faces_to_vertices);
os << "Faces->Control volumes " << floor(vag_grid.faces_to_volumes.size()/2) << endl;
writeVector(os,vag_grid.faces_to_volumes,2);
os << "Edges " << floor(vag_grid.edges.size()/2) << endl;
writeVector(os,vag_grid.edges,2);
/*
assert(vag_grid.material.size()%vag_grid.number_of_volumes==0);
int lines= floor(vag_grid.material.size()/vag_grid.number_of_volumes);
os << "Material number " << 1 << endl;
writeVector(os,vag_grid.material,lines);
*/
}
}

View File

@@ -43,6 +43,7 @@
#include <fstream>
#include <string>
#include <vector>
#include <cassert>
namespace OPM
{
/**
@@ -88,20 +89,21 @@ namespace OPM
/**
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.
\param[in] is is is stream of the file.
\param[out] vag_grid 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.
Function to write vag format.
\param[out] is is is stream of the file.
\param[in] vag_grid is a reference to a vag_grid struct.
*/
void writeVagFormat(std::ostream& os,OPM::VAG& vag_grid);
/**
Function to read a vector of some type from a stream.
\param[in] os is is stream of the file.
\param[out] vag_grid is a resized and filled vector containing the quantiy read.
*/
template <typename T>
void readVector(std::istream& is,std::vector<T>& vec){
@@ -110,20 +112,53 @@ namespace OPM
is >> vec[i];
}
}
/**
Function to write a vector of some type from a stream.
\param[in] os is is stream of the file.
\param[out] vag_grid is a resized and filled vector containing the quantiy read.
\param[in] n number of doubles on each line.
The function will only write full lines an potentially skip numbers at end of the vector.
*/
template <typename T>
void writeVector(std::ostream& os,std::vector<T>& vec,int n){
using namespace std;
int lines = floor(vec.size()/n);
assert(vec.size()%n==0);
for(int j=0;j< lines;++j){
for(int i=0;i< n;++i){
os << vec[j*n+i] << " ";
}
os << endl;
}
}
/**
Read pos struct type mapping from a stream
\param[in] stream
\param[in] number of lines to read
\param[out] reference to PosStruct
\param[in] is is stream
\param[in] n number of lines to read
\param[out] pos_struct reference to PosStruct
*/
void readPosStruct(std::istream& is,int n,PosStruct& pos_struct);
/**
Read pos struct type mapping from a stream
\param[in] os is stream to write to
\param[in] pos_struct to write
*/
void writePosStruct(std::ostream& os,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.
\param[out] vag_grid s is a valid vag_grid struct.
\param[in] grid is a grid with have allocated correct size to each pointer.
*/
void vagToUnstructuredGrid(OPM::VAG& vag_grid,UnstructuredGrid& grid);
/**
Fill a vag_grid from UnstructuredGrid
\param[out] vag_grid s is a valid vag_grid struct.
\param[in] grid is a grid with have allocated correct size to each pointer.
*/
void unstructuredGridToVag(UnstructuredGrid& grid, OPM::VAG& vag_grid);
}
#endif /* OPM_VAG_HPP_HEADER */

View File

@@ -17,33 +17,46 @@ sparsevector_test \
test_cartgrid \
test_column_extract \
test_lapack \
test_read_vag \
test_readpolymer \
test_readvector \
test_sf2p \
test_writeVtkData \
unit_test \
test_read_vag
unit_test
bo_resprop_test_SOURCES = bo_resprop_test.cpp
monotcubicinterpolator_test_SOURCES = monotcubicinterpolator_test.cpp
param_test_SOURCES = param_test.cpp
param_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LDADD)
param_test_LDADD = $(LDADD) $(BOOST_UNIT_TEST_FRAMEWORK_LIB)
sparsetable_test_SOURCES = sparsetable_test.cpp
sparsetable_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LDADD)
sparsetable_test_LDADD = $(LDADD) $(BOOST_UNIT_TEST_FRAMEWORK_LIB)
sparsevector_test_SOURCES = sparsevector_test.cpp
sparsevector_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LDADD)
sparsevector_test_LDADD = $(LDADD) $(BOOST_UNIT_TEST_FRAMEWORK_LIB)
test_cartgrid_SOURCES = test_cartgrid.cpp
test_column_extract_SOURCES = test_column_extract.cpp
test_column_extract_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LDADD)
test_column_extract_LDADD = $(LDADD) $(BOOST_UNIT_TEST_FRAMEWORK_LIB)
test_lapack_SOURCES = test_lapack.cpp
test_lapack_LDADD = $(LAPACK_LIBS) $(LDADD)
test_lapack_LDADD = $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS)
test_readpolymer_SOURCES = test_readpolymer.cpp
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)
test_readvector_SOURCES = test_readvector.cpp
test_sf2p_SOURCES = test_sf2p.cpp
test_writeVtkData_SOURCES = test_writeVtkData.cpp
unit_test_SOURCES = unit_test.cpp
if UMFPACK
noinst_PROGRAMS += test_cfs_tpfa

View File

@@ -54,16 +54,31 @@ int main(int argc, char** argv)
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);
//{
VAG vag_grid;
readVagGrid(is,vag_grid);
// Size of mappings found
std::cout << " faces_to_vertices " << vag_grid.faces_to_vertices.value.size() << endl;
std::cout << " volumes_to_faces " << vag_grid.volumes_to_vertices.value.size() << endl;
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);
//}
// {
std::cout << "*************************************************************\n";
VAG vag_grid_new;
unstructuredGridToVag(*grid,vag_grid_new);
writeVagFormat(std::cout,vag_grid_new);
// }
destroy_grid(grid);
}