16 #ifndef dealii_block_vector_base_h
17 #define dealii_block_vector_base_h
36 #include <type_traits>
50 using has_block_t = decltype(std::declval<const T>().block(0));
53 constexpr
bool has_block = internal::is_supported_operation<has_block_t, T>;
60 internal::is_supported_operation<has_n_blocks_t, T>;
80 template <
typename VectorType>
89 static const bool value = internal::is_block_vector<VectorType>;
94 template <
typename VectorType>
104 namespace BlockVectorIterators
121 template <
typename BlockVectorType,
bool Constness>
136 typename std::conditional<Constness,
137 const typename BlockVectorType::value_type,
138 typename BlockVectorType::value_type>::type;
161 typename BlockVectorType::BlockType::reference>::type;
168 conditional<Constness, const BlockVectorType, BlockVectorType>::type;
263 template <
bool OtherConstness>
271 template <
bool OtherConstness>
280 template <
bool OtherConstness>
287 template <
bool OtherConstness>
294 template <
bool OtherConstness>
301 template <
bool OtherConstness>
308 template <
bool OtherConstness>
350 "Your program tried to compare iterators pointing to "
351 "different block vectors. There is no reasonable way "
397 template <
typename,
bool>
441 template <
typename VectorType>
443 public ReadVector<typename VectorType::value_type>
651 template <typename OtherNumber>
654 std::vector<OtherNumber> &
values) const;
687 template <typename ForwardIterator, typename OutputIterator>
690 const ForwardIterator indices_end,
691 OutputIterator values_begin) const;
717 template <typename VectorType2>
725 operator=(const VectorType &v);
731 template <typename VectorType2>
840 template <typename Number>
848 template <typename Number>
857 template <typename Number>
935 template <class BlockVector2>
942 template <class BlockVector2>
973 template <typename
N,
bool C>
974 friend class ::
internal::BlockVectorIterators::Iterator;
989 namespace BlockVectorIterators
991 template <
typename BlockVectorType,
bool Constness>
992 inline Iterator<BlockVectorType, Constness>::Iterator(
993 const Iterator<BlockVectorType, Constness> &c)
996 , current_block(c.current_block)
997 , index_within_block(c.index_within_block)
998 , next_break_forward(c.next_break_forward)
999 , next_break_backward(c.next_break_backward)
1004 template <
typename BlockVectorType,
bool Constness>
1005 inline Iterator<BlockVectorType, Constness>::Iterator(
1006 const Iterator<BlockVectorType, !Constness> &c)
1009 , current_block(c.current_block)
1010 , index_within_block(c.index_within_block)
1011 , next_break_forward(c.next_break_forward)
1012 , next_break_backward(c.next_break_backward)
1017 static_assert(Constness ==
true,
1018 "Constructing a non-const iterator from a const iterator "
1019 "does not make sense.");
1024 template <
typename BlockVectorType,
bool Constness>
1025 inline Iterator<BlockVectorType, Constness>::Iterator(
1034 , current_block(current_block)
1035 , index_within_block(index_within_block)
1036 , next_break_forward(next_break_forward)
1037 , next_break_backward(next_break_backward)
1042 template <
typename BlockVectorType,
bool Constness>
1043 inline Iterator<BlockVectorType, Constness> &
1044 Iterator<BlockVectorType, Constness>::operator=(
const Iterator &c)
1048 index_within_block = c.index_within_block;
1049 current_block = c.current_block;
1050 next_break_forward = c.next_break_forward;
1051 next_break_backward = c.next_break_backward;
1058 template <
typename BlockVectorType,
bool Constness>
1059 inline typename Iterator<BlockVectorType, Constness>::dereference_type
1062 return parent->
block(current_block)(index_within_block);
1067 template <
typename BlockVectorType,
bool Constness>
1068 inline typename Iterator<BlockVectorType, Constness>::dereference_type
1069 Iterator<BlockVectorType, Constness>::operator[](
1070 const difference_type
d)
const
1079 return parent->
block(current_block)(index_within_block +
d);
1093 template <
typename BlockVectorType,
bool Constness>
1094 inline Iterator<BlockVectorType, Constness> &
1103 template <
typename BlockVectorType,
bool Constness>
1104 inline Iterator<BlockVectorType, Constness>
1107 const Iterator old_value = *
this;
1114 template <
typename BlockVectorType,
bool Constness>
1115 inline Iterator<BlockVectorType, Constness> &
1116 Iterator<BlockVectorType, Constness>::operator--()
1124 template <
typename BlockVectorType,
bool Constness>
1125 inline Iterator<BlockVectorType, Constness>
1126 Iterator<BlockVectorType, Constness>::operator--(
int)
1128 const Iterator old_value = *
this;
1135 template <
typename BlockVectorType,
bool Constness>
1136 template <
bool OtherConstness>
1139 const Iterator<BlockVectorType, OtherConstness> &i)
const
1141 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1148 template <
typename BlockVectorType,
bool Constness>
1149 template <
bool OtherConstness>
1152 const Iterator<BlockVectorType, OtherConstness> &i)
const
1154 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1161 template <
typename BlockVectorType,
bool Constness>
1162 template <
bool OtherConstness>
1165 const Iterator<BlockVectorType, OtherConstness> &i)
const
1167 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1174 template <
typename BlockVectorType,
bool Constness>
1175 template <
bool OtherConstness>
1178 const Iterator<BlockVectorType, OtherConstness> &i)
const
1180 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1187 template <
typename BlockVectorType,
bool Constness>
1188 template <
bool OtherConstness>
1191 const Iterator<BlockVectorType, OtherConstness> &i)
const
1193 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1200 template <
typename BlockVectorType,
bool Constness>
1201 template <
bool OtherConstness>
1204 const Iterator<BlockVectorType, OtherConstness> &i)
const
1206 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1213 template <
typename BlockVectorType,
bool Constness>
1214 template <
bool OtherConstness>
1215 inline typename Iterator<BlockVectorType, Constness>::difference_type
1217 const Iterator<BlockVectorType, OtherConstness> &i)
const
1219 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1222 static_cast<signed int>(i.global_index));
1227 template <
typename BlockVectorType,
bool Constness>
1228 inline Iterator<BlockVectorType, Constness>
1230 const difference_type &
d)
const
1239 return Iterator(*parent,
1242 index_within_block +
d,
1244 next_break_backward);
1254 template <
typename BlockVectorType,
bool Constness>
1255 inline Iterator<BlockVectorType, Constness>
1257 const difference_type &
d)
const
1266 return Iterator(*parent,
1269 index_within_block -
d,
1271 next_break_backward);
1281 template <
typename BlockVectorType,
bool Constness>
1282 inline Iterator<BlockVectorType, Constness> &
1283 Iterator<BlockVectorType, Constness>::operator+=(
const difference_type &
d)
1294 index_within_block +=
d;
1307 template <
typename BlockVectorType,
bool Constness>
1308 inline Iterator<BlockVectorType, Constness> &
1309 Iterator<BlockVectorType, Constness>::operator-=(
const difference_type &
d)
1320 index_within_block -=
d;
1332 template <
typename BlockVectorType,
bool Constness>
1333 Iterator<BlockVectorType, Constness>::Iterator(
BlockVector &parent,
1346 const std::pair<size_type, size_type> indices =
1348 current_block = indices.first;
1349 index_within_block = indices.second;
1351 next_break_backward =
1353 next_break_forward =
1361 this->global_index = parent.
size();
1363 index_within_block = 0;
1371 template <
typename BlockVectorType,
bool Constness>
1373 Iterator<BlockVectorType, Constness>::move_forward()
1376 ++index_within_block;
1381 index_within_block = 0;
1386 next_break_backward = next_break_forward + 1;
1390 next_break_forward +=
1405 template <
typename BlockVectorType,
bool Constness>
1407 Iterator<BlockVectorType, Constness>::move_backward()
1410 --index_within_block;
1411 else if (current_block != 0)
1416 index_within_block =
1421 next_break_forward = next_break_backward - 1;
1424 next_break_backward -=
1433 next_break_forward = 0;
1434 next_break_backward = 0;
1447 template <
typename VectorType>
1456 template <
typename VectorType>
1460 std::size_t local_size = 0;
1462 local_size +=
block(
b).locally_owned_size();
1468 template <
typename VectorType>
1489 template <
typename VectorType>
1497 template <
typename VectorType>
1508 template <
typename VectorType>
1519 template <
typename VectorType>
1527 template <
typename VectorType>
1531 std::vector<size_type> sizes(
n_blocks());
1534 sizes[i] =
block(i).size();
1541 template <
typename VectorType>
1545 for (
unsigned int i = 0; i <
n_blocks(); ++i)
1546 block(i).compress(operation);
1551 template <
typename VectorType>
1560 template <
typename VectorType>
1568 template <
typename VectorType>
1577 template <
typename VectorType>
1585 template <
typename VectorType>
1589 const std::pair<size_type, size_type> local_index =
1596 template <
typename VectorType>
1609 template <
typename VectorType>
1622 template <
typename VectorType>
1638 template <
typename VectorType>
1651 template <
typename VectorType>
1668 template <
typename VectorType>
1681 template <
typename VectorType>
1690 template <
typename VectorType>
1706 template <
typename VectorType>
1725 template <
typename VectorType>
1742 template <
typename VectorType>
1758 template <
typename VectorType>
1759 template <
typename Number>
1762 const std::vector<Number> &
values)
1766 add(indices.size(), indices.data(),
values.data());
1771 template <
typename VectorType>
1772 template <
typename Number>
1779 const size_type n_indices = indices.size();
1780 for (
size_type i = 0; i < n_indices; ++i)
1781 (*
this)(indices[i]) +=
values(i);
1786 template <
typename VectorType>
1787 template <
typename Number>
1793 for (
size_type i = 0; i < n_indices; ++i)
1794 (*
this)(indices[i]) +=
values[i];
1799 template <
typename VectorType>
1813 template <
typename VectorType>
1831 template <
typename VectorType>
1855 template <
typename VectorType>
1873 template <
typename VectorType>
1893 template <
typename VectorType>
1918 template <
typename VectorType>
1949 template <
typename VectorType>
1950 template <
class BlockVector2>
1962 template <
typename VectorType>
1972 template <
typename VectorType>
1973 template <
class BlockVector2>
1988 template <
typename VectorType>
1993 block(i).update_ghost_values();
1998 template <
typename VectorType>
2011 template <
typename VectorType>
2024 template <
typename VectorType>
2025 template <
typename VectorType2>
2039 template <
typename VectorType>
2048 block(
b)(i) = v(index_v);
2055 template <
typename VectorType>
2056 template <
typename VectorType2>
2072 template <
typename VectorType>
2086 template <
typename VectorType>
2102 template <
typename VectorType>
2106 const std::pair<unsigned int, size_type> local_index =
2108 return components[local_index.first](local_index.second);
2113 template <
typename VectorType>
2117 const std::pair<unsigned int, size_type> local_index =
2119 return components[local_index.first](local_index.second);
2124 template <
typename VectorType>
2133 template <
typename VectorType>
2142 template <
typename VectorType>
2143 template <
typename OtherNumber>
2146 const std::vector<size_type> &indices,
2147 std::vector<OtherNumber> &
values)
const
2149 for (
size_type i = 0; i < indices.size(); ++i)
2150 values[i] =
operator()(indices[i]);
2155 template <
typename VectorType>
2162 for (
unsigned int i = 0; i < indices.
size(); ++i)
2165 entries[i] = (*this)[indices[i]];
2171 template <
typename VectorType>
2172 template <
typename ForwardIterator,
typename OutputIterator>
2175 ForwardIterator indices_begin,
2176 const ForwardIterator indices_end,
2177 OutputIterator values_begin)
const
2179 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
BlockVectorBase()=default
BlockVectorBase & operator/=(const value_type factor)
void extract_subvector_to(const std::vector< size_type > &indices, std::vector< OtherNumber > &values) const
const BlockIndices & get_block_indices() const
value_type mean_value() const
virtual size_type size() const override
void add(const std::vector< size_type > &indices, const std::vector< Number > &values)
BlockVectorBase & operator+=(const BlockVectorBase &V)
::internal::BlockVectorIterators::Iterator< BlockVectorBase, false > iterator
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
BlockVectorBase & operator=(const value_type s)
value_type operator*(const BlockVectorBase &V) const
void compress(VectorOperation::values operation)
void sadd(const value_type s, const BlockVectorBase &V)
BlockVectorBase & operator*=(const value_type factor)
std::vector< VectorType > components
bool in_local_range(const size_type global_index) const
::internal::BlockVectorIterators::Iterator< BlockVectorBase, true > const_iterator
BlockVectorBase(BlockVectorBase &&) noexcept=default
BlockVectorBase(const BlockVectorBase &)=default
typename BlockType::reference reference
value_type operator[](const size_type i) const
BlockIndices block_indices
typename BlockType::real_type real_type
void scale(const BlockVector2 &v)
BlockVectorBase & operator-=(const BlockVectorBase &V)
real_type l2_norm() const
value_type operator()(const size_type i) const
IndexSet locally_owned_elements() const
bool is_non_negative() const
BlockType & block(const unsigned int i)
bool operator==(const BlockVectorBase< VectorType2 > &v) const
std::size_t locally_owned_size() const
void equ(const value_type a, const BlockVector2 &V)
bool operator==(const Iterator< BlockVectorType, OtherConstness > &i) const
Iterator & operator-=(const difference_type &d)
dereference_type operator[](const difference_type d) const
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
Iterator & operator+=(const difference_type &d)
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)
types::global_dof_index size_type
size_type next_break_forward
bool operator>=(const Iterator< BlockVectorType, OtherConstness > &i) const
Iterator & operator=(const Iterator &c)
unsigned int current_block
typename std::conditional< Constness, const typename BlockVectorType::value_type, typename BlockVectorType::value_type >::type value_type
size_type next_break_backward
std::ptrdiff_t difference_type
size_type index_within_block
bool operator<=(const Iterator< BlockVectorType, OtherConstness > &i) const
typename BlockVectorType::reference reference
Iterator operator+(const difference_type &d) const
bool operator!=(const Iterator< BlockVectorType, OtherConstness > &i) const
bool operator>(const Iterator< BlockVectorType, OtherConstness > &i) const
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 & ExcPointerToDifferentVectors()
static ::ExceptionBase & ExcDivideByZero()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
#define Assert(cond, exc)
#define AssertIsFinite(number)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcDifferentBlockIndices()
Expression operator>=(const Expression &lhs, const Expression &rhs)
Expression operator>(const Expression &lhs, const Expression &rhs)
Expression operator<=(const Expression &lhs, const Expression &rhs)
std::enable_if_t< IsBlockVector< VectorType >::value, unsigned int > n_blocks(const VectorType &vector)
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
SymmetricTensor< 2, dim, Number > C(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
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)
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)
constexpr bool has_n_blocks
decltype(std::declval< const T >().n_blocks()) has_n_blocks_t
decltype(std::declval< const T >().block(0)) has_block_t
constexpr bool is_block_vector
const types::global_dof_index invalid_size_type
unsigned int global_dof_index
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
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)