From 85f62ec1d463b8bf670a8b740e09c1159f031212 Mon Sep 17 00:00:00 2001 From: Stein Dale Date: Mon, 11 May 2015 13:25:05 +0200 Subject: [PATCH] Moved code to new library: ResultStatisticsCache Moved RigStatisticsCalculator.h/.cpp, RigStatisticsDataCache.h/.cpp, RigStatisticsMath.h/.cpp to new library ResultStatisticsCache. ResInsight and some unit tests now link with this new library. --- ApplicationCode/CMakeLists.txt | 3 + .../FileInterface_UnitTests/CMakeLists.txt | 5 +- .../ReservoirDataModel/CMakeLists_files.cmake | 6 - .../CMakeLists.txt | 3 + .../RigStatisticsCalculator.cpp | 262 ------------------ .../ResultStatisticsCache/CMakeLists.txt | 18 ++ .../RigStatisticsCalculator.cpp | 44 +++ .../RigStatisticsCalculator.h | 0 .../RigStatisticsDataCache.cpp | 0 .../RigStatisticsDataCache.h | 0 .../RigStatisticsMath.cpp | 0 .../RigStatisticsMath.h | 0 12 files changed, 72 insertions(+), 269 deletions(-) delete mode 100644 ApplicationCode/ReservoirDataModel/RigStatisticsCalculator.cpp create mode 100644 ApplicationCode/ResultStatisticsCache/CMakeLists.txt create mode 100644 ApplicationCode/ResultStatisticsCache/RigStatisticsCalculator.cpp rename ApplicationCode/{ReservoirDataModel => ResultStatisticsCache}/RigStatisticsCalculator.h (100%) rename ApplicationCode/{ReservoirDataModel => ResultStatisticsCache}/RigStatisticsDataCache.cpp (100%) rename ApplicationCode/{ReservoirDataModel => ResultStatisticsCache}/RigStatisticsDataCache.h (100%) rename ApplicationCode/{ReservoirDataModel => ResultStatisticsCache}/RigStatisticsMath.cpp (100%) rename ApplicationCode/{ReservoirDataModel => ResultStatisticsCache}/RigStatisticsMath.h (100%) diff --git a/ApplicationCode/CMakeLists.txt b/ApplicationCode/CMakeLists.txt index 9da6ec2d16..b8aaf651a2 100644 --- a/ApplicationCode/CMakeLists.txt +++ b/ApplicationCode/CMakeLists.txt @@ -18,6 +18,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/ModelVisualization ${CMAKE_CURRENT_SOURCE_DIR}/UserInterface ${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel + ${CMAKE_CURRENT_SOURCE_DIR}/ResultStatisticsCache ${CMAKE_CURRENT_SOURCE_DIR}/ReservoirDataModel ${CMAKE_CURRENT_SOURCE_DIR}/WellPathImportSsihub ${CMAKE_CURRENT_SOURCE_DIR}/GeoMech/OdbReader @@ -100,6 +101,7 @@ list( APPEND CPP_SOURCES ############################################################################# add_subdirectory(WellPathImportSsihub) +add_subdirectory(ResultStatisticsCache) # # Odb api @@ -292,6 +294,7 @@ set( LINK_LIBRARIES LibGeometry LibCore + ResultStatisticsCache RigGeoMechDataModel ecl diff --git a/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt b/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt index 1837990216..c8fe5f4f85 100644 --- a/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt +++ b/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt @@ -10,7 +10,8 @@ include (${QT_USE_FILE}) include_directories( ${ResInsight_SOURCE_DIR}/ApplicationCode - ${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel + ${ResInsight_SOURCE_DIR}/ApplicationCode/ResultStatisticsCache + ${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel ${ResInsight_SOURCE_DIR}/ApplicationCode/FileInterface ${ResInsight_SOURCE_DIR}/ApplicationCode/ProjectDataModel ${ResInsight_SOURCE_DIR}/ThirdParty @@ -63,6 +64,8 @@ set( LINK_LIBRARIES cafProjectDataModel CommonCode + ResultStatisticsCache + LibViewing LibRender LibGeometry diff --git a/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake b/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake index 5de18ee8d4..f1e142c668 100644 --- a/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake +++ b/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake @@ -24,7 +24,6 @@ ${CEE_CURRENT_LIST_DIR}RigMainGrid.h ${CEE_CURRENT_LIST_DIR}RigReservoirBuilderMock.h ${CEE_CURRENT_LIST_DIR}RigCaseCellResultsData.h ${CEE_CURRENT_LIST_DIR}RigSingleWellResultsData.h -${CEE_CURRENT_LIST_DIR}RigStatisticsMath.h ${CEE_CURRENT_LIST_DIR}RigWellPath.h ${CEE_CURRENT_LIST_DIR}RigFault.h ${CEE_CURRENT_LIST_DIR}RigNNCData.h @@ -33,8 +32,6 @@ ${CEE_CURRENT_LIST_DIR}cvfGeometryTools.inl ${CEE_CURRENT_LIST_DIR}RigPipeInCellEvaluator.h ${CEE_CURRENT_LIST_DIR}RigResultAccessor2d.h ${CEE_CURRENT_LIST_DIR}RigTernaryResultAccessor2d.h -${CEE_CURRENT_LIST_DIR}RigStatisticsDataCache.h -${CEE_CURRENT_LIST_DIR}RigStatisticsCalculator.h ${CEE_CURRENT_LIST_DIR}RigNativeStatCalc.h ${CEE_CURRENT_LIST_DIR}RigMultipleDatasetStatCalc.h ) @@ -58,14 +55,11 @@ ${CEE_CURRENT_LIST_DIR}RigMainGrid.cpp ${CEE_CURRENT_LIST_DIR}RigReservoirBuilderMock.cpp ${CEE_CURRENT_LIST_DIR}RigCaseCellResultsData.cpp ${CEE_CURRENT_LIST_DIR}RigSingleWellResultsData.cpp -${CEE_CURRENT_LIST_DIR}RigStatisticsMath.cpp ${CEE_CURRENT_LIST_DIR}RigWellPath.cpp ${CEE_CURRENT_LIST_DIR}RigFault.cpp ${CEE_CURRENT_LIST_DIR}RigNNCData.cpp ${CEE_CURRENT_LIST_DIR}cvfGeometryTools.cpp ${CEE_CURRENT_LIST_DIR}RigTernaryResultAccessor2d.cpp -${CEE_CURRENT_LIST_DIR}RigStatisticsDataCache.cpp -${CEE_CURRENT_LIST_DIR}RigStatisticsCalculator.cpp ${CEE_CURRENT_LIST_DIR}RigNativeStatCalc.cpp ${CEE_CURRENT_LIST_DIR}RigMultipleDatasetStatCalc.cpp ) diff --git a/ApplicationCode/ReservoirDataModel/ReservoirDataModel_UnitTests/CMakeLists.txt b/ApplicationCode/ReservoirDataModel/ReservoirDataModel_UnitTests/CMakeLists.txt index e46aef6985..b066ea1698 100644 --- a/ApplicationCode/ReservoirDataModel/ReservoirDataModel_UnitTests/CMakeLists.txt +++ b/ApplicationCode/ReservoirDataModel/ReservoirDataModel_UnitTests/CMakeLists.txt @@ -14,6 +14,7 @@ include_directories( ${LibViewing_SOURCE_DIR} ${ResInsight_SOURCE_DIR}/ApplicationCode + ${ResInsight_SOURCE_DIR}/ApplicationCode/ResultStatisticsCache ${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel ${ResInsight_SOURCE_DIR}/ApplicationCode/FileInterface ${ResInsight_SOURCE_DIR}/ApplicationCode/ProjectDataModel @@ -53,6 +54,8 @@ source_group( "UnitTests" FILES ${UNIT_TEST_CPP_SOURCES} ) set( LINK_LIBRARIES CommonCode + ResultStatisticsCache + LibViewing LibRender LibGeometry diff --git a/ApplicationCode/ReservoirDataModel/RigStatisticsCalculator.cpp b/ApplicationCode/ReservoirDataModel/RigStatisticsCalculator.cpp deleted file mode 100644 index af56724a2d..0000000000 --- a/ApplicationCode/ReservoirDataModel/RigStatisticsCalculator.cpp +++ /dev/null @@ -1,262 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) Statoil ASA -// Copyright (C) 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 -// for more details. -// -///////////////////////////////////////////////////////////////////////////////// - -#include "RigStatisticsCalculator.h" - -#include "RigStatisticsMath.h" -#include "RigCaseCellResultsData.h" - -#include // Needed for HUGE_VAL on Linux - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigStatisticsCalculator::meanCellScalarValue(double& meanValue) -{ - double valueSum = 0.0; - size_t sampleCount = 0; - - this->valueSumAndSampleCount(valueSum, sampleCount); - - if (sampleCount == 0) - { - meanValue = HUGE_VAL; - } - else - { - meanValue = valueSum / sampleCount; - } -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RigNativeStatCalc::RigNativeStatCalc(RigCaseCellResultsData* cellResultsData, size_t scalarResultIndex) - : m_resultsData(cellResultsData), - m_scalarResultIndex(scalarResultIndex) -{ - -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigNativeStatCalc::minMaxCellScalarValues(size_t timeStepIndex, double& min, double& max) -{ - std::vector& values = m_resultsData->cellScalarResults(m_scalarResultIndex, timeStepIndex); - - size_t i; - for (i = 0; i < values.size(); i++) - { - if (values[i] == HUGE_VAL) - { - continue; - } - - if (values[i] < min) - { - min = values[i]; - } - - if (values[i] > max) - { - max = values[i]; - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigNativeStatCalc::posNegClosestToZero(size_t timeStepIndex, double& pos, double& neg) -{ - std::vector& values = m_resultsData->cellScalarResults(m_scalarResultIndex, timeStepIndex); - - size_t i; - for (i = 0; i < values.size(); i++) - { - if (values[i] == HUGE_VAL) - { - continue; - } - - if (values[i] < pos && values[i] > 0) - { - pos = values[i]; - } - - if (values[i] > neg && values[i] < 0) - { - neg = values[i]; - } - } -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigNativeStatCalc::addDataToHistogramCalculator(RigHistogramCalculator& histogramCalculator) -{ - for (size_t tIdx = 0; tIdx < m_resultsData->timeStepCount(m_scalarResultIndex); tIdx++) - { - std::vector& values = m_resultsData->cellScalarResults(m_scalarResultIndex, tIdx); - - histogramCalculator.addData(values); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigNativeStatCalc::valueSumAndSampleCount(double& valueSum, size_t& sampleCount) -{ - for (size_t tIdx = 0; tIdx < m_resultsData->timeStepCount(m_scalarResultIndex); tIdx++) - { - std::vector& values = m_resultsData->cellScalarResults(m_scalarResultIndex, tIdx); - size_t undefValueCount = 0; - for (size_t cIdx = 0; cIdx < values.size(); ++cIdx) - { - double value = values[cIdx]; - if (value == HUGE_VAL || value != value) - { - ++undefValueCount; - continue; - } - - valueSum += value; - } - - sampleCount += values.size(); - sampleCount -= undefValueCount; - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -size_t RigNativeStatCalc::timeStepCount() -{ - return m_resultsData->timeStepCount(m_scalarResultIndex); -} - - - - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RigMultipleDatasetStatCalc::RigMultipleDatasetStatCalc() -{ -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigMultipleDatasetStatCalc::addStatisticsCalculator(RigStatisticsCalculator* statisticsCalculator) -{ - if (statisticsCalculator) - { - m_nativeStatisticsCalculators.push_back(statisticsCalculator); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigMultipleDatasetStatCalc::minMaxCellScalarValues(size_t timeStepIndex, double& min, double& max) -{ - for (size_t i = 0; i < m_nativeStatisticsCalculators.size(); i++) - { - if (m_nativeStatisticsCalculators.at(i)) - { - m_nativeStatisticsCalculators.at(i)->minMaxCellScalarValues(timeStepIndex, min, max); - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigMultipleDatasetStatCalc::posNegClosestToZero(size_t timeStepIndex, double& pos, double& neg) -{ - for (size_t i = 0; i < m_nativeStatisticsCalculators.size(); i++) - { - if (m_nativeStatisticsCalculators.at(i)) - { - m_nativeStatisticsCalculators.at(i)->posNegClosestToZero(timeStepIndex, pos, neg); - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigMultipleDatasetStatCalc::valueSumAndSampleCount(double& valueSum, size_t& sampleCount) -{ - for (size_t i = 0; i < m_nativeStatisticsCalculators.size(); i++) - { - if (m_nativeStatisticsCalculators.at(i)) - { - m_nativeStatisticsCalculators.at(i)->valueSumAndSampleCount(valueSum, sampleCount); - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigMultipleDatasetStatCalc::addDataToHistogramCalculator(RigHistogramCalculator& histogramCalculator) -{ - for (size_t i = 0; i < m_nativeStatisticsCalculators.size(); i++) - { - if (m_nativeStatisticsCalculators.at(i)) - { - m_nativeStatisticsCalculators.at(i)->addDataToHistogramCalculator(histogramCalculator); - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -size_t RigMultipleDatasetStatCalc::timeStepCount() -{ - if (m_nativeStatisticsCalculators.size() > 0) - { - return m_nativeStatisticsCalculators[0]->timeStepCount(); - } - - return 0; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigMultipleDatasetStatCalc::addNativeStatisticsCalculator(RigCaseCellResultsData* cellResultsData, size_t scalarResultIndex) -{ - if (scalarResultIndex != cvf::UNDEFINED_SIZE_T) - { - this->addStatisticsCalculator(new RigNativeStatCalc(cellResultsData, scalarResultIndex)); - } -} - diff --git a/ApplicationCode/ResultStatisticsCache/CMakeLists.txt b/ApplicationCode/ResultStatisticsCache/CMakeLists.txt new file mode 100644 index 0000000000..4ac1d30def --- /dev/null +++ b/ApplicationCode/ResultStatisticsCache/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required (VERSION 2.8) + +project (ResultStatisticsCache) + +include_directories( + ${LibCore_SOURCE_DIR} +) + +add_library( ${PROJECT_NAME} + RigStatisticsCalculator.h + RigStatisticsCalculator.cpp + RigStatisticsDataCache.h + RigStatisticsDataCache.cpp + RigStatisticsMath.h + RigStatisticsMath.cpp +) + +target_link_libraries(${PROJECT_NAME} LibCore) diff --git a/ApplicationCode/ResultStatisticsCache/RigStatisticsCalculator.cpp b/ApplicationCode/ResultStatisticsCache/RigStatisticsCalculator.cpp new file mode 100644 index 0000000000..6550dc8e68 --- /dev/null +++ b/ApplicationCode/ResultStatisticsCache/RigStatisticsCalculator.cpp @@ -0,0 +1,44 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Statoil ASA +// Copyright (C) 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RigStatisticsCalculator.h" + +#include // Needed for HUGE_VAL on Linux + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigStatisticsCalculator::meanCellScalarValue(double& meanValue) +{ + double valueSum = 0.0; + size_t sampleCount = 0; + + this->valueSumAndSampleCount(valueSum, sampleCount); + + if (sampleCount == 0) + { + meanValue = HUGE_VAL; + } + else + { + meanValue = valueSum / sampleCount; + } +} + diff --git a/ApplicationCode/ReservoirDataModel/RigStatisticsCalculator.h b/ApplicationCode/ResultStatisticsCache/RigStatisticsCalculator.h similarity index 100% rename from ApplicationCode/ReservoirDataModel/RigStatisticsCalculator.h rename to ApplicationCode/ResultStatisticsCache/RigStatisticsCalculator.h diff --git a/ApplicationCode/ReservoirDataModel/RigStatisticsDataCache.cpp b/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp similarity index 100% rename from ApplicationCode/ReservoirDataModel/RigStatisticsDataCache.cpp rename to ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp diff --git a/ApplicationCode/ReservoirDataModel/RigStatisticsDataCache.h b/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.h similarity index 100% rename from ApplicationCode/ReservoirDataModel/RigStatisticsDataCache.h rename to ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.h diff --git a/ApplicationCode/ReservoirDataModel/RigStatisticsMath.cpp b/ApplicationCode/ResultStatisticsCache/RigStatisticsMath.cpp similarity index 100% rename from ApplicationCode/ReservoirDataModel/RigStatisticsMath.cpp rename to ApplicationCode/ResultStatisticsCache/RigStatisticsMath.cpp diff --git a/ApplicationCode/ReservoirDataModel/RigStatisticsMath.h b/ApplicationCode/ResultStatisticsCache/RigStatisticsMath.h similarity index 100% rename from ApplicationCode/ReservoirDataModel/RigStatisticsMath.h rename to ApplicationCode/ResultStatisticsCache/RigStatisticsMath.h