From 1ac50e178e2a622344f272d1fef59dfa639bd92c Mon Sep 17 00:00:00 2001 From: Rebecca Cox Date: Fri, 15 Sep 2017 14:26:06 +0200 Subject: [PATCH] #1813 Observed data: Make summary reader interface and make observed data reader object --- .../FileInterface/CMakeLists_files.cmake | 4 + .../FileInterface/RifReaderEclipseSummary.cpp | 53 ----------- .../FileInterface/RifReaderEclipseSummary.h | 26 ++--- .../FileInterface/RifReaderObservedData.cpp | 94 +++++++++++++++++++ .../FileInterface/RifReaderObservedData.h | 59 ++++++++++++ .../RifSummaryReaderInterface.cpp | 78 +++++++++++++++ .../FileInterface/RifSummaryReaderInterface.h | 63 +++++++++++++ 7 files changed, 306 insertions(+), 71 deletions(-) create mode 100644 ApplicationCode/FileInterface/RifReaderObservedData.cpp create mode 100644 ApplicationCode/FileInterface/RifReaderObservedData.h create mode 100644 ApplicationCode/FileInterface/RifSummaryReaderInterface.cpp create mode 100644 ApplicationCode/FileInterface/RifSummaryReaderInterface.h diff --git a/ApplicationCode/FileInterface/CMakeLists_files.cmake b/ApplicationCode/FileInterface/CMakeLists_files.cmake index a3903e1ae8..9a8398324a 100644 --- a/ApplicationCode/FileInterface/CMakeLists_files.cmake +++ b/ApplicationCode/FileInterface/CMakeLists_files.cmake @@ -15,6 +15,8 @@ ${CEE_CURRENT_LIST_DIR}RifEclipseUnifiedRestartFileAccess.h ${CEE_CURRENT_LIST_DIR}RifPerforationIntervalReader.h ${CEE_CURRENT_LIST_DIR}RifReaderEclipseInput.h ${CEE_CURRENT_LIST_DIR}RifReaderEclipseOutput.h +${CEE_CURRENT_LIST_DIR}RifSummaryReaderInterface.h +${CEE_CURRENT_LIST_DIR}RifReaderObservedData.h ${CEE_CURRENT_LIST_DIR}RifReaderEclipseSummary.h ${CEE_CURRENT_LIST_DIR}RifJsonEncodeDecode.h ${CEE_CURRENT_LIST_DIR}RifReaderInterface.h @@ -45,6 +47,8 @@ ${CEE_CURRENT_LIST_DIR}RifEclipseSummaryTools.cpp ${CEE_CURRENT_LIST_DIR}RifPerforationIntervalReader.cpp ${CEE_CURRENT_LIST_DIR}RifReaderEclipseInput.cpp ${CEE_CURRENT_LIST_DIR}RifReaderEclipseOutput.cpp +${CEE_CURRENT_LIST_DIR}RifSummaryReaderInterface.cpp +${CEE_CURRENT_LIST_DIR}RifReaderObservedData.cpp ${CEE_CURRENT_LIST_DIR}RifReaderEclipseSummary.cpp ${CEE_CURRENT_LIST_DIR}RifJsonEncodeDecode.cpp ${CEE_CURRENT_LIST_DIR}RifReaderInterface.cpp diff --git a/ApplicationCode/FileInterface/RifReaderEclipseSummary.cpp b/ApplicationCode/FileInterface/RifReaderEclipseSummary.cpp index d826d24ba2..004341c7d6 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseSummary.cpp +++ b/ApplicationCode/FileInterface/RifReaderEclipseSummary.cpp @@ -231,16 +231,6 @@ RifEclipseSummaryAddress addressFromErtSmSpecNode(const smspec_node_type * ertSu cellI, cellJ, cellK); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const std::vector& RifReaderEclipseSummary::allResultAddresses() -{ - buildMetaData(); - - return m_allResultAddresses; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -293,38 +283,6 @@ const std::vector& RifReaderEclipseSummary::timeSteps() const return m_timeSteps; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector RifReaderEclipseSummary::fromTimeT(const std::vector& timeSteps) -{ - std::vector a; - - for (size_t i = 0; i < timeSteps.size(); i++) - { - QDateTime dt = QDateTime::fromTime_t(timeSteps[i]); - a.push_back(dt); - } - - return a; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -int RifReaderEclipseSummary::indexFromAddress(const RifEclipseSummaryAddress& resultAddress) -{ - this->buildMetaData(); - - auto it = m_resultAddressToErtNodeIdx.find(resultAddress); - if (it != m_resultAddressToErtNodeIdx.end()) - { - return it->second; - } - - return -1; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -343,17 +301,6 @@ void RifReaderEclipseSummary::buildMetaData() } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RifReaderEclipseSummary::hasAddress(const RifEclipseSummaryAddress& resultAddress) -{ - this->buildMetaData(); - - auto it = m_resultAddressToErtNodeIdx.find(resultAddress); - - return (it != m_resultAddressToErtNodeIdx.end()); -} //-------------------------------------------------------------------------------------------------- /// diff --git a/ApplicationCode/FileInterface/RifReaderEclipseSummary.h b/ApplicationCode/FileInterface/RifReaderEclipseSummary.h index e4170447be..bc9840c07b 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseSummary.h +++ b/ApplicationCode/FileInterface/RifReaderEclipseSummary.h @@ -19,6 +19,7 @@ #pragma once #include "RifEclipseSummaryAddress.h" +#include "RifSummaryReaderInterface.h" #include #include @@ -34,30 +35,23 @@ class QDateTime; // // //================================================================================================== -class RifReaderEclipseSummary : public cvf::Object +class RifReaderEclipseSummary : public RifSummaryReaderInterface { public: RifReaderEclipseSummary(); ~RifReaderEclipseSummary(); - bool open(const std::string& headerFileName, const std::vector& dataFileNames); + virtual bool open(const std::string& headerFileName, const std::vector& dataFileNames) override; - bool hasAddress(const RifEclipseSummaryAddress& resultAddress); - const std::vector& allResultAddresses(); - const std::vector& timeSteps() const; + virtual const std::vector& timeSteps() const override; - bool values(const RifEclipseSummaryAddress& resultAddress, std::vector* values); - std::string unitName(const RifEclipseSummaryAddress& resultAddress); + virtual bool values(const RifEclipseSummaryAddress& resultAddress, std::vector* values) override; + std::string unitName(const RifEclipseSummaryAddress& resultAddress) override; - // TODO: Move this to a tools class with static members - static std::vector fromTimeT(const std::vector& timeSteps); - private: + virtual int timeStepCount() const override; - int timeStepCount() const; - int indexFromAddress(const RifEclipseSummaryAddress& resultAddress); - - void buildMetaData(); + virtual void buildMetaData() override; private: // Taken from ecl_sum.h typedef struct ecl_sum_struct ecl_sum_type; @@ -66,9 +60,5 @@ private: ecl_sum_type* m_ecl_sum; const ecl_smspec_type * m_ecl_SmSpec; std::vector m_timeSteps; - - std::vector m_allResultAddresses; - std::map m_resultAddressToErtNodeIdx; - }; diff --git a/ApplicationCode/FileInterface/RifReaderObservedData.cpp b/ApplicationCode/FileInterface/RifReaderObservedData.cpp new file mode 100644 index 0000000000..f2abfcf6d1 --- /dev/null +++ b/ApplicationCode/FileInterface/RifReaderObservedData.cpp @@ -0,0 +1,94 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RifReaderObservedData.h" + +#include "ert/ecl/ecl_sum.h" + +#include +#include + +#include +#include "ert/ecl/smspec_node.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RifReaderObservedData::RifReaderObservedData() +{ + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RifReaderObservedData::~RifReaderObservedData() +{ + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RifReaderObservedData::open(const std::string& headerFileName, const std::vector& dataFileNames) +{ + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RifReaderObservedData::values(const RifEclipseSummaryAddress& resultAddress, std::vector* values) +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int RifReaderObservedData::timeStepCount() const +{ + return 0; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const std::vector& RifReaderObservedData::timeSteps() const +{ + std::vector steps; + return steps; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RifReaderObservedData::buildMetaData() +{ + +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::string RifReaderObservedData::unitName(const RifEclipseSummaryAddress& resultAddress) +{ + std::string str = ""; + return str; +} diff --git a/ApplicationCode/FileInterface/RifReaderObservedData.h b/ApplicationCode/FileInterface/RifReaderObservedData.h new file mode 100644 index 0000000000..96c56e26be --- /dev/null +++ b/ApplicationCode/FileInterface/RifReaderObservedData.h @@ -0,0 +1,59 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + + +#pragma once + +#include "RifEclipseSummaryAddress.h" +#include "RifSummaryReaderInterface.h" + +#include +#include +#include + +#include "cvfObject.h" + + +class QDateTime; + + +//================================================================================================== +// +// +//================================================================================================== +class RifReaderObservedData : public RifSummaryReaderInterface +{ +public: + RifReaderObservedData(); + ~RifReaderObservedData(); + + virtual bool open(const std::string& headerFileName, const std::vector& dataFileNames) override; + + virtual const std::vector& timeSteps() const override; + + virtual bool values(const RifEclipseSummaryAddress& resultAddress, std::vector* values) override; + std::string unitName(const RifEclipseSummaryAddress& resultAddress) override; + +private: + virtual int timeStepCount() const override; + + virtual void buildMetaData() override; +private: + +}; + diff --git a/ApplicationCode/FileInterface/RifSummaryReaderInterface.cpp b/ApplicationCode/FileInterface/RifSummaryReaderInterface.cpp new file mode 100644 index 0000000000..e79a808566 --- /dev/null +++ b/ApplicationCode/FileInterface/RifSummaryReaderInterface.cpp @@ -0,0 +1,78 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RifSummaryReaderInterface.h" + +#include + +#include + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const std::vector& RifSummaryReaderInterface::allResultAddresses() +{ + this->buildMetaData(); + + return m_allResultAddresses; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RifSummaryReaderInterface::fromTimeT(const std::vector& timeSteps) +{ + std::vector a; + + for (size_t i = 0; i < timeSteps.size(); i++) + { + QDateTime dt = QDateTime::fromTime_t(timeSteps[i]); + a.push_back(dt); + } + + return a; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int RifSummaryReaderInterface::indexFromAddress(const RifEclipseSummaryAddress& resultAddress) +{ + this->buildMetaData(); + + auto it = m_resultAddressToErtNodeIdx.find(resultAddress); + if (it != m_resultAddressToErtNodeIdx.end()) + { + return it->second; + } + + return -1; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RifSummaryReaderInterface::hasAddress(const RifEclipseSummaryAddress& resultAddress) +{ + this->buildMetaData(); + + auto it = m_resultAddressToErtNodeIdx.find(resultAddress); + + return (it != m_resultAddressToErtNodeIdx.end()); +} diff --git a/ApplicationCode/FileInterface/RifSummaryReaderInterface.h b/ApplicationCode/FileInterface/RifSummaryReaderInterface.h new file mode 100644 index 0000000000..2a0baa815a --- /dev/null +++ b/ApplicationCode/FileInterface/RifSummaryReaderInterface.h @@ -0,0 +1,63 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RifEclipseSummaryAddress.h" + +#include +#include +#include + +#include "cvfObject.h" + + +class QDateTime; + + +//================================================================================================== +// +// +//================================================================================================== +class RifSummaryReaderInterface : public cvf::Object +{ +public: + virtual bool open(const std::string& headerFileName, const std::vector& dataFileNames) = 0; + + bool hasAddress(const RifEclipseSummaryAddress& resultAddress); + const std::vector& allResultAddresses(); + virtual const std::vector& timeSteps() const = 0; + + virtual bool values(const RifEclipseSummaryAddress& resultAddress, std::vector* values) = 0; + virtual std::string unitName(const RifEclipseSummaryAddress& resultAddress) = 0; + + // TODO: Move this to a tools class with static members + static std::vector fromTimeT(const std::vector& timeSteps); + +protected: + + virtual int timeStepCount() const = 0; + int indexFromAddress(const RifEclipseSummaryAddress& resultAddress); + + virtual void buildMetaData() = 0; + +protected: + std::vector m_allResultAddresses; + std::map m_resultAddressToErtNodeIdx; +}; +