Loading [MathJax]/extensions/TeX/newcommand.js
 Reference documentation for deal.II version 9.1.1
\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
vector_element_access.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2019 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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_vector_element_access_h
17 #define dealii_vector_element_access_h
18 
19 
20 #include <deal.II/lac/trilinos_epetra_vector.h>
21 #include <deal.II/lac/trilinos_tpetra_vector.h>
22 
23 DEAL_II_NAMESPACE_OPEN
24 
25 namespace internal
26 {
27  template <typename VectorType>
28  struct ElementAccess
29  {
30  public:
31  static void
32  add(const typename VectorType::value_type value,
34  VectorType & V);
35 
36  static void
37  set(typename VectorType::value_type value,
39  VectorType & V);
40 
41  static typename VectorType::value_type
42  get(const VectorType &V, const types::global_dof_index i);
43  };
44 
45 
46 
47  template <typename VectorType>
48  inline void
49  ElementAccess<VectorType>::add(const typename VectorType::value_type value,
51  VectorType & V)
52  {
53  V(i) += value;
54  }
55 
56 
57 
58  template <typename VectorType>
59  inline void
60  ElementAccess<VectorType>::set(const typename VectorType::value_type value,
62  VectorType & V)
63  {
64  V(i) = value;
65  }
66 
67 
68 
69  template <typename VectorType>
70  inline typename VectorType::value_type
71  ElementAccess<VectorType>::get(const VectorType & V,
73  {
74  return V(i);
75  }
76 
77 
78 
79 #if defined(DEAL_II_WITH_TRILINOS) && defined(DEAL_II_WITH_MPI)
80  template <>
81  inline void
82  ElementAccess<LinearAlgebra::EpetraWrappers::Vector>::add(
83  const double value,
86  {
87  // Extract local indices in the vector.
88  Epetra_FEVector vector = V.trilinos_vector();
89  TrilinosWrappers::types::int_type trilinos_i =
90  vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
91 
92  vector[0][trilinos_i] += value;
93  }
94 
95 
96 
97  template <>
98  inline void
100  const double value,
101  const types::global_dof_index i,
103  {
104  // Extract local indices in the vector.
105  Epetra_FEVector vector = V.trilinos_vector();
106  TrilinosWrappers::types::int_type trilinos_i =
107  vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
108 
109  vector[0][trilinos_i] = value;
110  }
111 
112  template <>
113  inline double
114  ElementAccess<LinearAlgebra::EpetraWrappers::Vector>::get(
116  const types::global_dof_index i)
117  {
118  // Extract local indices in the vector.
119  Epetra_FEVector vector = V.trilinos_vector();
120  TrilinosWrappers::types::int_type trilinos_i =
121  vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
122 
123  return vector[0][trilinos_i];
124  }
125 
126 
127 
128 # ifdef DEAL_II_TRILINOS_WITH_TPETRA
129  template <typename NumberType>
130  struct ElementAccess<LinearAlgebra::TpetraWrappers::Vector<NumberType>>
131  {
132  public:
133  using VectorType = LinearAlgebra::TpetraWrappers::Vector<NumberType>;
134  static void
135  add(const typename VectorType::value_type value,
136  const types::global_dof_index i,
137  VectorType & V);
138 
139  static void
140  set(typename VectorType::value_type value,
141  const types::global_dof_index i,
142  VectorType & V);
143 
144  static typename VectorType::value_type
145  get(const VectorType &V, const types::global_dof_index i);
146  };
147 
148 
149 
150  template <typename NumberType>
151  inline void
152  ElementAccess<LinearAlgebra::TpetraWrappers::Vector<NumberType>>::add(
153  const typename VectorType::value_type value,
154  const types::global_dof_index i,
155  LinearAlgebra::TpetraWrappers::Vector<NumberType> &V)
156  {
157  // Extract local indices in the vector.
158  Tpetra::Vector<NumberType, int, types::global_dof_index> vector =
159  V.trilinos_vector();
160  TrilinosWrappers::types::int_type trilinos_i =
161  vector.getMap()->getLocalElement(
162  static_cast<TrilinosWrappers::types::int_type>(i));
163 
164  vector.template sync<Kokkos::HostSpace>();
165  auto vector_2d = vector.template getLocalView<Kokkos::HostSpace>();
166  auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
167  // We're going to modify the data on host.
168  vector.template modify<Kokkos::HostSpace>();
169  vector_1d(trilinos_i) += value;
170  vector.template sync<
171  typename Tpetra::Vector<NumberType, int, types::global_dof_index>::
172  device_type::memory_space>();
173  }
174 
175 
176 
177  template <typename NumberType>
178  inline void
179  ElementAccess<LinearAlgebra::TpetraWrappers::Vector<NumberType>>::set(
180  const typename VectorType::value_type value,
181  const types::global_dof_index i,
182  LinearAlgebra::TpetraWrappers::Vector<NumberType> &V)
183  {
184  // Extract local indices in the vector.
185  Tpetra::Vector<NumberType, int, types::global_dof_index> vector =
186  V.trilinos_vector();
187  TrilinosWrappers::types::int_type trilinos_i =
188  vector.getMap()->getLocalElement(
189  static_cast<TrilinosWrappers::types::int_type>(i));
190 
191  vector.template sync<Kokkos::HostSpace>();
192  auto vector_2d = vector.template getLocalView<Kokkos::HostSpace>();
193  auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
194  // We're going to modify the data on host.
195  vector.template modify<Kokkos::HostSpace>();
196  vector_1d(trilinos_i) = value;
197  vector.template sync<
198  typename Tpetra::Vector<NumberType, int, types::global_dof_index>::
199  device_type::memory_space>();
200  }
201 
202 
203 
204  template <typename NumberType>
205  inline typename LinearAlgebra::TpetraWrappers::Vector<NumberType>::value_type
206  ElementAccess<LinearAlgebra::TpetraWrappers::Vector<NumberType>>::get(
207  const LinearAlgebra::TpetraWrappers::Vector<NumberType> &V,
208  const types::global_dof_index i)
209  {
210  // Extract local indices in the vector.
211  Tpetra::Vector<NumberType, int, types::global_dof_index> vector =
212  V.trilinos_vector();
213  TrilinosWrappers::types::int_type trilinos_i =
214  vector.getMap()->getLocalElement(
215  static_cast<TrilinosWrappers::types::int_type>(i));
216 
217  vector.template sync<Kokkos::HostSpace>();
218  auto vector_2d = vector.template getLocalView<Kokkos::HostSpace>();
219  auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
220  // We're going to modify the data on host.
221  return vector_1d(trilinos_i);
222  }
223 # endif
224 #endif
225 } // namespace internal
226 
227 DEAL_II_NAMESPACE_CLOSE
228 
229 #endif
LinearAlgebra::distributed::Vector< Number > Vector
const Epetra_FEVector & trilinos_vector() const
unsigned int global_dof_index
Definition: types.h:89
__global__ void set(Number *val, const Number s, const size_type N)