Files
ResInsight/ApplicationLibCode/FileInterface/RifOpmFlowDeckFile.h
T
Kristian Bendiksen 65f16d04ef #14622 Sector export: Preserve separate include files for ACTNUM and FAULTS
Sector model export removed all ACTNUM and FAULTS keywords from the deck
and re-inserted the sector-specific replacements at the end of the GRID
section, which always lands in the main DATA file. Decks that keep these
keywords in separate include files lost their file organization, leaving
the original include files empty while the data was written inline.

Collapse duplicates to a single occurrence instead of removing all
occurrences, so the subsequent in-place replacement keeps the keyword in
its original file when the deck is saved with OutputMode::COPY. ACTNUM
keeps the last occurrence since a later ACTNUM overrides an earlier one;
FAULTS keeps the first so fault definitions do not move past keywords
referencing them.
2026-08-31 20:14:38 +02:00

123 lines
5.2 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <ctime>
#include <expected>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <vector>
#include "opm/input/eclipse/Deck/FileDeck.hpp"
namespace Opm
{
class Deck;
class DeckKeyword;
class DeckItem;
class DeckRecord;
class ParseContext;
} // namespace Opm
//==================================================================================================
///
///
//==================================================================================================
class RifOpmFlowDeckFile
{
public:
RifOpmFlowDeckFile();
~RifOpmFlowDeckFile();
std::expected<void, std::string> loadDeck( std::string filename );
bool saveDeck( std::string folder, std::string filename );
bool saveDeckInline( std::string folder, std::string filename );
int addKeywordAtPosition( int deckPosition, const Opm::DeckKeyword& keyword );
bool addKeywordAtTimeStep( int timeStep, const Opm::DeckKeyword& keyword, std::string insertAfterKeyword = "" );
int mergeKeywordAtPosition( int deckPosition, const Opm::DeckKeyword& keyword );
bool mergeKeywordAtTimeStep( int timeStep, const Opm::DeckKeyword& keyword, std::string insertAfterKeyword = "" );
bool openWellAtTimeStep( int timeStep, Opm::DeckKeyword& openKeyword );
bool openWellAtDeckPosition( int deckPosition, Opm::DeckKeyword& openKeyword );
bool restartAtTimeStep( int timeStep, std::string deckName );
bool stopAtTimeStep( int timeStep );
std::vector<std::string> keywords( bool includeDates = true );
std::optional<Opm::DeckKeyword> findKeyword( const std::string& keyword );
std::vector<Opm::DeckKeyword> findAllKeywords( const std::string& keyword );
std::vector<std::pair<Opm::FileDeck::Index, Opm::DeckKeyword>> findAllKeywordsWithIndices( const std::string& keyword );
bool hasDatesKeyword();
bool isRestartFile();
std::vector<std::string> dateStrings();
std::vector<std::time_t> dates();
bool appendDateKeywords( const std::vector<std::time_t>& dates );
std::set<std::string> wellGroupsInFile();
std::vector<int> welldims();
bool setWelldims( int maxWells, int maxConnections, int maxGroups, int maxWellsInGroup );
std::vector<int> wsegdims();
bool setWsegdims( int maxMSWells, int maxSegmentsPerWell, int maxBranchesPerWell );
bool setSpecgrid( int nx, int ny, int nz );
bool setDimens( int nx, int ny, int nz );
std::vector<int> regdims();
bool setRegdims( int maxRegions,
int maxRegionDefinitions,
int maxRegionFlowConnections,
int maxFIPRegions,
int maxEtrack,
int maxCompRegions,
int maxOperNum );
bool ensureRegdimsKeyword();
bool addIncludeKeyword( std::string section, std::string keyword, std::string filePath );
Opm::FileDeck* fileDeck();
const Opm::Deck* deck() const;
bool addKeyword( const std::string& section, const Opm::DeckKeyword& keyword );
bool replaceKeyword( const std::string& section, const Opm::DeckKeyword& keyword );
bool insertKeywordAtSectionStart( const std::string& section, const Opm::DeckKeyword& keyword );
bool replaceKeyword( const std::string& keyword, const std::vector<double>& data, bool dataKeyword = false );
bool replaceKeyword( const std::string& keyword, const std::vector<int>& data, bool dataKeyword = false );
bool replaceAllKeywords( const std::string& keywordName, const std::vector<Opm::DeckKeyword>& keywords );
bool replaceKeywordAtIndex( const Opm::FileDeck::Index& index, const Opm::DeckKeyword& keyword );
int removeKeywords( const std::string& keywordName );
int removeDuplicateKeywords( const std::string& keywordName, bool keepFirstOccurrence );
bool removeKeywordAtIndex( const Opm::FileDeck::Index& index );
private:
void splitDatesIfNecessary();
private:
std::unique_ptr<Opm::Deck> m_deck;
std::unique_ptr<Opm::FileDeck> m_fileDeck;
};