#3457 Export visible cells. New command file command

This commit is contained in:
Bjørn Erik Jensen 2018-10-04 13:50:29 +02:00
parent 677914a338
commit f23fa64235
7 changed files with 240 additions and 26 deletions

View File

@ -22,6 +22,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfScaleFractureTemplate.h
${CMAKE_CURRENT_LIST_DIR}/RicfSetFractureContainment.h
${CMAKE_CURRENT_LIST_DIR}/RicfCreateMultipleFractures.h
${CMAKE_CURRENT_LIST_DIR}/RicfExportWellPaths.h
${CMAKE_CURRENT_LIST_DIR}/RicfExportVisibleCells.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -47,6 +48,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfScaleFractureTemplate.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfSetFractureContainment.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfCreateMultipleFractures.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfExportWellPaths.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfExportVisibleCells.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -35,6 +35,7 @@ namespace caf {
addItem(RicfCommandFileExecutor::SNAPSHOTS, "SNAPSHOTS", "Snapshots");
addItem(RicfCommandFileExecutor::STATISTICS, "STATISTICS", "Statistics");
addItem(RicfCommandFileExecutor::WELLPATHS, "WELLPATHS", "Well Path");
addItem(RicfCommandFileExecutor::CELLS, "CELLS", "Cells");
setDefault(RicfCommandFileExecutor::COMPLETIONS);
}
}

View File

@ -40,7 +40,8 @@ public:
SNAPSHOTS,
PROPERTIES,
STATISTICS,
WELLPATHS
WELLPATHS,
CELLS
};
typedef caf::AppEnum<ExportType> ExportTypeEnum;

View File

