OpenCAEPoro  v0.5.0
A simulator for multicomponent porous media flow
ParamWell.cpp
Go to the documentation of this file.
1 
12 #include "ParamWell.hpp"
13 
14 WellOptParam::WellOptParam(string intype, vector<string>& vbuf)
15 {
16  type = intype;
17  if (type == "INJ") {
18  fluidType = vbuf[1];
19  state = vbuf[2];
20  optMode = vbuf[3];
21  if (vbuf[4] == "1*") {
22  if (optMode == "BHP")
23  maxRate = 1E10;
24  else {
25  cout << "### ERROR: Inj Rate is missing in WCONINJE!" << endl;
26  }
27  } else {
28  maxRate = stod(vbuf[4]);
29  }
30  maxBHP = stod(vbuf[5]);
31  } else if (type == "PROD") {
32  state = vbuf[1];
33  optMode = vbuf[2];
34  if (vbuf[3] == "1*") {
35  if (optMode == "BHP")
36  maxRate = 1E10;
37  else {
38  cout << "### ERROR: Prod Rate is missing in WCONINJE!" << endl;
39  }
40  } else {
41  maxRate = stod(vbuf[3]);
42  }
43  minBHP = stod(vbuf[4]);
44  } else {
45  OCP_ABORT("Wrong Well Type!");
46  }
47 }
48 
49 WellParam::WellParam(vector<string>& info)
50 {
51  name = info[0];
52  if (info[1] != "DEFAULT") group = info[1];
53  I = stoi(info[2]);
54  J = stoi(info[3]);
55  if (info[4] != "DEFAULT") depth = stod(info[4]);
56 }
57 
58 Solvent::Solvent(const vector<string>& vbuf)
59 {
60  name = vbuf[0];
61  USI len = vbuf.size();
62  for (USI i = 0; i < len - 1; i++) {
63  if (vbuf[i + 1] == "/") break;
64  comRatio.push_back(stod(vbuf[i + 1]));
65  }
66 }
67 
68 void ParamWell::InputWELSPECS(ifstream& ifs)
69 {
70  vector<string> vbuf;
71  while (ReadLine(ifs, vbuf)) {
72  if (vbuf[0] == "/") break;
73 
74  DealDefault(vbuf);
75  well.push_back(WellParam(vbuf));
76  }
77  // cout << "WELSPECS" << endl;
78 }
79 
80 void ParamWell::InputCOMPDAT(ifstream& ifs)
81 {
82  USI num = well.size();
83  vector<string> vbuf;
84  while (ReadLine(ifs, vbuf)) {
85  if (vbuf[0] == "/") break;
86 
87  DealDefault(vbuf);
88  string src = vbuf[0];
89  string::size_type pos = src.find("*");
90  OCP_BOOL match = (pos != string::npos);
91  if (match) {
92  src.erase(pos);
93  }
94  OCP_BOOL tmp = OCP_FALSE;
95 
96  for (USI w = 0; w < num; w++) {
97  if (match)
98  tmp = (well[w].name.substr(0, pos) == src);
99  else
100  tmp = (well[w].name == src);
101 
102  if (tmp) {
103 
104  USI k1 = stoi(vbuf[3]);
105  USI k2 = stoi(vbuf[4]);
106 
107  for (USI k = k1; k <= k2; k++) {
108  if (vbuf[1] == "DEFAULT" || vbuf[2] == "DEFAULT") {
109  well[w].I_perf.push_back(well[w].I);
110  well[w].J_perf.push_back(well[w].J);
111  } else {
112  well[w].I_perf.push_back(stoi(vbuf[1]));
113  well[w].J_perf.push_back(stoi(vbuf[2]));
114  }
115  well[w].K_perf.push_back(k);
116 
117  if (vbuf[5] != "DEFAULT")
118  well[w].WI.push_back(stod(vbuf[5]));
119  else
120  well[w].WI.push_back(-1.0);
121 
122  if (vbuf[6] != "DEFAULT")
123  well[w].diameter.push_back(stod(vbuf[6]));
124  else
125  well[w].diameter.push_back(1.0);
126 
127  if (vbuf[7] != "DEFAULT")
128  well[w].kh.push_back(stod(vbuf[7]));
129  else
130  well[w].kh.push_back(-1.0);
131 
132  if (vbuf[8] != "DEFAULT")
133  well[w].skinFactor.push_back(stod(vbuf[8]));
134  else
135  well[w].skinFactor.push_back(0.0);
136 
137  if (vbuf[9] != "DEFAULT")
138  well[w].direction.push_back(vbuf[9]);
139  else
140  well[w].direction.push_back("z");
141  }
142  }
143  }
144  }
145  // cout << "COMPDAT" << endl;
146 }
147 
148 void ParamWell::InputWCONINJE(ifstream& ifs)
149 {
150  assert(criticalTime.size() > 0);
151 
152  const USI d = criticalTime.size() - 1;
153  const USI num = well.size();
154  vector<string> vbuf;
155  while (ReadLine(ifs, vbuf)) {
156  if (vbuf[0] == "/") break;
157 
158  DealDefault(vbuf);
159  string src = vbuf[0];
160  string::size_type pos = src.find("*");
161  const OCP_BOOL fuzzyMatch = (pos != string::npos);
162  if (fuzzyMatch) {
163  src.erase(pos);
164  }
165 
166  if (fuzzyMatch) {
167  for (USI w = 0; w < num; w++) {
168  if (well[w].name.find(src) != string::npos) {
169  well[w].optParam.push_back(WellOptPair(d, "INJ", vbuf));
170  }
171  }
172  } else {
173  for (USI w = 0; w < num; w++) {
174  if (well[w].name == src) {
175  well[w].optParam.push_back(WellOptPair(d, "INJ", vbuf));
176  }
177  }
178  }
179  }
180  // cout << "WCONINJE" << endl;
181 }
182 
183 void ParamWell::InputWCONPROD(ifstream& ifs)
184 {
185  assert(criticalTime.size() > 0);
186 
187  const USI d = criticalTime.size() - 1;
188  const USI num = well.size();
189  vector<string> vbuf;
190  while (ReadLine(ifs, vbuf)) {
191  if (vbuf[0] == "/") break;
192 
193  DealDefault(vbuf);
194  string src = vbuf[0];
195  string::size_type pos = src.find("*");
196  const OCP_BOOL fuzzyMatch = (pos != string::npos);
197  if (fuzzyMatch) {
198  src.erase(pos);
199  }
200 
201  if (fuzzyMatch) {
202  for (USI w = 0; w < num; w++)
203  if (well[w].name.find(src) != string::npos)
204  well[w].optParam.push_back(WellOptPair(d, "PROD", vbuf));
205  } else {
206  for (USI w = 0; w < num; w++)
207  if (well[w].name == src)
208  well[w].optParam.push_back(WellOptPair(d, "PROD", vbuf));
209  }
210  }
211  // cout << "WCONPROD" << endl;
212 }
213 
214 void ParamWell::InputTSTEP(ifstream& ifs)
215 {
216  assert(criticalTime.size() > 0);
217 
218  vector<string> vbuf;
219  while (ReadLine(ifs, vbuf)) {
220  if (vbuf[0] == "/") break;
221 
222  DealDefault(vbuf);
223  OCP_INT len = vbuf.size();
224  for (OCP_INT i = 0; i < len - 1; i++) {
225  OCP_DBL t = criticalTime.back() + stod(vbuf[i]);
226  criticalTime.push_back(t);
227  }
228  if (vbuf.back() != "/") {
229  OCP_DBL t = criticalTime.back() + stod(vbuf.back());
230  criticalTime.push_back(t);
231  }
232  }
233 }
234 
235 void ParamWell::InputWELTARG(ifstream& ifs)
236 {
237  assert(criticalTime.size() > 0);
238 
239  cout << "\n---------------------" << endl
240  << "WELTARG"
241  << "\n---------------------" << endl;
242 
243  const USI d = criticalTime.size() - 1;
244  const USI num = well.size();
245  vector<string> vbuf;
246  while (ReadLine(ifs, vbuf)) {
247  if (vbuf[0] == "/") break;
248 
249  for (const auto& s : vbuf) {
250  cout << s << " ";
251  }
252  cout << endl;
253 
254  string src = vbuf[0];
255  string::size_type pos = src.find("*");
256  const OCP_BOOL fuzzyMatch = (pos != string::npos);
257  if (fuzzyMatch) {
258  src.erase(pos);
259  }
260  OCP_BOOL succMatch = OCP_FALSE;
261 
262  for (USI w = 0; w < num; w++) {
263  if (fuzzyMatch)
264  succMatch = (well[w].name.find(src) != string::npos);
265  else
266  succMatch = (well[w].name == src);
267 
268  if (succMatch) {
269  if (well[w].optParam.size() == 0) {
270  OCP_ABORT("No Well Control Defined in Advance!");
271  }
272  WellOptPair tar = well[w].optParam.back();
273  tar.d = d;
274  tar.opt.optMode = vbuf[1];
275  OCP_DBL val = stod(vbuf[2]);
276  if (vbuf[1] == "BHP") {
277  if (tar.opt.type == "INJ")
278  tar.opt.maxBHP = val;
279  else
280  tar.opt.minBHP = val;
281  } else {
282  tar.opt.maxRate = val;
283  }
284  well[w].optParam.push_back(tar);
285  }
286  }
287  }
288 }
289 
290 void ParamWell::InputWTEMP(ifstream& ifs)
291 {
292  assert(criticalTime.size() > 0);
293 
294  cout << "\n---------------------" << endl
295  << "WTEMP"
296  << "\n---------------------" << endl;
297 
298  const USI d = criticalTime.size() - 1;
299  const USI numWell = well.size();
300  vector<string> vbuf;
301  while (ReadLine(ifs, vbuf)) {
302  if (vbuf[0] == "/") break;
303 
304  for (const auto& s : vbuf) {
305  cout << s << " ";
306  }
307  cout << endl;
308 
309  string src = vbuf[0];
310  string::size_type pos = src.find("*");
311  const OCP_BOOL fuzzyMatch = (pos != string::npos);
312  if (fuzzyMatch) {
313  src.erase(pos);
314  }
315  OCP_BOOL succMatch = OCP_FALSE;
316 
317  for (USI w = 0; w < numWell; w++) {
318  if (fuzzyMatch)
319  succMatch = (well[w].name.find(src) != string::npos);
320  else
321  succMatch = (well[w].name == src);
322 
323  if (succMatch) {
324  if (well[w].optParam.size() == 0) {
325  OCP_ABORT("No Well Control Defined in Advance!");
326  }
327  WellOptPair tar = well[w].optParam.back();
328  tar.d = d;
329  tar.opt.injTemp = stod(vbuf[1]);
330  well[w].optParam.push_back(tar);
331  }
332  }
333  }
334 }
335 
336 void ParamWell::InputUNWEIGHT(ifstream& ifs)
337 {
338  assert(criticalTime.size() > 0);
339 
340  cout << "\n---------------------" << endl
341  << "UNWEIGHT"
342  << "\n---------------------" << endl;
343 
344  const USI num = well.size();
345  vector<string> vbuf;
346  while (ReadLine(ifs, vbuf)) {
347  if (vbuf[0] == "/") break;
348 
349  for (const auto& s : vbuf) {
350  cout << s << " ";
351  }
352  cout << endl;
353 
354  DealDefault(vbuf);
355  string src = vbuf[0];
356  string::size_type pos = src.find("*");
357  const OCP_BOOL fuzzyMatch = (pos != string::npos);
358  if (fuzzyMatch) {
359  src.erase(pos);
360  }
361 
362  if (fuzzyMatch) {
363  for (USI w = 0; w < num; w++)
364  if (well[w].name.find(src) != string::npos)
365  well[w].ifUseUnweight = OCP_TRUE;
366  } else {
367  for (USI w = 0; w < num; w++)
368  if (well[w].name == src) well[w].ifUseUnweight = OCP_TRUE;
369  }
370  }
371 }
372 
373 void ParamWell::InputWELLSTRE(ifstream& ifs)
374 {
375  vector<string> vbuf;
376  while (ReadLine(ifs, vbuf)) {
377  if (vbuf[0] == "/") break;
378  solSet.push_back(Solvent(vbuf));
379  }
380  // cout << "WELLSTRE" << endl;
381 }
382 
383 void ParamWell::InputPSURF(ifstream& ifs)
384 {
385  vector<string> vbuf;
386  ReadLine(ifs, vbuf);
387 
388  Psurf = stod(vbuf[0]);
389 
390  cout << "\n---------------------" << endl
391  << "PSURF"
392  << "\n---------------------" << endl;
393  cout << Psurf << endl;
394 }
395 
396 void ParamWell::InputTSURF(ifstream& ifs)
397 {
398  vector<string> vbuf;
399  ReadLine(ifs, vbuf);
400 
401  Tsurf = stod(vbuf[0]);
402 
403  cout << "\n---------------------" << endl
404  << "TSURF"
405  << "\n---------------------" << endl;
406  cout << Tsurf << endl;
407 }
408 
409 // check
410 void ParamWell::CheckParam(const OCP_BOOL& boModel) const
411 {
412  if (boModel) {
413  CheckINJFluid();
414  }
415  CheckPerf();
416 }
417 
418 void ParamWell::CheckINJFluid() const
419 {
420  USI wellnum = well.size();
421  USI len;
422  for (USI w = 0; w < wellnum; w++) {
423  len = well[w].optParam.size();
424  for (USI i = 0; i < len; i++) {
425  const WellOptParam& tmpOpt = well[w].optParam[i].opt;
426  if (tmpOpt.type == "INJ") {
427  if (tmpOpt.fluidType == "WAT" || tmpOpt.fluidType == "WATER") {
428  } else if (tmpOpt.fluidType == "GAS") {
429  } else {
430  OCP_ABORT("Wrong FluidType!");
431  }
432  }
433  }
434  }
435 }
436 
438 {
439  USI wellnum = well.size();
440  USI perfnum;
441  for (USI w = 0; w < wellnum; w++) {
442  perfnum = well[w].I_perf.size();
443  if (well[w].J_perf.size() != perfnum) {
444  OCP_ABORT("Wrong perforation size J_perf!");
445  }
446  if (well[w].K_perf.size() != perfnum) {
447  OCP_ABORT("Wrong perforation size K_perf!");
448  }
449  if (well[w].diameter.size() != perfnum) {
450  OCP_ABORT("Wrong perforation diameter size!");
451  }
452  if (well[w].WI.size() != perfnum) {
453  OCP_ABORT("Wrong perforation WI size!");
454  }
455  if (well[w].kh.size() != perfnum) {
456  OCP_ABORT("Wrong perforation kh size!");
457  }
458  if (well[w].skinFactor.size() != perfnum) {
459  OCP_ABORT("Wrong perforation skinFactor size!");
460  }
461  if (well[w].direction.size() != perfnum) {
462  OCP_ABORT("Wrong perforation direction size!");
463  }
464  }
465 }
466 
467 /*----------------------------------------------------------------------------*/
468 /* Brief Change History of This File */
469 /*----------------------------------------------------------------------------*/
470 /* Author Date Actions */
471 /*----------------------------------------------------------------------------*/
472 /* Shizhe Li Oct/01/2021 Create file */
473 /* Chensong Zhang Oct/15/2021 Format file */
474 /* Chensong Zhang Oct/27/2021 Unify error messages */
475 /*----------------------------------------------------------------------------*/
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:23
double OCP_DBL
Double precision.
Definition: OCPConst.hpp:27
int OCP_INT
Long integer.
Definition: OCPConst.hpp:26
unsigned int OCP_BOOL
OCP_BOOL in OCP.
Definition: OCPConst.hpp:29
ParamWell class declaration.
#define OCP_ABORT(msg)
Abort if critical error happens.
Definition: UtilError.hpp:47
void DealDefault(vector< string > &result)
Definition: UtilInput.cpp:50
OCP_BOOL ReadLine(ifstream &ifs, vector< string > &result)
Definition: UtilInput.cpp:14
void InputWTEMP(ifstream &ifs)
Input the temperature of injected fluid.
Definition: ParamWell.cpp:290
void InputWCONPROD(ifstream &ifs)
Definition: ParamWell.cpp:183
void InputPSURF(ifstream &ifs)
Input surface pressure.
Definition: ParamWell.cpp:383
void InputWELLSTRE(ifstream &ifs)
Definition: ParamWell.cpp:373
OCP_DBL Psurf
Pressure in surface condition.
Definition: ParamWell.hpp:105
void InputWELSPECS(ifstream &ifs)
Definition: ParamWell.cpp:68
vector< Solvent > solSet
Sets of Solvent.
Definition: ParamWell.hpp:104
void InputWELTARG(ifstream &ifs)
Definition: ParamWell.cpp:235
void InputTSTEP(ifstream &ifs)
Definition: ParamWell.cpp:214
void CheckPerf() const
Check if params of Perforation is wrong.
Definition: ParamWell.cpp:437
vector< OCP_DBL > criticalTime
Records the critical time given by users.
Definition: ParamWell.hpp:103
void InputWCONINJE(ifstream &ifs)
Definition: ParamWell.cpp:148
OCP_DBL Tsurf
Temperature in surface condition.
Definition: ParamWell.hpp:106
void InputUNWEIGHT(ifstream &ifs)
Input injector type – MOBWEIGHT(defaulted) or UNWEIGHT.
Definition: ParamWell.cpp:336
void InputTSURF(ifstream &ifs)
Input surface temperature.
Definition: ParamWell.cpp:396
void InputCOMPDAT(ifstream &ifs)
Definition: ParamWell.cpp:80
void CheckParam(const OCP_BOOL &boModel) const
Check if wrong params are input.
Definition: ParamWell.cpp:410
vector< WellParam > well
Contains all the information of wells.
Definition: ParamWell.hpp:102
Describe the molar fraction of components of fluid injected to reservoir from INJ.
Definition: ParamWell.hpp:87
OCP_DBL maxBHP
Maximum allowable pressure in the injection well.
Definition: ParamWell.hpp:39
string type
Type of well, injection or production?
Definition: ParamWell.hpp:33
string fluidType
Type of fluid into the injection well. (injection well only)
Definition: ParamWell.hpp:34
OCP_DBL injTemp
Temperature of injected fluid.
Definition: ParamWell.hpp:41
OCP_DBL maxRate
Maximum allowable flow rate into/out the well.
Definition: ParamWell.hpp:38
string optMode
Mode of well, Rate or BHP?
Definition: ParamWell.hpp:36
OCP_DBL minBHP
Minimum allowable pressure in the production well.
Definition: ParamWell.hpp:40
string state
State of well, open or close?
Definition: ParamWell.hpp:35
TODO: Add Doxygen.
Definition: ParamWell.hpp:59
OCP_DBL depth
Depth of well.
Definition: ParamWell.hpp:68
USI I
I index of well.
Definition: ParamWell.hpp:66
string name
Name of Well.
Definition: ParamWell.hpp:64
USI J
J index of well.
Definition: ParamWell.hpp:67
string group
Group the well belongs to.
Definition: ParamWell.hpp:65