Reference documentation for deal.II version Git 05e4468 2017-09-21 10:18:23 +0200
block_vector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 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_block_vector_h
17 #define dealii_block_vector_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/exceptions.h>
22 #include <deal.II/lac/block_indices.h>
23 #include <deal.II/lac/block_vector_base.h>
24 #include <deal.II/lac/vector_type_traits.h>
25 
26 #include <cstdio>
27 #include <vector>
28 
29 DEAL_II_NAMESPACE_OPEN
30 
31 
32 #ifdef DEAL_II_WITH_TRILINOS
33 namespace TrilinosWrappers
34 {
35  namespace MPI
36  {
37  class BlockVector;
38  }
39 }
40 #endif
41 
42 
64 template <typename Number>
65 class BlockVector : public BlockVectorBase<Vector<Number> >
66 {
67 public:
72 
76  typedef typename BaseClass::BlockType BlockType;
77 
81  typedef typename BaseClass::value_type value_type;
82  typedef typename BaseClass::real_type real_type;
83  typedef typename BaseClass::pointer pointer;
84  typedef typename BaseClass::const_pointer const_pointer;
85  typedef typename BaseClass::reference reference;
86  typedef typename BaseClass::const_reference const_reference;
87  typedef typename BaseClass::size_type size_type;
88  typedef typename BaseClass::iterator iterator;
90 
101  explicit BlockVector (const unsigned int n_blocks = 0,
102  const size_type block_size = 0);
103 
108  BlockVector (const BlockVector<Number> &V);
109 
110 
115  BlockVector (BlockVector<Number> &&/*v*/) = default;
116 
129  template <typename OtherNumber>
130  explicit
132 
133 #ifdef DEAL_II_WITH_TRILINOS
134 
139 
140 #endif
141 
145  BlockVector (const std::vector<size_type> &block_sizes);
146 
152 
162  template <typename InputIterator>
163  BlockVector (const std::vector<size_type> &block_sizes,
164  const InputIterator first,
165  const InputIterator end);
166 
170  ~BlockVector () = default;
171 
182  void compress (::VectorOperation::values operation
184 
189  BlockVector &operator= (const value_type s);
190 
197 
203 
208  template <class Number2>
211 
216  operator= (const Vector<Number> &V);
217 
218 #ifdef DEAL_II_WITH_TRILINOS
219 
225 #endif
226 
239  void reinit (const unsigned int n_blocks,
240  const size_type block_size = 0,
241  const bool omit_zeroing_entries = false);
242 
259  void reinit (const std::vector<size_type> &block_sizes,
260  const bool omit_zeroing_entries=false);
261 
271  void reinit (const BlockIndices &block_indices,
272  const bool omit_zeroing_entries=false);
273 
287  template <typename Number2>
288  void reinit (const BlockVector<Number2> &V,
289  const bool omit_zeroing_entries=false);
290 
295  template <class BlockVector2>
296  void scale (const BlockVector2 &v);
297 
309  void swap (BlockVector<Number> &v);
310 
316  void print (const char *format = nullptr) const DEAL_II_DEPRECATED;
317 
321  void print (std::ostream &out,
322  const unsigned int precision = 3,
323  const bool scientific = true,
324  const bool across = true) const;
325 
331  void block_write (std::ostream &out) const;
332 
344  void block_read (std::istream &in);
345 
356 };
357 
360 #ifndef DOXYGEN
361 /*----------------------- Inline functions ----------------------------------*/
362 
363 
364 
365 template <typename Number>
366 template <typename InputIterator>
367 BlockVector<Number>::BlockVector (const std::vector<size_type> &block_sizes,
368  const InputIterator first,
369  const InputIterator end)
370 {
371  // first set sizes of blocks, but
372  // don't initialize them as we will
373  // copy elements soon
374  (void)end;
375  reinit (block_sizes, true);
376  InputIterator start = first;
377  for (size_type b=0; b<block_sizes.size(); ++b)
378  {
379  InputIterator end = start;
380  std::advance (end, static_cast<signed int>(block_sizes[b]));
381  std::copy (start, end, this->block(b).begin());
382  start = end;
383  };
385 }
386 
387 
388 
389 template <typename Number>
390 inline
392 BlockVector<Number>::operator= (const value_type s)
393 {
394 
395  AssertIsFinite(s);
396 
398  return *this;
399 }
400 
401 
402 
403 template <typename Number>
404 inline
407 {
408  reinit (v, true);
410  return *this;
411 }
412 
413 
414 
415 template <typename Number>
416 inline
419 {
421  return *this;
422 }
423 
424 
425 
426 template <typename Number>
427 template <typename Number2>
428 inline
431 {
432  reinit (v, true);
434  return *this;
435 }
436 
437 template <typename Number>
438 inline
440 {
441  for (size_type i=0; i<this->n_blocks(); ++i)
442  this->components[i].compress(operation);
443 }
444 
445 
446 
447 template <typename Number>
448 template <class BlockVector2>
449 void BlockVector<Number>::scale (const BlockVector2 &v)
450 {
451  BaseClass::scale (v);
452 }
453 
454 #endif // DOXYGEN
455 
456 
465 template <typename Number>
466 inline
469 {
470  u.swap (v);
471 }
472 
473 
474 namespace internal
475 {
476  namespace LinearOperator
477  {
478  template <typename> class ReinitHelper;
479 
484  template <typename number>
485  class ReinitHelper<BlockVector<number> >
486  {
487  public:
488  template <typename Matrix>
489  static
490  void reinit_range_vector (const Matrix &matrix,
492  bool omit_zeroing_entries)
493  {
494  v.reinit(matrix.get_row_indices(), omit_zeroing_entries);
495  }
496 
497  template <typename Matrix>
498  static
499  void reinit_domain_vector(const Matrix &matrix,
501  bool omit_zeroing_entries)
502  {
503  v.reinit(matrix.get_column_indices(), omit_zeroing_entries);
504  }
505  };
506 
507  } /* namespace LinearOperator */
508 } /* namespace internal */
509 
510 
516 template <typename Number>
517 struct is_serial_vector< BlockVector< Number > > : std::true_type
518 {
519 };
520 
521 DEAL_II_NAMESPACE_CLOSE
522 
523 #endif
BaseClass::value_type value_type
Definition: block_vector.h:81
BlockVector & operator=(const value_type s)
void block_write(std::ostream &out) const
STL namespace.
void scale(const BlockVector2 &v)
void swap(BlockVector< Number > &u, BlockVector< Number > &v)
Definition: block_vector.h:467
void scale(const BlockVector2 &v)
BlockVectorBase< Vector< Number > > BaseClass
Definition: block_vector.h:71
~BlockVector()=default
void print(const char *format=nullptr) const 1
static::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
#define Assert(cond, exc)
Definition: exceptions.h:337
BlockType::real_type real_type
void compress(::VectorOperation::values operation=::VectorOperation::unknown)
#define DeclException0(Exception0)
Definition: exceptions.h:570
void reinit(const unsigned int n_blocks, const size_type block_size=0, const bool omit_zeroing_entries=false)
std::vector< Vector< Number > > components
void swap(BlockVector< Number > &v)
BlockVector(const unsigned int n_blocks=0, const size_type block_size=0)
BaseClass::BlockType BlockType
Definition: block_vector.h:76
BlockType & block(const unsigned int i)
BlockVectorBase & operator=(const value_type s)
#define AssertIsFinite(number)
Definition: exceptions.h:1211
void block_read(std::istream &in)