deal.II version GIT relicensing-6809-ge913b9bb34 2026-09-25 17: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
trilinos_tpetra_vector.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) 2018 - 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_trilinos_tpetra_vector_h
14#define dealii_trilinos_tpetra_vector_h
15
16
17#include <deal.II/base/config.h>
18
19#include <deal.II/base/types.h>
20
22
23#ifdef DEAL_II_TRILINOS_WITH_TPETRA
24
27
30# include <deal.II/lac/vector.h>
33
34# include <Teuchos_Comm.hpp>
35# include <Teuchos_OrdinalTraits.hpp>
36# include <Tpetra_Core.hpp>
37# include <Tpetra_Vector.hpp>
38# include <Tpetra_Version.hpp>
39
40# include <complex>
41# include <memory>
42# include <optional>
43# include <utility>
44
45#endif
46
48
49#ifdef DEAL_II_TRILINOS_WITH_TPETRA
55template <typename Number>
56struct is_tpetra_type : std::false_type
57{};
58
59# ifdef DEAL_II_TRILINOS_WITH_TPETRA_INST_FLOAT
60template <>
61struct is_tpetra_type<float> : std::true_type
62{};
63# endif
64
65# ifdef DEAL_II_TRILINOS_WITH_TPETRA_INST_DOUBLE
66template <>
67struct is_tpetra_type<double> : std::true_type
68{};
69# endif
70
71# ifdef DEAL_II_WITH_COMPLEX_VALUES
72# ifdef DEAL_II_TRILINOS_WITH_TPETRA_INST_COMPLEX_FLOAT
73template <>
74struct is_tpetra_type<std::complex<float>> : std::true_type
75{};
76# endif
77
78# ifdef DEAL_II_TRILINOS_WITH_TPETRA_INST_COMPLEX_DOUBLE
79template <>
80struct is_tpetra_type<std::complex<double>> : std::true_type
81{};
82# endif
83# endif
84
85namespace LinearAlgebra
86{
87 // Forward declaration
88# ifndef DOXYGEN
89 template <typename Number>
90 class ReadWriteVector;
91# endif
92
107 namespace TpetraWrappers
108 {
109
115 {
116 public:
118 };
119
130 namespace internal
131 {
135 using size_type = types::global_dof_index;
136
146 template <typename Number,
148 class VectorReference
149 {
150 private:
155 VectorReference(Vector<Number, MemorySpace> &vector,
156 const size_type index);
157
158 public:
162 VectorReference(const VectorReference &) = default;
163
175 const VectorReference &
176 operator=(const VectorReference &r) const;
177
181 VectorReference &
182 operator=(const VectorReference &r);
183
187 const VectorReference &
188 operator=(const Number &s) const;
189
193 const VectorReference &
194 operator+=(const Number &s) const;
195
199 const VectorReference &
200 operator-=(const Number &s) const;
201
205 const VectorReference &
206 operator*=(const Number &s) const;
207
211 const VectorReference &
212 operator/=(const Number &s) const;
213
218 operator Number() const;
219
223 DeclException1(ExcTrilinosError,
224 int,
225 << "An error with error number " << arg1
226 << " occurred while calling a Trilinos function");
227
228 /*
229 * Access to a an element that is not (locally-)owned.
230 *
231 * @ingroup Exceptions
232 */
234 ExcAccessToNonLocalElement,
235 size_type,
236 size_type,
237 size_type,
238 size_type,
239 << "You are trying to access element " << arg1
240 << " of a distributed vector, but this element is not stored "
241 << "on the current processor. Note: There are " << arg2
242 << " elements stored "
243 << "on the current processor from within the range [" << arg3 << ','
244 << arg4 << "] but Trilinos vectors need not store contiguous "
245 << "ranges on each processor, and not every element in "
246 << "this range may in fact be stored locally."
247 << "\n\n"
248 << "A common source for this kind of problem is that you "
249 << "are passing a 'fully distributed' vector into a function "
250 << "that needs read access to vector elements that correspond "
251 << "to degrees of freedom on ghost cells (or at least to "
252 << "'locally active' degrees of freedom that are not also "
253 << "'locally owned'). You need to pass a vector that has these "
254 << "elements as ghost entries.");
255
256 private:
261
265 const size_type index;
266
267 // Make the vector class a friend, so that it can create objects of the
268 // present type.
269 friend class Vector<Number, MemorySpace>;
270 }; // class VectorReference
271
272 } // namespace internal
289 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
290 class Vector : public ReadVector<Number>
291 {
292 public:
296 using value_type = Number;
299 using reference = internal::VectorReference<Number, MemorySpace>;
301 const internal::VectorReference<Number, MemorySpace>;
302
313
318 Vector(const Vector &V);
319
325
333 explicit Vector(const IndexSet &parallel_partitioner,
334 const MPI_Comm communicator = MPI_COMM_WORLD);
335
350 explicit Vector(const IndexSet &locally_owned_entries,
351 const IndexSet &ghost_entries,
352 const MPI_Comm communicator,
353 const bool vector_writable = false);
354
359 void
361
368 void
369 reinit(const IndexSet &parallel_partitioner,
370 const MPI_Comm communicator = MPI_COMM_WORLD,
371 const bool omit_zeroing_entries = false);
372
387 void
388 reinit(const IndexSet &locally_owned_entries,
389 const IndexSet &locally_relevant_or_ghost_entries,
390 const MPI_Comm communicator = MPI_COMM_WORLD,
391 const bool vector_writable = false);
392
397 void
399 const bool omit_zeroing_entries = false);
400
416 virtual void
417 swap(Vector &v) noexcept;
418
422 virtual void
425 const ArrayView<Number> &elements) const override;
426
456 Vector &
457 operator=(const Vector &V);
458
464 template <typename OtherNumber>
465 Vector &
466 operator=(const ::Vector<OtherNumber> &V);
467
481 Vector &
482 operator=(const Number s);
483
492 void
495 VectorOperation::values operation,
496 const Teuchos::RCP<const Utilities::MPI::CommunicationPatternBase>
497 &communication_pattern);
498
499 /*
500 * Imports all the elements present in the vector's IndexSet from the
501 * input vector @p V. VectorOperation::values @p operation is used to decide if
502 * the elements in @p V should be added to the current vector or replace the
503 * current elements.
504 */
505 void
507 VectorOperation::values operation);
508
525 operator()(const size_type index);
526
534 Number
535 operator()(const size_type index) const;
536
543 operator[](const size_type index);
544
550 Number
551 operator[](const size_type index) const;
552
564 Vector &
565 operator*=(const Number factor);
566
570 Vector &
571 operator/=(const Number factor);
572
576 Vector &
578
582 Vector &
584
589 Number
591
595 void
596 add(const Number a);
597
610 void
612 const bool allow_different_maps = false);
613
618 void
619 add(const Number a, const Vector<Number, MemorySpace> &V);
620
625 void
626 add(const Number a,
628 const Number b,
630
635 void
636 add(const std::vector<size_type> &indices,
637 const std::vector<Number> &values);
638
643 void
644 add(const std::vector<size_type> &indices,
645 const ::Vector<Number> &values);
646
652 void
653 add(const size_type n_elements,
654 const size_type *indices,
655 const Number *values);
656
661 void
662 sadd(const Number s,
663 const Number a,
665
670 void
671 sadd(const Number s, const Vector<Number, MemorySpace> &V);
672
679 void
680 set(const size_type n_elements,
681 const size_type *indices,
682 const Number *values);
683
690 void
691 set(const std::vector<size_type> &indices,
692 const std::vector<Number> &values);
693
700 void
701 scale(const Vector<Number, MemorySpace> &scaling_factors);
702
706 void
707 equ(const Number a, const Vector<Number, MemorySpace> &V);
708
712 bool
713 all_zero() const;
714
720 bool
722
734 Number
735 mean_value() const;
736
740 Number
741 min() const;
742
746 Number
747 max() const;
748
754 l1_norm() const;
755
761 l2_norm() const;
762
768 lp_norm(const real_type p) const;
769
775 linfty_norm() const;
776
781 norm_sqr() const;
782
809 Number
810 add_and_dot(const Number a,
813
825 bool
827
833 bool
835
841 bool
843
848 virtual size_type
849 size() const override;
850
857
884 std::pair<size_type, size_type>
885 local_range() const;
886
894 bool
895 in_local_range(const size_type index) const;
896
902 bool
904
910
924
947 void
949
956 void
958
965
972
979
984 Teuchos::RCP<const TpetraTypes::VectorType<Number, MemorySpace>>
986
991 Teuchos::RCP<TpetraTypes::VectorType<Number, MemorySpace>>
993
997 void
998 print(std::ostream &out,
999 const unsigned int precision = 3,
1000 const bool scientific = true,
1001 const bool across = true) const;
1002
1006 std::size_t
1008
1012 MPI_Comm
1013 mpi_comm() const;
1014
1025
1032
1033 /*
1034 * Access to a an element that is not (locally-)owned.
1035 *
1036 * @ingroup Exceptions
1037 */
1040 size_type,
1041 size_type,
1042 size_type,
1043 size_type,
1044 << "You are trying to access element " << arg1
1045 << " of a distributed vector, but this element is not stored "
1046 << "on the current processor. Note: There are " << arg2
1047 << " elements stored "
1048 << "on the current processor from within the range [" << arg3 << ','
1049 << arg4 << "] but Trilinos vectors need not store contiguous "
1050 << "ranges on each processor, and not every element in "
1051 << "this range may in fact be stored locally."
1052 << "\n\n"
1053 << "A common source for this kind of problem is that you "
1054 << "are passing a 'fully distributed' vector into a function "
1055 << "that needs read access to vector elements that correspond "
1056 << "to degrees of freedom on ghost cells (or at least to "
1057 << "'locally active' degrees of freedom that are not also "
1058 << "'locally owned'). You need to pass a vector that has these "
1059 << "elements as ghost entries.");
1060
1067 "To compress a vector, a locally_relevant_dofs "
1068 "index set, and a locally_owned_dofs index set "
1069 "must be provided. These index sets must be "
1070 "provided either when the vector is initialized "
1071 "or when compress is called. See the documentation "
1072 "of compress() for more information.");
1073
1080 int,
1081 << "An error with error number " << arg1
1082 << " occurred while calling a Trilinos function");
1083
1084 private:
1090 void
1091 create_tpetra_comm_pattern(const IndexSet &source_index_set,
1092 const MPI_Comm mpi_comm);
1093
1099
1109
1117
1121 Teuchos::RCP<TpetraTypes::VectorType<Number, MemorySpace>> vector;
1122
1128 Teuchos::RCP<TpetraTypes::VectorType<Number, MemorySpace>>
1130
1135
1140
1143 using host_view_type = typename dual_view_type::t_host;
1144
1146 Kokkos::Subview<host_view_type,
1147 std::remove_const_t<decltype(Kokkos::ALL)>,
1148 unsigned>;
1159 std::vector<types::global_dof_index> nonlocal_cached_indices;
1160
1165 std::vector<Number> nonlocal_cached_values;
1166
1171 mutable std::optional<array_view_type> vector_1d_view;
1172
1177 mutable std::optional<array_view_type> nonlocal_vector_1d_view;
1178
1187 mutable std::mutex mutex;
1188
1193 Teuchos::RCP<const TpetraWrappers::CommunicationPattern<MemorySpace>>
1195
1196 // Make the reference class a friend.
1197 friend class internal::VectorReference<Number, MemorySpace>;
1198 };
1199
1200
1201 /* ------------------------- Inline functions ---------------------- */
1202
1203 template <typename Number, typename MemorySpace>
1204 inline void
1206 Vector<Number, MemorySpace> &v) noexcept
1207 {
1208 u.swap(v);
1209 }
1210
1211
1212 template <typename Number, typename MemorySpace>
1213 inline bool
1215 {
1216 return has_ghost;
1217 }
1218
1219
1220
1221 template <typename Number, typename MemorySpace>
1222 inline bool
1224 {
1225 return compressed;
1226 }
1227
1228
1229
1230 template <typename Number, typename MemorySpace>
1231 inline void
1233 {
1234 std::swap(compressed, v.compressed);
1235 std::swap(has_ghost, v.has_ghost);
1236 std::swap(last_action, v.last_action);
1237 vector.swap(v.vector);
1238 nonlocal_vector.swap(v.nonlocal_vector);
1239 std::swap(vector_1d_view, v.vector_1d_view);
1240 std::swap(nonlocal_vector_1d_view, v.nonlocal_vector_1d_view);
1241 std::swap(source_stored_elements, v.source_stored_elements);
1242 std::swap(local_entries, v.local_entries);
1243 std::swap(nonlocal_cached_indices, v.nonlocal_cached_indices);
1244 std::swap(nonlocal_cached_values, v.nonlocal_cached_values);
1245 tpetra_comm_pattern.swap(v.tpetra_comm_pattern);
1246 }
1247
1248
1249
1250 template <typename Number, typename MemorySpace>
1251 inline void
1253 const bool allow_different_maps)
1254 {
1255 Assert(!allow_different_maps, ExcNotImplemented());
1256 this->add(1, V);
1257 }
1258
1259
1260
1261 template <typename Number, typename MemorySpace>
1262 inline void
1263 Vector<Number, MemorySpace>::add(const std::vector<size_type> &indices,
1264 const std::vector<Number> &values)
1265 {
1266 // if we have ghost values, do not allow
1267 // writing to this vector at all.
1268 AssertDimension(indices.size(), values.size());
1269
1270 add(indices.size(), indices.data(), values.data());
1271 }
1272
1273
1274
1275 template <typename Number, typename MemorySpace>
1276 inline void
1277 Vector<Number, MemorySpace>::add(const std::vector<size_type> &indices,
1278 const ::Vector<Number> &values)
1279 {
1280 // if we have ghost values, do not allow
1281 // writing to this vector at all.
1282 Assert(!has_ghost_elements(), ExcGhostsPresent());
1283 AssertDimension(indices.size(), values.size());
1284
1285 add(indices.size(), indices.data(), values.begin());
1286 }
1287
1288
1289
1290 template <typename Number, typename MemorySpace>
1291 inline void
1293 const size_type *indices,
1294 const Number *values)
1295 {
1296 // if we have ghost values, do not allow
1297 // writing to this vector at all.
1298 Assert(!has_ghost_elements(), ExcGhostsPresent());
1299
1300 Assert(
1301 nonlocal_vector.is_null() ||
1302 (last_action == VectorOperation::unknown) ||
1303 (last_action == VectorOperation::add),
1304 ExcMessage(
1305 "Cannot mix add and insert operations on a Tpetra vector "
1306 "with non-locally owned entries without calling compress() in between."));
1307
1308 last_action = VectorOperation::add;
1309
1310 // Create a non-owning pointer to the vector map. This way we avoid thread
1311 // safety problems with owning pointers.
1312 Teuchos::Ptr<
1314 vector_map;
1315 {
1316# ifndef HAVE_TEUCHOS_THREAD_SAFE
1317 // Make this part of the function thread safe
1318 std::scoped_lock lock(mutex);
1319# endif
1320
1321 vector_map = vector->getMap().ptr();
1322
1323 // Make sure we have a view available to access the vector entries.
1324 if (!vector_1d_view)
1325 {
1326 auto vector_2d_view =
1327 vector->template getLocalView<Kokkos::HostSpace>(
1328 Tpetra::Access::ReadWriteStruct{});
1329
1330 vector_1d_view = Kokkos::subview(vector_2d_view, Kokkos::ALL(), 0);
1331 }
1332
1333 if (!nonlocal_vector_1d_view && !nonlocal_vector.is_null())
1334 {
1335 auto nonlocal_vector_2d_view =
1336 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1337 Tpetra::Access::ReadWriteStruct{});
1338
1339 nonlocal_vector_1d_view =
1340 Kokkos::subview(nonlocal_vector_2d_view, Kokkos::ALL(), 0);
1341 }
1342 }
1343
1344 for (size_type i = 0; i < n_elements; ++i)
1345 {
1346 const size_type row = indices[i];
1347
1348 // Check if the index is in the locally owned index set.
1349 // If so, we can write right into the locally owned
1350 // part of the vector.
1351 if (TrilinosWrappers::types::int_type local_row =
1352 vector_map->getLocalElement(row);
1353 local_row != Teuchos::OrdinalTraits<int>::invalid())
1354 {
1355 (*vector_1d_view)(local_row) += values[i];
1356
1357 // Set the compressed state to false only if there is nonlocal
1358 // part in this distributed vector, otherwise it's always
1359 // compressed.
1360 if (nonlocal_vector.get() != nullptr)
1361 compressed = false;
1362 }
1363 else if (nonlocal_vector.get() == nullptr)
1364 {
1365# ifndef HAVE_TEUCHOS_THREAD_SAFE
1366 // Make this part of the function thread safe
1367 std::scoped_lock lock(mutex);
1368# endif
1369
1370 // The element is not in the locally owned part, and
1371 // there is no specified nonlocal_vector, i.e. this is
1372 // a fully distributed vector with a nonlocal cache.
1373 // Add the element to the cache.
1374 nonlocal_cached_indices.push_back(row);
1375 nonlocal_cached_values.push_back(values[i]);
1376 compressed = false;
1377 }
1378 else
1379 {
1380# ifndef HAVE_TEUCHOS_THREAD_SAFE
1381 // Make this part of the function thread safe
1382 std::scoped_lock lock(mutex);
1383# endif
1384
1385 // If the element was not in the locally owned part,
1386 // and we have a predetermined nonlocal buffer, we need
1387 // to figure out whether it is in the nonlocal
1388 // part. It better be:
1390 nonlocal_vector->getMap()->getLocalElement(row);
1391
1392# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1393 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1394 ExcAccessToNonLocalElement(
1395 row,
1396 vector->getMap()->getLocalNumElements(),
1397 vector->getMap()->getMinLocalIndex(),
1398 vector->getMap()->getMaxLocalIndex()));
1399# else
1400 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1401 ExcAccessToNonLocalElement(
1402 row,
1403 vector->getMap()->getNodeNumElements(),
1404 vector->getMap()->getMinLocalIndex(),
1405 vector->getMap()->getMaxLocalIndex()));
1406
1407# endif
1408
1409 (*nonlocal_vector_1d_view)(nonlocal_row) += values[i];
1410 compressed = false;
1411 }
1412 }
1413 }
1414
1415
1416
1417 template <typename Number, typename MemorySpace>
1418 inline void
1419 Vector<Number, MemorySpace>::set(const std::vector<size_type> &indices,
1420 const std::vector<Number> &values)
1421 {
1422 AssertDimension(indices.size(), values.size());
1423 set(indices.size(), indices.data(), values.data());
1424 }
1425
1426
1427
1428 template <typename Number, typename MemorySpace>
1429 inline void
1431 const size_type *indices,
1432 const Number *values)
1433 {
1434 // if we have ghost values, do not allow
1435 // writing to this vector at all.
1436 Assert(!has_ghost_elements(), ExcGhostsPresent());
1437
1438 Assert(
1439 nonlocal_vector.is_null() ||
1440 (last_action == VectorOperation::unknown) ||
1441 (last_action == VectorOperation::insert),
1442 ExcMessage(
1443 "Cannot mix add and insert operations on a Tpetra vector "
1444 "with non-locally owned entries without calling compress() in between."));
1445
1446 last_action = VectorOperation::insert;
1447
1448 // Create a non-owning pointer to the vector map. This way we avoid thread
1449 // safety problems with owning pointers.
1450 Teuchos::Ptr<
1452 vector_map;
1453 {
1454# ifndef HAVE_TEUCHOS_THREAD_SAFE
1455 // Make this part of the function thread safe
1456 std::scoped_lock lock(mutex);
1457# endif
1458
1459 vector_map = vector->getMap().ptr();
1460
1461 // Make sure we have a view available to access the vector entries.
1462 if (!vector_1d_view)
1463 {
1464 auto vector_2d_view =
1465 vector->template getLocalView<Kokkos::HostSpace>(
1466 Tpetra::Access::ReadWriteStruct{});
1467
1468 vector_1d_view = Kokkos::subview(vector_2d_view, Kokkos::ALL(), 0);
1469 }
1470
1471 if (!nonlocal_vector_1d_view && !nonlocal_vector.is_null())
1472 {
1473 auto nonlocal_vector_2d_view =
1474 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1475 Tpetra::Access::ReadWriteStruct{});
1476
1477 nonlocal_vector_1d_view =
1478 Kokkos::subview(nonlocal_vector_2d_view, Kokkos::ALL(), 0);
1479 }
1480 }
1481
1482 for (size_type i = 0; i < n_elements; ++i)
1483 {
1484 const size_type row = indices[i];
1485
1486 // Check if the index is in the locally owned index set.
1487 // If so, we can write right into the locally owned
1488 // part of the vector.
1489 if (TrilinosWrappers::types::int_type local_row =
1490 vector_map->getLocalElement(row);
1491 local_row != Teuchos::OrdinalTraits<int>::invalid())
1492 {
1493 (*vector_1d_view)(local_row) = values[i];
1494
1495 // Set the compressed state to false only if there is nonlocal
1496 // part in this distributed vector, otherwise it's always
1497 // compressed.
1498 if (nonlocal_vector.get() != nullptr)
1499 compressed = false;
1500 }
1501 else if (nonlocal_vector.get() == nullptr)
1502 {
1503# ifndef HAVE_TEUCHOS_THREAD_SAFE
1504 // Make this part of the function thread safe
1505 std::scoped_lock lock(mutex);
1506# endif
1507
1508 // The element is not in the locally owned part, and
1509 // there is no specified nonlocal_vector, i.e. this is
1510 // a fully distributed vector with a nonlocal cache.
1511 // Add the element to the cache.
1512 nonlocal_cached_indices.push_back(row);
1513 nonlocal_cached_values.push_back(values[i]);
1514 compressed = false;
1515 }
1516 else
1517 {
1518# ifndef HAVE_TEUCHOS_THREAD_SAFE
1519 // Make this part of the function thread safe
1520 std::scoped_lock lock(mutex);
1521# endif
1522
1523 // If the element was not in the locally owned part,
1524 // and we have a predetermined nonlocal buffer, we need
1525 // to figure out whether it is in the nonlocal
1526 // part. It better be:
1528 nonlocal_vector->getMap()->getLocalElement(row);
1529
1530# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1531 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1532 ExcAccessToNonLocalElement(
1533 row,
1534 vector->getMap()->getLocalNumElements(),
1535 vector->getMap()->getMinLocalIndex(),
1536 vector->getMap()->getMaxLocalIndex()));
1537# else
1538 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1539 ExcAccessToNonLocalElement(
1540 row,
1541 vector->getMap()->getNodeNumElements(),
1542 vector->getMap()->getMinLocalIndex(),
1543 vector->getMap()->getMaxLocalIndex()));
1544
1545# endif
1546
1547 (*nonlocal_vector_1d_view)(nonlocal_row) = values[i];
1548 compressed = false;
1549 }
1550 }
1551 }
1552
1553
1554
1555 template <typename Number, typename MemorySpace>
1556 inline internal::VectorReference<Number, MemorySpace>
1558 {
1559 return internal::VectorReference(*this, index);
1560 }
1561
1562 template <typename Number, typename MemorySpace>
1563 inline internal::VectorReference<Number, MemorySpace>
1565 {
1566 return operator()(index);
1567 }
1568
1569 template <typename Number, typename MemorySpace>
1570 inline Number
1572 {
1573 return operator()(index);
1574 }
1575
1576# ifndef DOXYGEN
1577
1578 // VectorReference
1579 namespace internal
1580 {
1581 template <typename Number, typename MemorySpace>
1582 inline VectorReference<Number, MemorySpace>::VectorReference(
1584 const size_type index)
1585 : vector(vector)
1586 , index(index)
1587 {}
1588
1589
1590
1591 template <typename Number, typename MemorySpace>
1592 inline const VectorReference<Number, MemorySpace> &
1593 VectorReference<Number, MemorySpace>::operator=(
1594 const VectorReference<Number, MemorySpace> &r) const
1595 {
1596 // as explained in the class
1597 // documentation, this is not the copy
1598 // operator. so simply pass on to the
1599 // "correct" assignment operator
1600 *this = static_cast<Number>(r);
1601
1602 return *this;
1603 }
1604
1605
1606
1607 template <typename Number, typename MemorySpace>
1608 inline VectorReference<Number, MemorySpace> &
1609 VectorReference<Number, MemorySpace>::operator=(
1610 const VectorReference<Number, MemorySpace> &r)
1611 {
1612 // as above
1613 *this = static_cast<Number>(r);
1614
1615 return *this;
1616 }
1617
1618
1619
1620 template <typename Number, typename MemorySpace>
1621 inline const VectorReference<Number, MemorySpace> &
1622 VectorReference<Number, MemorySpace>::operator=(const Number &value) const
1623 {
1624 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
1625
1626 vector.set(1, &index, &value);
1627
1628 return *this;
1629 }
1630
1631
1632
1633 template <typename Number, typename MemorySpace>
1634 inline const VectorReference<Number, MemorySpace> &
1635 VectorReference<Number, MemorySpace>::operator+=(
1636 const Number &value) const
1637 {
1638 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
1639
1640 vector.add(1, &index, &value);
1641
1642 return *this;
1643 }
1644
1645
1646
1647 template <typename Number, typename MemorySpace>
1648 inline const VectorReference<Number, MemorySpace> &
1649 VectorReference<Number, MemorySpace>::operator-=(
1650 const Number &value) const
1651 {
1652 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
1653
1654 const Number new_value = -value;
1655 vector.add(1, &index, &new_value);
1656
1657 return *this;
1658 }
1659
1660
1661
1662 template <typename Number, typename MemorySpace>
1663 inline const VectorReference<Number, MemorySpace> &
1664 VectorReference<Number, MemorySpace>::operator*=(
1665 const Number &value) const
1666 {
1667 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
1668
1669 const Number new_value = static_cast<Number>(*this) * value;
1670 vector.set(1, &index, &new_value);
1671
1672 return *this;
1673 }
1674
1675
1676
1677 template <typename Number, typename MemorySpace>
1678 inline const VectorReference<Number, MemorySpace> &
1679 VectorReference<Number, MemorySpace>::operator/=(
1680 const Number &value) const
1681 {
1682 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
1683
1684 const Number new_value = static_cast<Number>(*this) / value;
1685 vector.set(1, &index, &new_value);
1686
1687 return *this;
1688 }
1689 } // namespace internal
1690
1691# endif /* DOXYGEN */
1692
1693 } // namespace TpetraWrappers
1694
1697} // namespace LinearAlgebra
1698
1699
1700
1701namespace internal
1702{
1703 namespace LinearOperatorImplementation
1704 {
1705 template <typename>
1706 class ReinitHelper;
1707
1712 template <typename Number, typename MemorySpace>
1714 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>>
1715 {
1716 public:
1717 template <typename Matrix>
1718 static void
1720 const Matrix &matrix,
1722 bool omit_zeroing_entries)
1723 {
1724 v.reinit(matrix.locally_owned_range_indices(),
1725 matrix.get_mpi_communicator(),
1726 omit_zeroing_entries);
1727 }
1728
1729 template <typename Matrix>
1730 static void
1732 const Matrix &matrix,
1734 bool omit_zeroing_entries)
1735 {
1736 v.reinit(matrix.locally_owned_domain_indices(),
1737 matrix.get_mpi_communicator(),
1738 omit_zeroing_entries);
1739 }
1740 };
1741
1742 } // namespace LinearOperatorImplementation
1743} /* namespace internal */
1744
1748template <typename Number, typename MemorySpace>
1750 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>> : std::false_type
1751{};
1752
1753#endif
1754
1756
1757#endif
*  x_component_mask set(0, true)
*  *  Point< dim > operator()(const Point< dim > &p) const * 
const TpetraTypes::MapType< MemorySpace > & trilinos_partitioner() const
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)
std::optional< array_view_type > nonlocal_vector_1d_view
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
std::optional< array_view_type > vector_1d_view
void sadd(const Number s, const Vector< Number, MemorySpace > &V)
typename dual_view_type::t_host host_view_type
Number operator[](const size_type index) const
bool operator==(const Vector< Number, MemorySpace > &v) const
void scale(const Vector< Number, MemorySpace > &scaling_factors)
void add(const std::vector< size_type > &indices, const ::Vector< Number > &values)
void set(const std::vector< size_type > &indices, const std::vector< Number > &values)
Vector(const IndexSet &parallel_partitioner, const MPI_Comm communicator=MPI_COMM_WORLD)
void set(const size_type n_elements, const size_type *indices, const Number *values)
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)
Kokkos::Subview< host_view_type, std::remove_const_t< decltype(Kokkos::ALL)>, unsigned > array_view_type
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 Vector< Number, MemorySpace > &V, const bool allow_different_maps=false)
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)
typename TpetraTypes::VectorType< Number, MemorySpace >::dual_view_type dual_view_type
void create_tpetra_comm_pattern(const IndexSet &source_index_set, const MPI_Comm mpi_comm)
std::vector< types::global_dof_index > nonlocal_cached_indices
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
real_type lp_norm(const real_type p) 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_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DeclException0(Exception0)
static ::ExceptionBase & ExcGhostsPresent()
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
static ::ExceptionBase & ExcVectorTypeNotCompatible()
static ::ExceptionBase & ExcNotImplemented()
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)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcDifferentParallelPartitioning()
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcTrilinosError(int arg1)
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
Tpetra::Map< LO, GO, NodeType< MemorySpace > > MapType
void swap(Vector< Number, MemorySpace > &u, Vector< Number, MemorySpace > &v) noexcept
*  *  *  RotationFunction< dim, Number >::RotationFunction Number(dim)
STL namespace.
unsigned int global_dof_index
Definition types.h:92