Reference documentation for deal.II version 9.6.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: 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
30
33# include <deal.II/lac/vector.h>
36
37# include <Teuchos_Comm.hpp>
38# include <Teuchos_OrdinalTraits.hpp>
39# include <Tpetra_Core.hpp>
40# include <Tpetra_Vector.hpp>
41# include <Tpetra_Version.hpp>
42
43# include <memory>
44# include <optional>
45
47
53template <typename Number>
54struct is_tpetra_type : std::false_type
55{};
56
57# ifdef HAVE_TPETRA_INST_FLOAT
58template <>
59struct is_tpetra_type<float> : std::true_type
60{};
61# endif
62
63# ifdef HAVE_TPETRA_INST_DOUBLE
64template <>
65struct is_tpetra_type<double> : std::true_type
66{};
67# endif
68
69# ifdef DEAL_II_WITH_COMPLEX_VALUES
70# ifdef HAVE_TPETRA_INST_COMPLEX_FLOAT
71template <>
72struct is_tpetra_type<std::complex<float>> : std::true_type
73{};
74# endif
75
76# ifdef HAVE_TPETRA_INST_COMPLEX_DOUBLE
77template <>
78struct is_tpetra_type<std::complex<double>> : std::true_type
79{};
80# endif
81# endif
82
83namespace LinearAlgebra
84{
85 // Forward declaration
86# ifndef DOXYGEN
87 template <typename Number>
88 class ReadWriteVector;
89# endif
90
105 namespace TpetraWrappers
106 {
107
113 {
114 public:
116 };
117
128 namespace internal
129 {
133 using size_type = types::global_dof_index;
134
144 template <typename Number,
146 class VectorReference
147 {
148 private:
153 VectorReference(Vector<Number, MemorySpace> &vector,
154 const size_type index);
155
156 public:
160 VectorReference(const VectorReference &) = default;
161
173 const VectorReference &
174 operator=(const VectorReference &r) const;
175
179 VectorReference &
180 operator=(const VectorReference &r);
181
185 const VectorReference &
186 operator=(const Number &s) const;
187
191 const VectorReference &
192 operator+=(const Number &s) const;
193
197 const VectorReference &
198 operator-=(const Number &s) const;
199
203 const VectorReference &
204 operator*=(const Number &s) const;
205
209 const VectorReference &
210 operator/=(const Number &s) const;
211
216 operator Number() const;
217
221 DeclException1(ExcTrilinosError,
222 int,
223 << "An error with error number " << arg1
224 << " occurred while calling a Trilinos function");
225
226 /*
227 * Access to a an element that is not (locally-)owned.
228 *
229 * @ingroup Exceptions
230 */
232 ExcAccessToNonLocalElement,
233 size_type,
234 size_type,
235 size_type,
236 size_type,
237 << "You are trying to access element " << arg1
238 << " of a distributed vector, but this element is not stored "
239 << "on the current processor. Note: There are " << arg2
240 << " elements stored "
241 << "on the current processor from within the range [" << arg3 << ','
242 << arg4 << "] but Trilinos vectors need not store contiguous "
243 << "ranges on each processor, and not every element in "
244 << "this range may in fact be stored locally."
245 << "\n\n"
246 << "A common source for this kind of problem is that you "
247 << "are passing a 'fully distributed' vector into a function "
248 << "that needs read access to vector elements that correspond "
249 << "to degrees of freedom on ghost cells (or at least to "
250 << "'locally active' degrees of freedom that are not also "
251 << "'locally owned'). You need to pass a vector that has these "
252 << "elements as ghost entries.");
253
254 private:
259
263 const size_type index;
264
265 // Make the vector class a friend, so that it can create objects of the
266 // present type.
267 friend class Vector<Number, MemorySpace>;
268 }; // class VectorReference
269
270 } // namespace internal
287 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
288 class Vector : public ReadVector<Number>, public Subscriptor
289 {
290 public:
294 using value_type = Number;
297 using reference = internal::VectorReference<Number, MemorySpace>;
299 const internal::VectorReference<Number, MemorySpace>;
300
311
316 Vector(const Vector &V);
317
323
331 explicit Vector(const IndexSet &parallel_partitioner,
332 const MPI_Comm communicator);
333
348 explicit Vector(const IndexSet &locally_owned_entries,
349 const IndexSet &ghost_entries,
350 const MPI_Comm communicator,
351 const bool vector_writable = false);
352
357 void
359
366 void
367 reinit(const IndexSet &parallel_partitioner,
368 const MPI_Comm communicator = MPI_COMM_WORLD,
369 const bool omit_zeroing_entries = false);
370
385 void
386 reinit(const IndexSet &locally_owned_entries,
387 const IndexSet &locally_relevant_or_ghost_entries,
388 const MPI_Comm communicator = MPI_COMM_WORLD,
389 const bool vector_writable = false);
390
395 void
397 const bool omit_zeroing_entries = false);
398
414 virtual void
415 swap(Vector &v) noexcept;
416
420 virtual void
423 ArrayView<Number> &elements) const override;
424
454 Vector &
455 operator=(const Vector &V);
456
462 template <typename OtherNumber>
463 Vector &
464 operator=(const ::Vector<OtherNumber> &V);
465
470 Vector &
471 operator=(const Number s);
472
481 void
484 VectorOperation::values operation,
485 const Teuchos::RCP<const Utilities::MPI::CommunicationPatternBase>
486 &communication_pattern);
487
492 void
495 VectorOperation::values operation,
496 const std::shared_ptr<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
513 void
514 import(const ReadWriteVector<Number> &V,
515 VectorOperation::values operation,
516 std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
517 communication_pattern = {})
518 {
519 import_elements(V, operation, communication_pattern);
520 }
521
538 operator()(const size_type index);
539
547 Number
548 operator()(const size_type index) const;
549
556 operator[](const size_type index);
557
563 Number
564 operator[](const size_type index) const;
565
577 Vector &
578 operator*=(const Number factor);
579
583 Vector &
584 operator/=(const Number factor);
585
589 Vector &
591
595 Vector &
597
602 Number
604
608 void
609 add(const Number a);
610
615 void
616 add(const Number a, const Vector<Number, MemorySpace> &V);
617
622 void
623 add(const Number a,
625 const Number b,
627
632 void
633 add(const std::vector<size_type> &indices,
634 const std::vector<Number> &values);
635
636
642 void
643 add(const size_type n_elements,
644 const size_type *indices,
645 const Number *values);
646
651 void
652 sadd(const Number s,
653 const Number a,
655
662 void
663 set(const size_type n_elements,
664 const size_type *indices,
665 const Number *values);
666
673 void
674 scale(const Vector<Number, MemorySpace> &scaling_factors);
675
679 void
680 equ(const Number a, const Vector<Number, MemorySpace> &V);
681
685 bool
686 all_zero() const;
687
693 bool
695
707 Number
708 mean_value() const;
709
715 l1_norm() const;
716
722 l2_norm() const;
723
729 linfty_norm() const;
730
735 norm_sqr() const;
736
763 Number
764 add_and_dot(const Number a,
767
779 bool
781
787 bool
789
795 bool
797
802 virtual size_type
803 size() const override;
804
811
834 std::pair<size_type, size_type>
835 local_range() const;
836
844 bool
845 in_local_range(const size_type index) const;
846
852 bool
854
860
874
897 void
899
906
913
918 Teuchos::RCP<const TpetraTypes::VectorType<Number, MemorySpace>>
920
925 Teuchos::RCP<TpetraTypes::VectorType<Number, MemorySpace>>
927
931 void
932 print(std::ostream &out,
933 const unsigned int precision = 3,
934 const bool scientific = true,
935 const bool across = true) const;
936
940 std::size_t
942
947 mpi_comm() const;
948
959
966
967 /*
968 * Access to a an element that is not (locally-)owned.
969 *
970 * @ingroup Exceptions
971 */
974 size_type,
975 size_type,
976 size_type,
977 size_type,
978 << "You are trying to access element " << arg1
979 << " of a distributed vector, but this element is not stored "
980 << "on the current processor. Note: There are " << arg2
981 << " elements stored "
982 << "on the current processor from within the range [" << arg3 << ','
983 << arg4 << "] but Trilinos vectors need not store contiguous "
984 << "ranges on each processor, and not every element in "
985 << "this range may in fact be stored locally."
986 << "\n\n"
987 << "A common source for this kind of problem is that you "
988 << "are passing a 'fully distributed' vector into a function "
989 << "that needs read access to vector elements that correspond "
990 << "to degrees of freedom on ghost cells (or at least to "
991 << "'locally active' degrees of freedom that are not also "
992 << "'locally owned'). You need to pass a vector that has these "
993 << "elements as ghost entries.");
994
1001 "To compress a vector, a locally_relevant_dofs "
1002 "index set, and a locally_owned_dofs index set "
1003 "must be provided. These index sets must be "
1004 "provided either when the vector is initialized "
1005 "or when compress is called. See the documentation "
1006 "of compress() for more information.");
1007
1014 int,
1015 << "An error with error number " << arg1
1016 << " occurred while calling a Trilinos function");
1017
1018 private:
1024 void
1025 create_tpetra_comm_pattern(const IndexSet &source_index_set,
1026 const MPI_Comm mpi_comm);
1027
1033
1043
1047 Teuchos::RCP<TpetraTypes::VectorType<Number, MemorySpace>> vector;
1048
1054 Teuchos::RCP<TpetraTypes::VectorType<Number, MemorySpace>>
1056
1061
1066 Teuchos::RCP<const TpetraWrappers::CommunicationPattern<MemorySpace>>
1068
1069 // Make the reference class a friend.
1070 friend class internal::VectorReference<Number, MemorySpace>;
1071 };
1072
1073
1074 /* ------------------------- Inline functions ---------------------- */
1075
1076 template <typename Number, typename MemorySpace>
1077 inline void
1079 Vector<Number, MemorySpace> &v) noexcept
1080 {
1081 u.swap(v);
1082 }
1083
1084
1085 template <typename Number, typename MemorySpace>
1086 inline bool
1088 {
1089 return has_ghost;
1090 }
1091
1092
1093
1094 template <typename Number, typename MemorySpace>
1095 inline bool
1097 {
1098 return compressed;
1099 }
1100
1101 template <typename Number, typename MemorySpace>
1102 inline void
1104 {
1105 vector.swap(v.vector);
1106 }
1107
1108
1109 template <typename Number, typename MemorySpace>
1110 inline void
1111 Vector<Number, MemorySpace>::add(const std::vector<size_type> &indices,
1112 const std::vector<Number> &values)
1113 {
1114 // if we have ghost values, do not allow
1115 // writing to this vector at all.
1116 AssertDimension(indices.size(), values.size());
1117
1118 add(indices.size(), indices.data(), values.data());
1119 }
1120
1121
1122
1123 template <typename Number, typename MemorySpace>
1124 inline void
1126 const size_type *indices,
1127 const Number *values)
1128 {
1129 // if we have ghost values, do not allow
1130 // writing to this vector at all.
1131 Assert(!has_ghost_elements(), ExcGhostsPresent());
1132
1133# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1134 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>(
1135 Tpetra::Access::ReadWrite);
1136# else
1137 vector->template sync<Kokkos::HostSpace>();
1138
1139 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>();
1140# endif
1141
1142 // Having extracted a view into the multivectors above, now also
1143 // extract a view into the one vector we actually store. We can
1144 // do this right away for the locally owned part. We defer creating
1145 // the view into the nonlocal part to when we know that we actually
1146 // need it; this also makes sure that we correctly deal with the
1147 // case where we do not actually store a nonlocal part.
1148 auto vector_1d_local = Kokkos::subview(vector_2d_local, Kokkos::ALL(), 0);
1149 using ViewType1d = decltype(vector_1d_local);
1150 std::optional<ViewType1d> vector_1d_nonlocal;
1151
1152# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1153 // Mark vector as to-be-modified. We may do the same with
1154 // the nonlocal part too if we end up writing into it.
1155 vector->template modify<Kokkos::HostSpace>();
1156# endif
1157
1158 for (size_type i = 0; i < n_elements; ++i)
1159 {
1160 const size_type row = indices[i];
1161
1162 // Check if the index is in the locally owned index set.
1163 // If so, we can write right into the locally owned
1164 // part of the vector.
1165 if (TrilinosWrappers::types::int_type local_row =
1166 vector->getMap()->getLocalElement(row);
1167 local_row != Teuchos::OrdinalTraits<int>::invalid())
1168 {
1169 vector_1d_local(local_row) += values[i];
1170 }
1171 else
1172 {
1173 // If the element was not in the locally owned part,
1174 // we need to figure out whether it is in the nonlocal
1175 // part. It better be:
1176 Assert(nonlocal_vector.get() != nullptr, ExcInternalError());
1178 nonlocal_vector->getMap()->getLocalElement(row);
1179
1180# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1181 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1182 ExcAccessToNonLocalElement(
1183 row,
1184 vector->getMap()->getLocalNumElements(),
1185 vector->getMap()->getMinLocalIndex(),
1186 vector->getMap()->getMaxLocalIndex()));
1187# else
1188 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1189 ExcAccessToNonLocalElement(
1190 row,
1191 vector->getMap()->getNodeNumElements(),
1192 vector->getMap()->getMinLocalIndex(),
1193 vector->getMap()->getMaxLocalIndex()));
1194
1195# endif
1196
1197 // Having asserted that it is, write into the nonlocal part.
1198 // To do so, we first need to make sure that we have a view
1199 // of the nonlocal part of the vectors, since we have
1200 // deferred creating this view previously:
1201 if (!vector_1d_nonlocal)
1202 {
1203# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1204 auto vector_2d_nonlocal =
1205 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1206 Tpetra::Access::ReadWrite);
1207# else
1208 auto vector_2d_nonlocal =
1209 nonlocal_vector->template getLocalView<Kokkos::HostSpace>();
1210# endif
1211
1212 vector_1d_nonlocal =
1213 Kokkos::subview(vector_2d_nonlocal, Kokkos::ALL(), 0);
1214
1215# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1216 // Mark the nonlocal vector as to-be-modified as well.
1217 nonlocal_vector->template modify<Kokkos::HostSpace>();
1218# endif
1219 }
1220 (*vector_1d_nonlocal)(nonlocal_row) += values[i];
1221 compressed = false;
1222 }
1223 }
1224
1225# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1226 vector->template sync<
1227 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1228 device_type::memory_space>();
1229
1230 // If we have created a view to the nonlocal part, then we have also
1231 // written into it. Flush these modifications.
1232 if (vector_1d_nonlocal)
1233 nonlocal_vector->template sync<
1234 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1235 device_type::memory_space>();
1236# endif
1237 }
1238
1239
1240
1241 template <typename Number, typename MemorySpace>
1242 inline void
1244 const size_type *indices,
1245 const Number *values)
1246 {
1247 // if we have ghost values, do not allow
1248 // writing to this vector at all.
1249 Assert(!has_ghost_elements(), ExcGhostsPresent());
1250
1251# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1252 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>(
1253 Tpetra::Access::ReadWrite);
1254# else
1255 vector->template sync<Kokkos::HostSpace>();
1256
1257 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>();
1258# endif
1259
1260 // Having extracted a view into the multivectors above, now also
1261 // extract a view into the one vector we actually store. We can
1262 // do this right away for the locally owned part. We defer creating
1263 // the view into the nonlocal part to when we know that we actually
1264 // need it; this also makes sure that we correctly deal with the
1265 // case where we do not actually store a nonlocal part.
1266 auto vector_1d_local = Kokkos::subview(vector_2d_local, Kokkos::ALL(), 0);
1267 using ViewType1d = decltype(vector_1d_local);
1268 std::optional<ViewType1d> vector_1d_nonlocal;
1269
1270# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1271 // Mark vector as to-be-modified. We may do the same with
1272 // the nonlocal part too if we end up writing into it.
1273 vector->template modify<Kokkos::HostSpace>();
1274# endif
1275
1276 for (size_type i = 0; i < n_elements; ++i)
1277 {
1278 const size_type row = indices[i];
1279
1280 // Check if the index is in the locally owned index set.
1281 // If so, we can write right into the locally owned
1282 // part of the vector.
1283 if (TrilinosWrappers::types::int_type local_row =
1284 vector->getMap()->getLocalElement(row);
1285 local_row != Teuchos::OrdinalTraits<int>::invalid())
1286 {
1287 vector_1d_local(local_row) = values[i];
1288 }
1289 else
1290 {
1291 // If the element was not in the locally owned part,
1292 // we need to figure out whether it is in the nonlocal
1293 // part. It better be:
1294 Assert(nonlocal_vector.get() != nullptr, ExcInternalError());
1296 nonlocal_vector->getMap()->getLocalElement(row);
1297
1298# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1299 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1300 ExcAccessToNonLocalElement(
1301 row,
1302 vector->getMap()->getLocalNumElements(),
1303 vector->getMap()->getMinLocalIndex(),
1304 vector->getMap()->getMaxLocalIndex()));
1305# else
1306 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1307 ExcAccessToNonLocalElement(
1308 row,
1309 vector->getMap()->getNodeNumElements(),
1310 vector->getMap()->getMinLocalIndex(),
1311 vector->getMap()->getMaxLocalIndex()));
1312
1313# endif
1314
1315 // Having asserted that it is, write into the nonlocal part.
1316 // To do so, we first need to make sure that we have a view
1317 // of the nonlocal part of the vectors, since we have
1318 // deferred creating this view previously:
1319 if (!vector_1d_nonlocal)
1320 {
1321# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1322 auto vector_2d_nonlocal =
1323 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1324 Tpetra::Access::ReadWrite);
1325# else
1326 auto vector_2d_nonlocal =
1327 nonlocal_vector->template getLocalView<Kokkos::HostSpace>();
1328# endif
1329
1330 vector_1d_nonlocal =
1331 Kokkos::subview(vector_2d_nonlocal, Kokkos::ALL(), 0);
1332
1333# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1334 // Mark the nonlocal vector as to-be-modified as well.
1335 nonlocal_vector->template modify<Kokkos::HostSpace>();
1336# endif
1337 }
1338 (*vector_1d_nonlocal)(nonlocal_row) = values[i];
1339 compressed = false;
1340 }
1341 }
1342
1343# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1344 vector->template sync<
1345 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1346 device_type::memory_space>();
1347
1348 // If we have created a view to the nonlocal part, then we have also
1349 // written into it. Flush these modifications.
1350 if (vector_1d_nonlocal)
1351 nonlocal_vector->template sync<
1352 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1353 device_type::memory_space>();
1354# endif
1355 }
1356
1357
1358
1359 template <typename Number, typename MemorySpace>
1360 inline internal::VectorReference<Number, MemorySpace>
1362 {
1363 return internal::VectorReference(*this, index);
1364 }
1365
1366 template <typename Number, typename MemorySpace>
1367 inline internal::VectorReference<Number, MemorySpace>
1369 {
1370 return operator()(index);
1371 }
1372
1373 template <typename Number, typename MemorySpace>
1374 inline Number
1376 {
1377 return operator()(index);
1378 }
1379
1380# ifndef DOXYGEN
1381
1382 // VectorReference
1383 namespace internal
1384 {
1385 template <typename Number, typename MemorySpace>
1386 inline VectorReference<Number, MemorySpace>::VectorReference(
1388 const size_type index)
1389 : vector(vector)
1390 , index(index)
1391 {}
1392
1393
1394
1395 template <typename Number, typename MemorySpace>
1396 inline const VectorReference<Number, MemorySpace> &
1397 VectorReference<Number, MemorySpace>::operator=(
1398 const VectorReference<Number, MemorySpace> &r) const
1399 {
1400 // as explained in the class
1401 // documentation, this is not the copy
1402 // operator. so simply pass on to the
1403 // "correct" assignment operator
1404 *this = static_cast<Number>(r);
1405
1406 return *this;
1407 }
1408
1409
1410
1411 template <typename Number, typename MemorySpace>
1412 inline VectorReference<Number, MemorySpace> &
1413 VectorReference<Number, MemorySpace>::operator=(
1414 const VectorReference<Number, MemorySpace> &r)
1415 {
1416 // as above
1417 *this = static_cast<Number>(r);
1418
1419 return *this;
1420 }
1421
1422
1423
1424 template <typename Number, typename MemorySpace>
1425 inline const VectorReference<Number, MemorySpace> &
1426 VectorReference<Number, MemorySpace>::operator=(const Number &value) const
1427 {
1428 vector.set(1, &index, &value);
1429 return *this;
1430 }
1431
1432
1433
1434 template <typename Number, typename MemorySpace>
1435 inline const VectorReference<Number, MemorySpace> &
1436 VectorReference<Number, MemorySpace>::operator+=(
1437 const Number &value) const
1438 {
1439 vector.add(1, &index, &value);
1440 return *this;
1441 }
1442
1443
1444
1445 template <typename Number, typename MemorySpace>
1446 inline const VectorReference<Number, MemorySpace> &
1447 VectorReference<Number, MemorySpace>::operator-=(
1448 const Number &value) const
1449 {
1450 Number new_value = -value;
1451 vector.add(1, &index, &new_value);
1452 return *this;
1453 }
1454
1455
1456
1457 template <typename Number, typename MemorySpace>
1458 inline const VectorReference<Number, MemorySpace> &
1459 VectorReference<Number, MemorySpace>::operator*=(
1460 const Number &value) const
1461 {
1462 Number new_value = static_cast<Number>(*this) * value;
1463 vector.set(1, &index, &new_value);
1464 return *this;
1465 }
1466
1467
1468
1469 template <typename Number, typename MemorySpace>
1470 inline const VectorReference<Number, MemorySpace> &
1471 VectorReference<Number, MemorySpace>::operator/=(
1472 const Number &value) const
1473 {
1474 Number new_value = static_cast<Number>(*this) / value;
1475 vector.set(1, &index, &new_value);
1476 return *this;
1477 }
1478 } // namespace internal
1479
1480# endif /* DOXYGEN */
1481
1482 } // namespace TpetraWrappers
1483
1486} // namespace LinearAlgebra
1487
1488
1489namespace internal
1490{
1491 namespace LinearOperatorImplementation
1492 {
1493 template <typename>
1494 class ReinitHelper;
1495
1500 template <typename Number, typename MemorySpace>
1502 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>>
1503 {
1504 public:
1505 template <typename Matrix>
1506 static void
1508 const Matrix &matrix,
1510 bool omit_zeroing_entries)
1511 {
1512 v.reinit(matrix.locally_owned_range_indices(),
1513 matrix.get_mpi_communicator(),
1514 omit_zeroing_entries);
1515 }
1516
1517 template <typename Matrix>
1518 static void
1520 const Matrix &matrix,
1522 bool omit_zeroing_entries)
1523 {
1524 v.reinit(matrix.locally_owned_domain_indices(),
1525 matrix.get_mpi_communicator(),
1526 omit_zeroing_entries);
1527 }
1528 };
1529
1530 } // namespace LinearOperatorImplementation
1531} /* namespace internal */
1532
1536template <typename Number, typename MemorySpace>
1538 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>> : std::false_type
1539{};
1540
1542
1543#endif
1544
1545#endif
void reinit(const Vector< Number, MemorySpace > &V, const bool omit_zeroing_entries=false)
void equ(const Number a, const Vector< Number, MemorySpace > &V)
Teuchos::RCP< const TpetraWrappers::CommunicationPattern< MemorySpace > > tpetra_comm_pattern
void reinit(const IndexSet &locally_owned_entries, const IndexSet &locally_relevant_or_ghost_entries, const MPI_Comm communicator=MPI_COMM_WORLD, const bool vector_writable=false)
void add(const Number a, const Vector< Number, MemorySpace > &V, const Number b, const Vector< Number, MemorySpace > &W)
Number add_and_dot(const Number a, const Vector< Number, MemorySpace > &V, const Vector< Number, MemorySpace > &W)
TpetraTypes::VectorType< Number, MemorySpace > & trilinos_vector()
void reinit(const IndexSet &parallel_partitioner, const MPI_Comm communicator=MPI_COMM_WORLD, const bool omit_zeroing_entries=false)
Teuchos::RCP< TpetraTypes::VectorType< Number, MemorySpace > > vector
Number operator[](const size_type index) const
bool operator==(const Vector< Number, MemorySpace > &v) const
Vector(const IndexSet &parallel_partitioner, const MPI_Comm communicator)
void scale(const Vector< Number, MemorySpace > &scaling_factors)
void set(const size_type n_elements, const size_type *indices, const Number *values)
void import_elements(const ReadWriteVector< Number > &V, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern)
Vector(const Teuchos::RCP< TpetraTypes::VectorType< Number, MemorySpace > > V)
internal::VectorReference< Number, MemorySpace > reference
reference operator()(const size_type index)
virtual void swap(Vector &v) noexcept
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
virtual void extract_subvector_to(const ArrayView< const types::global_dof_index > &indices, ArrayView< Number > &elements) const override
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
const internal::VectorReference< Number, MemorySpace > const_reference
Number operator*(const Vector< Number, MemorySpace > &V) const
std::size_t memory_consumption() const
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
bool in_local_range(const size_type index) const
Vector(const IndexSet &locally_owned_entries, const IndexSet &ghost_entries, const MPI_Comm communicator, const bool vector_writable=false)
Teuchos::RCP< TpetraTypes::VectorType< Number, MemorySpace > > nonlocal_vector
Teuchos::RCP< TpetraTypes::VectorType< Number, MemorySpace > > trilinos_rcp()
static void reinit_range_vector(const Matrix &matrix, LinearAlgebra::TpetraWrappers::Vector< Number, MemorySpace > &v, bool omit_zeroing_entries)
static void reinit_domain_vector(const Matrix &matrix, LinearAlgebra::TpetraWrappers::Vector< Number, MemorySpace > &v, bool omit_zeroing_entries)
#define DEAL_II_DEPRECATED
Definition config.h:207
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
#define DeclException0(Exception0)
Definition exceptions.h:471
static ::ExceptionBase & ExcGhostsPresent()
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
Definition exceptions.h:585
static ::ExceptionBase & ExcVectorTypeNotCompatible()
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
#define Assert(cond, exc)
static ::ExceptionBase & ExcMissingIndexSet()
#define AssertDimension(dim1, dim2)
#define DeclExceptionMsg(Exception, defaulttext)
Definition exceptions.h:494
static ::ExceptionBase & ExcInternalError()
#define DeclException1(Exception1, type1, outsequence)
Definition exceptions.h:516
static ::ExceptionBase & ExcDifferentParallelPartitioning()
static ::ExceptionBase & ExcTrilinosError(int arg1)
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
void swap(Vector< Number, MemorySpace > &u, Vector< Number, MemorySpace > &v) noexcept
STL namespace.
unsigned int global_dof_index
Definition types.h:81