OpenCAEPoro  v0.5.0
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
56 };
57 
59 class ControlNR
60 {
61 public:
62  ControlNR() = default;
63  ControlNR(const vector<OCP_DBL>& src);
64 
65 public:
66  // 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  OCP_BOOL activity{OCP_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 Out4RPT;
98 
99  friend class IsoT_FIM;
100  friend class IsoT_FIMn;
101  friend class IsoT_IMPEC;
102  friend class IsoT_AIMc;
103  friend class T_FIM;
104  // temp
105  friend class Solver;
106 
107 public:
109  void InputParam(const ParamControl& CtrlParam);
110 
112  USI GetModel() const { return model; }
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() const { 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 RecordTimeLS(const OCP_DBL& t) { totalLStime += t; }
164 
166  void RecordTimeAssembleMat(const OCP_DBL& t) { totalAssembleMatTime += t; }
167 
169  void RecordTimeUpdateProperty(const OCP_DBL& t) { totalUpdatePropertyTime += t; }
170 
172  void RecordTotalTime(const OCP_DBL& t) { totalSimTime += t; }
173 
176  {
177  return ((criticalTime[d] - current_time) < TINY);
178  }
179 
181  string GetWorkDir() const { return workDir; }
182 
184  string GetLsFile() const { return linearSolverFile; }
185 
186  // Check order is important
187  OCP_BOOL Check(Reservoir& rs, initializer_list<string> il);
188 
189  // Calculate next time step
190  void CalNextTimeStep(Reservoir& rs, initializer_list<string> il);
191 
192 private:
193  USI model;
194  USI method;
195  string workDir;
196  string linearSolverFile;
197 
198  vector<OCP_DBL> criticalTime;
199 
200  // Record time information
201  OCP_DBL init_dt;
202  OCP_DBL current_dt;
203  OCP_DBL last_dt;
204  OCP_DBL current_time{0};
205  OCP_DBL end_time;
206 
207  OCP_DBL totalSimTime{0};
208  OCP_DBL initTime{0};
209  OCP_DBL totalUpdatePropertyTime{0};
210  OCP_DBL totalAssembleMatTime{0};
211  OCP_DBL totalLStime{0};
212 
213  // Record iteration information
214  USI numTstep{0};
215  USI iterLS{0};
216  USI iterLS_total{0};
217  USI iterNR{0};
218  USI iterNR_total{0};
219  USI wastedIterNR{0};
220  USI wastedIterLS{0};
221 
222  // Print level
223  USI printLevel{0};
224 
225  // Time, error, and iteration dynamic controllers, all of which could change at
226  // any critical time steps
227  ControlTime ctrlTime;
228  vector<ControlTime> ctrlTimeSet;
229  ControlPreTime ctrlPreTime;
230  vector<ControlPreTime> ctrlPreTimeSet;
231  ControlNR ctrlNR;
232  vector<ControlNR> ctrlNRSet;
233 
234  // Receive directly from command lines, which will overwrite others
235  FastControl ctrlFast;
236 
237  // Well
238  OCP_BOOL wellChange;
239 };
240 
241 #endif /* end if __OCP_Control_HEADER__ */
242 
243 /*----------------------------------------------------------------------------*/
244 /* Brief Change History of This File */
245 /*----------------------------------------------------------------------------*/
246 /* Author Date Actions */
247 /*----------------------------------------------------------------------------*/
248 /* Shizhe Li Oct/01/2021 Create file */
249 /* Chensong Zhang Oct/15/2021 Format file */
250 /* Chensong Zhang Jan/08/2022 Update Doxygen */
251 /*----------------------------------------------------------------------------*/
Definition of build-in datatypes and consts.
const OCP_DBL TINY
Small constant.
Definition: OCPConst.hpp:38
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:23
double OCP_DBL
Double precision.
Definition: OCPConst.hpp:27
unsigned int OCP_BOOL
OCP_BOOL in OCP.
Definition: OCPConst.hpp:29
ParamControl class declaration.
Reservoir class declaration.
Params for Newton iterations and linear iterations.
Definition: OCPControl.hpp:60
OCP_DBL NRtol
Maximum non-linear convergence error.
Definition: OCPControl.hpp:68
OCP_DBL NRdSmin
Minimum Saturation change in a Newton iteration.
Definition: OCPControl.hpp:72
OCP_DBL NRdPmax
Maximum Pressure change in a Newton iteration.
Definition: OCPControl.hpp:69
USI maxNRiter
Maximum number of Newton iterations in a time step.
Definition: OCPControl.hpp:67
OCP_DBL NRdSmax
Maximum Saturation change in a Newton iteration.
Definition: OCPControl.hpp:70
OCP_DBL Verrmax
Maximum Verr (vol error b/w fluid and pore) in a Newton step.
Definition: OCPControl.hpp:73
OCP_DBL NRdPmin
Minimum Pressure change in a Newton iteration.
Definition: OCPControl.hpp:71
Params for convergence and material balance error checks.
Definition: OCPControl.hpp:44
OCP_DBL dSlim
Ideal max Saturation change.
Definition: OCPControl.hpp:53
OCP_DBL eVlim
Ideal max relative Verr (pore - fluid) change.
Definition: OCPControl.hpp:55
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:54
OCP_DBL dTlim
Ideal max Temperature change.
Definition: OCPControl.hpp:52
Params for choosing time stepsize in time marching.
Definition: OCPControl.hpp:27
OCP_DBL cutFacNR
Factor by which time step 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 time step.
Definition: OCPControl.hpp:34
OCP_DBL timeMin
Min time step during running.
Definition: OCPControl.hpp:36
OCP_DBL minChopFac
Min choppable factor.
Definition: OCPControl.hpp:38
OCP_DBL maxIncreFac
Max increase factor.
Definition: OCPControl.hpp:37
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
Minimum time step during running.
Definition: OCPControl.hpp:87
OCP_DBL timeInit
Maximum Init step length of next time step.
Definition: OCPControl.hpp:85
IsoT_FIM is FIM (Fully Implicit Method).
IsoT_IMPEC is IMPEC (implicit pressure explict saturation) method.
All control parameters except for well controllers.
Definition: OCPControl.hpp:94
USI GetNumTSteps() const
Return number of TSTEPs.
Definition: OCPControl.hpp:127
void RecordTotalTime(const OCP_DBL &t)
Record the total time of simulation.
Definition: OCPControl.hpp:172
string GetWorkDir() const
Return work dir name.
Definition: OCPControl.hpp:181
OCP_BOOL IsCriticalTime(const USI &d)
Determine whether the critical time point has been reached.
Definition: OCPControl.hpp:175
USI GetNRiter() const
Return the number of Newton iterations in one time step.
Definition: OCPControl.hpp:145
OCP_DBL GetLastDt() const
Return last time step size.
Definition: OCPControl.hpp:136
OCP_DBL GetCurDt() const
Return current time step size.
Definition: OCPControl.hpp:133
void UpdateIterNR()
Update the number of Newton iterations.
Definition: OCPControl.hpp:157
void RecordTimeUpdateProperty(const OCP_DBL &t)
Record time used for update property.
Definition: OCPControl.hpp:169
USI GetLSiter() const
Return the number of linear iterations in one time step.
Definition: OCPControl.hpp:139
void RecordTimeAssembleMat(const OCP_DBL &t)
Record time used for assemble matrix.
Definition: OCPControl.hpp:166
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:184
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
void RecordTimeLS(const OCP_DBL &t)
Record time used for linear solver.
Definition: OCPControl.hpp:163
USI GetNRiterT() const
Return the total number of Newton iterations.
Definition: OCPControl.hpp:148
USI GetModel() const
Get model.
Definition: OCPControl.hpp:112
The OCPOutput class manages different kinds of ways to output information.
Definition: OCPOutput.hpp:436
Top-level data structure for the OpenCAEPoro simulator.
Definition: OCP.hpp:27
Collect more detailed information of each time step.
Definition: OCPOutput.hpp:211
Solver class for overall solution methods.
Definition: Solver.hpp:22