opm-simulators
StandardWellConnections.hpp
1 /*
2  Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
3  Copyright 2017 Statoil ASA.
4  Copyright 2016 - 2017 IRIS AS.
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 
23 #ifndef OPM_STANDARDWELL_CONNECTIONS_HEADER_INCLUDED
24 #define OPM_STANDARDWELL_CONNECTIONS_HEADER_INCLUDED
25 
26 #include <opm/simulators/wells/StandardWellPrimaryVariables.hpp>
27 
28 #include <array>
29 #include <functional>
30 #include <optional>
31 #include <tuple>
32 #include <variant>
33 #include <vector>
34 
35 namespace Opm
36 {
37 
38 class DeferredLogger;
39 enum class Phase;
40 template<typename FluidSystem, typename Indices> class WellInterfaceIndices;
41 template<typename Scalar, typename IndexTraits> class WellState;
42 template<class Scalar> class PerfData;
43 
44 template<class FluidSystem, class Indices>
46 {
47 public:
48  using Scalar = typename FluidSystem::Scalar;
49  using IndexTraits = typename FluidSystem::IndexTraitsType;
51 
52  struct Properties
53  {
54  std::vector<Scalar> b_perf{};
55  std::vector<Scalar> rsmax_perf{};
56  std::vector<Scalar> rvmax_perf{};
57  std::vector<Scalar> rvwmax_perf{};
58  std::vector<Scalar> rswmax_perf{};
59  std::vector<Scalar> surf_dens_perf{};
60  };
61 
63  {
64  std::function<Scalar(int,int)> getTemperature{};
65  std::function<Scalar(int)> getSaltConcentration{};
66  std::function<int(int)> pvtRegionIdx{};
67  std::function<Scalar(int)> solventInverseFormationVolumeFactor{};
68  std::function<Scalar(int)> solventRefDensity{};
69  };
70 
72  {
73  std::function<void(int, const std::vector<int>&, std::vector<Scalar>&)> mobility{};
74  std::function<void(int, const std::vector<int>&, std::vector<Scalar>&)> densityInCell{};
75  };
76 
78  computePropertiesForPressures(const WellState<Scalar, IndexTraits>& well_state,
79  const PressurePropertyFunctions& propFunc) const;
80 
82  void computeProperties(const bool stop_or_zero_rate_target,
83  const WellState<Scalar, IndexTraits>& well_state,
84  const DensityPropertyFunctions& prop_func,
85  const Properties& props,
86  DeferredLogger& deferred_logger);
87 
93  Scalar rho(const typename std::vector<Scalar>::size_type i) const
94  {
95  return (i < this->perf_densities_.size())
96  ? this->perf_densities_[i]
97  : 0.0;
98  }
99 
101  Scalar pressure_diff(const unsigned perf) const
102  { return perf_pressure_diffs_[perf]; }
103 
104  using Eval = typename WellInterfaceIndices<FluidSystem, Indices>::Eval;
106 
107  Eval connectionRateBrine(Scalar& rate,
108  const Scalar vap_wat_rate,
109  const std::vector<EvalWell>& cq_s,
110  const std::variant<Scalar,EvalWell>& saltConcentration) const;
111 
112  Eval connectionRateFoam(const std::vector<EvalWell>& cq_s,
113  const std::variant<Scalar,EvalWell>& foamConcentration,
114  const Phase transportPhase,
115  DeferredLogger& deferred_logger) const;
116 
117  std::tuple<Eval,EvalWell>
118  connectionRatePolymer(Scalar& rate,
119  const std::vector<EvalWell>& cq_s,
120  const std::variant<Scalar,EvalWell>& polymerConcentration) const;
121 
122  Eval connectionRateBioeffects(Scalar& rate,
123  const Scalar vap_wat_rate,
124  const std::vector<EvalWell>& cq_s,
125  const std::variant<Scalar,EvalWell>& microbialConcentration) const;
126 
127  std::tuple<Eval,Eval,Eval>
128  connectionRatesMICP(Scalar& rate_m,
129  Scalar& rate_o,
130  Scalar& rate_u,
131  const std::vector<EvalWell>& cq_s,
132  const std::variant<Scalar,EvalWell>& microbialConcentration,
133  const std::variant<Scalar,EvalWell>& oxygenConcentration,
134  const std::variant<Scalar,EvalWell>& ureaConcentration) const;
135 
136  std::tuple<Eval,EvalWell>
137  connectionRatezFraction(Scalar& rate,
138  const Scalar dis_gas_rate,
139  const std::vector<EvalWell>& cq_s,
140  const std::variant<Scalar, std::array<EvalWell,2>>& solventConcentration) const;
141 
142 private:
143  void computePressureDelta();
144 
145  // TODO: not total sure whether it is a good idea to put this function here
146  // the major reason to put here is to avoid the usage of Wells struct
147  void computeDensities(const std::vector<Scalar>& perfComponentRates,
148  const Properties& props,
149  DeferredLogger& deferred_logger);
150 
151  void computeDensitiesForStoppedProducer(const DensityPropertyFunctions& prop_func);
152 
153  std::vector<Scalar>
154  calculatePerforationOutflow(const std::vector<Scalar>& perfComponentRates) const;
155 
156  template <typename Ix>
157  void initialiseConnectionMixture(const int num_comp,
158  const int perf,
159  const std::optional<Ix> preferredPhaseIdx,
160  const std::vector<Scalar>& q_out_perf,
161  const std::vector<Scalar>& currentMixture,
162  std::vector<Scalar>& previousMixture) const;
163 
164  std::vector<Scalar>
165  copyInPerforationRates(const Properties& props,
166  const PerfData<Scalar>& perf_data) const;
167 
169 
170  std::vector<Scalar> perf_densities_;
171  std::vector<Scalar> perf_pressure_diffs_;
172 };
173 
174 }
175 
176 #endif // OPM_STANDARDWELL_CONNECTIONS_HEADER_INCLUDED
Scalar pressure_diff(const unsigned perf) const
Returns pressure drop for a given perforation.
Definition: StandardWellConnections.hpp:101
Definition: StandardWellConnections.hpp:45
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Definition: StandardWellConnections.hpp:71
Definition: PerfData.hpp:33
Definition: MultisegmentWellAssemble.hpp:38
Definition: DeferredLogger.hpp:56
Definition: StandardWellConnections.hpp:62
DenseAd::DynamicEvaluation< Scalar, numStaticWellEq+Indices::numEq+1 > EvalWell
Evaluation for the well equations.
Definition: StandardWellPrimaryVariables.hpp:89
Definition: StandardWellConnections.hpp:52
Scalar rho(const typename std::vector< Scalar >::size_type i) const
Returns density for specific perforation/connection.
Definition: StandardWellConnections.hpp:93
void computeProperties(const bool stop_or_zero_rate_target, const WellState< Scalar, IndexTraits > &well_state, const DensityPropertyFunctions &prop_func, const Properties &props, DeferredLogger &deferred_logger)
Compute connection properties (densities, pressure drop, ...)
Definition: StandardWellConnections.cpp:669
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: TemperatureModel.hpp:61