示例#1
0
 const std::vector<DeckKeywordConstPtr>&  KeywordContainer::getKeywordList(const std::string& keyword) const {
     if (hasKeyword(keyword)) {
         const std::vector<DeckKeywordConstPtr>& keywordList = m_keywordMap.find(keyword)->second;
         return keywordList;
     } else
         throw std::invalid_argument("Keyword: " + keyword + " is not found in the container");
 }
示例#2
0
    RawKeywordPtr Parser::createRawKeyword(const DeckConstPtr deck, const std::string& filename , size_t lineNR , const std::string& keywordString, bool strictParsing) const {
        if (hasKeyword(keywordString)) {
            ParserKeywordConstPtr parserKeyword = m_parserKeywords.find(keywordString)->second;
            ParserKeywordActionEnum action = parserKeyword->getAction();
            
            if (action == THROW_EXCEPTION)
                throw std::invalid_argument("Parsing terminated by fatal keyword: " + keywordString);
            
            if (parserKeyword->getSizeType() == SLASH_TERMINATED)
                return RawKeywordPtr(new RawKeyword(keywordString , filename , lineNR));
            else {
                size_t targetSize;

                if (parserKeyword->hasFixedSize())
                    targetSize = parserKeyword->getFixedSize();
                else {
                    const std::pair<std::string, std::string> sizeKeyword = parserKeyword->getSizeDefinitionPair();
                    DeckKeywordConstPtr sizeDefinitionKeyword = deck->getKeyword(sizeKeyword.first);
                    DeckItemConstPtr sizeDefinitionItem;
                    {
                        DeckRecordConstPtr record = sizeDefinitionKeyword->getRecord(0);
                        sizeDefinitionItem = record->getItem(sizeKeyword.second);
                    }
                    targetSize = sizeDefinitionItem->getInt(0);
                }
                return RawKeywordPtr(new RawKeyword(keywordString, filename , lineNR , targetSize , parserKeyword->isTableCollection()));
            }
        } else {
            if (strictParsing) {
                throw std::invalid_argument("Keyword " + keywordString + " not recognized ");
            } else {
                return RawKeywordPtr(new RawKeyword(keywordString, filename , lineNR , 0));
            }
        }
    }
示例#3
0
 ParserKeywordConstPtr Parser::getKeyword(const std::string& keyword) const {
     if (hasKeyword(keyword)) {
         return m_parserKeywords.at(keyword);
     }
     else
         throw std::invalid_argument("Keyword: " + keyword + " does not exist");
 }
示例#4
0
    bool GridProperties<T>::addKeyword(const std::string& keywordName) {

        if (!supportsKeyword( keywordName ))
            throw std::invalid_argument("The keyword: " + keywordName + " is not supported in this container");

        if (hasKeyword(keywordName))
            return false;
        else {
            const std::string kw = normalize(keywordName);

            // if the property was already added auto generated, we just need to make it
            // non-auto generated
            if (m_autoGeneratedProperties.count(kw)) {
                OpmLog::warning("The keyword "+kw+" has been used to calculate the "
                                   "defaults of another keyword before the first time it was "
                                   "explicitly mentioned in the deck. Maybe you need to change "
                                   "the ordering of your keywords (move "+kw+" to the front?).");
                m_autoGeneratedProperties.erase(m_autoGeneratedProperties.find(kw));
                return true;
            }

            if (isFipxxx<T>(kw))
                m_supportedKeywords.emplace(kw, SupportedKeywordInfo( kw , 1, "1" ));

            insertKeyword( m_supportedKeywords.at( kw ) );
            return true;
        }
    }
