Functions
Problem
Sparspak.SpkProblem.Problem
— MethodProblem(nrows::IT, ncols::IT, nnz::IT=2500, z::FT=0.0, info = "") where {IT, FT}
Construct a problem.
Sparspak.SpkProblem.inaij!
— Methodinaij!(p::Problem{IT,FT}, rnum, cnum, aij=zero(FT)) where {IT,FT}
Input a matrix coefficient.
The value is added to the existing contents.
Sparspak.SpkProblem.inbi!
— Methodinbi!(p::Problem{IT, FT}, rnum::IT, bi::FT) where {IT, FT}
Input an entry of the right-hand side vector.
Sparspak.SpkProblem.insparse!
— Methodinsparse!(p::Problem{IT,FT}, spm) where {IT,FT}
Input sparse matrix.
Build a problem from a sparse matrix.
Sparspak.SpkProblem.infullrhs!
— Functioninfullrhs!(p::Problem{IT,FT}, rhs) where {IT,FT}
Add a vector of values, rhs, to the current right hand side of a problem object.
Input:
rhs
- the source right-hand side. It must be of length at leastp.nrows
and if it is greater thanp.nrows
, only the firstp.nrows
are used.
Updated:
p
- the problem in which rhs is to be inserted.
Sparspak.SpkProblem.outsparse
— Functionoutsparse(p::Problem{IT,FT}) where {IT,FT}
Output the sparse matrix.
Sparspak.SpkProblem.computeresidual
— Functioncomputeresidual(p::Problem, res::Vector{FT}, xin::Vector{FT} = FT[], mtype = "T") where {FT}
Compute the residual of a problem.
Given a vector x
, this routine calculates the difference between the RHS of the given Problem and A*x
and places this in res
.
Input:
p
- theProblem
used to calculateres
, usingxin
xin
- the input "solution" vector used to compute the residualmtype
- matrix type (optional). If the matrix is symmetric and only the lower or upper triangle is present, the user must let the routine know this by setting mType to one of: "L" or "l" - when only the lower triangle is present "U" or "u" - when only the upper triangle is present "T" or "t" - when either the lower or upper triangle is present.
Output:
res
- the calculated residual
Sparspak.SpkProblem.makerhs!
— Functionmakerhs!(p::Problem, x::Vector{FT} = FT[], mtype = "T") where {FT}
This routine constructs the RHS of a problem given an x
for the equation Ax = rhs
. The x
must have the same number of elements as the problem (represented by A above) has columns. If x
is not present, a right hand side is contructed so that the solution is 1, 2, 3, ...m.
Input Parameter: x - the vector in the equation ``Ax = rhs"" mType - matrix type (optional). If the matrix is symmetric and only the lower or upper triangle is present, the user must let the routine know this by setting mType to one of: "L" or "l" - when only the lower triangle is present "U" or "u" - when only the upper triangle is present "T" or "t" - when either the lower or upper triangle is present. Updated Parameter: p - the problem for which the RHS is being constructed.
Sparspak.SpkProblem.makegridproblem
— Functionmakegridproblem(g::Grid{IT}) where {IT}
This routine fills in a problem object using a given grid.
Input:
g
- theGrid
to be used to fill aProblem
matrix
Output:
p
- the Problem object to be filled
makegridproblem(h::IT, k::IT) where {IT}
Construct a problem object based on a grid.
Input:
h
- the number of rows in the Gridk
- the number of columns in the Grid
Output:
p
- the Problem object to be filled
Sparse LU Solver
Main interface
Sparspak.SpkSparseSolver.SparseSolver
— TypeSparseSolver{IT, FT}
Type of LU general sparse solver.
Sparspak.SpkSparseSolver.SparseSolver
— MethodSparseSolver(p::Problem)
Create a sparse solver from a problem.
The solver pulls all it needs from the problem.
Sparspak.SpkSparseSolver.solve!
— Functionsolve!(s,rhs)
Solves linear system defined with sparse solver and provides the solution in rhs.
solve!(s::SparseSolver{IT}) where {IT}
Execute all the steps of the solution process.
Given a symmetric matrix A
, the steps are:
- Reordering of the matrix
A
. - Symbolic factorization of the(reordered) matrix
A
. - Putting numerical values of
A
into the data structures. - Numerical factorization of
A
. - Forward and backward substitution (triangular solution).
The solution can be retrieved as p.x
.
Fine-granularity actions
Sparspak.SpkSparseSolver.findorder!
— Functionfindorder!(s::SparseSolver{IT}, orderfunction::F) where {IT, F}
Find reordering of the coefficient matrix.
orderfunction
: ordering function
If ordering has already been done for the solver, nothing happens. Otherwise, the order function is applied.
Finding the ordering invalidates symbolic factorization.
findorder!(s::SparseSolver{IT}) where {IT}
Find reordering of the coefficient matrix using the default method.
If ordering has already been done for the solver, nothing happens. Otherwise, the order function is applied.
Finding the ordering invalidates symbolic factorization.
Sparspak.SpkSparseSolver.findorderperm!
— Functionfindorderperm!(s::SparseSolver{IT}, perm) where {IT}
Find reordering of the coefficient matrix using a given permutation.
If ordering has already been done for the solver, nothing happens. Otherwise, the order function is applied.
Finding the ordering invalidates symbolic factorization.
Sparspak.SpkSparseSolver.symbolicfactor!
— Functionsymbolicfactor!(s::SparseSolver{IT})
Symbolic factorization of the(reordered) matrix A.
Create the data structures for the factorization and forward and backward substitution.
A symbolic factorization invalidates the input of the matrix.
Sparspak.SpkSparseSolver.inmatrix!
— Functioninmatrix!(s::SparseSolver{IT}) where {IT}
Put numerical values of the matrix stored in the problem into the data structures of the solver.
If a matrix has been input before, and has not been invalidated by symbolic factorization, nothing is done.
Input of the numerical values of the matrix invalidates the factorization.
Sparspak.SpkSparseSolver.factor!
— Functionfactor!(s::SparseSolver{IT}) where {IT}
Numerical factorization of the coefficient matrix.
Numerical factorization invalidates the triangular solve.
Sparspak.SpkSparseSolver.triangularsolve!
— Functiontriangularsolve!(s::SparseSolver{IT}) where {IT}
Forward and backward substitution (triangular solution).
The triangular solve is only done if it hasn't been done before; otherwise nothing is done and the solution is the one obtained before.
triangularsolve!(s::SparseSolver{IT, FT}, rhs::Vector{FT}) where {IT, FT}
Forward and backward substitution (triangular solution).
Variant where the right-hand side vector is passed in. This always triggers a triangular solve.
LU Factorization API
Sparspak.SparseCSCInterface.sparspaklu
— Functionsparspaklu(m::SparseMatrixCSC; factorize=true) -> lu::SparseSolver
If factorize==true
, calculate LU factorization using Sparspak. Steps are findorder
, symbolicfactor
, factor
.
If factorize==false
, ordering, symbolic factorization and factorization are delayed to a subsequent call to sparspaklu!
.
Returns a SparseSolver
instance in the respective state, which has methods for LinearAlgebra.ldiv!
and "backslash".
Sparspak.SparseCSCInterface.sparspaklu!
— Functionsparspaklu!(lu::SparseSolver, m::SparseMatrixCSC; allow_pattern_change=true) -> lu::SparseSolver
Calculate LU factorization of a sparse matrix m
, reusing ordering and symbolic factorization lu
, if that was previously calculated.
If allow_pattern_change = true
(the default) the sparse matrix m
may have a nonzero pattern different to that of the matrix used to create the LU factorization lu
, in which case the ordering and symbolic factorization are updated.
If allow_pattern_change = false
an error is thrown if the nonzero pattern of m
is different to that of the matrix used to create the LU factorization lu
.
If lu
has not been factorized (ie it has just been created with option factorize = false
) then lu
is always updated from m
and allow_pattern_change
is ignored.
Multiple minimum degree (MMD) ordering.
Sparspak.SpkMmd.mmd!
— Methodmmd!(g::Graph, order::Ordering)
Multiple minimum degree Ordering algorithm (MMD).
Written by Erik Demaine, eddemaine@uwaterloo.ca Based on a Fortran 77 code written by Joseph Liu.
For information on the minimum degree algorithm see the articles:
The evolution of the minimum degree algorithm by Alan George and Joseph Liu, SIAM Rev. 31 pp. 1 - 19, 1989.0
Modification of the minimum degree algorithm by multiple elimination, ACM Trans. Math. Soft. 2 pp.141 - 152, 1985
Input:
g
: graph
Output:
order
: updated ordering. Rows and columns are permuted in the same way.
Graphs
Sparspak.SpkGraph.Graph
— MethodGraph(p::Problem{IT}, diagonal=false) where {IT}
Construct a graph from a problem object.
It does not check that the problem object contains a structurally symmetric matrix, since sometimes only the lower or upper triangle of a symmetric matrix may be stored. There are routines in this module to make a given graph object structurally symmetric.
Input:
p
- the problem object, used to create the graphdiagonal
- indicates that the diagonal elements are included. If diagonal is not given, the adjacency structure does not include the diagonal elements.
Sparspak.SpkGraph.makestructuresymmetric
— Methodmakestructuresymmetric(g::Graph{IT}) where {IT}
Make the graph structure symmetric.
Sparspak.SpkGraph.sortgraph!
— Methodsortgraph!(g::Graph{IT}) where {IT}
Sort the adjacency lists of the graph.
Important assumption: This works only for graphs that are symmetric.
Sparspak.SpkGraph.isstructuresymmetric
— Methodisstructuresymmetric(g::Graph{IT}) where {IT}
Determines if a graph is structurally symmetric.
Output: either true or false
Grid
Sparspak.SpkGrid.Grid
— MethodGrid(h::IT, k::IT) where {IT}
Construct a grid with a given number of spacings.