Reference documentation for deal.II version 9.3.0
\(\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 - 2021 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 
437 template <int N, typename T>
438 class TableBase : public Subscriptor
439 {
440 public:
441  using value_type = T;
442 
447 
448 
452  TableBase() = default;
453 
458  explicit TableBase(const TableIndices<N> &sizes);
459 
465  template <typename InputIterator>
466  TableBase(const TableIndices<N> &sizes,
467  InputIterator entries,
468  const bool C_style_indexing = true);
469 
473  TableBase(const TableBase<N, T> &src);
474 
479  template <typename T2>
480  TableBase(const TableBase<N, T2> &src);
481 
485  TableBase(TableBase<N, T> &&src) noexcept;
486 
490  ~TableBase() override = default;
491 
501  operator=(const TableBase<N, T> &src);
502 
510  template <typename T2>
512  operator=(const TableBase<N, T2> &src);
513 
519  operator=(TableBase<N, T> &&src) noexcept;
520 
524  bool
525  operator==(const TableBase<N, T> &T2) const;
526 
531  void
532  reset_values();
533 
542  void
543  reinit(const TableIndices<N> &new_size,
544  const bool omit_default_initialization = false);
545 
549  size_type
550  size(const unsigned int i) const;
551 
555  const TableIndices<N> &
556  size() const;
557 
562  size_type
563  n_elements() const;
564 
569  bool
570  empty() const;
571 
608  template <typename InputIterator>
609  void
610  fill(InputIterator entries, const bool C_style_indexing = true);
611 
615  void
616  fill(const T &value);
617 
622  operator()(const TableIndices<N> &indices);
623 
632  operator()(const TableIndices<N> &indices) const;
633 
718  void
719  replicate_across_communicator(const MPI_Comm & communicator,
720  const unsigned int root_process);
721 
734  void
735  swap(TableBase<N, T> &v);
736 
741  std::size_t
742  memory_consumption() const;
743 
749  template <class Archive>
750  void
751  serialize(Archive &ar, const unsigned int version);
752 
753 protected:
758  size_type
759  position(const TableIndices<N> &indices) const;
760 
768  el(const TableIndices<N> &indices);
769 
781  el(const TableIndices<N> &indices) const;
782 
783 protected:
788 
793 
794  // Make all other table classes friends.
795  template <int, typename>
796  friend class TableBase;
797 };
798 
799 
812 template <int N, typename T>
813 class Table;
814 
815 
824 template <typename T>
825 class Table<1, T> : public TableBase<1, T>
826 {
827 public:
832 
836  Table() = default;
837 
841  explicit Table(const size_type size);
842 
880  template <typename InputIterator>
881  Table(const size_type size,
882  InputIterator entries,
883  const bool C_style_indexing = true);
884 
890  operator[](const size_type i) const;
891 
896  typename AlignedVector<T>::reference operator[](const size_type i);
897 
903  operator()(const size_type i) const;
904 
910  operator()(const size_type i);
911 
916 };
917 
918 
919 
928 {
933  enum class Storage
934  {
938  row_major,
939 
944  };
945 
946  // Forward declaration of the iterator class.
947  template <typename TableType, bool Constness, Storage storage_order>
948  class Iterator;
949 
954  template <typename TableType, bool Constness, Storage storage_order>
955  class Accessor;
956 
973  template <typename TableType, bool Constness, Storage storage_order>
975  {
976  public:
980  using container_pointer_type = typename std::
981  conditional<Constness, const TableType *, TableType *>::type;
982 
986  using value_type = typename TableType::value_type;
987 
991  using size_type = typename TableType::size_type;
992 
996  AccessorBase();
997 
1001  AccessorBase(const container_pointer_type table);
1002 
1007 
1012  const std::ptrdiff_t linear_index);
1013 
1017  template <bool OtherConstness>
1018  friend bool
1022  {
1023  return left.container == right.container &&
1024  left.linear_index == right.linear_index;
1025  }
1026 
1031  const value_type &
1032  value() const;
1033 
1037  operator const value_type &() const;
1038 
1042  size_type
1043  row() const;
1044 
1048  size_type
1049  column() const;
1050 
1051  protected:
1056 
1060  std::ptrdiff_t linear_index;
1061 
1068  void
1069  assert_valid_linear_index() const;
1070 
1071  // Make the const version a friend for copying.
1072  friend class AccessorBase<TableType, true, storage_order>;
1073 
1074  // Make the underlying iterator class a friend.
1075  friend class LinearIndexIterator<
1076  Iterator<TableType, Constness, storage_order>,
1077  Accessor<TableType, Constness, storage_order>>;
1078  };
1079 
1084  template <typename TableType, Storage storage_order>
1085  class Accessor<TableType, true, storage_order>
1086  : public AccessorBase<TableType, true, storage_order>
1087  {
1088  public:
1092  using value_type =
1094 
1098  using size_type =
1100 
1105  };
1106 
1111  template <typename TableType, Storage storage_order>
1112  class Accessor<TableType, false, storage_order>
1113  : public AccessorBase<TableType, false, storage_order>
1114  {
1115  public:
1119  using value_type =
1121 
1125  using size_type =
1127 
1132 
1138  operator=(const value_type &) const;
1139 
1145  operator=(value_type &&) const;
1146 
1152 
1157  value_type &
1158  value() const;
1159 
1163  operator value_type &();
1164  };
1165 
1178  template <typename TableType, bool Constness, Storage storage_order>
1179  class Iterator
1180  : public LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
1181  Accessor<TableType, Constness, storage_order>>
1182  {
1183  public:
1188 
1192  using container_pointer_type = typename std::
1193  conditional<Constness, const TableType *, TableType *>::type;
1194 
1199 
1203  Iterator(const container_pointer_type object);
1204 
1208  Iterator(const container_pointer_type object,
1209  const size_type row,
1210  const size_type column);
1211 
1216 
1220  Iterator(const container_pointer_type container,
1221  const std::ptrdiff_t linear_index);
1222  };
1223 } // namespace MatrixTableIterators
1224 
1225 
1226 
1240 template <typename T>
1241 class Table<2, T> : public TableBase<2, T>
1242 {
1243 public:
1248 
1253 
1258 
1263 
1268  using const_iterator = MatrixTableIterators::
1269  Iterator<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1270 
1274  using iterator = MatrixTableIterators::
1275  Iterator<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1276 
1280  Table() = default;
1281 
1285  Table(const size_type size1, const size_type size2);
1286 
1325  template <typename InputIterator>
1326  Table(const size_type size1,
1327  const size_type size2,
1328  InputIterator entries,
1329  const bool C_style_indexing = true);
1330 
1336  void
1337  reinit(const size_type size1,
1338  const size_type size2,
1339  const bool omit_default_initialization = false);
1340 
1342 
1350  operator[](const size_type i) const;
1351 
1359  operator[](const size_type i);
1360 
1368  operator()(const size_type i, const size_type j) const;
1369 
1377  operator()(const size_type i, const size_type j);
1378 
1382  using TableBase<2, T>::operator();
1383 
1388  size_type
1389  n_rows() const;
1390 
1395  size_type
1396  n_cols() const;
1397 
1401  iterator
1402  begin();
1403 
1408  begin() const;
1409 
1413  iterator
1414  end();
1415 
1420  end() const;
1421 
1422 protected:
1434  el(const size_type i, const size_type j);
1435 
1451  el(const size_type i, const size_type j) const;
1452 
1453  // Make the AccessorBase class a friend so that it may directly index into
1454  // the array.
1455  friend class MatrixTableIterators::
1456  AccessorBase<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1457  friend class MatrixTableIterators::
1458  AccessorBase<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1459 
1460  // Make the mutable accessor class a friend so that we can write to array
1461  // entries with iterators.
1462  friend class MatrixTableIterators::
1463  Accessor<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1464 };
1465 
1466 
1467 
1477 template <typename T>
1478 class Table<3, T> : public TableBase<3, T>
1479 {
1480 public:
1485 
1489  Table() = default;
1490 
1494  Table(const size_type size1, const size_type size2, const size_type size3);
1495 
1536  template <typename InputIterator>
1537  Table(const size_type size1,
1538  const size_type size2,
1539  const size_type size3,
1540  InputIterator entries,
1541  const bool C_style_indexing = true);
1542 
1551  operator[](const size_type i) const;
1552 
1561  operator[](const size_type i);
1562 
1570  operator()(const size_type i, const size_type j, const size_type k) const;
1571 
1572 
1580  operator()(const size_type i, const size_type j, const size_type k);
1581 
1585  using TableBase<3, T>::operator();
1586 };
1587 
1588 
1589 
1599 template <typename T>
1600 class Table<4, T> : public TableBase<4, T>
1601 {
1602 public:
1607 
1611  Table() = default;
1612 
1616  Table(const size_type size1,
1617  const size_type size2,
1618  const size_type size3,
1619  const size_type size4);
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) const;
1652 
1653 
1661  operator()(const size_type i,
1662  const size_type j,
1663  const size_type k,
1664  const size_type l);
1665 
1669  using TableBase<4, T>::operator();
1670 };
1671 
1672 
1673 
1683 template <typename T>
1684 class Table<5, T> : public TableBase<5, T>
1685 {
1686 public:
1691 
1692 
1696  Table() = default;
1697 
1701  Table(const size_type size1,
1702  const size_type size2,
1703  const size_type size3,
1704  const size_type size4,
1705  const size_type size5);
1706 
1715  operator[](const size_type i) const;
1716 
1725  operator[](const size_type i);
1726 
1734  operator()(const size_type i,
1735  const size_type j,
1736  const size_type k,
1737  const size_type l,
1738  const size_type m) const;
1739 
1747  operator()(const size_type i,
1748  const size_type j,
1749  const size_type k,
1750  const size_type l,
1751  const size_type m);
1752 
1756  using TableBase<5, T>::operator();
1757 };
1758 
1759 
1760 
1770 template <typename T>
1771 class Table<6, T> : public TableBase<6, T>
1772 {
1773 public:
1778 
1782  Table() = default;
1783 
1787  Table(const size_type size1,
1788  const size_type size2,
1789  const size_type size3,
1790  const size_type size4,
1791  const size_type size5,
1792  const size_type size6);
1793 
1802  operator[](const size_type i) const;
1803 
1812  operator[](const size_type i);
1813 
1821  operator()(const size_type i,
1822  const size_type j,
1823  const size_type k,
1824  const size_type l,
1825  const size_type m,
1826  const size_type n) const;
1827 
1835  operator()(const size_type i,
1836  const size_type j,
1837  const size_type k,
1838  const size_type l,
1839  const size_type m,
1840  const size_type n);
1841 
1845  using TableBase<6, T>::operator();
1846 };
1847 
1848 
1858 template <typename T>
1859 class Table<7, T> : public TableBase<7, T>
1860 {
1861 public:
1866 
1870  Table() = default;
1871 
1875  Table(const size_type size1,
1876  const size_type size2,
1877  const size_type size3,
1878  const size_type size4,
1879  const size_type size5,
1880  const size_type size6,
1881  const size_type size7);
1882 
1891  operator[](const size_type i) const;
1892 
1901  operator[](const size_type i);
1902 
1910  operator()(const size_type i,
1911  const size_type j,
1912  const size_type k,
1913  const size_type l,
1914  const size_type m,
1915  const size_type n,
1916  const size_type o) const;
1917 
1925  operator()(const size_type i,
1926  const size_type j,
1927  const size_type k,
1928  const size_type l,
1929  const size_type m,
1930  const size_type n,
1931  const size_type o);
1932 
1936  using TableBase<7, T>::operator();
1937 };
1938 
1939 
1952 template <typename T>
1953 class TransposeTable : public TableBase<2, T>
1954 {
1955 public:
1960 
1965 
1970 
1975 
1980  using const_iterator =
1982  true,
1984 
1988  using iterator =
1990  false,
1992 
1996  TransposeTable() = default;
1997 
2001  TransposeTable(const size_type size1, const size_type size2);
2002 
2008  void
2009  reinit(const size_type size1,
2010  const size_type size2,
2011  const bool omit_default_initialization = false);
2012 
2020  operator()(const size_type i, const size_type j) const;
2021 
2028  reference
2029  operator()(const size_type i, const size_type j);
2030 
2035  size_type
2036  n_rows() const;
2037 
2042  size_type
2043  n_cols() const;
2044 
2048  iterator
2049  begin();
2050 
2055  begin() const;
2056 
2060  iterator
2061  end();
2062 
2067  end() const;
2068 
2069 protected:
2080  reference
2081  el(const size_type i, const size_type j);
2082 
2098  el(const size_type i, const size_type j) const;
2099 
2100  // Make the AccessorBase class a friend so that it may directly index into
2101  // the array.
2103  TransposeTable<T>,
2104  true,
2107  TransposeTable<T>,
2108  false,
2109  MatrixTableIterators::Storage::column_major>;
2110 
2111  // Make the mutable accessor class a friend so that we can write to array
2112  // entries with iterators.
2113  friend class MatrixTableIterators::Accessor<
2114  TransposeTable<T>,
2115  false,
2116  MatrixTableIterators::Storage::column_major>;
2117 };
2118 
2119 
2120 
2121 /* --------------------- Template and inline functions ---------------- */
2122 
2123 #ifndef DOXYGEN
2124 
2125 template <int N, typename T>
2126 TableBase<N, T>::TableBase(const TableIndices<N> &sizes)
2127 {
2128  reinit(sizes);
2129 }
2130 
2131 
2132 
2133 template <int N, typename T>
2134 template <typename InputIterator>
2136  InputIterator entries,
2137  const bool C_style_indexing)
2138 {
2139  reinit(sizes);
2140  fill(entries, C_style_indexing);
2141 }
2142 
2143 
2144 
2145 template <int N, typename T>
2147  : Subscriptor()
2148 {
2149  reinit(src.table_size, true);
2150  values = src.values;
2151 }
2152 
2153 
2154 
2155 template <int N, typename T>
2156 template <typename T2>
2158 {
2159  reinit(src.table_size);
2160  if (src.n_elements() != 0)
2161  std::copy(src.values.begin(), src.values.end(), values.begin());
2162 }
2163 
2164 
2165 
2166 template <int N, typename T>
2168  : Subscriptor(std::move(src))
2169  , values(std::move(src.values))
2170  , table_size(src.table_size)
2171 {
2172  src.table_size = TableIndices<N>();
2173 }
2174 
2175 
2176 
2177 template <int N, typename T>
2178 template <class Archive>
2179 inline void
2180 TableBase<N, T>::serialize(Archive &ar, const unsigned int)
2181 {
2182  ar &static_cast<Subscriptor &>(*this);
2183 
2184  ar &values &table_size;
2185 }
2186 
2187 
2188 
2189 namespace internal
2190 {
2191  namespace TableBaseAccessors
2192  {
2193  template <int N, typename T, bool C, unsigned int P>
2194  inline Accessor<N, T, C, P>::Accessor(const TableType &table,
2195  const iterator data)
2196  : table(table)
2197  , data(data)
2198  {}
2199 
2200 
2201 
2202  template <int N, typename T, bool C, unsigned int P>
2203  inline Accessor<N, T, C, P>::Accessor(const Accessor &a)
2204  : table(a.table)
2205  , data(a.data)
2206  {}
2207 
2208 
2209 
2210  template <int N, typename T, bool C, unsigned int P>
2211  inline Accessor<N, T, C, P - 1> Accessor<N, T, C, P>::
2212  operator[](const size_type i) const
2213  {
2214  AssertIndexRange(i, table.size()[N - P]);
2215 
2216  // access i-th
2217  // subobject. optimize on the
2218  // case i==0
2219  if (i == 0)
2220  return Accessor<N, T, C, P - 1>(table, data);
2221  else
2222  {
2223  // note: P>1, otherwise the
2224  // specialization would have
2225  // been taken!
2226  size_type subobject_size = table.size()[N - 1];
2227  for (int p = P - 1; p > 1; --p)
2228  subobject_size *= table.size()[N - p];
2229  const iterator new_data = data + i * subobject_size;
2230  return Accessor<N, T, C, P - 1>(table, new_data);
2231  }
2232  }
2233 
2234 
2235 
2236  template <int N, typename T, bool C>
2237  inline Accessor<N, T, C, 1>::Accessor(const TableType &table,
2238  const iterator data)
2239  : table(table)
2240  , data(data)
2241  {}
2242 
2243 
2244 
2245  template <int N, typename T, bool C>
2246  inline Accessor<N, T, C, 1>::Accessor(const Accessor &a)
2247  : table(a.table)
2248  , data(a.data)
2249  {}
2250 
2251 
2252 
2253  template <int N, typename T, bool C>
2255  operator[](const size_type i) const
2256  {
2257  AssertIndexRange(i, table.size()[N - 1]);
2258  return *(data + i);
2259  }
2260 
2261 
2262 
2263  template <int N, typename T, bool C>
2264  inline typename Accessor<N, T, C, 1>::size_type
2266  {
2267  return table.size()[N - 1];
2268  }
2269 
2270 
2271 
2272  template <int N, typename T, bool C>
2273  inline typename Accessor<N, T, C, 1>::iterator
2275  {
2276  return data;
2277  }
2278 
2279 
2280 
2281  template <int N, typename T, bool C>
2282  inline typename Accessor<N, T, C, 1>::iterator
2284  {
2285  return data + table.size()[N - 1];
2286  }
2287  } // namespace TableBaseAccessors
2288 } // namespace internal
2289 
2290 
2291 
2292 template <int N, typename T>
2293 inline TableBase<N, T> &
2295 {
2296  if (!m.empty())
2297  values = m.values;
2298  reinit(m.size(), true);
2299 
2300  return *this;
2301 }
2302 
2303 
2304 
2305 template <int N, typename T>
2306 template <typename T2>
2307 inline TableBase<N, T> &
2309 {
2310  reinit(m.size(), true);
2311  if (!empty())
2312  std::copy(m.values.begin(),
2313  m.values.begin() + n_elements(),
2314  values.begin());
2315 
2316  return *this;
2317 }
2318 
2319 
2320 
2321 template <int N, typename T>
2322 inline TableBase<N, T> &
2324 {
2325  static_cast<Subscriptor &>(*this) = std::move(static_cast<Subscriptor &>(m));
2326  values = std::move(m.values);
2327  table_size = m.table_size;
2329 
2330  return *this;
2331 }
2332 
2333 
2334 
2335 template <int N, typename T>
2336 inline bool
2338 {
2339  return (values == T2.values);
2340 }
2341 
2342 
2343 
2344 template <int N, typename T>
2345 inline void
2347 {
2348  // use parallel set operation
2349  if (n_elements() != 0)
2350  values.fill(T());
2351 }
2352 
2353 
2354 
2355 template <int N, typename T>
2356 inline void
2357 TableBase<N, T>::fill(const T &value)
2358 {
2359  if (n_elements() != 0)
2360  values.fill(value);
2361 }
2362 
2363 
2364 
2365 template <int N, typename T>
2366 inline void
2368  const unsigned int root_process)
2369 {
2370  // Replicate first the actual data, then also exchange the
2371  // extents of the table
2372  values.replicate_across_communicator(communicator, root_process);
2373 
2374  table_size =
2375  Utilities::MPI::broadcast(communicator, table_size, root_process);
2376 }
2377 
2378 
2379 
2380 template <int N, typename T>
2381 inline void
2382 TableBase<N, T>::reinit(const TableIndices<N> &new_sizes,
2383  const bool omit_default_initialization)
2384 {
2385  table_size = new_sizes;
2386 
2387  const size_type new_size = n_elements();
2388 
2389  // if zero size was given: free all memory
2390  if (new_size == 0)
2391  {
2392  values.resize(0);
2393  // set all sizes to zero, even
2394  // if one was previously
2395  // nonzero. This simplifies
2396  // some assertions.
2397  table_size = TableIndices<N>();
2398 
2399  return;
2400  }
2401 
2402  // adjust values field. If it was empty before, we can simply call resize(),
2403  // which can set all the data fields. Otherwise, select the fast resize and
2404  // manually fill in all the elements as required by the design of this
2405  // class. (Selecting another code for the empty case ensures that we touch
2406  // the memory only once for non-trivial classes that need to initialize the
2407  // memory also in resize_fast.)
2408  if (!omit_default_initialization)
2409  {
2410  if (values.empty())
2411  values.resize(new_size);
2412  else
2413  {
2414  values.resize_fast(new_size);
2415  values.fill();
2416  }
2417  }
2418  else
2419  values.resize_fast(new_size);
2420 }
2421 
2422 
2423 
2424 template <int N, typename T>
2425 inline const TableIndices<N> &
2426 TableBase<N, T>::size() const
2427 {
2428  return table_size;
2429 }
2430 
2431 
2432 
2433 template <int N, typename T>
2434 inline typename TableBase<N, T>::size_type
2435 TableBase<N, T>::size(const unsigned int i) const
2436 {
2437  AssertIndexRange(i, N);
2438  return table_size[i];
2439 }
2440 
2441 
2442 
2443 template <int N, typename T>
2444 inline typename TableBase<N, T>::size_type
2446 {
2447  size_type s = 1;
2448  for (unsigned int n = 0; n < N; ++n)
2449  s *= table_size[n];
2450  return s;
2451 }
2452 
2453 
2454 
2455 template <int N, typename T>
2456 inline bool
2457 TableBase<N, T>::empty() const
2458 {
2459  return (n_elements() == 0);
2460 }
2461 
2462 
2463 
2464 namespace internal
2465 {
2466  namespace TableImplementation
2467  {
2468  template <typename InputIterator, typename T>
2469  void
2470  fill_Fortran_style(InputIterator entries, TableBase<1, T> &table)
2471  {
2472  using size_type = typename TableBase<1, T>::size_type;
2473  for (size_type i = 0; i < table.size()[0]; ++i)
2474  table(TableIndices<1>(i)) = *entries++;
2475  }
2476 
2477 
2478  template <typename InputIterator, typename T>
2479  void
2480  fill_Fortran_style(InputIterator entries, TableBase<2, T> &table)
2481  {
2482  using size_type = typename TableBase<2, T>::size_type;
2483  for (size_type j = 0; j < table.size()[1]; ++j)
2484  for (size_type i = 0; i < table.size()[0]; ++i)
2485  table(TableIndices<2>(i, j)) = *entries++;
2486  }
2487 
2488 
2489  template <typename InputIterator, typename T>
2490  void
2491  fill_Fortran_style(InputIterator entries, TableBase<3, T> &table)
2492  {
2493  using size_type = typename TableBase<3, T>::size_type;
2494  for (size_type k = 0; k < table.size()[2]; ++k)
2495  for (size_type j = 0; j < table.size()[1]; ++j)
2496  for (size_type i = 0; i < table.size()[0]; ++i)
2497  table(TableIndices<3>(i, j, k)) = *entries++;
2498  }
2499 
2500 
2501  template <typename InputIterator, typename T, int N>
2502  void
2503  fill_Fortran_style(InputIterator, TableBase<N, T> &)
2504  {
2505  Assert(false, ExcNotImplemented());
2506  }
2507  } // namespace TableImplementation
2508 } // namespace internal
2509 
2510 
2511 template <int N, typename T>
2512 template <typename InputIterator>
2513 inline void
2514 TableBase<N, T>::fill(InputIterator entries, const bool C_style_indexing)
2515 {
2516  Assert(n_elements() != 0, ExcMessage("Trying to fill an empty matrix."));
2517 
2518  if (C_style_indexing)
2519  for (typename AlignedVector<T>::iterator p = values.begin();
2520  p != values.end();
2521  ++p)
2522  *p = *entries++;
2523  else
2524  internal::TableImplementation::fill_Fortran_style(entries, *this);
2525 }
2526 
2527 
2528 
2529 template <int N, typename T>
2530 inline void
2532 {
2533  values.swap(v.values);
2534  std::swap(table_size, v.table_size);
2535 }
2536 
2537 
2538 
2539 template <int N, typename T>
2540 inline std::size_t
2542 {
2543  return sizeof(*this) + MemoryConsumption::memory_consumption(values);
2544 }
2545 
2546 
2547 
2548 template <int N, typename T>
2549 inline typename TableBase<N, T>::size_type
2550 TableBase<N, T>::position(const TableIndices<N> &indices) const
2551 {
2552  // specialize this for the
2553  // different numbers of dimensions,
2554  // to make the job somewhat easier
2555  // for the compiler. have the
2556  // general formula nevertheless:
2557  switch (N)
2558  {
2559  case 1:
2560  return indices[0];
2561  case 2:
2562  return size_type(indices[0]) * table_size[1] + indices[1];
2563  case 3:
2564  return ((size_type(indices[0]) * table_size[1] + indices[1]) *
2565  table_size[2] +
2566  indices[2]);
2567  default:
2568  {
2569  unsigned int s = indices[0];
2570  for (unsigned int n = 1; n < N; ++n)
2571  s = s * table_size[n] + indices[n];
2572  return s;
2573  }
2574  }
2575 }
2576 
2577 
2578 
2579 template <int N, typename T>
2580 inline typename AlignedVector<T>::const_reference
2581 TableBase<N, T>::operator()(const TableIndices<N> &indices) const
2582 {
2583  for (unsigned int n = 0; n < N; ++n)
2584  AssertIndexRange(indices[n], table_size[n]);
2585  return el(indices);
2586 }
2587 
2588 
2589 
2590 template <int N, typename T>
2591 inline typename AlignedVector<T>::reference
2593 {
2594  for (unsigned int n = 0; n < N; ++n)
2595  AssertIndexRange(indices[n], table_size[n]);
2596  return el(indices);
2597 }
2598 
2599 
2600 
2601 template <int N, typename T>
2602 inline typename AlignedVector<T>::const_reference
2603 TableBase<N, T>::el(const TableIndices<N> &indices) const
2604 {
2605  return values[position(indices)];
2606 }
2607 
2608 
2609 
2610 template <int N, typename T>
2611 inline typename AlignedVector<T>::reference
2612 TableBase<N, T>::el(const TableIndices<N> &indices)
2613 {
2614  AssertIndexRange(position(indices), values.size());
2615  return values[position(indices)];
2616 }
2617 
2618 
2619 
2620 template <typename T>
2621 inline Table<1, T>::Table(const size_type size)
2623 {}
2624 
2625 
2626 
2627 template <typename T>
2628 template <typename InputIterator>
2629 inline Table<1, T>::Table(const size_type size,
2630  InputIterator entries,
2631  const bool C_style_indexing)
2632  : TableBase<1, T>(TableIndices<1>(size), entries, C_style_indexing)
2633 {}
2634 
2635 
2636 
2637 template <typename T>
2639  operator[](const size_type i) const
2640 {
2641  AssertIndexRange(i, this->table_size[0]);
2642  return this->values[i];
2643 }
2644 
2645 
2646 
2647 template <typename T>
2649  operator[](const size_type i)
2650 {
2651  AssertIndexRange(i, this->table_size[0]);
2652  return this->values[i];
2653 }
2654 
2655 
2656 
2657 template <typename T>
2658 inline typename AlignedVector<T>::const_reference
2659 Table<1, T>::operator()(const size_type i) const
2660 {
2661  AssertIndexRange(i, this->table_size[0]);
2662  return this->values[i];
2663 }
2664 
2665 
2666 
2667 template <typename T>
2668 inline typename AlignedVector<T>::reference
2670 {
2671  AssertIndexRange(i, this->table_size[0]);
2672  return this->values[i];
2673 }
2674 
2675 
2676 //---------------------------------------------------------------------------
2677 
2678 
2679 
2680 template <typename T>
2681 inline Table<2, T>::Table(const size_type size1, const size_type size2)
2682  : TableBase<2, T>(TableIndices<2>(size1, size2))
2683 {}
2684 
2685 
2686 
2687 template <typename T>
2688 template <typename InputIterator>
2689 inline Table<2, T>::Table(const size_type size1,
2690  const size_type size2,
2691  InputIterator entries,
2692  const bool C_style_indexing)
2693  : TableBase<2, T>(TableIndices<2>(size1, size2), entries, C_style_indexing)
2694 {}
2695 
2696 
2697 
2698 template <typename T>
2699 inline void
2700 Table<2, T>::reinit(const size_type size1,
2701  const size_type size2,
2702  const bool omit_default_initialization)
2703 {
2704  this->TableBase<2, T>::reinit(TableIndices<2>(size1, size2),
2705  omit_default_initialization);
2706 }
2707 
2708 
2709 
2710 template <typename T>
2711 inline ::internal::TableBaseAccessors::Accessor<2, T, true, 1>
2712  Table<2, T>::operator[](const size_type i) const
2713 {
2714  AssertIndexRange(i, this->table_size[0]);
2715  return ::internal::TableBaseAccessors::Accessor<2, T, true, 1>(
2716  *this, this->values.begin() + size_type(i) * n_cols());
2717 }
2718 
2719 
2720 
2721 template <typename T>
2722 inline ::internal::TableBaseAccessors::Accessor<2, T, false, 1>
2724 {
2725  AssertIndexRange(i, this->table_size[0]);
2726  return ::internal::TableBaseAccessors::Accessor<2, T, false, 1>(
2727  *this, this->values.begin() + size_type(i) * n_cols());
2728 }
2729 
2730 
2731 
2732 template <typename T>
2733 inline typename AlignedVector<T>::const_reference
2734 Table<2, T>::operator()(const size_type i, const size_type j) const
2735 {
2736  AssertIndexRange(i, this->table_size[0]);
2737  AssertIndexRange(j, this->table_size[1]);
2738  return this->values[size_type(i) * this->table_size[1] + j];
2739 }
2740 
2741 
2742 
2743 template <typename T>
2744 inline typename AlignedVector<T>::reference
2746 {
2747  AssertIndexRange(i, this->table_size[0]);
2748  AssertIndexRange(j, this->table_size[1]);
2749  return this->values[size_type(i) * this->table_size[1] + j];
2750 }
2751 
2752 
2753 
2754 template <typename T>
2755 inline typename AlignedVector<T>::const_reference
2756 Table<2, T>::el(const size_type i, const size_type j) const
2757 {
2758  return this->values[size_type(i) * this->table_size[1] + j];
2759 }
2760 
2761 
2762 
2763 template <typename T>
2764 inline typename AlignedVector<T>::reference
2765 Table<2, T>::el(const size_type i, const size_type j)
2766 {
2767  return this->values[size_type(i) * this->table_size[1] + j];
2768 }
2769 
2770 
2771 
2772 template <typename T>
2773 inline typename Table<2, T>::size_type
2774 Table<2, T>::n_rows() const
2775 {
2776  return this->table_size[0];
2777 }
2778 
2779 
2780 
2781 template <typename T>
2782 inline typename Table<2, T>::size_type
2783 Table<2, T>::n_cols() const
2784 {
2785  return this->table_size[1];
2786 }
2787 
2788 
2789 
2790 template <typename T>
2791 inline typename Table<2, T>::iterator
2793 {
2794  return typename Table<2, T>::iterator(this, 0, 0);
2795 }
2796 
2797 
2798 
2799 template <typename T>
2800 inline typename Table<2, T>::const_iterator
2801 Table<2, T>::begin() const
2802 {
2803  return typename Table<2, T>::const_iterator(this, 0, 0);
2804 }
2805 
2806 
2807 
2808 template <typename T>
2809 inline typename Table<2, T>::iterator
2811 {
2812  return typename Table<2, T>::iterator(this);
2813 }
2814 
2815 
2816 
2817 template <typename T>
2818 inline typename Table<2, T>::const_iterator
2819 Table<2, T>::end() const
2820 {
2821  return typename Table<2, T>::const_iterator(this);
2822 }
2823 
2824 
2825 
2826 //---------------------------------------------------------------------------
2827 namespace MatrixTableIterators
2828 {
2829  namespace internal
2830  {
2831  // Internal calculation routines for AccessorBase. These do not do any
2832  // checking whatsoever.
2833  template <typename TableType, Storage storage_order>
2834  inline std::ptrdiff_t
2835  get_row_index(const std::ptrdiff_t linear_index,
2836  const TableType *const container)
2837  {
2838  switch (storage_order)
2839  {
2840  case Storage::row_major:
2841  return linear_index / container->n_cols();
2842  case Storage::column_major:
2843  return linear_index % container->n_rows();
2844  default:
2845  Assert(false, ExcInternalError());
2846  }
2847  return {};
2848  }
2849 
2850 
2851 
2852  template <typename TableType, Storage storage_order>
2853  inline std::ptrdiff_t
2854  get_column_index(const std::ptrdiff_t linear_index,
2855  const TableType *const container)
2856  {
2857  switch (storage_order)
2858  {
2859  case Storage::row_major:
2860  return linear_index % container->n_cols();
2861  case Storage::column_major:
2862  return linear_index / container->n_rows();
2863  default:
2864  Assert(false, ExcInternalError());
2865  }
2866  return {};
2867  }
2868  } // namespace internal
2869 
2870 
2871 
2872  template <typename TableType, bool Constness, Storage storage_order>
2873  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase()
2874  : container(nullptr)
2875  , linear_index(std::numeric_limits<decltype(linear_index)>::max())
2876  {}
2877 
2878 
2879 
2880  template <typename TableType, bool Constness, Storage storage_order>
2881  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2882  const container_pointer_type table)
2883  : container(table)
2884  , linear_index(container->values.size())
2885  {}
2886 
2887 
2888 
2889  template <typename TableType, bool Constness, Storage storage_order>
2890  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2891  const AccessorBase<TableType, false, storage_order> &a)
2892  : container(a.container)
2893  , linear_index(a.linear_index)
2894  {}
2895 
2896 
2897 
2898  template <typename TableType, bool Constness, Storage storage_order>
2899  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2900  const container_pointer_type table,
2901  const std::ptrdiff_t index)
2902  : container(table)
2903  , linear_index(index)
2904  {
2905  Assert(0 <= linear_index &&
2906  std::size_t(linear_index) < container->values.size() + 1,
2907  ExcMessage("The current iterator points outside of the table and is "
2908  "not the end iterator."));
2909  }
2910 
2911 
2912 
2913  template <typename TableType, bool Constness, Storage storage_order>
2914  inline const typename AccessorBase<TableType, Constness, storage_order>::
2915  value_type &
2917  {
2918  assert_valid_linear_index();
2919  return this->container->values[linear_index];
2920  }
2921 
2922 
2923 
2924  template <typename TableType, bool Constness, Storage storage_order>
2925  inline AccessorBase<TableType, Constness, storage_order>::
2926  operator const value_type &() const
2927  {
2928  assert_valid_linear_index();
2929  return this->container->values[linear_index];
2930  }
2931 
2932 
2933 
2934  template <typename TableType, bool Constness, Storage storage_order>
2936  AccessorBase<TableType, Constness, storage_order>::row() const
2937  {
2938  assert_valid_linear_index();
2939  return static_cast<std::size_t>(
2940  internal::get_row_index<TableType, storage_order>(linear_index,
2941  container));
2942  }
2943 
2944 
2945 
2946  template <typename TableType, bool Constness, Storage storage_order>
2948  AccessorBase<TableType, Constness, storage_order>::column() const
2949  {
2950  assert_valid_linear_index();
2951  return static_cast<std::size_t>(
2952  internal::get_column_index<TableType, storage_order>(linear_index,
2953  container));
2954  }
2955 
2956 
2957 
2958  template <typename TableType, bool Constness, Storage storage_order>
2959  inline void
2960  AccessorBase<TableType, Constness, storage_order>::assert_valid_linear_index()
2961  const
2962  {
2963 # ifdef DEBUG // avoid unused variable warnings by guarding everything
2964  Assert(container != nullptr,
2965  ExcMessage("This accessor has been default-constructed and does not "
2966  "have a corresponding table."));
2967  Assert(!container->empty(),
2968  ExcMessage("An empty table has no rows or columns."));
2969  Assert(0 <= linear_index &&
2970  std::size_t(linear_index) < container->values.size(),
2971  ExcMessage("The current iterator points outside of the table."));
2972  const std::ptrdiff_t row_n =
2973  internal::get_row_index<TableType, storage_order>(linear_index,
2974  container);
2975  const std::ptrdiff_t column_n =
2976  internal::get_column_index<TableType, storage_order>(linear_index,
2977  container);
2978  Assert(0 <= column_n && std::size_t(column_n) < container->n_cols(),
2979  ExcMessage("The current iterator points outside the table."));
2980  Assert(0 <= row_n && std::size_t(row_n) < container->n_rows(),
2981  ExcMessage("The current iterator points outside the table."));
2982 # endif
2983  }
2984 
2985 
2986 
2987  template <typename TableType, Storage storage_order>
2988  inline const Accessor<TableType, false, storage_order> &
2989  Accessor<TableType, false, storage_order>::operator=(
2990  const typename Accessor<TableType, false, storage_order>::value_type &t)
2991  const
2992  {
2993  this->assert_valid_linear_index();
2994  this->container->values[this->linear_index] = t;
2995  return *this;
2996  }
2997 
2998 
2999 
3000  template <typename TableType, Storage storage_order>
3001  inline const Accessor<TableType, false, storage_order> &
3002  Accessor<TableType, false, storage_order>::operator=(
3003  typename Accessor<TableType, false, storage_order>::value_type &&t) const
3004  {
3005  this->assert_valid_linear_index();
3006  this->container->values[this->linear_index] = t;
3007  return *this;
3008  }
3009 
3010 
3011 
3012  template <typename TableType, Storage storage_order>
3013  inline typename Accessor<TableType, false, storage_order>::value_type &
3015  {
3016  this->assert_valid_linear_index();
3017  return this->container->values[this->linear_index];
3018  }
3019 
3020 
3021 
3022  template <typename TableType, Storage storage_order>
3023  inline Accessor<TableType, false, storage_order>::operator value_type &()
3024  {
3025  this->assert_valid_linear_index();
3026  return this->container->values[this->linear_index];
3027  }
3028 
3029 
3030 
3031  template <typename TableType, bool Constness, Storage storage_order>
3032  inline Iterator<TableType, Constness, storage_order>::Iterator(
3036  {}
3037 
3038 
3039 
3040  template <typename TableType, bool Constness, Storage storage_order>
3041  inline Iterator<TableType, Constness, storage_order>::Iterator(
3042  const container_pointer_type table)
3046  {}
3047 
3048 
3049 
3050  template <typename TableType, bool Constness, Storage storage_order>
3051  inline Iterator<TableType, Constness, storage_order>::Iterator(
3052  const Iterator<TableType, false, storage_order> &i)
3055  {}
3056 
3057 
3058 
3059  template <typename TableType, bool Constness, Storage storage_order>
3060  inline Iterator<TableType, Constness, storage_order>::Iterator(
3061  const container_pointer_type table,
3062  const size_type row_n,
3063  const size_type col_n)
3064  : Iterator(table,
3065  storage_order == Storage::row_major ?
3066  table->n_cols() * row_n + col_n :
3067  table->n_rows() * col_n + row_n)
3068  {}
3069 
3070 
3071 
3072  template <typename TableType, bool Constness, Storage storage_order>
3073  inline Iterator<TableType, Constness, storage_order>::Iterator(
3074  const container_pointer_type table,
3075  const std::ptrdiff_t linear_index)
3078  Accessor<TableType, Constness, storage_order>(table, linear_index))
3079  {}
3080 } // namespace MatrixTableIterators
3081 
3082 
3083 
3084 //---------------------------------------------------------------------------
3085 template <typename T>
3086 inline TransposeTable<T>::TransposeTable(const size_type size1,
3087  const size_type size2)
3088  : TableBase<2, T>(TableIndices<2>(size2, size1))
3089 {}
3090 
3091 
3092 
3093 template <typename T>
3094 inline void
3096  const size_type size2,
3097  const bool omit_default_initialization)
3098 {
3099  this->TableBase<2, T>::reinit(TableIndices<2>(size2, size1),
3100  omit_default_initialization);
3101 }
3102 
3103 
3104 
3105 template <typename T>
3106 inline typename TransposeTable<T>::const_reference
3107 TransposeTable<T>::operator()(const size_type i, const size_type j) const
3108 {
3109  AssertIndexRange(i, this->table_size[1]);
3110  AssertIndexRange(j, this->table_size[0]);
3111  return this->values[size_type(j) * this->table_size[1] + i];
3112 }
3113 
3114 
3115 
3116 template <typename T>
3117 inline typename TransposeTable<T>::reference
3119 {
3120  AssertIndexRange(i, this->table_size[1]);
3121  AssertIndexRange(j, this->table_size[0]);
3122  return this->values[size_type(j) * this->table_size[1] + i];
3123 }
3124 
3125 
3126 
3127 template <typename T>
3128 inline typename TransposeTable<T>::const_reference
3129 TransposeTable<T>::el(const size_type i, const size_type j) const
3130 {
3131  return this->values[size_type(j) * this->table_size[1] + i];
3132 }
3133 
3134 
3135 
3136 template <typename T>
3137 inline typename TransposeTable<T>::reference
3138 TransposeTable<T>::el(const size_type i, const size_type j)
3139 {
3140  return this->values[size_type(j) * this->table_size[1] + i];
3141 }
3142 
3143 
3144 
3145 template <typename T>
3146 inline typename TransposeTable<T>::size_type
3148 {
3149  return this->table_size[1];
3150 }
3151 
3152 
3153 
3154 template <typename T>
3155 inline typename TransposeTable<T>::size_type
3157 {
3158  return this->table_size[0];
3159 }
3160 
3161 
3162 
3163 template <typename T>
3164 inline typename TransposeTable<T>::iterator
3166 {
3167  return typename TransposeTable<T>::iterator(this, 0, 0);
3168 }
3169 
3170 
3171 
3172 template <typename T>
3173 inline typename TransposeTable<T>::const_iterator
3175 {
3176  return typename TransposeTable<T>::const_iterator(this, 0, 0);
3177 }
3178 
3179 
3180 
3181 template <typename T>
3182 inline typename TransposeTable<T>::iterator
3184 {
3185  return typename TransposeTable<T>::iterator(this);
3186 }
3187 
3188 
3189 
3190 template <typename T>
3191 inline typename TransposeTable<T>::const_iterator
3192 TransposeTable<T>::end() const
3193 {
3194  return typename TransposeTable<T>::const_iterator(this);
3195 }
3196 //---------------------------------------------------------------------------
3197 
3198 
3199 
3200 template <typename T>
3201 inline Table<3, T>::Table(const size_type size1,
3202  const size_type size2,
3203  const size_type size3)
3204  : TableBase<3, T>(TableIndices<3>(size1, size2, size3))
3205 {}
3206 
3207 
3208 
3209 template <typename T>
3210 template <typename InputIterator>
3211 inline Table<3, T>::Table(const size_type size1,
3212  const size_type size2,
3213  const size_type size3,
3214  InputIterator entries,
3215  const bool C_style_indexing)
3216  : TableBase<3, T>(TableIndices<3>(size1, size2, size3),
3217  entries,
3218  C_style_indexing)
3219 {}
3220 
3221 
3222 
3223 template <typename T>
3224 inline ::internal::TableBaseAccessors::Accessor<3, T, true, 2>
3225  Table<3, T>::operator[](const size_type i) const
3226 {
3227  AssertIndexRange(i, this->table_size[0]);
3228  const size_type subobject_size =
3229  size_type(this->table_size[1]) * this->table_size[2];
3231  *this, this->values.begin() + i * subobject_size));
3232 }
3233 
3234 
3235 
3236 template <typename T>
3237 inline ::internal::TableBaseAccessors::Accessor<3, T, false, 2>
3239 {
3240  AssertIndexRange(i, this->table_size[0]);
3241  const size_type subobject_size =
3242  size_type(this->table_size[1]) * this->table_size[2];
3244  *this, this->values.begin() + i * subobject_size));
3245 }
3246 
3247 
3248 
3249 template <typename T>
3250 inline typename AlignedVector<T>::const_reference
3252 operator()(const size_type i, const size_type j, const size_type k) const
3253 {
3254  AssertIndexRange(i, this->table_size[0]);
3255  AssertIndexRange(j, this->table_size[1]);
3256  AssertIndexRange(k, this->table_size[2]);
3257  return this
3258  ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3259  k];
3260 }
3261 
3262 
3263 
3264 template <typename T>
3265 inline typename AlignedVector<T>::reference
3266 Table<3, T>::operator()(const size_type i, const size_type j, const size_type k)
3267 {
3268  AssertIndexRange(i, this->table_size[0]);
3269  AssertIndexRange(j, this->table_size[1]);
3270  AssertIndexRange(k, this->table_size[2]);
3271  return this
3272  ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3273  k];
3274 }
3275 
3276 
3277 
3278 template <typename T>
3279 inline Table<4, T>::Table(const size_type size1,
3280  const size_type size2,
3281  const size_type size3,
3282  const size_type size4)
3283  : TableBase<4, T>(TableIndices<4>(size1, size2, size3, size4))
3284 {}
3285 
3286 
3287 
3288 template <typename T>
3289 inline ::internal::TableBaseAccessors::Accessor<4, T, true, 3>
3290  Table<4, T>::operator[](const size_type i) const
3291 {
3292  AssertIndexRange(i, this->table_size[0]);
3293  const size_type subobject_size =
3294  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3296  *this, this->values.begin() + i * subobject_size));
3297 }
3298 
3299 
3300 
3301 template <typename T>
3302 inline ::internal::TableBaseAccessors::Accessor<4, T, false, 3>
3304 {
3305  AssertIndexRange(i, this->table_size[0]);
3306  const size_type subobject_size =
3307  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3309  *this, this->values.begin() + i * subobject_size));
3310 }
3311 
3312 
3313 
3314 template <typename T>
3315 inline typename AlignedVector<T>::const_reference
3317  const size_type j,
3318  const size_type k,
3319  const size_type l) const
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>::reference
3337  const size_type j,
3338  const size_type k,
3339  const size_type l)
3340 {
3341  AssertIndexRange(i, this->table_size[0]);
3342  AssertIndexRange(j, this->table_size[1]);
3343  AssertIndexRange(k, this->table_size[2]);
3344  AssertIndexRange(l, this->table_size[3]);
3345  return this
3346  ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3347  k) *
3348  this->table_size[3] +
3349  l];
3350 }
3351 
3352 
3353 
3354 template <typename T>
3355 inline Table<5, T>::Table(const size_type size1,
3356  const size_type size2,
3357  const size_type size3,
3358  const size_type size4,
3359  const size_type size5)
3360  : TableBase<5, T>(TableIndices<5>(size1, size2, size3, size4, size5))
3361 {}
3362 
3363 
3364 
3365 template <typename T>
3366 inline ::internal::TableBaseAccessors::Accessor<5, T, true, 4>
3367  Table<5, T>::operator[](const size_type i) const
3368 {
3369  AssertIndexRange(i, this->table_size[0]);
3370  const size_type subobject_size = size_type(this->table_size[1]) *
3371  this->table_size[2] * this->table_size[3] *
3372  this->table_size[4];
3374  *this, this->values.begin() + i * subobject_size));
3375 }
3376 
3377 
3378 
3379 template <typename T>
3380 inline ::internal::TableBaseAccessors::Accessor<5, T, false, 4>
3382 {
3383  AssertIndexRange(i, this->table_size[0]);
3384  const size_type subobject_size = size_type(this->table_size[1]) *
3385  this->table_size[2] * this->table_size[3] *
3386  this->table_size[4];
3388  *this, this->values.begin() + i * subobject_size));
3389 }
3390 
3391 
3392 
3393 template <typename T>
3394 inline typename AlignedVector<T>::const_reference
3396  const size_type j,
3397  const size_type k,
3398  const size_type l,
3399  const size_type m) const
3400 {
3401  AssertIndexRange(i, this->table_size[0]);
3402  AssertIndexRange(j, this->table_size[1]);
3403  AssertIndexRange(k, this->table_size[2]);
3404  AssertIndexRange(l, this->table_size[3]);
3405  AssertIndexRange(m, this->table_size[4]);
3406  return this
3407  ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3408  k) *
3409  this->table_size[3] +
3410  l) *
3411  this->table_size[4] +
3412  m];
3413 }
3414 
3415 
3416 
3417 template <typename T>
3418 inline typename AlignedVector<T>::reference
3420  const size_type j,
3421  const size_type k,
3422  const size_type l,
3423  const size_type m)
3424 {
3425  AssertIndexRange(i, this->table_size[0]);
3426  AssertIndexRange(j, this->table_size[1]);
3427  AssertIndexRange(k, this->table_size[2]);
3428  AssertIndexRange(l, this->table_size[3]);
3429  AssertIndexRange(m, this->table_size[4]);
3430  return this
3431  ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3432  k) *
3433  this->table_size[3] +
3434  l) *
3435  this->table_size[4] +
3436  m];
3437 }
3438 
3439 
3440 
3441 template <typename T>
3442 inline Table<6, T>::Table(const size_type size1,
3443  const size_type size2,
3444  const size_type size3,
3445  const size_type size4,
3446  const size_type size5,
3447  const size_type size6)
3448  : TableBase<6, T>()
3449 {
3450  TableIndices<6> table_indices;
3451  table_indices[0] = size1;
3452  table_indices[1] = size2;
3453  table_indices[2] = size3;
3454  table_indices[3] = size4;
3455  table_indices[4] = size5;
3456  table_indices[5] = size6;
3457 
3458  TableBase<6, T>::reinit(table_indices);
3459 }
3460 
3461 
3462 
3463 template <typename T>
3464 inline ::internal::TableBaseAccessors::Accessor<6, T, true, 5>
3465  Table<6, T>::operator[](const size_type i) const
3466 {
3467  AssertIndexRange(i, this->table_size[0]);
3468  const size_type subobject_size = size_type(this->table_size[1]) *
3469  this->table_size[2] * this->table_size[3] *
3470  this->table_size[4] * this->table_size[5];
3472  *this, this->values.begin() + i * subobject_size));
3473 }
3474 
3475 
3476 
3477 template <typename T>
3478 inline ::internal::TableBaseAccessors::Accessor<6, T, false, 5>
3480 {
3481  AssertIndexRange(i, this->table_size[0]);
3482  const size_type subobject_size = size_type(this->table_size[1]) *
3483  this->table_size[2] * this->table_size[3] *
3484  this->table_size[4] * this->table_size[5];
3486  *this, this->values.begin() + i * subobject_size));
3487 }
3488 
3489 
3490 
3491 template <typename T>
3492 inline typename AlignedVector<T>::const_reference
3494  const size_type j,
3495  const size_type k,
3496  const size_type l,
3497  const size_type m,
3498  const size_type n) const
3499 {
3500  AssertIndexRange(i, this->table_size[0]);
3501  AssertIndexRange(j, this->table_size[1]);
3502  AssertIndexRange(k, this->table_size[2]);
3503  AssertIndexRange(l, this->table_size[3]);
3504  AssertIndexRange(m, this->table_size[4]);
3505  AssertIndexRange(n, this->table_size[5]);
3506  return this
3507  ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3508  k) *
3509  this->table_size[3] +
3510  l) *
3511  this->table_size[4] +
3512  m) *
3513  this->table_size[5] +
3514  n];
3515 }
3516 
3517 
3518 
3519 template <typename T>
3520 inline typename AlignedVector<T>::reference
3522  const size_type j,
3523  const size_type k,
3524  const size_type l,
3525  const size_type m,
3526  const size_type n)
3527 {
3528  AssertIndexRange(i, this->table_size[0]);
3529  AssertIndexRange(j, this->table_size[1]);
3530  AssertIndexRange(k, this->table_size[2]);
3531  AssertIndexRange(l, this->table_size[3]);
3532  AssertIndexRange(m, this->table_size[4]);
3533  AssertIndexRange(n, this->table_size[5]);
3534  return this
3535  ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3536  k) *
3537  this->table_size[3] +
3538  l) *
3539  this->table_size[4] +
3540  m) *
3541  this->table_size[5] +
3542  n];
3543 }
3544 
3545 
3546 
3547 template <typename T>
3548 inline Table<7, T>::Table(const size_type size1,
3549  const size_type size2,
3550  const size_type size3,
3551  const size_type size4,
3552  const size_type size5,
3553  const size_type size6,
3554  const size_type size7)
3555  : TableBase<7, T>()
3556 {
3557  TableIndices<7> table_indices;
3558  table_indices[0] = size1;
3559  table_indices[1] = size2;
3560  table_indices[2] = size3;
3561  table_indices[3] = size4;
3562  table_indices[4] = size5;
3563  table_indices[5] = size6;
3564  table_indices[6] = size7;
3565 
3566  TableBase<7, T>::reinit(table_indices);
3567 }
3568 
3569 
3570 
3571 template <typename T>
3572 inline ::internal::TableBaseAccessors::Accessor<7, T, true, 6>
3573  Table<7, T>::operator[](const size_type i) const
3574 {
3575  AssertIndexRange(i, this->table_size[0]);
3576  const size_type subobject_size =
3577  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3578  this->table_size[4] * this->table_size[5] * this->table_size[6];
3580  *this, this->values.begin() + i * subobject_size));
3581 }
3582 
3583 
3584 
3585 template <typename T>
3586 inline ::internal::TableBaseAccessors::Accessor<7, T, false, 6>
3588 {
3589  AssertIndexRange(i, this->table_size[0]);
3590  const size_type subobject_size =
3591  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3592  this->table_size[4] * this->table_size[5] * this->table_size[6];
3594  *this, this->values.begin() + i * subobject_size));
3595 }
3596 
3597 
3598 
3599 template <typename T>
3600 inline typename AlignedVector<T>::const_reference
3602  const size_type j,
3603  const size_type k,
3604  const size_type l,
3605  const size_type m,
3606  const size_type n,
3607  const size_type o) const
3608 {
3609  AssertIndexRange(i, this->table_size[0]);
3610  AssertIndexRange(j, this->table_size[1]);
3611  AssertIndexRange(k, this->table_size[2]);
3612  AssertIndexRange(l, this->table_size[3]);
3613  AssertIndexRange(m, this->table_size[4]);
3614  AssertIndexRange(n, this->table_size[5]);
3615  AssertIndexRange(o, this->table_size[6]);
3616  return this->values
3617  [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3618  this->table_size[3] +
3619  l) *
3620  this->table_size[4] +
3621  m) *
3622  this->table_size[5] +
3623  n) *
3624  this->table_size[6] +
3625  o];
3626 }
3627 
3628 
3629 
3630 template <typename T>
3631 inline typename AlignedVector<T>::reference
3633  const size_type j,
3634  const size_type k,
3635  const size_type l,
3636  const size_type m,
3637  const size_type n,
3638  const size_type o)
3639 {
3640  AssertIndexRange(i, this->table_size[0]);
3641  AssertIndexRange(j, this->table_size[1]);
3642  AssertIndexRange(k, this->table_size[2]);
3643  AssertIndexRange(l, this->table_size[3]);
3644  AssertIndexRange(m, this->table_size[4]);
3645  AssertIndexRange(n, this->table_size[5]);
3646  AssertIndexRange(o, this->table_size[6]);
3647  return this->values
3648  [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3649  this->table_size[3] +
3650  l) *
3651  this->table_size[4] +
3652  m) *
3653  this->table_size[5] +
3654  n) *
3655  this->table_size[6] +
3656  o];
3657 }
3658 
3659 
3660 #endif // DOXYGEN
3661 
3662 
3663 
3669 template <int N, typename T>
3670 inline void
3672 {
3673  u.swap(v);
3674 }
3675 
3677 
3678 #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:1484
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:933
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:1959
MatrixTableIterators::Iterator< TransposeTable< T >, true, MatrixTableIterators::Storage::column_major > const_iterator
Definition: table.h:1983
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:1777
typename AccessorBase< TableType, true, storage_order >::value_type value_type
Definition: table.h:1120
size_type n_cols() const
typename Types< N, T, C >::iterator iterator
Definition: table.h:165
typename AlignedVector< number >::reference reference
Definition: table.h:1969
typename std::conditional< Constness, const TableType *, TableType * >::type container_pointer_type
Definition: table.h:981
#define AssertIndexRange(index, range)
Definition: exceptions.h:1690
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:1247
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:831
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:1262
typename Types< N, T, C >::TableType TableType
Definition: table.h:259
typename TableBase< 4, T >::size_type size_type
Definition: table.h:1606
MatrixTableIterators::Iterator< TransposeTable< T >, false, MatrixTableIterators::Storage::column_major > iterator
Definition: table.h:1991
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition: table.h:1126
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:1093
#define Assert(cond, exc)
Definition: exceptions.h:1465
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition: table.h:1099
Accessor base class for Table<2, T> and TransposeTable.
Definition: table.h:974
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:1055
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:395
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:1187
TableBase()=default
typename AlignedVector< T >::const_reference reference
Definition: table.h:100
void replicate_across_communicator(const MPI_Comm &communicator, const unsigned int root_process)
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:1019
Accessor class offering read and write access to the elements of a table.
Definition: table.h:1112
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:948
void swap(TableBase< N, T > &u, TableBase< N, T > &v)
Definition: table.h:3671
size_type size(const unsigned int i) const
TableBase< N, T > & operator=(const TableBase< N, T > &src)
typename AlignedVector< T >::size_type size_type
Definition: table.h:446
std::size_t memory_consumption() const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:394
VectorType::value_type * begin(VectorType &V)
typename TableBase< 5, T >::size_type size_type
Definition: table.h:1690
T broadcast(const MPI_Comm &comm, const T &object_to_send, const unsigned int root_process=0)
void reset_values()
static const char N
typename AlignedVector< T >::reference reference
Definition: table.h:1257
TransposeTable()=default
typename AlignedVector< T >::value_type value_type
Definition: table.h:1252
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
bool empty() const
TableIndices< N > table_size
Definition: table.h:792
#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:787
Accessor class template. This class is partially specialized for both values of Constness.
Definition: table.h:955
void copy(const T *begin, const T *end, U *dest)
typename TableBase< 7, T >::size_type size_type
Definition: table.h:1865
const value_type & const_reference
void fill(InputIterator entries, const bool C_style_indexing=true)
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:1974
typename std::conditional< Constness, const TableType *, TableType * >::type container_pointer_type
Definition: table.h:1193
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
static ::ExceptionBase & ExcInternalError()