Refactor: move simulation file/input code to separate class.

This commit is contained in:
Kristian Bendiksen committed 2025-11-17 15:48:12 +01:00
1 parent 3a8d521bc2
commit c47e8ac76f
10 files changed
+1399 -1091

No files matched your search

@@ -0,0 +1,12 @@
set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RigSimulationInputSettings.h
${CMAKE_CURRENT_LIST_DIR}/RigSimulationInputTool.h
)
set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RigSimulationInputSettings.cpp
${CMAKE_CURRENT_LIST_DIR}/RigSimulationInputTool.cpp
)
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
list(APPEND CODE_SOURCE_FILES ${SOURCE_GROUP_SOURCE_FILES})
@@ -0,0 +1,144 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RigSimulationInputSettings.h"
#include "opm/input/eclipse/Deck/DeckRecord.hpp"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigSimulationInputSettings::RigSimulationInputSettings()
: m_min( caf::VecIjk0::ZERO )
, m_max( caf::VecIjk0::ZERO )
, m_refinement( 1, 1, 1 )
, m_boundaryCondition( 0 )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::VecIjk0 RigSimulationInputSettings::min() const
{
return m_min;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::VecIjk0 RigSimulationInputSettings::max() const
{
return m_max;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigSimulationInputSettings::setMin( const caf::VecIjk0& min )
{
m_min = min;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigSimulationInputSettings::setMax( const caf::VecIjk0& max )
{
m_max = max;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec3st RigSimulationInputSettings::refinement() const
{
return m_refinement;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigSimulationInputSettings::setRefinement( const cvf::Vec3st& refinement )
{
m_refinement = refinement;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<Opm::DeckRecord> RigSimulationInputSettings::bcpropKeywords() const
{
return m_bcpropKeywords;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigSimulationInputSettings::setBcpropKeywords( const std::vector<Opm::DeckRecord>& keywords )
{
m_bcpropKeywords = keywords;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RigSimulationInputSettings::boundaryCondition() const
{
return m_boundaryCondition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigSimulationInputSettings::setBoundaryCondition( int value )
{
m_boundaryCondition = value;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RigSimulationInputSettings::inputDeckFileName() const
{
return m_inputDeckFileName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigSimulationInputSettings::setInputDeckFileName( const QString& fileName )
{
m_inputDeckFileName = fileName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RigSimulationInputSettings::outputDeckFileName() const
{
return m_outputDeckFileName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigSimulationInputSettings::setOutputDeckFileName( const QString& fileName )
{
m_outputDeckFileName = fileName;
}
@@ -0,0 +1,74 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "cafVecIjk.h"
#include "cvfVector3.h"
#include <QString>
#include <vector>
namespace Opm
{
class DeckRecord;
}
//==================================================================================================
///
/// Settings for exporting simulation input files (sector models)
///
//==================================================================================================
class RigSimulationInputSettings
{
public:
RigSimulationInputSettings();
// Sector bounds (0-based grid coordinates)
caf::VecIjk0 min() const;
caf::VecIjk0 max() const;
void setMin( const caf::VecIjk0& min );
void setMax( const caf::VecIjk0& max );
// Grid refinement
cvf::Vec3st refinement() const;
void setRefinement( const cvf::Vec3st& refinement );
// Boundary conditions
std::vector<Opm::DeckRecord> bcpropKeywords() const;
void setBcpropKeywords( const std::vector<Opm::DeckRecord>& keywords );
int boundaryCondition() const;
void setBoundaryCondition( int value );
// File paths
QString inputDeckFileName() const;
void setInputDeckFileName( const QString& fileName );
QString outputDeckFileName() const;
void setOutputDeckFileName( const QString& fileName );
private:
caf::VecIjk0 m_min;
caf::VecIjk0 m_max;
cvf::Vec3st m_refinement;
std::vector<Opm::DeckRecord> m_bcpropKeywords;
int m_boundaryCondition;
QString m_inputDeckFileName;
QString m_outputDeckFileName;
};
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,94 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "cafVecIjk.h"
#include "cvfVector3.h"
#include <QString>
#include <expected>
#include <string>
#include <vector>
class RimEclipseView;
class RimEclipseCase;
class RigSimulationInputSettings;
class RifOpmFlowDeckFile;
class RigSimWellData;
namespace Opm
{
class DeckRecord;
class DeckKeyword;
} // namespace Opm
//==================================================================================================
///
/// Tool for exporting simulation input files (sector models)
///
//==================================================================================================
class RigSimulationInputTool
{
public:
static std::expected<void, QString>
exportSimulationInput( RimEclipseView& view, RimEclipseCase& eclipseCase, const RigSimulationInputSettings& settings );
static std::expected<Opm::DeckRecord, QString>
processEqualsRecord( const Opm::DeckRecord& record, const caf::VecIjk0& min, const caf::VecIjk0& max, const cvf::Vec3st& refinement );
private:
static std::expected<void, QString> updateCornerPointGridInDeckFile( RimEclipseCase* eclipseCase,
const RigSimulationInputSettings& settings,
RifOpmFlowDeckFile& deckFile );
static std::expected<void, QString> replaceKeywordValuesInDeckFile( RimEclipseCase* eclipseCase,
const RigSimulationInputSettings& settings,
RifOpmFlowDeckFile& deckFile );
static std::expected<void, QString>
addBorderBoundaryConditions( RimEclipseCase* eclipseCase, const RigSimulationInputSettings& settings, RifOpmFlowDeckFile& deckFile );
static std::expected<void, QString>
replaceEqualsKeywordIndices( RimEclipseCase* eclipseCase, const RigSimulationInputSettings& settings, RifOpmFlowDeckFile& deckFile );
static std::expected<void, QString>
addFaultsToDeckFile( RimEclipseCase* eclipseCase, const RigSimulationInputSettings& settings, RifOpmFlowDeckFile& deckFile );
static std::expected<void, QString>
filterAndUpdateWellKeywords( RimEclipseCase* eclipseCase, const RigSimulationInputSettings& settings, RifOpmFlowDeckFile& deckFile );
static std::expected<void, QString> addOperNumRegionAndOperater( RimEclipseCase* eclipseCase,
const RigSimulationInputSettings& settings,
RifOpmFlowDeckFile& deckFile,
int operNumRegion );
static std::vector<RigSimWellData*> findIntersectingWells( RimEclipseCase* eclipseCase, const cvf::Vec3st& min, const cvf::Vec3st& max );
static std::expected<Opm::DeckRecord, QString>
processWelspecsRecord( const Opm::DeckRecord& record, const std::string& wellName, const RigSimulationInputSettings& settings );
static std::expected<Opm::DeckRecord, QString>
processCompdatRecord( const Opm::DeckRecord& record, const std::string& wellName, const RigSimulationInputSettings& settings );
static std::expected<Opm::DeckRecord, QString> processCompsegsRecord( const Opm::DeckRecord& record,
const std::string& wellName,
bool isWellNameRecord,
const RigSimulationInputSettings& settings );
};