OpenCAEPoro  0.2.0 Sep/22/2022
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) { SetupMethod(rs, ctrl); }
16 
19 {
20  // Initialize the fluid part
21  IsoTSolver.InitReservoir(rs);
22 }
23 
26 {
27  GetWallTime timer;
28  timer.Start();
29  output.PrintInfoSched(rs, ctrl, timer.Stop());
30  USI numTSteps = ctrl.GetNumTSteps();
31  for (USI d = 0; d < numTSteps - 1; d++)
32  {
33  rs.ApplyControl(d);
34  ctrl.ApplyControl(d, rs);
35  while (!ctrl.IsCriticalTime(d + 1))
36  {
37  GoOneStep(rs, ctrl);
38  output.SetVal(rs, ctrl);
39  }
40  output.PrintInfoSched(rs, ctrl, timer.Stop());
41  if (ctrl.printLevel > 2) {
42  // Print Summary and critical information at every TSTEP
43  output.PrintInfo();
44  }
45  // rs.allWells.ShowWellStatus(rs.bulk);
46  }
47 
48  if (rs.bulk.GetMixMode() == EOS_PVTW)
49  {
50  cout << "SSMSTA: " << setw(12) << rs.bulk.GetSSMSTAiters()
51  << setw(15) << rs.bulk.GetSSMSTAiters() * 1.0 / rs.bulk.GetSSMSTAcounts() << endl;
52  cout << "NRSTA: " << setw(12) << rs.bulk.GetNRSTAiters()
53  << setw(15) << rs.bulk.GetNRSTAiters() * 1.0 / rs.bulk.GetNRSTAcounts() << endl;
54  cout << "SSMSP: " << setw(12) << rs.bulk.GetSSMSPiters()
55  << setw(15) << rs.bulk.GetSSMSPiters() * 1.0 / rs.bulk.GetSSMSPcounts() << endl;
56  cout << "NRSP: " << setw(12) << rs.bulk.GetNRSPiters()
57  << setw(15) << rs.bulk.GetNRSPiters() * 1.0 / rs.bulk.GetNRSPcounts() << endl;
58  cout << "NRRR: " << setw(12) << rs.bulk.GetRRiters()
59  << setw(15) << rs.bulk.GetRRiters() * 1.0 / rs.bulk.GetRRcounts() << endl;
60  }
61  ctrl.RecordTotalTime(timer.Stop() / 1000);
62 }
63 
65 void Solver::GoOneStep(Reservoir &rs, OCPControl &ctrl)
66 {
67  OCP_DBL &dt = ctrl.GetCurDt();
68 
69  if (ctrl.printLevel > 0) {
70  cout << "### DEBUG: " << setprecision(3) << fixed << ctrl.GetCurTime() << " Days";
71  cout << " NR: " << ctrl.GetNRiterT() << " LS: " << ctrl.GetLSiterT() << " ";
72  cout << "Last dt " << ctrl.last_dt << " Days" << endl;
73  }
74 
75  // Prepare for time marching
76  Prepare(rs, dt);
77 
78  // Time marching with adaptive time stepsize
79  while (true)
80  {
81  if (dt < MIN_TIME_CURSTEP)
82  OCP_ABORT("Time stepsize is too small!");
83  AssembleSolve(rs, ctrl);
84  if (!UpdateProperty(rs, ctrl))
85  {
86  ctrl.ResetIterNRLS();
87  continue;
88  }
89  if (FinishNR(rs, ctrl))
90  break;
91  }
92 
93  // Finish current time step
94  FinishStep(rs, ctrl);
95 }
96 
98 void Solver::Prepare(Reservoir &rs, OCP_DBL &dt)
99 {
100  // Prepare for the fluid part
101  IsoTSolver.Prepare(rs, dt);
102 }
103 
104 void Solver::SetupMethod(Reservoir &rs, const OCPControl &ctrl)
105 {
106  IsoTSolver.SetupMethod(rs, ctrl);
107 }
108 
110 void Solver::AssembleSolve(Reservoir &rs, OCPControl &ctrl)
111 {
112  // Assemble linear system
113  IsoTSolver.AssembleMat(rs, ctrl.current_dt);
114  // Solve linear system
115  IsoTSolver.SolveLinearSystem(rs, ctrl);
116 }
117 
119 bool Solver::UpdateProperty(Reservoir &rs, OCPControl &ctrl)
120 {
121  // Update for the fluid part
122  return IsoTSolver.UpdateProperty(rs, ctrl);
123 }
124 
126 bool Solver::FinishNR(Reservoir &rs, OCPControl &ctrl)
127 {
128  // Clean up the fluid part
129  return IsoTSolver.FinishNR(rs, ctrl);
130 }
131 
133 void Solver::FinishStep(Reservoir &rs, OCPControl &ctrl)
134 {
135  // Clean up the fluid part
136  IsoTSolver.FinishStep(rs, ctrl);
137 }
138 
139 /*----------------------------------------------------------------------------*/
140 /* Brief Change History of This File */
141 /*----------------------------------------------------------------------------*/
142 /* Author Date Actions */
143 /*----------------------------------------------------------------------------*/
144 /* Shizhe Li Oct/21/2021 Create file */
145 /*----------------------------------------------------------------------------*/
const USI EOS_PVTW
Mixture model = equation-of-state.
Definition: OCPConst.hpp:89
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:22
double OCP_DBL
Double precision.
Definition: OCPConst.hpp:26
const OCP_DBL MIN_TIME_CURSTEP
Minimal time stepsize of current step ???
Definition: OCPConst.hpp:42
Solver class declaration.
#define OCP_ABORT(msg)
Abort if critical error happens.
Definition: UtilError.hpp:47
USI GetMixMode() const
Return the mixture mode.
Definition: Bulk.cpp:2270
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.
void SetupMethod(Reservoir &rs, const OCPControl &ctrl)
Setup the fluid solver.
bool UpdateProperty(Reservoir &rs, OCPControl &ctrl)
Update properties of fluid.
bool FinishNR(Reservoir &rs, OCPControl &ctrl)
Finish the Newton-Raphson iteration.
void FinishStep(Reservoir &rs, OCPControl &ctrl)
Finish the current time step.
void AssembleMat(const Reservoir &rs, const OCP_DBL &dt)
Assemble Mat.
void Prepare(Reservoir &rs, OCP_DBL &dt)
Prepare for assembling Mat.
All control parameters except for well controlers.
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:191
OCP_DBL & GetCurDt()
Return current dt.
Definition: OCPControl.hpp:133
void RecordTotalTime(const OCP_DBL &t)
Record the total time of simulation.
Definition: OCPControl.hpp:166
bool IsCriticalTime(const USI &d)
Determine whether the critical time point has been reached.
Definition: OCPControl.hpp:173
USI GetLSiterT() const
Return the total number of linear iterations.
Definition: OCPControl.hpp:142
void ResetIterNRLS()
Reset the number of iterations.
Definition: OCPControl.cpp:333
OCP_DBL GetCurTime() const
Return the current time.
Definition: OCPControl.hpp:130
USI GetNRiterT() const
Return the total nubmer of Newton iterations.
Definition: OCPControl.hpp:148
The OCPOutput class manages different kinds of ways to output information.
Definition: OCPOutput.hpp:202
void ApplyControl(const USI &i)
Apply the control of ith critical time point.
Definition: Reservoir.cpp:38
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:25
void InitReservoir(Reservoir &rs) const
Initialize the reservoir.
Definition: Solver.cpp:18