14 ControlTime::ControlTime(
const vector<OCP_DBL>& src)
24 ControlPreTime::ControlPreTime(
const vector<OCP_DBL>& src)
32 ControlNR::ControlNR(
const vector<OCP_DBL>& src)
43 void FastControl::ReadParam(
const USI& argc,
const char* optset[])
48 std::stringstream buffer;
52 for (
USI n = 2; n < argc; n++) {
56 OCP_INT pos = tmp.find_last_of(
'=');
58 if (pos == string::npos)
OCP_ABORT(
"Unknown Usage! See -h");
60 key = tmp.substr(0, pos);
61 value = tmp.substr(pos + 1, tmp.size() - pos);
69 }
else if (value ==
"FIMn") {
71 }
else if (value ==
"IMPEC") {
73 }
else if (value ==
"AIMc") {
75 }
else if (value ==
"AIMs") {
77 }
else if (value ==
"AIMt") {
80 OCP_ABORT(
"Wrong method param in command line!");
111 OCP_ABORT(
"Unknown Options: " + key +
" See -h");
123 if (argc >= 6 &&
false) {
125 if (
string(optset[2]) ==
"FIM") {
127 }
else if (
string(optset[2]) ==
"FIMn") {
129 }
else if (
string(optset[2]) ==
"IMPEC") {
131 }
else if (
string(optset[2]) ==
"AIMc") {
133 }
else if (
string(optset[2]) ==
"AIMs") {
135 }
else if (
string(optset[2]) ==
"AIMt") {
138 OCP_ABORT(
"Wrong method param in command line!");
151 workDir = CtrlParam.
dir;
152 if (CtrlParam.
method ==
"IMPEC") {
154 }
else if (CtrlParam.
method ==
"FIM") {
156 }
else if (CtrlParam.
method ==
"FIMn") {
158 }
else if (CtrlParam.
method ==
"AIMc") {
160 }
else if (CtrlParam.
method ==
"AIMs") {
162 }
else if (CtrlParam.
method ==
"AIMt") {
172 ctrlTimeSet.resize(t);
173 ctrlPreTimeSet.resize(t);
177 vector<USI> ctrlCriticalTime(n + 1);
178 for (
USI i = 0; i < n; i++) {
179 ctrlCriticalTime[i] = CtrlParam.
tuning_T[i].d;
181 ctrlCriticalTime.back() = t;
182 for (
USI i = 0; i < n; i++) {
183 for (
USI d = ctrlCriticalTime[i]; d < ctrlCriticalTime[i + 1]; d++) {
193 ctrlTime = ctrlTimeSet[i];
194 ctrlPreTime = ctrlPreTimeSet[i];
195 ctrlNR = ctrlNRSet[i];
196 end_time = criticalTime[i + 1];
197 wellChange = rs.allWells.GetWellChange();
203 OCP_DBL dt = criticalTime[i + 1] - current_time;
204 if (dt <= 0)
OCP_ABORT(
"Non-positive time stepsize!");
206 static bool firstflag =
true;
207 if (wellChange || firstflag) {
208 current_dt = min(dt, ctrlTime.
timeInit);
212 current_dt = min(dt, init_dt);
219 ctrlFast.ReadParam(argc, optset);
220 if (ctrlFast.activity) {
225 linearsolveFile =
"./csr.fasp";
231 linearsolveFile =
"./bsr.fasp";
234 OCP_ABORT(
"Wrong method in command line!");
237 USI n = ctrlTimeSet.size();
238 for (
USI i = 0; i < n; i++) {
239 ctrlTimeSet[i].timeInit = ctrlFast.
timeInit;
240 ctrlTimeSet[i].timeMax = ctrlFast.
timeMax;
241 ctrlTimeSet[i].timeMin = ctrlFast.
timeMin;
249 last_dt = current_dt;
250 current_time += current_dt;
253 c1 = c2 = c3 = c4 = 10;
262 if (dPmax >
TINY) c1 = ctrlPreTime.
dPlim / dPmax;
263 if (dSmax >
TINY) c2 = ctrlPreTime.
dSlim / dSmax;
264 if (dNmax >
TINY) c3 = ctrlPreTime.
dNlim / dNmax;
265 if (dVmax >
TINY) c4 = ctrlPreTime.
dVlim / dVmax;
267 c = min(min(c1, c2), min(c3, c4));
276 init_dt = current_dt;
278 OCP_DBL dt = end_time - current_time;
279 if (current_dt > dt) current_dt = dt;
285 void OCPControl::CalNextTstepFIM(
const Reservoir& reservoir)
287 last_dt = current_dt;
288 current_time += current_dt;
294 const OCP_DBL dPmaxW = reservoir.allWells.GetdBHPmax();
295 const OCP_DBL dPmax = max(dPmaxB, dPmaxW);
298 if (dPmax >
TINY) c1 = ctrlPreTime.
dPlim / dPmax;
299 if (dSmax >
TINY) c2 = ctrlPreTime.
dSlim / dSmax;
305 }
else if (iterNR > 8) {
309 c = min(min(c1, c2), c3);
317 init_dt = current_dt;
319 const OCP_DBL dt = end_time - current_time;
320 if (current_dt > dt) current_dt = dt;
327 iterNR_total += iterNR;
328 iterLS_total += iterLS;
335 wastedIterNR += iterNR;
337 wastedIterLS += iterLS;
const USI AIMs
Adaptive implicit.
const OCP_DBL TINY
Small constant.
const USI AIMt
improved version of IMPEC, loacl FIM after IMPEC
unsigned int USI
Generic unsigned integer.
double OCP_DBL
Double precision.
const USI FIMn
Solution method = FIM.
const USI FIM
Solution method = FIM.
const USI AIMc
Adaptive implicit -— Collins.
const USI IMPEC
Solution method = IMPEC.
OCPControl class declaration.
#define OCP_ABORT(msg)
Abort if critical error happens.
OCP_DBL GetdVmax() const
Return dVmax.
OCP_DBL GetdSmax() const
Return dSmax.
OCP_DBL GetdNmax() const
Return dNmax.
OCP_DBL GetdPmax() const
Return dPmax.
Params for Newton iterations and linear iterations.
OCP_DBL NRtol
Maximum non-linear convergence error.
OCP_DBL NRdSmin
Minimum Saturation change in a Newton iteration.
OCP_DBL NRdPmax
Maximum Pressure change in a Newton iteration.
USI maxNRiter
Maximum number of Newton iterations in a timestep.
OCP_DBL NRdSmax
Maximum Saturation change in a Newton iteration.
OCP_DBL NRdPmin
Minimum Pressure change in a Newton iteration.
Params for convergence and material balance error checks.
OCP_DBL dVlim
Ideal max relative Verr (pore - fluid) change.
OCP_DBL dSlim
Ideal max Saturation change.
OCP_DBL dPlim
Ideal max Pressure change.
OCP_DBL dNlim
Ideal max relative Ni (moles of components) change.
Params for choosing time stepsize in time marching.
OCP_DBL cutFacNR
Factor by which timestep is cut after convergence failure.
OCP_DBL timeMax
Max time step during running.
OCP_DBL timeInit
Max init step length of next timestep.
OCP_DBL timeMin
Min time step during running.
OCP_DBL minChopFac
Min choppable timestep.
OCP_DBL maxIncreFac
Max timestep increase factor.
USI printLevel
Decide the depth for printfing.
OCP_DBL timeMax
Maximum time step during running.
OCP_DBL timeMin
Minmum time step during running.
OCP_DBL timeInit
Maximum Init step length of next timestep.
void ApplyControl(const USI &i, const Reservoir &rs)
Apply control for time step i.
void SetupFastControl(const USI &argc, const char *optset[])
Setup fast Control.
void CalNextTstepIMPEC(const Reservoir &reservoir)
Calculate the next time step according to max change of some variables.
void InputParam(const ParamControl &CtrlParam)
Input parameters for control.
void UpdateIters()
Update the number of iterations.
void ResetIterNRLS()
Reset the number of iterations.
void InitTime(const USI &i)
Initialize time step i.
vector< OCP_DBL > criticalTime
string method
Decide which method to use to discrete the fluid equations.
string dir
Current work directory.
string linearSolve
Fasp file.
vector< TuningPair > tuning_T
Tuning set.