From 6f9f77e009c8ea69c901317b8bf3b37dd39594eb Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Wed, 24 Mar 2021 11:24:22 +0100 Subject: [PATCH] #7493 Add RigSlice2D utility class. --- .../ReservoirDataModel/CMakeLists_files.cmake | 2 + .../ReservoirDataModel/RigSlice2D.cpp | 73 +++++++++++++++++++ .../ReservoirDataModel/RigSlice2D.h | 42 +++++++++++ .../UnitTests/CMakeLists_files.cmake | 1 + .../UnitTests/RigSlice2D-Test.cpp | 24 ++++++ 5 files changed, 142 insertions(+) create mode 100644 ApplicationLibCode/ReservoirDataModel/RigSlice2D.cpp create mode 100644 ApplicationLibCode/ReservoirDataModel/RigSlice2D.h create mode 100644 ApplicationLibCode/UnitTests/RigSlice2D-Test.cpp diff --git a/ApplicationLibCode/ReservoirDataModel/CMakeLists_files.cmake b/ApplicationLibCode/ReservoirDataModel/CMakeLists_files.cmake index c402e44968..b71bf2a794 100644 --- a/ApplicationLibCode/ReservoirDataModel/CMakeLists_files.cmake +++ b/ApplicationLibCode/ReservoirDataModel/CMakeLists_files.cmake @@ -86,6 +86,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RigVisibleTracerFilter.h ${CMAKE_CURRENT_LIST_DIR}/RigTracerPoint.h ${CMAKE_CURRENT_LIST_DIR}/RigTracer.h ${CMAKE_CURRENT_LIST_DIR}/RigStimPlanModelTools.h +${CMAKE_CURRENT_LIST_DIR}/RigSlice2D.h ) @@ -169,6 +170,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RigVisibleTracerFilter.cpp ${CMAKE_CURRENT_LIST_DIR}/RigTracerPoint.cpp ${CMAKE_CURRENT_LIST_DIR}/RigTracer.cpp ${CMAKE_CURRENT_LIST_DIR}/RigStimPlanModelTools.cpp +${CMAKE_CURRENT_LIST_DIR}/RigSlice2D.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationLibCode/ReservoirDataModel/RigSlice2D.cpp b/ApplicationLibCode/ReservoirDataModel/RigSlice2D.cpp new file mode 100644 index 0000000000..383b238728 --- /dev/null +++ b/ApplicationLibCode/ReservoirDataModel/RigSlice2D.cpp @@ -0,0 +1,73 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2021 - Equinor 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 "RigSlice2D.h" + +#include "RiaLogging.h" + +#include + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RigSlice2D::RigSlice2D( size_t nx, size_t ny ) + : m_nx( nx ) + , m_ny( ny ) +{ + m_values.resize( nx * ny, 0.0 ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RigSlice2D::getIndex( size_t x, size_t y ) const +{ + return y * m_nx + x; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RigSlice2D::ny() const +{ + return m_ny; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RigSlice2D::nx() const +{ + return m_nx; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigSlice2D::setValue( size_t x, size_t y, double value ) +{ + m_values[getIndex( x, y )] = value; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RigSlice2D::getValue( size_t x, size_t y ) const +{ + return m_values[getIndex( x, y )]; +} diff --git a/ApplicationLibCode/ReservoirDataModel/RigSlice2D.h b/ApplicationLibCode/ReservoirDataModel/RigSlice2D.h new file mode 100644 index 0000000000..270b5e46d4 --- /dev/null +++ b/ApplicationLibCode/ReservoirDataModel/RigSlice2D.h @@ -0,0 +1,42 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2021 - Equinor 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 + +//================================================================================================== +/// +/// +//================================================================================================== +class RigSlice2D +{ +public: + RigSlice2D( size_t nx, size_t ny ); + size_t nx() const; + size_t ny() const; + void setValue( size_t x, size_t y, double value ); + double getValue( size_t x, size_t y ) const; + +private: + size_t getIndex( size_t x, size_t y ) const; + + std::vector m_values; + size_t m_nx; + size_t m_ny; +}; diff --git a/ApplicationLibCode/UnitTests/CMakeLists_files.cmake b/ApplicationLibCode/UnitTests/CMakeLists_files.cmake index c1a9decdc6..8d8f0aeaa3 100644 --- a/ApplicationLibCode/UnitTests/CMakeLists_files.cmake +++ b/ApplicationLibCode/UnitTests/CMakeLists_files.cmake @@ -75,6 +75,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RifStimPlanXmlReader-Test.cpp ${CMAKE_CURRENT_LIST_DIR}/RigWellPathGeometryExporter-Test.cpp ${CMAKE_CURRENT_LIST_DIR}/RifStimPlanModelDeviationFrkExporter-Test.cpp ${CMAKE_CURRENT_LIST_DIR}/RifSummaryDataReader-Test.cpp +${CMAKE_CURRENT_LIST_DIR}/RigSlice2D-Test.cpp ) if (RESINSIGHT_ENABLE_GRPC) diff --git a/ApplicationLibCode/UnitTests/RigSlice2D-Test.cpp b/ApplicationLibCode/UnitTests/RigSlice2D-Test.cpp new file mode 100644 index 0000000000..ddc639f4d7 --- /dev/null +++ b/ApplicationLibCode/UnitTests/RigSlice2D-Test.cpp @@ -0,0 +1,24 @@ +#include "gtest/gtest.h" + +#include "RigSlice2D.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +TEST( RigSlice2DTest, GetAndSet ) +{ + size_t nx = 12; + size_t ny = 23; + + RigSlice2D slice( nx, ny ); + EXPECT_EQ( nx, slice.nx() ); + EXPECT_EQ( ny, slice.ny() ); + + for ( size_t y = 0; y < ny; y++ ) + for ( size_t x = 0; x < nx; x++ ) + slice.setValue( x, y, x * y ); + + for ( size_t y = 0; y < ny; y++ ) + for ( size_t x = 0; x < nx; x++ ) + EXPECT_EQ( x * y, slice.getValue( x, y ) ); +}