Extendable matrices

The type hierarchy of extendable matrices in this package is as follows:

ExtendableSparse.AbstractExtendableSparseMatrixCSC <: SparseArrays.AbstractSparseMatrixCSC <: SparseArrays.AbstractSparseMatrix <: AbstractMatrix

The package defines two subtypes of ExtendableSparse.AbstractExtendableSparseMatrixCSC which are parametrized by types of extension matrices:

User facing defaults are defined by type aliases:

  • const MTExtendableSparseMatrixCSC = GenericMTExtendableSparseMatrixCSC{SparseMatrixDILNKC}
  • const STExtendableSparseMatrixCSC = GenericExtendableSparseMatrixCSC{SparseMatrixLNK}
  • const ExtendableSparseMatrixCSC = STExtendableSparseMatrixCSC
  • const ExtendableSparseMatrix = ExtendableSparseMatrixCSC

Abstract type

ExtendableSparse.AbstractExtendableSparseMatrixCSCType
abstract type AbstractExtendableSparseMatrixCSC{Tv, Ti} <: AbstractSparseMatrixCSC{Tv, Ti} end

Abstract super type for extendable CSC matrices. It implements what is being discussed as the "AbstractSparseMatrixCSC interfacee"

Subtypes must implement:

  • SparseArrays.sparse: flush+return SparseMatrixCSC
  • Constructor from SparseMatrixCSC
  • rawupdateindex!
  • reset!: empty all internals, just keep size
  • flush!: (re)build SparseMatrixCSC, incorporate new entries

Subtypes of this type would contain a SparseMatrixCSC which is used in linear algebra operations. In addition they would contain data structures for efficiently adding new entries, like instances or vectors of instances of subtypes of AbstractSparseMatrixExtension.

source

Subtypes of AbstractExtendableSparseMatrixCSC

ExtendableSparse.GenericExtendableSparseMatrixCSCType
mutable struct GenericExtendableSparseMatrixCSC{Tm<:ExtendableSparse.AbstractSparseMatrixExtension, Tv, Ti<:Integer} <: ExtendableSparse.AbstractExtendableSparseMatrixCSC{Tv, Ti<:Integer}

Single threaded extendable sparse matrix parametrized by sparse matrix extension.

Fields:

  • cscmatrix: a SparseMatrixCSC containing existing matrix entries
  • xmatrix: instance of an AbstractSparseMatrixExtension which is used to collect new entries
source
ExtendableSparse.GenericMTExtendableSparseMatrixCSCType
mutable struct GenericMTExtendableSparseMatrixCSC{Tm<:ExtendableSparse.AbstractSparseMatrixExtension, Tv, Ti<:Integer} <: ExtendableSparse.AbstractExtendableSparseMatrixCSC{Tv, Ti<:Integer}

Extendable sparse matrix parametrized by sparse matrix extension allowing multithreaded assembly and parallel matrix-vector multiplication.

Fields:

  • cscmatrix: a SparseMatrixCSC containing existing matrix entries
  • xmatrices: vector of instances of AbstractSparseMatrixExtension used to collect new entries
  • colparts: vector describing colors of the partitions of the unknowns
  • partnodes: vector describing partition of the unknowns

It is assumed that the set of unknowns is partitioned, and the partitioning is colored in such a way that several partitions of the same color can be handled by different threads, both during matrix assembly (which in general would use a partition of e.g. finite elements compatible to the partitioning of the nodes) and during matrix-vector multiplication. This approach is compatible with the current choice of the standard Julia sparse ecosystem which prefers compressed colume storage (CSC) over compressed row storage (CSR).

source

Type aliases

Required methods

SparseArrays.sparseFunction
sparse(
    mat::ExtendableSparse.SparseMatrixDict{Tv, Ti}
) -> SparseMatrixCSC
source
SparseArrays.sparse(A::AbstractExtendableSparseMatrixCSC)

Return SparseMatrixCSC which contains all matrix entries introduced so far.

source
sparse(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC
) -> SparseMatrixCSC
source
sparse(
    ext::ExtendableSparse.GenericExtendableSparseMatrixCSC
) -> SparseMatrixCSC
source
ExtendableSparse.rawupdateindex!Function
rawupdateindex!(
    lnk::ExtendableSparse.SparseMatrixLNK{Tv, Ti},
    op,
    v,
    i,
    j
) -> ExtendableSparse.SparseMatrixLNK{Tv, Ti} where {Tv, Ti}

Update element of the matrix with operation op. It assumes that op(0,0)==0. If v is zero a new entry is created nevertheless.

