mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 06:38:13 -05:00
120 lines
5.3 KiB
C++
120 lines
5.3 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2026- 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 "gtest/gtest.h"
|
|
|
|
#include "RifReaderOpmCommon.h"
|
|
|
|
#include "RiaEclipseUnitTools.h"
|
|
#include "RiaTestDataDirectory.h"
|
|
|
|
#include "RigEclipseCaseData.h"
|
|
|
|
#include "opm/io/eclipse/ERst.hpp"
|
|
|
|
#include <QFile>
|
|
#include <QTemporaryDir>
|
|
|
|
#include <filesystem>
|
|
#include <stdexcept>
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
/// opm-common scales MAPAXES to meter based on MAPUNITS, while the cell corner coordinates are left in the units
|
|
/// given by GRIDUNIT. Verify that the map axes are scaled back into grid units.
|
|
//--------------------------------------------------------------------------------------------------
|
|
TEST( RifReaderOpmCommon, MapAxesScaleFactor )
|
|
{
|
|
const int gridUnitMetric = 1;
|
|
const int gridUnitField = 2;
|
|
const int gridUnitLab = 3;
|
|
const int gridUnitUnknown = -1;
|
|
|
|
const double feetToMeter = RiaEclipseUnitTools::meterPerFeet();
|
|
|
|
// MAPUNITS is missing, opm-common has not scaled the map axes
|
|
EXPECT_DOUBLE_EQ( 1.0, RifReaderOpmCommon::mapAxesScaleFactor( "", gridUnitField ) );
|
|
EXPECT_DOUBLE_EQ( 1.0, RifReaderOpmCommon::mapAxesScaleFactor( "", gridUnitMetric ) );
|
|
|
|
// MAPUNITS is not recognized by opm-common, the map axes are left unscaled
|
|
EXPECT_DOUBLE_EQ( 1.0, RifReaderOpmCommon::mapAxesScaleFactor( "FT", gridUnitField ) );
|
|
|
|
// Same unit for map axes and grid, the scaling applied by opm-common must be undone
|
|
EXPECT_DOUBLE_EQ( 1.0, RifReaderOpmCommon::mapAxesScaleFactor( "METRES", gridUnitMetric ) );
|
|
EXPECT_DOUBLE_EQ( 1.0 / feetToMeter, RifReaderOpmCommon::mapAxesScaleFactor( "FEET", gridUnitField ) );
|
|
EXPECT_DOUBLE_EQ( 100.0, RifReaderOpmCommon::mapAxesScaleFactor( "CM", gridUnitLab ) );
|
|
|
|
// Map axes and grid have different units, convert from meter to grid unit
|
|
EXPECT_DOUBLE_EQ( 1.0, RifReaderOpmCommon::mapAxesScaleFactor( "FEET", gridUnitMetric ) );
|
|
EXPECT_DOUBLE_EQ( 1.0 / feetToMeter, RifReaderOpmCommon::mapAxesScaleFactor( "METRES", gridUnitField ) );
|
|
|
|
// Unknown grid unit, undo the scaling applied by opm-common
|
|
EXPECT_DOUBLE_EQ( 1.0 / feetToMeter, RifReaderOpmCommon::mapAxesScaleFactor( "FEET", gridUnitUnknown ) );
|
|
EXPECT_DOUBLE_EQ( 1.0, RifReaderOpmCommon::mapAxesScaleFactor( "METRES", gridUnitUnknown ) );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
TEST( RifReaderOpmCommon, RestartDataSize )
|
|
{
|
|
const auto testFile = std::filesystem::path( TEST_MODEL_DIR ) / "TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.UNRST";
|
|
|
|
Opm::EclIO::ERst restartFile( testFile.string() );
|
|
const int reportStep = 0;
|
|
|
|
// PRESSURE is stored once for the global grid and once for the LGR, with 8517 and 2608 elements.
|
|
const int pressureOccurrences = restartFile.occurrence_count( "PRESSURE", reportStep );
|
|
EXPECT_EQ( 2, pressureOccurrences );
|
|
|
|
std::int64_t pressureSize = 0;
|
|
for ( int occurrence = 0; occurrence < pressureOccurrences; ++occurrence )
|
|
{
|
|
pressureSize += restartFile.getRestartData<float>( "PRESSURE", reportStep, occurrence ).size();
|
|
}
|
|
|
|
EXPECT_EQ( 8517 + 2608, pressureSize );
|
|
EXPECT_EQ( pressureSize, RifReaderOpmCommon::restartDataSize( restartFile, "PRESSURE", reportStep ) );
|
|
|
|
// SEQNUM exists in the global grid only.
|
|
EXPECT_EQ( 1, RifReaderOpmCommon::restartDataSize( restartFile, "SEQNUM", reportStep ) );
|
|
|
|
EXPECT_EQ( 0, RifReaderOpmCommon::restartDataSize( restartFile, "XXXX", reportStep ) );
|
|
EXPECT_THROW( RifReaderOpmCommon::restartDataSize( restartFile, "PRESSURE", 99 ), std::invalid_argument );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
TEST( RifReaderOpmCommon, EmptyRestartFile )
|
|
{
|
|
QTemporaryDir tempDir;
|
|
ASSERT_TRUE( tempDir.isValid() );
|
|
|
|
const QString sourceGrid = QString( TEST_MODEL_DIR ) + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID";
|
|
const QString gridFile = tempDir.filePath( "EMPTY_RESTART.EGRID" );
|
|
ASSERT_TRUE( QFile::copy( sourceGrid, gridFile ) );
|
|
|
|
QFile restartFile( tempDir.filePath( "EMPTY_RESTART.UNRST" ) );
|
|
ASSERT_TRUE( restartFile.open( QIODevice::WriteOnly ) );
|
|
restartFile.close();
|
|
|
|
cvf::ref<RigEclipseCaseData> caseData = new RigEclipseCaseData( nullptr );
|
|
cvf::ref<RifReaderOpmCommon> reader = new RifReaderOpmCommon;
|
|
EXPECT_TRUE( reader->open( gridFile, caseData.p() ) );
|
|
}
|