示例#5
0
// parse a STATA command 
DwUseOptions* DwUseOptionParser::Parse(vector<string> words) {	

	// there are 10 keywords we expect to see
	string keys[] = {"variables", "if", "using", "limit",
					 "nulldata", "lowercase", "uppercase", 
					 "label_variable", "label_values", 
					 "username", "password", "database"};
	size_t nkeys(sizeof(keys) / sizeof(string));
	// create parser that accepts these keywords
	OptionParser* parser = new OptionParser( set<string>(keys, keys + nkeys) );

	// prepare another vector where we can search 

	// see if we have a using anywhere, if we do, the first part is the varlist, if not it is the tablename
	bool hasUsing = hasKeyword(words, "using");

	// if it contains using somewhere we can start with variables (if missing it will be an empty string, if the list is there it will be expected)
	if( !hasUsing ) 
		words.insert(words.begin(), "using"); 
	else if( lowerCase(words[0]) != "if" && lowerCase(words[0]) != "using" )
		words.insert(words.begin(), "variables");

	// parse the options
	map<string,string> options = parser->Parse( words );
	delete parser;

	// create a meaningful options object
	DwUseOptions* useOptions = new DwUseOptions( options );	
	return useOptions;
}
示例#6
0
 size_t KeywordContainer::numKeywords(const std::string& keyword) const{
     if (hasKeyword(keyword)) {
         const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
         return keywordList.size();
     } else
         return 0;
 }
示例#7
0
    bool addKeyword(const std::string& keywordName) {
        if (!supportsKeyword( keywordName ))
            throw std::invalid_argument("The keyword: " + keywordName + " is not supported in this container");

        if (hasKeyword(keywordName))
            return false;
        else {
            // if the property was already added auto generated, we just need to make it
            // non-auto generated
            if (m_autoGeneratedProperties_.count(keywordName)) {
                OpmLog::addMessage(Log::MessageType::Warning,
                                   "The keyword "+keywordName+" has been used to calculate the "
                                   "defaults of another keyword before the first time it was "
                                   "explicitly mentioned in the deck. Maybe you need to change "
                                   "the ordering of your keywords (move "+keywordName+" to the "
                                   "front?).");
                m_autoGeneratedProperties_.erase(m_autoGeneratedProperties_.find(keywordName));
                return true;
            }

            auto supportedKeyword = m_supportedKeywords.at( keywordName );
            int nx = m_eclipseGrid->getNX();
            int ny = m_eclipseGrid->getNY();
            int nz = m_eclipseGrid->getNZ();
            std::shared_ptr<GridProperty<T> > newProperty(new GridProperty<T>(nx , ny , nz , supportedKeyword));

            m_properties.insert( std::pair<std::string , std::shared_ptr<GridProperty<T> > > ( keywordName , newProperty ));
            m_property_list.push_back( newProperty );
            return true;
        }
    }
示例#8
0
    GridProperty<T>& GridProperties<T>::getKeyword(const std::string& keyword) {
        const std::string kw = normalize(keyword);

        if (!hasKeyword(kw))
            addAutoGeneratedKeyword_(kw);

        return m_properties.at( kw );
    }
示例#9
0
 std::shared_ptr<GridProperty<T> > getInitializedKeyword(const std::string& keyword) const {
     if (hasKeyword(keyword))
         return m_properties.at( keyword );
     else {
         if (supportsKeyword(keyword))
             throw std::invalid_argument("Keyword: " + keyword + " is supported - but not initialized.");
         else
             throw std::invalid_argument("Keyword: " + keyword + " is not supported.");
     }
 }
示例#10
0
    void GridProperties<T>::handleMINVALUERecord( const DeckRecord& record, BoxManager& boxManager) {
        const std::string& field = record.getItem("field").get< std::string >(0);

        if (hasKeyword( field )) {
            GridProperty<T>& property = getKeyword( field );
            T value  = convertInputValue( property, record.getItem("value").get< double >(0) );
            setKeywordBox(record, boxManager);
            property.minvalue( value , boxManager.getActiveBox() );
        } else
            throw std::invalid_argument("Fatal error processing MINVALUE keyword. Tried to limit not defined keyword " + field);
    }
