OpenCAEPoro  v0.5.0
A simulator for multicomponent porous media flow
Mixture.hpp
Go to the documentation of this file.
1 
12 #ifndef __MIXTURE_HEADER__
13 #define __MIXTURE_HEADER__
14 
15 // Standard header files
16 #include <iostream>
17 #include <vector>
18 
19 // OpenCAEPoro header files
20 #include "OCPConst.hpp"
21 #include "OptionalFeatures.hpp"
22 #include "ParamReservoir.hpp"
23 #include "WellOpt.hpp"
24 
25 using namespace std;
26 
30 class Mixture
31 {
32  friend class Bulk;
33  friend class Well;
34  friend class AllWells;
35 
36 public:
37  Mixture() = default;
38  virtual ~Mixture(){};
40  void Allocate()
41  {
42  Ni.resize(numCom);
43  phaseExist.resize(numPhase);
44  vj.resize(numPhase);
45  S.resize(numPhase);
46  xi.resize(numPhase);
47  nj.resize(numPhase);
48  xij.resize(numPhase * numCom);
49  rho.resize(numPhase);
50  mu.resize(numPhase);
51  // Derivatives
52  vfi.resize(numCom);
53  rhoP.resize(numPhase);
54  xiP.resize(numPhase);
55  muP.resize(numPhase);
56  rhox.resize(numPhase * numCom);
57  xix.resize(numPhase * numCom);
58  mux.resize(numPhase * numCom);
59  dXsdXp.resize((numCom + 1) * (numPhase + numPhase * numCom));
60  // Auxiliary variable
61  pSderExist.resize(numPhase);
62  pVnumCom.resize(numPhase);
63  // Thermal model
64 
65  // used in FIM_n
66  res.resize(numPhase + numPhase * numCom +
67  1); // a precomputed value stored in last position
68  // water not in hydrocarbon, hydrocarbon not in water
69  // keyDer.resize((numCom + 1) * ((numPhase - 1) * (numCom - 1) + 1));
70  };
71  virtual void SetupOptionalFeatures(OptionalFeatures& optFeatures,
72  const OCP_USI& numBulk) = 0;
74  USI GetMixtureType() const { return mixtureType; }
76  virtual void Flash(const OCP_DBL& Pin, const OCP_DBL& Tin, const OCP_DBL* Niin) = 0;
77  virtual void InitFlashIMPEC(const OCP_DBL& Pin,
78  const OCP_DBL& Pbbin,
79  const OCP_DBL& Tin,
80  const OCP_DBL* Sjin,
81  const OCP_DBL& Vpore,
82  const OCP_DBL* Ziin,
83  const OCP_USI& bId) = 0;
84  virtual void InitFlashFIM(const OCP_DBL& Pin,
85  const OCP_DBL& Pbbin,
86  const OCP_DBL& Tin,
87  const OCP_DBL* Sjin,
88  const OCP_DBL& Vpore,
89  const OCP_DBL* Ziin,
90  const OCP_USI& bId) = 0;
91  virtual void InitFlashFIMn(const OCP_DBL& Pin,
92  const OCP_DBL& Pbbin,
93  const OCP_DBL& Tin,
94  const OCP_DBL* Sjin,
95  const OCP_DBL& Vpore,
96  const OCP_DBL* Ziin,
97  const OCP_USI& bId) = 0;
99  virtual void FlashIMPEC(const OCP_DBL& Pin,
100  const OCP_DBL& Tin,
101  const OCP_DBL* Niin,
102  const USI& lastNP,
103  const OCP_DBL* xijin,
104  const OCP_USI& bId) = 0;
106  virtual void FlashFIM(const OCP_DBL& Pin,
107  const OCP_DBL& Tin,
108  const OCP_DBL* Niin,
109  const OCP_DBL* Sjin,
110  const USI& lastNP,
111  const OCP_DBL* xijin,
112  const OCP_USI& bId) = 0;
113  virtual void FlashFIMn(const OCP_DBL& Pin,
114  const OCP_DBL& Tin,
115  const OCP_DBL* Niin,
116  const OCP_DBL* Sjin,
117  const OCP_DBL* xijin,
118  const OCP_DBL* njin,
119  const USI* phaseExistin,
120  const USI& lastNP,
121  const OCP_USI& bId) = 0;
122 
124  // for blackoil model: if tarPhase is gas and water, Pin and tar phase is needed
125  // for compositional model: if tar phase is hydrocarbon phase, Pin, Tin, Ziin is
126  // needed. if tar phase is water, only Pin is needed.
127  virtual OCP_DBL XiPhase(const OCP_DBL& Pin,
128  const OCP_DBL& Tin,
129  const OCP_DBL* Ziin,
130  const USI& tarPhase) = 0;
131 
133  // for blackoil model: if tarPhase is gas and water, Pin and tar phase is needed, if
134  // tarPhase is oil,then Pbb is needed, too for compositional model: if tar phase is
135  // hydrocarbon phase, Pin, Tin, Ziin is needed. if tar phase is water, only Pin is
136  // needed.
137  virtual OCP_DBL RhoPhase(const OCP_DBL& Pin,
138  const OCP_DBL& Pbb,
139  const OCP_DBL& Tin,
140  const OCP_DBL* Ziin,
141  const USI& tarPhase) = 0;
142 
143  // for well
146  virtual void SetupWellOpt(WellOpt& opt,
147  const vector<SolventINJ>& sols,
148  const OCP_DBL& Psurf,
149  const OCP_DBL& Tsurf) = 0;
151  virtual void CalProdWeight(const OCP_DBL& Pin,
152  const OCP_DBL& Tin,
153  const OCP_DBL* Niin,
154  const vector<OCP_DBL>& prodPhase,
155  vector<OCP_DBL>& prodWeight) = 0;
157  virtual void CalProdRate(const OCP_DBL& Pin,
158  const OCP_DBL& Tin,
159  const OCP_DBL* Niin,
160  vector<OCP_DBL>& prodRate) = 0;
161  virtual OCP_DBL CalInjWellEnthalpy(const OCP_DBL& Tin, const OCP_DBL* Ziin) = 0;
162 
166  void CheckNi(const OCP_DBL* Ni)
167  {
168  OCP_BOOL flag = OCP_TRUE;
169  for (USI i = 0; i < numCom; i++) {
170  if (Ni[i] < 0) {
171  cout << "Ni[" << i << "] = " << Ni[i] << endl;
172  flag = OCP_FALSE;
173  break; // skip the rest checks
174  }
175  }
176  if (!flag) OCP_ABORT("Ni is negative!");
177  }
178 
179  virtual OCP_DBL GetErrorPEC() = 0;
180  virtual void OutMixtureIters() const = 0;
181 
182 public:
183  const OCP_DBL& GetNt() const { return Nt; }
184  const OCP_DBL& GetNi(const USI& i) const { return Ni[i]; }
185  const OCP_DBL& GetVf() const { return vf; }
186  const OCP_BOOL& GetPhaseExist(const USI& j) const { return phaseExist[j]; }
187  const OCP_DBL& GetS(const USI& j) const { return S[j]; }
188  const OCP_DBL& GetVj(const USI& j) const { return vj[j]; }
189  const OCP_DBL& GetNj(const USI& j) const { return nj[j]; }
190  const OCP_DBL& GetXij(const USI& j, const USI& i) const
191  {
192  return xij[j * numCom + i];
193  }
194  const OCP_DBL& GetRho(const USI& j) const { return rho[j]; }
195  const OCP_DBL& GetXi(const USI& j) const { return xi[j]; }
196  const OCP_DBL& GetMu(const USI& j) const { return mu[j]; }
197  const OCP_DBL& GetVfP() const { return vfP; }
198  const OCP_DBL& GetVfT() const { return vfT; }
199  const OCP_DBL& GetVfi(const USI& i) const { return vfi[i]; }
200  const OCP_DBL& GetRhoP(const USI& j) const { return rhoP[j]; }
201  const OCP_DBL& GetRhoT(const USI& j) const { return rhoT[j]; }
202  const OCP_DBL& GetXiP(const USI& j) const { return xiP[j]; }
203  const OCP_DBL& GetXiT(const USI& j) const { return xiT[j]; }
204  const OCP_DBL& GetMuP(const USI& j) const { return muP[j]; }
205  const OCP_DBL& GetMuT(const USI& j) const { return muT[j]; }
206  const OCP_DBL& GetRhoX(const USI& j, const USI& i) const
207  {
208  return rhox[j * numCom + i];
209  }
210  const OCP_DBL& GetXiX(const USI& j, const USI& i) const
211  {
212  return xix[j * numCom + i];
213  }
214  const OCP_DBL& GetMuX(const USI& j, const USI& i) const
215  {
216  return mux[j * numCom + i];
217  }
218  const OCP_BOOL& GetPSderExist(const USI& j) const { return pSderExist[j]; }
219  const USI& GetPVnumCom(const USI& j) const { return pVnumCom[j]; }
220  const vector<OCP_DBL>& GetDXsDXp() const { return dXsdXp; }
221  const vector<OCP_DBL>& GetRes() const { return res; }
222  const OCP_DBL GetResPc() const { return resPc; }
223  const OCP_DBL GetUf() const { return Uf; }
224  const OCP_DBL GetUfP() const { return UfP; }
225  const OCP_DBL GetUfT() const { return UfT; }
226  const OCP_DBL GetUfi(const USI& i) const { return Ufi[i]; }
227  const OCP_DBL GetH(const USI& j) const { return H[j]; }
228  const OCP_DBL GetHT(const USI& j) const { return HT[j]; }
229  const OCP_DBL& GetHx(const USI& j, const USI& i) const
230  {
231  return Hx[j * numCom + i];
232  }
233 
234 protected:
235  void SetBulkId(const OCP_USI& n) { bulkId = n; }
236 
237 protected:
245 
248  vector<OCP_DBL> Ni;
249  vector<OCP_BOOL> phaseExist;
250  vector<OCP_DBL> S;
251  vector<OCP_DBL> vj;
252  vector<OCP_DBL> nj;
253  vector<OCP_DBL> xij;
254  vector<OCP_DBL> rho;
255  vector<OCP_DBL> xi;
256  vector<OCP_DBL> mu;
257 
258  // Derivatives
262  vector<OCP_DBL> vfi;
264 
265  vector<OCP_DBL> rhoP;
266  vector<OCP_DBL> rhoT;
267  vector<OCP_DBL> rhox;
268  vector<OCP_DBL> xiP;
269  vector<OCP_DBL> xiT;
270  vector<OCP_DBL> xix;
271  vector<OCP_DBL> muP;
272  vector<OCP_DBL> muT;
273  vector<OCP_DBL> mux;
274 
275  vector<OCP_DBL> dXsdXp;
276 
280  vector<OCP_DBL> Ufi;
281  vector<OCP_DBL> H;
282  vector<OCP_DBL> HT;
283  vector<OCP_DBL> Hx;
284 
285  // Auxiliary variable for dSec_dPr
286  vector<OCP_BOOL> pSderExist;
287  vector<USI> pVnumCom;
288 
289  vector<OCP_DBL> res;
291  vector<OCP_DBL> keyDer;
292 };
293 
294 #endif /* end if __MIXTURE_HEADER__ */
295 
296 /*----------------------------------------------------------------------------*/
297 /* Brief Change History of This File */
298 /*----------------------------------------------------------------------------*/
299 /* Author Date Actions */
300 /*----------------------------------------------------------------------------*/
301 /* Shizhe Li Oct/01/2021 Create file */
302 /* Chensong Zhang Oct/15/2021 Format file */
303 /*----------------------------------------------------------------------------*/
Definition of build-in datatypes and consts.
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:23
double OCP_DBL
Double precision.
Definition: OCPConst.hpp:27
unsigned int OCP_USI
Long unsigned integer.
Definition: OCPConst.hpp:25
unsigned int OCP_BOOL
OCP_BOOL in OCP.
Definition: OCPConst.hpp:29
OptionalFeatures class declaration.
ParamReservoir class declaration.
#define OCP_ABORT(msg)
Abort if critical error happens.
Definition: UtilError.hpp:47
WellOpt class declaration.
OCP_DBL Psurf
well reference pressure
Definition: AllWells.hpp:184
OCP_DBL Tsurf
well reference temperature
Definition: AllWells.hpp:185
Physical information of each active reservoir bulk.
Definition: Bulk.hpp:104
virtual void CalProdRate(const OCP_DBL &Pin, const OCP_DBL &Tin, const OCP_DBL *Niin, vector< OCP_DBL > &prodRate)=0
Calculate Production rate for PROD well.
USI GetMixtureType() const
return type of mixture.
Definition: Mixture.hpp:74
OCP_DBL resPc
a precalculated value
Definition: Mixture.hpp:290
virtual void FlashFIM(const OCP_DBL &Pin, const OCP_DBL &Tin, const OCP_DBL *Niin, const OCP_DBL *Sjin, const USI &lastNP, const OCP_DBL *xijin, const OCP_USI &bId)=0
Flash calculation with moles of components and Calculate the derivative.
vector< OCP_DBL > rhoP
d rho / dP: numphase
Definition: Mixture.hpp:265
virtual OCP_DBL XiPhase(const OCP_DBL &Pin, const OCP_DBL &Tin, const OCP_DBL *Ziin, const USI &tarPhase)=0
return mass density of phase
virtual OCP_DBL RhoPhase(const OCP_DBL &Pin, const OCP_DBL &Pbb, const OCP_DBL &Tin, const OCP_DBL *Ziin, const USI &tarPhase)=0
return mass density of phase
vector< OCP_DBL > muT
d mu j / dT: numPhase
Definition: Mixture.hpp:272
USI numCom
num of components.
Definition: Mixture.hpp:242
vector< OCP_DBL > dXsdXp
derivatives of second variables wrt. primary variables
Definition: Mixture.hpp:275
vector< OCP_DBL > rho
mass density of phase: numPhase
Definition: Mixture.hpp:254
vector< OCP_DBL > mu
viscosity of phase: numPhase
Definition: Mixture.hpp:256
vector< OCP_DBL > Ufi
dUf / dNi
Definition: Mixture.hpp:280
virtual void SetupWellOpt(WellOpt &opt, const vector< SolventINJ > &sols, const OCP_DBL &Psurf, const OCP_DBL &Tsurf)=0
OCP_DBL P
pressure when flash calculation.
Definition: Mixture.hpp:243
vector< OCP_BOOL > pSderExist
Existence of derivative of phase saturation.
Definition: Mixture.hpp:286
USI numPhase
num of phases.
Definition: Mixture.hpp:241
OCP_DBL vfT
d vf / dT
Definition: Mixture.hpp:261
vector< OCP_DBL > xix
d xi[j] / d x[i][j]: numphase * numCom
Definition: Mixture.hpp:270
vector< OCP_DBL > vj
volume of phase: numPhase;
Definition: Mixture.hpp:251
OCP_USI bulkId
index of current bulk
Definition: Mixture.hpp:240
OCP_DBL vfP
Definition: Mixture.hpp:259
vector< OCP_DBL > rhox
d rho[j] / d x[i][j]: numphase * numCom
Definition: Mixture.hpp:267
OCP_DBL T
temperature when flash calculation.
Definition: Mixture.hpp:244
vector< OCP_DBL > Hx
d Hj / d xij
Definition: Mixture.hpp:283
vector< OCP_DBL > S
saturation of phase: numPhase
Definition: Mixture.hpp:250
virtual void CalProdWeight(const OCP_DBL &Pin, const OCP_DBL &Tin, const OCP_DBL *Niin, const vector< OCP_DBL > &prodPhase, vector< OCP_DBL > &prodWeight)=0
Calculate ProdWeight for PROD well.
vector< OCP_DBL > xij
Nij / nj: numPhase*numCom.
Definition: Mixture.hpp:253
vector< OCP_DBL > H
Enthalpy.
Definition: Mixture.hpp:281
OCP_DBL Nt
Total moles of Components.
Definition: Mixture.hpp:247
vector< OCP_DBL > xiT
d xi j / dT: numPhase
Definition: Mixture.hpp:269
vector< OCP_DBL > nj
mole number of phase j
Definition: Mixture.hpp:252
vector< OCP_DBL > Ni
moles of component: numCom
Definition: Mixture.hpp:248
void CheckNi(const OCP_DBL *Ni)
Definition: Mixture.hpp:166
vector< OCP_DBL > HT
d Hj / d T
Definition: Mixture.hpp:282
vector< OCP_DBL > vfi
Definition: Mixture.hpp:262
OCP_DBL Uf
Internal energy of fluid.
Definition: Mixture.hpp:277
vector< OCP_BOOL > phaseExist
existence of phase: numPhase
Definition: Mixture.hpp:249
vector< OCP_DBL > rhoT
d rho j / dT: numPhase
Definition: Mixture.hpp:266
virtual void FlashIMPEC(const OCP_DBL &Pin, const OCP_DBL &Tin, const OCP_DBL *Niin, const USI &lastNP, const OCP_DBL *xijin, const OCP_USI &bId)=0
Flash calculation with moles of components.
vector< OCP_DBL > keyDer
d (xij*xi/mu) / dP or dNk
Definition: Mixture.hpp:291
vector< OCP_DBL > xiP
d xi / dP: numphase
Definition: Mixture.hpp:268
OCP_DBL vf
volume of total fluids.
Definition: Mixture.hpp:246
vector< USI > pVnumCom
num of variable components in the phase
Definition: Mixture.hpp:287
vector< OCP_DBL > muP
d mu / dP: numPhase
Definition: Mixture.hpp:271
virtual void Flash(const OCP_DBL &Pin, const OCP_DBL &Tin, const OCP_DBL *Niin)=0
flash calculation with saturation of phases.
vector< OCP_DBL > mux
d mu[j] / d x[i][j]: numphase * numCom
Definition: Mixture.hpp:273
vector< OCP_DBL > res
residual of a set of equations
Definition: Mixture.hpp:289
OCP_DBL UfP
dUf / dP
Definition: Mixture.hpp:278
OCP_DBL UfT
dUf / dT
Definition: Mixture.hpp:279
USI mixtureType
Definition: Mixture.hpp:238
void Allocate()
Allocate memory for common variables for basic class.
Definition: Mixture.hpp:40
vector< OCP_DBL > xi
molar density of phase: numPhase
Definition: Mixture.hpp:255
Definition: Well.hpp:45