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; } }
void GridProperties<T>::handleOPERATERRecord( const DeckRecord& record, const GridProperty<int>& regionProperty) { const std::string& result_array = record.getItem("RESULT_ARRAY").get< std::string >(0); const std::string& parameter_array = record.getItem("ARRAY_PARAMETER").get< std::string >(0); const std::string& operation = record.getItem("OPERATION").get< std::string >(0); double alpha = record.getItem("PARAM1").get< double >(0); double beta = record.getItem("PARAM2").get< double >(0); int region_value = record.getItem("REGION_NUMBER").get<int>(0); if (!supportsKeyword( result_array)) throw std::invalid_argument("Fatal error processing OPERATER record - invalid/undefined keyword: " + result_array); { auto& result_prop = getKeyword(result_array); if (parameter_array == result_array) result_prop.runPostProcessor(); else { if (operation == "MULTIPLY" || operation == "POLY") result_prop.runPostProcessor(); } std::vector<T>& result_data = result_prop.getData(); const std::vector<T>& parameter_data = getKeyword( parameter_array ).getData(); operate_fptr func = operations.at( operation ); std::vector<bool> mask; regionProperty.initMask(region_value, mask); for (size_t index = 0; index < mask.size(); index++) { if (mask[index]) result_data[index] = func(result_data[index], parameter_data[index], alpha, beta); } } }
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; } }
void GridProperties<T>::handleOPERATERecord( const DeckRecord& record, BoxManager& boxManager) { const std::string& srcArray = record.getItem("ARRAY").get< std::string >(0); const std::string& targetArray = record.getItem("TARGET_ARRAY").get< std::string >(0); const std::string& operation = record.getItem("OPERATION").get< std::string >(0); double alpha = record.getItem("PARAM1").get< double >(0); double beta = record.getItem("PARAM2").get< double >(0); if (!supportsKeyword( targetArray)) throw std::invalid_argument("Fatal error processing OPERATE record - invalid/undefined keyword: " + targetArray); { auto& result_prop = getKeyword(targetArray); if (srcArray == targetArray) result_prop.runPostProcessor(); else { if (operation == "MULTIPLY" || operation == "POLY") result_prop.runPostProcessor(); } std::vector<T>& targetData= result_prop.getData(); const std::vector<T>& srcData = getKeyword( srcArray ).getData(); operate_fptr func = operations.at( operation ); setKeywordBox(record, boxManager); for (auto index : boxManager.getActiveBox()) targetData[index] = func( targetData[index] , srcData[index] , alpha, beta ); } }
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."); } }
const GridProperty<T>& GridProperties<T>::getDeckKeyword(const std::string& keyword) const { const std::string kw = normalize(keyword); if (hasDeckKeyword(kw)) return m_properties.at( kw ); else { if (supportsKeyword(kw)) throw std::invalid_argument("Keyword: " + kw + " is supported - but not initialized."); else throw std::invalid_argument("Keyword: " + kw + " is not supported."); } }
void GridProperties<T>::handleEQUALSRecord( const DeckRecord& record, BoxManager& boxManager) { const std::string& field = record.getItem("field").get< std::string >(0); double value = record.getItem("value").get< double >(0); if (supportsKeyword( field )) { GridProperty<T>& property = getOrCreateProperty( field ); T targetValue = convertInputValue( property , value ); setKeywordBox(record, boxManager); property.setScalar( targetValue , boxManager.getActiveBox() ); } else throw std::invalid_argument("Fatal error processing EQUALS keyword. Tried to set not defined keyword " + field); }
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); } }
void GridProperties<T>::handleEQUALREGRecord( const DeckRecord& record, const GridProperty<int>& regionProperty ) { const std::string& targetArray = record.getItem("ARRAY").get< std::string >(0); if (supportsKeyword( targetArray )) { GridProperty<T>& targetProperty = getOrCreateProperty( targetArray ); double inputValue = record.getItem("VALUE").get<double>(0); int regionValue = record.getItem("REGION_NUMBER").get<int>(0); T targetValue = convertInputValue( targetProperty , inputValue ); std::vector<bool> mask; regionProperty.initMask( regionValue , mask); targetProperty.maskedSet( targetValue , mask); } else throw std::invalid_argument("Fatal error processing EQUALREG record - invalid/undefined keyword: " + targetArray); }
bool GridProperties<T>::addAutoGeneratedKeyword_(const std::string& keywordName) const { if (!supportsKeyword( keywordName )) throw std::invalid_argument("The keyword: " + keywordName + " is not supported in this container"); if (m_properties.count( keywordName ) > 0) return false; // property already exists (if it is auto generated or not doesn't matter) else { m_autoGeneratedProperties.insert(keywordName); if (isFipxxx<T>(keywordName)) m_supportedKeywords.emplace(keywordName, SupportedKeywordInfo( keywordName , 1, "1" )); insertKeyword( m_supportedKeywords.at( keywordName ) ); return true; } }
bool addAutoGeneratedKeyword_(const std::string& keywordName) const { if (!supportsKeyword( keywordName )) throw std::invalid_argument("The keyword: " + keywordName + " is not supported in this container"); if (m_properties.count( keywordName ) > 0) return false; // property already exists (if it is auto generated or not doesn't matter) else { 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_autoGeneratedProperties_.insert(keywordName); m_properties.insert( std::pair<std::string , std::shared_ptr<GridProperty<T> > > ( keywordName , newProperty )); m_property_list.push_back( newProperty ); return true; } }
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 ); } }