From 0f7967f86a0758eaa990661a72ae79764f3e2150 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 26 May 2021 09:16:19 +0200 Subject: [PATCH] cosmetics: do not indent for namespace --- opm/simulators/wells/WellInterface.hpp | 573 ++++++++++++------------- 1 file changed, 286 insertions(+), 287 deletions(-) diff --git a/opm/simulators/wells/WellInterface.hpp b/opm/simulators/wells/WellInterface.hpp index 16adb511d..3fd14321f 100644 --- a/opm/simulators/wells/WellInterface.hpp +++ b/opm/simulators/wells/WellInterface.hpp @@ -70,347 +70,346 @@ namespace Opm { namespace Opm { +template +class WellInterface : public WellInterfaceFluidSystem> +{ +public: - template - class WellInterface : public WellInterfaceFluidSystem> + using ModelParameters = BlackoilModelParametersEbos; + + using Grid = GetPropType; + using Simulator = GetPropType; + using FluidSystem = GetPropType; + using Indices = GetPropType; + using IntensiveQuantities = GetPropType; + using MaterialLaw = GetPropType; + using SparseMatrixAdapter = GetPropType; + using RateVector = GetPropType; + using GasLiftSingleWell = ::Opm::GasLiftSingleWell; + using GLiftOptWells = typename BlackoilWellModel::GLiftOptWells; + using GLiftProdWells = typename BlackoilWellModel::GLiftProdWells; + using GLiftWellStateMap = + typename BlackoilWellModel::GLiftWellStateMap; + + static const int numEq = Indices::numEq; + static const int numPhases = Indices::numPhases; + using Scalar = GetPropType; + + using VectorBlockType = Dune::FieldVector; + using MatrixBlockType = Dune::FieldMatrix; + using BVector = Dune::BlockVector; + using Eval = DenseAd::Evaluation; + + using RateConverterType = + typename WellInterfaceFluidSystem::RateConverterType; + + using WellInterfaceFluidSystem::Gas; + using WellInterfaceFluidSystem::Oil; + using WellInterfaceFluidSystem::Water; + using RatioLimitCheckReport = typename WellInterfaceFluidSystem::RatioLimitCheckReport; + + static constexpr bool has_solvent = getPropValue(); + static constexpr bool has_zFraction = getPropValue(); + static constexpr bool has_polymer = getPropValue(); + static constexpr bool has_energy = getPropValue(); + static const bool has_temperature = getPropValue(); + // flag for polymer molecular weight related + static constexpr bool has_polymermw = getPropValue(); + static constexpr bool has_foam = getPropValue(); + static constexpr bool has_brine = getPropValue(); + static const int contiSolventEqIdx = Indices::contiSolventEqIdx; + static const int contiZfracEqIdx = Indices::contiZfracEqIdx; + static const int contiPolymerEqIdx = Indices::contiPolymerEqIdx; + // index for the polymer molecular weight continuity equation + static const int contiPolymerMWEqIdx = Indices::contiPolymerMWEqIdx; + static const int contiFoamEqIdx = Indices::contiFoamEqIdx; + static const int contiBrineEqIdx = Indices::contiBrineEqIdx; + + // For the conversion between the surface volume rate and reservoir voidage rate + static const bool compositionSwitchEnabled = Indices::gasEnabled; + using FluidState = BlackOilFluidState; + /// Constructor + WellInterface(const Well& well, + const ParallelWellInfo& pw_info, + const int time_step, + const ModelParameters& param, + const RateConverterType& rate_converter, + const int pvtRegionIdx, + const int num_components, + const int num_phases, + const int index_of_well, + const int first_perf_index, + const std::vector& perf_data); + + /// Virtual destructor + virtual ~WellInterface() = default; + + virtual void init(const PhaseUsage* phase_usage_arg, + const std::vector& depth_arg, + const double gravity_arg, + const int num_cells, + const std::vector< Scalar >& B_avg); + + virtual void initPrimaryVariablesEvaluation() const = 0; + + virtual ConvergenceReport getWellConvergence(const WellState& well_state, const std::vector& B_avg, DeferredLogger& deferred_logger, const bool relax_tolerance = false) const = 0; + + virtual void solveEqAndUpdateWellState(WellState& well_state, DeferredLogger& deferred_logger) = 0; + + void assembleWellEq(const Simulator& ebosSimulator, + const double dt, + WellState& well_state, + const GroupState& group_state, + DeferredLogger& deferred_logger); + + virtual void gasLiftOptimizationStage1 ( + WellState& well_state, + const Simulator& ebosSimulator, + DeferredLogger& deferred_logger, + GLiftProdWells& prod_wells, + GLiftOptWells& glift_wells, + GLiftWellStateMap& state_map + ) const = 0; + + /// using the solution x to recover the solution xw for wells and applying + /// xw to update Well State + virtual void recoverWellSolutionAndUpdateWellState(const BVector& x, + WellState& well_state, + DeferredLogger& deferred_logger) const = 0; + + /// Ax = Ax - C D^-1 B x + virtual void apply(const BVector& x, BVector& Ax) const = 0; + + /// r = r - C D^-1 Rw + virtual void apply(BVector& r) const = 0; + + // TODO: before we decide to put more information under mutable, this function is not const + virtual void computeWellPotentials(const Simulator& ebosSimulator, + const WellState& well_state, + std::vector& well_potentials, + DeferredLogger& deferred_logger) = 0; + + void updateWellStateWithTarget(const Simulator& ebos_simulator, + WellState& well_state, + DeferredLogger& deferred_logger) const; + + enum class IndividualOrGroup { Individual, Group, Both }; + bool updateWellControl(const Simulator& ebos_simulator, + const IndividualOrGroup iog, + WellState& well_state, + const GroupState& group_state, + DeferredLogger& deferred_logger) /* const */; + + virtual void updatePrimaryVariables(const WellState& well_state, DeferredLogger& deferred_logger) const = 0; + + virtual void calculateExplicitQuantities(const Simulator& ebosSimulator, + const WellState& well_state, + DeferredLogger& deferred_logger) = 0; // should be const? + + virtual void updateProductivityIndex(const Simulator& ebosSimulator, + const WellProdIndexCalculator& wellPICalc, + WellState& well_state, + DeferredLogger& deferred_logger) const = 0; + + /// \brief Wether the Jacobian will also have well contributions in it. + virtual bool jacobianContainsWellContributions() const { - public: + return false; + } - using ModelParameters = BlackoilModelParametersEbos; + // Add well contributions to matrix + virtual void addWellContributions(SparseMatrixAdapter&) const = 0; - using Grid = GetPropType; - using Simulator = GetPropType; - using FluidSystem = GetPropType; - using Indices = GetPropType; - using IntensiveQuantities = GetPropType; - using MaterialLaw = GetPropType; - using SparseMatrixAdapter = GetPropType; - using RateVector = GetPropType; - using GasLiftSingleWell = ::Opm::GasLiftSingleWell; - using GLiftOptWells = typename BlackoilWellModel::GLiftOptWells; - using GLiftProdWells = typename BlackoilWellModel::GLiftProdWells; - using GLiftWellStateMap = - typename BlackoilWellModel::GLiftWellStateMap; + void addCellRates(RateVector& rates, int cellIdx) const; - static const int numEq = Indices::numEq; - static const int numPhases = Indices::numPhases; - using Scalar = GetPropType; + Scalar volumetricSurfaceRateForConnection(int cellIdx, int phaseIdx) const; - using VectorBlockType = Dune::FieldVector; - using MatrixBlockType = Dune::FieldMatrix; - using BVector = Dune::BlockVector; - using Eval = DenseAd::Evaluation; - using RateConverterType = - typename WellInterfaceFluidSystem::RateConverterType; - - using WellInterfaceFluidSystem::Gas; - using WellInterfaceFluidSystem::Oil; - using WellInterfaceFluidSystem::Water; - using RatioLimitCheckReport = typename WellInterfaceFluidSystem::RatioLimitCheckReport; - - static constexpr bool has_solvent = getPropValue(); - static constexpr bool has_zFraction = getPropValue(); - static constexpr bool has_polymer = getPropValue(); - static constexpr bool has_energy = getPropValue(); - static const bool has_temperature = getPropValue(); - // flag for polymer molecular weight related - static constexpr bool has_polymermw = getPropValue(); - static constexpr bool has_foam = getPropValue(); - static constexpr bool has_brine = getPropValue(); - static const int contiSolventEqIdx = Indices::contiSolventEqIdx; - static const int contiZfracEqIdx = Indices::contiZfracEqIdx; - static const int contiPolymerEqIdx = Indices::contiPolymerEqIdx; - // index for the polymer molecular weight continuity equation - static const int contiPolymerMWEqIdx = Indices::contiPolymerMWEqIdx; - static const int contiFoamEqIdx = Indices::contiFoamEqIdx; - static const int contiBrineEqIdx = Indices::contiBrineEqIdx; - - // For the conversion between the surface volume rate and reservoir voidage rate - static const bool compositionSwitchEnabled = Indices::gasEnabled; - using FluidState = BlackOilFluidState; - /// Constructor - WellInterface(const Well& well, - const ParallelWellInfo& pw_info, - const int time_step, - const ModelParameters& param, - const RateConverterType& rate_converter, - const int pvtRegionIdx, - const int num_components, - const int num_phases, - const int index_of_well, - const int first_perf_index, - const std::vector& perf_data); - - /// Virtual destructor - virtual ~WellInterface() = default; - - virtual void init(const PhaseUsage* phase_usage_arg, - const std::vector& depth_arg, - const double gravity_arg, - const int num_cells, - const std::vector< Scalar >& B_avg); - - virtual void initPrimaryVariablesEvaluation() const = 0; - - virtual ConvergenceReport getWellConvergence(const WellState& well_state, const std::vector& B_avg, DeferredLogger& deferred_logger, const bool relax_tolerance = false) const = 0; - - virtual void solveEqAndUpdateWellState(WellState& well_state, DeferredLogger& deferred_logger) = 0; - - void assembleWellEq(const Simulator& ebosSimulator, - const double dt, - WellState& well_state, - const GroupState& group_state, - DeferredLogger& deferred_logger); - - virtual void gasLiftOptimizationStage1 ( - WellState& well_state, - const Simulator& ebosSimulator, - DeferredLogger& deferred_logger, - GLiftProdWells& prod_wells, - GLiftOptWells& glift_wells, - GLiftWellStateMap& state_map - ) const = 0; - - /// using the solution x to recover the solution xw for wells and applying - /// xw to update Well State - virtual void recoverWellSolutionAndUpdateWellState(const BVector& x, - WellState& well_state, - DeferredLogger& deferred_logger) const = 0; - - /// Ax = Ax - C D^-1 B x - virtual void apply(const BVector& x, BVector& Ax) const = 0; - - /// r = r - C D^-1 Rw - virtual void apply(BVector& r) const = 0; - - // TODO: before we decide to put more information under mutable, this function is not const - virtual void computeWellPotentials(const Simulator& ebosSimulator, - const WellState& well_state, - std::vector& well_potentials, - DeferredLogger& deferred_logger) = 0; - - void updateWellStateWithTarget(const Simulator& ebos_simulator, - WellState& well_state, - DeferredLogger& deferred_logger) const; - - enum class IndividualOrGroup { Individual, Group, Both }; - bool updateWellControl(const Simulator& ebos_simulator, - const IndividualOrGroup iog, - WellState& well_state, - const GroupState& group_state, - DeferredLogger& deferred_logger) /* const */; - - virtual void updatePrimaryVariables(const WellState& well_state, DeferredLogger& deferred_logger) const = 0; - - virtual void calculateExplicitQuantities(const Simulator& ebosSimulator, - const WellState& well_state, - DeferredLogger& deferred_logger) = 0; // should be const? - - virtual void updateProductivityIndex(const Simulator& ebosSimulator, - const WellProdIndexCalculator& wellPICalc, - WellState& well_state, - DeferredLogger& deferred_logger) const = 0; - - /// \brief Wether the Jacobian will also have well contributions in it. - virtual bool jacobianContainsWellContributions() const - { - return false; + template + Eval restrictEval(const EvalWell& in) const + { + Eval out = 0.0; + out.setValue(in.value()); + for(int eqIdx = 0; eqIdx < numEq;++eqIdx) { + out.setDerivative(eqIdx, in.derivative(eqIdx)); } + return out; + } - // Add well contributions to matrix - virtual void addWellContributions(SparseMatrixAdapter&) const = 0; + // TODO: theoretically, it should be a const function + // Simulator is not const is because that assembleWellEq is non-const Simulator + void wellTesting(const Simulator& simulator, + const double simulation_time, const int report_step, + const WellTestConfig::Reason testing_reason, + /* const */ WellState& well_state, const GroupState& group_state, WellTestState& welltest_state, + DeferredLogger& deferred_logger); - void addCellRates(RateVector& rates, int cellIdx) const; + void checkWellOperability(const Simulator& ebos_simulator, const WellState& well_state, DeferredLogger& deferred_logger); - Scalar volumetricSurfaceRateForConnection(int cellIdx, int phaseIdx) const; - - - template - Eval restrictEval(const EvalWell& in) const - { - Eval out = 0.0; - out.setValue(in.value()); - for(int eqIdx = 0; eqIdx < numEq;++eqIdx) { - out.setDerivative(eqIdx, in.derivative(eqIdx)); - } - return out; - } - - // TODO: theoretically, it should be a const function - // Simulator is not const is because that assembleWellEq is non-const Simulator - void wellTesting(const Simulator& simulator, - const double simulation_time, const int report_step, - const WellTestConfig::Reason testing_reason, - /* const */ WellState& well_state, const GroupState& group_state, WellTestState& welltest_state, - DeferredLogger& deferred_logger); - - void checkWellOperability(const Simulator& ebos_simulator, const WellState& well_state, DeferredLogger& deferred_logger); - - // check whether the well is operable under the current reservoir condition - // mostly related to BHP limit and THP limit - void updateWellOperability(const Simulator& ebos_simulator, - const WellState& well_state, - DeferredLogger& deferred_logger); - - - // update perforation water throughput based on solved water rate - virtual void updateWaterThroughput(const double dt, WellState& well_state) const = 0; - - /// Compute well rates based on current reservoir conditions and well variables. - /// Used in updateWellStateRates(). - virtual std::vector computeCurrentWellRates(const Simulator& ebosSimulator, - DeferredLogger& deferred_logger) const = 0; - - /// Modify the well_state's rates if there is only one nonzero rate. - /// If so, that rate is kept as is, but the others are set proportionally - /// to the rates returned by computeCurrentWellRates(). - void updateWellStateRates(const Simulator& ebosSimulator, - WellState& well_state, - DeferredLogger& deferred_logger) const; - - void solveWellEquation(const Simulator& ebosSimulator, - WellState& well_state, - const GroupState& group_state, + // check whether the well is operable under the current reservoir condition + // mostly related to BHP limit and THP limit + void updateWellOperability(const Simulator& ebos_simulator, + const WellState& well_state, DeferredLogger& deferred_logger); - virtual bool useInnerIterations() const = 0; - protected: + // update perforation water throughput based on solved water rate + virtual void updateWaterThroughput(const double dt, WellState& well_state) const = 0; - // simulation parameters - const ModelParameters& param_; + /// Compute well rates based on current reservoir conditions and well variables. + /// Used in updateWellStateRates(). + virtual std::vector computeCurrentWellRates(const Simulator& ebosSimulator, + DeferredLogger& deferred_logger) const = 0; - std::vector connectionRates_; + /// Modify the well_state's rates if there is only one nonzero rate. + /// If so, that rate is kept as is, but the others are set proportionally + /// to the rates returned by computeCurrentWellRates(). + void updateWellStateRates(const Simulator& ebosSimulator, + WellState& well_state, + DeferredLogger& deferred_logger) const; - std::vector< Scalar > B_avg_; + void solveWellEquation(const Simulator& ebosSimulator, + WellState& well_state, + const GroupState& group_state, + DeferredLogger& deferred_logger); - bool changed_to_stopped_this_step_ = false; + virtual bool useInnerIterations() const = 0; - int flowPhaseToEbosCompIdx( const int phaseIdx ) const; +protected: - int flowPhaseToEbosPhaseIdx( const int phaseIdx ) const; + // simulation parameters + const ModelParameters& param_; - int ebosCompIdxToFlowCompIdx( const unsigned compIdx ) const; + std::vector connectionRates_; - double wpolymer() const; + std::vector< Scalar > B_avg_; - double wfoam() const; + bool changed_to_stopped_this_step_ = false; - double wsalt() const; + int flowPhaseToEbosCompIdx( const int phaseIdx ) const; - template - ValueType calculateBhpFromThp(const WellState& well_state, const std::vector& rates, const Well& well, const SummaryState& summaryState, DeferredLogger& deferred_logger) const; + int flowPhaseToEbosPhaseIdx( const int phaseIdx ) const; - virtual double getRefDensity() const = 0; + int ebosCompIdxToFlowCompIdx( const unsigned compIdx ) const; - // Component fractions for each phase for the well - const std::vector& compFrac() const; + double wpolymer() const; - double scalingFactor(const int comp_idx) const; + double wfoam() const; - std::vector initialWellRateFractions(const Simulator& ebosSimulator, const std::vector& potentials) const; + double wsalt() const; - // check whether the well is operable under BHP limit with current reservoir condition - virtual void checkOperabilityUnderBHPLimitProducer(const WellState& well_state, const Simulator& ebos_simulator, DeferredLogger& deferred_logger) =0; + template + ValueType calculateBhpFromThp(const WellState& well_state, const std::vector& rates, const Well& well, const SummaryState& summaryState, DeferredLogger& deferred_logger) const; - // check whether the well is operable under THP limit with current reservoir condition - virtual void checkOperabilityUnderTHPLimitProducer(const Simulator& ebos_simulator, const WellState& well_state, DeferredLogger& deferred_logger) =0; + virtual double getRefDensity() const = 0; - virtual void updateIPR(const Simulator& ebos_simulator, DeferredLogger& deferred_logger) const=0; + // Component fractions for each phase for the well + const std::vector& compFrac() const; + + double scalingFactor(const int comp_idx) const; + + std::vector initialWellRateFractions(const Simulator& ebosSimulator, const std::vector& potentials) const; + + // check whether the well is operable under BHP limit with current reservoir condition + virtual void checkOperabilityUnderBHPLimitProducer(const WellState& well_state, const Simulator& ebos_simulator, DeferredLogger& deferred_logger) =0; + + // check whether the well is operable under THP limit with current reservoir condition + virtual void checkOperabilityUnderTHPLimitProducer(const Simulator& ebos_simulator, const WellState& well_state, DeferredLogger& deferred_logger) =0; + + virtual void updateIPR(const Simulator& ebos_simulator, DeferredLogger& deferred_logger) const=0; - void wellTestingEconomic(const Simulator& simulator, - const double simulation_time, const WellState& well_state, const GroupState& group_state, - WellTestState& welltest_state, DeferredLogger& deferred_logger); + void wellTestingEconomic(const Simulator& simulator, + const double simulation_time, const WellState& well_state, const GroupState& group_state, + WellTestState& welltest_state, DeferredLogger& deferred_logger); - void wellTestingPhysical(const Simulator& simulator, - const double simulation_time, const int report_step, - WellState& well_state, - const GroupState& group_state, - WellTestState& welltest_state, DeferredLogger& deferred_logger); + void wellTestingPhysical(const Simulator& simulator, + const double simulation_time, const int report_step, + WellState& well_state, + const GroupState& group_state, + WellTestState& welltest_state, DeferredLogger& deferred_logger); - virtual void assembleWellEqWithoutIteration(const Simulator& ebosSimulator, - const double dt, - const Well::InjectionControls& inj_controls, - const Well::ProductionControls& prod_controls, - WellState& well_state, - const GroupState& group_state, - DeferredLogger& deferred_logger) = 0; + virtual void assembleWellEqWithoutIteration(const Simulator& ebosSimulator, + const double dt, + const Well::InjectionControls& inj_controls, + const Well::ProductionControls& prod_controls, + WellState& well_state, + const GroupState& group_state, + DeferredLogger& deferred_logger) = 0; - // iterate well equations with the specified control until converged - virtual bool iterateWellEqWithControl(const Simulator& ebosSimulator, - const double dt, - const Well::InjectionControls& inj_controls, - const Well::ProductionControls& prod_controls, - WellState& well_state, - const GroupState& group_state, - DeferredLogger& deferred_logger) = 0; + // iterate well equations with the specified control until converged + virtual bool iterateWellEqWithControl(const Simulator& ebosSimulator, + const double dt, + const Well::InjectionControls& inj_controls, + const Well::ProductionControls& prod_controls, + WellState& well_state, + const GroupState& group_state, + DeferredLogger& deferred_logger) = 0; - bool iterateWellEquations(const Simulator& ebosSimulator, - const double dt, - WellState& well_state, - const GroupState& group_state, - DeferredLogger& deferred_logger); + bool iterateWellEquations(const Simulator& ebosSimulator, + const double dt, + WellState& well_state, + const GroupState& group_state, + DeferredLogger& deferred_logger); - void solveWellForTesting(const Simulator& ebosSimulator, WellState& well_state, const GroupState& group_state, - DeferredLogger& deferred_logger); + void solveWellForTesting(const Simulator& ebosSimulator, WellState& well_state, const GroupState& group_state, + DeferredLogger& deferred_logger); - template - void getGroupInjectionControl(const Group& group, - const WellState& well_state, - const GroupState& group_state, - const Schedule& schedule, - const SummaryState& summaryState, - const InjectorType& injectorType, - const EvalWell& bhp, - const EvalWell& injection_rate, - EvalWell& control_eq, - double efficiencyFactor, - DeferredLogger& deferred_logger); - - template - void getGroupProductionControl(const Group& group, - const WellState& well_state, - const GroupState& group_state, - const Schedule& schedule, - const SummaryState& summaryState, - const EvalWell& bhp, - const std::vector& rates, - EvalWell& control_eq, - double efficiencyFactor); - - template - void assembleControlEqInj(const WellState& well_state, + template + void getGroupInjectionControl(const Group& group, + const WellState& well_state, const GroupState& group_state, const Schedule& schedule, const SummaryState& summaryState, - const Well::InjectionControls& controls, + const InjectorType& injectorType, const EvalWell& bhp, const EvalWell& injection_rate, - BhpFromThpFunc bhp_from_thp, EvalWell& control_eq, + double efficiencyFactor, DeferredLogger& deferred_logger); - template - void assembleControlEqProd(const WellState& well_state, + template + void getGroupProductionControl(const Group& group, + const WellState& well_state, const GroupState& group_state, const Schedule& schedule, const SummaryState& summaryState, - const Well::ProductionControls& controls, const EvalWell& bhp, - const std::vector& rates, // Always 3 canonical rates. - BhpFromThpFunc bhp_from_thp, + const std::vector& rates, EvalWell& control_eq, - DeferredLogger& deferred_logger); - }; + double efficiencyFactor); + + template + void assembleControlEqInj(const WellState& well_state, + const GroupState& group_state, + const Schedule& schedule, + const SummaryState& summaryState, + const Well::InjectionControls& controls, + const EvalWell& bhp, + const EvalWell& injection_rate, + BhpFromThpFunc bhp_from_thp, + EvalWell& control_eq, + DeferredLogger& deferred_logger); + + template + void assembleControlEqProd(const WellState& well_state, + const GroupState& group_state, + const Schedule& schedule, + const SummaryState& summaryState, + const Well::ProductionControls& controls, + const EvalWell& bhp, + const std::vector& rates, // Always 3 canonical rates. + BhpFromThpFunc bhp_from_thp, + EvalWell& control_eq, + DeferredLogger& deferred_logger); +}; }