#9099 Thermal Fracture Import: include perimter nodes.

This commit is contained in:
Kristian Bendiksen
2022-07-06 10:42:35 +02:00
parent 6f623e9320
commit 44c469c12c
8 changed files with 218 additions and 59 deletions

View File

@@ -44,12 +44,12 @@ std::pair<std::shared_ptr<RigThermalFractureDefinition>, QString>
QString separator = ",";
auto appendPropertyValues = [def]( int nodeIndex, int timeStepIndex, int valueOffset, const QStringList& values ) {
auto appendPropertyValues = [def]( int nodeIndex, 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 );
def->appendPropertyValue( propertyIndex, nodeIndex, value );
}
};
@@ -60,8 +60,8 @@ std::pair<std::shared_ptr<RigThermalFractureDefinition>, QString>
// The two items in the csv is name and timestep
const int valueOffset = 2;
int nodeIndex = 0;
int timeStepIndex = 0;
bool isFirstHeader = true;
bool isValidNode = false;
while ( !in.atEnd() )
{
QString line = in.readLine();
@@ -84,10 +84,9 @@ std::pair<std::shared_ptr<RigThermalFractureDefinition>, QString>
isFirstHeader = false;
}
else
else if ( isValidNode )
{
nodeIndex++;
timeStepIndex = 0;
}
}
else if ( isCenterNodeLine( line ) )
@@ -96,27 +95,22 @@ std::pair<std::shared_ptr<RigThermalFractureDefinition>, QString>
auto values = RifFileParseTools::splitLineAndTrim( line, separator );
// Second is the timestamp
QString dateString = values[1];
QString dateFormat = "dd.MM.yyyy hh:mm:ss";
QDateTime dateTime = QDateTime::fromString( dateString, dateFormat );
// Sometimes the datetime field is missing time
if ( !dateTime.isValid() )
{
QString dateFormat = "dd.MM.yyyy";
dateTime = QDateTime::fromString( dateString, dateFormat );
}
QDateTime dateTime = parseDateTime( values[1] );
def->addTimeStep( dateTime.toSecsSinceEpoch() );
//
appendPropertyValues( nodeIndex, timeStepIndex, valueOffset, values );
timeStepIndex = 0;
appendPropertyValues( nodeIndex, valueOffset, values );
isValidNode = true;
}
else if ( isInternalNodeLine( line ) )
else if ( isInternalNodeLine( line ) || isPerimeterNodeLine( line ) )
{
auto values = RifFileParseTools::splitLineAndTrim( line, separator );
appendPropertyValues( nodeIndex, timeStepIndex, valueOffset, values );
timeStepIndex = 0;
appendPropertyValues( nodeIndex, valueOffset, values );
isValidNode = true;
}
else
{
isValidNode = false;
}
lineNumber++;
@@ -125,6 +119,23 @@ std::pair<std::shared_ptr<RigThermalFractureDefinition>, QString>
return std::make_pair( def, "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QDateTime RifThermalFractureReader::parseDateTime( const QString& dateString )
{
QString dateFormat = "dd.MM.yyyy hh:mm:ss";
QDateTime dateTime = QDateTime::fromString( dateString, dateFormat );
// Sometimes the datetime field is missing time
if ( !dateTime.isValid() )
{
QString dateFormat = "dd.MM.yyyy";
dateTime = QDateTime::fromString( dateString, dateFormat );
}
return dateTime;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -149,6 +160,20 @@ bool RifThermalFractureReader::isInternalNodeLine( const QString& line )
return line.contains( "Internal Node" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifThermalFractureReader::isPerimeterNodeLine( const QString& line )
{
std::vector<QString> validPerimeterNames = { "Perimeter Node", "Bottom Node", "Top Node", "Right Node", "Left Node" };
bool result = std::any_of( validPerimeterNames.begin(), validPerimeterNames.end(), [line]( const QString& str ) {
return line.contains( str );
} );
return result;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -18,12 +18,16 @@
#pragma once
#include <QDateTime>
#include <QString>
#include <memory>
class RigThermalFractureDefinition;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RifThermalFractureReader
{
public:
@@ -33,6 +37,9 @@ private:
static bool isHeaderLine( const QString& line );
static bool isCenterNodeLine( const QString& line );
static bool isInternalNodeLine( const QString& line );
static bool isPerimeterNodeLine( const QString& line );
static QDateTime parseDateTime( const QString& dateString );
static std::pair<QString, QString> parseNameAndUnit( const QString& value );
};