00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef OPM_BLACKOILWELLMODEL_HEADER_INCLUDED
00025 #define OPM_BLACKOILWELLMODEL_HEADER_INCLUDED
00026
00027 #include <opm/common/OpmLog/OpmLog.hpp>
00028
00029 #include <opm/common/utility/platform_dependent/disable_warnings.h>
00030 #include <opm/common/utility/platform_dependent/reenable_warnings.h>
00031
00032 #include <cassert>
00033 #include <tuple>
00034
00035 #include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
00036
00037 #include <opm/core/wells.h>
00038 #include <opm/core/wells/DynamicListEconLimited.hpp>
00039 #include <opm/core/wells/WellCollection.hpp>
00040 #include <opm/core/simulator/SimulatorReport.hpp>
00041 #include <opm/autodiff/VFPProperties.hpp>
00042 #include <opm/autodiff/WellHelpers.hpp>
00043 #include <opm/autodiff/BlackoilModelEnums.hpp>
00044 #include <opm/autodiff/WellDensitySegmented.hpp>
00045 #include <opm/autodiff/BlackoilPropsAdFromDeck.hpp>
00046 #include <opm/autodiff/BlackoilDetails.hpp>
00047 #include <opm/autodiff/BlackoilModelParameters.hpp>
00048 #include <opm/autodiff/WellStateFullyImplicitBlackoil.hpp>
00049 #include <opm/autodiff/RateConverter.hpp>
00050 #include <opm/autodiff/WellInterface.hpp>
00051 #include <opm/autodiff/StandardWell.hpp>
00052 #include <opm/autodiff/MultisegmentWell.hpp>
00053 #include<dune/common/fmatrix.hh>
00054 #include<dune/istl/bcrsmatrix.hh>
00055 #include<dune/istl/matrixmatrix.hh>
00056
00057 #include <opm/material/densead/Math.hpp>
00058
00059 #include <opm/simulators/WellSwitchingLogger.hpp>
00060
00061
00062 namespace Opm {
00063
00065 template<typename TypeTag>
00066 class BlackoilWellModel {
00067 public:
00068
00069 typedef WellStateFullyImplicitBlackoil WellState;
00070 typedef BlackoilModelParameters ModelParameters;
00071
00072 typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
00073 typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
00074 typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
00075 typedef typename GET_PROP_TYPE(TypeTag, Indices) BlackoilIndices;
00076 typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
00077 typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
00078
00079 static const int numEq = BlackoilIndices::numEq;
00080 static const int solventSaturationIdx = BlackoilIndices::solventSaturationIdx;
00081
00082
00083
00084 typedef Dune::FieldVector<Scalar, numEq > VectorBlockType;
00085 typedef Dune::BlockVector<VectorBlockType> BVector;
00086
00087 typedef Ewoms::BlackOilPolymerModule<TypeTag> PolymerModule;
00088
00089
00090 using RateConverterType = RateConverter::
00091 SurfaceToReservoirVoidage<BlackoilPropsAdFromDeck::FluidSystem, std::vector<int> >;
00092
00093
00094 BlackoilWellModel(const Wells* wells_arg,
00095 WellCollection* well_collection,
00096 const std::vector< const Well* >& wells_ecl,
00097 const ModelParameters& param,
00098 const RateConverterType& rate_converter,
00099 const bool terminal_output,
00100 const int current_index,
00101 const std::vector<int>& pvt_region_idx);
00102
00103 void init(const PhaseUsage phase_usage_arg,
00104 const std::vector<bool>& active_arg,
00105 const double gravity_arg,
00106 const std::vector<double>& depth_arg,
00107 long int global_nc,
00108 const Grid& grid);
00109
00110 void setVFPProperties(const VFPProperties* vfp_properties_arg);
00111
00112
00113 SimulatorReport assemble(Simulator& ebosSimulator,
00114 const int iterationIdx,
00115 const double dt,
00116 WellState& well_state);
00117
00118
00119 void apply( BVector& r) const;
00120
00121
00122 void apply(const BVector& x, BVector& Ax) const;
00123
00124
00125 void applyScaleAdd(const Scalar alpha, const BVector& x, BVector& Ax) const;
00126
00127
00128
00129 void recoverWellSolutionAndUpdateWellState(const BVector& x, WellState& well_state) const;
00130
00131 int numWells() const;
00132
00134 bool wellsActive() const;
00135
00136 void setWellsActive(const bool wells_active);
00137
00139 bool localWellsActive() const;
00140
00141 bool getWellConvergence(const Simulator& ebosSimulator,
00142 const std::vector<Scalar>& B_avg) const;
00143
00145 void updateListEconLimited(const Schedule& schedule,
00146 const int current_step,
00147 const Wells* wells_struct,
00148 const WellState& well_state,
00149 DynamicListEconLimited& list_econ_limited) const;
00150
00151 WellCollection* wellCollection() const;
00152
00153
00154 protected:
00155 bool wells_active_;
00156 const Wells* wells_;
00157 const std::vector< const Well* > wells_ecl_;
00158
00159
00160
00161
00162 const int number_of_wells_;
00163
00164 const int number_of_phases_;
00165
00166 const ModelParameters& param_;
00167
00168 using WellInterfacePtr = std::unique_ptr<WellInterface<TypeTag> >;
00169
00170
00171
00172
00173 std::vector<WellInterfacePtr > well_container_;
00174
00175 using ConvergenceReport = typename WellInterface<TypeTag>::ConvergenceReport;
00176
00177
00178 static std::vector<WellInterfacePtr > createWellContainer(const Wells* wells,
00179 const std::vector<const Well*>& wells_ecl,
00180 const bool use_multisegment_well,
00181 const int time_step,
00182 const ModelParameters& param);
00183
00184
00185 WellCollection* well_collection_;
00186
00187 bool terminal_output_;
00188 bool has_solvent_;
00189 bool has_polymer_;
00190 int current_timeIdx_;
00191
00192 PhaseUsage phase_usage_;
00193 std::vector<bool> active_;
00194 const RateConverterType& rate_converter_;
00195 const std::vector<int>& pvt_region_idx_;
00196
00197
00198 int number_of_cells_;
00199
00200 long int global_nc_;
00201
00202
00203 mutable BVector scaleAddRes_;
00204
00205 void updateWellControls(WellState& xw) const;
00206
00207 void updateGroupControls(WellState& well_state) const;
00208
00209
00210 void updatePrimaryVariables(const WellState& well_state) const;
00211
00212 void setupCompressedToCartesian(const int* global_cell, int number_of_cells, std::map<int,int>& cartesian_to_compressed ) const;
00213
00214 void computeRepRadiusPerfLength(const Grid& grid);
00215
00216
00217 void computeAverageFormationFactor(const Simulator& ebosSimulator,
00218 std::vector<double>& B_avg) const;
00219
00220 void applyVREPGroupControl(WellState& well_state) const;
00221
00222 void computeWellVoidageRates(const WellState& well_state,
00223 std::vector<double>& well_voidage_rates,
00224 std::vector<double>& voidage_conversion_coeffs) const;
00225
00226
00227
00228 void computeWellPotentials(const Simulator& ebosSimulator,
00229 const WellState& well_state,
00230 std::vector<double>& well_potentials) const;
00231
00232 const std::vector<double>& wellPerfEfficiencyFactors() const;
00233
00234 void calculateEfficiencyFactors();
00235
00236
00237
00238
00241 void calculateExplicitQuantities(const Simulator& ebosSimulator,
00242 const WellState& xw) const;
00243
00244 SimulatorReport solveWellEq(Simulator& ebosSimulator,
00245 const double dt,
00246 WellState& well_state) const;
00247
00248 void initPrimaryVariablesEvaluation() const;
00249
00250
00251 int numComponents() const
00252 {
00253 if (numPhases() == 2) {
00254 return 2;
00255 }
00256 int numComp = FluidSystem::numComponents;
00257 if (has_solvent_) {
00258 numComp ++;
00259 }
00260
00261 return numComp;
00262 }
00263
00264 int numPhases() const;
00265
00266 int flowPhaseToEbosPhaseIdx( const int phaseIdx ) const;
00267
00268 void resetWellControlFromState(const WellState& xw) const;
00269
00270 void assembleWellEq(Simulator& ebosSimulator,
00271 const double dt,
00272 WellState& well_state,
00273 bool only_wells) const;
00274
00275
00276
00277 void prepareTimeStep(const Simulator& ebos_simulator,
00278 WellState& well_state) const;
00279
00280 void prepareGroupControl(const Simulator& ebos_simulator,
00281 WellState& well_state) const;
00282
00283 };
00284
00285
00286 }
00287
00288 #include "BlackoilWellModel_impl.hpp"
00289 #endif