18 #include "libmesh/petsc_vector.h" 20 #ifdef LIBMESH_HAVE_PETSC 23 #include "libmesh/petsc_matrix_base.h" 24 #include "libmesh/dense_subvector.h" 25 #include "libmesh/dense_vector.h" 26 #include "libmesh/int_range.h" 27 #include "libmesh/petsc_macro.h" 28 #include "libmesh/wrapped_petsc.h" 46 this->_restore_array();
51 LibmeshPetscCall(VecSum (_vec, &
value));
53 return static_cast<T
>(
value);
62 parallel_object_only();
64 this->_restore_array();
69 LibmeshPetscCall(VecNorm (_vec, N, &
value));
95 parallel_object_only();
97 this->_restore_array();
107 template <
typename T>
111 parallel_object_only();
113 this->_restore_array();
123 template <
typename T>
126 this->_restore_array();
127 libmesh_assert_less (i, size());
129 PetscInt i_val =
static_cast<PetscInt
>(i);
130 PetscScalar petsc_value =
PS(
value);
132 std::scoped_lock lock(this->_numeric_vector_mutex);
133 LibmeshPetscCall(VecSetValues (_vec, 1, &i_val, &petsc_value, INSERT_VALUES));
135 this->_is_closed =
false;
140 template <
typename T>
143 parallel_object_only();
147 LibmeshPetscCall(VecReciprocal(_vec));
152 template <
typename T>
155 parallel_object_only();
159 LibmeshPetscCall(VecConjugate(_vec));
164 template <
typename T>
167 this->_restore_array();
168 libmesh_assert_less (i, size());
170 PetscInt i_val =
static_cast<PetscInt
>(i);
171 PetscScalar petsc_value =
PS(
value);
173 std::scoped_lock lock(this->_numeric_vector_mutex);
174 LibmeshPetscCall(VecSetValues (_vec, 1, &i_val, &petsc_value, ADD_VALUES));
176 this->_is_closed =
false;
181 template <
typename T>
183 const std::vector<numeric_index_type> & dof_indices)
186 if (dof_indices.empty())
189 this->_restore_array();
191 const PetscInt * i_val =
reinterpret_cast<const PetscInt *
>(dof_indices.data());
192 const PetscScalar * petsc_value =
pPS(v);
194 std::scoped_lock lock(this->_numeric_vector_mutex);
195 LibmeshPetscCall(VecSetValues (_vec, cast_int<PetscInt>(dof_indices.size()),
196 i_val, petsc_value, ADD_VALUES));
198 this->_is_closed =
false;
203 template <
typename T>
207 parallel_object_only();
209 this->_restore_array();
211 const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
218 libmesh_warning(
"Matrix A must be assembled before calling PetscVector::add_vector(v, A).\n" 219 "Please update your code, as this warning will become an error in a future release.");
220 libmesh_deprecated();
231 template <
typename T>
235 parallel_object_only();
237 this->_restore_array();
239 const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
246 libmesh_warning(
"Matrix A must be assembled before calling PetscVector::add_vector_transpose(v, A).\n" 247 "Please update your code, as this warning will become an error in a future release.");
248 libmesh_deprecated();
259 template <
typename T>
263 parallel_object_only();
265 this->_restore_array();
267 const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
273 libmesh_warning(
"Matrix A must be assembled before calling PetscVector::add_vector_conjugate_transpose(v, A).\n" 274 "Please update your code, as this warning will become an error in a future release.");
275 libmesh_deprecated();
281 std::unique_ptr<NumericVector<Number>> this_clone = this->clone();
288 this->add(1., *this_clone);
293 template <
typename T>
296 this->_get_array(
false);
299 _values[i] += PetscScalar(v_in);
304 template <
typename T>
307 parallel_object_only();
314 template <
typename T>
317 parallel_object_only();
319 this->_restore_array();
328 PetscScalar a =
PS(a_in);
331 const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
334 libmesh_assert_equal_to (this->size(), v->
size());
336 LibmeshPetscCall(VecAXPY(_vec, a, v->
vec()));
339 static_cast<typename std::underlying_type<ParallelType>::type
>(this->type())));
341 if (this->is_effectively_ghosted())
342 VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
344 this->_is_closed =
true;
349 template <
typename T>
351 const std::vector<numeric_index_type> & dof_indices)
353 if (dof_indices.empty())
356 this->_restore_array();
359 std::scoped_lock lock(this->_numeric_vector_mutex);
360 LibmeshPetscCall(VecSetValues (_vec, cast_int<PetscInt>(dof_indices.size()),
361 idx_values,
pPS(v), INSERT_VALUES));
363 this->_is_closed =
false;
368 template <
typename T>
371 parallel_object_only();
373 this->_restore_array();
375 PetscScalar factor =
PS(factor_in);
377 LibmeshPetscCall(VecScale(_vec, factor));
380 static_cast<typename std::underlying_type<ParallelType>::type
>(this->type())));
382 if (this->is_effectively_ghosted())
383 VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
386 template <
typename T>
389 parallel_object_only();
392 const PetscVector<T> * v_vec = cast_ptr<const PetscVector<T> *>(&v);
394 LibmeshPetscCall(VecPointwiseMult(_vec, _vec, v_vec->
_vec));
399 template <
typename T>
402 parallel_object_only();
405 const PetscVector<T> * v_vec = cast_ptr<const PetscVector<T> *>(&v);
407 LibmeshPetscCall(VecPointwiseDivide(_vec, _vec, v_vec->
_vec));
412 template <
typename T>
415 parallel_object_only();
417 this->_restore_array();
419 LibmeshPetscCall(VecAbs(_vec));
422 static_cast<typename std::underlying_type<ParallelType>::type
>(this->type())));
424 if (this->is_effectively_ghosted())
425 VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
428 template <
typename T>
431 parallel_object_only();
433 this->_restore_array();
438 PetscScalar
value=0.;
441 const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
444 LibmeshPetscCall(VecDot(this->_vec, v->
_vec, &
value));
446 return static_cast<T
>(
value);
449 template <
typename T>
452 parallel_object_only();
454 this->_restore_array();
459 PetscScalar
value=0.;
462 const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
465 LibmeshPetscCall(VecTDot(this->_vec, v->
_vec, &
value));
467 return static_cast<T
>(
value);
471 template <
typename T>
475 parallel_object_only();
477 this->_restore_array();
480 PetscScalar s =
PS(s_in);
482 if (this->size() != 0)
484 LibmeshPetscCall(VecSet(_vec, s));
487 static_cast<typename std::underlying_type<ParallelType>::type
>(this->type())));
489 if (this->is_effectively_ghosted())
490 VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
498 template <
typename T>
502 parallel_object_only();
505 const PetscVector<T> * v = cast_ptr<const PetscVector<T> *>(&v_in);
514 template <
typename T>
518 enum AssignmentType { ParallelToSerial, SerialToParallel, SameToSame, Error };
520 parallel_object_only();
522 static_cast<typename std::underlying_type<ParallelType>::type
>(this->type())));
524 static_cast<typename std::underlying_type<ParallelType>::type
>(v.
type())));
529 this->_restore_array();
532 libmesh_assert_equal_to (this->size(), v.
size());
535 AssignmentType assign_type = Error;
537 assign_type = ParallelToSerial;
539 assign_type = SerialToParallel;
540 else if (this->local_size() == v.
local_size())
541 assign_type = SameToSame;
544 static_cast<typename std::underlying_type<AssignmentType>::type
>(assign_type)));
548 case ParallelToSerial:
553 LibmeshPetscCall(VecScatterCreateToAll(v.
_vec, scatter.get(),
nullptr));
554 VecScatterBeginEnd(v.
comm(), scatter, v.
_vec, _vec, INSERT_VALUES, SCATTER_FORWARD);
559 LibmeshPetscCall(VecCopy(v.
_vec, _vec));
561 case SerialToParallel:
562 libmesh_not_implemented_msg(
563 "Scattering from a serial vector on every rank to a parallel vector is not behavior we " 564 "define because we do not verify the serial vector is the same on each rank");
566 libmesh_error_msg(
"Unhandled vector combination");
570 static_cast<typename std::underlying_type<ParallelType>::type
>(this->type())));
572 if (this->is_effectively_ghosted())
573 VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
575 this->_is_closed =
true;
582 template <
typename T>
586 parallel_object_only();
588 this->_get_array(
false);
594 if (this->size() == v.size())
599 _values[i] =
PS(v[first + i]);
609 _values[i] =
PS(v[i]);
613 if (this->is_effectively_ghosted())
621 template <
typename T>
624 parallel_object_only();
627 static_cast<typename std::underlying_type<ParallelType>::type
>(this->type())));
629 static_cast<typename std::underlying_type<ParallelType>::type
>(v_local_in.
type())));
636 template <
typename T>
638 const std::vector<numeric_index_type> & )
const 640 this->localize(v_local_in);
645 template <
typename T>
647 const std::vector<numeric_index_type> & indices)
const 649 parallel_object_only();
655 LibmeshPetscCall(VecCreateSeq(PETSC_COMM_SELF, cast_int<PetscInt>(indices.size()), dest.
get()));
663 LibmeshPetscCall(ISCreateGeneral(this->comm().
get(), cast_int<PetscInt>(indices.size()), idxptr,
664 PETSC_USE_POINTER,
is.get()));
668 LibmeshPetscCall(VecScatterCreate(_vec,
671 LIBMESH_PETSC_NULLPTR,
675 VecScatterBeginEnd(this->comm(), scatter, _vec, dest, INSERT_VALUES, SCATTER_FORWARD);
678 PetscScalar * values;
679 LibmeshPetscCall(VecGetArray (dest, &values));
684 v_local.reserve(indices.size());
686 v_local.insert(v_local.begin(), values, values+indices.size());
689 LibmeshPetscCall(VecRestoreArray (dest, &values));
694 template <
typename T>
697 const std::vector<numeric_index_type> & send_list)
699 parallel_object_only();
701 this->_restore_array();
703 libmesh_assert_less_equal (send_list.size(), this->size());
704 libmesh_assert_less_equal (last_local_idx+1, this->size());
713 if (this->n_processors() == 1)
721 parallel_vec.
init (my_size, my_local_size,
true,
PARALLEL);
727 std::vector<PetscInt>
idx(my_local_size);
728 std::iota (
idx.begin(),
idx.end(), first_local_idx);
732 LibmeshPetscCall(ISCreateGeneral(this->comm().
get(), my_local_size,
733 my_local_size ?
idx.data() :
nullptr, PETSC_USE_POINTER,
is.get()));
736 LibmeshPetscCall(VecScatterCreate(_vec,
is,
741 VecScatterBeginEnd(this->comm(), scatter, _vec, parallel_vec.
_vec, INSERT_VALUES, SCATTER_FORWARD);
745 parallel_vec.
close();
746 parallel_vec.
localize (*
this, send_list);
752 template <
typename T>
755 parallel_object_only();
757 this->_restore_array();
760 parallel_object_only();
762 const PetscInt n = this->size();
763 const PetscInt nl = this->local_size();
764 PetscScalar * values;
767 v_local.resize(n, 0.);
769 LibmeshPetscCall(VecGetArray (_vec, &values));
773 for (PetscInt i=0; i<nl; i++)
774 v_local[i+ioff] = static_cast<T>(values[i]);
776 LibmeshPetscCall(VecRestoreArray (_vec, &values));
778 this->comm().sum(v_local);
784 #ifdef LIBMESH_USE_REAL_NUMBERS 789 timpi_mpi_var(pid))
const 791 parallel_object_only();
793 this->_restore_array();
795 const PetscInt n = size();
796 PetscScalar * values;
799 if (n_processors() == 1)
803 LibmeshPetscCall(VecGetArray (_vec, &values));
805 for (PetscInt i=0; i<n; i++)
806 v_local[i] = static_cast<Real>(values[i]);
808 LibmeshPetscCall(VecRestoreArray (_vec, &values));
812 #ifdef LIBMESH_HAVE_MPI 820 LibmeshPetscCall(VecScatterCreateToZero(_vec,
ctx.get(), vout.
get()));
822 VecScatterBeginEnd(this->comm(),
ctx, _vec, vout, INSERT_VALUES, SCATTER_FORWARD);
824 if (processor_id() == 0)
828 LibmeshPetscCall(VecGetArray (vout, &values));
830 for (PetscInt i=0; i<n; i++)
831 v_local[i] = static_cast<Real>(values[i]);
833 LibmeshPetscCall(VecRestoreArray (vout, &values));
841 std::vector<Real> local_values (n, 0.);
844 LibmeshPetscCall(VecGetArray (_vec, &values));
846 const PetscInt nl = local_size();
847 for (PetscInt i=0; i<nl; i++)
848 local_values[i+ioff] = static_cast<Real>(values[i]);
850 LibmeshPetscCall(VecRestoreArray (_vec, &values));
854 MPI_Reduce (local_values.data(), v_local.data(), n,
860 #endif // LIBMESH_HAVE_MPI 867 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 873 parallel_object_only();
875 this->_restore_array();
877 const PetscInt n = size();
878 const PetscInt nl = local_size();
879 PetscScalar * values;
885 for (PetscInt i=0; i<n; i++)
889 if (n_processors() == 1)
891 LibmeshPetscCall(VecGetArray (_vec, &values));
893 for (PetscInt i=0; i<n; i++)
894 v_local[i] = static_cast<Complex>(values[i]);
896 LibmeshPetscCall(VecRestoreArray (_vec, &values));
907 std::vector<Real> real_local_values(n, 0.);
908 std::vector<Real> imag_local_values(n, 0.);
911 LibmeshPetscCall(VecGetArray (_vec, &values));
914 for (PetscInt i=0; i<nl; i++)
916 real_local_values[i+ioff] =
static_cast<Complex>(values[i]).
real();
917 imag_local_values[i+ioff] =
static_cast<Complex>(values[i]).
imag();
920 LibmeshPetscCall(VecRestoreArray (_vec, &values));
928 std::vector<Real> real_v_local(n);
929 std::vector<Real> imag_v_local(n);
932 MPI_Reduce (real_local_values.data(),
933 real_v_local.data(), n,
936 pid, this->comm().get());
938 MPI_Reduce (imag_local_values.data(),
939 imag_v_local.data(), n,
942 pid, this->comm().get());
945 for (PetscInt i=0; i<n; i++)
946 v_local[i] =
Complex(real_v_local[i], imag_v_local[i]);
954 template <
typename T>
958 parallel_object_only();
960 this->_restore_array();
963 const PetscVector<T> * vec1_petsc = cast_ptr<const PetscVector<T> *>(&vec1);
964 const PetscVector<T> * vec2_petsc = cast_ptr<const PetscVector<T> *>(&vec2);
967 LibmeshPetscCall(VecPointwiseMult(_vec, vec1_petsc->
vec(), vec2_petsc->vec()));
970 static_cast<typename std::underlying_type<ParallelType>::type
>(this->type())));
972 if (this->is_effectively_ghosted())
973 VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
975 this->_is_closed =
true;
978 template <
typename T>
982 parallel_object_only();
984 this->_restore_array();
987 const PetscVector<T> *
const vec1_petsc = cast_ptr<const PetscVector<T> *>(&vec1);
988 const PetscVector<T> *
const vec2_petsc = cast_ptr<const PetscVector<T> *>(&vec2);
991 LibmeshPetscCall(VecPointwiseDivide(_vec, vec1_petsc->
vec(), vec2_petsc->vec()));
994 static_cast<typename std::underlying_type<ParallelType>::type
>(this->type())));
996 if (this->is_effectively_ghosted())
997 VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
999 this->_is_closed =
true;
1002 template <
typename T>
1005 parallel_object_only();
1007 this->_restore_array();
1016 LibmeshPetscCall(PetscViewerASCIIOpen(this->comm().
get(),
1018 petsc_viewer.
get()));
1020 #if PETSC_VERSION_LESS_THAN(3,7,0) 1021 LibmeshPetscCall(PetscViewerSetFormat (petsc_viewer,
1022 PETSC_VIEWER_ASCII_MATLAB));
1024 LibmeshPetscCall(PetscViewerPushFormat (petsc_viewer,
1025 PETSC_VIEWER_ASCII_MATLAB));
1028 LibmeshPetscCall(VecView (_vec, petsc_viewer));
1035 #if PETSC_VERSION_LESS_THAN(3,7,0) 1036 LibmeshPetscCall(PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD,
1037 PETSC_VIEWER_ASCII_MATLAB));
1039 LibmeshPetscCall(PetscViewerPushFormat (PETSC_VIEWER_STDOUT_WORLD,
1040 PETSC_VIEWER_ASCII_MATLAB));
1043 LibmeshPetscCall(VecView (_vec, PETSC_VIEWER_STDOUT_WORLD));
1051 template <
typename T>
1053 const std::vector<numeric_index_type> & rows,
1054 const bool supplying_global_rows)
const 1056 parallel_object_only();
1058 libmesh_error_msg_if(
1060 "We do not support scattering parallel information to ghosts for subvectors");
1062 this->_restore_array();
1067 PetscVector<T> * petsc_subvector = cast_ptr<PetscVector<T> *>(&subvector);
1074 if (this->is_effectively_serial())
1077 LibmeshPetscCall(VecCreateSeq(this->comm().
get(), rows.size(), &(petsc_subvector->
_vec)));
1079 #ifdef LIBMESH_ENABLE_DEPRECATED 1087 this->type() != petsc_subvector->
type())
1088 libmesh_deprecated();
1094 petsc_subvector->
_type = this->type();
1099 #ifndef LIBMESH_ENABLE_DEPRECATED 1107 libmesh_not_implemented_msg(
"Cannot yet create non-PARALLEL subvectors in parallel");
1110 if (supplying_global_rows)
1117 LibmeshPetscCall(VecCreateMPI(this->comm().
get(),
1119 cast_int<PetscInt>(rows.size()),
1120 &(petsc_subvector->
_vec)));
1122 LibmeshPetscCall(VecCreateMPI(this->comm().
get(),
1123 cast_int<PetscInt>(rows.size()),
1125 &(petsc_subvector->
_vec)));
1131 LibmeshPetscCall(VecSetFromOptions (petsc_subvector->
_vec));
1142 std::vector<PetscInt>
idx(rows.size());
1143 if (supplying_global_rows)
1144 std::iota (
idx.begin(),
idx.end(), 0);
1148 LibmeshPetscCall(VecGetOwnershipRange(petsc_subvector->
_vec, &start,
nullptr));
1149 std::iota (
idx.begin(),
idx.end(), start);
1154 LibmeshPetscCall(ISCreateGeneral(this->comm().
get(),
1155 cast_int<PetscInt>(rows.size()),
1161 LibmeshPetscCall(ISCreateGeneral(this->comm().
get(),
1162 cast_int<PetscInt>(rows.size()),
1165 subvector_is.
get()));
1169 LibmeshPetscCall(VecScatterCreate(this->_vec,
1171 petsc_subvector->
_vec,
1176 VecScatterBeginEnd(this->comm(), scatter, this->_vec, petsc_subvector->
_vec, INSERT_VALUES, SCATTER_FORWARD);
1183 template <
typename T>
1188 bool initially_array_is_present = _array_is_present.load(std::memory_order_acquire);
1192 if (initially_array_is_present && read_only && !_values_read_only)
1193 _read_only_values = _values;
1199 if (initially_array_is_present && !read_only && _values_read_only)
1202 initially_array_is_present =
false;
1205 if (!initially_array_is_present)
1207 std::scoped_lock lock(_petsc_get_restore_array_mutex);
1208 if (!_array_is_present.load(std::memory_order_relaxed))
1210 if (!this->is_effectively_ghosted())
1214 LibmeshPetscCall(VecGetArrayRead(_vec, &_read_only_values));
1215 _values_read_only =
true;
1219 LibmeshPetscCall(VecGetArray(_vec, &_values));
1220 _values_read_only =
false;
1222 _local_size = this->local_size();
1226 LibmeshPetscCall(VecGhostGetLocalForm (_vec,&_local_form));
1230 LibmeshPetscCall(VecGetArrayRead(_local_form, &_read_only_values));
1231 _values_read_only =
true;
1235 LibmeshPetscCall(VecGetArray(_local_form, &_values));
1236 _values_read_only =
false;
1239 PetscInt my_local_size = 0;
1240 LibmeshPetscCall(VecGetLocalSize(_local_form, &my_local_size));
1245 PetscInt petsc_first=0, petsc_last=0;
1246 LibmeshPetscCall(VecGetOwnershipRange (_vec, &petsc_first, &petsc_last));
1250 _array_is_present.store(
true, std::memory_order_release);
1257 template <
typename T>
1260 libmesh_error_msg_if(_values_manually_retrieved,
1261 "PetscVector values were manually retrieved but are being automatically restored!");
1264 if (_array_is_present.load(std::memory_order_acquire))
1266 std::scoped_lock lock(_petsc_get_restore_array_mutex);
1267 if (_array_is_present.load(std::memory_order_relaxed))
1269 if (!this->is_effectively_ghosted())
1271 if (_values_read_only)
1272 LibmeshPetscCall(VecRestoreArrayRead (_vec, &_read_only_values));
1274 LibmeshPetscCall(VecRestoreArray (_vec, &_values));
1280 if (_values_read_only)
1281 LibmeshPetscCall(VecRestoreArrayRead (_local_form, &_read_only_values));
1283 LibmeshPetscCall(VecRestoreArray (_local_form, &_values));
1286 LibmeshPetscCall(VecGhostRestoreLocalForm (_vec,&_local_form));
1287 _local_form =
nullptr;
1290 _array_is_present.store(
false, std::memory_order_release);
1295 template <
typename T>
1296 std::unique_ptr<NumericVector<T>>
1301 LibmeshPetscCall(ISCreateGeneral(this->comm().
get(),
1302 cast_int<PetscInt>(rows.size()),
1308 LibmeshPetscCall(VecGetSubVector(_vec, parent_is, &subvec));
1310 this->_is_closed =
false;
1312 return std::make_unique<PetscVector<T>>(subvec, this->comm());
1315 template <
typename T>
1318 const std::vector<numeric_index_type> & rows)
1320 auto *
const petsc_subvector = cast_ptr<PetscVector<T> *>(subvector.get());
1324 LibmeshPetscCall(ISCreateGeneral(this->comm().
get(),
1325 cast_int<PetscInt>(rows.size()),
1330 Vec subvec = petsc_subvector->vec();
1331 LibmeshPetscCall(VecRestoreSubVector(_vec, parent_is, &subvec));
1333 if (this->is_effectively_ghosted())
1334 VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
1336 this->_is_closed =
true;
1347 #endif // #ifdef LIBMESH_HAVE_PETSC std::string name(const ElemQuality q)
This function returns a string containing some name for q.
virtual Real l2_norm() const override
bool closed()
Checks that the library has been closed.
virtual void localize(std::vector< T > &v_local) const override
Creates a copy of the global vector in the local vector v_local.
This class provides a nice interface to PETSc's Vec object.
void add_vector_conjugate_transpose(const NumericVector< T > &v, const SparseMatrix< T > &A)
.
virtual void add_vector_transpose(const NumericVector< T > &v, const SparseMatrix< T > &A) override
Computes , i.e.
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
This class provides a nice interface to the PETSc C-based data structures for parallel, sparse matrices.
virtual numeric_index_type size() const override
virtual Real linfty_norm() const override
virtual bool initialized() const
void _get_array(bool read_only) const
Queries the array (and the local form if the vector is ghosted) from PETSc.
virtual numeric_index_type local_size() const override
virtual void add(const numeric_index_type i, const T value) override
Adds value to the vector entry specified by i.
Vec _vec
Actual PETSc vector datatype to hold vector entries.
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
const Parallel::Communicator & comm() const
PetscScalar * pPS(T *ptr)
bool is_effectively_ghosted() const
bool _is_initialized
true once init() has been called.
The libMesh namespace provides an interface to certain functionality in the library.
virtual void pointwise_divide(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
Computes (summation not implied) i.e.
void _restore_array() const
Restores the array (and the local form if the vector is ghosted) to PETSc.
uint8_t processor_id_type
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
processor_id_type size() const
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices) override
Inserts the entries of v in *this at the locations specified by v.
virtual void pointwise_mult(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
Computes (summation not implied) i.e.
bool is_effectively_serial() const
virtual Real l1_norm() const override
virtual void abs() override
Sets for each entry in the vector.
dof_id_type numeric_index_type
virtual NumericVector< T > & operator+=(const NumericVector< T > &v) override
Adds v to *this, .
virtual void conjugate() override
Negates the imaginary component of each entry in the vector.
virtual void localize_to_one(std::vector< T > &v_local, const processor_id_type proc_id=0) const override
Creates a local copy of the global vector in v_local only on processor proc_id.
PetscErrorCode PetscInt const PetscInt IS * is
ParallelType _type
Type of vector.
virtual void create_subvector(NumericVector< T > &subvector, const std::vector< numeric_index_type > &rows, bool supplying_global_rows=true) const override
Fills in subvector from this vector using the indices in rows.
virtual bool closed() const
virtual T sum() const override
std::complex< Real > Complex
ParallelType type() const
virtual void set(const numeric_index_type i, const T value) override
Sets v(i) = value.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
T indefinite_dot(const NumericVector< T > &v) const
virtual void restore_subvector(std::unique_ptr< NumericVector< T >> subvector, const std::vector< numeric_index_type > &rows) override
Restores a view into this vector using the indices in rows.
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType type=AUTOMATIC) override
Change the dimension of the vector to n.
bool initialized()
Checks that library initialization has been done.
PetscVector< T > & operator=(const PetscVector< T > &v)
Copy assignment operator.
virtual void reciprocal() override
Computes the component-wise reciprocal, .
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices) override
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i]...
virtual NumericVector< T > & operator*=(const NumericVector< T > &v) override
Computes the component-wise multiplication of this vector's entries by another's, ...
boost::multiprecision::float128 imag(const boost::multiprecision::float128)
virtual void print_matlab(const std::string &name="") const override
Print the contents of the vector in Matlab's sparse matrix format.
virtual std::unique_ptr< NumericVector< T > > get_subvector(const std::vector< numeric_index_type > &rows) override
Creates a view into this vector using the indices in rows.
virtual void scale(const T factor) override
Scale each element of the vector by the given factor.
bool _is_closed
Flag which tracks whether the vector's values are consistent on all processors after insertion or add...
virtual void close() override
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
virtual NumericVector< T > & operator/=(const NumericVector< T > &v) override
Computes the component-wise division of this vector's entries by another's, .
virtual NumericVector< T > & operator-=(const NumericVector< T > &v) override
Subtracts v from *this, .
virtual T dot(const NumericVector< T > &v) const override