deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20: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: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2017 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_vector_element_access_h
14#define dealii_vector_element_access_h
15
16
17#include <deal.II/base/config.h>
18
22
24
25namespace internal
26{
27 template <typename VectorType>
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#ifdef DEAL_II_TRILINOS_WITH_EPETRA
79 template <>
80 inline void
82 const double value,
85 {
86 // Extract local indices in the vector.
87 Epetra_FEVector &vector = V.trilinos_vector();
89 vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
90
91 vector[0][trilinos_i] += value;
92 }
93
94
95
96 template <>
97 inline void
99 const double value,
102 {
103 // Extract local indices in the vector.
104 Epetra_FEVector &vector = V.trilinos_vector();
106 vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
107
108 vector[0][trilinos_i] = value;
109 }
110
111 template <>
112 inline double
116 {
117 // Extract local indices in the vector.
118 const Epetra_FEVector &vector = V.trilinos_vector();
120 vector.Map().LID(static_cast<TrilinosWrappers::types::int_type>(i));
121
122 return vector[0][trilinos_i];
123 }
124#endif
125
126
127
128#ifdef DEAL_II_TRILINOS_WITH_TPETRA
129 template <typename NumberType, typename MemorySpace>
131 LinearAlgebra::TpetraWrappers::Vector<NumberType, MemorySpace>>
132 {
133 public:
136 static void
139 VectorType &V);
140
141 static void
144 VectorType &V);
145
146 static typename VectorType::value_type
148 };
149
150
151
152# ifndef DOXYGEN
153 template <typename NumberType, typename MemorySpace>
154 inline void
157 add(const typename VectorType::value_type value,
160 {
161 // Extract local indices in the vector.
162 auto vector = V.trilinos_vector();
164 vector.getMap()->getLocalElement(
165 static_cast<TrilinosWrappers::types::int_type>(i));
166
167 auto vector_2d = vector.template getLocalView<Kokkos::HostSpace>(
168 Tpetra::Access::ReadWriteStruct{});
169 auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
170 vector_1d(trilinos_i) += value;
171 }
172
173
174
175 template <typename NumberType, typename MemorySpace>
176 inline void
177 ElementAccess<
179 set(const typename VectorType::value_type value,
182 {
183 // Extract local indices in the vector.
184 auto vector = V.trilinos_vector();
186 vector.getMap()->getLocalElement(
187 static_cast<TrilinosWrappers::types::int_type>(i));
188
189 auto vector_2d = vector.template getLocalView<Kokkos::HostSpace>(
190 Tpetra::Access::ReadWriteStruct{});
191 auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
192 // We're going to modify the data on host.
193 vector_1d(trilinos_i) = value;
194 }
195
196
197
198 template <typename NumberType, typename MemorySpace>
199 inline typename LinearAlgebra::TpetraWrappers::Vector<NumberType,
201 ElementAccess<
205 {
206 // Extract local indices in the vector.
207 const auto &vector = V.trilinos_vector();
208 auto vector_2d = vector.template getLocalView<Kokkos::HostSpace>(
209 Tpetra::Access::ReadOnlyStruct{});
210 auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0);
212 vector.getMap()->getLocalElement(
213 static_cast<TrilinosWrappers::types::int_type>(i));
214 return vector_1d(trilinos_i);
215 }
216# endif
217#endif
218} // namespace internal
219
221
222#endif
*  x_component_mask set(0, true)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
constexpr char V
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)
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)