TransFlow  0.1.0
A transient pipeline flow simulation library
MatrixEquation Class Reference

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.
 

Detailed Description

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.

See also
Discretizer

Member Function Documentation

◆ fillCoefficientMatrixAndConstantsVector()

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.

See also
Discretizer::discretize()
Parameters
nGridPointsNumber of grid points
nEquationsAndVariablesNumber of equations and variables
boundaryConditionsThe boundary conditions
term_iMatrix coefficients at point i (see above)
term_ippMatrix coefficients at point i+1 (see above)
boundaryTermsThe boundary terms (see above)

◆ reshapeSolverOutput()

arma::mat MatrixEquation::reshapeSolverOutput ( const arma::vec &  x,
const BoundaryConditions boundaryConditions,
const arma::uword  nGridPoints,
const arma::uword  nVariables 
) const
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.

Parameters
xSolution of matrix equation
boundaryConditionsBoundary conditions
nGridPointsNumber of grid points
nVariablesNumber of variables
Returns
Matrix containing flow, pressure and temperature columns.

◆ solve()

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().

Parameters
nGridPointsNumber of grid points
nEquationsAndVariablesNumber of equations and variables
boundaryConditionsThe boundary conditions
Returns
The solution of the matrix equation (x), reshaped to contain flow, pressure and temperature in separate columns.

◆ solveMatrixEquation()

arma::vec MatrixEquation::solveMatrixEquation ( ) const
private

Internal method that solves the matrix equation.

See also
solve()
Returns
Vector x, solution of the matrix equation Ax = b.

The documentation for this class was generated from the following file: