diff --git a/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp b/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp index 27c59aecd5..633bc85a49 100644 --- a/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp +++ b/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp @@ -1,17 +1,17 @@ ///////////////////////////////////////////////////////////////////////////////// // // 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 +// +// See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// @@ -31,27 +31,29 @@ CAF_PDM_SOURCE_INIT(RicfExportSnapshots, "exportSnapshots"); -namespace caf { - template<> - void RicfExportSnapshots::SnapshotsTypeEnum::setUp() - { - addItem(RicfExportSnapshots::ALL, "ALL", "All"); - addItem(RicfExportSnapshots::VIEWS, "VIEWS", "Views"); - addItem(RicfExportSnapshots::PLOTS, "PLOTS", "Plots"); - setDefault(RicfExportSnapshots::ALL); - } +namespace caf +{ +template<> +void RicfExportSnapshots::SnapshotsTypeEnum::setUp() +{ + addItem(RicfExportSnapshots::ALL, "ALL", "All"); + addItem(RicfExportSnapshots::VIEWS, "VIEWS", "Views"); + addItem(RicfExportSnapshots::PLOTS, "PLOTS", "Plots"); + setDefault(RicfExportSnapshots::ALL); } +} // namespace caf //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- RicfExportSnapshots::RicfExportSnapshots() { - RICF_InitField(&m_type, "type", RicfExportSnapshots::SnapshotsTypeEnum(), "Type", "", "", ""); + RICF_InitField(&m_type, "type", RicfExportSnapshots::SnapshotsTypeEnum(), "Type", "", "", ""); + RICF_InitField(&m_prefix, "prefix", QString(), "Prefix", "", "", ""); } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- void RicfExportSnapshots::execute() { @@ -67,11 +69,11 @@ void RicfExportSnapshots::execute() } if (m_type == RicfExportSnapshots::VIEWS || m_type == RicfExportSnapshots::ALL) { - RicSnapshotAllViewsToFileFeature::exportSnapshotOfAllViewsIntoFolder(absolutePathToSnapshotDir); + RicSnapshotAllViewsToFileFeature::exportSnapshotOfAllViewsIntoFolder(absolutePathToSnapshotDir, m_prefix); } if (m_type == RicfExportSnapshots::PLOTS || m_type == RicfExportSnapshots::ALL) { - RicSnapshotAllPlotsToFileFeature::exportSnapshotOfAllPlotsIntoFolder(absolutePathToSnapshotDir); + RicSnapshotAllPlotsToFileFeature::exportSnapshotOfAllPlotsIntoFolder(absolutePathToSnapshotDir, m_prefix); } mainWnd->loadWinGeoAndDockToolBarLayout(); diff --git a/ApplicationCode/CommandFileInterface/RicfExportSnapshots.h b/ApplicationCode/CommandFileInterface/RicfExportSnapshots.h index e2a6fe5e10..fcfac350f7 100644 --- a/ApplicationCode/CommandFileInterface/RicfExportSnapshots.h +++ b/ApplicationCode/CommandFileInterface/RicfExportSnapshots.h @@ -1,17 +1,17 @@ ///////////////////////////////////////////////////////////////////////////////// // // 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 +// +// See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// @@ -48,4 +48,5 @@ public: private: caf::PdmField m_type; -}; \ No newline at end of file + caf::PdmField m_prefix; +}; diff --git a/ApplicationCode/Commands/CompletionCommands/RicNewValveFeature.cpp b/ApplicationCode/Commands/CompletionCommands/RicNewValveFeature.cpp index d4c9b17320..6dbf2e4c53 100644 --- a/ApplicationCode/Commands/CompletionCommands/RicNewValveFeature.cpp +++ b/ApplicationCode/Commands/CompletionCommands/RicNewValveFeature.cpp @@ -1,6 +1,7 @@ #include "RicNewValveFeature.h" #include "Riu3DMainWindowTools.h" +#include "RiaApplication.h" #include "RimPerforationInterval.h" #include "RimWellPathValve.h" #include "RimWellPathCollection.h" @@ -17,7 +18,7 @@ CAF_CMD_SOURCE_INIT(RicNewValveFeature, "RicNewValveFeature"); bool RicNewValveFeature::isCommandEnabled() { const RimPerforationInterval* perfInterval = caf::SelectionManager::instance()->selectedItemOfType(); - return perfInterval != nullptr; + return perfInterval != nullptr && RiaApplication::enableDevelopmentFeatures(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.cpp b/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.cpp index 6a6e01532c..4ef60d3392 100644 --- a/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.cpp +++ b/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.cpp @@ -359,9 +359,10 @@ std::vector RicExportFractureCompletionsImpl::generateCompdat RicWellPathFractureReportItem reportItem( wellPathName, fracture->name(), fracTemplate->name(), fracture->fractureMD()); reportItem.setUnitSystem(fracTemplate->fractureTemplateUnit()); - reportItem.setPressureDepletionParameters(performPressureDepletionScaling ? "True" : "False", + reportItem.setPressureDepletionParameters(performPressureDepletionScaling, + caseToApply->timeStepStrings()[pdParams.pressureScalingTimeStep], caf::AppEnum::uiTextFromIndex(pdParams.wbhpSource), - pdParams.userWBHP, minPressureDrop, maxPressureDrop); + pdParams.userWBHP, currentWellPressure, minPressureDrop, maxPressureDrop); RicExportFractureCompletionsImpl::calculateAndSetReportItemData( allCompletionsForOneFracture, eclToFractureCalc, reportItem); diff --git a/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureReportItem.cpp b/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureReportItem.cpp index 5d0323c125..876019fa85 100644 --- a/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureReportItem.cpp +++ b/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureReportItem.cpp @@ -32,7 +32,6 @@ RicWellPathFractureReportItem::RicWellPathFractureReportItem(const QString& well : m_wellPathNameForExport(wellPathName) , m_wellPathFracture(fractureName) , m_wellPathFractureTemplate(fractureTemplateName) - , m_pressureDepletionScalingString() , m_mesuredDepth(measuredDepth) , m_transmissibility(0.0) , m_connectionCount(0) @@ -43,6 +42,9 @@ RicWellPathFractureReportItem::RicWellPathFractureReportItem(const QString& well , m_xf(0.0) , m_h(0.0) , m_km(0.0) + , m_performPressureDepletionScaling(false) + , m_pressureDepletionUserWBHP(0.0) + , m_pressureDepletionActualWBHP(0.0) , m_pressureDepletionMinPressureDrop(-1.0) , m_pressureDepletionMaxPressureDrop(-1.0) { @@ -112,22 +114,6 @@ QString RicWellPathFractureReportItem::fractureTemplateName() const return m_wellPathFractureTemplate; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QString RicWellPathFractureReportItem::pressureDepletionScaling() const -{ - return m_pressureDepletionScalingString; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QString RicWellPathFractureReportItem::pressureDepletionWBHPString() const -{ - return m_pressureDepletionWBHPString; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -139,13 +125,15 @@ void RicWellPathFractureReportItem::setUnitSystem(RiaEclipseUnitTools::UnitSyste //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicWellPathFractureReportItem::setPressureDepletionParameters(QString scalingString, QString wbhpString, double userWBHP, double minPressureDrop, double maxPressureDrop) +void RicWellPathFractureReportItem::setPressureDepletionParameters(bool performPDDScaling, QString timeStepString, QString wbhpString, double userWBHP, double actualWBHP, double minPressureDrop, double maxPressureDrop) { - m_pressureDepletionScalingString = scalingString; - m_pressureDepletionWBHPString = wbhpString; - m_pressureDepletionUserWBHP = userWBHP; - m_pressureDepletionMinPressureDrop = minPressureDrop; - m_pressureDepletionMaxPressureDrop = maxPressureDrop; + m_performPressureDepletionScaling = performPDDScaling; + m_pressureDepletionTimeStepString = timeStepString; + m_pressureDepletionWBHPString = wbhpString; + m_pressureDepletionUserWBHP = userWBHP; + m_pressureDepletionActualWBHP = actualWBHP; + m_pressureDepletionMinPressureDrop = minPressureDrop; + m_pressureDepletionMaxPressureDrop = maxPressureDrop; } //-------------------------------------------------------------------------------------------------- @@ -252,6 +240,30 @@ double RicWellPathFractureReportItem::kmxf() const return m_km * m_xf; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicWellPathFractureReportItem::performPressureDepletionScaling() const +{ + return m_performPressureDepletionScaling; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RicWellPathFractureReportItem::pressureDepletionTimeStepString() const +{ + return m_pressureDepletionTimeStepString; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RicWellPathFractureReportItem::pressureDepletionWBHPString() const +{ + return m_pressureDepletionWBHPString; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -260,6 +272,14 @@ double RicWellPathFractureReportItem::pressureDepletionUserWBHP() const return m_pressureDepletionUserWBHP; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RicWellPathFractureReportItem::pressureDepletionActualWBHP() const +{ + return m_pressureDepletionActualWBHP; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureReportItem.h b/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureReportItem.h index 4f7b63ffca..9e47a4e483 100644 --- a/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureReportItem.h +++ b/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureReportItem.h @@ -35,13 +35,11 @@ public: void setHeightAndHalfLength(double height, double halfLength); void setAreaWeightedTransmissibility(double transmissibility); void setUnitSystem(RiaEclipseUnitTools::UnitSystem unitSystem); - void setPressureDepletionParameters(QString scalingString, QString wbhpString, double userWBHP, double minPressureDrop, double maxPressureDrop); + void setPressureDepletionParameters(bool performPressureDepletionScaling, QString timeStepString, QString wbhpString, double userWBHP, double actualWBHP, double minPressureDrop, double maxPressureDrop); QString wellPathNameForExport() const; QString fractureName() const; QString fractureTemplateName() const; - QString pressureDepletionScaling() const; - QString pressureDepletionWBHPString() const; RiaEclipseUnitTools::UnitSystem unitSystem() const; @@ -59,9 +57,13 @@ public: double km() const; double kmxf() const; - double pressureDepletionUserWBHP() const; - double pressureDepletionMinPressureDrop() const; - double pressureDepletionMaxPressureDrop() const; + bool performPressureDepletionScaling() const; + QString pressureDepletionTimeStepString() const; + QString pressureDepletionWBHPString() const; + double pressureDepletionUserWBHP() const; + double pressureDepletionActualWBHP() const; + double pressureDepletionMinPressureDrop() const; + double pressureDepletionMaxPressureDrop() const; bool operator < (const RicWellPathFractureReportItem& other) const; @@ -70,8 +72,6 @@ private: QString m_wellPathNameForExport; QString m_wellPathFracture; QString m_wellPathFractureTemplate; - QString m_pressureDepletionScalingString; - QString m_pressureDepletionWBHPString; double m_mesuredDepth; double m_transmissibility; @@ -84,8 +84,12 @@ private: double m_xf; double m_h; double m_km; - - double m_pressureDepletionUserWBHP; - double m_pressureDepletionMinPressureDrop; - double m_pressureDepletionMaxPressureDrop; + + bool m_performPressureDepletionScaling; + QString m_pressureDepletionTimeStepString; + QString m_pressureDepletionWBHPString; + double m_pressureDepletionUserWBHP; + double m_pressureDepletionActualWBHP; + double m_pressureDepletionMinPressureDrop; + double m_pressureDepletionMaxPressureDrop; }; diff --git a/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureTextReportFeatureImpl.cpp b/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureTextReportFeatureImpl.cpp index afe40e528e..2ef8bf3732 100644 --- a/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureTextReportFeatureImpl.cpp +++ b/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureTextReportFeatureImpl.cpp @@ -709,30 +709,40 @@ QString RicWellPathFractureTextReportFeatureImpl::createFracturePressureDepletio std::vector header = { RifEclipseOutputTableColumn("Well"), RifEclipseOutputTableColumn("Fracture"), - RifEclipseOutputTableColumn("PDD Scaling"), RifEclipseOutputTableColumn("WBHP Source"), - RifEclipseOutputTableColumn("User WBHP"), + RifEclipseOutputTableColumn("Actual WBHP"), RifEclipseOutputTableColumn("Min Pressure Drop"), RifEclipseOutputTableColumn("Max Pressure Drop") }; - formatter.header(header); - formatter.addHorizontalLine('-'); + bool createdTable = false; for (const auto& reportItem : wellPathFractureReportItems) { - formatter.add(reportItem.wellPathNameForExport()); - formatter.add(reportItem.fractureName()); - formatter.add(reportItem.pressureDepletionScaling()); - formatter.add(reportItem.pressureDepletionWBHPString()); - formatter.add(reportItem.pressureDepletionUserWBHP()); - formatter.add(reportItem.pressureDepletionMinPressureDrop()); - formatter.add(reportItem.pressureDepletionMaxPressureDrop()); + if (reportItem.performPressureDepletionScaling()) + { + if (!createdTable) + { + formatter.comment(QString("Pressure Depletion Time step: %1").arg(reportItem.pressureDepletionTimeStepString())); + formatter.comment(QString("User Defined WBHP: %1").arg(reportItem.pressureDepletionUserWBHP())); - formatter.rowCompleted(); + formatter.header(header); + formatter.addHorizontalLine('-'); + createdTable = true; + } + formatter.add(reportItem.wellPathNameForExport()); + formatter.add(reportItem.fractureName()); + formatter.add(reportItem.pressureDepletionWBHPString()); + formatter.add(reportItem.pressureDepletionActualWBHP()); + formatter.add(reportItem.pressureDepletionMinPressureDrop()); + formatter.add(reportItem.pressureDepletionMaxPressureDrop()); + formatter.rowCompleted(); + } + } + if (createdTable) + { + formatter.tableCompleted(); } - - formatter.tableCompleted(); return tableText; } diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.cpp index 3572a5c125..548cbaccde 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.cpp +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.cpp @@ -68,7 +68,7 @@ void RicSnapshotAllPlotsToFileFeature::saveAllPlots() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfAllPlotsIntoFolder(QString snapshotFolderName) +void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfAllPlotsIntoFolder(const QString& snapshotFolderName, const QString& prefix) { RiaApplication* app = RiaApplication::instance(); @@ -91,6 +91,11 @@ void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfAllPlotsIntoFolder(QStrin if (viewWindow->isMdiWindow() && viewWindow->viewWidget()) { QString fileName = RicSnapshotFilenameGenerator::generateSnapshotFileName(viewWindow); + if (!prefix.isEmpty()) + { + fileName = prefix + fileName; + } + fileName.replace(" ", "_"); QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png"); diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.h b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.h index 45041d345d..f191172432 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.h +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.h @@ -32,7 +32,7 @@ class RicSnapshotAllPlotsToFileFeature : public caf::CmdFeature public: static void saveAllPlots(); - static void exportSnapshotOfAllPlotsIntoFolder(QString snapshotFolderName); + static void exportSnapshotOfAllPlotsIntoFolder(const QString& snapshotFolderName, const QString& prefix = ""); protected: // Overrides diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.cpp index 46f51c874e..2d880c5cef 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.cpp +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.cpp @@ -70,7 +70,7 @@ void RicSnapshotAllViewsToFileFeature::saveAllViews() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicSnapshotAllViewsToFileFeature::exportSnapshotOfAllViewsIntoFolder(QString snapshotFolderName) +void RicSnapshotAllViewsToFileFeature::exportSnapshotOfAllViewsIntoFolder(const QString& snapshotFolderName, const QString& prefix) { RimProject* project = RiaApplication::instance()->project(); @@ -114,6 +114,10 @@ void RicSnapshotAllViewsToFileFeature::exportSnapshotOfAllViewsIntoFolder(QStrin viewer->repaint(); QString fileName = RicSnapshotFilenameGenerator::generateSnapshotFileName(riv); + if (!prefix.isEmpty()) + { + fileName = prefix + fileName; + } QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png"); diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.h b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.h index 82f333d96a..e8d664f36b 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.h +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.h @@ -32,7 +32,7 @@ class RicSnapshotAllViewsToFileFeature : public caf::CmdFeature public: static void saveAllViews(); - static void exportSnapshotOfAllViewsIntoFolder(QString snapshotFolderName); + static void exportSnapshotOfAllViewsIntoFolder(const QString& snapshotFolderName, const QString& prefix = ""); protected: // Overrides diff --git a/ApplicationCode/Commands/RicCreateTemporaryLgrFeature.cpp b/ApplicationCode/Commands/RicCreateTemporaryLgrFeature.cpp index 174807e502..080d6c3c69 100644 --- a/ApplicationCode/Commands/RicCreateTemporaryLgrFeature.cpp +++ b/ApplicationCode/Commands/RicCreateTemporaryLgrFeature.cpp @@ -198,6 +198,7 @@ void RicCreateTemporaryLgrFeature::onActionTriggered(bool isChecked) void RicCreateTemporaryLgrFeature::setupActionLook(QAction* actionToSetup) { actionToSetup->setText("Create Temporary LGR"); + actionToSetup->setIcon(QIcon(":/TempLGR16x16.png")); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/WellPathCommands/RicDeleteWellPathAttributeFeature.cpp b/ApplicationCode/Commands/WellPathCommands/RicDeleteWellPathAttributeFeature.cpp index 115d733946..e702e53271 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicDeleteWellPathAttributeFeature.cpp +++ b/ApplicationCode/Commands/WellPathCommands/RicDeleteWellPathAttributeFeature.cpp @@ -79,12 +79,22 @@ void RicDeleteWellPathAttributeFeature::onActionTriggered(bool isChecked) } } - if (wellPathAttributeCollection->attributes().empty()) + if (wellPathAttributeCollection) { - RimWellPath* wellPath = nullptr; - wellPathAttributeCollection->firstAncestorOrThisOfTypeAsserted(wellPath); - wellPath->updateConnectedEditors(); - Riu3DMainWindowTools::selectAsCurrentItem(wellPath); + if (wellPathAttributeCollection->attributes().empty()) + { + RimWellPath* wellPath = nullptr; + wellPathAttributeCollection->firstAncestorOrThisOfTypeAsserted(wellPath); + wellPath->updateConnectedEditors(); + Riu3DMainWindowTools::selectAsCurrentItem(wellPath); + } + + RimProject* proj = nullptr; + wellPathAttributeCollection->firstAncestorOrThisOfType(proj); + if (proj) + { + proj->scheduleCreateDisplayModelAndRedrawAllViews(); + } } } diff --git a/ApplicationCode/FileInterface/RifReaderEclipseSummary.cpp b/ApplicationCode/FileInterface/RifReaderEclipseSummary.cpp index 32531941d7..a7a2eb7b4d 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseSummary.cpp +++ b/ApplicationCode/FileInterface/RifReaderEclipseSummary.cpp @@ -344,6 +344,7 @@ RifEclipseSummaryAddress addressFromErtSmSpecNode(const smspec_node_type * ertSu case ECL_SMSPEC_SEGMENT_VAR: { sumCategory = RifEclipseSummaryAddress::SUMMARY_WELL_SEGMENT; + wellName = smspec_node_get_wgname(ertSumVarNode); wellSegmentNumber = smspec_node_get_num(ertSumVarNode); } break; diff --git a/ApplicationCode/ModelVisualization/RivContourMapProjectionPartMgr.cpp b/ApplicationCode/ModelVisualization/RivContourMapProjectionPartMgr.cpp index 81945cc7d5..0dfe93034b 100644 --- a/ApplicationCode/ModelVisualization/RivContourMapProjectionPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivContourMapProjectionPartMgr.cpp @@ -97,7 +97,7 @@ void RivContourMapProjectionPartMgr::appendPickPointVisToModel(cvf::ModelBasicLi //-------------------------------------------------------------------------------------------------- cvf::ref RivContourMapProjectionPartMgr::createTextureCoords() const { - cvf::Vec2ui patchSize = m_contourMapProjection->vertexGridSize(); + cvf::Vec2ui patchSize = m_contourMapProjection->numberOfVerticesIJ(); cvf::ref textureCoords = new cvf::Vec2fArray(m_contourMapProjection->numberOfVertices()); @@ -155,7 +155,7 @@ cvf::ref RivContourMapProjectionPartMgr::createProjectionMapDr { cvf::ref vertexArray = new cvf::Vec3fArray; m_contourMapProjection->generateVertices(vertexArray.p(), displayCoordTransform); - cvf::Vec2ui patchSize = m_contourMapProjection->vertexGridSize(); + cvf::Vec2ui patchSize = m_contourMapProjection->numberOfVerticesIJ(); // Surface cvf::ref faceList = new cvf::UIntArray; diff --git a/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp b/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp index 305ab13117..9d68b66ac2 100644 --- a/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp +++ b/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp @@ -502,8 +502,8 @@ QString Rim3dOverlayInfoConfig::caseInfoText(RimEclipseView* eclipseView) QString totCellCount = QString::number(contourMap->contourMapProjection()->numberOfCells()); cvf::uint validCellCount = contourMap->contourMapProjection()->numberOfValidCells(); QString activeCellCountText = QString::number(validCellCount); - QString iSize = QString::number(contourMap->contourMapProjection()->mapSize().x()); - QString jSize = QString::number(contourMap->contourMapProjection()->mapSize().y()); + QString iSize = QString::number(contourMap->contourMapProjection()->numberOfElementsIJ().x()); + QString jSize = QString::number(contourMap->contourMapProjection()->numberOfElementsIJ().y()); QString aggregationType = contourMap->contourMapProjection()->resultAggregationText(); QString weightingParameterString; if (contourMap->contourMapProjection()->weightingParameter() != "None") diff --git a/ApplicationCode/ProjectDataModel/RimContourMapProjection.cpp b/ApplicationCode/ProjectDataModel/RimContourMapProjection.cpp index 9acc645d7a..b495f5784b 100644 --- a/ApplicationCode/ProjectDataModel/RimContourMapProjection.cpp +++ b/ApplicationCode/ProjectDataModel/RimContourMapProjection.cpp @@ -98,58 +98,6 @@ RimContourMapProjection::~RimContourMapProjection() } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimContourMapProjection::generateGridMapping() -{ - calculateTotalCellVisibility(); - - RimEclipseResultCase* eclipseCase = nullptr; - firstAncestorOrThisOfTypeAsserted(eclipseCase); - - int nCells = numberOfCells(); - m_projected3dGridIndices.resize(nCells); - - const std::vector* weightingResultValues = nullptr; - if (m_weightByParameter()) - { - size_t gridScalarResultIdx = m_weightingResult->scalarResultIndex(); - if (gridScalarResultIdx != cvf::UNDEFINED_SIZE_T) - { - m_weightingResult->loadResult(); - int timeStep = 0; - if (m_weightingResult->hasDynamicResult()) - { - timeStep = view()->currentTimeStep(); - - } - weightingResultValues = &(m_weightingResult->currentGridCellResults()->cellScalarResults(gridScalarResultIdx)[timeStep]); - } - } - - if (isStraightSummationResult()) - { - for (int index = 0; index < nCells; ++index) - { - cvf::Vec2ui ij = ijFromCellIndex(index); - - cvf::Vec2d globalPos = globalCellCenterPosition(ij.x(), ij.y()); - m_projected3dGridIndices[index] = visibleCellsAndLengthInCellFrom2dPoint(globalPos, weightingResultValues); - } - } - else - { -#pragma omp parallel for - for (int index = 0; index < nCells; ++index) - { - cvf::Vec2ui ij = ijFromCellIndex(index); - - cvf::Vec2d globalPos = globalCellCenterPosition(ij.x(), ij.y()); - m_projected3dGridIndices[index] = visibleCellsAndOverlapVolumeFrom2dPoint(globalPos, weightingResultValues); - } - } -} //-------------------------------------------------------------------------------------------------- /// @@ -188,30 +136,36 @@ RimContourMapProjection::ContourPolygons RimContourMapProjection::generateContou std::fabs(maxValue() - minValue()) > 1.0e-8) { std::vector contourLevels; - legendConfig()->scalarMapper()->majorTickValues(&contourLevels); - int nContourLevels = static_cast(contourLevels.size()); - if (nContourLevels > 2) + if (legendConfig()->mappingMode() != RimRegularLegendConfig::CATEGORY_INTEGER) { - // Slight fudge to avoid very jagged contour lines at the very edge - // Shift the contour levels inwards. - contourLevels[0] += (contourLevels[1] - contourLevels[0]) * 0.1; - contourLevels[nContourLevels - 1] -= (contourLevels[nContourLevels - 1] - contourLevels[nContourLevels - 2]) * 0.1; - std::vector> contourLines; - caf::ContourLines::create(m_aggregatedVertexResults, xVertexPositions(), yVertexPositions(), contourLevels, &contourLines); - - contourPolygons.reserve(contourLines.size()); - for (size_t i = 0; i < contourLines.size(); ++i) + legendConfig()->scalarMapper()->majorTickValues(&contourLevels); + int nContourLevels = static_cast(contourLevels.size()); + if (nContourLevels > 2) { - if (!contourLines[i].empty()) + if (legendConfig()->mappingMode() == RimRegularLegendConfig::LINEAR_CONTINUOUS || legendConfig()->mappingMode() == RimRegularLegendConfig::LINEAR_DISCRETE) { - cvf::ref contourPolygon = new cvf::Vec3fArray(contourLines[i].size()); - for (size_t j = 0; j < contourLines[i].size(); ++j) + // Slight fudge to avoid very jagged contour lines at the very edge + // Shift the contour levels inwards. + contourLevels[0] += (contourLevels[1] - contourLevels[0]) * 0.1; + contourLevels[nContourLevels - 1] -= (contourLevels[nContourLevels - 1] - contourLevels[nContourLevels - 2]) * 0.1; + } + std::vector> contourLines; + caf::ContourLines::create(m_aggregatedVertexResults, xVertexPositions(), yVertexPositions(), contourLevels, &contourLines); + + contourPolygons.reserve(contourLines.size()); + for (size_t i = 0; i < contourLines.size(); ++i) + { + if (!contourLines[i].empty()) { - cvf::Vec3d contourPoint3d = cvf::Vec3d(contourLines[i][j], m_fullBoundingBox.min().z()); - cvf::Vec3d displayPoint3d = displayCoordTransform->transformToDisplayCoord(contourPoint3d); - (*contourPolygon)[j] = cvf::Vec3f(displayPoint3d); + cvf::ref contourPolygon = new cvf::Vec3fArray(contourLines[i].size()); + for (size_t j = 0; j < contourLines[i].size(); ++j) + { + cvf::Vec3d contourPoint3d = cvf::Vec3d(contourLines[i][j], m_fullBoundingBox.min().z()); + cvf::Vec3d displayPoint3d = displayCoordTransform->transformToDisplayCoord(contourPoint3d); + (*contourPolygon)[j] = cvf::Vec3f(displayPoint3d); + } + contourPolygons.push_back(contourPolygon); } - contourPolygons.push_back(contourPolygon); } } } @@ -223,7 +177,7 @@ RimContourMapProjection::ContourPolygons RimContourMapProjection::generateContou /// //-------------------------------------------------------------------------------------------------- cvf::ref - RimContourMapProjection::generatePickPointPolygon(const caf::DisplayCoordTransform* displayCoordTransform) +RimContourMapProjection::generatePickPointPolygon(const caf::DisplayCoordTransform* displayCoordTransform) { cvf::ref pickPolygon; if (!m_pickPoint.isUndefined()) @@ -284,8 +238,7 @@ void RimContourMapProjection::generateResults() int timeStep = view()->currentTimeStep(); RimEclipseCellColors* cellColors = view()->cellResult(); - RimEclipseResultCase* eclipseCase = nullptr; - firstAncestorOrThisOfTypeAsserted(eclipseCase); + RimEclipseResultCase* eclipseCase = this->eclipseCase(); { if (!cellColors->isTernarySaturationSelected()) { @@ -332,6 +285,73 @@ void RimContourMapProjection::generateResults() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimContourMapProjection::ResultAggregation RimContourMapProjection::resultAggregation() const +{ + return m_resultAggregation(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RimContourMapProjection::sampleSpacing() const +{ + return m_sampleSpacing; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RimContourMapProjection::sampleSpacingFactor() const +{ + return m_relativeSampleSpacing(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimContourMapProjection::showContourLines() const +{ + return m_showContourLines(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimContourMapProjection::resultAggregationText() const +{ + return m_resultAggregation().uiText(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimContourMapProjection::resultDescriptionText() const +{ + QString resultText = resultAggregationText(); + if (!isColumnResult()) + { + resultText += QString(", %1").arg(view()->cellResult()->resultVariable()); + } + + return resultText; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimContourMapProjection::weightingParameter() const +{ + QString parameter = "None"; + if (m_weightByParameter() && !m_weightingResult->isTernarySaturationSelected()) + { + parameter = m_weightingResult->resultVariableUiShortName(); + } + return parameter; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -400,23 +420,7 @@ double RimContourMapProjection::sumAllValues() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -double RimContourMapProjection::sampleSpacing() const -{ - return m_sampleSpacing; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -double RimContourMapProjection::sampleSpacingFactor() const -{ - return m_relativeSampleSpacing(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui RimContourMapProjection::mapSize() const +cvf::Vec2ui RimContourMapProjection::numberOfElementsIJ() const { return m_mapSize; } @@ -424,80 +428,14 @@ cvf::Vec2ui RimContourMapProjection::mapSize() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::Vec2ui RimContourMapProjection::vertexGridSize() const +cvf::Vec2ui RimContourMapProjection::numberOfVerticesIJ() const { - cvf::Vec2ui mapSize = this->mapSize(); + cvf::Vec2ui mapSize = this->numberOfElementsIJ(); mapSize.x() += 1u; mapSize.y() += 1u; return mapSize; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimContourMapProjection::showContourLines() const -{ - return m_showContourLines(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const std::vector& RimContourMapProjection::aggregatedResults() const -{ - return m_aggregatedResults; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QString RimContourMapProjection::weightingParameter() const -{ - QString parameter = "None"; - if (m_weightByParameter() && !m_weightingResult->isTernarySaturationSelected()) - { - parameter = m_weightingResult->resultVariableUiShortName(); - } - return parameter; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimContourMapProjection::isMeanResult() const -{ - return m_resultAggregation() == RESULTS_MEAN_VALUE || - m_resultAggregation() == RESULTS_HARM_VALUE || - m_resultAggregation() == RESULTS_GEOM_VALUE; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimContourMapProjection::isSummationResult() const -{ - return isStraightSummationResult() || m_resultAggregation() == RESULTS_VOLUME_SUM; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimContourMapProjection::isStraightSummationResult() const -{ - return isStraightSummationResult(m_resultAggregation()); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimContourMapProjection::isStraightSummationResult(ResultAggregationEnum aggregationType) -{ - return aggregationType == RESULTS_OIL_COLUMN || - aggregationType == RESULTS_GAS_COLUMN || - aggregationType == RESULTS_HC_COLUMN || - aggregationType == RESULTS_SUM; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -513,7 +451,7 @@ bool RimContourMapProjection::isColumnResult() const //-------------------------------------------------------------------------------------------------- double RimContourMapProjection::valueAtVertex(uint i, uint j) const { - size_t index = vertexIndex(i, j); + size_t index = vertexIndexFromIJ(i, j); if (index < numberOfVertices()) { return m_aggregatedVertexResults.at(index); @@ -527,220 +465,10 @@ double RimContourMapProjection::valueAtVertex(uint i, uint j) const //-------------------------------------------------------------------------------------------------- bool RimContourMapProjection::hasResultAtVertex(uint i, uint j) const { - size_t index = vertexIndex(i, j); + size_t index = vertexIndexFromIJ(i, j); return m_aggregatedVertexResults[index] != std::numeric_limits::infinity(); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -double RimContourMapProjection::calculateValueAtVertex(uint vi, uint vj) const -{ - std::vector averageIs; - std::vector averageJs; - - if (vi > 0u) averageIs.push_back(vi - 1); - if (vj > 0u) averageJs.push_back(vj - 1); - if (vi < m_mapSize.x()) averageIs.push_back(vi); - if (vj < m_mapSize.y()) averageJs.push_back(vj); - - RiaWeightedMeanCalculator calc; - for (uint j : averageJs) - { - for (uint i : averageIs) - { - if (hasResultInCell(i, j)) - { - calc.addValueAndWeight(valueInCell(i, j), 1.0); - } - } - } - if (calc.validAggregatedWeight()) - { - return calc.weightedMean(); - } - return std::numeric_limits::infinity(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -double RimContourMapProjection::calculateValueInCell(uint i, uint j) const -{ - if (!isColumnResult() && view()->cellResult()->scalarResultIndex() == cvf::UNDEFINED_SIZE_T) - { - return 0.0; // Special case of NONE-result. Show 0 all over to ensure we see something. - } - const std::vector>& matchingCells = cellsAtIJ(i, j); - if (!matchingCells.empty()) - { - switch (m_resultAggregation()) - { - case RESULTS_TOP_VALUE: - { - size_t cellIdx = matchingCells.front().first; - double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); - return cellValue; - } - case RESULTS_MEAN_VALUE: - { - RiaWeightedMeanCalculator calculator; - for (auto cellIdxAndWeight : matchingCells) - { - size_t cellIdx = cellIdxAndWeight.first; - double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); - calculator.addValueAndWeight(cellValue, cellIdxAndWeight.second); - } - if (calculator.validAggregatedWeight()) - { - return calculator.weightedMean(); - } - return std::numeric_limits::infinity(); - } - case RESULTS_GEOM_VALUE: - { - RiaWeightedGeometricMeanCalculator calculator; - for (auto cellIdxAndWeight : matchingCells) - { - size_t cellIdx = cellIdxAndWeight.first; - double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); - if (cellValue < 1.0e-8) - { - return 0.0; - } - calculator.addValueAndWeight(cellValue, cellIdxAndWeight.second); - } - if (calculator.validAggregatedWeight()) - { - return calculator.weightedMean(); - } - return std::numeric_limits::infinity(); - } - case RESULTS_HARM_VALUE: - { - RiaWeightedHarmonicMeanCalculator calculator; - for (auto cellIdxAndWeight : matchingCells) - { - size_t cellIdx = cellIdxAndWeight.first; - double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); - if (std::fabs(cellValue) < 1.0e-8) - { - return 0.0; - } - calculator.addValueAndWeight(cellValue, cellIdxAndWeight.second); - } - if (calculator.validAggregatedWeight()) - { - return calculator.weightedMean(); - } - return std::numeric_limits::infinity(); - } - case RESULTS_MAX_VALUE: - { - double maxValue = -std::numeric_limits::infinity(); - for (auto cellIdxAndWeight : matchingCells) - { - size_t cellIdx = cellIdxAndWeight.first; - double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); - maxValue = std::max(maxValue, cellValue); - } - return maxValue; - } - case RESULTS_MIN_VALUE: - { - double minValue = std::numeric_limits::infinity(); - for (auto cellIdxAndWeight : matchingCells) - { - size_t cellIdx = cellIdxAndWeight.first; - double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); - minValue = std::min(minValue, cellValue); - } - return minValue; - } - case RESULTS_VOLUME_SUM: - case RESULTS_SUM: - { - double sum = 0.0; - for (auto cellIdxAndWeight : matchingCells) - { - size_t cellIdx = cellIdxAndWeight.first; - double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); - sum += cellValue * cellIdxAndWeight.second; - } - return sum; - } - case RESULTS_OIL_COLUMN: - case RESULTS_GAS_COLUMN: - case RESULTS_HC_COLUMN: - { - double sum = 0.0; - for (auto cellIdxAndWeight : matchingCells) - { - size_t cellIdx = cellIdxAndWeight.first; - double cellValue = findColumnResult(m_resultAggregation(), cellIdx); - sum += cellValue * cellIdxAndWeight.second; - } - return sum; - } - default: - CVF_TIGHT_ASSERT(false); - } - } - return std::numeric_limits::infinity(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -double RimContourMapProjection::valueInCell(uint i, uint j) const -{ - size_t index = cellIndex(i, j); - if (index < numberOfCells()) - { - return m_aggregatedResults.at(index); - } - return std::numeric_limits::infinity(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimContourMapProjection::hasResultInCell(uint i, uint j) const -{ - RimEclipseCellColors* cellColors = view()->cellResult(); - - if (cellColors->isTernarySaturationSelected()) - { - return false; - } - return !cellsAtIJ(i, j).empty(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -uint RimContourMapProjection::numberOfCells() const -{ - return m_mapSize.x() * m_mapSize.y(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -uint RimContourMapProjection::numberOfValidCells() const -{ - uint validCount = 0u; - for (uint i = 0; i < numberOfCells(); ++i) - { - cvf::Vec2ui ij = ijFromCellIndex(i); - if (hasResultInCell(ij.x(), ij.y())) - { - validCount++; - } - } - return validCount; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -749,317 +477,6 @@ RimRegularLegendConfig* RimContourMapProjection::legendConfig() const return view()->cellResult()->legendConfig(); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimContourMapProjection::calculateTotalCellVisibility() -{ - m_cellGridIdxVisibility = view()->currentTotalCellVisibility(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec2d RimContourMapProjection::globalCellCenterPosition(uint i, uint j) const -{ - cvf::Vec3d gridExtent = m_fullBoundingBox.extent(); - cvf::Vec2d origin(m_fullBoundingBox.min().x(), m_fullBoundingBox.min().y()); - - cvf::Vec2d cellCorner = origin + cvf::Vec2d((i * gridExtent.x()) / (m_mapSize.x()), - (j * gridExtent.y()) / (m_mapSize.y())); - - return cellCorner + cvf::Vec2d(m_sampleSpacing*0.5, m_sampleSpacing * 0.5); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui RimContourMapProjection::ijFromLocalPos(const cvf::Vec2d& localPos2d) const -{ - uint i = localPos2d.x() / m_sampleSpacing; - uint j = localPos2d.y() / m_sampleSpacing; - return cvf::Vec2ui(i, j); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector> RimContourMapProjection::cellsAtIJ(uint i, uint j) const -{ - size_t cellIndex = this->cellIndex(i, j); - if (cellIndex < m_projected3dGridIndices.size()) - { - return m_projected3dGridIndices[cellIndex]; - } - return std::vector>(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector> RimContourMapProjection::visibleCellsAndOverlapVolumeFrom2dPoint(const cvf::Vec2d& globalPos2d, const std::vector* weightingResultValues) const -{ - cvf::Vec3d top2dElementCentroid(globalPos2d, m_fullBoundingBox.max().z()); - cvf::Vec3d bottom2dElementCentroid(globalPos2d, m_fullBoundingBox.min().z()); - cvf::Vec3d planarDiagonalVector(0.5 * m_sampleSpacing, 0.5 * m_sampleSpacing, 0.0); - cvf::Vec3d topNECorner = top2dElementCentroid + planarDiagonalVector; - cvf::Vec3d bottomSWCorner = bottom2dElementCentroid - planarDiagonalVector; - - cvf::BoundingBox bbox2dElement(bottomSWCorner, topNECorner); - - std::vector allCellIndices; - mainGrid()->findIntersectingCells(bbox2dElement, &allCellIndices); - - typedef std::map>> KLayerCellWeightMap; - KLayerCellWeightMap matchingVisibleCellsWeightPerKLayer; - - std::array hexCorners; - for (size_t globalCellIdx : allCellIndices) - { - if ((*m_cellGridIdxVisibility)[globalCellIdx]) - { - RigCell cell = mainGrid()->globalCellArray()[globalCellIdx]; - - size_t mainGridCellIdx = cell.mainGridCellIndex(); - size_t i, j, k; - mainGrid()->ijkFromCellIndex(mainGridCellIdx, &i, &j, &k); - - size_t localCellIdx = cell.gridLocalCellIndex(); - RigGridBase* localGrid = cell.hostGrid(); - - localGrid->cellCornerVertices(localCellIdx, hexCorners.data()); - - cvf::BoundingBox overlapBBox; - std::array overlapCorners = RigCellGeometryTools::estimateHexOverlapWithBoundingBox(hexCorners, bbox2dElement, &overlapBBox); - - double overlapVolume = RigCellGeometryTools::calculateCellVolume(overlapCorners); - - if (overlapVolume > 0.0) - { - double weight = overlapVolume; - if (weightingResultValues) - { - const RigActiveCellInfo* activeCellInfo = eclipseCase()->eclipseCaseData()->activeCellInfo(RiaDefines::MATRIX_MODEL); - size_t cellResultIdx = activeCellInfo->cellResultIndex(globalCellIdx); - double result = std::max((*weightingResultValues)[cellResultIdx], 0.0); - if (result < 1.0e-6) - { - result = 0.0; - } - weight *= result; - } - if (weight > 0.0) - { - matchingVisibleCellsWeightPerKLayer[k].push_back(std::make_pair(globalCellIdx, weight)); - } - } - } - } - - std::vector> matchingVisibleCellsAndWeight; - for (auto kLayerCellWeight : matchingVisibleCellsWeightPerKLayer) - { - for (auto cellWeight : kLayerCellWeight.second) - { - matchingVisibleCellsAndWeight.push_back(std::make_pair(cellWeight.first, cellWeight.second)); - } - } - - return matchingVisibleCellsAndWeight; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector> RimContourMapProjection::visibleCellsAndLengthInCellFrom2dPoint(const cvf::Vec2d& globalPos2d, const std::vector* weightingResultValues /*= nullptr*/) const -{ - cvf::Vec3d highestPoint(globalPos2d, m_fullBoundingBox.max().z()); - cvf::Vec3d lowestPoint(globalPos2d, m_fullBoundingBox.min().z()); - - cvf::BoundingBox rayBBox; - rayBBox.add(highestPoint); - rayBBox.add(lowestPoint); - - std::vector allCellIndices; - mainGrid()->findIntersectingCells(rayBBox, &allCellIndices); - - std::map>> matchingVisibleCellsAndWeightPerKLayer; - - cvf::Vec3d hexCorners[8]; - for (size_t globalCellIdx : allCellIndices) - { - if ((*m_cellGridIdxVisibility)[globalCellIdx]) - { - RigCell cell = mainGrid()->globalCellArray()[globalCellIdx]; - - size_t mainGridCellIdx = cell.mainGridCellIndex(); - size_t i, j, k; - mainGrid()->ijkFromCellIndex(mainGridCellIdx, &i, &j, &k); - - size_t localCellIdx = cell.gridLocalCellIndex(); - RigGridBase* localGrid = cell.hostGrid(); - - localGrid->cellCornerVertices(localCellIdx, hexCorners); - std::vector intersections; - - if (RigHexIntersectionTools::lineHexCellIntersection(highestPoint, lowestPoint, hexCorners, 0, &intersections)) - { - double lengthInCell = (intersections.back().m_intersectionPoint - intersections.front().m_intersectionPoint).length(); - matchingVisibleCellsAndWeightPerKLayer[k].push_back(std::make_pair(globalCellIdx, lengthInCell)); - } - } - } - - std::vector> matchingVisibleCellsAndWeight; - for (auto kLayerCellWeight : matchingVisibleCellsAndWeightPerKLayer) - { - // Make sure the sum of all weights in the same K-layer is 1. - double weightSumThisKLayer = 0.0; - for (auto cellWeight : kLayerCellWeight.second) - { - weightSumThisKLayer += cellWeight.second; - } - - for (auto cellWeight : kLayerCellWeight.second) - { - matchingVisibleCellsAndWeight.push_back(std::make_pair(cellWeight.first, cellWeight.second / weightSumThisKLayer)); - } - } - - return matchingVisibleCellsAndWeight; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -double RimContourMapProjection::findColumnResult(ResultAggregation resultAggregation, size_t cellGlobalIdx) const -{ - const RigCaseCellResultsData* resultData = eclipseCase()->results(RiaDefines::MATRIX_MODEL); - size_t poroResultIndex = resultData->findScalarResultIndex(RiaDefines::STATIC_NATIVE, "PORO"); - size_t ntgResultIndex = resultData->findScalarResultIndex(RiaDefines::STATIC_NATIVE, "NTG"); - size_t dzResultIndex = resultData->findScalarResultIndex(RiaDefines::STATIC_NATIVE, "DZ"); - - if (poroResultIndex == cvf::UNDEFINED_SIZE_T || ntgResultIndex == cvf::UNDEFINED_SIZE_T) - { - return std::numeric_limits::infinity(); - } - - const std::vector& poroResults = resultData->cellScalarResults(poroResultIndex)[0]; - const std::vector& ntgResults = resultData->cellScalarResults(ntgResultIndex)[0]; - const std::vector& dzResults = resultData->cellScalarResults(dzResultIndex)[0]; - - const RigActiveCellInfo* activeCellInfo = eclipseCase()->eclipseCaseData()->activeCellInfo(RiaDefines::MATRIX_MODEL); - size_t cellResultIdx = activeCellInfo->cellResultIndex(cellGlobalIdx); - - if (cellResultIdx >= poroResults.size() || cellResultIdx >= ntgResults.size()) - { - return std::numeric_limits::infinity(); - } - - double poro = poroResults.at(cellResultIdx); - double ntg = ntgResults.at(cellResultIdx); - double dz = dzResults.at(cellResultIdx); - - int timeStep = view()->currentTimeStep(); - - double resultValue = 0.0; - if (resultAggregation == RESULTS_OIL_COLUMN || resultAggregation == RESULTS_HC_COLUMN) - { - size_t soilResultIndex = resultData->findScalarResultIndex(RiaDefines::DYNAMIC_NATIVE, "SOIL"); - const std::vector& soilResults = resultData->cellScalarResults(soilResultIndex)[timeStep]; - if (cellResultIdx < soilResults.size()) - { - resultValue = soilResults.at(cellResultIdx); - } - } - if (resultAggregation == RESULTS_GAS_COLUMN || resultAggregation == RESULTS_HC_COLUMN) - { - size_t sgasResultIndex = resultData->findScalarResultIndex(RiaDefines::DYNAMIC_NATIVE, "SGAS"); - const std::vector& sgasResults = resultData->cellScalarResults(sgasResultIndex)[timeStep]; - if (cellResultIdx < sgasResults.size()) - { - resultValue += sgasResults.at(cellResultIdx); - } - } - - return resultValue * poro * ntg * dz; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const RimEclipseResultCase* RimContourMapProjection::eclipseCase() const -{ - const RimEclipseResultCase* eclipseCase = nullptr; - firstAncestorOrThisOfType(eclipseCase); - return eclipseCase; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimEclipseResultCase* RimContourMapProjection::eclipseCase() -{ - RimEclipseResultCase* eclipseCase = nullptr; - firstAncestorOrThisOfType(eclipseCase); - return eclipseCase; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimContourMapView* RimContourMapProjection::view() const -{ - RimContourMapView* view = nullptr; - firstAncestorOrThisOfTypeAsserted(view); - return view; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -size_t RimContourMapProjection::cellIndex(uint i, uint j) const -{ - CVF_ASSERT(i < m_mapSize.x()); - CVF_ASSERT(j < m_mapSize.y()); - - return i + j * m_mapSize.x(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -size_t RimContourMapProjection::vertexIndex(uint i, uint j) const -{ - return i + j * (m_mapSize.x() + 1); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui RimContourMapProjection::ijFromVertexIndex(size_t gridIndex) const -{ - cvf::Vec2ui gridSize = vertexGridSize(); - - uint quotientX = static_cast(gridIndex) / gridSize.x(); - uint remainderX = static_cast(gridIndex) % gridSize.x(); - - return cvf::Vec2ui(remainderX, quotientX); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui RimContourMapProjection::ijFromCellIndex(size_t cellIndex) const -{ - CVF_TIGHT_ASSERT(cellIndex < numberOfCells()); - - uint quotientX = static_cast(cellIndex) / m_mapSize.x(); - uint remainderX = static_cast(cellIndex) % m_mapSize.x(); - - return cvf::Vec2ui(remainderX, quotientX); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1098,44 +515,40 @@ void RimContourMapProjection::updateLegend() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +uint RimContourMapProjection::numberOfCells() const +{ + return m_mapSize.x() * m_mapSize.y(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +uint RimContourMapProjection::numberOfValidCells() const +{ + uint validCount = 0u; + for (uint i = 0; i < numberOfCells(); ++i) + { + cvf::Vec2ui ij = ijFromCellIndex(i); + if (hasResultInCell(ij.x(), ij.y())) + { + validCount++; + } + } + return validCount; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- size_t RimContourMapProjection::numberOfVertices() const { - cvf::Vec2ui gridSize = vertexGridSize(); + cvf::Vec2ui gridSize = numberOfVerticesIJ(); return static_cast(gridSize.x()) * static_cast(gridSize.y()); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimContourMapProjection::ResultAggregation RimContourMapProjection::resultAggregation() const -{ - return m_resultAggregation(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QString RimContourMapProjection::resultAggregationText() const -{ - return m_resultAggregation().uiText(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QString RimContourMapProjection::resultDescriptionText() const -{ - QString resultText = resultAggregationText(); - if (!isColumnResult()) - { - resultText += QString(", %1").arg(view()->cellResult()->resultVariable()); - } - - return resultText; -} //-------------------------------------------------------------------------------------------------- /// @@ -1205,55 +618,9 @@ void RimContourMapProjection::setPickPoint(cvf::Vec2d pickedPoint) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RimContourMapProjection::xVertexPositions() const -{ - double gridExtent = m_fullBoundingBox.extent().x(); - double origin = m_fullBoundingBox.min().x(); - - cvf::Vec2ui gridSize = vertexGridSize(); - std::vector positions; - positions.reserve(gridSize.x()); - for (uint i = 0; i < gridSize.x(); ++i) - { - positions.push_back(origin + (i * gridExtent) / (gridSize.x() - 1)); - } - - return positions; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector RimContourMapProjection::yVertexPositions() const -{ - double gridExtent = m_fullBoundingBox.extent().y(); - double origin = m_fullBoundingBox.min().y(); - - cvf::Vec2ui gridSize = vertexGridSize(); - std::vector positions; - positions.reserve(gridSize.y()); - for (uint j = 0; j < gridSize.y(); ++j) - { - positions.push_back(origin + (j * gridExtent) / (gridSize.y() - 1)); - } - - return positions; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RigMainGrid* RimContourMapProjection::mainGrid() const -{ - RimEclipseResultCase* eclipseCase = nullptr; - firstAncestorOrThisOfTypeAsserted(eclipseCase); - return eclipseCase->eclipseCaseData()->mainGrid(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimContourMapProjection::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) +void RimContourMapProjection::fieldChangedByUi(const caf::PdmFieldHandle* changedField, + const QVariant& oldValue, + const QVariant& newValue) { legendConfig()->disableAllTimeStepsRange(!getLegendRangeFrom3dGrid()); @@ -1269,8 +636,10 @@ void RimContourMapProjection::fieldChangedByUi(const caf::PdmFieldHandle* change //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimContourMapProjection::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute) -{ +void RimContourMapProjection::defineEditorAttribute(const caf::PdmFieldHandle* field, + QString uiConfigName, + caf::PdmUiEditorAttribute* attribute) +{ if (&m_relativeSampleSpacing == field) { caf::PdmUiDoubleSliderEditorAttribute* myAttr = dynamic_cast(attribute); @@ -1278,7 +647,7 @@ void RimContourMapProjection::defineEditorAttribute(const caf::PdmFieldHandle* f { myAttr->m_minimum = 0.25; myAttr->m_maximum = 2.0; - } + } } } @@ -1330,6 +699,593 @@ void RimContourMapProjection::initAfterRead() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimContourMapProjection::generateGridMapping() +{ + m_cellGridIdxVisibility = view()->currentTotalCellVisibility(); + + int nCells = numberOfCells(); + m_projected3dGridIndices.resize(nCells); + + const std::vector* weightingResultValues = nullptr; + if (m_weightByParameter()) + { + size_t gridScalarResultIdx = m_weightingResult->scalarResultIndex(); + if (gridScalarResultIdx != cvf::UNDEFINED_SIZE_T) + { + m_weightingResult->loadResult(); + int timeStep = 0; + if (m_weightingResult->hasDynamicResult()) + { + timeStep = view()->currentTimeStep(); + } + weightingResultValues = + &(m_weightingResult->currentGridCellResults()->cellScalarResults(gridScalarResultIdx)[timeStep]); + } + } + + if (isStraightSummationResult()) + { + for (int index = 0; index < nCells; ++index) + { + cvf::Vec2ui ij = ijFromCellIndex(index); + + cvf::Vec2d globalPos = globalCellCenterPosition(ij.x(), ij.y()); + m_projected3dGridIndices[index] = visibleCellsAndLengthInCellFrom2dPoint(globalPos, weightingResultValues); + } + } + else + { +#pragma omp parallel for + for (int index = 0; index < nCells; ++index) + { + cvf::Vec2ui ij = ijFromCellIndex(index); + + cvf::Vec2d globalPos = globalCellCenterPosition(ij.x(), ij.y()); + m_projected3dGridIndices[index] = visibleCellsAndOverlapVolumeFrom2dPoint(globalPos, weightingResultValues); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RimContourMapProjection::valueInCell(uint i, uint j) const +{ + size_t index = cellIndexFromIJ(i, j); + if (index < numberOfCells()) + { + return m_aggregatedResults.at(index); + } + return std::numeric_limits::infinity(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimContourMapProjection::hasResultInCell(uint i, uint j) const +{ + RimEclipseCellColors* cellColors = view()->cellResult(); + + if (cellColors->isTernarySaturationSelected()) + { + return false; + } + return !cellsAtIJ(i, j).empty(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RimContourMapProjection::calculateValueInCell(uint i, uint j) const +{ + if (!isColumnResult() && view()->cellResult()->scalarResultIndex() == cvf::UNDEFINED_SIZE_T) + { + return 0.0; // Special case of NONE-result. Show 0 all over to ensure we see something. + } + const std::vector>& matchingCells = cellsAtIJ(i, j); + if (!matchingCells.empty()) + { + switch (m_resultAggregation()) + { + case RESULTS_TOP_VALUE: + { + size_t cellIdx = matchingCells.front().first; + double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); + return cellValue; + } + case RESULTS_MEAN_VALUE: + { + RiaWeightedMeanCalculator calculator; + for (auto cellIdxAndWeight : matchingCells) + { + size_t cellIdx = cellIdxAndWeight.first; + double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); + calculator.addValueAndWeight(cellValue, cellIdxAndWeight.second); + } + if (calculator.validAggregatedWeight()) + { + return calculator.weightedMean(); + } + return std::numeric_limits::infinity(); + } + case RESULTS_GEOM_VALUE: + { + RiaWeightedGeometricMeanCalculator calculator; + for (auto cellIdxAndWeight : matchingCells) + { + size_t cellIdx = cellIdxAndWeight.first; + double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); + if (cellValue < 1.0e-8) + { + return 0.0; + } + calculator.addValueAndWeight(cellValue, cellIdxAndWeight.second); + } + if (calculator.validAggregatedWeight()) + { + return calculator.weightedMean(); + } + return std::numeric_limits::infinity(); + } + case RESULTS_HARM_VALUE: + { + RiaWeightedHarmonicMeanCalculator calculator; + for (auto cellIdxAndWeight : matchingCells) + { + size_t cellIdx = cellIdxAndWeight.first; + double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); + if (std::fabs(cellValue) < 1.0e-8) + { + return 0.0; + } + calculator.addValueAndWeight(cellValue, cellIdxAndWeight.second); + } + if (calculator.validAggregatedWeight()) + { + return calculator.weightedMean(); + } + return std::numeric_limits::infinity(); + } + case RESULTS_MAX_VALUE: + { + double maxValue = -std::numeric_limits::infinity(); + for (auto cellIdxAndWeight : matchingCells) + { + size_t cellIdx = cellIdxAndWeight.first; + double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); + maxValue = std::max(maxValue, cellValue); + } + return maxValue; + } + case RESULTS_MIN_VALUE: + { + double minValue = std::numeric_limits::infinity(); + for (auto cellIdxAndWeight : matchingCells) + { + size_t cellIdx = cellIdxAndWeight.first; + double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); + minValue = std::min(minValue, cellValue); + } + return minValue; + } + case RESULTS_VOLUME_SUM: + case RESULTS_SUM: + { + double sum = 0.0; + for (auto cellIdxAndWeight : matchingCells) + { + size_t cellIdx = cellIdxAndWeight.first; + double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx); + sum += cellValue * cellIdxAndWeight.second; + } + return sum; + } + case RESULTS_OIL_COLUMN: + case RESULTS_GAS_COLUMN: + case RESULTS_HC_COLUMN: + { + double sum = 0.0; + for (auto cellIdxAndWeight : matchingCells) + { + size_t cellIdx = cellIdxAndWeight.first; + double cellValue = findColumnResult(m_resultAggregation(), cellIdx); + sum += cellValue * cellIdxAndWeight.second; + } + return sum; + } + default: + CVF_TIGHT_ASSERT(false); + } + } + return std::numeric_limits::infinity(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RimContourMapProjection::calculateValueAtVertex(uint vi, uint vj) const +{ + std::vector averageIs; + std::vector averageJs; + + if (vi > 0u) averageIs.push_back(vi - 1); + if (vj > 0u) averageJs.push_back(vj - 1); + if (vi < m_mapSize.x()) averageIs.push_back(vi); + if (vj < m_mapSize.y()) averageJs.push_back(vj); + + RiaWeightedMeanCalculator calc; + for (uint j : averageJs) + { + for (uint i : averageIs) + { + if (hasResultInCell(i, j)) + { + calc.addValueAndWeight(valueInCell(i, j), 1.0); + } + } + } + if (calc.validAggregatedWeight()) + { + return calc.weightedMean(); + } + return std::numeric_limits::infinity(); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector> RimContourMapProjection::cellsAtIJ(uint i, uint j) const +{ + size_t cellIndex = this->cellIndexFromIJ(i, j); + if (cellIndex < m_projected3dGridIndices.size()) + { + return m_projected3dGridIndices[cellIndex]; + } + return std::vector>(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector> + RimContourMapProjection::visibleCellsAndOverlapVolumeFrom2dPoint(const cvf::Vec2d& globalPos2d, + const std::vector* weightingResultValues) const +{ + cvf::Vec3d top2dElementCentroid(globalPos2d, m_fullBoundingBox.max().z()); + cvf::Vec3d bottom2dElementCentroid(globalPos2d, m_fullBoundingBox.min().z()); + cvf::Vec3d planarDiagonalVector(0.5 * m_sampleSpacing, 0.5 * m_sampleSpacing, 0.0); + cvf::Vec3d topNECorner = top2dElementCentroid + planarDiagonalVector; + cvf::Vec3d bottomSWCorner = bottom2dElementCentroid - planarDiagonalVector; + + cvf::BoundingBox bbox2dElement(bottomSWCorner, topNECorner); + + std::vector allCellIndices; + m_mainGrid->findIntersectingCells(bbox2dElement, &allCellIndices); + + typedef std::map>> KLayerCellWeightMap; + KLayerCellWeightMap matchingVisibleCellsWeightPerKLayer; + + std::array hexCorners; + for (size_t globalCellIdx : allCellIndices) + { + if ((*m_cellGridIdxVisibility)[globalCellIdx]) + { + RigCell cell = m_mainGrid->globalCellArray()[globalCellIdx]; + + size_t mainGridCellIdx = cell.mainGridCellIndex(); + size_t i, j, k; + m_mainGrid->ijkFromCellIndex(mainGridCellIdx, &i, &j, &k); + + size_t localCellIdx = cell.gridLocalCellIndex(); + RigGridBase* localGrid = cell.hostGrid(); + + localGrid->cellCornerVertices(localCellIdx, hexCorners.data()); + + cvf::BoundingBox overlapBBox; + std::array overlapCorners = + RigCellGeometryTools::estimateHexOverlapWithBoundingBox(hexCorners, bbox2dElement, &overlapBBox); + + double overlapVolume = RigCellGeometryTools::calculateCellVolume(overlapCorners); + + if (overlapVolume > 0.0) + { + double weight = overlapVolume; + if (weightingResultValues) + { + const RigActiveCellInfo* activeCellInfo = + eclipseCase()->eclipseCaseData()->activeCellInfo(RiaDefines::MATRIX_MODEL); + size_t cellResultIdx = activeCellInfo->cellResultIndex(globalCellIdx); + double result = std::max((*weightingResultValues)[cellResultIdx], 0.0); + if (result < 1.0e-6) + { + result = 0.0; + } + weight *= result; + } + if (weight > 0.0) + { + matchingVisibleCellsWeightPerKLayer[k].push_back(std::make_pair(globalCellIdx, weight)); + } + } + } + } + + std::vector> matchingVisibleCellsAndWeight; + for (auto kLayerCellWeight : matchingVisibleCellsWeightPerKLayer) + { + for (auto cellWeight : kLayerCellWeight.second) + { + matchingVisibleCellsAndWeight.push_back(std::make_pair(cellWeight.first, cellWeight.second)); + } + } + + return matchingVisibleCellsAndWeight; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector> RimContourMapProjection::visibleCellsAndLengthInCellFrom2dPoint( + const cvf::Vec2d& globalPos2d, + const std::vector* weightingResultValues /*= nullptr*/) const +{ + cvf::Vec3d highestPoint(globalPos2d, m_fullBoundingBox.max().z()); + cvf::Vec3d lowestPoint(globalPos2d, m_fullBoundingBox.min().z()); + + cvf::BoundingBox rayBBox; + rayBBox.add(highestPoint); + rayBBox.add(lowestPoint); + + std::vector allCellIndices; + m_mainGrid->findIntersectingCells(rayBBox, &allCellIndices); + + std::map>> matchingVisibleCellsAndWeightPerKLayer; + + cvf::Vec3d hexCorners[8]; + for (size_t globalCellIdx : allCellIndices) + { + if ((*m_cellGridIdxVisibility)[globalCellIdx]) + { + RigCell cell = m_mainGrid->globalCellArray()[globalCellIdx]; + + size_t mainGridCellIdx = cell.mainGridCellIndex(); + size_t i, j, k; + m_mainGrid->ijkFromCellIndex(mainGridCellIdx, &i, &j, &k); + + size_t localCellIdx = cell.gridLocalCellIndex(); + RigGridBase* localGrid = cell.hostGrid(); + + localGrid->cellCornerVertices(localCellIdx, hexCorners); + std::vector intersections; + + if (RigHexIntersectionTools::lineHexCellIntersection(highestPoint, lowestPoint, hexCorners, 0, &intersections)) + { + double lengthInCell = + (intersections.back().m_intersectionPoint - intersections.front().m_intersectionPoint).length(); + matchingVisibleCellsAndWeightPerKLayer[k].push_back(std::make_pair(globalCellIdx, lengthInCell)); + } + } + } + + std::vector> matchingVisibleCellsAndWeight; + for (auto kLayerCellWeight : matchingVisibleCellsAndWeightPerKLayer) + { + // Make sure the sum of all weights in the same K-layer is 1. + double weightSumThisKLayer = 0.0; + for (auto cellWeight : kLayerCellWeight.second) + { + weightSumThisKLayer += cellWeight.second; + } + + for (auto cellWeight : kLayerCellWeight.second) + { + matchingVisibleCellsAndWeight.push_back(std::make_pair(cellWeight.first, cellWeight.second / weightSumThisKLayer)); + } + } + + return matchingVisibleCellsAndWeight; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RimContourMapProjection::findColumnResult(ResultAggregation resultAggregation, size_t cellGlobalIdx) const +{ + const RigCaseCellResultsData* resultData = eclipseCase()->results(RiaDefines::MATRIX_MODEL); + size_t poroResultIndex = resultData->findScalarResultIndex(RiaDefines::STATIC_NATIVE, "PORO"); + size_t ntgResultIndex = resultData->findScalarResultIndex(RiaDefines::STATIC_NATIVE, "NTG"); + size_t dzResultIndex = resultData->findScalarResultIndex(RiaDefines::STATIC_NATIVE, "DZ"); + + if (poroResultIndex == cvf::UNDEFINED_SIZE_T || ntgResultIndex == cvf::UNDEFINED_SIZE_T) + { + return std::numeric_limits::infinity(); + } + + const std::vector& poroResults = resultData->cellScalarResults(poroResultIndex)[0]; + const std::vector& ntgResults = resultData->cellScalarResults(ntgResultIndex)[0]; + const std::vector& dzResults = resultData->cellScalarResults(dzResultIndex)[0]; + + const RigActiveCellInfo* activeCellInfo = eclipseCase()->eclipseCaseData()->activeCellInfo(RiaDefines::MATRIX_MODEL); + size_t cellResultIdx = activeCellInfo->cellResultIndex(cellGlobalIdx); + + if (cellResultIdx >= poroResults.size() || cellResultIdx >= ntgResults.size()) + { + return std::numeric_limits::infinity(); + } + + double poro = poroResults.at(cellResultIdx); + double ntg = ntgResults.at(cellResultIdx); + double dz = dzResults.at(cellResultIdx); + + int timeStep = view()->currentTimeStep(); + + double resultValue = 0.0; + if (resultAggregation == RESULTS_OIL_COLUMN || resultAggregation == RESULTS_HC_COLUMN) + { + size_t soilResultIndex = resultData->findScalarResultIndex(RiaDefines::DYNAMIC_NATIVE, "SOIL"); + const std::vector& soilResults = resultData->cellScalarResults(soilResultIndex)[timeStep]; + if (cellResultIdx < soilResults.size()) + { + resultValue = soilResults.at(cellResultIdx); + } + } + if (resultAggregation == RESULTS_GAS_COLUMN || resultAggregation == RESULTS_HC_COLUMN) + { + size_t sgasResultIndex = resultData->findScalarResultIndex(RiaDefines::DYNAMIC_NATIVE, "SGAS"); + const std::vector& sgasResults = resultData->cellScalarResults(sgasResultIndex)[timeStep]; + if (cellResultIdx < sgasResults.size()) + { + resultValue += sgasResults.at(cellResultIdx); + } + } + + return resultValue * poro * ntg * dz; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimContourMapProjection::isMeanResult() const +{ + return m_resultAggregation() == RESULTS_MEAN_VALUE || m_resultAggregation() == RESULTS_HARM_VALUE || + m_resultAggregation() == RESULTS_GEOM_VALUE; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimContourMapProjection::isSummationResult() const +{ + return isStraightSummationResult() || m_resultAggregation() == RESULTS_VOLUME_SUM; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimContourMapProjection::isStraightSummationResult() const +{ + return isStraightSummationResult(m_resultAggregation()); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimContourMapProjection::isStraightSummationResult(ResultAggregationEnum aggregationType) +{ + return aggregationType == RESULTS_OIL_COLUMN || aggregationType == RESULTS_GAS_COLUMN || + aggregationType == RESULTS_HC_COLUMN || aggregationType == RESULTS_SUM; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RimContourMapProjection::cellIndexFromIJ(uint i, uint j) const +{ + CVF_ASSERT(i < m_mapSize.x()); + CVF_ASSERT(j < m_mapSize.y()); + + return i + j * m_mapSize.x(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RimContourMapProjection::vertexIndexFromIJ(uint i, uint j) const +{ + return i + j * (m_mapSize.x() + 1); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Vec2ui RimContourMapProjection::ijFromVertexIndex(size_t gridIndex) const +{ + cvf::Vec2ui gridSize = numberOfVerticesIJ(); + + uint quotientX = static_cast(gridIndex) / gridSize.x(); + uint remainderX = static_cast(gridIndex) % gridSize.x(); + + return cvf::Vec2ui(remainderX, quotientX); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Vec2ui RimContourMapProjection::ijFromCellIndex(size_t cellIndex) const +{ + CVF_TIGHT_ASSERT(cellIndex < numberOfCells()); + + uint quotientX = static_cast(cellIndex) / m_mapSize.x(); + uint remainderX = static_cast(cellIndex) % m_mapSize.x(); + + return cvf::Vec2ui(remainderX, quotientX); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Vec2ui RimContourMapProjection::ijFromLocalPos(const cvf::Vec2d& localPos2d) const +{ + uint i = localPos2d.x() / m_sampleSpacing; + uint j = localPos2d.y() / m_sampleSpacing; + return cvf::Vec2ui(i, j); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Vec2d RimContourMapProjection::globalCellCenterPosition(uint i, uint j) const +{ + cvf::Vec3d gridExtent = m_fullBoundingBox.extent(); + cvf::Vec2d origin(m_fullBoundingBox.min().x(), m_fullBoundingBox.min().y()); + + cvf::Vec2d cellCorner = origin + cvf::Vec2d((i * gridExtent.x()) / (m_mapSize.x()), (j * gridExtent.y()) / (m_mapSize.y())); + + return cellCorner + cvf::Vec2d(m_sampleSpacing * 0.5, m_sampleSpacing * 0.5); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimContourMapProjection::xVertexPositions() const +{ + double gridExtent = m_fullBoundingBox.extent().x(); + double origin = m_fullBoundingBox.min().x(); + + cvf::Vec2ui gridSize = numberOfVerticesIJ(); + std::vector positions; + positions.reserve(gridSize.x()); + for (uint i = 0; i < gridSize.x(); ++i) + { + positions.push_back(origin + (i * gridExtent) / (gridSize.x() - 1)); + } + + return positions; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimContourMapProjection::yVertexPositions() const +{ + double gridExtent = m_fullBoundingBox.extent().y(); + double origin = m_fullBoundingBox.min().y(); + + cvf::Vec2ui gridSize = numberOfVerticesIJ(); + std::vector positions; + positions.reserve(gridSize.y()); + for (uint j = 0; j < gridSize.y(); ++j) + { + positions.push_back(origin + (j * gridExtent) / (gridSize.y() - 1)); + } + + return positions; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1351,11 +1307,10 @@ bool RimContourMapProjection::getLegendRangeFrom3dGrid() const //-------------------------------------------------------------------------------------------------- void RimContourMapProjection::updateGridInformation() { - m_sampleSpacing = m_relativeSampleSpacing * mainGrid()->characteristicIJCellSize(); - + m_mainGrid = eclipseCase()->eclipseCaseData()->mainGrid(); + m_sampleSpacing = m_relativeSampleSpacing * m_mainGrid->characteristicIJCellSize(); m_fullBoundingBox = eclipseCase()->activeCellsBoundingBox(); - - m_mapSize = calculateMapSize(); + m_mapSize = calculateMapSize(); // Re-jig max point to be an exact multiple of cell size cvf::Vec3d minPoint = m_fullBoundingBox.min(); @@ -1378,3 +1333,22 @@ cvf::Vec2ui RimContourMapProjection::calculateMapSize() const return cvf::Vec2ui(projectionSizeX, projectionSizeY); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimEclipseResultCase* RimContourMapProjection::eclipseCase() const +{ + RimEclipseResultCase* eclipseCase = nullptr; + firstAncestorOrThisOfType(eclipseCase); + return eclipseCase; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimContourMapView* RimContourMapProjection::view() const +{ + RimContourMapView* view = nullptr; + firstAncestorOrThisOfTypeAsserted(view); + return view; +} diff --git a/ApplicationCode/ProjectDataModel/RimContourMapProjection.h b/ApplicationCode/ProjectDataModel/RimContourMapProjection.h index dbb4c7124d..05c5fbedc9 100644 --- a/ApplicationCode/ProjectDataModel/RimContourMapProjection.h +++ b/ApplicationCode/ProjectDataModel/RimContourMapProjection.h @@ -65,105 +65,116 @@ public: RimContourMapProjection(); ~RimContourMapProjection() override; - void generateVertices(cvf::Vec3fArray* vertices, const caf::DisplayCoordTransform* displayCoordTransform); - + void generateVertices(cvf::Vec3fArray* vertices, const caf::DisplayCoordTransform* displayCoordTransform); ContourPolygons generateContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform); cvf::ref generatePickPointPolygon(const caf::DisplayCoordTransform* displayCoordTransform); - void generateResults(); + + ResultAggregation resultAggregation() const; + double sampleSpacing() const; + double sampleSpacingFactor() const; + bool showContourLines() const; + + QString resultAggregationText() const; + QString resultDescriptionText() const; + QString weightingParameter() const; + double maxValue() const; double minValue() const; double meanValue() const; double sumAllValues() const; - double sampleSpacing() const; - double sampleSpacingFactor() const; - cvf::Vec2ui mapSize() const; - cvf::Vec2ui vertexGridSize() const; - bool showContourLines() const; + cvf::Vec2ui numberOfElementsIJ() const; + cvf::Vec2ui numberOfVerticesIJ() const; - const std::vector& aggregatedResults() const; - QString weightingParameter() const; - bool isMeanResult() const; - bool isSummationResult() const; - bool isStraightSummationResult() const; - static bool isStraightSummationResult(ResultAggregationEnum aggregationType); bool isColumnResult() const; double valueAtVertex(uint i, uint j) const; bool hasResultAtVertex(uint i, uint j) const; RimRegularLegendConfig* legendConfig() const; - - size_t cellIndex(uint i, uint j) const; - size_t vertexIndex(uint i, uint j) const; - cvf::Vec2ui ijFromVertexIndex(size_t gridIndex) const; - cvf::Vec2ui ijFromCellIndex(size_t mapIndex) const; void updateLegend(); - size_t numberOfVertices() const; uint numberOfCells() const; uint numberOfValidCells() const; + size_t numberOfVertices() const; - ResultAggregation resultAggregation() const; - QString resultAggregationText() const; - QString resultDescriptionText() const; void updatedWeightingResult(); - bool checkForMapIntersection(const cvf::Vec3d& localPoint3d, cvf::Vec2d* contourMapPoint, cvf::Vec2ui* contourMapCell, double* valueAtPoint) const; - void setPickPoint(cvf::Vec2d pickedPoint); + bool checkForMapIntersection(const cvf::Vec3d& localPoint3d, cvf::Vec2d* contourMapPoint, cvf::Vec2ui* contourMapCell, double* valueAtPoint) const; + void setPickPoint(cvf::Vec2d pickedPoint); protected: - double valueInCell(uint i, uint j) const; - bool hasResultInCell(uint i, uint j) const; - - double calculateValueInCell(uint i, uint j) const; - double calculateValueAtVertex(uint i, uint j) const; - - void generateGridMapping(); - void calculateTotalCellVisibility(); - cvf::Vec2d globalCellCenterPosition(uint i, uint j) const; - cvf::Vec2ui ijFromLocalPos(const cvf::Vec2d& localPos2d) const; - - std::vector> cellsAtIJ(uint i, uint j) const; - std::vector xVertexPositions() const; - std::vector yVertexPositions() const; - - std::vector> visibleCellsAndOverlapVolumeFrom2dPoint(const cvf::Vec2d& globalPos2d, const std::vector* weightingResultValues = nullptr) const; - std::vector> visibleCellsAndLengthInCellFrom2dPoint(const cvf::Vec2d& globalPos2d, const std::vector* weightingResultValues = nullptr) const; - double findColumnResult(ResultAggregation resultAggregation, size_t cellGlobalIdx) const; - const RimEclipseResultCase* eclipseCase() const; - RimEclipseResultCase* eclipseCase(); - RimContourMapView* view() const; - RigMainGrid* mainGrid() const; - void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; - void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute) override; + void defineEditorAttribute(const caf::PdmFieldHandle* field, + QString uiConfigName, + caf::PdmUiEditorAttribute* attribute) override; void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override; void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "") override; - void initAfterRead() override; - bool getLegendRangeFrom3dGrid() const; - void updateGridInformation(); - cvf::Vec2ui calculateMapSize() const; + void initAfterRead() override; + +private: + typedef std::pair CellIndexAndResult; + +private: + void generateGridMapping(); + + double valueInCell(uint i, uint j) const; + bool hasResultInCell(uint i, uint j) const; + + double calculateValueInCell(uint i, uint j) const; + double calculateValueAtVertex(uint i, uint j) const; + + + std::vector cellsAtIJ(uint i, uint j) const; + + std::vector visibleCellsAndOverlapVolumeFrom2dPoint(const cvf::Vec2d& globalPos2d, const std::vector* weightingResultValues = nullptr) const; + std::vector visibleCellsAndLengthInCellFrom2dPoint(const cvf::Vec2d& globalPos2d, const std::vector* weightingResultValues = nullptr) const; + double findColumnResult(ResultAggregation resultAggregation, size_t cellGlobalIdx) const; + + bool isMeanResult() const; + bool isSummationResult() const; + bool isStraightSummationResult() const; + static bool isStraightSummationResult(ResultAggregationEnum aggregationType); + + size_t cellIndexFromIJ(uint i, uint j) const; + size_t vertexIndexFromIJ(uint i, uint j) const; + + cvf::Vec2ui ijFromVertexIndex(size_t gridIndex) const; + cvf::Vec2ui ijFromCellIndex(size_t mapIndex) const; + cvf::Vec2ui ijFromLocalPos(const cvf::Vec2d& localPos2d) const; + cvf::Vec2d globalCellCenterPosition(uint i, uint j) const; + + std::vector xVertexPositions() const; + std::vector yVertexPositions() const; + + bool getLegendRangeFrom3dGrid() const; + void updateGridInformation(); + cvf::Vec2ui calculateMapSize() const; + + RimEclipseResultCase* eclipseCase() const; + RimContourMapView* view() const; protected: - caf::PdmField m_relativeSampleSpacing; - caf::PdmField m_resultAggregation; - caf::PdmField m_showContourLines; - caf::PdmField m_weightByParameter; - caf::PdmChildField m_weightingResult; - cvf::ref m_cellGridIdxVisibility; + caf::PdmField m_relativeSampleSpacing; + caf::PdmField m_resultAggregation; + caf::PdmField m_showContourLines; + caf::PdmField m_weightByParameter; + caf::PdmChildField m_weightingResult; + cvf::ref m_cellGridIdxVisibility; - std::vector m_aggregatedResults; - std::vector m_aggregatedVertexResults; + std::vector m_aggregatedResults; + std::vector m_aggregatedVertexResults; std::vector>> m_projected3dGridIndices; - cvf::ref m_resultAccessor; + cvf::ref m_resultAccessor; - cvf::Vec2d m_pickPoint; + cvf::Vec2d m_pickPoint; - cvf::Vec2ui m_mapSize; - cvf::BoundingBox m_fullBoundingBox; - double m_sampleSpacing; + caf::PdmPointer m_eclipseCase; + cvf::ref m_mainGrid; + cvf::Vec2ui m_mapSize; + cvf::BoundingBox m_fullBoundingBox; + double m_sampleSpacing; }; diff --git a/ApplicationCode/ProjectDataModel/RimContourMapView.cpp b/ApplicationCode/ProjectDataModel/RimContourMapView.cpp index 869eb82769..711b843e2d 100644 --- a/ApplicationCode/ProjectDataModel/RimContourMapView.cpp +++ b/ApplicationCode/ProjectDataModel/RimContourMapView.cpp @@ -120,18 +120,6 @@ QString RimContourMapView::createAutoName() const return autoName.join(": "); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimContourMapView::isTimeStepDependentDataVisible() const -{ - if (RimEclipseView::isTimeStepDependentDataVisible()) - { - return true; - } - return m_contourMapProjection->isChecked(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -153,6 +141,12 @@ void RimContourMapView::createDisplayModel() { RimEclipseView::createDisplayModel(); + if (!this->isTimeStepDependentDataVisible()) + { + // Need to add geometry even if it hasn't happened during dynamic time step update. + updateGeometry(); + } + if (this->viewer()->mainCamera()->viewMatrix() == defaultViewMatrix) { this->zoomAll(); @@ -199,9 +193,16 @@ void RimContourMapView::defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrder void RimContourMapView::updateCurrentTimeStep() { static_cast(nativePropertyFilterCollection())->updateFromCurrentTimeStep(); + updateGeometry(); +} +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimContourMapView::updateGeometry() +{ this->updateVisibleGeometriesAndCellColors(); - + if (m_contourMapProjection->isChecked()) { m_contourMapProjection->generateResults(); diff --git a/ApplicationCode/ProjectDataModel/RimContourMapView.h b/ApplicationCode/ProjectDataModel/RimContourMapView.h index 4536dc8fdc..0d29303d3f 100644 --- a/ApplicationCode/ProjectDataModel/RimContourMapView.h +++ b/ApplicationCode/ProjectDataModel/RimContourMapView.h @@ -33,7 +33,6 @@ public: RimContourMapProjection* contourMapProjection() const; QString createAutoName() const override; - bool isTimeStepDependentDataVisible() const override; protected: void initAfterRead() override; @@ -41,7 +40,7 @@ protected: void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override; void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "") override; void updateCurrentTimeStep() override; - + void updateGeometry(); void setFaultVisParameters(); void appendContourMapProjectionToModel(); void appendPickPointVisToModel(); diff --git a/ApplicationCode/ProjectDataModel/RimGridCollection.cpp b/ApplicationCode/ProjectDataModel/RimGridCollection.cpp index 7187fc3506..cfbdf6196b 100644 --- a/ApplicationCode/ProjectDataModel/RimGridCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimGridCollection.cpp @@ -476,7 +476,10 @@ void RimGridCollection::defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrder { uiTreeOrdering.add(m_persistentLgrs()); } - uiTreeOrdering.add(m_temporaryLgrs()); + if (hasTemporaryLgrs()) + { + uiTreeOrdering.add(m_temporaryLgrs()); + } uiTreeOrdering.skipRemainingChildren(true); } @@ -505,3 +508,20 @@ bool RimGridCollection::hasPersistentLgrs() const } return false; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimGridCollection::hasTemporaryLgrs() const +{ + auto mainGrid = this->mainGrid(); + if (!mainGrid) return false; + + for (size_t i = 1; i < mainGrid->gridCount(); i++) + { + const auto grid = mainGrid->gridByIndex(i); + if (grid->isTempGrid()) return true; + } + return false; +} + diff --git a/ApplicationCode/ProjectDataModel/RimGridCollection.h b/ApplicationCode/ProjectDataModel/RimGridCollection.h index 83ca2e20d2..c8d7b18a0c 100644 --- a/ApplicationCode/ProjectDataModel/RimGridCollection.h +++ b/ApplicationCode/ProjectDataModel/RimGridCollection.h @@ -117,6 +117,7 @@ protected: private: const RigMainGrid* mainGrid() const; bool hasPersistentLgrs() const; + bool hasTemporaryLgrs() const; caf::PdmField m_isActive; caf::PdmChildField m_mainGrid; diff --git a/ApplicationCode/ProjectDataModel/RimWellPathAttribute.cpp b/ApplicationCode/ProjectDataModel/RimWellPathAttribute.cpp index a7835e20e1..23bfff2eaf 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathAttribute.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPathAttribute.cpp @@ -218,6 +218,13 @@ void RimWellPathAttribute::fieldChangedByUi(const caf::PdmFieldHandle* changedFi m_startMD = wellPath->wellPathGeometry()->measureDepths().front(); } } + if (changedField == &m_startMD) + { + if (m_type() == RiaDefines::PACKER) + { + m_endMD = m_startMD + 50; + } + } { RimWellPathAttributeCollection* collection = nullptr; @@ -237,9 +244,7 @@ void RimWellPathAttribute::fieldChangedByUi(const caf::PdmFieldHandle* changedFi void RimWellPathAttribute::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) { bool startDepthAvailable = m_type() != RiaDefines::CASING; - bool endDepthAvailable = m_type() != RiaDefines::PACKER; m_startMD.uiCapability()->setUiReadOnly(!startDepthAvailable); - m_endMD.uiCapability()->setUiReadOnly(!endDepthAvailable); m_diameterInInches.uiCapability()->setUiReadOnly(!isDiameterSupported()); } diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurveAutoName.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurveAutoName.cpp index c3e2c7001b..ea8bb162fe 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurveAutoName.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurveAutoName.cpp @@ -305,7 +305,7 @@ void RimSummaryCurveAutoName::appendAddressDetails(std::string& if (m_wellSegmentNumber) { if (!text.empty()) text += ":"; - text += ":" + summaryAddress.wellSegmentNumber(); + text += std::to_string(summaryAddress.wellSegmentNumber()); } } break; diff --git a/ApplicationCode/UserInterface/RiuSummaryCurveDefSelection.cpp b/ApplicationCode/UserInterface/RiuSummaryCurveDefSelection.cpp index 258c8f88e9..c5dde90a83 100644 --- a/ApplicationCode/UserInterface/RiuSummaryCurveDefSelection.cpp +++ b/ApplicationCode/UserInterface/RiuSummaryCurveDefSelection.cpp @@ -19,6 +19,7 @@ #include "RiuSummaryCurveDefSelection.h" #include "RiaApplication.h" +#include "RiaStdStringTools.h" #include "RiaSummaryCurveDefinition.h" #include "RiaCurveSetDefinition.h" @@ -421,13 +422,10 @@ void RiuSummaryCurveDefSelection::setDefaultSelection(const std::vectorproject(); auto allSumCases = proj->allSummaryCases(); auto allSumGroups = proj->summaryGroups(); - bool hasEnsembles = std::count_if(allSumGroups.begin(), allSumGroups.end(), - [](const RimSummaryCaseCollection* sumGroup) { return sumGroup->isEnsemble(); }) > 0; if (allSumCases.size() > 0) { - RifEclipseSummaryAddress defaultAddress = !hasEnsembles ? - RifEclipseSummaryAddress::fieldAddress("FOPT") : RifEclipseSummaryAddress(); + RifEclipseSummaryAddress defaultAddress = RifEclipseSummaryAddress(); std::vector selectTheseSources = defaultSources; if (selectTheseSources.empty()) selectTheseSources.push_back(allSumCases[0]); @@ -727,7 +725,34 @@ QList RiuSummaryCurveDefSelection::calculateValueOptions } auto itemPostfix = (isVectorField && i == OBS_DATA) ? QString(OBSERVED_DATA_AVALUE_POSTFIX) : QString(""); - for (const auto& itemName : itemNames[i]) + + // Sort numeric identifiers by numeric val + std::vector itemNamesVector; + { + switch (identifierAndField->summaryIdentifier()) + { + case RifEclipseSummaryAddress::INPUT_REGION_NUMBER: + case RifEclipseSummaryAddress::INPUT_SEGMENT_NUMBER: + case RifEclipseSummaryAddress::INPUT_AQUIFER_NUMBER: + { + std::set values; + for (const std::string& itemName : itemNames[i]) + { + values.insert(RiaStdStringTools::toInt(itemName)); + } + for (int v : values) + { + itemNamesVector.push_back(std::to_string(v)); + } + break; + } + default: + itemNamesVector.insert(itemNamesVector.end(), itemNames[i].begin(), itemNames[i].end()); + break; + } + } + + for (const auto& itemName : itemNamesVector) { QString displayName; diff --git a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp index 7352ff7994..e71b46b904 100644 --- a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp @@ -47,6 +47,8 @@ #include +#include + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -169,6 +171,27 @@ void caf::TrackBallBasedNavigation::zoomAlongRay(cvf::Ray* ray, int delta) m_viewer->updateParallelProjectionHeightFromMoveZoom(m_pointOfInterest); m_viewer->updateParallelProjectionCameraPosFromPointOfInterestMove(m_pointOfInterest); + // Ceeviz Workaround for #3697: + // Ceeviz may create a singular projection*view matrix internally. In which case we need to revert. + cvf::Mat4d projectionMatrix = m_viewer->mainCamera()->projectionMatrix(); + cvf::Mat4d viewMatrix = m_viewer->mainCamera()->viewMatrix(); + cvf::Mat4d multMatrix = projectionMatrix * viewMatrix; + double determinant = std::fabs(multMatrix.determinant()); + + if (determinant < 1.0e-15) + { + m_viewer->mainCamera()->setFromLookAt(pos, vrp, up); + m_viewer->updateParallelProjectionHeightFromMoveZoom(m_pointOfInterest); + m_viewer->updateParallelProjectionCameraPosFromPointOfInterestMove(m_pointOfInterest); +#ifndef NDEBUG + projectionMatrix = m_viewer->mainCamera()->projectionMatrix(); + viewMatrix = m_viewer->mainCamera()->viewMatrix(); + multMatrix = projectionMatrix * viewMatrix; + determinant = std::fabs(multMatrix.determinant()); + CVF_ASSERT(determinant > 1.0e-15); +#endif + } + m_viewer->navigationPolicyUpdate(); } }