OpenCAEPoro  0.2.0 Sep/22/2022
A simulator for multicomponent porous media flow
OCPControl.hpp
Go to the documentation of this file.
1 
12 #ifndef __OCP_CONTROL_HEADER__
13 #define __OCP_CONTROL_HEADER__
14 
15 // Standard header files
16 #include <vector>
17 
18 // OpenCAEPoro header files
19 #include "OCPConst.hpp"
20 #include "ParamControl.hpp"
21 #include "Reservoir.hpp"
22 
23 using namespace std;
24 
27 {
28 public:
29  ControlTime() = default;
30  ControlTime(const vector<OCP_DBL>& src);
31 
32 public:
33  // Note: Most commonly used params are the first three
40 };
41 
44 {
45 public:
46  ControlPreTime() = default;
47  ControlPreTime(const vector<OCP_DBL>& src);
48 
49 public:
50  // Limits for changes at next time step
55 };
56 
58 class ControlNR
59 {
60 public:
61  ControlNR() = default;
62  ControlNR(const vector<OCP_DBL>& src);
63 
64 public:
65  // Note: Important for convergence of solution methods
74 };
75 
78 {
79 public:
80  void ReadParam(const USI& argc, const char* optset[]);
81 
82 public:
83  bool activity{false};
88  USI printLevel{0};
89 };
90 
92 // Note: Which solution method will be used is determined here!
94 {
95  friend class OpenCAEPoro;
96  friend class OCPOutput;
97  friend class DetailInfo;
98  friend class Reservoir;
99 
100  friend class OCP_FIM;
101  friend class OCP_FIMn;
102  friend class OCP_IMPEC;
103  friend class OCP_AIMc;
104  friend class OCP_AIMs;
105  friend class OCP_AIMt;
106  friend class OCP_FIM_IMPEC;
107  // temp
108  friend class Solver;
109 
110 public:
112  void InputParam(const ParamControl& CtrlParam);
113 
115  void ApplyControl(const USI& i, const Reservoir& rs);
116 
118  void InitTime(const USI& i);
119 
121  void SetupFastControl(const USI& argc, const char* optset[]);
122 
124  USI GetMethod() const { return method; }
125 
127  USI GetNumTSteps() const { return criticalTime.size(); }
128 
130  OCP_DBL GetCurTime() const { return current_time; }
131 
133  OCP_DBL& GetCurDt() { return current_dt; }
134 
136  OCP_DBL GetLastDt() const { return last_dt; }
137 
139  USI GetLSiter() const { return iterLS; }
140 
142  USI GetLSiterT() const { return iterLS_total; }
143 
145  USI GetNRiter() const { return iterNR; }
146 
148  USI GetNRiterT() const { return iterNR_total; }
149 
151  void UpdateIters();
152 
154  void UpdateIterLS(const USI& num) { iterLS += num; }
155 
157  void UpdateIterNR() { iterNR++; }
158 
160  void ResetIterNRLS();
161 
163  void UpdateTimeLS(const OCP_DBL& t) { totalLStime += t; }
164 
166  void RecordTotalTime(const OCP_DBL& t) { totalSimTime += t; }
167 
169  void CalNextTstepIMPEC(const Reservoir& reservoir);
170  void CalNextTstepFIM(const Reservoir& reservoir);
171 
173  bool IsCriticalTime(const USI& d)
174  {
175  return ((criticalTime[d] - current_time) < TINY);
176  }
177 
179  string GetWorkDir() const { return workDir; }
180 
182  string GetLsFile() const { return linearsolveFile; }
183 
184  // Set wellChange
185  void SetWellChange(const bool& flag) { wellChange = flag; }
186 
187 private:
188  USI method;
189  string workDir;
190  string linearsolveFile;
191 
192  vector<OCP_DBL> criticalTime;
193 
194  // Record time information
195  OCP_DBL current_dt;
196  OCP_DBL last_dt;
197  OCP_DBL current_time{0};
198  OCP_DBL end_time;
199  OCP_DBL totalSimTime{0};
200  OCP_DBL totalLStime{0};
201  OCP_DBL init_dt;
202 
203  // Record iteration information
204  USI numTstep{0};
205  USI iterLS{0};
206  USI iterLS_total{0};
207  USI iterNR{0};
208  USI iterNR_total{0};
209  USI wastedIterNR{0};
210  USI wastedIterLS{0};
211 
212  // Print level
213  USI printLevel{ 0 };
214 
215  // Includes time controler, error controler, and iteration controler, all of which
216  // could change at different critical time step.
217  ControlTime ctrlTime;
218  vector<ControlTime> ctrlTimeSet;
219  ControlPreTime ctrlPreTime;
220  vector<ControlPreTime> ctrlPreTimeSet;
221  ControlNR ctrlNR;
222  vector<ControlNR> ctrlNRSet;
224  FastControl ctrlFast;
225 
226  // Well
227  bool wellChange;
228 };
229 
230 #endif /* end if __OCP_Control_HEADER__ */
231 
232 /*----------------------------------------------------------------------------*/
233 /* Brief Change History of This File */
234 /*----------------------------------------------------------------------------*/
235 /* Author Date Actions */
236 /*----------------------------------------------------------------------------*/
237 /* Shizhe Li Oct/01/2021 Create file */
238 /* Chensong Zhang Oct/15/2021 Format file */
239 /* Chensong Zhang Jan/08/2022 Update Doxygen */
240 /*----------------------------------------------------------------------------*/
Definition of build-in datatypes and consts.
const OCP_DBL TINY
Small constant.
Definition: OCPConst.hpp:36
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:22
double OCP_DBL
Double precision.
Definition: OCPConst.hpp:26
ParamControl class declaration.
Reservoir class declaration.
Params for Newton iterations and linear iterations.
Definition: OCPControl.hpp:59
OCP_DBL NRtol
Maximum non-linear convergence error.
Definition: OCPControl.hpp:67
OCP_DBL NRdSmin
Minimum Saturation change in a Newton iteration.
Definition: OCPControl.hpp:71
OCP_DBL NRdPmax
Maximum Pressure change in a Newton iteration.
Definition: OCPControl.hpp:68
USI maxNRiter
Maximum number of Newton iterations in a timestep.
Definition: OCPControl.hpp:66
OCP_DBL NRdSmax
Maximum Saturation change in a Newton iteration.
Definition: OCPControl.hpp:69
OCP_DBL Verrmax
Definition: OCPControl.hpp:72
OCP_DBL NRdPmin
Minimum Pressure change in a Newton iteration.
Definition: OCPControl.hpp:70
Params for convergence and material balance error checks.
Definition: OCPControl.hpp:44
OCP_DBL dVlim
Ideal max relative Verr (pore - fluid) change.
Definition: OCPControl.hpp:54
OCP_DBL dSlim
Ideal max Saturation change.
Definition: OCPControl.hpp:52
OCP_DBL dPlim
Ideal max Pressure change.
Definition: OCPControl.hpp:51
OCP_DBL dNlim
Ideal max relative Ni (moles of components) change.
Definition: OCPControl.hpp:53
Params for choosing time stepsize in time marching.
Definition: OCPControl.hpp:27
OCP_DBL cutFacNR
Factor by which timestep is cut after convergence failure.
Definition: OCPControl.hpp:39
OCP_DBL timeMax
Max time step during running.
Definition: OCPControl.hpp:35
OCP_DBL timeInit
Max init step length of next timestep.
Definition: OCPControl.hpp:34
OCP_DBL timeMin
Min time step during running.
Definition: OCPControl.hpp:36
OCP_DBL minChopFac
Min choppable timestep.
Definition: OCPControl.hpp:38
OCP_DBL maxIncreFac
Max timestep increase factor.
Definition: OCPControl.hpp:37
Collect more detailed information of each time step.
Definition: OCPOutput.hpp:165
Store shortcut instructions from the command line.
Definition: OCPControl.hpp:78
USI method
IMPEC or FIM.
Definition: OCPControl.hpp:84
OCP_DBL timeMax
Maximum time step during running.
Definition: OCPControl.hpp:86
OCP_DBL timeMin
Minmum time step during running.
Definition: OCPControl.hpp:87
OCP_DBL timeInit
Maximum Init step length of next timestep.
Definition: OCPControl.hpp:85
All control parameters except for well controlers.
Definition: OCPControl.hpp:94
USI GetNumTSteps() const
Return number of TSTEPs.
Definition: OCPControl.hpp:127
OCP_DBL & GetCurDt()
Return current dt.
Definition: OCPControl.hpp:133
void RecordTotalTime(const OCP_DBL &t)
Record the total time of simulation.
Definition: OCPControl.hpp:166
bool IsCriticalTime(const USI &d)
Determine whether the critical time point has been reached.
Definition: OCPControl.hpp:173
string GetWorkDir() const
Return work dir name.
Definition: OCPControl.hpp:179
USI GetNRiter() const
Return the number of Newton iterations in one time step.
Definition: OCPControl.hpp:145
OCP_DBL GetLastDt() const
Return last dt.
Definition: OCPControl.hpp:136
void UpdateIterNR()
Update the number of Newton iterations.
Definition: OCPControl.hpp:157
USI GetLSiter() const
Return the number of linear iterations in one time step.
Definition: OCPControl.hpp:139
USI GetLSiterT() const
Return the total number of linear iterations.
Definition: OCPControl.hpp:142
string GetLsFile() const
Return linear solver file name.
Definition: OCPControl.hpp:182
void UpdateIterLS(const USI &num)
Update the number of linear iterations.
Definition: OCPControl.hpp:154
USI GetMethod() const
Return type of the solution method.
Definition: OCPControl.hpp:124
OCP_DBL GetCurTime() const
Return the current time.
Definition: OCPControl.hpp:130
USI GetNRiterT() const
Return the total nubmer of Newton iterations.
Definition: OCPControl.hpp:148
void UpdateTimeLS(const OCP_DBL &t)
Update time used for linear solver.
Definition: OCPControl.hpp:163
The OCPOutput class manages different kinds of ways to output information.
Definition: OCPOutput.hpp:202
perform AIM in space, that is, some grids will be implicit, others will be explicit at the same time ...
perform AIM in time, that is, local FIM will be performed after global IMPEC performs
OCP_FIM is FIM (Fully Implicit Method).
OCP_IMPEC is IMPEC (implict pressure explict saturation) method.
Top-level data structure for the OpenCAEPoro simulator.
Definition: OCP.hpp:27
Solver class for overall solution methods.
Definition: Solver.hpp:21