Roff: allow roff files in input property import

This commit is contained in:
Kristian Bendiksen
2022-12-21 11:16:35 +01:00
parent 264ad01e9e
commit fc4294a6ad
13 changed files with 201 additions and 91 deletions

View File

@@ -51,6 +51,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RifActiveCellsReader.h
${CMAKE_CURRENT_LIST_DIR}/RifCsvDataTableFormatter.h
${CMAKE_CURRENT_LIST_DIR}/RifEclipseInputPropertyLoader.h
${CMAKE_CURRENT_LIST_DIR}/RifInputPropertyLoader.h
${CMAKE_CURRENT_LIST_DIR}/RifSurfaceImporter.h
${CMAKE_CURRENT_LIST_DIR}/RifRoffReader.h
${CMAKE_CURRENT_LIST_DIR}/RifColorLegendData.h
@@ -127,6 +128,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RifCsvDataTableFormatter.cpp
${CMAKE_CURRENT_LIST_DIR}/RifReaderEnsembleStatisticsRft.cpp
${CMAKE_CURRENT_LIST_DIR}/RifEclipseInputPropertyLoader.cpp
${CMAKE_CURRENT_LIST_DIR}/RifInputPropertyLoader.cpp
${CMAKE_CURRENT_LIST_DIR}/RifSurfaceImporter.cpp
${CMAKE_CURRENT_LIST_DIR}/RifRoffReader.cpp
${CMAKE_CURRENT_LIST_DIR}/RifColorLegendData.cpp

View File

@@ -31,65 +31,6 @@
#include "RimEclipseInputProperty.h"
#include "RimEclipseInputPropertyCollection.h"
#include "RimTools.h"
#include "cafProgressInfo.h"
#include <QFile>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseInputPropertyLoader::loadAndSyncronizeInputProperties( RimEclipseInputPropertyCollection* inputPropertyCollection,
RigEclipseCaseData* eclipseCaseData,
const std::vector<QString>& filenames,
bool allowImportOfFaults )
{
std::vector<RimEclipseInputProperty*> existingProperties = inputPropertyCollection->inputProperties.children();
caf::ProgressInfo progInfo( static_cast<int>( filenames.size() ), "Reading Input properties" );
for ( const auto& filename : filenames )
{
progInfo.setProgressDescription( filename );
auto resultNamesEclipseKeywords = RifEclipseInputPropertyLoader::readProperties( filename, eclipseCaseData );
for ( const auto& [resultName, eclipseKeyword] : resultNamesEclipseKeywords )
{
bool isProperyPresent = false;
bool isFaultKeywordPresent = false;
for ( const auto* propertyObj : existingProperties )
{
if ( propertyObj->resultName() == resultName )
{
isProperyPresent = true;
}
else if ( propertyObj->resultName() == "FAULTS" )
{
isFaultKeywordPresent = true;
}
}
if ( !isProperyPresent )
{
RimEclipseInputProperty* inputProperty = new RimEclipseInputProperty;
inputProperty->resultName = resultName;
inputProperty->eclipseKeyword = eclipseKeyword;
inputProperty->fileName = filename;
inputProperty->resolvedState = RimEclipseInputProperty::RESOLVED;
inputPropertyCollection->inputProperties.push_back( inputProperty );
}
if ( allowImportOfFaults && isFaultKeywordPresent )
{
RifEclipseInputFileTools::importFaultsFromFile( eclipseCaseData, filename );
}
}
progInfo.incrementProgress();
}
}
//--------------------------------------------------------------------------------------------------
///

View File

