ResInsight/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.cpp

354 lines
13 KiB
C++
Raw Normal View History

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// 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 "RimWellLogExtractionCurve.h"
#include "RimProject.h"
#include "RiaApplication.h"
#include "RimOilField.h"
#include "RimWellPathCollection.h"
#include "RimWellPath.h"
#include "RimEclipseCase.h"
#include "RimEclipseResultDefinition.h"
#include "RimGeoMechResultDefinition.h"
#include "RimGeoMechCase.h"
#include "RigEclipseWellLogExtractor.h"
#include "RigResultAccessorFactory.h"
#include "RigCaseCellResultsData.h"
#include "RigCaseData.h"
#include "RimWellLogPlotCurve.h"
#include "RimWellLogPlot.h"
#include "RimWellLogPlotTrace.h"
#include "RiuWellLogTracePlot.h"
#include "qwt_plot_curve.h"
#include "RimWellLogPlotCollection.h"
#include "cafPdmUiTreeOrdering.h"
#include "RigGeoMechWellLogExtractor.h"
//==================================================================================================
///
///
//==================================================================================================
CAF_PDM_SOURCE_INIT(RimWellLogExtractionCurve, "WellLogEclipseCurve");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellLogExtractionCurve::RimWellLogExtractionCurve()
{
CAF_PDM_InitObject("Well Log Curve", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_wellPath, "CurveWellPath", "Well Path", "", "", "");
m_wellPath.uiCapability()->setUiChildrenHidden(true);
//m_wellPath.uiCapability()->setUiHidden(true);
CAF_PDM_InitFieldNoDefault(&m_case, "CurveCase", "Case", "", "", "");
m_case.uiCapability()->setUiChildrenHidden(true);
//m_case.uiCapability()->setUiHidden(true);
CAF_PDM_InitFieldNoDefault(&m_eclipseResultDefinition, "CurveEclipseResult", "", "", "", "");
m_eclipseResultDefinition.uiCapability()->setUiHidden(true);
m_eclipseResultDefinition.uiCapability()->setUiChildrenHidden(true);
m_eclipseResultDefinition = new RimEclipseResultDefinition;
CAF_PDM_InitFieldNoDefault(&m_geomResultDefinition, "CurveGeomechResult", "", "", "", "");
m_geomResultDefinition.uiCapability()->setUiHidden(true);
m_geomResultDefinition.uiCapability()->setUiChildrenHidden(true);
m_geomResultDefinition = new RimGeoMechResultDefinition;
CAF_PDM_InitField(&m_timeStep, "CurveTimeStep", 0,"Time Step", "", "", "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellLogExtractionCurve::~RimWellLogExtractionCurve()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogExtractionCurve::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
RimWellLogPlotCurve::fieldChangedByUi(changedField, oldValue, newValue);
if (changedField == &m_case)
{
this->updatePlotData();
}
if (changedField == &m_wellPath)
{
this->updatePlotData();
}
if (changedField == &m_timeStep)
{
this->updatePlotData();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogExtractionCurve::updatePlotData()
{
RimWellLogPlotCurve::updatePlotData();
if (m_showCurve)
{
// Make sure we have set correct case data into the result definitions.
RimGeoMechCase* geomCase = dynamic_cast<RimGeoMechCase*>(m_case.value());
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case.value());
m_eclipseResultDefinition->setEclipseCase(eclipseCase);
m_geomResultDefinition->setGeoMechCase(geomCase);
RimWellLogPlotCollection* wellLogCollection = NULL;
this->firstAnchestorOrThisOfType(wellLogCollection);
CVF_ASSERT(wellLogCollection);
cvf::ref<RigEclipseWellLogExtractor> eclExtractor = wellLogCollection->findOrCreateExtractor(m_wellPath, eclipseCase);
cvf::ref<RigGeoMechWellLogExtractor> geomExtractor = wellLogCollection->findOrCreateExtractor(m_wellPath, geomCase);
std::vector<double> filteredValues;
std::vector<double> filteredDepths;
if (eclExtractor.notNull())
{
RimWellLogPlot* wellLogPlot;
firstAnchestorOrThisOfType(wellLogPlot);
CVF_ASSERT(wellLogPlot);
const std::vector<double>& depthValues = wellLogPlot->depthType() == RimWellLogPlot::MEASURED_DEPTH ? eclExtractor->measuredDepth() : eclExtractor->trueVerticalDepth();
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(m_eclipseResultDefinition->porosityModel());
m_eclipseResultDefinition->loadResult();
cvf::ref<RigResultAccessor> resAcc = RigResultAccessorFactory::createResultAccessor(
eclipseCase->reservoirData(), 0,
porosityModel,
m_timeStep,
m_eclipseResultDefinition->resultVariable());
std::vector<double> values;
if (resAcc.notNull())
{
eclExtractor->curveData(resAcc.p(), &values);
}
filterPlotValues( depthValues, filteredDepths,
values, filteredValues );
}
else if (geomExtractor.notNull()) // geomExtractor
{
const std::vector<double>& depthValues = geomExtractor->measuredDepth();
m_geomResultDefinition->loadResult();
std::vector<double> values;
geomExtractor->curveData(m_geomResultDefinition->resultAddress() , m_timeStep, &values);
filterPlotValues( depthValues, filteredDepths,
values, filteredValues );
}
m_plotCurve->setSamples(filteredValues.data(), filteredDepths.data(), (int)filteredValues.size());
if (filteredValues.size())
{
RimWellLogPlotTrace* plotTrace;
firstAnchestorOrThisOfType(plotTrace);
RimWellLogPlot* wellLogPlot;
firstAnchestorOrThisOfType(wellLogPlot);
if (wellLogPlot && plotTrace)
{
bool setDepthRange = !wellLogPlot->hasAvailableDepthRange();
wellLogPlot->updateAvailableDepthRange();
if (setDepthRange)
{
wellLogPlot->setVisibleDepthRangeFromContents();
}
else if (plotTrace->curveCount() == 1)
{
plotTrace->updateAxisRangesAndReplot();
}
}
}
updateCurveTitle();
m_plot->replot();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo> RimWellLogExtractionCurve::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly)
{
QList<caf::PdmOptionItemInfo> optionList;
if (fieldNeedingOptions == &m_wellPath)
{
RimProject* proj = RiaApplication::instance()->project();
if (proj->activeOilField()->wellPathCollection())
{
caf::PdmChildArrayField<RimWellPath*>& wellPaths = proj->activeOilField()->wellPathCollection()->wellPaths;
for (size_t i = 0; i< wellPaths.size(); i++)
{
optionList.push_back(caf::PdmOptionItemInfo(wellPaths[i]->name(), QVariant::fromValue(caf::PdmPointer<caf::PdmObjectHandle>(wellPaths[i]))));
}
if (optionList.size() > 0)
{
optionList.push_front(caf::PdmOptionItemInfo("None", QVariant::fromValue(caf::PdmPointer<caf::PdmObjectHandle>(NULL))));
}
}
}
if (fieldNeedingOptions == &m_case)
{
RimProject* proj = RiaApplication::instance()->project();
std::vector<RimCase*> cases;
proj->allCases(cases);
for (size_t i = 0; i< cases.size(); i++)
{
optionList.push_back(caf::PdmOptionItemInfo(cases[i]->caseUserDescription(), QVariant::fromValue(caf::PdmPointer<caf::PdmObjectHandle>(cases[i]))));
}
if (optionList.size() > 0)
{
optionList.push_front(caf::PdmOptionItemInfo("None", QVariant::fromValue(caf::PdmPointer<caf::PdmObjectHandle>(NULL))));
}
}
return optionList;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogExtractionCurve::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
RimGeoMechCase* geomCase = dynamic_cast<RimGeoMechCase*>(m_case.value());
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case.value());
uiOrdering.add(&m_userName);
uiOrdering.add(&m_wellPath);
caf::PdmUiGroup* group1 = uiOrdering.addNewGroup("Result");
group1->add(&m_case);
if (eclipseCase)
{
group1->add(&(m_eclipseResultDefinition->m_resultTypeUiField));
group1->add(&(m_eclipseResultDefinition->m_porosityModelUiField));
group1->add(&(m_eclipseResultDefinition->m_resultVariableUiField));
}
if (geomCase)
{
group1->add(&(m_geomResultDefinition->m_resultPositionTypeUiField));
group1->add(&(m_geomResultDefinition->m_resultVariableUiField));
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogExtractionCurve::initAfterRead()
{
RimGeoMechCase* geomCase = dynamic_cast<RimGeoMechCase*>(m_case.value());
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case.value());
m_eclipseResultDefinition->setEclipseCase(eclipseCase);
m_geomResultDefinition->setGeoMechCase(geomCase);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogExtractionCurve::updateCurveTitle()
{
RimGeoMechCase* geomCase = dynamic_cast<RimGeoMechCase*>(m_case.value());
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case.value());
QString resVar;
if (eclipseCase)
{
resVar = m_eclipseResultDefinition->resultVariable();
}
if (geomCase)
{
QString resCompName = m_geomResultDefinition->resultComponentUiName();
if (resCompName.isEmpty())
resVar = m_geomResultDefinition->resultFieldUiName();
else
resVar = m_geomResultDefinition->resultFieldUiName() + "." + resCompName ;
}
m_userName = resVar;
m_plotCurve->setTitle(m_userName);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogExtractionCurve::defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= ""*/)
{
uiTreeOrdering.setForgetRemainingFields(true);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogExtractionCurve::filterPlotValues(const std::vector<double>& depthValues, std::vector<double> &filteredDepths,
const std::vector<double> &values, std::vector<double> &filteredValues )
{
// Remove values that are too difficult for Qwt to handle
filteredValues.reserve(values.size());
filteredDepths.reserve(values.size());
for (size_t vIdx = 0; vIdx < values.size(); ++vIdx)
{
if (values[vIdx] == HUGE_VAL || values[vIdx] == -HUGE_VAL || (values[vIdx] != values[vIdx]))
{
continue;
}
filteredDepths.push_back(depthValues[vIdx]);
filteredValues.push_back(values[vIdx]);
}
}