tk::CSR class

Compressed sparse row (CSR) storage for a sparse matrix.

Constructors, destructors, conversion operators

CSR(std::size_t nc, const std::pair<std::vector<std::size_t>, std::vector<std::size_t>>& psup) explicit
Constructor: Create a CSR symmetric matrix with ncomp scalar components, storing only the upper triangular part.
CSR() defaulted explicit
Empty constructor for Charm++.

Public functions

auto operator()(std::size_t row, std::size_t col, std::size_t pos = 0) const -> const real&
Return const reference to sparse matrix entry at a position.
auto operator()(std::size_t row, std::size_t col, std::size_t pos = 0) -> real&
void dirichlet(std::size_t i, const std::vector<std::size_t>& gid = {}, const NodeCommMap& nodecommap = {}, std::size_t pos = 0)
Set Dirichlet boundary condition at a node.
void mult(const std::vector<real>& x, std::vector<real>& r, const std::vector<tk::real>& bcmask) const
Multiply CSR matrix with vector from the right: r = A * x.
auto rsize() const -> std::size_t
Access real size of matrix.
auto Ncomp() const -> std::size_t
Access the number of scalar components per non-zero matrix entry.
auto write_stored(std::ostream& os) const -> std::ostream&
Write out CSR as stored.
auto write_structure(std::ostream& os) const -> std::ostream&
Write out CSR nonzero structure.
auto write_contribute(std::ostream& os) const -> std::ostream&
Write out CSR contribute structure.
auto write_matrix(std::ostream& os) const -> std::ostream&
Write out CSR as a real matrix.
auto write_matlab(std::ostream& os) const -> std::ostream&
Write out CSR in Matlab/Octave format.

Pack/unpack (Charm++ serialization) routines

void pup(PUP::er& p)
Pack/Unpack serialize member function.
void operator|(PUP::er& p, CSR& c)
Pack/Unpack serialize operator|.

Function documentation

tk::CSR::CSR(std::size_t nc, const std::pair<std::vector<std::size_t>, std::vector<std::size_t>>& psup) explicit

Constructor: Create a CSR symmetric matrix with ncomp scalar components, storing only the upper triangular part.

Parameters
nc in Number of scalar components (degrees of freedom)
psup in Points surrounding points of mesh graph, see tk::genPsup

const real& tk::CSR::operator()(std::size_t row, std::size_t col, std::size_t pos = 0) const

Return const reference to sparse matrix entry at a position.

Parameters
row in Block row
col in Block column
pos in Position in block
Returns Const reference to matrix entry at position specified

real& tk::CSR::operator()(std::size_t row, std::size_t col, std::size_t pos = 0)

Return non-const reference to sparse matrix entry at a position

void tk::CSR::dirichlet(std::size_t i, const std::vector<std::size_t>& gid = {}, const NodeCommMap& nodecommap = {}, std::size_t pos = 0)

Set Dirichlet boundary condition at a node.

Parameters
in Local id at which to set Dirichlet BC
gid in Local->global node id map
nodecommap in Node communication map with global node ids
pos in Position in block

In parallel there can be multiple contributions to a single node on the mesh, and correspondingly, a single matrix row can be partially represented on multiple partitions. Setting a Dirichlet BC entails zeroing out the row of the matrix and putting 1/N into the diagonal entry, where N is the number of partitions that contribute to the mesh node (matrix row). As a result, when the matrix participates in a matrix-vector product, where the partial contributions across all partitions are aggregated, the diagonal will contain 1 after the sum across partitions.

void tk::CSR::mult(const std::vector<real>& x, std::vector<real>& r, const std::vector<tk::real>& bcmask) const

Multiply CSR matrix with vector from the right: r = A * x.

Parameters
in Vector to multiply matrix with from the right
in Result vector of product r = A * x
bcmask in Dirichlet BC mask

std::ostream& tk::CSR::write_stored(std::ostream& os) const

Write out CSR as stored.

Parameters
os in/out Output stream to write to
Returns Updated output stream

std::ostream& tk::CSR::write_structure(std::ostream& os) const

Write out CSR nonzero structure.

Parameters
os in/out Output stream to write to
Returns Updated output stream

std::ostream& tk::CSR::write_matrix(std::ostream& os) const

Write out CSR as a real matrix.

Parameters
os in/out Output stream to write to
Returns Updated output stream

std::ostream& tk::CSR::write_matlab(std::ostream& os) const

Write out CSR in Matlab/Octave format.

Parameters
os in/out Output stream to write to
Returns Updated output stream

void tk::CSR::pup(PUP::er& p)

Pack/Unpack serialize member function.

Parameters
in/out Charm++'s PUP::er serializer object reference

void tk::CSR::operator|(PUP::er& p, CSR& c)

Pack/Unpack serialize operator|.

Parameters
in/out Charm++'s PUP::er serializer object reference
in/out CSR object reference