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 string::size_type pos = tmp.find_last_of(
'=');
57 if (pos == string::npos)
OCP_ABORT(
"Unknown Usage! See -h");
59 key = tmp.substr(0, pos);
60 value = tmp.substr(pos + 1, tmp.size() - pos);
67 }
else if (value ==
"FIMn") {
69 }
else if (value ==
"IMPEC") {
71 }
else if (value ==
"AIMc") {
74 OCP_ABORT(
"Wrong method param in command line!");
101 printLevel = MIN(MAX(stoi(value), PRINT_NONE), PRINT_ALL);
105 OCP_ABORT(
"Unknown Options: " + key +
" See -h");
112 if (argc >= 6 && OCP_FALSE) {
114 if (
string(optset[2]) ==
"FIM") {
116 }
else if (
string(optset[2]) ==
"FIMn") {
118 }
else if (
string(optset[2]) ==
"IMPEC") {
120 }
else if (
string(optset[2]) ==
"AIMc") {
123 OCP_ABORT(
"Wrong method param in command line!");
136 model = CtrlParam.
model;
137 workDir = CtrlParam.
dir;
138 if (CtrlParam.
method ==
"IMPEC") {
140 }
else if (CtrlParam.
method ==
"FIM") {
142 }
else if (CtrlParam.
method ==
"FIMn") {
144 }
else if (CtrlParam.
method ==
"AIMc") {
154 ctrlTimeSet.resize(t);
155 ctrlPreTimeSet.resize(t);
159 vector<USI> ctrlCriticalTime(n + 1);
160 for (
USI i = 0; i < n; i++) {
161 ctrlCriticalTime[i] = CtrlParam.
tuning_T[i].d;
163 ctrlCriticalTime.back() = t;
164 for (
USI i = 0; i < n; i++) {
165 for (
USI d = ctrlCriticalTime[i]; d < ctrlCriticalTime[i + 1]; d++) {
175 ctrlTime = ctrlTimeSet[i];
176 ctrlPreTime = ctrlPreTimeSet[i];
177 ctrlNR = ctrlNRSet[i];
178 end_time = criticalTime[i + 1];
179 wellChange = rs.
allWells.GetWellChange();
185 OCP_DBL dt = criticalTime[i + 1] - current_time;
186 if (dt <= 0)
OCP_ABORT(
"Non-positive time stepsize!");
188 static OCP_BOOL firstflag = OCP_TRUE;
189 if (wellChange || firstflag) {
190 current_dt = min(dt, ctrlTime.
timeInit);
191 firstflag = OCP_FALSE;
193 current_dt = min(dt, init_dt);
199 ctrlFast.ReadParam(argc, optset);
200 if (ctrlFast.activity) {
204 linearSolverFile =
"./csr.fasp";
209 linearSolverFile =
"./bsr.fasp";
212 OCP_ABORT(
"Wrong method specified from command line!");
215 USI n = ctrlTimeSet.size();
216 for (
USI i = 0; i < n; i++) {
217 ctrlTimeSet[i].timeInit = ctrlFast.
timeInit;
218 ctrlTimeSet[i].timeMax = ctrlFast.
timeMax;
219 ctrlTimeSet[i].timeMin = ctrlFast.
timeMin;
228 iterNR_total += iterNR;
229 iterLS_total += iterLS;
236 wastedIterNR += iterNR;
238 wastedIterLS += iterLS;
249 else if (s ==
"BulkT")
251 else if (s ==
"BulkNi")
253 else if (s ==
"BulkVe")
257 else if (s ==
"WellP")
260 OCP_ABORT(
"Check iterm not recognized!");
266 case BULK_NEGATIVE_PRESSURE:
267 case BULK_NEGATIVE_TEMPERATURE:
268 case BULK_NEGATIVE_COMPONENTS_MOLES:
269 case BULK_OUTRANGED_VOLUME_ERROR:
272 case BULK_OUTRANGED_CFL:
278 case WELL_NEGATIVE_PRESSURE:
281 case WELL_SWITCH_TO_BHPMODE:
292 void OCPControl::CalNextTimeStep(
Reservoir& rs, initializer_list<string> il)
294 last_dt = current_dt;
295 current_time += current_dt;
307 if (dPmax >
TINY) factor = min(factor, ctrlPreTime.
dPlim / dPmax);
308 }
else if (s ==
"dT") {
310 if (dTmax >
TINY) factor = min(factor, ctrlPreTime.
dTlim / dTmax);
311 }
else if (s ==
"dN") {
312 if (dNmax >
TINY) factor = min(factor, ctrlPreTime.
dNlim / dNmax);
313 }
else if (s ==
"dS") {
314 if (dSmax >
TINY) factor = min(factor, ctrlPreTime.
dSlim / dSmax);
315 }
else if (s ==
"eV") {
316 if (eVmax >
TINY) factor = min(factor, ctrlPreTime.
eVlim / eVmax);
317 }
else if (s ==
"iter") {
319 factor = min(factor, 2.0);
320 else if (iterNR > 10)
321 factor = min(factor, 0.5);
323 factor = min(factor, 1.5);
329 current_dt *= factor;
333 init_dt = current_dt;
335 const OCP_DBL dt = end_time - current_time;
336 if (current_dt > dt) current_dt = dt;
const OCP_DBL TINY
Small constant.
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.
unsigned int OCP_BOOL
OCP_BOOL in OCP.
OCPControl class declaration.
#define OCP_ABORT(msg)
Abort if critical error happens.
OCP_INT CheckP(const Bulk &myBulk)
Check if unreasonable well pressure or perforation pressure occurs.
OCP_DBL GeteVmax() const
Return eVmax.
OCP_INT CheckNi()
Check if negative Ni occurs.
OCP_INT CheckT() const
Check if negative T occurs.
OCP_DBL GetMaxCFL() const
Return maxCFL.
OCP_DBL GetdSmax() const
Return dSmax.
OCP_INT CheckP() const
Check if negative P occurs.
OCP_DBL GetdNmax() const
Return dNmax.
OCP_DBL GetdPmax() const
Return dPmax.
OCP_INT CheckVe(const OCP_DBL &Vlim) const
Check if relative volume error is outranged.
OCP_DBL GetdTmax() const
Return dTmax.
OCP_INT CheckCFL(const OCP_DBL &cflLim) const
Check if Cfl is outranged.
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 time step.
OCP_DBL NRdSmax
Maximum Saturation change in a Newton iteration.
OCP_DBL Verrmax
Maximum Verr (vol error b/w fluid and pore) in a Newton step.
OCP_DBL NRdPmin
Minimum Pressure change in a Newton iteration.
Params for convergence and material balance error checks.
OCP_DBL dSlim
Ideal max Saturation change.
OCP_DBL eVlim
Ideal max relative Verr (pore - fluid) change.
OCP_DBL dPlim
Ideal max Pressure change.
OCP_DBL dNlim
Ideal max relative Ni (moles of components) change.
OCP_DBL dTlim
Ideal max Temperature change.
Params for choosing time stepsize in time marching.
OCP_DBL cutFacNR
Factor by which time step is cut after convergence failure.
OCP_DBL timeMax
Max time step during running.
OCP_DBL timeInit
Max init step length of next time step.
OCP_DBL timeMin
Min time step during running.
OCP_DBL minChopFac
Min choppable factor.
OCP_DBL maxIncreFac
Max increase factor.
USI printLevel
Decide the depth for printing.
OCP_DBL timeMax
Maximum time step during running.
OCP_DBL timeMin
Minimum time step during running.
OCP_DBL timeInit
Maximum Init step length of next time step.
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 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
USI model
model: thermal or isothermal.
string method
Discretization method for fluid equations.
string dir
Current work directory.
string linearSolve
Fasp file.
vector< TuningPair > tuning_T
Tuning set.
Bulk bulk
Active grid info.
AllWells allWells
Wells class info.