///////////////////////////////////////////////////////////////////////////////// // // 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 // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RifThermalToStimPlanFractureXmlOutput.h" #include "RigFractureGrid.h" #include "RimThermalFractureTemplate.h" #include #include //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- 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 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 << "" << '\n' << "" << '\n'; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifThermalToStimPlanFractureXmlOutput::appendGridDefinitionToStream( QTextStream& stream, const RigFractureGrid& fractureGrid ) { size_t xCount = fractureGrid.iCellCount(); size_t yCount = fractureGrid.jCellCount(); stream << QString( "" ).arg( xCount ).arg( yCount ); std::vector 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 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 << "\n"; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifThermalToStimPlanFractureXmlOutput::appendPropertiesToStream( QTextStream& stream, const RimThermalFractureTemplate& fractureTemplate, const RigFractureGrid& fractureGrid ) { stream << "\n"; auto resultNamesWithUnit = fractureTemplate.uiResultNamesWithUnit(); for ( auto [name, unit] : resultNamesWithUnit ) { stream << QString( "\n" ).arg( name ).arg( unit ); stream << "\n"; stream << "\n"; } stream << "\n"; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifThermalToStimPlanFractureXmlOutput::appendDataVector( QTextStream& stream, const QString& name, const std::vector& vals ) { stream << QString( "<%1>[" ).arg( name ); for ( auto v : vals ) { stream << v << " "; } stream << QString( "]\n" ).arg( name ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifThermalToStimPlanFractureXmlOutput::appendFooterToStream( QTextStream& stream ) { stream << "" << '\n'; }