16 #ifndef dealii_block_vector_base_h
17 #define dealii_block_vector_base_h
66 template <
typename VectorType>
107 template <
typename VectorType>
119 namespace BlockVectorIterators
138 template <
class BlockVectorType,
bool Constness>
153 typename std::conditional<Constness,
154 const typename BlockVectorType::value_type,
155 typename BlockVectorType::value_type>::type;
170 typename BlockVectorType::BlockType::reference>::type;
177 conditional<Constness, const BlockVectorType, BlockVectorType>::type;
270 template <
bool OtherConstness>
278 template <
bool OtherConstness>
287 template <
bool OtherConstness>
294 template <
bool OtherConstness>
301 template <
bool OtherConstness>
308 template <
bool OtherConstness>
315 template <
bool OtherConstness>
357 "Your program tried to compare iterators pointing to "
358 "different block vectors. There is no reasonable way "
404 template <
typename,
bool>
449 template <
class VectorType>
533 block(const
unsigned int i);
539 block(const
unsigned int i) const;
648 template <typename OtherNumber>
651 std::vector<OtherNumber> & values) const;
680 template <typename ForwardIterator, typename OutputIterator>
683 const ForwardIterator indices_end,
684 OutputIterator values_begin) const;
710 template <class VectorType2>
724 template <class VectorType2>
832 template <typename Number>
834 add(const std::vector<
size_type> &indices, const std::vector<Number> &values);
840 template <typename Number>
849 template <typename Number>
853 const Number * values);
927 template <class BlockVector2>
929 scale(const BlockVector2 &v);
934 template <class BlockVector2>
965 template <typename
N,
bool C>
981 namespace BlockVectorIterators
983 template <
class BlockVectorType,
bool Constness>
985 const Iterator<BlockVectorType, Constness> &c)
988 , current_block(c.current_block)
989 , index_within_block(c.index_within_block)
990 , next_break_forward(c.next_break_forward)
991 , next_break_backward(c.next_break_backward)
996 template <
class BlockVectorType,
bool Constness>
998 const Iterator<BlockVectorType, !Constness> &c)
1001 , current_block(c.current_block)
1002 , index_within_block(c.index_within_block)
1003 , next_break_forward(c.next_break_forward)
1004 , next_break_backward(c.next_break_backward)
1009 static_assert(Constness ==
true,
1010 "Constructing a non-const iterator from a const iterator "
1011 "does not make sense.");
1016 template <
class BlockVectorType,
bool Constness>
1026 , current_block(current_block)
1027 , index_within_block(index_within_block)
1028 , next_break_forward(next_break_forward)
1029 , next_break_backward(next_break_backward)
1034 template <
class BlockVectorType,
bool Constness>
1035 inline Iterator<BlockVectorType, Constness> &
1036 Iterator<BlockVectorType, Constness>::operator=(
const Iterator &c)
1040 index_within_block = c.index_within_block;
1041 current_block = c.current_block;
1042 next_break_forward = c.next_break_forward;
1043 next_break_backward = c.next_break_backward;
1050 template <
class BlockVectorType,
bool Constness>
1051 inline typename Iterator<BlockVectorType, Constness>::dereference_type
1054 return parent->
block(current_block)(index_within_block);
1059 template <
class BlockVectorType,
bool Constness>
1060 inline typename Iterator<BlockVectorType, Constness>::dereference_type
1061 Iterator<BlockVectorType, Constness>::
1062 operator[](
const difference_type
d)
const
1071 return parent->
block(current_block)(index_within_block +
d);
1085 template <
class BlockVectorType,
bool Constness>
1086 inline Iterator<BlockVectorType, Constness> &
1095 template <
class BlockVectorType,
bool Constness>
1096 inline Iterator<BlockVectorType, Constness>
1106 template <
class BlockVectorType,
bool Constness>
1107 inline Iterator<BlockVectorType, Constness> &
1108 Iterator<BlockVectorType, Constness>::operator--()
1116 template <
class BlockVectorType,
bool Constness>
1117 inline Iterator<BlockVectorType, Constness>
1118 Iterator<BlockVectorType, Constness>::operator--(
int)
1127 template <
class BlockVectorType,
bool Constness>
1128 template <
bool OtherConstness>
1131 operator==(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1133 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1140 template <
class BlockVectorType,
bool Constness>
1141 template <
bool OtherConstness>
1144 operator!=(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1146 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1153 template <
class BlockVectorType,
bool Constness>
1154 template <
bool OtherConstness>
1157 operator<(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1159 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1166 template <
class BlockVectorType,
bool Constness>
1167 template <
bool OtherConstness>
1170 operator<=(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1172 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1179 template <
class BlockVectorType,
bool Constness>
1180 template <
bool OtherConstness>
1183 operator>(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1185 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1192 template <
class BlockVectorType,
bool Constness>
1193 template <
bool OtherConstness>
1196 operator>=(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1198 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1205 template <
class BlockVectorType,
bool Constness>
1206 template <
bool OtherConstness>
1207 inline typename Iterator<BlockVectorType, Constness>::difference_type
1209 operator-(
const Iterator<BlockVectorType, OtherConstness> &i)
const
1211 Assert(parent == i.parent, ExcPointerToDifferentVectors());
1214 static_cast<signed int>(i.global_index));
1219 template <
class BlockVectorType,
bool Constness>
1220 inline Iterator<BlockVectorType, Constness>
1234 index_within_block +
d,
1236 next_break_backward);
1246 template <
class BlockVectorType,
bool Constness>
1247 inline Iterator<BlockVectorType, Constness>
1261 index_within_block -
d,
1263 next_break_backward);
1273 template <
class BlockVectorType,
bool Constness>
1274 inline Iterator<BlockVectorType, Constness> &
1275 Iterator<BlockVectorType, Constness>::operator+=(
const difference_type &
d)
1286 index_within_block +=
d;
1299 template <
class BlockVectorType,
bool Constness>
1300 inline Iterator<BlockVectorType, Constness> &
1301 Iterator<BlockVectorType, Constness>::operator-=(
const difference_type &
d)
1312 index_within_block -=
d;
1324 template <
class BlockVectorType,
bool Constness>
1338 const std::pair<size_type, size_type> indices =
1340 current_block = indices.first;
1341 index_within_block = indices.second;
1343 next_break_backward =
1345 next_break_forward =
1353 this->global_index = parent.
size();
1355 index_within_block = 0;
1363 template <
class BlockVectorType,
bool Constness>
1365 Iterator<BlockVectorType, Constness>::move_forward()
1368 ++index_within_block;
1373 index_within_block = 0;
1378 next_break_backward = next_break_forward + 1;
1382 next_break_forward +=
1397 template <
class BlockVectorType,
bool Constness>
1399 Iterator<BlockVectorType, Constness>::move_backward()
1402 --index_within_block;
1403 else if (current_block != 0)
1408 index_within_block =
1413 next_break_forward = next_break_backward - 1;
1416 next_break_backward -=
1425 next_break_forward = 0;
1426 next_break_backward = 0;
1439 template <
class VectorType>
1448 template <
class VectorType>
1469 template <
class VectorType>
1477 template <
class VectorType>
1488 template <
class VectorType>
1499 template <
class VectorType>
1507 template <
class VectorType>
1511 std::vector<size_type> sizes(
n_blocks());
1514 sizes[i] =
block(i).size();
1521 template <
class VectorType>
1526 for (
unsigned int i = 0; i <
n_blocks(); ++i)
1527 block(i).compress(operation);
1532 template <
class VectorType>
1541 template <
class VectorType>
1549 template <
class VectorType>
1558 template <
class VectorType>
1566 template <
class VectorType>
1570 const std::pair<size_type, size_type> local_index =
1577 template <
class VectorType>
1590 template <
class VectorType>
1603 template <
class VectorType>
1618 template <
class VectorType>
1631 template <
class VectorType>
1648 template <
class VectorType>
1661 template <
class VectorType>
1670 template <
class VectorType>
1686 template <
class VectorType>
1705 template <
class VectorType>
1722 template <
class VectorType>
1738 template <
class VectorType>
1739 template <
typename Number>
1742 const std::vector<Number> & values)
1744 Assert(indices.size() == values.size(),
1746 add(indices.size(), indices.data(), values.data());
1751 template <
class VectorType>
1752 template <
typename Number>
1755 const Vector<Number> & values)
1757 Assert(indices.size() == values.size(),
1759 const size_type n_indices = indices.size();
1760 for (
size_type i = 0; i < n_indices; ++i)
1761 (*
this)(indices[i]) += values(i);
1766 template <
class VectorType>
1767 template <
typename Number>
1771 const Number * values)
1773 for (
size_type i = 0; i < n_indices; ++i)
1774 (*
this)(indices[i]) += values[i];
1779 template <
class VectorType>
1793 template <
class VectorType>
1811 template <
class VectorType>
1835 template <
class VectorType>
1853 template <
class VectorType>
1873 template <
class VectorType>
1898 template <
class VectorType>
1929 template <
class VectorType>
1930 template <
class BlockVector2>
1942 template <
class VectorType>
1952 template <
class VectorType>
1953 template <
class BlockVector2>
1968 template <
class VectorType>
1973 block(i).update_ghost_values();
1978 template <
class VectorType>
1991 template <
class VectorType>
2004 template <
class VectorType>
2005 template <
class VectorType2>
2019 template <
class VectorType>
2028 block(
b)(i) = v(index_v);
2035 template <
class VectorType>
2036 template <
class VectorType2>
2052 template <
class VectorType>
2066 template <
class VectorType>
2082 template <
class VectorType>
2086 const std::pair<unsigned int, size_type> local_index =
2088 return components[local_index.first](local_index.second);
2093 template <
class VectorType>
2097 const std::pair<unsigned int, size_type> local_index =
2099 return components[local_index.first](local_index.second);
2104 template <
class VectorType>
2113 template <
class VectorType>
2122 template <
typename VectorType>
2123 template <
typename OtherNumber>
2126 const std::vector<size_type> &indices,
2127 std::vector<OtherNumber> & values)
const
2129 for (
size_type i = 0; i < indices.size(); ++i)
2130 values[i] =
operator()(indices[i]);
2135 template <
typename VectorType>
2136 template <
typename ForwardIterator,
typename OutputIterator>
2139 ForwardIterator indices_begin,
2140 const ForwardIterator indices_end,
2141 OutputIterator values_begin)
const
2143 while (indices_begin != indices_end)