Reference documentation for deal.II version 8.1.0
block_vector.h
1 // ---------------------------------------------------------------------
2 // @f$Id: block_vector.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 1999 - 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_vector_h
18 #define __deal2__block_vector_h
19 
20 
21 #include <deal.II/base/config.h>
23 #include <deal.II/lac/block_indices.h>
24 #include <deal.II/lac/block_vector_base.h>
25 
26 #include <cstdio>
27 #include <vector>
28 
30 
31 
32 #ifdef DEAL_II_WITH_TRILINOS
33 namespace TrilinosWrappers
34 {
35  class Vector;
36  class BlockVector;
37 }
38 #endif
39 
40 
41 
60 template <typename Number>
61 class BlockVector : public BlockVectorBase<Vector<Number> >
62 {
63 public:
69 
74  typedef typename BaseClass::BlockType BlockType;
75 
80  typedef typename BaseClass::value_type value_type;
81  typedef typename BaseClass::real_type real_type;
82  typedef typename BaseClass::pointer pointer;
83  typedef typename BaseClass::const_pointer const_pointer;
84  typedef typename BaseClass::reference reference;
85  typedef typename BaseClass::const_reference const_reference;
86  typedef typename BaseClass::size_type size_type;
87  typedef typename BaseClass::iterator iterator;
89 
109  explicit BlockVector (const unsigned int num_blocks = 0,
110  const size_type block_size = 0);
111 
117  BlockVector (const BlockVector<Number> &V);
118 
119 
120 #ifndef DEAL_II_EXPLICIT_CONSTRUCTOR_BUG
121 
141  template <typename OtherNumber>
142  explicit
144 #endif
145 
146 
147 #ifdef DEAL_II_WITH_TRILINOS
148 
155 
156 #endif
157 
165  BlockVector (const std::vector<size_type> &block_sizes);
166 
173 
192  template <typename InputIterator>
193  BlockVector (const std::vector<size_type> &n,
194  const InputIterator first,
195  const InputIterator end);
196 
200  ~BlockVector ();
201 
215  void compress (::VectorOperation::values operation
216  =::VectorOperation::unknown);
217 
223  BlockVector &operator = (const value_type s);
224 
230  BlockVector &
231  operator= (const BlockVector &V);
232 
238  template <class Number2>
239  BlockVector &
241 
246  BlockVector &
247  operator= (const Vector<Number> &V);
248 
249 #ifdef DEAL_II_WITH_TRILINOS
250 
255  BlockVector &
257 #endif
258 
278  void reinit (const unsigned int num_blocks,
279  const size_type block_size = 0,
280  const bool fast = false);
281 
313  void reinit (const std::vector<size_type> &N,
314  const bool fast=false);
315 
330  void reinit (const BlockIndices &block_indices,
331  const bool fast=false);
332 
359  template <typename Number2>
360  void reinit (const BlockVector<Number2> &V,
361  const bool fast=false);
362 
376  void scale (const value_type factor) DEAL_II_DEPRECATED;
377 
383  template <class BlockVector2>
384  void scale (const BlockVector2 &v);
385 
416  void swap (BlockVector<Number> &v);
417 
422  void print (const char *format = 0) const;
423 
427  void print (std::ostream &out,
428  const unsigned int precision = 3,
429  const bool scientific = true,
430  const bool across = true) const;
431 
440  void block_write (std::ostream &out) const;
441 
457  void block_read (std::istream &in);
458 
465  DeclException0 (ExcIteratorRangeDoesNotMatchVectorSize);
467 };
468 
471 #ifndef DOXYGEN
472 /*----------------------- Inline functions ----------------------------------*/
473 
474 
475 
476 template <typename Number>
477 template <typename InputIterator>
478 BlockVector<Number>::BlockVector (const std::vector<size_type> &n,
479  const InputIterator first,
480  const InputIterator end)
481 {
482  // first set sizes of blocks, but
483  // don't initialize them as we will
484  // copy elements soon
485  reinit (n, true);
486  InputIterator start = first;
487  for (size_type b=0; b<n.size(); ++b)
488  {
489  InputIterator end = start;
490  std::advance (end, static_cast<signed int>(n[b]));
491  std::copy (start, end, this->block(b).begin());
492  start = end;
493  };
494  Assert (start == end, ExcIteratorRangeDoesNotMatchVectorSize());
495 }
496 
497 
498 
499 template <typename Number>
500 inline
502 BlockVector<Number>::operator = (const value_type s)
503 {
504 
506 
508  return *this;
509 }
510 
511 
512 
513 template <typename Number>
514 inline
517 {
518  reinit (v, true);
520  return *this;
521 }
522 
523 
524 
525 template <typename Number>
526 inline
529 {
531  return *this;
532 }
533 
534 
535 
536 template <typename Number>
537 template <typename Number2>
538 inline
541 {
542  reinit (v, true);
544  return *this;
545 }
546 
547 template <typename Number>
548 inline
549 void BlockVector<Number>::compress (::VectorOperation::values operation)
550 {
551  for (size_type i=0; i<this->n_blocks(); ++i)
552  this->components[i].compress(operation);
553 }
554 
555 
556 
557 template <typename Number>
558 void BlockVector<Number>::scale (const value_type factor)
559 {
560 
562 
563  for (size_type i=0; i<this->n_blocks(); ++i)
564  this->components[i] *= factor;
565 }
566 
567 
568 
569 template <typename Number>
570 template <class BlockVector2>
571 void BlockVector<Number>::scale (const BlockVector2 &v)
572 {
573  BaseClass::scale (v);
574 }
575 
576 #endif // DOXYGEN
577 
578 
587 template <typename Number>
588 inline
591 {
592  u.swap (v);
593 }
594 
595 DEAL_II_NAMESPACE_CLOSE
596 
597 #endif
BaseClass::value_type value_type
Definition: block_vector.h:80
Auxiliary class aiding in the handling of block structures like in BlockVector or FESystem...
Definition: block_indices.h:55
unsigned int n_blocks() const
bool is_finite(const double x)
void swap(BlockVector< Number > &u, BlockVector< Number > &v)
Definition: block_vector.h:589
void scale(const BlockVector2 &v)
BlockVectorBase< Vector< Number > > BaseClass
Definition: block_vector.h:68
BlockVector & operator=(const value_type s)
void reinit(const std::vector< Epetra_Map > &partitioning, const bool fast=false)
DeclException0(ExcIteratorRangeDoesNotMatchVectorSize)
#define Assert(cond, exc)
Definition: exceptions.h:299
BlockType::real_type real_type
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
BlockCompressedSparsityPattern CompressedBlockSparsityPattern DEAL_II_DEPRECATED
std::vector< Vector > components
void swap(BlockVector< Number > &v)
::ExceptionBase & ExcNumberNotFinite()
void compress() DEAL_II_DEPRECATED
BaseClass::BlockType BlockType
Definition: block_vector.h:74
BlockType & block(const unsigned int i)
BlockVectorBase & operator=(const value_type s)