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>
|
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>
|
|
|
|
|
|
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,
|
|
|
|
|
ParserKeywordActionEnum action = INTERNALIZE ,
|
|
|
|
|
bool isTableCollection = false);
|
|
|
|
|
ParserKeyword(const std::string& name ,
|
|
|
|
|
ParserKeywordSizeEnum sizeType = SLASH_TERMINATED ,
|
|
|
|
|
ParserKeywordActionEnum action = INTERNALIZE);
|
|
|
|
|
ParserKeyword(const std::string& name ,
|
|
|
|
|
size_t fixedKeywordSize,
|
|
|
|
|
ParserKeywordActionEnum action = INTERNALIZE);
|
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-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,
|
|
|
|
|
size_t fixedKeywordSize,
|
|
|
|
|
ParserKeywordActionEnum action = INTERNALIZE);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \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,
|
|
|
|
|
ParserKeywordSizeEnum sizeType = SLASH_TERMINATED ,
|
|
|
|
|
ParserKeywordActionEnum action = INTERNALIZE);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \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,
|
|
|
|
|
ParserKeywordActionEnum action = INTERNALIZE,
|
|
|
|
|
bool isTableCollection = false);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Factory method to create a keyword from a JSON
|
|
|
|
|
* configuration object.
|
|
|
|
|
*/
|
|
|
|
|
static ParserKeywordPtr createFromJson(const Json::JsonObject& jsonConfig);
|
|
|
|
|
|
2014-06-11 16:28:48 +02:00
|
|
|
static bool validInternalName(const std::string& name);
|
|
|
|
|
static bool validDeckName(const std::string& name);
|
2013-12-01 09:25:52 +01:00
|
|
|
static bool wildCardName(const std::string& name);
|
2014-06-11 16:28:48 +02:00
|
|
|
bool matches(const std::string& deckKeyword) const;
|
2013-12-09 21:12:27 +01:00
|
|
|
bool hasDimension() const;
|
2013-08-26 15:17:52 +02:00
|
|
|
ParserRecordPtr getRecord() const;
|
2013-05-06 12:13:49 +02:00
|
|
|
const std::string& getName() const;
|
2013-10-08 13:46:55 +02:00
|
|
|
ParserKeywordActionEnum getAction() 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;
|
|
|
|
|
|
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;
|
2013-12-14 10:28:49 +01:00
|
|
|
void applyUnitsToDeck(std::shared_ptr<const Deck> deck , std::shared_ptr<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;
|
2013-07-31 15:02:00 +02:00
|
|
|
ParserRecordPtr m_record;
|
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;
|
2013-10-08 13:46:55 +02:00
|
|
|
ParserKeywordActionEnum m_action;
|
2014-01-10 10:57:35 +01:00
|
|
|
std::string m_Description;
|
2013-10-08 13:46:55 +02:00
|
|
|
|
2013-12-02 11:19:22 +01:00
|
|
|
static bool validNameStart(const std::string& name);
|
2014-06-11 16:28:48 +02:00
|
|
|
void initDeckNames( const Json::JsonObject& jsonConfig );
|
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);
|
2013-12-04 15:31:28 +01:00
|
|
|
void commonInit(const std::string& name, ParserKeywordSizeEnum sizeType , ParserKeywordActionEnum action);
|
2013-07-31 17:58:05 +02:00
|
|
|
void addItems( const Json::JsonObject& jsonConfig);
|
2014-04-01 09:05:33 +02:00
|
|
|
static void initDoubleItemDimension( ParserDoubleItemPtr item, const Json::JsonObject itemConfig);
|
|
|
|
|
static 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
|