Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
block_sparse_matrix.templates.h
1 // ---------------------------------------------------------------------
2 // @f$Id: block_sparse_matrix.templates.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2000 - 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_templates_h
18 #define __deal2__block_sparse_matrix_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.h>
24 
25 DEAL_II_NAMESPACE_OPEN
26 
27 
28 template <typename number>
30 {}
31 
32 
33 
34 template <typename number>
37 {
38  reinit (sparsity);
39 }
40 
41 
42 
43 template <typename number>
45 {
46  // delete previous content of
47  // the subobjects array
48  clear ();
49  sparsity_pattern = 0;
50 }
51 
52 
53 
54 template <typename number>
58 {
59  Assert (this->row_block_indices == m.row_block_indices,
60  ExcBlockDimensionMismatch());
61  Assert (this->column_block_indices == m.column_block_indices,
62  ExcBlockDimensionMismatch());
63 
64  // this operator does not do
65  // anything except than checking
66  // whether the base objects want to
67  // do something
68  for (size_type r=0; r<this->n_block_rows(); ++r)
69  for (size_type c=0; c<this->n_block_cols(); ++c)
70  this->block(r,c) = m.block(r,c);
71 
72  return *this;
73 }
74 
75 
76 
77 template <typename number>
78 void
80 {
82  sparsity_pattern = 0;
83 }
84 
85 
86 
87 template <typename number>
88 void
90 reinit (const BlockSparsityPattern &sparsity)
91 {
92  // first delete previous content of
93  // the subobjects array and delete
94  // the table completely
95  clear ();
96 
97  // then associate new sparsity
98  // pattern and resize
99  sparsity_pattern = &sparsity;
100 
101  this->row_block_indices = sparsity.row_indices;
102  this->column_block_indices = sparsity.column_indices;
103 
104  this->sub_objects.reinit (sparsity.n_block_rows(),
105  sparsity.n_block_cols());
106 
107  // and reinitialize the blocks
108  for (size_type r=0; r<this->n_block_rows(); ++r)
109  for (size_type c=0; c<this->n_block_cols(); ++c)
110  {
111  BlockType *p = new SparseMatrix<number>();
112  p->reinit (sparsity.block(r,c));
113  this->sub_objects[r][c] = p;
114  }
115 }
116 
117 
118 
119 template <typename number>
120 bool
122 {
123  for (size_type r=0; r<this->n_block_rows(); ++r)
124  for (size_type c=0; c<this->n_block_cols(); ++c)
125  if (this->block(r,c).empty () == false)
126  return false;
127 
128  return true;
129 }
130 
131 
132 
133 
134 template <typename number>
135 typename BlockSparseMatrix<number>::size_type
136 BlockSparseMatrix<number>::get_row_length (const size_type row) const
137 {
138  return sparsity_pattern->row_length(row);
139 }
140 
141 
142 
143 template <typename number>
144 typename BlockSparseMatrix<number>::size_type
146 {
147  return sparsity_pattern->n_nonzero_elements ();
148 }
149 
150 
151 
152 template <typename number>
153 typename BlockSparseMatrix<number>::size_type
155 {
156  size_type count = 0;
157  for (size_type i=0; i<this->n_block_rows(); ++i)
158  for (size_type j=0; j<this->n_block_cols(); ++j)
159  count += this->sub_objects[i][j]->n_actually_nonzero_elements (threshold);
160 
161  return count;
162 }
163 
164 
165 
166 template <typename number>
167 const BlockSparsityPattern &
169 {
170  return *sparsity_pattern;
171 }
172 
173 
174 
175 template <typename number>
176 void
178 print_formatted (std::ostream &out,
179  const unsigned int precision,
180  const bool scientific,
181  const unsigned int width,
182  const char *zero_string,
183  const double denominator) const
184 {
185  for (size_type r=0; r<this->n_block_rows(); ++r)
186  for (size_type c=0; c<this->n_block_cols(); ++c)
187  {
188  out << "Component (" << r << "," << c << ")" << std::endl;
189  this->block(r,c).print_formatted (out, precision, scientific,
190  width, zero_string, denominator);
191  }
192 }
193 
194 
195 
196 template <typename number>
197 std::size_t
199 {
200  std::size_t mem = sizeof(*this);
201  mem += MemoryConsumption::memory_consumption (this->sub_objects);
202  for (size_type r=0; r<this->n_block_rows(); ++r)
203  for (size_type c=0; c<this->n_block_cols(); ++c)
204  mem += MemoryConsumption::memory_consumption(*this->sub_objects[r][c]);
205 
206  return mem;
207 }
208 
209 
210 
211 DEAL_II_NAMESPACE_CLOSE
212 
213 #endif // ifdef block_sparse_matrix_templates_h
std::size_t memory_consumption() const
size_type n_nonzero_elements() const
SparsityPatternBase & block(const size_type row, const size_type column)
size_type n_actually_nonzero_elements(const double threshold=0.0) const
#define Assert(cond, exc)
Definition: exceptions.h:299
std::size_t memory_consumption(const T &t)
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
void print_formatted(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const unsigned int width=0, const char *zero_string=" ", const double denominator=1.) const
size_type get_row_length(const size_type row) const
virtual void reinit(const SparsityPattern &sparsity)
BaseClass::BlockType BlockType
virtual void reinit(const BlockSparsityPattern &sparsity)
BlockSparseMatrix & operator=(const BlockSparseMatrix &)
const BlockSparsityPattern & get_sparsity_pattern() const
BlockType & block(const unsigned int row, const unsigned int column)