|
| 1 | +///////////////////////////////////////////////////////////////////////////////// |
| 2 | +// |
| 3 | +// Copyright (C) 2025- Equinor ASA |
| 4 | +// |
| 5 | +// ResInsight is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 | +// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | +// FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | +// |
| 14 | +// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> |
| 15 | +// for more details. |
| 16 | +// |
| 17 | +///////////////////////////////////////////////////////////////////////////////// |
| 18 | + |
| 19 | +#include "RicScheduleDataGenerator.h" |
| 20 | + |
| 21 | +#include "RimEclipseCase.h" |
| 22 | +#include "RimWellEventControl.h" |
| 23 | +#include "RimWellEventPerf.h" |
| 24 | +#include "RimWellEventState.h" |
| 25 | +#include "RimWellEventTimeline.h" |
| 26 | +#include "RimWellEventTubing.h" |
| 27 | +#include "RimWellEventType.h" |
| 28 | +#include "RimWellEventValve.h" |
| 29 | +#include "RimWellPath.h" |
| 30 | + |
| 31 | +#include <QLocale> |
| 32 | + |
| 33 | +#include <algorithm> |
| 34 | +#include <set> |
| 35 | + |
| 36 | +//-------------------------------------------------------------------------------------------------- |
| 37 | +/// |
| 38 | +//-------------------------------------------------------------------------------------------------- |
| 39 | +QString RicScheduleDataGenerator::generateSchedule( RimEclipseCase* eclipseCase, |
| 40 | + const std::vector<RimWellPath*>& wellPaths, |
| 41 | + const std::vector<QDateTime>& dates, |
| 42 | + const Options& options ) |
| 43 | +{ |
| 44 | + QString result; |
| 45 | + |
| 46 | + // Header |
| 47 | + result += "-- Generated by ResInsight\n"; |
| 48 | + result += "-- Schedule data based on well events\n"; |
| 49 | + result += "--\n"; |
| 50 | + |
| 51 | + // List wells |
| 52 | + if ( options.includeComments ) |
| 53 | + { |
| 54 | + result += "-- Wells: "; |
| 55 | + QStringList wellNames; |
| 56 | + for ( const auto* well : wellPaths ) |
| 57 | + { |
| 58 | + if ( well ) |
| 59 | + { |
| 60 | + wellNames.append( well->name() ); |
| 61 | + } |
| 62 | + } |
| 63 | + result += wellNames.join( ", " ); |
| 64 | + result += "\n--\n\n"; |
| 65 | + } |
| 66 | + |
| 67 | + // Sort dates chronologically |
| 68 | + std::vector<QDateTime> sortedDates = dates; |
| 69 | + std::sort( sortedDates.begin(), sortedDates.end() ); |
| 70 | + |
| 71 | + // Generate section for each date |
| 72 | + for ( const auto& date : sortedDates ) |
| 73 | + { |
| 74 | + QString dateSection = generateDateSection( eclipseCase, wellPaths, date, options ); |
| 75 | + if ( !dateSection.isEmpty() ) |
| 76 | + { |
| 77 | + result += dateSection; |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + return result; |
| 82 | +} |
| 83 | + |
| 84 | +//-------------------------------------------------------------------------------------------------- |
| 85 | +/// |
| 86 | +//-------------------------------------------------------------------------------------------------- |
| 87 | +std::vector<QDateTime> RicScheduleDataGenerator::collectAllDates( const std::vector<RimWellPath*>& wellPaths ) |
| 88 | +{ |
| 89 | + std::set<QDateTime> uniqueDates; |
| 90 | + |
| 91 | + for ( const auto* well : wellPaths ) |
| 92 | + { |
| 93 | + if ( well && well->eventTimeline() ) |
| 94 | + { |
| 95 | + auto dates = well->eventTimeline()->getAllEventDates(); |
| 96 | + for ( const auto& date : dates ) |
| 97 | + { |
| 98 | + uniqueDates.insert( date ); |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + return std::vector<QDateTime>( uniqueDates.begin(), uniqueDates.end() ); |
| 104 | +} |
| 105 | + |
| 106 | +//-------------------------------------------------------------------------------------------------- |
| 107 | +/// |
| 108 | +//-------------------------------------------------------------------------------------------------- |
| 109 | +QString RicScheduleDataGenerator::generateDateSection( RimEclipseCase* eclipseCase, |
| 110 | + const std::vector<RimWellPath*>& wellPaths, |
| 111 | + const QDateTime& date, |
| 112 | + const Options& options ) |
| 113 | +{ |
| 114 | + QString result; |
| 115 | + |
| 116 | + // Generate DATES keyword |
| 117 | + result += generateDatesKeyword( date ); |
| 118 | + |
| 119 | + // Collect all output for this date |
| 120 | + QString compdatData; |
| 121 | + QString mswData; |
| 122 | + QString wellControlData; |
| 123 | + |
| 124 | + for ( auto* well : wellPaths ) |
| 125 | + { |
| 126 | + if ( !well ) |
| 127 | + continue; |
| 128 | + |
| 129 | + if ( options.includeCompdat ) |
| 130 | + { |
| 131 | + QString wellCompdat = generateCompdatForWell( eclipseCase, well, date ); |
| 132 | + if ( !wellCompdat.isEmpty() ) |
| 133 | + { |
| 134 | + compdatData += wellCompdat; |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + if ( options.includeMsw ) |
| 139 | + { |
| 140 | + QString wellMsw = generateMswForWell( eclipseCase, well, date ); |
| 141 | + if ( !wellMsw.isEmpty() ) |
| 142 | + { |
| 143 | + mswData += wellMsw; |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + if ( options.includeWellControl ) |
| 148 | + { |
| 149 | + QString wellControl = generateWellControlForWell( well, date ); |
| 150 | + if ( !wellControl.isEmpty() ) |
| 151 | + { |
| 152 | + wellControlData += wellControl; |
| 153 | + } |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + // Output collected data |
| 158 | + if ( !compdatData.isEmpty() ) |
| 159 | + { |
| 160 | + result += compdatData; |
| 161 | + } |
| 162 | + |
| 163 | + if ( !mswData.isEmpty() ) |
| 164 | + { |
| 165 | + result += mswData; |
| 166 | + } |
| 167 | + |
| 168 | + if ( !wellControlData.isEmpty() ) |
| 169 | + { |
| 170 | + result += wellControlData; |
| 171 | + } |
| 172 | + |
| 173 | + return result; |
| 174 | +} |
| 175 | + |
| 176 | +//-------------------------------------------------------------------------------------------------- |
| 177 | +/// |
| 178 | +//-------------------------------------------------------------------------------------------------- |
| 179 | +QString RicScheduleDataGenerator::generateDatesKeyword( const QDateTime& date ) |
| 180 | +{ |
| 181 | + // Format: DATES |
| 182 | + // 1 JAN 2024 / |
| 183 | + // / |
| 184 | + |
| 185 | + QLocale locale( QLocale::English ); |
| 186 | + QString day = QString::number( date.date().day() ); |
| 187 | + QString month = locale.monthName( date.date().month(), QLocale::ShortFormat ).toUpper(); |
| 188 | + QString year = QString::number( date.date().year() ); |
| 189 | + |
| 190 | + QString result = QString( "DATES\n %1 %2 %3 /\n/\n\n" ).arg( day ).arg( month ).arg( year ); |
| 191 | + |
| 192 | + return result; |
| 193 | +} |
| 194 | + |
| 195 | +//-------------------------------------------------------------------------------------------------- |
| 196 | +/// |
| 197 | +//-------------------------------------------------------------------------------------------------- |
| 198 | +QString RicScheduleDataGenerator::generateCompdatForWell( RimEclipseCase* eclipseCase, RimWellPath* well, const QDateTime& date ) |
| 199 | +{ |
| 200 | + if ( !well || !well->eventTimeline() ) |
| 201 | + return QString(); |
| 202 | + |
| 203 | + // Get perforation events at this exact date |
| 204 | + auto events = well->eventTimeline()->getEventsAtDate( date ); |
| 205 | + |
| 206 | + QString perfEvents; |
| 207 | + for ( auto* event : events ) |
| 208 | + { |
| 209 | + if ( event->eventType() == RimWellEvent::EventType::PERF ) |
| 210 | + { |
| 211 | + perfEvents += event->generateScheduleKeyword( well->name() ); |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + if ( perfEvents.isEmpty() ) |
| 216 | + return QString(); |
| 217 | + |
| 218 | + // Note: Actual COMPDAT generation requires grid intersection calculations |
| 219 | + // This is a placeholder that generates comments with event data |
| 220 | + QString result = QString( "-- COMPDAT events for %1 at %2\n" ).arg( well->name() ).arg( date.toString( "yyyy-MM-dd" ) ); |
| 221 | + result += perfEvents; |
| 222 | + result += "\n"; |
| 223 | + |
| 224 | + return result; |
| 225 | +} |
| 226 | + |
| 227 | +//-------------------------------------------------------------------------------------------------- |
| 228 | +/// |
| 229 | +//-------------------------------------------------------------------------------------------------- |
| 230 | +QString RicScheduleDataGenerator::generateMswForWell( RimEclipseCase* eclipseCase, RimWellPath* well, const QDateTime& date ) |
| 231 | +{ |
| 232 | + if ( !well || !well->eventTimeline() ) |
| 233 | + return QString(); |
| 234 | + |
| 235 | + // Get valve and tubing events at this exact date |
| 236 | + auto events = well->eventTimeline()->getEventsAtDate( date ); |
| 237 | + |
| 238 | + QString valveEvents; |
| 239 | + QString tubingEvents; |
| 240 | + |
| 241 | + for ( auto* event : events ) |
| 242 | + { |
| 243 | + if ( event->eventType() == RimWellEvent::EventType::VALVE ) |
| 244 | + { |
| 245 | + valveEvents += event->generateScheduleKeyword( well->name() ); |
| 246 | + } |
| 247 | + else if ( event->eventType() == RimWellEvent::EventType::TUBING ) |
| 248 | + { |
| 249 | + tubingEvents += event->generateScheduleKeyword( well->name() ); |
| 250 | + } |
| 251 | + } |
| 252 | + |
| 253 | + if ( valveEvents.isEmpty() && tubingEvents.isEmpty() ) |
| 254 | + return QString(); |
| 255 | + |
| 256 | + QString result; |
| 257 | + |
| 258 | + if ( !tubingEvents.isEmpty() ) |
| 259 | + { |
| 260 | + result += QString( "-- WELSEGS tubing events for %1 at %2\n" ).arg( well->name() ).arg( date.toString( "yyyy-MM-dd" ) ); |
| 261 | + result += tubingEvents; |
| 262 | + } |
| 263 | + |
| 264 | + if ( !valveEvents.isEmpty() ) |
| 265 | + { |
| 266 | + result += QString( "-- WSEGVALV events for %1 at %2\n" ).arg( well->name() ).arg( date.toString( "yyyy-MM-dd" ) ); |
| 267 | + result += valveEvents; |
| 268 | + } |
| 269 | + |
| 270 | + result += "\n"; |
| 271 | + |
| 272 | + return result; |
| 273 | +} |
| 274 | + |
| 275 | +//-------------------------------------------------------------------------------------------------- |
| 276 | +/// |
| 277 | +//-------------------------------------------------------------------------------------------------- |
| 278 | +QString RicScheduleDataGenerator::generateWellControlForWell( RimWellPath* well, const QDateTime& date ) |
| 279 | +{ |
| 280 | + if ( !well || !well->eventTimeline() ) |
| 281 | + return QString(); |
| 282 | + |
| 283 | + // Get state and control events at this exact date |
| 284 | + auto events = well->eventTimeline()->getEventsAtDate( date ); |
| 285 | + |
| 286 | + QString result; |
| 287 | + |
| 288 | + for ( auto* event : events ) |
| 289 | + { |
| 290 | + if ( event->eventType() == RimWellEvent::EventType::WSTATE ) |
| 291 | + { |
| 292 | + result += event->generateScheduleKeyword( well->name() ); |
| 293 | + } |
| 294 | + else if ( event->eventType() == RimWellEvent::EventType::WCONTROL ) |
| 295 | + { |
| 296 | + result += event->generateScheduleKeyword( well->name() ); |
| 297 | + } |
| 298 | + else if ( event->eventType() == RimWellEvent::EventType::WTYPE ) |
| 299 | + { |
| 300 | + result += event->generateScheduleKeyword( well->name() ); |
| 301 | + } |
| 302 | + } |
| 303 | + |
| 304 | + return result; |
| 305 | +} |
| 306 | + |
| 307 | +//-------------------------------------------------------------------------------------------------- |
| 308 | +/// |
| 309 | +//-------------------------------------------------------------------------------------------------- |
| 310 | +std::vector<RimWellEvent*> RicScheduleDataGenerator::getActiveEventsAtDate( RimWellPath* well, const QDateTime& date ) |
| 311 | +{ |
| 312 | + if ( !well || !well->eventTimeline() ) |
| 313 | + return {}; |
| 314 | + |
| 315 | + return well->eventTimeline()->getEventsUpToDate( date ); |
| 316 | +} |
0 commit comments