Skip to content

Commit

Permalink
Look for fault definition in Pflotran input files
Browse files Browse the repository at this point in the history
If no *.DATA file is found, look for *.IN file and search for fault definitions.
  • Loading branch information
magnesj committed Aug 28, 2024
1 parent 41256e0 commit 977e8f3
Show file tree
Hide file tree
Showing 7 changed files with 481 additions and 0 deletions.
105 changes: 105 additions & 0 deletions ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,111 @@ QString RifEclipseInputFileTools::faultFaceText( cvf::StructGridInterface::FaceT
return "";
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseInputFileTools::parsePflotranInputFile( const QString& fileName, cvf::Collection<RigFault>* faults )
{
QStringList gridSectionFilenames;

RiaLogging::info( "Looking for 'Pflotran' fault definitions in " + fileName );

{
// Find all referenced grdecl files in a pflotran input file, in the GRID section, example
/*
GRID
TYPE grdecl ../include/ccs_3df_kh.grdecl
TYPE grdecl ../include/ccs_3df_other.grdecl
END
*/

QFile file( fileName );
if ( !file.open( QFile::ReadOnly ) ) return;

QString line;
bool continueParsing = true;
bool foundGridKeyword = false;
bool foundEndKeyword = false;
do
{
line = file.readLine();
line = line.trimmed();

if ( line.startsWith( "GRID" ) ) foundGridKeyword = true;

if ( foundGridKeyword )
{
if ( line.startsWith( "TYPE" ) )
{
auto words = RiaTextStringTools::splitSkipEmptyParts( line, " " );
if ( words.size() == 3 && words[1].startsWith( "grdecl", Qt::CaseInsensitive ) )
{
QFileInfo fi( fileName );
QDir currentFileFolder = fi.absoluteDir();

QString absoluteFilePath = currentFileFolder.absoluteFilePath( words.back() );
gridSectionFilenames.push_back( absoluteFilePath );
}
}

if ( line.startsWith( "END" ) ) foundEndKeyword = true;
}

if ( foundEndKeyword ) continueParsing = false;

if ( file.atEnd() )
{
continueParsing = false;
}

} while ( continueParsing );
}

// Find all grdecl files defined by the external_file keyword
// For all these files, search for the FAULTS keyword and create fault objects
/*
external_file ccs_3df_kh.grdecl
external_file ccs_3df_other.grdecl
*/

for ( const auto& gridSectionFilename : gridSectionFilenames )
{
QFile file( gridSectionFilename );
if ( !file.open( QFile::ReadOnly ) ) continue;

QString line;
do
{
line = file.readLine();
line = line.trimmed();

if ( line.startsWith( "external_file", Qt::CaseInsensitive ) )
{
auto words = RiaTextStringTools::splitSkipEmptyParts( line, " " );
if ( words.size() == 2 )
{
QFileInfo fi( gridSectionFilename );
QDir currentFileFolder = fi.absoluteDir();

QString absoluteFilePath = currentFileFolder.absoluteFilePath( words.back() );
QFile grdeclFilename( absoluteFilePath );
if ( !grdeclFilename.open( QFile::ReadOnly ) ) continue;

auto currentFaultCount = faults->size();

readFaults( grdeclFilename, 0, faults, nullptr );

if ( currentFaultCount != faults->size() )
{
RiaLogging::info( "Imported faults from " + absoluteFilePath );
}
}
}

} while ( !file.atEnd() );
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions ApplicationLibCode/FileInterface/RifEclipseInputFileTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class RifEclipseInputFileTools : public cvf::Object

static bool hasGridData( const QString& fileName );

static void parsePflotranInputFile( const QString& fileName, cvf::Collection<RigFault>* faults );

private:
static void readFaults( QFile& data, qint64 filePos, cvf::Collection<RigFault>* faults, bool* isEditKeywordDetected );

Expand Down
18 changes: 18 additions & 0 deletions ApplicationLibCode/FileInterface/RifReaderInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "RifReaderInterface.h"

#include "RiaLogging.h"
#include "RiaPreferencesGrid.h"

#include "RifEclipseInputFileTools.h"
Expand Down Expand Up @@ -151,10 +152,14 @@ void RifReaderInterface::importFaults( const QStringList& fileSet, cvf::Collecti
}
else
{
bool isDataFileFound = false;

foreach ( QString fname, fileSet )
{
if ( fname.endsWith( ".DATA" ) )
{
isDataFileFound = true;

std::vector<QString> filenamesWithFaults;
RifEclipseInputFileTools::readFaultsInGridSection( fname, faults, &filenamesWithFaults, faultIncludeFileAbsolutePathPrefix() );

Expand All @@ -165,5 +170,18 @@ void RifReaderInterface::importFaults( const QStringList& fileSet, cvf::Collecti
setFilenamesWithFaults( filenamesWithFaults );
}
}

if ( !isDataFileFound )
{
RiaLogging::info( "No *.DATA file is found" );

for ( const auto& filename : fileSet )
{
if ( filename.endsWith( ".IN", Qt::CaseInsensitive ) )
{
RifEclipseInputFileTools::parsePflotranInputFile( filename, faults );
}
}
}
}
}
18 changes: 18 additions & 0 deletions ApplicationLibCode/UnitTests/RifEclipseInputFileTools-Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,24 @@ TEST( RifEclipseInputFileToolsTest, FaultData )
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST( RifEclipseInputFileToolsTest, FaultDataPflotran )
{
static const QString testDataRootFolder = QString( "%1/RifEclipseInputFileTools/pflotran" ).arg( TEST_DATA_DIR );

{
QString fileName = testDataRootFolder + "/model/P_FLT_TEST_NO-KH.in";

cvf::Collection<RigFault> faults;

RifEclipseInputFileTools::parsePflotranInputFile( fileName, &faults );

EXPECT_EQ( (size_t)4, faults.size() );
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 977e8f3

Please sign in to comment.