2013-03-21 15:37:40 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2013 Statoil ASA.
|
|
|
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
2013-04-08 10:36:14 +02:00
|
|
|
*/
|
2013-06-20 15:30:37 +02:00
|
|
|
#ifndef PARSER_KEYWORD_H
|
|
|
|
|
#define PARSER_KEYWORD_H
|
2013-03-21 15:37:40 +01:00
|
|
|
|
|
|
|
|
#include <string>
|
2013-09-13 22:23:12 +02:00
|
|
|
#include <iostream>
|
2013-12-02 13:07:01 +01:00
|
|
|
#include <memory>
|
2014-06-11 16:28:48 +02:00
|
|
|
#include <set>
|
2014-06-25 16:32:02 +02:00
|
|
|
|
2014-07-08 12:49:05 +02:00
|
|
|
#ifdef HAVE_REGEX
|
2014-07-07 17:50:46 +02:00
|
|
|
#include <regex>
|
|
|
|
|
#else
|
2014-06-25 16:32:02 +02:00
|
|
|
#include <boost/regex.hpp>
|
2014-07-07 17:50:46 +02:00
|
|
|
#endif
|
2014-06-25 16:32:02 +02:00
|
|
|
|
2013-07-30 14:10:07 +02:00
|
|
|
#include <opm/json/JsonObject.hpp>
|
|
|
|
|
|
2013-05-27 14:28:23 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
2013-12-10 17:35:20 +01:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
2014-04-01 09:05:33 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserFloatItem.hpp>
|
2013-10-08 13:46:55 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
2013-06-03 15:54:16 +02:00
|
|
|
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
|
2013-12-14 10:28:49 +01:00
|
|
|
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
|
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
|
|
|
|
|
2015-02-20 00:21:32 +01:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Util/ElasticVector.hpp>
|
2013-06-03 15:54:16 +02:00
|
|
|
|
2013-03-21 15:37:40 +01:00
|
|
|
|
|
|
|
|
namespace Opm {
|
2014-06-11 15:08:58 +02:00
|
|
|
class ParserKeyword;
|
|
|
|
|
typedef std::shared_ptr<ParserKeyword> ParserKeywordPtr;
|
|
|
|
|
typedef std::shared_ptr<const ParserKeyword> ParserKeywordConstPtr;
|
2013-04-08 10:36:14 +02:00
|
|
|
|
2013-06-20 15:30:37 +02:00
|
|
|
class ParserKeyword {
|
2014-06-11 15:08:58 +02:00
|
|
|
ParserKeyword(const std::string& name ,
|
|
|
|
|
const std::string& sizeKeyword ,
|
|
|
|
|
const std::string& sizeItem,
|
|
|
|
|
bool isTableCollection = false);
|
|
|
|
|
ParserKeyword(const std::string& name ,
|
2015-01-14 10:06:21 +01:00
|
|
|
ParserKeywordSizeEnum sizeType = SLASH_TERMINATED);
|
2014-06-11 15:08:58 +02:00
|
|
|
ParserKeyword(const std::string& name ,
|
2015-01-14 10:06:21 +01:00
|
|
|
size_t fixedKeywordSize);
|
2013-07-30 14:10:07 +02:00
|
|
|
ParserKeyword(const Json::JsonObject& jsonConfig);
|
2014-06-11 15:08:58 +02:00
|
|
|
|
|
|
|
|
public:
|
2014-06-11 16:28:48 +02:00
|
|
|
typedef std::set<std::string> DeckNameSet;
|
2014-08-29 18:52:09 +02:00
|
|
|
typedef std::set<std::string> SectionNameSet;
|
2014-06-11 16:28:48 +02:00
|
|
|
|
2014-06-11 15:08:58 +02:00
|
|
|
/*!
|
|
|
|
|
* \brief Factory method to create a keyword where the number
|
|
|
|
|
* of items per record is defined at compile time.
|
|
|
|
|
*
|
|
|
|
|
* This are for example well specifcation keywords like WCONPROD...
|
|
|
|
|
*/
|
|
|
|
|
static ParserKeywordPtr createFixedSized(const std::string& name,
|
2015-01-14 10:06:21 +01:00
|
|
|
size_t fixedKeywordSize);
|
2014-06-11 15:08:58 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Factory method to create a keyword with an per-se
|
|
|
|
|
* unspecified number of items per record.
|
|
|
|
|
*
|
|
|
|
|
* This are for example grid properties like PERM?...
|
|
|
|
|
*/
|
|
|
|
|
static ParserKeywordPtr createDynamicSized(const std::string& name,
|
2015-01-14 10:06:21 +01:00
|
|
|
ParserKeywordSizeEnum sizeType = SLASH_TERMINATED);
|
2014-06-11 15:08:58 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Factory method to create a keyword which has a
|
|
|
|
|
* dynamic number of items per record.
|
|
|
|
|
*
|
|
|
|
|
* But with the number of items are specified via an item of a
|
|
|
|
|
* different keyword, e.g. for tables.
|
|
|
|
|
*/
|
|
|
|
|
static ParserKeywordPtr createTable(const std::string& name,
|
|
|
|
|
const std::string& sizeKeyword,
|
|
|
|
|
const std::string& sizeItem,
|
|
|
|
|
bool isTableCollection = false);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Factory method to create a keyword from a JSON
|
|
|
|
|
* configuration object.
|
|
|
|
|
*/
|
|
|
|
|
static ParserKeywordPtr createFromJson(const Json::JsonObject& jsonConfig);
|
|
|
|
|
|
2014-09-02 17:26:07 +02:00
|
|
|
static std::string getDeckName(const std::string& rawString);
|
2014-06-11 16:28:48 +02:00
|
|
|
static bool validInternalName(const std::string& name);
|
2014-11-07 14:23:08 +01:00
|
|
|
static bool validDeckName(const std::string& name);
|
2014-06-25 16:32:02 +02:00
|
|
|
bool hasMatchRegex() const;
|
|
|
|
|
void setMatchRegex(const std::string& deckNameRegexp);
|
|
|
|
|
bool matches(const std::string& deckKeywordName) const;
|
2013-12-09 21:12:27 +01:00
|
|
|
bool hasDimension() const;
|
2015-02-20 00:21:32 +01:00
|
|
|
ParserRecordPtr getRecord(size_t recordIndex) const;
|
2013-05-06 12:13:49 +02:00
|
|
|
const std::string& getName() const;
|
2013-06-21 15:34:06 +02:00
|
|
|
size_t getFixedSize() const;
|
|
|
|
|
bool hasFixedSize() const;
|
2013-10-01 16:35:55 +02:00
|
|
|
bool isTableCollection() const;
|
2014-01-10 10:57:35 +01:00
|
|
|
std::string getDescription() const;
|
|
|
|
|
void setDescription(const std::string &description);
|
2013-10-01 16:35:55 +02:00
|
|
|
|
2013-08-23 00:20:22 +02:00
|
|
|
size_t numItems() const;
|
2014-06-11 16:28:48 +02:00
|
|
|
|
|
|
|
|
bool hasMultipleDeckNames() const;
|
|
|
|
|
void clearDeckNames();
|
|
|
|
|
void addDeckName( const std::string& deckName );
|
|
|
|
|
DeckNameSet::const_iterator deckNamesBegin() const;
|
|
|
|
|
DeckNameSet::const_iterator deckNamesEnd() const;
|
|
|
|
|
|
2014-08-29 18:52:09 +02:00
|
|
|
void clearValidSectionNames();
|
|
|
|
|
void addValidSectionName(const std::string& sectionName);
|
|
|
|
|
bool isValidSection(const std::string& sectionName) const;
|
|
|
|
|
SectionNameSet::const_iterator validSectionNamesBegin() const;
|
|
|
|
|
SectionNameSet::const_iterator validSectionNamesEnd() const;
|
|
|
|
|
|
2013-06-20 15:30:37 +02:00
|
|
|
DeckKeywordPtr parse(RawKeywordConstPtr rawKeyword) const;
|
2013-08-06 16:26:49 +02:00
|
|
|
enum ParserKeywordSizeEnum getSizeType() const;
|
2013-08-14 08:43:54 +02:00
|
|
|
const std::pair<std::string,std::string>& getSizeDefinitionPair() const;
|
2013-09-13 22:23:12 +02:00
|
|
|
void addItem( ParserItemConstPtr item );
|
2013-09-22 17:23:27 +02:00
|
|
|
void addDataItem( ParserItemConstPtr item );
|
|
|
|
|
bool isDataKeyword() const;
|
2013-09-13 22:23:12 +02:00
|
|
|
bool equal(const ParserKeyword& other) const;
|
2013-09-14 22:14:58 +02:00
|
|
|
void inlineNew(std::ostream& os , const std::string& lhs, const std::string& indent) const;
|
2014-12-09 11:26:27 +01:00
|
|
|
void applyUnitsToDeck(std::shared_ptr<const Deck> deck , std::shared_ptr<const DeckKeyword> deckKeyword) const;
|
2013-05-06 12:13:49 +02:00
|
|
|
private:
|
2013-08-14 08:43:54 +02:00
|
|
|
std::pair<std::string,std::string> m_sizeDefinitionPair;
|
2013-05-06 12:13:49 +02:00
|
|
|
std::string m_name;
|
2014-06-11 16:28:48 +02:00
|
|
|
DeckNameSet m_deckNames;
|
2014-08-29 18:52:09 +02:00
|
|
|
DeckNameSet m_validSectionNames;
|
2014-06-25 16:32:02 +02:00
|
|
|
std::string m_matchRegexString;
|
2014-07-08 12:49:05 +02:00
|
|
|
#ifdef HAVE_REGEX
|
2014-07-07 17:50:46 +02:00
|
|
|
std::regex m_matchRegex;
|
|
|
|
|
#else
|
|
|
|
|
boost::regex m_matchRegex;
|
|
|
|
|
#endif
|
2015-02-20 00:21:32 +01:00
|
|
|
ElasticVector<ParserRecordPtr> m_records;
|
2013-06-24 14:08:53 +02:00
|
|
|
enum ParserKeywordSizeEnum m_keywordSizeType;
|
|
|
|
|
size_t m_fixedSize;
|
2013-09-22 17:23:27 +02:00
|
|
|
bool m_isDataKeyword;
|
2013-10-01 16:35:55 +02:00
|
|
|
bool m_isTableCollection;
|
2014-01-10 10:57:35 +01:00
|
|
|
std::string m_Description;
|
2013-10-08 13:46:55 +02:00
|
|
|
|
2014-11-07 14:23:08 +01:00
|
|
|
static bool validNameStart(const std::string& name);
|
2014-06-11 16:28:48 +02:00
|
|
|
void initDeckNames( const Json::JsonObject& jsonConfig );
|
2014-08-29 18:52:09 +02:00
|
|
|
void initSectionNames( const Json::JsonObject& jsonConfig );
|
2014-06-25 16:32:02 +02:00
|
|
|
void initMatchRegex( const Json::JsonObject& jsonObject );
|
2013-09-22 17:23:27 +02:00
|
|
|
void initData( const Json::JsonObject& jsonConfig );
|
|
|
|
|
void initSize( const Json::JsonObject& jsonConfig );
|
2013-08-06 16:26:49 +02:00
|
|
|
void initSizeKeyword( const std::string& sizeKeyword, const std::string& sizeItem);
|
2013-10-01 17:13:40 +02:00
|
|
|
void initSizeKeyword(const Json::JsonObject& sizeObject);
|
2015-01-14 10:06:21 +01:00
|
|
|
void commonInit(const std::string& name, ParserKeywordSizeEnum sizeType);
|
2013-07-31 17:58:05 +02:00
|
|
|
void addItems( const Json::JsonObject& jsonConfig);
|
2014-10-21 17:29:11 +02:00
|
|
|
void initDoubleItemDimension( ParserDoubleItemPtr item, const Json::JsonObject itemConfig);
|
|
|
|
|
void initFloatItemDimension( ParserFloatItemPtr item, const Json::JsonObject itemConfig);
|
2013-05-06 12:13:49 +02:00
|
|
|
};
|
2013-03-21 15:37:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|