///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2017 Statoil ASA // // ResInsight 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. // // ResInsight 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 at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RiaSummaryCurveAnalyzer.h" #include "RiaStdStringTools.h" #include "RiaSummaryCurveDefinition.h" #include "RimSummaryCurve.h" #include "RimSummaryCurveCollection.h" #include #include //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RiaSummaryCurveAnalyzer::RiaSummaryCurveAnalyzer() {} //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiaSummaryCurveAnalyzer::appendAdresses(const std::vector& allAddresses) { for (const auto& adr : allAddresses) { analyzeSingleAddress(adr); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiaSummaryCurveAnalyzer::appendAdresses(const std::set& allAddresses) { for (const auto& adr : allAddresses) { analyzeSingleAddress(adr); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::set RiaSummaryCurveAnalyzer::quantities() const { return m_quantities; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::set RiaSummaryCurveAnalyzer::quantityNamesWithHistory() const { assignCategoryToQuantities(); return m_quantitiesWithMatchingHistory; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::set RiaSummaryCurveAnalyzer::quantityNamesNoHistory() const { assignCategoryToQuantities(); return m_quantitiesNoMatchingHistory; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::string RiaSummaryCurveAnalyzer::quantityNameForTitle() const { if (quantityNamesWithHistory().size() == 1 && quantityNamesNoHistory().empty()) { return *quantityNamesWithHistory().begin(); } if (quantityNamesNoHistory().size() == 1 && quantityNamesWithHistory().empty()) { return *quantityNamesNoHistory().begin(); } return std::string(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::set RiaSummaryCurveAnalyzer::wellNames() const { return m_wellNames; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::set RiaSummaryCurveAnalyzer::wellGroupNames() const { return m_wellGroupNames; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::set RiaSummaryCurveAnalyzer::regionNumbers() const { return m_regionNumbers; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::set RiaSummaryCurveAnalyzer::categories() const { return m_categories; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector RiaSummaryCurveAnalyzer::identifierTexts(RifEclipseSummaryAddress::SummaryVarCategory category) const { std::vector stringSet; if (category == RifEclipseSummaryAddress::SUMMARY_REGION) { for (const auto& regionNumber : m_regionNumbers) { stringSet.push_back(QString::number(regionNumber)); } } else if (category == RifEclipseSummaryAddress::SUMMARY_WELL) { for (const auto& wellName : m_wellNames) { stringSet.push_back(QString::fromStdString(wellName)); } } else if (category == RifEclipseSummaryAddress::SUMMARY_WELL_GROUP) { for (const auto& wellGroupName : m_wellGroupNames) { stringSet.push_back(QString::fromStdString(wellGroupName)); } } return stringSet; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector RiaSummaryCurveAnalyzer::addressesForCategory(const std::set& addresses, RifEclipseSummaryAddress::SummaryVarCategory category) { std::vector filteredAddresses; for (const auto& adr : addresses) { if (adr.category() == category) { filteredAddresses.push_back(adr); } } return filteredAddresses; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::string RiaSummaryCurveAnalyzer::correspondingHistorySummaryCurveName(const std::string& curveName) { static std::string historyIdentifier = "H"; if (RiaStdStringTools::endsWith(curveName, historyIdentifier)) { std::string candidate = curveName.substr(0, curveName.size() - 1); return candidate; } else { return curveName + historyIdentifier; } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiaSummaryCurveAnalyzer::clear() { m_quantities.clear(); m_wellNames.clear(); m_wellGroupNames.clear(); m_regionNumbers.clear(); m_categories.clear(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiaSummaryCurveAnalyzer::assignCategoryToQuantities() const { if (!m_quantities.empty()) { if (m_quantitiesWithMatchingHistory.empty() && m_quantitiesNoMatchingHistory.empty()) { computeQuantityNamesWithHistory(); } } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiaSummaryCurveAnalyzer::computeQuantityNamesWithHistory() const { m_quantitiesNoMatchingHistory.clear(); m_quantitiesWithMatchingHistory.clear(); const std::string historyIdentifier("H"); for (const auto& s : m_quantities) { std::string correspondingHistoryCurve = correspondingHistorySummaryCurveName(s); if (m_quantities.find(correspondingHistoryCurve) != m_quantities.end()) { // Insert the curve name without H if (RiaStdStringTools::endsWith(s, historyIdentifier)) { m_quantitiesWithMatchingHistory.insert(correspondingHistoryCurve); } else { m_quantitiesWithMatchingHistory.insert(s); } } else { m_quantitiesNoMatchingHistory.insert(s); } } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiaSummaryCurveAnalyzer::analyzeSingleAddress(const RifEclipseSummaryAddress& address) { if (!address.wellName().empty()) { m_wellNames.insert(address.wellName()); } if (!address.quantityName().empty()) { m_quantities.insert(address.quantityName()); } if (!address.wellGroupName().empty()) { m_wellGroupNames.insert(address.wellGroupName()); } if (address.regionNumber() != -1) { m_regionNumbers.insert(address.regionNumber()); } if (address.category() != RifEclipseSummaryAddress::SUMMARY_INVALID) { m_categories.insert(address.category()); } }