]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Working
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Fri, 14 Sep 2018 11:59:27 +0000 (13:59 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 20 Feb 2019 12:46:19 +0000 (13:46 +0100)
19 files changed:
cmake/config/template-arguments.in
cmake/configure/configure_2_trilinos.cmake
include/deal.II/dofs/dof_accessor.templates.h
include/deal.II/fe/fe_tools_extrapolate.templates.h
include/deal.II/fe/fe_tools_interpolate.templates.h
include/deal.II/lac/read_write_vector.h
include/deal.II/lac/read_write_vector.templates.h
include/deal.II/lac/trilinos_sparse_matrix.h
include/deal.II/lac/trilinos_tpetra_vector.h
include/deal.II/lac/vector_element_access.h
include/deal.II/multigrid/mg_transfer.h
source/fe/mapping_q1_eulerian.cc
source/lac/trilinos_sparse_matrix.cc
source/lac/trilinos_tpetra_vector.cc
tests/trilinos/tpetra_vector_01.cc
tests/trilinos/tpetra_vector_02.cc
tests/trilinos/tpetra_vector_03.cc
tests/trilinos/tpetra_vector_03.mpirun=2.output
tests/trilinos/tpetra_vector_03.mpirun=4.output

index 17a9f2ba94776fe00e3ce9271db04d6e265c25b5..8a58e905961b18e2fbc7eeb27da242cfade5fc20 100644 (file)
@@ -95,7 +95,8 @@ VECTOR_TYPES := {   Vector<double>;
 
                     @DEAL_II_EXPAND_TRILINOS_MPI_VECTOR@;
                     @DEAL_II_EXPAND_EPETRA_VECTOR@;
-                    @DEAL_II_EXPAND_TPETRA_VECTOR@;
+                    @DEAL_II_EXPAND_TPETRA_VECTOR_DOUBLE@;
+                    @DEAL_II_EXPAND_TPETRA_VECTOR_FLOAT@;
                     @DEAL_II_EXPAND_PETSC_MPI_VECTOR@;
 
                     @DEAL_II_EXPAND_TRILINOS_MPI_BLOCKVECTOR@;
@@ -121,7 +122,8 @@ REAL_VECTOR_TYPES  := {  Vector<double>;
 
                          @DEAL_II_EXPAND_TRILINOS_MPI_VECTOR@;
                          @DEAL_II_EXPAND_EPETRA_VECTOR@;
-                         @DEAL_II_EXPAND_TPETRA_VECTOR@;
+                         @DEAL_II_EXPAND_TPETRA_VECTOR_DOUBLE@;
+                         @DEAL_II_EXPAND_TPETRA_VECTOR_FLOAT@;
                          @DEAL_II_EXPAND_PETSC_MPI_VECTOR_REAL@;
 
                          @DEAL_II_EXPAND_TRILINOS_MPI_BLOCKVECTOR@;
@@ -140,7 +142,8 @@ REAL_NONBLOCK_VECTORS := { Vector<double>;
 
                            @DEAL_II_EXPAND_TRILINOS_MPI_VECTOR@;
                            @DEAL_II_EXPAND_EPETRA_VECTOR@;
-                           @DEAL_II_EXPAND_TPETRA_VECTOR@;
+                           @DEAL_II_EXPAND_TPETRA_VECTOR_DOUBLE@;
+                           @DEAL_II_EXPAND_TPETRA_VECTOR_FLOAT@;
                            @DEAL_II_EXPAND_PETSC_MPI_VECTOR_REAL@;
                          }
 
@@ -148,7 +151,8 @@ REAL_NONBLOCK_VECTORS := { Vector<double>;
 EXTERNAL_PARALLEL_VECTORS := { @DEAL_II_EXPAND_TRILINOS_MPI_VECTOR@;
                                @DEAL_II_EXPAND_TRILINOS_MPI_BLOCKVECTOR@;
                                @DEAL_II_EXPAND_EPETRA_VECTOR@;
-                               @DEAL_II_EXPAND_TPETRA_VECTOR@;
+                               @DEAL_II_EXPAND_TPETRA_VECTOR_DOUBLE@;
+                               @DEAL_II_EXPAND_TPETRA_VECTOR_FLOAT@;
                                @DEAL_II_EXPAND_PETSC_MPI_VECTOR@;
                                @DEAL_II_EXPAND_PETSC_MPI_BLOCKVECTOR@
                              }
@@ -167,7 +171,8 @@ VECTORS_WITH_MATRIX := { Vector<double>;
 
                          @DEAL_II_EXPAND_TRILINOS_MPI_VECTOR@;
                          @DEAL_II_EXPAND_EPETRA_VECTOR@;
-                         @DEAL_II_EXPAND_TPETRA_VECTOR@;
+                         @DEAL_II_EXPAND_TPETRA_VECTOR_DOUBLE@;
+                         @DEAL_II_EXPAND_TPETRA_VECTOR_FLOAT@;
                          @DEAL_II_EXPAND_PETSC_MPI_VECTOR@;
                        }
 
index abe66905d82c2f73b9fb790afa1c9c7624247a75..661c739b7c7f14f1099984052b7b23b1048cebe9 100644 (file)
@@ -227,7 +227,8 @@ MACRO(FEATURE_TRILINOS_CONFIGURE_EXTERNAL)
   SET(DEAL_II_EXPAND_TRILINOS_MPI_VECTOR "TrilinosWrappers::MPI::Vector")
   IF (TRILINOS_WITH_MPI)
     SET(DEAL_II_EXPAND_EPETRA_VECTOR "LinearAlgebra::EpetraWrappers::Vector")
-    SET(DEAL_II_EXPAND_TPETRA_VECTOR "LinearAlgebra::TpetraWrappers::Vector")
+    SET(DEAL_II_EXPAND_TPETRA_VECTOR_DOUBLE "LinearAlgebra::TpetraWrappers::Vector<double>")
+    #SET(DEAL_II_EXPAND_TPETRA_VECTOR_FLOAT "LinearAlgebra::TpetraWrappers::Vector<float>")
   ENDIF()
   IF(${DEAL_II_TRILINOS_WITH_SACADO})
     # Note: Only CMake 3.0 and greater support line continuation with the "\" character
index 73b77c07a57d79e625ca721bc594916578c600b9..9b89e6e31f470c7194cdb01f27035aef19e40684 100644 (file)
@@ -1534,12 +1534,13 @@ namespace internal
 
 
 
-      template <typename ForwardIterator>
+      template <typename ForwardIterator, typename Number>
       static void
-      extract_subvector_to(const LinearAlgebra::TpetraWrappers::Vector &values,
-                           const types::global_dof_index *cache_begin,
-                           const types::global_dof_index *cache_end,
-                           ForwardIterator                local_values_begin)
+      extract_subvector_to(
+        const LinearAlgebra::TpetraWrappers::Vector<Number> &values,
+        const types::global_dof_index *                      cache_begin,
+        const types::global_dof_index *                      cache_end,
+        ForwardIterator                                      local_values_begin)
       {
         std::vector<unsigned int> sorted_indices_pos =
           sort_indices(cache_begin, cache_end);
@@ -1551,7 +1552,7 @@ namespace internal
         IndexSet index_set(cache_indices.back() + 1);
         index_set.add_indices(cache_indices.begin(), cache_indices.end());
         index_set.compress();
-        LinearAlgebra::ReadWriteVector<double> read_write_vector(index_set);
+        LinearAlgebra::ReadWriteVector<Number> read_write_vector(index_set);
         read_write_vector.import(values, VectorOperation::insert);
 
         // Copy the elements from read_write_vector and reorder them.
index 850a4c6216cab919e741f89a0bfc6152d27403d6..ea76059356c799cb0708bcba4f4158a439b0a422 100644 (file)
@@ -1581,10 +1581,10 @@ namespace FETools
 
 
 #  ifdef DEAL_II_WITH_MPI
-    template <int dim, int spacedim>
+    template <int dim, int spacedim, typename Number>
     void
-    reinit_distributed(const DoFHandler<dim, spacedim> &      dh,
-                       LinearAlgebra::TpetraWrappers::Vector &vector)
+    reinit_distributed(const DoFHandler<dim, spacedim> &              dh,
+                       LinearAlgebra::TpetraWrappers::Vector<Number> &vector)
     {
       const parallel::distributed::Triangulation<dim, spacedim> *parallel_tria =
         dynamic_cast<
index e2e9b417fe02a87316d1935c459157ef99c52254..9699c0a9b43dddf2993bc1c0acd4c793075ff59f 100644 (file)
@@ -513,17 +513,17 @@ namespace FETools
       AssertThrow(false, ExcNotImplemented());
     }
 
-    template <int dim, int spacedim>
+    template <int dim, int spacedim, typename Number>
     void
     back_interpolate(
       const DoFHandler<dim, spacedim> &,
       const AffineConstraints<
-        typename LinearAlgebra::TpetraWrappers::Vector::value_type> &,
-      const LinearAlgebra::TpetraWrappers::Vector &,
+        typename LinearAlgebra::TpetraWrappers::Vector<Number>::value_type> &,
+      const LinearAlgebra::TpetraWrappers::Vector<Number> &,
       const DoFHandler<dim, spacedim> &,
       const AffineConstraints<
-        typename LinearAlgebra::TpetraWrappers::Vector::value_type> &,
-      LinearAlgebra::TpetraWrappers::Vector &)
+        typename LinearAlgebra::TpetraWrappers::Vector<Number>::value_type> &,
+      LinearAlgebra::TpetraWrappers::Vector<Number> &)
     {
       AssertThrow(false, ExcNotImplemented());
     }
index 70d89ade7a1c88a3d3a2fb0de2c762f9fc07a567..0ed6f9d829d3f204a6377a566c0beadd12f29210 100644 (file)
@@ -344,8 +344,8 @@ namespace LinearAlgebra
      * performance.
      */
     void
-    import(const TpetraWrappers::Vector &tpetra_vec,
-           VectorOperation::values       operation,
+    import(const TpetraWrappers::Vector<Number> &tpetra_vec,
+           VectorOperation::values               operation,
            const std::shared_ptr<const CommunicationPatternBase>
              &communication_pattern =
                std::shared_ptr<const CommunicationPatternBase>());
@@ -615,10 +615,10 @@ namespace LinearAlgebra
      * used directly.
      */
     void
-    import(const Tpetra::Vector<> &tpetra_vector,
-           const IndexSet &        locally_owned_elements,
-           VectorOperation::values operation,
-           const MPI_Comm &        mpi_comm,
+    import(const Tpetra::Vector<Number> &tpetra_vector,
+           const IndexSet &              locally_owned_elements,
+           VectorOperation::values       operation,
+           const MPI_Comm &              mpi_comm,
            const std::shared_ptr<const CommunicationPatternBase>
              &communication_pattern);
 
index b4437cfd3fbf9de007806af6aa4048ff3c10a09a..87139aedd776fe82d5a5a013cb7b317dbf90bf2f 100644 (file)
@@ -509,10 +509,10 @@ namespace LinearAlgebra
   template <typename Number>
   void
   ReadWriteVector<Number>::import(
-    const Tpetra::Vector<> &vector,
-    const IndexSet &        source_elements,
-    VectorOperation::values operation,
-    const MPI_Comm &        mpi_comm,
+    const Tpetra::Vector<Number> &vector,
+    const IndexSet &              source_elements,
+    VectorOperation::values       operation,
+    const MPI_Comm &              mpi_comm,
     const std::shared_ptr<const CommunicationPatternBase>
       &communication_pattern)
   {
@@ -554,13 +554,13 @@ namespace LinearAlgebra
 
     Tpetra::Export<> tpetra_export(tpetra_comm_pattern->get_tpetra_export());
 
-    Tpetra::Vector<> target_vector(tpetra_export.getSourceMap());
+    Tpetra::Vector<Number> target_vector(tpetra_export.getSourceMap());
     target_vector.doImport(vector, tpetra_export, Tpetra::REPLACE);
 
     const auto *new_values = target_vector.getData().get();
     const auto  size       = target_vector.getLocalLength();
 
-    using size_type = std::decay<decltype(size)>::type;
+    using size_type = typename std::decay<decltype(size)>::type;
 
     Assert(size == 0 || values != nullptr, ExcInternalError("Export failed."));
     AssertDimension(size, stored_elements.n_elements());
@@ -741,8 +741,8 @@ namespace LinearAlgebra
   template <typename Number>
   void
   ReadWriteVector<Number>::import(
-    const LinearAlgebra::TpetraWrappers::Vector &trilinos_vec,
-    VectorOperation::values                      operation,
+    const LinearAlgebra::TpetraWrappers::Vector<Number> &trilinos_vec,
+    VectorOperation::values                              operation,
     const std::shared_ptr<const CommunicationPatternBase>
       &communication_pattern)
   {
index 006dc31712195ad6f1326f79cd90ef373d39bd8c..b158a224d493619427b1647fc8e397acd29f6c02 100644 (file)
@@ -1317,6 +1317,14 @@ namespace TrilinosWrappers
      * initialize the matrix with a sparsity pattern to fix the matrix
      * structure before inserting elements.
      */
+    template <typename Number>
+    void
+    set(const size_type  row,
+        const size_type  n_cols,
+        const size_type *col_indices,
+        const Number *   values,
+        const bool       elide_zero_values = false);
+
     void
     set(const size_type       row,
         const size_type       n_cols,
index df0b0c99c58131ad21551af9fd1f95c481a8dcc2..798248703ab4ef2e6dc59e20b991177df37fea13 100644 (file)
@@ -51,16 +51,20 @@ namespace LinearAlgebra
     /**
      * This class implements a wrapper to the Trilinos distributed vector
      * class Tpetra::Vector. This class is derived from the
-     * LinearAlgebra::VectorSpaceVector class. Note however that Tpetra only
-     * works with Number = double.
+     * LinearAlgebra::VectorSpaceVector class.
      *
      * @ingroup TrilinosWrappers
      * @ingroup Vectors
      * @author Daniel Arndt, 2018
      */
-    class Vector : public VectorSpaceVector<double>, public Subscriptor
+    template <typename Number>
+    class Vector : public VectorSpaceVector<Number>, public Subscriptor
     {
     public:
+      using value_type = Number;
+
+      using size_type = typename VectorSpaceVector<Number>::size_type;
+
       /**
        * Constructor. Create a vector of dimension zero.
        */
@@ -97,7 +101,7 @@ namespace LinearAlgebra
        * copied.
        */
       virtual void
-      reinit(const VectorSpaceVector<double> &V,
+      reinit(const VectorSpaceVector<Number> &V,
              const bool omit_zeroing_entries = false) override;
 
       /**
@@ -113,7 +117,7 @@ namespace LinearAlgebra
        * only allowed if @p s is equal to zero.
        */
       virtual Vector &
-      operator=(const double s) override;
+      operator=(const Number s) override;
 
       /**
        * Imports all the elements present in the vector's IndexSet from the
@@ -126,7 +130,7 @@ namespace LinearAlgebra
        */
       virtual void
       import(
-        const ReadWriteVector<double> &                 V,
+        const ReadWriteVector<Number> &                 V,
         VectorOperation::values                         operation,
         std::shared_ptr<const CommunicationPatternBase> communication_pattern =
           std::shared_ptr<const CommunicationPatternBase>()) override;
@@ -135,64 +139,64 @@ namespace LinearAlgebra
        * Multiply the entire vector by a fixed factor.
        */
       virtual Vector &
-      operator*=(const double factor) override;
+      operator*=(const Number factor) override;
 
       /**
        * Divide the entire vector by a fixed factor.
        */
       virtual Vector &
-      operator/=(const double factor) override;
+      operator/=(const Number factor) override;
 
       /**
        * Add the vector @p V to the present one.
        */
       virtual Vector &
-      operator+=(const VectorSpaceVector<double> &V) override;
+      operator+=(const VectorSpaceVector<Number> &V) override;
 
       /**
        * Subtract the vector @p V from the present one.
        */
       virtual Vector &
-      operator-=(const VectorSpaceVector<double> &V) override;
+      operator-=(const VectorSpaceVector<Number> &V) override;
 
       /**
        * Return the scalar product of two vectors. The vectors need to have the
        * same layout.
        */
-      virtual double
-      operator*(const VectorSpaceVector<double> &V) const override;
+      virtual Number
+      operator*(const VectorSpaceVector<Number> &V) const override;
 
       /**
        * Add @p a to all components. Note that @p is a scalar not a vector.
        */
       virtual void
-      add(const double a) override;
+      add(const Number a) override;
 
       /**
        * Simple addition of a multiple of a vector, i.e. <tt>*this +=
        * a*V</tt>. The vectors need to have the same layout.
        */
       virtual void
-      add(const double a, const VectorSpaceVector<double> &V) override;
+      add(const Number a, const VectorSpaceVector<Number> &V) override;
 
       /**
        * Multiple addition of multiple of a vector, i.e. <tt>*this> +=
        * a*V+b*W</tt>. The vectors need to have the same layout.
        */
       virtual void
-      add(const double                     a,
-          const VectorSpaceVector<double> &V,
-          const double                     b,
-          const VectorSpaceVector<double> &W) override;
+      add(const Number                     a,
+          const VectorSpaceVector<Number> &V,
+          const Number                     b,
+          const VectorSpaceVector<Number> &W) override;
 
       /**
        * Scaling and simple addition of a multiple of a vector, i.e. <tt>*this
        * = s*(*this)+a*V</tt>.
        */
       virtual void
-      sadd(const double                     s,
-           const double                     a,
-           const VectorSpaceVector<double> &V) override;
+      sadd(const Number                     s,
+           const Number                     a,
+           const VectorSpaceVector<Number> &V) override;
 
       /**
        * Scale each element of this vector by the corresponding element in the
@@ -201,13 +205,13 @@ namespace LinearAlgebra
        * vectors need to have the same layout.
        */
       virtual void
-      scale(const VectorSpaceVector<double> &scaling_factors) override;
+      scale(const VectorSpaceVector<Number> &scaling_factors) override;
 
       /**
        * Assignment <tt>*this = a*V</tt>.
        */
       virtual void
-      equ(const double a, const VectorSpaceVector<double> &V) override;
+      equ(const Number a, const VectorSpaceVector<Number> &V) override;
 
       /**
        * Return whether the vector contains only elements with value zero.
@@ -218,28 +222,28 @@ namespace LinearAlgebra
       /**
        * Return the mean value of the element of this vector.
        */
-      virtual double
+      virtual Number
       mean_value() const override;
 
       /**
        * Return the l<sub>1</sub> norm of the vector (i.e., the sum of the
        * absolute values of all entries among all processors).
        */
-      virtual double
+      virtual typename LinearAlgebra::VectorSpaceVector<Number>::real_type
       l1_norm() const override;
 
       /**
        * Return the l<sub>2</sub> norm of the vector (i.e., the square root of
        * the sum of the square of all entries among all processors).
        */
-      virtual double
+      virtual typename LinearAlgebra::VectorSpaceVector<Number>::real_type
       l2_norm() const override;
 
       /**
        * Return the maximum norm of the vector (i.e., the maximum absolute value
        * among all entries and among all processors).
        */
-      virtual double
+      virtual typename LinearAlgebra::VectorSpaceVector<Number>::real_type
       linfty_norm() const override;
 
       /**
@@ -264,10 +268,10 @@ namespace LinearAlgebra
        * implemented as
        * $\left<v,w\right>=\sum_i v_i \bar{w_i}$.
        */
-      virtual double
-      add_and_dot(const double                     a,
-                  const VectorSpaceVector<double> &V,
-                  const VectorSpaceVector<double> &W) override;
+      virtual Number
+      add_and_dot(const Number                     a,
+                  const VectorSpaceVector<Number> &V,
+                  const VectorSpaceVector<Number> &W) override;
       /**
        * This function always returns false and is present only for backward
        * compatibility.
@@ -306,14 +310,14 @@ namespace LinearAlgebra
        * Return a const reference to the underlying Trilinos
        * Tpetra::Vector class.
        */
-      const Tpetra::Vector<> &
+      const Tpetra::Vector<Number> &
       trilinos_vector() const;
 
       /**
        * Return a (modifyable) reference to the underlying Trilinos
        * Tpetra::Vector class.
        */
-      Tpetra::Vector<> &
+      Tpetra::Vector<Number> &
       trilinos_vector();
 
       /**
@@ -367,7 +371,7 @@ namespace LinearAlgebra
       /**
        * Pointer to the actual Tpetra vector object.
        */
-      std::unique_ptr<Tpetra::Vector<>> vector;
+      std::unique_ptr<Tpetra::Vector<Number>> vector;
 
       /**
        * IndexSet of the elements of the last imported vector.
@@ -383,8 +387,9 @@ namespace LinearAlgebra
     };
 
 
+    template <typename Number>
     inline bool
-    Vector::has_ghost_elements() const
+    Vector<Number>::has_ghost_elements() const
     {
       return false;
     }
@@ -395,8 +400,9 @@ namespace LinearAlgebra
 /**
  * Declare dealii::LinearAlgebra::TpetraWrappers::Vector as distributed vector.
  */
-template <>
-struct is_serial_vector<LinearAlgebra::TpetraWrappers::Vector> : std::false_type
+template <typename Number>
+struct is_serial_vector<LinearAlgebra::TpetraWrappers::Vector<Number>>
+  : std::false_type
 {};
 
 DEAL_II_NAMESPACE_CLOSE
index b168260588851e9152285588e41de38e0d70c416..22e541033c520f1677002513f08fec06588b052b 100644 (file)
@@ -127,13 +127,13 @@ namespace internal
 
   template <>
   inline void
-  ElementAccess<LinearAlgebra::TpetraWrappers::Vector>::add(
-    const double                           value,
-    const types::global_dof_index          i,
-    LinearAlgebra::TpetraWrappers::Vector &V)
+  ElementAccess<LinearAlgebra::TpetraWrappers::Vector<double>>::add(
+    const double                                   value,
+    const types::global_dof_index                  i,
+    LinearAlgebra::TpetraWrappers::Vector<double> &V)
   {
     // Extract local indices in the vector.
-    Tpetra::Vector<>                  vector = V.trilinos_vector();
+    Tpetra::Vector<double>            vector = V.trilinos_vector();
     TrilinosWrappers::types::int_type trilinos_i =
       vector.getMap()->getLocalElement(
         static_cast<TrilinosWrappers::types::int_type>(i));
@@ -144,20 +144,68 @@ namespace internal
     // We're going to modify the data on host.
     vector.modify<Kokkos::HostSpace>();
     vector_1d(trilinos_i) += value;
-    vector.sync<Tpetra::Vector<>::device_type::memory_space>();
+    vector.sync<Tpetra::Vector<double>::device_type::memory_space>();
   }
 
 
 
   template <>
   inline void
-  ElementAccess<LinearAlgebra::TpetraWrappers::Vector>::set(
-    const double                           value,
-    const types::global_dof_index          i,
-    LinearAlgebra::TpetraWrappers::Vector &V)
+  ElementAccess<LinearAlgebra::TpetraWrappers::Vector<float>>::add(
+    const float                                   value,
+    const types::global_dof_index                 i,
+    LinearAlgebra::TpetraWrappers::Vector<float> &V)
+  {
+    // Extract local indices in the vector.
+    Tpetra::Vector<float>             vector = V.trilinos_vector();
+    TrilinosWrappers::types::int_type trilinos_i =
+      vector.getMap()->getLocalElement(
+        static_cast<TrilinosWrappers::types::int_type>(i));
+
+    vector.sync<Kokkos::HostSpace>();
+    auto vector_2d = vector.getLocalView<Kokkos::HostSpace>();
+    auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
+    // We're going to modify the data on host.
+    vector.modify<Kokkos::HostSpace>();
+    vector_1d(trilinos_i) += value;
+    vector.sync<Tpetra::Vector<float>::device_type::memory_space>();
+  }
+
+
+
+  template <>
+  inline void
+  ElementAccess<LinearAlgebra::TpetraWrappers::Vector<double>>::set(
+    const double                                   value,
+    const types::global_dof_index                  i,
+    LinearAlgebra::TpetraWrappers::Vector<double> &V)
+  {
+    // Extract local indices in the vector.
+    Tpetra::Vector<double>            vector = V.trilinos_vector();
+    TrilinosWrappers::types::int_type trilinos_i =
+      vector.getMap()->getLocalElement(
+        static_cast<TrilinosWrappers::types::int_type>(i));
+
+    vector.sync<Kokkos::HostSpace>();
+    auto vector_2d = vector.getLocalView<Kokkos::HostSpace>();
+    auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
+    // We're going to modify the data on host.
+    vector.modify<Kokkos::HostSpace>();
+    vector_1d(trilinos_i) = value;
+    vector.sync<Tpetra::Vector<double>::device_type::memory_space>();
+  }
+
+
+
+  template <>
+  inline void
+  ElementAccess<LinearAlgebra::TpetraWrappers::Vector<float>>::set(
+    const float                                   value,
+    const types::global_dof_index                 i,
+    LinearAlgebra::TpetraWrappers::Vector<float> &V)
   {
     // Extract local indices in the vector.
-    Tpetra::Vector<>                  vector = V.trilinos_vector();
+    Tpetra::Vector<float>             vector = V.trilinos_vector();
     TrilinosWrappers::types::int_type trilinos_i =
       vector.getMap()->getLocalElement(
         static_cast<TrilinosWrappers::types::int_type>(i));
@@ -168,18 +216,40 @@ namespace internal
     // We're going to modify the data on host.
     vector.modify<Kokkos::HostSpace>();
     vector_1d(trilinos_i) = value;
-    vector.sync<Tpetra::Vector<>::device_type::memory_space>();
+    vector.sync<Tpetra::Vector<float>::device_type::memory_space>();
   }
 
 
+
   template <>
   inline double
-  ElementAccess<LinearAlgebra::TpetraWrappers::Vector>::get(
-    const LinearAlgebra::TpetraWrappers::Vector &V,
-    const types::global_dof_index                i)
+  ElementAccess<LinearAlgebra::TpetraWrappers::Vector<double>>::get(
+    const LinearAlgebra::TpetraWrappers::Vector<double> &V,
+    const types::global_dof_index                        i)
+  {
+    // Extract local indices in the vector.
+    Tpetra::Vector<double>            vector = V.trilinos_vector();
+    TrilinosWrappers::types::int_type trilinos_i =
+      vector.getMap()->getLocalElement(
+        static_cast<TrilinosWrappers::types::int_type>(i));
+
+    vector.sync<Kokkos::HostSpace>();
+    auto vector_2d = vector.getLocalView<Kokkos::HostSpace>();
+    auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
+    // We're going to modify the data on host.
+    return vector_1d(trilinos_i);
+  }
+
+
+
+  template <>
+  inline float
+  ElementAccess<LinearAlgebra::TpetraWrappers::Vector<float>>::get(
+    const LinearAlgebra::TpetraWrappers::Vector<float> &V,
+    const types::global_dof_index                       i)
   {
     // Extract local indices in the vector.
-    Tpetra::Vector<>                  vector = V.trilinos_vector();
+    Tpetra::Vector<float>             vector = V.trilinos_vector();
     TrilinosWrappers::types::int_type trilinos_i =
       vector.getMap()->getLocalElement(
         static_cast<TrilinosWrappers::types::int_type>(i));
index e4b4f3db2ac911ac493d75fca5a7bf760750e45b..961b0223dfc32f4a33fe07a55a005da000b36652 100644 (file)
@@ -132,8 +132,8 @@ namespace internal
   };
 
 #  ifdef DEAL_II_WITH_MPI
-  template <>
-  struct MatrixSelector<dealii::LinearAlgebra::TpetraWrappers::Vector>
+  template <typename Number>
+  struct MatrixSelector<dealii::LinearAlgebra::TpetraWrappers::Vector<Number>>
   {
     using Sparsity = ::dealii::TrilinosWrappers::SparsityPattern;
     using Matrix   = ::dealii::TrilinosWrappers::SparseMatrix;
index 666a7bef6e04a4acb062eb2ba1737d04c70ec17e..3c99fb8c833671a37441d859035127af3f095238 100644 (file)
@@ -77,7 +77,8 @@ MappingQ1Eulerian<dim, VectorType, spacedim>::get_vertices(
   Assert(dof_cell->active() == true, ExcInactiveCell());
 
   // now get the values of the shift vectors at the vertices
-  Vector<double> mapping_values(shiftmap_dof_handler->get_fe().dofs_per_cell);
+  Vector<typename VectorType::value_type> mapping_values(
+    shiftmap_dof_handler->get_fe().dofs_per_cell);
   dof_cell->get_dof_values(*euler_transform_vectors, mapping_values);
 
   for (unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_cell; ++i)
index 350006da3ccabd5811807a7a3b7ebff91ac59961..0996f76053ee05c4c842e24636f2a0bb3d33913a 100644 (file)
@@ -48,28 +48,28 @@ namespace TrilinosWrappers
   namespace internal
   {
     template <typename VectorType>
-    double *
+    typename VectorType::value_type *
     begin(VectorType &V)
     {
       return V.begin();
     }
 
     template <typename VectorType>
-    const double *
+    const typename VectorType::value_type *
     begin(const VectorType &V)
     {
       return V.begin();
     }
 
     template <typename VectorType>
-    double *
+    typename VectorType::value_type *
     end(VectorType &V)
     {
       return V.end();
     }
 
     template <typename VectorType>
-    const double *
+    const typename VectorType::value_type *
     end(const VectorType &V)
     {
       return V.end();
@@ -104,31 +104,31 @@ namespace TrilinosWrappers
       return V.trilinos_vector()[0] + V.trilinos_vector().MyLength();
     }
 
-    template <>
-    double *
-    begin(LinearAlgebra::TpetraWrappers::Vector &V)
+    template <typename Number>
+    Number *
+    begin(LinearAlgebra::TpetraWrappers::Vector<Number> &V)
     {
       return V.trilinos_vector().getDataNonConst().get();
     }
 
-    template <>
-    const double *
-    begin(const LinearAlgebra::TpetraWrappers::Vector &V)
+    template <typename Number>
+    const Number *
+    begin(const LinearAlgebra::TpetraWrappers::Vector<Number> &V)
     {
       return V.trilinos_vector().getData().get();
     }
 
-    template <>
-    double *
-    end(LinearAlgebra::TpetraWrappers::Vector &V)
+    template <typename Number>
+    Number *
+    end(LinearAlgebra::TpetraWrappers::Vector<Number> &V)
     {
       return V.trilinos_vector().getDataNonConst().get() +
              V.trilinos_vector().getLocalLength();
     }
 
-    template <>
-    const double *
-    end(const LinearAlgebra::TpetraWrappers::Vector &V)
+    template <typename Number>
+    const Number *
+    end(const LinearAlgebra::TpetraWrappers::Vector<Number> &V)
     {
       return V.trilinos_vector().getData().get() +
              V.trilinos_vector().getLocalLength();
@@ -1540,6 +1540,22 @@ namespace TrilinosWrappers
 
 
 
+  template <typename Number>
+  void
+  SparseMatrix::set(const size_type  row,
+                    const size_type  n_cols,
+                    const size_type *col_indices,
+                    const Number *   values,
+                    const bool       elide_zero_values)
+  {
+    std::vector<TrilinosScalar> trilinos_values(n_cols);
+    std::copy(values, values + n_cols, trilinos_values.begin());
+    this->set(
+      row, n_cols, col_indices, trilinos_values.data(), elide_zero_values);
+  }
+
+
+
   void
   SparseMatrix::set(const size_type       row,
                     const size_type       n_cols,
@@ -3476,78 +3492,98 @@ namespace TrilinosWrappers
 
   template void
   SparseMatrix::vmult(MPI::Vector &, const MPI::Vector &) const;
+
   template void
   SparseMatrix::vmult(dealii::Vector<double> &,
                       const dealii::Vector<double> &) const;
+
   template void
   SparseMatrix::vmult(
     dealii::LinearAlgebra::distributed::Vector<double> &,
     const dealii::LinearAlgebra::distributed::Vector<double> &) const;
+
 #  ifdef DEAL_II_WITH_MPI
   template void
   SparseMatrix::vmult(
-    dealii::LinearAlgebra::TpetraWrappers::Vector &,
-    const dealii::LinearAlgebra::TpetraWrappers::Vector &) const;
+    dealii::LinearAlgebra::TpetraWrappers::Vector<double> &,
+    const dealii::LinearAlgebra::TpetraWrappers::Vector<double> &) const;
+
+  /*template void
+     SparseMatrix::vmult(
+       dealii::LinearAlgebra::TpetraWrappers::Vector<float> &,
+       const dealii::LinearAlgebra::TpetraWrappers::Vector<float> &) const;*/
 
   template void
   SparseMatrix::vmult(
     dealii::LinearAlgebra::EpetraWrappers::Vector &,
     const dealii::LinearAlgebra::EpetraWrappers::Vector &) const;
 #  endif
+
   template void
   SparseMatrix::Tvmult(MPI::Vector &, const MPI::Vector &) const;
+
   template void
   SparseMatrix::Tvmult(dealii::Vector<double> &,
                        const dealii::Vector<double> &) const;
+
   template void
   SparseMatrix::Tvmult(
     dealii::LinearAlgebra::distributed::Vector<double> &,
     const dealii::LinearAlgebra::distributed::Vector<double> &) const;
+
 #  ifdef DEAL_II_WITH_MPI
   template void
   SparseMatrix::Tvmult(
-    dealii::LinearAlgebra::TpetraWrappers::Vector &,
-    const dealii::LinearAlgebra::TpetraWrappers::Vector &) const;
+    dealii::LinearAlgebra::TpetraWrappers::Vector<double> &,
+    const dealii::LinearAlgebra::TpetraWrappers::Vector<double> &) const;
 
   template void
   SparseMatrix::Tvmult(
     dealii::LinearAlgebra::EpetraWrappers::Vector &,
     const dealii::LinearAlgebra::EpetraWrappers::Vector &) const;
 #  endif
+
   template void
   SparseMatrix::vmult_add(MPI::Vector &, const MPI::Vector &) const;
+
   template void
   SparseMatrix::vmult_add(dealii::Vector<double> &,
                           const dealii::Vector<double> &) const;
+
   template void
   SparseMatrix::vmult_add(
     dealii::LinearAlgebra::distributed::Vector<double> &,
     const dealii::LinearAlgebra::distributed::Vector<double> &) const;
+
 #  ifdef DEAL_II_WITH_MPI
   template void
   SparseMatrix::vmult_add(
-    dealii::LinearAlgebra::TpetraWrappers::Vector &,
-    const dealii::LinearAlgebra::TpetraWrappers::Vector &) const;
+    dealii::LinearAlgebra::TpetraWrappers::Vector<double> &,
+    const dealii::LinearAlgebra::TpetraWrappers::Vector<double> &) const;
 
   template void
   SparseMatrix::vmult_add(
     dealii::LinearAlgebra::EpetraWrappers::Vector &,
     const dealii::LinearAlgebra::EpetraWrappers::Vector &) const;
 #  endif
+
   template void
   SparseMatrix::Tvmult_add(MPI::Vector &, const MPI::Vector &) const;
+
   template void
   SparseMatrix::Tvmult_add(dealii::Vector<double> &,
                            const dealii::Vector<double> &) const;
+
   template void
   SparseMatrix::Tvmult_add(
     dealii::LinearAlgebra::distributed::Vector<double> &,
     const dealii::LinearAlgebra::distributed::Vector<double> &) const;
+
 #  ifdef DEAL_II_WITH_MPI
   template void
   SparseMatrix::Tvmult_add(
-    dealii::LinearAlgebra::TpetraWrappers::Vector &,
-    const dealii::LinearAlgebra::TpetraWrappers::Vector &) const;
+    dealii::LinearAlgebra::TpetraWrappers::Vector<double> &,
+    const dealii::LinearAlgebra::TpetraWrappers::Vector<double> &) const;
 
   template void
   SparseMatrix::Tvmult_add(
index 5e3c00b53ad46f5f7f361c4197031117cb76ef8b..88324e6d53a7f819fc2e63201f28e6b6a9a88092 100644 (file)
@@ -40,37 +40,41 @@ namespace LinearAlgebra
 {
   namespace TpetraWrappers
   {
-    Vector::Vector()
-      : vector(new Tpetra::Vector<>(Teuchos::RCP<Tpetra::Map<>>(
+    template <typename Number>
+    Vector<Number>::Vector()
+      : vector(new Tpetra::Vector<Number>(Teuchos::RCP<Tpetra::Map<>>(
           new Tpetra::Map<>(0, 0, Utilities::Trilinos::tpetra_comm_self()))))
     {}
 
 
 
-    Vector::Vector(const Vector &V)
+    template <typename Number>
+    Vector<Number>::Vector(const Vector<Number> &V)
       : Subscriptor()
-      , vector(new Tpetra::Vector<>(V.trilinos_vector(), Teuchos::Copy))
+      , vector(new Tpetra::Vector<Number>(V.trilinos_vector(), Teuchos::Copy))
     {}
 
 
 
-    Vector::Vector(const IndexSet &parallel_partitioner,
-                   const MPI_Comm &communicator)
-      : vector(new Tpetra::Vector<>(Teuchos::rcp(new Tpetra::Map<>(
+    template <typename Number>
+    Vector<Number>::Vector(const IndexSet &parallel_partitioner,
+                           const MPI_Comm &communicator)
+      : vector(new Tpetra::Vector<Number>(Teuchos::rcp(new Tpetra::Map<>(
           parallel_partitioner.make_tpetra_map(communicator, false)))))
     {}
 
 
 
+    template <typename Number>
     void
-    Vector::reinit(const IndexSet &parallel_partitioner,
-                   const MPI_Comm &communicator,
-                   const bool      omit_zeroing_entries)
+    Vector<Number>::reinit(const IndexSet &parallel_partitioner,
+                           const MPI_Comm &communicator,
+                           const bool      omit_zeroing_entries)
     {
       Tpetra::Map<> input_map =
         parallel_partitioner.make_tpetra_map(communicator, false);
       if (vector->getMap()->isSameAs(input_map) == false)
-        vector = std_cxx14::make_unique<Tpetra::Vector<>>(
+        vector = std_cxx14::make_unique<Tpetra::Vector<Number>>(
           Teuchos::rcp(new Tpetra::Map<>(input_map)));
       else if (omit_zeroing_entries == false)
         {
@@ -80,16 +84,17 @@ namespace LinearAlgebra
 
 
 
+    template <typename Number>
     void
-    Vector::reinit(const VectorSpaceVector<double> &V,
-                   const bool                       omit_zeroing_entries)
+    Vector<Number>::reinit(const VectorSpaceVector<Number> &V,
+                           const bool omit_zeroing_entries)
     {
       // Check that casting will work.
-      Assert(dynamic_cast<const Vector *>(&V) != nullptr,
+      Assert(dynamic_cast<const Vector<Number> *>(&V) != nullptr,
              ExcVectorTypeNotCompatible());
 
       // Downcast V. If fails, throws an exception.
-      const Vector &down_V = dynamic_cast<const Vector &>(V);
+      const Vector<Number> &down_V = dynamic_cast<const Vector<Number> &>(V);
 
       reinit(down_V.locally_owned_elements(),
              down_V.get_mpi_communicator(),
@@ -98,8 +103,9 @@ namespace LinearAlgebra
 
 
 
-    Vector &
-    Vector::operator=(const Vector &V)
+    template <typename Number>
+    Vector<Number> &
+    Vector<Number>::operator=(const Vector<Number> &V)
     {
       // Distinguish three cases:
       //  - First case: both vectors have the same layout.
@@ -119,8 +125,8 @@ namespace LinearAlgebra
                                Tpetra::REPLACE);
             }
           else
-            vector =
-              std_cxx14::make_unique<Tpetra::Vector<>>(V.trilinos_vector());
+            vector = std_cxx14::make_unique<Tpetra::Vector<Number>>(
+              V.trilinos_vector());
         }
 
       return *this;
@@ -128,10 +134,12 @@ namespace LinearAlgebra
 
 
 
-    Vector &
-    Vector::operator=(const double s)
+    template <typename Number>
+    Vector<Number> &
+    Vector<Number>::operator=(const Number s)
     {
-      Assert(s == 0., ExcMessage("Only 0 can be assigned to a vector."));
+      Assert(s == Number(0.),
+             ExcMessage("Only 0 can be assigned to a vector."));
 
       vector->putScalar(s);
 
@@ -140,9 +148,10 @@ namespace LinearAlgebra
 
 
 
+    template <typename Number>
     void
-    Vector::import(
-      const ReadWriteVector<double> &                 V,
+    Vector<Number>::import(
+      const ReadWriteVector<Number> &                 V,
       VectorOperation::values                         operation,
       std::shared_ptr<const CommunicationPatternBase> communication_pattern)
     {
@@ -177,17 +186,18 @@ namespace LinearAlgebra
         }
 
       Tpetra::Export<> tpetra_export(tpetra_comm_pattern->get_tpetra_export());
-      Tpetra::Vector<> source_vector(tpetra_export.getSourceMap());
+      Tpetra::Vector<Number> source_vector(tpetra_export.getSourceMap());
 
-      source_vector.sync<Kokkos::HostSpace>();
-      auto x_2d = source_vector.getLocalView<Kokkos::HostSpace>();
+      source_vector.template sync<Kokkos::HostSpace>();
+      auto x_2d = source_vector.template getLocalView<Kokkos::HostSpace>();
       auto x_1d = Kokkos::subview(x_2d, Kokkos::ALL(), 0);
-      source_vector.modify<Kokkos::HostSpace>();
+      source_vector.template modify<Kokkos::HostSpace>();
       const size_t localLength = source_vector.getLocalLength();
       auto         values_it   = V.begin();
       for (size_t k = 0; k < localLength; ++k)
         x_1d(k) = *values_it++;
-      source_vector.sync<Tpetra::Vector<double>::device_type::memory_space>();
+      source_vector.template sync<
+        typename Tpetra::Vector<Number>::device_type::memory_space>();
       if (operation == VectorOperation::insert)
         vector->doExport(source_vector, tpetra_export, Tpetra::REPLACE);
       else if (operation == VectorOperation::add)
@@ -198,8 +208,9 @@ namespace LinearAlgebra
 
 
 
-    Vector &
-    Vector::operator*=(const double factor)
+    template <typename Number>
+    Vector<Number> &
+    Vector<Number>::operator*=(const Number factor)
     {
       AssertIsFinite(factor);
       vector->scale(factor);
@@ -209,27 +220,29 @@ namespace LinearAlgebra
 
 
 
-    Vector &
-    Vector::operator/=(const double factor)
+    template <typename Number>
+    Vector<Number> &
+    Vector<Number>::operator/=(const Number factor)
     {
       AssertIsFinite(factor);
-      Assert(factor != 0., ExcZero());
-      *this *= 1. / factor;
+      Assert(factor != Number(0.), ExcZero());
+      *this *= Number(1.) / factor;
 
       return *this;
     }
 
 
 
-    Vector &
-    Vector::operator+=(const VectorSpaceVector<double> &V)
+    template <typename Number>
+    Vector<Number> &
+    Vector<Number>::operator+=(const VectorSpaceVector<Number> &V)
     {
       // Check that casting will work.
-      Assert(dynamic_cast<const Vector *>(&V) != nullptr,
+      Assert(dynamic_cast<const Vector<Number> *>(&V) != nullptr,
              ExcVectorTypeNotCompatible());
 
       // Downcast V. If fails, throws an exception.
-      const Vector &down_V = dynamic_cast<const Vector &>(V);
+      const Vector<Number> &down_V = dynamic_cast<const Vector<Number> &>(V);
       // If the maps are the same we can Update right away.
       if (vector->getMap()->isSameAs(*(down_V.trilinos_vector().getMap())))
         {
@@ -247,8 +260,8 @@ namespace LinearAlgebra
                            data_exchange,
                            Tpetra::ADD);*/
 
-          Tpetra::Vector<> dummy(vector->getMap(), false);
-          Tpetra::Import<> data_exchange(dummy.getMap(),
+          Tpetra::Vector<Number> dummy(vector->getMap(), false);
+          Tpetra::Import<>       data_exchange(dummy.getMap(),
                                          down_V.trilinos_vector().getMap());
 
           dummy.doExport(down_V.trilinos_vector(),
@@ -263,8 +276,9 @@ namespace LinearAlgebra
 
 
 
-    Vector &
-    Vector::operator-=(const VectorSpaceVector<double> &V)
+    template <typename Number>
+    Vector<Number> &
+    Vector<Number>::operator-=(const VectorSpaceVector<Number> &V)
     {
       this->add(-1., V);
 
@@ -273,14 +287,15 @@ namespace LinearAlgebra
 
 
 
-    double Vector::operator*(const VectorSpaceVector<double> &V) const
+    template <typename Number>
+    Number Vector<Number>::operator*(const VectorSpaceVector<Number> &V) const
     {
       // Check that casting will work.
-      Assert(dynamic_cast<const Vector *>(&V) != nullptr,
+      Assert(dynamic_cast<const Vector<Number> *>(&V) != nullptr,
              ExcVectorTypeNotCompatible());
 
       // Downcast V. If fails, throws an exception.
-      const Vector &down_V = dynamic_cast<const Vector &>(V);
+      const Vector<Number> &down_V = dynamic_cast<const Vector<Number> &>(V);
       Assert(this->size() == down_V.size(),
              ExcDimensionMismatch(this->size(), down_V.size()));
       Assert(vector->getMap()->isSameAs(*down_V.trilinos_vector().getMap()),
@@ -291,34 +306,37 @@ namespace LinearAlgebra
 
 
 
+    template <typename Number>
     void
-    Vector::add(const double a)
+    Vector<Number>::add(const Number a)
     {
       AssertIsFinite(a);
 
-      vector->sync<Kokkos::HostSpace>();
-      auto vector_2d = vector->getLocalView<Kokkos::HostSpace>();
+      vector->template sync<Kokkos::HostSpace>();
+      auto vector_2d = vector->template getLocalView<Kokkos::HostSpace>();
       auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
-      vector->modify<Kokkos::HostSpace>();
+      vector->template modify<Kokkos::HostSpace>();
       const size_t localLength = vector->getLocalLength();
       for (size_t k = 0; k < localLength; ++k)
         {
           vector_1d(k) += a;
         }
-      vector->sync<Tpetra::Vector<double>::device_type::memory_space>();
+      vector->template sync<
+        typename Tpetra::Vector<Number>::device_type::memory_space>();
     }
 
 
 
+    template <typename Number>
     void
-    Vector::add(const double a, const VectorSpaceVector<double> &V)
+    Vector<Number>::add(const Number a, const VectorSpaceVector<Number> &V)
     {
       // Check that casting will work.
-      Assert(dynamic_cast<const Vector *>(&V) != nullptr,
+      Assert(dynamic_cast<const Vector<Number> *>(&V) != nullptr,
              ExcVectorTypeNotCompatible());
 
       // Downcast V. If fails, throws an exception.
-      const Vector &down_V = dynamic_cast<const Vector &>(V);
+      const Vector<Number> &down_V = dynamic_cast<const Vector<Number> &>(V);
       AssertIsFinite(a);
       Assert(vector->getMap()->isSameAs(*(down_V.trilinos_vector().getMap())),
              ExcDifferentParallelPartitioning());
@@ -328,23 +346,24 @@ namespace LinearAlgebra
 
 
 
+    template <typename Number>
     void
-    Vector::add(const double                     a,
-                const VectorSpaceVector<double> &V,
-                const double                     b,
-                const VectorSpaceVector<double> &W)
+    Vector<Number>::add(const Number                     a,
+                        const VectorSpaceVector<Number> &V,
+                        const Number                     b,
+                        const VectorSpaceVector<Number> &W)
     {
       // Check that casting will work.
-      Assert(dynamic_cast<const Vector *>(&V) != nullptr,
+      Assert(dynamic_cast<const Vector<Number> *>(&V) != nullptr,
              ExcVectorTypeNotCompatible());
       // Check that casting will work.
-      Assert(dynamic_cast<const Vector *>(&W) != nullptr,
+      Assert(dynamic_cast<const Vector<Number> *>(&W) != nullptr,
              ExcVectorTypeNotCompatible());
 
       // Downcast V. If fails, throws an exception.
-      const Vector &down_V = dynamic_cast<const Vector &>(V);
+      const Vector<Number> &down_V = dynamic_cast<const Vector<Number> &>(V);
       // Downcast W. If fails, throws an exception.
-      const Vector &down_W = dynamic_cast<const Vector &>(W);
+      const Vector<Number> &down_W = dynamic_cast<const Vector<Number> &>(W);
       Assert(vector->getMap()->isSameAs(*(down_V.trilinos_vector().getMap())),
              ExcDifferentParallelPartitioning());
       Assert(vector->getMap()->isSameAs(*(down_W.trilinos_vector().getMap())),
@@ -358,35 +377,37 @@ namespace LinearAlgebra
 
 
 
+    template <typename Number>
     void
-    Vector::sadd(const double                     s,
-                 const double                     a,
-                 const VectorSpaceVector<double> &V)
+    Vector<Number>::sadd(const Number                     s,
+                         const Number                     a,
+                         const VectorSpaceVector<Number> &V)
     {
       // Check that casting will work.
-      Assert(dynamic_cast<const Vector *>(&V) != nullptr,
+      Assert(dynamic_cast<const Vector<Number> *>(&V) != nullptr,
              ExcVectorTypeNotCompatible());
 
       *this *= s;
       // Downcast V. It fails, throws an exception.
-      const Vector &down_V = dynamic_cast<const Vector &>(V);
-      Vector        tmp(down_V);
+      const Vector<Number> &down_V = dynamic_cast<const Vector<Number> &>(V);
+      Vector<Number>        tmp(down_V);
       tmp *= a;
       *this += tmp;
     }
 
 
 
+    template <typename Number>
     void
-    Vector::scale(const VectorSpaceVector<double> &scaling_factors)
+    Vector<Number>::scale(const VectorSpaceVector<Number> &scaling_factors)
     {
       // Check that casting will work.
-      Assert(dynamic_cast<const Vector *>(&scaling_factors) != nullptr,
+      Assert(dynamic_cast<const Vector<Number> *>(&scaling_factors) != nullptr,
              ExcVectorTypeNotCompatible());
 
       // Downcast scaling_factors. If fails, throws an exception.
-      const Vector &down_scaling_factors =
-        dynamic_cast<const Vector &>(scaling_factors);
+      const Vector<Number> &down_scaling_factors =
+        dynamic_cast<const Vector<Number> &>(scaling_factors);
       Assert(vector->getMap()->isSameAs(
                *(down_scaling_factors.trilinos_vector().getMap())),
              ExcDifferentParallelPartitioning());
@@ -399,15 +420,16 @@ namespace LinearAlgebra
 
 
 
+    template <typename Number>
     void
-    Vector::equ(const double a, const VectorSpaceVector<double> &V)
+    Vector<Number>::equ(const Number a, const VectorSpaceVector<Number> &V)
     {
       // Check that casting will work.
-      Assert(dynamic_cast<const Vector *>(&V) != nullptr,
+      Assert(dynamic_cast<const Vector<Number> *>(&V) != nullptr,
              ExcVectorTypeNotCompatible());
 
       // Downcast V. If fails, throws an exception.
-      const Vector &down_V = dynamic_cast<const Vector &>(V);
+      const Vector<Number> &down_V = dynamic_cast<const Vector<Number> &>(V);
       // If we don't have the same map, copy.
       if (vector->getMap()->isSameAs(*down_V.trilinos_vector().getMap()) ==
           false)
@@ -421,18 +443,19 @@ namespace LinearAlgebra
 
 
 
+    template <typename Number>
     bool
-    Vector::all_zero() const
+    Vector<Number>::all_zero() const
     {
       // get a representation of the vector and
       // loop over all the elements
-      double *      start_ptr = vector->getDataNonConst().get();
-      const double *ptr       = start_ptr,
+      Number *      start_ptr = vector->getDataNonConst().get();
+      const Number *ptr       = start_ptr,
                    *eptr      = start_ptr + vector->getLocalLength();
       unsigned int flag       = 0;
       while (ptr != eptr)
         {
-          if (*ptr != 0)
+          if (*ptr != Number(0))
             {
               flag = 1;
               break;
@@ -453,42 +476,47 @@ namespace LinearAlgebra
 
 
 
-    double
-    Vector::mean_value() const
+    template <typename Number>
+    Number
+    Vector<Number>::mean_value() const
     {
       return vector->meanValue();
     }
 
 
 
-    double
-    Vector::l1_norm() const
+    template <typename Number>
+    typename LinearAlgebra::VectorSpaceVector<Number>::real_type
+    Vector<Number>::l1_norm() const
     {
       return vector->norm1();
     }
 
 
 
-    double
-    Vector::l2_norm() const
+    template <typename Number>
+    typename LinearAlgebra::VectorSpaceVector<Number>::real_type
+    Vector<Number>::l2_norm() const
     {
       return vector->norm2();
     }
 
 
 
-    double
-    Vector::linfty_norm() const
+    template <typename Number>
+    typename LinearAlgebra::VectorSpaceVector<Number>::real_type
+    Vector<Number>::linfty_norm() const
     {
       return vector->normInf();
     }
 
 
 
-    double
-    Vector::add_and_dot(const double                     a,
-                        const VectorSpaceVector<double> &V,
-                        const VectorSpaceVector<double> &W)
+    template <typename Number>
+    Number
+    Vector<Number>::add_and_dot(const Number                     a,
+                                const VectorSpaceVector<Number> &V,
+                                const VectorSpaceVector<Number> &W)
     {
       this->add(a, V);
 
@@ -497,16 +525,18 @@ namespace LinearAlgebra
 
 
 
-    Vector::size_type
-    Vector::size() const
+    template <typename Number>
+    typename Vector<Number>::size_type
+    Vector<Number>::size() const
     {
       return vector->getGlobalLength();
     }
 
 
 
+    template <typename Number>
     MPI_Comm
-    Vector::get_mpi_communicator() const
+    Vector<Number>::get_mpi_communicator() const
     {
       const auto tpetra_comm = dynamic_cast<const Teuchos::MpiComm<int> *>(
         vector->getMap()->getComm().get());
@@ -516,21 +546,17 @@ namespace LinearAlgebra
 
 
 
+    template <typename Number>
     ::dealii::IndexSet
-    Vector::locally_owned_elements() const
+    Vector<Number>::locally_owned_elements() const
     {
       IndexSet is(size());
 
       // easy case: local range is contiguous
       if (vector->getMap()->isContiguous())
         {
-#    ifndef DEAL_II_WITH_64BIT_INDICES
           is.add_range(vector->getMap()->getMinGlobalIndex(),
                        vector->getMap()->getMaxGlobalIndex() + 1);
-#    else
-          is.add_range(vector->getMap()->getMinGlobalIndex(),
-                       vector->getMap()->getMaxGlobalIndex() + 1);
-#    endif
         }
       else if (vector->getLocalLength() > 0)
         {
@@ -546,27 +572,30 @@ namespace LinearAlgebra
 
 
 
-    const Tpetra::Vector<> &
-    Vector::trilinos_vector() const
+    template <typename Number>
+    const Tpetra::Vector<Number> &
+    Vector<Number>::trilinos_vector() const
     {
       return *vector;
     }
 
 
 
-    Tpetra::Vector<> &
-    Vector::trilinos_vector()
+    template <typename Number>
+    Tpetra::Vector<Number> &
+    Vector<Number>::trilinos_vector()
     {
       return *vector;
     }
 
 
 
+    template <typename Number>
     void
-    Vector::print(std::ostream &     out,
-                  const unsigned int precision,
-                  const bool         scientific,
-                  const bool         across) const
+    Vector<Number>::print(std::ostream &     out,
+                          const unsigned int precision,
+                          const bool         scientific,
+                          const bool         across) const
     {
       AssertThrow(out, ExcIO());
       boost::io::ios_flags_saver restore_flags(out);
@@ -581,9 +610,9 @@ namespace LinearAlgebra
       else
         out.setf(std::ios::fixed, std::ios::floatfield);
 
-      vector->sync<Kokkos::HostSpace>();
-      auto         vector_2d    = vector->getLocalView<Kokkos::HostSpace>();
-      auto         vector_1d    = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
+      vector->template sync<Kokkos::HostSpace>();
+      auto vector_2d = vector->template getLocalView<Kokkos::HostSpace>();
+      auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
       const size_t local_length = vector->getLocalLength();
 
       if (across)
@@ -601,25 +630,33 @@ namespace LinearAlgebra
 
 
 
+    template <typename Number>
     std::size_t
-    Vector::memory_consumption() const
+    Vector<Number>::memory_consumption() const
     {
       return sizeof(*this) +
              vector->getLocalLength() *
-               (sizeof(double) + sizeof(TrilinosWrappers::types::int_type));
+               (sizeof(Number) + sizeof(TrilinosWrappers::types::int_type));
     }
 
 
 
+    template <typename Number>
     void
-    Vector::create_tpetra_comm_pattern(const IndexSet &source_index_set,
-                                       const MPI_Comm &mpi_comm)
+    Vector<Number>::create_tpetra_comm_pattern(const IndexSet &source_index_set,
+                                               const MPI_Comm &mpi_comm)
     {
       source_stored_elements = source_index_set;
       tpetra_comm_pattern =
         std::make_shared<TpetraWrappers::CommunicationPattern>(
           locally_owned_elements(), source_index_set, mpi_comm);
     }
+
+    template class Vector<float>;
+    template class Vector<double>;
+    template class Vector<std::complex<float>>;
+    template class Vector<std::complex<double>>;
+
   } // namespace TpetraWrappers
 } // namespace LinearAlgebra
 
index c10ac87bb1e33e4ea8f555ee8978aa9c1c5d8d47..ba39dfa34e8411c9e8bb65439807622738ee3a29 100644 (file)
@@ -26,7 +26,7 @@
 
 // Check LinearAlgebra::TpetraWrappers::Vector assignment and import
 
-
+template <typename Number>
 void
 test()
 {
@@ -45,10 +45,10 @@ test()
     }
   parallel_partitioner_1.compress();
   parallel_partitioner_2.compress();
-  LinearAlgebra::TpetraWrappers::Vector a;
-  LinearAlgebra::TpetraWrappers::Vector b(parallel_partitioner_1,
-                                          MPI_COMM_WORLD);
-  LinearAlgebra::TpetraWrappers::Vector c(b);
+  LinearAlgebra::TpetraWrappers::Vector<Number> a;
+  LinearAlgebra::TpetraWrappers::Vector<Number> b(parallel_partitioner_1,
+                                                  MPI_COMM_WORLD);
+  LinearAlgebra::TpetraWrappers::Vector<Number> c(b);
 
   AssertThrow(a.size() == 0, ExcMessage("Vector has the wrong size."));
   AssertThrow(b.size() == 10, ExcMessage("Vector has the wrong size."));
@@ -69,9 +69,9 @@ test()
     read_write_index_set.add_range(4, 10);
   read_write_index_set.compress();
 
-  LinearAlgebra::ReadWriteVector<double> read_write_1(read_write_index_set);
-  LinearAlgebra::ReadWriteVector<double> read_write_2(read_write_index_set);
-  LinearAlgebra::ReadWriteVector<double> read_write_3(read_write_index_set);
+  LinearAlgebra::ReadWriteVector<Number> read_write_1(read_write_index_set);
+  LinearAlgebra::ReadWriteVector<Number> read_write_2(read_write_index_set);
+  LinearAlgebra::ReadWriteVector<Number> read_write_3(read_write_index_set);
   if (rank == 0)
     {
       for (unsigned int i = 0; i < 6; ++i)
@@ -204,7 +204,7 @@ test()
 
   b.import(read_write_1, VectorOperation::insert);
   c.import(read_write_1, VectorOperation::insert);
-  const double val = b * c;
+  const Number val = b * c;
   AssertThrow(val == 285., ExcMessage("Problem in operator *."));
 }
 
@@ -217,7 +217,8 @@ main(int argc, char **argv)
 
   Utilities::MPI::MPI_InitFinalize mpi_init(argc, argv, 1);
 
-  test();
+  test<double>();
+  test<float>();
 
   deallog << "OK" << std::endl;
 
index 8e487535304458bcd15759af1c2ad0a0a2eab052..a775c7ec302557bf48d16cabd4947708e77971e4 100644 (file)
@@ -26,6 +26,7 @@
 
 // Check LinearAlgebra::TpetraWrappers::Vector add and sadd.
 
+template <typename Number>
 void
 test()
 {
@@ -44,12 +45,12 @@ test()
     }
   parallel_partitioner_1.compress();
   parallel_partitioner_2.compress();
-  LinearAlgebra::TpetraWrappers::Vector a(parallel_partitioner_1,
-                                          MPI_COMM_WORLD);
-  LinearAlgebra::TpetraWrappers::Vector b(parallel_partitioner_1,
-                                          MPI_COMM_WORLD);
-  LinearAlgebra::TpetraWrappers::Vector c(parallel_partitioner_2,
-                                          MPI_COMM_WORLD);
+  LinearAlgebra::TpetraWrappers::Vector<Number> a(parallel_partitioner_1,
+                                                  MPI_COMM_WORLD);
+  LinearAlgebra::TpetraWrappers::Vector<Number> b(parallel_partitioner_1,
+                                                  MPI_COMM_WORLD);
+  LinearAlgebra::TpetraWrappers::Vector<Number> c(parallel_partitioner_2,
+                                                  MPI_COMM_WORLD);
 
   IndexSet read_write_index_set(10);
   if (rank == 0)
@@ -58,9 +59,9 @@ test()
     read_write_index_set.add_range(5, 10);
   read_write_index_set.compress();
 
-  LinearAlgebra::ReadWriteVector<double> read_write_1(read_write_index_set);
-  LinearAlgebra::ReadWriteVector<double> read_write_2(read_write_index_set);
-  LinearAlgebra::ReadWriteVector<double> read_write_3(read_write_index_set);
+  LinearAlgebra::ReadWriteVector<Number> read_write_1(read_write_index_set);
+  LinearAlgebra::ReadWriteVector<Number> read_write_2(read_write_index_set);
+  LinearAlgebra::ReadWriteVector<Number> read_write_3(read_write_index_set);
   if (rank == 0)
     {
       for (unsigned int i = 0; i < 5; ++i)
@@ -188,14 +189,14 @@ test()
 
   AssertThrow(b.l1_norm() == 95., ExcMessage("Problem in l1_norm."));
 
-  const double eps = 1e-6;
+  const Number eps = 1e-6;
   AssertThrow(std::fabs(b.l2_norm() - 31.3847096) < eps,
               ExcMessage("Problem in l2_norm"));
 
   AssertThrow(b.linfty_norm() == 14., ExcMessage("Problem in linfty_norm."));
 
   a.import(read_write_1, VectorOperation::insert);
-  const double val = a.add_and_dot(2., a, b);
+  const Number val = a.add_and_dot(2., a, b);
   AssertThrow(val == 1530., ExcMessage("Problem in add_and_dot"));
 }
 
@@ -208,7 +209,8 @@ main(int argc, char **argv)
 
   Utilities::MPI::MPI_InitFinalize mpi_init(argc, argv, 1);
 
-  test();
+  test<double>();
+  test<float>();
 
   deallog << "OK" << std::endl;
 
index 4927aaedb82af7098f58e8389661b054f213af1f..650296a4913a7e5c3dd2f00fc0e796592c720d00 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "../tests.h"
 
+template <typename Number>
 void
 test()
 {
@@ -38,7 +39,8 @@ test()
   locally_owned.add_range(my_id * 2, my_id * 2 + 2);
   locally_owned.compress();
 
-  LinearAlgebra::TpetraWrappers::Vector v(locally_owned, MPI_COMM_WORLD);
+  LinearAlgebra::TpetraWrappers::Vector<Number> v(locally_owned,
+                                                  MPI_COMM_WORLD);
 
   IndexSet     workaround_set(n_procs * 2);
   unsigned int my_first_index  = (my_id * 2 + 2) % (n_procs * 2);
@@ -47,7 +49,7 @@ test()
   workaround_set.add_index(my_second_index);
   workaround_set.add_index(0);
   workaround_set.compress();
-  LinearAlgebra::ReadWriteVector<double> rw_vector(workaround_set);
+  LinearAlgebra::ReadWriteVector<Number> rw_vector(workaround_set);
 
   rw_vector(my_first_index)  = my_id + 10;
   rw_vector(my_second_index) = my_id + 100;
@@ -97,5 +99,6 @@ main(int argc, char **argv)
     argc, argv, testing_max_num_threads());
 
   MPILogInitAll log;
-  test();
+  test<double>();
+  test<float>();
 }
index 638319c2f1c301605717ad32147185097adec87b..e94f192176bcfaa835bf88cbc348cef301c2970f 100644 (file)
@@ -31,7 +31,66 @@ IndexSet: {[0,2]}
 [0]: 4.000e+00
 [1]: 2.000e+02
 [2]: 1.000e+02
+DEAL:0::Tpetra first import add:
+2.000e+00 1.000e+02 
+IndexSet: {[0,2]}
+
+[0]: 1.000e+00
+[1]: 1.000e+02
+[2]: 1.000e+01
+DEAL:0::Tpetra second import add:
+4.000e+00 2.000e+02 
+IndexSet: {[0,2]}
+
+[0]: 2.000e+00
+[1]: 2.000e+02
+[2]: 2.000e+01
+DEAL:0::ReadWrite import add:
+IndexSet: {[0,2]}
+
+[0]: 6.000e+00
+[1]: 4.000e+02
+[2]: 5.000e+01
+DEAL:0::ReadWrite import min:
+IndexSet: {[0,2]}
 
+[0]: 4.000e+00
+[1]: 1.000e+00
+[2]: 3.000e+01
+DEAL:0::ReadWrite import max:
+IndexSet: {[0,2]}
+
+[0]: 4.000e+00
+[1]: 2.000e+02
+[2]: 1.000e+02
+
+DEAL:1::Tpetra first import add:
+1.000e+01 1.010e+02 
+IndexSet: {0, 3}
+
+[0]: 1.000e+00
+[3]: 1.010e+02
+DEAL:1::Tpetra second import add:
+3.000e+01 2.010e+02 
+IndexSet: {0, 3}
+
+[0]: 2.000e+00
+[3]: 2.010e+02
+DEAL:1::ReadWrite import add:
+IndexSet: {0, 3}
+
+[0]: 6.000e+00
+[3]: 4.020e+02
+DEAL:1::ReadWrite import min:
+IndexSet: {0, 3}
+
+[0]: 4.000e+00
+[3]: 1.000e+00
+DEAL:1::ReadWrite import max:
+IndexSet: {0, 3}
+
+[0]: 4.000e+00
+[3]: 2.010e+02
 DEAL:1::Tpetra first import add:
 1.000e+01 1.010e+02 
 IndexSet: {0, 3}
index f70ed13b09e8db14f4cc3f6faf8202de0a5e7d09..5fbf8dea2d1f17b866a240d6c2cce467debbf0f5 100644 (file)
@@ -28,6 +28,38 @@ IndexSet: {[0,2]}
 DEAL:0::ReadWrite import max:
 IndexSet: {[0,2]}
 
+[0]: 8.000e+00
+[1]: 2.000e+02
+[2]: 1.000e+02
+DEAL:0::Tpetra first import add:
+4.000e+00 1.000e+02 
+IndexSet: {[0,2]}
+
+[0]: 1.000e+00
+[1]: 1.000e+02
+[2]: 1.000e+01
+DEAL:0::Tpetra second import add:
+8.000e+00 2.000e+02 
+IndexSet: {[0,2]}
+
+[0]: 2.000e+00
+[1]: 2.000e+02
+[2]: 2.000e+01
+DEAL:0::ReadWrite import add:
+IndexSet: {[0,2]}
+
+[0]: 1.000e+01
+[1]: 4.000e+02
+[2]: 5.000e+01
+DEAL:0::ReadWrite import min:
+IndexSet: {[0,2]}
+
+[0]: 4.000e+00
+[1]: 1.000e+00
+[2]: 3.000e+01
+DEAL:0::ReadWrite import max:
+IndexSet: {[0,2]}
+
 [0]: 8.000e+00
 [1]: 2.000e+02
 [2]: 1.000e+02
@@ -61,6 +93,38 @@ IndexSet: {0, [3,4]}
 DEAL:1::ReadWrite import max:
 IndexSet: {0, [3,4]}
 
+[0]: 8.000e+00
+[3]: 2.010e+02
+[4]: 1.010e+02
+DEAL:1::Tpetra first import add:
+1.000e+01 1.010e+02 
+IndexSet: {0, [3,4]}
+
+[0]: 1.000e+00
+[3]: 1.010e+02
+[4]: 1.100e+01
+DEAL:1::Tpetra second import add:
+3.000e+01 2.010e+02 
+IndexSet: {0, [3,4]}
+
+[0]: 2.000e+00
+[3]: 2.010e+02
+[4]: 2.100e+01
+DEAL:1::ReadWrite import add:
+IndexSet: {0, [3,4]}
+
+[0]: 1.000e+01
+[3]: 4.020e+02
+[4]: 5.300e+01
+DEAL:1::ReadWrite import min:
+IndexSet: {0, [3,4]}
+
+[0]: 4.000e+00
+[3]: 1.000e+00
+[4]: 3.200e+01
+DEAL:1::ReadWrite import max:
+IndexSet: {0, [3,4]}
+
 [0]: 8.000e+00
 [3]: 2.010e+02
 [4]: 1.010e+02
@@ -98,8 +162,67 @@ IndexSet: {0, [5,6]}
 [0]: 8.000e+00
 [5]: 2.020e+02
 [6]: 1.020e+02
+DEAL:2::Tpetra first import add:
+1.100e+01 1.020e+02 
+IndexSet: {0, [5,6]}
 
+[0]: 1.000e+00
+[5]: 1.020e+02
+[6]: 1.200e+01
+DEAL:2::Tpetra second import add:
+3.200e+01 2.020e+02 
+IndexSet: {0, [5,6]}
 
+[0]: 2.000e+00
+[5]: 2.020e+02
+[6]: 2.200e+01
+DEAL:2::ReadWrite import add:
+IndexSet: {0, [5,6]}
+
+[0]: 1.000e+01
+[5]: 4.040e+02
+[6]: 5.600e+01
+DEAL:2::ReadWrite import min:
+IndexSet: {0, [5,6]}
+
+[0]: 4.000e+00
+[5]: 1.000e+00
+[6]: 3.400e+01
+DEAL:2::ReadWrite import max:
+IndexSet: {0, [5,6]}
+
+[0]: 8.000e+00
+[5]: 2.020e+02
+[6]: 1.020e+02
+
+
+DEAL:3::Tpetra first import add:
+1.200e+01 1.030e+02 
+IndexSet: {0, 7}
+
+[0]: 1.000e+00
+[7]: 1.030e+02
+DEAL:3::Tpetra second import add:
+3.400e+01 2.030e+02 
+IndexSet: {0, 7}
+
+[0]: 2.000e+00
+[7]: 2.030e+02
+DEAL:3::ReadWrite import add:
+IndexSet: {0, 7}
+
+[0]: 1.000e+01
+[7]: 4.060e+02
+DEAL:3::ReadWrite import min:
+IndexSet: {0, 7}
+
+[0]: 4.000e+00
+[7]: 1.000e+00
+DEAL:3::ReadWrite import max:
+IndexSet: {0, 7}
+
+[0]: 8.000e+00
+[7]: 2.030e+02
 DEAL:3::Tpetra first import add:
 1.200e+01 1.030e+02 
 IndexSet: {0, 7}

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.