deal.II version GIT relicensing-6809-ge913b9bb34 2026-09-25 17:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
petsc_vector_base.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) 2004 - 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_petsc_vector_base_h
14#define dealii_petsc_vector_base_h
15
16
17#include <deal.II/base/config.h>
18
19#ifdef DEAL_II_WITH_PETSC
20
22
24# include <deal.II/lac/vector.h>
26
27# include <boost/serialization/split_member.hpp>
28# include <boost/serialization/utility.hpp>
29
30# include <petscvec.h>
31
32# include <utility>
33# include <vector>
34
35#endif // DEAL_II_WITH_PETSC
36
38
39#ifdef DEAL_II_WITH_PETSC
40// forward declaration
41# ifndef DOXYGEN
42template <typename number>
43class Vector;
44
45namespace PETScWrappers
46{
47 class VectorBase;
48}
49# endif
50
57namespace PETScWrappers
58{
68 namespace internal
69 {
82 class VectorReference
83 {
84 public:
89
90 private:
95 VectorReference(const VectorBase &vector, const size_type index);
96
97 public:
98 /*
99 * Copy constructor.
100 */
101 VectorReference(const VectorReference &vector) = default;
102
114 const VectorReference &
115 operator=(const VectorReference &r) const;
116
122 VectorReference &
123 operator=(const VectorReference &r);
124
128 const VectorReference &
129 operator=(const PetscScalar &s) const;
130
134 const VectorReference &
135 operator+=(const PetscScalar &s) const;
136
140 const VectorReference &
141 operator-=(const PetscScalar &s) const;
142
146 const VectorReference &
147 operator*=(const PetscScalar &s) const;
148
152 const VectorReference &
153 operator/=(const PetscScalar &s) const;
154
158 PetscReal
159 real() const;
160
167 PetscReal
168 imag() const;
169
174 operator PetscScalar() const;
179 ExcAccessToNonlocalElement,
180 int,
181 int,
182 int,
183 << "You tried to access element " << arg1
184 << " of a distributed vector, but only elements in range [" << arg2
185 << ',' << arg3 << "] are stored locally and can be accessed."
186 << "\n\n"
187 << "A common source for this kind of problem is that you "
188 << "are passing a 'fully distributed' vector into a function "
189 << "that needs read access to vector elements that correspond "
190 << "to degrees of freedom on ghost cells (or at least to "
191 << "'locally active' degrees of freedom that are not also "
192 << "'locally owned'). You need to pass a vector that has these "
193 << "elements as ghost entries.");
197 DeclException2(ExcWrongMode,
198 int,
199 int,
200 << "You tried to do a "
201 << (arg1 == 1 ? "'set'" : (arg1 == 2 ? "'add'" : "???"))
202 << " operation but the vector is currently in "
203 << (arg2 == 1 ? "'set'" : (arg2 == 2 ? "'add'" : "???"))
204 << " mode. You first have to call 'compress()'.");
205
206 private:
210 const VectorBase &vector;
211
215 const size_type index;
216
217 // Make the vector class a friend, so that it can create objects of the
218 // present type.
219 friend class ::PETScWrappers::VectorBase;
220 };
221 } // namespace internal
252 class VectorBase : public ReadVector<PetscScalar>
253 {
254 public:
260 using value_type = PetscScalar;
261 using real_type = PetscReal;
265
270 VectorBase();
271
276 VectorBase(const VectorBase &v);
277
282 explicit VectorBase(const Vec &v);
283
287 virtual ~VectorBase() override;
288
293 virtual void
294 clear();
295
306 void
307 compress(const VectorOperation::values operation);
308
312 VectorBase &
313 operator=(const VectorBase &);
314
335 VectorBase &
336 operator=(const PetscScalar s);
337
344 void
345 reinit(Vec v);
346
352 bool
353 operator==(const VectorBase &v) const;
354
360 bool
361 operator!=(const VectorBase &v) const;
362
367 size() const override;
368
378 locally_owned_size() const;
379
388 std::pair<size_type, size_type>
389 local_range() const;
390
395 bool
396 in_local_range(const size_type index) const;
397
413
420 bool
422
426 const IndexSet &
428
432 void
434
439 operator()(const size_type index);
440
444 PetscScalar
445 operator()(const size_type index) const;
446
453 operator[](const size_type index);
454
460 PetscScalar
461 operator[](const size_type index) const;
462
469 void
470 set(const std::vector<size_type> &indices,
471 const std::vector<PetscScalar> &values);
472
488 void
489 extract_subvector_to(const std::vector<size_type> &indices,
490 std::vector<PetscScalar> &values) const;
491
495 virtual void
498 const ArrayView<PetscScalar> &elements) const override;
499
527 template <typename ForwardIterator, typename OutputIterator>
528 void
529 extract_subvector_to(const ForwardIterator indices_begin,
530 const ForwardIterator indices_end,
531 OutputIterator values_begin) const;
532
537 void
538 add(const std::vector<size_type> &indices,
539 const std::vector<PetscScalar> &values);
540
545 void
546 add(const std::vector<size_type> &indices,
547 const ::Vector<PetscScalar> &values);
548
554 void
555 add(const size_type n_elements,
556 const size_type *indices,
557 const PetscScalar *values);
558
565 PetscScalar
566 operator*(const VectorBase &vec) const;
567
572 norm_sqr() const;
573
577 PetscScalar
578 mean_value() const;
579
588 l1_norm() const;
589
595 l2_norm() const;
596
602 lp_norm(const real_type p) const;
603
609 linfty_norm() const;
610
630 PetscScalar
631 add_and_dot(const PetscScalar a, const VectorBase &V, const VectorBase &W);
632
638 bool
639 all_zero() const;
640
644 VectorBase &
645 operator*=(const PetscScalar factor);
646
650 VectorBase &
651 operator/=(const PetscScalar factor);
652
656 VectorBase &
657 operator+=(const VectorBase &V);
658
662 VectorBase &
663 operator-=(const VectorBase &V);
664
669 void
670 add(const PetscScalar s);
671
675 void
676 add(const PetscScalar a, const VectorBase &V);
677
681 void
682 add(const PetscScalar a,
683 const VectorBase &V,
684 const PetscScalar b,
685 const VectorBase &W);
686
690 void
691 sadd(const PetscScalar s, const VectorBase &V);
692
696 void
697 sadd(const PetscScalar s, const PetscScalar a, const VectorBase &V);
698
704 void
705 scale(const VectorBase &scaling_factors);
706
710 void
711 equ(const PetscScalar a, const VectorBase &V);
712
720 void
721 write_ascii(const PetscViewerFormat format = PETSC_VIEWER_DEFAULT);
722
730 void
731 print(std::ostream &out,
732 const unsigned int precision = 3,
733 const bool scientific = true,
734 const bool across = true) const;
735
743 template <class Archive>
744 void
745 save(Archive &ar, const unsigned int version) const;
746
752 template <class Archive>
753 void
754 load(Archive &ar, const unsigned int version);
755
756# ifdef DOXYGEN
762 template <class Archive>
763 void
764 serialize(Archive &archive, const unsigned int version);
765# else
766 // This macro defines the serialize() method that is compatible with
767 // the templated save() and load() method that have been implemented.
768 BOOST_SERIALIZATION_SPLIT_MEMBER()
769# endif
770
783 void
784 swap(VectorBase &v) noexcept;
785
793 operator const Vec &() const;
794
800 Vec &
801 petsc_vector();
802
806 std::size_t
807 memory_consumption() const;
808
814
815 protected:
821
828
835
842
843 // Make the reference class a friend.
845
851 void
852 do_set_add_operation(const size_type n_elements,
853 const size_type *indices,
854 const PetscScalar *values,
855 const bool add_values);
856
860 void
862
868
873 const PetscScalar *ghost_vector_array;
874
878 void
880
884 void
886 };
887
888
889
890 // ------------------- inline and template functions --------------
891
899 inline void
900 swap(VectorBase &u, VectorBase &v) noexcept
901 {
902 u.swap(v);
903 }
904
905# ifndef DOXYGEN
906 namespace internal
907 {
908 inline VectorReference::VectorReference(const VectorBase &vector,
909 const size_type index)
910 : vector(vector)
911 , index(index)
912 {}
913
914
915 inline const VectorReference &
916 VectorReference::operator=(const VectorReference &r) const
917 {
918 // as explained in the class
919 // documentation, this is not the copy
920 // operator. so simply pass on to the
921 // "correct" assignment operator
922 *this = static_cast<PetscScalar>(r);
923
924 return *this;
925 }
926
927
928
929 inline VectorReference &
930 VectorReference::operator=(const VectorReference &r)
931 {
932 // as explained in the class
933 // documentation, this is not the copy
934 // operator. so simply pass on to the
935 // "correct" assignment operator
936 *this = static_cast<PetscScalar>(r);
937
938 return *this;
939 }
940
941
942
943 inline const VectorReference &
944 VectorReference::operator=(const PetscScalar &value) const
945 {
946 Assert((vector.last_action == VectorOperation::insert) ||
947 (vector.last_action == VectorOperation::unknown),
948 ExcWrongMode(VectorOperation::insert, vector.last_action));
949
950 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
951
952 const PetscInt petsc_i = index;
953
954 const PetscErrorCode ierr =
955 VecSetValues(vector, 1, &petsc_i, &value, INSERT_VALUES);
956 AssertThrow(ierr == 0, ExcPETScError(ierr));
957
958 vector.last_action = VectorOperation::insert;
959
960 return *this;
961 }
962
963
964
965 inline const VectorReference &
966 VectorReference::operator+=(const PetscScalar &value) const
967 {
968 Assert((vector.last_action == VectorOperation::add) ||
969 (vector.last_action == VectorOperation::unknown),
970 ExcWrongMode(VectorOperation::add, vector.last_action));
971
972 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
973
974 vector.last_action = VectorOperation::add;
975
976 // we have to do above actions in any
977 // case to be consistent with the MPI
978 // communication model (see the
979 // comments in the documentation of
980 // PETScWrappers::MPI::Vector), but we
981 // can save some work if the addend is
982 // zero
983 if (value == PetscScalar())
984 return *this;
985
986 // use the PETSc function to add something
987 const PetscInt petsc_i = index;
988 const PetscErrorCode ierr =
989 VecSetValues(vector, 1, &petsc_i, &value, ADD_VALUES);
990 AssertThrow(ierr == 0, ExcPETScError(ierr));
991
992
993 return *this;
994 }
995
996
997
998 inline const VectorReference &
999 VectorReference::operator-=(const PetscScalar &value) const
1000 {
1001 Assert((vector.last_action == VectorOperation::add) ||
1002 (vector.last_action == VectorOperation::unknown),
1003 ExcWrongMode(VectorOperation::add, vector.last_action));
1004
1005 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
1006
1007 vector.last_action = VectorOperation::add;
1008
1009 // we have to do above actions in any
1010 // case to be consistent with the MPI
1011 // communication model (see the
1012 // comments in the documentation of
1013 // PETScWrappers::MPI::Vector), but we
1014 // can save some work if the addend is
1015 // zero
1016 if (value == PetscScalar())
1017 return *this;
1018
1019 // use the PETSc function to
1020 // add something
1021 const PetscInt petsc_i = index;
1022 const PetscScalar subtractand = -value;
1023 const PetscErrorCode ierr =
1024 VecSetValues(vector, 1, &petsc_i, &subtractand, ADD_VALUES);
1025 AssertThrow(ierr == 0, ExcPETScError(ierr));
1026
1027 return *this;
1028 }
1029
1030
1031
1032 inline const VectorReference &
1033 VectorReference::operator*=(const PetscScalar &value) const
1034 {
1035 Assert((vector.last_action == VectorOperation::insert) ||
1036 (vector.last_action == VectorOperation::unknown),
1037 ExcWrongMode(VectorOperation::insert, vector.last_action));
1038
1039 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
1040
1041 vector.last_action = VectorOperation::insert;
1042
1043 // we have to do above actions in any
1044 // case to be consistent with the MPI
1045 // communication model (see the
1046 // comments in the documentation of
1047 // PETScWrappers::MPI::Vector), but we
1048 // can save some work if the factor is
1049 // one
1050 if (value == 1.)
1051 return *this;
1052
1053 const PetscInt petsc_i = index;
1054 const PetscScalar new_value = static_cast<PetscScalar>(*this) * value;
1055
1056 const PetscErrorCode ierr =
1057 VecSetValues(vector, 1, &petsc_i, &new_value, INSERT_VALUES);
1058 AssertThrow(ierr == 0, ExcPETScError(ierr));
1059
1060 return *this;
1061 }
1062
1063
1064
1065 inline const VectorReference &
1066 VectorReference::operator/=(const PetscScalar &value) const
1067 {
1068 Assert((vector.last_action == VectorOperation::insert) ||
1069 (vector.last_action == VectorOperation::unknown),
1070 ExcWrongMode(VectorOperation::insert, vector.last_action));
1071
1072 Assert(!vector.has_ghost_elements(), ExcGhostsPresent());
1073
1074 vector.last_action = VectorOperation::insert;
1075
1076 // we have to do above actions in any
1077 // case to be consistent with the MPI
1078 // communication model (see the
1079 // comments in the documentation of
1080 // PETScWrappers::MPI::Vector), but we
1081 // can save some work if the factor is
1082 // one
1083 if (value == 1.)
1084 return *this;
1085
1086 const PetscInt petsc_i = index;
1087 const PetscScalar new_value = static_cast<PetscScalar>(*this) / value;
1088
1089 const PetscErrorCode ierr =
1090 VecSetValues(vector, 1, &petsc_i, &new_value, INSERT_VALUES);
1091 AssertThrow(ierr == 0, ExcPETScError(ierr));
1092
1093 return *this;
1094 }
1095
1096
1097
1098 inline PetscReal
1099 VectorReference::real() const
1100 {
1101# ifndef PETSC_USE_COMPLEX
1102 return static_cast<PetscScalar>(*this);
1103# else
1104 return PetscRealPart(static_cast<PetscScalar>(*this));
1105# endif
1106 }
1107
1108
1109
1110 inline PetscReal
1111 VectorReference::imag() const
1112 {
1113# ifndef PETSC_USE_COMPLEX
1114 return PetscReal(0);
1115# else
1116 return PetscImaginaryPart(static_cast<PetscScalar>(*this));
1117# endif
1118 }
1119
1120 } // namespace internal
1121
1122 inline bool
1123 VectorBase::in_local_range(const size_type index) const
1124 {
1125 PetscInt begin, end;
1126 const PetscErrorCode ierr =
1127 VecGetOwnershipRange(static_cast<const Vec &>(vector), &begin, &end);
1128 AssertThrow(ierr == 0, ExcPETScError(ierr));
1129
1130 return ((index >= static_cast<size_type>(begin)) &&
1131 (index < static_cast<size_type>(end)));
1132 }
1133
1134
1135 inline IndexSet
1136 VectorBase::locally_owned_elements() const
1137 {
1138 IndexSet is(size());
1139
1140 // PETSc only allows for contiguous local ranges, so this is simple
1141 const std::pair<size_type, size_type> x = local_range();
1142 is.add_range(x.first, x.second);
1143 return is;
1144 }
1145
1146
1147
1148 inline bool
1149 VectorBase::has_ghost_elements() const
1150 {
1151 return ghosted;
1152 }
1153
1154
1155 inline const IndexSet &
1156 VectorBase::ghost_elements() const
1157 {
1158 return ghost_indices;
1159 }
1160
1161
1162 inline void
1163 VectorBase::update_ghost_values() const
1164 {
1165 if (ghosted)
1166 {
1167 PetscErrorCode ierr;
1168
1169 ierr = VecGhostUpdateBegin(vector, INSERT_VALUES, SCATTER_FORWARD);
1170 AssertThrow(ierr == 0, ExcPETScError(ierr));
1171 ierr = VecGhostUpdateEnd(vector, INSERT_VALUES, SCATTER_FORWARD);
1172 AssertThrow(ierr == 0, ExcPETScError(ierr));
1173 }
1174 }
1175
1176
1177
1178 inline internal::VectorReference
1179 VectorBase::operator()(const size_type index)
1180 {
1181 return internal::VectorReference(*this, index);
1182 }
1183
1184
1185
1186 inline PetscScalar
1187 VectorBase::operator()(const size_type index) const
1188 {
1189 return static_cast<PetscScalar>(internal::VectorReference(*this, index));
1190 }
1191
1192
1193
1194 inline internal::VectorReference
1195 VectorBase::operator[](const size_type index)
1196 {
1197 return operator()(index);
1198 }
1199
1200
1201
1202 inline PetscScalar
1203 VectorBase::operator[](const size_type index) const
1204 {
1205 return operator()(index);
1206 }
1207
1208 inline MPI_Comm
1209 VectorBase::get_mpi_communicator() const
1210 {
1211 return PetscObjectComm(reinterpret_cast<PetscObject>(vector));
1212 }
1213
1214 inline void
1215 VectorBase::extract_subvector_to(const std::vector<size_type> &indices,
1216 std::vector<PetscScalar> &values) const
1217 {
1218 Assert(indices.size() <= values.size(),
1219 ExcDimensionMismatch(indices.size(), values.size()));
1220 extract_subvector_to(indices.begin(), indices.end(), values.begin());
1221 }
1222
1223 inline void
1224 VectorBase::extract_subvector_to(
1226 const ArrayView<PetscScalar> &elements) const
1227 {
1228 AssertDimension(indices.size(), elements.size());
1229 extract_subvector_to(indices.begin(), indices.end(), elements.begin());
1230 }
1231
1232
1233 template <typename ForwardIterator, typename OutputIterator>
1234 inline void
1235 VectorBase::extract_subvector_to(const ForwardIterator indices_begin,
1236 const ForwardIterator indices_end,
1237 OutputIterator values_begin) const
1238 {
1239 if (indices_begin == indices_end)
1240 return;
1241
1242 // if we are dealing
1243 // with a parallel vector
1244 if (ghosted)
1245 {
1246 // there is the possibility
1247 // that the vector has
1248 // ghost elements. in that
1249 // case, we first need to
1250 // figure out which
1251 // elements we own locally,
1252 // then get a pointer to
1253 // the elements that are
1254 // stored here (both the
1255 // ones we own as well as
1256 // the ghost elements). in
1257 // this array, the locally
1258 // owned elements come
1259 // first followed by the
1260 // ghost elements whose
1261 // position we can get from
1262 // an index set
1263
1264 Assert(ghost_vector != nullptr && ghost_vector_array != nullptr,
1266 "Ghost elements are not acquired for the vector."));
1267
1268 PetscInt begin, end;
1269 PetscErrorCode ierr = VecGetOwnershipRange(vector, &begin, &end);
1270 AssertThrow(ierr == 0, ExcPETScError(ierr));
1271
1272 PetscInt lsize;
1273 ierr = VecGetSize(ghost_vector, &lsize);
1274 AssertThrow(ierr == 0, ExcPETScError(ierr));
1275
1276 auto input = indices_begin;
1277 auto output = values_begin;
1278 while (input != indices_end)
1279 {
1280 const auto index = static_cast<PetscInt>(*input);
1281 AssertIntegerConversion(index, *input);
1282 if (index >= begin && index < end)
1283 {
1284 // local entry
1285 *output = *(ghost_vector_array + index - begin);
1286 }
1287 else
1288 {
1289 // ghost entry
1290 const auto ghost_index = ghost_indices.index_within_set(*input);
1291
1292 AssertIndexRange(ghost_index + end - begin, lsize);
1293 *output = *(ghost_vector_array + ghost_index + end - begin);
1294 }
1295
1296 ++input;
1297 ++output;
1298 }
1299 }
1300 // if the vector is local or the
1301 // caller, then simply access the
1302 // element we are interested in
1303 else
1304 {
1305 PetscInt begin, end;
1306 PetscErrorCode ierr = VecGetOwnershipRange(vector, &begin, &end);
1307 AssertThrow(ierr == 0, ExcPETScError(ierr));
1308
1309 const PetscScalar *ptr;
1310 ierr = VecGetArrayRead(vector, &ptr);
1311 AssertThrow(ierr == 0, ExcPETScError(ierr));
1312
1313 auto input = indices_begin;
1314 auto output = values_begin;
1315 while (input != indices_end)
1316 {
1317 const auto index = static_cast<PetscInt>(*input);
1318 AssertIntegerConversion(index, *input);
1319
1320 Assert(index >= begin && index < end,
1321 ExcMessage("You are accessing elements of a vector without "
1322 "ghost elements that are not actually owned by "
1323 "this vector. A typical case where this may "
1324 "happen is if you are passing a non-ghosted "
1325 "(completely distributed) vector to a function "
1326 "that expects a vector that stores ghost "
1327 "elements for all locally relevant or locally "
1328 "active vector entries."));
1329
1330 *output = *(ptr + index - begin);
1331
1332 ++input;
1333 ++output;
1334 }
1335
1336 ierr = VecRestoreArrayRead(vector, &ptr);
1337 AssertThrow(ierr == 0, ExcPETScError(ierr));
1338 }
1339 }
1340
1341 template <class Archive>
1342 inline void
1343 VectorBase::save(Archive &ar, const unsigned int) const
1344 {
1345 // forward to serialization function in the base class.
1346 ar &static_cast<const EnableObserverPointer &>(*this);
1347 ar &size();
1348 ar &local_range();
1349
1350 const PetscScalar *array = nullptr;
1351 int ierr = VecGetArrayRead(*this, &array);
1352 AssertThrow(ierr == 0, ExcPETScError(ierr));
1353
1354 boost::serialization::array_wrapper<const PetscScalar> wrapper(
1355 array, locally_owned_size());
1356 ar &wrapper;
1357
1358 ierr = VecRestoreArrayRead(*this, &array);
1359 AssertThrow(ierr == 0, ExcPETScError(ierr));
1360 }
1361
1362
1363
1364 template <class Archive>
1365 inline void
1366 VectorBase::load(Archive &ar, const unsigned int)
1367 {
1368 ar &static_cast<EnableObserverPointer &>(*this);
1369
1370 size_type size = 0;
1371 std::pair<size_type, size_type> local_range;
1372
1373 ar &size;
1374 Assert(size == this->size(),
1375 ExcMessage("The serialized value of size (" + std::to_string(size) +
1376 ") does not match the current size (" +
1377 std::to_string(this->size()) + ")"));
1378 ar &local_range;
1379 Assert(local_range == this->local_range(),
1380 ExcMessage("The serialized value of local_range (" +
1381 std::to_string(local_range.first) + ", " +
1382 std::to_string(local_range.second) +
1383 ") does not match the current local_range (" +
1384 std::to_string(this->local_range().first) + ", " +
1385 std::to_string(this->local_range().second) + ")"));
1386
1387 PetscScalar *array = nullptr;
1388 int ierr = VecGetArray(petsc_vector(), &array);
1389 AssertThrow(ierr == 0, ExcPETScError(ierr));
1390
1391 boost::serialization::array_wrapper<PetscScalar> wrapper(
1392 array, locally_owned_size());
1393 ar &wrapper;
1394
1395 ierr = VecRestoreArray(petsc_vector(), &array);
1396 AssertThrow(ierr == 0, ExcPETScError(ierr));
1397 }
1398# endif // DOXYGEN
1399} // namespace PETScWrappers
1400
1401#endif // DEAL_II_WITH_PETSC
1402
1404
1405#endif
*  iterator end()
*  *  iterator begin()
*  *  reference operator*() const
*  *  Point< dim > operator()(const Point< dim > &p) const * 
iterator begin() const
Definition array_view.h:755
iterator end() const
Definition array_view.h:764
std::size_t size() const
Definition array_view.h:737
real_type lp_norm(const real_type p) const
VectorBase & operator+=(const VectorBase &V)
PetscScalar mean_value() const
VectorOperation::values last_action
bool operator==(const VectorBase &v) const
VectorBase & operator*=(const PetscScalar factor)
VectorBase & operator-=(const VectorBase &V)
void save(Archive &ar, const unsigned int version) const
bool operator!=(const VectorBase &v) const
IndexSet locally_owned_elements() const
bool in_local_range(const size_type index) const
void load(Archive &ar, const unsigned int version)
std::size_t memory_consumption() const
internal::VectorReference reference
VectorBase & operator/=(const PetscScalar factor)
friend class internal::VectorReference
PetscScalar operator[](const size_type index) const
MPI_Comm get_mpi_communicator() const
void scale(const VectorBase &scaling_factors)
void extract_subvector_to(const std::vector< size_type > &indices, std::vector< PetscScalar > &values) const
void update_ghost_values() const
std::pair< size_type, size_type > local_range() const
void sadd(const PetscScalar s, const VectorBase &V)
void compress(const VectorOperation::values operation)
void set(const std::vector< size_type > &indices, const std::vector< PetscScalar > &values)
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
PetscScalar add_and_dot(const PetscScalar a, const VectorBase &V, const VectorBase &W)
const PetscScalar * ghost_vector_array
const IndexSet & ghost_elements() const
void swap(VectorBase &v) noexcept
reference operator()(const size_type index)
void swap(VectorBase &u, VectorBase &v) noexcept
virtual void extract_subvector_to(const ArrayView< const types::global_dof_index > &indices, const ArrayView< PetscScalar > &elements) const override
const internal::VectorReference const_reference
void serialize(Archive &archive, const unsigned int version)
void add(const std::vector< size_type > &indices, const std::vector< PetscScalar > &values)
void write_ascii(const PetscViewerFormat format=PETSC_VIEWER_DEFAULT)
bool has_ghost_elements() const
reference operator[](const size_type index)
size_type locally_owned_size() const
void equ(const PetscScalar a, const VectorBase &V)
void do_set_add_operation(const size_type n_elements, const size_type *indices, const PetscScalar *values, const bool add_values)
VectorBase & operator=(const VectorBase &)
size_type size() const override
PetscScalar operator()(const size_type index) const
void extract_subvector_to(const ForwardIterator indices_begin, const ForwardIterator indices_end, OutputIterator values_begin) const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define AssertIntegerConversion(index1, index2)
static ::ExceptionBase & ExcGhostsPresent()
#define Assert(cond, exc)
#define DeclException2(Exception2, type1, type2, outsequence)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
#define DeclException3(Exception3, type1, type2, type3, outsequence)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
std::pair< types::global_dof_index, types::global_dof_index > local_range
Definition mpi.cc:814
std::size_t size
Definition mpi.cc:733
types::global_dof_index locally_owned_size
Definition mpi.cc:821
unsigned int global_dof_index
Definition types.h:92