Reference documentation for deal.II version 8.5.1
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  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 
116  BlockVector (BlockVector<Number> &&/*v*/) = default;
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
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 
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  };
396 }
397 
398 
399 
400 template <typename Number>
401 inline
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 template <typename Number>
427 inline
430 {
432  return *this;
433 }
434 
435 
436 
437 template <typename Number>
438 template <typename Number2>
439 inline
442 {
443  reinit (v, true);
445  return *this;
446 }
447 
448 template <typename Number>
449 inline
451 {
452  for (size_type i=0; i<this->n_blocks(); ++i)
453  this->components[i].compress(operation);
454 }
455 
456 
457 
458 template <typename Number>
459 template <class BlockVector2>
460 void BlockVector<Number>::scale (const BlockVector2 &v)
461 {
462  BaseClass::scale (v);
463 }
464 
465 #endif // DOXYGEN
466 
467 
476 template <typename Number>
477 inline
480 {
481  u.swap (v);
482 }
483 
484 
485 namespace internal
486 {
487  namespace LinearOperator
488  {
489  template <typename> class ReinitHelper;
490 
495  template<typename number>
496  class ReinitHelper<BlockVector<number> >
497  {
498  public:
499  template <typename Matrix>
500  static
501  void reinit_range_vector (const Matrix &matrix,
503  bool omit_zeroing_entries)
504  {
505  v.reinit(matrix.get_row_indices(), omit_zeroing_entries);
506  }
507 
508  template <typename Matrix>
509  static
510  void reinit_domain_vector(const Matrix &matrix,
512  bool omit_zeroing_entries)
513  {
514  v.reinit(matrix.get_column_indices(), omit_zeroing_entries);
515  }
516  };
517 
518  } /* namespace LinearOperator */
519 } /* namespace internal */
520 
521 
527 template <typename Number>
528 struct is_serial_vector< BlockVector< Number > > : std_cxx11::true_type
529 {
530 };
531 
532 DEAL_II_NAMESPACE_CLOSE
533 
534 #endif
void print(const char *format=0) const 1
BaseClass::value_type value_type
Definition: block_vector.h:78
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:478
void scale(const BlockVector2 &v)
BlockVectorBase< Vector< Number > > BaseClass
Definition: block_vector.h:68
static ::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
#define Assert(cond, exc)
Definition: exceptions.h:313
BlockType::real_type real_type
void compress(::VectorOperation::values operation=::VectorOperation::unknown)
#define DeclException0(Exception0)
Definition: exceptions.h:541
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:1197
void block_read(std::istream &in)