Reference documentation for deal.II version Git 344db16 2016-08-30 16:14:16 -0500
trilinos_vector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 2016 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__trilinos_vector_h
17 #define dealii__trilinos_vector_h
18 
19 
20 #include <deal.II/base/config.h>
21 
22 #ifdef DEAL_II_WITH_TRILINOS
23 
24 # include <deal.II/base/std_cxx11/shared_ptr.h>
25 # include <deal.II/base/subscriptor.h>
26 # include <deal.II/base/index_set.h>
27 # include <deal.II/base/utilities.h>
28 # include <deal.II/lac/exceptions.h>
29 # include <deal.II/lac/vector.h>
30 # include <deal.II/lac/trilinos_vector_base.h>
31 
32 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
33 # include "Epetra_Map.h"
34 # include "Epetra_LocalMap.h"
35 DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
36 
37 DEAL_II_NAMESPACE_OPEN
38 
39 
40 // forward declaration
41 template <typename> class Vector;
42 
47 namespace TrilinosWrappers
48 {
49  class SparseMatrix;
50 
51  namespace
52  {
53 #ifndef DEAL_II_WITH_64BIT_INDICES
54  // define a helper function that queries the global ID of local ID of
55  // an Epetra_BlockMap object by calling either the 32- or 64-bit
56  // function necessary.
57  inline
58  int gid(const Epetra_BlockMap &map, int i)
59  {
60  return map.GID(i);
61  }
62 #else
63  // define a helper function that queries the global ID of local ID of
64  // an Epetra_BlockMap object by calling either the 32- or 64-bit
65  // function necessary.
66  inline
67  long long int gid(const Epetra_BlockMap &map, int i)
68  {
69  return map.GID64(i);
70  }
71 #endif
72  }
73 
82  namespace MPI
83  {
84  class BlockVector;
85 
253  class Vector : public VectorBase
254  {
255  public:
259  typedef ::types::global_dof_index size_type;
260 
271  static const bool supports_distributed_data = true;
272 
282  Vector ();
283 
287  Vector (const Vector &v);
288 
289 #ifdef DEAL_II_WITH_CXX11
290 
297  Vector (Vector &&v);
298 #endif
299 
303  ~Vector ();
304 
328  void reinit (const VectorBase &v,
329  const bool omit_zeroing_entries = false,
330  const bool allow_different_maps = false);
331 
335  void reinit (const BlockVector &v,
336  const bool import_data = false);
337 
344  Vector &operator= (const TrilinosScalar s);
345 
351  Vector &operator= (const Vector &v);
352 
353 #ifdef DEAL_II_WITH_CXX11
354 
361  Vector &operator= (Vector &&v);
362 #endif
363 
371  Vector &operator= (const ::TrilinosWrappers::Vector &v);
372 
381  template <typename Number>
382  Vector &operator= (const ::Vector<Number> &v);
383 
402  (const ::TrilinosWrappers::SparseMatrix &matrix,
403  const Vector &vector);
405 
425  explicit Vector (const Epetra_Map &parallel_partitioning) DEAL_II_DEPRECATED;
426 
443  Vector (const Epetra_Map &parallel_partitioning,
444  const VectorBase &v) DEAL_II_DEPRECATED;
445 
460  template <typename number>
461  void reinit (const Epetra_Map &parallel_partitioner,
462  const ::Vector<number> &v) DEAL_II_DEPRECATED;
463 
478  void reinit (const Epetra_Map &parallel_partitioning,
479  const bool omit_zeroing_entries = false) DEAL_II_DEPRECATED;
480 
495  template <typename Number>
496  Vector (const Epetra_Map &parallel_partitioning,
497  const ::Vector<Number> &v) DEAL_II_DEPRECATED;
499 
517  explicit Vector (const IndexSet &parallel_partitioning,
518  const MPI_Comm &communicator = MPI_COMM_WORLD);
519 
531  Vector (const IndexSet &local,
532  const IndexSet &ghost,
533  const MPI_Comm &communicator = MPI_COMM_WORLD);
534 
549  Vector (const IndexSet &parallel_partitioning,
550  const VectorBase &v,
551  const MPI_Comm &communicator = MPI_COMM_WORLD);
552 
565  template <typename Number>
566  Vector (const IndexSet &parallel_partitioning,
567  const ::Vector<Number> &v,
568  const MPI_Comm &communicator = MPI_COMM_WORLD);
569 
589  void reinit (const IndexSet &parallel_partitioning,
590  const MPI_Comm &communicator = MPI_COMM_WORLD,
591  const bool omit_zeroing_entries = false);
592 
618  void reinit (const IndexSet &locally_owned_entries,
619  const IndexSet &ghost_entries,
620  const MPI_Comm &communicator = MPI_COMM_WORLD,
621  const bool vector_writable = false);
623  };
624 
625 
626 
627 
628 // ------------------- inline and template functions --------------
629 
630 
639  inline
640  void swap (Vector &u, Vector &v)
641  {
642  u.swap (v);
643  }
644 
645 
646 #ifndef DOXYGEN
647 
648  template <typename number>
649  Vector::Vector (const Epetra_Map &input_map,
650  const ::Vector<number> &v)
651  {
652  reinit (input_map, v);
653  }
654 
655 
656 
657  template <typename number>
658  Vector::Vector (const IndexSet &parallel_partitioner,
659  const ::Vector<number> &v,
660  const MPI_Comm &communicator)
661  {
662  *this = Vector(parallel_partitioner.make_trilinos_map (communicator, true),
663  v);
664  }
665 
666 
667 
668 
669  template <typename number>
670  void Vector::reinit (const Epetra_Map &parallel_partitioner,
671  const ::Vector<number> &v)
672  {
673  if (vector.get() == 0 || vector->Map().SameAs(parallel_partitioner) == false)
674  vector.reset (new Epetra_FEVector(parallel_partitioner));
675 
676  has_ghosts = vector->Map().UniqueGIDs()==false;
677 
678  const int size = parallel_partitioner.NumMyElements();
679 
680  // Need to copy out values, since the deal.II might not use doubles, so
681  // that a direct access is not possible.
682  for (int i=0; i<size; ++i)
683  (*vector)[0][i] = v(gid(parallel_partitioner,i));
684  }
685 
686 
687  inline
688  Vector &
689  Vector::operator= (const TrilinosScalar s)
690  {
692 
693  return *this;
694  }
695 
696 
697  template <typename Number>
698  Vector &
699  Vector::operator= (const ::Vector<Number> &v)
700  {
701  if (size() != v.size())
702  {
703  vector.reset (new Epetra_FEVector(Epetra_Map
704  (static_cast<TrilinosWrappers::types::int_type>(v.size()), 0,
705 #ifdef DEAL_II_WITH_MPI
706  Epetra_MpiComm(MPI_COMM_SELF)
707 #else
708  Epetra_SerialComm()
709 #endif
710  )));
711  }
712 
713  reinit (vector_partitioner(), v);
714  return *this;
715  }
716 
717 
718 #endif /* DOXYGEN */
719 
720  } /* end of namespace MPI */
721 
722 
723 
737  class Vector : public VectorBase
738  {
739  public:
743  typedef ::types::global_dof_index size_type;
744 
755  static const bool supports_distributed_data = false;
756 
762  Vector () DEAL_II_DEPRECATED;
763 
767  explicit Vector (const size_type n) DEAL_II_DEPRECATED;
768 
778  explicit Vector (const Epetra_Map &partitioning) DEAL_II_DEPRECATED;
779 
789  explicit Vector (const IndexSet &partitioning,
790  const MPI_Comm &communicator = MPI_COMM_WORLD) DEAL_II_DEPRECATED;
791 
796  explicit Vector (const VectorBase &V) DEAL_II_DEPRECATED;
797 
802  template <typename Number>
803  explicit Vector (const ::Vector<Number> &v) DEAL_II_DEPRECATED;
804 
814  void reinit (const size_type n,
815  const bool omit_zeroing_entries = false);
816 
834  void reinit (const Epetra_Map &input_map,
835  const bool omit_zeroing_entries = false);
836 
854  void reinit (const IndexSet &input_map,
855  const MPI_Comm &communicator = MPI_COMM_WORLD,
856  const bool omit_zeroing_entries = false);
857 
871  void reinit (const VectorBase &V,
872  const bool omit_zeroing_entries = false,
873  const bool allow_different_maps = false);
874 
881  Vector &operator= (const TrilinosScalar s);
882 
887  Vector &operator= (const MPI::Vector &v);
888 
892  template <typename Number>
893  Vector &operator= (const ::Vector<Number> &v);
894 
899  Vector &operator= (const Vector &v);
900 
912  void update_ghost_values () const;
913  };
914 
915 
916 
917 // ------------------- inline and template functions --------------
918 
919 
928  inline
929  void swap (Vector &u, Vector &v)
930  {
931  u.swap (v);
932  }
933 
934 
935 #ifndef DOXYGEN
936 
937  template <typename number>
938  Vector::Vector (const ::Vector<number> &v)
939  {
940  Epetra_LocalMap map ((TrilinosWrappers::types::int_type)v.size(), 0, Utilities::Trilinos::comm_self());
941  vector.reset (new Epetra_FEVector(map));
942  *this = v;
943  }
944 
945 
946 
947  inline
948  Vector &
949  Vector::operator= (const TrilinosScalar s)
950  {
952 
953  return *this;
954  }
955 
956 
957 
958  template <typename Number>
959  Vector &
960  Vector::operator= (const ::Vector<Number> &v)
961  {
962  if (size() != v.size())
963  {
964  vector.reset();
965 
966  Epetra_LocalMap map ((TrilinosWrappers::types::int_type)v.size(), 0,
968  vector.reset (new Epetra_FEVector(map));
969  }
970 
971  const Epetra_Map &map = vector_partitioner();
972  const TrilinosWrappers::types::int_type size = map.NumMyElements();
973 
974  Assert (map.MaxLID() == size-1,
975  ExcDimensionMismatch(map.MaxLID(), size-1));
976 
977  // Need to copy out values, since the
978  // deal.II might not use doubles, so
979  // that a direct access is not possible.
980  for (TrilinosWrappers::types::int_type i=0; i<size; ++i)
981  (*vector)[0][i] = v(i);
982 
983  return *this;
984  }
985 
986 
987 
988  inline
989  void
991  {}
992 
993 
994 #endif
995 
996 } /* namespace TrilinosWrappers */
997 
1001 namespace internal
1002 {
1003  namespace LinearOperator
1004  {
1005  template <typename> class ReinitHelper;
1006 
1011  template<>
1012  class ReinitHelper<TrilinosWrappers::MPI::Vector>
1013  {
1014  public:
1015  template <typename Matrix>
1016  static
1017  void reinit_range_vector (const Matrix &matrix,
1019  bool omit_zeroing_entries)
1020  {
1021  v.reinit(matrix.locally_owned_range_indices(), matrix.get_mpi_communicator(), omit_zeroing_entries);
1022  }
1023 
1024  template <typename Matrix>
1025  static
1026  void reinit_domain_vector(const Matrix &matrix,
1028  bool omit_zeroing_entries)
1029  {
1030  v.reinit(matrix.locally_owned_domain_indices(), matrix.get_mpi_communicator(), omit_zeroing_entries);
1031  }
1032  };
1033 
1038  template<>
1040  {
1041  public:
1042  template <typename Matrix>
1043  static
1044  void reinit_range_vector (const Matrix &matrix,
1046  bool omit_zeroing_entries)
1047  {
1048  v.reinit(matrix.locally_owned_range_indices(),
1049  matrix.get_mpi_communicator(),
1050  omit_zeroing_entries);
1051  }
1052 
1053  template <typename Matrix>
1054  static
1055  void reinit_domain_vector(const Matrix &matrix,
1057  bool omit_zeroing_entries)
1058  {
1059  v.reinit(matrix.locally_owned_domain_indices(),
1060  matrix.get_mpi_communicator(),
1061  omit_zeroing_entries);
1062  }
1063  };
1064 
1065  } /* namespace LinearOperator */
1066 } /* namespace internal */
1067 
1068 
1069 DEAL_II_NAMESPACE_CLOSE
1070 
1071 #endif // DEAL_II_WITH_TRILINOS
1072 
1073 /*---------------------------- trilinos_vector.h ---------------------------*/
1074 
1075 #endif
1076 /*---------------------------- trilinos_vector.h ---------------------------*/
Vector & operator=(const TrilinosScalar s)
::types::global_dof_index size_type
const Epetra_Comm & comm_self()
Definition: utilities.cc:734
void reinit(const VectorBase &v, const bool omit_zeroing_entries=false, const bool allow_different_maps=false)
std_cxx11::shared_ptr< Epetra_FEVector > vector
#define Assert(cond, exc)
Definition: exceptions.h:294
static::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void swap(Vector &u, Vector &v)
const Epetra_Map & vector_partitioner() const
void import_nonlocal_data_for_fe(const ::TrilinosWrappers::SparseMatrix &matrix, const Vector &vector)
Epetra_Map make_trilinos_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
Definition: index_set.cc:485
VectorBase & operator=(const TrilinosScalar s)
void reinit(const size_type n, const bool omit_zeroing_entries=false)
void update_ghost_values() const
::types::global_dof_index size_type
size_type size() const
static const bool supports_distributed_data