diff --git a/ApplicationCode/FileInterface/RifStimPlanModelGeologicalFrkExporter.cpp b/ApplicationCode/FileInterface/RifStimPlanModelGeologicalFrkExporter.cpp index 2878c8d516..515309f65e 100644 --- a/ApplicationCode/FileInterface/RifStimPlanModelGeologicalFrkExporter.cpp +++ b/ApplicationCode/FileInterface/RifStimPlanModelGeologicalFrkExporter.cpp @@ -92,12 +92,24 @@ bool RifStimPlanModelGeologicalFrkExporter::writeToFile( RimStimPlanModel* stimP labels.push_back( "zoneThermalExp" ); } - std::map> values; + std::vector tvd = stimPlanModel->calculator()->calculateTrueVerticalDepth(); + // Warn if the generated model has too many layers for StimPlan + if ( tvd.size() > MAX_STIMPLAN_LAYERS ) + { + RiaLogging::warning( + QString( "Exporting model with too many layers: %1. Maximum supported number of layers is %2." ) + .arg( tvd.size() ) + .arg( MAX_STIMPLAN_LAYERS ) ); + } - std::vector tvd = stimPlanModel->calculator()->calculateTrueVerticalDepth(); + // Make sure stress gradients are in the valid interval + std::vector stressGradients = stimPlanModel->calculator()->calculateStressGradient(); + fixupStressGradients( stressGradients, MIN_STRESS_GRADIENT, MAX_STRESS_GRADIENT, DEFAULT_STRESS_GRADIENT ); + + std::map> values; values["dpthlyr"] = tvd; values["strs"] = stimPlanModel->calculator()->calculateStress(); - values["strsg"] = stimPlanModel->calculator()->calculateStressGradient(); + values["strsg"] = stressGradients; values["elyr"] = stimPlanModel->calculator()->calculateYoungsModulus(); values["poissonr"] = stimPlanModel->calculator()->calculatePoissonsRatio(); values["tuflyr"] = stimPlanModel->calculator()->calculateKIc(); @@ -114,15 +126,6 @@ bool RifStimPlanModelGeologicalFrkExporter::writeToFile( RimStimPlanModel* stimP values["zonePoroElas"] = stimPlanModel->calculator()->calculatePoroElasticConstant(); values["zoneThermalExp"] = stimPlanModel->calculator()->calculateThermalExpansionCoefficient(); - // Warn if the generated model has too many layers for StimPlan - if ( tvd.size() > MAX_STIMPLAN_LAYERS ) - { - RiaLogging::warning( - QString( "Exporting model with too many layers: %1. Maximum supported number of layers is %2." ) - .arg( tvd.size() ) - .arg( MAX_STIMPLAN_LAYERS ) ); - } - QFile data( filepath ); if ( !data.open( QFile::WriteOnly | QFile::Truncate ) ) { @@ -142,11 +145,17 @@ bool RifStimPlanModelGeologicalFrkExporter::writeToFile( RimStimPlanModel* stimP return true; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- void RifStimPlanModelGeologicalFrkExporter::appendHeaderToStream( QTextStream& stream ) { stream << "" << endl << "" << endl; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- void RifStimPlanModelGeologicalFrkExporter::appendToStream( QTextStream& stream, const QString& label, const std::vector& values ) @@ -170,7 +179,34 @@ void RifStimPlanModelGeologicalFrkExporter::appendToStream( QTextStream& stream << "" << endl << "" << endl; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- void RifStimPlanModelGeologicalFrkExporter::appendFooterToStream( QTextStream& stream ) { stream << "" << endl; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RifStimPlanModelGeologicalFrkExporter::fixupStressGradients( std::vector& stressGradients, + double minStressGradient, + double maxStressGradient, + double defaultStressGradient ) +{ + for ( size_t i = 0; i < stressGradients.size(); i++ ) + { + if ( stressGradients[i] < minStressGradient || stressGradients[i] > maxStressGradient ) + { + RiaLogging::warning( + QString( "Found stress gradient outside valid range [%1, %2]. Replacing %3 with default value: %4." ) + .arg( minStressGradient ) + .arg( maxStressGradient ) + .arg( stressGradients[i] ) + .arg( defaultStressGradient ) ); + + stressGradients[i] = defaultStressGradient; + } + } +} diff --git a/ApplicationCode/FileInterface/RifStimPlanModelGeologicalFrkExporter.h b/ApplicationCode/FileInterface/RifStimPlanModelGeologicalFrkExporter.h index 838904ee97..f546584385 100644 --- a/ApplicationCode/FileInterface/RifStimPlanModelGeologicalFrkExporter.h +++ b/ApplicationCode/FileInterface/RifStimPlanModelGeologicalFrkExporter.h @@ -30,7 +30,10 @@ class QTextStream; class RifStimPlanModelGeologicalFrkExporter { public: - static const int MAX_STIMPLAN_LAYERS = 100; + static const int MAX_STIMPLAN_LAYERS = 100; + static constexpr double MIN_STRESS_GRADIENT = 0.3; + static constexpr double MAX_STRESS_GRADIENT = 0.8; + static constexpr double DEFAULT_STRESS_GRADIENT = 0.7; static bool writeToFile( RimStimPlanModel* plot, bool useDetailedFluidLoss, const QString& filepath ); @@ -38,4 +41,9 @@ private: static void appendHeaderToStream( QTextStream& stream ); static void appendToStream( QTextStream& stream, const QString& label, const std::vector& values ); static void appendFooterToStream( QTextStream& stream ); + + static void fixupStressGradients( std::vector& stressGradients, + double minStressGradient, + double maxStressGradient, + double defaultStressGradient ); };