source
rawupdateindex!(
    lnk::ExtendableSparse.SparseMatrixDILNKC{Tv, Ti},
    op,
    v,
    i,
    j
) -> ExtendableSparse.SparseMatrixDILNKC

Update element of the matrix with operation op. It assumes that op(0,0)==0. If v is zero a new entry is created nevertheless.

source
rawupdateindex!(
    m::ExtendableSparse.SparseMatrixDict{Tv, Ti},
    op,
    v,
    i,
    j
) -> Any
source
rawupdateindex!(A::AbstractExtendableSparseMatrixCSC,op,v,i,j,part = 1)

Add or update entry of A: A[i,j]=op(A[i,j],v) without checking if a zero is inserted. The optional parameter part denotes the partition.

source
rawupdateindex!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC,
    op,
    v,
    i,
    j
) -> Any
rawupdateindex!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC,
    op,
    v,
    i,
    j,
    tid
) -> Any
source
rawupdateindex!(
    ext::ExtendableSparse.GenericExtendableSparseMatrixCSC,
    op,
    v,
    i,
    j
) -> Any
rawupdateindex!(
    ext::ExtendableSparse.GenericExtendableSparseMatrixCSC,
    op,
    v,
    i,
    j,
    part
) -> Any
source
ExtendableSparse.flush!Function
flush!(csc::SparseMatrixCSC) -> SparseMatrixCSC

Trivial flush! method for allowing to run the code with both ExtendableSparseMatrix and SparseMatrixCSC.

source
flush!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC{Tm, Tv, Ti}
) -> ExtendableSparse.GenericMTExtendableSparseMatrixCSC{Tm, Tv, Ti} where {Tm, Tv, Ti}
source
flush!(
    ext::ExtendableSparse.GenericExtendableSparseMatrixCSC{Tm, Tv, Ti}
) -> ExtendableSparse.GenericExtendableSparseMatrixCSC{Tm, Tv, Ti} where {Tm, Tv, Ti}
source
ExtendableSparse.reset!Function
reset!(
    m::ExtendableSparse.SparseMatrixDict{Tv, Ti}
) -> Dict{Pair{_A, _B}} where {_A, _B}
source
reset!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC{Tm, Tv, Ti},
    p::Integer
) -> ExtendableSparse.GenericMTExtendableSparseMatrixCSC{Tm, Tv, Ti} where {Tm, Tv, Ti}
source
reset!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC
) -> ExtendableSparse.GenericMTExtendableSparseMatrixCSC
source
reset!(
    ext::ExtendableSparse.GenericExtendableSparseMatrixCSC{Tm, Tv, Ti}
) -> ExtendableSparse.GenericExtendableSparseMatrixCSC{Tm, Tv, Ti} where {Tm, Tv, Ti}
source

AbstractSparseMatrixCSC interface

See SparseArrways#395 for a discussion.

SparseArrays.nnzFunction
nnz(lnk::ExtendableSparse.SparseMatrixLNK) -> Integer

Return number of nonzero entries.

source
nnz(lnk::ExtendableSparse.SparseMatrixDILNKC) -> Integer

Return number of nonzero entries.

source
nnz(m::ExtendableSparse.SparseMatrixDict) -> Int64
source
SparseArrays.nnz(ext::AbstractExtendableSparseMatrixCSC)

flush! and return number of nonzeros in ext.cscmatrix.

source
SparseArrays.nonzerosFunction
SparseArrays.nonzeros(ext::AbstractExtendableSparseMatrixCSC) = nonzeros(sparse(ext))

flush! and return nonzeros in ext.cscmatrix.

source
SparseArrays.SparseMatrixCSCType
SparseMatrixCSC(
    lnk::ExtendableSparse.SparseMatrixLNK
) -> SparseMatrixCSC

Constructor from SparseMatrixLNK.

source
SparseMatrixCSC(
    lnk::ExtendableSparse.SparseMatrixDILNKC
) -> SparseMatrixCSC{Float64, Int64}

Constructor from SparseMatrixDILNKC.

source
SparseArrays.SparseMatrixCSC(A::AbstractExtendableSparseMatrixCSC)

Create SparseMatrixCSC from ExtendableSparseMatrix

source
Base.sizeFunction
size(
    lnk::ExtendableSparse.SparseMatrixLNK
) -> Tuple{Integer, Integer}

Return tuple containing size of the matrix.

source
size(
    lnk::ExtendableSparse.SparseMatrixDILNKC
) -> Tuple{Integer, Integer}

Return tuple containing size of the matrix.

source
size(
    m::ExtendableSparse.SparseMatrixDict
) -> Tuple{Any, Any}
source
Base.size(ext::AbstractExtendableSparseMatrixCSC)