示例#11
0
    void KeywordLoader::addKeyword(std::shared_ptr<ParserKeyword> keyword , const std::string& jsonFile) {
        const std::string& name = keyword->getName();

        if (hasKeyword(name)) {
            m_keywords[name] = keyword;
            m_jsonFile[name] = jsonFile;
        } else {
            m_keywords.insert( std::pair<std::string , std::shared_ptr<ParserKeyword> > (name , keyword) );
            m_jsonFile.insert( std::pair<std::string , std::string> ( name , jsonFile));
        }
    }
示例#12
0
 void KeywordContainer::addKeyword(DeckKeywordConstPtr keyword) {
     m_keywordList.push_back(keyword);
     
     if (!hasKeyword(keyword->name())) {
         m_keywordMap[keyword->name()] = std::vector<DeckKeywordConstPtr>();
     }
     
     {
         std::vector<DeckKeywordConstPtr>& keywordList = m_keywordMap[keyword->name()];
         keywordList.push_back(keyword);
     }
 }
示例#13
0
    void GridProperties<T>::assertKeyword(const std::string& keyword) const {
        const std::string kw = normalize(keyword);

        if ( !( hasKeyword( kw ) || isDefaultInitializable( kw ) || isFipxxx<T>( kw ) ) )
           throw std::invalid_argument("Keyword: " + keyword +
                                       " is not yet defined and could not be default initialized");

        if (m_properties.count( kw ) == 0)
            addAutoGeneratedKeyword_(kw);

        GridProperty<T>& property = m_properties.at( kw );
        property.runPostProcessor( );
    }
示例#14
0
    void GridProperties<T>::handleCOPYRecord( const DeckRecord& record, BoxManager& boxManager) {
        const std::string& srcField = record.getItem("src").get< std::string >(0);
        const std::string& targetField = record.getItem("target").get< std::string >(0);

        if (hasKeyword( srcField )) {
            setKeywordBox(record, boxManager);
            copyKeyword( srcField , targetField , boxManager.getActiveBox() );
        } else {
            if (!supportsKeyword( srcField))
                throw std::invalid_argument("Fatal error processing COPY keyword."
                                            " Tried to copy from not defined keyword " + srcField);
        }
    }
示例#15
0
文件: Deck.cpp 项目: alfbr/opm-common
    const std::vector< const DeckKeyword* > DeckView::getKeywordList( const std::string& keyword ) const {
        if( !hasKeyword( keyword ) ) return {};

        const auto& indices = this->offsets( keyword );

        std::vector< const DeckKeyword* > ret;
        ret.reserve( indices.size() );

        for( size_t i : indices )
            ret.push_back( &this->getKeyword( i ) );

        return ret;
    }
示例#16
0
    void Parser::parseFile(DeckPtr deck, const boost::filesystem::path& file, const boost::filesystem::path& rootPath, bool parseStrict) const {
        bool verbose = false;
        std::ifstream inputstream;
        size_t lineNR = 0;
        inputstream.open(file.string().c_str());

        if (inputstream) {
            RawKeywordPtr rawKeyword;
            
            while (tryParseKeyword(deck, file.string() , lineNR , inputstream, rawKeyword, parseStrict)) {
                if (rawKeyword->getKeywordName() == Opm::RawConsts::include) {
                    RawRecordConstPtr firstRecord = rawKeyword->getRecord(0);
                    std::string includeFileString = firstRecord->getItem(0);
                    boost::filesystem::path includeFile(includeFileString);

                    if (includeFile.is_relative())
                        includeFile = rootPath / includeFile;

                    if (verbose)
                        std::cout << rawKeyword->getKeywordName() << "  " << includeFile << std::endl;

                    parseFile(deck, includeFile, rootPath , parseStrict);
                } else {
                    if (verbose)
                        std::cout << rawKeyword->getKeywordName() << std::endl;

                    if (hasKeyword(rawKeyword->getKeywordName())) {
                        ParserKeywordConstPtr parserKeyword = m_parserKeywords.at(rawKeyword->getKeywordName());
                        ParserKeywordActionEnum action = parserKeyword->getAction();
                        if (action == INTERNALIZE) {
                            DeckKeywordConstPtr deckKeyword = parserKeyword->parse(rawKeyword);
                            deck->addKeyword(deckKeyword);
                        } else if (action == IGNORE_WARNING) 
                            deck->addWarning( "The keyword " + rawKeyword->getKeywordName() + " is ignored - this might potentially affect the results" , file.string() , rawKeyword->getLineNR());
                    } else {
                        DeckKeywordConstPtr deckKeyword(new DeckKeyword(rawKeyword->getKeywordName(), false));
                        deck->addKeyword(deckKeyword);
                        deck->addWarning( "The keyword " + rawKeyword->getKeywordName() + " is not recognized" , file.string() , lineNR);
                    }
                }
                rawKeyword.reset();
            }

            inputstream.close();
        } else
            throw std::invalid_argument("Failed to open file: " + file.string());
    }
