2025-11-17 12:56:41 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
|
2026-03-27 19:05:09 +01:00
|
|
|
#include "RigRefinement.h"
|
2026-03-27 10:58:18 +01:00
|
|
|
|
2025-11-17 12:56:41 +01:00
|
|
|
#include "cafVecIjk.h"
|
2025-11-19 12:27:58 +01:00
|
|
|
#include "cvfArray.h"
|
2026-10-19 14:50:22 +02:00
|
|
|
#include "cvfVector3.h"
|
2025-11-17 12:56:41 +01:00
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
|
|
#include <expected>
|
2025-12-08 15:08:53 +01:00
|
|
|
#include <functional>
|
2026-02-23 20:15:04 +01:00
|
|
|
#include <set>
|
2025-11-17 12:56:41 +01:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
class RimEclipseView;
|
|
|
|
|
class RimEclipseCase;
|
2026-02-02 14:18:39 +01:00
|
|
|
class RigModelPaddingSettings;
|
2025-11-17 12:56:41 +01:00
|
|
|
class RigSimulationInputSettings;
|
|
|
|
|
class RifOpmFlowDeckFile;
|
|
|
|
|
class RigSimWellData;
|
2026-01-09 15:13:28 +01:00
|
|
|
template <typename Vec>
|
2025-12-10 10:18:21 +01:00
|
|
|
class RigBoundingBoxIjk;
|
2025-12-11 19:55:41 +01:00
|
|
|
class RigGridExportAdapter;
|
2026-01-07 16:50:55 +01:00
|
|
|
class RigMainGrid;
|
2025-11-17 12:56:41 +01:00
|
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
|
{
|
|
|
|
|
class DeckRecord;
|
|
|
|
|
class DeckKeyword;
|
|
|
|
|
} // namespace Opm
|
|
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
|
///
|
|
|
|
|
/// Tool for exporting simulation input files (sector models)
|
|
|
|
|
///
|
|
|
|
|
//==================================================================================================
|
|
|
|
|
class RigSimulationInputTool
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static std::expected<void, QString>
|
2025-11-19 12:27:58 +01:00
|
|
|
exportSimulationInput( RimEclipseCase& eclipseCase, const RigSimulationInputSettings& settings, cvf::UByteArray* visibility );
|
2025-11-17 12:56:41 +01:00
|
|
|
|
2026-03-27 19:05:09 +01:00
|
|
|
static std::expected<Opm::DeckRecord, QString>
|
|
|
|
|
processEqualsRecord( const Opm::DeckRecord& record, const caf::VecIjk0& min, const caf::VecIjk0& max, const RigRefinement& refinement );
|
|
|
|
|
|
|
|
|
|
static std::expected<Opm::DeckRecord, QString>
|
|
|
|
|
processMultiplyRecord( const Opm::DeckRecord& record, const caf::VecIjk0& min, const caf::VecIjk0& max, const RigRefinement& refinement );
|
|
|
|
|
|
|
|
|
|
static std::expected<Opm::DeckRecord, QString>
|
|
|
|
|
processBoxRecord( const Opm::DeckRecord& record, const caf::VecIjk0& min, const caf::VecIjk0& max, const RigRefinement& refinement );
|
|
|
|
|
|
|
|
|
|
static std::expected<Opm::DeckRecord, QString>
|
|
|
|
|
processCopyRecord( const Opm::DeckRecord& record, const caf::VecIjk0& min, const caf::VecIjk0& max, const RigRefinement& refinement );
|
|
|
|
|
|
|
|
|
|
static std::expected<Opm::DeckRecord, QString>
|
|
|
|
|
processAddRecord( const Opm::DeckRecord& record, const caf::VecIjk0& min, const caf::VecIjk0& max, const RigRefinement& refinement );
|
|
|
|
|
|
2025-12-11 19:55:41 +01:00
|
|
|
static std::vector<int> createRefinedVisibility( const RigGridExportAdapter& gridAdapter );
|
|
|
|
|
|
2026-03-18 16:48:55 +01:00
|
|
|
static std::expected<void, QString>
|
|
|
|
|
transformKeywordsInDeckFile( RimEclipseCase* eclipseCase, const RigSimulationInputSettings& settings, RifOpmFlowDeckFile& deckFile );
|
2026-03-18 15:47:51 +01:00
|
|
|
|
2026-10-23 10:24:27 +02:00
|
|
|
// Utility: Transform global IJK to sector-relative coordinates with refinement
|
|
|
|
|
static caf::VecIjk0 transformToSectorCoordinates( const caf::VecIjk0& globalIjk, const caf::VecIjk0& min, const RigRefinement& refinement );
|
2026-01-07 16:50:55 +01:00
|
|
|
|
2026-03-20 13:05:35 +01:00
|
|
|
// Generic helper for processing keywords with box indices
|
|
|
|
|
using RecordProcessorFunc =
|
2026-03-27 19:05:09 +01:00
|
|
|
std::function<std::expected<Opm::DeckRecord, QString>( const Opm::DeckRecord&, const caf::VecIjk0&, const caf::VecIjk0&, const RigRefinement& )>;
|
2026-03-20 13:05:35 +01:00
|
|
|
|
2026-10-23 10:24:27 +02:00
|
|
|
static std::expected<void, QString> replaceKeywordWithBoxIndices( const std::string& keywordName,
|
|
|
|
|
RimEclipseCase* eclipseCase,
|
|
|
|
|
const RigSimulationInputSettings& settings,
|
|
|
|
|
RifOpmFlowDeckFile& deckFile,
|
|
|
|
|
RecordProcessorFunc processorFunc );
|
|
|
|
|
|
|
|
|
|
// Helper function to transform bounding box from global to sector coordinates
|
|
|
|
|
// Returns bounding box with 0-based sector-relative coordinates
|
|
|
|
|
static std::expected<RigBoundingBoxIjk<caf::VecIjk0>, QString>
|
|
|
|
|
transformBoxToSectorCoordinates( const RigBoundingBoxIjk<caf::VecIjk0>& inputBox,
|
|
|
|
|
const caf::VecIjk0& sectorMin,
|
|
|
|
|
const caf::VecIjk0& sectorMax,
|
|
|
|
|
const RigRefinement& refinement,
|
|
|
|
|
const QString& keywordName,
|
|
|
|
|
const QString& recordIdentifier );
|
|
|
|
|
|
|
|
|
|
// Helper function to extract IJK coordinates from a deck record
|
|
|
|
|
// Returns a VecIjk1 (1-based) constructed from values at the specified item indices
|
|
|
|
|
static caf::VecIjk1 extractIjk( const Opm::DeckRecord& record, size_t indexI, size_t indexJ, size_t indexK );
|
|
|
|
|
|
2025-11-17 12:56:41 +01:00
|
|
|
private:
|
|
|
|
|
static std::expected<void, QString> updateCornerPointGridInDeckFile( RimEclipseCase* eclipseCase,
|
|
|
|
|
const RigSimulationInputSettings& settings,
|
|
|
|
|
RifOpmFlowDeckFile& deckFile );
|
|
|
|
|
|
2026-04-23 17:51:46 +02:00
|
|
|
// Scale MINPV down by the maximum refinement factor so OPM Flow doesn't filter sub-cells
|
|
|
|
|
// whose pore volume falls below the original threshold simply because refinement shrunk
|
|
|
|
|
// them. Does nothing if MINPV is absent from the deck or the refinement is identity.
|
|
|
|
|
static std::expected<void, QString> scaleMinpvForRefinement( const RigSimulationInputSettings& settings, RifOpmFlowDeckFile& deckFile );
|
|
|
|
|
|
2025-11-17 12:56:41 +01:00
|
|
|
static std::expected<void, QString> replaceKeywordValuesInDeckFile( RimEclipseCase* eclipseCase,
|
|
|
|
|
const RigSimulationInputSettings& settings,
|
2026-03-16 17:54:38 +01:00
|
|
|
RifOpmFlowDeckFile& deckFile,
|
|
|
|
|
const std::set<std::string>& alreadyCropped = {} );
|
|
|
|
|
|
|
|
|
|
static std::set<std::string>
|
|
|
|
|
cropDataKeywordsInDeckFile( RimEclipseCase* eclipseCase, const RigSimulationInputSettings& settings, RifOpmFlowDeckFile& deckFile );
|
2025-11-17 12:56:41 +01:00
|
|
|
|
2025-12-01 09:29:45 +01:00
|
|
|
static std::expected<void, QString>
|
|
|
|
|
updateWelldimsKeyword( RimEclipseCase* eclipseCase, const RigSimulationInputSettings& settings, RifOpmFlowDeckFile& deckFile );
|
|
|
|
|
|
2025-12-11 09:49:33 +01:00
|
|
|
static std::expected<void, QString> addBorderBoundaryConditions( RimEclipseCase* eclipseCase,
|
|
|
|
|
const RigSimulationInputSettings& settings,
|
|
|
|
|
cvf::ref<cvf::UByteArray> visibility,
|
|
|
|
|
RifOpmFlowDeckFile& deckFile );
|
2025-11-17 12:56:41 +01:00
|
|
|
|
|
|
|
|
static std::expected<void, QString>
|
|
|
|
|
addFaultsToDeckFile( RimEclipseCase* eclipseCase, const RigSimulationInputSettings& settings, RifOpmFlowDeckFile& deckFile );
|
|
|
|
|
|
2026-10-19 14:50:22 +02:00
|
|
|
static std::expected<void, QString> filterAndUpdateWellKeywords( RimEclipseCase* eclipseCase,
|
|
|
|
|
std::set<std::string>& validWellNames,
|
2026-02-23 20:15:04 +01:00
|
|
|
const RigSimulationInputSettings& settings,
|
|
|
|
|
RifOpmFlowDeckFile& deckFile );
|
|
|
|
|
|
|
|
|
|
static std::expected<void, QString> updateWellListKeywords( std::set<std::string>& validWellNames,
|
|
|
|
|
const RigSimulationInputSettings& settings,
|
|
|
|
|
RifOpmFlowDeckFile& deckFile );
|
|
|
|
|
|
|
|
|
|
static std::set<std::string> wellNamesToInclude( RimEclipseCase* eclipseCase, const RigSimulationInputSettings& settings );
|
2025-11-17 12:56:41 +01:00
|
|
|
|
2026-02-02 14:18:39 +01:00
|
|
|
static std::expected<void, QString> applyModelPadding( RifOpmFlowDeckFile& deckFile, const RigModelPaddingSettings& paddingSettings );
|
|
|
|
|
|
2025-12-11 19:55:41 +01:00
|
|
|
static std::expected<void, QString> addOperNumRegionAndOperater( RifOpmFlowDeckFile& deckFile,
|
|
|
|
|
const RigGridExportAdapter& gridAdapter,
|
|
|
|
|
const std::vector<int>& operNumResult,
|
|
|
|
|
int operNumRegion,
|
|
|
|
|
double porvMultiplier );
|
2025-11-17 12:56:41 +01:00
|
|
|
|
2026-01-09 15:13:28 +01:00
|
|
|
static std::vector<RigSimWellData*> findIntersectingWells( RimEclipseCase* eclipseCase, const caf::VecIjk0& min, const caf::VecIjk0& max );
|
2025-11-17 12:56:41 +01:00
|
|
|
|
|
|
|
|
static std::expected<Opm::DeckRecord, QString>
|
|
|
|
|
processWelspecsRecord( const Opm::DeckRecord& record, const std::string& wellName, const RigSimulationInputSettings& settings );
|
|
|
|
|
};
|