00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __deal2__petsc_parallel_vector_h
00013 #define __deal2__petsc_parallel_vector_h
00014
00015
00016 #include <deal.II/base/config.h>
00017
00018 #ifdef DEAL_II_USE_PETSC
00019
00020 # include <deal.II/base/subscriptor.h>
00021 # include <deal.II/lac/exceptions.h>
00022 # include <deal.II/lac/vector.h>
00023 # include <deal.II/lac/petsc_vector_base.h>
00024 # include <deal.II/base/index_set.h>
00025
00026 DEAL_II_NAMESPACE_OPEN
00027
00028
00029
00030
00031 template <typename> class Vector;
00032 class IndexSet;
00033
00034
00038 namespace PETScWrappers
00039 {
00047 namespace MPI
00048 {
00049
00153 class Vector : public VectorBase
00154 {
00155 public:
00160 Vector ();
00161
00186 explicit Vector (const MPI_Comm &communicator,
00187 const unsigned int n,
00188 const unsigned int local_size);
00189
00190
00206 template <typename Number>
00207 explicit Vector (const MPI_Comm &communicator,
00208 const ::Vector<Number> &v,
00209 const unsigned int local_size);
00210
00211
00226 explicit Vector (const MPI_Comm &communicator,
00227 const VectorBase &v,
00228 const unsigned int local_size);
00229
00230
00249 explicit Vector (const MPI_Comm &communicator,
00250 const IndexSet & local,
00251 const IndexSet & ghost = IndexSet(0));
00252
00253
00260 Vector & operator = (const Vector &v);
00261
00262
00298 Vector & operator = (const PETScWrappers::Vector &v);
00299
00309 Vector & operator = (const PetscScalar s);
00310
00326 template <typename number>
00327 Vector & operator = (const ::Vector<number> &v);
00328
00355 void reinit (const MPI_Comm &communicator,
00356 const unsigned int N,
00357 const unsigned int local_size,
00358 const bool fast = false);
00359
00374 void reinit (const Vector &v,
00375 const bool fast = false);
00376
00382 void reinit (const MPI_Comm &communicator,
00383 const IndexSet & local,
00384 const IndexSet & ghost = IndexSet(0));
00385
00386
00392 const MPI_Comm & get_mpi_communicator () const;
00393
00394 protected:
00404 virtual void create_vector (const unsigned int n,
00405 const unsigned int local_size);
00406
00407
00408
00417 virtual void create_vector (const unsigned int n,
00418 const unsigned int local_size,
00419 const IndexSet & ghostnodes);
00420
00421
00422 private:
00427 MPI_Comm communicator;
00428 };
00429
00430
00431
00432
00433
00442 inline
00443 void swap (Vector &u, Vector &v)
00444 {
00445 u.swap (v);
00446 }
00447
00448
00449 #ifndef DOXYGEN
00450
00451 template <typename number>
00452 Vector::Vector (const MPI_Comm &communicator,
00453 const ::Vector<number> &v,
00454 const unsigned int local_size)
00455 :
00456 communicator (communicator)
00457 {
00458 Vector::create_vector (v.size(), local_size);
00459
00460 *this = v;
00461 }
00462
00463
00464
00465 inline
00466 Vector &
00467 Vector::operator = (const PetscScalar s)
00468 {
00469 VectorBase::operator = (s);
00470
00471 return *this;
00472 }
00473
00474
00475
00476 inline
00477 Vector &
00478 Vector::operator = (const Vector &v)
00479 {
00480
00481
00482 if (size() != v.size())
00483 reinit (v.communicator, v.size(), v.local_size(), true);
00484
00485 const int ierr = VecCopy (v.vector, vector);
00486 AssertThrow (ierr == 0, ExcPETScError(ierr));
00487
00488 return *this;
00489 }
00490
00491
00492
00493 template <typename number>
00494 inline
00495 Vector &
00496 Vector::operator = (const ::Vector<number> &v)
00497 {
00498 Assert (size() == v.size(),
00499 ExcDimensionMismatch (size(), v.size()));
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543 for (unsigned int i=0; i<v.size(); ++i)
00544 (*this)(i) = v(i);
00545
00546 compress ();
00547
00548 return *this;
00549 }
00550
00551
00552
00553 inline
00554 const MPI_Comm &
00555 Vector::get_mpi_communicator () const
00556 {
00557 return communicator;
00558 }
00559
00560 #endif // DOXYGEN
00561 }
00562 }
00563
00566 DEAL_II_NAMESPACE_CLOSE
00567
00568 #endif // DEAL_II_USE_PETSC
00569
00570
00571
00572 #endif
00573
00574