16 #ifndef dealii_block_vector_base_h
17 #define dealii_block_vector_base_h
35 #include <type_traits>
49 using has_block_t = decltype(std::declval<T const>().block(0));
52 constexpr
bool has_block = internal::is_supported_operation<has_block_t, T>;
59 internal::is_supported_operation<has_n_blocks_t, T>;
79 template <
typename VectorType>
88 static const bool value = internal::is_block_vector<VectorType>;
93 template <
typename VectorType>
103 namespace BlockVectorIterators
120 template <
class BlockVectorType,
bool Constness>
135 typename std::conditional<Constness,
136 const typename BlockVectorType::value_type,
137 typename BlockVectorType::value_type>::type;
153 typename BlockVectorType::BlockType::reference>::type;
160 conditional<Constness, const BlockVectorType, BlockVectorType>::type;
255 template <
bool OtherConstness>
263 template <
bool OtherConstness>
272 template <
bool OtherConstness>
279 template <
bool OtherConstness>
286 template <
bool OtherConstness>
293 template <
bool OtherConstness>
300 template <
bool OtherConstness>
342 "Your program tried to compare iterators pointing to "
343 "different block vectors. There is no reasonable way "
389 template <
typename,
bool>
433 template <
class VectorType>
642 template <typename OtherNumber>
645 std::vector<OtherNumber> &
values) const;
674 template <typename ForwardIterator, typename OutputIterator>
677 const ForwardIterator indices_end,
678 OutputIterator values_begin) const;
704 template <class VectorType2>
712 operator=(const VectorType &v);
718 template <class VectorType2>
827 template <typename Number>
835 template <typename Number>
844 template <typename Number>
922 template <class BlockVector2>
929 template <class BlockVector2>
960 template <typename
N,
bool C>
961 friend class ::
internal::BlockVectorIterators::Iterator;
976 namespace BlockVectorIterators
978 template <
class BlockVectorType,
bool Constness>
979 inline Iterator<BlockVectorType, Constness>::Iterator(
980 const Iterator<BlockVectorType, Constness> &c)
983 , current_block(c.current_block)
984 , index_within_block(c.index_within_block)
985 , next_break_forward(c.next_break_forward)
986 , next_break_backward(c.next_break_backward)
991 template <
class 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 static_assert(Constness ==
true,
1005 "Constructing a non-const iterator from a const iterator "
1006 "does not make sense.");
1011 template <
class BlockVectorType,
bool Constness>
1012 inline Iterator<BlockVectorType, Constness>::Iterator(
1021 , current_block(current_block)
1022 , index_within_block(index_within_block)
1023 , next_break_forward(next_break_forward)
1024 , next_break_backward(next_break_backward)
1029 template <
class BlockVectorType,
bool Constness>
1030 inline Iterator<BlockVectorType, Constness> &
1031 Iterator<BlockVectorType, Constness>::operator=(
const Iterator &c)
1035 index_within_block = c.index_within_block;
1036 current_block = c.current_block;
1037 next_break_forward = c.next_break_forward;
1038 next_break_backward = c.next_break_backward;
1045 template <
class BlockVectorType,
bool Constness>
1046 inline typename Iterator<BlockVectorType, Constness>::dereference_type
1049 return parent->
block(current_block)(index_within_block);
1054 template <
class BlockVectorType,
bool Constness>
1055 inline typename Iterator<BlockVectorType, Constness>::dereference_type
1056 Iterator<BlockVectorType, Constness>::operator[](
1057 const difference_type
d)
const
1066 return parent->
block(current_block)(index_within_block +
d);
1080 template <
class BlockVectorType,
bool Constness>
1081 inline Iterator<BlockVectorType, Constness> &
1090 template <
class BlockVectorType,
bool Constness>
1091 inline Iterator<BlockVectorType, Constness>
1094 const Iterator old_value = *
this;
1101 template <
class BlockVectorType,
bool Constness>
1102 inline Iterator<BlockVectorType, Constness> &
1103 Iterator<BlockVectorType, Constness>::operator--()
1111 template <
class BlockVectorType,
bool Constness>
1112 inline Iterator<BlockVectorType, Constness>
1113 Iterator<BlockVectorType, Constness>::operator--(
int)
1115 const Iterator old_value = *
this;
1122 template <
class BlockVectorType,
bool Constness>
1123 template <
bool OtherConstness>
1126 const Iterator<BlockVectorType, OtherConstness> &i)
const
1128 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1135 template <
class BlockVectorType,
bool Constness>
1136 template <
bool OtherConstness>
1139 const Iterator<BlockVectorType, OtherConstness> &i)
const
1141 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1148 template <
class BlockVectorType,
bool Constness>
1149 template <
bool OtherConstness>
1152 const Iterator<BlockVectorType, OtherConstness> &i)
const
1154 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1161 template <
class BlockVectorType,
bool Constness>
1162 template <
bool OtherConstness>
1165 const Iterator<BlockVectorType, OtherConstness> &i)
const
1167 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1174 template <
class BlockVectorType,
bool Constness>
1175 template <
bool OtherConstness>
1178 const Iterator<BlockVectorType, OtherConstness> &i)
const
1180 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1187 template <
class BlockVectorType,
bool Constness>
1188 template <
bool OtherConstness>
1191 const Iterator<BlockVectorType, OtherConstness> &i)
const
1193 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1200 template <
class BlockVectorType,
bool Constness>
1201 template <
bool OtherConstness>
1202 inline typename Iterator<BlockVectorType, Constness>::difference_type
1204 const Iterator<BlockVectorType, OtherConstness> &i)
const
1206 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1209 static_cast<signed int>(i.global_index));
1214 template <
class BlockVectorType,
bool Constness>
1215 inline Iterator<BlockVectorType, Constness>
1217 const difference_type &
d)
const
1226 return Iterator(*parent,
1229 index_within_block +
d,
1231 next_break_backward);
1241 template <
class BlockVectorType,
bool Constness>
1242 inline Iterator<BlockVectorType, Constness>
1244 const difference_type &
d)
const
1253 return Iterator(*parent,
1256 index_within_block -
d,
1258 next_break_backward);
1268 template <
class BlockVectorType,
bool Constness>
1269 inline Iterator<BlockVectorType, Constness> &
1270 Iterator<BlockVectorType, Constness>::operator+=(
const difference_type &
d)
1281 index_within_block +=
d;
1294 template <
class BlockVectorType,
bool Constness>
1295 inline Iterator<BlockVectorType, Constness> &
1296 Iterator<BlockVectorType, Constness>::operator-=(
const difference_type &
d)
1307 index_within_block -=
d;
1319 template <
class BlockVectorType,
bool Constness>
1320 Iterator<BlockVectorType, Constness>::Iterator(
BlockVector & parent,
1333 const std::pair<size_type, size_type> indices =
1335 current_block = indices.first;
1336 index_within_block = indices.second;
1338 next_break_backward =
1340 next_break_forward =
1348 this->global_index = parent.
size();
1350 index_within_block = 0;
1358 template <
class BlockVectorType,
bool Constness>
1360 Iterator<BlockVectorType, Constness>::move_forward()
1363 ++index_within_block;
1368 index_within_block = 0;
1373 next_break_backward = next_break_forward + 1;
1377 next_break_forward +=
1392 template <
class BlockVectorType,
bool Constness>
1394 Iterator<BlockVectorType, Constness>::move_backward()
1397 --index_within_block;
1398 else if (current_block != 0)
1403 index_within_block =
1408 next_break_forward = next_break_backward - 1;
1411 next_break_backward -=
1420 next_break_forward = 0;
1421 next_break_backward = 0;
1434 template <
class VectorType>
1443 template <
class VectorType>
1447 std::size_t local_size = 0;
1449 local_size +=
block(
b).locally_owned_size();
1455 template <
class VectorType>
1476 template <
class VectorType>
1484 template <
class VectorType>
1495 template <
class VectorType>
1506 template <
class VectorType>
1514 template <
class VectorType>
1518 std::vector<size_type> sizes(
n_blocks());
1521 sizes[i] =
block(i).size();
1528 template <
class VectorType>
1533 for (
unsigned int i = 0; i <
n_blocks(); ++i)
1534 block(i).compress(operation);
1539 template <
class VectorType>
1548 template <
class VectorType>
1556 template <
class VectorType>
1565 template <
class VectorType>
1573 template <
class VectorType>
1577 const std::pair<size_type, size_type> local_index =
1584 template <
class VectorType>
1597 template <
class VectorType>
1610 template <
class VectorType>
1626 template <
class VectorType>
1639 template <
class VectorType>
1656 template <
class VectorType>
1669 template <
class VectorType>
1678 template <
class VectorType>
1694 template <
class VectorType>
1713 template <
class VectorType>
1730 template <
class VectorType>
1746 template <
class VectorType>
1747 template <
typename Number>
1750 const std::vector<Number> &
values)
1754 add(indices.size(), indices.data(),
values.data());
1759 template <
class VectorType>
1760 template <
typename Number>
1767 const size_type n_indices = indices.size();
1768 for (
size_type i = 0; i < n_indices; ++i)
1769 (*
this)(indices[i]) +=
values(i);
1774 template <
class VectorType>
1775 template <
typename Number>
1781 for (
size_type i = 0; i < n_indices; ++i)
1782 (*
this)(indices[i]) +=
values[i];
1787 template <
class VectorType>
1801 template <
class VectorType>
1819 template <
class VectorType>
1843 template <
class VectorType>
1861 template <
class VectorType>
1881 template <
class VectorType>
1906 template <
class VectorType>
1937 template <
class VectorType>
1938 template <
class BlockVector2>
1950 template <
class VectorType>
1960 template <
class VectorType>
1961 template <
class BlockVector2>
1976 template <
class VectorType>
1981 block(i).update_ghost_values();
1986 template <
class VectorType>
1999 template <
class VectorType>
2012 template <
class VectorType>
2013 template <
class VectorType2>
2027 template <
class VectorType>
2036 block(
b)(i) = v(index_v);
2043 template <
class VectorType>
2044 template <
class VectorType2>
2060 template <
class VectorType>
2074 template <
class VectorType>
2090 template <
class VectorType>
2094 const std::pair<unsigned int, size_type> local_index =
2096 return components[local_index.first](local_index.second);
2101 template <
class VectorType>
2105 const std::pair<unsigned int, size_type> local_index =
2107 return components[local_index.first](local_index.second);
2112 template <
class VectorType>
2121 template <
class VectorType>
2130 template <
typename VectorType>
2131 template <
typename OtherNumber>
2134 const std::vector<size_type> &indices,
2135 std::vector<OtherNumber> &
values)
const
2137 for (
size_type i = 0; i < indices.size(); ++i)
2138 values[i] =
operator()(indices[i]);
2143 template <
typename VectorType>
2144 template <
typename ForwardIterator,
typename OutputIterator>
2147 ForwardIterator indices_begin,
2148 const ForwardIterator indices_end,
2149 OutputIterator values_begin)
const
2151 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
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 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)
void compress(::VectorOperation::values operation)
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< T >::value &&std::is_floating_point< U >::value, 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< T >::value, 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)
decltype(std::declval< T const >().block(0)) has_block_t
constexpr bool has_n_blocks
decltype(std::declval< T const >().n_blocks()) has_n_blocks_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)