00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __deal2__block_vector_h
00013 #define __deal2__block_vector_h
00014
00015
00016 #include <deal.II/base/config.h>
00017 #include <deal.II/base/exceptions.h>
00018 #include <deal.II/lac/block_indices.h>
00019 #include <deal.II/lac/block_vector_base.h>
00020
00021 #include <cstdio>
00022 #include <vector>
00023
00024 DEAL_II_NAMESPACE_OPEN
00025
00026
00027 #ifdef DEAL_II_USE_TRILINOS
00028 namespace TrilinosWrappers
00029 {
00030 class Vector;
00031 class BlockVector;
00032 }
00033 #endif
00034
00035
00036
00055 template <typename Number>
00056 class BlockVector : public BlockVectorBase<Vector<Number> >
00057 {
00058 public:
00063 typedef BlockVectorBase<Vector<Number> > BaseClass;
00064
00069 typedef typename BaseClass::BlockType BlockType;
00070
00075 typedef typename BaseClass::value_type value_type;
00076 typedef typename BaseClass::real_type real_type;
00077 typedef typename BaseClass::pointer pointer;
00078 typedef typename BaseClass::const_pointer const_pointer;
00079 typedef typename BaseClass::reference reference;
00080 typedef typename BaseClass::const_reference const_reference;
00081 typedef typename BaseClass::size_type size_type;
00082 typedef typename BaseClass::iterator iterator;
00083 typedef typename BaseClass::const_iterator const_iterator;
00084
00104 explicit BlockVector (const unsigned int num_blocks = 0,
00105 const unsigned int block_size = 0);
00106
00112 BlockVector (const BlockVector<Number>& V);
00113
00114
00115 #ifndef DEAL_II_EXPLICIT_CONSTRUCTOR_BUG
00116
00136 template <typename OtherNumber>
00137 explicit
00138 BlockVector (const BlockVector<OtherNumber> &v);
00139 #endif
00140
00141
00142 #ifdef DEAL_II_USE_TRILINOS
00143
00149 BlockVector (const TrilinosWrappers::BlockVector &v);
00150
00151 #endif
00152
00160 BlockVector (const std::vector<unsigned int> &block_sizes);
00161
00167 BlockVector (const BlockIndices& block_indices);
00168
00187 template <typename InputIterator>
00188 BlockVector (const std::vector<unsigned int> &n,
00189 const InputIterator first,
00190 const InputIterator end);
00191
00195 ~BlockVector ();
00196
00202 BlockVector & operator = (const value_type s);
00203
00209 BlockVector &
00210 operator= (const BlockVector &V);
00211
00217 template <class Number2>
00218 BlockVector &
00219 operator= (const BlockVector<Number2> &V);
00220
00225 BlockVector &
00226 operator= (const Vector<Number> &V);
00227
00228 #ifdef DEAL_II_USE_TRILINOS
00229
00234 BlockVector &
00235 operator= (const TrilinosWrappers::BlockVector &V);
00236 #endif
00237
00257 void reinit (const unsigned int num_blocks,
00258 const unsigned int block_size = 0,
00259 const bool fast = false);
00260
00292 void reinit (const std::vector<unsigned int> &N,
00293 const bool fast=false);
00294
00309 void reinit (const BlockIndices& block_indices,
00310 const bool fast=false);
00311
00338 template <typename Number2>
00339 void reinit (const BlockVector<Number2> &V,
00340 const bool fast=false);
00341
00355 void scale (const value_type factor);
00356
00362 template <class BlockVector2>
00363 void scale (const BlockVector2 &v);
00364
00395 void swap (BlockVector<Number> &v);
00396
00401 void print (const char* format = 0) const;
00402
00406 void print (std::ostream &out,
00407 const unsigned int precision = 3,
00408 const bool scientific = true,
00409 const bool across = true) const;
00410
00419 void block_write (std::ostream &out) const;
00420
00436 void block_read (std::istream &in);
00437
00444 DeclException0 (ExcIteratorRangeDoesNotMatchVectorSize);
00446 };
00447
00450 #ifndef DOXYGEN
00451
00452
00453
00454
00455 template <typename Number>
00456 template <typename InputIterator>
00457 BlockVector<Number>::BlockVector (const std::vector<unsigned int> &n,
00458 const InputIterator first,
00459 const InputIterator end)
00460 {
00461
00462
00463
00464 reinit (n, true);
00465 InputIterator start = first;
00466 for (unsigned int b=0; b<n.size(); ++b)
00467 {
00468 InputIterator end = start;
00469 std::advance (end, static_cast<signed int>(n[b]));
00470 std::copy (start, end, this->block(b).begin());
00471 start = end;
00472 };
00473 Assert (start == end, ExcIteratorRangeDoesNotMatchVectorSize());
00474 }
00475
00476
00477
00478 template <typename Number>
00479 inline
00480 BlockVector<Number> &
00481 BlockVector<Number>::operator = (const value_type s)
00482 {
00483
00484 Assert (numbers::is_finite(s), ExcNumberNotFinite());
00485
00486 BaseClass::operator = (s);
00487 return *this;
00488 }
00489
00490
00491
00492 template <typename Number>
00493 inline
00494 BlockVector<Number> &
00495 BlockVector<Number>::operator = (const BlockVector &v)
00496 {
00497 reinit (v, true);
00498 BaseClass::operator = (v);
00499 return *this;
00500 }
00501
00502
00503
00504 template <typename Number>
00505 inline
00506 BlockVector<Number> &
00507 BlockVector<Number>::operator = (const Vector<Number> &v)
00508 {
00509 BaseClass::operator = (v);
00510 return *this;
00511 }
00512
00513
00514
00515 template <typename Number>
00516 template <typename Number2>
00517 inline
00518 BlockVector<Number> &
00519 BlockVector<Number>::operator = (const BlockVector<Number2> &v)
00520 {
00521 reinit (v, true);
00522 BaseClass::operator = (v);
00523 return *this;
00524 }
00525
00526
00527
00528 template <typename Number>
00529 void BlockVector<Number>::scale (const value_type factor)
00530 {
00531
00532 Assert (numbers::is_finite(factor), ExcNumberNotFinite());
00533
00534 for (unsigned int i=0; i<this->n_blocks();++i)
00535 this->components[i].scale(factor);
00536 }
00537
00538
00539
00540 template <typename Number>
00541 template <class BlockVector2>
00542 void BlockVector<Number>::scale (const BlockVector2 &v)
00543 {
00544 BaseClass::scale (v);
00545 }
00546
00547 #endif // DOXYGEN
00548
00549
00558 template <typename Number>
00559 inline
00560 void swap (BlockVector<Number> &u,
00561 BlockVector<Number> &v)
00562 {
00563 u.swap (v);
00564 }
00565
00566 DEAL_II_NAMESPACE_CLOSE
00567
00568 #endif
00569