mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
#9039: Thermal Fractures: add file reader
This commit is contained in:
parent
fa2cf302bb
commit
972013c631
@ -40,6 +40,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifElementPropertyTableReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifElementPropertyReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanXmlReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifThermalFractureReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifSummaryCaseRestartSelector.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifCaseRealizationParametersReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifFileParseTools.h
|
||||
@ -115,6 +116,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifElementPropertyTableReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifElementPropertyReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanXmlReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifThermalFractureReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifSummaryCaseRestartSelector.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifCaseRealizationParametersReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifFileParseTools.cpp
|
||||
|
154
ApplicationLibCode/FileInterface/RifThermalFractureReader.cpp
Normal file
154
ApplicationLibCode/FileInterface/RifThermalFractureReader.cpp
Normal file
@ -0,0 +1,154 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RifThermalFractureReader.h"
|
||||
|
||||
#include "RiaTextStringTools.h"
|
||||
|
||||
#include "RigThermalFractureDefinition.h"
|
||||
|
||||
#include "RifFileParseTools.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<std::shared_ptr<RigThermalFractureDefinition>, QString>
|
||||
RifThermalFractureReader::readFractureCsvFile( const QString& filePath )
|
||||
{
|
||||
QFile file( filePath );
|
||||
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
||||
{
|
||||
return std::make_pair( nullptr, QString( "Unable to open file: %1" ).arg( filePath ) );
|
||||
}
|
||||
|
||||
std::shared_ptr<RigThermalFractureDefinition> def = std::make_shared<RigThermalFractureDefinition>();
|
||||
|
||||
QString separator = ",";
|
||||
|
||||
auto appendPropertyValues = [def]( int nodeIndex, int timeStepIndex, int valueOffset, const QStringList& values ) {
|
||||
for ( int i = valueOffset; i < values.size() - 1; i++ )
|
||||
{
|
||||
double value = values[i].toDouble();
|
||||
int propertyIndex = i - valueOffset;
|
||||
def->appendPropertyValue( propertyIndex, nodeIndex, timeStepIndex, value );
|
||||
}
|
||||
};
|
||||
|
||||
QTextStream in( &file );
|
||||
int lineNumber = 1;
|
||||
|
||||
QStringList headerValues;
|
||||
// The two items in the csv is name and timestep
|
||||
const int valueOffset = 2;
|
||||
int nodeIndex = 0;
|
||||
int timeStepIndex = 0;
|
||||
bool isFirstHeader = true;
|
||||
while ( !in.atEnd() )
|
||||
{
|
||||
QString line = in.readLine();
|
||||
if ( lineNumber == 1 )
|
||||
{
|
||||
// The first line is the name of the fracture
|
||||
def->setName( line );
|
||||
}
|
||||
else if ( isHeaderLine( line ) )
|
||||
{
|
||||
headerValues = RifFileParseTools::splitLineAndTrim( line, separator );
|
||||
if ( isFirstHeader )
|
||||
{
|
||||
// Create the result vector when encountering the first header
|
||||
for ( int i = valueOffset; i < headerValues.size() - 1; i++ )
|
||||
{
|
||||
auto [name, unit] = parseNameAndUnit( headerValues[i] );
|
||||
def->addProperty( name, unit );
|
||||
}
|
||||
|
||||
isFirstHeader = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeIndex++;
|
||||
timeStepIndex = 0;
|
||||
}
|
||||
}
|
||||
else if ( isCenterNodeLine( line ) )
|
||||
{
|
||||
// The first node is the center node
|
||||
auto values = RifFileParseTools::splitLineAndTrim( line, separator );
|
||||
|
||||
// Second is the timestamp
|
||||
QString dateString = values[1];
|
||||
QString dateFormat = "DD.MMMM.yy hh:mm:ss";
|
||||
QDateTime dateTime = QDateTime::fromString( dateString, dateFormat );
|
||||
def->addTimeStep( dateTime.toSecsSinceEpoch() );
|
||||
|
||||
//
|
||||
appendPropertyValues( nodeIndex, timeStepIndex, valueOffset, values );
|
||||
timeStepIndex = 0;
|
||||
}
|
||||
else if ( isInternalNodeLine( line ) )
|
||||
{
|
||||
auto values = RifFileParseTools::splitLineAndTrim( line, separator );
|
||||
appendPropertyValues( nodeIndex, timeStepIndex, valueOffset, values );
|
||||
timeStepIndex = 0;
|
||||
}
|
||||
|
||||
lineNumber++;
|
||||
}
|
||||
|
||||
return std::make_pair( def, "" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifThermalFractureReader::isHeaderLine( const QString& line )
|
||||
{
|
||||
return line.contains( "XCoord" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifThermalFractureReader::isCenterNodeLine( const QString& line )
|
||||
{
|
||||
return line.contains( "Centre Node" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifThermalFractureReader::isInternalNodeLine( const QString& line )
|
||||
{
|
||||
return line.contains( "Internal Node" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<QString, QString> RifThermalFractureReader::parseNameAndUnit( const QString& value )
|
||||
{
|
||||
QStringList values = value.split( " " );
|
||||
QString name = values[0];
|
||||
QString unit = values[1].replace( "(", "" ).replace( ")", "" );
|
||||
return std::make_pair( name, unit );
|
||||
}
|
38
ApplicationLibCode/FileInterface/RifThermalFractureReader.h
Normal file
38
ApplicationLibCode/FileInterface/RifThermalFractureReader.h
Normal file
@ -0,0 +1,38 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 <memory>
|
||||
|
||||
class RigThermalFractureDefinition;
|
||||
|
||||
class RifThermalFractureReader
|
||||
{
|
||||
public:
|
||||
static std::pair<std::shared_ptr<RigThermalFractureDefinition>, QString> readFractureCsvFile( const QString& fileName );
|
||||
|
||||
private:
|
||||
static bool isHeaderLine( const QString& line );
|
||||
static bool isCenterNodeLine( const QString& line );
|
||||
static bool isInternalNodeLine( const QString& line );
|
||||
|
||||
static std::pair<QString, QString> parseNameAndUnit( const QString& value );
|
||||
};
|
@ -60,6 +60,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigWeightedMeanCalc.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigWellPathFormations.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigStimPlanFractureDefinition.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigThermalFractureDefinition.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigFractureGrid.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigFractureCell.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigWellResultPoint.h
|
||||
@ -149,6 +150,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigWeightedMeanCalc.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigWellPathFormations.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigStimPlanFractureDefinition.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigThermalFractureDefinition.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigFractureGrid.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigFractureCell.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigWellResultPoint.cpp
|
||||
|
@ -0,0 +1,127 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RigThermalFractureDefinition.h"
|
||||
|
||||
#include "RiaEclipseUnitTools.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RigThermalFractureDefinition::RigThermalFractureDefinition()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RigThermalFractureDefinition::~RigThermalFractureDefinition()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigThermalFractureDefinition::setName( const QString& name )
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RigThermalFractureDefinition::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t RigThermalFractureDefinition::numNodes() const
|
||||
{
|
||||
if ( m_results.empty() ) return 0u;
|
||||
|
||||
return m_results[0].numNodes();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<double>& RigThermalFractureDefinition::timeSteps() const
|
||||
{
|
||||
return m_timeSteps;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigThermalFractureDefinition::addTimeStep( double timeStep )
|
||||
{
|
||||
m_timeSteps.push_back( timeStep );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t RigThermalFractureDefinition::numTimeSteps() const
|
||||
{
|
||||
return m_timeSteps.size();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigThermalFractureDefinition::addProperty( const QString& name, const QString& unit )
|
||||
{
|
||||
m_results.push_back( RigThermalFractureResult( name, unit ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<std::pair<QString, QString>> RigThermalFractureDefinition::getPropertyNamesUnits() const
|
||||
{
|
||||
std::vector<std::pair<QString, QString>> namesAndUnits;
|
||||
for ( auto r : m_results )
|
||||
namesAndUnits.push_back( std::make_pair( r.name(), r.unit() ) );
|
||||
|
||||
return namesAndUnits;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigThermalFractureDefinition::appendPropertyValue( int propertyIndex, int nodeIndex, int timeStepIndex, double value )
|
||||
{
|
||||
CAF_ASSERT( propertyIndex >= 0 );
|
||||
CAF_ASSERT( propertyIndex < static_cast<int>( m_results.size() ) );
|
||||
|
||||
m_results[propertyIndex].appendValue( nodeIndex, timeStepIndex, value );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RigThermalFractureDefinition::getPropertyValue( int propertyIndex, int nodeIndex, int timeStepIndex ) const
|
||||
{
|
||||
return m_results[propertyIndex].getValue( nodeIndex, timeStepIndex );
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RiaDefines.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <vector>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RigThermalFractureResult
|
||||
{
|
||||
public:
|
||||
RigThermalFractureResult( const QString& name, const QString& unit )
|
||||
: m_name( name )
|
||||
, m_unit( unit )
|
||||
{
|
||||
}
|
||||
|
||||
QString name() { return m_name; }
|
||||
QString unit() { return m_unit; }
|
||||
|
||||
void appendValue( int nodeIndex, int timeStepIndex, double value )
|
||||
{
|
||||
if ( nodeIndex >= static_cast<int>( parameterValues.size() ) )
|
||||
parameterValues.push_back( { value } );
|
||||
else
|
||||
parameterValues[nodeIndex].push_back( value );
|
||||
}
|
||||
|
||||
double getValue( int nodeIndex, int timeStepIndex ) const { return parameterValues[nodeIndex][timeStepIndex]; }
|
||||
|
||||
size_t numNodes() const { return parameterValues.size(); }
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_unit;
|
||||
|
||||
// Vector for each time step for each node
|
||||
std::vector<std::vector<double>> parameterValues;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RigThermalFractureDefinition
|
||||
{
|
||||
public:
|
||||
RigThermalFractureDefinition();
|
||||
~RigThermalFractureDefinition();
|
||||
|
||||
void setName( const QString& name );
|
||||
QString name() const;
|
||||
|
||||
const std::vector<double>& timeSteps() const;
|
||||
void addTimeStep( double timeStep );
|
||||
size_t numTimeSteps() const;
|
||||
|
||||
size_t numNodes() const;
|
||||
|
||||
void addProperty( const QString& name, const QString& unit );
|
||||
|
||||
std::vector<std::pair<QString, QString>> getPropertyNamesUnits() const;
|
||||
|
||||
void appendPropertyValue( int propertyIndex, int nodeIndex, int timeStepIndex, double value );
|
||||
|
||||
double getPropertyValue( int propertyIndex, int nodeIndex, int timeStepIndex ) const;
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
|
||||
std::vector<double> m_timeSteps;
|
||||
std::vector<RigThermalFractureResult> m_results;
|
||||
};
|
@ -72,6 +72,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifElasticPropertiesReader-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStatisticsTools-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanXmlReader-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifThermalFractureReader-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigWellPathGeometryExporter-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanModelDeviationFrkExporter-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifSummaryDataReader-Test.cpp
|
||||
|
@ -0,0 +1,45 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RiaTestDataDirectory.h"
|
||||
|
||||
#include "RifThermalFractureReader.h"
|
||||
#include "RigThermalFractureDefinition.h"
|
||||
|
||||
static const QString CASE_REAL_TEST_DATA_DIRECTORY = QString( "%1/RifThermalFractureReader/" ).arg( TEST_DATA_DIR );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RifThermalFractureReaderTest, LoadFile )
|
||||
{
|
||||
QString fileName = CASE_REAL_TEST_DATA_DIRECTORY + "fracture_metric.csv";
|
||||
|
||||
auto [fractureData, errorMessage] = RifThermalFractureReader::readFractureCsvFile( fileName );
|
||||
|
||||
EXPECT_TRUE( errorMessage.isEmpty() );
|
||||
EXPECT_TRUE( fractureData.get() );
|
||||
|
||||
EXPECT_EQ( "frac01", fractureData->name().toStdString() );
|
||||
|
||||
EXPECT_EQ( fractureData->numNodes(), 57u );
|
||||
|
||||
EXPECT_EQ( fractureData->numTimeSteps(), 29u );
|
||||
|
||||
auto properties = fractureData->getPropertyNamesUnits();
|
||||
EXPECT_EQ( properties.size(), 19u );
|
||||
EXPECT_EQ( properties[0].first.toStdString(), "XCoord" );
|
||||
EXPECT_EQ( properties[0].second.toStdString(), "m" );
|
||||
|
||||
// The location of the center node is the same for all timesteps
|
||||
double centerNodeX = 459352.0;
|
||||
double centerNodeY = -7.32599e+06;
|
||||
double centerNodeZ = 2735.0;
|
||||
|
||||
int nodeIndex = 0;
|
||||
for ( size_t timeStepIndex = 0; timeStepIndex < fractureData->numTimeSteps(); timeStepIndex++ )
|
||||
{
|
||||
EXPECT_DOUBLE_EQ( centerNodeX, fractureData->getPropertyValue( 0, nodeIndex, static_cast<int>( timeStepIndex ) ) );
|
||||
EXPECT_DOUBLE_EQ( centerNodeY, fractureData->getPropertyValue( 1, nodeIndex, static_cast<int>( timeStepIndex ) ) );
|
||||
EXPECT_DOUBLE_EQ( centerNodeZ, fractureData->getPropertyValue( 2, nodeIndex, static_cast<int>( timeStepIndex ) ) );
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user