mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-27 07:30:20 -05:00
Implement timeline-based event system for managing temporal changes in well completions, perforations, valves, and production controls. Features: - Event timeline container with date-based querying - Six event types: PERF, VALVE, TUBING, WSTATE, WTYPE, WCONTROL - Schedule keyword generation (DATES, COMPDAT, WELSEGS, WCONPROD, WCONINJE) - Multi-well schedule generation support - Python GRPC API for event management - YAML configuration file support - Comprehensive test suite Implementation: - New directory: ApplicationLibCode/ProjectDataModel/WellEvents/ - Event classes inherit from RimWellEvent base class - RimWellEventTimeline integrated into RimWellPath - RicScheduleDataGenerator for multi-well schedule export - Python API: event_timeline(), add_perf_event(), add_valve_event(), etc. - Tests verify all event types and YAML config parsing #13425 Add date tracking to valves and diameter/roughness intervals Add creation date fields to RimWellPathValve and RimDiameterRoughnessInterval to support filtering objects by date during completion data export. - Add m_useCustomStartDate and m_startDate fields - Add enableCustomStartDate(), setCustomStartDate(), isActiveOnDate() methods - Set creation dates when applying valve and tubing events in RimWellEventTimeline #13425 Add date-based filtering for schedule data export Add optional export date parameter to MSW data collection functions to filter valves and perforations based on their creation dates during schedule export. - Add exportDate parameter to collectWsegvalvData, collectWsegAicdData, collectWsegSicdData, and collectCompsegData functions - Filter valves by checking isActiveOnDate() on the associated RimWellPathValve - Add RimPerforationInterval reference to RicMswPerforation for date filtering - Pass export date from RicScheduleDataGenerator through the extraction chain This ensures segment numbers reflect the full model while only including objects active on the export date in output keywords. Add test to prove compsegs changes over time. #13425 Fix mypy type checking errors in well_events.py - Add type annotations to all function parameters - Fix generic type hints (dict -> Dict[str, Any]) - Import Any type for proper type safety - Add type: ignore for method reassignment - All 31 tests pass #13425 Add schedule-level keyword events for non-well-specific keywords Add a new event type called "Keyword Event" for schedule-level Eclipse keywords (RPTRST, GRUPTREE, RPTSCHED, etc.) that are NOT tied to a specific well path. This complements the existing RimWellEventKeyword which operates at the well level. - Add RimKeywordEvent class inheriting from RimWellEvent with null wellPath - Add SCHEDULE_KEYWORD enum value to EventType - Add addKeywordEvent() method to RimWellEventTimeline - Add AddKeywordEvent Python API method to RimcWellEventTimeline - Update RicScheduleDataGenerator to output global keywords after well sections - Add Python wrapper add_keyword_event() with type inference - Add tests and examples for RPTRST, GRUPTREE keywords
211 lines
9.5 KiB
C++
211 lines
9.5 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2025- 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 "RifEventKeywordFormatter.h"
|
|
|
|
#include "RifOpmDeckTools.h"
|
|
#include "RimWellEvent.h"
|
|
#include "RimWellEventControl.h"
|
|
#include "RimWellEventKeyword.h"
|
|
#include "RimWellEventKeywordItem.h"
|
|
|
|
#include "RiaLogging.h"
|
|
|
|
#include "cafAppEnum.h"
|
|
|
|
#include "opm/input/eclipse/Deck/DeckKeyword.hpp"
|
|
#include "opm/input/eclipse/Deck/DeckOutput.hpp"
|
|
#include "opm/input/eclipse/Deck/DeckRecord.hpp"
|
|
#include "opm/input/eclipse/Parser/Parser.hpp"
|
|
#include "opm/input/eclipse/Parser/ParserKeyword.hpp"
|
|
#include "opm/input/eclipse/Parser/ParserKeywords/W.hpp"
|
|
|
|
#include <sstream>
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RifEventKeywordFormatter::formatKeyword( const QString& keywordName, const std::vector<RimWellEventKeywordItem*>& items )
|
|
{
|
|
QString keyword = keywordName.toUpper();
|
|
std::string kwName = keyword.toStdString();
|
|
|
|
try
|
|
{
|
|
Opm::Parser parser;
|
|
const Opm::ParserKeyword& parserKw = parser.getKeyword( kwName );
|
|
Opm::DeckKeyword kw( parserKw );
|
|
|
|
// Build deck items from stored data
|
|
std::vector<Opm::DeckItem> deckItems;
|
|
for ( const auto* item : items )
|
|
{
|
|
switch ( item->itemType() )
|
|
{
|
|
case RimWellEventKeywordItem::ItemType::STRING:
|
|
deckItems.push_back( RifOpmDeckTools::item( item->itemName().toStdString(), item->stringValue().toStdString() ) );
|
|
break;
|
|
case RimWellEventKeywordItem::ItemType::INTEGER:
|
|
deckItems.push_back( RifOpmDeckTools::item( item->itemName().toStdString(), item->intValue() ) );
|
|
break;
|
|
case RimWellEventKeywordItem::ItemType::DOUBLE:
|
|
deckItems.push_back( RifOpmDeckTools::item( item->itemName().toStdString(), item->doubleValue() ) );
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ( !deckItems.empty() )
|
|
{
|
|
kw.addRecord( Opm::DeckRecord{ std::move( deckItems ) } );
|
|
}
|
|
|
|
// Return empty string if keyword creation failed
|
|
if ( kw.name().empty() )
|
|
{
|
|
return "";
|
|
}
|
|
|
|
// Format with OPM DeckOutput
|
|
std::ostringstream oss;
|
|
Opm::DeckOutput out( oss, 10 );
|
|
kw.write( out );
|
|
return QString::fromStdString( oss.str() );
|
|
}
|
|
catch ( const std::exception& e )
|
|
{
|
|
RiaLogging::error( QString( "Failed to create keyword '%1': %2" ).arg( keyword ).arg( e.what() ) );
|
|
return "";
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RifEventKeywordFormatter::formatWconprod( const RimWellEventControl* controlEvent, const QString& wellName )
|
|
{
|
|
using W = Opm::ParserKeywords::WCONPROD;
|
|
|
|
std::vector<Opm::DeckItem> items;
|
|
|
|
items.push_back( RifOpmDeckTools::item( W::WELL::itemName, wellName.toStdString() ) );
|
|
|
|
QString statusStr = caf::AppEnum<RimWellEventControl::WellStatus>( controlEvent->wellStatus() ).text();
|
|
items.push_back( RifOpmDeckTools::item( W::STATUS::itemName, statusStr.toStdString() ) );
|
|
|
|
QString controlModeStr = caf::AppEnum<RimWellEventControl::ControlMode>( controlEvent->controlMode() ).text();
|
|
items.push_back( RifOpmDeckTools::item( W::CMODE::itemName, controlModeStr.toStdString() ) );
|
|
|
|
items.push_back(
|
|
RifOpmDeckTools::optionalItem( W::ORAT::itemName,
|
|
controlEvent->oilRate() > 0.0 ? std::optional<double>( controlEvent->oilRate() ) : std::nullopt ) );
|
|
items.push_back( RifOpmDeckTools::optionalItem( W::WRAT::itemName,
|
|
controlEvent->waterRate() > 0.0 ? std::optional<double>( controlEvent->waterRate() )
|
|
: std::nullopt ) );
|
|
items.push_back(
|
|
RifOpmDeckTools::optionalItem( W::GRAT::itemName,
|
|
controlEvent->gasRate() > 0.0 ? std::optional<double>( controlEvent->gasRate() ) : std::nullopt ) );
|
|
items.push_back( RifOpmDeckTools::optionalItem( W::LRAT::itemName,
|
|
controlEvent->liquidRate() > 0.0 ? std::optional<double>( controlEvent->liquidRate() )
|
|
: std::nullopt ) );
|
|
items.push_back( RifOpmDeckTools::defaultItem( W::RESV::itemName ) );
|
|
items.push_back( RifOpmDeckTools::optionalItem( W::BHP::itemName,
|
|
controlEvent->bhpLimit() > 0.0 ? std::optional<double>( controlEvent->bhpLimit() )
|
|
: std::nullopt ) );
|
|
items.push_back( RifOpmDeckTools::optionalItem( W::THP::itemName,
|
|
controlEvent->thpLimit() > 0.0 ? std::optional<double>( controlEvent->thpLimit() )
|
|
: std::nullopt ) );
|
|
|
|
Opm::DeckKeyword kw{ W() };
|
|
kw.addRecord( Opm::DeckRecord{ std::move( items ) } );
|
|
|
|
std::ostringstream oss;
|
|
Opm::DeckOutput out( oss, 10 );
|
|
kw.write( out );
|
|
return QString::fromStdString( oss.str() );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RifEventKeywordFormatter::formatWconinje( const RimWellEventControl* controlEvent, const QString& wellName )
|
|
{
|
|
using W = Opm::ParserKeywords::WCONINJE;
|
|
|
|
std::vector<Opm::DeckItem> items;
|
|
|
|
items.push_back( RifOpmDeckTools::item( W::WELL::itemName, wellName.toStdString() ) );
|
|
items.push_back( RifOpmDeckTools::item( W::TYPE::itemName, "WATER" ) );
|
|
|
|
QString statusStr = caf::AppEnum<RimWellEventControl::WellStatus>( controlEvent->wellStatus() ).text();
|
|
items.push_back( RifOpmDeckTools::item( W::STATUS::itemName, statusStr.toStdString() ) );
|
|
|
|
QString controlModeStr = caf::AppEnum<RimWellEventControl::ControlMode>( controlEvent->controlMode() ).text();
|
|
items.push_back( RifOpmDeckTools::item( W::CMODE::itemName, controlModeStr.toStdString() ) );
|
|
|
|
items.push_back( RifOpmDeckTools::optionalItem( W::RATE::itemName,
|
|
controlEvent->controlValue() > 0.0 ? std::optional<double>( controlEvent->controlValue() )
|
|
: std::nullopt ) );
|
|
items.push_back( RifOpmDeckTools::defaultItem( W::RESV::itemName ) );
|
|
items.push_back( RifOpmDeckTools::optionalItem( W::BHP::itemName,
|
|
controlEvent->bhpLimit() > 0.0 ? std::optional<double>( controlEvent->bhpLimit() )
|
|
: std::nullopt ) );
|
|
items.push_back( RifOpmDeckTools::optionalItem( W::THP::itemName,
|
|
controlEvent->thpLimit() > 0.0 ? std::optional<double>( controlEvent->thpLimit() )
|
|
: std::nullopt ) );
|
|
|
|
Opm::DeckKeyword kw{ W() };
|
|
kw.addRecord( Opm::DeckRecord{ std::move( items ) } );
|
|
|
|
std::ostringstream oss;
|
|
Opm::DeckOutput out( oss, 10 );
|
|
kw.write( out );
|
|
return QString::fromStdString( oss.str() );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RifEventKeywordFormatter::formatWellEvent( const RimWellEvent* event, const QString& wellName )
|
|
{
|
|
if ( event->eventType() == RimWellEvent::EventType::WCONTROL )
|
|
{
|
|
auto* controlEvent = dynamic_cast<const RimWellEventControl*>( event );
|
|
if ( controlEvent )
|
|
{
|
|
if ( controlEvent->isProducer() )
|
|
{
|
|
return formatWconprod( controlEvent, wellName );
|
|
}
|
|
else
|
|
{
|
|
return formatWconinje( controlEvent, wellName );
|
|
}
|
|
}
|
|
}
|
|
else if ( event->eventType() == RimWellEvent::EventType::KEYWORD )
|
|
{
|
|
auto* keywordEvent = dynamic_cast<const RimWellEventKeyword*>( event );
|
|
if ( keywordEvent )
|
|
{
|
|
return formatKeyword( keywordEvent->keywordName(), keywordEvent->items() );
|
|
}
|
|
}
|
|
|
|
return {};
|
|
}
|