OpenCAEPoro  v0.5.0
A simulator for multicomponent porous media flow
Reservoir.cpp
Go to the documentation of this file.
1 
12 #include "Reservoir.hpp"
13 
15 // General
17 
19 {
21 
22  grid.InputParam(param.paramRs, param.paramOutput);
23  bulk.InputParam(param.paramRs);
25  optFeatures.InputParam(param.paramRs);
26 }
27 
29 {
31 
32  grid.SetupIsoT();
36 
38 }
39 
41 {
42  grid.SetupT();
43  bulk.SetupT(grid);
46 }
47 
49 {
51 
54 }
55 
57 {
59 
61  allWells.CalMaxBHPChange();
62 }
63 
64 void Reservoir::CalIPRT(const OCP_DBL& dt)
65 {
67  // Calculate injection / production rate for current step
68  allWells.CalIPRT(bulk, dt);
69  // Calculate Reinjection fluid for next step
71 }
72 
74 {
75  fill(bulk.cfl.begin(), bulk.cfl.end(), 0.0);
76  const USI np = bulk.numPhase;
77 
78  for (OCP_USI c = 0; c < conn.numConn; c++) {
79  for (USI j = 0; j < np; j++) {
80  const OCP_USI uId = conn.upblock[c * np + j];
81 
82  if (bulk.phaseExist[uId * np + j]) {
83  bulk.cfl[uId * np + j] += fabs(conn.upblock_Velocity[c * np + j]) * dt;
84  }
85  }
86  }
87 
88  for (const auto& wl : allWells.wells) {
89  if (wl.IsOpen() && wl.WellType() == PROD) {
90  for (USI p = 0; p < wl.PerfNum(); p++) {
91  if (wl.PerfState(p) == OPEN) {
92  const OCP_USI k = wl.PerfLocation(p);
93 
94  for (USI j = 0; j < np; j++) {
95  bulk.cfl[k * np + j] += fabs(wl.PerfProdQj_ft3(p, j)) * dt;
96  }
97  }
98  }
99  }
100  }
101 
102  bulk.maxCFL = 0;
103  const OCP_USI len = bulk.numBulk * np;
104  for (OCP_USI n = 0; n < len; n++) {
105  if (bulk.phaseExist[n]) {
106  bulk.cfl[n] /= bulk.vj[n];
107 #ifdef DEBUG
108  if (!isfinite(bulk.cfl[n])) {
109  OCP_ABORT("cfl is nan!");
110  }
111 #endif // DEBUG
112  if (bulk.maxCFL < bulk.cfl[n]) bulk.maxCFL = bulk.cfl[n];
113  }
114  }
115 
116  return bulk.maxCFL;
117 }
118 
119 void Reservoir::PrintSolFIM(const string& outfile) const
120 {
121  ofstream outu(outfile);
122  if (!outu.is_open()) cout << "Can not open " << outfile << endl;
123  const OCP_USI nb = bulk.numBulk;
124  const OCP_USI nc = bulk.numCom;
125 
126  for (OCP_USI n = 0; n < nb; n++) {
127  // Pressure
128  outu << bulk.P[n] << "\n";
129  // Ni
130  for (USI i = 0; i < nc; i++) {
131  outu << bulk.Ni[n * nc + i] << "\n";
132  }
133  }
134  // Well Pressure
135  for (USI w = 0; w < allWells.numWell; w++) {
136  outu << allWells.GetWBHP(w) << "\n";
137  }
138  outu.close();
139 }
140 
141 /*----------------------------------------------------------------------------*/
142 /* Brief Change History of This File */
143 /*----------------------------------------------------------------------------*/
144 /* Author Date Actions */
145 /*----------------------------------------------------------------------------*/
146 /* Shizhe Li Oct/01/2021 Create file */
147 /* Chensong Zhang Oct/15/2021 Format file */
148 /*----------------------------------------------------------------------------*/
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:23
double OCP_DBL
Double precision.
Definition: OCPConst.hpp:27
const OCP_BOOL OPEN
Well type = open.
Definition: OCPConst.hpp:126
unsigned int OCP_USI
Long unsigned integer.
Definition: OCPConst.hpp:25
const USI PROD
Well type = producer.
Definition: OCPConst.hpp:123
Reservoir class declaration.
#define OCP_FUNCNAME
Print Function Name.
Definition: UtilError.hpp:73
#define OCP_ABORT(msg)
Abort if critical error happens.
Definition: UtilError.hpp:47
void InputParam(const ParamWell &paramWell, const ParamOutput &output_param)
Input param from ParamWell.
Definition: AllWells.cpp:18
vector< Well > wells
well set.
Definition: AllWells.hpp:174
OCP_DBL GetWBHP(const USI &w) const
Return the BHP of wth well.
Definition: AllWells.hpp:156
void ApplyControl(const USI &i)
Apply the operation mode at the ith critical time.
Definition: AllWells.cpp:177
void CalIPRT(const Bulk &myBulk, OCP_DBL dt)
Calculate Injection rate, total Injection, Production rate, total Production.
Definition: AllWells.cpp:249
void SetupWellGroup(const Bulk &myBulk)
Setup information of wellGroup.
Definition: AllWells.cpp:93
void Setup(const Grid &myGrid, const Bulk &myBulk)
Setup wells.
Definition: AllWells.cpp:75
USI numWell
num of wells.
Definition: AllWells.hpp:173
void CalReInjFluid(const Bulk &myBulk)
Calculate Reinjection fluid.
Definition: AllWells.cpp:285
OCP_USI numConn
Number of connections between bulks.
Definition: BulkConn.hpp:108
vector< OCP_USI > upblock
Index of upwinding bulk of connections : numConn * numPhase.
Definition: BulkConn.hpp:133
vector< OCP_DBL > upblock_Velocity
Definition: BulkConn.hpp:138
void SetupIsoT(const Grid &myGrid, const Bulk &myBulk)
Setup active connections.
Definition: BulkConn.cpp:24
void SetupOptionalFeatures(const Grid &myGrid, OptionalFeatures &optFeatures)
Setup optional features.
Definition: Bulk.cpp:429
USI numPhase
Number of phase.
Definition: Bulk.hpp:154
OCP_DBL maxCFL
max CFL number
Definition: Bulk.hpp:466
vector< OCP_DBL > Ni
Moles of component: numCom*numBulk.
Definition: Bulk.hpp:306
void CalMaxChange()
Calculate max change of indicator variables.
Definition: Bulk.cpp:1335
void InputParam(const ParamReservoir &rs_param)
Input param from internal data structure ParamReservoir.
Definition: Bulk.cpp:99
vector< OCP_BOOL > phaseExist
Existence of phase: numPhase*numBulk.
Definition: Bulk.hpp:313
void SetupIsoT(const Grid &myGrid)
Allocate memory for fluid grid for isothermal model.
Definition: Bulk.cpp:408
vector< OCP_DBL > vj
Volume of phase: numPhase*numBulk.
Definition: Bulk.hpp:315
void SetupT(const Grid &myGrid)
Allocate memory for fluid grid for ifThermal model.
Definition: Bulk.cpp:419
OCP_USI numBulk
Number of bulks (active grids).
Definition: Bulk.hpp:153
vector< OCP_DBL > P
Pressure: numBulk.
Definition: Bulk.hpp:309
vector< OCP_DBL > cfl
CFL number for each bulk.
Definition: Bulk.hpp:465
USI numCom
Number of component.
Definition: Bulk.hpp:155
void InputParam(const ParamReservoir &rs_param, const ParamOutput &output_param)
Input parameters from the internal param structure.
Definition: Grid.cpp:18
void SetupT()
Setup for thermal model.
Definition: Grid.cpp:89
void SetupIsoT()
Setup for Isothermal model.
Definition: Grid.cpp:82
Pre-processing unit for OpenCAEPoro for reading params from input files.
Definition: ParamRead.hpp:33
ParamOutput paramOutput
Read the output params.
Definition: ParamRead.hpp:45
ParamWell paramWell
Read the well params.
Definition: ParamRead.hpp:43
ParamReservoir paramRs
Read the reservoir params.
Definition: ParamRead.hpp:42
void SetupT()
Setup static information for reservoir with input params for Thermal model.
Definition: Reservoir.cpp:40
BulkConn conn
Bulk's connection info.
Definition: Reservoir.hpp:76
OptionalFeatures optFeatures
optional features.
Definition: Reservoir.hpp:77
void InputParam(ParamRead &param)
Definition: Reservoir.cpp:18
OCP_DBL CalCFL(const OCP_DBL &dt) const
Calculate the CFL number, including bulks and wells for IMPEC.
Definition: Reservoir.cpp:73
void CalMaxChange()
Calculate Maximum Change of some reference variables for IMPEC.
Definition: Reservoir.cpp:56
Grid grid
Init Grid info.
Definition: Reservoir.hpp:73
void ApplyControl(const USI &i)
Apply the control of ith critical time point.
Definition: Reservoir.cpp:48
Bulk bulk
Active grid info.
Definition: Reservoir.hpp:74
AllWells allWells
Wells class info.
Definition: Reservoir.hpp:75
void SetupIsoT()
Setup static information for reservoir with input params for Isothermal model.
Definition: Reservoir.cpp:28
void CalIPRT(const OCP_DBL &dt)
Calculate num of Injection, Production.
Definition: Reservoir.cpp:64