mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Move RigCurveDataTools and RigTimeHistoryCurveMerger to Application/Tools plus rename
This commit is contained in:
@@ -24,6 +24,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaTextFileCompare.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaRegressionTestRunner.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaExtractionTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFilePathTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaTimeHistoryCurveMerger.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCurveDataTools.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -51,6 +53,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaTextFileCompare.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaRegressionTestRunner.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaExtractionTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFilePathTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaTimeHistoryCurveMerger.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaCurveDataTools.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
||||
107
ApplicationCode/Application/Tools/RiaCurveDataTools.cpp
Normal file
107
ApplicationCode/Application/Tools/RiaCurveDataTools.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RiaCurveDataTools.h"
|
||||
|
||||
|
||||
#include <cmath> // Needed for HUGE_VAL on Linux
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaCurveDataTools::CurveIntervals RiaCurveDataTools::calculateIntervalsOfValidValues(const std::vector<double>& values,
|
||||
bool includePositiveValuesOnly)
|
||||
{
|
||||
CurveIntervals intervals;
|
||||
|
||||
int startIdx = -1;
|
||||
size_t vIdx = 0;
|
||||
|
||||
size_t valueCount = values.size();
|
||||
while (vIdx < valueCount)
|
||||
{
|
||||
bool isValid = RiaCurveDataTools::isValidValue(values[vIdx], includePositiveValuesOnly);
|
||||
|
||||
if (!isValid)
|
||||
{
|
||||
if (startIdx >= 0)
|
||||
{
|
||||
intervals.push_back(std::make_pair(startIdx, vIdx - 1));
|
||||
startIdx = -1;
|
||||
}
|
||||
}
|
||||
else if (startIdx < 0)
|
||||
{
|
||||
startIdx = (int)vIdx;
|
||||
}
|
||||
|
||||
vIdx++;
|
||||
}
|
||||
|
||||
if (startIdx >= 0 && startIdx < ((int)valueCount))
|
||||
{
|
||||
intervals.push_back(std::make_pair(startIdx, valueCount - 1));
|
||||
}
|
||||
|
||||
return intervals;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<std::pair<size_t, size_t>> RiaCurveDataTools::computePolyLineStartStopIndices(const CurveIntervals& intervals)
|
||||
{
|
||||
std::vector<std::pair<size_t, size_t>> lineStartAndStopIndices;
|
||||
|
||||
const size_t intervalCount = intervals.size();
|
||||
if (intervalCount < 1) return lineStartAndStopIndices;
|
||||
|
||||
size_t index = 0;
|
||||
for (size_t intIdx = 0; intIdx < intervalCount; intIdx++)
|
||||
{
|
||||
size_t intervalSize = intervals[intIdx].second - intervals[intIdx].first + 1;
|
||||
lineStartAndStopIndices.push_back(std::make_pair(index, index + intervalSize - 1));
|
||||
|
||||
index += intervalSize;
|
||||
}
|
||||
|
||||
return lineStartAndStopIndices;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaCurveDataTools::isValidValue(double value, bool allowPositiveValuesOnly)
|
||||
{
|
||||
if (value == HUGE_VAL || value == -HUGE_VAL || value != value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (allowPositiveValuesOnly && value <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
65
ApplicationCode/Application/Tools/RiaCurveDataTools.h
Normal file
65
ApplicationCode/Application/Tools/RiaCurveDataTools.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <set>
|
||||
|
||||
class QDateTime;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RiaCurveDataTools
|
||||
{
|
||||
public:
|
||||
typedef std::vector<std::pair<size_t, size_t>> CurveIntervals;
|
||||
|
||||
public:
|
||||
static CurveIntervals calculateIntervalsOfValidValues(const std::vector<double>& values,
|
||||
bool includePositiveValuesOnly);
|
||||
|
||||
template <typename T>
|
||||
static void getValuesByIntervals(const std::vector<T>& values,
|
||||
const CurveIntervals& intervals,
|
||||
std::vector<T>* filteredValues)
|
||||
{
|
||||
CVF_ASSERT(filteredValues);
|
||||
|
||||
for (size_t intIdx = 0; intIdx < intervals.size(); intIdx++)
|
||||
{
|
||||
for (size_t vIdx = intervals[intIdx].first; vIdx <= intervals[intIdx].second; vIdx++)
|
||||
{
|
||||
filteredValues->push_back(values[vIdx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static std::vector<std::pair<size_t, size_t>> computePolyLineStartStopIndices(const CurveIntervals& intervals);
|
||||
|
||||
public:
|
||||
static bool isValidValue(double value, bool allowPositiveValuesOnly);
|
||||
};
|
||||
|
||||
223
ApplicationCode/Application/Tools/RiaTimeHistoryCurveMerger.cpp
Normal file
223
ApplicationCode/Application/Tools/RiaTimeHistoryCurveMerger.cpp
Normal file
@@ -0,0 +1,223 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RiaTimeHistoryCurveMerger.h"
|
||||
|
||||
|
||||
#include <cmath> // Needed for HUGE_VAL on Linux
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaTimeHistoryCurveMerger::RiaTimeHistoryCurveMerger()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaTimeHistoryCurveMerger::addCurveData(const std::vector<double>& values, const std::vector<time_t>& timeSteps)
|
||||
{
|
||||
CVF_ASSERT(values.size() == timeSteps.size());
|
||||
|
||||
m_originalValues.push_back(std::make_pair(values, timeSteps));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaCurveDataTools::CurveIntervals RiaTimeHistoryCurveMerger::validIntervalsForAllTimeSteps() const
|
||||
{
|
||||
return m_validIntervalsForAllTimeSteps;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<time_t>& RiaTimeHistoryCurveMerger::allTimeSteps() const
|
||||
{
|
||||
return m_allTimeSteps;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<double>& RiaTimeHistoryCurveMerger::interpolatedCurveValuesForAllTimeSteps(size_t curveIdx) const
|
||||
{
|
||||
CVF_ASSERT(curveIdx < m_interpolatedValuesForAllCurves.size());
|
||||
|
||||
return m_interpolatedValuesForAllCurves[curveIdx];
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<double>& RiaTimeHistoryCurveMerger::interpolatedCurveValuesForAllTimeSteps(size_t curveIdx)
|
||||
{
|
||||
CVF_ASSERT(curveIdx < m_interpolatedValuesForAllCurves.size());
|
||||
|
||||
return m_interpolatedValuesForAllCurves[curveIdx];
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaTimeHistoryCurveMerger::interploatedCurveCount() const
|
||||
{
|
||||
return static_cast<int>(m_interpolatedValuesForAllCurves.size());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaTimeHistoryCurveMerger::computeInterpolatedValues()
|
||||
{
|
||||
m_validIntervalsForAllTimeSteps.clear();
|
||||
m_allTimeSteps.clear();
|
||||
m_interpolatedValuesForAllCurves.clear();
|
||||
|
||||
computeUnionOfTimeSteps();
|
||||
|
||||
const size_t curveCount = m_originalValues.size();
|
||||
if (curveCount == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t dataValueCount = m_allTimeSteps.size();
|
||||
if (dataValueCount == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_interpolatedValuesForAllCurves.resize(curveCount);
|
||||
|
||||
std::vector<double> accumulatedValidValues(dataValueCount, 1.0);
|
||||
|
||||
for (size_t curveIdx = 0; curveIdx < curveCount; curveIdx++)
|
||||
{
|
||||
std::vector<double>& curveValues = m_interpolatedValuesForAllCurves[curveIdx];
|
||||
curveValues.resize(dataValueCount);
|
||||
|
||||
for (size_t valueIndex = 0; valueIndex < dataValueCount; valueIndex++)
|
||||
{
|
||||
double interpolValue = interpolationValue(m_allTimeSteps[valueIndex], m_originalValues[curveIdx].first, m_originalValues[curveIdx].second);
|
||||
if (!RiaCurveDataTools::isValidValue(interpolValue, false))
|
||||
{
|
||||
accumulatedValidValues[valueIndex] = HUGE_VAL;
|
||||
}
|
||||
|
||||
curveValues[valueIndex] = interpolValue;
|
||||
}
|
||||
}
|
||||
|
||||
m_validIntervalsForAllTimeSteps = RiaCurveDataTools::calculateIntervalsOfValidValues(accumulatedValidValues, false);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaTimeHistoryCurveMerger::computeUnionOfTimeSteps()
|
||||
{
|
||||
m_allTimeSteps.clear();
|
||||
|
||||
std::set<time_t> unionOfTimeSteps;
|
||||
|
||||
for (const auto& curveData : m_originalValues)
|
||||
{
|
||||
for (const auto& dt : curveData.second)
|
||||
{
|
||||
unionOfTimeSteps.insert(dt);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& dt : unionOfTimeSteps)
|
||||
{
|
||||
m_allTimeSteps.push_back(dt);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaTimeHistoryCurveMerger::interpolationValue(const time_t& interpolationTimeStep,
|
||||
const std::vector<double>& curveValues,
|
||||
const std::vector<time_t>& curveTimeSteps)
|
||||
{
|
||||
if (curveValues.size() != curveTimeSteps.size()) return HUGE_VAL;
|
||||
|
||||
const bool removeInterpolatedValues = false;
|
||||
|
||||
for (size_t firstI = 0; firstI < curveTimeSteps.size(); firstI++)
|
||||
{
|
||||
if (curveTimeSteps.at(firstI) == interpolationTimeStep)
|
||||
{
|
||||
const double& firstValue = curveValues.at(firstI);
|
||||
if (!RiaCurveDataTools::isValidValue(firstValue, removeInterpolatedValues))
|
||||
{
|
||||
return HUGE_VAL;
|
||||
}
|
||||
|
||||
return firstValue;
|
||||
}
|
||||
|
||||
size_t secondI = firstI + 1;
|
||||
|
||||
if (secondI < curveTimeSteps.size() &&
|
||||
curveTimeSteps.at(firstI) <= interpolationTimeStep &&
|
||||
curveTimeSteps.at(secondI) > interpolationTimeStep)
|
||||
{
|
||||
if (curveTimeSteps.at(secondI) == interpolationTimeStep)
|
||||
{
|
||||
const double& secondValue = curveValues.at(secondI);
|
||||
if (!RiaCurveDataTools::isValidValue(secondValue, removeInterpolatedValues))
|
||||
{
|
||||
return HUGE_VAL;
|
||||
}
|
||||
|
||||
return secondValue;
|
||||
}
|
||||
|
||||
const double& firstValue = curveValues.at(firstI);
|
||||
const double& secondValue = curveValues.at(secondI);
|
||||
|
||||
bool isFirstValid = RiaCurveDataTools::isValidValue(firstValue, removeInterpolatedValues);
|
||||
if (!isFirstValid) return HUGE_VAL;
|
||||
|
||||
bool isSecondValid = RiaCurveDataTools::isValidValue(secondValue, removeInterpolatedValues);
|
||||
if (!isSecondValid) return HUGE_VAL;
|
||||
|
||||
double firstDiff = fabs(difftime(interpolationTimeStep, curveTimeSteps.at(firstI)));
|
||||
double secondDiff = fabs(difftime(curveTimeSteps.at(secondI), interpolationTimeStep));
|
||||
|
||||
double firstWeight = secondDiff / (firstDiff + secondDiff);
|
||||
double secondWeight = firstDiff / (firstDiff + secondDiff);
|
||||
|
||||
double val = (firstValue * firstWeight) + (secondValue * secondWeight);
|
||||
|
||||
CVF_ASSERT(RiaCurveDataTools::isValidValue(val, removeInterpolatedValues));
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
return HUGE_VAL;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RiaCurveDataTools.h"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RiaTimeHistoryCurveMerger
|
||||
{
|
||||
public:
|
||||
RiaTimeHistoryCurveMerger();
|
||||
|
||||
|
||||
void addCurveData(const std::vector<double>& values,
|
||||
const std::vector<time_t>& timeSteps);
|
||||
|
||||
void computeInterpolatedValues();
|
||||
|
||||
RiaCurveDataTools::CurveIntervals validIntervalsForAllTimeSteps() const;
|
||||
const std::vector<time_t>& allTimeSteps() const;
|
||||
const std::vector<double>& interpolatedCurveValuesForAllTimeSteps(size_t curveIdx) const;
|
||||
int interploatedCurveCount() const;
|
||||
|
||||
// Non-const access is not required by any clients, but the expression parser has no available const interface
|
||||
// for specifying a data source for an expression variable. Allow non-const access to avoid copy of the contained
|
||||
// values, interpolated for all time steps
|
||||
//
|
||||
// See ExpressionParserImpl::assignVector()
|
||||
std::vector<double>& interpolatedCurveValuesForAllTimeSteps(size_t curveIdx);
|
||||
|
||||
public:
|
||||
// Helper methods, available as public to be able to access from unit tests
|
||||
|
||||
static double interpolationValue(const time_t& interpolationTimeStep,
|
||||
const std::vector<double>& curveValues,
|
||||
const std::vector<time_t>& curveTimeSteps);
|
||||
|
||||
private:
|
||||
void computeUnionOfTimeSteps();
|
||||
|
||||
private:
|
||||
std::vector<std::pair<std::vector<double>, std::vector<time_t>>> m_originalValues;
|
||||
|
||||
RiaCurveDataTools::CurveIntervals m_validIntervalsForAllTimeSteps;
|
||||
|
||||
std::vector<time_t> m_allTimeSteps;
|
||||
std::vector<std::vector<double>> m_interpolatedValuesForAllCurves;
|
||||
};
|
||||
Reference in New Issue
Block a user