ERT-601: Added GridManager() constructor which takes a Parser::EclipseGrid instance

This commit is contained in:
Joakim Hove 2014-04-22 14:50:01 +02:00
parent b43b89063e
commit 0c9212a605
3 changed files with 81 additions and 2 deletions

View File

@ -18,6 +18,7 @@
*/
#include "config.h"
#include <opm/core/grid/GridManager.hpp>
#include <opm/core/io/eclipse/EclipseGridParser.hpp>
#include <opm/core/grid.h>
@ -55,6 +56,34 @@ namespace Opm
}
}
GridManager::GridManager(Opm::EclipseGridConstPtr eclipseGrid) {
struct grdecl g;
std::vector<int> actnum;
std::vector<double> coord;
std::vector<double> zcorn;
std::vector<double> mapaxes;
g.dims[0] = eclipseGrid->getNX();
g.dims[1] = eclipseGrid->getNY();
g.dims[2] = eclipseGrid->getNZ();
eclipseGrid->exportMAPAXES( mapaxes );
eclipseGrid->exportCOORD( coord );
eclipseGrid->exportZCORN( zcorn );
eclipseGrid->exportACTNUM( actnum );
g.coord = coord.data();
g.zcorn = zcorn.data();
g.actnum = actnum.data();
g.mapaxes = mapaxes.data();
ug_ = create_grid_cornerpoint(&g , 0.0);
if (!ug_) {
OPM_THROW(std::runtime_error, "Failed to construct grid.");
}
}
/// Construct a 3d corner-point grid from a deck.
GridManager::GridManager(Opm::DeckConstPtr newParserDeck)
{
@ -76,7 +105,7 @@ namespace Opm
initFromDeckTensorgrid(newParserDeck);
} else {
OPM_THROW(std::runtime_error, "Could not initialize grid from deck. "
"Need either ZCORN + COORD or DXV + DYV + DZV keywords.");
"Need either ZCORN + COORD or DXV + DYV + DZV keywords.");
}
}

View File

@ -21,6 +21,7 @@
#define OPM_GRIDMANAGER_HEADER_INCLUDED
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <string>
@ -49,6 +50,9 @@ namespace Opm
/// Construct a 3d corner-point grid or tensor grid from a deck.
explicit GridManager(Opm::DeckConstPtr newParserDeck);
/// Construct a grid from an EclipseState::EclipseGrid instance
explicit GridManager(Opm::EclipseGridConstPtr eclipseGrid);
/// Construct a 2d cartesian grid with cells of unit size.
GridManager(int nx, int ny);

View File

@ -21,9 +21,10 @@
#include <opm/core/grid.h>
#include <opm/core/grid/cornerpoint_grid.h> /* compute_geometry */
#include <opm/core/grid/GridManager.hpp> /* compute_geometry */
#include <opm/core/grid/cpgpreprocess/preprocess.h>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
using namespace std;
@ -52,6 +53,9 @@ BOOST_AUTO_TEST_CASE(Equal) {
Opm::DeckConstPtr deck1 = parser->parseFile( filename1 );
Opm::DeckConstPtr deck2 = parser->parseString( deck2Data );
BOOST_CHECK( deck1->hasKeyword("ZCORN") );
BOOST_CHECK( deck1->hasKeyword("COORD") );
Opm::GridManager grid1(deck1);
Opm::GridManager grid2(deck2);
@ -59,8 +63,50 @@ BOOST_AUTO_TEST_CASE(Equal) {
const UnstructuredGrid* cgrid2 = grid2.c_grid();
BOOST_CHECK( grid_equal( cgrid1 , cgrid1 ));
BOOST_CHECK( grid_equal( cgrid2 , cgrid2 ));
BOOST_CHECK( !grid_equal( cgrid1 , cgrid2 ));
}
BOOST_AUTO_TEST_CASE(EqualEclipseGrid) {
const std::string filename = "CORNERPOINT_ACTNUM.DATA";
Opm::ParserPtr parser(new Opm::Parser() );
Opm::DeckConstPtr deck = parser->parseFile( filename );
std::shared_ptr<Opm::RUNSPECSection> runspecSection(new Opm::RUNSPECSection(deck) );
std::shared_ptr<Opm::GRIDSection> gridSection(new Opm::GRIDSection(deck) );
std::shared_ptr<const Opm::EclipseGrid> grid(new Opm::EclipseGrid( runspecSection , gridSection ));
Opm::GridManager gridM(grid);
const UnstructuredGrid* cgrid1 = gridM.c_grid();
struct UnstructuredGrid * cgrid2;
{
struct grdecl g;
Opm::DeckKeywordConstPtr dimens = deck->getKeyword("DIMENS");
Opm::DeckKeywordConstPtr coord = deck->getKeyword("COORD");
Opm::DeckKeywordConstPtr zcorn = deck->getKeyword("ZCORN");
Opm::DeckKeywordConstPtr actnum = deck->getKeyword("ACTNUM");
g.dims[0] = dimens->getRecord(0)->getItem("NX")->getInt(0);
g.dims[1] = dimens->getRecord(0)->getItem("NY")->getInt(0);
g.dims[2] = dimens->getRecord(0)->getItem("NZ")->getInt(0);
g.coord = coord->getSIDoubleData().data();
g.zcorn = zcorn->getSIDoubleData().data();
g.actnum = actnum->getIntData().data();
g.mapaxes = NULL;
cgrid2 = create_grid_cornerpoint(&g , 0.0);
if (!cgrid2)
throw std::runtime_error("Failed to construct grid.");
}
BOOST_CHECK( grid_equal( cgrid1 , cgrid2 ));
destroy_grid( cgrid2 );
}