Reference documentation for deal.II version GIT relicensing-1308-g50a4ffc717 2024-07-25 10:40:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
vector_element_access.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2017 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_vector_element_access_h
16#define dealii_vector_element_access_h
17
18
19#include <deal.II/base/config.h>
20
23
25
26namespace internal
27{
28 template <typename VectorType>
30 {
31 public:
32 static void
33 add(const typename VectorType::value_type value,
35 VectorType &V);
36
37 static void
38 set(typename VectorType::value_type value,
40 VectorType &V);
41
42 static typename VectorType::value_type
43 get(const VectorType &V, const types::global_dof_index i);
44 };
45
46
47
48 template <typename VectorType>
49 inline void
50 ElementAccess<VectorType>::add(const typename VectorType::value_type value,
52 VectorType &V)
53 {
54 V(i) += value;
55 }
56
57
58
59 template <typename VectorType>
60 inline void
61 ElementAccess<VectorType>::set(const typename VectorType::value_type value,
63 VectorType &V)
64 {
65 V(i) = value;
66 }
67
68
69
70 template <typename VectorType>
71 inline typename VectorType::value_type
72 ElementAccess<VectorType>::get(const VectorType &V,
74 {
75 return V(i);
76 }
77
78
79
80#ifdef DEAL_II_WITH_TRILINOS
81 template <>
82 inline void
84 const double value,
87 {
88 // Extract local indices in the vector.
89 Epetra_FEVector vector = V.trilinos_vector();
91 vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
92
93 vector[0][trilinos_i] += value;
94 }
95
96
97
98 template <>
99 inline void
101 const double value,
104 {
105 // Extract local indices in the vector.
106 Epetra_FEVector vector = V.trilinos_vector();
108 vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
109
110 vector[0][trilinos_i] = value;
111 }
112
113 template <>
114 inline double
118 {
119 // Extract local indices in the vector.
120 Epetra_FEVector vector = V.trilinos_vector();
122 vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
123
124 return vector[0][trilinos_i];
125 }
126
127
128
129# ifdef DEAL_II_TRILINOS_WITH_TPETRA
130 template <typename NumberType>
131 struct ElementAccess<LinearAlgebra::TpetraWrappers::Vector<NumberType>>
132 {
133 public:
135 static void
136 add(const typename VectorType::value_type value,
138 VectorType &V);
139
140 static void
143 VectorType &V);
144
145 static typename VectorType::value_type
146 get(const VectorType &V, const types::global_dof_index i);
147 };
148
149
150
151 template <typename NumberType>
152 inline void
154 const typename VectorType::value_type value,
157 {
158 // Extract local indices in the vector.
159 Tpetra::Vector<NumberType, int, types::signed_global_dof_index> vector =
160 V.trilinos_vector();
162 vector.getMap()->getLocalElement(
163 static_cast<TrilinosWrappers::types::int_type>(i));
164
165# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
166 auto vector_2d = vector.template getLocalView<Kokkos::HostSpace>(
167 Tpetra::Access::ReadWrite);
168# else
169 vector.template sync<Kokkos::HostSpace>();
170 auto vector_2d = vector.template getLocalView<Kokkos::HostSpace>();
171# endif
172 auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
173# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
174 // We're going to modify the data on host.
175 vector.template modify<Kokkos::HostSpace>();
176# endif
177 vector_1d(trilinos_i) += value;
178# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
179 vector.template sync<
180 typename Tpetra::Vector<NumberType, int, types::signed_global_dof_index>::
181 device_type::memory_space>();
182# endif
183 }
184
185
186
187 template <typename NumberType>
188 inline void
190 const typename VectorType::value_type value,
193 {
194 // Extract local indices in the vector.
195 Tpetra::Vector<NumberType, int, types::signed_global_dof_index> vector =
196 V.trilinos_vector();
198 vector.getMap()->getLocalElement(
199 static_cast<TrilinosWrappers::types::int_type>(i));
200
201# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
202 auto vector_2d = vector.template getLocalView<Kokkos::HostSpace>(
203 Tpetra::Access::ReadWrite);
204# else
205 vector.template sync<Kokkos::HostSpace>();
206 auto vector_2d = vector.template getLocalView<Kokkos::HostSpace>();
207# endif
208 auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
209 // We're going to modify the data on host.
210# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
211 vector.template modify<Kokkos::HostSpace>();
212# endif
213 vector_1d(trilinos_i) = value;
214# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
215 vector.template sync<
216 typename Tpetra::Vector<NumberType, int, types::signed_global_dof_index>::
217 device_type::memory_space>();
218# endif
219 }
220
221
222
223 template <typename NumberType>
228 {
229 // Extract local indices in the vector.
230# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
231 const Tpetra::Vector<NumberType, int, types::signed_global_dof_index>
232 &vector = V.trilinos_vector();
233 auto vector_2d =
234 vector.template getLocalView<Kokkos::HostSpace>(Tpetra::Access::ReadOnly);
235# else
236 Tpetra::Vector<NumberType, int, types::signed_global_dof_index> vector =
237 V.trilinos_vector();
238 vector.template sync<Kokkos::HostSpace>();
239 auto vector_2d = vector.template getLocalView<Kokkos::HostSpace>();
240# endif
241 auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
243 vector.getMap()->getLocalElement(
244 static_cast<TrilinosWrappers::types::int_type>(i));
245 return vector_1d(trilinos_i);
246 }
247# endif
248#endif
249} // namespace internal
250
252
253#endif
const Epetra_FEVector & trilinos_vector() const
const TpetraTypes::VectorType< Number, MemorySpace > & trilinos_vector() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
static VectorType::value_type get(const VectorType &V, const types::global_dof_index i)
static void set(typename VectorType::value_type value, const types::global_dof_index i, VectorType &V)
static void add(const typename VectorType::value_type value, const types::global_dof_index i, VectorType &V)