Add dataFile to Deck if loaded from file

If loaded from string keep empty
This commit is contained in:
Kjell W. Kongsvik 2016-04-20 10:25:35 +02:00
parent 1640ad0826
commit 5fb3a6fc53
8 changed files with 70 additions and 36 deletions

View File

@ -120,9 +120,17 @@ namespace Opm {
DeckView( limits.first, limits.second )
{}
Deck::Deck() : Deck( std::vector< DeckKeyword >() ) {}
Deck::Deck( std::vector< DeckKeyword >&& x ) : DeckView( x.begin(), x.end() ),
keywordList( std::move( x ) ) {}
Deck::Deck() :
Deck( std::vector< DeckKeyword >() )
{
m_hasDataFile = false;
}
Deck::Deck( std::vector< DeckKeyword >&& x ) :
DeckView( x.begin(), x.end() ),
keywordList( std::move( x ) ),
m_hasDataFile(false)
{}
void Deck::addKeyword( DeckKeyword&& keyword ) {
this->keywordList.push_back( std::move( keyword ) );
@ -187,4 +195,17 @@ namespace Opm {
this->activeUnits = std::unique_ptr< UnitSystem >( UnitSystem::newMETRIC() );
}
const std::string Deck::getDataFile() const {
return m_dataFile;
}
void Deck::setDataFile(const std::string& dataFile) {
m_hasDataFile = true;
m_dataFile = dataFile;
}
bool Deck::hasDataFile() const {
return m_hasDataFile;
}
}

View File

@ -25,6 +25,8 @@
#include <vector>
#include <string>
#include <boost/filesystem.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
#include <opm/parser/eclipse/Parser/MessageContainer.hpp>
@ -113,17 +115,24 @@ namespace Opm {
const UnitSystem& getDefaultUnitSystem() const;
const UnitSystem& getActiveUnitSystem() const;
const std::string getDataFile() const;
void setDataFile(const std::string& dataFile);
bool hasDataFile() const;
private:
Deck( std::vector< DeckKeyword >&& );
void initUnitSystem() const;
std::vector< DeckKeyword > keywordList;
mutable MessageContainer m_messageContainer;
mutable std::unique_ptr< UnitSystem > activeUnits;
mutable std::unique_ptr< UnitSystem > defaultUnits;
std::string m_dataFile;
bool m_hasDataFile;
};
typedef std::shared_ptr<Deck> DeckPtr;

View File

@ -153,3 +153,11 @@ BOOST_AUTO_TEST_CASE(keywordList_getbyindex_correctkeywordreturned) {
BOOST_CHECK_EQUAL("TRULSX", deck.getKeyword(2).name());
}
BOOST_AUTO_TEST_CASE(set_and_get_data_file) {
Deck deck;
BOOST_REQUIRE(!deck.hasDataFile());
std::string file("/path/to/file.DATA");
deck.setDataFile( file );
BOOST_CHECK_EQUAL(file, deck.getDataFile());
}

View File

@ -161,7 +161,11 @@ namespace Opm {
}
void EclipseState::initIOConfig(DeckConstPtr deck) {
m_ioConfig = std::make_shared<IOConfig>();
std::string df = "";
if (deck->hasDataFile()) {
df = deck->getDataFile();
}
m_ioConfig = std::make_shared<IOConfig>(df);
if (Section::hasGRID(*deck)) {
std::shared_ptr<const GRIDSection> gridSection = std::make_shared<const GRIDSection>(*deck);
m_ioConfig->handleGridSection(gridSection);

View File

@ -22,6 +22,7 @@
#include <iterator>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
@ -46,12 +47,15 @@ namespace Opm {
m_UNIFOUT(false),
m_FMTIN(false),
m_FMTOUT(false),
m_eclipse_input_path(input_path),
m_ignore_RPTSCHED_RESTART(false),
m_deck_filename(""),
m_output_enabled(true),
m_output_dir(".")
m_deck_filename(input_path),
m_output_enabled(true)
{
m_output_dir = boost::filesystem::path(input_path).parent_path().string();
if (m_output_dir.length() < 1) {
m_output_dir = ".";
}
m_base_name = boost::filesystem::path(input_path).stem().string();
}
bool IOConfig::getWriteEGRIDFile() const {
@ -350,12 +354,6 @@ namespace Opm {
return m_FMTOUT;
}
const std::string& IOConfig::getEclipseInputPath() const {
return m_eclipse_input_path;
}
void IOConfig::setWriteInitialRestartFile(bool writeInitialRestartFile) {
m_write_initial_RST_file = writeInitialRestartFile;
}
@ -453,10 +451,6 @@ namespace Opm {
return m_deck_filename;
}
void IOConfig::setDeckFileName(const std::string& deckFileName){
m_deck_filename = deckFileName;
}
bool IOConfig::getOutputEnabled(){
return m_output_enabled;
}
@ -473,4 +467,8 @@ namespace Opm {
m_output_dir = outputDir;
}
std::string IOConfig::getBaseName() {
return m_base_name;
}
} //namespace Opm

View File

@ -159,7 +159,6 @@ namespace Opm {
std::string getRestartFileName(const std::string& restart_base, int report_step, bool output) const;
std::string getDeckFileName();
void setDeckFileName(const std::string& deckFileName);
bool getOutputEnabled();
void setOutputEnabled(bool enabled);
@ -167,6 +166,8 @@ namespace Opm {
std::string getOutputDir();
void setOutputDir(const std::string& outputDir);
std::string getBaseName();
private:
void assertTimeMap(std::shared_ptr< const TimeMap > timemap);
@ -186,13 +187,13 @@ namespace Opm {
bool m_UNIFOUT;
bool m_FMTIN;
bool m_FMTOUT;
std::string m_eclipse_input_path;
bool m_ignore_RPTSCHED_RESTART;
int m_first_restart_step;
int m_first_rft_step;
std::string m_deck_filename;
bool m_output_enabled;
std::string m_output_dir;
std::string m_base_name;
struct restartConfig {
/*

View File

@ -467,23 +467,15 @@ BOOST_AUTO_TEST_CASE(IOConfigTest) {
BOOST_CHECK_EQUAL("", ioConfigPtr5->getDeckFileName());
std::string testString = "testString";
ioConfigPtr5->setDeckFileName(testString);
BOOST_CHECK_EQUAL(testString, ioConfigPtr5->getDeckFileName());
IOConfigPtr ioConfigPtr6 = std::make_shared<IOConfig>(testString);
BOOST_CHECK_EQUAL(testString, ioConfigPtr6->getDeckFileName());
BOOST_CHECK_EQUAL(".", ioConfigPtr6->getOutputDir());
IOConfigPtr ioConfigPtr6;
BOOST_CHECK_NO_THROW(ioConfigPtr6 = std::make_shared<IOConfig>());
BOOST_CHECK_EQUAL(true, ioConfigPtr6->getOutputEnabled());
ioConfigPtr6->setOutputEnabled(false);
BOOST_CHECK_EQUAL(false, ioConfigPtr6->getOutputEnabled());
IOConfigPtr ioConfigPtr7;
BOOST_CHECK_NO_THROW(ioConfigPtr7 = std::make_shared<IOConfig>());
BOOST_CHECK_EQUAL(".", ioConfigPtr7->getOutputDir());
std::string testDir = "testDir";
ioConfigPtr7->setOutputDir(testDir);
BOOST_CHECK_EQUAL(testDir, ioConfigPtr7->getOutputDir());
std::string absTestPath = "/path/to/testString.DATA";
IOConfigPtr ioConfigPtr7 = std::make_shared<IOConfig>(absTestPath);
BOOST_CHECK_EQUAL(absTestPath, ioConfigPtr7->getDeckFileName());
BOOST_CHECK_EQUAL("/path/to", ioConfigPtr7->getOutputDir());
BOOST_CHECK_EQUAL("testString", ioConfigPtr7->getBaseName());
}

View File

@ -229,6 +229,7 @@ namespace Opm {
parserState->openRootFile( dataFileName );
parseState(parserState);
applyUnitsToDeck(*parserState->deck);
parserState->deck->setDataFile(dataFileName);
return parserState->deck;
}