OpenCAEPoro  v0.5.0
A simulator for multicomponent porous media flow
Solver.cpp
Go to the documentation of this file.
1 
12 // OpenCAEPoro header files
13 #include "Solver.hpp"
14 
15 void Solver::Setup(Reservoir& rs, const OCPControl& ctrl)
16 {
17  OCPModel = ctrl.GetModel();
18  switch (OCPModel) {
19  case ISOTHERMALMODEL:
20  SetupIsoT(rs, ctrl);
21  break;
22  case THERMALMODEL:
23  SetupT(rs, ctrl);
24  break;
25  default:
26  OCP_ABORT("Wrong model type specified!");
27  break;
28  }
29 }
30 
31 void Solver::SetupIsoT(Reservoir& rs, const OCPControl& ctrl)
32 {
33  // Setup static infomation for reservoir
34  rs.SetupIsoT();
35  IsoTSolver.SetupMethod(rs, ctrl);
36 }
37 
38 void Solver::SetupT(Reservoir& rs, const OCPControl& ctrl)
39 {
40  rs.SetupT();
41  TSolver.SetupMethod(rs, ctrl);
42 }
43 
46 {
47  switch (OCPModel) {
48  case ISOTHERMALMODEL:
49  IsoTSolver.InitReservoir(rs);
50  break;
51  case THERMALMODEL:
52  TSolver.InitReservoir(rs);
53  break;
54  default:
55  OCP_ABORT("Wrong model type specified!");
56  break;
57  }
58 }
59 
62 {
63  GetWallTime timer;
64  timer.Start();
65  output.PrintInfoSched(rs, ctrl, timer.Stop());
66  USI numTSteps = ctrl.GetNumTSteps();
67  for (USI d = 0; d < numTSteps - 1; d++) {
68  rs.ApplyControl(d);
69  ctrl.ApplyControl(d, rs);
70  while (!ctrl.IsCriticalTime(d + 1)) {
71  GoOneStep(rs, ctrl);
72  output.SetVal(rs, ctrl);
73  if (ctrl.printLevel >= PRINT_ALL) {
74  // Print Summary and critical information at every time step
75  output.PrintInfo();
76  }
77  }
78  output.PrintInfoSched(rs, ctrl, timer.Stop());
79  // rs.allWells.ShowWellStatus(rs.bulk);
80  }
81  rs.OutInfoFinal();
82  ctrl.RecordTotalTime(timer.Stop() / 1000);
83 }
84 
86 void Solver::GoOneStep(Reservoir& rs, OCPControl& ctrl)
87 {
88 
89  if (ctrl.printLevel >= PRINT_SOME) {
90  cout << "### DEBUG: " << setprecision(3) << fixed << ctrl.GetCurTime()
91  << " Days";
92  cout << ", NR: " << ctrl.GetNRiterT() << ", LS: " << ctrl.GetLSiterT()
93  << ", Last dt: " << ctrl.last_dt << " Days" << endl;
94  }
95 
96  switch (OCPModel) {
97  case ISOTHERMALMODEL:
98  GoOneStepIsoT(rs, ctrl);
99  break;
100  case THERMALMODEL:
101  GoOneStepT(rs, ctrl);
102  break;
103  default:
104  OCP_ABORT("Wrong model type specified!");
105  break;
106  }
107 }
108 
109 void Solver::GoOneStepIsoT(Reservoir& rs, OCPControl& ctrl)
110 {
111  // Prepare for time marching
112  IsoTSolver.Prepare(rs, ctrl);
113 
114  // Time marching with adaptive time stepsize
115  while (OCP_TRUE) {
116  if (ctrl.GetCurDt() < MIN_TIME_CURSTEP)
117  OCP_ABORT("Time stepsize is too small!");
118  // Assemble linear system
119  IsoTSolver.AssembleMat(rs, ctrl);
120  // Solve linear system
121  IsoTSolver.SolveLinearSystem(rs, ctrl);
122  if (!IsoTSolver.UpdateProperty(rs, ctrl)) {
123  continue;
124  }
125  if (IsoTSolver.FinishNR(rs, ctrl)) break;
126  }
127 
128  // Finish current time step
129  IsoTSolver.FinishStep(rs, ctrl);
130 }
131 
132 void Solver::GoOneStepT(Reservoir& rs, OCPControl& ctrl)
133 {
134  // Prepare for time marching
135  TSolver.Prepare(rs, ctrl);
136 
137  // Time marching with adaptive time stepsize
138  while (OCP_TRUE) {
139  if (ctrl.GetCurDt() < MIN_TIME_CURSTEP)
140  OCP_ABORT("Time stepsize is too small!");
141  // Assemble linear system
142  TSolver.AssembleMat(rs, ctrl);
143  // Solve linear system
144  TSolver.SolveLinearSystem(rs, ctrl);
145  if (!TSolver.UpdateProperty(rs, ctrl)) {
146  ctrl.ResetIterNRLS();
147  continue;
148  }
149  if (TSolver.FinishNR(rs, ctrl)) break;
150  }
151 
152  // Finish current time step
153  TSolver.FinishStep(rs, ctrl);
154 }
155 
156 /*----------------------------------------------------------------------------*/
157 /* Brief Change History of This File */
158 /*----------------------------------------------------------------------------*/
159 /* Author Date Actions */
160 /*----------------------------------------------------------------------------*/
161 /* Shizhe Li Oct/21/2021 Create file */
162 /*----------------------------------------------------------------------------*/
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:23
const OCP_DBL MIN_TIME_CURSTEP
Minimal time stepsize of current step ???
Definition: OCPConst.hpp:46
Solver class declaration.
#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 SolveLinearSystem(Reservoir &rs, OCPControl &ctrl)
Solve the linear system in single problem.
void InitReservoir(Reservoir &rs) const
Initialize the Reservoir and prepare variables for some method.
OCP_BOOL UpdateProperty(Reservoir &rs, OCPControl &ctrl)
Update properties of fluid.
void SetupMethod(Reservoir &rs, const OCPControl &ctrl)
Setup the fluid solver.
void FinishStep(Reservoir &rs, OCPControl &ctrl)
Finish the current time step.
void Prepare(Reservoir &rs, OCPControl &ctrl)
Prepare for assembling Mat.
void AssembleMat(const Reservoir &rs, OCPControl &ctrl)
Assemble Mat.
OCP_BOOL FinishNR(Reservoir &rs, OCPControl &ctrl)
Finish the Newton-Raphson iteration.
All control parameters except for well controllers.
Definition: OCPControl.hpp:94
USI GetNumTSteps() const
Return number of TSTEPs.
Definition: OCPControl.hpp:127
void ApplyControl(const USI &i, const Reservoir &rs)
Apply control for time step i.
Definition: OCPControl.cpp:173
void RecordTotalTime(const OCP_DBL &t)
Record the total time of simulation.
Definition: OCPControl.hpp:172
OCP_BOOL IsCriticalTime(const USI &d)
Determine whether the critical time point has been reached.
Definition: OCPControl.hpp:175
OCP_DBL GetCurDt() const
Return current time step size.
Definition: OCPControl.hpp:133
USI GetLSiterT() const
Return the total number of linear iterations.
Definition: OCPControl.hpp:142
void ResetIterNRLS()
Reset the number of iterations.
Definition: OCPControl.cpp:234
OCP_DBL GetCurTime() const
Return the current time.
Definition: OCPControl.hpp:130
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
void SetupT()
Setup static information for reservoir with input params for Thermal model.
Definition: Reservoir.cpp:40
void ApplyControl(const USI &i)
Apply the control of ith critical time point.
Definition: Reservoir.cpp:48
void SetupIsoT()
Setup static information for reservoir with input params for Isothermal model.
Definition: Reservoir.cpp:28
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
void SolveLinearSystem(Reservoir &rs, OCPControl &ctrl)
Solve the linear system in single problem.
OCP_BOOL FinishNR(Reservoir &rs, OCPControl &ctrl)
Finish the Newton-Raphson iteration.
void FinishStep(Reservoir &rs, OCPControl &ctrl)
Finish the current time step.
OCP_BOOL UpdateProperty(Reservoir &rs, OCPControl &ctrl)
Update properties of fluid.