deal.II version GIT relicensing-2169-gec1b43f35b 2024-11-22 07:10:00+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
trilinos_tpetra_vector.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2018 - 2024 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_trilinos_tpetra_vector_h
16#define dealii_trilinos_tpetra_vector_h
17
18
19#include <deal.II/base/config.h>
20
21#include "deal.II/base/types.h"
22
24
25#ifdef DEAL_II_TRILINOS_WITH_TPETRA
26
29
32# include <deal.II/lac/vector.h>
35
36# include <Teuchos_Comm.hpp>
37# include <Teuchos_OrdinalTraits.hpp>
38# include <Tpetra_Core.hpp>
39# include <Tpetra_Vector.hpp>
40# include <Tpetra_Version.hpp>
41
42# include <memory>
43# include <optional>
44
46
52template <typename Number>
53struct is_tpetra_type : std::false_type
54{};
55
56# ifdef HAVE_TPETRA_INST_FLOAT
57template <>
58struct is_tpetra_type<float> : std::true_type
59{};
60# endif
61
62# ifdef HAVE_TPETRA_INST_DOUBLE
63template <>
64struct is_tpetra_type<double> : std::true_type
65{};
66# endif
67
68# ifdef DEAL_II_WITH_COMPLEX_VALUES
69# ifdef HAVE_TPETRA_INST_COMPLEX_FLOAT
70template <>
71struct is_tpetra_type<std::complex<float>> : std::true_type
72{};
73# endif
74
75# ifdef HAVE_TPETRA_INST_COMPLEX_DOUBLE
76template <>
77struct is_tpetra_type<std::complex<double>> : std::true_type
78{};
79# endif
80# endif
81
82namespace LinearAlgebra
83{
84 // Forward declaration
85# ifndef DOXYGEN
86 template <typename Number>
87 class ReadWriteVector;
88# endif
89
104 namespace TpetraWrappers
105 {
106
112 {
113 public:
115 };
116
127 namespace internal
128 {
132 using size_type = types::global_dof_index;
133
143 template <typename Number,
145 class VectorReference
146 {
147 private:
152 VectorReference(Vector<Number, MemorySpace> &vector,
153 const size_type index);
154
155 public:
159 VectorReference(const VectorReference &) = default;
160
172 const VectorReference &
173 operator=(const VectorReference &r) const;
174
178 VectorReference &
179 operator=(const VectorReference &r);
180
184 const VectorReference &
185 operator=(const Number &s) const;
186
190 const VectorReference &
191 operator+=(const Number &s) const;
192
196 const VectorReference &
197 operator-=(const Number &s) const;
198
202 const VectorReference &
203 operator*=(const Number &s) const;
204
208 const VectorReference &
209 operator/=(const Number &s) const;
210
215 operator Number() const;
216
220 DeclException1(ExcTrilinosError,
221 int,
222 << "An error with error number " << arg1
223 << " occurred while calling a Trilinos function");
224
225 /*
226 * Access to a an element that is not (locally-)owned.
227 *
228 * @ingroup Exceptions
229 */
231 ExcAccessToNonLocalElement,
232 size_type,
233 size_type,
234 size_type,
235 size_type,
236 << "You are trying to access element " << arg1
237 << " of a distributed vector, but this element is not stored "
238 << "on the current processor. Note: There are " << arg2
239 << " elements stored "
240 << "on the current processor from within the range [" << arg3 << ','
241 << arg4 << "] but Trilinos vectors need not store contiguous "
242 << "ranges on each processor, and not every element in "
243 << "this range may in fact be stored locally."
244 << "\n\n"
245 << "A common source for this kind of problem is that you "
246 << "are passing a 'fully distributed' vector into a function "
247 << "that needs read access to vector elements that correspond "
248 << "to degrees of freedom on ghost cells (or at least to "
249 << "'locally active' degrees of freedom that are not also "
250 << "'locally owned'). You need to pass a vector that has these "
251 << "elements as ghost entries.");
252
253 private:
258
262 const size_type index;
263
264 // Make the vector class a friend, so that it can create objects of the
265 // present type.
266 friend class Vector<Number, MemorySpace>;
267 }; // class VectorReference
268
269 } // namespace internal
286 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
287 class Vector : public ReadVector<Number>
288 {
289 public:
293 using value_type = Number;
296 using reference = internal::VectorReference<Number, MemorySpace>;
298 const internal::VectorReference<Number, MemorySpace>;
299
310
315 Vector(const Vector &V);
316
322
330 explicit Vector(const IndexSet &parallel_partitioner,
331 const MPI_Comm communicator);
332
347 explicit Vector(const IndexSet &locally_owned_entries,
348 const IndexSet &ghost_entries,
349 const MPI_Comm communicator,
350 const bool vector_writable = false);
351
356 void
358
365 void
366 reinit(const IndexSet &parallel_partitioner,
367 const MPI_Comm communicator = MPI_COMM_WORLD,
368 const bool omit_zeroing_entries = false);
369
384 void
385 reinit(const IndexSet &locally_owned_entries,
386 const IndexSet &locally_relevant_or_ghost_entries,
387 const MPI_Comm communicator = MPI_COMM_WORLD,
388 const bool vector_writable = false);
389
394 void
396 const bool omit_zeroing_entries = false);
397
413 virtual void
414 swap(Vector &v) noexcept;
415
419 virtual void
422 const ArrayView<Number> &elements) const override;
423
453 Vector &
454 operator=(const Vector &V);
455
461 template <typename OtherNumber>
462 Vector &
463 operator=(const ::Vector<OtherNumber> &V);
464
469 Vector &
470 operator=(const Number s);
471
480 void
483 VectorOperation::values operation,
484 const Teuchos::RCP<const Utilities::MPI::CommunicationPatternBase>
485 &communication_pattern);
486
491 void
494 VectorOperation::values operation,
495 const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
496 &communication_pattern);
497
498 /*
499 * Imports all the elements present in the vector's IndexSet from the
500 * input vector @p V. VectorOperation::values @p operation is used to decide if
501 * the elements in @p V should be added to the current vector or replace the
502 * current elements.
503 */
504 void
506 VectorOperation::values operation);
507
512 void
513 import(const ReadWriteVector<Number> &V,
514 VectorOperation::values operation,
515 std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
516 communication_pattern = {})
517 {
518 import_elements(V, operation, communication_pattern);
519 }
520
537 operator()(const size_type index);
538
546 Number
547 operator()(const size_type index) const;
548
555 operator[](const size_type index);
556
562 Number
563 operator[](const size_type index) const;
564
576 Vector &
577 operator*=(const Number factor);
578
582 Vector &
583 operator/=(const Number factor);
584
588 Vector &
590
594 Vector &
596
601 Number
603
607 void
608 add(const Number a);
609
614 void
615 add(const Number a, const Vector<Number, MemorySpace> &V);
616
621 void
622 add(const Number a,
624 const Number b,
626
631 void
632 add(const std::vector<size_type> &indices,
633 const std::vector<Number> &values);
634
635
641 void
642 add(const size_type n_elements,
643 const size_type *indices,
644 const Number *values);
645
650 void
651 sadd(const Number s,
652 const Number a,
654
661 void
662 set(const size_type n_elements,
663 const size_type *indices,
664 const Number *values);
665
672 void
673 scale(const Vector<Number, MemorySpace> &scaling_factors);
674
678 void
679 equ(const Number a, const Vector<Number, MemorySpace> &V);
680
684 bool
685 all_zero() const;
686
692 bool
694
706 Number
707 mean_value() const;
708
714 l1_norm() const;
715
721 l2_norm() const;
722
728 linfty_norm() const;
729
734 norm_sqr() const;
735
762 Number
763 add_and_dot(const Number a,
766
778 bool
780
786 bool
788
794 bool
796
801 virtual size_type
802 size() const override;
803
810
833 std::pair<size_type, size_type>
834 local_range() const;
835
843 bool
844 in_local_range(const size_type index) const;
845
851 bool
853
859
873
896 void
898
905
912
917 Teuchos::RCP<const TpetraTypes::VectorType<Number, MemorySpace>>
919
924 Teuchos::RCP<TpetraTypes::VectorType<Number, MemorySpace>>
926
930 void
931 print(std::ostream &out,
932 const unsigned int precision = 3,
933 const bool scientific = true,
934 const bool across = true) const;
935
939 std::size_t
941
946 mpi_comm() const;
947
958
965
966 /*
967 * Access to a an element that is not (locally-)owned.
968 *
969 * @ingroup Exceptions
970 */
973 size_type,
974 size_type,
975 size_type,
976 size_type,
977 << "You are trying to access element " << arg1
978 << " of a distributed vector, but this element is not stored "
979 << "on the current processor. Note: There are " << arg2
980 << " elements stored "
981 << "on the current processor from within the range [" << arg3 << ','
982 << arg4 << "] but Trilinos vectors need not store contiguous "
983 << "ranges on each processor, and not every element in "
984 << "this range may in fact be stored locally."
985 << "\n\n"
986 << "A common source for this kind of problem is that you "
987 << "are passing a 'fully distributed' vector into a function "
988 << "that needs read access to vector elements that correspond "
989 << "to degrees of freedom on ghost cells (or at least to "
990 << "'locally active' degrees of freedom that are not also "
991 << "'locally owned'). You need to pass a vector that has these "
992 << "elements as ghost entries.");
993
1000 "To compress a vector, a locally_relevant_dofs "
1001 "index set, and a locally_owned_dofs index set "
1002 "must be provided. These index sets must be "
1003 "provided either when the vector is initialized "
1004 "or when compress is called. See the documentation "
1005 "of compress() for more information.");
1006
1013 int,
1014 << "An error with error number " << arg1
1015 << " occurred while calling a Trilinos function");
1016
1017 private:
1023 void
1024 create_tpetra_comm_pattern(const IndexSet &source_index_set,
1025 const MPI_Comm mpi_comm);
1026
1032
1042
1046 Teuchos::RCP<TpetraTypes::VectorType<Number, MemorySpace>> vector;
1047
1053 Teuchos::RCP<TpetraTypes::VectorType<Number, MemorySpace>>
1055
1060
1065 Teuchos::RCP<const TpetraWrappers::CommunicationPattern<MemorySpace>>
1067
1068 // Make the reference class a friend.
1069 friend class internal::VectorReference<Number, MemorySpace>;
1070 };
1071
1072
1073 /* ------------------------- Inline functions ---------------------- */
1074
1075 template <typename Number, typename MemorySpace>
1076 inline void
1078 Vector<Number, MemorySpace> &v) noexcept
1079 {
1080 u.swap(v);
1081 }
1082
1083
1084 template <typename Number, typename MemorySpace>
1085 inline bool
1087 {
1088 return has_ghost;
1089 }
1090
1091
1092
1093 template <typename Number, typename MemorySpace>
1094 inline bool
1096 {
1097 return compressed;
1098 }
1099
1100 template <typename Number, typename MemorySpace>
1101 inline void
1103 {
1104 vector.swap(v.vector);
1105 }
1106
1107
1108 template <typename Number, typename MemorySpace>
1109 inline void
1110 Vector<Number, MemorySpace>::add(const std::vector<size_type> &indices,
1111 const std::vector<Number> &values)
1112 {
1113 // if we have ghost values, do not allow
1114 // writing to this vector at all.
1115 AssertDimension(indices.size(), values.size());
1116
1117 add(indices.size(), indices.data(), values.data());
1118 }
1119
1120
1121
1122 template <typename Number, typename MemorySpace>
1123 inline void
1125 const size_type *indices,
1126 const Number *values)
1127 {
1128 // if we have ghost values, do not allow
1129 // writing to this vector at all.
1130 Assert(!has_ghost_elements(), ExcGhostsPresent());
1131
1132# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1133 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>(
1134 Tpetra::Access::ReadWrite);
1135# else
1136 vector->template sync<Kokkos::HostSpace>();
1137
1138 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>();
1139# endif
1140
1141 // Having extracted a view into the multivectors above, now also
1142 // extract a view into the one vector we actually store. We can
1143 // do this right away for the locally owned part. We defer creating
1144 // the view into the nonlocal part to when we know that we actually
1145 // need it; this also makes sure that we correctly deal with the
1146 // case where we do not actually store a nonlocal part.
1147 auto vector_1d_local = Kokkos::subview(vector_2d_local, Kokkos::ALL(), 0);
1148 using ViewType1d = decltype(vector_1d_local);
1149 std::optional<ViewType1d> vector_1d_nonlocal;
1150
1151# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1152 // Mark vector as to-be-modified. We may do the same with
1153 // the nonlocal part too if we end up writing into it.
1154 vector->template modify<Kokkos::HostSpace>();
1155# endif
1156
1157 for (size_type i = 0; i < n_elements; ++i)
1158 {
1159 const size_type row = indices[i];
1160
1161 // Check if the index is in the locally owned index set.
1162 // If so, we can write right into the locally owned
1163 // part of the vector.
1164 if (TrilinosWrappers::types::int_type local_row =
1165 vector->getMap()->getLocalElement(row);
1166 local_row != Teuchos::OrdinalTraits<int>::invalid())
1167 {
1168 vector_1d_local(local_row) += values[i];
1169
1170 // Set the compressed state to false only if there is nonlocal
1171 // part in this distributed vector, otherwise it's always
1172 // compressed.
1173 if (nonlocal_vector.get() != nullptr)
1174 compressed = false;
1175 }
1176 else
1177 {
1178 // If the element was not in the locally owned part,
1179 // we need to figure out whether it is in the nonlocal
1180 // part. It better be:
1181 Assert(nonlocal_vector.get() != nullptr, ExcInternalError());
1183 nonlocal_vector->getMap()->getLocalElement(row);
1184
1185# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1186 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1187 ExcAccessToNonLocalElement(
1188 row,
1189 vector->getMap()->getLocalNumElements(),
1190 vector->getMap()->getMinLocalIndex(),
1191 vector->getMap()->getMaxLocalIndex()));
1192# else
1193 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1194 ExcAccessToNonLocalElement(
1195 row,
1196 vector->getMap()->getNodeNumElements(),
1197 vector->getMap()->getMinLocalIndex(),
1198 vector->getMap()->getMaxLocalIndex()));
1199
1200# endif
1201
1202 // Having asserted that it is, write into the nonlocal part.
1203 // To do so, we first need to make sure that we have a view
1204 // of the nonlocal part of the vectors, since we have
1205 // deferred creating this view previously:
1206 if (!vector_1d_nonlocal)
1207 {
1208# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1209 auto vector_2d_nonlocal =
1210 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1211 Tpetra::Access::ReadWrite);
1212# else
1213 auto vector_2d_nonlocal =
1214 nonlocal_vector->template getLocalView<Kokkos::HostSpace>();
1215# endif
1216
1217 vector_1d_nonlocal =
1218 Kokkos::subview(vector_2d_nonlocal, Kokkos::ALL(), 0);
1219
1220# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1221 // Mark the nonlocal vector as to-be-modified as well.
1222 nonlocal_vector->template modify<Kokkos::HostSpace>();
1223# endif
1224 }
1225 (*vector_1d_nonlocal)(nonlocal_row) += values[i];
1226 compressed = false;
1227 }
1228 }
1229
1230# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1231 vector->template sync<
1232 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1233 device_type::memory_space>();
1234
1235 // If we have created a view to the nonlocal part, then we have also
1236 // written into it. Flush these modifications.
1237 if (vector_1d_nonlocal)
1238 nonlocal_vector->template sync<
1239 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1240 device_type::memory_space>();
1241# endif
1242 }
1243
1244
1245
1246 template <typename Number, typename MemorySpace>
1247 inline void
1249 const size_type *indices,
1250 const Number *values)
1251 {
1252 // if we have ghost values, do not allow
1253 // writing to this vector at all.
1254 Assert(!has_ghost_elements(), ExcGhostsPresent());
1255
1256# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1257 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>(
1258 Tpetra::Access::ReadWrite);
1259# else
1260 vector->template sync<Kokkos::HostSpace>();
1261
1262 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>();
1263# endif
1264
1265 // Having extracted a view into the multivectors above, now also
1266 // extract a view into the one vector we actually store. We can
1267 // do this right away for the locally owned part. We defer creating
1268 // the view into the nonlocal part to when we know that we actually
1269 // need it; this also makes sure that we correctly deal with the
1270 // case where we do not actually store a nonlocal part.
1271 auto vector_1d_local = Kokkos::subview(vector_2d_local, Kokkos::ALL(), 0);
1272 using ViewType1d = decltype(vector_1d_local);
1273 std::optional<ViewType1d> vector_1d_nonlocal;
1274
1275# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1276 // Mark vector as to-be-modified. We may do the same with
1277 // the nonlocal part too if we end up writing into it.
1278 vector->template modify<Kokkos::HostSpace>();
1279# endif
1280
1281 for (size_type i = 0; i < n_elements; ++i)
1282 {
1283 const size_type row = indices[i];
1284
1285 // Check if the index is in the locally owned index set.
1286 // If so, we can write right into the locally owned
1287 // part of the vector.
1288 if (TrilinosWrappers::types::int_type local_row =
1289 vector->getMap()->getLocalElement(row);
1290 local_row != Teuchos::OrdinalTraits<int>::invalid())
1291 {
1292 vector_1d_local(local_row) = values[i];
1293
1294 // Set the compressed state to false only if there is nonlocal
1295 // part in this distributed vector, otherwise it's always
1296 // compressed.
1297 if (nonlocal_vector.get() != nullptr)
1298 compressed = false;
1299 }
1300 else
1301 {
1302 // If the element was not in the locally owned part,
1303 // we need to figure out whether it is in the nonlocal
1304 // part. It better be:
1305 Assert(nonlocal_vector.get() != nullptr, ExcInternalError());
1307 nonlocal_vector->getMap()->getLocalElement(row);
1308
1309# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1310 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1311 ExcAccessToNonLocalElement(
1312 row,
1313 vector->getMap()->getLocalNumElements(),
1314 vector->getMap()->getMinLocalIndex(),
1315 vector->getMap()->getMaxLocalIndex()));
1316# else
1317 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1318 ExcAccessToNonLocalElement(
1319 row,
1320 vector->getMap()->getNodeNumElements(),
1321 vector->getMap()->getMinLocalIndex(),
1322 vector->getMap()->getMaxLocalIndex()));
1323
1324# endif
1325
1326 // Having asserted that it is, write into the nonlocal part.
1327 // To do so, we first need to make sure that we have a view
1328 // of the nonlocal part of the vectors, since we have
1329 // deferred creating this view previously:
1330 if (!vector_1d_nonlocal)
1331 {
1332# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1333 auto vector_2d_nonlocal =
1334 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1335 Tpetra::Access::ReadWrite);
1336# else
1337 auto vector_2d_nonlocal =
1338 nonlocal_vector->template getLocalView<Kokkos::HostSpace>();
1339# endif
1340
1341 vector_1d_nonlocal =
1342 Kokkos::subview(vector_2d_nonlocal, Kokkos::ALL(), 0);
1343
1344# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1345 // Mark the nonlocal vector as to-be-modified as well.
1346 nonlocal_vector->template modify<Kokkos::HostSpace>();
1347# endif
1348 }
1349 (*vector_1d_nonlocal)(nonlocal_row) = values[i];
1350 compressed = false;
1351 }
1352 }
1353
1354# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1355 vector->template sync<
1356 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1357 device_type::memory_space>();
1358
1359 // If we have created a view to the nonlocal part, then we have also
1360 // written into it. Flush these modifications.
1361 if (vector_1d_nonlocal)
1362 nonlocal_vector->template sync<
1363 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1364 device_type::memory_space>();
1365# endif
1366 }
1367
1368
1369
1370 template <typename Number, typename MemorySpace>
1371 inline internal::VectorReference<Number, MemorySpace>
1373 {
1374 return internal::VectorReference(*this, index);
1375 }
1376
1377 template <typename Number, typename MemorySpace>
1378 inline internal::VectorReference<Number, MemorySpace>
1380 {
1381 return operator()(index);
1382 }
1383
1384 template <typename Number, typename MemorySpace>
1385 inline Number
1387 {
1388 return operator()(index);
1389 }
1390
1391# ifndef DOXYGEN
1392
1393 // VectorReference
1394 namespace internal
1395 {
1396 template <typename Number, typename MemorySpace>
1397 inline VectorReference<Number, MemorySpace>::VectorReference(
1399 const size_type index)
1400 : vector(vector)
1401 , index(index)
1402 {}
1403
1404
1405
1406 template <typename Number, typename MemorySpace>
1407 inline const VectorReference<Number, MemorySpace> &
1408 VectorReference<Number, MemorySpace>::operator=(
1409 const VectorReference<Number, MemorySpace> &r) const
1410 {
1411 // as explained in the class
1412 // documentation, this is not the copy
1413 // operator. so simply pass on to the
1414 // "correct" assignment operator
1415 *this = static_cast<Number>(r);
1416
1417 return *this;
1418 }
1419
1420
1421
1422 template <typename Number, typename MemorySpace>
1423 inline VectorReference<Number, MemorySpace> &
1424 VectorReference<Number, MemorySpace>::operator=(
1425 const VectorReference<Number, MemorySpace> &r)
1426 {
1427 // as above
1428 *this = static_cast<Number>(r);
1429
1430 return *this;
1431 }
1432
1433
1434
1435 template <typename Number, typename MemorySpace>
1436 inline const VectorReference<Number, MemorySpace> &
1437 VectorReference<Number, MemorySpace>::operator=(const Number &value) const
1438 {
1439 vector.set(1, &index, &value);
1440 return *this;
1441 }
1442
1443
1444
1445 template <typename Number, typename MemorySpace>
1446 inline const VectorReference<Number, MemorySpace> &
1447 VectorReference<Number, MemorySpace>::operator+=(
1448 const Number &value) const
1449 {
1450 vector.add(1, &index, &value);
1451 return *this;
1452 }
1453
1454
1455
1456 template <typename Number, typename MemorySpace>
1457 inline const VectorReference<Number, MemorySpace> &
1458 VectorReference<Number, MemorySpace>::operator-=(
1459 const Number &value) const
1460 {
1461 Number new_value = -value;
1462 vector.add(1, &index, &new_value);
1463 return *this;
1464 }
1465
1466
1467
1468 template <typename Number, typename MemorySpace>
1469 inline const VectorReference<Number, MemorySpace> &
1470 VectorReference<Number, MemorySpace>::operator*=(
1471 const Number &value) const
1472 {
1473 Number new_value = static_cast<Number>(*this) * value;
1474 vector.set(1, &index, &new_value);
1475 return *this;
1476 }
1477
1478
1479
1480 template <typename Number, typename MemorySpace>
1481 inline const VectorReference<Number, MemorySpace> &
1482 VectorReference<Number, MemorySpace>::operator/=(
1483 const Number &value) const
1484 {
1485 Number new_value = static_cast<Number>(*this) / value;
1486 vector.set(1, &index, &new_value);
1487 return *this;
1488 }
1489 } // namespace internal
1490
1491# endif /* DOXYGEN */
1492
1493 } // namespace TpetraWrappers
1494
1497} // namespace LinearAlgebra
1498
1499
1500namespace internal
1501{
1502 namespace LinearOperatorImplementation
1503 {
1504 template <typename>
1505 class ReinitHelper;
1506
1511 template <typename Number, typename MemorySpace>
1513 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>>
1514 {
1515 public:
1516 template <typename Matrix>
1517 static void
1519 const Matrix &matrix,
1521 bool omit_zeroing_entries)
1522 {
1523 v.reinit(matrix.locally_owned_range_indices(),
1524 matrix.get_mpi_communicator(),
1525 omit_zeroing_entries);
1526 }
1527
1528 template <typename Matrix>
1529 static void
1531 const Matrix &matrix,
1533 bool omit_zeroing_entries)
1534 {
1535 v.reinit(matrix.locally_owned_domain_indices(),
1536 matrix.get_mpi_communicator(),
1537 omit_zeroing_entries);
1538 }
1539 };
1540
1541 } // namespace LinearOperatorImplementation
1542} /* namespace internal */
1543
1547template <typename Number, typename MemorySpace>
1549 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>> : std::false_type
1550{};
1551
1553
1554#endif
1555
1556#endif
void reinit(const Vector< Number, MemorySpace > &V, const bool omit_zeroing_entries=false)
void equ(const Number a, const Vector< Number, MemorySpace > &V)
Teuchos::RCP< const TpetraWrappers::CommunicationPattern< MemorySpace > > tpetra_comm_pattern
void reinit(const IndexSet &locally_owned_entries, const IndexSet &locally_relevant_or_ghost_entries, const MPI_Comm communicator=MPI_COMM_WORLD, const bool vector_writable=false)
void add(const Number a, const Vector< Number, MemorySpace > &V, const Number b, const Vector< Number, MemorySpace > &W)
Number add_and_dot(const Number a, const Vector< Number, MemorySpace > &V, const Vector< Number, MemorySpace > &W)
TpetraTypes::VectorType< Number, MemorySpace > & trilinos_vector()
void reinit(const IndexSet &parallel_partitioner, const MPI_Comm communicator=MPI_COMM_WORLD, const bool omit_zeroing_entries=false)
Teuchos::RCP< TpetraTypes::VectorType< Number, MemorySpace > > vector
Number operator[](const size_type index) const
bool operator==(const Vector< Number, MemorySpace > &v) const
Vector(const IndexSet &parallel_partitioner, const MPI_Comm communicator)
void scale(const Vector< Number, MemorySpace > &scaling_factors)
void set(const size_type n_elements, const size_type *indices, const Number *values)
void import_elements(const ReadWriteVector< Number > &V, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern)
Vector(const Teuchos::RCP< TpetraTypes::VectorType< Number, MemorySpace > > V)
internal::VectorReference< Number, MemorySpace > reference
reference operator()(const size_type index)
virtual void swap(Vector &v) noexcept
virtual void extract_subvector_to(const ArrayView< const types::global_dof_index > &indices, const ArrayView< Number > &elements) const override
const internal::VectorReference< Number, MemorySpace > const_reference
void compress(const VectorOperation::values operation)
bool operator!=(const Vector< Number, MemorySpace > &v) const
Number operator()(const size_type index) const
Vector & operator/=(const Number factor)
std::pair< size_type, size_type > local_range() const
void sadd(const Number s, const Number a, const Vector< Number, MemorySpace > &V)
reference operator[](const size_type index)
void add(const Number a, const Vector< Number, MemorySpace > &V)
Vector & operator*=(const Number factor)
void add(const size_type n_elements, const size_type *indices, const Number *values)
void import_elements(const ReadWriteVector< Number > &V, VectorOperation::values operation, const Teuchos::RCP< const Utilities::MPI::CommunicationPatternBase > &communication_pattern)
void add(const std::vector< size_type > &indices, const std::vector< Number > &values)
typename numbers::NumberTraits< Number >::real_type real_type
Vector & operator-=(const Vector< Number, MemorySpace > &V)
Vector & operator=(const ::Vector< OtherNumber > &V)
::IndexSet locally_owned_elements() const
Vector & operator=(const Vector &V)
Vector & operator=(const Number s)
Vector & operator+=(const Vector< Number, MemorySpace > &V)
const TpetraTypes::VectorType< Number, MemorySpace > & trilinos_vector() const
virtual size_type size() const override
void import_elements(const ReadWriteVector< Number > &V, VectorOperation::values operation)
void create_tpetra_comm_pattern(const IndexSet &source_index_set, const MPI_Comm mpi_comm)
Teuchos::RCP< const TpetraTypes::VectorType< Number, MemorySpace > > trilinos_rcp() const
Number operator*(const Vector< Number, MemorySpace > &V) const
std::size_t memory_consumption() const
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
bool in_local_range(const size_type index) const
Vector(const IndexSet &locally_owned_entries, const IndexSet &ghost_entries, const MPI_Comm communicator, const bool vector_writable=false)
Teuchos::RCP< TpetraTypes::VectorType< Number, MemorySpace > > nonlocal_vector
Teuchos::RCP< TpetraTypes::VectorType< Number, MemorySpace > > trilinos_rcp()
static void reinit_range_vector(const Matrix &matrix, LinearAlgebra::TpetraWrappers::Vector< Number, MemorySpace > &v, bool omit_zeroing_entries)
static void reinit_domain_vector(const Matrix &matrix, LinearAlgebra::TpetraWrappers::Vector< Number, MemorySpace > &v, bool omit_zeroing_entries)
#define DEAL_II_DEPRECATED
Definition config.h:205
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
#define DeclException0(Exception0)
Definition exceptions.h:466
static ::ExceptionBase & ExcGhostsPresent()
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
Definition exceptions.h:580
static ::ExceptionBase & ExcVectorTypeNotCompatible()
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
#define Assert(cond, exc)
static ::ExceptionBase & ExcMissingIndexSet()
#define AssertDimension(dim1, dim2)
#define DeclExceptionMsg(Exception, defaulttext)
Definition exceptions.h:489
static ::ExceptionBase & ExcInternalError()
#define DeclException1(Exception1, type1, outsequence)
Definition exceptions.h:511
static ::ExceptionBase & ExcDifferentParallelPartitioning()
static ::ExceptionBase & ExcTrilinosError(int arg1)
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
void swap(Vector< Number, MemorySpace > &u, Vector< Number, MemorySpace > &v) noexcept
STL namespace.
unsigned int global_dof_index
Definition types.h:81