2019-03-18 06:52:01 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2019- Equinor 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 <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-03-29 07:37:25 -05:00
|
|
|
#include "RicExportEclipseSectorModelFeature.h"
|
2019-03-18 06:52:01 -05:00
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
|
|
|
#include "RiaLogging.h"
|
|
|
|
|
|
|
|
#include "RicExportFeatureImpl.h"
|
2019-03-29 07:37:25 -05:00
|
|
|
#include "RicExportEclipseSectorModelUi.h"
|
2019-03-18 06:52:01 -05:00
|
|
|
|
2019-03-19 07:52:48 -05:00
|
|
|
#include "RifEclipseInputFileTools.h"
|
2019-03-18 06:52:01 -05:00
|
|
|
#include "RifReaderEclipseOutput.h"
|
|
|
|
|
2019-03-21 04:35:52 -05:00
|
|
|
#include "Rim3dView.h"
|
2019-03-18 06:52:01 -05:00
|
|
|
#include "RimEclipseCase.h"
|
|
|
|
#include "RimEclipseCellColors.h"
|
|
|
|
#include "RimEclipseView.h"
|
2019-03-21 04:35:52 -05:00
|
|
|
#include "RimFaultInView.h"
|
|
|
|
#include "RimFaultInViewCollection.h"
|
2019-03-18 06:52:01 -05:00
|
|
|
|
|
|
|
#include "RigEclipseCaseData.h"
|
|
|
|
#include "RigMainGrid.h"
|
|
|
|
|
|
|
|
#include "Riu3DMainWindowTools.h"
|
2019-04-01 09:21:43 -05:00
|
|
|
#include "RiuPropertyViewTabWidget.h"
|
2019-03-18 06:52:01 -05:00
|
|
|
|
|
|
|
#include "cafPdmUiPropertyViewDialog.h"
|
|
|
|
#include "cafProgressInfo.h"
|
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDir>
|
|
|
|
|
2019-03-29 07:37:25 -05:00
|
|
|
CAF_CMD_SOURCE_INIT(RicExportEclipseSectorModelFeature, "RicExportEclipseInputGridFeature");
|
2019-03-18 06:52:01 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-29 07:37:25 -05:00
|
|
|
void RicExportEclipseSectorModelFeature::openDialogAndExecuteCommand(RimEclipseView* view)
|
2019-03-18 06:52:01 -05:00
|
|
|
{
|
|
|
|
if (!view) return;
|
|
|
|
|
|
|
|
RigEclipseCaseData* caseData = view->eclipseCase()->eclipseCaseData();
|
|
|
|
|
2019-04-01 09:21:43 -05:00
|
|
|
cvf::UByteArray cellVisibility;
|
|
|
|
view->calculateCurrentTotalCellVisibility(&cellVisibility, view->currentTimeStep());
|
|
|
|
|
|
|
|
cvf::Vec3i min, max;
|
|
|
|
std::tie(min, max) = getVisibleCellRange(view, cellVisibility);
|
|
|
|
|
|
|
|
RicExportEclipseSectorModelUi exportSettings(caseData, min, max);
|
|
|
|
RiuPropertyViewTabWidget propertyDialog(Riu3DMainWindowTools::mainWindowWidget(), &exportSettings, "Export Eclipse Sector Model", exportSettings.tabNames());
|
|
|
|
|
|
|
|
RicExportFeatureImpl::configureForExport(propertyDialog.dialogButtonBox());
|
2019-03-18 06:52:01 -05:00
|
|
|
|
|
|
|
if (propertyDialog.exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
executeCommand(view, exportSettings, "ExportInputGrid");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-29 07:37:25 -05:00
|
|
|
void RicExportEclipseSectorModelFeature::executeCommand(RimEclipseView* view,
|
|
|
|
const RicExportEclipseSectorModelUi& exportSettings,
|
2019-03-18 06:52:01 -05:00
|
|
|
const QString& logPrefix)
|
|
|
|
{
|
2019-04-01 07:15:50 -05:00
|
|
|
int resultProgressPercentage = exportSettings.exportParameters() ?
|
|
|
|
std::min((int) exportSettings.selectedKeywords().size(), 20) : 0;
|
2019-03-21 04:35:52 -05:00
|
|
|
|
|
|
|
int faultsProgressPercentage = exportSettings.exportFaults() ? 10 : 0;
|
|
|
|
|
|
|
|
int gridProgressPercentage = 100 - resultProgressPercentage - faultsProgressPercentage;
|
|
|
|
caf::ProgressInfo progress(gridProgressPercentage + resultProgressPercentage + faultsProgressPercentage,
|
2019-03-28 14:42:29 -05:00
|
|
|
"Export Eclipse Sector Model");
|
2019-03-18 06:52:01 -05:00
|
|
|
|
2019-04-01 09:21:43 -05:00
|
|
|
cvf::Vec3st refinement(exportSettings.refinementCountI(), exportSettings.refinementCountJ(), exportSettings.refinementCountK());
|
2019-03-19 04:49:09 -05:00
|
|
|
|
2019-03-21 04:35:52 -05:00
|
|
|
CVF_ASSERT(refinement.x() > 0u && refinement.y() > 0u && refinement.z() > 0u);
|
|
|
|
|
2019-03-29 08:26:49 -05:00
|
|
|
cvf::UByteArray cellVisibility;
|
|
|
|
view->calculateCurrentTotalCellVisibility(&cellVisibility, view->currentTimeStep());
|
2019-04-01 09:21:43 -05:00
|
|
|
getVisibleCellRange(view, cellVisibility);
|
|
|
|
|
|
|
|
cvf::Vec3st min(exportSettings.min());
|
|
|
|
cvf::Vec3st max(exportSettings.max());
|
2019-03-29 08:26:49 -05:00
|
|
|
|
2019-03-18 06:52:01 -05:00
|
|
|
if (exportSettings.exportGrid())
|
|
|
|
{
|
2019-03-29 08:26:49 -05:00
|
|
|
const cvf::UByteArray* cellVisibilityForActnum = exportSettings.makeInvisibleCellsInactive() ? &cellVisibility : nullptr;
|
2019-03-28 14:42:29 -05:00
|
|
|
auto task = progress.task("Export Grid", gridProgressPercentage);
|
2019-03-29 08:26:49 -05:00
|
|
|
|
|
|
|
bool worked = RifEclipseInputFileTools::exportGrid(exportSettings.exportGridFilename(),
|
|
|
|
view->eclipseCase()->eclipseCaseData(),
|
2019-04-01 05:47:28 -05:00
|
|
|
exportSettings.exportInLocalCoordinates(),
|
2019-03-29 08:26:49 -05:00
|
|
|
cellVisibilityForActnum,
|
|
|
|
min,
|
|
|
|
max,
|
|
|
|
refinement);
|
|
|
|
|
2019-03-18 06:52:01 -05:00
|
|
|
if (!worked)
|
|
|
|
{
|
|
|
|
RiaLogging::error(
|
|
|
|
QString("Unable to write grid to '%1'").arg(exportSettings.exportGridFilename));
|
|
|
|
}
|
2019-03-21 05:56:19 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (view->eclipseCase()->eclipseCaseData()->gridCount() > 1u)
|
|
|
|
{
|
|
|
|
RiaLogging::warning("Grid has LGRs but ResInsight only supports exporting the Main Grid");
|
|
|
|
}
|
|
|
|
|
|
|
|
QFileInfo info(exportSettings.exportGridFilename());
|
|
|
|
RiaApplication::instance()->setLastUsedDialogDirectory("EXPORT_INPUT_GRID", info.absolutePath());
|
|
|
|
}
|
2019-03-18 06:52:01 -05:00
|
|
|
}
|
|
|
|
|
2019-04-01 07:15:50 -05:00
|
|
|
if (exportSettings.exportParameters() != RicExportEclipseSectorModelUi::EXPORT_NO_RESULTS)
|
2019-03-18 06:52:01 -05:00
|
|
|
{
|
2019-03-28 14:42:29 -05:00
|
|
|
auto task = progress.task("Export Properties", resultProgressPercentage);
|
2019-04-01 07:15:50 -05:00
|
|
|
std::vector<QString> keywords = exportSettings.selectedKeywords;
|
2019-03-18 06:52:01 -05:00
|
|
|
|
2019-04-01 07:15:50 -05:00
|
|
|
if (exportSettings.exportParameters == RicExportEclipseSectorModelUi::EXPORT_TO_SEPARATE_FILE_PER_RESULT)
|
2019-03-18 06:52:01 -05:00
|
|
|
{
|
|
|
|
QFileInfo info(exportSettings.exportGridFilename());
|
|
|
|
QDir dirPath = info.absoluteDir();
|
|
|
|
QString fileWriteMode = "w";
|
|
|
|
for (QString keyword : keywords)
|
|
|
|
{
|
|
|
|
QString fileName = dirPath.absoluteFilePath(keyword + ".GRDECL");
|
2019-03-19 07:52:48 -05:00
|
|
|
bool worked = RifEclipseInputFileTools::exportKeywords(fileName,
|
2019-03-21 05:56:19 -05:00
|
|
|
view->eclipseCase()->eclipseCaseData(),
|
|
|
|
{keyword},
|
|
|
|
fileWriteMode,
|
|
|
|
min,
|
|
|
|
max,
|
|
|
|
refinement);
|
2019-03-18 06:52:01 -05:00
|
|
|
if (!worked)
|
|
|
|
{
|
|
|
|
RiaLogging::error(QString("Unable to write results to '%1'").arg(fileName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString fileWriteMode = "w";
|
2019-04-01 07:15:50 -05:00
|
|
|
QString fileName = exportSettings.exportParametersFilename();
|
|
|
|
if (exportSettings.exportParameters() == RicExportEclipseSectorModelUi::EXPORT_TO_GRID_FILE)
|
2019-03-18 06:52:01 -05:00
|
|
|
{
|
|
|
|
fileWriteMode = "a";
|
|
|
|
fileName = exportSettings.exportGridFilename();
|
|
|
|
}
|
|
|
|
|
2019-03-19 07:52:48 -05:00
|
|
|
bool worked = RifEclipseInputFileTools::exportKeywords(fileName,
|
2019-03-18 06:52:01 -05:00
|
|
|
view->eclipseCase()->eclipseCaseData(),
|
|
|
|
keywords,
|
|
|
|
fileWriteMode,
|
2019-03-19 04:49:09 -05:00
|
|
|
min,
|
|
|
|
max,
|
|
|
|
refinement);
|
2019-03-18 06:52:01 -05:00
|
|
|
|
|
|
|
if (!worked)
|
|
|
|
{
|
|
|
|
RiaLogging::error(QString("Unable to write results to '%1'").arg(fileName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-21 04:35:52 -05:00
|
|
|
|
2019-03-29 07:37:25 -05:00
|
|
|
if (exportSettings.exportFaults() != RicExportEclipseSectorModelUi::EXPORT_NO_RESULTS)
|
2019-03-21 04:35:52 -05:00
|
|
|
{
|
|
|
|
auto task = progress.task("Export Faults", faultsProgressPercentage);
|
2019-03-29 07:37:25 -05:00
|
|
|
if (exportSettings.exportFaults == RicExportEclipseSectorModelUi::EXPORT_TO_SEPARATE_FILE_PER_RESULT)
|
2019-03-21 04:35:52 -05:00
|
|
|
{
|
|
|
|
QFileInfo info(exportSettings.exportGridFilename());
|
|
|
|
QDir dirPath = info.absoluteDir();
|
|
|
|
|
|
|
|
for (auto faultInView : view->faultCollection()->faults())
|
|
|
|
{
|
|
|
|
auto rigFault = faultInView->faultGeometry();
|
|
|
|
QString fileName = QString("%1.GRDECL").arg(rigFault->name());
|
|
|
|
RifEclipseInputFileTools::saveFault(
|
|
|
|
fileName, view->eclipseCase()->mainGrid(), rigFault->faultFaces(), rigFault->name(), min, max, refinement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString fileName = exportSettings.exportFaultsFilename();
|
|
|
|
QIODevice::OpenMode openFlag = QIODevice::Truncate;
|
2019-04-01 07:15:50 -05:00
|
|
|
if (exportSettings.exportParameters() == RicExportEclipseSectorModelUi::EXPORT_TO_GRID_FILE)
|
2019-03-21 04:35:52 -05:00
|
|
|
{
|
|
|
|
openFlag = QIODevice::Append;
|
|
|
|
fileName = exportSettings.exportGridFilename();
|
|
|
|
}
|
|
|
|
QFile exportFile(fileName);
|
|
|
|
|
|
|
|
if (!exportFile.open(QIODevice::Text | QIODevice::WriteOnly | openFlag))
|
|
|
|
{
|
|
|
|
RiaLogging::error("Could not open the file : " + fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream stream(&exportFile);
|
|
|
|
RifEclipseInputFileTools::saveFaults(stream, view->eclipseCase()->mainGrid(), min, max, refinement);
|
|
|
|
}
|
|
|
|
}
|
2019-03-18 06:52:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-04-01 09:21:43 -05:00
|
|
|
std::pair<cvf::Vec3i, cvf::Vec3i> RicExportEclipseSectorModelFeature::getVisibleCellRange(RimEclipseView* view, const cvf::UByteArray& cellVisibillity)
|
2019-03-18 06:52:01 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
const RigMainGrid* mainGrid = view->eclipseCase()->mainGrid();
|
2019-04-01 09:21:43 -05:00
|
|
|
cvf::Vec3i max = cvf::Vec3i::ZERO;
|
|
|
|
cvf::Vec3i min = cvf::Vec3i(int(mainGrid->cellCountI() - 1),
|
|
|
|
int(mainGrid->cellCountJ() - 1),
|
|
|
|
int(mainGrid->cellCountK() - 1));
|
2019-03-18 06:52:01 -05:00
|
|
|
|
|
|
|
size_t cellCount = mainGrid->cellCount();
|
|
|
|
for (size_t index = 0; index < cellCount; ++index)
|
|
|
|
{
|
2019-03-29 08:26:49 -05:00
|
|
|
if (cellVisibillity[index])
|
2019-03-18 06:52:01 -05:00
|
|
|
{
|
|
|
|
cvf::Vec3st ijk;
|
|
|
|
mainGrid->ijkFromCellIndex(index, &ijk[0], &ijk[1], &ijk[2]);
|
|
|
|
for (int n = 0; n < 3; ++n)
|
|
|
|
{
|
2019-04-01 09:21:43 -05:00
|
|
|
min[n] = std::min(min[n], (int) ijk[n]);
|
|
|
|
max[n] = std::max(max[n], (int) ijk[n]);
|
2019-03-18 06:52:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return std::make_pair(min, max);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-29 07:37:25 -05:00
|
|
|
bool RicExportEclipseSectorModelFeature::isCommandEnabled()
|
2019-03-18 06:52:01 -05:00
|
|
|
{
|
|
|
|
return selectedView() != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-29 07:37:25 -05:00
|
|
|
void RicExportEclipseSectorModelFeature::onActionTriggered(bool isChecked)
|
2019-03-18 06:52:01 -05:00
|
|
|
{
|
2019-03-29 07:37:25 -05:00
|
|
|
RimEclipseView* view = RicExportEclipseSectorModelFeature::selectedView();
|
2019-03-18 06:52:01 -05:00
|
|
|
openDialogAndExecuteCommand(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-29 07:37:25 -05:00
|
|
|
void RicExportEclipseSectorModelFeature::setupActionLook(QAction* actionToSetup)
|
2019-03-18 06:52:01 -05:00
|
|
|
{
|
2019-04-01 09:21:43 -05:00
|
|
|
actionToSetup->setText("Export Eclipse Sector Model");
|
2019-03-18 06:52:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-29 07:37:25 -05:00
|
|
|
RimEclipseView* RicExportEclipseSectorModelFeature::selectedView() const
|
2019-03-18 06:52:01 -05:00
|
|
|
{
|
2019-03-28 14:42:29 -05:00
|
|
|
RimEclipseView* view = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimEclipseView>();
|
2019-03-18 06:52:01 -05:00
|
|
|
if (view)
|
|
|
|
{
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2019-03-28 14:42:29 -05:00
|
|
|
Rim3dView* activeView = RiaApplication::instance()->activeReservoirView();
|
|
|
|
return dynamic_cast<RimEclipseView*>(activeView);
|
2019-03-18 06:52:01 -05:00
|
|
|
}
|