Return size of matrix.

source
Base.eltypeFunction
Base.eltype(::AbstractExtendableSparseMatrixCSC{Tv, Ti})

Return element type.

source
Base.showFunction
Base.show(::IO, ::MIME"text/plain", ext::AbstractExtendableSparseMatrixCSC)

flush! and use the show method of SparseMatrixCSC to show the content.

source

Linear Algebra

Base.:\Function
 Base.:\(::AbstractExtendableSparseMatrixCSC, b)

\ for ExtendableSparse. It calls the LU factorization form Sparspak.jl, unless GPL components are allowed in the Julia sysimage and the floating point type of the matrix is Float64 or Complex64. In that case, Julias standard `` is called, which is realized via UMFPACK.

source
 Base.:\(Symmetric(::AbstractExtendableSparseMatrixCSC), b)

\ for Symmetric{ExtendableSparse}

source
 Base.:\(Hermitian(::AbstractExtendableSparseMatrixCSC), b)

\ for Hermitian{ExtendableSparse}

source
LinearAlgebra.ldiv!Function
ldiv!(
    r::AbstractArray,
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    x::AbstractArray
) -> SparseMatrixCSC

flush! and ldiv! with ext.cscmatrix

source
LinearAlgebra.mul!Function
mul!(
    r::AbstractVecOrMat,
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    x::AbstractVecOrMat
)

flush! and multiply with ext.cscmatrix

source
mul!(
    r::AbstractVecOrMat,
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC,
    x::AbstractVecOrMat
)
source
LinearAlgebra.normFunction
norm(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> Any
norm(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    p::Real
) -> Any

flush! and calculate norm from cscmatrix

source
LinearAlgebra.opnormFunction
opnorm(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> Any
opnorm(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    p::Real
) -> Any

flush! and calculate opnorm from cscmatrix

source
LinearAlgebra.condFunction
cond(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> Any
cond(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    p::Real
) -> Any

flush! and calculate cond from cscmatrix

source

Algebraic operations

Base.:+Function
+(
    lnk::ExtendableSparse.SparseMatrixLNK{Tv, Ti<:Integer},
    csc::SparseMatrixCSC
) -> SparseMatrixCSC

Add SparseMatrixCSC matrix and SparseMatrixLNK lnk, returning a SparseMatrixCSC

source
+(
    dictmatrix::ExtendableSparse.SparseMatrixDict{Tv, Ti},
    cscmatrix::SparseMatrixCSC{Tv, Ti}
) -> SparseMatrixCSC{Tv, Ti} where {Tv, Ti}
source
+(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    B::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> ExtendableSparse.GenericExtendableSparseMatrixCSC
source
+(
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    csc::SparseMatrixCSC
) -> SparseMatrixCSC
source
Base.:-Function
-(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    B::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> ExtendableSparse.GenericExtendableSparseMatrixCSC
source
-(
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    csc::SparseMatrixCSC
) -> SparseMatrixCSC
source
-(
    csc::SparseMatrixCSC,
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> SparseMatrixCSC
source
Base.:*Function
*(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    B::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> ExtendableSparse.GenericExtendableSparseMatrixCSC
source
*(
    d::Diagonal,
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> ExtendableSparse.GenericExtendableSparseMatrixCSC
source
*(
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    d::Diagonal
) -> ExtendableSparse.GenericExtendableSparseMatrixCSC
source

Handling of homogeneous Dirichlet BC

ExtendableSparse.mark_dirichletFunction

mark_dirichlet(A; penalty=1.0e20)

Return boolean vector marking Dirichlet nodes, known by A[i,i]>=penalty

source
mark_dirichlet(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC;
    penalty
) -> Vector{Bool}
source
ExtendableSparse.eliminate_dirichlet!Function
eliminate_dirichlet!(A,dirichlet_marker)

Eliminate dirichlet nodes in matrix by setting

    A[:,i]=0; A[i,:]=0; A[i,i]=1

for a node i marked as Dirichlet.

Returns A.

source
eliminate_dirichlet!(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    dirichlet
) -> ExtendableSparse.AbstractExtendableSparseMatrixCSC
source
ExtendableSparse.eliminate_dirichletFunction
eliminate_dirichlet(A,dirichlet_marker)

Create a copy B of A sharing the sparsity pattern. Eliminate dirichlet nodes in B by setting

    B[:,i]=0; B[i,:]=0; B[i,i]=1

for a node i marked as Dirichlet.

Returns B.

source
eliminate_dirichlet(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    dirichlet
) -> ExtendableSparse.GenericExtendableSparseMatrixCSC
source