#3603 Export completions. Also export CARFIN if temporary LGRs exist

This commit is contained in:
Bjørn Erik Jensen 2018-11-09 08:51:30 +01:00
parent fe3fe5c8f8
commit 9b8584c707
4 changed files with 108 additions and 41 deletions

View File

@ -22,6 +22,7 @@
class RimSimWellInView; class RimSimWellInView;
class RimWellPath; class RimWellPath;
class RigMainGrid;
//================================================================================================== //==================================================================================================
/// ///

View File

@ -22,6 +22,7 @@
#include "RiaApplication.h" #include "RiaApplication.h"
#include "RicExportFeatureImpl.h" #include "RicExportFeatureImpl.h"
#include "ExportCommands/RicExportLgrFeature.h"
#include "RimDialogData.h" #include "RimDialogData.h"
#include "RimFishbonesMultipleSubs.h" #include "RimFishbonesMultipleSubs.h"
@ -135,6 +136,16 @@ void RicWellPathExportCompletionDataFeature::prepareExportSettingsAndExportCompl
RiaApplication::instance()->setLastUsedDialogDirectory("COMPLETIONS", exportSettings->folder); RiaApplication::instance()->setLastUsedDialogDirectory("COMPLETIONS", exportSettings->folder);
RicWellPathExportCompletionDataFeatureImpl::exportCompletions(wellPaths, simWells, *exportSettings); RicWellPathExportCompletionDataFeatureImpl::exportCompletions(wellPaths, simWells, *exportSettings);
const auto mainGrid = exportSettings->caseToApply->mainGrid();
if (!mainGrid) return;
const auto& lgrInfosForWells = RicExportLgrFeature::createLgrInfoListForTemporaryLgrs(mainGrid);
for (const auto& lgrInfoForWell : lgrInfosForWells)
{
RicExportLgrFeature::exportLgrs(exportSettings->folder, lgrInfoForWell.first, lgrInfoForWell.second);
}
} }
} }

View File

