diff --git a/ApplicationCode/ProjectDataModel/RimProject.cpp b/ApplicationCode/ProjectDataModel/RimProject.cpp index ce1de50767..108c3170a8 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.cpp +++ b/ApplicationCode/ProjectDataModel/RimProject.cpp @@ -881,7 +881,7 @@ std::vector RimProject::simulationWellNames() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RimProject::simulationWellBranches(const QString& simWellName) +std::vector RimProject::simulationWellBranches(const QString& simWellName) { // Find first case containing the specified simulation well auto simCases = eclipseCases(); @@ -893,7 +893,7 @@ std::vector RimProject::simulationWellBranches(const QString& simW RigEclipseCaseData* eclCaseData = eclipseCase != nullptr ? eclipseCase->eclipseCaseData() : nullptr; return eclCaseData != nullptr ? eclCaseData->simulationWellBranches(simWellName) : - std::vector(); + std::vector(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimProject.h b/ApplicationCode/ProjectDataModel/RimProject.h index a9713b25ad..cefd61de55 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.h +++ b/ApplicationCode/ProjectDataModel/RimProject.h @@ -124,7 +124,7 @@ public: std::vector eclipseCases() const; std::vector simulationWellNames() const; - std::vector simulationWellBranches(const QString& simWellName); + std::vector simulationWellBranches(const QString& simWellName); RimWellPath* wellPathFromSimulationWell(const QString& simWellName, int branchIndex = -1); protected: diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp index a769030140..bd4891e2b3 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp @@ -462,41 +462,50 @@ bool RigEclipseCaseData::hasSimulationWell(const QString& simWellName) const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RigEclipseCaseData::simulationWellBranches(const QString& simWellName) +std::vector RigEclipseCaseData::simulationWellBranches(const QString& simWellName) { - std::vector branches; + std::vector branches; - if (!(!simWellName.isEmpty() && simWellName != "None")) + if (m_branchCache.find(simWellName) == m_branchCache.end()) { - return std::vector(); + if (!(!simWellName.isEmpty() && simWellName != "None")) + { + return branches; + } + + const RigSingleWellResultsData* wellResults = findWellResult(simWellName); + + if (!wellResults) return branches; + + std::vector< std::vector > pipeBranchesCLCoords; + std::vector< std::vector > pipeBranchesCellIds; + + RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellFrame(this, + wellResults, + -1, + true, + true, + pipeBranchesCLCoords, + pipeBranchesCellIds); + + m_branchCache.insert(std::make_pair(simWellName, cvf::Collection())); + + for (size_t brIdx = 0; brIdx < pipeBranchesCLCoords.size(); ++brIdx) + { + auto wellMdCalculator = RigSimulationWellCoordsAndMD(pipeBranchesCLCoords[brIdx]); + + cvf::ref newWellPath = new RigWellPath(); + newWellPath->m_measuredDepths = wellMdCalculator.measuredDepths(); + newWellPath->m_wellPathPoints = wellMdCalculator.wellPathPoints(); + + m_branchCache[simWellName].push_back(newWellPath.p()); + } } - const RigSingleWellResultsData* wellResults = findWellResult(simWellName); - - if (!wellResults) return std::vector(); - - std::vector< std::vector > pipeBranchesCLCoords; - std::vector< std::vector > pipeBranchesCellIds; - - RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellFrame(this, - wellResults, - -1, - true, - true, - pipeBranchesCLCoords, - pipeBranchesCellIds); - - for (size_t brIdx = 0; brIdx < pipeBranchesCLCoords.size(); ++brIdx) + for (const auto& branch : m_branchCache[simWellName]) { - auto wellMdCalculator = RigSimulationWellCoordsAndMD(pipeBranchesCLCoords[brIdx]); - - cvf::ref newWellPath = new RigWellPath(); - newWellPath->m_measuredDepths = wellMdCalculator.measuredDepths(); - newWellPath->m_wellPathPoints = wellMdCalculator.wellPathPoints(); - - branches.push_back(newWellPath.p()); + branches.push_back(branch.p()); } - return branches; } diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h index c2f019c991..c856065247 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h +++ b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h @@ -31,6 +31,7 @@ #include "cvfCollection.h" #include "cvfStructGrid.h" #include "cvfVector3.h" +#include "cvfCollection.h" #include @@ -95,7 +96,7 @@ public: std::vector simulationWellNames() const; bool hasSimulationWell(const QString& simWellName) const; - std::vector simulationWellBranches(const QString& simWellName); + std::vector simulationWellBranches(const QString& simWellName); private: void computeActiveCellIJKBBox(); @@ -119,4 +120,6 @@ private: cvf::Collection m_gridCellToResultWellIndex; //< Array pr grid with index to well pr cell telling which well a cell is in RiaEclipseUnitTools::UnitSystem m_unitsType; + + std::map> m_branchCache; };