@@ -41,21 +41,16 @@ class ProgressInfo;
class RifEclipseInputPropertyLoader
{
public:
static void loadAndSyncronizeInputProperties( RimEclipseInputPropertyCollection* inputPropertyCollection,
RigEclipseCaseData* eclipseCaseData,
const std::vector<QString>& filenames,
bool allowImportOfFaults );
static void createInputPropertiesFromKeywords( RigEclipseCaseData* eclipseCase,
const std::vector<RifEclipseKeywordContent>& keywordContent );
// Returns map of assigned resultName and Eclipse Keyword.
static std::map<QString, QString> readProperties( const QString& fileName, RigEclipseCaseData* eclipseCase );
private:
// Hide constructor to prevent instantiation
RifEclipseInputPropertyLoader();
// Returns map of assigned resultName and Eclipse Keyword.
static std::map<QString, QString> readProperties( const QString& fileName, RigEclipseCaseData* eclipseCase );
static const std::vector<QString>& invalidPropertyDataKeywords();
static bool isValidDataKeyword( const QString& keyword );

View File

@@ -0,0 +1,102 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022- 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 "RifInputPropertyLoader.h"
#include "RifEclipseInputFileTools.h"
#include "RifEclipseInputPropertyLoader.h"
#include "RifRoffFileTools.h"
#include "RigEclipseCaseData.h"
#include "RimEclipseInputProperty.h"
#include "RimEclipseInputPropertyCollection.h"
#include "cafProgressInfo.h"
#include <QFile>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifInputPropertyLoader::loadAndSyncronizeInputProperties( RimEclipseInputPropertyCollection* inputPropertyCollection,
RigEclipseCaseData* eclipseCaseData,
const std::vector<QString>& filenames,
bool allowImportOfFaults )
{
std::vector<RimEclipseInputProperty*> existingProperties = inputPropertyCollection->inputProperties.children();
caf::ProgressInfo progInfo( static_cast<int>( filenames.size() ), "Reading Input properties" );
for ( const auto& filename : filenames )
{
progInfo.setProgressDescription( filename );
auto resultNamesEclipseKeywords = RifInputPropertyLoader::readProperties( filename, eclipseCaseData );
for ( const auto& [resultName, eclipseKeyword] : resultNamesEclipseKeywords )
{
bool isProperyPresent = false;
bool isFaultKeywordPresent = false;
for ( const auto* propertyObj : existingProperties )
{
if ( propertyObj->resultName() == resultName )
{
isProperyPresent = true;
}
else if ( propertyObj->resultName() == "FAULTS" )
{
isFaultKeywordPresent = true;
}
}
if ( !isProperyPresent )
{
RimEclipseInputProperty* inputProperty = new RimEclipseInputProperty;
inputProperty->resultName = resultName;
inputProperty->eclipseKeyword = eclipseKeyword;
inputProperty->fileName = filename;
inputProperty->resolvedState = RimEclipseInputProperty::RESOLVED;
inputPropertyCollection->inputProperties.push_back( inputProperty );
}
if ( allowImportOfFaults && isFaultKeywordPresent )
{
RifEclipseInputFileTools::importFaultsFromFile( eclipseCaseData, filename );
}
}
progInfo.incrementProgress();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::map<QString, QString> RifInputPropertyLoader::readProperties( const QString& fileName,
RigEclipseCaseData* eclipseCaseData )
{
RiaDefines::ImportFileType fileType = RiaDefines::obtainFileTypeFromFileName( fileName );
if ( fileType == RiaDefines::ImportFileType::ROFF_FILE )
{
auto [isOk, keywordMapping] = RifRoffFileTools::createInputProperties( fileName, eclipseCaseData );
return keywordMapping;
}
return RifEclipseInputPropertyLoader::readProperties( fileName, eclipseCaseData );
}

View File

@@ -0,0 +1,44 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022- 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 <QString>
#include <map>
#include <vector>
class RimEclipseInputPropertyCollection;
class RigEclipseCaseData;
//==================================================================================================
//
//
//
//==================================================================================================
class RifInputPropertyLoader
{
public:
static void loadAndSyncronizeInputProperties( RimEclipseInputPropertyCollection* inputPropertyCollection,
RigEclipseCaseData* eclipseCaseData,
const std::vector<QString>& filenames,
bool allowImportOfFaults );
private:
static std::map<QString, QString> readProperties( const QString& fileName, RigEclipseCaseData* eclipseCaseData );
};

View File

@@ -592,17 +592,20 @@ size_t RifRoffFileTools::computeActiveCellMatrixIndex( std::vector<int>& activeC
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifRoffFileTools::createInputProperties( const QString& fileName, RigEclipseCaseData* eclipseCaseData )
std::pair<bool, std::map<QString, QString>>
RifRoffFileTools::createInputProperties( const QString& fileName, RigEclipseCaseData* eclipseCaseData )
{
RiaLogging::info( QString( "Opening roff file: %1" ).arg( fileName ) );
std::string filename = fileName.toStdString();
std::map<QString, QString> keywordMapping;
std::ifstream stream( filename, std::ios::binary );
if ( !stream.good() )
{
RiaLogging::error( "Unable to open roff file" );
return false;
return std::make_pair( false, keywordMapping );
}
try
@@ -634,18 +637,20 @@ bool RifRoffFileTools::createInputProperties( const QString& fileName, RigEclips
RiaLogging::error( QString( "Unable to import result '%1' from %2" )
.arg( QString::fromStdString( keyword ) )
.arg( fileName ) );
return false;
return std::make_pair( false, keywordMapping );
}
keywordMapping[QString::fromStdString( keyword )] = newResultName;
}
}
}
catch ( std::runtime_error& err )
{
RiaLogging::error( QString( "Roff property file import failed: %1" ).arg( err.what() ) );
return false;
return std::make_pair( false, keywordMapping );
}
return true;
return std::make_pair( true, keywordMapping );
}
//--------------------------------------------------------------------------------------------------

View File

@@ -23,6 +23,7 @@
#include <QString>
#include <map>
#include <vector>
#include "Token.hpp"
@@ -44,7 +45,8 @@ public:
static bool openGridFile( const QString& fileName, RigEclipseCaseData* eclipseCase, QString* errorMessages );
static bool createInputProperties( const QString& fileName, RigEclipseCaseData* eclipseCase );
static std::pair<bool, std::map<QString, QString>> createInputProperties( const QString& fileName,
RigEclipseCaseData* eclipseCase );
private:
static void interpretSplitenzData( int nz,