#4136 Command File : Export of flow characteristics

This commit is contained in:
Magne Sjaastad 2019-06-25 17:49:38 +02:00
parent 58b8ca6ff4
commit b2857676c8
5 changed files with 227 additions and 0 deletions

View File

@ -28,6 +28,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfExportLgrForCompletions.h
${CMAKE_CURRENT_LIST_DIR}/RicfCreateLgrForCompletions.h
${CMAKE_CURRENT_LIST_DIR}/RicfApplicationTools.h
${CMAKE_CURRENT_LIST_DIR}/RicfCreateSaturationPressurePlots.h
${CMAKE_CURRENT_LIST_DIR}/RicfExportFlowCharacteristics.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -59,6 +60,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfExportLgrForCompletions.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfCreateLgrForCompletions.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfApplicationTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfCreateSaturationPressurePlots.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfExportFlowCharacteristics.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -0,0 +1,116 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicfExportFlowCharacteristics.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "RicfApplicationTools.h"
#include "RimEclipseResultCase.h"
#include "RimFlowCharacteristicsPlot.h"
#include "RimFlowPlotCollection.h"
#include "RimMainPlotCollection.h"
#include "RimProject.h"
#include <QDir>
#include <QFile>
#include <QTextStream>
CAF_PDM_SOURCE_INIT(RicfExportFlowCharacteristics, "exportFlowCharacteristics");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfExportFlowCharacteristics::RicfExportFlowCharacteristics()
{
RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", "");
RICF_InitField(&m_selectedTimeSteps, "timeSteps", std::vector<int>(), "Selected Time Steps", "", "", "");
RICF_InitField(&m_injectors, "injectors", std::vector<QString>(), "Injectors", "", "", "");
RICF_InitField(&m_producers, "producers", std::vector<QString>(), "Producers", "", "", "");
RICF_InitField(&m_fileName, "fileName", QString(), "Export File Name", "", "", "");
RICF_InitField(&m_minCommunication, "minimumCommunication", 0.0, "Minimum Communication", "", "", "");
RICF_InitField(&m_maxPvFraction, "aquiferCellThreshold", 0.1, "Aquifer Cell Threshold", "", "", "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfCommandResponse RicfExportFlowCharacteristics::execute()
{
using TOOLS = RicfApplicationTools;
auto eclipseCase = dynamic_cast<RimEclipseResultCase*>(TOOLS::caseFromId(m_caseId()));
if (!eclipseCase)
{
QString error = QString("exportFlowCharacteristics: Could not find case with ID %1.").arg(m_caseId());
RiaLogging::error(error);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error);
}
{
QString exportFileName = m_fileName();
if (exportFileName.isEmpty())
{
QString exportFolder = RiaApplication::instance()->createAbsolutePathFromProjectRelativePath("flow_characteristics");
QDir exportDir(exportFolder);
if (!exportDir.exists())
{
if (!exportDir.mkpath("."))
{
QString msg = QString("Failed to create folder - %1").arg(exportFolder);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, msg);
}
}
exportFileName = exportFolder + QString("/flow_characteristics_data.txt");
}
RimFlowPlotCollection* flowPlotColl = RiaApplication::instance()->project()->mainPlotCollection->flowPlotCollection();
if (flowPlotColl)
{
RimFlowCharacteristicsPlot* plot = flowPlotColl->defaultFlowCharacteristicsPlot();
plot->setFromFlowSolution(eclipseCase->defaultFlowDiagSolution());
plot->setTimeSteps(m_selectedTimeSteps);
plot->setInjectorsAndProducers(m_injectors, m_producers);
plot->setAquiferCellThreshold(m_maxPvFraction);
plot->setMinimumCommunication(m_minCommunication);
plot->loadDataAndUpdate();
{
QString content = plot->curveDataAsText();
QFile file(exportFileName);
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream textstream(&file);
textstream << content;
}
else
{
QString msg = QString("Failed to export file - %1").arg(exportFileName);
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, msg);
}
}
}
}
return RicfCommandResponse();
}

View File

@ -0,0 +1,51 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <QString>
#include "cafPdmField.h"
//==================================================================================================
//
//
//
//==================================================================================================
class RicfExportFlowCharacteristics : public RicfCommandObject
{
CAF_PDM_HEADER_INIT;
public:
RicfExportFlowCharacteristics();
RicfCommandResponse execute() override;
private:
caf::PdmField<int> m_caseId;
caf::PdmField<std::vector<int>> m_selectedTimeSteps;
caf::PdmField<std::vector<QString>> m_injectors;
caf::PdmField<std::vector<QString>> m_producers;
caf::PdmField<QString> m_fileName;
caf::PdmField<double> m_minCommunication;
caf::PdmField<double> m_maxPvFraction;
};

View File

@ -141,6 +141,8 @@ void RimFlowCharacteristicsPlot::setFromFlowSolution(RimFlowDiagSolution* flowSo
m_flowDiagSolution = flowSolution;
m_showWindow = true;
m_timeStepToFlowResultMap.clear();
m_currentlyPlottedTimeSteps.clear();
onLoadDataAndUpdate();
}
@ -173,6 +175,57 @@ void RimFlowCharacteristicsPlot::updateCurrentTimeStep()
this->onLoadDataAndUpdate();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFlowCharacteristicsPlot::setTimeSteps(const std::vector<int>& timeSteps)
{
m_selectedTimeSteps = timeSteps;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFlowCharacteristicsPlot::setInjectorsAndProducers(const std::vector<QString>& injectors,
const std::vector<QString>& producers)
{
std::vector<QString> allTracers;
allTracers = producers;
allTracers.insert(allTracers.end(), injectors.begin(), injectors.end());
if (producers.empty() && !injectors.empty())
{
m_cellFilter = RigFlowDiagResults::CELLS_FLOODED;
}
else if (!producers.empty() && injectors.empty())
{
m_cellFilter = RigFlowDiagResults::CELLS_DRAINED;
}
else if (!producers.empty() && !injectors.empty())
{
m_cellFilter = RigFlowDiagResults::CELLS_COMMUNICATION;
}
m_selectedTracerNames = allTracers;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFlowCharacteristicsPlot::setMinimumCommunication(double minimumCommunication)
{
m_minCommunication = minimumCommunication;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFlowCharacteristicsPlot::setAquiferCellThreshold(double aquiferCellThreshold)
{
m_maxPvFraction = aquiferCellThreshold;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -75,6 +75,11 @@ public:
SELECTED,
};
void setTimeSteps(const std::vector<int>& timeSteps);
void setInjectorsAndProducers(const std::vector<QString>& injectors, const std::vector<QString>& producers);
void setMinimumCommunication(double minimumCommunication);
void setAquiferCellThreshold(double aquiferCellThreshold);
protected:
// RimViewWindow overrides