deal.II version 9.8.0
\(\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
97
107 namespace TpetraWrappers
108 {
109
115 {
116 public:
118 };
119
123
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
276
277
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
510
511
516
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
554
555
560
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
639
645 void
646 add(const size_type n_elements,
647 const size_type *indices,
648 const Number *values);
649
654 void
655 sadd(const Number s,
656 const Number a,
658
663 void
664 sadd(const Number s, const Vector<Number, MemorySpace> &V);
665
672 void
673 set(const size_type n_elements,
674 const size_type *indices,
675 const Number *values);
676
683 void
684 set(const std::vector<size_type> &indices,
685 const std::vector<Number> &values);
686
693 void
694 scale(const Vector<Number, MemorySpace> &scaling_factors);
695
699 void
700 equ(const Number a, const Vector<Number, MemorySpace> &V);
701
705 bool
706 all_zero() const;
707
713 bool
715
717
718
723
727 Number
728 mean_value() const;
729
733 Number
734 min() const;
735
739 Number
740 max() const;
741
747 l1_norm() const;
748
754 l2_norm() const;
755
761 linfty_norm() const;
762
767 norm_sqr() const;
768
795 Number
796 add_and_dot(const Number a,
799
801
802
807
811 bool
813
819 bool
821
827 bool
829
834 virtual size_type
835 size() const override;
836
843
866 std::pair<size_type, size_type>
867 local_range() const;
868
876 bool
877 in_local_range(const size_type index) const;
878
884 bool
886
892
906
908
909
929 void
931
938 void
940
947
954
961
966 Teuchos::RCP<const TpetraTypes::VectorType<Number, MemorySpace>>
968
973 Teuchos::RCP<TpetraTypes::VectorType<Number, MemorySpace>>
975
979 void
980 print(std::ostream &out,
981 const unsigned int precision = 3,
982 const bool scientific = true,
983 const bool across = true) const;
984
988 std::size_t
990
995 mpi_comm() const;
996
998
999
1007
1014
1015 /*
1016 * Access to a an element that is not (locally-)owned.
1017 *
1018 * @ingroup Exceptions
1019 */
1022 size_type,
1023 size_type,
1024 size_type,
1025 size_type,
1026 << "You are trying to access element " << arg1
1027 << " of a distributed vector, but this element is not stored "
1028 << "on the current processor. Note: There are " << arg2
1029 << " elements stored "
1030 << "on the current processor from within the range [" << arg3 << ','
1031 << arg4 << "] but Trilinos vectors need not store contiguous "
1032 << "ranges on each processor, and not every element in "
1033 << "this range may in fact be stored locally."
1034 << "\n\n"
1035 << "A common source for this kind of problem is that you "
1036 << "are passing a 'fully distributed' vector into a function "
1037 << "that needs read access to vector elements that correspond "
1038 << "to degrees of freedom on ghost cells (or at least to "
1039 << "'locally active' degrees of freedom that are not also "
1040 << "'locally owned'). You need to pass a vector that has these "
1041 << "elements as ghost entries.");
1042
1049 "To compress a vector, a locally_relevant_dofs "
1050 "index set, and a locally_owned_dofs index set "
1051 "must be provided. These index sets must be "
1052 "provided either when the vector is initialized "
1053 "or when compress is called. See the documentation "
1054 "of compress() for more information.");
1055
1062 int,
1063 << "An error with error number " << arg1
1064 << " occurred while calling a Trilinos function");
1065
1066 private:
1072 void
1073 create_tpetra_comm_pattern(const IndexSet &source_index_set,
1074 const MPI_Comm mpi_comm);
1075
1081
1091
1099
1103 Teuchos::RCP<TpetraTypes::VectorType<Number, MemorySpace>> vector;
1104
1110 Teuchos::RCP<TpetraTypes::VectorType<Number, MemorySpace>>
1112
1117
1122
1125 using host_view_type = typename dual_view_type::t_host;
1126
1128 Kokkos::Subview<host_view_type,
1129 std::remove_const_t<decltype(Kokkos::ALL)>,
1130 unsigned>;
1141 std::vector<types::global_dof_index> nonlocal_cached_indices;
1142
1147 std::vector<Number> nonlocal_cached_values;
1148
1153 mutable std::optional<array_view_type> vector_1d_view;
1154
1159 mutable std::optional<array_view_type> nonlocal_vector_1d_view;
1160
1169 mutable std::mutex mutex;
1170
1175 Teuchos::RCP<const TpetraWrappers::CommunicationPattern<MemorySpace>>
1177
1178 // Make the reference class a friend.
1179 friend class internal::VectorReference<Number, MemorySpace>;
1180 };
1181
1182
1183 /* ------------------------- Inline functions ---------------------- */
1184
1185 template <typename Number, typename MemorySpace>
1186 inline void
1188 Vector<Number, MemorySpace> &v) noexcept
1189 {
1190 u.swap(v);
1191 }
1192
1193
1194 template <typename Number, typename MemorySpace>
1195 inline bool
1200
1201
1202
1203 template <typename Number, typename MemorySpace>
1204 inline bool
1206 {
1207 return compressed;
1208 }
1209
1210
1211
1212 template <typename Number, typename MemorySpace>
1213 inline void
1215 {
1216 std::swap(compressed, v.compressed);
1217 std::swap(has_ghost, v.has_ghost);
1218 std::swap(last_action, v.last_action);
1219 vector.swap(v.vector);
1220 nonlocal_vector.swap(v.nonlocal_vector);
1221 std::swap(vector_1d_view, v.vector_1d_view);
1222 std::swap(nonlocal_vector_1d_view, v.nonlocal_vector_1d_view);
1223 std::swap(source_stored_elements, v.source_stored_elements);
1224 std::swap(local_entries, v.local_entries);
1225 std::swap(nonlocal_cached_indices, v.nonlocal_cached_indices);
1226 std::swap(nonlocal_cached_values, v.nonlocal_cached_values);
1227 tpetra_comm_pattern.swap(v.tpetra_comm_pattern);
1228 }
1229
1230
1231
1232 template <typename Number, typename MemorySpace>
1233 inline void
1235 const bool allow_different_maps)
1236 {
1237 Assert(!allow_different_maps, ExcNotImplemented());
1238 this->add(1, V);
1239 }
1240
1241
1242
1243 template <typename Number, typename MemorySpace>
1244 inline void
1245 Vector<Number, MemorySpace>::add(const std::vector<size_type> &indices,
1246 const std::vector<Number> &values)
1247 {
1248 // if we have ghost values, do not allow
1249 // writing to this vector at all.
1250 AssertDimension(indices.size(), values.size());
1251
1252 add(indices.size(), indices.data(), values.data());
1253 }
1254
1255
1256
1257 template <typename Number, typename MemorySpace>
1258 inline void
1260 const size_type *indices,
1261 const Number *values)
1262 {
1263 // if we have ghost values, do not allow
1264 // writing to this vector at all.
1266
1267 Assert(
1268 nonlocal_vector.is_null() ||
1271 ExcMessage(
1272 "Cannot mix add and insert operations on a Tpetra vector "
1273 "with non-locally owned entries without calling compress() in between."));
1274
1276
1277 // Create a non-owning pointer to the vector map. This way we avoid thread
1278 // safety problems with owning pointers.
1279 Teuchos::Ptr<
1281 vector_map;
1282 {
1283# ifndef HAVE_TEUCHOS_THREAD_SAFE
1284 // Make this part of the function thread safe
1285 std::scoped_lock lock(mutex);
1286# endif
1287
1288 vector_map = vector->getMap().ptr();
1289
1290 // Make sure we have a view available to access the vector entries.
1291 if (!vector_1d_view)
1292 {
1293 auto vector_2d_view =
1294 vector->template getLocalView<Kokkos::HostSpace>(
1295 Tpetra::Access::ReadWriteStruct{});
1296
1297 vector_1d_view = Kokkos::subview(vector_2d_view, Kokkos::ALL(), 0);
1298 }
1299
1300 if (!nonlocal_vector_1d_view && !nonlocal_vector.is_null())
1301 {
1302 auto nonlocal_vector_2d_view =
1303 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1304 Tpetra::Access::ReadWriteStruct{});
1305
1307 Kokkos::subview(nonlocal_vector_2d_view, Kokkos::ALL(), 0);
1308 }
1309 }
1310
1311 for (size_type i = 0; i < n_elements; ++i)
1312 {
1313 const size_type row = indices[i];
1314
1315 // Check if the index is in the locally owned index set.
1316 // If so, we can write right into the locally owned
1317 // part of the vector.
1318 if (TrilinosWrappers::types::int_type local_row =
1319 vector_map->getLocalElement(row);
1320 local_row != Teuchos::OrdinalTraits<int>::invalid())
1321 {
1322 (*vector_1d_view)(local_row) += values[i];
1323
1324 // Set the compressed state to false only if there is nonlocal
1325 // part in this distributed vector, otherwise it's always
1326 // compressed.
1327 if (nonlocal_vector.get() != nullptr)
1328 compressed = false;
1329 }
1330 else if (nonlocal_vector.get() == nullptr)
1331 {
1332# ifndef HAVE_TEUCHOS_THREAD_SAFE
1333 // Make this part of the function thread safe
1334 std::scoped_lock lock(mutex);
1335# endif
1336
1337 // The element is not in the locally owned part, and
1338 // there is no specified nonlocal_vector, i.e. this is
1339 // a fully distributed vector with a nonlocal cache.
1340 // Add the element to the cache.
1341 nonlocal_cached_indices.push_back(row);
1342 nonlocal_cached_values.push_back(values[i]);
1343 compressed = false;
1344 }
1345 else
1346 {
1347# ifndef HAVE_TEUCHOS_THREAD_SAFE
1348 // Make this part of the function thread safe
1349 std::scoped_lock lock(mutex);
1350# endif
1351
1352 // If the element was not in the locally owned part,
1353 // and we have a predetermined nonlocal buffer, we need
1354 // to figure out whether it is in the nonlocal
1355 // part. It better be:
1357 nonlocal_vector->getMap()->getLocalElement(row);
1358
1359# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1360 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1362 row,
1363 vector->getMap()->getLocalNumElements(),
1364 vector->getMap()->getMinLocalIndex(),
1365 vector->getMap()->getMaxLocalIndex()));
1366# else
1367 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1369 row,
1370 vector->getMap()->getNodeNumElements(),
1371 vector->getMap()->getMinLocalIndex(),
1372 vector->getMap()->getMaxLocalIndex()));
1373
1374# endif
1375
1376 (*nonlocal_vector_1d_view)(nonlocal_row) += values[i];
1377 compressed = false;
1378 }
1379 }
1380 }
1381
1382
1383
1384 template <typename Number, typename MemorySpace>
1385 inline void
1386 Vector<Number, MemorySpace>::set(const std::vector<size_type> &indices,
1387 const std::vector<Number> &values)
1388 {
1389 AssertDimension(indices.size(), values.size());
1390 set(indices.size(), indices.data(), values.data());
1391 }
1392
1393
1394
1395 template <typename Number, typename MemorySpace>
1396 inline void
1398 const size_type *indices,
1399 const Number *values)
1400 {
1401 // if we have ghost values, do not allow
1402 // writing to this vector at all.
1404
1405 Assert(
1406 nonlocal_vector.is_null() ||
1409 ExcMessage(
1410 "Cannot mix add and insert operations on a Tpetra vector "
1411 "with non-locally owned entries without calling compress() in between."));
1412
1414
1415 // Create a non-owning pointer to the vector map. This way we avoid thread
1416 // safety problems with owning pointers.
1417 Teuchos::Ptr<
1419 vector_map;
1420 {
1421# ifndef HAVE_TEUCHOS_THREAD_SAFE
1422 // Make this part of the function thread safe
1423 std::scoped_lock lock(mutex);
1424# endif
1425
1426 vector_map = vector->getMap().ptr();
1427
1428 // Make sure we have a view available to access the vector entries.
1429 if (!vector_1d_view)
1430 {
1431 auto vector_2d_view =
1432 vector->template getLocalView<Kokkos::HostSpace>(
1433 Tpetra::Access::ReadWriteStruct{});
1434
1435 vector_1d_view = Kokkos::subview(vector_2d_view, Kokkos::ALL(), 0);
1436 }
1437
1438 if (!nonlocal_vector_1d_view && !nonlocal_vector.is_null())
1439 {
1440 auto nonlocal_vector_2d_view =
1441 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1442 Tpetra::Access::ReadWriteStruct{});
1443
1445 Kokkos::subview(nonlocal_vector_2d_view, Kokkos::ALL(), 0);
1446 }
1447 }
1448
1449 for (size_type i = 0; i < n_elements; ++i)
1450 {
1451 const size_type row = indices[i];
1452
1453 // Check if the index is in the locally owned index set.
1454 // If so, we can write right into the locally owned
1455 // part of the vector.
1456 if (TrilinosWrappers::types::int_type local_row =
1457 vector_map->getLocalElement(row);
1458 local_row != Teuchos::OrdinalTraits<int>::invalid())
1459 {
1460 (*vector_1d_view)(local_row) = values[i];
1461
1462 // Set the compressed state to false only if there is nonlocal
1463 // part in this distributed vector, otherwise it's always
1464 // compressed.
1465 if (nonlocal_vector.get() != nullptr)
1466 compressed = false;
1467 }
1468 else if (nonlocal_vector.get() == nullptr)
1469 {
1470# ifndef HAVE_TEUCHOS_THREAD_SAFE
1471 // Make this part of the function thread safe
1472 std::scoped_lock lock(mutex);
1473# endif
1474
1475 // The element is not in the locally owned part, and
1476 // there is no specified nonlocal_vector, i.e. this is
1477 // a fully distributed vector with a nonlocal cache.
1478 // Add the element to the cache.
1479 nonlocal_cached_indices.push_back(row);
1480 nonlocal_cached_values.push_back(values[i]);
1481 compressed = false;
1482 }
1483 else
1484 {
1485# ifndef HAVE_TEUCHOS_THREAD_SAFE
1486 // Make this part of the function thread safe
1487 std::scoped_lock lock(mutex);
1488# endif
1489
1490 // If the element was not in the locally owned part,
1491 // and we have a predetermined nonlocal buffer, we need
1492 // to figure out whether it is in the nonlocal
1493 // part. It better be:
1495 nonlocal_vector->getMap()->getLocalElement(row);
1496
1497# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1498 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1500 row,
1501 vector->getMap()->getLocalNumElements(),
1502 vector->getMap()->getMinLocalIndex(),
1503 vector->getMap()->getMaxLocalIndex()));
1504# else
1505 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1507 row,
1508 vector->getMap()->getNodeNumElements(),
1509 vector->getMap()->getMinLocalIndex(),
1510 vector->getMap()->getMaxLocalIndex()));
1511
1512# endif
1513
1514 (*nonlocal_vector_1d_view)(nonlocal_row) = values[i];
1515 compressed = false;
1516 }
1517 }
1518 }
1519
1520
1521
1522 template <typename Number, typename MemorySpace>
1523 inline internal::VectorReference<Number, MemorySpace>
1525 {
1526 return internal::VectorReference(*this, index);
1527 }
1528
1529 template <typename Number, typename MemorySpace>
1530 inline internal::VectorReference<Number, MemorySpace>
1532 {
1533 return operator()(index);
1534 }
1535
1536 template <typename Number, typename MemorySpace>
1537 inline Number
1539 {
1540 return operator()(index);
1541 }
1542
1543# ifndef DOXYGEN
1544
1545 // VectorReference
1546 namespace internal
1547 {
1548 template <typename Number, typename MemorySpace>
1549 inline VectorReference<Number, MemorySpace>::VectorReference(
1551 const size_type index)
1552 : vector(vector)
1553 , index(index)
1554 {}
1555
1556
1557
1558 template <typename Number, typename MemorySpace>
1559 inline const VectorReference<Number, MemorySpace> &
1560 VectorReference<Number, MemorySpace>::operator=(
1561 const VectorReference<Number, MemorySpace> &r) const
1562 {
1563 // as explained in the class
1564 // documentation, this is not the copy
1565 // operator. so simply pass on to the
1566 // "correct" assignment operator
1567 *this = static_cast<Number>(r);
1568
1569 return *this;
1570 }
1571
1572
1573
1574 template <typename Number, typename MemorySpace>
1575 inline VectorReference<Number, MemorySpace> &
1576 VectorReference<Number, MemorySpace>::operator=(
1577 const VectorReference<Number, MemorySpace> &r)
1578 {
1579 // as above
1580 *this = static_cast<Number>(r);
1581
1582 return *this;
1583 }
1584
1585
1586
1587 template <typename Number, typename MemorySpace>
1588 inline const VectorReference<Number, MemorySpace> &
1589 VectorReference<Number, MemorySpace>::operator=(const Number &value) const
1590 {
1591 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
1592
1593 vector.set(1, &index, &value);
1594
1595 return *this;
1596 }
1597
1598
1599
1600 template <typename Number, typename MemorySpace>
1601 inline const VectorReference<Number, MemorySpace> &
1602 VectorReference<Number, MemorySpace>::operator+=(
1603 const Number &value) const
1604 {
1605 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
1606
1607 vector.add(1, &index, &value);
1608
1609 return *this;
1610 }
1611
1612
1613
1614 template <typename Number, typename MemorySpace>
1615 inline const VectorReference<Number, MemorySpace> &
1616 VectorReference<Number, MemorySpace>::operator-=(
1617 const Number &value) const
1618 {
1619 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
1620
1621 const Number new_value = -value;
1622 vector.add(1, &index, &new_value);
1623
1624 return *this;
1625 }
1626
1627
1628
1629 template <typename Number, typename MemorySpace>
1630 inline const VectorReference<Number, MemorySpace> &
1631 VectorReference<Number, MemorySpace>::operator*=(
1632 const Number &value) const
1633 {
1634 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
1635
1636 const Number new_value = static_cast<Number>(*this) * value;
1637 vector.set(1, &index, &new_value);
1638
1639 return *this;
1640 }
1641
1642
1643
1644 template <typename Number, typename MemorySpace>
1645 inline const VectorReference<Number, MemorySpace> &
1646 VectorReference<Number, MemorySpace>::operator/=(
1647 const Number &value) const
1648 {
1649 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
1650
1651 const Number new_value = static_cast<Number>(*this) / value;
1652 vector.set(1, &index, &new_value);
1653
1654 return *this;
1655 }
1656 } // namespace internal
1657
1658# endif /* DOXYGEN */
1659
1660 } // namespace TpetraWrappers
1661
1663
1664} // namespace LinearAlgebra
1665
1666
1667
1668namespace internal
1669{
1671 {
1672 template <typename>
1673 class ReinitHelper;
1674
1679 template <typename Number, typename MemorySpace>
1681 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>>
1682 {
1683 public:
1684 template <typename Matrix>
1685 static void
1687 const Matrix &matrix,
1689 bool omit_zeroing_entries)
1690 {
1691 v.reinit(matrix.locally_owned_range_indices(),
1692 matrix.get_mpi_communicator(),
1693 omit_zeroing_entries);
1694 }
1695
1696 template <typename Matrix>
1697 static void
1699 const Matrix &matrix,
1701 bool omit_zeroing_entries)
1702 {
1703 v.reinit(matrix.locally_owned_domain_indices(),
1704 matrix.get_mpi_communicator(),
1705 omit_zeroing_entries);
1706 }
1707 };
1708
1709 } // namespace LinearOperatorImplementation
1710} /* namespace internal */
1711
1715template <typename Number, typename MemorySpace>
1717 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>> : std::false_type
1718{};
1719
1720#endif
1721
1723
1724#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)
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< NumberType, MemorySpace > > vector
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 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 swap(Vector &v) noexcept
virtual void extract_subvector_to(const ArrayView< const types::global_dof_index > &indices, const ArrayView< Number > &elements) const override
void compress(const VectorOperation::values operation)
const internal::VectorReference< Number, MemorySpace > const_reference
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)
typename TpetraTypes::VectorType< Number, MemorySpace >::dual_view_type dual_view_type
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)
void create_tpetra_comm_pattern(const IndexSet &source_index_set, const MPI_Comm mpi_comm)
Kokkos::Subview< host_view_type, std::remove_const_t< decltype(Kokkos::ALL)>, unsigned > array_view_type
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< NumberType, 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_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 & ExcNotImplemented()
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define DeclExceptionMsg(Exception, defaulttext)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcMessage(std::string arg1)
const bool IsBlockVector< VectorType >::value
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