Skip to content

Commit

Permalink
Reveal: dump StimPlan XML for debugging thermal completions.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Sep 22, 2023
1 parent 4dd4ddc commit 748993f
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "RicWellPathFractureTextReportFeatureImpl.h"

#include "RifTextDataTableFormatter.h"
#include "RifThermalToStimPlanFractureXmlOutput.h"

#include "RigActiveCellInfo.h"
#include "RigCaseCellResultsData.h"
Expand All @@ -60,6 +61,7 @@
#include "RimPerforationInterval.h"
#include "RimProject.h"
#include "RimSimWellInView.h"
#include "RimThermalFractureTemplate.h"
#include "RimWellPath.h"
#include "RimWellPathCollection.h"
#include "RimWellPathCompletions.h"
Expand Down Expand Up @@ -139,6 +141,29 @@ void RicWellPathExportCompletionDataFeatureImpl::exportCompletions( const std::v
fractureTransmissibilityExportInformationStream =
std::make_unique<QTextStream>( &fractureTransmissibilityExportInformationFile );
}

// Extra debugging for thermal fractures
if ( exportSettings.includeFractures() )
{
for ( RimWellPath* wellPath : wellPaths )
{
std::vector<RimWellPath*> allWellPathLaterals = wellPath->allWellPathLaterals();
for ( auto wellPathLateral : allWellPathLaterals )
{
for ( auto& frac : wellPathLateral->fractureCollection()->activeFractures() )
{
if ( RimThermalFractureTemplate* fractureTemplate =
dynamic_cast<RimThermalFractureTemplate*>( frac->fractureTemplate() ) )
{
QString name = frac->name();
QString fractureXmlPath = QDir( exportSettings.folder ).absoluteFilePath( name + ".xml" );

RifThermalToStimPlanFractureXmlOutput::writeToFile( fractureTemplate, fractureXmlPath );
}
}
}
}
}
}

std::vector<RigCompletionData> completions;
Expand Down
2 changes: 2 additions & 0 deletions ApplicationLibCode/FileInterface/CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RifReaderOpmCommon.h
${CMAKE_CURRENT_LIST_DIR}/RifInpExportTools.h
${CMAKE_CURRENT_LIST_DIR}/RifFaultReactivationModelExporter.h
${CMAKE_CURRENT_LIST_DIR}/RifThermalToStimPlanFractureXmlOutput.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand Down Expand Up @@ -177,6 +178,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RifReaderOpmCommon.cpp
${CMAKE_CURRENT_LIST_DIR}/RifInpExportTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RifFaultReactivationModelExporter.cpp
${CMAKE_CURRENT_LIST_DIR}/RifThermalToStimPlanFractureXmlOutput.cpp
)

list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2023- 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 "RifThermalToStimPlanFractureXmlOutput.h"

#include "RigFractureGrid.h"

#include "RimThermalFractureTemplate.h"

