///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2021- 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 "RifEnsembleFractureStatisticsExporter.h" #include "RiaDefines.h" #include "RigSlice2D.h" #include "caf.h" #include "cafAssert.h" #include #include //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RifEnsembleFractureStatisticsExporter::writeAsStimPlanXml( const std::vector>& statistics, const std::vector>& properties, const QString& filePath, const std::vector& gridXs, const std::vector& gridYs, double time, RiaDefines::EclipseUnitSystem unitSystem, RigStimPlanFractureDefinition::Orientation orientation ) { QFile data( filePath ); if ( !data.open( QFile::WriteOnly | QFile::Truncate ) ) { return false; } QTextStream stream( &data ); appendHeaderToStream( stream ); appendOrientationToStream( stream, orientation ); appendGridDimensionsToStream( stream, gridXs, gridYs, unitSystem ); appendPropertiesToStream( stream, statistics, properties, gridYs, time ); appendFooterToStream( stream ); return true; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifEnsembleFractureStatisticsExporter::appendHeaderToStream( QTextStream& stream ) { stream << "" << caf::endl << "" << caf::endl; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifEnsembleFractureStatisticsExporter::appendPropertiesToStream( QTextStream& stream, const std::vector>& statistics, const std::vector>& properties, const std::vector& gridYs, double time ) { CAF_ASSERT( statistics.size() == properties.size() ); stream << "" << caf::endl; for ( size_t s = 0; s < statistics.size(); s++ ) { QString propertyName = properties[s].first; QString propertyUnit = properties[s].second; stream << QString( "" ).arg( propertyName ).arg( propertyUnit ) << caf::endl; stream << QString( "" << caf::endl; stream << "" << caf::endl; } stream << "" << caf::endl; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifEnsembleFractureStatisticsExporter::appendOrientationToStream( QTextStream& stream, RigStimPlanFractureDefinition::Orientation orientation ) { if ( orientation != RigStimPlanFractureDefinition::Orientation::UNDEFINED ) { QString orientationString = getStringForOrientation( orientation ); stream << QString( "%1" ).arg( orientationString ) << caf::endl; } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifEnsembleFractureStatisticsExporter::appendGridDimensionsToStream( QTextStream& stream, const std::vector& gridXs, const std::vector& gridYs, RiaDefines::EclipseUnitSystem unitSystem ) { QString unitString = getStringForUnitSystem( unitSystem ); stream << QString( "" ).arg( gridXs.size() ).arg( gridYs.size() ).arg( unitString ) << caf::endl; stream << "["; for ( auto x : gridXs ) stream << x << " "; stream << "]" << caf::endl; stream << "["; for ( auto y : gridYs ) stream << y << " "; stream << "]" << caf::endl; stream << "" << caf::endl; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifEnsembleFractureStatisticsExporter::appendFooterToStream( QTextStream& stream ) { stream << "" << caf::endl; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- QString RifEnsembleFractureStatisticsExporter::getStringForUnitSystem( RiaDefines::EclipseUnitSystem unitSystem ) { if ( unitSystem == RiaDefines::EclipseUnitSystem::UNITS_METRIC ) return "m"; else if ( unitSystem == RiaDefines::EclipseUnitSystem::UNITS_FIELD ) return "ft"; else return ""; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- QString RifEnsembleFractureStatisticsExporter::getStringForOrientation( RigStimPlanFractureDefinition::Orientation orientation ) { if ( orientation == RigStimPlanFractureDefinition::Orientation::TRANSVERSE ) return "transverse"; else if ( orientation == RigStimPlanFractureDefinition::Orientation::LONGITUDINAL ) return "longitudinal"; else return ""; }