示例#17
0
    void Deck::initUnitSystem() const {
        /*
         * The unit systems are lazily created as their exact value depend on
         * input values of the deck, but in a constructed deck this can be
         * considered constant (and in fact, if the deck is obtained through
         * ParseFromString/File, this these values set before the Deck is
         * available). The unit systems are needed from const contexts though,
         * but might not have been generated at that time. Generation is done
         * in this method, but it has to be callable from const'd this, and are
         * marked mutable.
         */

        this->defaultUnits = std::unique_ptr< UnitSystem >( UnitSystem::newMETRIC() );
        if (hasKeyword("FIELD"))
            this->activeUnits = std::unique_ptr< UnitSystem >( UnitSystem::newFIELD() );
        else
            this->activeUnits = std::unique_ptr< UnitSystem >( UnitSystem::newMETRIC() );
    }
示例#18
0
    void GridProperties<T>::handleCOPYREGRecord( const DeckRecord& record, const GridProperty<int>& regionProperty ) {
        const std::string& srcArray    = record.getItem("ARRAY").get< std::string >(0);
        const std::string& targetArray = record.getItem("TARGET_ARRAY").get< std::string >(0);

        if (!supportsKeyword( targetArray))
            throw std::invalid_argument("Fatal error processing COPYREG record - invalid/undefined keyword: " + targetArray);

        if (!hasKeyword( srcArray ))
            throw std::invalid_argument("Fatal error processing COPYREG record - invalid/undefined keyword: " + srcArray);

        {
            int regionValue = record.getItem("REGION_NUMBER").get< int >(0);
            std::vector<bool> mask;
            GridProperty<T>& targetProperty = getOrCreateProperty( targetArray );
            GridProperty<T>& srcProperty = getKeyword( srcArray );

            regionProperty.initMask( regionValue , mask);
            targetProperty.maskedCopy( srcProperty , mask );
        }
    }
示例#19
0
 bool hasKeyword() const {
     return hasKeyword( Keyword::keywordName );
 }
示例#20
0
文件: Deck.cpp 项目: alfbr/opm-common
    const std::vector< size_t >& DeckView::offsets( const std::string& keyword ) const {
        if( !hasKeyword( keyword ) ) return empty_indices;

        return this->keywordMap.find( keyword )->second;
    }
示例#21
0
void CompositeFood::addKeyword(string keyword) {
	if(hasKeyword(keyword)==false)
		keywords.push_back(keyword);
}
示例#22
0
    GridProperty<T>& GridProperties<T>::getOrCreateProperty(const std::string& name) {
        if (!hasKeyword(name))
            addKeyword(name);

        return getKeyword(name);
    }
示例#23
0
    std::shared_ptr<GridProperty<T> > getKeyword(const std::string& keyword) const {
        if (!hasKeyword(keyword))
            addAutoGeneratedKeyword_(keyword);

        return m_properties.at( keyword );
    }