mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#7493 Add RigSlice2D utility class.
This commit is contained in:
parent
836c679e89
commit
6f9f77e009
@ -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
|
||||
|
73
ApplicationLibCode/ReservoirDataModel/RigSlice2D.cpp
Normal file
73
ApplicationLibCode/ReservoirDataModel/RigSlice2D.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RigSlice2D.h"
|
||||
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
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 )];
|
||||
}
|
42
ApplicationLibCode/ReservoirDataModel/RigSlice2D.h
Normal file
42
ApplicationLibCode/ReservoirDataModel/RigSlice2D.h
Normal file
@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
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<double> m_values;
|
||||
size_t m_nx;
|
||||
size_t m_ny;
|
||||
};
|
@ -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)
|
||||
|
24
ApplicationLibCode/UnitTests/RigSlice2D-Test.cpp
Normal file
24
ApplicationLibCode/UnitTests/RigSlice2D-Test.cpp
Normal file
@ -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 ) );
|
||||
}
|
Loading…
Reference in New Issue
Block a user