mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3477 Export Property : Updates after code has moved to exportPropertyInViews
This commit is contained in:
parent
c74637c0cc
commit
e1e515b659
@ -18,25 +18,21 @@
|
|||||||
|
|
||||||
#include "RicfExportProperty.h"
|
#include "RicfExportProperty.h"
|
||||||
|
|
||||||
#include "RicfCommandFileExecutor.h"
|
|
||||||
|
|
||||||
#include "../Commands/ExportCommands/RicEclipseCellResultToFileImpl.h"
|
|
||||||
|
|
||||||
#include "RiaApplication.h"
|
#include "RiaApplication.h"
|
||||||
#include "RiaLogging.h"
|
#include "RiaLogging.h"
|
||||||
|
|
||||||
|
#include "../Commands/ExportCommands/RicEclipseCellResultToFileImpl.h"
|
||||||
|
#include "RicfCommandFileExecutor.h"
|
||||||
|
|
||||||
|
#include "RifEclipseInputFileTools.h"
|
||||||
|
|
||||||
#include "RigCaseCellResultsData.h"
|
#include "RigCaseCellResultsData.h"
|
||||||
#include "RigEclipseCaseData.h"
|
#include "RigEclipseCaseData.h"
|
||||||
#include "RigMainGrid.h"
|
|
||||||
#include "RigResultAccessor.h"
|
|
||||||
#include "RigResultAccessorFactory.h"
|
|
||||||
|
|
||||||
#include "RimProject.h"
|
|
||||||
#include "RimOilField.h"
|
|
||||||
#include "RimEclipseCaseCollection.h"
|
|
||||||
#include "RimEclipseCase.h"
|
#include "RimEclipseCase.h"
|
||||||
#include "RimEclipseView.h"
|
#include "RimEclipseCaseCollection.h"
|
||||||
#include "RimEclipseCellColors.h"
|
#include "RimEclipseCellColors.h"
|
||||||
|
#include "RimEclipseView.h"
|
||||||
|
#include "RimProject.h"
|
||||||
|
|
||||||
#include "cafUtils.h"
|
#include "cafUtils.h"
|
||||||
|
|
||||||
@ -49,12 +45,15 @@ CAF_PDM_SOURCE_INIT(RicfExportProperty, "exportProperty");
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
RicfExportProperty::RicfExportProperty()
|
RicfExportProperty::RicfExportProperty()
|
||||||
{
|
{
|
||||||
|
// clang-format off
|
||||||
RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", "");
|
RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", "");
|
||||||
RICF_InitField(&m_timeStepIndex, "timeStep", -1, "Time Step Index", "", "", "");
|
RICF_InitField(&m_timeStepIndex, "timeStep", -1, "Time Step Index", "", "", "");
|
||||||
RICF_InitField(&m_propertyName, "property", QString(), "Property Name", "", "", "");
|
RICF_InitField(&m_propertyName, "property", QString(), "Property Name", "", "", "");
|
||||||
RICF_InitField(&m_type, "type", caf::AppEnum<RiaDefines::ResultCatType>(RiaDefines::UNDEFINED), "Property type", "", "", "");
|
RICF_InitField(&m_type, "type", caf::AppEnum<RiaDefines::ResultCatType>(RiaDefines::DYNAMIC_NATIVE), "Property type", "", "", "");
|
||||||
RICF_InitField(&m_eclipseKeyword, "eclipseKeyword", QString(), "Eclipse Keyword", "", "", "");
|
RICF_InitField(&m_eclipseKeyword, "eclipseKeyword", QString(), "Eclipse Keyword", "", "", "");
|
||||||
RICF_InitField(&m_undefinedValue, "undefinedValue", 0.0, "Undefined Value", "", "", "");
|
RICF_InitField(&m_undefinedValue, "undefinedValue", 0.0, "Undefined Value", "", "", "");
|
||||||
|
RICF_InitField(&m_path, "exportFile", QString(), "Export File", "", "", "");
|
||||||
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -62,108 +61,63 @@ RicfExportProperty::RicfExportProperty()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicfExportProperty::execute()
|
void RicfExportProperty::execute()
|
||||||
{
|
{
|
||||||
|
|
||||||
RimEclipseCase* eclipseCase = nullptr;
|
RimEclipseCase* eclipseCase = nullptr;
|
||||||
{
|
{
|
||||||
bool foundCase = false;
|
std::vector<RimCase*> cases;
|
||||||
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels()->cases)
|
RiaApplication::instance()->project()->allCases(cases);
|
||||||
|
|
||||||
|
for (auto* c : cases)
|
||||||
{
|
{
|
||||||
if (c->caseId == m_caseId)
|
RimEclipseCase* eclCase = dynamic_cast<RimEclipseCase*>(c);
|
||||||
|
if (eclCase->caseId == m_caseId)
|
||||||
{
|
{
|
||||||
eclipseCase = c;
|
eclipseCase = eclCase;
|
||||||
foundCase = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!foundCase)
|
|
||||||
|
if (!eclipseCase)
|
||||||
{
|
{
|
||||||
RiaLogging::error(QString("exportProperty: Could not find case with ID %1").arg(m_caseId()));
|
RiaLogging::error(QString("exportProperty: Could not find case with ID %1").arg(m_caseId()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!eclipseCase->eclipseCaseData())
|
||||||
|
{
|
||||||
|
if (!eclipseCase->openReserviorCase())
|
||||||
|
{
|
||||||
|
RiaLogging::error(QString("exportProperty: Could not find eclipseCaseData with ID %1").arg(m_caseId()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fullySpecified = m_caseId >= 0 && m_timeStepIndex >= 0 && !m_propertyName().isEmpty();
|
RigEclipseCaseData* eclipseCaseData = eclipseCase->eclipseCaseData();
|
||||||
bool anyViewsFound = false;
|
|
||||||
for (Rim3dView* v : eclipseCase->views())
|
|
||||||
{
|
|
||||||
RimEclipseView* view = dynamic_cast<RimEclipseView*>(v);
|
|
||||||
if (!view) continue;
|
|
||||||
anyViewsFound = true;
|
|
||||||
|
|
||||||
auto timeStepIndex = m_timeStepIndex >= 0 ? m_timeStepIndex : view->currentTimeStep();
|
RigCaseCellResultsData* cellResultsData = eclipseCaseData->results(RiaDefines::MATRIX_MODEL);
|
||||||
auto propertyName = !m_propertyName().isEmpty() ? m_propertyName : view->cellResult()->resultVariable();
|
|
||||||
RiaDefines::ResultCatType propertyType;
|
size_t resultIdx = cellResultsData->findOrLoadScalarResult(m_propertyName);
|
||||||
if (!m_propertyName().isEmpty()) propertyType = m_type();
|
if (resultIdx == cvf::UNDEFINED_SIZE_T)
|
||||||
else propertyType = view->cellResult()->resultType();
|
{
|
||||||
|
RiaLogging::error(QString("exportProperty: Could not find result property : %1").arg(m_propertyName()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QString filePath = m_path;
|
QString filePath = m_path;
|
||||||
if (filePath.isNull())
|
if (filePath.isNull())
|
||||||
{
|
{
|
||||||
QDir propertiesDir(RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::PROPERTIES));
|
QDir propertiesDir(RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::PROPERTIES));
|
||||||
QString fileName;
|
QString fileName = QString("%1-%2").arg(eclipseCase->caseUserDescription()).arg(m_propertyName);
|
||||||
|
|
||||||
if (fullySpecified) fileName = QString("%1-T%2-%3").arg(eclipseCase->caseUserDescription()).arg(timeStepIndex).arg(propertyName);
|
|
||||||
else fileName = QString("%1-%2-T%3-%4").arg(eclipseCase->caseUserDescription()).arg(view->name()).arg(timeStepIndex).arg(propertyName);
|
|
||||||
|
|
||||||
fileName = caf::Utils::makeValidFileBasename(fileName);
|
fileName = caf::Utils::makeValidFileBasename(fileName);
|
||||||
filePath = propertiesDir.filePath(fileName);
|
filePath = propertiesDir.filePath(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto eclipseKeyword = m_eclipseKeyword();
|
QString eclipseKeyword = m_eclipseKeyword;
|
||||||
if (m_eclipseKeyword().isNull())
|
if (eclipseKeyword.isNull())
|
||||||
{
|
{
|
||||||
eclipseKeyword = propertyName;
|
eclipseKeyword = m_propertyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto resultAccessor = findResult(view, timeStepIndex, propertyType, propertyName);
|
RicEclipseCellResultToFileImpl::writePropertyToTextFile(
|
||||||
if (!resultAccessor.isNull())
|
filePath, eclipseCase->eclipseCaseData(), m_timeStepIndex, m_propertyName, eclipseKeyword, m_undefinedValue);
|
||||||
{
|
|
||||||
RicEclipseCellResultToFileImpl::writeResultToTextFile(filePath, eclipseCase->eclipseCaseData(), resultAccessor.p(), eclipseKeyword, m_undefinedValue, "exportProperty");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RiaLogging::error(QString("exportProperty: Could not find property. Case ID %1, time step %2, property '%3'")
|
|
||||||
.arg(m_caseId).arg(timeStepIndex).arg(propertyName));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fullySpecified) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!anyViewsFound)
|
|
||||||
{
|
|
||||||
RiaLogging::error(QString("exportProperty: Could not find any views for case ID %1").arg(m_caseId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
cvf::ref<RigResultAccessor> RicfExportProperty::findResult(RimEclipseView* view,
|
|
||||||
size_t timeStep,
|
|
||||||
RiaDefines::ResultCatType resultType,
|
|
||||||
const QString& property)
|
|
||||||
{
|
|
||||||
auto eclipseCase = view->eclipseCase();
|
|
||||||
size_t resultIndex = cvf::UNDEFINED_SIZE_T;
|
|
||||||
|
|
||||||
if (resultType == RiaDefines::UNDEFINED)
|
|
||||||
{
|
|
||||||
resultIndex = eclipseCase->results(RiaDefines::MATRIX_MODEL)->findOrLoadScalarResult(property);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
resultIndex = eclipseCase->results(RiaDefines::MATRIX_MODEL)->findOrLoadScalarResult(resultType, property);
|
|
||||||
}
|
|
||||||
|
|
||||||
cvf::ref<RigResultAccessor> resultAccessor = nullptr;
|
|
||||||
if (resultIndex != cvf::UNDEFINED_SIZE_T)
|
|
||||||
{
|
|
||||||
resultAccessor = RigResultAccessorFactory::createFromResultIdx(eclipseCase->eclipseCaseData(),
|
|
||||||
0,
|
|
||||||
RiaDefines::MATRIX_MODEL,
|
|
||||||
timeStep,
|
|
||||||
resultIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return resultAccessor;
|
|
||||||
}
|
}
|
||||||
|
@ -26,12 +26,6 @@
|
|||||||
|
|
||||||
#include "cafPdmField.h"
|
#include "cafPdmField.h"
|
||||||
|
|
||||||
#include <cvfObject.h>
|
|
||||||
|
|
||||||
class RigResultAccessor;
|
|
||||||
class RimEclipseCase;
|
|
||||||
class RimEclipseView;
|
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@ -46,11 +40,6 @@ public:
|
|||||||
|
|
||||||
virtual void execute() override;
|
virtual void execute() override;
|
||||||
|
|
||||||
cvf::ref<RigResultAccessor> findResult(RimEclipseView* view,
|
|
||||||
size_t timeStep,
|
|
||||||
RiaDefines::ResultCatType resultType,
|
|
||||||
const QString& property);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
caf::PdmField<int> m_caseId;
|
caf::PdmField<int> m_caseId;
|
||||||
caf::PdmField<int> m_timeStepIndex;
|
caf::PdmField<int> m_timeStepIndex;
|
||||||
|
@ -38,7 +38,8 @@ bool RicEclipseCellResultToFileImpl::writePropertyToTextFile(const QString&
|
|||||||
RigEclipseCaseData* eclipseCase,
|
RigEclipseCaseData* eclipseCase,
|
||||||
size_t timeStep,
|
size_t timeStep,
|
||||||
const QString& resultName,
|
const QString& resultName,
|
||||||
const QString& eclipseKeyword)
|
const QString& eclipseKeyword,
|
||||||
|
const double undefinedValue)
|
||||||
{
|
{
|
||||||
CVF_TIGHT_ASSERT(eclipseCase);
|
CVF_TIGHT_ASSERT(eclipseCase);
|
||||||
if (!eclipseCase) return false;
|
if (!eclipseCase) return false;
|
||||||
@ -50,8 +51,6 @@ bool RicEclipseCellResultToFileImpl::writePropertyToTextFile(const QString&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double undefinedValue = 0.0;
|
|
||||||
|
|
||||||
return writeResultToTextFile(
|
return writeResultToTextFile(
|
||||||
fileName, eclipseCase, resultAccessor.p(), eclipseKeyword, undefinedValue, "writePropertyToTextFile");
|
fileName, eclipseCase, resultAccessor.p(), eclipseKeyword, undefinedValue, "writePropertyToTextFile");
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,8 @@ public:
|
|||||||
RigEclipseCaseData* eclipseCase,
|
RigEclipseCaseData* eclipseCase,
|
||||||
size_t timeStep,
|
size_t timeStep,
|
||||||
const QString& resultName,
|
const QString& resultName,
|
||||||
const QString& eclipseKeyword);
|
const QString& eclipseKeyword,
|
||||||
|
const double undefinedValue);
|
||||||
|
|
||||||
static bool writeBinaryResultToTextFile(const QString& fileName,
|
static bool writeBinaryResultToTextFile(const QString& fileName,
|
||||||
RigEclipseCaseData* eclipseCase,
|
RigEclipseCaseData* eclipseCase,
|
||||||
|
@ -105,7 +105,14 @@ void RicSaveEclipseInputPropertyFeature::onActionTriggered(bool isChecked)
|
|||||||
|
|
||||||
if (propertyDialog.exec() == QDialog::Accepted)
|
if (propertyDialog.exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
bool isOk = RicEclipseCellResultToFileImpl::writePropertyToTextFile(exportSettings.fileName, inputReservoir->eclipseCaseData(), 0, inputProperty->resultName, exportSettings.eclipseKeyword);
|
const double undefinedValue = 0.0;
|
||||||
|
|
||||||
|
bool isOk = RicEclipseCellResultToFileImpl::writePropertyToTextFile(exportSettings.fileName,
|
||||||
|
inputReservoir->eclipseCaseData(),
|
||||||
|
0,
|
||||||
|
inputProperty->resultName,
|
||||||
|
exportSettings.eclipseKeyword,
|
||||||
|
undefinedValue);
|
||||||
if (isOk)
|
if (isOk)
|
||||||
{
|
{
|
||||||
inputProperty->fileName = exportSettings.fileName;
|
inputProperty->fileName = exportSettings.fileName;
|
||||||
|
Loading…
Reference in New Issue
Block a user