relax strictness of the section handling and fix/work around a few bugs

We now do not require the sections to be correctly ordered and the
presence of the mandatory sections since even the unit tests did not
always specify all mandatory sections, which lead to a section
containing the rest of the deck if one of the expected next sections
was not specified.

also it seems like the DeckKeyword::getDeckIndex() does not correctly
work in some situations which lead

assert(deck->getKeyword(i)->name() == startKeyword);

to fail in the Section::populateKeywords() method. now the deck is
always sequentially traversed to find the position of a section's
start keyword. (This is necessary anyway if one wants to make sure
that the deck does not specify the same section more than once, a
feature which this patch also adds.)
This commit is contained in:
Andreas Lauser
2014-08-20 18:17:29 +02:00
parent e406e91629
commit 3566b99b85
2 changed files with 19 additions and 9 deletions

View File

@@ -20,6 +20,7 @@
#include <iostream>
#include <exception>
#include <algorithm>
#include <cassert>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Deck/Section.hpp>
@@ -32,13 +33,22 @@ namespace Opm {
void Section::populateKeywords(DeckConstPtr deck, const std::string& startKeyword,
const std::vector<std::string>& stopKeywords)
{
size_t i;
// find the first occurence of the section's start keyword
size_t i = 0;
for (; i<deck->size() && deck->getKeyword(i)->name() != startKeyword; i++);
for (i=deck->getKeyword(startKeyword)->getDeckIndex(); i<deck->size(); i++) {
if (i == deck->size())
throw std::invalid_argument(std::string("Deck requires a '")+startKeyword+"' section");
for (; i<deck->size(); i++) {
if (std::find(stopKeywords.begin(), stopKeywords.end(), deck->getKeyword(i)->name()) != stopKeywords.end())
break;
m_keywords.addKeyword(deck->getKeyword(i));
}
for (; i<deck->size(); i++)
if (deck->getKeyword(i)->name() == startKeyword)
throw std::invalid_argument(std::string("Deck contains the '")+startKeyword+"' section multiple times");
}
size_t Section::count(const std::string& keyword) const {

View File

@@ -58,37 +58,37 @@ namespace Opm {
class RUNSPECSection : public Section {
public:
RUNSPECSection(DeckConstPtr deck) : Section (deck, "RUNSPEC", std::vector<std::string>() = {"GRID"}) {}
RUNSPECSection(DeckConstPtr deck) : Section (deck, "RUNSPEC", std::vector<std::string>() = {"GRID", "EDIT", "PROPS", "REGIONS", "SOLUTION", "SUMMARY", "SCHEDULE"}) {}
};
class GRIDSection : public Section {
public:
GRIDSection(DeckConstPtr deck) : Section (deck, "GRID", std::vector<std::string>() = {"EDIT", "PROPS"}) {}
GRIDSection(DeckConstPtr deck) : Section (deck, "GRID", std::vector<std::string>() = {"RUNSPEC", "EDIT", "PROPS", "REGIONS", "SOLUTION", "SUMMARY", "SCHEDULE"}) {}
};
class EDITSection : public Section {
public:
EDITSection(DeckConstPtr deck) : Section (deck, "EDIT", std::vector<std::string>() = {"PROPS"}) {}
EDITSection(DeckConstPtr deck) : Section (deck, "EDIT", std::vector<std::string>() = {"RUNSPEC", "GRID", "PROPS", "REGIONS", "SOLUTION", "SUMMARY", "SCHEDULE"}) {}
};
class PROPSSection : public Section {
public:
PROPSSection(DeckConstPtr deck) : Section (deck, "PROPS", std::vector<std::string>() = {"REGIONS", "SOLUTION"}) {}
PROPSSection(DeckConstPtr deck) : Section (deck, "PROPS", std::vector<std::string>() = {"RUNSPEC", "GRID", "EDIT", "REGIONS", "SOLUTION", "SUMMARY", "SCHEDULE"}) {}
};
class REGIONSSection : public Section {
public:
REGIONSSection(DeckConstPtr deck) : Section (deck, "REGIONS", std::vector<std::string>() = {"SOLUTION"}) {}
REGIONSSection(DeckConstPtr deck) : Section (deck, "REGIONS", std::vector<std::string>() = {"RUNSPEC", "GRID", "EDIT", "PROPS", "SOLUTION", "SUMMARY", "SCHEDULE"}) {}
};
class SOLUTIONSection : public Section {
public:
SOLUTIONSection(DeckConstPtr deck) : Section (deck, "SOLUTION", std::vector<std::string>() = {"SUMMARY", "SCHEDULE"}) {}
SOLUTIONSection(DeckConstPtr deck) : Section (deck, "SOLUTION", std::vector<std::string>() = {"RUNSPEC", "GRID", "EDIT", "PROPS", "REGIONS", "SUMMARY", "SCHEDULE"}) {}
};
class SCHEDULESection : public Section {
public:
SCHEDULESection(DeckConstPtr deck) : Section (deck, "SCHEDULE", std::vector<std::string>() = {}) {}
SCHEDULESection(DeckConstPtr deck) : Section (deck, "SCHEDULE", std::vector<std::string>() = {"RUNSPEC", "GRID", "EDIT", "PROPS", "REGIONS", "SOLUTION", "SUMMARY"}) {}
};
}