OpenCAEPoro  0.2.0 Sep/22/2022
A simulator for multicomponent porous media flow
ParamWell.cpp
Go to the documentation of this file.
1 
12 #include "ParamWell.hpp"
13 #include "UtilError.hpp"
14 
15 WellOptParam::WellOptParam(string intype, vector<string>& vbuf)
16 {
17  type = intype;
18  if (type == "INJ") {
19  fluidType = vbuf[1];
20  state = vbuf[2];
21  optMode = vbuf[3];
22  if (vbuf[4] == "1*") {
23  if (optMode == "BHP")
24  maxRate = 1E10;
25  else {
26  cout << "### ERROR: Inj Rate is missing in WCONINJE!" << endl;
27  }
28  } else {
29  maxRate = stod(vbuf[4]);
30  }
31  maxBHP = stod(vbuf[5]);
32  } else if (type == "PROD") {
33  state = vbuf[1];
34  optMode = vbuf[2];
35  if (vbuf[3] == "1*") {
36  if (optMode == "BHP")
37  maxRate = 1E10;
38  else {
39  cout << "### ERROR: Prod Rate is missing in WCONINJE!" << endl;
40  }
41  } else {
42  maxRate = stod(vbuf[3]);
43  }
44  minBHP = stod(vbuf[4]);
45  } else {
46  OCP_ABORT("Wrong Well Type!");
47  }
48 }
49 
50 WellParam::WellParam(vector<string>& info)
51 {
52  name = info[0];
53  if (info[1] != "DEFAULT") group = info[1];
54  I = stoi(info[2]);
55  J = stoi(info[3]);
56  if (info[4] != "DEFAULT") depth = stod(info[4]);
57 }
58 
59 Solvent::Solvent(const vector<string>& vbuf)
60 {
61  name = vbuf[0];
62  USI len = vbuf.size();
63  for (USI i = 0; i < len - 1; i++) {
64  if (vbuf[i + 1] == "/") break;
65  comRatio.push_back(stod(vbuf[i + 1]));
66  }
67 }
68 
69 void ParamWell::InputWELSPECS(ifstream& ifs)
70 {
71  vector<string> vbuf;
72  while (ReadLine(ifs, vbuf)) {
73  if (vbuf[0] == "/") break;
74 
75  DealDefault(vbuf);
76  well.push_back(WellParam(vbuf));
77  }
78  cout << "WELSPECS" << endl;
79 }
80 
81 void ParamWell::InputCOMPDAT(ifstream& ifs)
82 {
83  USI num = well.size();
84  vector<string> vbuf;
85  while (ReadLine(ifs, vbuf)) {
86  if (vbuf[0] == "/") break;
87 
88  DealDefault(vbuf);
89  string src = vbuf[0];
90  int pos = src.find("*");
91  bool match = (pos != string::npos);
92  if (match) {
93  src.erase(pos);
94  }
95  bool tmp = false;
96 
97  for (USI w = 0; w < num; w++) {
98  if (match)
99  tmp = (well[w].name.substr(0, pos) == src);
100  else
101  tmp = (well[w].name == src);
102 
103  if (tmp) {
104 
105  USI k1 = stoi(vbuf[3]);
106  USI k2 = stoi(vbuf[4]);
107 
108  for (USI k = k1; k <= k2; k++) {
109  if (vbuf[1] == "DEFAULT" || vbuf[2] == "DEFAULT") {
110  well[w].I_perf.push_back(well[w].I);
111  well[w].J_perf.push_back(well[w].J);
112  } else {
113  well[w].I_perf.push_back(stoi(vbuf[1]));
114  well[w].J_perf.push_back(stoi(vbuf[2]));
115  }
116  well[w].K_perf.push_back(k);
117 
118  if (vbuf[5] != "DEFAULT")
119  well[w].WI.push_back(stod(vbuf[5]));
120  else
121  well[w].WI.push_back(-1.0);
122 
123  if (vbuf[6] != "DEFAULT")
124  well[w].diameter.push_back(stod(vbuf[6]));
125  else
126  well[w].diameter.push_back(1.0);
127 
128  if (vbuf[7] != "DEFAULT")
129  well[w].kh.push_back(stod(vbuf[7]));
130  else
131  well[w].kh.push_back(-1.0);
132 
133  if (vbuf[8] != "DEFAULT")
134  well[w].skinFactor.push_back(stod(vbuf[8]));
135  else
136  well[w].skinFactor.push_back(0.0);
137 
138  if (vbuf[9] != "DEFAULT")
139  well[w].direction.push_back(vbuf[9]);
140  else
141  well[w].direction.push_back("z");
142  }
143  }
144  }
145  }
146  cout << "COMPDAT" << endl;
147 }
148 
149 void ParamWell::InputWCONINJE(ifstream& ifs)
150 {
151  assert(criticalTime.size() > 0);
152 
153  USI d = criticalTime.size() - 1;
154  USI num = well.size();
155  vector<string> vbuf;
156  while (ReadLine(ifs, vbuf)) {
157  if (vbuf[0] == "/") break;
158 
159  DealDefault(vbuf);
160  string src = vbuf[0];
161  int pos = src.find("*");
162  bool match = (pos != string::npos);
163  if (match) {
164  src.erase(pos);
165  }
166 
167  if (match) {
168  for (USI w = 0; w < num; w++) {
169  if (well[w].name.substr(0, pos) == src) {
170  well[w].optParam.push_back(WellOptPair(d, "INJ", vbuf));
171  }
172  }
173  } else {
174  for (USI w = 0; w < num; w++) {
175  if (well[w].name == src) {
176  well[w].optParam.push_back(WellOptPair(d, "INJ", vbuf));
177  }
178  }
179  }
180  }
181  cout << "WCONINJE" << endl;
182 }
183 
184 void ParamWell::InputWCONPROD(ifstream& ifs)
185 {
186  assert(criticalTime.size() > 0);
187 
188  USI d = criticalTime.size() - 1;
189  USI num = well.size();
190  vector<string> vbuf;
191  while (ReadLine(ifs, vbuf)) {
192  if (vbuf[0] == "/") break;
193 
194  DealDefault(vbuf);
195  string src = vbuf[0];
196  int pos = src.find("*");
197  bool match = (pos != string::npos);
198  if (match) {
199  src.erase(pos);
200  }
201 
202  if (match) {
203  for (USI w = 0; w < num; w++)
204  if (well[w].name.substr(0, pos) == src)
205  well[w].optParam.push_back(WellOptPair(d, "PROD", vbuf));
206  } else {
207  for (USI w = 0; w < num; w++)
208  if (well[w].name == src)
209  well[w].optParam.push_back(WellOptPair(d, "PROD", vbuf));
210  }
211  }
212  cout << "WCONPROD" << endl;
213 }
214 
215 void ParamWell::InputTSTEP(ifstream& ifs)
216 {
217  assert(criticalTime.size() > 0);
218 
219  vector<string> vbuf;
220  while (ReadLine(ifs, vbuf)) {
221  if (vbuf[0] == "/") break;
222 
223  DealDefault(vbuf);
224  OCP_INT len = vbuf.size();
225  for (OCP_INT i = 0; i < len - 1; i++) {
226  OCP_DBL t = criticalTime.back() + stod(vbuf[i]);
227  criticalTime.push_back(t);
228  }
229  if (vbuf.back() != "/") {
230  OCP_DBL t = criticalTime.back() + stod(vbuf.back());
231  criticalTime.push_back(t);
232  }
233  }
234 }
235 
236 void ParamWell::InputWELTARG(ifstream& ifs)
237 {
238  assert(criticalTime.size() > 0);
239 
240  USI d = criticalTime.size() - 1;
241  USI num = well.size();
242  vector<string> vbuf;
243  while (ReadLine(ifs, vbuf)) {
244  if (vbuf[0] == "/") break;
245 
246  DealDefault(vbuf);
247  string src = vbuf[0];
248  int pos = src.find("*");
249  bool match = (pos != string::npos);
250  if (match) {
251  src.erase(pos);
252  }
253  bool tmp = false;
254 
255  for (USI w = 0; w < num; w++) {
256  if (match)
257  tmp = (well[w].name.substr(0, pos) == src);
258  else
259  tmp = (well[w].name == src);
260 
261  if (tmp) {
262 
263  WellOptPair tar = well[w].optParam.back();
264  tar.d = d;
265  tar.opt.optMode = vbuf[1];
266  OCP_DBL val = stod(vbuf[2]);
267  if (vbuf[1] == "BHP") {
268  if (tar.opt.type == "INJ")
269  tar.opt.maxBHP = val;
270  else
271  tar.opt.minBHP = val;
272  } else {
273  tar.opt.maxRate = val;
274  }
275  well[w].optParam.push_back(tar);
276  }
277  }
278  }
279  cout << "WELTARG" << endl;
280 }
281 
282 void ParamWell::InputWELLSTRE(ifstream& ifs)
283 {
284  vector<string> vbuf;
285  while (ReadLine(ifs, vbuf)) {
286  if (vbuf[0] == "/") break;
287  solSet.push_back(Solvent(vbuf));
288  }
289  cout << "WELLSTRE" << endl;
290 }
291 
292 // check
293 void ParamWell::CheckParam(const bool& boModel) const
294 {
295  if (boModel) {
296  CheckINJFluid();
297  }
298  CheckPerf();
299 }
300 
301 void ParamWell::CheckINJFluid() const
302 {
303  USI wellnum = well.size();
304  USI len;
305  for (USI w = 0; w < wellnum; w++) {
306  len = well[w].optParam.size();
307  for (USI i = 0; i < len; i++) {
308  const WellOptParam& tmpOpt = well[w].optParam[i].opt;
309  if (tmpOpt.type == "INJ") {
310  if (tmpOpt.fluidType == "WAT" || tmpOpt.fluidType == "WATER") {
311  } else if (tmpOpt.fluidType == "GAS") {
312  } else {
313  OCP_ABORT("Wrong FluidType!");
314  }
315  }
316  }
317  }
318 }
319 
321 {
322  USI wellnum = well.size();
323  USI perfnum;
324  for (USI w = 0; w < wellnum; w++) {
325  perfnum = well[w].I_perf.size();
326  if (well[w].J_perf.size() != perfnum) {
327  OCP_ABORT("Wrong perforation size J_perf!");
328  }
329  if (well[w].K_perf.size() != perfnum) {
330  OCP_ABORT("Wrong perforation size K_perf!");
331  }
332  if (well[w].diameter.size() != perfnum) {
333  OCP_ABORT("Wrong perforation diameter size!");
334  }
335  if (well[w].WI.size() != perfnum) {
336  OCP_ABORT("Wrong perforation WI size!");
337  }
338  if (well[w].kh.size() != perfnum) {
339  OCP_ABORT("Wrong perforation kh size!");
340  }
341  if (well[w].skinFactor.size() != perfnum) {
342  OCP_ABORT("Wrong perforation skinFactor size!");
343  }
344  if (well[w].direction.size() != perfnum) {
345  OCP_ABORT("Wrong perforation direction size!");
346  }
347  }
348 }
349 
350 /*----------------------------------------------------------------------------*/
351 /* Brief Change History of This File */
352 /*----------------------------------------------------------------------------*/
353 /* Author Date Actions */
354 /*----------------------------------------------------------------------------*/
355 /* Shizhe Li Oct/01/2021 Create file */
356 /* Chensong Zhang Oct/15/2021 Format file */
357 /* Chensong Zhang Oct/27/2021 Unify error messages */
358 /*----------------------------------------------------------------------------*/
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:22
double OCP_DBL
Double precision.
Definition: OCPConst.hpp:26
int OCP_INT
Long integer.
Definition: OCPConst.hpp:25
ParamWell class declaration.
Logging error and warning messages.
#define OCP_ABORT(msg)
Abort if critical error happens.
Definition: UtilError.hpp:47
void DealDefault(vector< string > &result)
Definition: UtilInput.cpp:50
bool ReadLine(ifstream &ifs, vector< string > &result)
Definition: UtilInput.cpp:14
void InputWCONPROD(ifstream &ifs)
Definition: ParamWell.cpp:184
void InputWELLSTRE(ifstream &ifs)
Definition: ParamWell.cpp:282
void InputWELSPECS(ifstream &ifs)
Definition: ParamWell.cpp:69
vector< Solvent > solSet
Sets of Solvent.
Definition: ParamWell.hpp:105
void InputWELTARG(ifstream &ifs)
Definition: ParamWell.cpp:236
void InputTSTEP(ifstream &ifs)
Definition: ParamWell.cpp:215
void CheckPerf() const
Check if params of Perforation is wrong.
Definition: ParamWell.cpp:320
void CheckParam(const bool &boModel) const
Check if wrong params are input.
Definition: ParamWell.cpp:293
vector< OCP_DBL > criticalTime
Records the critical time given by users.
Definition: ParamWell.hpp:104
void InputWCONINJE(ifstream &ifs)
Definition: ParamWell.cpp:149
void InputCOMPDAT(ifstream &ifs)
Definition: ParamWell.cpp:81
vector< WellParam > well
Contains all the information of wells.
Definition: ParamWell.hpp:103
Describe the molar fraction of components of fluid injected to reservoir from INJ.
Definition: ParamWell.hpp:88
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 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:61
OCP_DBL depth
Depth of well.
Definition: ParamWell.hpp:70
USI I
I index of well.
Definition: ParamWell.hpp:68
string name
Name of Well.
Definition: ParamWell.hpp:66
USI J
J index of well.
Definition: ParamWell.hpp:69
string group
Group the well belongs to.
Definition: ParamWell.hpp:67