16 :
public mtl::dense2D<Matrix>
18 using Inserter = mtl::mat::inserter<Matrix, mtl::operations::update_plus<typename Matrix::value_type>>;
25 template <
class Mapping>
26 BlockMatrix(Matrix
const& matrix, Mapping
const& mapping,
bool diagonalsOnly =
false)
28 copyFrom(matrix, mapping, diagonalsOnly);
32 template <
class Mapping>
33 void copyFrom(Matrix
const& matrix, Mapping
const& mapping,
bool diagonalsOnly =
false)
35 initSizes(mapping.rowSizeInfo(), rowSizes_);
36 initSizes(mapping.colSizeInfo(), colSizes_);
40 std::size_t avgRowSize = std::round((1.2 * (matrix.nnz() / num_rows(matrix))) /
rows());
43 mtl::dense2D<Inserter*> inserter(
rows(),
cols());
44 for (std::size_t i = 0; i <
rows(); ++i) {
45 for (std::size_t j = 0; j <
cols(); ++j) {
46 (*this)[i][j].change_dim(
rows(i),
cols(j));
47 set_to_zero((*
this)[i][j]);
48 inserter[i][j] =
new Inserter((*
this)[i][j], avgRowSize);
53 auto row = mtl::mat::row_map(matrix);
54 auto col = mtl::mat::col_map(matrix);
55 auto value = mtl::mat::const_value_map(matrix);
57 for (
auto row_it : mtl::rows_of(matrix)) {
58 for (
auto it : mtl::nz_of(row_it)) {
59 auto r = mapping.row(row(it));
60 auto c = mapping.col(col(it));
62 assert(r[0] <
rows() && c[0] <
cols());
63 auto& ins = *inserter[r[0]][c[0]];
64 if (!diagonalsOnly || r[0] == c[0])
65 ins[r[1]][c[1]] << value(it);
70 for (std::size_t i = 0; i <
rows(); ++i)
71 for (std::size_t j = 0; j <
cols(); ++j)
72 delete inserter[i][j];
78 return rowSizes_.size();
82 std::size_t
rows(std::size_t i)
const
90 return colSizes_.size();
94 std::size_t
cols(std::size_t i)
const
102 template <
class SizeInfo>
103 static void initSizes(SizeInfo
const& sizeInfo, std::vector<std::size_t>& sizes)
105 using SizePrefix =
typename SizeInfo::SizePrefix;
106 SizePrefix sizePrefix{};
108 std::size_t numBlocks = sizeInfo.size(sizePrefix);
109 sizes.resize(numBlocks);
111 sizePrefix.push_back(0);
112 for (std::size_t i = 0; i < numBlocks; ++i) {
113 sizePrefix.back() = i;
114 sizes[i] = sizeInfo.size(sizePrefix);
119 std::vector<std::size_t> rowSizes_, colSizes_;
std::size_t cols(std::size_t i) const
Return the number of DOFs in i'th column block.
Definition BlockMatrix.hpp:94