mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 15:10:22 -05:00
The schedule generator previously concatenated full keyword blocks (`KEYWORD ... /\n/\n`) — one per well — producing verbose output where each WELSPECS / COMPDAT / WCONHIST / WELSEGS / COMPSEGS / etc. block appeared once per contributing well. Eclipse keywords are designed to hold multiple records under a single header; the per-well repetition is syntactically valid but bloats the file and obscures intent. Switch `RicScheduleDataGenerator` to accumulate `std::map<QString, Opm::DeckKeyword>` instead of raw concatenated text. Each per-well helper now returns an `Opm::DeckKeyword`, and a new `mergeKeyword` primitive appends its records into the accumulator entry, creating the entry from the helper's keyword on first encounter. At emission time each accumulated keyword is serialised once. To support this, `RifEventKeywordFormatter` is split: each `format*` QString function now wraps a corresponding `build*` function that returns `std::optional<Opm::DeckKeyword>`. `RimWellEventKeyword` and `RimKeywordEvent` expose a parallel `generateDeckKeyword` accessor. The text-scraping `extractKeywordName` helper becomes dead code and is removed.
162 lines
6.1 KiB
C++
162 lines
6.1 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 "RimWellEventKeyword.h"
|
|
|
|
#include "RimWellEventKeywordItem.h"
|
|
|
|
#include "FileInterface/RifEventKeywordFormatter.h"
|
|
|
|
#include "opm/input/eclipse/Deck/DeckKeyword.hpp"
|
|
|
|
#include "cafPdmFieldScriptingCapability.h"
|
|
#include "cafPdmObjectScriptingCapability.h"
|
|
#include "cafPdmUiOrdering.h"
|
|
#include "cafPdmUiTreeOrdering.h"
|
|
|
|
CAF_PDM_SOURCE_INIT( RimWellEventKeyword, "WellEventKeyword" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimWellEventKeyword::RimWellEventKeyword()
|
|
{
|
|
CAF_PDM_InitScriptableObject( "Well Keyword Event", "", "", "WellEventKeyword" );
|
|
|
|
CAF_PDM_InitScriptableField( &m_keywordName, "KeywordName", QString(), "Keyword Name" );
|
|
CAF_PDM_InitFieldNoDefault( &m_items, "Items", "Items" );
|
|
|
|
setDeletable( true );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimWellEventKeyword::~RimWellEventKeyword()
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RimWellEventKeyword::keywordName() const
|
|
{
|
|
return m_keywordName();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellEventKeyword::setKeywordName( const QString& keyword )
|
|
{
|
|
m_keywordName = keyword;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellEventKeyword::addStringItem( const QString& name, const QString& value )
|
|
{
|
|
auto* item = new RimWellEventKeywordItem();
|
|
item->setItemName( name );
|
|
item->setStringValue( value );
|
|
m_items.push_back( item );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellEventKeyword::addIntItem( const QString& name, int value )
|
|
{
|
|
auto* item = new RimWellEventKeywordItem();
|
|
item->setItemName( name );
|
|
item->setIntValue( value );
|
|
m_items.push_back( item );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellEventKeyword::addDoubleItem( const QString& name, double value )
|
|
{
|
|
auto* item = new RimWellEventKeywordItem();
|
|
item->setItemName( name );
|
|
item->setDoubleValue( value );
|
|
m_items.push_back( item );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellEventKeyword::addFlagItem( const QString& name )
|
|
{
|
|
auto* item = new RimWellEventKeywordItem();
|
|
item->setItemName( name );
|
|
item->setFlag();
|
|
m_items.push_back( item );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::vector<RimWellEventKeywordItem*> RimWellEventKeyword::items() const
|
|
{
|
|
std::vector<RimWellEventKeywordItem*> result;
|
|
for ( const auto& item : m_items )
|
|
{
|
|
if ( item.notNull() )
|
|
{
|
|
result.push_back( item.p() );
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RimWellEventKeyword::generateScheduleKeyword( const QString& wellName ) const
|
|
{
|
|
return RifEventKeywordFormatter::formatKeyword( m_keywordName(), items() );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::optional<Opm::DeckKeyword> RimWellEventKeyword::generateDeckKeyword( const QString& wellName ) const
|
|
{
|
|
return RifEventKeywordFormatter::buildKeyword( m_keywordName(), items() );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellEventKeyword::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
|
{
|
|
uiOrdering.add( &m_keywordName );
|
|
uiOrdering.add( &m_items );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellEventKeyword::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName )
|
|
{
|
|
uiTreeOrdering.add( &m_items );
|
|
}
|