Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed: move GasLift code in BlackoilWellModel to separate class #5832

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ list (APPEND MAIN_SOURCE_FILES
opm/simulators/utils/satfunc/RelpermDiagnostics.cpp
opm/simulators/wells/ALQState.cpp
opm/simulators/wells/BlackoilWellModelConstraints.cpp
opm/simulators/wells/BlackoilWellModelGasLift.cpp
opm/simulators/wells/BlackoilWellModelGeneric.cpp
opm/simulators/wells/BlackoilWellModelGuideRates.cpp
opm/simulators/wells/BlackoilWellModelRestart.cpp
Expand Down Expand Up @@ -959,6 +960,8 @@ list (APPEND PUBLIC_HEADER_FILES
opm/simulators/wells/BlackoilWellModel.hpp
opm/simulators/wells/BlackoilWellModel_impl.hpp
opm/simulators/wells/BlackoilWellModelConstraints.hpp
opm/simulators/wells/BlackoilWellModelGasLift.hpp
opm/simulators/wells/BlackoilWellModelGasLift_impl.hpp
opm/simulators/wells/BlackoilWellModelGeneric.hpp
opm/simulators/wells/BlackoilWellModelGuideRates.hpp
opm/simulators/wells/BlackoilWellModelRestart.hpp
Expand Down
37 changes: 3 additions & 34 deletions opm/simulators/wells/BlackoilWellModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <cstddef>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>

Expand All @@ -48,6 +47,7 @@

#include <opm/simulators/linalg/matrixblock.hh>

#include <opm/simulators/wells/BlackoilWellModelGasLift.hpp>
#include <opm/simulators/wells/BlackoilWellModelGeneric.hpp>
#include <opm/simulators/wells/BlackoilWellModelGuideRates.hpp>
#include <opm/simulators/wells/GasLiftGroupInfo.hpp>
Expand Down Expand Up @@ -80,12 +80,6 @@

#include <opm/simulators/utils/DeferredLogger.hpp>

namespace Opm::Parameters {

struct EnableTerminalOutput { static constexpr bool value = true; };

} // namespace Opm::Parameters

namespace Opm {

#if COMPILE_GPU_BRIDGE
Expand All @@ -110,14 +104,6 @@ template<class Scalar> class WellContributions;
using RateVector = GetPropType<TypeTag, Properties::RateVector>;
using GlobalEqVector = GetPropType<TypeTag, Properties::GlobalEqVector>;
using SparseMatrixAdapter = GetPropType<TypeTag, Properties::SparseMatrixAdapter>;
using GasLiftSingleWell = typename WellInterface<TypeTag>::GasLiftSingleWell;
using GLiftOptWells = typename BlackoilWellModelGeneric<Scalar>::GLiftOptWells;
using GLiftProdWells = typename BlackoilWellModelGeneric<Scalar>::GLiftProdWells;
using GLiftWellStateMap =
typename BlackoilWellModelGeneric<Scalar>::GLiftWellStateMap;
using GLiftEclWells = typename GasLiftGroupInfo<Scalar>::GLiftEclWells;
using GLiftSyncGroups = typename GasLiftSingleWellGeneric<Scalar>::GLiftSyncGroups;

using ModelParameters = BlackoilModelParameters<Scalar>;

constexpr static std::size_t pressureVarIndex = GetPropType<TypeTag, Properties::Indices>::pressureSwitchIdx;
Expand Down Expand Up @@ -362,8 +348,6 @@ template<class Scalar> class WellContributions;

void addWellPressureEquationsStruct(PressureMatrix& jacobian) const;

void initGliftEclWellMap(GLiftEclWells &ecl_well_map);

/// \brief Get list of local nonshut wells
const std::vector<WellInterfacePtr>& localNonshutWells() const
{
Expand Down Expand Up @@ -525,23 +509,6 @@ template<class Scalar> class WellContributions;
// TODO: finding a better naming
void assembleWellEqWithoutIteration(const double dt, DeferredLogger& deferred_logger);

bool maybeDoGasLiftOptimize(DeferredLogger& deferred_logger);

void gasLiftOptimizationStage1(DeferredLogger& deferred_logger,
GLiftProdWells& prod_wells,
GLiftOptWells& glift_wells,
GasLiftGroupInfo<Scalar>& group_info,
GLiftWellStateMap& state_map);

// cannot be const since it accesses the non-const WellState
void gasLiftOptimizationStage1SingleWell(WellInterface<TypeTag>* well,
DeferredLogger& deferred_logger,
GLiftProdWells& prod_wells,
GLiftOptWells& glift_wells,
GasLiftGroupInfo<Scalar>& group_info,
GLiftWellStateMap& state_map,
GLiftSyncGroups& groups_to_sync);

void extractLegacyCellPvtRegionIndex_();

void extractLegacyDepth_();
Expand Down Expand Up @@ -569,6 +536,8 @@ template<class Scalar> class WellContributions;
private:
BlackoilWellModel(Simulator& simulator, const PhaseUsage& pu);

BlackoilWellModelGasLift<TypeTag> gaslift_;

// These members are used to avoid reallocation in specific functions
// instead of using local variables.
// Their state is not relevant between function calls, so they can
Expand Down
110 changes: 110 additions & 0 deletions opm/simulators/wells/BlackoilWellModelGasLift.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
Copyright 2016 SINTEF ICT, Applied Mathematics.
Copyright 2016 - 2017 Statoil ASA.
Copyright 2017 Dr. Blatt - HPC-Simulation-Software & Services
Copyright 2016 - 2018 IRIS AS

This file is part of the Open Porous Media project (OPM).

OPM 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.

OPM 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 for more details.

You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/

#include <config.h>

#include <opm/simulators/utils/DeferredLogger.hpp>

#include <opm/simulators/wells/BlackoilWellModelGasLift.hpp>
#include <opm/simulators/wells/GasLiftStage2.hpp>
#include <opm/simulators/wells/WellInterfaceGeneric.hpp>
#include <opm/simulators/wells/WellState.hpp>

#include <fmt/format.h>

namespace Opm {

template<class Scalar>
void BlackoilWellModelGasLiftGeneric<Scalar>::
gliftDebug([[maybe_unused]] const std::string& msg,
[[maybe_unused]] DeferredLogger& deferred_logger) const
{
if constexpr (glift_debug) {
if (terminal_output_) {
const std::string message =
fmt::format(" GLIFT (DEBUG) : BlackoilWellModel : {}", msg);
deferred_logger.info(message);
}
}
}

template<class Scalar>
void BlackoilWellModelGasLiftGeneric<Scalar>::
gliftDebugShowALQ(const std::vector<WellInterfaceGeneric<Scalar>*>& well_container,
const WellState<Scalar>& wellState,
DeferredLogger& deferred_logger)
{
for (const auto& well : well_container) {
if (well->isProducer()) {
auto alq = wellState.getALQ(well->name());
const std::string msg = fmt::format("ALQ_REPORT : {} : {}",
well->name(), alq);
gliftDebug(msg, deferred_logger);
}
}
}

// If a group has any production rate constraints, and/or a limit
// on its total rate of lift gas supply, allocate lift gas
// preferentially to the wells that gain the most benefit from
// it. Lift gas increments are allocated in turn to the well that
// currently has the largest weighted incremental gradient. The
// procedure takes account of any limits on the group production
// rate or lift gas supply applied to any level of group.
template<class Scalar>
void BlackoilWellModelGasLiftGeneric<Scalar>::
gasLiftOptimizationStage2(const Parallel::Communication& comm,
const Schedule& schedule,
const SummaryState& summaryState,
WellState<Scalar>& wellState,
GroupState<Scalar>& groupState,
GLiftProdWells& prod_wells,
GLiftOptWells& glift_wells,
GasLiftGroupInfo<Scalar>& group_info,
GLiftWellStateMap& glift_well_state_map,
const int episodeIndex,
DeferredLogger& deferred_logger)

{
GasLiftStage2 glift {episodeIndex,
comm,
schedule,
summaryState,
deferred_logger,
wellState,
groupState,
prod_wells,
glift_wells,
group_info,
glift_well_state_map,
this->glift_debug
};
glift.runOptimize();
}

template class BlackoilWellModelGasLiftGeneric<double>;

#if FLOW_INSTANTIATE_FLOAT
template class BlackoilWellModelGasLiftGeneric<float>;
#endif

}
143 changes: 143 additions & 0 deletions opm/simulators/wells/BlackoilWellModelGasLift.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
Copyright 2016 SINTEF ICT, Applied Mathematics.
Copyright 2016 - 2017 Statoil ASA.
Copyright 2017 Dr. Blatt - HPC-Simulation-Software & Services
Copyright 2016 - 2018 IRIS AS

This file is part of the Open Porous Media project (OPM).

OPM 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.

OPM 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 for more details.

You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_BLACKOILWELLMODEL_GASLIFT_HEADER_INCLUDED
#define OPM_BLACKOILWELLMODEL_GASLIFT_HEADER_INCLUDED

#include "opm/models/utils/basicproperties.hh"
#include <opm/simulators/wells/GasLiftSingleWellGeneric.hpp>

#include <memory>
#include <map>
#include <string>

namespace Opm {

class DeferredLogger;
template<class Scalar> class GroupState;
template<class Scalar> class WellState;
template<class TypeTag> class WellInterface;

template<class Scalar>
class BlackoilWellModelGasLiftGeneric
{
public:
using GLiftOptWells = std::map<std::string, std::unique_ptr<GasLiftSingleWellGeneric<Scalar>>>;
using GLiftProdWells = std::map<std::string, const WellInterfaceGeneric<Scalar>*>;
using GLiftWellStateMap = std::map<std::string, std::unique_ptr<GasLiftWellState<Scalar>>>;
using GLiftEclWells = typename GasLiftGroupInfo<Scalar>::GLiftEclWells;
using GLiftSyncGroups = typename GasLiftSingleWellGeneric<Scalar>::GLiftSyncGroups;

explicit BlackoilWellModelGasLiftGeneric(bool terminal_output)
: terminal_output_(terminal_output)
{}

static constexpr bool glift_debug = false;

void gliftDebug(const std::string& msg,
DeferredLogger& deferred_logger) const;

bool terminalOutput() const { return terminal_output_; }

protected:
void gliftDebugShowALQ(const std::vector<WellInterfaceGeneric<Scalar>*>& well_container,
const WellState<Scalar>& wellState,
DeferredLogger& deferred_logger);

void gasLiftOptimizationStage2(const Parallel::Communication& comm,
const Schedule& schedule,
const SummaryState& summaryState,
WellState<Scalar>& wellState,
GroupState<Scalar>& groupState,
GLiftProdWells& prod_wells,
GLiftOptWells& glift_wells,
GasLiftGroupInfo<Scalar>& group_info,
GLiftWellStateMap& map,
const int episodeIndex,
DeferredLogger& deferred_logger);

bool terminal_output_;
double last_glift_opt_time_ = -1.0;
};

/// Class for handling the gaslift in the blackoil well model.
template<typename TypeTag>
class BlackoilWellModelGasLift :
public BlackoilWellModelGasLiftGeneric<GetPropType<TypeTag, Properties::Scalar>>
{
using Base = BlackoilWellModelGasLiftGeneric<GetPropType<TypeTag, Properties::Scalar>>;

public:
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
using GLiftEclWells = typename GasLiftGroupInfo<Scalar>::GLiftEclWells;
using GLiftOptWells = typename Base::GLiftOptWells;
using GLiftProdWells = typename Base::GLiftProdWells;
using GLiftSyncGroups = typename GasLiftSingleWellGeneric<Scalar>::GLiftSyncGroups;
using GLiftWellStateMap = typename Base::GLiftWellStateMap;
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
using WellInterfacePtr = std::shared_ptr<WellInterface<TypeTag>>;

BlackoilWellModelGasLift(bool terminal_output,
const PhaseUsage& phase_usage)
: Base(terminal_output)
, phase_usage_(phase_usage)
{}

static void initGliftEclWellMap(const std::vector<WellInterfacePtr>& well_container,
GLiftEclWells& ecl_well_map);

bool maybeDoGasLiftOptimize(const Simulator& simulator,
const std::vector<WellInterfacePtr>& well_container,
WellState<Scalar>& wellState,
GroupState<Scalar>& groupState,
DeferredLogger& deferred_logger);

private:
void gasLiftOptimizationStage1(const Simulator& simulator,
const std::vector<WellInterfacePtr>& well_container,
WellState<Scalar>& wellState,
GroupState<Scalar>& groupState,
GLiftProdWells& prod_wells,
GLiftOptWells& glift_wells,
GasLiftGroupInfo<Scalar>& group_info,
GLiftWellStateMap& state_map,
DeferredLogger& deferred_logger);

// cannot be const since it accesses the non-const WellState
void gasLiftOptimizationStage1SingleWell(WellInterface<TypeTag>* well,
const Simulator& simulator,
WellState<Scalar>& wellState,
GroupState<Scalar>& groupState,
GLiftProdWells& prod_wells,
GLiftOptWells& glift_wells,
GasLiftGroupInfo<Scalar>& group_info,
GLiftWellStateMap& state_map,
GLiftSyncGroups& groups_to_sync,
DeferredLogger& deferred_logger);

const PhaseUsage& phase_usage_;
};

} // namespace Opm

#include "BlackoilWellModelGasLift_impl.hpp"

#endif
Loading