mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-03 12:10:57 -06:00
#8143 Performance: Avoid parsing grid GRDECL file twice
Previous implementation parsed grid file twice both for geometry data and properties.
This commit is contained in:
parent
9940b4ea50
commit
6b13a31349
@ -68,6 +68,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifEclEclipseSummary.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifWellIAFileWriter.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifEclipseTextFileReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifEclipseKeywordContent.h
|
||||
)
|
||||
|
||||
set(SOURCE_GROUP_SOURCE_FILES
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaStringEncodingTools.h"
|
||||
|
||||
#include "RifEclipseInputPropertyLoader.h"
|
||||
#include "RifEclipseKeywordContent.h"
|
||||
#include "RifEclipseTextFileReader.h"
|
||||
#include "RifReaderEclipseOutput.h"
|
||||
|
||||
@ -190,6 +192,9 @@ bool RifEclipseInputFileTools::openGridFile( const QString& fileName,
|
||||
|
||||
ecl_grid_free( inputGrid );
|
||||
|
||||
// Import additional keywords as input properties
|
||||
RifEclipseInputPropertyLoader::createInputPropertiesFromKeywords( eclipseCase, objects );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "RifEclipseInputFileTools.h"
|
||||
#include "RifEclipseKeywordContent.h"
|
||||
#include "RifEclipseTextFileReader.h"
|
||||
#include "RifReaderEclipseInput.h"
|
||||
|
||||
@ -90,6 +91,54 @@ void RifEclipseInputPropertyLoader::loadAndSyncronizeInputProperties( RimEclipse
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RifEclipseInputPropertyLoader::evaluateAndCreateInputPropertyResult( RigEclipseCaseData* eclipseCase,
|
||||
const RifEclipseKeywordContent& keywordContent,
|
||||
QString* errorMessage )
|
||||
{
|
||||
auto eclipseKeyword = keywordContent.keyword;
|
||||
if ( isInputPropertyCandidate( eclipseCase, eclipseKeyword, keywordContent.values.size() ) )
|
||||
{
|
||||
QString newResultName = eclipseCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL )
|
||||
->makeResultNameUnique( QString::fromStdString( eclipseKeyword ) );
|
||||
|
||||
if ( appendNewInputPropertyResult( eclipseCase, newResultName, eclipseKeyword, keywordContent.values, errorMessage ) )
|
||||
{
|
||||
return newResultName;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifEclipseInputPropertyLoader::createInputPropertiesFromKeywords( RigEclipseCaseData* eclipseCase,
|
||||
const std::vector<RifEclipseKeywordContent>& keywordContent )
|
||||
{
|
||||
for ( const auto& keywordAndValues : keywordContent )
|
||||
{
|
||||
RifEclipseInputPropertyLoader::evaluateAndCreateInputPropertyResult( eclipseCase, keywordAndValues, nullptr );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifEclipseInputPropertyLoader::isInputPropertyCandidate( const RigEclipseCaseData* caseData,
|
||||
const std::string& eclipseKeyword,
|
||||
size_t numberOfValues )
|
||||
{
|
||||
CVF_ASSERT( caseData );
|
||||
|
||||
if ( !isValidDataKeyword( QString::fromStdString( eclipseKeyword ) ) ) return false;
|
||||
|
||||
return ( numberOfValues == caseData->mainGrid()->cellCount() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -98,24 +147,19 @@ std::map<QString, QString> RifEclipseInputPropertyLoader::readProperties( const
|
||||
{
|
||||
std::map<QString, QString> resultNameAndEclipseNameMap;
|
||||
|
||||
auto objects = RifEclipseTextFileReader::readKeywordAndValues( fileName.toStdString() );
|
||||
for ( const auto& obj : objects )
|
||||
auto keywordContent = RifEclipseTextFileReader::readKeywordAndValues( fileName.toStdString() );
|
||||
for ( const auto& keywordAndValues : keywordContent )
|
||||
{
|
||||
if ( !obj.values.empty() )
|
||||
{
|
||||
auto eclipseKeyword = obj.keyword;
|
||||
QString newResultName = eclipseCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL )
|
||||
->makeResultNameUnique( QString::fromStdString( eclipseKeyword ) );
|
||||
QString errorText;
|
||||
|
||||
QString errorText;
|
||||
if ( appendInputPropertyResult( eclipseCase, newResultName, eclipseKeyword, obj.values, &errorText ) )
|
||||
{
|
||||
resultNameAndEclipseNameMap[newResultName] = QString::fromStdString( eclipseKeyword );
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::error( errorText );
|
||||
}
|
||||
QString newResultName = evaluateAndCreateInputPropertyResult( eclipseCase, keywordAndValues, &errorText );
|
||||
if ( !newResultName.isEmpty() )
|
||||
{
|
||||
resultNameAndEclipseNameMap[newResultName] = QString::fromStdString( keywordAndValues.keyword );
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::error( errorText );
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,22 +199,25 @@ bool RifEclipseInputPropertyLoader::isValidDataKeyword( const QString& keyword )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifEclipseInputPropertyLoader::appendInputPropertyResult( RigEclipseCaseData* caseData,
|
||||
const QString& resultName,
|
||||
const std::string& eclipseKeyword,
|
||||
const std::vector<float>& values,
|
||||
QString* errMsg )
|
||||
bool RifEclipseInputPropertyLoader::appendNewInputPropertyResult( RigEclipseCaseData* caseData,
|
||||
const QString& resultName,
|
||||
const std::string& eclipseKeyword,
|
||||
const std::vector<float>& values,
|
||||
QString* errMsg )
|
||||
{
|
||||
if ( !isValidDataKeyword( QString::fromStdString( eclipseKeyword ) ) ) return false;
|
||||
|
||||
CVF_ASSERT( caseData );
|
||||
CVF_ASSERT( errMsg );
|
||||
|
||||
size_t keywordItemCount = values.size();
|
||||
if ( keywordItemCount != caseData->mainGrid()->cellCount() )
|
||||
{
|
||||
QString errFormat( "Size mismatch: Main Grid has %1 cells, keyword %2 has %3 cells" );
|
||||
*errMsg = errFormat.arg( caseData->mainGrid()->cellCount() ).arg( resultName ).arg( keywordItemCount );
|
||||
if ( errMsg )
|
||||
{
|
||||
QString errFormat( "Size mismatch: Main Grid has %1 cells, keyword %2 has %3 cells" );
|
||||
*errMsg = errFormat.arg( caseData->mainGrid()->cellCount() ).arg( resultName ).arg( keywordItemCount );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,8 @@
|
||||
|
||||
class RimEclipseInputPropertyCollection;
|
||||
class RigEclipseCaseData;
|
||||
class RifEclipseKeywordContent;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class ProgressInfo;
|
||||
@ -44,6 +46,9 @@ public:
|
||||
const std::vector<QString>& filenames,
|
||||
bool allowImportOfFaults );
|
||||
|
||||
static void createInputPropertiesFromKeywords( RigEclipseCaseData* eclipseCase,
|
||||
const std::vector<RifEclipseKeywordContent>& keywordContent );
|
||||
|
||||
private:
|
||||
// Hide constructor to prevent instantiation
|
||||
RifEclipseInputPropertyLoader();
|
||||
@ -54,9 +59,17 @@ private:
|
||||
static const std::vector<QString>& invalidPropertyDataKeywords();
|
||||
static bool isValidDataKeyword( const QString& keyword );
|
||||
|
||||
static bool appendInputPropertyResult( RigEclipseCaseData* caseData,
|
||||
const QString& resultName,
|
||||
const std::string& eclipseKeyword,
|
||||
const std::vector<float>& values,
|
||||
QString* errMsg );
|
||||
static bool isInputPropertyCandidate( const RigEclipseCaseData* caseData,
|
||||
const std::string& eclipseKeyword,
|
||||
size_t numberOfValues );
|
||||
|
||||
static bool appendNewInputPropertyResult( RigEclipseCaseData* caseData,
|
||||
const QString& resultName,
|
||||
const std::string& eclipseKeyword,
|
||||
const std::vector<float>& values,
|
||||
QString* errMsg );
|
||||
|
||||
static QString evaluateAndCreateInputPropertyResult( RigEclipseCaseData* eclipseCase,
|
||||
const RifEclipseKeywordContent& keywordContent,
|
||||
QString* errorMessage );
|
||||
};
|
||||
|
31
ApplicationLibCode/FileInterface/RifEclipseKeywordContent.h
Normal file
31
ApplicationLibCode/FileInterface/RifEclipseKeywordContent.h
Normal file
@ -0,0 +1,31 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 <string>
|
||||
#include <vector>
|
||||
|
||||
class RifEclipseKeywordContent
|
||||
{
|
||||
public:
|
||||
std::string keyword;
|
||||
std::string content;
|
||||
std::vector<float> values;
|
||||
size_t offset;
|
||||
};
|
@ -17,6 +17,7 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RifEclipseTextFileReader.h"
|
||||
#include "RifEclipseKeywordContent.h"
|
||||
|
||||
// Utility class for fast conversion from string to float
|
||||
#include "fast_float/include/fast_float/fast_float.h"
|
||||
|
@ -20,14 +20,7 @@
|
||||
|
||||
#include "RifReaderInterface.h"
|
||||
|
||||
class RifEclipseKeywordContent
|
||||
{
|
||||
public:
|
||||
std::string keyword;
|
||||
std::string content;
|
||||
std::vector<float> values;
|
||||
size_t offset;
|
||||
};
|
||||
class RifEclipseKeywordContent;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
|
@ -678,8 +678,6 @@ void RimEclipseCase::loadAndSyncronizeInputProperties( bool importGridOrFaultDat
|
||||
filenames.push_back( fileName );
|
||||
}
|
||||
|
||||
if ( importGridOrFaultData ) filenames.push_back( gridFileName() );
|
||||
|
||||
RifEclipseInputPropertyLoader::loadAndSyncronizeInputProperties( inputPropertyCollection(),
|
||||
eclipseCaseData(),
|
||||
filenames,
|
||||
|
@ -111,6 +111,8 @@ bool RimEclipseInputCase::openDataFileSet( const QStringList& fileNames )
|
||||
|
||||
std::vector<QString> allErrorMessages;
|
||||
|
||||
QString gridFileName;
|
||||
|
||||
// First find and read the grid data
|
||||
if ( this->eclipseCaseData()->mainGrid()->gridPointDimensions() == cvf::Vec3st( 0, 0, 0 ) )
|
||||
{
|
||||
@ -120,6 +122,7 @@ bool RimEclipseInputCase::openDataFileSet( const QStringList& fileNames )
|
||||
if ( RifEclipseInputFileTools::openGridFile( fileNames[i], this->eclipseCaseData(), importFaults, &errorMessages ) )
|
||||
{
|
||||
setGridFileName( fileNames[i] );
|
||||
gridFileName = fileNames[i];
|
||||
|
||||
QFileInfo gridFileName( fileNames[i] );
|
||||
QString caseName = gridFileName.completeBaseName();
|
||||
@ -154,6 +157,8 @@ bool RimEclipseInputCase::openDataFileSet( const QStringList& fileNames )
|
||||
std::vector<QString> filesToRead;
|
||||
for ( const QString& filename : fileNames )
|
||||
{
|
||||
if ( filename == gridFileName ) continue;
|
||||
|
||||
bool exists = false;
|
||||
for ( const QString& currentFileName : additionalFiles() )
|
||||
{
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RiaTestDataDirectory.h"
|
||||
|
||||
#include "RifEclipseKeywordContent.h"
|
||||
#include "RifEclipseTextFileReader.h"
|
||||
|
||||
#include <QString>
|
||||
|
Loading…
Reference in New Issue
Block a user