@ -248,13 +248,10 @@ bool RicExportLgrFeature::openFileForExport(const QString& folderName, const QSt
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicExportLgrFeature::exportLgrs(QTextStream& stream, const std::vector<LgrInfo>& lgrInfos) void RicExportLgrFeature::writeLgrs(QTextStream& stream, const std::vector<LgrInfo>& lgrInfos)
{ {
int count = 0;
for (auto lgrInfo : lgrInfos) for (auto lgrInfo : lgrInfos)
{ {
auto lgrName = QString("LGR_%1").arg(++count);
{ {
RifEclipseDataTableFormatter formatter(stream); RifEclipseDataTableFormatter formatter(stream);
formatter.comment(QString("LGR: ") + lgrInfo.name); formatter.comment(QString("LGR: ") + lgrInfo.name);
@ -270,7 +267,7 @@ void RicExportLgrFeature::exportLgrs(QTextStream& stream, const std::vector<LgrI
RifEclipseOutputTableColumn("NY"), RifEclipseOutputTableColumn("NY"),
RifEclipseOutputTableColumn("NZ")}); RifEclipseOutputTableColumn("NZ")});
formatter.add(lgrInfo.shortName); formatter.add(lgrInfo.name);
formatter.addOneBasedCellIndex(lgrInfo.mainGridStartCell.i()); formatter.addOneBasedCellIndex(lgrInfo.mainGridStartCell.i());
formatter.addOneBasedCellIndex(lgrInfo.mainGridEndCell.i()); formatter.addOneBasedCellIndex(lgrInfo.mainGridEndCell.i());
formatter.addOneBasedCellIndex(lgrInfo.mainGridStartCell.j()); formatter.addOneBasedCellIndex(lgrInfo.mainGridStartCell.j());
@ -315,15 +312,26 @@ void RicExportLgrFeature::exportLgrsForWellPath(const QString& export
intersectingOtherLgrs); intersectingOtherLgrs);
if (!*intersectingOtherLgrs && !lgrs.empty()) if (!*intersectingOtherLgrs && !lgrs.empty())
{
exportLgrs(exportFolder, wellPath->name(), lgrs);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicExportLgrFeature::exportLgrs(const QString& exportFolder, const QString& wellName, const std::vector<LgrInfo>& lgrInfos)
{
if (!lgrInfos.empty())
{ {
// Export // Export
QFile file; QFile file;
QString fileName = caf::Utils::makeValidFileBasename(QString("LGR_%1").arg(wellPath->name())) + ".dat"; QString fileName = caf::Utils::makeValidFileBasename(QString("LGR_%1").arg(wellName)) + ".dat";
openFileForExport(exportFolder, fileName, &file); openFileForExport(exportFolder, fileName, &file);
QTextStream stream(&file); QTextStream stream(&file);
stream.setRealNumberNotation(QTextStream::FixedNotation); stream.setRealNumberNotation(QTextStream::FixedNotation);
stream.setRealNumberPrecision(2); stream.setRealNumberPrecision(2);
exportLgrs(stream, lgrs); writeLgrs(stream, lgrInfos);
file.close(); file.close();
} }
} }
@ -356,8 +364,8 @@ std::vector<LgrInfo> RicExportLgrFeature::buildLgrsForWellPath(RimWellPath*
auto intersectingCells = cellsIntersectingCompletions(eclipseCase, wellPath, timeStep, completionTypes, intersectingOtherLgrs); auto intersectingCells = cellsIntersectingCompletions(eclipseCase, wellPath, timeStep, completionTypes, intersectingOtherLgrs);
int lgrId = firstAvailableLgrId(eclipseCase->mainGrid()); int lgrId = firstAvailableLgrId(eclipseCase->mainGrid());
auto lgrName = createLgrName("", lgrId); auto lgrName = createLgrName("WELL", lgrId);
lgrs.push_back(buildLgr(lgrId, lgrName, lgrName, eclipseCase, wellPath, intersectingCells, lgrCellCounts)); lgrs.push_back(buildLgr(lgrId, lgrName, eclipseCase, wellPath, intersectingCells, lgrCellCounts));
} }
return lgrs; return lgrs;
} }
@ -376,7 +384,7 @@ std::vector<LgrInfo> RicExportLgrFeature::buildLgrsPerMainCell(RimEclipseCase*
for (const auto& intersectionCell : intersectingCells) for (const auto& intersectionCell : intersectingCells)
{ {
auto lgrName = createLgrName("", lgrId); auto lgrName = createLgrName("", lgrId);
lgrs.push_back(buildLgr(lgrId++, lgrName, lgrName, eclipseCase, wellPath, {intersectionCell}, lgrSizes)); lgrs.push_back(buildLgr(lgrId++, lgrName, eclipseCase, wellPath, {intersectionCell}, lgrSizes));
} }
return lgrs; return lgrs;
} }
@ -399,11 +407,10 @@ std::vector<LgrInfo> RicExportLgrFeature::buildLgrsPerCompletion(
int lgrId = firstAvailableLgrId(eclipseCase->mainGrid()); int lgrId = firstAvailableLgrId(eclipseCase->mainGrid());
for (auto complInfo : completionInfo) for (auto complInfo : completionInfo)
{ {
auto lgrName = createLgrName(complInfo.first.name, complInfo.first.number);
auto& typeName = namesAndCounters[complInfo.first.type].first; auto& typeName = namesAndCounters[complInfo.first.type].first;
auto& typeCounter = namesAndCounters[complInfo.first.type].second; auto& typeCounter = namesAndCounters[complInfo.first.type].second;
auto lgrShortName = createShortLgrName(typeName, typeCounter++); auto lgrName = createLgrName(typeName, typeCounter++);
lgrs.push_back(buildLgr(lgrId++, lgrName, lgrShortName, eclipseCase, wellPath, complInfo.second, lgrSizesPerMainGridCell)); lgrs.push_back(buildLgr(lgrId++, lgrName, eclipseCase, wellPath, complInfo.second, lgrSizesPerMainGridCell));
} }
return lgrs; return lgrs;
} }
@ -413,7 +420,6 @@ std::vector<LgrInfo> RicExportLgrFeature::buildLgrsPerCompletion(
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
LgrInfo RicExportLgrFeature::buildLgr(int lgrId, LgrInfo RicExportLgrFeature::buildLgr(int lgrId,
const QString& lgrName, const QString& lgrName,
const QString& shortLgrName,
RimEclipseCase* eclipseCase, RimEclipseCase* eclipseCase,
RimWellPath* wellPath, RimWellPath* wellPath,
const std::vector<RigCompletionDataGridCell>& intersectingCells, const std::vector<RigCompletionDataGridCell>& intersectingCells,
@ -442,7 +448,7 @@ LgrInfo RicExportLgrFeature::buildLgr(int
caf::VecIjk mainGridStartCell(iRange.first, jRange.first, kRange.first); caf::VecIjk mainGridStartCell(iRange.first, jRange.first, kRange.first);
caf::VecIjk mainGridEndCell(iRange.second, jRange.second, kRange.second); caf::VecIjk mainGridEndCell(iRange.second, jRange.second, kRange.second);
return LgrInfo(lgrId, lgrName, shortLgrName, wellPath->name(), lgrSizes, mainGridStartCell, mainGridEndCell); return LgrInfo(lgrId, lgrName, wellPath->name(), lgrSizes, mainGridStartCell, mainGridEndCell);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -730,6 +736,68 @@ std::vector<RimWellPath*> RicExportLgrFeature::selectedWellPaths()
return wellPaths; return wellPaths;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<caf::VecIjk, caf::VecIjk> mainGridCellBoundingBoxFromLgr(const RigGridBase* lgr)
{
auto mainGrid = lgr->mainGrid();
// Find min and max IJK
auto iRange = RicExportLgrFeature::initRange();
auto jRange = RicExportLgrFeature::initRange();
auto kRange = RicExportLgrFeature::initRange();
for (size_t c = 0; c < lgr->cellCount(); c++)
{
const auto& cell = lgr->cell(c);
size_t mainGridCellIndex = cell.mainGridCellIndex();
size_t i, j, k;
mainGrid->ijkFromCellIndex(mainGridCellIndex, &i, &j, &k);
iRange.first = std::min(i, iRange.first);
iRange.second = std::max(i, iRange.second);
jRange.first = std::min(j, jRange.first);
jRange.second = std::max(j, jRange.second);
kRange.first = std::min(k, kRange.first);
kRange.second = std::max(k, kRange.second);
}
caf::VecIjk mainGridStartCell(iRange.first, jRange.first, kRange.first);
caf::VecIjk mainGridEndCell(iRange.second, jRange.second, kRange.second);
return std::make_pair(mainGridStartCell, mainGridEndCell);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::map<QString /*wellName*/, std::vector<LgrInfo>> RicExportLgrFeature::createLgrInfoListForTemporaryLgrs(const RigMainGrid* mainGrid)
{
std::map<QString, std::vector<LgrInfo>> lgrInfosPerWell;
for (size_t i = 0; i < mainGrid->gridCount(); i++)
{
const auto grid = mainGrid->gridByIndex(i);
if (!grid->isTempGrid()) continue;
caf::VecIjk lgrSizes(grid->cellCountI(), grid->cellCountJ(), grid->cellCountK());
std::pair<caf::VecIjk, caf::VecIjk> mainGridBoundingBox = mainGridCellBoundingBoxFromLgr(grid);
QString wellName = QString::fromStdString(grid->associatedWellPathName());
auto& item = lgrInfosPerWell[wellName];
item.emplace_back(LgrInfo(grid->gridId(),
QString::fromStdString(grid->gridName()),
QString::fromStdString(grid->associatedWellPathName()),
lgrSizes,
mainGridBoundingBox.first,
mainGridBoundingBox.second));
}
return lgrInfosPerWell;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -750,24 +818,8 @@ int RicExportLgrFeature::firstAvailableLgrId(const RigMainGrid* mainGrid)
QString RicExportLgrFeature::createLgrName(const QString& baseName, int number) QString RicExportLgrFeature::createLgrName(const QString& baseName, int number)
{ {
QString lgrName; QString lgrName;
if(baseName.isEmpty()) lgrName = "LGR_";
if (!baseName.isEmpty()) lgrName += baseName + "_" + QString::number(number + 1);
{
lgrName += "_" + baseName;
}
if (number > 0)
{
lgrName += "_" + QString::number(number);
}
return lgrName.replace(" ", "_");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicExportLgrFeature::createShortLgrName(const QString& baseName, int number)
{
QString lgrName = baseName + "_" + QString::number(number + 1);
return lgrName.replace(" ", "_"); return lgrName.replace(" ", "_");
} }

View File

@ -29,6 +29,7 @@
#include <limits> #include <limits>
#include <memory> #include <memory>
class RigMainGrid;
class RimEclipseCase; class RimEclipseCase;
class RimSimWellInView; class RimSimWellInView;
class RimWellPath; class RimWellPath;
@ -44,12 +45,11 @@ class LgrInfo
public: public:
LgrInfo(int id, LgrInfo(int id,
const QString& name, const QString& name,
const QString& shortName,
const QString& associatedWellPathName, const QString& associatedWellPathName,
const caf::VecIjk& sizes, const caf::VecIjk& sizes,
const caf::VecIjk& mainGridStartCell, const caf::VecIjk& mainGridStartCell,
const caf::VecIjk& mainGridEndCell) const caf::VecIjk& mainGridEndCell)
: id(id), name(name), shortName(shortName), associatedWellPathName(associatedWellPathName), : id(id), name(name), associatedWellPathName(associatedWellPathName),
sizes(sizes), mainGridStartCell(mainGridStartCell), mainGridEndCell(mainGridEndCell) sizes(sizes), mainGridStartCell(mainGridStartCell), mainGridEndCell(mainGridEndCell)
{ {
} }
@ -68,7 +68,6 @@ public:
int id; int id;
QString name; QString name;
QString shortName;
QString associatedWellPathName; QString associatedWellPathName;
caf::VecIjk sizes; caf::VecIjk sizes;
@ -129,7 +128,7 @@ class RicExportLgrFeature : public caf::CmdFeature
{ {
CAF_CMD_HEADER_INIT; CAF_CMD_HEADER_INIT;
typedef std::pair<size_t, size_t> Range; using Range = std::pair<size_t, size_t>;
static Range initRange() { return std::make_pair(std::numeric_limits<size_t>::max(), 0); } static Range initRange() { return std::make_pair(std::numeric_limits<size_t>::max(), 0); }
static RicExportLgrUi* openDialog(const QString& dialogTitle, static RicExportLgrUi* openDialog(const QString& dialogTitle,
@ -146,6 +145,10 @@ class RicExportLgrFeature : public caf::CmdFeature
const std::set<RigCompletionData::CompletionType>& completionTypes, const std::set<RigCompletionData::CompletionType>& completionTypes,
bool* intersectingOtherLgrs); bool* intersectingOtherLgrs);
static void exportLgrs(const QString& exportFolder,
const QString& wellName,
const std::vector<LgrInfo>& lgrInfos);
static std::vector<LgrInfo> buildLgrsForWellPath(RimWellPath* wellPath, static std::vector<LgrInfo> buildLgrsForWellPath(RimWellPath* wellPath,
RimEclipseCase* eclipseCase, RimEclipseCase* eclipseCase,
size_t timeStep, size_t timeStep,
@ -156,13 +159,15 @@ class RicExportLgrFeature : public caf::CmdFeature
static std::vector<RimWellPath*> selectedWellPaths(); static std::vector<RimWellPath*> selectedWellPaths();
static std::map<QString /*wellName*/, std::vector<LgrInfo>> createLgrInfoListForTemporaryLgrs(const RigMainGrid* mainGrid);
protected: protected:
bool isCommandEnabled() override; bool isCommandEnabled() override;
void onActionTriggered(bool isChecked) override; void onActionTriggered(bool isChecked) override;
void setupActionLook(QAction* actionToSetup) override; void setupActionLook(QAction* actionToSetup) override;
private: private:
static void exportLgrs(QTextStream& stream, const std::vector<LgrInfo>& lgrInfos); static void writeLgrs(QTextStream& stream, const std::vector<LgrInfo>& lgrInfos);
static std::vector<LgrInfo> buildLgrsPerMainCell(RimEclipseCase* eclipseCase, static std::vector<LgrInfo> buildLgrsPerMainCell(RimEclipseCase* eclipseCase,
RimWellPath* wellPath, RimWellPath* wellPath,
@ -175,7 +180,6 @@ private:
const caf::VecIjk& lgrSizesPerMainGridCell); const caf::VecIjk& lgrSizesPerMainGridCell);
static LgrInfo buildLgr(int lgrId, static LgrInfo buildLgr(int lgrId,
const QString& lgrName, const QString& lgrName,
const QString& shortLgrName,
RimEclipseCase* eclipseCase, RimEclipseCase* eclipseCase,
RimWellPath* wellPath, RimWellPath* wellPath,
const std::vector<RigCompletionDataGridCell>& intersectingCells, const std::vector<RigCompletionDataGridCell>& intersectingCells,
@ -194,6 +198,5 @@ private:
bool* isIntersectingOtherLgrs); bool* isIntersectingOtherLgrs);
static int firstAvailableLgrId(const RigMainGrid* mainGrid); static int firstAvailableLgrId(const RigMainGrid* mainGrid);
static QString createLgrName(const QString& baseName, int number = 0); static QString createLgrName(const QString& baseName, int number);
static QString createShortLgrName(const QString& baseName, int number);
}; };