OpenCAEPoro  0.2.0 Sep/22/2022
A simulator for multicomponent porous media flow
LinearSystem.hpp
Go to the documentation of this file.
1 
12 #ifndef __LINEARSYSTEM_HEADER__
13 #define __LINEARSYSTEM_HEADER__
14 
15 // Standard header files
16 #include <cmath>
17 #include <fstream>
18 #include <iostream>
19 #include <string>
20 
21 // OpenCAEPoro header files
22 #include "FaspSolver.hpp"
23 #include "OCPConst.hpp"
24 
25 using namespace std;
26 
28 // Note: The matrix is stored in the form of row-segmented CSRx internaly, whose
29 // sparsity pattern is almost the same as neighbor in BulkConn.
31 {
32  friend class OpenCAEPoro;
33  friend class BulkConn;
34  friend class Well;
35 
36 public:
38  void AllocateRowMem(const OCP_USI& dimMax, const USI& nb);
40  void AllocateColMem();
42  void AllocateColMem(const OCP_USI& colnum);
44  void EnlargeRowCap(const OCP_USI& row, const USI& n) { rowCapacity[row] += n; }
46  void AssembleRhs(const vector<OCP_DBL>& rhs);
48  void ClearData();
49 
50 
52  vector<OCP_DBL>& GetSolution() { return u; }
54  void CheckEquation() const;
56  void CheckSolution() const;
58  void OutputLinearSystem(const string& fileA, const string& fileb) const;
60  void OutputSolution(const string& filename) const;
61 
62  // Linear Solver
64  void SetupLinearSolver(const USI& i, const string& dir, const string& file);
66  void AssembleMatLinearSolver() { LS->AssembleMat(colId, val, dim, blockDim, b, u); }
68  OCP_INT Solve() { return LS->Solve(); }
69 
71  USI GetNumIters() { return LS->GetNumIters(); }
72 
73 private:
74  // Used for internal mat structure.
75  USI blockDim;
76  USI blockSize;
77 
78  // maxDim: fixed and used to allocate memory at the beginning of simulation;
79  // dim: might change during simulation but always less than maxDim.
80  OCP_USI maxDim;
81  OCP_USI dim;
82 
83  // The following values are stored for each row. Among them, rowCapacity is the max
84  // possible capacity of each row of the matrix. It is just a little bigger than the
85  // actual size and is used to allocate memory at the beginning of simulation.
86  // diagVal is an auxiliary variable used to help setup entries in diagnal line and
87  // it will only be used when matrix is assembled.
88  vector<USI> rowCapacity;
89  vector<vector<OCP_USI>> colId;
90  vector<USI> diagPtr;
91  vector<vector<OCP_DBL>> val;
92  vector<OCP_DBL> diagVal;
93  vector<OCP_DBL> b;
94  vector<OCP_DBL> u;
95 
96  string solveDir;
97 
98  LinearSolver* LS;
99 };
100 
101 #endif /* end if __LINEARSOLVER_HEADER__ */
102 
103 /*----------------------------------------------------------------------------*/
104 /* Brief Change History of This File */
105 /*----------------------------------------------------------------------------*/
106 /* Author Date Actions */
107 /*----------------------------------------------------------------------------*/
108 /* Shizhe Li Oct/01/2021 Create file */
109 /* Chensong Zhang Oct/15/2021 Format file */
110 /* Chensong Zhang Nov/09/2021 Remove decoupling methods */
111 /* Chensong Zhang Nov/22/2021 renamed to LinearSystem */
112 /*----------------------------------------------------------------------------*/
Declaration of classes interfacing to the FASP solvers.
Definition of build-in datatypes and consts.
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:22
unsigned int OCP_USI
Long unsigned integer.
Definition: OCPConst.hpp:24
int OCP_INT
Long integer.
Definition: OCPConst.hpp:25
Properties and operations on connections between bulks (active grids).
Definition: BulkConn.hpp:58
Virtual base class for linear solvers.
Linear solvers for discrete systems.
USI GetNumIters()
Return the Max Iters.
void AssembleMatLinearSolver()
Assemble Mat for Linear Solver.
OCP_INT Solve()
Solve the Linear System.
void EnlargeRowCap(const OCP_USI &row, const USI &n)
Enlarge row capacity.
vector< OCP_DBL > & GetSolution()
Return the solution.
Top-level data structure for the OpenCAEPoro simulator.
Definition: OCP.hpp:27
Definition: Well.hpp:105