34 comps = rs_param.
comps;
37 water = rs_param.
water;
40 EQUIL.Dref = rs_param.
EQUIL[0];
41 EQUIL.Pref = rs_param.
EQUIL[1];
42 NTPVT = rs_param.
NTPVT;
49 if (water && !oil && !gas) {
55 }
else if (water && oil && !gas) {
59 EQUIL.DOWC = rs_param.
EQUIL[2];
60 EQUIL.PcOW = rs_param.
EQUIL[3];
63 }
else if (water && oil && gas && !disGas) {
67 EQUIL.DOWC = rs_param.
EQUIL[2];
68 EQUIL.PcOW = rs_param.
EQUIL[3];
69 EQUIL.DGOC = rs_param.
EQUIL[4];
70 EQUIL.PcGO = rs_param.
EQUIL[5];
73 }
else if (water && oil && gas && disGas) {
77 EQUIL.DOWC = rs_param.
EQUIL[2];
78 EQUIL.PcOW = rs_param.
EQUIL[3];
79 EQUIL.DGOC = rs_param.
EQUIL[4];
80 EQUIL.PcGO = rs_param.
EQUIL[5];
89 numCom_1 = numCom - 1;
98 for (
USI i = 0; i < NTPVT; i++)
105 for (
USI i = 0; i < NTPVT; i++)
113 cout <<
"Bulk::InputParam --- BLACKOIL" << endl;
123 numCom_1 = numCom - 1;
124 EQUIL.DOWC = rs_param.
EQUIL[2];
125 EQUIL.PcOW = rs_param.
EQUIL[3];
126 EQUIL.DGOC = rs_param.
EQUIL[4];
127 EQUIL.PcGO = rs_param.
EQUIL[5];
139 for (
USI i = 0; i < NTPVT; i++)
142 cout <<
"Bulk::InputParam --- COMPOSITIONAL" << endl;
149 satcm.resize(NTSFUN);
153 for (
USI i = 0; i < NTSFUN; i++)
157 for (
USI i = 0; i < NTSFUN; i++)
161 for (
USI i = 0; i < NTSFUN; i++) {
163 satcm[i] = flow[i]->GetScm();
167 for (
USI i = 0; i < NTSFUN; i++) {
169 satcm[i] = flow[i]->GetScm();
173 for (
USI i = 0; i < NTSFUN; i++)
189 numBulk = myGrid.activeGridNum;
190 dx.resize(numBulk, 0);
191 dy.resize(numBulk, 0);
192 dz.resize(numBulk, 0);
193 depth.resize(numBulk, 0);
194 ntg.resize(numBulk, 0);
195 rockVpInit.resize(numBulk, 0);
196 rockVp.resize(numBulk, 0);
197 rockKxInit.resize(numBulk, 0);
198 rockKyInit.resize(numBulk, 0);
199 rockKzInit.resize(numBulk, 0);
200 SATNUM.resize(numBulk, 0);
201 PVTNUM.resize(numBulk, 0);
203 if (myGrid.SwatInit.size() > 0) {
204 SwatInitExist =
true;
205 SwatInit.resize(numBulk);
208 ScaleValuePcow.resize(numBulk, 0);
211 for (
OCP_USI bIdb = 0; bIdb < numBulk; bIdb++) {
212 OCP_USI bIdg = myGrid.activeMap_B2G[bIdb];
214 dx[bIdb] = myGrid.dx[bIdg];
215 dy[bIdb] = myGrid.dy[bIdg];
216 dz[bIdb] = myGrid.dz[bIdg];
217 depth[bIdb] = myGrid.depth[bIdg];
218 ntg[bIdb] = myGrid.ntg[bIdg];
220 rockVpInit[bIdb] = myGrid.v[bIdg] * myGrid.ntg[bIdg] * myGrid.poro[bIdg];
221 rockKxInit[bIdb] = myGrid.kx[bIdg];
222 rockKyInit[bIdb] = myGrid.ky[bIdg];
223 rockKzInit[bIdb] = myGrid.kz[bIdg];
225 SATNUM[bIdb] = myGrid.SATNUM[bIdg];
226 PVTNUM[bIdb] = myGrid.PVTNUM[bIdg];
229 SwatInit[bIdb] = myGrid.SwatInit[bIdg];
242 Pj.resize(numBulk * numPhase);
243 Pc.resize(numBulk * numPhase);
244 phaseExist.resize(numBulk * numPhase);
245 S.resize(numBulk * numPhase);
246 rho.resize(numBulk * numPhase);
247 xi.resize(numBulk * numPhase);
248 xij.resize(numBulk * numPhase * numCom);
249 Ni.resize(numBulk * numCom);
250 mu.resize(numBulk * numPhase);
251 kr.resize(numBulk * numPhase);
252 vj.resize(numBulk * numPhase);
257 phaseNum.resize(numBulk);
258 lphaseNum.resize(numBulk);
259 NRphaseNum.resize(numBulk);
261 phase2Index.resize(3);
266 index2Phase.resize(1);
267 index2Phase[0] =
WATER;
268 phase2Index[
WATER] = 0;
271 index2Phase.resize(2);
272 index2Phase[0] =
OIL;
273 index2Phase[1] =
WATER;
274 phase2Index[
OIL] = 0;
275 phase2Index[
WATER] = 1;
278 index2Phase.resize(2);
279 index2Phase[0] =
OIL;
280 index2Phase[1] =
GAS;
281 phase2Index[
OIL] = 0;
282 phase2Index[
GAS] = 1;
285 index2Phase.resize(2);
286 index2Phase[0] =
GAS;
287 index2Phase[1] =
WATER;
288 phase2Index[
GAS] = 0;
289 phase2Index[
WATER] = 1;
293 index2Phase.resize(3);
294 index2Phase[0] =
OIL;
295 index2Phase[1] =
GAS;
296 index2Phase[2] =
WATER;
297 phase2Index[
OIL] = 0;
298 phase2Index[
GAS] = 1;
299 phase2Index[
WATER] = 2;
305 initZi.resize(numBulk * numCom);
307 phase2Index[
OIL] = 0;
308 phase2Index[
GAS] = 1;
309 phase2Index[
WATER] = 2;
311 minEigenSkip.resize(numBulk);
312 flagSkip.resize(numBulk);
313 ziSkip.resize(numBulk * numCom);
314 PSkip.resize(numBulk);
315 lminEigenSkip.resize(numBulk);
316 lflagSkip.resize(numBulk);
317 lziSkip.resize(numBulk * numCom);
318 lPSkip.resize(numBulk);
319 Ks.resize(numBulk * (numCom - 1));
320 lKs.resize(numBulk * (numCom - 1));
323 surTen.resize(numBulk);
326 lsurTen.resize(numBulk);
331 ePEC.resize(numBulk);
351 for (
OCP_USI n = 0; n < numBulk; n++) {
352 if (rockVpInit[n] <
TINY) {
353 OCP_ABORT(
"Bulk volume is too small: bulk[" + std::to_string(n) +
354 "] = " + std::to_string(rockVpInit[n]));
362 for (
OCP_USI n = 0; n < numBulk; n++) {
363 if (rockVp[n] <
TINY) {
364 OCP_ABORT(
"Bulk volume is too small: bulk[" + std::to_string(n) +
365 "] = " + std::to_string(rockVp[n]));
384 for (
OCP_USI n = 0; n < numBulk; n++) {
385 OCP_DBL temp1 = depth[n] - dz[n] / 2;
386 OCP_DBL temp2 = depth[n] + dz[n] / 2;
387 Zmin = Zmin < temp1 ? Zmin : temp1;
388 Zmax = Zmax > temp2 ? Zmax : temp2;
390 OCP_DBL tabdz = (Zmax - Zmin) / (tabrow - 1);
394 vector<OCP_DBL>& Ztmp = DepthP.
GetCol(0);
395 vector<OCP_DBL>& Potmp = DepthP.
GetCol(1);
396 vector<OCP_DBL>& Pgtmp = DepthP.
GetCol(2);
397 vector<OCP_DBL>& Pwtmp = DepthP.
GetCol(3);
401 for (
USI i = 1; i < tabrow; i++) {
402 Ztmp[i] = Ztmp[i - 1] + tabdz;
407 if (Dref <= Ztmp[0]) {
409 }
else if (Dref >= Ztmp[tabrow - 1]) {
410 beginId = tabrow - 1;
413 distance(Ztmp.begin(), find_if(Ztmp.begin(), Ztmp.end(),
414 [s = Dref](
auto& t) { return t > s; }));
420 OCP_DBL gammaOtmp, gammaWtmp, gammaGtmp;
433 gammaGtmp = flashCal[0]->GammaPhaseG(Pgref);
434 Pbegin = Pgref + gammaGtmp * (Ztmp[beginId] - Dref);
435 Pgtmp[beginId] = Pbegin;
438 for (
USI id = beginId;
id > 0;
id--) {
439 gammaGtmp = flashCal[0]->GammaPhaseG(Pgtmp[
id]);
440 Pgtmp[
id - 1] = Pgtmp[id] - gammaGtmp * (Ztmp[id] - Ztmp[
id - 1]);
443 for (
USI id = beginId;
id < tabrow - 1;
id++) {
444 gammaGtmp = flashCal[0]->GammaPhaseG(Pgtmp[
id]);
445 Pgtmp[
id + 1] = Pgtmp[id] + gammaGtmp * (Ztmp[
id + 1] - Ztmp[id]);
451 mydz = (DOGC - Dref) / mynum;
453 for (
USI i = 0; i < mynum; i++) {
454 gammaGtmp = flashCal[0]->GammaPhaseG(Ptmp);
455 Ptmp += gammaGtmp * mydz;
458 for (
USI i = 0; i < mynum; i++) {
460 Pbb = EQUIL.PBVD.
Eval(0, DOGC - i * mydz, 1);
462 gammaOtmp = flashCal[0]->GammaPhaseO(Ptmp, Pbb);
463 Ptmp -= gammaOtmp * mydz;
469 Pbb = EQUIL.PBVD.
Eval(0, Dref, 1);
471 gammaOtmp = flashCal[0]->GammaPhaseO(Poref, Pbb);
472 Pbegin = Poref + gammaOtmp * (Ztmp[beginId] - Dref);
473 Potmp[beginId] = Pbegin;
475 for (
USI id = beginId;
id > 0;
id--) {
477 Pbb = EQUIL.PBVD.
Eval(0, Ztmp[
id], 1);
479 gammaOtmp = flashCal[0]->GammaPhaseO(Potmp[
id], Pbb);
480 Potmp[
id - 1] = Potmp[id] - gammaOtmp * (Ztmp[id] - Ztmp[
id - 1]);
483 for (
USI id = beginId;
id < tabrow - 1;
id++) {
485 Pbb = EQUIL.PBVD.
Eval(0, Ztmp[
id], 1);
487 gammaOtmp = flashCal[0]->GammaPhaseO(Potmp[
id], Pbb);
488 Potmp[
id + 1] = Potmp[id] + gammaOtmp * (Ztmp[
id + 1] - Ztmp[id]);
494 mydz = (DOWC - Dref) / mynum;
496 for (
USI i = 0; i < mynum; i++) {
498 Pbb = EQUIL.PBVD.
Eval(0, Dref + i * mydz, 1);
500 gammaOtmp = flashCal[0]->GammaPhaseO(Ptmp, Pbb);
501 Ptmp += gammaOtmp * mydz;
504 for (
USI i = 0; i < mynum; i++) {
505 gammaWtmp = flashCal[0]->GammaPhaseW(Ptmp);
506 Ptmp -= gammaWtmp * mydz;
511 gammaWtmp = flashCal[0]->GammaPhaseW(Pwref);
512 Pbegin = Pwref + gammaWtmp * (Ztmp[beginId] - Dref);
513 Pwtmp[beginId] = Pbegin;
515 for (
USI id = beginId;
id > 0;
id--) {
516 gammaWtmp = flashCal[0]->GammaPhaseW(Pwtmp[
id]);
517 Pwtmp[
id - 1] = Pwtmp[id] - gammaWtmp * (Ztmp[id] - Ztmp[
id - 1]);
520 for (
USI id = beginId;
id < tabrow - 1;
id++) {
521 gammaWtmp = flashCal[0]->GammaPhaseW(Pwtmp[
id]);
522 Pwtmp[
id + 1] = Pwtmp[id] + gammaWtmp * (Ztmp[
id + 1] - Ztmp[id]);
524 }
else if (Dref > DOWC) {
528 gammaWtmp = flashCal[0]->GammaPhaseW(Pwref);
529 Pbegin = Pwref + gammaWtmp * (Ztmp[beginId] - Dref);
530 Pwtmp[beginId] = Pbegin;
533 for (
USI id = beginId;
id > 0;
id--) {
534 gammaWtmp = flashCal[0]->GammaPhaseW(Pwtmp[
id]);
535 Pwtmp[
id - 1] = Pwtmp[id] - gammaWtmp * (Ztmp[id] - Ztmp[
id - 1]);
537 for (
USI id = beginId;
id < tabrow - 1;
id++) {
538 gammaWtmp = flashCal[0]->GammaPhaseW(Pwtmp[
id]);
539 Pwtmp[
id + 1] = Pwtmp[id] + gammaWtmp * (Ztmp[
id + 1] - Ztmp[id]);
545 mydz = (DOWC - Dref) / mynum;
547 for (
USI i = 0; i < mynum; i++) {
548 gammaWtmp = flashCal[0]->GammaPhaseW(Ptmp);
549 Ptmp += gammaWtmp * mydz;
553 for (
USI i = 0; i < mynum; i++) {
555 Pbb = EQUIL.PBVD.
Eval(0, DOWC - i * mydz, 1);
557 gammaOtmp = flashCal[0]->GammaPhaseO(Ptmp, Pbb);
558 Ptmp -= gammaOtmp * mydz;
564 Pbb = EQUIL.PBVD.
Eval(0, Dref, 1);
566 gammaOtmp = flashCal[0]->GammaPhaseO(Poref, Pbb);
567 Pbegin = Poref + gammaOtmp * (Ztmp[beginId] - Dref);
568 Potmp[beginId] = Pbegin;
570 for (
USI id = beginId;
id > 0;
id--) {
572 Pbb = EQUIL.PBVD.
Eval(0, Ztmp[
id], 1);
574 gammaOtmp = flashCal[0]->GammaPhaseO(Potmp[
id], Pbb);
575 Potmp[
id - 1] = Potmp[id] - gammaOtmp * (Ztmp[id] - Ztmp[
id - 1]);
578 for (
USI id = beginId;
id < tabrow - 1;
id++) {
580 Pbb = EQUIL.PBVD.
Eval(0, Ztmp[
id], 1);
582 gammaOtmp = flashCal[0]->GammaPhaseO(Potmp[
id], Pbb);
583 Potmp[
id + 1] = Potmp[id] + gammaOtmp * (Ztmp[
id + 1] - Ztmp[id]);
590 mydz = (DOGC - Dref) / mynum;
592 for (
USI i = 0; i < mynum; i++) {
594 Pbb = EQUIL.PBVD.
Eval(0, Dref + i * mydz, 1);
596 gammaOtmp = flashCal[0]->GammaPhaseO(Ptmp, Pbb);
597 Ptmp += gammaOtmp * mydz;
600 for (
USI i = 0; i < mynum; i++) {
601 gammaGtmp = flashCal[0]->GammaPhaseG(Ptmp);
602 Ptmp -= gammaGtmp * mydz;
607 gammaGtmp = flashCal[0]->GammaPhaseG(Pgref);
608 Pbegin = Pgref + gammaGtmp * (Ztmp[beginId] - Dref);
609 Pgtmp[beginId] = Pbegin;
611 for (
USI id = beginId;
id > 0;
id--) {
612 gammaGtmp = flashCal[0]->GammaPhaseG(Pgtmp[
id]);
613 Pgtmp[
id - 1] = Pgtmp[id] - gammaGtmp * (Ztmp[id] - Ztmp[
id - 1]);
615 for (
USI id = beginId;
id < tabrow - 1;
id++) {
616 gammaGtmp = flashCal[0]->GammaPhaseG(Pgtmp[
id]);
617 Pgtmp[
id + 1] = Pgtmp[id] + gammaGtmp * (Ztmp[
id + 1] - Ztmp[id]);
625 Pbb = EQUIL.PBVD.
Eval(0, Dref, 1);
627 gammaOtmp = flashCal[0]->GammaPhaseO(Poref, Pbb);
628 Pbegin = Poref + gammaOtmp * (Ztmp[beginId] - Dref);
629 Potmp[beginId] = Pbegin;
632 for (
USI id = beginId;
id > 0;
id--) {
634 Pbb = EQUIL.PBVD.
Eval(0, Ztmp[
id], 1);
636 gammaOtmp = flashCal[0]->GammaPhaseO(Potmp[
id], Pbb);
637 Potmp[
id - 1] = Potmp[id] - gammaOtmp * (Ztmp[id] - Ztmp[
id - 1]);
639 for (
USI id = beginId;
id < tabrow - 1;
id++) {
641 Pbb = EQUIL.PBVD.
Eval(0, Ztmp[
id], 1);
643 gammaOtmp = flashCal[0]->GammaPhaseO(Potmp[
id], Pbb);
644 Potmp[
id + 1] = Potmp[id] + gammaOtmp * (Ztmp[
id + 1] - Ztmp[id]);
651 mydz = (DOGC - Dref) / mynum;
653 for (
USI i = 0; i < mynum; i++) {
655 Pbb = EQUIL.PBVD.
Eval(0, Dref + i * mydz, 1);
657 gammaOtmp = flashCal[0]->GammaPhaseO(Ptmp, Pbb);
658 Ptmp += gammaOtmp * mydz;
661 for (
USI i = 0; i < mynum; i++) {
662 gammaGtmp = flashCal[0]->GammaPhaseG(Ptmp);
663 Ptmp -= gammaGtmp * mydz;
668 gammaGtmp = flashCal[0]->GammaPhaseG(Pgref);
669 Pbegin = Pgref + gammaGtmp * (Ztmp[beginId] - Dref);
670 Pgtmp[beginId] = Pbegin;
672 for (
USI id = beginId;
id > 0;
id--) {
673 gammaGtmp = flashCal[0]->GammaPhaseG(Pgtmp[
id]);
674 Pgtmp[
id - 1] = Pgtmp[id] - gammaGtmp * (Ztmp[id] - Ztmp[
id - 1]);
677 for (
USI id = beginId;
id < tabrow - 1;
id++) {
678 gammaGtmp = flashCal[0]->GammaPhaseG(Pgtmp[
id]);
679 Pgtmp[
id + 1] = Pgtmp[id] + gammaGtmp * (Ztmp[
id + 1] - Ztmp[id]);
686 mydz = (DOWC - Dref) / mynum;
688 for (
USI i = 0; i < mynum; i++) {
690 Pbb = EQUIL.PBVD.
Eval(0, Dref + i * mydz, 1);
692 gammaOtmp = flashCal[0]->GammaPhaseO(Ptmp, Pbb);
693 Ptmp += gammaOtmp * mydz;
696 for (
USI i = 0; i < mynum; i++) {
697 gammaWtmp = flashCal[0]->GammaPhaseW(Ptmp);
698 Ptmp -= gammaWtmp * mydz;
703 gammaWtmp = flashCal[0]->GammaPhaseW(Pwref);
704 Pbegin = Pwref + gammaWtmp * (Ztmp[beginId] - Dref);
705 Pwtmp[beginId] = Pbegin;
707 for (
USI id = beginId;
id > 0;
id--) {
708 gammaWtmp = flashCal[0]->GammaPhaseW(Pwtmp[
id]);
709 Pwtmp[
id - 1] = Pwtmp[id] - gammaWtmp * (Ztmp[id] - Ztmp[
id - 1]);
712 for (
USI id = beginId;
id < tabrow - 1;
id++) {
713 gammaWtmp = flashCal[0]->GammaPhaseW(Pwtmp[
id]);
714 Pwtmp[
id + 1] = Pwtmp[id] + gammaWtmp * (Ztmp[
id + 1] - Ztmp[id]);
721 std::vector<OCP_DBL> data(4, 0), cdata(4, 0);
723 vector<bool> FlagPcow(NTSFUN,
true);
724 for (
USI i = 0; i < NTSFUN; i++) {
725 if (fabs(flow[i]->GetPcowBySw(0.0 -
TINY)) <
TINY &&
726 fabs(flow[i]->GetPcowBySw(1.0 +
TINY) <
TINY)) {
731 for (
OCP_USI n = 0; n < numBulk; n++) {
732 DepthP.
Eval_All(0, depth[n], data, cdata);
738 OCP_DBL Sw = flow[SATNUM[n]]->GetSwByPcow(Pcow);
741 Sg = flow[SATNUM[n]]->GetSgByPcgo(Pcgo);
746 Sw = flow[SATNUM[n]]->GetSwByPcgw(Pcgw);
752 Po = Pw + flow[SATNUM[n]]->GetPcowBySw(1.0);
753 }
else if (1 - Sg <
TINY) {
755 Po = Pg - flow[SATNUM[n]]->GetPcgoBySg(1.0);
756 }
else if (1 - Sw - Sg <
TINY) {
758 Po = Pg - flow[SATNUM[n]]->GetPcgoBySg(Sg);
762 if (depth[n] < DOGC) {
764 }
else if (!EQUIL.PBVD.
IsEmpty()) {
765 Pbb = EQUIL.PBVD.
Eval(0, depth[n], 1);
774 for (
USI k = 0; k < ncut; k++) {
777 OCP_DBL dep = depth[n] + dz[n] / ncut * (k - (ncut - 1) / 2.0);
778 DepthP.
Eval_All(0, dep, data, cdata);
784 tmpSw = flow[SATNUM[n]]->GetSwByPcow(Pcow);
786 tmpSg = flow[SATNUM[n]]->GetSgByPcgo(Pcgo);
788 if (tmpSw + tmpSg > 1) {
791 tmpSw = flow[SATNUM[n]]->GetSwByPcgw(Pcgw);
799 S[n * numPhase + numPhase - 1] = Sw;
801 S[n * numPhase + numPhase - 2] = Sg;
805 if (!FlagPcow[SATNUM[n]]) {
806 S[n * numPhase + numPhase - 1] = flow[SATNUM[n]]->GetSwco();
827 for (
OCP_USI n = 0; n < numBulk; n++) {
828 OCP_DBL temp1 = depth[n] - dz[n] / 2;
829 OCP_DBL temp2 = depth[n] + dz[n] / 2;
830 Zmin = Zmin < temp1 ? Zmin : temp1;
831 Zmax = Zmax > temp2 ? Zmax : temp2;
833 OCP_DBL tabdz = (Zmax - Zmin) / (tabrow - 1);
837 vector<OCP_DBL>& Ztmp = DepthP.
GetCol(0);
838 vector<OCP_DBL>& Potmp = DepthP.
GetCol(1);
839 vector<OCP_DBL>& Pwtmp = DepthP.
GetCol(2);
840 vector<OCP_DBL>& Pgtmp = DepthP.
GetCol(3);
842 vector<OCP_DBL> tmpInitZi(numCom, 0);
846 for (
USI i = 1; i < tabrow; i++) {
847 Ztmp[i] = Ztmp[i - 1] + tabdz;
852 if (Dref <= Ztmp[0]) {
854 }
else if (Dref >= Ztmp[tabrow - 1]) {
855 beginId = tabrow - 1;
858 distance(Ztmp.begin(), find_if(Ztmp.begin(), Ztmp.end(),
859 [s = Dref](
auto& t) { return t > s; }));
865 OCP_DBL gammaOtmp, gammaWtmp, gammaGtmp;
875 initZi_T[0].Eval_All0(Dref, tmpInitZi);
876 gammaGtmp = flashCal[0]->GammaPhaseOG(Pgref, mytemp, &tmpInitZi[0]);
877 Pbegin = Pgref + gammaGtmp * (Ztmp[beginId] - Dref);
878 Pgtmp[beginId] = Pbegin;
881 for (
USI id = beginId;
id > 0;
id--) {
882 initZi_T[0].Eval_All0(Ztmp[
id], tmpInitZi);
883 gammaGtmp = flashCal[0]->GammaPhaseOG(Pgtmp[
id], mytemp, &tmpInitZi[0]);
884 Pgtmp[
id - 1] = Pgtmp[id] - gammaGtmp * (Ztmp[id] - Ztmp[
id - 1]);
887 for (
USI id = beginId;
id < tabrow - 1;
id++) {
888 initZi_T[0].Eval_All0(Ztmp[
id], tmpInitZi);
889 gammaGtmp = flashCal[0]->GammaPhaseOG(Pgtmp[
id], mytemp, &tmpInitZi[0]);
890 Pgtmp[
id + 1] = Pgtmp[id] + gammaGtmp * (Ztmp[
id + 1] - Ztmp[id]);
896 mydz = (DOGC - Dref) / mynum;
899 for (
USI i = 0; i < mynum; i++) {
900 initZi_T[0].Eval_All0(myz, tmpInitZi);
902 gammaGtmp = flashCal[0]->GammaPhaseOG(Ptmp, mytemp, &tmpInitZi[0]);
903 Ptmp += gammaGtmp * mydz;
906 for (
USI i = 0; i < mynum; i++) {
907 initZi_T[0].Eval_All0(myz, tmpInitZi);
909 gammaOtmp = flashCal[0]->GammaPhaseOG(Ptmp, mytemp, &tmpInitZi[0]);
910 Ptmp -= gammaOtmp * mydz;
915 initZi_T[0].Eval_All0(Dref, tmpInitZi);
916 gammaOtmp = flashCal[0]->GammaPhaseOG(Poref, Dref, &tmpInitZi[0]);
917 Pbegin = Poref + gammaOtmp * (Ztmp[beginId] - Dref);
918 Potmp[beginId] = Pbegin;
920 for (
USI id = beginId;
id > 0;
id--) {
921 initZi_T[0].Eval_All0(Ztmp[
id], tmpInitZi);
922 gammaOtmp = flashCal[0]->GammaPhaseOG(Potmp[
id], mytemp, &tmpInitZi[0]);
923 Potmp[
id - 1] = Potmp[id] - gammaOtmp * (Ztmp[id] - Ztmp[
id - 1]);
926 for (
USI id = beginId;
id < tabrow - 1;
id++) {
927 initZi_T[0].Eval_All0(Ztmp[
id], tmpInitZi);
928 gammaOtmp = flashCal[0]->GammaPhaseOG(Potmp[
id], mytemp, &tmpInitZi[0]);
929 Potmp[
id + 1] = Potmp[id] + gammaOtmp * (Ztmp[
id + 1] - Ztmp[id]);
935 mydz = (DOWC - Dref) / mynum;
938 for (
USI i = 0; i < mynum; i++) {
939 initZi_T[0].Eval_All0(myz, tmpInitZi);
941 gammaOtmp = flashCal[0]->GammaPhaseOG(Ptmp, mytemp, &tmpInitZi[0]);
942 Ptmp += gammaOtmp * mydz;
945 for (
USI i = 0; i < mynum; i++) {
946 gammaWtmp = flashCal[0]->GammaPhaseW(Ptmp);
947 Ptmp -= gammaWtmp * mydz;
952 gammaWtmp = flashCal[0]->GammaPhaseW(Pwref);
953 Pbegin = Pwref + gammaWtmp * (Ztmp[beginId] - Dref);
954 Pwtmp[beginId] = Pbegin;
956 for (
USI id = beginId;
id > 0;
id--) {
957 gammaWtmp = flashCal[0]->GammaPhaseW(Pwtmp[
id]);
958 Pwtmp[
id - 1] = Pwtmp[id] - gammaWtmp * (Ztmp[id] - Ztmp[
id - 1]);
961 for (
USI id = beginId;
id < tabrow - 1;
id++) {
962 gammaWtmp = flashCal[0]->GammaPhaseW(Pwtmp[
id]);
963 Pwtmp[
id + 1] = Pwtmp[id] + gammaWtmp * (Ztmp[
id + 1] - Ztmp[id]);
965 }
else if (Dref > DOWC) {
969 gammaWtmp = flashCal[0]->GammaPhaseW(Pwref);
970 Pbegin = Pwref + gammaWtmp * (Ztmp[beginId] - Dref);
971 Pwtmp[beginId] = Pbegin;
974 for (
USI id = beginId;
id > 0;
id--) {
975 gammaWtmp = flashCal[0]->GammaPhaseW(Pwtmp[
id]);
976 Pwtmp[
id - 1] = Pwtmp[id] - gammaWtmp * (Ztmp[id] - Ztmp[
id - 1]);
978 for (
USI id = beginId;
id < tabrow - 1;
id++) {
979 gammaWtmp = flashCal[0]->GammaPhaseW(Pwtmp[
id]);
980 Pwtmp[
id + 1] = Pwtmp[id] + gammaWtmp * (Ztmp[
id + 1] - Ztmp[id]);
986 mydz = (DOWC - Dref) / mynum;
989 for (
USI i = 0; i < mynum; i++) {
991 gammaWtmp = flashCal[0]->GammaPhaseW(Ptmp);
992 Ptmp += gammaWtmp * mydz;
996 for (
USI i = 0; i < mynum; i++) {
997 initZi_T[0].Eval_All0(myz, tmpInitZi);
999 gammaOtmp = flashCal[0]->GammaPhaseOG(Ptmp, mytemp, &tmpInitZi[0]);
1000 Ptmp -= gammaOtmp * mydz;
1005 initZi_T[0].Eval_All0(Dref, tmpInitZi);
1006 gammaOtmp = flashCal[0]->GammaPhaseOG(Poref, mytemp, &tmpInitZi[0]);
1007 Pbegin = Poref + gammaOtmp * (Ztmp[beginId] - Dref);
1008 Potmp[beginId] = Pbegin;
1010 for (
USI id = beginId;
id > 0;
id--) {
1011 initZi_T[0].Eval_All0(Ztmp[
id], tmpInitZi);
1012 gammaOtmp = flashCal[0]->GammaPhaseOG(Potmp[
id], mytemp, &tmpInitZi[0]);
1013 Potmp[
id - 1] = Potmp[id] - gammaOtmp * (Ztmp[id] - Ztmp[
id - 1]);
1016 for (
USI id = beginId;
id < tabrow - 1;
id++) {
1017 initZi_T[0].Eval_All0(Ztmp[
id], tmpInitZi);
1018 gammaOtmp = flashCal[0]->GammaPhaseOG(Potmp[
id], mytemp, &tmpInitZi[0]);
1019 Potmp[
id + 1] = Potmp[id] + gammaOtmp * (Ztmp[
id + 1] - Ztmp[id]);
1025 mydz = (DOGC - Dref) / mynum;
1028 for (
USI i = 0; i < mynum; i++) {
1029 initZi_T[0].Eval_All0(myz, tmpInitZi);
1031 gammaOtmp = flashCal[0]->GammaPhaseOG(Ptmp, mytemp, &tmpInitZi[0]);
1032 Ptmp += gammaOtmp * mydz;
1035 for (
USI i = 0; i < mynum; i++) {
1036 initZi_T[0].Eval_All0(myz, tmpInitZi);
1038 gammaGtmp = flashCal[0]->GammaPhaseOG(Ptmp, mytemp, &tmpInitZi[0]);
1039 Ptmp -= gammaGtmp * mydz;
1044 initZi_T[0].Eval_All0(Dref, tmpInitZi);
1045 gammaGtmp = flashCal[0]->GammaPhaseOG(Pgref, mytemp, &tmpInitZi[0]);
1046 Pbegin = Pgref + gammaGtmp * (Ztmp[beginId] - Dref);
1047 Pgtmp[beginId] = Pbegin;
1049 for (
USI id = beginId;
id > 0;
id--) {
1050 initZi_T[0].Eval_All0(Ztmp[
id], tmpInitZi);
1051 gammaGtmp = flashCal[0]->GammaPhaseOG(Pgtmp[
id], mytemp, &tmpInitZi[0]);
1052 Pgtmp[
id - 1] = Pgtmp[id] - gammaGtmp * (Ztmp[id] - Ztmp[
id - 1]);
1054 for (
USI id = beginId;
id < tabrow - 1;
id++) {
1055 initZi_T[0].Eval_All0(Ztmp[
id], tmpInitZi);
1056 gammaGtmp = flashCal[0]->GammaPhaseOG(Pgtmp[
id], mytemp, &tmpInitZi[0]);
1057 Pgtmp[
id + 1] = Pgtmp[id] + gammaGtmp * (Ztmp[
id + 1] - Ztmp[id]);
1062 initZi_T[0].Eval_All0(Dref, tmpInitZi);
1063 gammaOtmp = flashCal[0]->GammaPhaseOG(Poref, mytemp, &tmpInitZi[0]);
1064 Pbegin = Poref + gammaOtmp * (Ztmp[beginId] - Dref);
1065 Potmp[beginId] = Pbegin;
1068 for (
USI id = beginId;
id > 0;
id--) {
1069 initZi_T[0].Eval_All0(Ztmp[
id], tmpInitZi);
1070 gammaOtmp = flashCal[0]->GammaPhaseOG(Potmp[
id], mytemp, &tmpInitZi[0]);
1071 Potmp[
id - 1] = Potmp[id] - gammaOtmp * (Ztmp[id] - Ztmp[
id - 1]);
1073 for (
USI id = beginId;
id < tabrow - 1;
id++) {
1074 initZi_T[0].Eval_All0(Ztmp[
id], tmpInitZi);
1075 gammaOtmp = flashCal[0]->GammaPhaseOG(Potmp[
id], mytemp, &tmpInitZi[0]);
1076 Potmp[
id + 1] = Potmp[id] + gammaOtmp * (Ztmp[
id + 1] - Ztmp[id]);
1082 mydz = (DOGC - Dref) / mynum;
1085 for (
USI i = 0; i < mynum; i++) {
1086 initZi_T[0].Eval_All0(myz, tmpInitZi);
1088 gammaOtmp = flashCal[0]->GammaPhaseOG(Ptmp, mytemp, &tmpInitZi[0]);
1089 Ptmp += gammaOtmp * mydz;
1092 for (
USI i = 0; i < mynum; i++) {
1093 initZi_T[0].Eval_All0(myz, tmpInitZi);
1095 gammaGtmp = flashCal[0]->GammaPhaseOG(Ptmp, mytemp, &tmpInitZi[0]);
1096 Ptmp -= gammaGtmp * mydz;
1101 initZi_T[0].Eval_All0(Dref, tmpInitZi);
1102 gammaGtmp = flashCal[0]->GammaPhaseOG(Pgref, mytemp, &tmpInitZi[0]);
1103 Pbegin = Pgref + gammaGtmp * (Ztmp[beginId] - Dref);
1104 Pgtmp[beginId] = Pbegin;
1106 for (
USI id = beginId;
id > 0;
id--) {
1107 initZi_T[0].Eval_All0(Ztmp[
id], tmpInitZi);
1108 gammaGtmp = flashCal[0]->GammaPhaseOG(Pgtmp[
id], mytemp, &tmpInitZi[0]);
1109 Pgtmp[
id - 1] = Pgtmp[id] - gammaGtmp * (Ztmp[id] - Ztmp[
id - 1]);
1112 for (
USI id = beginId;
id < tabrow - 1;
id++) {
1113 initZi_T[0].Eval_All0(Ztmp[
id], tmpInitZi);
1114 gammaGtmp = flashCal[0]->GammaPhaseOG(Pgtmp[
id], mytemp, &tmpInitZi[0]);
1115 Pgtmp[
id + 1] = Pgtmp[id] + gammaGtmp * (Ztmp[
id + 1] - Ztmp[id]);
1121 mydz = (DOWC - Dref) / mynum;
1124 for (
USI i = 0; i < mynum; i++) {
1125 initZi_T[0].Eval_All0(myz, tmpInitZi);
1127 gammaOtmp = flashCal[0]->GammaPhaseOG(Ptmp, mytemp, &tmpInitZi[0]);
1128 Ptmp += gammaOtmp * mydz;
1131 for (
USI i = 0; i < mynum; i++) {
1132 gammaWtmp = flashCal[0]->GammaPhaseW(Ptmp);
1133 Ptmp -= gammaWtmp * mydz;
1138 gammaWtmp = flashCal[0]->GammaPhaseW(Pwref);
1139 Pbegin = Pwref + gammaWtmp * (Ztmp[beginId] - Dref);
1140 Pwtmp[beginId] = Pbegin;
1142 for (
USI id = beginId;
id > 0;
id--) {
1143 gammaWtmp = flashCal[0]->GammaPhaseW(Pwtmp[
id]);
1144 Pwtmp[
id - 1] = Pwtmp[id] - gammaWtmp * (Ztmp[id] - Ztmp[
id - 1]);
1147 for (
USI id = beginId;
id < tabrow - 1;
id++) {
1148 gammaWtmp = flashCal[0]->GammaPhaseW(Pwtmp[
id]);
1149 Pwtmp[
id + 1] = Pwtmp[id] + gammaWtmp * (Ztmp[
id + 1] - Ztmp[id]);
1160 std::vector<OCP_DBL> data(4, 0), cdata(4, 0);
1162 vector<bool> FlagPcow(NTSFUN,
true);
1163 for (
USI i = 0; i < NTSFUN; i++) {
1164 if (fabs(flow[i]->GetPcowBySw(0.0 -
TINY)) <
TINY &&
1165 fabs(flow[i]->GetPcowBySw(1.0 +
TINY) <
TINY)) {
1166 FlagPcow[i] =
false;
1170 for (
OCP_USI n = 0; n < numBulk; n++) {
1171 initZi_T[0].Eval_All0(depth[n], tmpInitZi);
1172 for (
USI i = 0; i < numCom_1; i++) {
1173 initZi[n * numCom + i] = tmpInitZi[i];
1176 DepthP.
Eval_All(0, depth[n], data, cdata);
1182 OCP_DBL Sw = flow[SATNUM[n]]->GetSwByPcow(Pcow);
1185 Sg = flow[SATNUM[n]]->GetSgByPcgo(Pcgo);
1190 Sw = flow[SATNUM[n]]->GetSwByPcgw(Pcgw);
1194 if (1 - Sw <
TINY) {
1196 Po = Pw + flow[SATNUM[n]]->GetPcowBySw(1.0);
1197 }
else if (1 - Sg <
TINY) {
1199 Po = Pg - flow[SATNUM[n]]->GetPcgoBySg(1.0);
1200 }
else if (1 - Sw - Sg <
TINY) {
1202 Po = Pg - flow[SATNUM[n]]->GetPcgoBySg(Sg);
1207 OCP_DBL swco = flow[SATNUM[n]]->GetSwco();
1208 if (!FlagPcow[SATNUM[n]]) {
1209 S[n * numPhase + numPhase - 1] = swco;
1218 for (
USI k = 0; k < ncut; k++) {
1221 OCP_DBL dep = depth[n] + dz[n] / ncut * (k - (ncut - 1) / 2.0);
1222 DepthP.
Eval_All(0, dep, data, cdata);
1229 tmpSw = flow[SATNUM[n]]->GetSwByPcow(Pcow);
1231 tmpSg = flow[SATNUM[n]]->GetSgByPcgo(Pcgo);
1233 if (tmpSw + tmpSg > 1) {
1236 tmpSw = flow[SATNUM[n]]->GetSwByPcgw(Pcgw);
1246 if (SwatInitExist) {
1248 ScaleValuePcow[n] = 1.0;
1250 if (SwatInit[n] <= swco) {
1256 tmp = flow[SATNUM[n]]->GetPcowBySw(Sw);
1258 ScaleValuePcow[n] = avePcow / tmp;
1269 S[n * numPhase + numPhase - 1] = Sw;
1284 for (
OCP_USI n = 0; n < numBulk; n++) {
1285 flashCal[PVTNUM[n]]->InitFlash(P[n], Pb[n], T, &S[n * numPhase], rockVp[n],
1286 initZi.data() + n * numCom);
1287 for (
USI i = 0; i < numCom; i++) {
1288 Ni[n * numCom + i] = flashCal[PVTNUM[n]]->Ni[i];
1307 for (
OCP_USI n = 0; n < numBulk; n++) {
1308 flashCal[PVTNUM[n]]->InitFlashDer(P[n], Pb[n], T, &S[n * numPhase],
1309 rockVp[n], initZi.data() + n * numCom);
1310 for (
USI i = 0; i < numCom; i++) {
1311 Ni[n * numCom + i] = flashCal[PVTNUM[n]]->Ni[i];
1321 void Bulk::InitFlashDer_n()
1326 for (
OCP_USI n = 0; n < numBulk; n++) {
1327 flashCal[PVTNUM[n]]->InitFlashDer_n(P[n], Pb[n], T, &S[n * numPhase],
1328 rockVp[n], initZi.data() + n * numCom);
1329 for (
USI i = 0; i < numCom; i++) {
1330 Ni[n * numCom + i] = flashCal[PVTNUM[n]]->Ni[i];
1332 PassFlashValueDeriv_n(n);
1335 OCP_ABORT(
"Not Completed in BLKOIL MODEL!");
1357 for (
OCP_USI n = 0; n < numBulk; n++) {
1358 flashCal[PVTNUM[n]]->Flash(P[n], T, &Ni[n * numCom], 0, 0, 0);
1370 for (
OCP_USI n = 0; n < numBulk; n++) {
1373 minEig = minEigenSkip[n];
1374 if (fabs(1 - PSkip[n] / P[n]) >= minEig / 10) {
1381 Ntw = Nt[n] - Ni[bId + numCom - 1];
1382 for (
USI i = 0; i < numCom - 1; i++) {
1384 if (fabs(Ni[bId + i] / Ntw - ziSkip[bId + i]) >= minEig / 10) {
1394 flashCal[PVTNUM[n]]->Flash(P[n], T, &Ni[n * numCom], ftype, phaseNum[n],
1416 void Bulk::FlashDeriv_n()
1423 FlashDerivBLKOIL_n();
1431 for (
OCP_USI n = 0; n < numBulk; n++) {
1432 flashCal[PVTNUM[n]]->FlashDeriv(P[n], T, &Ni[n * numCom], 0, 0, 0);
1437 void Bulk::FlashDerivBLKOIL_n() {}
1445 index_maxNRdSSP = 0;
1447 for (
OCP_USI n = 0; n < numBulk; n++) {
1451 flashCal[PVTNUM[n]]->FlashDeriv(P[n], T, &Ni[n * numCom], ftype, phaseNum[n],
1457 void Bulk::FlashDerivCOMP_n()
1460 vector<USI> flagB(numPhase, 0);
1463 index_maxNRdSSP = 0;
1465 for (
OCP_USI n = 0; n < numBulk; n++) {
1469 for (
USI j = 0; j < numPhase; j++) flagB[j] = phaseExist[n * numPhase + j];
1471 flashCal[PVTNUM[n]]->FlashDeriv_n(
1472 P[n], T, &Ni[n * numCom], &S[n * numPhase], &xij[n * numPhase * numCom],
1473 &nj[n * numPhase], ftype, &flagB[0], phaseNum[n], &Ks[n * numCom_1]);
1475 PassFlashValueDeriv_n(n);
1490 minEig = minEigenSkip[n];
1491 if (fabs(1 - PSkip[n] / P[n]) >= minEig / 10) {
1496 Ntw = Nt[n] - Ni[bId + numCom_1];
1497 for (
USI i = 0; i < numCom_1; i++) {
1498 if (fabs(Ni[bId + i] / Ntw - ziSkip[bId + i]) >= minEig / 10) {
1507 if (phaseNum[n] == 2 &&
true) {
1512 for (
USI j = 0; j < numPhase; j++) {
1513 if (dSNR[bId + j] + dSNRP[bId + j] < 1E-4) {
1534 USI pvtnum = PVTNUM[n];
1536 for (
USI j = 0; j < numPhase; j++) {
1537 phaseExist[bIdp + j] = flashCal[pvtnum]->phaseExist[j];
1542 S[bIdp + j] = flashCal[pvtnum]->S[j];
1543 if (phaseExist[bIdp + j]) {
1545 rho[bIdp + j] = flashCal[pvtnum]->rho[j];
1546 xi[bIdp + j] = flashCal[pvtnum]->xi[j];
1547 for (
USI i = 0; i < numCom; i++) {
1548 xij[bIdp * numCom + j * numCom + i] =
1549 flashCal[pvtnum]->xij[j * numCom + i];
1551 mu[bIdp + j] = flashCal[pvtnum]->mu[j];
1552 vj[bIdp + j] = flashCal[pvtnum]->v[j];
1555 Nt[n] = flashCal[pvtnum]->Nt;
1556 vf[n] = flashCal[pvtnum]->vf;
1557 vfp[n] = flashCal[pvtnum]->vfp;
1559 for (
USI i = 0; i < numCom; i++) {
1560 vfi[bIdc + i] = flashCal[pvtnum]->vfi[i];
1563 phaseNum[n] = nptmp - 1;
1569 for (
USI i = 0; i < numCom_1; i++) {
1571 flashCal[pvtnum]->xij[i] / flashCal[pvtnum]->xij[numCom + i];
1575 if (flashCal[pvtnum]->GetFtype() == 0) {
1576 flagSkip[n] = flashCal[pvtnum]->GetFlagSkip();
1578 minEigenSkip[n] = flashCal[pvtnum]->GetMinEigenSkip();
1579 for (
USI j = 0; j < numPhase - 1; j++) {
1580 if (phaseExist[bIdp + j]) {
1581 for (
USI i = 0; i < numCom - 1; i++) {
1582 ziSkip[bIdc + i] = flashCal[pvtnum]->xij[j * numCom + i];
1592 surTen[n] = flashCal[pvtnum]->GetSurTen();
1597 void Bulk::PassFlashValueAIMc(
const OCP_USI& n)
1603 USI pvtnum = PVTNUM[n];
1605 Nt[n] = flashCal[pvtnum]->Nt;
1606 vf[n] = flashCal[pvtnum]->vf;
1607 vfp[n] = flashCal[pvtnum]->vfp;
1609 for (
USI i = 0; i < numCom; i++) {
1610 vfi[bIdc + i] = flashCal[pvtnum]->vfi[i];
1614 for (
USI j = 0; j < numPhase; j++) {
1615 if (flashCal[pvtnum]->phaseExist[j]) {
1620 phaseNum[n] = nptmp - 1;
1627 for (
USI i = 0; i < numCom_1; i++) {
1629 flashCal[pvtnum]->xij[i] / flashCal[pvtnum]->xij[numCom + i];
1633 if (flashCal[pvtnum]->GetFtype() == 0) {
1634 flagSkip[n] = flashCal[pvtnum]->GetFlagSkip();
1636 minEigenSkip[n] = flashCal[pvtnum]->GetMinEigenSkip();
1637 for (
USI j = 0; j < numPhase - 1; j++) {
1638 if (phaseExist[bIdp + j]) {
1639 for (
USI i = 0; i < numCom - 1; i++) {
1640 ziSkip[bIdc + i] = flashCal[pvtnum]->xij[j * numCom + i];
1650 surTen[n] = flashCal[pvtnum]->GetSurTen();
1660 USI pvtnum = PVTNUM[n];
1664 for (
USI j = 0; j < numPhase; j++) {
1669 S[bIdp + j] = flashCal[pvtnum]->S[j];
1670 dSNR[bIdp + j] = S[bIdp + j] - dSNR[bIdp + j];
1671 if (phaseExist[bIdp + j]) {
1673 (dSNR[bIdp + j] - dSNRP[bIdp + j]) * (dSNR[bIdp + j] - dSNRP[bIdp + j]);
1674 if (fabs(maxNRdSSP) < fabs(dSNR[bIdp + j] - dSNRP[bIdp + j])) {
1675 maxNRdSSP = dSNR[bIdp + j] - dSNRP[bIdp + j];
1676 index_maxNRdSSP = n;
1682 phaseExist[bIdp + j] = flashCal[pvtnum]->phaseExist[j];
1683 pEnumCom[bIdp + j] = flashCal[pvtnum]->pEnumCom[j];
1684 len += pEnumCom[bIdp + j];
1685 if (phaseExist[bIdp + j]) {
1687 nj[bIdp + j] = flashCal[pvtnum]->nj[j];
1688 rho[bIdp + j] = flashCal[pvtnum]->rho[j];
1689 xi[bIdp + j] = flashCal[pvtnum]->xi[j];
1690 mu[bIdp + j] = flashCal[pvtnum]->mu[j];
1691 vj[bIdp + j] = flashCal[pvtnum]->v[j];
1694 muP[bIdp + j] = flashCal[pvtnum]->muP[j];
1695 xiP[bIdp + j] = flashCal[pvtnum]->xiP[j];
1696 rhoP[bIdp + j] = flashCal[pvtnum]->rhoP[j];
1697 for (
USI i = 0; i < numCom; i++) {
1698 xij[bIdp * numCom + j * numCom + i] =
1699 flashCal[pvtnum]->xij[j * numCom + i];
1700 mux[bIdp * numCom + j * numCom + i] =
1701 flashCal[pvtnum]->mux[j * numCom + i];
1702 xix[bIdp * numCom + j * numCom + i] =
1703 flashCal[pvtnum]->xix[j * numCom + i];
1704 rhox[bIdp * numCom + j * numCom + i] =
1705 flashCal[pvtnum]->rhox[j * numCom + i];
1709 Nt[n] = flashCal[pvtnum]->Nt;
1710 vf[n] = flashCal[pvtnum]->vf;
1711 vfp[n] = flashCal[pvtnum]->vfp;
1714 for (
USI i = 0; i < numCom; i++) {
1715 vfi[bIdc + i] = flashCal[pvtnum]->vfi[i];
1721 len *= (numCom + 1);
1722 dSdPindex[n + 1] = dSdPindex[n] + len;
1723 Dcopy(len, &dSec_dPri[0] + dSdPindex[n], &flashCal[pvtnum]->dXsdXp[0]);
1725 Dcopy(lendSdP, &dSec_dPri[0] + n * lendSdP, &flashCal[pvtnum]->dXsdXp[0]);
1729 phaseNum[n] = nptmp - 1;
1732 ePEC[n] = flashCal[pvtnum]->GetErrorPEC();
1742 for (
USI i = 0; i < numCom_1; i++) {
1744 flashCal[pvtnum]->xij[i] / flashCal[pvtnum]->xij[numCom + i];
1748 if (flashCal[pvtnum]->GetFtype() == 0) {
1749 flagSkip[n] = flashCal[pvtnum]->GetFlagSkip();
1751 minEigenSkip[n] = flashCal[pvtnum]->GetMinEigenSkip();
1752 for (
USI j = 0; j < numPhase - 1; j++) {
1753 if (phaseExist[bIdp + j]) {
1754 for (
USI i = 0; i < numCom - 1; i++) {
1755 ziSkip[bIdc + i] = flashCal[pvtnum]->xij[j * numCom + i];
1764 surTen[n] = flashCal[pvtnum]->GetSurTen();
1769 void Bulk::PassFlashValueDeriv_n(
const OCP_USI& n)
1774 USI pvtnum = PVTNUM[n];
1778 for (
USI j = 0; j < numPhase; j++) {
1783 S[bIdp + j] = flashCal[pvtnum]->S[j];
1784 dSNR[bIdp + j] = S[bIdp + j] - dSNR[bIdp + j];
1785 if (phaseExist[bIdp + j]) {
1787 (dSNR[bIdp + j] - dSNRP[bIdp + j]) * (dSNR[bIdp + j] - dSNRP[bIdp + j]);
1788 if (fabs(maxNRdSSP) < fabs(dSNR[bIdp + j] - dSNRP[bIdp + j])) {
1789 maxNRdSSP = dSNR[bIdp + j] - dSNRP[bIdp + j];
1790 index_maxNRdSSP = n;
1794 phaseExist[bIdp + j] = flashCal[pvtnum]->phaseExist[j];
1795 pEnumCom[bIdp + j] = flashCal[pvtnum]->pEnumCom[j];
1796 len += pEnumCom[bIdp + j];
1797 if (phaseExist[bIdp + j]) {
1799 nj[bIdp + j] = flashCal[pvtnum]->nj[j];
1800 rho[bIdp + j] = flashCal[pvtnum]->rho[j];
1801 xi[bIdp + j] = flashCal[pvtnum]->xi[j];
1802 mu[bIdp + j] = flashCal[pvtnum]->mu[j];
1803 vj[bIdp + j] = flashCal[pvtnum]->v[j];
1806 muP[bIdp + j] = flashCal[pvtnum]->muP[j];
1807 xiP[bIdp + j] = flashCal[pvtnum]->xiP[j];
1808 rhoP[bIdp + j] = flashCal[pvtnum]->rhoP[j];
1809 for (
USI i = 0; i < numCom; i++) {
1810 xij[bIdp * numCom + j * numCom + i] =
1811 flashCal[pvtnum]->xij[j * numCom + i];
1812 mux[bIdp * numCom + j * numCom + i] =
1813 flashCal[pvtnum]->mux[j * numCom + i];
1814 xix[bIdp * numCom + j * numCom + i] =
1815 flashCal[pvtnum]->xix[j * numCom + i];
1816 rhox[bIdp * numCom + j * numCom + i] =
1817 flashCal[pvtnum]->rhox[j * numCom + i];
1821 Nt[n] = flashCal[pvtnum]->Nt;
1822 vf[n] = flashCal[pvtnum]->vf;
1823 vfp[n] = flashCal[pvtnum]->vfp;
1826 for (
USI i = 0; i < numCom; i++) {
1827 vfi[bIdc + i] = flashCal[pvtnum]->vfi[i];
1831 resIndex[n + 1] = resIndex[n] + len;
1832 Dcopy(len, &res_n[0] + resIndex[n], &flashCal[pvtnum]->res[0]);
1833 len *= (numCom + 1);
1834 dSdPindex[n + 1] = dSdPindex[n] + len;
1835 Dcopy(len, &dSec_dPri[0] + dSdPindex[n], &flashCal[pvtnum]->dXsdXp[0]);
1837 resPc[n] = flashCal[pvtnum]->resPc;
1840 phaseNum[n] = nptmp - 1;
1843 ePEC[n] = flashCal[pvtnum]->GetErrorPEC();
1853 for (
USI i = 0; i < numCom_1; i++) {
1855 flashCal[pvtnum]->xij[i] / flashCal[pvtnum]->xij[numCom + i];
1859 if (flashCal[pvtnum]->GetFtype() == 0) {
1860 flagSkip[n] = flashCal[pvtnum]->GetFlagSkip();
1862 minEigenSkip[n] = flashCal[pvtnum]->GetMinEigenSkip();
1863 for (
USI j = 0; j < numPhase - 1; j++) {
1864 if (phaseExist[bIdp + j]) {
1865 for (
USI i = 0; i < numCom - 1; i++) {
1866 ziSkip[bIdc + i] = flashCal[pvtnum]->xij[j * numCom + i];
1875 surTen[n] = flashCal[pvtnum]->GetSurTen();
1884 phaseExist = lphaseExist;
1903 for (
OCP_USI n = 0; n < numBulk; n++) {
1905 flow[SATNUM[n]]->CalKrPc(&S[bId], &kr[bId], &Pc[bId], 0, tmp, tmp);
1906 for (
USI j = 0; j < numPhase; j++)
1907 Pj[n * numPhase + j] = P[n] + Pc[n * numPhase + j];
1910 for (
OCP_USI n = 0; n < numBulk; n++) {
1912 flow[SATNUM[n]]->CalKrPc(&S[bId], &kr[bId], &Pc[bId], surTen[n], Fk[n],
1914 for (
USI j = 0; j < numPhase; j++)
1915 Pj[n * numPhase + j] = P[n] + Pc[n * numPhase + j];
1922 for (
USI n = 0; n < numBulk; n++) {
1923 Pc[n * numPhase + Wid] *= ScaleValuePcow[n];
1924 Pj[n * numPhase + Wid] = P[n] + Pc[n * numPhase + Wid];
1935 for (
OCP_USI n = 0; n < numBulk; n++) {
1937 flow[SATNUM[n]]->CalKrPcDeriv(&S[bId], &kr[bId], &Pc[bId],
1938 &dKr_dS[bId * numPhase],
1939 &dPcj_dS[bId * numPhase], 0, tmp, tmp);
1940 for (
USI j = 0; j < numPhase; j++) Pj[bId + j] = P[n] + Pc[bId + j];
1943 for (
OCP_USI n = 0; n < numBulk; n++) {
1945 flow[SATNUM[n]]->CalKrPcDeriv(
1946 &S[bId], &kr[bId], &Pc[bId], &dKr_dS[bId * numPhase],
1947 &dPcj_dS[bId * numPhase], surTen[n], Fk[n], Fp[n]);
1948 for (
USI j = 0; j < numPhase; j++)
1949 Pj[n * numPhase + j] = P[n] + Pc[n * numPhase + j];
1956 for (
USI n = 0; n < numBulk; n++) {
1957 Pc[n * numPhase + Wid] *= ScaleValuePcow[n];
1958 Pj[n * numPhase + Wid] = P[n] + Pc[n * numPhase + Wid];
1967 for (
OCP_USI n = 0; n < numBulk; n++) {
1968 OCP_DBL dP = rockC1 * (P[n] - rockPref);
1969 rockVp[n] = rockVpInit[n] * (1 + dP);
1982 if (numPhase == 3) {
1983 for (
OCP_USI n = 0; n < numBulk; n++) {
1984 tmp = rockVp[n] * (1 - S[n * numPhase + 2]);
1988 }
else if (numPhase < 3) {
1989 for (
OCP_USI n = 0; n < numBulk; n++) {
1990 tmp = rockVp[n] * (S[n * numPhase]);
1995 OCP_ABORT(
"Number of phases is out of range!");
2010 OCP_USI ndPmax, ndNmax, ndSmax, ndVmax;
2012 for (
OCP_USI n = 0; n < numBulk; n++) {
2015 tmp = fabs(P[n] - lP[n]);
2022 for (
USI j = 0; j < numPhase; j++) {
2023 id = n * numPhase + j;
2024 tmp = fabs(S[
id] - lS[
id]);
2032 for (
USI i = 0; i < numCom; i++) {
2033 id = n * numCom + i;
2035 tmp = fabs(max(Ni[
id], lNi[
id]));
2037 tmp = fabs(Ni[
id] - lNi[
id]) / tmp;
2045 tmp = fabs(vf[n] - rockVp[n]) / rockVp[n];
2099 for (
OCP_USI n = 0; n < numBulk; n++) {
2101 std::ostringstream PStringSci;
2102 PStringSci << std::scientific << P[n];
2103 OCP_WARNING(
"Negative pressure: P[" + std::to_string(n) +
2104 "] = " + PStringSci.str());
2105 cout <<
"P = " << P[n] << endl;
2118 OCP_USI len = numBulk * numCom;
2119 for (
OCP_USI n = 0; n < len; n++) {
2122 if (Ni[n] > -1E-3 * Nt[bId] &&
false) {
2123 Ni[n] = 1E-8 * Nt[bId];
2126 USI cId = n - bId * numCom;
2127 std::ostringstream NiStringSci;
2128 NiStringSci << std::scientific << Ni[n];
2129 OCP_WARNING(
"Negative Ni: Ni[" + std::to_string(cId) +
"] in Bulk[" +
2130 std::to_string(bId) +
"] = " + NiStringSci.str() +
" " +
2131 "dNi = " + std::to_string(dNNR[n]) + +
" lNi[" +
2132 std::to_string(cId) +
"] in Bulk[" + std::to_string(bId) +
2133 "] = " + std::to_string(lNi[n]) +
2134 " Nt = " + std::to_string(Nt[bId]) +
" " +
2135 std::to_string(phaseNum[bId]) +
" " +
2136 std::to_string(NRstep[bId]));
2137 for (
USI i = 0; i < numCom; i++) {
2138 cout << Ni[bId * numCom + i] <<
" ";
2141 for (
USI j = 0; j < numPhase - 1; j++) {
2142 cout << setprecision(9);
2143 if (phaseExist[bId * numPhase + j]) {
2145 for (
USI i = 0; i < numCom_1; i++) {
2146 cout << xij[bId * numPhase * numCom + j * numCom + i]
2167 for (
OCP_USI n = 0; n < numBulk; n++) {
2168 dVe = fabs(vf[n] - rockVp[n]) / rockVp[n];
2170 cout <<
"Volume error at Bulk[" << n <<
"] = " << setprecision(6) << dVe
2171 <<
" is too big!" << endl;
2188 for (
OCP_USI n = 0; n < numBulk; n++) {
2189 for (
USI j = 0; j < numPhase; j++) {
2190 id = n * numPhase + j;
2191 tmp = fabs(phaseExist[
id] - lphaseExist[
id]);
2193 cout <<
"Difference in phaseExist\t" << tmp <<
"\n";
2195 if (lphaseExist[
id] || phaseExist[
id]) {
2196 tmp = fabs(S[
id] - lS[
id]);
2198 cout << scientific << setprecision(16);
2199 cout <<
"Bulk[" << n <<
"]" << endl;
2200 cout <<
"Saturation" << endl;
2201 for (
USI j = 0; j < numPhase; j++) {
2202 cout << S[n * numPhase + j] <<
" " << lS[n * numPhase + j]
2205 cout <<
"Pressure" << endl;
2206 cout << P[n] <<
" " << lP[n] << endl;
2207 cout <<
"Ni" << endl;
2208 for (
USI i = 0; i < numCom; i++) {
2209 cout << Ni[n * numCom + i] <<
" " << lNi[n * numCom + i]
2212 cout <<
"PhaseNum" << endl;
2213 cout << phaseNum[n] <<
" " << lphaseNum[n] << endl;
2214 cout <<
"minEigenSkip" << endl;
2215 cout << minEigenSkip[n] <<
" " << lminEigenSkip[n] << endl;
2216 cout <<
"flagSkip" << endl;
2217 cout << flagSkip[n] <<
" " << lflagSkip[n] << endl;
2218 cout <<
"PSkip" << endl;
2219 cout << PSkip[n] <<
" " << lPSkip[n] << endl;
2220 cout <<
"ziSkip" << endl;
2221 for (
USI i = 0; i < numCom; i++) {
2222 cout << ziSkip[n * numCom + i] <<
" "
2223 << lziSkip[n * numCom + i] << endl;
2225 cout <<
"Ks" << endl;
2226 for (
USI i = 0; i < numCom_1; i++) {
2227 cout << Ks[n * numCom_1 + i] <<
" " << lKs[n * numCom_1 + i]
2231 cout <<
"Difference in S\t" << tmp <<
" " << phaseExist[id]
2234 tmp = fabs(xi[
id] - lxi[
id]);
2236 cout <<
"Difference in Xi\t" << tmp <<
" " << phaseExist[id]
2239 tmp = fabs(rho[
id] - lrho[
id]);
2241 cout <<
"Difference in rho\t" << tmp <<
" " << phaseExist[id]
2254 for (
OCP_USI n = 0; n < numBulk; n++) {
2256 for (
USI j = 0; j < numPhase; j++) {
2257 if (phaseExist[n * numPhase + j]) {
2258 if (S[n * numPhase + j] < 0) {
2261 tmp += S[n * numPhase + j];
2264 if (fabs(tmp - 1) >
TINY) {
2265 OCP_ABORT(
"Saturation is greater than 1!");
2279 OCP_ABORT(
"Mixture model is not supported!");
2282 void Bulk::CalSomeInfo(
const Grid& myGrid)
const
2314 const USI sp = myGrid.GetNumDigitIJK();
2315 for (
OCP_USI n = 0; n < numBulk; n++) {
2319 if (depthMax < depth[n]) {
2320 depthMax = depth[n];
2323 if (depthMin > depth[n]) {
2324 depthMin = depth[n];
2327 if (dxMax < dx[n]) {
2331 if (dxMin > dx[n]) {
2335 if (dyMax < dy[n]) {
2339 if (dyMin > dy[n]) {
2343 if (dzMax < dz[n]) {
2347 if (dzMin > dz[n]) {
2351 OCP_DBL tmp = myGrid.v[myGrid.activeMap_B2G[n]];
2370 if (PerxMax < tmp) {
2374 if (PerxMin > tmp && fabs(tmp) > 1E-8) {
2380 cout <<
"---------------------" << endl
2382 <<
"---------------------" << endl;
2384 cout <<
" Depthmax = " << depthMax <<
" feet " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2386 cout <<
" Depthmin = " << depthMin <<
" feet " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2388 cout <<
" DXmax = " << dxMax <<
" feet " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2390 cout <<
" DXmin = " << dxMin <<
" feet " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2392 cout <<
" DYmax = " << dyMax <<
" feet " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2394 cout <<
" DYmin = " << dyMin <<
" feet " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2396 cout <<
" DZmax = " << dzMax <<
" feet " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2398 cout <<
" DZmin = " << dzMin <<
" feet " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2400 cout <<
" RVmax = " << RVMax /
CONV1 <<
" rb " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2402 cout <<
" RVmin = " << RVMin /
CONV1 <<
" rb " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2404 cout <<
" RVmax = " << RVPMax /
CONV1 <<
" rb " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2406 cout <<
" RVmin = " << RVPMin /
CONV1 <<
" rb " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2408 cout <<
" Perxmax = " << PerxMax <<
" " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2410 cout <<
" Perxmin = " << scientific << PerxMin <<
" " << GetIJKformat(to_string(I), to_string(J), to_string(K), sp) << endl;
2422 vfi.resize(numBulk * numCom);
2423 vfp.resize(numBulk);
2424 cfl.resize(numBulk * numPhase);
2428 lPj.resize(numBulk * numPhase);
2429 lPc.resize(numBulk * numPhase);
2430 lphaseExist.resize(numBulk * numPhase);
2431 lS.resize(numBulk * numPhase);
2432 lrho.resize(numBulk * numPhase);
2433 lxi.resize(numBulk * numPhase);
2434 lxij.resize(numBulk * numPhase * numCom);
2435 lNi.resize(numBulk * numCom);
2436 lmu.resize(numBulk * numPhase);
2437 lkr.resize(numBulk * numPhase);
2438 lvj.resize(numBulk * numPhase);
2439 lvf.resize(numBulk);
2440 lNt.resize(numBulk);
2441 lvfi.resize(numBulk * numCom);
2442 lvfp.resize(numBulk);
2443 lrockVp.resize(numBulk);
2450 for (
OCP_USI n = 0; n < numBulk; n++) {
2452 for (
USI j = 0; j < numPhase; j++) {
2453 OCP_USI id = n * numPhase + j;
2454 if (phaseExist[
id]) Pj[id] = P[n] + Pc[id];
2465 for (
OCP_USI n = 0; n < numBulk; n++) {
2466 for (
USI j = 0; j < numPhase; j++) {
2467 id = n * numPhase + j;
2468 if (phaseExist[
id]) {
2469 if (vj[
id] <= 0)
continue;
2473 if (!isfinite(cfl[
id])) {
2478 if (tmp < cfl[
id]) tmp = cfl[id];
2488 lphaseNum = phaseNum;
2489 lminEigenSkip = minEigenSkip;
2490 lflagSkip = flagSkip;
2498 lphaseExist = phaseExist;
2527 nj.resize(numBulk * numPhase);
2528 vfi.resize(numBulk * numCom);
2529 vfp.resize(numBulk);
2530 muP.resize(numBulk * numPhase);
2531 xiP.resize(numBulk * numPhase);
2532 rhoP.resize(numBulk * numPhase);
2533 mux.resize(numBulk * numCom * numPhase);
2534 xix.resize(numBulk * numCom * numPhase);
2535 rhox.resize(numBulk * numCom * numPhase);
2536 lendSdP = (numCom + 1) * (numCom + 1) * numPhase;
2537 dSec_dPri.resize(numBulk * lendSdP);
2538 res_n.resize((numPhase + numPhase * numCom) * numBulk);
2539 resPc.resize(numBulk);
2540 dSdPindex.resize(numBulk + 1, 0);
2541 resIndex.resize(numBulk + 1, 0);
2542 pEnumCom.resize(numBulk * numPhase);
2543 dKr_dS.resize(numBulk * numPhase * numPhase);
2544 dPcj_dS.resize(numBulk * numPhase * numPhase);
2548 lPj.resize(numBulk * numPhase);
2549 lPc.resize(numBulk * numPhase);
2550 lphaseExist.resize(numBulk * numPhase);
2551 lS.resize(numBulk * numPhase);
2552 lnj.resize(numBulk * numPhase);
2553 lrho.resize(numBulk * numPhase);
2554 lxi.resize(numBulk * numPhase);
2555 lxij.resize(numBulk * numPhase * numCom);
2556 lNi.resize(numBulk * numCom);
2557 lmu.resize(numBulk * numPhase);
2558 lkr.resize(numBulk * numPhase);
2559 lvj.resize(numBulk * numPhase);
2560 lvf.resize(numBulk);
2561 lNt.resize(numBulk);
2562 lvfi.resize(numBulk * numCom);
2563 lvfp.resize(numBulk);
2564 lrockVp.resize(numBulk);
2565 lmuP.resize(numBulk * numPhase);
2566 lxiP.resize(numBulk * numPhase);
2567 lrhoP.resize(numBulk * numPhase);
2568 lmux.resize(numBulk * numCom * numPhase);
2569 lxix.resize(numBulk * numCom * numPhase);
2570 lrhox.resize(numBulk * numCom * numPhase);
2571 ldSec_dPri.resize(numBulk * lendSdP);
2572 lres_n.resize((numPhase + numPhase * numCom) * numBulk);
2573 ldSdPindex.resize(numBulk + 1, 0);
2574 lresIndex.resize(numBulk + 1, 0);
2575 lpEnumCom.resize(numBulk * numPhase);
2576 ldKr_dS.resize(numBulk * numPhase * numPhase);
2577 ldPcj_dS.resize(numBulk * numPhase * numPhase);
2579 dSNR.resize(numBulk * numPhase);
2580 dSNRP.resize(numBulk * numPhase);
2581 dNNR.resize(numBulk * numCom);
2582 dPNR.resize(numBulk);
2584 NRstep.resize(numBulk);
2593 NRphaseNum = phaseNum;
2599 USI row0 = numPhase;
2600 USI row = numPhase * (numCom + 1);
2601 USI col = numCom + 1;
2602 USI bsize = row * col;
2604 vector<OCP_DBL> dtmp(row, 0);
2608 for (
OCP_USI n = 0; n < numBulk; n++) {
2613 fill(dtmp.begin(), dtmp.end(), 0.0);
2615 DaAxpby((dSdPindex[n + 1] - dSdPindex[n]) / col, col, 1, dSec_dPri.data() + dSdPindex[n],
2616 u.data() + n * col, 1, dtmp.data());
2619 const bool newFIM =
true;
2621 DaAxpby(row0, col, 1, dSec_dPri.data() + n * bsize, u.data() + n * col, 1,
2623 const bool newFIM =
false;
2627 for (
USI j = 0; j < numPhase; j++) {
2628 if (!phaseExist[n * numPhase + j] && newFIM) {
2631 n_np_j = n * numPhase + j;
2634 if (fabs(dtmp[js]) > dSmaxlim) {
2635 choptmp = dSmaxlim / fabs(dtmp[js]);
2636 }
else if (S[n_np_j] + dtmp[js] < 0.0) {
2637 choptmp = 0.9 * S[n_np_j] / fabs(dtmp[js]);
2644 chopmin = min(chopmin, choptmp);
2650 for (
USI j = 0; j < numPhase; j++) {
2651 if (!phaseExist[n * numPhase + j] && newFIM) {
2652 dSNRP[n * numPhase + j] = 0;
2655 dSNRP[n * numPhase + j] = chopmin * dtmp[js];
2656 if (fabs(NRdSmaxP) < fabs(dSNRP[n * numPhase + j]))
2657 NRdSmaxP = dSNRP[n * numPhase + j];
2662 if (phaseNum[n] == 2 && comps) {
2663 bool tmpflag =
true;
2665 for (
USI j = 0; j < 2; j++) {
2666 bId = n * numPhase * numCom + j * numCom;
2667 for (
USI i = 0; i < numCom_1; i++) {
2668 xij[bId + i] += chopmin * dtmp[js];
2670 if (xij[bId + i] < 0) tmpflag =
false;
2673 if (tmpflag ||
true) {
2674 bId = n * numPhase * numCom;
2675 for (
USI i = 0; i < numCom_1; i++) {
2676 Ks[n * numCom_1 + i] = xij[bId + i] / xij[bId + numCom + i];
2686 if (fabs(NRdPmax) < fabs(dP)) NRdPmax = dP;
2692 NRstep[n] = chopmin;
2693 for (
USI i = 0; i < numCom; i++) {
2694 dNNR[n * numCom + i] = u[n * col + 1 + i] * chopmin;
2695 if (fabs(NRdNmax) < fabs(dNNR[n * numCom + i]) / Nt[n])
2696 NRdNmax = dNNR[n * numCom + i] / Nt[n];
2698 Ni[n * numCom + i] += dNNR[n * numCom + i];
2716 NRphaseNum = phaseNum;
2717 fill(dSNRP.begin(), dSNRP.end(), 0.0);
2723 USI row = numPhase * (numCom + 1);
2724 USI ncol = numCom + 1;
2727 vector<OCP_DBL> dtmp(row, 0);
2728 vector<OCP_DBL> tmpNij(numPhase * numCom, 0);
2737 for (
OCP_USI n = 0; n < numBulk; n++) {
2738 const vector<OCP_DBL>& scm = satcm[SATNUM[n]];
2743 if (fabs(NRdPmax) < fabs(dP)) NRdPmax = dP;
2751 const USI cNp = phaseNum[n] + 1;
2752 const USI len = resIndex[n + 1] - resIndex[n];
2757 Dcopy(len, &dtmp[0], &res_n[resIndex[n]]);
2758 DaAxpby(len, ncol, 1.0, dSec_dPri.data() + dSdPindex[n], u.data() + n * ncol,
2763 for (
USI j = 0; j < numPhase; j++) {
2764 n_np_j = n * numPhase + j;
2765 if (phaseExist[n_np_j]) {
2766 dSmax = max(fabs(dtmp[js]), dSmax);
2772 if (dSmax > dSmaxlim) {
2773 chop = min(chop, dSmaxlim / dSmax);
2777 for (
USI j = 0; j < numPhase; j++) {
2778 n_np_j = n * numPhase + j;
2779 if (phaseExist[n_np_j]) {
2780 if (fabs(S[n_np_j] - scm[j]) >
TINY &&
2781 (S[n_np_j] - scm[j]) / (chop * dtmp[js]) < 0)
2782 chop *= min(1.0, -((S[n_np_j] - scm[j]) / (chop * dtmp[js])));
2783 if (S[n_np_j] + chop * dtmp[js] < 0)
2784 chop *= min(1.0, -S[n_np_j] / (chop * dtmp[js]));
2790 fill(tmpNij.begin(), tmpNij.end(), 0.0);
2795 for (
USI j = 0; j < numPhase; j++) {
2796 n_np_j = n * numPhase + j;
2797 if (phaseExist[n_np_j]) {
2798 dSNRP[n_np_j] = chop * dtmp[js];
2799 if (fabs(NRdSmaxP) < fabs(dSNRP[n_np_j])) NRdSmaxP = dSNRP[n_np_j];
2807 Daxpy(numCom, nj[n_np_j], &xij[n_np_j * numCom], &tmpNij[j * numCom]);
2808 for (
USI i = 0; i < pEnumCom[j]; i++) {
2809 tmpNij[j * numCom + i] += chop * dtmp[jx + i];
2812 nj[n_np_j] =
Dnorm1(numCom, &tmpNij[j * numCom]);
2813 for (
USI i = 0; i < numCom; i++) {
2814 xij[n_np_j * numCom + i] = tmpNij[j * numCom + i] / nj[n_np_j];
2819 if (phaseNum[n] == 2 &&
false) {
2820 for (
USI i = 0; i < numCom_1; i++) {
2821 Ks[n * numCom_1 + i] = xij[n * numPhase * numCom + i] / xij[n * numPhase * numCom + numCom + i];
2849 for (
USI i = 0; i < numCom; i++) {
2850 dNNR[n * numCom + i] = u[n * ncol + 1 + i] * chop;
2851 if (fabs(NRdNmax) < fabs(dNNR[n * numCom + i]) / Nt[n])
2852 NRdNmax = dNNR[n * numCom + i] / Nt[n];
2853 Ni[n * numCom + i] += dNNR[n * numCom + i];
2868 const USI len = numCom + 1;
2869 for (
OCP_USI n = 0; n < numBulk; n++) {
2872 for (
USI i = 0; i < len; i++) {
2873 tmp = fabs(resFIM.res[n * len + i] / rockVp[n]);
2874 if (resFIM.maxRelRes_v < tmp) {
2875 resFIM.maxRelRes_v = tmp;
2880 eV[n] = sqrt(eV[n]);
2883 for (
USI i = 1; i < len; i++) {
2884 tmp = fabs(resFIM.res[n * len + i] / Nt[n]);
2885 if (resFIM.maxRelRes_mol < tmp) {
2886 resFIM.maxRelRes_mol = tmp;
2887 resFIM.maxId_mol = n;
2891 eN[n] = sqrt(eN[n]);
2906 void Bulk::ShowRes(
const vector<OCP_DBL>& res)
const
2910 const USI len = numCom + 1;
2911 for (
OCP_USI n = 0; n < numBulk; n++) {
2914 cout <<
"Bulk[" << setw(3) << n <<
"] ";
2915 cout <<
"Vp " << rockVp[n] <<
" ";
2916 cout <<
"Nt " << Nt[n] <<
" ";
2917 cout <<
"NRstep " << NRstep[n] <<
" ";
2918 cout <<
"P " << P[n] <<
" ";
2919 cout << dPNR[n] <<
" " << dPNR[n] / P[n] <<
" ";
2920 cout << (P[n] - lP[n]) / P[n] <<
" ";
2921 cout <<
"PhaseNum " << phaseNum[n] <<
" ";
2923 for (
USI i = 0; i < len; i++) {
2925 cout <<
"[" << setw(2) << i <<
"]"
2927 cout << -res[bId + i] <<
" ";
2928 cout << fabs(res[bId + i] / rockVp[n]) <<
" ";
2930 cout << fabs(res[bId + i] / Nt[n]) <<
" ";
2931 cout << Ni[n * numCom + i - 1] <<
" " << lNi[n * numCom + i - 1]
2933 cout << dNNR[n * numCom + i - 1] <<
" "
2934 << dNNR[n * numCom + i - 1] /
2935 (Ni[n * numCom + i - 1] - dNNR[n * numCom + i - 1])
2937 cout << (Ni[n * numCom + i - 1] - lNi[n * numCom + i - 1]) /
2938 lNi[n * numCom + i - 1]
2942 cout << rockVp[n] - vf[n] <<
" ";
2954 phaseNum = lphaseNum;
2955 minEigenSkip = lminEigenSkip;
2956 flagSkip = lflagSkip;
2964 phaseExist = lphaseExist;
2985 dSec_dPri = ldSec_dPri;
2988 dSdPindex = ldSdPindex;
2989 resIndex = lresIndex;
2990 pEnumCom = lpEnumCom;
3002 lphaseNum = phaseNum;
3003 lminEigenSkip = minEigenSkip;
3004 lflagSkip = flagSkip;
3012 lphaseExist = phaseExist;
3033 ldSec_dPri = dSec_dPri;
3036 ldSdPindex = dSdPindex;
3037 lresIndex = resIndex;
3038 lpEnumCom = pEnumCom;
3050 OCP_USI len = numBulk * numPhase;
3051 for (
USI n = 0; n < len; n++) {
3052 if (fabs(NRdSmax) < fabs(dSNR[n])) {
3065 OCP_DBL Bulk::GetNRdNmax() {
return NRdNmax; }
3067 void Bulk::CorrectNi(
const vector<OCP_DBL>& res)
3069 for (
OCP_USI n = 0; n < numBulk; n++) {
3070 for (
USI i = 0; i < numCom; i++) {
3071 Ni[n * numCom + i] += res[n * (numCom + 1) + i];
3072 if (Ni[n * numCom + i] < 0) {
3073 Ni[n * numCom + i] = 1E-8 * Nt[n];
3079 void Bulk::OutputInfo(
const OCP_USI& n)
const
3083 OCP_USI bIdPC = bIdP * numCom;
3085 cout <<
"------------------------------" << endl;
3086 cout <<
"Bulk[" << n <<
"]" << endl;
3087 cout << fixed << setprecision(3);
3088 for (
USI i = 0; i < numCom; i++) {
3089 cout << Ni[bIdC + i] <<
" ";
3091 cout << endl << P[n] <<
" " << T;
3094 cout << fixed << setprecision(8);
3095 if (phaseExist[bIdP + 0]) {
3096 for (
USI i = 0; i < numCom; i++) {
3097 cout << xij[bIdPC + i] <<
" ";
3100 for (
USI i = 0; i < numCom; i++) {
3101 cout << 0.000000 <<
" ";
3104 cout << phaseExist[bIdP + 0] <<
" ";
3105 cout << xi[bIdP + 0] <<
" ";
3106 cout << S[bIdP + 0] <<
" ";
3109 if (phaseExist[bIdP + 1]) {
3110 for (
USI i = 0; i < numCom; i++) {
3111 cout << xij[bIdPC + numCom + i] <<
" ";
3114 for (
USI i = 0; i < numCom; i++) {
3115 cout << 0.000000 <<
" ";
3119 cout << phaseExist[bIdP + 1] <<
" ";
3120 cout << xi[bIdP + 1] <<
" ";
3121 cout << S[bIdP + 1] <<
" ";
3124 cout << fixed << setprecision(3);
3126 cout << vf[n] <<
" " << rockVp[n] <<
" ";
3127 cout << fixed << setprecision(12);
3128 cout << fabs(vf[n] - rockVp[n]) / rockVp[n] << endl;
3129 cout << fixed << setprecision(3);
3130 cout << vj[bIdP] <<
" " << vj[bIdP + 1] <<
" " << vj[bIdP + 2] << endl;
3131 cout <<
"------------------------------" << endl;
3142 maxNumFIMBulk = numBulk * ratio;
3143 if (maxNumFIMBulk < wellBulkId.capacity()) {
3144 maxNumFIMBulk = wellBulkId.capacity();
3146 FIMBulk.reserve(maxNumFIMBulk);
3147 map_Bulk2FIM.resize(numBulk, -1);
3149 muP.resize(maxNumFIMBulk * numPhase);
3150 xiP.resize(maxNumFIMBulk * numPhase);
3151 rhoP.resize(maxNumFIMBulk * numPhase);
3152 mux.resize(maxNumFIMBulk * numCom * numPhase);
3153 xix.resize(maxNumFIMBulk * numCom * numPhase);
3154 rhox.resize(maxNumFIMBulk * numCom * numPhase);
3155 lendSdP = (numCom + 1) * (numCom + 1) * numPhase;
3156 dSec_dPri.resize(maxNumFIMBulk * lendSdP);
3157 dKr_dS.resize(maxNumFIMBulk * numPhase * numPhase);
3158 dPcj_dS.resize(maxNumFIMBulk * numPhase * numPhase);
3160 lmuP.resize(maxNumFIMBulk * numPhase);
3161 lxiP.resize(maxNumFIMBulk * numPhase);
3162 lrhoP.resize(maxNumFIMBulk * numPhase);
3163 lmux.resize(maxNumFIMBulk * numCom * numPhase);
3164 lxix.resize(maxNumFIMBulk * numCom * numPhase);
3165 lrhox.resize(maxNumFIMBulk * numCom * numPhase);
3166 ldSec_dPri.resize(maxNumFIMBulk * lendSdP);
3167 ldKr_dS.resize(maxNumFIMBulk * numPhase * numPhase);
3168 ldPcj_dS.resize(maxNumFIMBulk * numPhase * numPhase);
3170 FIMNi.resize(maxNumFIMBulk * numCom);
3185 len = FIMBulk.size();
3190 for (
OCP_USI k = 0; k < len; k++) {
3195 minEig = minEigenSkip[n];
3196 if (fabs(1 - PSkip[n] / P[n]) >= minEig / 10) {
3201 Ntw = Nt[n] - Ni[bIdc + numCom_1];
3202 for (
USI i = 0; i < numCom_1; i++) {
3204 if (fabs(Ni[bIdc + i] / Ntw - ziSkip[bIdc + i]) >= minEig / 10) {
3215 flashCal[PVTNUM[n]]->FlashDeriv(P[n], T, &Ni[n * numCom], ftype, phaseNum[n],
3217 PassFlashValueDerivAIM(k);
3225 void Bulk::PassFlashValueDerivAIM(
const OCP_USI& fn)
3232 USI pvtnum = PVTNUM[n];
3234 for (
USI j = 0; j < numPhase; j++) {
3235 phaseExist[bIdp + j] = flashCal[pvtnum]->phaseExist[j];
3240 S[bIdp + j] = flashCal[pvtnum]->S[j];
3241 if (phaseExist[bIdp + j]) {
3243 rho[bIdp + j] = flashCal[pvtnum]->rho[j];
3244 xi[bIdp + j] = flashCal[pvtnum]->xi[j];
3245 mu[bIdp + j] = flashCal[pvtnum]->mu[j];
3246 vj[bIdp + j] = flashCal[pvtnum]->v[j];
3249 muP[fnp + j] = flashCal[pvtnum]->muP[j];
3250 xiP[fnp + j] = flashCal[pvtnum]->xiP[j];
3251 rhoP[fnp + j] = flashCal[pvtnum]->rhoP[j];
3252 for (
USI i = 0; i < numCom; i++) {
3253 xij[bIdp * numCom + j * numCom + i] =
3254 flashCal[pvtnum]->xij[j * numCom + i];
3255 mux[fnp * numCom + j * numCom + i] =
3256 flashCal[pvtnum]->mux[j * numCom + i];
3257 xix[fnp * numCom + j * numCom + i] =
3258 flashCal[pvtnum]->xix[j * numCom + i];
3259 rhox[fnp * numCom + j * numCom + i] =
3260 flashCal[pvtnum]->rhox[j * numCom + i];
3264 Nt[n] = flashCal[pvtnum]->Nt;
3265 vf[n] = flashCal[pvtnum]->vf;
3266 vfp[n] = flashCal[pvtnum]->vfp;
3269 for (
USI i = 0; i < numCom; i++) {
3270 vfi[bIdc + i] = flashCal[pvtnum]->vfi[i];
3272 dSec_dPri.insert(dSec_dPri.end(), flashCal[pvtnum]->dXsdXp.begin(),
3273 flashCal[pvtnum]->dXsdXp.end());
3275 phaseNum[n] = nptmp - 1;
3282 for (
USI i = 0; i < numCom_1; i++) {
3284 flashCal[pvtnum]->xij[i] / flashCal[pvtnum]->xij[numCom + i];
3288 if (flashCal[pvtnum]->GetFtype() == 0) {
3289 flagSkip[n] = flashCal[pvtnum]->GetFlagSkip();
3291 minEigenSkip[n] = flashCal[pvtnum]->GetMinEigenSkip();
3292 for (
USI j = 0; j < numPhase - 1; j++) {
3293 if (phaseExist[bIdp + j]) {
3294 for (
USI i = 0; i < numCom - 1; i++) {
3295 ziSkip[bIdc + i] = flashCal[pvtnum]->xij[j * numCom + i];
3304 surTen[n] = flashCal[pvtnum]->GetSurTen();
3315 len = FIMBulk.size();
3320 for (
OCP_USI fn = 0; fn < len; fn++) {
3324 flow[SATNUM[n]]->CalKrPcDeriv(&S[bId], &kr[bId], &Pc[bId],
3325 &dKr_dS[fnp * numPhase], &dPcj_dS[fnp * numPhase],
3327 for (
USI j = 0; j < numPhase; j++) Pj[bId + j] = P[n] + Pc[bId + j];
3339 const USI len = numCom + 1;
3340 for (
OCP_USI fn = 0; fn < numFIMBulk; fn++) {
3343 for (
USI i = 0; i < len; i++) {
3344 tmp = fabs(resFIM.res[fn * len + i] / rockVp[n]);
3345 if (resFIM.maxRelRes_v < tmp) {
3346 resFIM.maxRelRes_v = tmp;
3350 for (
USI i = 1; i < len; i++) {
3351 tmp = fabs(resFIM.res[fn * len + i] / Nt[n]);
3352 if (resFIM.maxRelRes_mol < tmp) {
3353 resFIM.maxRelRes_mol = tmp;
3368 USI row = numPhase * (numCom + 1);
3369 USI col = numCom + 1;
3370 USI bsize = row * col;
3371 vector<OCP_DBL> dtmp(row, 0);
3375 for (
OCP_USI fn = 0; fn < numFIMBulk; fn++) {
3380 fill(dtmp.begin(), dtmp.end(), 0.0);
3381 DaAxpby(row, col, 1, dSec_dPri.data() + fn * bsize, u.data() + fn * col, 1,
3384 for (
USI j = 0; j < numPhase; j++) {
3387 if (fabs(dtmp[j]) > dSmaxlim) {
3388 choptmp = dSmaxlim / fabs(dtmp[j]);
3389 }
else if (S[n * numPhase + j] + dtmp[j] < 0.0) {
3390 choptmp = 0.9 * S[n * numPhase + j] / fabs(dtmp[j]);
3393 chopmin = min(chopmin, choptmp);
3394 NRdSmaxP = max(NRdSmaxP, choptmp * fabs(dtmp[j]));
3397 choptmp = dPmaxlim / fabs(dP);
3398 chopmin = min(chopmin, choptmp);
3400 NRdPmax = max(NRdPmax, fabs(dP));
3415 for (
USI i = 0; i < numCom; i++) {
3416 Ni[n * numCom + i] += u[fn * col + 1 + i] * chopmin;
3434 const USI len = numCom + 1;
3435 for (
OCP_USI fn = 0; fn < numFIMBulk; fn++) {
3438 for (
USI i = 0; i < len; i++) {
3439 tmp = fabs(resFIM.res[n * len + i] / rockVp[n]);
3440 if (resFIM.maxRelRes_v < tmp) {
3441 resFIM.maxRelRes_v = tmp;
3445 for (
USI i = 1; i < len; i++) {
3446 tmp = fabs(resFIM.res[n * len + i] / Nt[n]);
3447 if (resFIM.maxRelRes_mol < tmp) {
3448 resFIM.maxRelRes_mol = tmp;
3455 void Bulk::GetSolAIMs(
const vector<OCP_DBL>& u,
const OCP_DBL& dPmaxlim,
3463 USI row = numPhase * (numCom + 1);
3464 USI col = numCom + 1;
3465 USI bsize = row * col;
3466 vector<OCP_DBL> dtmp(row, 0);
3471 for (
OCP_USI n = 0; n < numBulk; n++) {
3472 bIde = map_Bulk2FIM[n];
3474 if (bIde < 0 || bIde >= numFIMBulk) {
3487 fill(dtmp.begin(), dtmp.end(), 0.0);
3488 DaAxpby(row, col, 1, dSec_dPri.data() + bIde * bsize, u.data() + bIde * col,
3491 for (
USI j = 0; j < numPhase; j++) {
3493 if (fabs(dtmp[j]) > dSmaxlim) {
3494 choptmp = dSmaxlim / fabs(dtmp[j]);
3495 }
else if (S[n * numPhase + j] + dtmp[j] < 0.0) {
3496 choptmp = 0.9 * S[n * numPhase + j] / fabs(dtmp[j]);
3499 chopmin = min(chopmin, choptmp);
3500 NRdSmaxP = max(NRdSmaxP, choptmp * fabs(dtmp[j]));
3503 choptmp = dPmaxlim / fabs(dP);
3504 chopmin = min(chopmin, choptmp);
3506 NRdPmax = max(NRdPmax, fabs(dP));
3521 for (
USI i = 0; i < numCom; i++) {
3522 Ni[n * numCom + i] += u[n * col + 1 + i] * chopmin;
3533 void Bulk::UpdateLastStepAIM()
3543 ldSec_dPri = dSec_dPri;
3546 void Bulk::ResetFIMBulk()
3556 dSec_dPri = ldSec_dPri;
3559 void Bulk::ShowFIMBulk(
const bool& flag)
const
3561 cout << numFIMBulk <<
" " << fixed << setprecision(3)
3562 << numFIMBulk * 100.0 / numBulk <<
"%" << endl;
3564 for (
USI n = 0; n < numFIMBulk; n++) {
3565 cout << setw(6) << FIMBulk[n] <<
" ";
3566 if ((n + 1) % 10 == 0) {
3573 for (
USI n = 0; n < numBulk; n++) {
3574 cout << setw(6) << map_Bulk2FIM[n] <<
" ";
3575 if ((n + 1) % 10 == 0) {
3587 OCP_USI len = numBulk * numCom;
3588 for (
OCP_USI n = 0; n < len; n++) {
3591 USI cId = n - bId * numCom;
3592 std::ostringstream NiStringSci;
3593 NiStringSci << std::scientific << Ni[n];
3594 OCP_WARNING(
"Negative Ni: Ni[" + std::to_string(cId) +
"] in Bulk[" +
3595 std::to_string(bId) +
"] = " + NiStringSci.str());
3605 for (
OCP_USI n = 0; n < numFIMBulk; n++) {
3607 bIdb = FIMBulk[n] * numCom;
3608 for (
USI i = 0; i < numCom; i++) {
3609 FIMNi[bIdf + i] = Ni[bIdb + i];
3617 for (
OCP_USI n = 0; n < numFIMBulk; n++) {
3619 bIdb = FIMBulk[n] * numCom;
3620 for (
USI i = 0; i < numCom; i++) {
3621 Ni[bIdb + i] = FIMNi[bIdf + i];
3626 void Bulk::AllocateAuxAIMc()
3628 cfl.resize(numBulk * numPhase);
3629 map_Bulk2FIM.resize(numBulk, -1);
3643 for (
OCP_USI n = 0; n < numBulk; n++) {
3644 if (map_Bulk2FIM[n] > -1) {
3649 flashCal[PVTNUM[n]]->Flash(P[n], T, &Ni[n * numCom], 0, 0, 0);
3650 PassFlashValueAIMc(n);
3661 for (
OCP_USI n = 0; n < numBulk; n++) {
3662 if (map_Bulk2FIM[n] > -1) {
3669 minEig = minEigenSkip[n];
3670 if (fabs(1 - PSkip[n] / P[n]) >= minEig / 10) {
3677 Ntw = Nt[n] - Ni[bId + numCom - 1];
3678 for (
USI i = 0; i < numCom - 1; i++) {
3680 if (fabs(Ni[bId + i] / Ntw - ziSkip[bId + i]) >= minEig / 10) {
3690 flashCal[PVTNUM[n]]->Flash(P[n], T, &Ni[n * numCom], ftype, phaseNum[n],
3692 PassFlashValueAIMc(n);
3696 void Bulk::FlashAIMc01()
3701 FlashBLKOILAIMc01();
3705 void Bulk::FlashBLKOILAIMc01()
3707 for (
OCP_USI n = 0; n < numBulk; n++) {
3708 if (map_Bulk2FIM[n] > -1) {
3713 flashCal[PVTNUM[n]]->Flash(P[n], T, &Ni[n * numCom], 0, 0, 0);
3718 void Bulk::FlashCOMPAIMc01()
3725 for (
OCP_USI n = 0; n < numBulk; n++) {
3726 if (map_Bulk2FIM[n] > -1) {
3733 minEig = minEigenSkip[n];
3734 if (fabs(1 - PSkip[n] / P[n]) >= minEig / 10) {
3741 Ntw = Nt[n] - Ni[bId + numCom - 1];
3742 for (
USI i = 0; i < numCom - 1; i++) {
3744 if (fabs(Ni[bId + i] / Ntw - ziSkip[bId + i]) >= minEig / 10) {
3754 flashCal[PVTNUM[n]]->Flash(P[n], T, &Ni[n * numCom], ftype, phaseNum[n],
3772 for (
auto& n : FIMBulk) {
3773 flashCal[PVTNUM[n]]->FlashDeriv(P[n], T, &Ni[n * numCom], 0, 0, 0);
3785 for (
auto& n : FIMBulk) {
3788 minEig = minEigenSkip[n];
3789 if (fabs(1 - PSkip[n] / P[n]) >= minEig / 10) {
3796 Ntw = Nt[n] - Ni[bId + numCom - 1];
3797 for (
USI i = 0; i < numCom - 1; i++) {
3799 if (fabs(Ni[bId + i] / Ntw - ziSkip[bId + i]) >= minEig / 10) {
3810 flashCal[PVTNUM[n]]->FlashDeriv(P[n], T, &Ni[n * numCom], ftype, phaseNum[n],
3820 for (
OCP_USI n = 0; n < numBulk; n++) {
3821 if (map_Bulk2FIM[n] > -1) {
3826 flow[SATNUM[n]]->CalKrPc(&S[bId], &kr[bId], &Pc[bId], 0, tmp, tmp);
3827 for (
USI j = 0; j < numPhase; j++)
3828 Pj[n * numPhase + j] = P[n] + Pc[n * numPhase + j];
3835 for (
auto& n : FIMBulk) {
3837 flow[SATNUM[n]]->CalKrPcDeriv(&S[bId], &kr[bId], &Pc[bId],
3838 &dKr_dS[bId * numPhase], &dPcj_dS[bId * numPhase],
3840 for (
USI j = 0; j < numPhase; j++) Pj[bId + j] = P[n] + Pc[bId + j];
3844 void Bulk::GetSolAIMc(
const vector<OCP_DBL>& u,
const OCP_DBL& dPmaxlim,
3850 USI row = numPhase * (numCom + 1);
3851 USI col = numCom + 1;
3855 for (
OCP_USI n = 0; n < numBulk; n++) {
3860 dPNR[n] = u[n * col];
3861 tmp = fabs(dPNR[n] / P[n]);
3864 if (tmp > NRdPmax) {
3868 for (
USI i = 0; i < numCom; i++) {
3872 if (Ni[n * numCom + i] + u[n * col + 1 + i] < 0) {
3873 dNNR[n * numCom + i] = -Ni[n * numCom + i];
3875 Ni[n * numCom + i] = 1E-8 * Nt[n];
3877 }
else if (u[n * col + 1 + i] > Ni[n * numCom + i]) {
3878 dNNR[n * numCom + i] = Ni[n * numCom + i];
3880 Ni[n * numCom + i] += dNNR[n * numCom + i];
3882 dNNR[n * numCom + i] = u[n * col + 1 + i];
3883 tmp = fabs(dNNR[n * numCom + i]) / Ni[n * numCom + i];
3884 Ni[n * numCom + i] += dNNR[n * numCom + i];
3886 if (tmp > NRdNmax) {
3893 void Bulk::GetSolAIMc01(
const vector<OCP_DBL>& u,
const OCP_DBL& dPmaxlim,
3899 USI row0 = numPhase;
3900 USI row = numPhase * (numCom + 1);
3901 USI col = numCom + 1;
3902 USI bsize = row * col;
3903 vector<OCP_DBL> dtmp(row0, 0);
3907 for (
OCP_USI n = 0; n < numBulk; n++) {
3908 if (map_Bulk2FIM[n] < 0) {
3912 NRdPmax = max(NRdPmax, fabs(dP));
3917 for (
USI i = 0; i < numCom; i++) {
3918 dNNR[n * numCom + i] = u[n * col + 1 + i];
3919 Ni[n * numCom + i] += dNNR[n * numCom + i];
3926 fill(dtmp.begin(), dtmp.end(), 0.0);
3927 DaAxpby(row0, col, 1, dSec_dPri.data() + n * bsize, u.data() + n * col, 1,
3930 for (
USI j = 0; j < numPhase; j++) {
3932 if (fabs(dtmp[j]) > dSmaxlim) {
3933 choptmp = dSmaxlim / fabs(dtmp[j]);
3934 }
else if (S[n * numPhase + j] + dtmp[j] < 0.0) {
3935 choptmp = 0.9 * S[n * numPhase + j] / fabs(dtmp[j]);
3938 chopmin = min(chopmin, choptmp);
3939 NRdSmaxP = max(NRdSmaxP, choptmp * fabs(dtmp[j]));
3942 choptmp = dPmaxlim / fabs(dP);
3943 chopmin = min(chopmin, choptmp);
3944 NRdPmax = max(NRdPmax, fabs(dP));
3947 NRstep[n] = chopmin;
3949 for (
USI i = 0; i < numCom; i++) {
3950 dNNR[n * numCom + i] = u[n * col + 1 + i] * chopmin;
3951 Ni[n * numCom + i] += dNNR[n * numCom + i];
3956 void Bulk::UpdatePj()
3958 for (
OCP_USI n = 0; n < numBulk; n++) {
3959 for (
USI j = 0; j < numPhase; j++) {
3960 Pj[n * numPhase + j] = P[n] + Pc[n * numPhase + j];
void DaAxpby(const int &m, const int &n, const double &a, const double *A, const double *x, const double &b, double *y)
Computes y = a A x + b y.
void Daxpy(const int &n, const double &alpha, const double *x, double *y)
Constant times a vector plus a vector.
double Dnorm1(const int &N, double *x)
Computes the L1-norm of a vector.
void Dcopy(const int &N, double *dst, const double *src)
Calculate the minimal eigenvalue for sysmetric matrix with mkl lapack.
const USI BLKOIL
Mixture model = black-oil.
const OCP_DBL TINY
Small constant.
const USI PHASE_ODGW01
Phase type = oil-dry gas-water.
const USI EOS_PVTW
Mixture model = equation-of-state.
unsigned int USI
Generic unsigned integer.
const USI GAS
Fluid type = gas.
double OCP_DBL
Double precision.
const OCP_DBL CONV1
1 bbl = CONV1 ft3
const USI WATER
Fluid type = water.
const USI PHASE_ODGW
Phase type = oil-dry gas-water.
const USI PHASE_ODGW02
Phase type = oil-dry gas-water.
const USI OIL
Fluid type = oil.
const USI PHASE_W
Phase type = water only.
unsigned int OCP_USI
Long unsigned integer.
const USI PHASE_ODGW01_MISCIBLE
Phase type = oil-dry gas-water.
const USI PHASE_OW
Phase type = oil-water.
const USI PHASE_DOGW
Phase type = dead oil-gas-water.
const USI PHASE_OG
Phase type = oil-gas.
const USI PHASE_GW
Phase type = gas-water.
#define OCP_FUNCNAME
Print Function Name.
#define OCP_WARNING(msg)
Log warning messages.
#define OCP_ABORT(msg)
Abort if critical error happens.
void AllocateAuxAIM(const OCP_DBL &ratio)
Allocate memory for auxiliary variables used for AIMt.
void InitSjPcComp(const USI &tabrow, const Grid &myGrid)
Calculate initial equilibrium for compositional model according to EQUIL.
void PassFlashValue(const OCP_USI &n)
Pass values from Flash to Bulk after Flash calculation.
void FlashBLKOIL()
Perform flash calculation with Ni in Black Oil Model.
USI CalFlashType(const OCP_USI &n) const
determine which flash type will be used
void CalRelResAIMs(ResFIM &resFIM) const
Calculate relative resiual for AIMs, parts related to FIM are considered.
void GetSolIMPEC(const vector< OCP_DBL > &u)
Update P and Pj after linear system is solved.
OCP_DBL GetNRdPmax()
Return NRdPmax.
void CheckDiff()
Check difference from last time step, for Debug and Test.
void FlashCOMPAIMc()
Perform flash calculation with Ni in Compositional Model.
void InitFlash(const bool &flag=false)
Perform flash calculation with saturations.
void FlashAIMc()
Perform flash calculation with Ni.
bool CheckVe(const OCP_DBL &Vlim) const
Check if relative volume error is out of range, return false if so.
void AllocateAuxIMPEC()
Allocate memory for auxiliary variables used for IMPEC.
void CalMaxChange()
Calculate max change of some variables.
USI GetMixMode() const
Return the mixture mode.
void OutFIMNi()
FIMNi -> Ni in FIM Bulk.
void UpdateLastStepFIM()
Update values of last step for FIM.
void PassFlashValueDeriv(const OCP_USI &n)
Pass derivative values from Flash to Bulk after Flash calculation.
void FlashDeriv()
Perform flash calculation with Ni and calculate derivatives.
OCP_DBL GetNRdSmaxP()
Return NRdSmaxP.
void CalVpore()
Calculate volume of pore with pressure.
void CalRelResFIM(ResFIM &resFIM) const
Calculate relative resiual for FIM.
void CheckSetup() const
Check if error occurs in Setup.
void ResetFIM()
Reset FIM.
void CalKrPcDerivAIMc()
Calculate relative permeability and capillary pressure and their derivatives.
void CheckSat() const
Check if the sum of saturations is one.
void FlashCOMP()
Perform flash calculation with Ni in Compositional Model.
void GetSolAIMt(const vector< OCP_DBL > &u, const OCP_DBL &dPmaxlim, const OCP_DBL &dSmaxlim)
Get the solution for local FIM after a Newton iteration.
void Flash()
Perform flash calculation with Ni.
void CalKrPcDeriv()
Calculate relative permeability and capillary pressure and their derivatives.
void CheckInitVpore() const
Check initial pore volume.
OCP_DBL CalNRdSmax(OCP_USI &index)
Calculate some auxiliary variable, for example, dSmax.
void GetSol01FIM(const vector< OCP_DBL > &u)
Get the solution for FIM after a Newton iteration???
bool CheckNiFIMBulk() const
Check if negative Ni occurs, return false if so.
void FlashDerivBLKOILAIMc()
Perform flash calculation with Ni in Black Oil Model.
OCP_DBL CalCFL() const
Calculate the CFL number.
void FlashDerivBLKOIL()
Perform flash calculation with Ni in Black Oil Model.
void Setup(const Grid &myGrid)
Allocate memory for bulk data of grid.
void FlashDerivAIM(const bool &IfAIMs)
Perform flash calculation with Ni and calculate derivatives.
void CalKrPcDerivAIM(const bool &IfAIMs)
Calculate relative permeability and capillary pressure and their derivatives.
void FlashDerivCOMPAIMc()
Perform flash calculation with Ni in Compositional Model.
void ResetFlash()
Reset variables in flash calculations.
void FlashDerivAIMc()
Perform flash calculation with Ni and calculate derivatives.
void InputParam(ParamReservoir &rs_param)
Input param from internal data structure ParamReservoir.
void CalKrPcAIMc()
Calculate relative permeability and capillary pressure with saturation.
void InFIMNi()
Ni in FIM Bulk -> FIMNi.
void CalKrPc()
Calculate relative permeability and capillary pressure with saturation.
OCP_DBL CalFPR() const
Calculate average pressure in reservoir.
void InitSjPcBo(const USI &tabrow)
Calculate initial equilibrium for blkoil model according to EQUIL.
void UpdateLastStepIMPEC()
Update value of last step for IMPEC.
bool CheckNi()
Check if negative Ni occurs, return false if so.
void InitFlashDer()
Perform flash calculation with saturations and calculate derivatives.
void AllocateAuxFIM()
Allocate memory for auxiliary variables used for FIM.
void GetSolFIM_n(const vector< OCP_DBL > &u, const OCP_DBL &dPmaxlim, const OCP_DBL &dSmaxlim)
void FlashBLKOILAIMc()
Perform flash calculation with Ni in Black Oil Model.
void CheckVpore() const
Check pore volume.
bool CheckP() const
Check if negative P occurs, return false if so.
void CalRelResAIMt(ResFIM &resFIM) const
Calculate relative resiual for local FIM.
void FlashDerivCOMP()
Perform flash calculation with Ni in Compositional Model.
void GetSolFIM(const vector< OCP_DBL > &u, const OCP_DBL &dPmaxlim, const OCP_DBL &dSmaxlim)
Get the solution for FIM after a Newton iteration.
USI numCom
num of components, water is excluded.
USI numPhase
num of phase, water is excluded, constant now.
bool miscible
Miscible treatment of hydrocarbons, used in compositional Model.
Basic information of computational grid, including the rock properties.
void GetIJKGrid(USI &i, USI &j, USI &k, const OCP_USI &n) const
Return the 3D coordinate for object grid with Grid index.
USI Eval_All(const USI &j, const OCP_DBL &val, vector< OCP_DBL > &outdata, vector< OCP_DBL > &slope)
void Display() const
Display the data of table on screen.
void Setup(const vector< vector< OCP_DBL >> &src)
Setup tables from existing data of table.
vector< OCP_DBL > & GetCol(const USI &j)
return the jth column in table to modify or use.
bool IsEmpty() const
judge if table is empty.
OCP_DBL Eval(const USI &j, const OCP_DBL &val, const USI &destj)
USI NTSFUN
Num of SAT regions.
bool disGas
If true, dissolve gas could exist in oil phase.
TableSet ZMFVD_T
Table set of ZMFVD.
vector< OCP_DBL > EQUIL
See ParamEQUIL.
USI numPhase
Number of phases.
bool gas
If true, gas phase could exist.
TableSet SOF3_T
Table set of SOF3.
TableSet PBVD_T
Table set of PBVD.
bool ScalePcow
whether Pcow should be scaled.
USI numCom
Number of components(hydrocarbon components), used in Compositional Model when input.
bool oil
If true, oil phase could exist.
bool blackOil
If ture, blackoil model will be used.
bool comps
If true, compositional model will be used.
USI NTPVT
Num of PVT regions.
OCP_DBL rsTemp
Temperature for reservoir.
bool water
If true, water phase could exist.
EoSparam EoSp
Initial component composition, used in compositional models.
OCP_DBL Cr
Compressibility factor of rock in reservoir.
OCP_DBL Pref
Reference pressure at initial porosity.
vector< vector< vector< OCP_DBL > > > data
All table with the same name.