Reference documentation for deal.II version 8.1.0
block_sparse_matrix_ez.templates.h
1 // ---------------------------------------------------------------------
2 // @f$Id: block_sparse_matrix_ez.templates.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2002 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__block_sparse_matrix_ez_templates_h
18 #define __deal2__block_sparse_matrix_ez_templates_h
19 
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/memory_consumption.h>
23 #include <deal.II/lac/block_sparse_matrix_ez.h>
24 
26 
27 
28 template <typename number>
30 {}
31 
32 
33 
34 template <typename number>
36 BlockSparseMatrixEZ (const unsigned int rows,
37  const unsigned int cols)
38  :
39  row_indices (rows, 0),
40  column_indices (cols, 0)
41 {}
42 
43 
44 
45 // template <typename number>
46 // BlockSparseMatrixEZ<number>::~BlockSparseMatrixEZ ()
47 // {
48 // // delete previous content of
49 // // the subobjects array
50 // clear ();
51 // };
52 
53 
54 
55 template <typename number>
59 {
64  // this operator does not do
65  // anything except than checking
66  // whether the base objects want to
67  // do something
68  for (unsigned int r=0; r<n_block_rows(); ++r)
69  for (unsigned int c=0; c<n_block_cols(); ++c)
70  block(r,c) = m.block(r,c);
71  return *this;
72 }
73 
74 
75 
76 template <typename number>
79 {
81 
82  for (unsigned int r=0; r<n_block_rows(); ++r)
83  for (unsigned int c=0; c<n_block_cols(); ++c)
84  block(r,c) = 0;
85 
86  return *this;
87 }
88 
89 
90 
91 template <typename number>
94  :
95  Subscriptor (m),
98  blocks(m.blocks)
99 {}
100 
101 
102 
103 template <typename number>
104 void
105 BlockSparseMatrixEZ<number>::reinit (const unsigned int rows,
106  const unsigned int cols)
107 {
108  row_indices.reinit(rows, 0);
109  column_indices.reinit(cols, 0);
110  blocks.reinit(rows, cols);
111 }
112 
113 
114 
115 template <typename number>
116 void
118 {
119  row_indices.reinit(0, 0);
120  column_indices.reinit(0, 0);
121  blocks.reinit(0, 0);
122 }
123 
124 
125 
126 template <typename number>
127 bool
129 {
130  for (unsigned int r=0; r<n_block_rows(); ++r)
131  for (unsigned int c=0; c<n_block_cols(); ++c)
132  if (block(r,c).empty () == false)
133  return false;
134  return true;
135 }
136 
137 
138 
139 template <typename number>
140 void
142 {
143  const unsigned int rows = n_block_rows();
144  const unsigned int columns = n_block_cols();
145  std::vector<size_type> row_sizes (rows);
146  std::vector<size_type> col_sizes (columns);
147 
148  // first find out the row sizes
149  // from the first block column
150  for (unsigned int r=0; r<rows; ++r)
151  row_sizes[r] = blocks[r][0].m();
152  // then check that the following
153  // block columns have the same
154  // sizes
155  for (unsigned int c=1; c<columns; ++c)
156  for (unsigned int r=0; r<rows; ++r)
157  Assert (row_sizes[r] == blocks[r][c].m(),
158  ExcDimensionMismatch (row_sizes[r], blocks[r][c].m()));
159 
160  // finally initialize the row
161  // indices with this array
162  row_indices.reinit (row_sizes);
163 
164 
165  // then do the same with the columns
166  for (unsigned int c=0; c<columns; ++c)
167  col_sizes[c] = blocks[0][c].n();
168  for (unsigned int r=1; r<rows; ++r)
169  for (unsigned int c=0; c<columns; ++c)
170  Assert (col_sizes[c] == blocks[r][c].n(),
171  ExcDimensionMismatch (col_sizes[c], blocks[r][c].n()));
172 
173  // finally initialize the row
174  // indices with this array
175  column_indices.reinit (col_sizes);
176 }
177 
178 
179 
180 
181 // template <typename number>
182 // unsigned int
183 // BlockSparseMatrixEZ<number>::n_nonzero_elements () const
184 // {
185 // return sparsity_pattern->n_nonzero_elements ();
186 // };
187 
188 
189 
190 // template <typename number>
191 // unsigned int
192 // BlockSparseMatrixEZ<number>::n_actually_nonzero_elements () const
193 // {
194 // unsigned int count = 0;
195 // for (unsigned int i=0; i<rows; ++i)
196 // for (unsigned int j=0; j<columns; ++j)
197 // count += sub_objects[i][j]->n_actually_nonzero_elements ();
198 // return count;
199 // };
200 
201 
202 
203 // template <typename number>
204 // std::size_t
205 // BlockSparseMatrixEZ<number>::memory_consumption () const
206 // {
207 // std::size_t mem = sizeof(*this);
208 // mem += MemoryConsumption::memory_consumption (sub_objects);
209 // for (unsigned int r=0; r<rows; ++r)
210 // for (unsigned int c=0; c<columns; ++c)
211 // mem += MemoryConsumption::memory_consumption(*sub_objects[r][c]);
212 // return mem;
213 // };
214 
215 
216 
217 DEAL_II_NAMESPACE_CLOSE
218 
219 #endif // ifdef block_sparse_matrix_templates_h
void reinit(const TableIndices< N > &new_size, const bool fast=false)
Table< 2, SparseMatrixEZ< Number > > blocks
SparseMatrixEZ< Number > & block(const unsigned int row, const unsigned int column)
unsigned int n_block_rows() const
unsigned int n_block_cols() const
#define Assert(cond, exc)
Definition: exceptions.h:299
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
BlockSparseMatrixEZ & operator=(const BlockSparseMatrixEZ< Number > &)
::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
void reinit(const unsigned int n_block_rows, const unsigned int n_block_cols)