#include <QFile>
#include <QTextStream>

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifThermalToStimPlanFractureXmlOutput::writeToFile( RimThermalFractureTemplate* fractureTemplate, const QString& filepath )
{
CAF_ASSERT( fractureTemplate );

QFile data( filepath );
if ( !data.open( QFile::WriteOnly | QFile::Truncate ) ) return false;

// Can use a fake depths here: depths must be adjusted when importing
double fakeDepth = 1000.0;
cvf::cref<RigFractureGrid> fractureGrid = fractureTemplate->createFractureGrid( fakeDepth );
if ( fractureGrid.isNull() ) return false;

QTextStream stream( &data );
appendHeaderToStream( stream );

appendGridDefinitionToStream( stream, *fractureGrid );

appendPropertiesToStream( stream, *fractureTemplate, *fractureGrid );

appendFooterToStream( stream );

return true;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifThermalToStimPlanFractureXmlOutput::appendHeaderToStream( QTextStream& stream )
{
stream << "<?xml version=\"1.0\" ?>" << '\n' << "<contours>" << '\n';
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifThermalToStimPlanFractureXmlOutput::appendGridDefinitionToStream( QTextStream& stream, const RigFractureGrid& fractureGrid )
{
size_t xCount = fractureGrid.iCellCount();
size_t yCount = fractureGrid.jCellCount();

stream << QString( "<grid xCount=\"%1\" yCount=\"%2\" uom=\"m\">" ).arg( xCount ).arg( yCount );

std::vector<double> xs;
for ( size_t i = 0; i < xCount; i++ )
{
size_t idx = fractureGrid.getGlobalIndexFromIJ( i, 0 );
auto fractureCell = fractureGrid.cellFromIndex( idx );
xs.push_back( fractureCell.centerPosition().x() );
}

std::vector<double> ys;
for ( size_t j = 0; j < yCount; j++ )
{
size_t idx = fractureGrid.getGlobalIndexFromIJ( 0, j );
auto fractureCell = fractureGrid.cellFromIndex( idx );
ys.push_back( -fractureCell.centerPosition().y() );
}

appendDataVector( stream, "xs", xs );
appendDataVector( stream, "ys", ys );

stream << "</grid>\n";
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifThermalToStimPlanFractureXmlOutput::appendPropertiesToStream( QTextStream& stream,
const RimThermalFractureTemplate& fractureTemplate,
const RigFractureGrid& fractureGrid )
{
stream << "<properties>\n";

auto resultNamesWithUnit = fractureTemplate.uiResultNamesWithUnit();

for ( auto [name, unit] : resultNamesWithUnit )
{
stream << QString( "<property name=\"%1\" uom=\"%2\">\n" ).arg( name ).arg( unit );
stream << "<time value=\"1\">\n";

std::vector<std::vector<double>> results = fractureTemplate.resultValues( name, unit, fractureTemplate.activeTimeStepIndex() );

for ( int j = static_cast<int>( fractureGrid.jCellCount() ) - 1; j >= 0; j-- )
{
size_t idx = fractureGrid.getGlobalIndexFromIJ( 0, j );
auto fractureCell = fractureGrid.cellFromIndex( idx );
double depth = -fractureCell.centerPosition().y();

stream << QString( "<depth>%1</depth>\n" ).arg( depth );

std::vector<double> data;
for ( size_t i = 1; i < results[j].size() - 1; i++ )
data.push_back( results[j][i] );

appendDataVector( stream, "data", data );
}

stream << "</time>\n";
stream << "</property>\n";
}
stream << "</properties>\n";
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifThermalToStimPlanFractureXmlOutput::appendDataVector( QTextStream& stream, const QString& name, const std::vector<double>& vals )
{
stream << QString( "<%1>[" ).arg( name );

for ( auto v : vals )
{
stream << v << " ";
}

stream << QString( "]</%1>\n" ).arg( name );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifThermalToStimPlanFractureXmlOutput::appendFooterToStream( QTextStream& stream )
{
stream << "</contours>" << '\n';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2023- 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 <vector>

class RimThermalFractureTemplate;
class RigFractureGrid;

class QString;
class QTextStream;

//==================================================================================================
//
//==================================================================================================
class RifThermalToStimPlanFractureXmlOutput
{
public:
static bool writeToFile( RimThermalFractureTemplate* fractureTemplate, const QString& filepath );

private:
static void appendHeaderToStream( QTextStream& stream );

static void appendPropertiesToStream( QTextStream& stream,
const RimThermalFractureTemplate& fractureTemplate,
const RigFractureGrid& fractureGrid );

static void appendGridDefinitionToStream( QTextStream& stream, const RigFractureGrid& fractureGrid );

static void appendDataVector( QTextStream& stream, const QString& name, const std::vector<double>& vals );

static void appendFooterToStream( QTextStream& stream );
};
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ RimMeshFractureTemplate::~RimMeshFractureTemplate()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RimMeshFractureTemplate::activeTimeStepIndex()
int RimMeshFractureTemplate::activeTimeStepIndex() const
{
return m_activeTimeStepIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class RimMeshFractureTemplate : public RimFractureTemplate
RimMeshFractureTemplate();
~RimMeshFractureTemplate() override;

int activeTimeStepIndex();
int activeTimeStepIndex() const;

virtual void setDefaultsBasedOnFile() = 0;

Expand Down

0 comments on commit 748993f

Please sign in to comment.