OpenCAEPoro  v0.5.0
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 
111  if (vbuf.size() > 1) linearSolve = vbuf[1];
112 
113  cout << "\n---------------------" << endl
114  << "METHOD"
115  << "\n---------------------" << endl;
116  cout << " " << method << " " << linearSolve << endl;
117 }
118 
120 void ParamControl::InputTUNING(ifstream& ifs)
121 {
122  assert(criticalTime.size() >= 1);
123 
124  TUNING tmp(tuning);
125  USI d = criticalTime.size() - 1;
126  USI row = 0;
127  vector<string> vbuf;
128 
129  while (ReadLine(ifs, vbuf)) {
130  DealDefault(vbuf);
131  OCP_INT len = vbuf.size();
132 
133  for (OCP_INT i = 0; i < len - 1; i++) {
134  tmp[row][i] = stod(vbuf[i]);
135  }
136  if (vbuf[len - 1] != "/") {
137  tmp[row][len - 1] = stod(vbuf[len - 1]);
138  } else {
139  row++;
140  }
141  if (row == 3) break;
142  }
143 
144  tuning_T.push_back(TuningPair(d, tmp));
145  DisplayTuning();
146 }
147 
150 {
151  cout << "\n---------------------" << endl
152  << "TUNING"
153  << "\n---------------------" << endl;
154  for (auto v : tuning_T) {
155  cout << v.d << endl;
156  for (auto v1 : v.Tuning) {
157  for (auto v2 : v1) {
158  cout << v2 << " ";
159  }
160  cout << "/ " << endl;
161  }
162  }
163 }
164 
165 /*----------------------------------------------------------------------------*/
166 /* Brief Change History of This File */
167 /*----------------------------------------------------------------------------*/
168 /* Author Date Actions */
169 /*----------------------------------------------------------------------------*/
170 /* Shizhe Li Oct/01/2021 Create file */
171 /* Chensong Zhang Oct/15/2021 Format file */
172 /* Chensong Zhang Jan/08/2022 Update Doxygen */
173 /*----------------------------------------------------------------------------*/
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:23
int OCP_INT
Long integer.
Definition: OCPConst.hpp:26
ParamControl class declaration.
vector< vector< OCP_DBL > > TUNING
void DealDefault(vector< string > &result)
Definition: UtilInput.cpp:50
OCP_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
Discretization method for fluid equations.
void InputTUNING(ifstream &ifs)
Input the Keyword: TUNING.
void DisplayTuning() const
Display the Tuning.
string dir
Current work directory.
TUNING tuning
Tuning.
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.