OpenCAEPoro  v0.5.0
A simulator for multicomponent porous media flow
OCP.cpp
Go to the documentation of this file.
1 
12 #include "OCP.hpp"
13 
15 void OpenCAEPoro::ReadInputFile(const string& filename)
16 {
17  ParamRead rp;
18  rp.ReadInputFile(filename);
19  // Read parameters from input file
20  InputParam(rp);
21 }
22 
25 {
26  reservoir.InputParam(param);
27  control.InputParam(param.paramControl);
28  output.InputParam(param.paramOutput);
29 }
30 
32 void OpenCAEPoro::SetupSimulator(const USI& argc, const char* options[])
33 {
34  GetWallTime timer;
35  timer.Start();
36 
37  control.SetupFastControl(argc, options); // Read Fast control
38 
39  switch (control.GetModel()) {
40  case ISOTHERMALMODEL:
41  if (control.printLevel >= PRINT_MIN) {
42  cout << endl << "Dynamic simulation for isothermal models" << endl;
43  }
44  break;
45  case THERMALMODEL:
46  if (control.printLevel >= PRINT_MIN) {
47  cout << endl << "Dynamic simulation for thermal models" << endl;
48  }
49  break;
50  default:
51  OCP_ABORT("Wrong model type specified!");
52  }
53 
54  solver.Setup(reservoir, control); // Setup static info for solver
55 
56  output.Setup(reservoir, control); // Setup output for dynamic simulation
57 
58  double finalTime = timer.Stop() / 1000;
59  if (control.printLevel >= PRINT_MIN) {
60  cout << endl
61  << "Setup simulation done. Wall time : " << fixed << setprecision(3)
62  << finalTime << " Sec" << endl;
63  }
64 
65  control.RecordTotalTime(finalTime);
66 }
67 
70 {
71  GetWallTime timer;
72  timer.Start();
73 
74  solver.InitReservoir(reservoir);
75 
76  double finalTime = timer.Stop() / 1000;
77  if (control.printLevel >= PRINT_MIN) {
78  cout << endl
79  << "Initialization done. Wall time : " << fixed << setprecision(3)
80  << finalTime << " Sec" << endl;
81  }
82  control.RecordTotalTime(finalTime);
83  control.initTime = finalTime;
84 }
85 
88 {
89  switch (control.GetMethod()) {
90  case IMPEC:
91  if (control.printLevel >= PRINT_MIN) {
92  cout << "\nDynamic simulation with IMPEC\n" << endl;
93  }
94  break;
95  case FIM:
96  if (control.printLevel >= PRINT_MIN) {
97  cout << "\nDynamic simulation with FIM\n" << endl;
98  }
99  break;
100  case FIMn:
101  if (control.printLevel >= PRINT_MIN) {
102  cout << "\nDynamic simulation with FIMn\n" << endl;
103  }
104  break;
105  case AIMc:
106  if (control.printLevel >= PRINT_MIN) {
107  cout << "\nDynamic simulation with AIMc\n" << endl;
108  }
109  break;
110  default:
111  OCP_ABORT("Wrong method type is used!");
112  }
113 
114  solver.RunSimulation(reservoir, control, output);
115 }
116 
119 {
120  // find an appropriate size for printing times
121  int fixWidth =
122  MAX(log10(control.current_time), log10(MAX(control.totalSimTime, 1.0))) + 6;
123 
124  cout << "==================================================" << endl;
125 
126  // print numbers of steps
127  cout << "Final time: " << right << fixed << setprecision(3)
128  << setw(fixWidth) << control.current_time << " (Days)" << endl;
129  cout << " - Avg time step size ......." << setw(fixWidth)
130  << control.current_time / control.numTstep << " (" << control.numTstep
131  << " steps)" << endl;
132  cout << " - Avg Newton steps ........." << setw(fixWidth)
133  << static_cast<double>(control.iterNR_total) / control.numTstep << " ("
134  << control.iterNR_total << " succeeded + " << control.wastedIterNR
135  << " wasted)" << endl;
136  cout << " - Avg linear steps ........." << setw(fixWidth)
137  << static_cast<double>(control.iterLS_total) / control.iterNR_total << " ("
138  << control.iterLS_total << " succeeded + " << control.wastedIterLS
139  << " wasted)" << endl;
140 
141  // print time usages
142  cout << "Simulation time: " << setw(fixWidth) << control.totalSimTime
143  << " (Seconds)" << endl;
144  cout << " - % Initialization ........." << setw(fixWidth)
145  << 100.0 * control.initTime / control.totalSimTime << " (" << control.initTime
146  << "s)" << endl;
147  cout << " - % Assembling ............." << setw(fixWidth)
148  << 100.0 * control.totalAssembleMatTime / control.totalSimTime << " ("
149  << control.totalAssembleMatTime << "s)" << endl;
150  cout << " - % Linear solver .........." << setw(fixWidth)
151  << 100.0 * control.totalLStime / control.totalSimTime << " ("
152  << control.totalLStime << "s)" << endl;
153  cout << " - % Updating properties ...." << setw(fixWidth)
154  << 100.0 * control.totalUpdatePropertyTime / control.totalSimTime << " ("
155  << control.totalUpdatePropertyTime << "s)" << endl;
156  cout << " - % Scheduled output ......." << setw(fixWidth)
157  << 100.0 * output.outputTime / control.totalSimTime << " ("
158  << output.outputTime << "s)" << endl;
159 
160  cout << "==================================================" << endl;
161 
162  output.PrintInfo();
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 Dec/05/2021 Format file */
172 /*----------------------------------------------------------------------------*/
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:23
const USI FIMn
Solution method = FIM.
Definition: OCPConst.hpp:84
const USI FIM
Solution method = FIM.
Definition: OCPConst.hpp:82
const USI AIMc
Adaptive implicit -— Collins.
Definition: OCPConst.hpp:83
const USI IMPEC
Solution method = IMPEC.
Definition: OCPConst.hpp:81
Main header file for OpenCAEPoro simulator.
#define OCP_ABORT(msg)
Abort if critical error happens.
Definition: UtilError.hpp:47
Get elapsed wall-time in millisecond.
Definition: UtilTiming.hpp:32
__inline__ double Stop() const
Stop the timer and return duration from start() in ms.
Definition: UtilTiming.hpp:54
__inline__ void Start()
Start the timer.
Definition: UtilTiming.hpp:51
void SetupFastControl(const USI &argc, const char *optset[])
Setup fast Control.
Definition: OCPControl.cpp:197
void RecordTotalTime(const OCP_DBL &t)
Record the total time of simulation.
Definition: OCPControl.hpp:172
void InputParam(const ParamControl &CtrlParam)
Input parameters for control.
Definition: OCPControl.cpp:134
USI GetMethod() const
Return type of the solution method.
Definition: OCPControl.hpp:124
USI GetModel() const
Get model.
Definition: OCPControl.hpp:112
void InputParam(ParamRead &param)
Read input parameters to an internal structure.
Definition: OCP.cpp:24
void RunSimulation()
Run dynamic simulation.
Definition: OCP.cpp:87
void OutputResults() const
Output necessary information for post-processing.
Definition: OCP.cpp:118
void InitReservoir()
Initialize or get initial status of reservoir.
Definition: OCP.cpp:69
void SetupSimulator(const USI &argc, const char *options[])
Setup reservoir based on an internal structure.
Definition: OCP.cpp:32
void ReadInputFile(const string &filename)
Read Param from an input file.
Definition: OCP.cpp:15
Pre-processing unit for OpenCAEPoro for reading params from input files.
Definition: ParamRead.hpp:33
ParamOutput paramOutput
Read the output params.
Definition: ParamRead.hpp:45
void ReadInputFile(const string &file)
General interface for reading input data.
Definition: ParamRead.cpp:39
ParamControl paramControl
Read the control params.
Definition: ParamRead.hpp:44
void InputParam(ParamRead &param)
Definition: Reservoir.cpp:18
void Setup(Reservoir &rs, const OCPControl &ctrl)
Setup Solver.
Definition: Solver.cpp:15
void RunSimulation(Reservoir &rs, OCPControl &ctrl, OCPOutput &output)
Start simulation.
Definition: Solver.cpp:61
void InitReservoir(Reservoir &rs) const
Initialize the reservoir.
Definition: Solver.cpp:45