From 14f91736b711321cbc06224c99ce3c398cb05709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rnar=20Grip=20Fj=C3=A6r?= Date: Thu, 15 Jun 2017 11:21:37 +0200 Subject: [PATCH] #1607 Optionally split export of completions over several files --- .../RicCaseAndFileExportSettingsUi.cpp | 8 +- .../RicCaseAndFileExportSettingsUi.h | 2 +- .../RicExportFishbonesWellSegmentsFeature.cpp | 9 +- ...RicWellPathExportCompletionDataFeature.cpp | 95 ++++++++++++++++--- .../RicWellPathExportCompletionDataFeature.h | 2 + .../Completions/RimFishbonesMultipleSubs.cpp | 5 +- 6 files changed, 96 insertions(+), 25 deletions(-) diff --git a/ApplicationCode/Commands/CompletionCommands/RicCaseAndFileExportSettingsUi.cpp b/ApplicationCode/Commands/CompletionCommands/RicCaseAndFileExportSettingsUi.cpp index e36855aeac..7925b2ad50 100644 --- a/ApplicationCode/Commands/CompletionCommands/RicCaseAndFileExportSettingsUi.cpp +++ b/ApplicationCode/Commands/CompletionCommands/RicCaseAndFileExportSettingsUi.cpp @@ -31,8 +31,8 @@ RicCaseAndFileExportSettingsUi::RicCaseAndFileExportSettingsUi() { CAF_PDM_InitObject("RimCaseAndFileExportSettings", "", "", ""); - CAF_PDM_InitFieldNoDefault(&fileName, "Filename", "Export Filename", "", "", ""); - fileName.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName()); + CAF_PDM_InitFieldNoDefault(&folder, "Folder", "Export Folder", "", "", ""); + folder.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName()); CAF_PDM_InitFieldNoDefault(&caseToApply, "CaseToApply", "Case to Apply", "", "", ""); } @@ -57,12 +57,12 @@ QList RicCaseAndFileExportSettingsUi::calculateValueOpti //-------------------------------------------------------------------------------------------------- void RicCaseAndFileExportSettingsUi::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute) { - if (field == &fileName) + if (field == &folder) { caf::PdmUiFilePathEditorAttribute* myAttr = static_cast(attribute); if (myAttr) { - myAttr->m_selectSaveFileName = true; + myAttr->m_selectDirectory = true; } } } diff --git a/ApplicationCode/Commands/CompletionCommands/RicCaseAndFileExportSettingsUi.h b/ApplicationCode/Commands/CompletionCommands/RicCaseAndFileExportSettingsUi.h index 20b31a090d..eeb2d126b6 100644 --- a/ApplicationCode/Commands/CompletionCommands/RicCaseAndFileExportSettingsUi.h +++ b/ApplicationCode/Commands/CompletionCommands/RicCaseAndFileExportSettingsUi.h @@ -35,7 +35,7 @@ public: RicCaseAndFileExportSettingsUi(); - caf::PdmField fileName; + caf::PdmField folder; caf::PdmPtrField caseToApply; virtual QList calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) override; diff --git a/ApplicationCode/Commands/CompletionCommands/RicExportFishbonesWellSegmentsFeature.cpp b/ApplicationCode/Commands/CompletionCommands/RicExportFishbonesWellSegmentsFeature.cpp index 34ca9fa51c..82610ce293 100644 --- a/ApplicationCode/Commands/CompletionCommands/RicExportFishbonesWellSegmentsFeature.cpp +++ b/ApplicationCode/Commands/CompletionCommands/RicExportFishbonesWellSegmentsFeature.cpp @@ -74,12 +74,12 @@ void RicExportFishbonesWellSegmentsFeature::onActionTriggered(bool isChecked) } } - exportSettings.fileName = QDir(defaultDir).filePath("WellSegments"); + exportSettings.folder = defaultDir; caf::PdmUiPropertyViewDialog propertyDialog(RiuMainWindow::instance(), &exportSettings, "Export Completion Data", ""); if (propertyDialog.exec() == QDialog::Accepted) { - RiaApplication::instance()->setLastUsedDialogDirectory("COMPLETIONS", QFileInfo(exportSettings.fileName).absolutePath()); + RiaApplication::instance()->setLastUsedDialogDirectory("COMPLETIONS", QFileInfo(exportSettings.folder).absolutePath()); std::vector fishbonesSubs; for (RimFishbonesMultipleSubs* subs : fishbonesCollection->fishbonesSubs) @@ -153,7 +153,8 @@ bool RicExportFishbonesWellSegmentsFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicExportFishbonesWellSegmentsFeature::exportWellSegments(const RimWellPath* wellPath, const std::vector& fishbonesSubs, const RicExportWellSegmentsSettingsUi& settings) { - QFile exportFile(settings.fileName()); + QString filePath = QDir(settings.folder()).filePath("Welsegs"); + QFile exportFile(filePath); if (settings.caseToApply() == nullptr) { @@ -163,7 +164,7 @@ void RicExportFishbonesWellSegmentsFeature::exportWellSegments(const RimWellPath if (!exportFile.open(QIODevice::WriteOnly)) { - RiaLogging::error(QString("Export Well Segments: Could not open the file: %1").arg(settings.fileName())); + RiaLogging::error(QString("Export Well Segments: Could not open the file: %1").arg(filePath)); return; } diff --git a/ApplicationCode/Commands/CompletionCommands/RicWellPathExportCompletionDataFeature.cpp b/ApplicationCode/Commands/CompletionCommands/RicWellPathExportCompletionDataFeature.cpp index 7fa6ad98dd..309c4c732c 100644 --- a/ApplicationCode/Commands/CompletionCommands/RicWellPathExportCompletionDataFeature.cpp +++ b/ApplicationCode/Commands/CompletionCommands/RicWellPathExportCompletionDataFeature.cpp @@ -92,12 +92,12 @@ void RicWellPathExportCompletionDataFeature::onActionTriggered(bool isChecked) } } - exportSettings.fileName = QDir(defaultDir).filePath("Completions"); + exportSettings.folder = defaultDir; caf::PdmUiPropertyViewDialog propertyDialog(RiuMainWindow::instance(), &exportSettings, "Export Completion Data", ""); if (propertyDialog.exec() == QDialog::Accepted) { - RiaApplication::instance()->setLastUsedDialogDirectory("COMPLETIONS", QFileInfo(exportSettings.fileName).absolutePath()); + RiaApplication::instance()->setLastUsedDialogDirectory("COMPLETIONS", QFileInfo(exportSettings.folder).absolutePath()); exportCompletions(wellPaths, exportSettings); } @@ -140,7 +140,6 @@ std::vector RicWellPathExportCompletionDataFeature::selectedWellPa //-------------------------------------------------------------------------------------------------- void RicWellPathExportCompletionDataFeature::exportCompletions(const std::vector& wellPaths, const RicExportCompletionDataSettingsUi& exportSettings) { - QFile exportFile(exportSettings.fileName()); if (exportSettings.caseToApply() == nullptr) { @@ -148,12 +147,6 @@ void RicWellPathExportCompletionDataFeature::exportCompletions(const std::vector return; } - if (!exportFile.open(QIODevice::WriteOnly)) - { - RiaLogging::error(QString("Export Completions Data: Could not open the file: %1").arg(exportSettings.fileName())); - return; - } - { bool unitSystemMismatch = false; for (const RimWellPath* wellPath : wellPaths) @@ -176,8 +169,6 @@ void RicWellPathExportCompletionDataFeature::exportCompletions(const std::vector } } - QTextStream stream(&exportFile); - RifEclipseDataTableFormatter formatter(stream); std::map > completionData; @@ -209,16 +200,94 @@ void RicWellPathExportCompletionDataFeature::exportCompletions(const std::vector { completions.push_back(RigCompletionData::combine(data.second)); } + + const QString eclipseCaseName = exportSettings.caseToApply->caseUserDescription(); + + if (exportSettings.fileSplit == RicExportCompletionDataSettingsUi::UNIFIED_FILE) + { + const QString fileName = QString("UnifiedCompletions_%1").arg(eclipseCaseName); + printCompletionsToFile(exportSettings.folder, fileName, completions, exportSettings.includeWpimult); + } + else if (exportSettings.fileSplit == RicExportCompletionDataSettingsUi::SPLIT_ON_WELL) + { + for (auto wellPath : wellPaths) + { + std::vector wellCompletions; + for (auto completion : completions) + { + if (completion.wellName() == wellPath->completions()->wellNameForExport()) + { + wellCompletions.push_back(completion); + } + } + + QString fileName = QString("%1_unifiedCompletions_%2").arg(wellPath->name()).arg(eclipseCaseName); + printCompletionsToFile(exportSettings.folder, fileName, wellCompletions, exportSettings.includeWpimult); + } + } + else if (exportSettings.fileSplit == RicExportCompletionDataSettingsUi::SPLIT_ON_WELL_AND_COMPLETION_TYPE) + { + for (auto wellPath : wellPaths) + { + { + std::vector fishbonesCompletions = getCompletionsForWellAndCompletionType(completions, wellPath->completions()->wellNameForExport(), RigCompletionData::FISHBONES); + QString fileName = QString("%1_Fishbones_%2").arg(wellPath->name()).arg(eclipseCaseName); + printCompletionsToFile(exportSettings.folder, fileName, fishbonesCompletions, exportSettings.includeWpimult); + } + { + std::vector perforationCompletions = getCompletionsForWellAndCompletionType(completions, wellPath->completions()->wellNameForExport(), RigCompletionData::PERFORATION); + QString fileName = QString("%1_Perforations_%2").arg(wellPath->name()).arg(eclipseCaseName); + printCompletionsToFile(exportSettings.folder, fileName, perforationCompletions, exportSettings.includeWpimult); + } + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicWellPathExportCompletionDataFeature::printCompletionsToFile(const QString& exportFolder, const QString& fileName, std::vector& completions, bool includeWpimult) +{ + QString filePath = QDir(exportFolder).filePath(fileName); + QFile exportFile(filePath); + if (!exportFile.open(QIODevice::WriteOnly)) + { + RiaLogging::error(QString("Export Completions Data: Could not open the file: %1").arg(filePath)); + return; + } + + QTextStream stream(&exportFile); + RifEclipseDataTableFormatter formatter(stream); + // Sort by well name / cell index std::sort(completions.begin(), completions.end()); + // Print completion data generateCompdatTable(formatter, completions); - if (exportSettings.includeWpimult) + if (includeWpimult) { generateWpimultTable(formatter, completions); } - RiaLogging::info(QString("Successfully exported completion data to %1").arg(exportSettings.fileName())); + RiaLogging::info(QString("Successfully exported completion data to %1").arg(filePath)); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RicWellPathExportCompletionDataFeature::getCompletionsForWellAndCompletionType(const std::vector& completions, + const QString& wellName, + RigCompletionData::CompletionType completionType) +{ + std::vector filteredCompletions; + for (auto completion : completions) + { + if (completion.wellName() == wellName && completion.completionType() == completionType) + { + filteredCompletions.push_back(completion); + } + } + return filteredCompletions; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/CompletionCommands/RicWellPathExportCompletionDataFeature.h b/ApplicationCode/Commands/CompletionCommands/RicWellPathExportCompletionDataFeature.h index 7add6e336d..9e29fc008c 100644 --- a/ApplicationCode/Commands/CompletionCommands/RicWellPathExportCompletionDataFeature.h +++ b/ApplicationCode/Commands/CompletionCommands/RicWellPathExportCompletionDataFeature.h @@ -139,6 +139,8 @@ public: static double calculateTransmissibility(RimEclipseCase* eclipseCase, const RimWellPath* wellPath, const cvf::Vec3d& internalCellLengths, double skinFactor, double wellRadius, size_t cellIndex, size_t volumeScaleConstant = 1, QString directionForVolumeScaling = "DX"); private: static void exportCompletions(const std::vector& wellPaths, const RicExportCompletionDataSettingsUi& exportSettings); + static void printCompletionsToFile(const QString& exportFolder, const QString& fileName, std::vector& completions, bool includeWpimult); + static std::vector getCompletionsForWellAndCompletionType(const std::vector& completions, const QString& wellName, RigCompletionData::CompletionType completionType); static void generateCompdatTable(RifEclipseDataTableFormatter& formatter, const std::vector& completionData); static void generateWpimultTable(RifEclipseDataTableFormatter& formatter, const std::vector& completionData); diff --git a/ApplicationCode/ProjectDataModel/Completions/RimFishbonesMultipleSubs.cpp b/ApplicationCode/ProjectDataModel/Completions/RimFishbonesMultipleSubs.cpp index 3b6cd5fd80..47f9d08c51 100644 --- a/ApplicationCode/ProjectDataModel/Completions/RimFishbonesMultipleSubs.cpp +++ b/ApplicationCode/ProjectDataModel/Completions/RimFishbonesMultipleSubs.cpp @@ -128,7 +128,6 @@ void RimFishbonesMultipleSubs::setMeasuredDepthAndCount(double measuredDepth, do computeRangesAndLocations(); computeRotationAngles(); - computeSubLateralIndices(); } //-------------------------------------------------------------------------------------------------- @@ -275,8 +274,7 @@ void RimFishbonesMultipleSubs::fieldChangedByUi(const caf::PdmFieldHandle* chang computeRotationAngles(); } - if (recomputeLocations || - changedField == &m_locationOfSubs || + if (changedField == &m_locationOfSubs || changedField == &m_lateralInstallSuccessFraction || changedField == &m_lateralCountPerSub) { @@ -338,6 +336,7 @@ void RimFishbonesMultipleSubs::computeRangesAndLocations() RimFishbonesCollection* collection; this->firstAncestorOrThisOfTypeAsserted(collection); + computeSubLateralIndices(); collection->recalculateStartMD(); }