2017-07-27 03:23:05 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// 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 "RicfExportProperty.h"
|
|
|
|
|
|
|
|
#include "RicfCommandFileExecutor.h"
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
2017-07-27 07:26:59 -05:00
|
|
|
#include "RiaLogging.h"
|
|
|
|
|
2018-10-03 08:44:38 -05:00
|
|
|
#include "RigCaseCellResultsData.h"
|
|
|
|
#include "RigEclipseCaseData.h"
|
|
|
|
#include "RigMainGrid.h"
|
|
|
|
#include "RigResultAccessor.h"
|
|
|
|
#include "RigResultAccessorFactory.h"
|
|
|
|
|
2017-07-27 03:23:05 -05:00
|
|
|
#include "RimProject.h"
|
|
|
|
#include "RimOilField.h"
|
|
|
|
#include "RimEclipseCaseCollection.h"
|
|
|
|
#include "RimEclipseCase.h"
|
|
|
|
#include "RimEclipseView.h"
|
|
|
|
#include "RimEclipseCellColors.h"
|
|
|
|
|
|
|
|
#include "RifEclipseInputFileTools.h"
|
|
|
|
|
2017-08-29 02:39:06 -05:00
|
|
|
#include "cafUtils.h"
|
|
|
|
|
2017-07-27 03:23:05 -05:00
|
|
|
#include <QDir>
|
|
|
|
|
|
|
|
CAF_PDM_SOURCE_INIT(RicfExportProperty, "exportProperty");
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicfExportProperty::RicfExportProperty()
|
|
|
|
{
|
2017-08-30 08:29:01 -05:00
|
|
|
RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", "");
|
|
|
|
RICF_InitField(&m_timeStepIndex, "timeStep", -1, "Time Step Index", "", "", "");
|
|
|
|
RICF_InitField(&m_propertyName, "property", QString(), "Property Name", "", "", "");
|
2018-10-03 08:44:38 -05:00
|
|
|
RICF_InitField(&m_type, "type", caf::AppEnum<RiaDefines::ResultCatType>(RiaDefines::UNDEFINED), "Property type", "", "", "");
|
2017-08-30 08:29:01 -05:00
|
|
|
RICF_InitField(&m_eclipseKeyword, "eclipseKeyword", QString(), "Eclipse Keyword", "", "", "");
|
|
|
|
RICF_InitField(&m_undefinedValue, "undefinedValue", 0.0, "Undefined Value", "", "", "");
|
2017-07-27 03:23:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicfExportProperty::execute()
|
|
|
|
{
|
|
|
|
|
2018-09-11 14:56:15 -05:00
|
|
|
RimEclipseCase* eclipseCase = nullptr;
|
2017-07-27 03:23:05 -05:00
|
|
|
{
|
2017-07-27 07:26:59 -05:00
|
|
|
bool foundCase = false;
|
|
|
|
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels()->cases)
|
|
|
|
{
|
|
|
|
if (c->caseId == m_caseId)
|
|
|
|
{
|
|
|
|
eclipseCase = c;
|
|
|
|
foundCase = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!foundCase)
|
2017-07-27 03:23:05 -05:00
|
|
|
{
|
2017-07-27 07:26:59 -05:00
|
|
|
RiaLogging::error(QString("exportProperty: Could not find case with ID %1").arg(m_caseId()));
|
|
|
|
return;
|
2017-07-27 03:23:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 03:20:38 -05:00
|
|
|
bool fullySpecified = m_caseId >= 0 && m_timeStepIndex >= 0 && !m_propertyName().isEmpty();
|
|
|
|
bool anyViewsFound = false;
|
2018-01-09 03:11:28 -06:00
|
|
|
for (Rim3dView* v : eclipseCase->views())
|
2017-07-27 03:23:05 -05:00
|
|
|
{
|
2018-10-05 03:20:38 -05:00
|
|
|
RimEclipseView* view = dynamic_cast<RimEclipseView*>(v);
|
|
|
|
if (!view) continue;
|
|
|
|
anyViewsFound = true;
|
2017-07-27 03:23:05 -05:00
|
|
|
|
2018-10-05 03:20:38 -05:00
|
|
|
auto timeStepIndex = m_timeStepIndex >= 0 ? m_timeStepIndex : view->currentTimeStep();
|
|
|
|
auto propertyName = !m_propertyName().isEmpty() ? m_propertyName : view->cellResult()->resultVariable();
|
2018-10-05 08:20:18 -05:00
|
|
|
RiaDefines::ResultCatType propertyType;
|
|
|
|
if (!m_propertyName().isEmpty()) propertyType = m_type();
|
|
|
|
else propertyType = view->cellResult()->resultType();
|
2018-10-05 03:20:38 -05:00
|
|
|
|
|
|
|
QString filePath = m_path;
|
|
|
|
if (filePath.isNull())
|
|
|
|
{
|
|
|
|
QDir propertiesDir(RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::PROPERTIES));
|
|
|
|
QString fileName;
|
|
|
|
|
|
|
|
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);
|
|
|
|
filePath = propertiesDir.filePath(fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto eclipseKeyword = m_eclipseKeyword();
|
|
|
|
if (m_eclipseKeyword().isNull())
|
|
|
|
{
|
|
|
|
eclipseKeyword = propertyName;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto resultAccessor = findResult(view, timeStepIndex, propertyType, propertyName);
|
|
|
|
if (!resultAccessor.isNull())
|
|
|
|
{
|
2018-10-05 03:58:37 -05:00
|
|
|
RifEclipseInputFileTools::writeResultToTextFile(filePath, eclipseCase->eclipseCaseData(), resultAccessor, 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));
|
2018-10-05 03:20:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fullySpecified) break;
|
2017-07-27 03:23:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-05 03:20:38 -05:00
|
|
|
if (!anyViewsFound)
|
2018-10-03 08:44:38 -05:00
|
|
|
{
|
2018-10-05 03:58:37 -05:00
|
|
|
RiaLogging::error(QString("exportProperty: Could not find any views for case ID %1").arg(m_caseId()));
|
2018-10-03 08:44:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
cvf::ref<RigResultAccessor> RicfExportProperty::findResult(RimEclipseView* view,
|
|
|
|
size_t timeStep,
|
|
|
|
RiaDefines::ResultCatType resultType,
|
|
|
|
const QString& property)
|
|
|
|
{
|
2018-10-05 03:20:38 -05:00
|
|
|
auto eclipseCase = view->eclipseCase();
|
2018-10-03 08:44:38 -05:00
|
|
|
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);
|
|
|
|
}
|
2017-07-27 03:23:05 -05:00
|
|
|
|
2018-10-03 08:44:38 -05:00
|
|
|
return resultAccessor;
|
2017-07-27 03:23:05 -05:00
|
|
|
}
|