Reference documentation for deal.II version Git 31af17f30d 2020-12-04 11:18:37 -0500
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
table.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2002 - 2020 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_table_h
17 #define dealii_table_h
18 
19 #include <deal.II/base/config.h>
20 
27 
28 #include <algorithm>
29 #include <cstddef>
30 
32 
33 // forward declaration
34 #ifndef DOXYGEN
35 template <int N, typename T>
36 class TableBase;
37 template <int N, typename T>
38 class Table;
39 template <typename T>
40 class TransposeTable;
41 template <typename T>
42 class Table<1, T>;
43 template <typename T>
44 class Table<2, T>;
45 template <typename T>
46 class Table<3, T>;
47 template <typename T>
48 class Table<4, T>;
49 template <typename T>
50 class Table<5, T>;
51 template <typename T>
52 class Table<6, T>;
53 #endif
54 
55 
56 
57 namespace internal
58 {
73  namespace TableBaseAccessors
74  {
82  template <int N, typename T, bool Constness>
83  struct Types
84  {};
85 
91  template <int N, typename T>
92  struct Types<N, T, true>
93  {
94  using value_type = const T;
95  using TableType = const TableBase<N, T>;
96 
99 
102  };
103 
109  template <int N, typename T>
110  struct Types<N, T, false>
111  {
112  using value_type = T;
114 
117 
120  };
121 
122 
159  template <int N, typename T, bool C, unsigned int P>
160  class Accessor
161  {
162  public:
164 
167 
168  using size_type = size_t;
169  using difference_type = ptrdiff_t;
170 
171  private:
177  Accessor(const TableType &table, const iterator data);
178 
179  public:
187  Accessor(const Accessor &a);
188 
192  Accessor<N, T, C, P - 1> operator[](const size_type i) const;
193 
199  size_type,
200  size_type,
201  size_type,
202  << "Index " << N - P + 1 << "has a value of " << arg1
203  << " but needs to be in the range [" << arg2 << "," << arg3
204  << "[.");
205 
206  private:
212  const TableType &table;
213  const iterator data;
214 
215  // declare some other classes
216  // as friends. make sure to
217  // work around bugs in some
218  // compilers
219  template <int N1, typename T1>
220  friend class ::Table;
221  template <int N1, typename T1, bool C1, unsigned int P1>
222  friend class Accessor;
223  friend class ::Table<N, T>;
224  friend class Accessor<N, T, C, P + 1>;
225  };
226 
227 
228 
236  template <int N, typename T, bool C>
237  class Accessor<N, T, C, 1>
238  {
239  public:
246 
249 
252 
253  using size_type = size_t;
254  using difference_type = ptrdiff_t;
255 
260 
261  private:
273  Accessor(const TableType &table, const iterator data);
274 
275  public:
283  Accessor(const Accessor &a);
284 
288  reference operator[](const size_type) const;
289 
294  size_type
295  size() const;
296 
300  iterator
301  begin() const;
302 
306  iterator
307  end() const;
308 
309  private:
315  const TableType &table;
316  const iterator data;
317 
318  // declare some other classes
319  // as friends. make sure to
320  // work around bugs in some
321  // compilers
322  template <int N1, typename T1>
323  friend class ::Table;
324  template <int N1, typename T1, bool C1, unsigned int P1>
325  friend class Accessor;
326  friend class ::Table<2, T>;
327  friend class Accessor<N, T, C, 2>;
328  };
329  } // namespace TableBaseAccessors
330 
331 } // namespace internal
332 
333 
334 
400 template <int N, typename T>
401 class TableBase : public Subscriptor
402 {
403 public:
404  using value_type = T;
405 
410 
411 
415  TableBase() = default;
416 
421  TableBase(const TableIndices<N> &sizes);
422 
428  template <typename InputIterator>
429  TableBase(const TableIndices<N> &sizes,
430  InputIterator entries,
431  const bool C_style_indexing = true);
432 
436  TableBase(const TableBase<N, T> &src);
437 
442  template <typename T2>
443  TableBase(const TableBase<N, T2> &src);
444 
448  TableBase(TableBase<N, T> &&src) noexcept;
449 
453  ~TableBase() override = default;
454 
464  operator=(const TableBase<N, T> &src);
465 
473  template <typename T2>
475  operator=(const TableBase<N, T2> &src);
476 
482  operator=(TableBase<N, T> &&src) noexcept;
483 
487  bool
488  operator==(const TableBase<N, T> &T2) const;
489 
494  void
495  reset_values();
496 
505  void
506  reinit(const TableIndices<N> &new_size,
507  const bool omit_default_initialization = false);
508 
512  size_type
513  size(const unsigned int i) const;
514 
518  const TableIndices<N> &
519  size() const;
520 
525  size_type
526  n_elements() const;
527 
532  bool
533  empty() const;
534 
571  template <typename InputIterator>
572  void
573  fill(InputIterator entries, const bool C_style_indexing = true);
574 
578  void
579  fill(const T &value);
580 
585  operator()(const TableIndices<N> &indices);
586 
595  operator()(const TableIndices<N> &indices) const;
596 
609  void
610  swap(TableBase<N, T> &v);
611 
616  std::size_t
617  memory_consumption() const;
618 
623  template <class Archive>
624  void
625  serialize(Archive &ar, const unsigned int version);
626 
627 protected:
632  size_type
633  position(const TableIndices<N> &indices) const;
634 
642  el(const TableIndices<N> &indices);
643 
655  el(const TableIndices<N> &indices) const;
656 
657 protected:
662 
667 
668  // Make all other table classes friends.
669  template <int, typename>
670  friend class TableBase;
671 };
672 
673 
686 template <int N, typename T>
687 class Table : public TableBase<N, T>
688 {};
689 
690 
702 template <typename T>
703 class Table<1, T> : public TableBase<1, T>
704 {
705 public:
710 
714  Table() = default;
715 
719  Table(const size_type size);
720 
758  template <typename InputIterator>
759  Table(const size_type size,
760  InputIterator entries,
761  const bool C_style_indexing = true);
762 
768  operator[](const size_type i) const;
769 
774  typename AlignedVector<T>::reference operator[](const size_type i);
775 
781  operator()(const size_type i) const;
782 
788  operator()(const size_type i);
789 
795  operator()(const TableIndices<1> &indices);
796 
802  operator()(const TableIndices<1> &indices) const;
803 };
804 
805 
806 
815 {
820  enum class Storage
821  {
825  row_major,
826 
831  };
832 
833  // Forward declaration of the iterator class.
834  template <typename TableType, bool Constness, Storage storage_order>
835  class Iterator;
836 
841  template <typename TableType, bool Constness, Storage storage_order>
842  class Accessor;
843 
860  template <typename TableType, bool Constness, Storage storage_order>
862  {
863  public:
867  using container_pointer_type = typename std::
868  conditional<Constness, const TableType *, TableType *>::type;
869 
873  using value_type = typename TableType::value_type;
874 
878  using size_type = typename TableType::size_type;
879 
883  AccessorBase();
884 
889 
894 
899  const std::ptrdiff_t linear_index);
900 
904  template <bool OtherConstness>
905  friend bool
909  {
910  return left.container == right.container &&
911  left.linear_index == right.linear_index;
912  }
913 
918  const value_type &
919  value() const;
920 
924  operator const value_type &() const;
925 
929  size_type
930  row() const;
931 
935  size_type
936  column() const;
937 
938  protected:
943 
947  std::ptrdiff_t linear_index;
948 
955  void
956  assert_valid_linear_index() const;
957 
958  // Make the const version a friend for copying.
959  friend class AccessorBase<TableType, true, storage_order>;
960 
961  // Make the underlying iterator class a friend.
962  friend class LinearIndexIterator<
963  Iterator<TableType, Constness, storage_order>,
964  Accessor<TableType, Constness, storage_order>>;
965  };
966 
971  template <typename TableType, Storage storage_order>
972  class Accessor<TableType, true, storage_order>
973  : public AccessorBase<TableType, true, storage_order>
974  {
975  public:
979  using value_type =
981 
985  using size_type =
987 
992  };
993 
998  template <typename TableType, Storage storage_order>
999  class Accessor<TableType, false, storage_order>
1000  : public AccessorBase<TableType, false, storage_order>
1001  {
1002  public:
1006  using value_type =
1008 
1012  using size_type =
1014 
1019 
1025  operator=(const value_type &) const;
1026 
1032  operator=(value_type &&) const;
1033 
1039 
1044  value_type &
1045  value() const;
1046 
1050  operator value_type &();
1051  };
1052 
1065  template <typename TableType, bool Constness, Storage storage_order>
1066  class Iterator
1067  : public LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
1068  Accessor<TableType, Constness, storage_order>>
1069  {
1070  public:
1075 
1079  using container_pointer_type = typename std::
1080  conditional<Constness, const TableType *, TableType *>::type;
1081 
1086 
1090  Iterator(const container_pointer_type object);
1091 
1095  Iterator(const container_pointer_type object,
1096  const size_type row,
1097  const size_type column);
1098 
1103 
1107  Iterator(const container_pointer_type container,
1108  const std::ptrdiff_t linear_index);
1109  };
1110 } // namespace MatrixTableIterators
1111 
1112 
1113 
1126 template <typename T>
1127 class Table<2, T> : public TableBase<2, T>
1128 {
1129 public:
1134 
1139 
1144 
1149 
1154  using const_iterator = MatrixTableIterators::
1155  Iterator<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1156 
1160  using iterator = MatrixTableIterators::
1161  Iterator<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1162 
1166  Table() = default;
1167 
1171  Table(const size_type size1, const size_type size2);
1172 
1211  template <typename InputIterator>
1212  Table(const size_type size1,
1213  const size_type size2,
1214  InputIterator entries,
1215  const bool C_style_indexing = true);
1216 
1222  void
1223  reinit(const size_type size1,
1224  const size_type size2,
1225  const bool omit_default_initialization = false);
1226 
1228 
1236  operator[](const size_type i) const;
1237 
1245  operator[](const size_type i);
1246 
1254  operator()(const size_type i, const size_type j) const;
1255 
1263  operator()(const size_type i, const size_type j);
1264 
1270  operator()(const TableIndices<2> &indices);
1271 
1277  operator()(const TableIndices<2> &indices) const;
1278 
1279 
1284  size_type
1285  n_rows() const;
1286 
1291  size_type
1292  n_cols() const;
1293 
1297  iterator
1298  begin();
1299 
1304  begin() const;
1305 
1309  iterator
1310  end();
1311 
1316  end() const;
1317 
1318 protected:
1330  el(const size_type i, const size_type j);
1331 
1347  el(const size_type i, const size_type j) const;
1348 
1349  // Make the AccessorBase class a friend so that it may directly index into
1350  // the array.
1351  friend class MatrixTableIterators::
1352  AccessorBase<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1353  friend class MatrixTableIterators::
1354  AccessorBase<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1355 
1356  // Make the mutable accessor class a friend so that we can write to array
1357  // entries with iterators.
1358  friend class MatrixTableIterators::
1359  Accessor<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1360 };
1361 
1362 
1363 
1373 template <typename T>
1374 class Table<3, T> : public TableBase<3, T>
1375 {
1376 public:
1381 
1385  Table() = default;
1386 
1390  Table(const size_type size1, const size_type size2, const size_type size3);
1391 
1432  template <typename InputIterator>
1433  Table(const size_type size1,
1434  const size_type size2,
1435  const size_type size3,
1436  InputIterator entries,
1437  const bool C_style_indexing = true);
1438 
1447  operator[](const size_type i) const;
1448 
1457  operator[](const size_type i);
1458 
1466  operator()(const size_type i, const size_type j, const size_type k) const;
1467 
1468 
1476  operator()(const size_type i, const size_type j, const size_type k);
1477 
1483  operator()(const TableIndices<3> &indices);
1484 
1490  operator()(const TableIndices<3> &indices) const;
1491 };
1492 
1493 
1494 
1504 template <typename T>
1505 class Table<4, T> : public TableBase<4, T>
1506 {
1507 public:
1512 
1516  Table() = default;
1517 
1521  Table(const size_type size1,
1522  const size_type size2,
1523  const size_type size3,
1524  const size_type size4);
1525 
1534  operator[](const size_type i) const;
1535 
1544  operator[](const size_type i);
1545 
1553  operator()(const size_type i,
1554  const size_type j,
1555  const size_type k,
1556  const size_type l) const;
1557 
1558 
1566  operator()(const size_type i,
1567  const size_type j,
1568  const size_type k,
1569  const size_type l);
1570 
1576  operator()(const TableIndices<4> &indices);
1577 
1583  operator()(const TableIndices<4> &indices) const;
1584 };
1585 
1586 
1587 
1597 template <typename T>
1598 class Table<5, T> : public TableBase<5, T>
1599 {
1600 public:
1605 
1606 
1610  Table() = default;
1611 
1615  Table(const size_type size1,
1616  const size_type size2,
1617  const size_type size3,
1618  const size_type size4,
1619  const size_type size5);
1620 
1629  operator[](const size_type i) const;
1630 
1639  operator[](const size_type i);
1640 
1648  operator()(const size_type i,
1649  const size_type j,
1650  const size_type k,
1651  const size_type l,
1652  const size_type m) const;
1653 
1661  operator()(const size_type i,
1662  const size_type j,
1663  const size_type k,
1664  const size_type l,
1665  const size_type m);
1666 
1672  operator()(const TableIndices<5> &indices);
1673 
1679  operator()(const TableIndices<5> &indices) const;
1680 };
1681 
1682 
1683 
1693 template <typename T>
1694 class Table<6, T> : public TableBase<6, T>
1695 {
1696 public:
1701 
1705  Table() = default;
1706 
1710  Table(const size_type size1,
1711  const size_type size2,
1712  const size_type size3,
1713  const size_type size4,
1714  const size_type size5,
1715  const size_type size6);
1716 
1725  operator[](const size_type i) const;
1726 
1735  operator[](const size_type i);
1736 
1744  operator()(const size_type i,
1745  const size_type j,
1746  const size_type k,
1747  const size_type l,
1748  const size_type m,
1749  const size_type n) const;
1750 
1758  operator()(const size_type i,
1759  const size_type j,
1760  const size_type k,
1761  const size_type l,
1762  const size_type m,
1763  const size_type n);
1764 
1770  operator()(const TableIndices<6> &indices);
1771 
1777  operator()(const TableIndices<6> &indices) const;
1778 };
1779 
1780 
1790 template <typename T>
1791 class Table<7, T> : public TableBase<7, T>
1792 {
1793 public:
1798 
1802  Table() = default;
1803 
1807  Table(const size_type size1,
1808  const size_type size2,
1809  const size_type size3,
1810  const size_type size4,
1811  const size_type size5,
1812  const size_type size6,
1813  const size_type size7);
1814 
1823  operator[](const size_type i) const;
1824 
1833  operator[](const size_type i);
1834 
1842  operator()(const size_type i,
1843  const size_type j,
1844  const size_type k,
1845  const size_type l,
1846  const size_type m,
1847  const size_type n,
1848  const size_type o) const;
1849 
1857  operator()(const size_type i,
1858  const size_type j,
1859  const size_type k,
1860  const size_type l,
1861  const size_type m,
1862  const size_type n,
1863  const size_type o);
1864 
1870  operator()(const TableIndices<7> &indices);
1871 
1877  operator()(const TableIndices<7> &indices) const;
1878 };
1879 
1880 
1893 template <typename T>
1894 class TransposeTable : public TableBase<2, T>
1895 {
1896 public:
1901 
1906 
1911 
1916 
1921  using const_iterator =
1923  true,
1925 
1929  using iterator =
1931  false,
1933 
1937  TransposeTable() = default;
1938 
1942  TransposeTable(const size_type size1, const size_type size2);
1943 
1949  void
1950  reinit(const size_type size1,
1951  const size_type size2,
1952  const bool omit_default_initialization = false);
1953 
1961  operator()(const size_type i, const size_type j) const;
1962 
1969  reference
1970  operator()(const size_type i, const size_type j);
1971 
1976  size_type
1977  n_rows() const;
1978 
1983  size_type
1984  n_cols() const;
1985 
1989  iterator
1990  begin();
1991 
1996  begin() const;
1997 
2001  iterator
2002  end();
2003 
2008  end() const;
2009 
2010 protected:
2021  reference
2022  el(const size_type i, const size_type j);
2023 
2039  el(const size_type i, const size_type j) const;
2040 
2041  // Make the AccessorBase class a friend so that it may directly index into
2042  // the array.
2044  TransposeTable<T>,
2045  true,
2048  TransposeTable<T>,
2049  false,
2050  MatrixTableIterators::Storage::column_major>;
2051 
2052  // Make the mutable accessor class a friend so that we can write to array
2053  // entries with iterators.
2054  friend class MatrixTableIterators::Accessor<
2055  TransposeTable<T>,
2056  false,
2057  MatrixTableIterators::Storage::column_major>;
2058 };
2059 
2060 
2061 
2062 /* --------------------- Template and inline functions ---------------- */
2063 
2064 #ifndef DOXYGEN
2065 
2066 template <int N, typename T>
2067 TableBase<N, T>::TableBase(const TableIndices<N> &sizes)
2068 {
2069  reinit(sizes);
2070 }
2071 
2072 
2073 
2074 template <int N, typename T>
2075 template <typename InputIterator>
2077  InputIterator entries,
2078  const bool C_style_indexing)
2079 {
2080  reinit(sizes);
2081  fill(entries, C_style_indexing);
2082 }
2083 
2084 
2085 
2086 template <int N, typename T>
2088  : Subscriptor()
2089 {
2090  reinit(src.table_size, true);
2091  values = src.values;
2092 }
2093 
2094 
2095 
2096 template <int N, typename T>
2097 template <typename T2>
2099 {
2100  reinit(src.table_size);
2101  if (src.n_elements() != 0)
2102  std::copy(src.values.begin(), src.values.end(), values.begin());
2103 }
2104 
2105 
2106 
2107 template <int N, typename T>
2109  : Subscriptor(std::move(src))
2110  , values(std::move(src.values))
2111  , table_size(src.table_size)
2112 {
2113  src.table_size = TableIndices<N>();
2114 }
2115 
2116 
2117 
2118 template <int N, typename T>
2119 template <class Archive>
2120 inline void
2121 TableBase<N, T>::serialize(Archive &ar, const unsigned int)
2122 {
2123  ar &static_cast<Subscriptor &>(*this);
2124 
2125  ar &values &table_size;
2126 }
2127 
2128 
2129 
2130 namespace internal
2131 {
2132  namespace TableBaseAccessors
2133  {
2134  template <int N, typename T, bool C, unsigned int P>
2135  inline Accessor<N, T, C, P>::Accessor(const TableType &table,
2136  const iterator data)
2137  : table(table)
2138  , data(data)
2139  {}
2140 
2141 
2142 
2143  template <int N, typename T, bool C, unsigned int P>
2144  inline Accessor<N, T, C, P>::Accessor(const Accessor &a)
2145  : table(a.table)
2146  , data(a.data)
2147  {}
2148 
2149 
2150 
2151  template <int N, typename T, bool C, unsigned int P>
2152  inline Accessor<N, T, C, P - 1> Accessor<N, T, C, P>::
2153  operator[](const size_type i) const
2154  {
2155  AssertIndexRange(i, table.size()[N - P]);
2156 
2157  // access i-th
2158  // subobject. optimize on the
2159  // case i==0
2160  if (i == 0)
2161  return Accessor<N, T, C, P - 1>(table, data);
2162  else
2163  {
2164  // note: P>1, otherwise the
2165  // specialization would have
2166  // been taken!
2167  size_type subobject_size = table.size()[N - 1];
2168  for (int p = P - 1; p > 1; --p)
2169  subobject_size *= table.size()[N - p];
2170  const iterator new_data = data + i * subobject_size;
2171  return Accessor<N, T, C, P - 1>(table, new_data);
2172  }
2173  }
2174 
2175 
2176 
2177  template <int N, typename T, bool C>
2178  inline Accessor<N, T, C, 1>::Accessor(const TableType &table,
2179  const iterator data)
2180  : table(table)
2181  , data(data)
2182  {}
2183 
2184 
2185 
2186  template <int N, typename T, bool C>
2187  inline Accessor<N, T, C, 1>::Accessor(const Accessor &a)
2188  : table(a.table)
2189  , data(a.data)
2190  {}
2191 
2192 
2193 
2194  template <int N, typename T, bool C>
2196  operator[](const size_type i) const
2197  {
2198  AssertIndexRange(i, table.size()[N - 1]);
2199  return *(data + i);
2200  }
2201 
2202 
2203 
2204  template <int N, typename T, bool C>
2205  inline typename Accessor<N, T, C, 1>::size_type
2207  {
2208  return table.size()[N - 1];
2209  }
2210 
2211 
2212 
2213  template <int N, typename T, bool C>
2214  inline typename Accessor<N, T, C, 1>::iterator
2216  {
2217  return data;
2218  }
2219 
2220 
2221 
2222  template <int N, typename T, bool C>
2223  inline typename Accessor<N, T, C, 1>::iterator
2225  {
2226  return data + table.size()[N - 1];
2227  }
2228  } // namespace TableBaseAccessors
2229 } // namespace internal
2230 
2231 
2232 
2233 template <int N, typename T>
2234 inline TableBase<N, T> &
2236 {
2237  if (!m.empty())
2238  values = m.values;
2239  reinit(m.size(), true);
2240 
2241  return *this;
2242 }
2243 
2244 
2245 
2246 template <int N, typename T>
2247 template <typename T2>
2248 inline TableBase<N, T> &
2250 {
2251  reinit(m.size(), true);
2252  if (!empty())
2253  std::copy(m.values.begin(),
2254  m.values.begin() + n_elements(),
2255  values.begin());
2256 
2257  return *this;
2258 }
2259 
2260 
2261 
2262 template <int N, typename T>
2263 inline TableBase<N, T> &
2265 {
2266  static_cast<Subscriptor &>(*this) = std::move(static_cast<Subscriptor &>(m));
2267  values = std::move(m.values);
2268  table_size = m.table_size;
2270 
2271  return *this;
2272 }
2273 
2274 
2275 
2276 template <int N, typename T>
2277 inline bool
2279 {
2280  return (values == T2.values);
2281 }
2282 
2283 
2284 
2285 template <int N, typename T>
2286 inline void
2288 {
2289  // use parallel set operation
2290  if (n_elements() != 0)
2291  values.fill(T());
2292 }
2293 
2294 
2295 
2296 template <int N, typename T>
2297 inline void
2298 TableBase<N, T>::fill(const T &value)
2299 {
2300  if (n_elements() != 0)
2301  values.fill(value);
2302 }
2303 
2304 
2305 
2306 template <int N, typename T>
2307 inline void
2308 TableBase<N, T>::reinit(const TableIndices<N> &new_sizes,
2309  const bool omit_default_initialization)
2310 {
2311  table_size = new_sizes;
2312 
2313  const size_type new_size = n_elements();
2314 
2315  // if zero size was given: free all memory
2316  if (new_size == 0)
2317  {
2318  values.resize(0);
2319  // set all sizes to zero, even
2320  // if one was previously
2321  // nonzero. This simplifies
2322  // some assertions.
2323  table_size = TableIndices<N>();
2324 
2325  return;
2326  }
2327 
2328  // adjust values field. If it was empty before, we can simply call resize(),
2329  // which can set all the data fields. Otherwise, select the fast resize and
2330  // manually fill in all the elements as required by the design of this
2331  // class. (Selecting another code for the empty case ensures that we touch
2332  // the memory only once for non-trivial classes that need to initialize the
2333  // memory also in resize_fast.)
2334  if (!omit_default_initialization)
2335  {
2336  if (values.empty())
2337  values.resize(new_size);
2338  else
2339  {
2340  values.resize_fast(new_size);
2341  values.fill();
2342  }
2343  }
2344  else
2345  values.resize_fast(new_size);
2346 }
2347 
2348 
2349 
2350 template <int N, typename T>
2351 inline const TableIndices<N> &
2352 TableBase<N, T>::size() const
2353 {
2354  return table_size;
2355 }
2356 
2357 
2358 
2359 template <int N, typename T>
2360 inline typename TableBase<N, T>::size_type
2361 TableBase<N, T>::size(const unsigned int i) const
2362 {
2363  AssertIndexRange(i, N);
2364  return table_size[i];
2365 }
2366 
2367 
2368 
2369 template <int N, typename T>
2370 inline typename TableBase<N, T>::size_type
2372 {
2373  size_type s = 1;
2374  for (unsigned int n = 0; n < N; ++n)
2375  s *= table_size[n];
2376  return s;
2377 }
2378 
2379 
2380 
2381 template <int N, typename T>
2382 inline bool
2383 TableBase<N, T>::empty() const
2384 {
2385  return (n_elements() == 0);
2386 }
2387 
2388 
2389 
2390 namespace internal
2391 {
2392  namespace TableImplementation
2393  {
2394  template <typename InputIterator, typename T>
2395  void
2396  fill_Fortran_style(InputIterator entries, TableBase<1, T> &table)
2397  {
2398  using size_type = typename TableBase<1, T>::size_type;
2399  for (size_type i = 0; i < table.size()[0]; ++i)
2400  table(TableIndices<1>(i)) = *entries++;
2401  }
2402 
2403 
2404  template <typename InputIterator, typename T>
2405  void
2406  fill_Fortran_style(InputIterator entries, TableBase<2, T> &table)
2407  {
2408  using size_type = typename TableBase<2, T>::size_type;
2409  for (size_type j = 0; j < table.size()[1]; ++j)
2410  for (size_type i = 0; i < table.size()[0]; ++i)
2411  table(TableIndices<2>(i, j)) = *entries++;
2412  }
2413 
2414 
2415  template <typename InputIterator, typename T>
2416  void
2417  fill_Fortran_style(InputIterator entries, TableBase<3, T> &table)
2418  {
2419  using size_type = typename TableBase<3, T>::size_type;
2420  for (size_type k = 0; k < table.size()[2]; ++k)
2421  for (size_type j = 0; j < table.size()[1]; ++j)
2422  for (size_type i = 0; i < table.size()[0]; ++i)
2423  table(TableIndices<3>(i, j, k)) = *entries++;
2424  }
2425 
2426 
2427  template <typename InputIterator, typename T, int N>
2428  void
2429  fill_Fortran_style(InputIterator, TableBase<N, T> &)
2430  {
2431  Assert(false, ExcNotImplemented());
2432  }
2433  } // namespace TableImplementation
2434 } // namespace internal
2435 
2436 
2437 template <int N, typename T>
2438 template <typename InputIterator>
2439 inline void
2440 TableBase<N, T>::fill(InputIterator entries, const bool C_style_indexing)
2441 {
2442  Assert(n_elements() != 0, ExcMessage("Trying to fill an empty matrix."));
2443 
2444  if (C_style_indexing)
2445  for (typename AlignedVector<T>::iterator p = values.begin();
2446  p != values.end();
2447  ++p)
2448  *p = *entries++;
2449  else
2450  internal::TableImplementation::fill_Fortran_style(entries, *this);
2451 }
2452 
2453 
2454 
2455 template <int N, typename T>
2456 inline void
2458 {
2459  values.swap(v.values);
2460  std::swap(table_size, v.table_size);
2461 }
2462 
2463 
2464 
2465 template <int N, typename T>
2466 inline std::size_t
2468 {
2469  return sizeof(*this) + MemoryConsumption::memory_consumption(values);
2470 }
2471 
2472 
2473 
2474 template <int N, typename T>
2475 inline typename TableBase<N, T>::size_type
2476 TableBase<N, T>::position(const TableIndices<N> &indices) const
2477 {
2478  // specialize this for the
2479  // different numbers of dimensions,
2480  // to make the job somewhat easier
2481  // for the compiler. have the
2482  // general formula nevertheless:
2483  switch (N)
2484  {
2485  case 1:
2486  return indices[0];
2487  case 2:
2488  return size_type(indices[0]) * table_size[1] + indices[1];
2489  case 3:
2490  return ((size_type(indices[0]) * table_size[1] + indices[1]) *
2491  table_size[2] +
2492  indices[2]);
2493  default:
2494  {
2495  unsigned int s = indices[0];
2496  for (unsigned int n = 1; n < N; ++n)
2497  s = s * table_size[n] + indices[n];
2498  return s;
2499  }
2500  }
2501 }
2502 
2503 
2504 
2505 template <int N, typename T>
2506 inline typename AlignedVector<T>::const_reference
2507 TableBase<N, T>::operator()(const TableIndices<N> &indices) const
2508 {
2509  for (unsigned int n = 0; n < N; ++n)
2510  AssertIndexRange(indices[n], table_size[n]);
2511  return el(indices);
2512 }
2513 
2514 
2515 
2516 template <int N, typename T>
2517 inline typename AlignedVector<T>::reference
2519 {
2520  for (unsigned int n = 0; n < N; ++n)
2521  AssertIndexRange(indices[n], table_size[n]);
2522  return el(indices);
2523 }
2524 
2525 
2526 
2527 template <int N, typename T>
2528 inline typename AlignedVector<T>::const_reference
2529 TableBase<N, T>::el(const TableIndices<N> &indices) const
2530 {
2531  return values[position(indices)];
2532 }
2533 
2534 
2535 
2536 template <int N, typename T>
2537 inline typename AlignedVector<T>::reference
2538 TableBase<N, T>::el(const TableIndices<N> &indices)
2539 {
2540  AssertIndexRange(position(indices), values.size());
2541  return values[position(indices)];
2542 }
2543 
2544 
2545 
2546 template <typename T>
2547 inline Table<1, T>::Table(const size_type size)
2549 {}
2550 
2551 
2552 
2553 template <typename T>
2554 template <typename InputIterator>
2555 inline Table<1, T>::Table(const size_type size,
2556  InputIterator entries,
2557  const bool C_style_indexing)
2558  : TableBase<1, T>(TableIndices<1>(size), entries, C_style_indexing)
2559 {}
2560 
2561 
2562 
2563 template <typename T>
2565  operator[](const size_type i) const
2566 {
2567  AssertIndexRange(i, this->table_size[0]);
2568  return this->values[i];
2569 }
2570 
2571 
2572 
2573 template <typename T>
2575  operator[](const size_type i)
2576 {
2577  AssertIndexRange(i, this->table_size[0]);
2578  return this->values[i];
2579 }
2580 
2581 
2582 
2583 template <typename T>
2584 inline typename AlignedVector<T>::const_reference
2585 Table<1, T>::operator()(const size_type i) const
2586 {
2587  AssertIndexRange(i, this->table_size[0]);
2588  return this->values[i];
2589 }
2590 
2591 
2592 
2593 template <typename T>
2594 inline typename AlignedVector<T>::reference
2596 {
2597  AssertIndexRange(i, this->table_size[0]);
2598  return this->values[i];
2599 }
2600 
2601 
2602 
2603 template <typename T>
2604 inline typename AlignedVector<T>::const_reference
2605 Table<1, T>::operator()(const TableIndices<1> &indices) const
2606 {
2607  return TableBase<1, T>::operator()(indices);
2608 }
2609 
2610 
2611 
2612 template <typename T>
2613 inline typename AlignedVector<T>::reference
2615 {
2616  return TableBase<1, T>::operator()(indices);
2617 }
2618 
2619 
2620 //---------------------------------------------------------------------------
2621 
2622 
2623 
2624 template <typename T>
2625 inline Table<2, T>::Table(const size_type size1, const size_type size2)
2626  : TableBase<2, T>(TableIndices<2>(size1, size2))
2627 {}
2628 
2629 
2630 
2631 template <typename T>
2632 template <typename InputIterator>
2633 inline Table<2, T>::Table(const size_type size1,
2634  const size_type size2,
2635  InputIterator entries,
2636  const bool C_style_indexing)
2637  : TableBase<2, T>(TableIndices<2>(size1, size2), entries, C_style_indexing)
2638 {}
2639 
2640 
2641 
2642 template <typename T>
2643 inline void
2644 Table<2, T>::reinit(const size_type size1,
2645  const size_type size2,
2646  const bool omit_default_initialization)
2647 {
2648  this->TableBase<2, T>::reinit(TableIndices<2>(size1, size2),
2649  omit_default_initialization);
2650 }
2651 
2652 
2653 
2654 template <typename T>
2655 inline ::internal::TableBaseAccessors::Accessor<2, T, true, 1>
2656  Table<2, T>::operator[](const size_type i) const
2657 {
2658  AssertIndexRange(i, this->table_size[0]);
2659  return ::internal::TableBaseAccessors::Accessor<2, T, true, 1>(
2660  *this, this->values.begin() + size_type(i) * n_cols());
2661 }
2662 
2663 
2664 
2665 template <typename T>
2666 inline ::internal::TableBaseAccessors::Accessor<2, T, false, 1>
2668 {
2669  AssertIndexRange(i, this->table_size[0]);
2670  return ::internal::TableBaseAccessors::Accessor<2, T, false, 1>(
2671  *this, this->values.begin() + size_type(i) * n_cols());
2672 }
2673 
2674 
2675 
2676 template <typename T>
2677 inline typename AlignedVector<T>::const_reference
2678 Table<2, T>::operator()(const size_type i, const size_type j) const
2679 {
2680  AssertIndexRange(i, this->table_size[0]);
2681  AssertIndexRange(j, this->table_size[1]);
2682  return this->values[size_type(i) * this->table_size[1] + j];
2683 }
2684 
2685 
2686 
2687 template <typename T>
2688 inline typename AlignedVector<T>::reference
2690 {
2691  AssertIndexRange(i, this->table_size[0]);
2692  AssertIndexRange(j, this->table_size[1]);
2693  return this->values[size_type(i) * this->table_size[1] + j];
2694 }
2695 
2696 
2697 
2698 template <typename T>
2699 inline typename AlignedVector<T>::const_reference
2700 Table<2, T>::operator()(const TableIndices<2> &indices) const
2701 {
2702  return TableBase<2, T>::operator()(indices);
2703 }
2704 
2705 
2706 
2707 template <typename T>
2708 inline typename AlignedVector<T>::reference
2710 {
2711  return TableBase<2, T>::operator()(indices);
2712 }
2713 
2714 
2715 
2716 template <typename T>
2717 inline typename AlignedVector<T>::const_reference
2718 Table<2, T>::el(const size_type i, const size_type j) const
2719 {
2720  return this->values[size_type(i) * this->table_size[1] + j];
2721 }
2722 
2723 
2724 
2725 template <typename T>
2726 inline typename AlignedVector<T>::reference
2727 Table<2, T>::el(const size_type i, const size_type j)
2728 {
2729  return this->values[size_type(i) * this->table_size[1] + j];
2730 }
2731 
2732 
2733 
2734 template <typename T>
2735 inline typename Table<2, T>::size_type
2736 Table<2, T>::n_rows() const
2737 {
2738  return this->table_size[0];
2739 }
2740 
2741 
2742 
2743 template <typename T>
2744 inline typename Table<2, T>::size_type
2745 Table<2, T>::n_cols() const
2746 {
2747  return this->table_size[1];
2748 }
2749 
2750 
2751 
2752 template <typename T>
2753 inline typename Table<2, T>::iterator
2755 {
2756  return typename Table<2, T>::iterator(this, 0, 0);
2757 }
2758 
2759 
2760 
2761 template <typename T>
2762 inline typename Table<2, T>::const_iterator
2763 Table<2, T>::begin() const
2764 {
2765  return typename Table<2, T>::const_iterator(this, 0, 0);
2766 }
2767 
2768 
2769 
2770 template <typename T>
2771 inline typename Table<2, T>::iterator
2773 {
2774  return typename Table<2, T>::iterator(this);
2775 }
2776 
2777 
2778 
2779 template <typename T>
2780 inline typename Table<2, T>::const_iterator
2781 Table<2, T>::end() const
2782 {
2783  return typename Table<2, T>::const_iterator(this);
2784 }
2785 
2786 
2787 
2788 //---------------------------------------------------------------------------
2789 namespace MatrixTableIterators
2790 {
2791  namespace internal
2792  {
2793  // Internal calculation routines for AccessorBase. These do not do any
2794  // checking whatsoever.
2795  template <typename TableType, Storage storage_order>
2796  inline std::ptrdiff_t
2797  get_row_index(const std::ptrdiff_t linear_index,
2798  const TableType *const container)
2799  {
2800  switch (storage_order)
2801  {
2802  case Storage::row_major:
2803  return linear_index / container->n_cols();
2804  case Storage::column_major:
2805  return linear_index % container->n_rows();
2806  default:
2807  Assert(false, ExcInternalError());
2808  }
2809  return {};
2810  }
2811 
2812 
2813 
2814  template <typename TableType, Storage storage_order>
2815  inline std::ptrdiff_t
2816  get_column_index(const std::ptrdiff_t linear_index,
2817  const TableType *const container)
2818  {
2819  switch (storage_order)
2820  {
2821  case Storage::row_major:
2822  return linear_index % container->n_cols();
2823  case Storage::column_major:
2824  return linear_index / container->n_rows();
2825  default:
2826  Assert(false, ExcInternalError());
2827  }
2828  return {};
2829  }
2830  } // namespace internal
2831 
2832 
2833 
2834  template <typename TableType, bool Constness, Storage storage_order>
2835  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase()
2836  : container(nullptr)
2837  , linear_index(std::numeric_limits<decltype(linear_index)>::max())
2838  {}
2839 
2840 
2841 
2842  template <typename TableType, bool Constness, Storage storage_order>
2843  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2844  const container_pointer_type table)
2845  : container(table)
2846  , linear_index(container->values.size())
2847  {}
2848 
2849 
2850 
2851  template <typename TableType, bool Constness, Storage storage_order>
2852  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2853  const AccessorBase<TableType, false, storage_order> &a)
2854  : container(a.container)
2855  , linear_index(a.linear_index)
2856  {}
2857 
2858 
2859 
2860  template <typename TableType, bool Constness, Storage storage_order>
2861  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2862  const container_pointer_type table,
2863  const std::ptrdiff_t index)
2864  : container(table)
2865  , linear_index(index)
2866  {
2867  Assert(0 <= linear_index &&
2868  std::size_t(linear_index) < container->values.size() + 1,
2869  ExcMessage("The current iterator points outside of the table and is "
2870  "not the end iterator."));
2871  }
2872 
2873 
2874 
2875  template <typename TableType, bool Constness, Storage storage_order>
2876  inline const typename AccessorBase<TableType, Constness, storage_order>::
2877  value_type &
2879  {
2880  assert_valid_linear_index();
2881  return this->container->values[linear_index];
2882  }
2883 
2884 
2885 
2886  template <typename TableType, bool Constness, Storage storage_order>
2887  inline AccessorBase<TableType, Constness, storage_order>::
2888  operator const value_type &() const
2889  {
2890  assert_valid_linear_index();
2891  return this->container->values[linear_index];
2892  }
2893 
2894 
2895 
2896  template <typename TableType, bool Constness, Storage storage_order>
2898  AccessorBase<TableType, Constness, storage_order>::row() const
2899  {
2900  assert_valid_linear_index();
2901  return static_cast<std::size_t>(
2902  internal::get_row_index<TableType, storage_order>(linear_index,
2903  container));
2904  }
2905 
2906 
2907 
2908  template <typename TableType, bool Constness, Storage storage_order>
2910  AccessorBase<TableType, Constness, storage_order>::column() const
2911  {
2912  assert_valid_linear_index();
2913  return static_cast<std::size_t>(
2914  internal::get_column_index<TableType, storage_order>(linear_index,
2915  container));
2916  }
2917 
2918 
2919 
2920  template <typename TableType, bool Constness, Storage storage_order>
2921  inline void
2922  AccessorBase<TableType, Constness, storage_order>::assert_valid_linear_index()
2923  const
2924  {
2925 # ifdef DEBUG // avoid unused variable warnings by guarding everything
2926  Assert(container != nullptr,
2927  ExcMessage("This accessor has been default-constructed and does not "
2928  "have a corresponding table."));
2929  Assert(!container->empty(),
2930  ExcMessage("An empty table has no rows or columns."));
2931  Assert(0 <= linear_index &&
2932  std::size_t(linear_index) < container->values.size(),
2933  ExcMessage("The current iterator points outside of the table."));
2934  const std::ptrdiff_t row_n =
2935  internal::get_row_index<TableType, storage_order>(linear_index,
2936  container);
2937  const std::ptrdiff_t column_n =
2938  internal::get_column_index<TableType, storage_order>(linear_index,
2939  container);
2940  Assert(0 <= column_n && std::size_t(column_n) < container->n_cols(),
2941  ExcMessage("The current iterator points outside the table."));
2942  Assert(0 <= row_n && std::size_t(row_n) < container->n_rows(),
2943  ExcMessage("The current iterator points outside the table."));
2944 # endif
2945  }
2946 
2947 
2948 
2949  template <typename TableType, Storage storage_order>
2950  inline const Accessor<TableType, false, storage_order> &
2951  Accessor<TableType, false, storage_order>::operator=(
2952  const typename Accessor<TableType, false, storage_order>::value_type &t)
2953  const
2954  {
2955  this->assert_valid_linear_index();
2956  this->container->values[this->linear_index] = t;
2957  return *this;
2958  }
2959 
2960 
2961 
2962  template <typename TableType, Storage storage_order>
2963  inline const Accessor<TableType, false, storage_order> &
2964  Accessor<TableType, false, storage_order>::operator=(
2965  typename Accessor<TableType, false, storage_order>::value_type &&t) const
2966  {
2967  this->assert_valid_linear_index();
2968  this->container->values[this->linear_index] = t;
2969  return *this;
2970  }
2971 
2972 
2973 
2974  template <typename TableType, Storage storage_order>
2975  inline typename Accessor<TableType, false, storage_order>::value_type &
2977  {
2978  this->assert_valid_linear_index();
2979  return this->container->values[this->linear_index];
2980  }
2981 
2982 
2983 
2984  template <typename TableType, Storage storage_order>
2985  inline Accessor<TableType, false, storage_order>::operator value_type &()
2986  {
2987  this->assert_valid_linear_index();
2988  return this->container->values[this->linear_index];
2989  }
2990 
2991 
2992 
2993  template <typename TableType, bool Constness, Storage storage_order>
2994  inline Iterator<TableType, Constness, storage_order>::Iterator(
2998  {}
2999 
3000 
3001 
3002  template <typename TableType, bool Constness, Storage storage_order>
3003  inline Iterator<TableType, Constness, storage_order>::Iterator(
3004  const container_pointer_type table)
3008  {}
3009 
3010 
3011 
3012  template <typename TableType, bool Constness, Storage storage_order>
3013  inline Iterator<TableType, Constness, storage_order>::Iterator(
3014  const Iterator<TableType, false, storage_order> &i)
3017  {}
3018 
3019 
3020 
3021  template <typename TableType, bool Constness, Storage storage_order>
3022  inline Iterator<TableType, Constness, storage_order>::Iterator(
3023  const container_pointer_type table,
3024  const size_type row_n,
3025  const size_type col_n)
3026  : Iterator(table,
3027  storage_order == Storage::row_major ?
3028  table->n_cols() * row_n + col_n :
3029  table->n_rows() * col_n + row_n)
3030  {}
3031 
3032 
3033 
3034  template <typename TableType, bool Constness, Storage storage_order>
3035  inline Iterator<TableType, Constness, storage_order>::Iterator(
3036  const container_pointer_type table,
3037  const std::ptrdiff_t linear_index)
3040  Accessor<TableType, Constness, storage_order>(table, linear_index))
3041  {}
3042 } // namespace MatrixTableIterators
3043 
3044 
3045 
3046 //---------------------------------------------------------------------------
3047 template <typename T>
3048 inline TransposeTable<T>::TransposeTable(const size_type size1,
3049  const size_type size2)
3050  : TableBase<2, T>(TableIndices<2>(size2, size1))
3051 {}
3052 
3053 
3054 
3055 template <typename T>
3056 inline void
3058  const size_type size2,
3059  const bool omit_default_initialization)
3060 {
3061  this->TableBase<2, T>::reinit(TableIndices<2>(size2, size1),
3062  omit_default_initialization);
3063 }
3064 
3065 
3066 
3067 template <typename T>
3068 inline typename TransposeTable<T>::const_reference
3069 TransposeTable<T>::operator()(const size_type i, const size_type j) const
3070 {
3071  AssertIndexRange(i, this->table_size[1]);
3072  AssertIndexRange(j, this->table_size[0]);
3073  return this->values[size_type(j) * this->table_size[1] + i];
3074 }
3075 
3076 
3077 
3078 template <typename T>
3079 inline typename TransposeTable<T>::reference
3081 {
3082  AssertIndexRange(i, this->table_size[1]);
3083  AssertIndexRange(j, this->table_size[0]);
3084  return this->values[size_type(j) * this->table_size[1] + i];
3085 }
3086 
3087 
3088 
3089 template <typename T>
3090 inline typename TransposeTable<T>::const_reference
3091 TransposeTable<T>::el(const size_type i, const size_type j) const
3092 {
3093  return this->values[size_type(j) * this->table_size[1] + i];
3094 }
3095 
3096 
3097 
3098 template <typename T>
3099 inline typename TransposeTable<T>::reference
3100 TransposeTable<T>::el(const size_type i, const size_type j)
3101 {
3102  return this->values[size_type(j) * this->table_size[1] + i];
3103 }
3104 
3105 
3106 
3107 template <typename T>
3108 inline typename TransposeTable<T>::size_type
3110 {
3111  return this->table_size[1];
3112 }
3113 
3114 
3115 
3116 template <typename T>
3117 inline typename TransposeTable<T>::size_type
3119 {
3120  return this->table_size[0];
3121 }
3122 
3123 
3124 
3125 template <typename T>
3126 inline typename TransposeTable<T>::iterator
3128 {
3129  return typename TransposeTable<T>::iterator(this, 0, 0);
3130 }
3131 
3132 
3133 
3134 template <typename T>
3135 inline typename TransposeTable<T>::const_iterator
3137 {
3138  return typename TransposeTable<T>::const_iterator(this, 0, 0);
3139 }
3140 
3141 
3142 
3143 template <typename T>
3144 inline typename TransposeTable<T>::iterator
3146 {
3147  return typename TransposeTable<T>::iterator(this);
3148 }
3149 
3150 
3151 
3152 template <typename T>
3153 inline typename TransposeTable<T>::const_iterator
3154 TransposeTable<T>::end() const
3155 {
3156  return typename TransposeTable<T>::const_iterator(this);
3157 }
3158 //---------------------------------------------------------------------------
3159 
3160 
3161 
3162 template <typename T>
3163 inline Table<3, T>::Table(const size_type size1,
3164  const size_type size2,
3165  const size_type size3)
3166  : TableBase<3, T>(TableIndices<3>(size1, size2, size3))
3167 {}
3168 
3169 
3170 
3171 template <typename T>
3172 template <typename InputIterator>
3173 inline Table<3, T>::Table(const size_type size1,
3174  const size_type size2,
3175  const size_type size3,
3176  InputIterator entries,
3177  const bool C_style_indexing)
3178  : TableBase<3, T>(TableIndices<3>(size1, size2, size3),
3179  entries,
3180  C_style_indexing)
3181 {}
3182 
3183 
3184 
3185 template <typename T>
3186 inline ::internal::TableBaseAccessors::Accessor<3, T, true, 2>
3187  Table<3, T>::operator[](const size_type i) const
3188 {
3189  AssertIndexRange(i, this->table_size[0]);
3190  const size_type subobject_size =
3191  size_type(this->table_size[1]) * this->table_size[2];
3193  *this, this->values.begin() + i * subobject_size));
3194 }
3195 
3196 
3197 
3198 template <typename T>
3199 inline ::internal::TableBaseAccessors::Accessor<3, T, false, 2>
3201 {
3202  AssertIndexRange(i, this->table_size[0]);
3203  const size_type subobject_size =
3204  size_type(this->table_size[1]) * this->table_size[2];
3206  *this, this->values.begin() + i * subobject_size));
3207 }
3208 
3209 
3210 
3211 template <typename T>
3212 inline typename AlignedVector<T>::const_reference
3214 operator()(const size_type i, const size_type j, const size_type k) const
3215 {
3216  AssertIndexRange(i, this->table_size[0]);
3217  AssertIndexRange(j, this->table_size[1]);
3218  AssertIndexRange(k, this->table_size[2]);
3219  return this
3220  ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3221  k];
3222 }
3223 
3224 
3225 
3226 template <typename T>
3227 inline typename AlignedVector<T>::reference
3228 Table<3, T>::operator()(const size_type i, const size_type j, const size_type k)
3229 {
3230  AssertIndexRange(i, this->table_size[0]);
3231  AssertIndexRange(j, this->table_size[1]);
3232  AssertIndexRange(k, this->table_size[2]);
3233  return this
3234  ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3235  k];
3236 }
3237 
3238 
3239 
3240 template <typename T>
3241 inline typename AlignedVector<T>::const_reference
3242 Table<3, T>::operator()(const TableIndices<3> &indices) const
3243 {
3244  return TableBase<3, T>::operator()(indices);
3245 }
3246 
3247 
3248 
3249 template <typename T>
3250 inline typename AlignedVector<T>::reference
3252 {
3253  return TableBase<3, T>::operator()(indices);
3254 }
3255 
3256 
3257 
3258 template <typename T>
3259 inline Table<4, T>::Table(const size_type size1,
3260  const size_type size2,
3261  const size_type size3,
3262  const size_type size4)
3263  : TableBase<4, T>(TableIndices<4>(size1, size2, size3, size4))
3264 {}
3265 
3266 
3267 
3268 template <typename T>
3269 inline ::internal::TableBaseAccessors::Accessor<4, T, true, 3>
3270  Table<4, T>::operator[](const size_type i) const
3271 {
3272  AssertIndexRange(i, this->table_size[0]);
3273  const size_type subobject_size =
3274  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3276  *this, this->values.begin() + i * subobject_size));
3277 }
3278 
3279 
3280 
3281 template <typename T>
3282 inline ::internal::TableBaseAccessors::Accessor<4, T, false, 3>
3284 {
3285  AssertIndexRange(i, this->table_size[0]);
3286  const size_type subobject_size =
3287  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3289  *this, this->values.begin() + i * subobject_size));
3290 }
3291 
3292 
3293 
3294 template <typename T>
3295 inline typename AlignedVector<T>::const_reference
3297  const size_type j,
3298  const size_type k,
3299  const size_type l) const
3300 {
3301  AssertIndexRange(i, this->table_size[0]);
3302  AssertIndexRange(j, this->table_size[1]);
3303  AssertIndexRange(k, this->table_size[2]);
3304  AssertIndexRange(l, this->table_size[3]);
3305  return this
3306  ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3307  k) *
3308  this->table_size[3] +
3309  l];
3310 }
3311 
3312 
3313 
3314 template <typename T>
3315 inline typename AlignedVector<T>::reference
3317  const size_type j,
3318  const size_type k,
3319  const size_type l)
3320 {
3321  AssertIndexRange(i, this->table_size[0]);
3322  AssertIndexRange(j, this->table_size[1]);
3323  AssertIndexRange(k, this->table_size[2]);
3324  AssertIndexRange(l, this->table_size[3]);
3325  return this
3326  ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3327  k) *
3328  this->table_size[3] +
3329  l];
3330 }
3331 
3332 
3333 
3334 template <typename T>
3335 inline typename AlignedVector<T>::const_reference
3336 Table<4, T>::operator()(const TableIndices<4> &indices) const
3337 {
3338  return TableBase<4, T>::operator()(indices);
3339 }
3340 
3341 
3342 
3343 template <typename T>
3344 inline typename AlignedVector<T>::reference
3346 {
3347  return TableBase<4, T>::operator()(indices);
3348 }
3349 
3350 
3351 
3352 template <typename T>
3353 inline Table<5, T>::Table(const size_type size1,
3354  const size_type size2,
3355  const size_type size3,
3356  const size_type size4,
3357  const size_type size5)
3358  : TableBase<5, T>(TableIndices<5>(size1, size2, size3, size4, size5))
3359 {}
3360 
3361 
3362 
3363 template <typename T>
3364 inline ::internal::TableBaseAccessors::Accessor<5, T, true, 4>
3365  Table<5, T>::operator[](const size_type i) const
3366 {
3367  AssertIndexRange(i, this->table_size[0]);
3368  const size_type subobject_size = size_type(this->table_size[1]) *
3369  this->table_size[2] * this->table_size[3] *
3370  this->table_size[4];
3372  *this, this->values.begin() + i * subobject_size));
3373 }
3374 
3375 
3376 
3377 template <typename T>
3378 inline ::internal::TableBaseAccessors::Accessor<5, T, false, 4>
3380 {
3381  AssertIndexRange(i, this->table_size[0]);
3382  const size_type subobject_size = size_type(this->table_size[1]) *
3383  this->table_size[2] * this->table_size[3] *
3384  this->table_size[4];
3386  *this, this->values.begin() + i * subobject_size));
3387 }
3388 
3389 
3390 
3391 template <typename T>
3392 inline typename AlignedVector<T>::const_reference
3394  const size_type j,
3395  const size_type k,
3396  const size_type l,
3397  const size_type m) const
3398 {
3399  AssertIndexRange(i, this->table_size[0]);
3400  AssertIndexRange(j, this->table_size[1]);
3401  AssertIndexRange(k, this->table_size[2]);
3402  AssertIndexRange(l, this->table_size[3]);
3403  AssertIndexRange(m, this->table_size[4]);
3404  return this
3405  ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3406  k) *
3407  this->table_size[3] +
3408  l) *
3409  this->table_size[4] +
3410  m];
3411 }
3412 
3413 
3414 
3415 template <typename T>
3416 inline typename AlignedVector<T>::reference
3418  const size_type j,
3419  const size_type k,
3420  const size_type l,
3421  const size_type m)
3422 {
3423  AssertIndexRange(i, this->table_size[0]);
3424  AssertIndexRange(j, this->table_size[1]);
3425  AssertIndexRange(k, this->table_size[2]);
3426  AssertIndexRange(l, this->table_size[3]);
3427  AssertIndexRange(m, this->table_size[4]);
3428  return this
3429  ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3430  k) *
3431  this->table_size[3] +
3432  l) *
3433  this->table_size[4] +
3434  m];
3435 }
3436 
3437 
3438 
3439 template <typename T>
3440 inline typename AlignedVector<T>::const_reference
3441 Table<5, T>::operator()(const TableIndices<5> &indices) const
3442 {
3443  return TableBase<5, T>::operator()(indices);
3444 }
3445 
3446 
3447 
3448 template <typename T>
3449 inline typename AlignedVector<T>::reference
3451 {
3452  return TableBase<5, T>::operator()(indices);
3453 }
3454 
3455 
3456 
3457 template <typename T>
3458 inline Table<6, T>::Table(const size_type size1,
3459  const size_type size2,
3460  const size_type size3,
3461  const size_type size4,
3462  const size_type size5,
3463  const size_type size6)
3464  : TableBase<6, T>()
3465 {
3466  TableIndices<6> table_indices;
3467  table_indices[0] = size1;
3468  table_indices[1] = size2;
3469  table_indices[2] = size3;
3470  table_indices[3] = size4;
3471  table_indices[4] = size5;
3472  table_indices[5] = size6;
3473 
3474  TableBase<6, T>::reinit(table_indices);
3475 }
3476 
3477 
3478 
3479 template <typename T>
3480 inline ::internal::TableBaseAccessors::Accessor<6, T, true, 5>
3481  Table<6, T>::operator[](const size_type i) const
3482 {
3483  AssertIndexRange(i, this->table_size[0]);
3484  const size_type subobject_size = size_type(this->table_size[1]) *
3485  this->table_size[2] * this->table_size[3] *
3486  this->table_size[4] * this->table_size[5];
3488  *this, this->values.begin() + i * subobject_size));
3489 }
3490 
3491 
3492 
3493 template <typename T>
3494 inline ::internal::TableBaseAccessors::Accessor<6, T, false, 5>
3496 {
3497  AssertIndexRange(i, this->table_size[0]);
3498  const size_type subobject_size = size_type(this->table_size[1]) *
3499  this->table_size[2] * this->table_size[3] *
3500  this->table_size[4] * this->table_size[5];
3502  *this, this->values.begin() + i * subobject_size));
3503 }
3504 
3505 
3506 
3507 template <typename T>
3508 inline typename AlignedVector<T>::const_reference
3510  const size_type j,
3511  const size_type k,
3512  const size_type l,
3513  const size_type m,
3514  const size_type n) const
3515 {
3516  AssertIndexRange(i, this->table_size[0]);
3517  AssertIndexRange(j, this->table_size[1]);
3518  AssertIndexRange(k, this->table_size[2]);
3519  AssertIndexRange(l, this->table_size[3]);
3520  AssertIndexRange(m, this->table_size[4]);
3521  AssertIndexRange(n, this->table_size[5]);
3522  return this
3523  ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3524  k) *
3525  this->table_size[3] +
3526  l) *
3527  this->table_size[4] +
3528  m) *
3529  this->table_size[5] +
3530  n];
3531 }
3532 
3533 
3534 
3535 template <typename T>
3536 inline typename AlignedVector<T>::reference
3538  const size_type j,
3539  const size_type k,
3540  const size_type l,
3541  const size_type m,
3542  const size_type n)
3543 {
3544  AssertIndexRange(i, this->table_size[0]);
3545  AssertIndexRange(j, this->table_size[1]);
3546  AssertIndexRange(k, this->table_size[2]);
3547  AssertIndexRange(l, this->table_size[3]);
3548  AssertIndexRange(m, this->table_size[4]);
3549  AssertIndexRange(n, this->table_size[5]);
3550  return this
3551  ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3552  k) *
3553  this->table_size[3] +
3554  l) *
3555  this->table_size[4] +
3556  m) *
3557  this->table_size[5] +
3558  n];
3559 }
3560 
3561 
3562 
3563 template <typename T>
3564 inline typename AlignedVector<T>::const_reference
3565 Table<6, T>::operator()(const TableIndices<6> &indices) const
3566 {
3567  return TableBase<6, T>::operator()(indices);
3568 }
3569 
3570 
3571 
3572 template <typename T>
3573 inline typename AlignedVector<T>::reference
3575 {
3576  return TableBase<6, T>::operator()(indices);
3577 }
3578 
3579 
3580 
3581 template <typename T>
3582 inline Table<7, T>::Table(const size_type size1,
3583  const size_type size2,
3584  const size_type size3,
3585  const size_type size4,
3586  const size_type size5,
3587  const size_type size6,
3588  const size_type size7)
3589  : TableBase<7, T>()
3590 {
3591  TableIndices<7> table_indices;
3592  table_indices[0] = size1;
3593  table_indices[1] = size2;
3594  table_indices[2] = size3;
3595  table_indices[3] = size4;
3596  table_indices[4] = size5;
3597  table_indices[5] = size6;
3598  table_indices[6] = size7;
3599 
3600  TableBase<7, T>::reinit(table_indices);
3601 }
3602 
3603 
3604 
3605 template <typename T>
3606 inline ::internal::TableBaseAccessors::Accessor<7, T, true, 6>
3607  Table<7, T>::operator[](const size_type i) const
3608 {
3609  AssertIndexRange(i, this->table_size[0]);
3610  const size_type subobject_size =
3611  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3612  this->table_size[4] * this->table_size[5] * this->table_size[6];
3614  *this, this->values.begin() + i * subobject_size));
3615 }
3616 
3617 
3618 
3619 template <typename T>
3620 inline ::internal::TableBaseAccessors::Accessor<7, T, false, 6>
3622 {
3623  AssertIndexRange(i, this->table_size[0]);
3624  const size_type subobject_size =
3625  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3626  this->table_size[4] * this->table_size[5] * this->table_size[6];
3628  *this, this->values.begin() + i * subobject_size));
3629 }
3630 
3631 
3632 
3633 template <typename T>
3634 inline typename AlignedVector<T>::const_reference
3636  const size_type j,
3637  const size_type k,
3638  const size_type l,
3639  const size_type m,
3640  const size_type n,
3641  const size_type o) const
3642 {
3643  AssertIndexRange(i, this->table_size[0]);
3644  AssertIndexRange(j, this->table_size[1]);
3645  AssertIndexRange(k, this->table_size[2]);
3646  AssertIndexRange(l, this->table_size[3]);
3647  AssertIndexRange(m, this->table_size[4]);
3648  AssertIndexRange(n, this->table_size[5]);
3649  AssertIndexRange(o, this->table_size[6]);
3650  return this->values
3651  [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3652  this->table_size[3] +
3653  l) *
3654  this->table_size[4] +
3655  m) *
3656  this->table_size[5] +
3657  n) *
3658  this->table_size[6] +
3659  o];
3660 }
3661 
3662 
3663 
3664 template <typename T>
3665 inline typename AlignedVector<T>::reference
3667  const size_type j,
3668  const size_type k,
3669  const size_type l,
3670  const size_type m,
3671  const size_type n,
3672  const size_type o)
3673 {
3674  AssertIndexRange(i, this->table_size[0]);
3675  AssertIndexRange(j, this->table_size[1]);
3676  AssertIndexRange(k, this->table_size[2]);
3677  AssertIndexRange(l, this->table_size[3]);
3678  AssertIndexRange(m, this->table_size[4]);
3679  AssertIndexRange(n, this->table_size[5]);
3680  AssertIndexRange(o, this->table_size[6]);
3681  return this->values
3682  [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3683  this->table_size[3] +
3684  l) *
3685  this->table_size[4] +
3686  m) *
3687  this->table_size[5] +
3688  n) *
3689  this->table_size[6] +
3690  o];
3691 }
3692 
3693 
3694 
3695 template <typename T>
3696 inline typename AlignedVector<T>::const_reference
3697 Table<7, T>::operator()(const TableIndices<7> &indices) const
3698 {
3699  return TableBase<7, T>::operator()(indices);
3700 }
3701 
3702 
3703 
3704 template <typename T>
3705 inline typename AlignedVector<T>::reference
3707 {
3708  return TableBase<7, T>::operator()(indices);
3709 }
3710 
3711 
3712 #endif // DOXYGEN
3713 
3714 
3715 
3721 template <int N, typename T>
3722 inline void
3724 {
3725  u.swap(v);
3726 }
3727 
3729 
3730 #endif
bool operator==(const TableBase< N, T > &T2) const
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition: matrix_block.h:618
typename TableBase< 3, T >::size_type size_type
Definition: table.h:1380
size_type position(const TableIndices< N > &indices) const
Storage
Enumeration describing the storage order (i.e., the in-memory layout) of a table class.
Definition: table.h:820
void serialize(Archive &ar, const unsigned int version)
void swap(TableBase< N, T > &v)
types::global_dof_index size_type
Definition: cuda_kernels.h:45
typename Types< N, T, C >::TableType TableType
Definition: table.h:163
typename AlignedVector< T >::iterator iterator
Definition: table.h:115
typename TableBase< 2, T >::size_type size_type
Definition: table.h:1900
MatrixTableIterators::Iterator< TransposeTable< T >, true, MatrixTableIterators::Storage::column_major > const_iterator
Definition: table.h:1924
const TableIndices< N > & size() const
Accessor< N, T, C, P - 1 > operator[](const size_type i) const
typename TableBase< 6, T >::size_type size_type
Definition: table.h:1700
typename AccessorBase< TableType, true, storage_order >::value_type value_type
Definition: table.h:1007
size_type n_cols() const
typename Types< N, T, C >::iterator iterator
Definition: table.h:165
typename AlignedVector< number >::reference reference
Definition: table.h:1910
typename std::conditional< Constness, const TableType *, TableType * >::type container_pointer_type
Definition: table.h:868
#define AssertIndexRange(index, range)
Definition: exceptions.h:1691
typename AlignedVector< T >::const_reference const_reference
Definition: table.h:119
size_type n_rows() const
typename Types< N, T, C >::const_iterator const_iterator
Definition: table.h:248
typename TableBase< 2, T >::size_type size_type
Definition: table.h:1133
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
size_type n_elements() const
typename AlignedVector< T >::reference reference
Definition: table.h:118
bool operator==(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
typename TableBase< 1, T >::size_type size_type
Definition: table.h:709
value_type * iterator
SymmetricTensor< 2, dim, Number > C(const Tensor< 2, dim, Number > &F)
typename Types< N, T, C >::const_iterator const_iterator
Definition: table.h:166
typename AlignedVector< T >::const_reference const_reference
Definition: table.h:1148
typename Types< N, T, C >::TableType TableType
Definition: table.h:259
typename TableBase< 4, T >::size_type size_type
Definition: table.h:1511
MatrixTableIterators::Iterator< TransposeTable< T >, false, MatrixTableIterators::Storage::column_major > iterator
Definition: table.h:1932
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition: table.h:1013
static ::ExceptionBase & ExcMessage(std::string arg1)
iterator end()
iterator begin()
typename AlignedVector< T >::const_iterator const_iterator
Definition: table.h:98
static const char T
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
typename AccessorBase< TableType, true, storage_order >::value_type value_type
Definition: table.h:980
#define Assert(cond, exc)
Definition: exceptions.h:1466
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition: table.h:986
Accessor base class for Table<2, T> and TransposeTable.
Definition: table.h:861
void reinit(const size_type size1, const size_type size2, const bool omit_default_initialization=false)
AlignedVector< T >::reference el(const TableIndices< N > &indices)
container_pointer_type container
Definition: table.h:942
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:372
VectorType::value_type * end(VectorType &V)
typename Types< N, T, C >::iterator iterator
Definition: table.h:247
typename TableType::size_type size_type
Definition: table.h:1074
TableBase()=default
typename AlignedVector< T >::const_reference reference
Definition: table.h:100
const value_type * const_iterator
value_type & reference
friend bool operator==(const AccessorBase< TableType, Constness, storage_order > &left, const AccessorBase< TableType, OtherConstness, storage_order > &right)
Definition: table.h:906
Accessor class offering read and write access to the elements of a table.
Definition: table.h:999
typename Types< N, T, C >::reference reference
Definition: table.h:250
typename AlignedVector< T >::const_reference const_reference
Definition: table.h:101
typename AlignedVector< T >::const_iterator iterator
Definition: table.h:97
typename Types< N, T, C >::const_reference const_reference
Definition: table.h:251
Iterator class for both matrix-like tables, i.e., Table<2, T> and TransposeTable. ...
Definition: table.h:835
void swap(TableBase< N, T > &u, TableBase< N, T > &v)
Definition: table.h:3723
size_type size(const unsigned int i) const
TableBase< N, T > & operator=(const TableBase< N, T > &src)
typename AlignedVector< Number >::size_type size_type
Definition: table.h:409
std::size_t memory_consumption() const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:371
VectorType::value_type * begin(VectorType &V)
typename TableBase< 5, T >::size_type size_type
Definition: table.h:1604
void reset_values()
static const char N
typename AlignedVector< T >::reference reference
Definition: table.h:1143
TransposeTable()=default
typename AlignedVector< T >::value_type value_type
Definition: table.h:1138
reference el(const size_type i, const size_type j)
static ::ExceptionBase & ExcNotImplemented()
typename Types< N, T, C >::value_type value_type
Definition: table.h:245
Definition: table.h:687
bool empty() const
TableIndices< N > table_size
Definition: table.h:666
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:561
const_reference operator()(const size_type i, const size_type j) const
AlignedVector< T >::reference operator()(const TableIndices< N > &indices)
AlignedVector< T > values
Definition: table.h:661
Accessor class template. This class is partially specialized for both values of Constness.
Definition: table.h:842
void copy(const T *begin, const T *end, U *dest)
typename TableBase< 7, T >::size_type size_type
Definition: table.h:1797
const value_type & const_reference
void fill(InputIterator entries, const bool C_style_indexing=true)
T max(const T &t, const MPI_Comm &mpi_communicator)
typename AlignedVector< T >::const_iterator const_iterator
Definition: table.h:116
std::size_t size_type
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
typename AlignedVector< number >::const_reference const_reference
Definition: table.h:1915
typename std::conditional< Constness, const TableType *, TableType * >::type container_pointer_type
Definition: table.h:1080
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
static ::ExceptionBase & ExcInternalError()