15#ifndef dealii_block_matrix_base_h
16#define dealii_block_matrix_base_h
61 template <
typename BlockMatrixType>
109 template <
typename BlockMatrixType,
bool Constness>
116 template <
typename BlockMatrixType>
193 friend class ::MatrixIterator;
195 friend class Accessor<BlockMatrixType, true>;
204 template <
typename BlockMatrixType>
283 friend class ::MatrixIterator;
348template <
typename MatrixType>
402 template <
typename BlockMatrixType>
410 block(
const unsigned int row,
const unsigned int column);
418 block(
const unsigned int row,
const unsigned int column)
const;
472 template <
typename number>
474 set(
const std::vector<size_type> &indices,
476 const bool elide_zero_values =
false);
483 template <
typename number>
485 set(
const std::vector<size_type> &row_indices,
486 const std::vector<size_type> &col_indices,
488 const bool elide_zero_values =
false);
500 template <
typename number>
503 const std::vector<size_type> &col_indices,
504 const std::vector<number> &values,
505 const bool elide_zero_values =
false);
516 template <
typename number>
521 const number *values,
522 const bool elide_zero_values =
false);
546 template <
typename number>
548 add(
const std::vector<size_type> &indices,
550 const bool elide_zero_values =
true);
557 template <
typename number>
559 add(
const std::vector<size_type> &row_indices,
560 const std::vector<size_type> &col_indices,
562 const bool elide_zero_values =
true);
573 template <
typename number>
576 const std::vector<size_type> &col_indices,
577 const std::vector<number> &values,
578 const bool elide_zero_values =
true);
589 template <
typename number>
594 const number *values,
595 const bool elide_zero_values =
true,
596 const bool col_indices_are_sorted =
false);
672 template <
typename BlockVectorType>
674 vmult_add(BlockVectorType &dst,
const BlockVectorType &src)
const;
681 template <
typename BlockVectorType>
683 Tvmult_add(BlockVectorType &dst,
const BlockVectorType &src)
const;
697 template <
typename BlockVectorType>
711 template <
typename BlockVectorType>
714 const BlockVectorType &v)
const;
719 template <
typename BlockVectorType>
722 const BlockVectorType &x,
723 const BlockVectorType &b)
const;
732 print(std::ostream &out,
const bool alternative_output =
false)
const;
814 <<
"The blocks [" << arg1 <<
',' << arg2 <<
"] and [" << arg3
815 <<
',' << arg4 <<
"] have differing row numbers.");
824 <<
"The blocks [" << arg1 <<
',' << arg2 <<
"] and [" << arg3
825 <<
',' << arg4 <<
"] have differing column numbers.");
885 template <
typename BlockVectorType>
899 template <
typename BlockVectorType,
typename VectorType>
913 template <
typename BlockVectorType,
typename VectorType>
927 template <
typename VectorType>
942 template <
typename BlockVectorType>
956 template <
typename BlockVectorType,
typename VectorType>
970 template <
typename BlockVectorType,
typename VectorType>
984 template <
typename VectorType>
1068 template <
typename,
bool>
1084 template <
typename BlockMatrixType>
1091 template <
typename BlockMatrixType>
1093 AccessorBase<BlockMatrixType>::block_row()
const
1101 template <
typename BlockMatrixType>
1103 AccessorBase<BlockMatrixType>::block_column()
const
1111 template <
typename BlockMatrixType>
1112 inline Accessor<BlockMatrixType, true>::Accessor(
1113 const BlockMatrixType *matrix,
1114 const size_type row,
1115 const size_type col)
1124 if (row < matrix->
m())
1126 const std::pair<unsigned int, size_type> indices =
1127 matrix->row_block_indices.global_to_local(row);
1131 for (
unsigned int bc = 0; bc <
matrix->n_block_cols(); ++bc)
1134 matrix->block(indices.first, bc).begin(indices.second);
1135 if (base_iterator !=
1136 matrix->block(indices.first, bc).end(indices.second))
1138 this->row_block = indices.first;
1139 this->col_block = bc;
1150 *
this =
Accessor(matrix, row + 1, 0);
1175 template <
typename BlockMatrixType>
1176 inline Accessor<BlockMatrixType, true>::Accessor(
1177 const Accessor<BlockMatrixType, false> &other)
1179 , base_iterator(other.base_iterator)
1181 this->row_block = other.row_block;
1182 this->col_block = other.col_block;
1186 template <
typename BlockMatrixType>
1187 inline typename Accessor<BlockMatrixType, true>::size_type
1188 Accessor<BlockMatrixType, true>::row()
const
1193 return (
matrix->row_block_indices.local_to_global(this->row_block, 0) +
1194 base_iterator->row());
1198 template <
typename BlockMatrixType>
1199 inline typename Accessor<BlockMatrixType, true>::size_type
1200 Accessor<BlockMatrixType, true>::column()
const
1205 return (
matrix->column_block_indices.local_to_global(this->col_block, 0) +
1206 base_iterator->column());
1210 template <
typename BlockMatrixType>
1211 inline typename Accessor<BlockMatrixType, true>::value_type
1212 Accessor<BlockMatrixType, true>::value()
const
1219 return base_iterator->value();
1224 template <
typename BlockMatrixType>
1226 Accessor<BlockMatrixType, true>::advance()
1234 size_type local_row = base_iterator->row();
1245 while (base_iterator ==
1246 matrix->block(this->row_block, this->col_block).end(local_row))
1251 if (this->col_block < matrix->n_block_cols() - 1)
1255 matrix->block(this->row_block, this->col_block).begin(local_row);
1261 this->col_block = 0;
1271 matrix->block(this->row_block, this->col_block).m())
1275 if (this->row_block ==
matrix->n_block_rows())
1284 matrix->block(this->row_block, this->col_block).begin(local_row);
1290 template <
typename BlockMatrixType>
1292 Accessor<BlockMatrixType, true>::operator==(
const Accessor &a)
const
1294 if (matrix != a.matrix)
1297 if (this->row_block == a.row_block && this->col_block == a.col_block)
1304 (base_iterator == a.base_iterator));
1312 template <
typename BlockMatrixType>
1313 inline Accessor<BlockMatrixType, false>::Accessor(BlockMatrixType *matrix,
1314 const size_type row,
1315 const size_type col)
1323 if (row < matrix->
m())
1325 const std::pair<unsigned int, size_type> indices =
1326 matrix->row_block_indices.global_to_local(row);
1330 for (size_type bc = 0; bc <
matrix->n_block_cols(); ++bc)
1333 matrix->block(indices.first, bc).begin(indices.second);
1334 if (base_iterator !=
1335 matrix->block(indices.first, bc).end(indices.second))
1337 this->row_block = indices.first;
1338 this->col_block = bc;
1349 *
this =
Accessor(matrix, row + 1, 0);
1361 template <
typename BlockMatrixType>
1362 inline typename Accessor<BlockMatrixType, false>::size_type
1363 Accessor<BlockMatrixType, false>::row()
const
1367 return (
matrix->row_block_indices.local_to_global(this->row_block, 0) +
1368 base_iterator->row());
1372 template <
typename BlockMatrixType>
1373 inline typename Accessor<BlockMatrixType, false>::size_type
1374 Accessor<BlockMatrixType, false>::column()
const
1378 return (
matrix->column_block_indices.local_to_global(this->col_block, 0) +
1379 base_iterator->column());
1383 template <
typename BlockMatrixType>
1384 inline typename Accessor<BlockMatrixType, false>::value_type
1385 Accessor<BlockMatrixType, false>::value()
const
1390 return base_iterator->value();
1395 template <
typename BlockMatrixType>
1397 Accessor<BlockMatrixType, false>::set_value(
1398 typename Accessor<BlockMatrixType, false>::value_type newval)
const
1403 base_iterator->value() = newval;
1408 template <
typename BlockMatrixType>
1410 Accessor<BlockMatrixType, false>::advance()
1416 size_type local_row = base_iterator->row();
1427 while (base_iterator ==
1428 matrix->block(this->row_block, this->col_block).end(local_row))
1433 if (this->col_block < matrix->n_block_cols() - 1)
1437 matrix->block(this->row_block, this->col_block).begin(local_row);
1443 this->col_block = 0;
1453 matrix->block(this->row_block, this->col_block).m())
1457 if (this->row_block ==
matrix->n_block_rows())
1466 matrix->block(this->row_block, this->col_block).begin(local_row);
1473 template <
typename BlockMatrixType>
1475 Accessor<BlockMatrixType, false>::operator==(
const Accessor &a)
const
1477 if (matrix != a.matrix)
1480 if (this->row_block == a.row_block && this->col_block == a.col_block)
1487 (base_iterator == a.base_iterator));
1496template <
typename MatrixType>
1508template <
typename MatrixType>
1509template <
typename BlockMatrixType>
1513 for (
unsigned int r = 0; r < n_block_rows(); ++r)
1514 for (
unsigned int c = 0; c < n_block_cols(); ++c)
1515 block(r, c).
copy_from(source.block(r, c));
1521template <
typename MatrixType>
1532 sizeof(temporary_data.mutex);
1534 for (
unsigned int r = 0; r < n_block_rows(); ++r)
1535 for (
unsigned int c = 0; c < n_block_cols(); ++c)
1537 MatrixType *p = this->sub_objects[r][c];
1546template <
typename MatrixType>
1550 for (
unsigned int r = 0; r < n_block_rows(); ++r)
1551 for (
unsigned int c = 0; c < n_block_cols(); ++c)
1553 MatrixType *p = this->sub_objects[r][c];
1554 this->sub_objects[r][c] =
nullptr;
1557 sub_objects.reinit(0, 0);
1560 row_block_indices = column_block_indices =
BlockIndices();
1565template <
typename MatrixType>
1568 const unsigned int column)
1573 return *sub_objects[row][column];
1578template <
typename MatrixType>
1581 const unsigned int column)
const
1586 return *sub_objects[row][column];
1590template <
typename MatrixType>
1594 return row_block_indices.total_size();
1599template <
typename MatrixType>
1603 return column_block_indices.total_size();
1608template <
typename MatrixType>
1612 return column_block_indices.size();
1617template <
typename MatrixType>
1621 return row_block_indices.size();
1629template <
typename MatrixType>
1633 const value_type value)
1635 prepare_set_operation();
1639 const std::pair<unsigned int, size_type>
1640 row_index = row_block_indices.global_to_local(i),
1641 col_index = column_block_indices.global_to_local(j);
1642 block(row_index.first, col_index.first)
1643 .set(row_index.second, col_index.second, value);
1648template <
typename MatrixType>
1649template <
typename number>
1652 const std::vector<size_type> &col_indices,
1654 const bool elide_zero_values)
1656 Assert(row_indices.size() == values.m(),
1658 Assert(col_indices.size() == values.n(),
1661 for (size_type i = 0; i < row_indices.size(); ++i)
1671template <
typename MatrixType>
1672template <
typename number>
1676 const bool elide_zero_values)
1678 Assert(indices.size() == values.m(),
1682 for (size_type i = 0; i < indices.size(); ++i)
1692template <
typename MatrixType>
1693template <
typename number>
1696 const std::vector<size_type> &col_indices,
1697 const std::vector<number> &values,
1698 const bool elide_zero_values)
1700 Assert(col_indices.size() == values.size(),
1715template <
typename MatrixType>
1716template <
typename number>
1719 const size_type n_cols,
1720 const size_type *col_indices,
1721 const number *values,
1722 const bool elide_zero_values)
1724 prepare_set_operation();
1728 std::lock_guard<std::mutex> lock(temporary_data.mutex);
1731 if (temporary_data.column_indices.size() < this->n_block_cols())
1733 temporary_data.column_indices.resize(this->n_block_cols());
1734 temporary_data.column_values.resize(this->n_block_cols());
1735 temporary_data.counter_within_block.resize(this->n_block_cols());
1748 if (temporary_data.column_indices[0].size() < n_cols)
1750 for (
unsigned int i = 0; i < this->n_block_cols(); ++i)
1752 temporary_data.column_indices[i].resize(n_cols);
1753 temporary_data.column_values[i].resize(n_cols);
1759 for (
unsigned int i = 0; i < this->n_block_cols(); ++i)
1760 temporary_data.counter_within_block[i] = 0;
1771 for (size_type j = 0; j < n_cols; ++j)
1773 number
value = values[j];
1775 if (value == number() && elide_zero_values ==
true)
1778 const std::pair<unsigned int, size_type> col_index =
1779 this->column_block_indices.global_to_local(col_indices[j]);
1781 const size_type local_index =
1782 temporary_data.counter_within_block[col_index.first]++;
1784 temporary_data.column_indices[col_index.first][local_index] =
1786 temporary_data.column_values[col_index.first][local_index] =
value;
1792 size_type length = 0;
1793 for (
unsigned int i = 0; i < this->n_block_cols(); ++i)
1794 length += temporary_data.counter_within_block[i];
1803 const std::pair<unsigned int, size_type> row_index =
1804 this->row_block_indices.global_to_local(row);
1805 for (
unsigned int block_col = 0; block_col < n_block_cols(); ++block_col)
1807 if (temporary_data.counter_within_block[block_col] == 0)
1810 block(row_index.first, block_col)
1811 .set(row_index.second,
1812 temporary_data.counter_within_block[block_col],
1813 temporary_data.column_indices[block_col].data(),
1814 temporary_data.column_values[block_col].data(),
1821template <
typename MatrixType>
1825 const value_type value)
1829 prepare_add_operation();
1834 using MatrixTraits =
typename MatrixType::Traits;
1835 if ((MatrixTraits::zero_addition_can_be_elided ==
true) &&
1836 (value == value_type()))
1839 const std::pair<unsigned int, size_type>
1840 row_index = row_block_indices.global_to_local(i),
1841 col_index = column_block_indices.global_to_local(j);
1842 block(row_index.first, col_index.first)
1843 .add(row_index.second, col_index.second, value);
1848template <
typename MatrixType>
1849template <
typename number>
1852 const std::vector<size_type> &col_indices,
1854 const bool elide_zero_values)
1856 Assert(row_indices.size() == values.m(),
1858 Assert(col_indices.size() == values.n(),
1861 for (size_type i = 0; i < row_indices.size(); ++i)
1871template <
typename MatrixType>
1872template <
typename number>
1876 const bool elide_zero_values)
1878 Assert(indices.size() == values.m(),
1882 for (size_type i = 0; i < indices.size(); ++i)
1892template <
typename MatrixType>
1893template <
typename number>
1896 const std::vector<size_type> &col_indices,
1897 const std::vector<number> &values,
1898 const bool elide_zero_values)
1900 Assert(col_indices.size() == values.size(),
1915template <
typename MatrixType>
1916template <
typename number>
1919 const size_type n_cols,
1920 const size_type *col_indices,
1921 const number *values,
1922 const bool elide_zero_values,
1923 const bool col_indices_are_sorted)
1925 prepare_add_operation();
1930 if (col_indices_are_sorted ==
true)
1935 size_type before = col_indices[0];
1936 for (size_type i = 1; i < n_cols; ++i)
1937 if (col_indices[i] <= before)
1940 ExcMessage(
"Flag col_indices_are_sorted is set, but "
1941 "indices appear to not be sorted."));
1944 before = col_indices[i];
1946 const std::pair<unsigned int, size_type> row_index =
1947 this->row_block_indices.global_to_local(row);
1949 if (this->n_block_cols() > 1)
1951 const size_type *first_block =
1953 col_indices + n_cols,
1954 this->column_block_indices.block_start(1));
1956 const size_type n_zero_block_indices = first_block - col_indices;
1957 block(row_index.first, 0)
1958 .add(row_index.second,
1959 n_zero_block_indices,
1963 col_indices_are_sorted);
1965 if (n_zero_block_indices < n_cols)
1967 n_cols - n_zero_block_indices,
1969 values + n_zero_block_indices,
1975 block(row_index.first, 0)
1976 .add(row_index.second,
1981 col_indices_are_sorted);
1988 std::lock_guard<std::mutex> lock(temporary_data.mutex);
1990 if (temporary_data.column_indices.size() < this->n_block_cols())
1992 temporary_data.column_indices.resize(this->n_block_cols());
1993 temporary_data.column_values.resize(this->n_block_cols());
1994 temporary_data.counter_within_block.resize(this->n_block_cols());
2007 if (temporary_data.column_indices[0].size() < n_cols)
2009 for (
unsigned int i = 0; i < this->n_block_cols(); ++i)
2011 temporary_data.column_indices[i].resize(n_cols);
2012 temporary_data.column_values[i].resize(n_cols);
2018 for (
unsigned int i = 0; i < this->n_block_cols(); ++i)
2019 temporary_data.counter_within_block[i] = 0;
2030 for (size_type j = 0; j < n_cols; ++j)
2032 number
value = values[j];
2034 if (value == number() && elide_zero_values ==
true)
2037 const std::pair<unsigned int, size_type> col_index =
2038 this->column_block_indices.global_to_local(col_indices[j]);
2040 const size_type local_index =
2041 temporary_data.counter_within_block[col_index.first]++;
2043 temporary_data.column_indices[col_index.first][local_index] =
2045 temporary_data.column_values[col_index.first][local_index] =
value;
2051 size_type length = 0;
2052 for (
unsigned int i = 0; i < this->n_block_cols(); ++i)
2053 length += temporary_data.counter_within_block[i];
2062 const std::pair<unsigned int, size_type> row_index =
2063 this->row_block_indices.global_to_local(row);
2064 for (
unsigned int block_col = 0; block_col < n_block_cols(); ++block_col)
2066 if (temporary_data.counter_within_block[block_col] == 0)
2069 block(row_index.first, block_col)
2070 .add(row_index.second,
2071 temporary_data.counter_within_block[block_col],
2072 temporary_data.column_indices[block_col].data(),
2073 temporary_data.column_values[block_col].data(),
2075 col_indices_are_sorted);
2081template <
typename MatrixType>
2088 prepare_add_operation();
2093 using MatrixTraits =
typename MatrixType::Traits;
2094 if ((MatrixTraits::zero_addition_can_be_elided ==
true) && (factor == 0))
2097 for (
unsigned int row = 0; row < n_block_rows(); ++row)
2098 for (
unsigned int col = 0; col < n_block_cols(); ++col)
2101 block(row, col).add(factor,
matrix.block(row, col));
2106template <
typename MatrixType>
2109 const size_type j)
const
2111 const std::pair<unsigned int, size_type>
2112 row_index = row_block_indices.global_to_local(i),
2113 col_index = column_block_indices.global_to_local(j);
2114 return block(row_index.first, col_index.first)(row_index.second,
2120template <
typename MatrixType>
2124 const std::pair<unsigned int, size_type>
2125 row_index = row_block_indices.global_to_local(i),
2126 col_index = column_block_indices.global_to_local(j);
2127 return block(row_index.first, col_index.first)
2128 .el(row_index.second, col_index.second);
2133template <
typename MatrixType>
2139 const std::pair<unsigned int, size_type>
index =
2140 row_block_indices.global_to_local(i);
2146template <
typename MatrixType>
2150 for (
unsigned int r = 0; r < n_block_rows(); ++r)
2151 for (
unsigned int c = 0; c < n_block_cols(); ++c)
2152 block(r, c).compress(operation);
2157template <
typename MatrixType>
2164 for (
unsigned int r = 0; r < n_block_rows(); ++r)
2165 for (
unsigned int c = 0; c < n_block_cols(); ++c)
2166 block(r, c) *= factor;
2173template <
typename MatrixType>
2181 const value_type factor_inv = 1. / factor;
2183 for (
unsigned int r = 0; r < n_block_rows(); ++r)
2184 for (
unsigned int c = 0; c < n_block_cols(); ++c)
2185 block(r, c) *= factor_inv;
2192template <
typename MatrixType>
2196 return this->row_block_indices;
2201template <
typename MatrixType>
2205 return this->column_block_indices;
2210template <
typename MatrixType>
2211template <
typename BlockVectorType>
2214 const BlockVectorType &src)
const
2216 Assert(dst.n_blocks() == n_block_rows(),
2218 Assert(src.n_blocks() == n_block_cols(),
2221 for (size_type row = 0; row < n_block_rows(); ++row)
2223 block(row, 0).vmult(dst.block(row), src.block(0));
2224 for (size_type col = 1; col < n_block_cols(); ++col)
2225 block(row, col).vmult_add(dst.block(row), src.block(col));
2231template <
typename MatrixType>
2232template <
typename BlockVectorType,
typename VectorType>
2236 const BlockVectorType &src)
const
2239 Assert(src.n_blocks() == n_block_cols(),
2242 block(0, 0).vmult(dst, src.block(0));
2243 for (size_type col = 1; col < n_block_cols(); ++col)
2244 block(0, col).vmult_add(dst, src.block(col));
2249template <
typename MatrixType>
2250template <
typename BlockVectorType,
typename VectorType>
2253 const VectorType &src)
const
2255 Assert(dst.n_blocks() == n_block_rows(),
2259 for (size_type row = 0; row < n_block_rows(); ++row)
2260 block(row, 0).vmult(dst.block(row), src);
2265template <
typename MatrixType>
2266template <
typename VectorType>
2270 const VectorType &src)
const
2275 block(0, 0).vmult(dst, src);
2280template <
typename MatrixType>
2281template <
typename BlockVectorType>
2284 const BlockVectorType &src)
const
2286 Assert(dst.n_blocks() == n_block_rows(),
2288 Assert(src.n_blocks() == n_block_cols(),
2291 for (
unsigned int row = 0; row < n_block_rows(); ++row)
2292 for (
unsigned int col = 0; col < n_block_cols(); ++col)
2293 block(row, col).vmult_add(dst.block(row), src.block(col));
2298template <
typename MatrixType>
2299template <
typename BlockVectorType>
2302 BlockVectorType &dst,
2303 const BlockVectorType &src)
const
2305 Assert(dst.n_blocks() == n_block_cols(),
2307 Assert(src.n_blocks() == n_block_rows(),
2312 for (
unsigned int row = 0; row < n_block_rows(); ++row)
2314 for (
unsigned int col = 0; col < n_block_cols(); ++col)
2315 block(row, col).Tvmult_add(dst.block(col), src.block(row));
2321template <
typename MatrixType>
2322template <
typename BlockVectorType,
typename VectorType>
2325 const VectorType &src)
const
2327 Assert(dst.n_blocks() == n_block_cols(),
2333 for (
unsigned int col = 0; col < n_block_cols(); ++col)
2334 block(0, col).Tvmult_add(dst.block(col), src);
2339template <
typename MatrixType>
2340template <
typename BlockVectorType,
typename VectorType>
2344 const BlockVectorType &src)
const
2347 Assert(src.n_blocks() == n_block_rows(),
2350 block(0, 0).Tvmult(dst, src.block(0));
2352 for (size_type row = 1; row < n_block_rows(); ++row)
2353 block(row, 0).Tvmult_add(dst, src.block(row));
2358template <
typename MatrixType>
2359template <
typename VectorType>
2363 const VectorType &src)
const
2368 block(0, 0).Tvmult(dst, src);
2373template <
typename MatrixType>
2374template <
typename BlockVectorType>
2377 const BlockVectorType &src)
const
2379 Assert(dst.n_blocks() == n_block_cols(),
2381 Assert(src.n_blocks() == n_block_rows(),
2384 for (
unsigned int row = 0; row < n_block_rows(); ++row)
2385 for (
unsigned int col = 0; col < n_block_cols(); ++col)
2386 block(row, col).Tvmult_add(dst.block(col), src.block(row));
2391template <
typename MatrixType>
2392template <
typename BlockVectorType>
2397 Assert(v.n_blocks() == n_block_rows(),
2400 value_type norm_sqr = 0;
2401 for (
unsigned int row = 0; row < n_block_rows(); ++row)
2402 for (
unsigned int col = 0; col < n_block_cols(); ++col)
2404 norm_sqr += block(row, col).matrix_norm_square(v.block(row));
2407 block(row, col).matrix_scalar_product(v.block(row), v.block(col));
2413template <
typename MatrixType>
2417 value_type norm_sqr = 0;
2421 for (
unsigned int row = 0; row < n_block_rows(); ++row)
2423 for (
unsigned int col = 0; col < n_block_cols(); ++col)
2425 const value_type block_norm = block(row, col).frobenius_norm();
2426 norm_sqr += block_norm * block_norm;
2435template <
typename MatrixType>
2436template <
typename BlockVectorType>
2439 const BlockVectorType &u,
2440 const BlockVectorType &v)
const
2442 Assert(u.n_blocks() == n_block_rows(),
2444 Assert(v.n_blocks() == n_block_cols(),
2447 value_type result = 0;
2448 for (
unsigned int row = 0; row < n_block_rows(); ++row)
2449 for (
unsigned int col = 0; col < n_block_cols(); ++col)
2451 block(row, col).matrix_scalar_product(u.block(row), v.block(col));
2457template <
typename MatrixType>
2458template <
typename BlockVectorType>
2461 const BlockVectorType &x,
2462 const BlockVectorType &b)
const
2464 Assert(dst.n_blocks() == n_block_rows(),
2466 Assert(
b.n_blocks() == n_block_rows(),
2468 Assert(x.n_blocks() == n_block_cols(),
2484 for (
unsigned int row = 0; row < n_block_rows(); ++row)
2486 block(row, 0).residual(dst.block(row), x.block(0),
b.block(row));
2488 for (size_type i = 0; i < dst.block(row).size(); ++i)
2489 dst.block(row)(i) = -dst.block(row)(i);
2491 for (
unsigned int col = 1; col < n_block_cols(); ++col)
2492 block(row, col).vmult_add(dst.block(row), x.block(col));
2494 for (size_type i = 0; i < dst.block(row).size(); ++i)
2495 dst.block(row)(i) = -dst.block(row)(i);
2499 for (size_type row = 0; row < n_block_rows(); ++row)
2500 res += dst.block(row).norm_sqr();
2506template <
typename MatrixType>
2509 const bool alternative_output)
const
2511 for (
unsigned int row = 0; row < n_block_rows(); ++row)
2512 for (
unsigned int col = 0; col < n_block_cols(); ++col)
2514 if (!alternative_output)
2515 out <<
"Block (" << row <<
", " << col <<
')' << std::endl;
2517 block(row, col).print(out, alternative_output);
2523template <
typename MatrixType>
2527 return const_iterator(
this, 0);
2532template <
typename MatrixType>
2536 return const_iterator(
this, m());
2541template <
typename MatrixType>
2546 return const_iterator(
this, r);
2551template <
typename MatrixType>
2556 return const_iterator(
this, r + 1);
2561template <
typename MatrixType>
2565 return iterator(
this, 0);
2570template <
typename MatrixType>
2574 return iterator(
this, m());
2579template <
typename MatrixType>
2584 return iterator(
this, r);
2589template <
typename MatrixType>
2594 return iterator(
this, r + 1);
2599template <
typename MatrixType>
2603 std::vector<size_type> row_sizes(this->n_block_rows());
2604 std::vector<size_type> col_sizes(this->n_block_cols());
2608 for (
unsigned int r = 0; r < this->n_block_rows(); ++r)
2609 row_sizes[r] = sub_objects[r][0]->m();
2613 for (
unsigned int c = 1; c < this->n_block_cols(); ++c)
2614 for (
unsigned int r = 0; r < this->n_block_rows(); ++r)
2615 Assert(row_sizes[r] == sub_objects[r][c]->m(),
2616 ExcIncompatibleRowNumbers(r, 0, r, c));
2620 this->row_block_indices.reinit(row_sizes);
2624 for (
unsigned int c = 0; c < this->n_block_cols(); ++c)
2625 col_sizes[c] = sub_objects[0][c]->n();
2626 for (
unsigned int r = 1; r < this->n_block_rows(); ++r)
2627 for (
unsigned int c = 0; c < this->n_block_cols(); ++c)
2628 Assert(col_sizes[c] == sub_objects[r][c]->n(),
2629 ExcIncompatibleRowNumbers(0, c, r, c));
2633 this->column_block_indices.reinit(col_sizes);
2638template <
typename MatrixType>
2642 for (
unsigned int row = 0; row < n_block_rows(); ++row)
2643 for (
unsigned int col = 0; col < n_block_cols(); ++col)
2644 block(row, col).prepare_add();
2649template <
typename MatrixType>
2653 for (
unsigned int row = 0; row < n_block_rows(); ++row)
2654 for (
unsigned int col = 0; col < n_block_cols(); ++col)
2655 block(row, col).prepare_set();
void Tvmult_nonblock_nonblock(VectorType &dst, const VectorType &src) const
void vmult_nonblock_nonblock(VectorType &dst, const VectorType &src) const
void add(const size_type row, const std::vector< size_type > &col_indices, const std::vector< number > &values, const bool elide_zero_values=true)
void add(const std::vector< size_type > &row_indices, const std::vector< size_type > &col_indices, const FullMatrix< number > &full_matrix, const bool elide_zero_values=true)
void add(const size_type row, const size_type n_cols, const size_type *col_indices, const number *values, const bool elide_zero_values=true, const bool col_indices_are_sorted=false)
void print(std::ostream &out, const bool alternative_output=false) const
friend class BlockMatrixIterators::Accessor
const_iterator end() const
BlockIndices column_block_indices
BlockMatrixBase & operator*=(const value_type factor)
value_type matrix_norm_square(const BlockVectorType &v) const
void Tvmult_block_block(BlockVectorType &dst, const BlockVectorType &src) const
const value_type & const_reference
void Tvmult_nonblock_block(VectorType &dst, const BlockVectorType &src) const
unsigned int n_block_rows() const
value_type operator()(const size_type i, const size_type j) const
value_type el(const size_type i, const size_type j) const
const_iterator begin() const
real_type frobenius_norm() const
void vmult_block_block(BlockVectorType &dst, const BlockVectorType &src) const
void compress(VectorOperation::values operation)
void vmult_add(BlockVectorType &dst, const BlockVectorType &src) const
Table< 2, SmartPointer< BlockType, BlockMatrixBase< MatrixType > > > sub_objects
void Tvmult_add(BlockVectorType &dst, const BlockVectorType &src) const
typename BlockType::value_type value_type
void prepare_add_operation()
void vmult_nonblock_block(VectorType &dst, const BlockVectorType &src) const
value_type residual(BlockVectorType &dst, const BlockVectorType &x, const BlockVectorType &b) const
BlockMatrixBase()=default
void set(const size_type row, const size_type n_cols, const size_type *col_indices, const number *values, const bool elide_zero_values=false)
void prepare_set_operation()
unsigned int n_block_cols() const
const value_type * const_pointer
TemporaryData temporary_data
const BlockIndices & get_row_indices() const
void set(const size_type i, const size_type j, const value_type value)
BlockMatrixBase & copy_from(const BlockMatrixType &source)
std::size_t memory_consumption() const
void add(const value_type factor, const BlockMatrixBase< MatrixType > &matrix)
const BlockType & block(const unsigned int row, const unsigned int column) const
typename numbers::NumberTraits< value_type >::real_type real_type
BlockIndices row_block_indices
~BlockMatrixBase() override
BlockType & block(const unsigned int row, const unsigned int column)
value_type matrix_scalar_product(const BlockVectorType &u, const BlockVectorType &v) const
const BlockIndices & get_column_indices() const
void set(const std::vector< size_type > &indices, const FullMatrix< number > &full_matrix, const bool elide_zero_values=false)
void add(const std::vector< size_type > &indices, const FullMatrix< number > &full_matrix, const bool elide_zero_values=true)
void add(const size_type i, const size_type j, const value_type value)
void set(const size_type row, const std::vector< size_type > &col_indices, const std::vector< number > &values, const bool elide_zero_values=false)
value_type diag_element(const size_type i) const
void vmult_block_nonblock(BlockVectorType &dst, const VectorType &src) const
iterator begin(const size_type r)
const_iterator begin(const size_type r) const
BlockMatrixBase & operator/=(const value_type factor)
void Tvmult_block_nonblock(BlockVectorType &dst, const VectorType &src) const
iterator end(const size_type r)
const_iterator end(const size_type r) const
void set(const std::vector< size_type > &row_indices, const std::vector< size_type > &col_indices, const FullMatrix< number > &full_matrix, const bool elide_zero_values=false)
unsigned int block_row() const
unsigned int block_column() const
typename BlockMatrixType::value_type value_type
Accessor(BlockMatrixType *m, const size_type row, const size_type col)
BlockMatrixType MatrixType
BlockMatrixType::BlockType::iterator base_iterator
bool operator==(const Accessor &a) const
void set_value(value_type newval) const
typename BlockMatrixType::value_type value_type
const BlockMatrixType MatrixType
typename BlockMatrixType::value_type value_type
bool operator==(const Accessor &a) const
Accessor(const Accessor< BlockMatrixType, false > &)
const BlockMatrixType * matrix
BlockMatrixType::BlockType::const_iterator base_iterator
Accessor(const BlockMatrixType *m, const size_type row, const size_type col)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
__global__ void set(Number *val, const Number s, const size_type N)
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
static ::ExceptionBase & ExcIncompatibleColNumbers(int arg1, int arg2, int arg3, int arg4)
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcIncompatibleRowNumbers(int arg1, int arg2, int arg3, int arg4)
static ::ExceptionBase & ExcIteratorPastEnd()
#define AssertIsFinite(number)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDivideByZero()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcNotQuadratic()
static ::ExceptionBase & ExcMessage(std::string arg1)
@ matrix
Contents is actually a matrix.
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
VectorType::value_type * begin(VectorType &V)
Iterator lower_bound(Iterator first, Iterator last, const T &val)
static const unsigned int invalid_unsigned_int
const types::global_dof_index invalid_size_type
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
unsigned int global_dof_index
std::vector< std::vector< size_type > > column_indices
std::vector< std::vector< value_type > > column_values
TemporaryData & operator=(const TemporaryData &)
std::vector< size_type > counter_within_block