Reference documentation for deal.II version Git f0ecfd8 2016-12-09 00:16:27 +0100
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 
521  explicit Vector (const IndexSet &parallel_partitioning,
522  const MPI_Comm &communicator = MPI_COMM_WORLD);
523 
535  Vector (const IndexSet &local,
536  const IndexSet &ghost,
537  const MPI_Comm &communicator = MPI_COMM_WORLD);
538 
553  Vector (const IndexSet &parallel_partitioning,
554  const VectorBase &v,
555  const MPI_Comm &communicator = MPI_COMM_WORLD);
556 
569  template <typename Number>
570  Vector (const IndexSet &parallel_partitioning,
571  const ::Vector<Number> &v,
572  const MPI_Comm &communicator = MPI_COMM_WORLD);
573 
597  void reinit (const IndexSet &parallel_partitioning,
598  const MPI_Comm &communicator = MPI_COMM_WORLD,
599  const bool omit_zeroing_entries = false);
600 
626  void reinit (const IndexSet &locally_owned_entries,
627  const IndexSet &ghost_entries,
628  const MPI_Comm &communicator = MPI_COMM_WORLD,
629  const bool vector_writable = false);
631  };
632 
633 
634 
635 
636 // ------------------- inline and template functions --------------
637 
638 
647  inline
648  void swap (Vector &u, Vector &v)
649  {
650  u.swap (v);
651  }
652 
653 
654 #ifndef DOXYGEN
655 
656  template <typename number>
657  Vector::Vector (const Epetra_Map &input_map,
658  const ::Vector<number> &v)
659  {
660  reinit (input_map, v);
661  }
662 
663 
664 
665  template <typename number>
666  Vector::Vector (const IndexSet &parallel_partitioner,
667  const ::Vector<number> &v,
668  const MPI_Comm &communicator)
669  {
670  *this = Vector(parallel_partitioner.make_trilinos_map (communicator, true),
671  v);
672  owned_elements = parallel_partitioner;
673  }
674 
675 
676 
677 
678  template <typename number>
679  void Vector::reinit (const Epetra_Map &parallel_partitioner,
680  const ::Vector<number> &v)
681  {
682  if (vector.get() == 0 || vector->Map().SameAs(parallel_partitioner) == false)
683  reinit(parallel_partitioner);
684 
685  const int size = parallel_partitioner.NumMyElements();
686 
687  // Need to copy out values, since the deal.II might not use doubles, so
688  // that a direct access is not possible.
689  for (int i=0; i<size; ++i)
690  (*vector)[0][i] = v(gid(parallel_partitioner,i));
691 
692  }
693 
694 
695  inline
696  Vector &
697  Vector::operator= (const TrilinosScalar s)
698  {
700 
701  return *this;
702  }
703 
704 
705  template <typename Number>
706  Vector &
707  Vector::operator= (const ::Vector<Number> &v)
708  {
709  if (size() != v.size())
710  {
711  vector.reset (new Epetra_FEVector(Epetra_Map
712  (static_cast<TrilinosWrappers::types::int_type>(v.size()), 0,
713 #ifdef DEAL_II_WITH_MPI
714  Epetra_MpiComm(MPI_COMM_SELF)
715 #else
716  Epetra_SerialComm()
717 #endif
718  )));
719  }
720 
721  reinit (vector_partitioner(), v);
722  return *this;
723  }
724 
725 
726 #endif /* DOXYGEN */
727 
728  } /* end of namespace MPI */
729 
730 
731 
745  class Vector : public VectorBase
746  {
747  public:
751  typedef ::types::global_dof_index size_type;
752 
763  static const bool supports_distributed_data = false;
764 
770  Vector () DEAL_II_DEPRECATED;
771 
775  explicit Vector (const size_type n) DEAL_II_DEPRECATED;
776 
786  explicit Vector (const Epetra_Map &partitioning) DEAL_II_DEPRECATED;
787 
797  explicit Vector (const IndexSet &partitioning,
798  const MPI_Comm &communicator = MPI_COMM_WORLD) DEAL_II_DEPRECATED;
799 
804  explicit Vector (const VectorBase &V) DEAL_II_DEPRECATED;
805 
810  template <typename Number>
811  explicit Vector (const ::Vector<Number> &v) DEAL_II_DEPRECATED;
812 
822  void reinit (const size_type n,
823  const bool omit_zeroing_entries = false);
824 
842  void reinit (const Epetra_Map &input_map,
843  const bool omit_zeroing_entries = false);
844 
862  void reinit (const IndexSet &input_map,
863  const MPI_Comm &communicator = MPI_COMM_WORLD,
864  const bool omit_zeroing_entries = false);
865 
879  void reinit (const VectorBase &V,
880  const bool omit_zeroing_entries = false,
881  const bool allow_different_maps = false);
882 
889  Vector &operator= (const TrilinosScalar s);
890 
895  Vector &operator= (const MPI::Vector &v);
896 
900  template <typename Number>
901  Vector &operator= (const ::Vector<Number> &v);
902 
907  Vector &operator= (const Vector &v);
908 
920  void update_ghost_values () const;
921  };
922 
923 
924 
925 // ------------------- inline and template functions --------------
926 
927 
936  inline
937  void swap (Vector &u, Vector &v)
938  {
939  u.swap (v);
940  }
941 
942 
943 #ifndef DOXYGEN
944 
945  template <typename number>
946  Vector::Vector (const ::Vector<number> &v)
947  {
948  Epetra_LocalMap map ((TrilinosWrappers::types::int_type)v.size(), 0, Utilities::Trilinos::comm_self());
949  vector.reset (new Epetra_FEVector(map));
950  *this = v;
951  }
952 
953 
954 
955  inline
956  Vector &
957  Vector::operator= (const TrilinosScalar s)
958  {
960 
961  return *this;
962  }
963 
964 
965 
966  template <typename Number>
967  Vector &
968  Vector::operator= (const ::Vector<Number> &v)
969  {
970  if (size() != v.size())
971  {
972  vector.reset();
973 
974  Epetra_LocalMap map ((TrilinosWrappers::types::int_type)v.size(), 0,
976  vector.reset (new Epetra_FEVector(map));
977  owned_elements = v.locally_owned_elements();
978  }
979 
980  const Epetra_Map &map = vector_partitioner();
981  const TrilinosWrappers::types::int_type size = map.NumMyElements();
982 
983  Assert (map.MaxLID() == size-1,
984  ExcDimensionMismatch(map.MaxLID(), size-1));
985 
986  // Need to copy out values, since the
987  // deal.II might not use doubles, so
988  // that a direct access is not possible.
989  for (TrilinosWrappers::types::int_type i=0; i<size; ++i)
990  (*vector)[0][i] = v(i);
991 
992  return *this;
993  }
994 
995 
996 
997  inline
998  void
1000  {}
1001 
1002 
1003 #endif
1004 
1005 } /* namespace TrilinosWrappers */
1006 
1010 namespace internal
1011 {
1012  namespace LinearOperator
1013  {
1014  template <typename> class ReinitHelper;
1015 
1020  template<>
1021  class ReinitHelper<TrilinosWrappers::MPI::Vector>
1022  {
1023  public:
1024  template <typename Matrix>
1025  static
1026  void reinit_range_vector (const Matrix &matrix,
1028  bool omit_zeroing_entries)
1029  {
1030  v.reinit(matrix.locally_owned_range_indices(), matrix.get_mpi_communicator(), omit_zeroing_entries);
1031  }
1032 
1033  template <typename Matrix>
1034  static
1035  void reinit_domain_vector(const Matrix &matrix,
1037  bool omit_zeroing_entries)
1038  {
1039  v.reinit(matrix.locally_owned_domain_indices(), matrix.get_mpi_communicator(), omit_zeroing_entries);
1040  }
1041  };
1042 
1047  template<>
1049  {
1050  public:
1051  template <typename Matrix>
1052  static
1053  void reinit_range_vector (const Matrix &matrix,
1055  bool omit_zeroing_entries)
1056  {
1057  v.reinit(matrix.locally_owned_range_indices(),
1058  matrix.get_mpi_communicator(),
1059  omit_zeroing_entries);
1060  }
1061 
1062  template <typename Matrix>
1063  static
1064  void reinit_domain_vector(const Matrix &matrix,
1066  bool omit_zeroing_entries)
1067  {
1068  v.reinit(matrix.locally_owned_domain_indices(),
1069  matrix.get_mpi_communicator(),
1070  omit_zeroing_entries);
1071  }
1072  };
1073 
1074  } /* namespace LinearOperator */
1075 } /* namespace internal */
1076 
1077 
1078 DEAL_II_NAMESPACE_CLOSE
1079 
1080 #endif // DEAL_II_WITH_TRILINOS
1081 
1082 /*---------------------------- trilinos_vector.h ---------------------------*/
1083 
1084 #endif
1085 /*---------------------------- 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:299
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:523
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