00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __deal2__petsc_parallel_block_vector_h
00013 #define __deal2__petsc_parallel_block_vector_h
00014
00015
00016 #include <deal.II/base/config.h>
00017
00018 #ifdef DEAL_II_USE_PETSC
00019
00020 # include <deal.II/lac/petsc_parallel_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 namespace PETScWrappers
00029 {
00030
00031 class BlockVector;
00032
00033 namespace MPI
00034 {
00035
00057 class BlockVector : public BlockVectorBase<Vector>
00058 {
00059 public:
00064 typedef BlockVectorBase<Vector> BaseClass;
00065
00070 typedef BaseClass::BlockType BlockType;
00071
00076 typedef BaseClass::value_type value_type;
00077 typedef BaseClass::pointer pointer;
00078 typedef BaseClass::const_pointer const_pointer;
00079 typedef BaseClass::reference reference;
00080 typedef BaseClass::const_reference const_reference;
00081 typedef BaseClass::size_type size_type;
00082 typedef BaseClass::iterator iterator;
00083 typedef BaseClass::const_iterator const_iterator;
00084
00089 BlockVector ();
00090
00100 explicit BlockVector (const unsigned int n_blocks,
00101 const MPI_Comm &communicator,
00102 const unsigned int block_size,
00103 const unsigned int local_size);
00104
00111 BlockVector (const BlockVector &V);
00112
00125 BlockVector (const std::vector<unsigned int> &block_sizes,
00126 const MPI_Comm &communicator,
00127 const std::vector<unsigned int> &local_elements);
00128
00132 ~BlockVector ();
00133
00139 BlockVector & operator = (const value_type s);
00140
00145 BlockVector &
00146 operator= (const BlockVector &V);
00147
00177 BlockVector &
00178 operator = (const PETScWrappers::BlockVector &v);
00179
00193 void reinit (const unsigned int n_blocks,
00194 const MPI_Comm &communicator,
00195 const unsigned int block_size,
00196 const unsigned int local_size,
00197 const bool fast = false);
00198
00234 void reinit (const std::vector<unsigned int> &block_sizes,
00235 const MPI_Comm &communicator,
00236 const std::vector<unsigned int> &local_sizes,
00237 const bool fast=false);
00238
00265 void reinit (const BlockVector &V,
00266 const bool fast=false);
00267
00273 const MPI_Comm & get_mpi_communicator () const;
00274
00305 void swap (BlockVector &v);
00306
00310 void print (std::ostream &out,
00311 const unsigned int precision = 3,
00312 const bool scientific = true,
00313 const bool across = true) const;
00314
00318 DeclException0 (ExcIteratorRangeDoesNotMatchVectorSize);
00322 DeclException0 (ExcNonMatchingBlockVectors);
00323 };
00324
00327
00328
00329
00330 inline
00331 BlockVector::BlockVector ()
00332 {}
00333
00334
00335
00336 inline
00337 BlockVector::BlockVector (const unsigned int n_blocks,
00338 const MPI_Comm &communicator,
00339 const unsigned int block_size,
00340 const unsigned int local_size)
00341 {
00342 reinit (n_blocks, communicator, block_size, local_size);
00343 }
00344
00345
00346
00347 inline
00348 BlockVector::BlockVector (const std::vector<unsigned int> &block_sizes,
00349 const MPI_Comm &communicator,
00350 const std::vector<unsigned int> &local_elements)
00351 {
00352 reinit (block_sizes, communicator, local_elements, false);
00353 }
00354
00355
00356 inline
00357 BlockVector::BlockVector (const BlockVector& v)
00358 :
00359 BlockVectorBase<Vector > ()
00360 {
00361 this->components.resize (v.n_blocks());
00362 this->block_indices = v.block_indices;
00363
00364 for (unsigned int i=0; i<this->n_blocks(); ++i)
00365 this->components[i] = v.components[i];
00366 }
00367
00368
00369
00370 inline
00371 BlockVector &
00372 BlockVector::operator = (const value_type s)
00373 {
00374 BaseClass::operator = (s);
00375 return *this;
00376 }
00377
00378
00379
00380 inline
00381 BlockVector &
00382 BlockVector::operator = (const BlockVector &v)
00383 {
00384 BaseClass::operator = (v);
00385 return *this;
00386 }
00387
00388
00389
00390 inline
00391 BlockVector::~BlockVector ()
00392 {}
00393
00394
00395 inline
00396 void
00397 BlockVector::reinit (const unsigned int n_blocks,
00398 const MPI_Comm &communicator,
00399 const unsigned int block_size,
00400 const unsigned int local_size,
00401 const bool fast)
00402 {
00403 reinit(std::vector<unsigned int>(n_blocks, block_size),
00404 communicator,
00405 std::vector<unsigned int>(n_blocks, local_size),
00406 fast);
00407 }
00408
00409
00410
00411 inline
00412 void
00413 BlockVector::reinit (const std::vector<unsigned int> &block_sizes,
00414 const MPI_Comm &communicator,
00415 const std::vector<unsigned int> &local_sizes,
00416 const bool fast)
00417 {
00418 this->block_indices.reinit (block_sizes);
00419 if (this->components.size() != this->n_blocks())
00420 this->components.resize(this->n_blocks());
00421
00422 for (unsigned int i=0; i<this->n_blocks(); ++i)
00423 this->components[i].reinit(communicator, block_sizes[i],
00424 local_sizes[i], fast);
00425 }
00426
00427
00428 inline
00429 void
00430 BlockVector::reinit (const BlockVector& v,
00431 const bool fast)
00432 {
00433 this->block_indices = v.get_block_indices();
00434 if (this->components.size() != this->n_blocks())
00435 this->components.resize(this->n_blocks());
00436
00437 for (unsigned int i=0;i<this->n_blocks();++i)
00438 block(i).reinit(v.block(i), fast);
00439 }
00440
00441
00442
00443 inline
00444 const MPI_Comm &
00445 BlockVector::get_mpi_communicator () const
00446 {
00447 return block(0).get_mpi_communicator();
00448 }
00449
00450
00451
00452 inline
00453 void
00454 BlockVector::swap (BlockVector &v)
00455 {
00456 Assert (this->n_blocks() == v.n_blocks(),
00457 ExcDimensionMismatch(this->n_blocks(), v.n_blocks()));
00458
00459 for (unsigned int i=0; i<this->n_blocks(); ++i)
00460 this->components[i].swap (v.components[i]);
00461 ::swap (this->block_indices, v.block_indices);
00462 }
00463
00464
00465
00466 inline
00467 void
00468 BlockVector::print (std::ostream &out,
00469 const unsigned int precision,
00470 const bool scientific,
00471 const bool across) const
00472 {
00473 for (unsigned int i=0;i<this->n_blocks();++i)
00474 {
00475 if (across)
00476 out << 'C' << i << ':';
00477 else
00478 out << "Component " << i << std::endl;
00479 this->components[i].print(out, precision, scientific, across);
00480 }
00481 }
00482
00483
00484
00493 inline
00494 void swap (BlockVector &u,
00495 BlockVector &v)
00496 {
00497 u.swap (v);
00498 }
00499
00500 }
00501
00502 }
00503
00504 DEAL_II_NAMESPACE_CLOSE
00505
00506 #endif // DEAL_II_USE_PETSC
00507
00508 #endif
00509