Reference documentation for deal.II version GIT relicensing-750-gcfa4c29382 2024-05-25 07:20:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
trilinos_tpetra_vector.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2018 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_trilinos_tpetra_vector_h
16#define dealii_trilinos_tpetra_vector_h
17
18
19#include <deal.II/base/config.h>
20
21#ifdef DEAL_II_TRILINOS_WITH_TPETRA
22
26
29# include <deal.II/lac/vector.h>
32
33# include <Teuchos_Comm.hpp>
34# include <Teuchos_OrdinalTraits.hpp>
35# include <Tpetra_Core.hpp>
36# include <Tpetra_Vector.hpp>
37# include <Tpetra_Version.hpp>
38
39# include <memory>
40# include <optional>
41
43
49template <typename Number>
50struct is_tpetra_type : std::false_type
51{};
52
53# ifdef HAVE_TPETRA_INST_FLOAT
54template <>
55struct is_tpetra_type<float> : std::true_type
56{};
57# endif
58
59# ifdef HAVE_TPETRA_INST_DOUBLE
60template <>
61struct is_tpetra_type<double> : std::true_type
62{};
63# endif
64
65# ifdef DEAL_II_WITH_COMPLEX_VALUES
66# ifdef HAVE_TPETRA_INST_COMPLEX_FLOAT
67template <>
68struct is_tpetra_type<std::complex<float>> : std::true_type
69{};
70# endif
71
72# ifdef HAVE_TPETRA_INST_COMPLEX_DOUBLE
73template <>
74struct is_tpetra_type<std::complex<double>> : std::true_type
75{};
76# endif
77# endif
78
79namespace LinearAlgebra
80{
81 // Forward declaration
82# ifndef DOXYGEN
83 template <typename Number>
84 class ReadWriteVector;
85# endif
86
101 namespace TpetraWrappers
102 {
108 {
109 public:
111 };
112
123 namespace internal
124 {
128 using size_type = VectorTraits::size_type;
129
139 template <typename Number,
141 class VectorReference
142 {
143 private:
148 VectorReference(Vector<Number, MemorySpace> &vector,
149 const size_type index);
150
151 public:
155 VectorReference(const VectorReference &) = default;
156
168 const VectorReference &
169 operator=(const VectorReference &r) const;
170
174 VectorReference &
175 operator=(const VectorReference &r);
176
180 const VectorReference &
181 operator=(const Number &s) const;
182
186 const VectorReference &
187 operator+=(const Number &s) const;
188
192 const VectorReference &
193 operator-=(const Number &s) const;
194
198 const VectorReference &
199 operator*=(const Number &s) const;
200
204 const VectorReference &
205 operator/=(const Number &s) const;
206
211 operator Number() const;
212
216 DeclException1(ExcTrilinosError,
217 int,
218 << "An error with error number " << arg1
219 << " occurred while calling a Trilinos function");
220
221 /*
222 * Access to a an element that is not (locally-)owned.
223 *
224 * @ingroup Exceptions
225 */
227 ExcAccessToNonLocalElement,
228 size_type,
229 size_type,
230 size_type,
231 size_type,
232 << "You are trying to access element " << arg1
233 << " of a distributed vector, but this element is not stored "
234 << "on the current processor. Note: There are " << arg2
235 << " elements stored "
236 << "on the current processor from within the range [" << arg3 << ','
237 << arg4 << "] but Trilinos vectors need not store contiguous "
238 << "ranges on each processor, and not every element in "
239 << "this range may in fact be stored locally."
240 << "\n\n"
241 << "A common source for this kind of problem is that you "
242 << "are passing a 'fully distributed' vector into a function "
243 << "that needs read access to vector elements that correspond "
244 << "to degrees of freedom on ghost cells (or at least to "
245 << "'locally active' degrees of freedom that are not also "
246 << "'locally owned'). You need to pass a vector that has these "
247 << "elements as ghost entries.");
248
249 private:
254
258 const size_type index;
259
260 // Make the vector class a friend, so that it can create objects of the
261 // present type.
262 friend class Vector<Number, MemorySpace>;
263 }; // class VectorReference
264
265 } // namespace internal
282 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
283 class Vector : public ReadVector<Number>, public Subscriptor
284 {
285 public:
289# if DEAL_II_TRILINOS_VERSION_GTE(14, 2, 0)
290 using NodeType = Tpetra::KokkosCompat::KokkosDeviceWrapperNode<
291 typename MemorySpace::kokkos_space::execution_space,
292 typename MemorySpace::kokkos_space>;
293# else
294 using NodeType = Kokkos::Compat::KokkosDeviceWrapperNode<
295 typename MemorySpace::kokkos_space::execution_space,
296 typename MemorySpace::kokkos_space>;
297# endif
298 using value_type = Number;
301 using reference = internal::VectorReference<Number, MemorySpace>;
303 const internal::VectorReference<Number, MemorySpace>;
304 using MapType =
305 Tpetra::Map<int, ::types::signed_global_dof_index, NodeType>;
306 using VectorType = Tpetra::
307 Vector<Number, int, ::types::signed_global_dof_index, NodeType>;
309 Tpetra::Export<int, ::types::signed_global_dof_index, NodeType>;
311 Tpetra::Import<int, ::types::signed_global_dof_index, NodeType>;
312
323
328 Vector(const Vector &V);
329
333 Vector(const Teuchos::RCP<VectorType> V);
334
342 explicit Vector(const IndexSet &parallel_partitioner,
343 const MPI_Comm communicator);
344
359 explicit Vector(const IndexSet &locally_owned_entries,
360 const IndexSet &ghost_entries,
361 const MPI_Comm communicator,
362 const bool vector_writable = false);
363
368 void
370
377 void
378 reinit(const IndexSet &parallel_partitioner,
379 const MPI_Comm communicator = MPI_COMM_WORLD,
380 const bool omit_zeroing_entries = false);
381
396 void
397 reinit(const IndexSet &locally_owned_entries,
398 const IndexSet &locally_relevant_or_ghost_entries,
399 const MPI_Comm communicator = MPI_COMM_WORLD,
400 const bool vector_writable = false);
401
406 void
408 const bool omit_zeroing_entries = false);
409
425 virtual void
427
431 virtual void
434 ArrayView<Number> &elements) const override;
435
465 Vector &
466 operator=(const Vector &V);
467
473 template <typename OtherNumber>
474 Vector &
475 operator=(const ::Vector<OtherNumber> &V);
476
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
503 void
506 VectorOperation::values operation,
507 const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
508 &communication_pattern);
509
510 /*
511 * Imports all the elements present in the vector's IndexSet from the
512 * input vector @p V. VectorOperation::values @p operation is used to decide if
513 * the elements in @p V should be added to the current vector or replace the
514 * current elements.
515 */
516 void
518 VectorOperation::values operation);
519
524 void
525 import(const ReadWriteVector<Number> &V,
526 VectorOperation::values operation,
527 std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
528 communication_pattern = {})
529 {
530 import_elements(V, operation, communication_pattern);
531 }
532
549 operator()(const size_type index);
550
558 Number
559 operator()(const size_type index) const;
560
567 operator[](const size_type index);
568
574 Number
575 operator[](const size_type index) const;
576
588 Vector &
589 operator*=(const Number factor);
590
594 Vector &
595 operator/=(const Number factor);
596
600 Vector &
602
606 Vector &
608
613 Number
615
619 void
620 add(const Number a);
621
626 void
627 add(const Number a, const Vector<Number, MemorySpace> &V);
628
633 void
634 add(const Number a,
636 const Number b,
638
643 void
644 add(const std::vector<size_type> &indices,
645 const std::vector<Number> &values);
646
647
653 void
654 add(const size_type n_elements,
655 const size_type *indices,
656 const Number *values);
657
662 void
663 sadd(const Number s,
664 const Number a,
666
673 void
674 set(const size_type n_elements,
675 const size_type *indices,
676 const Number *values);
677
684 void
685 scale(const Vector<Number, MemorySpace> &scaling_factors);
686
690 void
691 equ(const Number a, const Vector<Number, MemorySpace> &V);
692
696 bool
697 all_zero() const;
698
704 bool
706
718 Number
719 mean_value() const;
720
726 l1_norm() const;
727
733 l2_norm() const;
734
740 linfty_norm() const;
741
746 norm_sqr() const;
747
774 Number
775 add_and_dot(const Number a,
778
790 bool
792
798 bool
800
806 bool
808
813 virtual size_type
814 size() const override;
815
822
845 std::pair<size_type, size_type>
846 local_range() const;
847
855 bool
856 in_local_range(const size_type index) const;
857
863 bool
865
871
885
908 void
910
915 const Tpetra::Vector<Number, int, types::signed_global_dof_index> &
917
922 Tpetra::Vector<Number, int, types::signed_global_dof_index> &
924
929 Teuchos::RCP<
930 const Tpetra::Vector<Number, int, types::signed_global_dof_index>>
932
937 Teuchos::RCP<Tpetra::Vector<Number, int, types::signed_global_dof_index>>
939
943 void
944 print(std::ostream &out,
945 const unsigned int precision = 3,
946 const bool scientific = true,
947 const bool across = true) const;
948
952 std::size_t
954
959 mpi_comm() const;
960
971
978
979 /*
980 * Access to a an element that is not (locally-)owned.
981 *
982 * @ingroup Exceptions
983 */
986 size_type,
987 size_type,
988 size_type,
989 size_type,
990 << "You are trying to access element " << arg1
991 << " of a distributed vector, but this element is not stored "
992 << "on the current processor. Note: There are " << arg2
993 << " elements stored "
994 << "on the current processor from within the range [" << arg3 << ','
995 << arg4 << "] but Trilinos vectors need not store contiguous "
996 << "ranges on each processor, and not every element in "
997 << "this range may in fact be stored locally."
998 << "\n\n"
999 << "A common source for this kind of problem is that you "
1000 << "are passing a 'fully distributed' vector into a function "
1001 << "that needs read access to vector elements that correspond "
1002 << "to degrees of freedom on ghost cells (or at least to "
1003 << "'locally active' degrees of freedom that are not also "
1004 << "'locally owned'). You need to pass a vector that has these "
1005 << "elements as ghost entries.");
1006
1013 "To compress a vector, a locally_relevant_dofs "
1014 "index set, and a locally_owned_dofs index set "
1015 "must be provided. These index sets must be "
1016 "provided either when the vector is initialized "
1017 "or when compress is called. See the documentation "
1018 "of compress() for more information.");
1019
1026 int,
1027 << "An error with error number " << arg1
1028 << " occurred while calling a Trilinos function");
1029
1030 private:
1036 void
1037 create_tpetra_comm_pattern(const IndexSet &source_index_set,
1038 const MPI_Comm mpi_comm);
1039
1045
1055
1059 Teuchos::RCP<VectorType> vector;
1060
1066 Teuchos::RCP<VectorType> nonlocal_vector;
1067
1072
1077 Teuchos::RCP<const TpetraWrappers::CommunicationPattern>
1079
1080 // Make the reference class a friend.
1081 friend class internal::VectorReference<Number, MemorySpace>;
1082 };
1083
1084
1085 /* ------------------------- Inline functions ---------------------- */
1086
1087 template <typename Number, typename MemorySpace>
1088 inline void
1093
1094
1095 template <typename Number, typename MemorySpace>
1096 inline bool
1098 {
1099 return has_ghost;
1100 }
1101
1102
1103
1104 template <typename Number, typename MemorySpace>
1105 inline bool
1107 {
1108 return compressed;
1109 }
1110
1111 template <typename Number, typename MemorySpace>
1112 inline void
1117
1118
1119 template <typename Number, typename MemorySpace>
1120 inline void
1121 Vector<Number, MemorySpace>::add(const std::vector<size_type> &indices,
1122 const std::vector<Number> &values)
1123 {
1124 // if we have ghost values, do not allow
1125 // writing to this vector at all.
1126 AssertDimension(indices.size(), values.size());
1127
1128 add(indices.size(), indices.data(), values.data());
1129 }
1130
1131
1132
1133 template <typename Number, typename MemorySpace>
1134 inline void
1136 const size_type *indices,
1137 const Number *values)
1138 {
1139 // if we have ghost values, do not allow
1140 // writing to this vector at all.
1141 Assert(!has_ghost_elements(), ExcGhostsPresent());
1142
1143# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1144 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>(
1145 Tpetra::Access::ReadWrite);
1146# else
1147 vector->template sync<Kokkos::HostSpace>();
1148
1149 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>();
1150# endif
1151
1152 // Having extracted a view into the multivectors above, now also
1153 // extract a view into the one vector we actually store. We can
1154 // do this right away for the locally owned part. We defer creating
1155 // the view into the nonlocal part to when we know that we actually
1156 // need it; this also makes sure that we correctly deal with the
1157 // case where we do not actually store a nonlocal part.
1158 auto vector_1d_local = Kokkos::subview(vector_2d_local, Kokkos::ALL(), 0);
1159 using ViewType1d = decltype(vector_1d_local);
1160 std::optional<ViewType1d> vector_1d_nonlocal;
1161
1162# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1163 // Mark vector as to-be-modified. We may do the same with
1164 // the nonlocal part too if we end up writing into it.
1165 vector->template modify<Kokkos::HostSpace>();
1166# endif
1167
1168 for (size_type i = 0; i < n_elements; ++i)
1169 {
1170 const size_type row = indices[i];
1171
1172 // Check if the index is in the locally owned index set.
1173 // If so, we can write right into the locally owned
1174 // part of the vector.
1175 if (TrilinosWrappers::types::int_type local_row =
1176 vector->getMap()->getLocalElement(row);
1177 local_row != Teuchos::OrdinalTraits<int>::invalid())
1178 {
1179 vector_1d_local(local_row) += values[i];
1180 }
1181 else
1182 {
1183 // If the element was not in the locally owned part,
1184 // we need to figure out whether it is in the nonlocal
1185 // part. It better be:
1186 Assert(nonlocal_vector.get() != nullptr, ExcInternalError());
1188 nonlocal_vector->getMap()->getLocalElement(row);
1189
1190# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1191 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1192 ExcAccessToNonLocalElement(
1193 row,
1194 vector->getMap()->getLocalNumElements(),
1195 vector->getMap()->getMinLocalIndex(),
1196 vector->getMap()->getMaxLocalIndex()));
1197# else
1198 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1199 ExcAccessToNonLocalElement(
1200 row,
1201 vector->getMap()->getNodeNumElements(),
1202 vector->getMap()->getMinLocalIndex(),
1203 vector->getMap()->getMaxLocalIndex()));
1204
1205# endif
1206
1207 // Having asserted that it is, write into the nonlocal part.
1208 // To do so, we first need to make sure that we have a view
1209 // of the nonlocal part of the vectors, since we have
1210 // deferred creating this view previously:
1211 if (!vector_1d_nonlocal)
1212 {
1213# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1214 auto vector_2d_nonlocal =
1215 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1216 Tpetra::Access::ReadWrite);
1217# else
1218 auto vector_2d_nonlocal =
1219 nonlocal_vector->template getLocalView<Kokkos::HostSpace>();
1220# endif
1221
1222 vector_1d_nonlocal =
1223 Kokkos::subview(vector_2d_nonlocal, Kokkos::ALL(), 0);
1224
1225# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1226 // Mark the nonlocal vector as to-be-modified as well.
1227 nonlocal_vector->template modify<Kokkos::HostSpace>();
1228# endif
1229 }
1230 (*vector_1d_nonlocal)(nonlocal_row) += values[i];
1231 compressed = false;
1232 }
1233 }
1234
1235# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1236 vector->template sync<
1237 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1238 device_type::memory_space>();
1239
1240 // If we have created a view to the nonlocal part, then we have also
1241 // written into it. Flush these modifications.
1242 if (vector_1d_nonlocal)
1243 nonlocal_vector->template sync<
1244 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1245 device_type::memory_space>();
1246# endif
1247 }
1248
1249
1250
1251 template <typename Number, typename MemorySpace>
1252 inline void
1254 const size_type *indices,
1255 const Number *values)
1256 {
1257 // if we have ghost values, do not allow
1258 // writing to this vector at all.
1259 Assert(!has_ghost_elements(), ExcGhostsPresent());
1260
1261# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1262 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>(
1263 Tpetra::Access::ReadWrite);
1264# else
1265 vector->template sync<Kokkos::HostSpace>();
1266
1267 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>();
1268# endif
1269
1270 // Having extracted a view into the multivectors above, now also
1271 // extract a view into the one vector we actually store. We can
1272 // do this right away for the locally owned part. We defer creating
1273 // the view into the nonlocal part to when we know that we actually
1274 // need it; this also makes sure that we correctly deal with the
1275 // case where we do not actually store a nonlocal part.
1276 auto vector_1d_local = Kokkos::subview(vector_2d_local, Kokkos::ALL(), 0);
1277 using ViewType1d = decltype(vector_1d_local);
1278 std::optional<ViewType1d> vector_1d_nonlocal;
1279
1280# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1281 // Mark vector as to-be-modified. We may do the same with
1282 // the nonlocal part too if we end up writing into it.
1283 vector->template modify<Kokkos::HostSpace>();
1284# endif
1285
1286 for (size_type i = 0; i < n_elements; ++i)
1287 {
1288 const size_type row = indices[i];
1289
1290 // Check if the index is in the locally owned index set.
1291 // If so, we can write right into the locally owned
1292 // part of the vector.
1293 if (TrilinosWrappers::types::int_type local_row =
1294 vector->getMap()->getLocalElement(row);
1295 local_row != Teuchos::OrdinalTraits<int>::invalid())
1296 {
1297 vector_1d_local(local_row) = values[i];
1298 }
1299 else
1300 {
1301 // If the element was not in the locally owned part,
1302 // we need to figure out whether it is in the nonlocal
1303 // part. It better be:
1304 Assert(nonlocal_vector.get() != nullptr, ExcInternalError());
1306 nonlocal_vector->getMap()->getLocalElement(row);
1307
1308# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1309 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1310 ExcAccessToNonLocalElement(
1311 row,
1312 vector->getMap()->getLocalNumElements(),
1313 vector->getMap()->getMinLocalIndex(),
1314 vector->getMap()->getMaxLocalIndex()));
1315# else
1316 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1317 ExcAccessToNonLocalElement(
1318 row,
1319 vector->getMap()->getNodeNumElements(),
1320 vector->getMap()->getMinLocalIndex(),
1321 vector->getMap()->getMaxLocalIndex()));
1322
1323# endif
1324
1325 // Having asserted that it is, write into the nonlocal part.
1326 // To do so, we first need to make sure that we have a view
1327 // of the nonlocal part of the vectors, since we have
1328 // deferred creating this view previously:
1329 if (!vector_1d_nonlocal)
1330 {
1331# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1332 auto vector_2d_nonlocal =
1333 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1334 Tpetra::Access::ReadWrite);
1335# else
1336 auto vector_2d_nonlocal =
1337 nonlocal_vector->template getLocalView<Kokkos::HostSpace>();
1338# endif
1339
1340 vector_1d_nonlocal =
1341 Kokkos::subview(vector_2d_nonlocal, Kokkos::ALL(), 0);
1342
1343# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1344 // Mark the nonlocal vector as to-be-modified as well.
1345 nonlocal_vector->template modify<Kokkos::HostSpace>();
1346# endif
1347 }
1348 (*vector_1d_nonlocal)(nonlocal_row) = values[i];
1349 compressed = false;
1350 }
1351 }
1352
1353# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1354 vector->template sync<
1355 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1356 device_type::memory_space>();
1357
1358 // If we have created a view to the nonlocal part, then we have also
1359 // written into it. Flush these modifications.
1360 if (vector_1d_nonlocal)
1361 nonlocal_vector->template sync<
1362 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1363 device_type::memory_space>();
1364# endif
1365 }
1366
1367
1368
1369 template <typename Number, typename MemorySpace>
1370 inline internal::VectorReference<Number, MemorySpace>
1372 {
1373 return internal::VectorReference(*this, index);
1374 }
1375
1376 template <typename Number, typename MemorySpace>
1377 inline internal::VectorReference<Number, MemorySpace>
1379 {
1380 return operator()(index);
1381 }
1382
1383 template <typename Number, typename MemorySpace>
1384 inline Number
1386 {
1387 return operator()(index);
1388 }
1389
1390# ifndef DOXYGEN
1391
1392 // VectorReference
1393 namespace internal
1394 {
1395 template <typename Number, typename MemorySpace>
1396 inline VectorReference<Number, MemorySpace>::VectorReference(
1398 const size_type index)
1399 : vector(vector)
1400 , index(index)
1401 {}
1402
1403
1404
1405 template <typename Number, typename MemorySpace>
1406 inline const VectorReference<Number, MemorySpace> &
1407 VectorReference<Number, MemorySpace>::operator=(
1408 const VectorReference<Number, MemorySpace> &r) const
1409 {
1410 // as explained in the class
1411 // documentation, this is not the copy
1412 // operator. so simply pass on to the
1413 // "correct" assignment operator
1414 *this = static_cast<Number>(r);
1415
1416 return *this;
1417 }
1418
1419
1420
1421 template <typename Number, typename MemorySpace>
1422 inline VectorReference<Number, MemorySpace> &
1423 VectorReference<Number, MemorySpace>::operator=(
1424 const VectorReference<Number, MemorySpace> &r)
1425 {
1426 // as above
1427 *this = static_cast<Number>(r);
1428
1429 return *this;
1430 }
1431
1432
1433
1434 template <typename Number, typename MemorySpace>
1435 inline const VectorReference<Number, MemorySpace> &
1436 VectorReference<Number, MemorySpace>::operator=(const Number &value) const
1437 {
1438 vector.set(1, &index, &value);
1439 return *this;
1440 }
1441
1442
1443
1444 template <typename Number, typename MemorySpace>
1445 inline const VectorReference<Number, MemorySpace> &
1446 VectorReference<Number, MemorySpace>::operator+=(
1447 const Number &value) const
1448 {
1449 vector.add(1, &index, &value);
1450 return *this;
1451 }
1452
1453
1454
1455 template <typename Number, typename MemorySpace>
1456 inline const VectorReference<Number, MemorySpace> &
1457 VectorReference<Number, MemorySpace>::operator-=(
1458 const Number &value) const
1459 {
1460 Number new_value = -value;
1461 vector.add(1, &index, &new_value);
1462 return *this;
1463 }
1464
1465
1466
1467 template <typename Number, typename MemorySpace>
1468 inline const VectorReference<Number, MemorySpace> &
1469 VectorReference<Number, MemorySpace>::operator*=(
1470 const Number &value) const
1471 {
1472 Number new_value = static_cast<Number>(*this) * value;
1473 vector.set(1, &index, &new_value);
1474 return *this;
1475 }
1476
1477
1478
1479 template <typename Number, typename MemorySpace>
1480 inline const VectorReference<Number, MemorySpace> &
1481 VectorReference<Number, MemorySpace>::operator/=(
1482 const Number &value) const
1483 {
1484 Number new_value = static_cast<Number>(*this) / value;
1485 vector.set(1, &index, &new_value);
1486 return *this;
1487 }
1488 } // namespace internal
1489
1490# endif /* DOXYGEN */
1491
1492 } // namespace TpetraWrappers
1493
1496} // namespace LinearAlgebra
1497
1498
1499namespace internal
1500{
1501 namespace LinearOperatorImplementation
1502 {
1503 template <typename>
1504 class ReinitHelper;
1505
1510 template <typename Number, typename MemorySpace>
1512 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>>
1513 {
1514 public:
1515 template <typename Matrix>
1516 static void
1518 const Matrix &matrix,
1520 bool omit_zeroing_entries)
1521 {
1522 v.reinit(matrix.locally_owned_range_indices(),
1523 matrix.get_mpi_communicator(),
1524 omit_zeroing_entries);
1525 }
1526
1527 template <typename Matrix>
1528 static void
1530 const Matrix &matrix,
1532 bool omit_zeroing_entries)
1533 {
1534 v.reinit(matrix.locally_owned_domain_indices(),
1535 matrix.get_mpi_communicator(),
1536 omit_zeroing_entries);
1537 }
1538 };
1539
1540 } // namespace LinearOperatorImplementation
1541} /* namespace internal */
1542
1546template <typename Number, typename MemorySpace>
1548 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>> : std::false_type
1549{};
1550
1552
1553#endif
1554
1555#endif
void reinit(const Vector< Number, MemorySpace > &V, const bool omit_zeroing_entries=false)
void equ(const Number a, const Vector< Number, MemorySpace > &V)
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)
void reinit(const IndexSet &parallel_partitioner, const MPI_Comm communicator=MPI_COMM_WORLD, const bool omit_zeroing_entries=false)
Tpetra::Export< int, ::types::signed_global_dof_index, NodeType > ExportType
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)
Teuchos::RCP< Tpetra::Vector< Number, int, types::signed_global_dof_index > > trilinos_rcp()
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)
internal::VectorReference< Number, MemorySpace > reference
reference operator()(const size_type index)
Tpetra::Import< int, ::types::signed_global_dof_index, NodeType > ImportType
Teuchos::RCP< const Tpetra::Vector< Number, int, types::signed_global_dof_index > > trilinos_rcp() const
const internal::VectorReference< Number, MemorySpace > const_reference
Teuchos::RCP< const TpetraWrappers::CommunicationPattern > tpetra_comm_pattern
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)
const Tpetra::Vector< Number, int, types::signed_global_dof_index > & trilinos_vector() const
Vector & operator=(const ::Vector< OtherNumber > &V)
::IndexSet locally_owned_elements() const
Tpetra::Vector< Number, int, ::types::signed_global_dof_index, NodeType > VectorType
Vector & operator=(const Vector &V)
Vector & operator=(const Number s)
Vector & operator+=(const Vector< Number, MemorySpace > &V)
virtual size_type size() const override
void import_elements(const ReadWriteVector< Number > &V, VectorOperation::values operation)
Tpetra::Vector< Number, int, types::signed_global_dof_index > & trilinos_vector()
void create_tpetra_comm_pattern(const IndexSet &source_index_set, const MPI_Comm mpi_comm)
Vector(const Teuchos::RCP< VectorType > V)
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
Tpetra::Map< int, ::types::signed_global_dof_index, NodeType > MapType
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)
Tpetra::KokkosCompat::KokkosDeviceWrapperNode< typename MemorySpace::kokkos_space::execution_space, typename MemorySpace::kokkos_space > NodeType
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:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
#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)
void swap(Vector< Number, MemorySpace > &u, Vector< Number, MemorySpace > &v)
STL namespace.
unsigned int global_dof_index
Definition types.h:81