Reference documentation for deal.II version 8.4.1
block_vector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2015 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 
25 #include <cstdio>
26 #include <vector>
27 
28 DEAL_II_NAMESPACE_OPEN
29 
30 
31 #ifdef DEAL_II_WITH_TRILINOS
32 namespace TrilinosWrappers
33 {
34  class Vector;
35  class BlockVector;
36 }
37 #endif
38 
39 
61 template <typename Number>
62 class BlockVector : public BlockVectorBase<Vector<Number> >
63 {
64 public:
69 
73  typedef typename BaseClass::BlockType BlockType;
74 
78  typedef typename BaseClass::value_type value_type;
79  typedef typename BaseClass::real_type real_type;
80  typedef typename BaseClass::pointer pointer;
81  typedef typename BaseClass::const_pointer const_pointer;
82  typedef typename BaseClass::reference reference;
83  typedef typename BaseClass::const_reference const_reference;
84  typedef typename BaseClass::size_type size_type;
85  typedef typename BaseClass::iterator iterator;
87 
98  explicit BlockVector (const unsigned int n_blocks = 0,
99  const size_type block_size = 0);
100 
105  BlockVector (const BlockVector<Number> &V);
106 
107 
108 #ifdef DEAL_II_WITH_CXX11
109 
117 #endif
118 
119 
120 #ifndef DEAL_II_EXPLICIT_CONSTRUCTOR_BUG
121 
133  template <typename OtherNumber>
134  explicit
136 #endif
137 
138 
139 #ifdef DEAL_II_WITH_TRILINOS
140 
145 
146 #endif
147 
151  BlockVector (const std::vector<size_type> &block_sizes);
152 
158 
168  template <typename InputIterator>
169  BlockVector (const std::vector<size_type> &block_sizes,
170  const InputIterator first,
171  const InputIterator end);
172 
176  ~BlockVector ();
177 
188  void compress (::VectorOperation::values operation
189  =::VectorOperation::unknown);
190 
195  BlockVector &operator= (const value_type s);
196 
203 
204 #ifdef DEAL_II_WITH_CXX11
205 
213 #endif
214 
219  template <class Number2>
222 
227  operator= (const Vector<Number> &V);
228 
229 #ifdef DEAL_II_WITH_TRILINOS
230 
236 #endif
237 
250  void reinit (const unsigned int n_blocks,
251  const size_type block_size = 0,
252  const bool omit_zeroing_entries = false);
253 
270  void reinit (const std::vector<size_type> &block_sizes,
271  const bool omit_zeroing_entries=false);
272 
282  void reinit (const BlockIndices &block_indices,
283  const bool omit_zeroing_entries=false);
284 
298  template <typename Number2>
299  void reinit (const BlockVector<Number2> &V,
300  const bool omit_zeroing_entries=false);
301 
306  template <class BlockVector2>
307  void scale (const BlockVector2 &v);
308 
320  void swap (BlockVector<Number> &v);
321 
327  void print (const char *format = 0) const DEAL_II_DEPRECATED;
328 
332  void print (std::ostream &out,
333  const unsigned int precision = 3,
334  const bool scientific = true,
335  const bool across = true) const;
336 
342  void block_write (std::ostream &out) const;
343 
355  void block_read (std::istream &in);
356 
365  DeclException0 (ExcIteratorRangeDoesNotMatchVectorSize);
367 };
368 
371 #ifndef DOXYGEN
372 /*----------------------- Inline functions ----------------------------------*/
373 
374 
375 
376 template <typename Number>
377 template <typename InputIterator>
378 BlockVector<Number>::BlockVector (const std::vector<size_type> &block_sizes,
379  const InputIterator first,
380  const InputIterator end)
381 {
382  // first set sizes of blocks, but
383  // don't initialize them as we will
384  // copy elements soon
385  (void)end;
386  reinit (block_sizes, true);
387  InputIterator start = first;
388  for (size_type b=0; b<block_sizes.size(); ++b)
389  {
390  InputIterator end = start;
391  std::advance (end, static_cast<signed int>(block_sizes[b]));
392  std::copy (start, end, this->block(b).begin());
393  start = end;
394  };
395  Assert (start == end, ExcIteratorRangeDoesNotMatchVectorSize());
396 }
397 
398 
399 
400 template <typename Number>
401 inline
403 BlockVector<Number>::operator= (const value_type s)
404 {
405 
406  AssertIsFinite(s);
407 
409  return *this;
410 }
411 
412 
413 
414 template <typename Number>
415 inline
418 {
419  reinit (v, true);
421  return *this;
422 }
423 
424 
425 
426 #ifdef DEAL_II_WITH_CXX11
427 template <typename Number>
428 inline
431 {
432  swap(v);
433 
434  return *this;
435 }
436 #endif
437 
438 
439 
440 template <typename Number>
441 inline
444 {
446  return *this;
447 }
448 
449 
450 
451 template <typename Number>
452 template <typename Number2>
453 inline
456 {
457  reinit (v, true);
459  return *this;
460 }
461 
462 template <typename Number>
463 inline
464 void BlockVector<Number>::compress (::VectorOperation::values operation)
465 {
466  for (size_type i=0; i<this->n_blocks(); ++i)
467  this->components[i].compress(operation);
468 }
469 
470 
471 
472 template <typename Number>
473 template <class BlockVector2>
474 void BlockVector<Number>::scale (const BlockVector2 &v)
475 {
476  BaseClass::scale (v);
477 }
478 
479 #endif // DOXYGEN
480 
481 
490 template <typename Number>
491 inline
494 {
495  u.swap (v);
496 }
497 
498 
499 namespace internal
500 {
501  namespace LinearOperator
502  {
503  template <typename> class ReinitHelper;
504 
509  template<typename number>
510  class ReinitHelper<BlockVector<number> >
511  {
512  public:
513  template <typename Matrix>
514  static
515  void reinit_range_vector (const Matrix &matrix,
517  bool omit_zeroing_entries)
518  {
519  v.reinit(matrix.get_row_indices(), omit_zeroing_entries);
520  }
521 
522  template <typename Matrix>
523  static
524  void reinit_domain_vector(const Matrix &matrix,
526  bool omit_zeroing_entries)
527  {
528  v.reinit(matrix.get_column_indices(), omit_zeroing_entries);
529  }
530  };
531 
532  } /* namespace LinearOperator */
533 } /* namespace internal */
534 
535 DEAL_II_NAMESPACE_CLOSE
536 
537 #endif
BaseClass::value_type value_type
Definition: block_vector.h:78
BlockVector & operator=(const value_type s)
void block_write(std::ostream &out) const
DeclException0(ExcIteratorRangeDoesNotMatchVectorSize)
Auxiliary class aiding in the handling of block structures like in BlockVector or FESystem...
Definition: block_indices.h:54
void print(const char *format=0) const DEAL_II_DEPRECATED
STL namespace.
void scale(const BlockVector2 &v)
void swap(BlockVector< Number > &u, BlockVector< Number > &v)
Definition: block_vector.h:492
void scale(const BlockVector2 &v)
BlockVectorBase< Vector< Number > > BaseClass
Definition: block_vector.h:68
BlockDynamicSparsityPattern BlockCompressedSparsityPattern DEAL_II_DEPRECATED
#define Assert(cond, exc)
Definition: exceptions.h:294
BlockType::real_type real_type
void compress(::VectorOperation::values operation=::VectorOperation::unknown)
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:73
BlockType & block(const unsigned int i)
BlockVectorBase & operator=(const value_type s)
#define AssertIsFinite(number)
Definition: exceptions.h:1096
void block_read(std::istream &in)