TransFlow
0.1.0
A transient pipeline flow simulation library
|
The MatrixEquation class sets up the matrix equation from the system of equations found from the governing equations. More...
#include <matrixequation.hpp>
Public Member Functions | |
~MatrixEquation () | |
Declared to avoid the inline compiler-generated default destructor. | |
void | fillCoefficientMatrixAndConstantsVector (const arma::uword nGridPoints, const arma::uword nEquationsAndVariables, const BoundaryConditions &boundaryConditions, const arma::cube &term_i, const arma::cube &term_ipp, const arma::mat &boundaryTerms) |
Fill in the coefficient matrix A (MatrixEquation::m_coefficients) and constants vector b (MatrixEquation::m_constants) in the matrix equation Ax = b. More... | |
arma::mat | solve (const arma::uword nGridPoints, const arma::uword nEquationsAndVariables, const BoundaryConditions &boundaryConditions) const |
Solve the matrix equation Ax = b. More... | |
const arma::sp_mat & | coefficients () const |
Get coefficient matrix A. For testing purposes. | |
const arma::vec & | constants () const |
Get constants vector b. For testing purposes. | |
Private Member Functions | |
arma::mat | reshapeSolverOutput (const arma::vec &x, const BoundaryConditions &boundaryConditions, const arma::uword nGridPoints, const arma::uword nVariables) const |
Reshape output from solving the matrix equation into a matrix containing flow, pressure and temperature as columns. More... | |
arma::vec | solveMatrixEquation () const |
Internal method that solves the matrix equation. More... | |
Private Attributes | |
arma::sp_mat | m_coefficients |
Coefficient matrix A. | |
arma::vec | m_constants |
Constants vector b. | |
The MatrixEquation class sets up the matrix equation from the system of equations found from the governing equations.
The governing equations are discretized using a implicit backward difference method, as detailed in
This class supports all combinations of inlet and outlet boundary conditions, so we can for example use flow at the inlet, pressure at the outlet, and temperature at the inlet, or any other combination. Also supports over-determined systems.
This class is designed for use together with a Discretizer instance, which sets up the individual elements of the matrix. MatrixEquation just fills in the matrix using results from Discretizer, and solves the matrix equation.
The matrix equation is solved using the sparse matrix solver arma::spsolve, which uses superlu internally. This solver only works for critically determined systems, not for over-determined systems. In that case the regular solver is used, and the sparse matrix has to be converted to a regular matrix.
Most of the elements in the matrix are zero, so we use sparse matrices. The non-zero elements are all located near the diagonal.
void MatrixEquation::fillCoefficientMatrixAndConstantsVector | ( | const arma::uword | nGridPoints, |
const arma::uword | nEquationsAndVariables, | ||
const BoundaryConditions & | boundaryConditions, | ||
const arma::cube & | term_i, | ||
const arma::cube & | term_ipp, | ||
const arma::mat & | boundaryTerms | ||
) |
Fill in the coefficient matrix A (MatrixEquation::m_coefficients) and constants vector b (MatrixEquation::m_constants) in the matrix equation Ax = b.
Here term_i
and term_ipp
refer to the coefficients of the variables in the discretized governing equations (flow, pressure and temperature – \(y_i\) in general). See for example eq. (14)-(16) in Gas composition tracking in transient pipeline flow. These coefficients are calculated by the Discretizer class.
The boundary terms are the constant terms, the elements of the vector \(b\) in the matrix equation \(Ax = b\).
MatrixEquation supports all combinations of inlet and outlet boundary conditions, but giving more than 3 boundary conditions lead to an over-determined system, and giving less than 3 leads to a under-determined system.
nGridPoints | Number of grid points |
nEquationsAndVariables | Number of equations and variables |
boundaryConditions | The boundary conditions |
term_i | Matrix coefficients at point i (see above) |
term_ipp | Matrix coefficients at point i+1 (see above) |
boundaryTerms | The boundary terms (see above) |
|
private |
Reshape output from solving the matrix equation into a matrix containing flow, pressure and temperature as columns.
Reshapes the vector x, the solution of the matrix equation Ax = b, into a matrix with three columns. Also inserts the boundary conditions where at the correct locations.
Supports all combinations of inlet/outlet boundary settings.
x | Solution of matrix equation |
boundaryConditions | Boundary conditions |
nGridPoints | Number of grid points |
nVariables | Number of variables |
arma::mat MatrixEquation::solve | ( | const arma::uword | nGridPoints, |
const arma::uword | nEquationsAndVariables, | ||
const BoundaryConditions & | boundaryConditions | ||
) | const |
Solve the matrix equation Ax = b.
This solves the matrix equation, after the coefficient matrix MatrixEquation::m_coefficients and constant vector MatrixEquation::m_coefficients has been filled in by fillCoefficientMatrixAndConstantsVector().
nGridPoints | Number of grid points |
nEquationsAndVariables | Number of equations and variables |
boundaryConditions | The boundary conditions |
|
private |
Internal method that solves the matrix equation.