Merge pull request #533 from joakim-hove/GDFILE-location

Update GDFILE hadling to parse DATA outside cwd
This commit is contained in:
Joakim Hove 2018-10-22 13:45:27 +02:00 committed by GitHub
commit eea23abedd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 10 deletions

View File

@ -147,6 +147,7 @@ namespace Opm {
const std::string& getInputPath() const;
const std::string& getDataFile() const;
void setDataFile(const std::string& dataFile);
std::string makeDeckPath(const std::string& path) const;
iterator begin();
iterator end();

View File

@ -65,7 +65,7 @@ namespace Opm {
private:
void init(const DeckKeyword& keyword);
void binary_init(const DeckKeyword& gdfile);
void binary_init(const Deck& deck);
};
}

View File

@ -217,6 +217,17 @@ namespace Opm {
return this->input_path;
}
std::string Deck::makeDeckPath(const std::string& path) const {
if (path.size() > 0 && path[0] == '/')
return path;
if (this->input_path.size() == 0)
return path;
else
return this->input_path + "/" + path;
}
void Deck::setDataFile(const std::string& dataFile) {
this->m_dataFile = dataFile;

View File

@ -297,8 +297,10 @@ namespace Opm {
void EclipseGrid::initBinaryGrid(const Deck& deck) {
const auto& gdfile_record = deck.getKeyword<ParserKeywords::GDFILE>().getRecord(0);
const std::string& filename = gdfile_record.getItem("filename").get<std::string>(0);
const DeckKeyword& gdfile_kw = deck.getKeyword("GDFILE");
const std::string& gdfile_arg = gdfile_kw.getRecord(0).getItem("filename").get<std::string>(0);
std::string filename = deck.makeDeckPath(gdfile_arg);
ecl_grid_type * grid_ptr = ecl_grid_load_case__( filename.c_str(), false);
if (grid_ptr)
this->m_grid.reset( grid_ptr );

View File

@ -49,7 +49,7 @@ namespace Opm {
else if (deck.hasKeyword("DIMENS"))
init(deck.getKeyword("DIMENS"));
else if (deck.hasKeyword("GDFILE"))
binary_init(deck.getKeyword("GDFILE"));
binary_init(deck);
else
throw std::invalid_argument("Must have either SPECGRID or DIMENS to indicate grid dimensions");
}
@ -137,8 +137,10 @@ namespace Opm {
m_nz = dims[2];
}
void GridDims::binary_init(const DeckKeyword& gdfile) {
const std::string& filename = gdfile.getRecord(0).getItem("filename").get<std::string>(0);
void GridDims::binary_init(const Deck& deck) {
const DeckKeyword& gdfile_kw = deck.getKeyword("GDFILE");
const std::string& gdfile_arg = gdfile_kw.getRecord(0).getItem("filename").get<std::string>(0);
std::string filename = deck.makeDeckPath(gdfile_arg);
ecl_grid_dims_type * grid_dims = ecl_grid_dims_alloc( filename.c_str(), nullptr );
if (grid_dims) {
const auto& dims = ecl_grid_dims_iget_dims(grid_dims, 0);
@ -146,7 +148,7 @@ namespace Opm {
m_ny = dims->ny;
m_nz = dims->nz;
} else
throw std::invalid_argument("Could not determine grid dimensions from " + filename);
throw std::invalid_argument("Could not determine grid dimensions from: " + filename);
}
}

View File

@ -167,10 +167,15 @@ BOOST_AUTO_TEST_CASE(set_and_get_data_file) {
Deck deck;
BOOST_CHECK_EQUAL("", deck.getDataFile());
BOOST_CHECK_EQUAL("", deck.getInputPath());
BOOST_CHECK_EQUAL("some/path", deck.makeDeckPath("some/path"));
BOOST_CHECK_EQUAL("/abs/path", deck.makeDeckPath("/abs/path"));
std::string file("/path/to/file.DATA");
deck.setDataFile( file );
BOOST_CHECK_EQUAL(file, deck.getDataFile());
BOOST_CHECK_EQUAL("/path/to", deck.getInputPath());
BOOST_CHECK_EQUAL("/path/to/some/path", deck.makeDeckPath("some/path"));
BOOST_CHECK_EQUAL("/abs/path", deck.makeDeckPath("/abs/path"));
deck.setDataFile("FILE");
BOOST_CHECK_EQUAL("FILE", deck.getDataFile());

View File

@ -23,6 +23,7 @@
#include <cstdio>
#include <numeric>
#define BOOST_TEST_MODULE EclipseGridTests
#include <boost/test/unit_test.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
@ -792,15 +793,21 @@ BOOST_AUTO_TEST_CASE(GDFILE) {
const char* gdfile_deck =
"GRID\n"
"GDFILE\n"
"CASE.EGRID /\n"
"'grid/CASE.EGRID' /\n"
"\n";
Opm::EclipseGrid grid1(createCPDeck());
test_work_area_type * work_area = test_work_area_alloc("GDFILE");
grid1.save("CASE.EGRID", Opm::UnitSystem::UnitType::UNIT_TYPE_METRIC);
util_mkdir_p("ecl/grid");
grid1.save("ecl/grid/CASE.EGRID", Opm::UnitSystem::UnitType::UNIT_TYPE_METRIC);
{
FILE * stream = fopen("ecl/DECK.DATA", "w");
fputs(gdfile_deck, stream);
fclose(stream);
}
{
Opm::Parser parser;
Opm::EclipseGrid grid2(parser.parseString(gdfile_deck, Opm::ParseContext() ));
Opm::EclipseGrid grid2(parser.parseFile("ecl/DECK.DATA", Opm::ParseContext() ));
BOOST_CHECK(grid1.equal(grid2));
}
test_work_area_free( work_area );