17#ifdef DEAL_II_WITH_PETSC
34 VectorReference::operator PetscScalar()
const
48 VecGetOwnershipRange(vector.vector, &begin, &end);
51 Vec locally_stored_elements =
nullptr;
52 ierr = VecGhostGetLocalForm(vector.vector, &locally_stored_elements);
56 ierr = VecGetSize(locally_stored_elements, &lsize);
59 const PetscScalar *ptr;
60 ierr = VecGetArrayRead(locally_stored_elements, &ptr);
65 if (index >=
static_cast<size_type
>(begin) &&
66 index <
static_cast<size_type
>(end))
69 value = *(ptr + index - begin);
74 Assert(vector.ghost_indices.is_element(index),
76 "You are trying to access an element of a vector "
77 "that is neither a locally owned element nor a "
78 "ghost element of the vector."));
79 const size_type ghostidx =
80 vector.ghost_indices.index_within_set(index);
83 value = *(ptr + ghostidx + end - begin);
86 ierr = VecRestoreArrayRead(locally_stored_elements, &ptr);
90 VecGhostRestoreLocalForm(vector.vector, &locally_stored_elements);
102 PetscErrorCode ierr = VecGetOwnershipRange(vector.vector, &begin, &end);
105 AssertThrow((index >=
static_cast<size_type
>(begin)) &&
106 (index <
static_cast<size_type
>(end)),
107 ExcAccessToNonlocalElement(index, begin, end - 1));
109 const PetscScalar *ptr;
111 ierr = VecGetArrayRead(vector.vector, &ptr);
113 value = *(ptr + index - begin);
114 ierr = VecRestoreArrayRead(vector.vector, &ptr);
133 , ghost_indices(v.ghost_indices)
187 template <
typename Iterator,
typename OutType>
188 class ConvertingIterator
193 using difference_type =
194 typename std::iterator_traits<Iterator>::difference_type;
195 using value_type = OutType;
196 using pointer = OutType *;
197 using reference = OutType &;
198 using iterator_category = std::forward_iterator_tag;
200 ConvertingIterator(
const Iterator &iterator)
207 return static_cast<OutType
>(std::real(*m_iterator));
220 ConvertingIterator old = *
this;
226 operator==(
const ConvertingIterator &other)
const
228 return this->m_iterator == other.m_iterator;
232 operator!=(
const ConvertingIterator &other)
const
234 return this->m_iterator != other.m_iterator;
313 [](PetscScalar left, PetscScalar right) {
314 return static_cast<PetscInt>(std::real(left)) <
315 static_cast<PetscInt>(std::real(right));
450 std::pair<VectorBase::size_type, VectorBase::size_type>
458 return std::make_pair(begin, end);
465 const std::vector<PetscScalar> &values)
467 Assert(indices.size() == values.size(),
468 ExcMessage(
"Function called with arguments of different sizes"));
476 const std::vector<PetscScalar> &values)
478 Assert(indices.size() == values.size(),
479 ExcMessage(
"Function called with arguments of different sizes"));
487 const ::Vector<PetscScalar> &values)
489 Assert(indices.size() == values.size(),
490 ExcMessage(
"Function called with arguments of different sizes"));
499 const PetscScalar *values)
543 ExcMessage(
"Calling compress() is only useful if a vector "
544 "has been written into, but this is a vector with ghost "
545 "elements and consequently is read-only. It does "
546 "not make sense to call compress() for such "
566 ExcMessage(
"Error: not all processors agree on the last "
567 "VectorOperation before this compress() call."));
574 "Missing compress() or calling with wrong VectorOperation argument."));
622 return sum /
static_cast<PetscReal
>(
size());
631 PetscScalar mean = 0;
653 static_cast<PetscReal
>(
size());
781 template <
typename T>
790 template <
typename T>
796 "whether it is non-negative."));
823 const PetscScalar factor = 1. / a;
892 const PetscScalar weights[2] = {a, b};
977 const unsigned int precision,
978 const bool scientific,
979 const bool across)
const
985 const PetscScalar *val;
991 const std::ios::fmtflags
old_flags = out.flags();
994 out.precision(precision);
996 out.setf(std::ios::scientific, std::ios::floatfield);
998 out.setf(std::ios::fixed, std::ios::floatfield);
1002 out << val[i] <<
' ';
1005 out << val[i] << std::endl;
1025 std::swap(this->vector, v.vector);
1026 std::swap(this->ghosted, v.ghosted);
1027 std::swap(this->last_action, v.last_action);
1030 this->ghost_indices = v.ghost_indices;
1031 v.ghost_indices = t;
1051 std::size_t mem =
sizeof(Vec) +
sizeof(
last_action) +
1073 const PetscScalar *values,
1074 const bool add_values)
1083 for (
size_type i = 0; i < n_elements; ++i)
bool operator!=(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
bool operator==(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
size_type n_elements() const
void set_size(const size_type size)
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
real_type lp_norm(const real_type p) const
real_type l1_norm() const
VectorBase & operator+=(const VectorBase &V)
PetscScalar mean_value() const
void determine_ghost_indices()
VectorOperation::values last_action
PetscScalar operator*(const VectorBase &vec) const
bool operator==(const VectorBase &v) const
VectorBase & operator*=(const PetscScalar factor)
VectorBase & operator-=(const VectorBase &V)
bool operator!=(const VectorBase &v) const
std::size_t memory_consumption() const
VectorBase & operator/=(const PetscScalar factor)
MPI_Comm get_mpi_communicator() const
void scale(const VectorBase &scaling_factors)
std::pair< size_type, size_type > local_range() const
void sadd(const PetscScalar s, const VectorBase &V)
real_type norm_sqr() const
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)
virtual ~VectorBase() override
real_type linfty_norm() const
void swap(VectorBase &v) noexcept
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
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 &)
real_type l2_norm() const
size_type size() const override
std::enable_if_t< std::is_floating_point_v< T > &&std::is_floating_point_v< U >, typename ProductType< std::complex< T >, std::complex< U > >::type > operator*(const std::complex< T > &left, const std::complex< U > &right)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcGhostsPresent()
#define Assert(cond, exc)
#define AssertIsFinite(number)
#define AssertThrowMPI(error_code)
#define AssertNothrow(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
#define AssertIntegerConversion(index1, index2)
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
bool is_non_negative(const T &t)
T sum(const T &t, const MPI_Comm mpi_communicator)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)
*braid_SplitCommworld & comm
SynchronousIterators< Iterators > operator++(SynchronousIterators< Iterators > &a)