Loading [MathJax]/extensions/TeX/AMSsymbols.js
 deal.II version GIT relicensing-2972-g3b1da50de6 2025-03-29 20: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\}}\)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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
331 const MPI_Comm communicator);
332
348 const IndexSet &ghost_entries,
349 const MPI_Comm communicator,
350 const bool vector_writable = false);
351
356 void
358
365 void
367 const MPI_Comm communicator = MPI_COMM_WORLD,
368 const bool omit_zeroing_entries = false);
369
384 void
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
484 const Teuchos::RCP<const Utilities::MPI::CommunicationPatternBase>
486
491 void
495 const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
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
507
512 void
513 import(const ReadWriteVector<Number> &V,
515 std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
517 {
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
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
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 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>(
1133 Tpetra::Access::ReadWrite);
1134
1135 // Having extracted a view into the multivectors above, now also
1136 // extract a view into the one vector we actually store. We can
1137 // do this right away for the locally owned part. We defer creating
1138 // the view into the nonlocal part to when we know that we actually
1139 // need it; this also makes sure that we correctly deal with the
1140 // case where we do not actually store a nonlocal part.
1141 auto vector_1d_local = Kokkos::subview(vector_2d_local, Kokkos::ALL(), 0);
1142 using ViewType1d = decltype(vector_1d_local);
1143 std::optional<ViewType1d> vector_1d_nonlocal;
1144
1145# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1146 // Mark vector as to-be-modified. We may do the same with
1147 // the nonlocal part too if we end up writing into it.
1148 vector->template modify<Kokkos::HostSpace>();
1149# endif
1150
1151 for (size_type i = 0; i < n_elements; ++i)
1152 {
1153 const size_type row = indices[i];
1154
1155 // Check if the index is in the locally owned index set.
1156 // If so, we can write right into the locally owned
1157 // part of the vector.
1158 if (TrilinosWrappers::types::int_type local_row =
1159 vector->getMap()->getLocalElement(row);
1160 local_row != Teuchos::OrdinalTraits<int>::invalid())
1161 {
1162 vector_1d_local(local_row) += values[i];
1163
1164 // Set the compressed state to false only if there is nonlocal
1165 // part in this distributed vector, otherwise it's always
1166 // compressed.
1167 if (nonlocal_vector.get() != nullptr)
1168 compressed = false;
1169 }
1170 else
1171 {
1172 // If the element was not in the locally owned part,
1173 // we need to figure out whether it is in the nonlocal
1174 // part. It better be:
1175 Assert(nonlocal_vector.get() != nullptr, ExcInternalError());
1177 nonlocal_vector->getMap()->getLocalElement(row);
1178
1179# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1180 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1181 ExcAccessToNonLocalElement(
1182 row,
1183 vector->getMap()->getLocalNumElements(),
1184 vector->getMap()->getMinLocalIndex(),
1185 vector->getMap()->getMaxLocalIndex()));
1186# else
1187 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1188 ExcAccessToNonLocalElement(
1189 row,
1190 vector->getMap()->getNodeNumElements(),
1191 vector->getMap()->getMinLocalIndex(),
1192 vector->getMap()->getMaxLocalIndex()));
1193
1194# endif
1195
1196 // Having asserted that it is, write into the nonlocal part.
1197 // To do so, we first need to make sure that we have a view
1198 // of the nonlocal part of the vectors, since we have
1199 // deferred creating this view previously:
1200 if (!vector_1d_nonlocal)
1201 {
1202# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1203 auto vector_2d_nonlocal =
1204 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1205 Tpetra::Access::ReadWrite);
1206# else
1207 auto vector_2d_nonlocal =
1208 nonlocal_vector->template getLocalView<Kokkos::HostSpace>();
1209# endif
1210
1211 vector_1d_nonlocal =
1212 Kokkos::subview(vector_2d_nonlocal, Kokkos::ALL(), 0);
1213
1214# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1215 // Mark the nonlocal vector as to-be-modified as well.
1216 nonlocal_vector->template modify<Kokkos::HostSpace>();
1217# endif
1218 }
1219 (*vector_1d_nonlocal)(nonlocal_row) += values[i];
1220 compressed = false;
1221 }
1222 }
1223
1224# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1225 vector->template sync<
1226 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1227 device_type::memory_space>();
1228
1229 // If we have created a view to the nonlocal part, then we have also
1230 // written into it. Flush these modifications.
1231 if (vector_1d_nonlocal)
1232 nonlocal_vector->template sync<
1233 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1234 device_type::memory_space>();
1235# endif
1236 }
1237
1238
1239
1240 template <typename Number, typename MemorySpace>
1241 inline void
1243 const size_type *indices,
1244 const Number *values)
1245 {
1246 // if we have ghost values, do not allow
1247 // writing to this vector at all.
1248 Assert(!has_ghost_elements(), ExcGhostsPresent());
1249
1250# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1251 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>(
1252 Tpetra::Access::ReadWrite);
1253# else
1254 vector->template sync<Kokkos::HostSpace>();
1255
1256 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>();
1257# endif
1258
1259 // Having extracted a view into the multivectors above, now also
1260 // extract a view into the one vector we actually store. We can
1261 // do this right away for the locally owned part. We defer creating
1262 // the view into the nonlocal part to when we know that we actually
1263 // need it; this also makes sure that we correctly deal with the
1264 // case where we do not actually store a nonlocal part.
1265 auto vector_1d_local = Kokkos::subview(vector_2d_local, Kokkos::ALL(), 0);
1266 using ViewType1d = decltype(vector_1d_local);
1267 std::optional<ViewType1d> vector_1d_nonlocal;
1268
1269# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1270 // Mark vector as to-be-modified. We may do the same with
1271 // the nonlocal part too if we end up writing into it.
1272 vector->template modify<Kokkos::HostSpace>();
1273# endif
1274
1275 for (size_type i = 0; i < n_elements; ++i)
1276 {
1277 const size_type row = indices[i];
1278
1279 // Check if the index is in the locally owned index set.
1280 // If so, we can write right into the locally owned
1281 // part of the vector.
1282 if (TrilinosWrappers::types::int_type local_row =
1283 vector->getMap()->getLocalElement(row);
1284 local_row != Teuchos::OrdinalTraits<int>::invalid())
1285 {
1286 vector_1d_local(local_row) = values[i];
1287
1288 // Set the compressed state to false only if there is nonlocal
1289 // part in this distributed vector, otherwise it's always
1290 // compressed.
1291 if (nonlocal_vector.get() != nullptr)
1292 compressed = false;
1293 }
1294 else
1295 {
1296 // If the element was not in the locally owned part,
1297 // we need to figure out whether it is in the nonlocal
1298 // part. It better be:
1299 Assert(nonlocal_vector.get() != nullptr, ExcInternalError());
1301 nonlocal_vector->getMap()->getLocalElement(row);
1302
1303# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1304 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1305 ExcAccessToNonLocalElement(
1306 row,
1307 vector->getMap()->getLocalNumElements(),
1308 vector->getMap()->getMinLocalIndex(),
1309 vector->getMap()->getMaxLocalIndex()));
1310# else
1311 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1312 ExcAccessToNonLocalElement(
1313 row,
1314 vector->getMap()->getNodeNumElements(),
1315 vector->getMap()->getMinLocalIndex(),
1316 vector->getMap()->getMaxLocalIndex()));
1317
1318# endif
1319
1320 // Having asserted that it is, write into the nonlocal part.
1321 // To do so, we first need to make sure that we have a view
1322 // of the nonlocal part of the vectors, since we have
1323 // deferred creating this view previously:
1324 if (!vector_1d_nonlocal)
1325 {
1326# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1327 auto vector_2d_nonlocal =
1328 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1329 Tpetra::Access::ReadWrite);
1330# else
1331 auto vector_2d_nonlocal =
1332 nonlocal_vector->template getLocalView<Kokkos::HostSpace>();
1333# endif
1334
1335 vector_1d_nonlocal =
1336 Kokkos::subview(vector_2d_nonlocal, Kokkos::ALL(), 0);
1337
1338# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1339 // Mark the nonlocal vector as to-be-modified as well.
1340 nonlocal_vector->template modify<Kokkos::HostSpace>();
1341# endif
1342 }
1343 (*vector_1d_nonlocal)(nonlocal_row) = values[i];
1344 compressed = false;
1345 }
1346 }
1347
1348# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1349 vector->template sync<
1350 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1351 device_type::memory_space>();
1352
1353 // If we have created a view to the nonlocal part, then we have also
1354 // written into it. Flush these modifications.
1355 if (vector_1d_nonlocal)
1356 nonlocal_vector->template sync<
1357 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1358 device_type::memory_space>();
1359# endif
1360 }
1361
1362
1363
1364 template <typename Number, typename MemorySpace>
1365 inline internal::VectorReference<Number, MemorySpace>
1367 {
1368 return internal::VectorReference(*this, index);
1369 }
1370
1371 template <typename Number, typename MemorySpace>
1372 inline internal::VectorReference<Number, MemorySpace>
1374 {
1375 return operator()(index);
1376 }
1377
1378 template <typename Number, typename MemorySpace>
1379 inline Number
1381 {
1382 return operator()(index);
1383 }
1384
1385# ifndef DOXYGEN
1386
1387 // VectorReference
1388 namespace internal
1389 {
1390 template <typename Number, typename MemorySpace>
1391 inline VectorReference<Number, MemorySpace>::VectorReference(
1393 const size_type index)
1394 : vector(vector)
1395 , index(index)
1396 {}
1397
1398
1399
1400 template <typename Number, typename MemorySpace>
1401 inline const VectorReference<Number, MemorySpace> &
1402 VectorReference<Number, MemorySpace>::operator=(
1403 const VectorReference<Number, MemorySpace> &r) const
1404 {
1405 // as explained in the class
1406 // documentation, this is not the copy
1407 // operator. so simply pass on to the
1408 // "correct" assignment operator
1409 *this = static_cast<Number>(r);
1410
1411 return *this;
1412 }
1413
1414
1415
1416 template <typename Number, typename MemorySpace>
1417 inline VectorReference<Number, MemorySpace> &
1418 VectorReference<Number, MemorySpace>::operator=(
1419 const VectorReference<Number, MemorySpace> &r)
1420 {
1421 // as above
1422 *this = static_cast<Number>(r);
1423
1424 return *this;
1425 }
1426
1427
1428
1429 template <typename Number, typename MemorySpace>
1430 inline const VectorReference<Number, MemorySpace> &
1431 VectorReference<Number, MemorySpace>::operator=(const Number &value) const
1432 {
1433 vector.set(1, &index, &value);
1434 return *this;
1435 }
1436
1437
1438
1439 template <typename Number, typename MemorySpace>
1440 inline const VectorReference<Number, MemorySpace> &
1441 VectorReference<Number, MemorySpace>::operator+=(
1442 const Number &value) const
1443 {
1444 vector.add(1, &index, &value);
1445 return *this;
1446 }
1447
1448
1449
1450 template <typename Number, typename MemorySpace>
1451 inline const VectorReference<Number, MemorySpace> &
1452 VectorReference<Number, MemorySpace>::operator-=(
1453 const Number &value) const
1454 {
1455 Number new_value = -value;
1456 vector.add(1, &index, &new_value);
1457 return *this;
1458 }
1459
1460
1461
1462 template <typename Number, typename MemorySpace>
1463 inline const VectorReference<Number, MemorySpace> &
1464 VectorReference<Number, MemorySpace>::operator*=(
1465 const Number &value) const
1466 {
1467 Number new_value = static_cast<Number>(*this) * value;
1468 vector.set(1, &index, &new_value);
1469 return *this;
1470 }
1471
1472
1473
1474 template <typename Number, typename MemorySpace>
1475 inline const VectorReference<Number, MemorySpace> &
1476 VectorReference<Number, MemorySpace>::operator/=(
1477 const Number &value) const
1478 {
1479 Number new_value = static_cast<Number>(*this) / value;
1480 vector.set(1, &index, &new_value);
1481 return *this;
1482 }
1483 } // namespace internal
1484
1485# endif /* DOXYGEN */
1486
1487 } // namespace TpetraWrappers
1488
1491} // namespace LinearAlgebra
1492
1493
1494namespace internal
1495{
1496 namespace LinearOperatorImplementation
1497 {
1498 template <typename>
1499 class ReinitHelper;
1500
1505 template <typename Number, typename MemorySpace>
1507 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>>
1508 {
1509 public:
1510 template <typename Matrix>
1511 static void
1513 const Matrix &matrix,
1515 bool omit_zeroing_entries)
1516 {
1517 v.reinit(matrix.locally_owned_range_indices(),
1518 matrix.get_mpi_communicator(),
1519 omit_zeroing_entries);
1520 }
1521
1522 template <typename Matrix>
1523 static void
1525 const Matrix &matrix,
1527 bool omit_zeroing_entries)
1528 {
1529 v.reinit(matrix.locally_owned_domain_indices(),
1530 matrix.get_mpi_communicator(),
1531 omit_zeroing_entries);
1532 }
1533 };
1534
1535 } // namespace LinearOperatorImplementation
1536} /* namespace internal */
1537
1541template <typename Number, typename MemorySpace>
1543 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>> : std::false_type
1544{};
1545
1547
1548#endif
1549
1550#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 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()
virtual void swap(Vector &v) noexcept
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:284
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:40
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:41
#define DeclException0(Exception0)
static ::ExceptionBase & ExcGhostsPresent()
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
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)
static ::ExceptionBase & ExcInternalError()
#define DeclException1(Exception1, type1, outsequence)
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:90