From 8c321460936980b7e17c6ce36f84c624fdae52a1 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 24 Jul 2013 14:42:40 +0200 Subject: [PATCH 1/6] Rewritten EclipseGridParser to use input actnum instead of ACTNUM from deck --- opm/core/io/eclipse/EclipseGridParser.cpp | 6 +++--- opm/core/io/eclipse/EclipseGridParser.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/opm/core/io/eclipse/EclipseGridParser.cpp b/opm/core/io/eclipse/EclipseGridParser.cpp index c4bfda4d0..4f34dbcb4 100644 --- a/opm/core/io/eclipse/EclipseGridParser.cpp +++ b/opm/core/io/eclipse/EclipseGridParser.cpp @@ -966,7 +966,7 @@ ecl_grid_type * EclipseGridParser::newGrid( ) { } */ -void EclipseGridParser::saveEGRID( const std::string & filename) const { + void EclipseGridParser::saveEGRID( const std::string & filename , std::vector& actnum) const { bool endian_flip = true;//ECL_ENDIAN_FLIP; bool fmt_file; struct grdecl grdecl = get_grdecl(); @@ -994,7 +994,7 @@ void EclipseGridParser::saveEGRID( const std::string & filename) const { { ecl_kw_type * coord_kw = newEclKW( COORD_KW , ECL_FLOAT_TYPE ); ecl_kw_type * zcorn_kw = newEclKW( ZCORN_KW , ECL_FLOAT_TYPE ); - ecl_kw_type * actnum_kw = newEclKW( ACTNUM_KW , ECL_INT_TYPE ); + ecl_kw_type * actnum_kw = ecl_kw_alloc_new_shared( ACTNUM_KW , grdecl.dims[0] * grdecl.dims[1] * grdecl.dims[2] , ECL_INT_TYPE , &actnum ); ecl_kw_type * endgrid_kw = ecl_kw_alloc( ENDGRID_KW , 0 , ECL_INT_TYPE ); ecl_kw_fwrite( coord_kw , fortio ); @@ -1092,7 +1092,7 @@ void EclipseGridParser::saveEGRID_INIT( const std::string& output_dir , const st } #else -void EclipseGridParser::saveEGRID( const std::string & filename) const + void EclipseGridParser::saveEGRID( const std::string & filename, std::vector& actnum) const { static_cast(filename); // Suppress "unused variable" warning. THROW("Cannot write EGRID format without ERT library support. Reconfigure opm-core with ERT support and recompile."); diff --git a/opm/core/io/eclipse/EclipseGridParser.hpp b/opm/core/io/eclipse/EclipseGridParser.hpp index f9fddb23f..f193b21ed 100644 --- a/opm/core/io/eclipse/EclipseGridParser.hpp +++ b/opm/core/io/eclipse/EclipseGridParser.hpp @@ -226,7 +226,7 @@ public: struct grdecl get_grdecl() const; /// Save grid parts of deck in EGRID format. - void saveEGRID(const std::string & filename) const; + void saveEGRID(const std::string & filename, std::vector& actnum) const; #ifdef HAVE_ERT void saveEGRID_INIT( const std::string& output_dir , const std::string& basename, bool fmt_file = false); From 59b99f7444fceb8af91478bc0bd3777513b58883 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 24 Jul 2013 14:43:06 +0200 Subject: [PATCH 2/6] Added method saveEGRID() on GridManager --- opm/core/grid/GridManager.cpp | 15 +++++++++++++-- opm/core/grid/GridManager.hpp | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/opm/core/grid/GridManager.cpp b/opm/core/grid/GridManager.cpp index df93bdcb4..ef3ff20f2 100644 --- a/opm/core/grid/GridManager.cpp +++ b/opm/core/grid/GridManager.cpp @@ -115,7 +115,19 @@ namespace Opm } } - + void GridManager::saveEGRID(const std::string& filename , const Opm::EclipseGridParser& deck) { + int global_size = ug_->cartdims[0] * ug_->cartdims[1] * ug_->cartdims[2]; + std::vector actnum(global_size); + + if (ug_->global_cell) { + actnum.assign( actnum.size() , 0 ); + for (int c=0; c < ug_->number_of_cells; c++) + actnum[ug_->global_cell[c]] = 1; + } else + actnum.assign( actnum.size() , 1 ); + + deck.saveEGRID( "FILE.EGRID" , actnum ); + } /// Destructor. @@ -136,7 +148,6 @@ namespace Opm } - // Construct corner-point grid from deck. void GridManager::initFromDeckCornerpoint(const Opm::EclipseGridParser& deck) { diff --git a/opm/core/grid/GridManager.hpp b/opm/core/grid/GridManager.hpp index 38fb09d77..03666377b 100644 --- a/opm/core/grid/GridManager.hpp +++ b/opm/core/grid/GridManager.hpp @@ -65,6 +65,8 @@ namespace Opm /// Destructor. ~GridManager(); + void saveEGRID(const std::string& filename , const Opm::EclipseGridParser& deck); + /// Access the managed UnstructuredGrid. /// The method is named similarly to c_str() in std::string, /// to make it clear that we are returning a C-compatible struct. From 9cc3d4dd2d69b5904d940fa70b037e4c81d03090 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Thu, 25 Jul 2013 12:08:08 +0200 Subject: [PATCH 3/6] Changed EclipseGridParser::saveEGRID() to take globalCells as input --- opm/core/grid/GridManager.cpp | 12 +-- opm/core/io/eclipse/EclipseGridParser.cpp | 112 ++++++++++++---------- opm/core/io/eclipse/EclipseGridParser.hpp | 2 +- 3 files changed, 64 insertions(+), 62 deletions(-) diff --git a/opm/core/grid/GridManager.cpp b/opm/core/grid/GridManager.cpp index ef3ff20f2..6c35e1703 100644 --- a/opm/core/grid/GridManager.cpp +++ b/opm/core/grid/GridManager.cpp @@ -116,17 +116,7 @@ namespace Opm } void GridManager::saveEGRID(const std::string& filename , const Opm::EclipseGridParser& deck) { - int global_size = ug_->cartdims[0] * ug_->cartdims[1] * ug_->cartdims[2]; - std::vector actnum(global_size); - - if (ug_->global_cell) { - actnum.assign( actnum.size() , 0 ); - for (int c=0; c < ug_->number_of_cells; c++) - actnum[ug_->global_cell[c]] = 1; - } else - actnum.assign( actnum.size() , 1 ); - - deck.saveEGRID( "FILE.EGRID" , actnum ); + deck.saveEGRID( "FILE.EGRID" , ug_->number_of_cells , ug_->global_cell ); } diff --git a/opm/core/io/eclipse/EclipseGridParser.cpp b/opm/core/io/eclipse/EclipseGridParser.cpp index 4f34dbcb4..31dd798cb 100644 --- a/opm/core/io/eclipse/EclipseGridParser.cpp +++ b/opm/core/io/eclipse/EclipseGridParser.cpp @@ -966,54 +966,66 @@ ecl_grid_type * EclipseGridParser::newGrid( ) { } */ - void EclipseGridParser::saveEGRID( const std::string & filename , std::vector& actnum) const { - bool endian_flip = true;//ECL_ENDIAN_FLIP; - bool fmt_file; - struct grdecl grdecl = get_grdecl(); - fortio_type * fortio; + void EclipseGridParser::saveEGRID( const std::string & filename , int num_cells , const int * global_cell) const { + bool endian_flip = true;//ECL_ENDIAN_FLIP; + bool fmt_file; + struct grdecl grdecl = get_grdecl(); + fortio_type * fortio; + + if (!ecl_util_fmt_file( filename.c_str() , &fmt_file)) { + cerr << "Could not determine formatted/unformatted status of file:" << filename << " non-standard name?" << endl; + throw exception(); + } + + fortio = fortio_open_writer( filename.c_str() , fmt_file , endian_flip ); + { + float * mapaxes = NULL; + if (grdecl.mapaxes != NULL) { + mapaxes = new float[6]; + for (int i=0; i < 6; i++) + mapaxes[i]= grdecl.mapaxes[i]; + } + + ecl_grid_fwrite_EGRID_header( grdecl.dims , mapaxes , fortio ); + + if (grdecl.mapaxes != NULL) + delete[] mapaxes; + } - if (!ecl_util_fmt_file( filename.c_str() , &fmt_file)) { - cerr << "Could not determine formatted/unformatted status of file:" << filename << " non-standard name?" << endl; - throw exception(); - } - - fortio = fortio_open_writer( filename.c_str() , fmt_file , endian_flip ); - { - float * mapaxes = NULL; - if (grdecl.mapaxes != NULL) { - mapaxes = new float[6]; - for (int i=0; i < 6; i++) - mapaxes[i]= grdecl.mapaxes[i]; + { + ecl_kw_type * coord_kw = newEclKW( COORD_KW , ECL_FLOAT_TYPE ); + ecl_kw_type * zcorn_kw = newEclKW( ZCORN_KW , ECL_FLOAT_TYPE ); + ecl_kw_type * endgrid_kw = ecl_kw_alloc( ENDGRID_KW , 0 , ECL_INT_TYPE ); + + + ecl_kw_fwrite( coord_kw , fortio ); + ecl_kw_fwrite( zcorn_kw , fortio ); + if (global_cell) { + int global_size = grdecl.dims[0] * grdecl.dims[1] * grdecl.dims[2]; + ecl_kw_type * actnum_kw = ecl_kw_alloc( ACTNUM_KW , global_size , ECL_INT_TYPE ); + int * actnum_data = ecl_kw_get_int_ptr( actnum_kw ); + + ecl_kw_scalar_set_int( actnum_kw , 0 ); + for (int c=0; c < num_cells; c++) + actnum_data[global_cell[c]] = 1; + + ecl_kw_fwrite( actnum_kw , fortio ); + ecl_kw_free( actnum_kw ); + } + ecl_kw_fwrite( endgrid_kw , fortio ); + + ecl_kw_free( coord_kw ); + ecl_kw_free( zcorn_kw ); + ecl_kw_free( endgrid_kw ); + } + fortio_fclose( fortio ); } - - ecl_grid_fwrite_EGRID_header( grdecl.dims , mapaxes , fortio ); - - if (grdecl.mapaxes != NULL) - delete[] mapaxes; - } - { - ecl_kw_type * coord_kw = newEclKW( COORD_KW , ECL_FLOAT_TYPE ); - ecl_kw_type * zcorn_kw = newEclKW( ZCORN_KW , ECL_FLOAT_TYPE ); - ecl_kw_type * actnum_kw = ecl_kw_alloc_new_shared( ACTNUM_KW , grdecl.dims[0] * grdecl.dims[1] * grdecl.dims[2] , ECL_INT_TYPE , &actnum ); - ecl_kw_type * endgrid_kw = ecl_kw_alloc( ENDGRID_KW , 0 , ECL_INT_TYPE ); - - ecl_kw_fwrite( coord_kw , fortio ); - ecl_kw_fwrite( zcorn_kw , fortio ); - ecl_kw_fwrite( actnum_kw , fortio ); - ecl_kw_fwrite( endgrid_kw , fortio ); - ecl_kw_free( coord_kw ); - ecl_kw_free( zcorn_kw ); - ecl_kw_free( actnum_kw ); - ecl_kw_free( endgrid_kw ); - } - fortio_fclose( fortio ); -} + /** + Will query the deck for keyword @kw; and save it to the @fortio + instance if the keyword can be found. + */ -/** - Will query the deck for keyword @kw; and save it to the @fortio - instance if the keyword can be found. -*/ void EclipseGridParser::save_kw( fortio_type * fortio , const std::string & kw , ecl_type_enum ecl_type) { ecl_kw_type * ecl_kw = newEclKW( kw , ecl_type ); if (ecl_kw != NULL) { @@ -1092,12 +1104,12 @@ void EclipseGridParser::saveEGRID_INIT( const std::string& output_dir , const st } #else - void EclipseGridParser::saveEGRID( const std::string & filename, std::vector& actnum) const -{ - static_cast(filename); // Suppress "unused variable" warning. - THROW("Cannot write EGRID format without ERT library support. Reconfigure opm-core with ERT support and recompile."); -} - + void EclipseGridParser::saveEGRID( const std::string & filename, int num_cells , const int * global_cell) const + { + static_cast(filename); // Suppress "unused variable" warning. + THROW("Cannot write EGRID format without ERT library support. Reconfigure opm-core with ERT support and recompile."); + } + #endif // Read an imported fortio data file using Ert. diff --git a/opm/core/io/eclipse/EclipseGridParser.hpp b/opm/core/io/eclipse/EclipseGridParser.hpp index f193b21ed..d5d42349b 100644 --- a/opm/core/io/eclipse/EclipseGridParser.hpp +++ b/opm/core/io/eclipse/EclipseGridParser.hpp @@ -226,7 +226,7 @@ public: struct grdecl get_grdecl() const; /// Save grid parts of deck in EGRID format. - void saveEGRID(const std::string & filename, std::vector& actnum) const; + void saveEGRID(const std::string & filename, int num_cells , const int * global_cell) const; #ifdef HAVE_ERT void saveEGRID_INIT( const std::string& output_dir , const std::string& basename, bool fmt_file = false); From bdd587bf93e3d0fd36ad78b2fe6fce86f67b840f Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Tue, 30 Jul 2013 14:56:21 +0200 Subject: [PATCH 4/6] Minor merge fixup - sorry --- opm/core/io/eclipse/EclipseGridParser.cpp | 2 +- opm/core/io/eclipse/EclipseGridParser.hpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/opm/core/io/eclipse/EclipseGridParser.cpp b/opm/core/io/eclipse/EclipseGridParser.cpp index f0b1c1a1d..c5a365fa4 100644 --- a/opm/core/io/eclipse/EclipseGridParser.cpp +++ b/opm/core/io/eclipse/EclipseGridParser.cpp @@ -1020,7 +1020,7 @@ ecl_grid_type * EclipseGridParser::newGrid( ) { } fortio_fclose( fortio ); } -} + /** Will query the deck for keyword @kw; and save it to the @fortio diff --git a/opm/core/io/eclipse/EclipseGridParser.hpp b/opm/core/io/eclipse/EclipseGridParser.hpp index cf7c55439..82b969ab8 100644 --- a/opm/core/io/eclipse/EclipseGridParser.hpp +++ b/opm/core/io/eclipse/EclipseGridParser.hpp @@ -231,6 +231,7 @@ public: #ifdef HAVE_ERT //void saveEGRID_INIT( const std::string& output_dir , const std::string& basename, bool fmt_file = false); void saveINIT( const std::string & filename , const ecl_grid_type * ecl_grid); + void saveEGRID_INIT( const std::string& output_dir , const std::string& basename, bool fmt_file); ecl_grid_type * newGrid( ); #endif From f5ac9fc240f1c675583651dd1fceb9b54868a218 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Tue, 30 Jul 2013 15:37:49 +0200 Subject: [PATCH 5/6] Actually using filename argument in GridManager::saveEGRID --- opm/core/grid/GridManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/core/grid/GridManager.cpp b/opm/core/grid/GridManager.cpp index 6c35e1703..9cc23677d 100644 --- a/opm/core/grid/GridManager.cpp +++ b/opm/core/grid/GridManager.cpp @@ -116,7 +116,7 @@ namespace Opm } void GridManager::saveEGRID(const std::string& filename , const Opm::EclipseGridParser& deck) { - deck.saveEGRID( "FILE.EGRID" , ug_->number_of_cells , ug_->global_cell ); + deck.saveEGRID( filename , ug_->number_of_cells , ug_->global_cell ); } From 0595269934c7a343ca8c887d855b63a63aaded4e Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Tue, 30 Jul 2013 15:41:32 +0200 Subject: [PATCH 6/6] Added static_cast to avoid warnings about unused variables --- opm/core/io/eclipse/EclipseGridParser.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/opm/core/io/eclipse/EclipseGridParser.cpp b/opm/core/io/eclipse/EclipseGridParser.cpp index c5a365fa4..1bf9dcb69 100644 --- a/opm/core/io/eclipse/EclipseGridParser.cpp +++ b/opm/core/io/eclipse/EclipseGridParser.cpp @@ -1106,7 +1106,9 @@ void EclipseGridParser::saveEGRID_INIT( const std::string& output_dir , const st void EclipseGridParser::saveEGRID( const std::string & filename, int num_cells , const int * global_cell) const { - static_cast(filename); // Suppress "unused variable" warning. + static_cast(filename); // Suppress "unused variable" warning. + static_cast(num_cells); // Suppress "unused variable" warning. + static_cast(global_cell); // Suppress "unused variable" warning. THROW("Cannot write EGRID format without ERT library support. Reconfigure opm-core with ERT support and recompile."); }