Integrate ImportContainer into the parser inner loop
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include <opm/common/OpmLog/OpmLog.hpp>
|
||||
#include <opm/common/OpmLog/LogUtil.hpp>
|
||||
#include <opm/common/utility/OpmInputError.hpp>
|
||||
#include <opm/parser/eclipse/Deck/ImportContainer.hpp>
|
||||
|
||||
#include <opm/json/JsonObject.hpp>
|
||||
|
||||
@@ -47,6 +48,7 @@
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeywords/I.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
@@ -382,13 +384,13 @@ class ParserState {
|
||||
InputStack input_stack;
|
||||
|
||||
std::map< std::string, std::string > pathMap;
|
||||
Opm::filesystem::path rootPath;
|
||||
|
||||
public:
|
||||
ParserKeywordSizeEnum lastSizeType = SLASH_TERMINATED;
|
||||
std::string lastKeyWord;
|
||||
|
||||
Deck deck;
|
||||
Opm::filesystem::path rootPath;
|
||||
std::unique_ptr<Python> python;
|
||||
const ParseContext& parseContext;
|
||||
ErrorGuard& errors;
|
||||
@@ -543,7 +545,7 @@ void ParserState::openRootFile( const Opm::filesystem::path& inputFile) {
|
||||
this->loadFile( inputFile );
|
||||
this->deck.setDataFile( inputFile.string() );
|
||||
const Opm::filesystem::path& inputFileCanonical = Opm::filesystem::canonical(inputFile);
|
||||
rootPath = inputFileCanonical.parent_path();
|
||||
this->rootPath = inputFileCanonical.parent_path();
|
||||
}
|
||||
|
||||
Opm::filesystem::path ParserState::getIncludeFilePath( std::string path ) const {
|
||||
@@ -936,12 +938,26 @@ bool parseState( ParserState& parserState, const Parser& parser ) {
|
||||
else
|
||||
throw std::logic_error("Cannot yet embed Python while still running Python.");
|
||||
}
|
||||
else
|
||||
parserState.deck.addKeyword( parserKeyword.parse( parserState.parseContext,
|
||||
parserState.errors,
|
||||
*rawKeyword,
|
||||
parserState.deck.getActiveUnitSystem(),
|
||||
parserState.deck.getDefaultUnitSystem()));
|
||||
else {
|
||||
auto deck_keyword = parserKeyword.parse( parserState.parseContext,
|
||||
parserState.errors,
|
||||
*rawKeyword,
|
||||
parserState.deck.getActiveUnitSystem(),
|
||||
parserState.deck.getDefaultUnitSystem());
|
||||
|
||||
if (deck_keyword.name() == ParserKeywords::IMPORT::keywordName) {
|
||||
bool formatted = deck_keyword.getRecord(0).getItem(1).get<std::string>(0)[0] == 'F';
|
||||
auto import_file = Opm::filesystem::path(deck_keyword.getRecord(0).getItem(0).get<std::string>(0));
|
||||
|
||||
if (import_file.is_relative())
|
||||
import_file = parserState.rootPath / import_file;
|
||||
|
||||
ImportContainer import(parser, parserState.deck.getActiveUnitSystem(), import_file.string(), formatted, parserState.deck.size());
|
||||
for (auto kw : import)
|
||||
parserState.deck.addKeyword(std::move(kw));
|
||||
} else
|
||||
parserState.deck.addKeyword( std::move(deck_keyword) );
|
||||
}
|
||||
} catch (const OpmInputError& opm_error) {
|
||||
throw;
|
||||
} catch (const std::exception& e) {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#define BOOST_TEST_MODULE ImportTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <opm/common/utility/FileSystem.hpp>
|
||||
|
||||
#include <opm/io/eclipse/EclOutput.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
@@ -30,7 +31,12 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserKeywords/I.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeywords/P.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeywords/Z.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
namespace fs = Opm::filesystem;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CreateImportContainer) {
|
||||
WorkArea work;
|
||||
@@ -65,3 +71,60 @@ BOOST_AUTO_TEST_CASE(CreateImportContainer) {
|
||||
|
||||
BOOST_CHECK_EQUAL(deck.size(), 3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ImportDeck) {
|
||||
const std::string deck_string = R"(
|
||||
RUNSPEC
|
||||
|
||||
DIMENS
|
||||
10 10 10 /
|
||||
|
||||
GRID
|
||||
|
||||
IMPORT
|
||||
'import/GRID' /
|
||||
|
||||
IMPORT
|
||||
'import/PROPS' /
|
||||
)";
|
||||
|
||||
WorkArea work;
|
||||
auto unit_system = UnitSystem::newMETRIC();
|
||||
const std::size_t nx = 10;
|
||||
const std::size_t ny = 10;
|
||||
const std::size_t nz = 10;
|
||||
|
||||
EclipseGrid grid(nx,ny,nz);
|
||||
fs::create_directory("import");
|
||||
fs::create_directory("cwd");
|
||||
grid.save("import/GRID", false, {}, unit_system);
|
||||
{
|
||||
EclIO::EclOutput output {"import/PROPS", false};
|
||||
|
||||
std::vector<double> poro{nx*ny*nz, 0.25};
|
||||
std::vector<float> perm{nx*ny*nz, 100};
|
||||
output.write<double>("PORO", poro);
|
||||
output.write<float>("PERMX", perm);
|
||||
output.write<float>("PERMY", perm);
|
||||
output.write<float>("PERMZ", perm);
|
||||
}
|
||||
|
||||
{
|
||||
FILE * stream = fopen("DECK.DATA", "w");
|
||||
fprintf(stream, "%s", deck_string.c_str());
|
||||
fclose(stream);
|
||||
}
|
||||
|
||||
fs::current_path( fs::path("cwd") );
|
||||
Parser parser;
|
||||
|
||||
auto deck = parser.parseFile( "../DECK.DATA" );
|
||||
|
||||
BOOST_CHECK( deck.hasKeyword<ParserKeywords::ZCORN>() );
|
||||
BOOST_CHECK( deck.hasKeyword<ParserKeywords::PERMX>() );
|
||||
BOOST_CHECK( deck.hasKeyword<ParserKeywords::PORO>() );
|
||||
BOOST_CHECK( !deck.hasKeyword<ParserKeywords::IMPORT>() );
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user