16#ifndef dealii_block_vector_base_h
17#define dealii_block_vector_base_h
65template <
typename VectorType>
81 static std::false_type
91 std::is_same<decltype(check_for_block_vector(std::declval<VectorType *>())),
97template <
typename VectorType>
107 namespace BlockVectorIterators
124 template <
class BlockVectorType,
bool Constness>
139 typename std::conditional<Constness,
140 const typename BlockVectorType::value_type,
141 typename BlockVectorType::value_type>::type;
156 typename BlockVectorType::BlockType::reference>::type;
163 conditional<Constness, const BlockVectorType, BlockVectorType>::type;
256 template <
bool OtherConstness>
264 template <
bool OtherConstness>
273 template <
bool OtherConstness>
280 template <
bool OtherConstness>
287 template <
bool OtherConstness>
294 template <
bool OtherConstness>
301 template <
bool OtherConstness>
343 "Your program tried to compare iterators pointing to "
344 "different block vectors. There is no reasonable way "
390 template <
typename,
bool>
434template <
class VectorType>
641 template <typename OtherNumber>
644 std::vector<OtherNumber> &
values) const;
673 template <typename ForwardIterator, typename OutputIterator>
676 const ForwardIterator indices_end,
677 OutputIterator values_begin) const;
703 template <class VectorType2>
711 operator=(const VectorType &v);
717 template <class VectorType2>
825 template <typename Number>
833 template <typename Number>
842 template <typename Number>
920 template <class BlockVector2>
927 template <class BlockVector2>
958 template <typename
N,
bool C>
959 friend class ::
internal::BlockVectorIterators::Iterator;
974 namespace BlockVectorIterators
976 template <
class BlockVectorType,
bool Constness>
977 inline Iterator<BlockVectorType, Constness>::Iterator(
978 const Iterator<BlockVectorType, Constness> &c)
981 , current_block(c.current_block)
982 , index_within_block(c.index_within_block)
983 , next_break_forward(c.next_break_forward)
984 , next_break_backward(c.next_break_backward)
989 template <
class BlockVectorType,
bool Constness>
990 inline Iterator<BlockVectorType, Constness>::Iterator(
991 const Iterator<BlockVectorType, !Constness> &c)
994 , current_block(c.current_block)
995 , index_within_block(c.index_within_block)
996 , next_break_forward(c.next_break_forward)
997 , next_break_backward(c.next_break_backward)
1002 static_assert(Constness ==
true,
1003 "Constructing a non-const iterator from a const iterator "
1004 "does not make sense.");
1009 template <
class BlockVectorType,
bool Constness>
1010 inline Iterator<BlockVectorType, Constness>::Iterator(
1019 , current_block(current_block)
1020 , index_within_block(index_within_block)
1021 , next_break_forward(next_break_forward)
1022 , next_break_backward(next_break_backward)
1027 template <
class BlockVectorType,
bool Constness>
1028 inline Iterator<BlockVectorType, Constness> &
1029 Iterator<BlockVectorType, Constness>::operator=(
const Iterator &c)
1033 index_within_block = c.index_within_block;
1034 current_block = c.current_block;
1035 next_break_forward = c.next_break_forward;
1036 next_break_backward = c.next_break_backward;
1043 template <
class BlockVectorType,
bool Constness>
1044 inline typename Iterator<BlockVectorType, Constness>::dereference_type
1047 return parent->
block(current_block)(index_within_block);
1052 template <
class BlockVectorType,
bool Constness>
1053 inline typename Iterator<BlockVectorType, Constness>::dereference_type
1054 Iterator<BlockVectorType, Constness>::
1055 operator[](
const difference_type
d)
const
1064 return parent->
block(current_block)(index_within_block +
d);
1078 template <
class BlockVectorType,
bool Constness>
1079 inline Iterator<BlockVectorType, Constness> &
1088 template <
class BlockVectorType,
bool Constness>
1089 inline Iterator<BlockVectorType, Constness>
1092 const Iterator old_value = *
this;
1099 template <
class BlockVectorType,
bool Constness>
1100 inline Iterator<BlockVectorType, Constness> &
1101 Iterator<BlockVectorType, Constness>::operator--()
1109 template <
class BlockVectorType,
bool Constness>
1110 inline Iterator<BlockVectorType, Constness>
1111 Iterator<BlockVectorType, Constness>::operator--(
int)
1113 const Iterator old_value = *
this;
1120 template <
class BlockVectorType,
bool Constness>
1121 template <
bool OtherConstness>
1124 operator==(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1126 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1133 template <
class BlockVectorType,
bool Constness>
1134 template <
bool OtherConstness>
1137 operator!=(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1139 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1146 template <
class BlockVectorType,
bool Constness>
1147 template <
bool OtherConstness>
1150 operator<(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1152 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1159 template <
class BlockVectorType,
bool Constness>
1160 template <
bool OtherConstness>
1163 operator<=(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1165 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1172 template <
class BlockVectorType,
bool Constness>
1173 template <
bool OtherConstness>
1176 operator>(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1178 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1185 template <
class BlockVectorType,
bool Constness>
1186 template <
bool OtherConstness>
1189 operator>=(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1191 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1198 template <
class BlockVectorType,
bool Constness>
1199 template <
bool OtherConstness>
1200 inline typename Iterator<BlockVectorType, Constness>::difference_type
1202 operator-(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1204 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1207 static_cast<signed int>(i.global_index));
1212 template <
class BlockVectorType,
bool Constness>
1213 inline Iterator<BlockVectorType, Constness>
1224 return Iterator(*parent,
1227 index_within_block +
d,
1229 next_break_backward);
1239 template <
class BlockVectorType,
bool Constness>
1240 inline Iterator<BlockVectorType, Constness>
1251 return Iterator(*parent,
1254 index_within_block -
d,
1256 next_break_backward);
1266 template <
class BlockVectorType,
bool Constness>
1267 inline Iterator<BlockVectorType, Constness> &
1268 Iterator<BlockVectorType, Constness>::operator+=(
const difference_type &
d)
1279 index_within_block +=
d;
1292 template <
class BlockVectorType,
bool Constness>
1293 inline Iterator<BlockVectorType, Constness> &
1294 Iterator<BlockVectorType, Constness>::operator-=(
const difference_type &
d)
1305 index_within_block -=
d;
1317 template <
class BlockVectorType,
bool Constness>
1318 Iterator<BlockVectorType, Constness>::Iterator(
BlockVector & parent,
1331 const std::pair<size_type, size_type> indices =
1333 current_block = indices.first;
1334 index_within_block = indices.second;
1336 next_break_backward =
1338 next_break_forward =
1346 this->global_index = parent.
size();
1348 index_within_block = 0;
1356 template <
class BlockVectorType,
bool Constness>
1358 Iterator<BlockVectorType, Constness>::move_forward()
1361 ++index_within_block;
1366 index_within_block = 0;
1371 next_break_backward = next_break_forward + 1;
1375 next_break_forward +=
1390 template <
class BlockVectorType,
bool Constness>
1392 Iterator<BlockVectorType, Constness>::move_backward()
1395 --index_within_block;
1396 else if (current_block != 0)
1401 index_within_block =
1406 next_break_forward = next_break_backward - 1;
1409 next_break_backward -=
1418 next_break_forward = 0;
1419 next_break_backward = 0;
1432template <
class VectorType>
1441template <
class VectorType>
1445 std::size_t local_size = 0;
1447 local_size +=
block(
b).locally_owned_size();
1453template <
class VectorType>
1474template <
class VectorType>
1482template <
class VectorType>
1493template <
class VectorType>
1504template <
class VectorType>
1512template <
class VectorType>
1516 std::vector<size_type> sizes(
n_blocks());
1519 sizes[i] =
block(i).size();
1526template <
class VectorType>
1531 for (
unsigned int i = 0; i <
n_blocks(); ++i)
1532 block(i).compress(operation);
1537template <
class VectorType>
1546template <
class VectorType>
1554template <
class VectorType>
1563template <
class VectorType>
1571template <
class VectorType>
1575 const std::pair<size_type, size_type> local_index =
1582template <
class VectorType>
1595template <
class VectorType>
1608template <
class VectorType>
1623template <
class VectorType>
1636template <
class VectorType>
1653template <
class VectorType>
1666template <
class VectorType>
1675template <
class VectorType>
1691template <
class VectorType>
1710template <
class VectorType>
1727template <
class VectorType>
1743template <
class VectorType>
1744template <
typename Number>
1747 const std::vector<Number> &
values)
1751 add(indices.size(), indices.data(),
values.data());
1756template <
class VectorType>
1757template <
typename Number>
1764 const size_type n_indices = indices.size();
1765 for (
size_type i = 0; i < n_indices; ++i)
1766 (*
this)(indices[i]) +=
values(i);
1771template <
class VectorType>
1772template <
typename Number>
1778 for (
size_type i = 0; i < n_indices; ++i)
1779 (*
this)(indices[i]) +=
values[i];
1784template <
class VectorType>
1798template <
class VectorType>
1816template <
class VectorType>
1840template <
class VectorType>
1858template <
class VectorType>
1878template <
class VectorType>
1903template <
class VectorType>
1934template <
class VectorType>
1935template <
class BlockVector2>
1947template <
class VectorType>
1957template <
class VectorType>
1958template <
class BlockVector2>
1973template <
class VectorType>
1978 block(i).update_ghost_values();
1983template <
class VectorType>
1996template <
class VectorType>
2009template <
class VectorType>
2010template <
class VectorType2>
2024template <
class VectorType>
2033 block(
b)(i) = v(index_v);
2040template <
class VectorType>
2041template <
class VectorType2>
2057template <
class VectorType>
2071template <
class VectorType>
2087template <
class VectorType>
2091 const std::pair<unsigned int, size_type> local_index =
2093 return components[local_index.first](local_index.second);
2098template <
class VectorType>
2102 const std::pair<unsigned int, size_type> local_index =
2104 return components[local_index.first](local_index.second);
2109template <
class VectorType>
2118template <
class VectorType>
2127template <
typename VectorType>
2128template <
typename OtherNumber>
2131 const std::vector<size_type> &indices,
2132 std::vector<OtherNumber> &
values)
const
2134 for (
size_type i = 0; i < indices.size(); ++i)
2135 values[i] =
operator()(indices[i]);
2140template <
typename VectorType>
2141template <
typename ForwardIterator,
typename OutputIterator>
2144 ForwardIterator indices_begin,
2145 const ForwardIterator indices_end,
2146 OutputIterator values_begin)
const
2148 while (indices_begin != indices_end)
bool operator!=(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
bool operator==(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
size_type block_size(const unsigned int i) const
size_type total_size() const
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
unsigned int size() const
size_type local_to_global(const unsigned int block, const size_type index) const
size_type block_start(const unsigned int i) const
std::pair< unsigned int, size_type > global_to_local(const size_type i) const
std::enable_if< std::is_floating_point< T >::value &&std::is_floating_point< U >::value, typenameProductType< std::complex< T >, std::complex< U > >::type >::type operator*(const std::complex< T > &left, const std::complex< U > &right)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
BlockVectorBase & operator+=(const BlockVectorBase &V)
BlockVectorBase()=default
void extract_subvector_to(const std::vector< size_type > &indices, std::vector< OtherNumber > &values) const
value_type mean_value() const
void add(const std::vector< size_type > &indices, const std::vector< Number > &values)
::internal::BlockVectorIterators::Iterator< BlockVectorBase, false > iterator
BlockVectorBase & operator/=(const value_type factor)
unsigned int n_blocks() const
real_type norm_sqr() const
const value_type * const_pointer
typename BlockType::const_reference const_reference
void update_ghost_values() const
std::size_t memory_consumption() const
real_type l1_norm() const
types::global_dof_index size_type
real_type linfty_norm() const
value_type add_and_dot(const value_type a, const BlockVectorBase &V, const BlockVectorBase &W)
typename BlockType::value_type value_type
value_type operator*(const BlockVectorBase &V) const
BlockVectorBase & operator=(const value_type s)
#define Assert(cond, exc)
BlockVectorBase & operator*=(const value_type factor)
void sadd(const value_type s, const BlockVectorBase &V)
std::vector< VectorType > components
static ::ExceptionBase & ExcPointerToDifferentVectors()
Expression operator>=(const Expression &lhs, const Expression &rhs)
bool in_local_range(const size_type global_index) const
#define AssertIsFinite(number)
::internal::BlockVectorIterators::Iterator< BlockVectorBase, true > const_iterator
BlockVectorBase(BlockVectorBase &&) noexcept=default
#define AssertDimension(dim1, dim2)
BlockVectorBase(const BlockVectorBase &)=default
typename BlockType::reference reference
size_type next_break_forward
value_type operator[](const size_type i) const
unsigned int current_block
BlockIndices block_indices
#define AssertIndexRange(index, range)
#define DeclExceptionMsg(Exception, defaulttext)
typename BlockType::real_type real_type
Expression operator>(const Expression &lhs, const Expression &rhs)
void scale(const BlockVector2 &v)
void compress(::VectorOperation::values operation)
BlockType & block(const unsigned int i)
static ::ExceptionBase & ExcDivideByZero()
static ::ExceptionBase & ExcDifferentBlockIndices()
Expression operator<=(const Expression &lhs, const Expression &rhs)
real_type l2_norm() const
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
value_type operator()(const size_type i) const
size_type next_break_backward
IndexSet locally_owned_elements() const
bool is_non_negative() const
BlockVectorBase & operator-=(const BlockVectorBase &V)
bool operator==(const BlockVectorBase< VectorType2 > &v) const
std::size_t locally_owned_size() const
const BlockIndices & get_block_indices() const
size_type index_within_block
void equ(const value_type a, const BlockVector2 &V)
bool operator==(const Iterator< BlockVectorType, OtherConstness > &i) const
static std::true_type check_for_block_vector(const BlockVectorBase< T > *)
dereference_type operator[](const difference_type d) const
Iterator & operator=(const Iterator &c)
bool operator<(const Iterator< BlockVectorType, OtherConstness > &i) const
Iterator(BlockVector &parent, const size_type global_index, const size_type current_block, const size_type index_within_block, const size_type next_break_forward, const size_type next_break_backward)
Iterator(const Iterator< BlockVectorType, !Constness > &c)
Iterator(const Iterator &c)
dereference_type operator*() const
Iterator operator-(const difference_type &d) const
difference_type operator-(const Iterator< BlockVectorType, OtherConstness > &i) const
std::random_access_iterator_tag iterator_category
typename std::conditional< Constness, value_type, typename BlockVectorType::BlockType::reference >::type dereference_type
Iterator(BlockVector &parent, const size_type global_index)
bool operator>=(const Iterator< BlockVectorType, OtherConstness > &i) const
static std::false_type check_for_block_vector(...)
typename std::conditional< Constness, const typename BlockVectorType::value_type, typename BlockVectorType::value_type >::type value_type
Iterator & operator-=(const difference_type &d)
std::ptrdiff_t difference_type
bool operator<=(const Iterator< BlockVectorType, OtherConstness > &i) const
typename BlockVectorType::reference reference
Iterator operator+(const difference_type &d) const
Iterator & operator+=(const difference_type &d)
bool operator!=(const Iterator< BlockVectorType, OtherConstness > &i) const
bool operator>(const Iterator< BlockVectorType, OtherConstness > &i) const
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
SymmetricTensor< 2, dim, Number > C(const Tensor< 2, dim, Number > &F)
Tensor< 2, dim, Number > w(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
T sum(const T &t, const MPI_Comm &mpi_communicator)
const types::global_dof_index invalid_size_type
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
unsigned int global_dof_index
BarycentricPolynomial< dim, Number1 > operator-(const Number2 &a, const BarycentricPolynomial< dim, Number1 > &bp)
BarycentricPolynomial< dim, Number1 > operator+(const Number2 &a, const BarycentricPolynomial< dim, Number1 > &bp)
SynchronousIterators< Iterators > operator++(SynchronousIterators< Iterators > &a)
bool operator<(const SynchronousIterators< Iterators > &a, const SynchronousIterators< Iterators > &b)