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