2012-05-18 02:45:23 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2011-2012 Statoil ASA, Ceetron 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 "RigReservoirCellResults.h"
|
|
|
|
#include "RifReaderInterface.h"
|
2012-06-26 09:10:41 -05:00
|
|
|
#include "RigMainGrid.h"
|
|
|
|
|
|
|
|
#include <QDateTime>
|
2013-02-13 07:59:30 -06:00
|
|
|
#include <math.h>
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2012-06-26 09:10:41 -05:00
|
|
|
RigReservoirCellResults::RigReservoirCellResults(RigMainGrid* ownerGrid)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2012-06-26 09:10:41 -05:00
|
|
|
CVF_ASSERT(ownerGrid != NULL);
|
|
|
|
m_ownerMainGrid = ownerGrid;
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RigReservoirCellResults::minMaxCellScalarValues( size_t scalarResultIndex, double& min, double& max )
|
|
|
|
{
|
|
|
|
min = HUGE_VAL;
|
|
|
|
max = -HUGE_VAL;
|
|
|
|
|
|
|
|
CVF_ASSERT(scalarResultIndex < resultCount());
|
|
|
|
|
|
|
|
// Extend array and cache vars
|
|
|
|
|
|
|
|
if (scalarResultIndex >= m_maxMinValues.size() )
|
|
|
|
{
|
|
|
|
m_maxMinValues.resize(scalarResultIndex+1, std::make_pair(HUGE_VAL, -HUGE_VAL));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_maxMinValues[scalarResultIndex].first != HUGE_VAL)
|
|
|
|
{
|
|
|
|
min = m_maxMinValues[scalarResultIndex].first;
|
|
|
|
max = m_maxMinValues[scalarResultIndex].second;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < timeStepCount(scalarResultIndex); i++)
|
|
|
|
{
|
|
|
|
double tsmin, tsmax;
|
|
|
|
minMaxCellScalarValues(scalarResultIndex, i, tsmin, tsmax);
|
|
|
|
if (tsmin < min) min = tsmin;
|
|
|
|
if (tsmax > max) max = tsmax;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_maxMinValues[scalarResultIndex].first = min;
|
|
|
|
m_maxMinValues[scalarResultIndex].second= max;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RigReservoirCellResults::minMaxCellScalarValues(size_t scalarResultIndex, size_t timeStepIndex, double& min, double& max)
|
|
|
|
{
|
|
|
|
min = HUGE_VAL;
|
|
|
|
max = -HUGE_VAL;
|
|
|
|
|
|
|
|
CVF_ASSERT(scalarResultIndex < resultCount());
|
|
|
|
CVF_ASSERT(timeStepIndex < m_cellScalarResults[scalarResultIndex].size() );
|
|
|
|
|
|
|
|
if (scalarResultIndex >= m_maxMinValuesPrTs.size())
|
|
|
|
{
|
|
|
|
m_maxMinValuesPrTs.resize(scalarResultIndex+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timeStepIndex >= m_maxMinValuesPrTs[scalarResultIndex].size())
|
|
|
|
{
|
|
|
|
m_maxMinValuesPrTs[scalarResultIndex].resize(timeStepIndex+1, std::make_pair(HUGE_VAL, -HUGE_VAL));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_maxMinValuesPrTs[scalarResultIndex][timeStepIndex].first != HUGE_VAL)
|
|
|
|
{
|
|
|
|
min = m_maxMinValuesPrTs[scalarResultIndex][timeStepIndex].first;
|
|
|
|
max = m_maxMinValuesPrTs[scalarResultIndex][timeStepIndex].second;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<double>& values = m_cellScalarResults[scalarResultIndex][timeStepIndex];
|
|
|
|
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < values.size(); i++)
|
|
|
|
{
|
2012-10-24 03:52:44 -05:00
|
|
|
if (values[i] == HUGE_VAL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
if (values[i] < min)
|
|
|
|
{
|
|
|
|
min = values[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (values[i] > max)
|
|
|
|
{
|
|
|
|
max = values[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_maxMinValuesPrTs[scalarResultIndex][timeStepIndex].first = min;
|
|
|
|
m_maxMinValuesPrTs[scalarResultIndex][timeStepIndex].second= max;
|
|
|
|
}
|
|
|
|
|
2012-09-11 02:22:36 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
const std::vector<size_t>& RigReservoirCellResults::cellScalarValuesHistogram(size_t scalarResultIndex)
|
|
|
|
{
|
|
|
|
CVF_ASSERT(scalarResultIndex < resultCount());
|
|
|
|
|
|
|
|
// Extend array and cache vars
|
|
|
|
|
|
|
|
if (scalarResultIndex >= m_histograms.size() )
|
|
|
|
{
|
|
|
|
m_histograms.resize(resultCount());
|
|
|
|
m_p10p90.resize(resultCount(), std::make_pair(HUGE_VAL, HUGE_VAL));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_histograms[scalarResultIndex].size())
|
|
|
|
{
|
|
|
|
return m_histograms[scalarResultIndex];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
double min;
|
|
|
|
double max;
|
|
|
|
size_t nBins = 100;
|
|
|
|
this->minMaxCellScalarValues( scalarResultIndex, min, max );
|
|
|
|
RigHistogramCalculator histCalc(min, max, nBins, &m_histograms[scalarResultIndex]);
|
|
|
|
|
|
|
|
for (size_t tsIdx = 0; tsIdx < this->timeStepCount(scalarResultIndex); tsIdx++)
|
|
|
|
{
|
|
|
|
std::vector<double>& values = m_cellScalarResults[scalarResultIndex][tsIdx];
|
|
|
|
|
|
|
|
histCalc.addData(values);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_p10p90[scalarResultIndex].first = histCalc.calculatePercentil(0.1);
|
|
|
|
m_p10p90[scalarResultIndex].second = histCalc.calculatePercentil(0.9);
|
|
|
|
|
|
|
|
return m_histograms[scalarResultIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RigReservoirCellResults::p10p90CellScalarValues(size_t scalarResultIndex, double& p10, double& p90)
|
|
|
|
{
|
|
|
|
const std::vector<size_t>& histogr = cellScalarValuesHistogram( scalarResultIndex);
|
|
|
|
p10 = m_p10p90[scalarResultIndex].first;
|
|
|
|
p90 = m_p10p90[scalarResultIndex].second;
|
|
|
|
}
|
|
|
|
|
2012-10-23 05:08:46 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RigReservoirCellResults::meanCellScalarValues(size_t scalarResultIndex, double& meanValue)
|
|
|
|
{
|
|
|
|
CVF_ASSERT(scalarResultIndex < resultCount());
|
|
|
|
|
|
|
|
// Extend array and cache vars
|
|
|
|
|
|
|
|
if (scalarResultIndex >= m_meanValues.size() )
|
|
|
|
{
|
|
|
|
m_meanValues.resize(scalarResultIndex+1, HUGE_VAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_meanValues[scalarResultIndex] != HUGE_VAL)
|
|
|
|
{
|
|
|
|
meanValue = m_meanValues[scalarResultIndex];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
double valueSum = 0.0;
|
|
|
|
size_t count = 0;
|
|
|
|
for (size_t tIdx = 0; tIdx < timeStepCount(scalarResultIndex); tIdx++)
|
|
|
|
{
|
|
|
|
std::vector<double>& values = m_cellScalarResults[scalarResultIndex][tIdx];
|
|
|
|
for (size_t cIdx = 0; cIdx < values.size(); ++cIdx)
|
|
|
|
{
|
|
|
|
valueSum += values[cIdx];
|
|
|
|
}
|
|
|
|
count += values.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_meanValues[scalarResultIndex] = valueSum/count;
|
|
|
|
meanValue = m_meanValues[scalarResultIndex];
|
|
|
|
}
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
size_t RigReservoirCellResults::resultCount() const
|
|
|
|
{
|
|
|
|
return m_cellScalarResults.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
size_t RigReservoirCellResults::timeStepCount(size_t scalarResultIndex) const
|
|
|
|
{
|
|
|
|
CVF_TIGHT_ASSERT(scalarResultIndex < resultCount());
|
|
|
|
|
|
|
|
return m_cellScalarResults[scalarResultIndex].size();
|
|
|
|
}
|
|
|
|
|
2013-02-13 06:10:54 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
const std::vector< std::vector<double> > & RigReservoirCellResults::cellScalarResults( size_t scalarResultIndex ) const
|
|
|
|
{
|
|
|
|
CVF_TIGHT_ASSERT(scalarResultIndex < resultCount());
|
|
|
|
|
|
|
|
return m_cellScalarResults[scalarResultIndex];
|
|
|
|
}
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector< std::vector<double> > & RigReservoirCellResults::cellScalarResults( size_t scalarResultIndex )
|
|
|
|
{
|
|
|
|
CVF_TIGHT_ASSERT(scalarResultIndex < resultCount());
|
|
|
|
|
|
|
|
return m_cellScalarResults[scalarResultIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-01 09:00:34 -06:00
|
|
|
double RigReservoirCellResults::cellScalarResult( size_t scalarResultIndex, size_t timeStepIndex, size_t resultValueIndex)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2012-08-31 12:12:47 -05:00
|
|
|
if (scalarResultIndex < resultCount() &&
|
|
|
|
timeStepIndex < m_cellScalarResults[scalarResultIndex].size() &&
|
|
|
|
resultValueIndex != cvf::UNDEFINED_SIZE_T &&
|
|
|
|
resultValueIndex < m_cellScalarResults[scalarResultIndex][timeStepIndex].size())
|
|
|
|
{
|
|
|
|
return m_cellScalarResults[scalarResultIndex][timeStepIndex][resultValueIndex];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return HUGE_VAL;
|
|
|
|
}
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2012-06-26 09:10:41 -05:00
|
|
|
size_t RigReservoirCellResults::findOrLoadScalarResult(RimDefines::ResultCatType type, const QString& resultName)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
size_t resultGridIndex = cvf::UNDEFINED_SIZE_T;
|
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
resultGridIndex = findScalarResultIndex(type, resultName);
|
|
|
|
|
|
|
|
if (resultGridIndex == cvf::UNDEFINED_SIZE_T) return cvf::UNDEFINED_SIZE_T;
|
|
|
|
|
|
|
|
if (cellScalarResults(resultGridIndex).size()) return resultGridIndex;
|
|
|
|
|
2012-08-31 12:12:47 -05:00
|
|
|
if (type == RimDefines::GENERATED)
|
|
|
|
{
|
|
|
|
return cvf::UNDEFINED_SIZE_T;
|
|
|
|
}
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
if (m_readerInterface.notNull())
|
|
|
|
{
|
|
|
|
// Add one more result to result container
|
2012-06-26 09:10:41 -05:00
|
|
|
size_t timeStepCount = m_resultInfos[resultGridIndex].m_timeStepDates.size();
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
bool resultLoadingSucess = true;
|
|
|
|
|
|
|
|
if (type == RimDefines::DYNAMIC_NATIVE && timeStepCount > 0)
|
|
|
|
{
|
2012-06-26 09:10:41 -05:00
|
|
|
m_cellScalarResults[resultGridIndex].resize(timeStepCount);
|
|
|
|
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < timeStepCount; i++)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2012-06-26 09:10:41 -05:00
|
|
|
std::vector<double>& values = m_cellScalarResults[resultGridIndex][i];
|
2013-01-30 07:13:50 -06:00
|
|
|
if (!m_readerInterface->dynamicResult(resultName, RifReaderInterface::MATRIX_RESULTS, i, &values))
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2012-06-26 09:10:41 -05:00
|
|
|
resultLoadingSucess = false;
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == RimDefines::STATIC_NATIVE)
|
|
|
|
{
|
2012-06-26 09:10:41 -05:00
|
|
|
m_cellScalarResults[resultGridIndex].resize(1);
|
|
|
|
|
|
|
|
std::vector<double>& values = m_cellScalarResults[resultGridIndex][0];
|
2013-01-30 07:13:50 -06:00
|
|
|
if (!m_readerInterface->staticResult(resultName, RifReaderInterface::MATRIX_RESULTS, &values))
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
resultLoadingSucess = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
if (!resultLoadingSucess)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
// Remove last scalar result because loading of result failed
|
2012-06-26 09:10:41 -05:00
|
|
|
m_cellScalarResults[resultGridIndex].clear();
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultGridIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RigReservoirCellResults::setReaderInterface(RifReaderInterface* readerInterface)
|
|
|
|
{
|
|
|
|
m_readerInterface = readerInterface;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2012-06-26 09:10:41 -05:00
|
|
|
size_t RigReservoirCellResults::findScalarResultIndex(RimDefines::ResultCatType type, const QString& resultName) const
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2012-06-26 09:10:41 -05:00
|
|
|
std::vector<ResultInfo>::const_iterator it;
|
|
|
|
for (it = m_resultInfos.begin(); it != m_resultInfos.end(); it++)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
if (it->m_resultType == type && it->m_resultName == resultName)
|
|
|
|
{
|
|
|
|
return it->m_gridScalarResultIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cvf::UNDEFINED_SIZE_T;
|
|
|
|
}
|
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
size_t RigReservoirCellResults::findScalarResultIndex(const QString& resultName) const
|
|
|
|
{
|
|
|
|
size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T;
|
|
|
|
|
|
|
|
scalarResultIndex = this->findScalarResultIndex(RimDefines::STATIC_NATIVE, resultName);
|
|
|
|
|
|
|
|
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
scalarResultIndex = this->findScalarResultIndex(RimDefines::DYNAMIC_NATIVE, resultName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
scalarResultIndex = this->findScalarResultIndex(RimDefines::GENERATED, resultName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
scalarResultIndex = this->findScalarResultIndex(RimDefines::INPUT_PROPERTY, resultName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return scalarResultIndex;
|
|
|
|
}
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RigReservoirCellResults::loadOrComputeSOIL()
|
|
|
|
{
|
2012-10-12 07:27:43 -05:00
|
|
|
size_t soilResultGridIndex = findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL");
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2012-10-12 07:27:43 -05:00
|
|
|
if (soilResultGridIndex == cvf::UNDEFINED_SIZE_T)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2013-01-15 08:40:09 -06:00
|
|
|
size_t scalarIndexSWAT = findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SWAT");
|
|
|
|
size_t scalarIndexSGAS = findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SGAS");
|
|
|
|
|
|
|
|
// Early exit if none of SWAT or SGAS is present
|
|
|
|
if (scalarIndexSWAT == cvf::UNDEFINED_SIZE_T && scalarIndexSGAS == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
soilResultGridIndex = addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL");
|
|
|
|
|
2012-10-12 07:27:43 -05:00
|
|
|
const std::vector< std::vector<double> >* swat = NULL;
|
|
|
|
const std::vector< std::vector<double> >* sgas = NULL;
|
|
|
|
if (scalarIndexSWAT != cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
swat = &(cellScalarResults(scalarIndexSWAT));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scalarIndexSGAS != cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
sgas = &(cellScalarResults(scalarIndexSGAS));
|
|
|
|
}
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2012-10-12 07:27:43 -05:00
|
|
|
size_t soilResultValueCount = 0;
|
|
|
|
size_t soilTimeStepCount = 0;
|
|
|
|
if (swat)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2012-10-12 07:27:43 -05:00
|
|
|
soilResultValueCount = swat->at(0).size();
|
|
|
|
soilTimeStepCount = m_resultInfos[scalarIndexSWAT].m_timeStepDates.size();
|
|
|
|
}
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2012-10-12 07:27:43 -05:00
|
|
|
if (sgas)
|
|
|
|
{
|
|
|
|
soilResultValueCount = qMax(soilResultValueCount, sgas->at(0).size());
|
|
|
|
|
|
|
|
size_t sgasTimeStepCount = m_resultInfos[scalarIndexSGAS].m_timeStepDates.size();
|
|
|
|
soilTimeStepCount = qMax(soilTimeStepCount, sgasTimeStepCount);
|
|
|
|
}
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2012-10-12 07:27:43 -05:00
|
|
|
m_cellScalarResults[soilResultGridIndex].resize(soilTimeStepCount);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2012-10-12 07:27:43 -05:00
|
|
|
std::vector< std::vector<double> >& soil = cellScalarResults(soilResultGridIndex);
|
|
|
|
|
|
|
|
int timeStepIdx = 0;
|
|
|
|
for (timeStepIdx = 0; timeStepIdx < static_cast<int>(soilTimeStepCount); timeStepIdx++)
|
|
|
|
{
|
|
|
|
soil[timeStepIdx].resize(soilResultValueCount);
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
#pragma omp parallel for
|
2013-01-15 08:40:09 -06:00
|
|
|
for (int idx = 0; idx < static_cast<int>(soilResultValueCount); idx++)
|
2012-10-12 07:27:43 -05:00
|
|
|
{
|
|
|
|
double soilValue = 1.0;
|
|
|
|
if (sgas)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2012-10-12 07:27:43 -05:00
|
|
|
soilValue -= sgas->at(timeStepIdx)[idx];
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
2012-10-12 07:27:43 -05:00
|
|
|
|
|
|
|
if (swat)
|
|
|
|
{
|
|
|
|
soilValue -= swat->at(timeStepIdx)[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
soil[timeStepIdx][idx] = soilValue;
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-24 03:52:44 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RigReservoirCellResults::computeDepthRelatedResults()
|
|
|
|
{
|
|
|
|
size_t depthResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DEPTH");
|
|
|
|
size_t dxResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DX");
|
|
|
|
size_t dyResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DY");
|
|
|
|
size_t dzResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DZ");
|
2012-10-24 06:05:42 -05:00
|
|
|
size_t topsResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "TOPS");
|
2012-10-24 03:52:44 -05:00
|
|
|
size_t bottomResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "BOTTOM");
|
|
|
|
|
|
|
|
bool computeDepth = false;
|
|
|
|
bool computeDx = false;
|
|
|
|
bool computeDy = false;
|
|
|
|
bool computeDz = false;
|
2012-10-24 06:05:42 -05:00
|
|
|
bool computeTops = false;
|
2012-10-24 03:52:44 -05:00
|
|
|
bool computeBottom = false;
|
|
|
|
|
|
|
|
size_t resultValueCount = m_ownerMainGrid->cells().size();
|
|
|
|
|
|
|
|
if (depthResultGridIndex == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
depthResultGridIndex = addStaticScalarResult(RimDefines::STATIC_NATIVE, "DEPTH", resultValueCount);
|
|
|
|
computeDepth = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dxResultGridIndex == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
dxResultGridIndex = addStaticScalarResult(RimDefines::STATIC_NATIVE, "DX", resultValueCount);
|
|
|
|
computeDx = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dyResultGridIndex == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
dyResultGridIndex = addStaticScalarResult(RimDefines::STATIC_NATIVE, "DY", resultValueCount);
|
|
|
|
computeDy = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dzResultGridIndex == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
dzResultGridIndex = addStaticScalarResult(RimDefines::STATIC_NATIVE, "DZ", resultValueCount);
|
|
|
|
computeDz = true;
|
|
|
|
}
|
|
|
|
|
2012-10-24 06:05:42 -05:00
|
|
|
if (topsResultGridIndex == cvf::UNDEFINED_SIZE_T)
|
2012-10-24 03:52:44 -05:00
|
|
|
{
|
2012-10-24 06:05:42 -05:00
|
|
|
topsResultGridIndex = addStaticScalarResult(RimDefines::STATIC_NATIVE, "TOPS", resultValueCount);
|
|
|
|
computeTops = true;
|
2012-10-24 03:52:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bottomResultGridIndex == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
bottomResultGridIndex = addStaticScalarResult(RimDefines::STATIC_NATIVE, "BOTTOM", resultValueCount);
|
|
|
|
computeBottom = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< std::vector<double> >& depth = cellScalarResults(depthResultGridIndex);
|
|
|
|
std::vector< std::vector<double> >& dx = cellScalarResults(dxResultGridIndex);
|
|
|
|
std::vector< std::vector<double> >& dy = cellScalarResults(dyResultGridIndex);
|
|
|
|
std::vector< std::vector<double> >& dz = cellScalarResults(dzResultGridIndex);
|
2012-10-24 06:05:42 -05:00
|
|
|
std::vector< std::vector<double> >& tops = cellScalarResults(topsResultGridIndex);
|
2012-10-24 03:52:44 -05:00
|
|
|
std::vector< std::vector<double> >& bottom = cellScalarResults(bottomResultGridIndex);
|
|
|
|
|
|
|
|
size_t cellIdx = 0;
|
|
|
|
for (cellIdx = 0; cellIdx < m_ownerMainGrid->cells().size(); cellIdx++)
|
|
|
|
{
|
|
|
|
const RigCell& cell = m_ownerMainGrid->cells()[cellIdx];
|
|
|
|
|
|
|
|
if (computeDepth)
|
|
|
|
{
|
|
|
|
depth[0][cellIdx] = cvf::Math::abs(cell.center().z());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (computeDx)
|
|
|
|
{
|
|
|
|
cvf::Vec3d cellWidth = cell.faceCenter(cvf::StructGridInterface::NEG_I) - cell.faceCenter(cvf::StructGridInterface::POS_I);
|
2013-01-24 03:41:09 -06:00
|
|
|
dx[0][cellIdx] = cvf::Math::abs(cellWidth.x());
|
2012-10-24 03:52:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (computeDy)
|
|
|
|
{
|
|
|
|
cvf::Vec3d cellWidth = cell.faceCenter(cvf::StructGridInterface::NEG_J) - cell.faceCenter(cvf::StructGridInterface::POS_J);
|
2013-01-24 03:41:09 -06:00
|
|
|
dy[0][cellIdx] = cvf::Math::abs(cellWidth.y());
|
2012-10-24 03:52:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (computeDz)
|
|
|
|
{
|
|
|
|
cvf::Vec3d cellWidth = cell.faceCenter(cvf::StructGridInterface::NEG_K) - cell.faceCenter(cvf::StructGridInterface::POS_K);
|
2013-01-24 03:41:09 -06:00
|
|
|
dz[0][cellIdx] = cvf::Math::abs(cellWidth.z());
|
2012-10-24 03:52:44 -05:00
|
|
|
}
|
|
|
|
|
2012-10-24 06:05:42 -05:00
|
|
|
if (computeTops)
|
2012-10-24 03:52:44 -05:00
|
|
|
{
|
2012-10-24 06:05:42 -05:00
|
|
|
tops[0][cellIdx] = cvf::Math::abs(cell.faceCenter(cvf::StructGridInterface::NEG_K).z());
|
2012-10-24 03:52:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (computeBottom)
|
|
|
|
{
|
2012-10-24 06:05:42 -05:00
|
|
|
bottom[0][cellIdx] = cvf::Math::abs(cell.faceCenter(cvf::StructGridInterface::POS_K).z());
|
2012-10-24 03:52:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
size_t RigReservoirCellResults::findOrLoadScalarResult(const QString& resultName)
|
|
|
|
{
|
|
|
|
size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T;
|
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
scalarResultIndex = this->findOrLoadScalarResult(RimDefines::STATIC_NATIVE, resultName);
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
2012-06-26 09:10:41 -05:00
|
|
|
scalarResultIndex = this->findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, resultName);
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
2012-06-26 09:10:41 -05:00
|
|
|
scalarResultIndex = this->findScalarResultIndex(RimDefines::GENERATED, resultName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
scalarResultIndex = this->findScalarResultIndex(RimDefines::INPUT_PROPERTY, resultName);
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return scalarResultIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Adds an empty scalar set, and returns the scalarResultIndex to it.
|
|
|
|
/// if resultName already exists, it returns the scalarResultIndex to the existing result.
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
size_t RigReservoirCellResults::addEmptyScalarResult(RimDefines::ResultCatType type, const QString& resultName)
|
|
|
|
{
|
|
|
|
size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T;
|
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
scalarResultIndex = this->findScalarResultIndex(type, resultName);
|
2012-05-18 02:45:23 -05:00
|
|
|
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
scalarResultIndex = this->resultCount();
|
|
|
|
m_cellScalarResults.push_back(std::vector<std::vector<double> >());
|
2012-06-26 09:10:41 -05:00
|
|
|
ResultInfo resInfo(type, resultName, scalarResultIndex);
|
|
|
|
m_resultInfos.push_back(resInfo);
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return scalarResultIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2012-06-26 09:10:41 -05:00
|
|
|
QStringList RigReservoirCellResults::resultNames(RimDefines::ResultCatType resType) const
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
QStringList varList;
|
2012-06-26 09:10:41 -05:00
|
|
|
std::vector<ResultInfo>::const_iterator it;
|
|
|
|
for (it = m_resultInfos.begin(); it != m_resultInfos.end(); it++)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
if (it->m_resultType == resType )
|
|
|
|
{
|
|
|
|
varList.push_back(it->m_resultName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return varList;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RigReservoirCellResults::recalculateMinMax(size_t scalarResultIndex)
|
|
|
|
{
|
|
|
|
// Make sure cached max min values are recalculated next time asked for, since
|
|
|
|
// the data could be changed.
|
|
|
|
|
|
|
|
if (scalarResultIndex < m_maxMinValues.size())
|
|
|
|
{
|
|
|
|
m_maxMinValues[scalarResultIndex] = std::make_pair(HUGE_VAL, -HUGE_VAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scalarResultIndex < m_maxMinValuesPrTs.size())
|
|
|
|
{
|
|
|
|
m_maxMinValuesPrTs[scalarResultIndex].clear();
|
|
|
|
}
|
|
|
|
}
|
2012-06-26 09:10:41 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Returns whether the result data in question is addressed by Active Cell Index
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RigReservoirCellResults::isUsingGlobalActiveIndex(size_t scalarResultIndex) const
|
|
|
|
{
|
|
|
|
CVF_TIGHT_ASSERT(scalarResultIndex < m_cellScalarResults.size());
|
|
|
|
|
|
|
|
if (!m_cellScalarResults[scalarResultIndex].size()) return true;
|
2013-02-06 03:02:50 -06:00
|
|
|
|
|
|
|
size_t firstTimeStepResultValueCount = m_cellScalarResults[scalarResultIndex][0].size();
|
|
|
|
if (firstTimeStepResultValueCount == m_ownerMainGrid->cells().size()) return false;
|
2012-06-26 09:10:41 -05:00
|
|
|
|
2013-02-12 04:50:23 -06:00
|
|
|
return true;
|
2012-06-26 09:10:41 -05:00
|
|
|
}
|
|
|
|
|
2012-09-11 02:22:36 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QDateTime RigReservoirCellResults::timeStepDate(size_t scalarResultIndex, size_t timeStepIndex) const
|
|
|
|
{
|
|
|
|
if (scalarResultIndex < m_resultInfos.size() && (size_t)(m_resultInfos[scalarResultIndex].m_timeStepDates.size()) > timeStepIndex)
|
2013-01-22 04:34:47 -06:00
|
|
|
return m_resultInfos[scalarResultIndex].m_timeStepDates[static_cast<int>(timeStepIndex)];
|
2012-09-11 02:22:36 -05:00
|
|
|
else
|
|
|
|
return QDateTime();
|
|
|
|
}
|
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QList<QDateTime> RigReservoirCellResults::timeStepDates(size_t scalarResultIndex) const
|
|
|
|
{
|
|
|
|
if (scalarResultIndex < m_resultInfos.size() )
|
|
|
|
return m_resultInfos[scalarResultIndex].m_timeStepDates;
|
|
|
|
else
|
|
|
|
return QList<QDateTime>();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RigReservoirCellResults::setTimeStepDates(size_t scalarResultIndex, const QList<QDateTime>& dates)
|
|
|
|
{
|
|
|
|
CVF_ASSERT(scalarResultIndex < m_resultInfos.size() );
|
|
|
|
|
|
|
|
m_resultInfos[scalarResultIndex].m_timeStepDates = dates;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
size_t RigReservoirCellResults::maxTimeStepCount() const
|
|
|
|
{
|
|
|
|
size_t maxTsCount = 0;
|
|
|
|
for (size_t i = 0; i < m_cellScalarResults.size(); ++i)
|
|
|
|
{
|
|
|
|
maxTsCount = m_cellScalarResults[i].size() > maxTsCount ? m_cellScalarResults[i].size() : maxTsCount;
|
|
|
|
}
|
|
|
|
return maxTsCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RigReservoirCellResults::makeResultNameUnique(const QString& resultNameProposal) const
|
|
|
|
{
|
|
|
|
QString newResultName = resultNameProposal;
|
|
|
|
size_t resultIndex = cvf::UNDEFINED_SIZE_T;
|
|
|
|
int nameNum = 1;
|
|
|
|
int stringLength = newResultName.size();
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
resultIndex = this->findScalarResultIndex(newResultName);
|
|
|
|
if (resultIndex == cvf::UNDEFINED_SIZE_T) break;
|
|
|
|
|
|
|
|
newResultName.truncate(stringLength);
|
|
|
|
newResultName += "_" + QString::number(nameNum);
|
|
|
|
++nameNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newResultName;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RigReservoirCellResults::removeResult(const QString& resultName)
|
|
|
|
{
|
|
|
|
size_t resultIdx = findScalarResultIndex(resultName);
|
|
|
|
if (resultIdx == cvf::UNDEFINED_SIZE_T) return;
|
|
|
|
|
|
|
|
m_cellScalarResults[resultIdx].clear();
|
|
|
|
|
|
|
|
m_resultInfos[resultIdx].m_resultType = RimDefines::REMOVED;
|
|
|
|
}
|
2012-08-31 12:12:47 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RigReservoirCellResults::clearAllResults()
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < m_cellScalarResults.size(); i++)
|
|
|
|
{
|
|
|
|
m_cellScalarResults[i].clear();
|
|
|
|
}
|
|
|
|
}
|
2012-10-24 03:52:44 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Add a result with given type and name, and allocate one result vector for the static result values
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
size_t RigReservoirCellResults::addStaticScalarResult(RimDefines::ResultCatType type, const QString& resultName, size_t resultValueCount)
|
|
|
|
{
|
|
|
|
size_t resultIdx = addEmptyScalarResult(type, resultName);
|
|
|
|
|
|
|
|
m_cellScalarResults[resultIdx].push_back(std::vector<double>());
|
|
|
|
m_cellScalarResults[resultIdx][0].resize(resultValueCount, HUGE_VAL);
|
|
|
|
|
|
|
|
return resultIdx;
|
|
|
|
}
|
|
|
|
|
2013-02-01 07:39:32 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RifReaderInterface::PorosityModelResultType RigReservoirCellResults::convertFromProjectModelPorosityModel(RimDefines::PorosityModelType porosityModel)
|
|
|
|
{
|
|
|
|
if (porosityModel == RimDefines::MATRIX_MODEL) return RifReaderInterface::MATRIX_RESULTS;
|
|
|
|
|
|
|
|
return RifReaderInterface::FRACTURE_RESULTS;
|
|
|
|
}
|
|
|
|
|