2017-07-27 03:23:05 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2018-10-11 00:31:15 -05:00
|
|
|
//
|
2017-07-27 03:23:05 -05:00
|
|
|
// 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.
|
2018-10-11 00:31:15 -05:00
|
|
|
//
|
2017-07-27 03:23:05 -05:00
|
|
|
// 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.
|
2018-10-11 00:31:15 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-07-27 03:23:05 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicfExportProperty.h"
|
|
|
|
|
2018-10-11 00:31:15 -05:00
|
|
|
#include "RiaApplication.h"
|
|
|
|
#include "RiaLogging.h"
|
2017-07-27 03:23:05 -05:00
|
|
|
|
2018-10-10 08:12:54 -05:00
|
|
|
#include "../Commands/ExportCommands/RicEclipseCellResultToFileImpl.h"
|
2018-10-11 00:31:15 -05:00
|
|
|
#include "RicfCommandFileExecutor.h"
|
2018-10-10 08:12:54 -05:00
|
|
|
|
2018-10-11 00:31:15 -05:00
|
|
|
#include "RifEclipseInputFileTools.h"
|
2017-07-27 07:26:59 -05:00
|
|
|
|
2018-10-03 08:44:38 -05:00
|
|
|
#include "RigCaseCellResultsData.h"
|
|
|
|
#include "RigEclipseCaseData.h"
|
2017-07-27 03:23:05 -05:00
|
|
|
#include "RimEclipseCase.h"
|
2018-10-11 00:31:15 -05:00
|
|
|
#include "RimEclipseCaseCollection.h"
|
2017-07-27 03:23:05 -05:00
|
|
|
#include "RimEclipseCellColors.h"
|
2018-10-11 00:31:15 -05:00
|
|
|
#include "RimEclipseView.h"
|
|
|
|
#include "RimProject.h"
|
2017-07-27 03:23:05 -05:00
|
|
|
|
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");
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-10-11 00:31:15 -05:00
|
|
|
///
|
2017-07-27 03:23:05 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicfExportProperty::RicfExportProperty()
|
|
|
|
{
|
2018-10-11 00:31:15 -05:00
|
|
|
// clang-format off
|
|
|
|
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", "", "", "");
|
|
|
|
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_undefinedValue, "undefinedValue", 0.0, "Undefined Value", "", "", "");
|
|
|
|
RICF_InitField(&m_path, "exportFile", QString(), "Export File", "", "", "");
|
|
|
|
// clang-format on
|
2017-07-27 03:23:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-10-11 00:31:15 -05:00
|
|
|
///
|
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
|
|
|
{
|
2018-10-11 00:31:15 -05:00
|
|
|
std::vector<RimCase*> cases;
|
|
|
|
RiaApplication::instance()->project()->allCases(cases);
|
|
|
|
|
|
|
|
for (auto* c : cases)
|
2017-07-27 07:26:59 -05:00
|
|
|
{
|
2018-10-11 00:31:15 -05:00
|
|
|
RimEclipseCase* eclCase = dynamic_cast<RimEclipseCase*>(c);
|
|
|
|
if (eclCase->caseId == m_caseId)
|
2017-07-27 07:26:59 -05:00
|
|
|
{
|
2018-10-11 00:31:15 -05:00
|
|
|
eclipseCase = eclCase;
|
2017-07-27 07:26:59 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-10-11 00:31:15 -05:00
|
|
|
|
|
|
|
if (!eclipseCase)
|
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-11 00:31:15 -05:00
|
|
|
if (!eclipseCase->eclipseCaseData())
|
2018-10-05 03:20:38 -05:00
|
|
|
{
|
2018-10-11 00:31:15 -05:00
|
|
|
if (!eclipseCase->openReserviorCase())
|
|
|
|
{
|
|
|
|
RiaLogging::error(QString("exportProperty: Could not find eclipseCaseData with ID %1").arg(m_caseId()));
|
|
|
|
return;
|
|
|
|
}
|
2018-10-05 03:20:38 -05:00
|
|
|
}
|
2017-07-27 03:23:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-11 00:31:15 -05:00
|
|
|
RigEclipseCaseData* eclipseCaseData = eclipseCase->eclipseCaseData();
|
2018-10-03 08:44:38 -05:00
|
|
|
|
2018-10-11 00:31:15 -05:00
|
|
|
RigCaseCellResultsData* cellResultsData = eclipseCaseData->results(RiaDefines::MATRIX_MODEL);
|
2018-10-03 08:44:38 -05:00
|
|
|
|
2018-10-11 00:31:15 -05:00
|
|
|
size_t resultIdx = cellResultsData->findOrLoadScalarResult(m_propertyName);
|
|
|
|
if (resultIdx == cvf::UNDEFINED_SIZE_T)
|
2018-10-03 08:44:38 -05:00
|
|
|
{
|
2018-10-11 00:31:15 -05:00
|
|
|
RiaLogging::error(QString("exportProperty: Could not find result property : %1").arg(m_propertyName()));
|
|
|
|
return;
|
2018-10-03 08:44:38 -05:00
|
|
|
}
|
2018-10-11 00:31:15 -05:00
|
|
|
|
|
|
|
QString filePath = m_path;
|
|
|
|
if (filePath.isNull())
|
2018-10-03 08:44:38 -05:00
|
|
|
{
|
2018-10-11 00:31:15 -05:00
|
|
|
QDir propertiesDir(RicfCommandFileExecutor::instance()->getExportPath(RicfCommandFileExecutor::PROPERTIES));
|
|
|
|
QString fileName = QString("%1-%2").arg(eclipseCase->caseUserDescription()).arg(m_propertyName);
|
|
|
|
fileName = caf::Utils::makeValidFileBasename(fileName);
|
|
|
|
filePath = propertiesDir.filePath(fileName);
|
2018-10-03 08:44:38 -05:00
|
|
|
}
|
|
|
|
|
2018-10-11 00:31:15 -05:00
|
|
|
QString eclipseKeyword = m_eclipseKeyword;
|
|
|
|
if (eclipseKeyword.isNull())
|
2018-10-03 08:44:38 -05:00
|
|
|
{
|
2018-10-11 00:31:15 -05:00
|
|
|
eclipseKeyword = m_propertyName;
|
2018-10-03 08:44:38 -05:00
|
|
|
}
|
2017-07-27 03:23:05 -05:00
|
|
|
|
2018-10-11 00:31:15 -05:00
|
|
|
RicEclipseCellResultToFileImpl::writePropertyToTextFile(
|
|
|
|
filePath, eclipseCase->eclipseCaseData(), m_timeStepIndex, m_propertyName, eclipseKeyword, m_undefinedValue);
|
2017-07-27 03:23:05 -05:00
|
|
|
}
|