@ -0,0 +1,138 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicfExportVisibleCells.h"
#include "RiaFilePathTools.h"
#include "RicfCommandFileExecutor.h"
#include "ExportCommands/RicSaveEclipseInputVisibleCellsFeature.h"
#include "ExportCommands/RicSaveEclipseInputVisibleCellsUi.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "RimProject.h"
#include "RimOilField.h"
#include "RimEclipseCaseCollection.h"
#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RimEclipseCellColors.h"
#include "RifEclipseInputFileTools.h"
#include <QDir>
#include <cafUtils.h>
#include <QDir>
CAF_PDM_SOURCE_INIT(RicfExportVisibleCells, "exportVisibleCells");
namespace caf
{
template<>
void AppEnum< RicfExportVisibleCells::ExportKeyword >::setUp()
{
addItem(RicfExportVisibleCells::FLUXNUM, "FLUXNUM", "FLUXNUM");
addItem(RicfExportVisibleCells::MULTNUM, "MULTNUM", "MULTNUM");
setDefault(RicfExportVisibleCells::FLUXNUM);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfExportVisibleCells::RicfExportVisibleCells()
{
RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", "");
RICF_InitField(&m_viewName, "viewName", QString(), "View Name", "", "", "");
RICF_InitField(&m_exportKeyword, "exportKeyword", caf::AppEnum<RicfExportVisibleCells::ExportKeyword>(), "Export Keyword", "", "", "");
RICF_InitField(&m_visibleActiveCellsValue, "visibleActiveCellsValue", 1, "Visible Active Cells Value", "", "", "");
RICF_InitField(&m_hiddenActiveCellsValue, "hiddenActiveCellsValue", 0, "Hidden Active Cells Value", "", "", "");
RICF_InitField(&m_inactiveCellsValue, "inactiveCellsValue", 0, "Inactive Cells Value", "", "", "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfExportVisibleCells::execute()
{
if (m_caseId < 0 || m_viewName().isEmpty())
{
RiaLogging::error("exportVisibleCells: CaseId or view name not specified");
return;
}
auto eclipseView = viewFromCaseIdAndViewName(m_caseId, m_viewName);
if (!eclipseView)
{
RiaLogging::error(QString("exportVisibleCells: Could not find view '%1' in case ID %2").arg(m_viewName).arg(m_caseId));
return;
}
QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::CELLS);
if (exportFolder.isNull())
{
exportFolder = RiaApplication::instance()->createAbsolutePathFromProjectRelativePath("visibleCells");
}
RicSaveEclipseInputVisibleCellsUi exportSettings;
buildExportSettings(exportFolder, &exportSettings);
RicSaveEclipseInputVisibleCellsFeature::executeCommand(eclipseView, exportSettings, "exportVisibleCells");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseView* RicfExportVisibleCells::viewFromCaseIdAndViewName(int caseId, const QString& viewName)
{
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels->cases())
{
if (c->caseId() == caseId)
{
for (auto v : c->views())
{
auto eclipseView = dynamic_cast<RimEclipseView*>(v);
if (eclipseView && eclipseView->name().compare(viewName, Qt::CaseInsensitive) == 0)
{
return eclipseView;
}
}
}
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfExportVisibleCells::buildExportSettings(const QString& exportFolder, RicSaveEclipseInputVisibleCellsUi* exportSettings)
{
QDir baseDir(exportFolder);
exportSettings->exportFilename = baseDir.absoluteFilePath(QString("%1.grdecl").arg(m_exportKeyword().text()));
if (m_exportKeyword == ExportKeyword::FLUXNUM) exportSettings->exportKeyword = RicSaveEclipseInputVisibleCellsUi::FLUXNUM;
else if (m_exportKeyword == ExportKeyword::MULTNUM) exportSettings->exportKeyword = RicSaveEclipseInputVisibleCellsUi::MULTNUM;
exportSettings->visibleActiveCellsValue = m_visibleActiveCellsValue;
exportSettings->hiddenActiveCellsValue = m_hiddenActiveCellsValue;
exportSettings->inactiveCellsValue = m_inactiveCellsValue;
}

View File

@ -0,0 +1,56 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RiaDefines.h"
#include "RicfCommandObject.h"
#include "cafPdmField.h"
class RimEclipseView;
class RicSaveEclipseInputVisibleCellsUi;
//==================================================================================================
//
//
//
//==================================================================================================
class RicfExportVisibleCells : public RicfCommandObject
{
CAF_PDM_HEADER_INIT;
enum ExportKeyword {FLUXNUM, MULTNUM};
public:
RicfExportVisibleCells();
virtual void execute() override;
private:
RimEclipseView* viewFromCaseIdAndViewName(int caseId, const QString& viewName);
void buildExportSettings(const QString& exportFolder, RicSaveEclipseInputVisibleCellsUi* exportSettings);
caf::PdmField<int> m_caseId;
caf::PdmField<QString> m_viewName;
caf::PdmField<caf::AppEnum<ExportKeyword>> m_exportKeyword;
caf::PdmField<int> m_visibleActiveCellsValue;
caf::PdmField<int> m_hiddenActiveCellsValue;
caf::PdmField<int> m_inactiveCellsValue;
};

View File

@ -49,7 +49,7 @@ CAF_CMD_SOURCE_INIT(RicSaveEclipseInputActiveVisibleCellsFeature, "RicSaveEclips
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void executeCommand(RimEclipseView* view)
void RicSaveEclipseInputVisibleCellsFeature::openDialogAndExecuteCommand(RimEclipseView* view)
{
if (!view) return;
@ -59,37 +59,47 @@ void executeCommand(RimEclipseView* view)
if (propertyDialog.exec() == QDialog::Accepted)
{
std::vector<double> values;
cvf::UByteArray visibleCells;
view->calculateCurrentTotalCellVisibility(&visibleCells, view->currentTimeStep());
RigActiveCellInfo* activeCellInfo = view->eclipseCase()->eclipseCaseData()->activeCellInfo(RiaDefines::MATRIX_MODEL);
values.resize(visibleCells.size());
for (size_t i = 0; i < visibleCells.size(); ++i)
executeCommand(view, exportSettings, "saveEclipseInputVisibleCells");
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveEclipseInputVisibleCellsFeature::executeCommand(RimEclipseView* view,
const RicSaveEclipseInputVisibleCellsUi& exportSettings,
const QString& logPrefix)
{
std::vector<double> values;
cvf::UByteArray visibleCells;
view->calculateCurrentTotalCellVisibility(&visibleCells, view->currentTimeStep());
RigActiveCellInfo* activeCellInfo = view->eclipseCase()->eclipseCaseData()->activeCellInfo(RiaDefines::MATRIX_MODEL);
values.resize(visibleCells.size());
for (size_t i = 0; i < visibleCells.size(); ++i)
{
if (activeCellInfo->isActive(i))
{
if (activeCellInfo->isActive(i))
if (visibleCells[i])
{
if (visibleCells[i])
{
values[i] = static_cast<double>(exportSettings.visibleActiveCellsValue);
}
else
{
values[i] = static_cast<double>(exportSettings.hiddenActiveCellsValue);
}
values[i] = static_cast<double>(exportSettings.visibleActiveCellsValue);
}
else
{
values[i] = static_cast<double>(exportSettings.inactiveCellsValue);
values[i] = static_cast<double>(exportSettings.hiddenActiveCellsValue);
}
}
QFile exportFile(exportSettings.exportFilename);
if (!exportFile.open(QIODevice::WriteOnly | QIODevice::Text))
else
{
RiaLogging::error(QString("saveEclipseInputVisibleCells: Unable to open file '%1' for writing.").arg(exportSettings.exportFilename));
return;
values[i] = static_cast<double>(exportSettings.inactiveCellsValue);
}
RifEclipseInputFileTools::writeDataToTextFile(&exportFile, exportSettings.exportKeyword().text(), values);
}
QFile exportFile(exportSettings.exportFilename);
if (!exportFile.open(QIODevice::WriteOnly | QIODevice::Text))
{
RiaLogging::error(QString("%1: Unable to open file '%2' for writing.").arg(logPrefix).arg(exportSettings.exportFilename));
return;
}
RifEclipseInputFileTools::writeDataToTextFile(&exportFile, exportSettings.exportKeyword().text(), values);
}
//--------------------------------------------------------------------------------------------------
@ -106,7 +116,7 @@ bool RicSaveEclipseInputVisibleCellsFeature::isCommandEnabled()
void RicSaveEclipseInputVisibleCellsFeature::onActionTriggered(bool isChecked)
{
RimEclipseView* view = RicSaveEclipseInputVisibleCellsFeature::selectedView();
executeCommand(view);
openDialogAndExecuteCommand(view);
}
//--------------------------------------------------------------------------------------------------
@ -157,7 +167,7 @@ bool RicSaveEclipseInputActiveVisibleCellsFeature::isCommandEnabled()
void RicSaveEclipseInputActiveVisibleCellsFeature::onActionTriggered(bool isChecked)
{
RimEclipseView* view = RicSaveEclipseInputActiveVisibleCellsFeature::getEclipseActiveView();
executeCommand(view);
RicSaveEclipseInputVisibleCellsFeature::openDialogAndExecuteCommand(view);
}
//--------------------------------------------------------------------------------------------------

View File

@ -20,8 +20,8 @@
#include "cafCmdFeature.h"
class RimEclipseInputProperty;
class RimEclipseView;
class RicSaveEclipseInputVisibleCellsUi;
//==================================================================================================
///
@ -30,6 +30,12 @@ class RicSaveEclipseInputVisibleCellsFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
public :
static void openDialogAndExecuteCommand(RimEclipseView* view);
static void executeCommand(RimEclipseView* view,
const RicSaveEclipseInputVisibleCellsUi& exportSettings,
const QString& logPrefix);
protected:
virtual bool isCommandEnabled() override;
virtual void onActionTriggered(bool isChecked) override;