Reference documentation for deal.II version GIT acb749f4f5 2024-02-21 16:10: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// Copyright (C) 2018 - 2023 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_trilinos_tpetra_vector_h
17#define dealii_trilinos_tpetra_vector_h
18
19
20#include <deal.II/base/config.h>
21
22#ifdef DEAL_II_TRILINOS_WITH_TPETRA
23
27
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 {
113 namespace internal
114 {
119
129 template <typename Number,
131 class VectorReference
132 {
133 private:
138 VectorReference(Vector<Number, MemorySpace> &vector,
139 const size_type index);
140
141 public:
145 VectorReference(const VectorReference &) = default;
146
158 const VectorReference &
159 operator=(const VectorReference &r) const;
160
164 VectorReference &
165 operator=(const VectorReference &r);
166
170 const VectorReference &
171 operator=(const Number &s) const;
172
176 const VectorReference &
177 operator+=(const Number &s) const;
178
182 const VectorReference &
183 operator-=(const Number &s) const;
184
188 const VectorReference &
189 operator*=(const Number &s) const;
190
194 const VectorReference &
195 operator/=(const Number &s) const;
196
201 operator Number() const;
202
206 DeclException1(ExcTrilinosError,
207 int,
208 << "An error with error number " << arg1
209 << " occurred while calling a Trilinos function");
210
211 /*
212 * Access to a an element that is not (locally-)owned.
213 *
214 * @ingroup Exceptions
215 */
217 ExcAccessToNonLocalElement,
218 size_type,
219 size_type,
220 size_type,
221 size_type,
222 << "You are trying to access element " << arg1
223 << " of a distributed vector, but this element is not stored "
224 << "on the current processor. Note: There are " << arg2
225 << " elements stored "
226 << "on the current processor from within the range [" << arg3 << ','
227 << arg4 << "] but Trilinos vectors need not store contiguous "
228 << "ranges on each processor, and not every element in "
229 << "this range may in fact be stored locally."
230 << "\n\n"
231 << "A common source for this kind of problem is that you "
232 << "are passing a 'fully distributed' vector into a function "
233 << "that needs read access to vector elements that correspond "
234 << "to degrees of freedom on ghost cells (or at least to "
235 << "'locally active' degrees of freedom that are not also "
236 << "'locally owned'). You need to pass a vector that has these "
237 << "elements as ghost entries.");
238
239 private:
244
248 const size_type index;
249
250 // Make the vector class a friend, so that it can create objects of the
251 // present type.
252 friend class Vector<Number, MemorySpace>;
253 }; // class VectorReference
254
255 } // namespace internal
272 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
273 class Vector : public ReadVector<Number>, public Subscriptor
274 {
275 public:
279# if DEAL_II_TRILINOS_VERSION_GTE(14, 2, 0)
280 using NodeType = Tpetra::KokkosCompat::KokkosDeviceWrapperNode<
281 typename MemorySpace::kokkos_space::execution_space,
282 typename MemorySpace::kokkos_space>;
283# else
284 using NodeType = Kokkos::Compat::KokkosDeviceWrapperNode<
285 typename MemorySpace::kokkos_space::execution_space,
286 typename MemorySpace::kokkos_space>;
287# endif
288 using value_type = Number;
291 using reference = internal::VectorReference<Number, MemorySpace>;
293 const internal::VectorReference<Number, MemorySpace>;
294 using MapType =
295 Tpetra::Map<int, ::types::signed_global_dof_index, NodeType>;
296 using VectorType = Tpetra::
297 Vector<Number, int, ::types::signed_global_dof_index, NodeType>;
299 Tpetra::Export<int, ::types::signed_global_dof_index, NodeType>;
301 Tpetra::Import<int, ::types::signed_global_dof_index, NodeType>;
302
313
318 Vector(const Vector &V);
319
323 Vector(const Teuchos::RCP<VectorType> V);
324
332 explicit Vector(const IndexSet &parallel_partitioner,
333 const MPI_Comm communicator);
334
349 explicit Vector(const IndexSet &locally_owned_entries,
350 const IndexSet &ghost_entries,
351 const MPI_Comm communicator,
352 const bool vector_writable = false);
353
358 void
360
367 void
368 reinit(const IndexSet &parallel_partitioner,
369 const MPI_Comm communicator = MPI_COMM_WORLD,
370 const bool omit_zeroing_entries = false);
371
386 void
387 reinit(const IndexSet &locally_owned_entries,
388 const IndexSet &locally_relevant_or_ghost_entries,
389 const MPI_Comm communicator = MPI_COMM_WORLD,
390 const bool vector_writable = false);
391
396 void
398 const bool omit_zeroing_entries = false);
399
415 virtual void
417
421 virtual void
424 ArrayView<Number> &elements) const override;
425
431 Vector &
432 operator=(const Vector &V);
433
438 Vector &
439 operator=(const Number s);
440
449 void
452 VectorOperation::values operation,
453 const Teuchos::RCP<const Utilities::MPI::CommunicationPatternBase>
454 &communication_pattern);
455
460 void
463 VectorOperation::values operation,
464 const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
465 &communication_pattern);
466
467 /*
468 * Imports all the elements present in the vector's IndexSet from the
469 * input vector @p V. VectorOperation::values @p operation is used to decide if
470 * the elements in @p V should be added to the current vector or replace the
471 * current elements.
472 */
473 void
475 VectorOperation::values operation);
476
481 void
482 import(const ReadWriteVector<Number> &V,
483 VectorOperation::values operation,
484 std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
485 communication_pattern = {})
486 {
487 import_elements(V, operation, communication_pattern);
488 }
489
506 operator()(const size_type index);
507
515 Number
516 operator()(const size_type index) const;
517
524 operator[](const size_type index);
525
531 Number
532 operator[](const size_type index) const;
533
545 Vector &
546 operator*=(const Number factor);
547
551 Vector &
552 operator/=(const Number factor);
553
557 Vector &
559
563 Vector &
565
570 Number
572
576 void
577 add(const Number a);
578
583 void
584 add(const Number a, const Vector<Number, MemorySpace> &V);
585
590 void
591 add(const Number a,
593 const Number b,
595
600 void
601 add(const std::vector<size_type> &indices,
602 const std::vector<Number> &values);
603
604
610 void
611 add(const size_type n_elements,
612 const size_type *indices,
613 const Number *values);
614
619 void
620 sadd(const Number s,
621 const Number a,
623
630 void
631 set(const size_type n_elements,
632 const size_type *indices,
633 const Number *values);
634
641 void
642 scale(const Vector<Number, MemorySpace> &scaling_factors);
643
647 void
648 equ(const Number a, const Vector<Number, MemorySpace> &V);
649
653 bool
654 all_zero() const;
655
661 bool
663
675 Number
676 mean_value() const;
677
683 l1_norm() const;
684
690 l2_norm() const;
691
697 linfty_norm() const;
698
703 norm_sqr() const;
704
731 Number
732 add_and_dot(const Number a,
735
747 bool
749
755 bool
757
763 bool
765
770 virtual size_type
771 size() const override;
772
779
785 bool
787
793
807
830 void
832
837 const Tpetra::Vector<Number, int, types::signed_global_dof_index> &
839
844 Tpetra::Vector<Number, int, types::signed_global_dof_index> &
846
851 Teuchos::RCP<
852 const Tpetra::Vector<Number, int, types::signed_global_dof_index>>
854
859 Teuchos::RCP<Tpetra::Vector<Number, int, types::signed_global_dof_index>>
861
865 void
866 print(std::ostream &out,
867 const unsigned int precision = 3,
868 const bool scientific = true,
869 const bool across = true) const;
870
874 std::size_t
876
881 mpi_comm() const;
882
893
900
901 /*
902 * Access to a an element that is not (locally-)owned.
903 *
904 * @ingroup Exceptions
905 */
908 size_type,
909 size_type,
910 size_type,
911 size_type,
912 << "You are trying to access element " << arg1
913 << " of a distributed vector, but this element is not stored "
914 << "on the current processor. Note: There are " << arg2
915 << " elements stored "
916 << "on the current processor from within the range [" << arg3 << ','
917 << arg4 << "] but Trilinos vectors need not store contiguous "
918 << "ranges on each processor, and not every element in "
919 << "this range may in fact be stored locally."
920 << "\n\n"
921 << "A common source for this kind of problem is that you "
922 << "are passing a 'fully distributed' vector into a function "
923 << "that needs read access to vector elements that correspond "
924 << "to degrees of freedom on ghost cells (or at least to "
925 << "'locally active' degrees of freedom that are not also "
926 << "'locally owned'). You need to pass a vector that has these "
927 << "elements as ghost entries.");
928
935 "To compress a vector, a locally_relevant_dofs "
936 "index set, and a locally_owned_dofs index set "
937 "must be provided. These index sets must be "
938 "provided either when the vector is initialized "
939 "or when compress is called. See the documentation "
940 "of compress() for more information.");
941
948 int,
949 << "An error with error number " << arg1
950 << " occurred while calling a Trilinos function");
951
952 private:
958 void
959 create_tpetra_comm_pattern(const IndexSet &source_index_set,
960 const MPI_Comm mpi_comm);
961
967
977
981 Teuchos::RCP<VectorType> vector;
982
988 Teuchos::RCP<VectorType> nonlocal_vector;
989
994
999 Teuchos::RCP<const TpetraWrappers::CommunicationPattern>
1001
1002 // Make the reference class a friend.
1003 friend class internal::VectorReference<Number, MemorySpace>;
1004 };
1005
1006
1007 /* ------------------------- Inline functions ---------------------- */
1008
1009 template <typename Number, typename MemorySpace>
1010 inline void
1015
1016
1017 template <typename Number, typename MemorySpace>
1018 inline bool
1020 {
1021 return has_ghost;
1022 }
1023
1024
1025
1026 template <typename Number, typename MemorySpace>
1027 inline bool
1029 {
1030 return compressed;
1031 }
1032
1033 template <typename Number, typename MemorySpace>
1034 inline void
1039
1040
1041 template <typename Number, typename MemorySpace>
1042 inline void
1043 Vector<Number, MemorySpace>::add(const std::vector<size_type> &indices,
1044 const std::vector<Number> &values)
1045 {
1046 // if we have ghost values, do not allow
1047 // writing to this vector at all.
1048 AssertDimension(indices.size(), values.size());
1049
1050 add(indices.size(), indices.data(), values.data());
1051 }
1052
1053
1054
1055 template <typename Number, typename MemorySpace>
1056 inline void
1058 const size_type *indices,
1059 const Number *values)
1060 {
1061 // if we have ghost values, do not allow
1062 // writing to this vector at all.
1063 Assert(!has_ghost_elements(), ExcGhostsPresent());
1064
1065# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1066 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>(
1067 Tpetra::Access::ReadWrite);
1068# else
1069 vector->template sync<Kokkos::HostSpace>();
1070
1071 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>();
1072# endif
1073
1074 // Having extracted a view into the multivectors above, now also
1075 // extract a view into the one vector we actually store. We can
1076 // do this right away for the locally owned part. We defer creating
1077 // the view into the nonlocal part to when we know that we actually
1078 // need it; this also makes sure that we correctly deal with the
1079 // case where we do not actually store a nonlocal part.
1080 auto vector_1d_local = Kokkos::subview(vector_2d_local, Kokkos::ALL(), 0);
1081 using ViewType1d = decltype(vector_1d_local);
1082 std::optional<ViewType1d> vector_1d_nonlocal;
1083
1084# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1085 // Mark vector as to-be-modified. We may do the same with
1086 // the nonlocal part too if we end up writing into it.
1087 vector->template modify<Kokkos::HostSpace>();
1088# endif
1089
1090 for (size_type i = 0; i < n_elements; ++i)
1091 {
1092 const size_type row = indices[i];
1093
1094 // Check if the index is in the locally owned index set.
1095 // If so, we can write right into the locally owned
1096 // part of the vector.
1097 if (TrilinosWrappers::types::int_type local_row =
1098 vector->getMap()->getLocalElement(row);
1099 local_row != Teuchos::OrdinalTraits<int>::invalid())
1100 {
1101 vector_1d_local(local_row) += values[i];
1102 }
1103 else
1104 {
1105 // If the element was not in the locally owned part,
1106 // we need to figure out whether it is in the nonlocal
1107 // part. It better be:
1108 Assert(nonlocal_vector.get() != nullptr, ExcInternalError());
1110 nonlocal_vector->getMap()->getLocalElement(row);
1111
1112# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1113 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1114 ExcAccessToNonLocalElement(
1115 row,
1116 vector->getMap()->getLocalNumElements(),
1117 vector->getMap()->getMinLocalIndex(),
1118 vector->getMap()->getMaxLocalIndex()));
1119# else
1120 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1121 ExcAccessToNonLocalElement(
1122 row,
1123 vector->getMap()->getNodeNumElements(),
1124 vector->getMap()->getMinLocalIndex(),
1125 vector->getMap()->getMaxLocalIndex()));
1126
1127# endif
1128
1129 // Having asserted that it is, write into the nonlocal part.
1130 // To do so, we first need to make sure that we have a view
1131 // of the nonlocal part of the vectors, since we have
1132 // deferred creating this view previously:
1133 if (!vector_1d_nonlocal)
1134 {
1135# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1136 auto vector_2d_nonlocal =
1137 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1138 Tpetra::Access::ReadWrite);
1139# else
1140 auto vector_2d_nonlocal =
1141 nonlocal_vector->template getLocalView<Kokkos::HostSpace>();
1142# endif
1143
1144 vector_1d_nonlocal =
1145 Kokkos::subview(vector_2d_nonlocal, Kokkos::ALL(), 0);
1146
1147# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1148 // Mark the nonlocal vector as to-be-modified as well.
1149 nonlocal_vector->template modify<Kokkos::HostSpace>();
1150# endif
1151 }
1152 (*vector_1d_nonlocal)(nonlocal_row) += values[i];
1153 compressed = false;
1154 }
1155 }
1156
1157# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1158 vector->template sync<
1159 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1160 device_type::memory_space>();
1161
1162 // If we have created a view to the nonlocal part, then we have also
1163 // written into it. Flush these modifications.
1164 if (vector_1d_nonlocal)
1165 nonlocal_vector->template sync<
1166 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1167 device_type::memory_space>();
1168# endif
1169 }
1170
1171
1172
1173 template <typename Number, typename MemorySpace>
1174 inline void
1176 const size_type *indices,
1177 const Number *values)
1178 {
1179 // if we have ghost values, do not allow
1180 // writing to this vector at all.
1181 Assert(!has_ghost_elements(), ExcGhostsPresent());
1182
1183# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1184 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>(
1185 Tpetra::Access::ReadWrite);
1186# else
1187 vector->template sync<Kokkos::HostSpace>();
1188
1189 auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>();
1190# endif
1191
1192 // Having extracted a view into the multivectors above, now also
1193 // extract a view into the one vector we actually store. We can
1194 // do this right away for the locally owned part. We defer creating
1195 // the view into the nonlocal part to when we know that we actually
1196 // need it; this also makes sure that we correctly deal with the
1197 // case where we do not actually store a nonlocal part.
1198 auto vector_1d_local = Kokkos::subview(vector_2d_local, Kokkos::ALL(), 0);
1199 using ViewType1d = decltype(vector_1d_local);
1200 std::optional<ViewType1d> vector_1d_nonlocal;
1201
1202# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1203 // Mark vector as to-be-modified. We may do the same with
1204 // the nonlocal part too if we end up writing into it.
1205 vector->template modify<Kokkos::HostSpace>();
1206# endif
1207
1208 for (size_type i = 0; i < n_elements; ++i)
1209 {
1210 const size_type row = indices[i];
1211
1212 // Check if the index is in the locally owned index set.
1213 // If so, we can write right into the locally owned
1214 // part of the vector.
1215 if (TrilinosWrappers::types::int_type local_row =
1216 vector->getMap()->getLocalElement(row);
1217 local_row != Teuchos::OrdinalTraits<int>::invalid())
1218 {
1219 vector_1d_local(local_row) = values[i];
1220 }
1221 else
1222 {
1223 // If the element was not in the locally owned part,
1224 // we need to figure out whether it is in the nonlocal
1225 // part. It better be:
1226 Assert(nonlocal_vector.get() != nullptr, ExcInternalError());
1228 nonlocal_vector->getMap()->getLocalElement(row);
1229
1230# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1231 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1232 ExcAccessToNonLocalElement(
1233 row,
1234 vector->getMap()->getLocalNumElements(),
1235 vector->getMap()->getMinLocalIndex(),
1236 vector->getMap()->getMaxLocalIndex()));
1237# else
1238 Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
1239 ExcAccessToNonLocalElement(
1240 row,
1241 vector->getMap()->getNodeNumElements(),
1242 vector->getMap()->getMinLocalIndex(),
1243 vector->getMap()->getMaxLocalIndex()));
1244
1245# endif
1246
1247 // Having asserted that it is, write into the nonlocal part.
1248 // To do so, we first need to make sure that we have a view
1249 // of the nonlocal part of the vectors, since we have
1250 // deferred creating this view previously:
1251 if (!vector_1d_nonlocal)
1252 {
1253# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1254 auto vector_2d_nonlocal =
1255 nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
1256 Tpetra::Access::ReadWrite);
1257# else
1258 auto vector_2d_nonlocal =
1259 nonlocal_vector->template getLocalView<Kokkos::HostSpace>();
1260# endif
1261
1262 vector_1d_nonlocal =
1263 Kokkos::subview(vector_2d_nonlocal, Kokkos::ALL(), 0);
1264
1265# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1266 // Mark the nonlocal vector as to-be-modified as well.
1267 nonlocal_vector->template modify<Kokkos::HostSpace>();
1268# endif
1269 }
1270 (*vector_1d_nonlocal)(nonlocal_row) = values[i];
1271 compressed = false;
1272 }
1273 }
1274
1275# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1276 vector->template sync<
1277 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1278 device_type::memory_space>();
1279
1280 // If we have created a view to the nonlocal part, then we have also
1281 // written into it. Flush these modifications.
1282 if (vector_1d_nonlocal)
1283 nonlocal_vector->template sync<
1284 typename Tpetra::Vector<Number, int, types::signed_global_dof_index>::
1285 device_type::memory_space>();
1286# endif
1287 }
1288
1289
1290
1291 template <typename Number, typename MemorySpace>
1292 inline internal::VectorReference<Number, MemorySpace>
1294 {
1295 return internal::VectorReference(*this, index);
1296 }
1297
1298 template <typename Number, typename MemorySpace>
1299 inline internal::VectorReference<Number, MemorySpace>
1301 {
1302 return operator()(index);
1303 }
1304
1305 template <typename Number, typename MemorySpace>
1306 inline Number
1308 {
1309 return operator()(index);
1310 }
1311
1312# ifndef DOXYGEN
1313
1314 // VectorReference
1315 namespace internal
1316 {
1317 template <typename Number, typename MemorySpace>
1318 inline VectorReference<Number, MemorySpace>::VectorReference(
1320 const size_type index)
1321 : vector(vector)
1322 , index(index)
1323 {}
1324
1325
1326
1327 template <typename Number, typename MemorySpace>
1328 inline const VectorReference<Number, MemorySpace> &
1329 VectorReference<Number, MemorySpace>::operator=(
1330 const VectorReference<Number, MemorySpace> &r) const
1331 {
1332 // as explained in the class
1333 // documentation, this is not the copy
1334 // operator. so simply pass on to the
1335 // "correct" assignment operator
1336 *this = static_cast<Number>(r);
1337
1338 return *this;
1339 }
1340
1341
1342
1343 template <typename Number, typename MemorySpace>
1344 inline VectorReference<Number, MemorySpace> &
1345 VectorReference<Number, MemorySpace>::operator=(
1346 const VectorReference<Number, MemorySpace> &r)
1347 {
1348 // as above
1349 *this = static_cast<Number>(r);
1350
1351 return *this;
1352 }
1353
1354
1355
1356 template <typename Number, typename MemorySpace>
1357 inline const VectorReference<Number, MemorySpace> &
1358 VectorReference<Number, MemorySpace>::operator=(const Number &value) const
1359 {
1360 vector.set(1, &index, &value);
1361 return *this;
1362 }
1363
1364
1365
1366 template <typename Number, typename MemorySpace>
1367 inline const VectorReference<Number, MemorySpace> &
1368 VectorReference<Number, MemorySpace>::operator+=(
1369 const Number &value) const
1370 {
1371 vector.add(1, &index, &value);
1372 return *this;
1373 }
1374
1375
1376
1377 template <typename Number, typename MemorySpace>
1378 inline const VectorReference<Number, MemorySpace> &
1379 VectorReference<Number, MemorySpace>::operator-=(
1380 const Number &value) const
1381 {
1382 Number new_value = -value;
1383 vector.add(1, &index, &new_value);
1384 return *this;
1385 }
1386
1387
1388
1389 template <typename Number, typename MemorySpace>
1390 inline const VectorReference<Number, MemorySpace> &
1391 VectorReference<Number, MemorySpace>::operator*=(
1392 const Number &value) const
1393 {
1394 Number new_value = static_cast<Number>(*this) * value;
1395 vector.set(1, &index, &new_value);
1396 return *this;
1397 }
1398
1399
1400
1401 template <typename Number, typename MemorySpace>
1402 inline const VectorReference<Number, MemorySpace> &
1403 VectorReference<Number, MemorySpace>::operator/=(
1404 const Number &value) const
1405 {
1406 Number new_value = static_cast<Number>(*this) / value;
1407 vector.set(1, &index, &new_value);
1408 return *this;
1409 }
1410 } // namespace internal
1411
1412# endif /* DOXYGEN */
1413
1414 } // namespace TpetraWrappers
1415
1418} // namespace LinearAlgebra
1419
1420
1421namespace internal
1422{
1423 namespace LinearOperatorImplementation
1424 {
1425 template <typename>
1426 class ReinitHelper;
1427
1432 template <typename Number, typename MemorySpace>
1434 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>>
1435 {
1436 public:
1437 template <typename Matrix>
1438 static void
1440 const Matrix &matrix,
1442 bool omit_zeroing_entries)
1443 {
1444 v.reinit(matrix.locally_owned_range_indices(),
1445 matrix.get_mpi_communicator(),
1446 omit_zeroing_entries);
1447 }
1448
1449 template <typename Matrix>
1450 static void
1452 const Matrix &matrix,
1454 bool omit_zeroing_entries)
1455 {
1456 v.reinit(matrix.locally_owned_domain_indices(),
1457 matrix.get_mpi_communicator(),
1458 omit_zeroing_entries);
1459 }
1460 };
1461
1462 } // namespace LinearOperatorImplementation
1463} /* namespace internal */
1464
1468template <typename Number, typename MemorySpace>
1470 LinearAlgebra::TpetraWrappers::Vector<Number, MemorySpace>> : std::false_type
1471{};
1472
1474
1475#endif
1476
1477#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)
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
::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
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:208
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
#define DeclException0(Exception0)
Definition exceptions.h:472
static ::ExceptionBase & ExcGhostsPresent()
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
Definition exceptions.h:586
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:495
static ::ExceptionBase & ExcInternalError()
#define DeclException1(Exception1, type1, outsequence)
Definition exceptions.h:517
static ::ExceptionBase & ExcDifferentParallelPartitioning()
static ::ExceptionBase & ExcTrilinosError(int arg1)
types::global_dof_index size_type
void swap(Vector< Number, MemorySpace > &u, Vector< Number, MemorySpace > &v)
STL namespace.
unsigned int global_dof_index
Definition types.h:82