Reference documentation for deal.II version 8.5.1
diagonal_matrix.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2016 - 2017 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__diagonal_matrix_h
17 #define dealii__diagonal_matrix_h
18 
19 
20 #include <deal.II/lac/vector.h>
21 
22 DEAL_II_NAMESPACE_OPEN
23 
45 template <typename VectorType=Vector<double> >
47 {
48 public:
49  typedef typename VectorType::value_type value_type;
50  typedef typename VectorType::size_type size_type;
51 
56 
61  void reinit (const VectorType &vec);
62 
68  void compress (VectorOperation::values operation);
69 
74  VectorType &get_vector();
75 
79  void clear();
80 
84  const VectorType &get_vector() const;
85 
90  size_type m () const;
91 
96  size_type n () const;
97 
107  value_type operator()(const size_type i,
108  const size_type j) const;
109 
119  value_type &operator()(const size_type i,
120  const size_type j);
121 
133  template <typename number2>
134  void add (const size_type row,
135  const size_type n_cols,
136  const size_type *col_indices,
137  const number2 *values,
138  const bool elide_zero_values = true,
139  const bool col_indices_are_sorted = false);
140 
147  void add (const size_type i,
148  const size_type j,
149  const value_type value);
150 
154  void vmult (VectorType &dst,
155  const VectorType &src) const;
156 
162  void Tvmult (VectorType &dst,
163  const VectorType &src) const;
164 
170  void vmult_add (VectorType &dst,
171  const VectorType &src) const;
172 
178  void Tvmult_add (VectorType &dst,
179  const VectorType &src) const;
180 
184  std::size_t memory_consumption () const;
185 
186 private:
190  VectorType diagonal;
191 };
192 
193 /* ---------------------------------- Inline functions ------------------- */
194 
195 #ifndef DOXYGEN
196 
197 template <typename VectorType>
199  :
200  Subscriptor()
201 {}
202 
203 
204 
205 template <typename VectorType>
206 void
208 {
209  diagonal.reinit(0);
210 }
211 
212 
213 
214 template <typename VectorType>
215 std::size_t
217 {
218  return diagonal.memory_consumption();
219 }
220 
221 
222 
223 template <typename VectorType>
224 void
225 DiagonalMatrix<VectorType>::reinit(const VectorType &vec)
226 {
227  diagonal = vec;
228 }
229 
230 
231 
232 template <typename VectorType>
233 void
235 {
236  diagonal.compress(operation);
237 }
238 
239 
240 
241 template <typename VectorType>
242 VectorType &
244 {
245  return diagonal;
246 }
247 
248 
249 
250 template <typename VectorType>
251 const VectorType &
253 {
254  return diagonal;
255 }
256 
257 
258 
259 template <typename VectorType>
260 typename VectorType::size_type
262 {
263  return diagonal.size();
264 }
265 
266 
267 
268 template <typename VectorType>
269 typename VectorType::size_type
271 {
272  return diagonal.size();
273 }
274 
275 
276 
277 template <typename VectorType>
278 typename VectorType::value_type
280  const size_type j) const
281 {
282  Assert (i==j, ExcIndexRange(j,i,i+1));
283  (void) j;
284  return diagonal(i);
285 }
286 
287 
288 
289 template <typename VectorType>
290 typename VectorType::value_type &
292  const size_type j)
293 {
294  Assert (i==j, ExcIndexRange(j,i,i+1));
295  (void)j;
296  return diagonal(i);
297 }
298 
299 
300 
301 template <typename VectorType>
302 template <typename number2>
303 void
304 DiagonalMatrix<VectorType>::add (const size_type row,
305  const size_type n_cols,
306  const size_type *col_indices,
307  const number2 *values,
308  const bool ,
309  const bool )
310 {
311  for (size_type i=0; i<n_cols; ++i)
312  if (col_indices[i] == row)
313  diagonal(row) += values[i];
314 }
315 
316 
317 
318 template <typename VectorType>
319 void
320 DiagonalMatrix<VectorType>::add (const size_type i,
321  const size_type j,
322  const value_type value)
323 {
324  if (i == j)
325  diagonal(i) += value;
326 }
327 
328 
329 
330 template <typename VectorType>
331 void
332 DiagonalMatrix<VectorType>::vmult(VectorType &dst,
333  const VectorType &src) const
334 {
335  dst = src;
336  dst.scale(diagonal);
337 }
338 
339 
340 
341 template <typename VectorType>
342 void
343 DiagonalMatrix<VectorType>::Tvmult(VectorType &dst,
344  const VectorType &src) const
345 {
346  vmult(dst, src);
347 }
348 
349 
350 
351 template <typename VectorType>
352 void
354  const VectorType &src) const
355 {
356  VectorType tmp(src);
357  tmp.scale(diagonal);
358  dst += tmp;
359 }
360 
361 
362 
363 template <typename VectorType>
364 void
366  const VectorType &src) const
367 {
368  vmult_add(dst, src);
369 }
370 
371 
372 #endif
373 
374 DEAL_II_NAMESPACE_CLOSE
375 
376 #endif
std::size_t memory_consumption() const
VectorType & get_vector()
void Tvmult(VectorType &dst, const VectorType &src) const
void compress(VectorOperation::values operation)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
value_type operator()(const size_type i, const size_type j) const
void add(const size_type row, const size_type n_cols, const size_type *col_indices, const number2 *values, const bool elide_zero_values=true, const bool col_indices_are_sorted=false)
size_type n() const
void vmult(VectorType &dst, const VectorType &src) const
#define Assert(cond, exc)
Definition: exceptions.h:313
size_type m() const
VectorType diagonal
void reinit(const VectorType &vec)
void vmult_add(VectorType &dst, const VectorType &src) const
void Tvmult_add(VectorType &dst, const VectorType &src) const