OpenCAEPoro  0.2.0 Sep/22/2022
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 "ParamReservoir.hpp"
22 
23 using namespace std;
24 
28 class Mixture
29 {
30  friend class Bulk;
31  friend class Well;
32  friend class AllWells;
33 
34 public:
35  Mixture() = default;
36  virtual ~Mixture(){};
38  void Allocate()
39  {
40  Ni.resize(numCom);
41  phaseExist.resize(numPhase);
42  v.resize(numPhase);
43  S.resize(numPhase);
44  xi.resize(numPhase);
45  nj.resize(numPhase);
46  xij.resize(numPhase * numCom);
47  rho.resize(numPhase);
48  mu.resize(numPhase);
49  vfi.resize(numCom);
50  vji.resize(numPhase);
51  for (auto& v : vji) {
52  v.resize(numCom, 0);
53  }
54  vjp.resize(numPhase, 0);
55  // Derivatives for FIM
56  rhoP.resize(numPhase);
57  xiP.resize(numPhase);
58  muP.resize(numPhase);
59  rhoN.resize(numPhase * numCom);
60  xiN.resize(numPhase * numCom);
61  muN.resize(numPhase * numCom);
62  rhox.resize(numPhase * numCom);
63  xix.resize(numPhase * numCom);
64  mux.resize(numPhase * numCom);
65  dXsdXp.resize((numCom + 1) * (numPhase + numPhase * numCom));
66  pEnumCom.resize(numPhase);
67  res.resize(numPhase + numPhase * numCom + 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  };
72  virtual void SetPVTW(){};
74  USI GetType() const { return mixtureType; }
76  virtual bool IsEmpty_PVDG() const { return true; };
78  virtual void InitFlash(const OCP_DBL& Pin, const OCP_DBL& Pbbin, const OCP_DBL& Tin,
79  const OCP_DBL* Sjin, const OCP_DBL& Vpore,
80  const OCP_DBL* Ziin) = 0;
81  virtual void InitFlashDer(const OCP_DBL& Pin, const OCP_DBL& Pbbin,
82  const OCP_DBL& Tin, const OCP_DBL* Sjin,
83  const OCP_DBL& Vpore, const OCP_DBL* Ziin) = 0;
84  virtual void InitFlashDer_n(const OCP_DBL& Pin, const OCP_DBL& Pbbin,
85  const OCP_DBL& Tin, const OCP_DBL* Sjin,
86  const OCP_DBL& Vpore, const OCP_DBL* Ziin) = 0;
88  virtual void Flash(const OCP_DBL& Pin, const OCP_DBL& Tin,
89  const OCP_DBL* Niin, const USI& ftype, const USI& lastNP,
90  const OCP_DBL* lastKs) = 0;
92  virtual void FlashDeriv(const OCP_DBL& Pin, const OCP_DBL& Tin,
93  const OCP_DBL* Niin, const USI& ftype, const USI& lastNP,
94  const OCP_DBL* lastKs) = 0;
95  virtual void FlashDeriv_n(const OCP_DBL& Pin, const OCP_DBL& Tin,
96  const OCP_DBL* Niin, const OCP_DBL* Sjin, const OCP_DBL* xijin,
97  const OCP_DBL* njin, const USI& ftype, const USI* phaseExistin,
98  const USI& lastNP, const OCP_DBL* lastKs) = 0;
101  virtual OCP_DBL XiPhase(const OCP_DBL& Pin, const OCP_DBL& Tin,
102  const OCP_DBL* Ziin) = 0;
103 
105  virtual OCP_DBL RhoPhase(const OCP_DBL& Pin, const OCP_DBL& Tin,
106  const OCP_DBL* Ziin) = 0;
107 
109  virtual OCP_DBL GammaPhaseO(const OCP_DBL& Pin, const OCP_DBL& Pbbin) = 0;
111  virtual OCP_DBL GammaPhaseW(const OCP_DBL& Pin) = 0;
113  virtual OCP_DBL GammaPhaseG(const OCP_DBL& Pin) = 0;
116  virtual OCP_DBL GammaPhaseOG(const OCP_DBL& Pin, const OCP_DBL& Tin,
117  const OCP_DBL* Ziin) = 0;
118 
122  void CheckNi(const OCP_DBL* Ni)
123  {
124  bool flag = true;
125  for (USI i = 0; i < numCom; i++) {
126  if (Ni[i] < 0) {
127  cout << "Ni[" << i << "] = " << Ni[i] << endl;
128  flag = false;
129  break; // skip the rest checks
130  }
131  }
132  if (!flag) OCP_ABORT("Ni is negative!");
133  }
134  // used in Compositional Model
135  virtual USI GetFtype() = 0;
136  virtual OCP_SIN GetMinEigenSkip() = 0;
137  virtual bool GetFlagSkip() = 0;
138  virtual OCP_DBL GetSurTen() = 0;
139 
140  virtual OCP_DBL GetErrorPEC() = 0;
141  virtual OCP_ULL GetSSMSTAiters() = 0;
142  virtual OCP_ULL GetNRSTAiters() = 0;
143  virtual OCP_ULL GetSSMSPiters() = 0;
144  virtual OCP_ULL GetNRSPiters() = 0;
145  virtual OCP_ULL GetRRiters() = 0;
146  virtual OCP_ULL GetSSMSTAcounts() = 0;
147  virtual OCP_ULL GetNRSTAcounts() = 0;
148  virtual OCP_ULL GetSSMSPcounts() = 0;
149  virtual OCP_ULL GetNRSPcounts() = 0;
150  virtual OCP_ULL GetRRcounts() = 0;
151 
152 protected:
155 
160 
161  vector<OCP_DBL> Ni;
162  vector<bool> phaseExist;
163  vector<OCP_DBL> S;
164  vector<OCP_DBL> rho;
165  vector<OCP_DBL> xi;
166  vector<OCP_DBL> xij;
168  vector<OCP_DBL> nj;
169  vector<OCP_DBL> mu;
170  vector<OCP_DBL> v;
171 
174 
175  // Derivatives
176 
177  vector<vector<OCP_DBL>> vji;
178  vector<OCP_DBL> vjp;
179 
182  vector<OCP_DBL> vfi;
184 
185  vector<OCP_DBL> muP;
186  vector<OCP_DBL> xiP;
187  vector<OCP_DBL> rhoP;
188  vector<OCP_DBL> muN;
189  vector<OCP_DBL> xiN;
190  vector<OCP_DBL> rhoN;
191  vector<OCP_DBL> mux;
192  vector<OCP_DBL> xix;
193  vector<OCP_DBL> rhox;
194 
195  vector<OCP_DBL> dXsdXp;
196  vector<USI> pEnumCom;
197  vector<OCP_DBL> res;
199 
200  vector<OCP_DBL> keyDer;
201 };
202 
203 #endif /* end if __MIXTURE_HEADER__ */
204 
205 /*----------------------------------------------------------------------------*/
206 /* Brief Change History of This File */
207 /*----------------------------------------------------------------------------*/
208 /* Author Date Actions */
209 /*----------------------------------------------------------------------------*/
210 /* Shizhe Li Oct/01/2021 Create file */
211 /* Chensong Zhang Oct/15/2021 Format file */
212 /*----------------------------------------------------------------------------*/
Definition of build-in datatypes and consts.
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:22
double OCP_DBL
Double precision.
Definition: OCPConst.hpp:26
float OCP_SIN
Single precision.
Definition: OCPConst.hpp:27
unsigned long long OCP_ULL
Long long unsigned integer.
Definition: OCPConst.hpp:23
ParamReservoir class declaration.
#define OCP_ABORT(msg)
Abort if critical error happens.
Definition: UtilError.hpp:47
Physical information of each active reservoir bulk.
Definition: Bulk.hpp:58
virtual OCP_DBL GammaPhaseW(const OCP_DBL &Pin)=0
return gamma of water phase, gamma equals to mass density times gravity factor.
OCP_DBL resPc
a precalculated value
Definition: Mixture.hpp:198
vector< OCP_DBL > rhoP
d rho / dP: numphase
Definition: Mixture.hpp:187
vector< USI > pEnumCom
see pEnumCom in bulk
Definition: Mixture.hpp:196
USI numCom
num of components.
Definition: Mixture.hpp:157
vector< OCP_DBL > dXsdXp
the derivates of second variables wrt. primary variables
Definition: Mixture.hpp:195
vector< OCP_DBL > rho
mass density of phase: numPhase
Definition: Mixture.hpp:164
vector< OCP_DBL > mu
viscosity of phase: numPhase
Definition: Mixture.hpp:169
vector< bool > phaseExist
existence of phase: numPhase
Definition: Mixture.hpp:162
OCP_DBL P
pressure when flash calculation.
Definition: Mixture.hpp:158
vector< OCP_DBL > vjp
dvj / dp, used in 2 hydrocarbon phase in EOS
Definition: Mixture.hpp:178
USI numPhase
num of phases.
Definition: Mixture.hpp:156
vector< OCP_DBL > xiN
d xi[j] / d N[i]: numphase * numCom
Definition: Mixture.hpp:189
virtual void InitFlash(const OCP_DBL &Pin, const OCP_DBL &Pbbin, const OCP_DBL &Tin, const OCP_DBL *Sjin, const OCP_DBL &Vpore, const OCP_DBL *Ziin)=0
flash calculation with saturation of phases.
virtual void Flash(const OCP_DBL &Pin, const OCP_DBL &Tin, const OCP_DBL *Niin, const USI &ftype, const USI &lastNP, const OCP_DBL *lastKs)=0
Flash calculation with moles of components.
vector< vector< OCP_DBL > > vji
dvj / dNi, used in 2 hydrocarbon phase in EOS; or dvj / dnij
Definition: Mixture.hpp:177
vector< OCP_DBL > xix
d xi[j] / d x[i][j]: numphase * numCom
Definition: Mixture.hpp:192
virtual OCP_DBL GammaPhaseOG(const OCP_DBL &Pin, const OCP_DBL &Tin, const OCP_DBL *Ziin)=0
virtual OCP_DBL GammaPhaseO(const OCP_DBL &Pin, const OCP_DBL &Pbbin)=0
return gamma of oil phase, gamma equals to mass density times gravity factor.
vector< OCP_DBL > rhox
d rho[j] / d x[i][j]: numphase * numCom
Definition: Mixture.hpp:193
OCP_DBL T
temperature when flash calculation.
Definition: Mixture.hpp:159
vector< OCP_DBL > v
volume of phase: numPhase;
Definition: Mixture.hpp:170
vector< OCP_DBL > S
saturation of phase: numPhase
Definition: Mixture.hpp:163
vector< OCP_DBL > muN
d mu[j] / d N[i]: numphase * numCom
Definition: Mixture.hpp:188
virtual void FlashDeriv(const OCP_DBL &Pin, const OCP_DBL &Tin, const OCP_DBL *Niin, const USI &ftype, const USI &lastNP, const OCP_DBL *lastKs)=0
Flash calculation with moles of components and Calculate the derivative.
vector< OCP_DBL > xij
Definition: Mixture.hpp:166
OCP_DBL Nt
Total moles of Components.
Definition: Mixture.hpp:173
virtual OCP_DBL GammaPhaseG(const OCP_DBL &Pin)=0
return gamma of gas phase, gamma equals to mass density times gravity factor.
vector< OCP_DBL > nj
mole number of phase j
Definition: Mixture.hpp:168
vector< OCP_DBL > Ni
moles of component: numCom
Definition: Mixture.hpp:161
void CheckNi(const OCP_DBL *Ni)
Definition: Mixture.hpp:122
virtual OCP_DBL XiPhase(const OCP_DBL &Pin, const OCP_DBL &Tin, const OCP_DBL *Ziin)=0
virtual bool IsEmpty_PVDG() const
Check whether Table PVDG is empty, it will only be used in black oil model.
Definition: Mixture.hpp:76
vector< OCP_DBL > vfi
Definition: Mixture.hpp:182
vector< OCP_DBL > keyDer
d (xij*xi/mu) / dP or dNk
Definition: Mixture.hpp:200
vector< OCP_DBL > xiP
d xi / dP: numphase
Definition: Mixture.hpp:186
OCP_DBL vf
volume of total fluids.
Definition: Mixture.hpp:172
vector< OCP_DBL > rhoN
d rho[j] / d N[i]: numphase * numCom
Definition: Mixture.hpp:190
USI GetType() const
return type of mixture.
Definition: Mixture.hpp:74
virtual OCP_DBL RhoPhase(const OCP_DBL &Pin, const OCP_DBL &Tin, const OCP_DBL *Ziin)=0
return mass density of phase.
OCP_DBL vfp
Definition: Mixture.hpp:180
vector< OCP_DBL > muP
d mu / dP: numPhase
Definition: Mixture.hpp:185
vector< OCP_DBL > mux
d mu[j] / d x[i][j]: numphase * numCom
Definition: Mixture.hpp:191
vector< OCP_DBL > res
residual of a set of equations
Definition: Mixture.hpp:197
USI mixtureType
Definition: Mixture.hpp:153
void Allocate()
Allocate memory for common variables for basic class.
Definition: Mixture.hpp:38
vector< OCP_DBL > xi
molar density of phase: numPhase
Definition: Mixture.hpp:165
Definition: Well.hpp:105