OpenCAEPoro  0.2.0 Sep/22/2022
A simulator for multicomponent porous media flow
ParamControl.cpp
Go to the documentation of this file.
1 
12 #include "ParamControl.hpp"
13 
15 void ParamControl::Init(string& indir)
16 {
17  dir = indir;
18  InitMethod();
19  InitTime();
20  InitTuning();
21 }
22 
25 {
26  method = "IMPEC";
27  linearSolve = "./csr.fasp";
28 }
29 
32 {
33  tuning.resize(3);
34 
35  // Timestepping controls, * means this param is available
36  // Limits: timestep and change factor.
37  tuning[0].resize(10);
38  tuning[0][0] = 1.0; //* Maximum initial time stepsize of next timestep
39  tuning[0][1] = 365.0; //* Maximum length of timesteps after the next
40  tuning[0][2] = 0.1; //* Minimum length of all timesteps
41  tuning[0][3] = 3.0; //* Maximum time stepsize increase factor
42  tuning[0][4] = 0.15; //* Minimum choppable timestep
43  tuning[0][5] = 0.3; //* Factor by which timestep is cut after convergence failure
44  tuning[0][6] = 0.1; // ???
45  tuning[0][7] = 1.25; // Maximum increase factor after a convergence failure
46  tuning[0][8] = (method == "IMPEC") ? 0.2 : 1E20; // ???
47  tuning[0][9] = -1; // Maximum next time stepsize following a well modification
48 
49  // Timestepping controls, * means this param is available
50  // Prediction: an ideal maximum change of variables at next time step.
51  // So they're used to calculate change factor of time step by predicting linearly.
52  tuning[1].resize(13);
53  //* dPlim: ideal maximum Pressure change at next time step.
54  tuning[1][0] = (method == "IMPEC") ? 200.0 : 300.0;
55  //* dSlim: ideal maximum Saturation change at next time step.
56  tuning[1][1] = (method == "IMPEC") ? 0.2 : 0.2;
57  //* dNlim: ideal maximum relative Ni(moles of components) change at next time step.
58  tuning[1][2] = 0.3; // Target material balance error
59  //* dVerrlim: ideal maximum relative Verr(error between fluid and pore) change at
60  // next time step.
61  tuning[1][3] = (method == "IMPEC") ? 1E-3 : 1E-3;
62 
63  tuning[1][4] = 10.0; // Maximum time truncation error
64  // Maximum non-linear convergence error
65  tuning[1][5] = (method == "IMPEC") ? 0.75 : 0.01;
66  tuning[1][6] = 1E-6; // Maximum material balance error
67  // Maximum linear convergence error
68  tuning[1][7] = (method == "IMPEC") ? 1E-4 : 1E-3;
69  tuning[1][8] = 1E-3; // Maximum well flow rate convergence error
70  tuning[1][9] = 0.025; // Target Fluid-in-place error for LGR runs
71  tuning[1][10] = -1; // Target surfactant change (Surfactant Model only)
72  tuning[1][11] = 0.01; // Threshold for damping in ion exchange calc. (Multi-Comp.
73  // Brine Model only)
74  tuning[1][12] = 1; // Weighting factor for active tracer updates
75 
76  // Nonlinear Solver controls, * means this param is available
77  tuning[2].resize(10);
78  //* Maximum number of Newton iterations in a timestep
79  tuning[2][0] = (method == "IMPEC") ? 1 : 10;
80  //* Maximum non-linear convergence error
81  tuning[2][1] = 1e-3;
82  //* Maximum Pressure change in a Newton iteration
83  tuning[2][2] = 200.0;
84  //* Maximum Saturation change in a Newton iteration
85  tuning[2][3] = 0.2;
86  //* Minimum Pressure change in a Newton iteration
87  tuning[2][4] = 1;
88  //* Minimum Saturation change in a Newton iteration
89  tuning[2][5] = 0.01;
90  //* Maximum Verr(error between fluid and pore) change in a Newton iteration
91  tuning[2][6] = 0.01;
92 
93  tuning[2][7] = 1E6; // Maximum saturation change at last Newton iteration
94  // Target maximum pressure change in a timestep
95  tuning[2][8] = (method == "IMPEC") ? 100 : 1E6;
96  tuning[2][9] = -1; // Maximum tolerable pressure change in a timestep
97 }
98 
100 void ParamControl::InputMETHOD(ifstream& ifs)
101 {
102  vector<string> vbuf;
103  ReadLine(ifs, vbuf);
104  if (vbuf[0] == "/") return;
105 
106  if (vbuf[0] == "FIM") {
107  method = "FIM";
108  linearSolve = "./bsr.fasp";
109  }
110  if (vbuf[0] == "AIMt") {
111  method = "AIMt";
112  }
113 
114  if (vbuf.size() > 1) linearSolve = vbuf[1];
115 
116 #ifdef DEBUG
117  cout << "METHOD" << endl;
118  cout << method << " " << linearSolve << endl;
119 #endif // DEBUG
120 }
121 
123 void ParamControl::InputTUNING(ifstream& ifs)
124 {
125  assert(criticalTime.size() >= 1);
126 
127  TUNING tmp(tuning);
128  USI d = criticalTime.size() - 1;
129  USI row = 0;
130  vector<string> vbuf;
131 
132  while (ReadLine(ifs, vbuf)) {
133  DealDefault(vbuf);
134  OCP_INT len = vbuf.size();
135 
136  for (OCP_INT i = 0; i < len - 1; i++) {
137  tmp[row][i] = stod(vbuf[i]);
138  }
139  if (vbuf[len - 1] != "/") {
140  tmp[row][len - 1] = stod(vbuf[len - 1]);
141  } else {
142  row++;
143  }
144  if (row == 3) break;
145  }
146 
147  tuning_T.push_back(TuningPair(d, tmp));
148  DisplayTuning();
149 }
150 
153 {
154  cout << "---------------------\n";
155  cout << "TUNING" << endl;
156  cout << "---------------------\n";
157  for (auto v : tuning_T) {
158  cout << v.d << endl;
159  for (auto v1 : v.Tuning) {
160  for (auto v2 : v1) {
161  cout << v2 << " ";
162  }
163  cout << "/ " << endl;
164  }
165  }
166 }
167 
168 /*----------------------------------------------------------------------------*/
169 /* Brief Change History of This File */
170 /*----------------------------------------------------------------------------*/
171 /* Author Date Actions */
172 /*----------------------------------------------------------------------------*/
173 /* Shizhe Li Oct/01/2021 Create file */
174 /* Chensong Zhang Oct/15/2021 Format file */
175 /* Chensong Zhang Jan/08/2022 Update Doxygen */
176 /*----------------------------------------------------------------------------*/
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:22
int OCP_INT
Long integer.
Definition: OCPConst.hpp:25
ParamControl class declaration.
vector< vector< OCP_DBL > > TUNING
void DealDefault(vector< string > &result)
Definition: UtilInput.cpp:50
bool ReadLine(ifstream &ifs, vector< string > &result)
Definition: UtilInput.cpp:14
void InitTime()
Init the critical time.
vector< OCP_DBL > criticalTime
void InitTuning()
Determine the default Tuning.
void Init(string &indir)
Assign default values to parameters.
string method
Decide which method to use to discrete the fluid equations.
void InputTUNING(ifstream &ifs)
Input the Keyword: TUNING.
void DisplayTuning() const
Display the Tuning.
string dir
Current work directory.
void InitMethod()
Determine the default discrete method.
string linearSolve
Fasp file.
void InputMETHOD(ifstream &ifs)
Input the Keyword: METHOD.
vector< TuningPair > tuning_T
Tuning set.
TODO: Add Doxygen.