| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2002 - 2024 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
#ifndef dealii_block_sparse_matrix_ez_templates_h |
| 16 |
#define dealii_block_sparse_matrix_ez_templates_h |
| 17 |
|
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/base/memory_consumption.h> |
| 22 |
|
| 23 |
#include <deal.II/lac/block_sparse_matrix_ez.h> |
| 24 |
|
| 25 |
DEAL_II_NAMESPACE_OPEN |
| 26 |
|
| 27 |
template <typename number> |
| 28 |
BlockSparseMatrixEZ<number>::BlockSparseMatrixEZ(const unsigned int rows, |
| 29 |
const unsigned int cols) |
| 30 |
: row_indices(rows, 0) |
| 31 |
, column_indices(cols, 0) |
| 32 |
{} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
// template <typename number> |
| 37 |
// BlockSparseMatrixEZ<number>::~BlockSparseMatrixEZ () |
| 38 |
// { |
| 39 |
// // delete previous content of |
| 40 |
// // the subobjects array |
| 41 |
// clear (); |
| 42 |
// }; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
template <typename number> |
| 47 |
BlockSparseMatrixEZ<number> & |
| 48 |
BlockSparseMatrixEZ<number>::operator=(const BlockSparseMatrixEZ<number> &m) |
| 49 |
{ |
| 50 |
Assert(n_block_rows() == m.n_block_rows(), |
| 51 |
ExcDimensionMismatch(n_block_rows(), m.n_block_rows())); |
| 52 |
Assert(n_block_cols() == m.n_block_cols(), |
| 53 |
ExcDimensionMismatch(n_block_cols(), m.n_block_cols())); |
| 54 |
// this operator does not do |
| 55 |
// anything except than checking |
| 56 |
// whether the base objects want to |
| 57 |
// do something |
| 58 |
for (unsigned int r = 0; r < n_block_rows(); ++r) |
| 59 |
for (unsigned int c = 0; c < n_block_cols(); ++c) |
| 60 |
block(r, c) = m.block(r, c); |
| 61 |
return *this; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
template <typename number> |
| 67 |
BlockSparseMatrixEZ<number> & |
| 68 |
BlockSparseMatrixEZ<number>::operator=(const double d) |
| 69 |
{ |
| 70 |
(void)d; |
| 71 |
Assert(d == 0, ExcScalarAssignmentOnlyForZeroValue()); |
| 72 |
|
| 73 |
for (unsigned int r = 0; r < n_block_rows(); ++r) |
| 74 |
for (unsigned int c = 0; c < n_block_cols(); ++c) |
| 75 |
block(r, c) = 0; |
| 76 |
|
| 77 |
return *this; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
template <typename number> |
| 83 |
BlockSparseMatrixEZ<number>::BlockSparseMatrixEZ( |
| 84 |
const BlockSparseMatrixEZ<number> &m) |
| 85 |
: EnableObserverPointer(m) |
| 86 |
, row_indices(m.row_indices) |
| 87 |
, column_indices(m.column_indices) |
| 88 |
, blocks(m.blocks) |
| 89 |
{} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
template <typename number> |
| 94 |
void |
| 95 |
BlockSparseMatrixEZ<number>::reinit(const unsigned int rows, |
| 96 |
const unsigned int cols) |
| 97 |
{ |
| 98 |
row_indices.reinit(rows, 0); |
| 99 |
column_indices.reinit(cols, 0); |
| 100 |
blocks.reinit(rows, cols); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
template <typename number> |
| 106 |
void |
| 107 |
BlockSparseMatrixEZ<number>::clear() |
| 108 |
{ |
| 109 |
row_indices.reinit(0, 0); |
| 110 |
column_indices.reinit(0, 0); |
| 111 |
blocks.reinit(0, 0); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
template <typename number> |
| 117 |
bool |
| 118 |
BlockSparseMatrixEZ<number>::empty() const |
| 119 |
{ |
| 120 |
for (unsigned int r = 0; r < n_block_rows(); ++r) |
| 121 |
for (unsigned int c = 0; c < n_block_cols(); ++c) |
| 122 |
if (block(r, c).empty() == false) |
| 123 |
return false; |
| 124 |
return true; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
template <typename number> |
| 130 |
void |
| 131 |
BlockSparseMatrixEZ<number>::collect_sizes() |
| 132 |
{ |
| 133 |
const unsigned int rows = n_block_rows(); |
| 134 |
const unsigned int columns = n_block_cols(); |
| 135 |
std::vector<size_type> row_sizes(rows); |
| 136 |
std::vector<size_type> col_sizes(columns); |
| 137 |
|
| 138 |
// first find out the row sizes |
| 139 |
// from the first block column |
| 140 |
for (unsigned int r = 0; r < rows; ++r) |
| 141 |
row_sizes[r] = blocks[r][0].m(); |
| 142 |
// then check that the following |
| 143 |
// block columns have the same |
| 144 |
// sizes |
| 145 |
for (unsigned int c = 1; c < columns; ++c) |
| 146 |
for (unsigned int r = 0; r < rows; ++r) |
| 147 |
Assert(row_sizes[r] == blocks[r][c].m(), |
| 148 |
ExcDimensionMismatch(row_sizes[r], blocks[r][c].m())); |
| 149 |
|
| 150 |
// finally initialize the row |
| 151 |
// indices with this array |
| 152 |
row_indices.reinit(row_sizes); |
| 153 |
|
| 154 |
|
| 155 |
// then do the same with the columns |
| 156 |
for (unsigned int c = 0; c < columns; ++c) |
| 157 |
col_sizes[c] = blocks[0][c].n(); |
| 158 |
for (unsigned int r = 1; r < rows; ++r) |
| 159 |
for (unsigned int c = 0; c < columns; ++c) |
| 160 |
Assert(col_sizes[c] == blocks[r][c].n(), |
| 161 |
ExcDimensionMismatch(col_sizes[c], blocks[r][c].n())); |
| 162 |
|
| 163 |
// finally initialize the row |
| 164 |
// indices with this array |
| 165 |
column_indices.reinit(col_sizes); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
DEAL_II_NAMESPACE_CLOSE |
| 171 |
|
| 172 |
#endif // ifdef block_sparse_matrix_templates_h |