#3446 #3445 LGR Export. Per cell LGR export

This commit is contained in:
Bjørn Erik Jensen 2018-10-09 08:01:56 +02:00
parent 83b93e1a1e
commit f16ad3d3dc
4 changed files with 202 additions and 3 deletions

View File

@ -19,12 +19,21 @@
#include "RicExportCarfinForCompletionsFeature.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "CompletionExportCommands/RicWellPathExportCompletionDataFeature.h"
#include "RicExportCarfinForCompletionsUi.h"
#include "RifEclipseDataTableFormatter.h"
#include "RigCaseCellResultsData.h"
#include "RigResultAccessor.h"
#include "RigResultAccessorFactory.h"
#include "RigVirtualPerforationTransmissibilities.h"
#include "RimDialogData.h"
#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RimWellPath.h"
#include "RimProject.h"
#include "RimWellPathCollection.h"
@ -34,9 +43,13 @@
#include <cafPdmUiPropertyViewDialog.h>
#include <cafSelectionManager.h>
#include <cafSelectionManagerTools.h>
#include <cafVecIjk.h>
#include <QAction>
#include <QFileInfo>
#include <QDir>
#include <QFile>
#include <QTextStream>
CAF_CMD_SOURCE_INIT(RicExportCarfinForCompletionsFeature, "RicExportCarfinForCompletionsFeature");
@ -49,7 +62,7 @@ RicExportCarfinForCompletionsUi* RicExportCarfinForCompletionsFeature::openDialo
RiaApplication* app = RiaApplication::instance();
RimProject* proj = app->project();
QString startPath = app->lastUsedDialogDirectory("WELL_PATH_EXPORT_DIR");
QString startPath = app->lastUsedDialogDirectory("CARFIN_DIR");
if (startPath.isEmpty())
{
QFileInfo fi(proj->fileName());
@ -82,12 +95,90 @@ RicExportCarfinForCompletionsUi* RicExportCarfinForCompletionsFeature::openDialo
if (propertyDialog.exec() == QDialog::Accepted && !featureUi->exportFolder().isEmpty())
{
app->setLastUsedDialogDirectory("WELL_PATH_EXPORT_DIR", featureUi->exportFolder());
app->setLastUsedDialogDirectory("CARFIN_DIR", featureUi->exportFolder());
return featureUi;
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicExportCarfinForCompletionsFeature::openFileForExport(const QString& folderName, const QString& fileName, QFile* exportFile)
{
QDir exportFolder = QDir(folderName);
if (!exportFolder.exists())
{
bool createdPath = exportFolder.mkpath(".");
if (createdPath)
RiaLogging::info("Created export folder " + folderName);
}
QString filePath = exportFolder.filePath(fileName);
exportFile->setFileName(filePath);
if (!exportFile->open(QIODevice::WriteOnly | QIODevice::Text))
{
auto errorMessage = QString("Export Well Path: Could not open the file: %1").arg(filePath);
RiaLogging::error(errorMessage);
return false;
}
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicExportCarfinForCompletionsFeature::exportCarfin(QTextStream& stream, const std::map<RigCompletionDataGridCell, LgrInfo>& lgrInfos)
{
int count = 0;
for (auto lgr : lgrInfos)
{
auto lgrName = QString("LGR_%1").arg(++count);
auto dataGridCell = lgr.first;
auto lgrInfo = lgr.second;
{
RifEclipseDataTableFormatter formatter(stream);
formatter.keyword("CARFIN");
formatter.header(
{
RifEclipseOutputTableColumn("Name"),
RifEclipseOutputTableColumn("I1"),
RifEclipseOutputTableColumn("I2"),
RifEclipseOutputTableColumn("J1"),
RifEclipseOutputTableColumn("J2"),
RifEclipseOutputTableColumn("K1"),
RifEclipseOutputTableColumn("K2"),
RifEclipseOutputTableColumn("NX"),
RifEclipseOutputTableColumn("NY"),
RifEclipseOutputTableColumn("NZ")
}
);
formatter.add(lgrInfo.name);
formatter.add(dataGridCell.localCellIndexI());
formatter.add(dataGridCell.localCellIndexI());
formatter.add(dataGridCell.localCellIndexJ());
formatter.add(dataGridCell.localCellIndexJ());
formatter.add(dataGridCell.localCellIndexK());
formatter.add(dataGridCell.localCellIndexK());
formatter.add(lgrInfo.sizes.i());
formatter.add(lgrInfo.sizes.j());
formatter.add(lgrInfo.sizes.k());
formatter.rowCompleted();
formatter.tableCompleted("", false);
}
RifEclipseDataTableFormatter::addValueTable(stream, "PORO", lgrInfo.sizes.i(), lgrInfo.values);
{
RifEclipseDataTableFormatter formatter(stream);
formatter.keyword("ENDFIN");
formatter.tableCompleted("", true);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -112,7 +203,62 @@ void RicExportCarfinForCompletionsFeature::onActionTriggered(bool isChecked)
auto dialogData = openDialog();
if (dialogData)
{
// Per cell LGR
std::map<RigCompletionDataGridCell, LgrInfo> lgrs;
auto activeView = dynamic_cast<RimEclipseView*>(RiaApplication::instance()->activeGridView());
if (!activeView) return;
auto eclipseCase = dialogData->caseToApply();
eclipseCase->results(RiaDefines::MATRIX_MODEL)->findOrLoadScalarResult(RiaDefines::STATIC_NATIVE, "PORO");
cvf::ref<RigResultAccessor> poroAccessObject =
RigResultAccessorFactory::createFromUiResultName(eclipseCase->eclipseCaseData(), 0, RiaDefines::MATRIX_MODEL, 0, "PORO");
auto lgrCellCounts = dialogData->lgrCellCount();
auto completions = eclipseCase->computeAndGetVirtualPerforationTransmissibilities();
if (completions)
{
size_t timeStep = activeView->currentTimeStep();
for (const auto& wellPath : wellPaths)
{
int lgrCount = 0;
for (const auto& completionsForWell : completions->multipleCompletionsPerEclipseCell(wellPath, timeStep))
{
size_t globCellIndex = completionsForWell.first.globalCellIndex();
double poro = poroAccessObject->cellScalarGlobIdx(globCellIndex);
std::vector<double> lgrValues;
for (int k = 0; k < lgrCellCounts.k(); k++)
{
for (int j = 0; j < lgrCellCounts.j(); j++)
{
for (int i = 0; i < lgrCellCounts.i(); i++)
{
lgrValues.push_back(poro);
}
}
}
LgrInfo lgrInfo(QString("LGR_%1").arg(++lgrCount), lgrCellCounts);
lgrInfo.values = lgrValues;
lgrs.insert(std::make_pair(completionsForWell.first, lgrInfo));
}
}
}
// Export
QFile file;
openFileForExport(dialogData->exportFolder(), "CARFIN.dat", &file);
QTextStream stream(&file);
stream.setRealNumberNotation(QTextStream::FixedNotation);
stream.setRealNumberPrecision(2);
exportCarfin(stream, lgrs);
file.close();
}
}

View File

@ -18,11 +18,32 @@
#pragma once
#include "RigCompletionDataGridCell.h"
#include "cafCmdFeature.h"
#include <cafVecIjk.h>
#include <memory>
class RimSimWellInView;
class RimWellPath;
class RicExportCarfinForCompletionsUi;
class QFile;
class QTextStream;
//==================================================================================================
///
//==================================================================================================
class LgrInfo
{
public:
LgrInfo(const QString&name, caf::VecIjk& sizes) : name(name), sizes(sizes)
{
}
QString name;
caf::VecIjk sizes;
std::vector<double> values;
};
//==================================================================================================
///
@ -32,12 +53,16 @@ class RicExportCarfinForCompletionsFeature : public caf::CmdFeature
CAF_CMD_HEADER_INIT;
static RicExportCarfinForCompletionsUi* openDialog();
static bool openFileForExport(const QString& folderName, const QString& fileName, QFile* exportFile);
static void exportCarfin(QTextStream& stream, const std::map<RigCompletionDataGridCell, LgrInfo>& lgrInfos);
protected:
virtual bool isCommandEnabled() override;
virtual void onActionTriggered(bool isChecked) override;
virtual void setupActionLook(QAction* actionToSetup) override;
private:
public:
static std::vector<RimWellPath*> visibleWellPaths();
};

View File

@ -29,6 +29,20 @@
CAF_PDM_SOURCE_INIT(RicExportCarfinForCompletionsUi, "RicExportCarfinForCompletionsUi");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
namespace caf
{
template<>
void RicExportCarfinForCompletionsUi::LgrSplitTypeEnum::setUp()
{
addItem(RicExportCarfinForCompletionsUi::PER_CELL_LGR, "PER_CELL_LGR", "LGR Per Cell");
addItem(RicExportCarfinForCompletionsUi::SINGLE_LGR, "SINGLE_LGR", "Single LGR");
setDefault(RicExportCarfinForCompletionsUi::PER_CELL_LGR);
}
}
//--------------------------------------------------------------------------------------------------
///
@ -45,6 +59,8 @@ RicExportCarfinForCompletionsUi::RicExportCarfinForCompletionsUi()
CAF_PDM_InitField(&m_cellCountI, "CellCountI", 2, "Cell Count I", "", "", "");
CAF_PDM_InitField(&m_cellCountJ, "CellCountJ", 2, "Cell Count J", "", "", "");
CAF_PDM_InitField(&m_cellCountK, "CellCountK", 2, "Cell Count K", "", "", "");
CAF_PDM_InitField(&m_splitType, "SplitType", LgrSplitTypeEnum(), "Split Type", "", "", "");
}
//--------------------------------------------------------------------------------------------------
@ -85,6 +101,14 @@ RimEclipseCase* RicExportCarfinForCompletionsUi::caseToApply() const
return m_caseToApply();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicExportCarfinForCompletionsUi::singleLgrSplit() const
{
return m_splitType == SINGLE_LGR;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -159,7 +183,7 @@ void RicExportCarfinForCompletionsUi::defineEditorAttribute(const caf::PdmFieldH
caf::PdmUiFilePathEditorAttribute* myAttr = dynamic_cast<caf::PdmUiFilePathEditorAttribute*>(attribute);
if (myAttr)
{
myAttr->m_selectSaveFileName = true;
myAttr->m_selectDirectory = true;
}
}
}

View File

@ -39,6 +39,7 @@ class RicExportCarfinForCompletionsUi : public caf::PdmObject
public:
enum LgrSplitType { PER_CELL_LGR, SINGLE_LGR};
typedef caf::AppEnum<LgrSplitType> LgrSplitTypeEnum;
RicExportCarfinForCompletionsUi();
@ -47,6 +48,7 @@ public:
caf::VecIjk lgrCellCount() const;
QString exportFolder() const;
RimEclipseCase* caseToApply() const;
bool singleLgrSplit() const;
void setExportFolder(const QString& folder);
@ -66,4 +68,6 @@ private:
caf::PdmField<int> m_cellCountI;
caf::PdmField<int> m_cellCountJ;
caf::PdmField<int> m_cellCountK;
caf::PdmField<LgrSplitTypeEnum> m_splitType;
};