00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __deal2__trilinos_block_vector_h
00013 #define __deal2__trilinos_block_vector_h
00014
00015
00016 #include <deal.II/base/config.h>
00017
00018 #ifdef DEAL_II_USE_TRILINOS
00019
00020 # include <deal.II/lac/trilinos_vector.h>
00021 # include <deal.II/lac/block_indices.h>
00022 # include <deal.II/lac/block_vector_base.h>
00023 # include <deal.II/lac/exceptions.h>
00024
00025 DEAL_II_NAMESPACE_OPEN
00026
00027
00028 template <typename Number> class BlockVector;
00029
00034 namespace TrilinosWrappers
00035 {
00036
00037 namespace MPI
00038 {
00039 class BlockVector;
00040 }
00041 class BlockVector;
00042 class BlockSparseMatrix;
00043
00044
00045 namespace MPI
00046 {
00067 class BlockVector : public BlockVectorBase<Vector>
00068 {
00069 public:
00074 typedef BlockVectorBase<Vector> BaseClass;
00075
00080 typedef BaseClass::BlockType BlockType;
00081
00086 typedef BaseClass::value_type value_type;
00087 typedef BaseClass::pointer pointer;
00088 typedef BaseClass::const_pointer const_pointer;
00089 typedef BaseClass::reference reference;
00090 typedef BaseClass::const_reference const_reference;
00091 typedef BaseClass::size_type size_type;
00092 typedef BaseClass::iterator iterator;
00093 typedef BaseClass::const_iterator const_iterator;
00094
00099 BlockVector ();
00100
00110 BlockVector (const std::vector<Epetra_Map> ¶llel_partitioning);
00111
00122 BlockVector (const std::vector<IndexSet> ¶llel_partitioning,
00123 const MPI_Comm &communicator = MPI_COMM_WORLD);
00124
00131 BlockVector (const BlockVector &V);
00132
00143 BlockVector (const unsigned int num_blocks);
00144
00148 ~BlockVector ();
00149
00156 BlockVector &
00157 operator = (const value_type s);
00158
00163 BlockVector &
00164 operator = (const BlockVector &V);
00165
00171 BlockVector &
00172 operator = (const ::TrilinosWrappers::BlockVector &V);
00173
00194 template <typename Number>
00195 BlockVector &
00196 operator = (const ::BlockVector<Number> &V);
00197
00210 void reinit (const std::vector<Epetra_Map> ¶llel_partitioning,
00211 const bool fast = false);
00212
00225 void reinit (const std::vector<IndexSet> ¶llel_partitioning,
00226 const MPI_Comm &communicator = MPI_COMM_WORLD,
00227 const bool fast = false);
00228
00255 void reinit (const BlockVector &V,
00256 const bool fast = false);
00257
00269 void reinit (const unsigned int num_blocks);
00270
00306 void import_nonlocal_data_for_fe (const TrilinosWrappers::BlockSparseMatrix &m,
00307 const BlockVector &v);
00308
00338 void compress (const Epetra_CombineMode last_action = Zero);
00339
00354 bool is_compressed () const;
00355
00386 void swap (BlockVector &v);
00387
00391 void print (std::ostream &out,
00392 const unsigned int precision = 3,
00393 const bool scientific = true,
00394 const bool across = true) const;
00395
00399 DeclException0 (ExcIteratorRangeDoesNotMatchVectorSize);
00400
00404 DeclException0 (ExcNonMatchingBlockVectors);
00405 };
00406
00407
00408
00409
00410
00411
00412 inline
00413 BlockVector::BlockVector ()
00414 {}
00415
00416
00417
00418 inline
00419 BlockVector::BlockVector (const std::vector<Epetra_Map> ¶llel_partitioning)
00420 {
00421 reinit (parallel_partitioning, false);
00422 }
00423
00424
00425
00426 inline
00427 BlockVector::BlockVector (const std::vector<IndexSet> ¶llel_partitioning,
00428 const MPI_Comm &communicator)
00429 {
00430 reinit (parallel_partitioning, communicator, false);
00431 }
00432
00433
00434
00435 inline
00436 BlockVector::BlockVector (const unsigned int num_blocks)
00437 {
00438 reinit (num_blocks);
00439 }
00440
00441
00442
00443 inline
00444 BlockVector::BlockVector (const BlockVector& v)
00445 :
00446 BlockVectorBase<Vector > ()
00447 {
00448 this->components.resize (v.n_blocks());
00449 this->block_indices = v.block_indices;
00450
00451 for (unsigned int i=0; i<this->n_blocks(); ++i)
00452 this->components[i] = v.components[i];
00453 }
00454
00455
00456
00457 inline
00458 bool
00459 BlockVector::is_compressed () const
00460 {
00461 bool compressed = true;
00462 for (unsigned int row=0; row<n_blocks(); ++row)
00463 if (block(row).is_compressed() == false)
00464 {
00465 compressed = false;
00466 break;
00467 }
00468
00469 return compressed;
00470 }
00471
00472
00473
00474 template <typename Number>
00475 BlockVector &
00476 BlockVector::operator = (const ::BlockVector<Number> &v)
00477 {
00478 if (n_blocks() != v.n_blocks())
00479 {
00480 std::vector<unsigned int> block_sizes (v.n_blocks(), 0);
00481 block_indices.reinit (block_sizes);
00482 if (components.size() != n_blocks())
00483 components.resize(n_blocks());
00484 }
00485
00486 for (unsigned int i=0; i<this->n_blocks(); ++i)
00487 this->components[i] = v.block(i);
00488
00489 collect_sizes();
00490
00491 return *this;
00492 }
00493
00494
00495 inline
00496 void
00497 BlockVector::swap (BlockVector &v)
00498 {
00499 Assert (n_blocks() == v.n_blocks(),
00500 ExcDimensionMismatch(n_blocks(),v.n_blocks()));
00501
00502 for (unsigned int row=0; row<n_blocks(); ++row)
00503 block(row).swap (v.block(row));
00504 }
00505
00506
00507
00516 inline
00517 void swap (BlockVector &u,
00518 BlockVector &v)
00519 {
00520 u.swap (v);
00521 }
00522
00523 }
00524
00525
00526
00527
00547 class BlockVector : public BlockVectorBase<Vector>
00548 {
00549 public:
00554 typedef BlockVectorBase<Vector> BaseClass;
00555
00560 typedef BaseClass::BlockType BlockType;
00561
00566 typedef BaseClass::value_type value_type;
00567 typedef BaseClass::pointer pointer;
00568 typedef BaseClass::const_pointer const_pointer;
00569 typedef BaseClass::reference reference;
00570 typedef BaseClass::const_reference const_reference;
00571 typedef BaseClass::size_type size_type;
00572 typedef BaseClass::iterator iterator;
00573 typedef BaseClass::const_iterator const_iterator;
00574
00579 BlockVector ();
00580
00590 BlockVector (const std::vector<Epetra_Map> &partitioner);
00591
00601 BlockVector (const std::vector<IndexSet> &partitioner,
00602 const MPI_Comm &communicator = MPI_COMM_WORLD);
00603
00611 BlockVector (const MPI::BlockVector &V);
00612
00619 BlockVector (const BlockVector &V);
00620
00631 BlockVector (const unsigned int num_blocks);
00632
00641 BlockVector (const std::vector<unsigned int> &N);
00642
00661 template <typename InputIterator>
00662 BlockVector (const std::vector<unsigned int> &n,
00663 const InputIterator first,
00664 const InputIterator end);
00665
00669 ~BlockVector ();
00670
00677 BlockVector &
00678 operator = (const value_type s);
00679
00685 BlockVector &
00686 operator = (const MPI::BlockVector &V);
00687
00692 BlockVector &
00693 operator = (const BlockVector &V);
00694
00715 template <typename Number>
00716 BlockVector &
00717 operator = (const ::BlockVector<Number> &V);
00718
00739 void reinit (const std::vector<Epetra_Map> &partitioning,
00740 const bool fast = false);
00741
00761 void reinit (const std::vector<IndexSet> &partitioning,
00762 const MPI_Comm &communicator = MPI_COMM_WORLD,
00763 const bool fast = false);
00764
00777 void reinit (const std::vector<unsigned int> &N,
00778 const bool fast=false);
00779
00787 void reinit (const MPI::BlockVector &V);
00788
00815 void reinit (const BlockVector &V,
00816 const bool fast = false);
00817
00829 void reinit (const unsigned int num_blocks);
00830
00861 void swap (BlockVector &v);
00862
00866 void print (std::ostream &out,
00867 const unsigned int precision = 3,
00868 const bool scientific = true,
00869 const bool across = true) const;
00870
00874 DeclException0 (ExcIteratorRangeDoesNotMatchVectorSize);
00875
00879 DeclException0 (ExcNonMatchingBlockVectors);
00880
00884 DeclException2 (ExcNonLocalizedMap,
00885 int, int,
00886 << "For the generation of a localized vector the map has "
00887 << "to assign all elements to all vectors! "
00888 << "local_size = global_size is a necessary condition, but"
00889 << arg1 << " != " << arg2 << " was given!");
00890
00891 };
00892
00893
00894
00895
00896
00897
00898
00899 inline
00900 BlockVector::BlockVector ()
00901 {}
00902
00903
00904
00905 inline
00906 BlockVector::BlockVector (const std::vector<Epetra_Map> &partitioning)
00907 {
00908 reinit (partitioning);
00909 }
00910
00911
00912
00913 inline
00914 BlockVector::BlockVector (const std::vector<IndexSet> &partitioning,
00915 const MPI_Comm &communicator)
00916 {
00917 reinit (partitioning, communicator);
00918 }
00919
00920
00921
00922 inline
00923 BlockVector::BlockVector (const std::vector<unsigned int> &N)
00924 {
00925 reinit (N);
00926 }
00927
00928
00929
00930 template <typename InputIterator>
00931 BlockVector::BlockVector (const std::vector<unsigned int> &n,
00932 const InputIterator first,
00933 const InputIterator end)
00934 {
00935
00936
00937
00938 reinit (n, true);
00939 InputIterator start = first;
00940 for (unsigned int b=0; b<n.size(); ++b)
00941 {
00942 InputIterator end = start;
00943 std::advance (end, static_cast<signed int>(n[b]));
00944
00945 for (unsigned int i=0; i<n[b]; ++i, ++start)
00946 this->block(b)(i) = *start;
00947 }
00948 Assert (start == end, ExcIteratorRangeDoesNotMatchVectorSize());
00949 }
00950
00951
00952
00953 inline
00954 BlockVector::BlockVector (const unsigned int num_blocks)
00955 {
00956 reinit (num_blocks);
00957 }
00958
00959
00960
00961 inline
00962 BlockVector::~BlockVector()
00963 {}
00964
00965
00966
00967 inline
00968 BlockVector::BlockVector (const MPI::BlockVector &v)
00969 {
00970 reinit (v);
00971 }
00972
00973
00974
00975 inline
00976 BlockVector::BlockVector (const BlockVector& v)
00977 :
00978 BlockVectorBase<Vector > ()
00979 {
00980 this->components.resize (v.n_blocks());
00981 this->block_indices = v.block_indices;
00982
00983 for (unsigned int i=0; i<this->n_blocks(); ++i)
00984 this->components[i] = v.components[i];
00985 }
00986
00987
00988 inline
00989 void
00990 BlockVector::swap (BlockVector &v)
00991 {
00992 Assert (n_blocks() == v.n_blocks(),
00993 ExcDimensionMismatch(n_blocks(),v.n_blocks()));
00994
00995 for (unsigned int row=0; row<n_blocks(); ++row)
00996 block(row).swap (v.block(row));
00997 }
00998
00999
01000 template <typename Number>
01001 BlockVector &
01002 BlockVector::operator = (const ::BlockVector<Number> &v)
01003 {
01004 if (n_blocks() != v.n_blocks())
01005 {
01006 std::vector<unsigned int> block_sizes (v.n_blocks(), 0);
01007 block_indices.reinit (block_sizes);
01008 if (components.size() != n_blocks())
01009 components.resize(n_blocks());
01010 }
01011
01012 for (unsigned int i=0; i<this->n_blocks(); ++i)
01013 this->components[i] = v.block(i);
01014
01015 collect_sizes();
01016
01017 return *this;
01018 }
01019
01020
01029 inline
01030 void swap (BlockVector &u,
01031 BlockVector &v)
01032 {
01033 u.swap (v);
01034 }
01035
01036 }
01037
01040 DEAL_II_NAMESPACE_CLOSE
01041
01042 #endif // DEAL_II_USE_TRILINOS
01043
01044 #endif
01045