Reference documentation for deal.II version Git f9e0250abc 2021-03-01 16:46:02 +0100
\(\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  explicit 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 
624  template <class Archive>
625  void
626  serialize(Archive &ar, const unsigned int version);
627 
628 protected:
633  size_type
634  position(const TableIndices<N> &indices) const;
635 
643  el(const TableIndices<N> &indices);
644 
656  el(const TableIndices<N> &indices) const;
657 
658 protected:
663 
668 
669  // Make all other table classes friends.
670  template <int, typename>
671  friend class TableBase;
672 };
673 
674 
687 template <int N, typename T>
688 class Table : public TableBase<N, T>
689 {};
690 
691 
703 template <typename T>
704 class Table<1, T> : public TableBase<1, T>
705 {
706 public:
711 
715  Table() = default;
716 
720  explicit Table(const size_type size);
721 
759  template <typename InputIterator>
760  Table(const size_type size,
761  InputIterator entries,
762  const bool C_style_indexing = true);
763 
769  operator[](const size_type i) const;
770 
775  typename AlignedVector<T>::reference operator[](const size_type i);
776 
782  operator()(const size_type i) const;
783 
789  operator()(const size_type i);
790 
796  operator()(const TableIndices<1> &indices);
797 
803  operator()(const TableIndices<1> &indices) const;
804 };
805 
806 
807 
816 {
821  enum class Storage
822  {
826  row_major,
827 
832  };
833 
834  // Forward declaration of the iterator class.
835  template <typename TableType, bool Constness, Storage storage_order>
836  class Iterator;
837 
842  template <typename TableType, bool Constness, Storage storage_order>
843  class Accessor;
844 
861  template <typename TableType, bool Constness, Storage storage_order>
863  {
864  public:
868  using container_pointer_type = typename std::
869  conditional<Constness, const TableType *, TableType *>::type;
870 
874  using value_type = typename TableType::value_type;
875 
879  using size_type = typename TableType::size_type;
880 
884  AccessorBase();
885 
890 
895 
900  const std::ptrdiff_t linear_index);
901 
905  template <bool OtherConstness>
906  friend bool
910  {
911  return left.container == right.container &&
912  left.linear_index == right.linear_index;
913  }
914 
919  const value_type &
920  value() const;
921 
925  operator const value_type &() const;
926 
930  size_type
931  row() const;
932 
936  size_type
937  column() const;
938 
939  protected:
944 
948  std::ptrdiff_t linear_index;
949 
956  void
957  assert_valid_linear_index() const;
958 
959  // Make the const version a friend for copying.
960  friend class AccessorBase<TableType, true, storage_order>;
961 
962  // Make the underlying iterator class a friend.
963  friend class LinearIndexIterator<
964  Iterator<TableType, Constness, storage_order>,
965  Accessor<TableType, Constness, storage_order>>;
966  };
967 
972  template <typename TableType, Storage storage_order>
973  class Accessor<TableType, true, storage_order>
974  : public AccessorBase<TableType, true, storage_order>
975  {
976  public:
980  using value_type =
982 
986  using size_type =
988 
993  };
994 
999  template <typename TableType, Storage storage_order>
1000  class Accessor<TableType, false, storage_order>
1001  : public AccessorBase<TableType, false, storage_order>
1002  {
1003  public:
1007  using value_type =
1009 
1013  using size_type =
1015 
1020 
1026  operator=(const value_type &) const;
1027 
1033  operator=(value_type &&) const;
1034 
1040 
1045  value_type &
1046  value() const;
1047 
1051  operator value_type &();
1052  };
1053 
1066  template <typename TableType, bool Constness, Storage storage_order>
1067  class Iterator
1068  : public LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
1069  Accessor<TableType, Constness, storage_order>>
1070  {
1071  public:
1076 
1080  using container_pointer_type = typename std::
1081  conditional<Constness, const TableType *, TableType *>::type;
1082 
1087 
1091  Iterator(const container_pointer_type object);
1092 
1096  Iterator(const container_pointer_type object,
1097  const size_type row,
1098  const size_type column);
1099 
1104 
1108  Iterator(const container_pointer_type container,
1109  const std::ptrdiff_t linear_index);
1110  };
1111 } // namespace MatrixTableIterators
1112 
1113 
1114 
1127 template <typename T>
1128 class Table<2, T> : public TableBase<2, T>
1129 {
1130 public:
1135 
1140 
1145 
1150 
1155  using const_iterator = MatrixTableIterators::
1156  Iterator<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1157 
1161  using iterator = MatrixTableIterators::
1162  Iterator<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1163 
1167  Table() = default;
1168 
1172  Table(const size_type size1, const size_type size2);
1173 
1212  template <typename InputIterator>
1213  Table(const size_type size1,
1214  const size_type size2,
1215  InputIterator entries,
1216  const bool C_style_indexing = true);
1217 
1223  void
1224  reinit(const size_type size1,
1225  const size_type size2,
1226  const bool omit_default_initialization = false);
1227 
1229 
1237  operator[](const size_type i) const;
1238 
1246  operator[](const size_type i);
1247 
1255  operator()(const size_type i, const size_type j) const;
1256 
1264  operator()(const size_type i, const size_type j);
1265 
1271  operator()(const TableIndices<2> &indices);
1272 
1278  operator()(const TableIndices<2> &indices) const;
1279 
1280 
1285  size_type
1286  n_rows() const;
1287 
1292  size_type
1293  n_cols() const;
1294 
1298  iterator
1299  begin();
1300 
1305  begin() const;
1306 
1310  iterator
1311  end();
1312 
1317  end() const;
1318 
1319 protected:
1331  el(const size_type i, const size_type j);
1332 
1348  el(const size_type i, const size_type j) const;
1349 
1350  // Make the AccessorBase class a friend so that it may directly index into
1351  // the array.
1352  friend class MatrixTableIterators::
1353  AccessorBase<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1354  friend class MatrixTableIterators::
1355  AccessorBase<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1356 
1357  // Make the mutable accessor class a friend so that we can write to array
1358  // entries with iterators.
1359  friend class MatrixTableIterators::
1360  Accessor<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1361 };
1362 
1363 
1364 
1374 template <typename T>
1375 class Table<3, T> : public TableBase<3, T>
1376 {
1377 public:
1382 
1386  Table() = default;
1387 
1391  Table(const size_type size1, const size_type size2, const size_type size3);
1392 
1433  template <typename InputIterator>
1434  Table(const size_type size1,
1435  const size_type size2,
1436  const size_type size3,
1437  InputIterator entries,
1438  const bool C_style_indexing = true);
1439 
1448  operator[](const size_type i) const;
1449 
1458  operator[](const size_type i);
1459 
1467  operator()(const size_type i, const size_type j, const size_type k) const;
1468 
1469 
1477  operator()(const size_type i, const size_type j, const size_type k);
1478 
1484  operator()(const TableIndices<3> &indices);
1485 
1491  operator()(const TableIndices<3> &indices) const;
1492 };
1493 
1494 
1495 
1505 template <typename T>
1506 class Table<4, T> : public TableBase<4, T>
1507 {
1508 public:
1513 
1517  Table() = default;
1518 
1522  Table(const size_type size1,
1523  const size_type size2,
1524  const size_type size3,
1525  const size_type size4);
1526 
1535  operator[](const size_type i) const;
1536 
1545  operator[](const size_type i);
1546 
1554  operator()(const size_type i,
1555  const size_type j,
1556  const size_type k,
1557  const size_type l) const;
1558 
1559 
1567  operator()(const size_type i,
1568  const size_type j,
1569  const size_type k,
1570  const size_type l);
1571 
1577  operator()(const TableIndices<4> &indices);
1578 
1584  operator()(const TableIndices<4> &indices) const;
1585 };
1586 
1587 
1588 
1598 template <typename T>
1599 class Table<5, T> : public TableBase<5, T>
1600 {
1601 public:
1606 
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  const size_type size5);
1621 
1630  operator[](const size_type i) const;
1631 
1640  operator[](const size_type i);
1641 
1649  operator()(const size_type i,
1650  const size_type j,
1651  const size_type k,
1652  const size_type l,
1653  const size_type m) const;
1654 
1662  operator()(const size_type i,
1663  const size_type j,
1664  const size_type k,
1665  const size_type l,
1666  const size_type m);
1667 
1673  operator()(const TableIndices<5> &indices);
1674 
1680  operator()(const TableIndices<5> &indices) const;
1681 };
1682 
1683 
1684 
1694 template <typename T>
1695 class Table<6, T> : public TableBase<6, T>
1696 {
1697 public:
1702 
1706  Table() = default;
1707 
1711  Table(const size_type size1,
1712  const size_type size2,
1713  const size_type size3,
1714  const size_type size4,
1715  const size_type size5,
1716  const size_type size6);
1717 
1726  operator[](const size_type i) const;
1727 
1736  operator[](const size_type i);
1737 
1745  operator()(const size_type i,
1746  const size_type j,
1747  const size_type k,
1748  const size_type l,
1749  const size_type m,
1750  const size_type n) const;
1751 
1759  operator()(const size_type i,
1760  const size_type j,
1761  const size_type k,
1762  const size_type l,
1763  const size_type m,
1764  const size_type n);
1765 
1771  operator()(const TableIndices<6> &indices);
1772 
1778  operator()(const TableIndices<6> &indices) const;
1779 };
1780 
1781 
1791 template <typename T>
1792 class Table<7, T> : public TableBase<7, T>
1793 {
1794 public:
1799 
1803  Table() = default;
1804 
1808  Table(const size_type size1,
1809  const size_type size2,
1810  const size_type size3,
1811  const size_type size4,
1812  const size_type size5,
1813  const size_type size6,
1814  const size_type size7);
1815 
1824  operator[](const size_type i) const;
1825 
1834  operator[](const size_type i);
1835 
1843  operator()(const size_type i,
1844  const size_type j,
1845  const size_type k,
1846  const size_type l,
1847  const size_type m,
1848  const size_type n,
1849  const size_type o) const;
1850 
1858  operator()(const size_type i,
1859  const size_type j,
1860  const size_type k,
1861  const size_type l,
1862  const size_type m,
1863  const size_type n,
1864  const size_type o);
1865 
1871  operator()(const TableIndices<7> &indices);
1872 
1878  operator()(const TableIndices<7> &indices) const;
1879 };
1880 
1881 
1894 template <typename T>
1895 class TransposeTable : public TableBase<2, T>
1896 {
1897 public:
1902 
1907 
1912 
1917 
1922  using const_iterator =
1924  true,
1926 
1930  using iterator =
1932  false,
1934 
1938  TransposeTable() = default;
1939 
1943  TransposeTable(const size_type size1, const size_type size2);
1944 
1950  void
1951  reinit(const size_type size1,
1952  const size_type size2,
1953  const bool omit_default_initialization = false);
1954 
1962  operator()(const size_type i, const size_type j) const;
1963 
1970  reference
1971  operator()(const size_type i, const size_type j);
1972 
1977  size_type
1978  n_rows() const;
1979 
1984  size_type
1985  n_cols() const;
1986 
1990  iterator
1991  begin();
1992 
1997  begin() const;
1998 
2002  iterator
2003  end();
2004 
2009  end() const;
2010 
2011 protected:
2022  reference
2023  el(const size_type i, const size_type j);
2024 
2040  el(const size_type i, const size_type j) const;
2041 
2042  // Make the AccessorBase class a friend so that it may directly index into
2043  // the array.
2045  TransposeTable<T>,
2046  true,
2049  TransposeTable<T>,
2050  false,
2051  MatrixTableIterators::Storage::column_major>;
2052 
2053  // Make the mutable accessor class a friend so that we can write to array
2054  // entries with iterators.
2055  friend class MatrixTableIterators::Accessor<
2056  TransposeTable<T>,
2057  false,
2058  MatrixTableIterators::Storage::column_major>;
2059 };
2060 
2061 
2062 
2063 /* --------------------- Template and inline functions ---------------- */
2064 
2065 #ifndef DOXYGEN
2066 
2067 template <int N, typename T>
2068 TableBase<N, T>::TableBase(const TableIndices<N> &sizes)
2069 {
2070  reinit(sizes);
2071 }
2072 
2073 
2074 
2075 template <int N, typename T>
2076 template <typename InputIterator>
2078  InputIterator entries,
2079  const bool C_style_indexing)
2080 {
2081  reinit(sizes);
2082  fill(entries, C_style_indexing);
2083 }
2084 
2085 
2086 
2087 template <int N, typename T>
2089  : Subscriptor()
2090 {
2091  reinit(src.table_size, true);
2092  values = src.values;
2093 }
2094 
2095 
2096 
2097 template <int N, typename T>
2098 template <typename T2>
2100 {
2101  reinit(src.table_size);
2102  if (src.n_elements() != 0)
2103  std::copy(src.values.begin(), src.values.end(), values.begin());
2104 }
2105 
2106 
2107 
2108 template <int N, typename T>
2110  : Subscriptor(std::move(src))
2111  , values(std::move(src.values))
2112  , table_size(src.table_size)
2113 {
2114  src.table_size = TableIndices<N>();
2115 }
2116 
2117 
2118 
2119 template <int N, typename T>
2120 template <class Archive>
2121 inline void
2122 TableBase<N, T>::serialize(Archive &ar, const unsigned int)
2123 {
2124  ar &static_cast<Subscriptor &>(*this);
2125 
2126  ar &values &table_size;
2127 }
2128 
2129 
2130 
2131 namespace internal
2132 {
2133  namespace TableBaseAccessors
2134  {
2135  template <int N, typename T, bool C, unsigned int P>
2136  inline Accessor<N, T, C, P>::Accessor(const TableType &table,
2137  const iterator data)
2138  : table(table)
2139  , data(data)
2140  {}
2141 
2142 
2143 
2144  template <int N, typename T, bool C, unsigned int P>
2145  inline Accessor<N, T, C, P>::Accessor(const Accessor &a)
2146  : table(a.table)
2147  , data(a.data)
2148  {}
2149 
2150 
2151 
2152  template <int N, typename T, bool C, unsigned int P>
2153  inline Accessor<N, T, C, P - 1> Accessor<N, T, C, P>::
2154  operator[](const size_type i) const
2155  {
2156  AssertIndexRange(i, table.size()[N - P]);
2157 
2158  // access i-th
2159  // subobject. optimize on the
2160  // case i==0
2161  if (i == 0)
2162  return Accessor<N, T, C, P - 1>(table, data);
2163  else
2164  {
2165  // note: P>1, otherwise the
2166  // specialization would have
2167  // been taken!
2168  size_type subobject_size = table.size()[N - 1];
2169  for (int p = P - 1; p > 1; --p)
2170  subobject_size *= table.size()[N - p];
2171  const iterator new_data = data + i * subobject_size;
2172  return Accessor<N, T, C, P - 1>(table, new_data);
2173  }
2174  }
2175 
2176 
2177 
2178  template <int N, typename T, bool C>
2179  inline Accessor<N, T, C, 1>::Accessor(const TableType &table,
2180  const iterator data)
2181  : table(table)
2182  , data(data)
2183  {}
2184 
2185 
2186 
2187  template <int N, typename T, bool C>
2188  inline Accessor<N, T, C, 1>::Accessor(const Accessor &a)
2189  : table(a.table)
2190  , data(a.data)
2191  {}
2192 
2193 
2194 
2195  template <int N, typename T, bool C>
2197  operator[](const size_type i) const
2198  {
2199  AssertIndexRange(i, table.size()[N - 1]);
2200  return *(data + i);
2201  }
2202 
2203 
2204 
2205  template <int N, typename T, bool C>
2206  inline typename Accessor<N, T, C, 1>::size_type
2208  {
2209  return table.size()[N - 1];
2210  }
2211 
2212 
2213 
2214  template <int N, typename T, bool C>
2215  inline typename Accessor<N, T, C, 1>::iterator
2217  {
2218  return data;
2219  }
2220 
2221 
2222 
2223  template <int N, typename T, bool C>
2224  inline typename Accessor<N, T, C, 1>::iterator
2226  {
2227  return data + table.size()[N - 1];
2228  }
2229  } // namespace TableBaseAccessors
2230 } // namespace internal
2231 
2232 
2233 
2234 template <int N, typename T>
2235 inline TableBase<N, T> &
2237 {
2238  if (!m.empty())
2239  values = m.values;
2240  reinit(m.size(), true);
2241 
2242  return *this;
2243 }
2244 
2245 
2246 
2247 template <int N, typename T>
2248 template <typename T2>
2249 inline TableBase<N, T> &
2251 {
2252  reinit(m.size(), true);
2253  if (!empty())
2254  std::copy(m.values.begin(),
2255  m.values.begin() + n_elements(),
2256  values.begin());
2257 
2258  return *this;
2259 }
2260 
2261 
2262 
2263 template <int N, typename T>
2264 inline TableBase<N, T> &
2266 {
2267  static_cast<Subscriptor &>(*this) = std::move(static_cast<Subscriptor &>(m));
2268  values = std::move(m.values);
2269  table_size = m.table_size;
2271 
2272  return *this;
2273 }
2274 
2275 
2276 
2277 template <int N, typename T>
2278 inline bool
2280 {
2281  return (values == T2.values);
2282 }
2283 
2284 
2285 
2286 template <int N, typename T>
2287 inline void
2289 {
2290  // use parallel set operation
2291  if (n_elements() != 0)
2292  values.fill(T());
2293 }
2294 
2295 
2296 
2297 template <int N, typename T>
2298 inline void
2299 TableBase<N, T>::fill(const T &value)
2300 {
2301  if (n_elements() != 0)
2302  values.fill(value);
2303 }
2304 
2305 
2306 
2307 template <int N, typename T>
2308 inline void
2309 TableBase<N, T>::reinit(const TableIndices<N> &new_sizes,
2310  const bool omit_default_initialization)
2311 {
2312  table_size = new_sizes;
2313 
2314  const size_type new_size = n_elements();
2315 
2316  // if zero size was given: free all memory
2317  if (new_size == 0)
2318  {
2319  values.resize(0);
2320  // set all sizes to zero, even
2321  // if one was previously
2322  // nonzero. This simplifies
2323  // some assertions.
2324  table_size = TableIndices<N>();
2325 
2326  return;
2327  }
2328 
2329  // adjust values field. If it was empty before, we can simply call resize(),
2330  // which can set all the data fields. Otherwise, select the fast resize and
2331  // manually fill in all the elements as required by the design of this
2332  // class. (Selecting another code for the empty case ensures that we touch
2333  // the memory only once for non-trivial classes that need to initialize the
2334  // memory also in resize_fast.)
2335  if (!omit_default_initialization)
2336  {
2337  if (values.empty())
2338  values.resize(new_size);
2339  else
2340  {
2341  values.resize_fast(new_size);
2342  values.fill();
2343  }
2344  }
2345  else
2346  values.resize_fast(new_size);
2347 }
2348 
2349 
2350 
2351 template <int N, typename T>
2352 inline const TableIndices<N> &
2353 TableBase<N, T>::size() const
2354 {
2355  return table_size;
2356 }
2357 
2358 
2359 
2360 template <int N, typename T>
2361 inline typename TableBase<N, T>::size_type
2362 TableBase<N, T>::size(const unsigned int i) const
2363 {
2364  AssertIndexRange(i, N);
2365  return table_size[i];
2366 }
2367 
2368 
2369 
2370 template <int N, typename T>
2371 inline typename TableBase<N, T>::size_type
2373 {
2374  size_type s = 1;
2375  for (unsigned int n = 0; n < N; ++n)
2376  s *= table_size[n];
2377  return s;
2378 }
2379 
2380 
2381 
2382 template <int N, typename T>
2383 inline bool
2384 TableBase<N, T>::empty() const
2385 {
2386  return (n_elements() == 0);
2387 }
2388 
2389 
2390 
2391 namespace internal
2392 {
2393  namespace TableImplementation
2394  {
2395  template <typename InputIterator, typename T>
2396  void
2397  fill_Fortran_style(InputIterator entries, TableBase<1, T> &table)
2398  {
2399  using size_type = typename TableBase<1, T>::size_type;
2400  for (size_type i = 0; i < table.size()[0]; ++i)
2401  table(TableIndices<1>(i)) = *entries++;
2402  }
2403 
2404 
2405  template <typename InputIterator, typename T>
2406  void
2407  fill_Fortran_style(InputIterator entries, TableBase<2, T> &table)
2408  {
2409  using size_type = typename TableBase<2, T>::size_type;
2410  for (size_type j = 0; j < table.size()[1]; ++j)
2411  for (size_type i = 0; i < table.size()[0]; ++i)
2412  table(TableIndices<2>(i, j)) = *entries++;
2413  }
2414 
2415 
2416  template <typename InputIterator, typename T>
2417  void
2418  fill_Fortran_style(InputIterator entries, TableBase<3, T> &table)
2419  {
2420  using size_type = typename TableBase<3, T>::size_type;
2421  for (size_type k = 0; k < table.size()[2]; ++k)
2422  for (size_type j = 0; j < table.size()[1]; ++j)
2423  for (size_type i = 0; i < table.size()[0]; ++i)
2424  table(TableIndices<3>(i, j, k)) = *entries++;
2425  }
2426 
2427 
2428  template <typename InputIterator, typename T, int N>
2429  void
2430  fill_Fortran_style(InputIterator, TableBase<N, T> &)
2431  {
2432  Assert(false, ExcNotImplemented());
2433  }
2434  } // namespace TableImplementation
2435 } // namespace internal
2436 
2437 
2438 template <int N, typename T>
2439 template <typename InputIterator>
2440 inline void
2441 TableBase<N, T>::fill(InputIterator entries, const bool C_style_indexing)
2442 {
2443  Assert(n_elements() != 0, ExcMessage("Trying to fill an empty matrix."));
2444 
2445  if (C_style_indexing)
2446  for (typename AlignedVector<T>::iterator p = values.begin();
2447  p != values.end();
2448  ++p)
2449  *p = *entries++;
2450  else
2451  internal::TableImplementation::fill_Fortran_style(entries, *this);
2452 }
2453 
2454 
2455 
2456 template <int N, typename T>
2457 inline void
2459 {
2460  values.swap(v.values);
2461  std::swap(table_size, v.table_size);
2462 }
2463 
2464 
2465 
2466 template <int N, typename T>
2467 inline std::size_t
2469 {
2470  return sizeof(*this) + MemoryConsumption::memory_consumption(values);
2471 }
2472 
2473 
2474 
2475 template <int N, typename T>
2476 inline typename TableBase<N, T>::size_type
2477 TableBase<N, T>::position(const TableIndices<N> &indices) const
2478 {
2479  // specialize this for the
2480  // different numbers of dimensions,
2481  // to make the job somewhat easier
2482  // for the compiler. have the
2483  // general formula nevertheless:
2484  switch (N)
2485  {
2486  case 1:
2487  return indices[0];
2488  case 2:
2489  return size_type(indices[0]) * table_size[1] + indices[1];
2490  case 3:
2491  return ((size_type(indices[0]) * table_size[1] + indices[1]) *
2492  table_size[2] +
2493  indices[2]);
2494  default:
2495  {
2496  unsigned int s = indices[0];
2497  for (unsigned int n = 1; n < N; ++n)
2498  s = s * table_size[n] + indices[n];
2499  return s;
2500  }
2501  }
2502 }
2503 
2504 
2505 
2506 template <int N, typename T>
2507 inline typename AlignedVector<T>::const_reference
2508 TableBase<N, T>::operator()(const TableIndices<N> &indices) const
2509 {
2510  for (unsigned int n = 0; n < N; ++n)
2511  AssertIndexRange(indices[n], table_size[n]);
2512  return el(indices);
2513 }
2514 
2515 
2516 
2517 template <int N, typename T>
2518 inline typename AlignedVector<T>::reference
2520 {
2521  for (unsigned int n = 0; n < N; ++n)
2522  AssertIndexRange(indices[n], table_size[n]);
2523  return el(indices);
2524 }
2525 
2526 
2527 
2528 template <int N, typename T>
2529 inline typename AlignedVector<T>::const_reference
2530 TableBase<N, T>::el(const TableIndices<N> &indices) const
2531 {
2532  return values[position(indices)];
2533 }
2534 
2535 
2536 
2537 template <int N, typename T>
2538 inline typename AlignedVector<T>::reference
2539 TableBase<N, T>::el(const TableIndices<N> &indices)
2540 {
2541  AssertIndexRange(position(indices), values.size());
2542  return values[position(indices)];
2543 }
2544 
2545 
2546 
2547 template <typename T>
2548 inline Table<1, T>::Table(const size_type size)
2550 {}
2551 
2552 
2553 
2554 template <typename T>
2555 template <typename InputIterator>
2556 inline Table<1, T>::Table(const size_type size,
2557  InputIterator entries,
2558  const bool C_style_indexing)
2559  : TableBase<1, T>(TableIndices<1>(size), entries, C_style_indexing)
2560 {}
2561 
2562 
2563 
2564 template <typename T>
2566  operator[](const size_type i) const
2567 {
2568  AssertIndexRange(i, this->table_size[0]);
2569  return this->values[i];
2570 }
2571 
2572 
2573 
2574 template <typename T>
2576  operator[](const size_type i)
2577 {
2578  AssertIndexRange(i, this->table_size[0]);
2579  return this->values[i];
2580 }
2581 
2582 
2583 
2584 template <typename T>
2585 inline typename AlignedVector<T>::const_reference
2586 Table<1, T>::operator()(const size_type i) const
2587 {
2588  AssertIndexRange(i, this->table_size[0]);
2589  return this->values[i];
2590 }
2591 
2592 
2593 
2594 template <typename T>
2595 inline typename AlignedVector<T>::reference
2597 {
2598  AssertIndexRange(i, this->table_size[0]);
2599  return this->values[i];
2600 }
2601 
2602 
2603 
2604 template <typename T>
2605 inline typename AlignedVector<T>::const_reference
2606 Table<1, T>::operator()(const TableIndices<1> &indices) const
2607 {
2608  return TableBase<1, T>::operator()(indices);
2609 }
2610 
2611 
2612 
2613 template <typename T>
2614 inline typename AlignedVector<T>::reference
2616 {
2617  return TableBase<1, T>::operator()(indices);
2618 }
2619 
2620 
2621 //---------------------------------------------------------------------------
2622 
2623 
2624 
2625 template <typename T>
2626 inline Table<2, T>::Table(const size_type size1, const size_type size2)
2627  : TableBase<2, T>(TableIndices<2>(size1, size2))
2628 {}
2629 
2630 
2631 
2632 template <typename T>
2633 template <typename InputIterator>
2634 inline Table<2, T>::Table(const size_type size1,
2635  const size_type size2,
2636  InputIterator entries,
2637  const bool C_style_indexing)
2638  : TableBase<2, T>(TableIndices<2>(size1, size2), entries, C_style_indexing)
2639 {}
2640 
2641 
2642 
2643 template <typename T>
2644 inline void
2645 Table<2, T>::reinit(const size_type size1,
2646  const size_type size2,
2647  const bool omit_default_initialization)
2648 {
2649  this->TableBase<2, T>::reinit(TableIndices<2>(size1, size2),
2650  omit_default_initialization);
2651 }
2652 
2653 
2654 
2655 template <typename T>
2656 inline ::internal::TableBaseAccessors::Accessor<2, T, true, 1>
2657  Table<2, T>::operator[](const size_type i) const
2658 {
2659  AssertIndexRange(i, this->table_size[0]);
2660  return ::internal::TableBaseAccessors::Accessor<2, T, true, 1>(
2661  *this, this->values.begin() + size_type(i) * n_cols());
2662 }
2663 
2664 
2665 
2666 template <typename T>
2667 inline ::internal::TableBaseAccessors::Accessor<2, T, false, 1>
2669 {
2670  AssertIndexRange(i, this->table_size[0]);
2671  return ::internal::TableBaseAccessors::Accessor<2, T, false, 1>(
2672  *this, this->values.begin() + size_type(i) * n_cols());
2673 }
2674 
2675 
2676 
2677 template <typename T>
2678 inline typename AlignedVector<T>::const_reference
2679 Table<2, T>::operator()(const size_type i, const size_type j) const
2680 {
2681  AssertIndexRange(i, this->table_size[0]);
2682  AssertIndexRange(j, this->table_size[1]);
2683  return this->values[size_type(i) * this->table_size[1] + j];
2684 }
2685 
2686 
2687 
2688 template <typename T>
2689 inline typename AlignedVector<T>::reference
2691 {
2692  AssertIndexRange(i, this->table_size[0]);
2693  AssertIndexRange(j, this->table_size[1]);
2694  return this->values[size_type(i) * this->table_size[1] + j];
2695 }
2696 
2697 
2698 
2699 template <typename T>
2700 inline typename AlignedVector<T>::const_reference
2701 Table<2, T>::operator()(const TableIndices<2> &indices) const
2702 {
2703  return TableBase<2, T>::operator()(indices);
2704 }
2705 
2706 
2707 
2708 template <typename T>
2709 inline typename AlignedVector<T>::reference
2711 {
2712  return TableBase<2, T>::operator()(indices);
2713 }
2714 
2715 
2716 
2717 template <typename T>
2718 inline typename AlignedVector<T>::const_reference
2719 Table<2, T>::el(const size_type i, const size_type j) const
2720 {
2721  return this->values[size_type(i) * this->table_size[1] + j];
2722 }
2723 
2724 
2725 
2726 template <typename T>
2727 inline typename AlignedVector<T>::reference
2728 Table<2, T>::el(const size_type i, const size_type j)
2729 {
2730  return this->values[size_type(i) * this->table_size[1] + j];
2731 }
2732 
2733 
2734 
2735 template <typename T>
2736 inline typename Table<2, T>::size_type
2737 Table<2, T>::n_rows() const
2738 {
2739  return this->table_size[0];
2740 }
2741 
2742 
2743 
2744 template <typename T>
2745 inline typename Table<2, T>::size_type
2746 Table<2, T>::n_cols() const
2747 {
2748  return this->table_size[1];
2749 }
2750 
2751 
2752 
2753 template <typename T>
2754 inline typename Table<2, T>::iterator
2756 {
2757  return typename Table<2, T>::iterator(this, 0, 0);
2758 }
2759 
2760 
2761 
2762 template <typename T>
2763 inline typename Table<2, T>::const_iterator
2764 Table<2, T>::begin() const
2765 {
2766  return typename Table<2, T>::const_iterator(this, 0, 0);
2767 }
2768 
2769 
2770 
2771 template <typename T>
2772 inline typename Table<2, T>::iterator
2774 {
2775  return typename Table<2, T>::iterator(this);
2776 }
2777 
2778 
2779 
2780 template <typename T>
2781 inline typename Table<2, T>::const_iterator
2782 Table<2, T>::end() const
2783 {
2784  return typename Table<2, T>::const_iterator(this);
2785 }
2786 
2787 
2788 
2789 //---------------------------------------------------------------------------
2790 namespace MatrixTableIterators
2791 {
2792  namespace internal
2793  {
2794  // Internal calculation routines for AccessorBase. These do not do any
2795  // checking whatsoever.
2796  template <typename TableType, Storage storage_order>
2797  inline std::ptrdiff_t
2798  get_row_index(const std::ptrdiff_t linear_index,
2799  const TableType *const container)
2800  {
2801  switch (storage_order)
2802  {
2803  case Storage::row_major:
2804  return linear_index / container->n_cols();
2805  case Storage::column_major:
2806  return linear_index % container->n_rows();
2807  default:
2808  Assert(false, ExcInternalError());
2809  }
2810  return {};
2811  }
2812 
2813 
2814 
2815  template <typename TableType, Storage storage_order>
2816  inline std::ptrdiff_t
2817  get_column_index(const std::ptrdiff_t linear_index,
2818  const TableType *const container)
2819  {
2820  switch (storage_order)
2821  {
2822  case Storage::row_major:
2823  return linear_index % container->n_cols();
2824  case Storage::column_major:
2825  return linear_index / container->n_rows();
2826  default:
2827  Assert(false, ExcInternalError());
2828  }
2829  return {};
2830  }
2831  } // namespace internal
2832 
2833 
2834 
2835  template <typename TableType, bool Constness, Storage storage_order>
2836  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase()
2837  : container(nullptr)
2838  , linear_index(std::numeric_limits<decltype(linear_index)>::max())
2839  {}
2840 
2841 
2842 
2843  template <typename TableType, bool Constness, Storage storage_order>
2844  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2845  const container_pointer_type table)
2846  : container(table)
2847  , linear_index(container->values.size())
2848  {}
2849 
2850 
2851 
2852  template <typename TableType, bool Constness, Storage storage_order>
2853  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2854  const AccessorBase<TableType, false, storage_order> &a)
2855  : container(a.container)
2856  , linear_index(a.linear_index)
2857  {}
2858 
2859 
2860 
2861  template <typename TableType, bool Constness, Storage storage_order>
2862  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2863  const container_pointer_type table,
2864  const std::ptrdiff_t index)
2865  : container(table)
2866  , linear_index(index)
2867  {
2868  Assert(0 <= linear_index &&
2869  std::size_t(linear_index) < container->values.size() + 1,
2870  ExcMessage("The current iterator points outside of the table and is "
2871  "not the end iterator."));
2872  }
2873 
2874 
2875 
2876  template <typename TableType, bool Constness, Storage storage_order>
2877  inline const typename AccessorBase<TableType, Constness, storage_order>::
2878  value_type &
2880  {
2881  assert_valid_linear_index();
2882  return this->container->values[linear_index];
2883  }
2884 
2885 
2886 
2887  template <typename TableType, bool Constness, Storage storage_order>
2888  inline AccessorBase<TableType, Constness, storage_order>::
2889  operator const value_type &() const
2890  {
2891  assert_valid_linear_index();
2892  return this->container->values[linear_index];
2893  }
2894 
2895 
2896 
2897  template <typename TableType, bool Constness, Storage storage_order>
2899  AccessorBase<TableType, Constness, storage_order>::row() const
2900  {
2901  assert_valid_linear_index();
2902  return static_cast<std::size_t>(
2903  internal::get_row_index<TableType, storage_order>(linear_index,
2904  container));
2905  }
2906 
2907 
2908 
2909  template <typename TableType, bool Constness, Storage storage_order>
2911  AccessorBase<TableType, Constness, storage_order>::column() const
2912  {
2913  assert_valid_linear_index();
2914  return static_cast<std::size_t>(
2915  internal::get_column_index<TableType, storage_order>(linear_index,
2916  container));
2917  }
2918 
2919 
2920 
2921  template <typename TableType, bool Constness, Storage storage_order>
2922  inline void
2923  AccessorBase<TableType, Constness, storage_order>::assert_valid_linear_index()
2924  const
2925  {
2926 # ifdef DEBUG // avoid unused variable warnings by guarding everything
2927  Assert(container != nullptr,
2928  ExcMessage("This accessor has been default-constructed and does not "
2929  "have a corresponding table."));
2930  Assert(!container->empty(),
2931  ExcMessage("An empty table has no rows or columns."));
2932  Assert(0 <= linear_index &&
2933  std::size_t(linear_index) < container->values.size(),
2934  ExcMessage("The current iterator points outside of the table."));
2935  const std::ptrdiff_t row_n =
2936  internal::get_row_index<TableType, storage_order>(linear_index,
2937  container);
2938  const std::ptrdiff_t column_n =
2939  internal::get_column_index<TableType, storage_order>(linear_index,
2940  container);
2941  Assert(0 <= column_n && std::size_t(column_n) < container->n_cols(),
2942  ExcMessage("The current iterator points outside the table."));
2943  Assert(0 <= row_n && std::size_t(row_n) < container->n_rows(),
2944  ExcMessage("The current iterator points outside the table."));
2945 # endif
2946  }
2947 
2948 
2949 
2950  template <typename TableType, Storage storage_order>
2951  inline const Accessor<TableType, false, storage_order> &
2952  Accessor<TableType, false, storage_order>::operator=(
2953  const typename Accessor<TableType, false, storage_order>::value_type &t)
2954  const
2955  {
2956  this->assert_valid_linear_index();
2957  this->container->values[this->linear_index] = t;
2958  return *this;
2959  }
2960 
2961 
2962 
2963  template <typename TableType, Storage storage_order>
2964  inline const Accessor<TableType, false, storage_order> &
2965  Accessor<TableType, false, storage_order>::operator=(
2966  typename Accessor<TableType, false, storage_order>::value_type &&t) const
2967  {
2968  this->assert_valid_linear_index();
2969  this->container->values[this->linear_index] = t;
2970  return *this;
2971  }
2972 
2973 
2974 
2975  template <typename TableType, Storage storage_order>
2976  inline typename Accessor<TableType, false, storage_order>::value_type &
2978  {
2979  this->assert_valid_linear_index();
2980  return this->container->values[this->linear_index];
2981  }
2982 
2983 
2984 
2985  template <typename TableType, Storage storage_order>
2986  inline Accessor<TableType, false, storage_order>::operator value_type &()
2987  {
2988  this->assert_valid_linear_index();
2989  return this->container->values[this->linear_index];
2990  }
2991 
2992 
2993 
2994  template <typename TableType, bool Constness, Storage storage_order>
2995  inline Iterator<TableType, Constness, storage_order>::Iterator(
2999  {}
3000 
3001 
3002 
3003  template <typename TableType, bool Constness, Storage storage_order>
3004  inline Iterator<TableType, Constness, storage_order>::Iterator(
3005  const container_pointer_type table)
3009  {}
3010 
3011 
3012 
3013  template <typename TableType, bool Constness, Storage storage_order>
3014  inline Iterator<TableType, Constness, storage_order>::Iterator(
3015  const Iterator<TableType, false, storage_order> &i)
3018  {}
3019 
3020 
3021 
3022  template <typename TableType, bool Constness, Storage storage_order>
3023  inline Iterator<TableType, Constness, storage_order>::Iterator(
3024  const container_pointer_type table,
3025  const size_type row_n,
3026  const size_type col_n)
3027  : Iterator(table,
3028  storage_order == Storage::row_major ?
3029  table->n_cols() * row_n + col_n :
3030  table->n_rows() * col_n + row_n)
3031  {}
3032 
3033 
3034 
3035  template <typename TableType, bool Constness, Storage storage_order>
3036  inline Iterator<TableType, Constness, storage_order>::Iterator(
3037  const container_pointer_type table,
3038  const std::ptrdiff_t linear_index)
3041  Accessor<TableType, Constness, storage_order>(table, linear_index))
3042  {}
3043 } // namespace MatrixTableIterators
3044 
3045 
3046 
3047 //---------------------------------------------------------------------------
3048 template <typename T>
3049 inline TransposeTable<T>::TransposeTable(const size_type size1,
3050  const size_type size2)
3051  : TableBase<2, T>(TableIndices<2>(size2, size1))
3052 {}
3053 
3054 
3055 
3056 template <typename T>
3057 inline void
3059  const size_type size2,
3060  const bool omit_default_initialization)
3061 {
3062  this->TableBase<2, T>::reinit(TableIndices<2>(size2, size1),
3063  omit_default_initialization);
3064 }
3065 
3066 
3067 
3068 template <typename T>
3069 inline typename TransposeTable<T>::const_reference
3070 TransposeTable<T>::operator()(const size_type i, const size_type j) const
3071 {
3072  AssertIndexRange(i, this->table_size[1]);
3073  AssertIndexRange(j, this->table_size[0]);
3074  return this->values[size_type(j) * this->table_size[1] + i];
3075 }
3076 
3077 
3078 
3079 template <typename T>
3080 inline typename TransposeTable<T>::reference
3082 {
3083  AssertIndexRange(i, this->table_size[1]);
3084  AssertIndexRange(j, this->table_size[0]);
3085  return this->values[size_type(j) * this->table_size[1] + i];
3086 }
3087 
3088 
3089 
3090 template <typename T>
3091 inline typename TransposeTable<T>::const_reference
3092 TransposeTable<T>::el(const size_type i, const size_type j) const
3093 {
3094  return this->values[size_type(j) * this->table_size[1] + i];
3095 }
3096 
3097 
3098 
3099 template <typename T>
3100 inline typename TransposeTable<T>::reference
3101 TransposeTable<T>::el(const size_type i, const size_type j)
3102 {
3103  return this->values[size_type(j) * this->table_size[1] + i];
3104 }
3105 
3106 
3107 
3108 template <typename T>
3109 inline typename TransposeTable<T>::size_type
3111 {
3112  return this->table_size[1];
3113 }
3114 
3115 
3116 
3117 template <typename T>
3118 inline typename TransposeTable<T>::size_type
3120 {
3121  return this->table_size[0];
3122 }
3123 
3124 
3125 
3126 template <typename T>
3127 inline typename TransposeTable<T>::iterator
3129 {
3130  return typename TransposeTable<T>::iterator(this, 0, 0);
3131 }
3132 
3133 
3134 
3135 template <typename T>
3136 inline typename TransposeTable<T>::const_iterator
3138 {
3139  return typename TransposeTable<T>::const_iterator(this, 0, 0);
3140 }
3141 
3142 
3143 
3144 template <typename T>
3145 inline typename TransposeTable<T>::iterator
3147 {
3148  return typename TransposeTable<T>::iterator(this);
3149 }
3150 
3151 
3152 
3153 template <typename T>
3154 inline typename TransposeTable<T>::const_iterator
3155 TransposeTable<T>::end() const
3156 {
3157  return typename TransposeTable<T>::const_iterator(this);
3158 }
3159 //---------------------------------------------------------------------------
3160 
3161 
3162 
3163 template <typename T>
3164 inline Table<3, T>::Table(const size_type size1,
3165  const size_type size2,
3166  const size_type size3)
3167  : TableBase<3, T>(TableIndices<3>(size1, size2, size3))
3168 {}
3169 
3170 
3171 
3172 template <typename T>
3173 template <typename InputIterator>
3174 inline Table<3, T>::Table(const size_type size1,
3175  const size_type size2,
3176  const size_type size3,
3177  InputIterator entries,
3178  const bool C_style_indexing)
3179  : TableBase<3, T>(TableIndices<3>(size1, size2, size3),
3180  entries,
3181  C_style_indexing)
3182 {}
3183 
3184 
3185 
3186 template <typename T>
3187 inline ::internal::TableBaseAccessors::Accessor<3, T, true, 2>
3188  Table<3, T>::operator[](const size_type i) const
3189 {
3190  AssertIndexRange(i, this->table_size[0]);
3191  const size_type subobject_size =
3192  size_type(this->table_size[1]) * this->table_size[2];
3194  *this, this->values.begin() + i * subobject_size));
3195 }
3196 
3197 
3198 
3199 template <typename T>
3200 inline ::internal::TableBaseAccessors::Accessor<3, T, false, 2>
3202 {
3203  AssertIndexRange(i, this->table_size[0]);
3204  const size_type subobject_size =
3205  size_type(this->table_size[1]) * this->table_size[2];
3207  *this, this->values.begin() + i * subobject_size));
3208 }
3209 
3210 
3211 
3212 template <typename T>
3213 inline typename AlignedVector<T>::const_reference
3215 operator()(const size_type i, const size_type j, const size_type k) const
3216 {
3217  AssertIndexRange(i, this->table_size[0]);
3218  AssertIndexRange(j, this->table_size[1]);
3219  AssertIndexRange(k, this->table_size[2]);
3220  return this
3221  ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3222  k];
3223 }
3224 
3225 
3226 
3227 template <typename T>
3228 inline typename AlignedVector<T>::reference
3229 Table<3, T>::operator()(const size_type i, const size_type j, const size_type k)
3230 {
3231  AssertIndexRange(i, this->table_size[0]);
3232  AssertIndexRange(j, this->table_size[1]);
3233  AssertIndexRange(k, this->table_size[2]);
3234  return this
3235  ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3236  k];
3237 }
3238 
3239 
3240 
3241 template <typename T>
3242 inline typename AlignedVector<T>::const_reference
3243 Table<3, T>::operator()(const TableIndices<3> &indices) const
3244 {
3245  return TableBase<3, T>::operator()(indices);
3246 }
3247 
3248 
3249 
3250 template <typename T>
3251 inline typename AlignedVector<T>::reference
3253 {
3254  return TableBase<3, T>::operator()(indices);
3255 }
3256 
3257 
3258 
3259 template <typename T>
3260 inline Table<4, T>::Table(const size_type size1,
3261  const size_type size2,
3262  const size_type size3,
3263  const size_type size4)
3264  : TableBase<4, T>(TableIndices<4>(size1, size2, size3, size4))
3265 {}
3266 
3267 
3268 
3269 template <typename T>
3270 inline ::internal::TableBaseAccessors::Accessor<4, T, true, 3>
3271  Table<4, T>::operator[](const size_type i) const
3272 {
3273  AssertIndexRange(i, this->table_size[0]);
3274  const size_type subobject_size =
3275  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3277  *this, this->values.begin() + i * subobject_size));
3278 }
3279 
3280 
3281 
3282 template <typename T>
3283 inline ::internal::TableBaseAccessors::Accessor<4, T, false, 3>
3285 {
3286  AssertIndexRange(i, this->table_size[0]);
3287  const size_type subobject_size =
3288  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3290  *this, this->values.begin() + i * subobject_size));
3291 }
3292 
3293 
3294 
3295 template <typename T>
3296 inline typename AlignedVector<T>::const_reference
3298  const size_type j,
3299  const size_type k,
3300  const size_type l) const
3301 {
3302  AssertIndexRange(i, this->table_size[0]);
3303  AssertIndexRange(j, this->table_size[1]);
3304  AssertIndexRange(k, this->table_size[2]);
3305  AssertIndexRange(l, this->table_size[3]);
3306  return this
3307  ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3308  k) *
3309  this->table_size[3] +
3310  l];
3311 }
3312 
3313 
3314 
3315 template <typename T>
3316 inline typename AlignedVector<T>::reference
3318  const size_type j,
3319  const size_type k,
3320  const size_type l)
3321 {
3322  AssertIndexRange(i, this->table_size[0]);
3323  AssertIndexRange(j, this->table_size[1]);
3324  AssertIndexRange(k, this->table_size[2]);
3325  AssertIndexRange(l, this->table_size[3]);
3326  return this
3327  ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3328  k) *
3329  this->table_size[3] +
3330  l];
3331 }
3332 
3333 
3334 
3335 template <typename T>
3336 inline typename AlignedVector<T>::const_reference
3337 Table<4, T>::operator()(const TableIndices<4> &indices) const
3338 {
3339  return TableBase<4, T>::operator()(indices);
3340 }
3341 
3342 
3343 
3344 template <typename T>
3345 inline typename AlignedVector<T>::reference
3347 {
3348  return TableBase<4, T>::operator()(indices);
3349 }
3350 
3351 
3352 
3353 template <typename T>
3354 inline Table<5, T>::Table(const size_type size1,
3355  const size_type size2,
3356  const size_type size3,
3357  const size_type size4,
3358  const size_type size5)
3359  : TableBase<5, T>(TableIndices<5>(size1, size2, size3, size4, size5))
3360 {}
3361 
3362 
3363 
3364 template <typename T>
3365 inline ::internal::TableBaseAccessors::Accessor<5, T, true, 4>
3366  Table<5, T>::operator[](const size_type i) const
3367 {
3368  AssertIndexRange(i, this->table_size[0]);
3369  const size_type subobject_size = size_type(this->table_size[1]) *
3370  this->table_size[2] * this->table_size[3] *
3371  this->table_size[4];
3373  *this, this->values.begin() + i * subobject_size));
3374 }
3375 
3376 
3377 
3378 template <typename T>
3379 inline ::internal::TableBaseAccessors::Accessor<5, T, false, 4>
3381 {
3382  AssertIndexRange(i, this->table_size[0]);
3383  const size_type subobject_size = size_type(this->table_size[1]) *
3384  this->table_size[2] * this->table_size[3] *
3385  this->table_size[4];
3387  *this, this->values.begin() + i * subobject_size));
3388 }
3389 
3390 
3391 
3392 template <typename T>
3393 inline typename AlignedVector<T>::const_reference
3395  const size_type j,
3396  const size_type k,
3397  const size_type l,
3398  const size_type m) const
3399 {
3400  AssertIndexRange(i, this->table_size[0]);
3401  AssertIndexRange(j, this->table_size[1]);
3402  AssertIndexRange(k, this->table_size[2]);
3403  AssertIndexRange(l, this->table_size[3]);
3404  AssertIndexRange(m, this->table_size[4]);
3405  return this
3406  ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3407  k) *
3408  this->table_size[3] +
3409  l) *
3410  this->table_size[4] +
3411  m];
3412 }
3413 
3414 
3415 
3416 template <typename T>
3417 inline typename AlignedVector<T>::reference
3419  const size_type j,
3420  const size_type k,
3421  const size_type l,
3422  const size_type m)
3423 {
3424  AssertIndexRange(i, this->table_size[0]);
3425  AssertIndexRange(j, this->table_size[1]);
3426  AssertIndexRange(k, this->table_size[2]);
3427  AssertIndexRange(l, this->table_size[3]);
3428  AssertIndexRange(m, this->table_size[4]);
3429  return this
3430  ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3431  k) *
3432  this->table_size[3] +
3433  l) *
3434  this->table_size[4] +
3435  m];
3436 }
3437 
3438 
3439 
3440 template <typename T>
3441 inline typename AlignedVector<T>::const_reference
3442 Table<5, T>::operator()(const TableIndices<5> &indices) const
3443 {
3444  return TableBase<5, T>::operator()(indices);
3445 }
3446 
3447 
3448 
3449 template <typename T>
3450 inline typename AlignedVector<T>::reference
3452 {
3453  return TableBase<5, T>::operator()(indices);
3454 }
3455 
3456 
3457 
3458 template <typename T>
3459 inline Table<6, T>::Table(const size_type size1,
3460  const size_type size2,
3461  const size_type size3,
3462  const size_type size4,
3463  const size_type size5,
3464  const size_type size6)
3465  : TableBase<6, T>()
3466 {
3467  TableIndices<6> table_indices;
3468  table_indices[0] = size1;
3469  table_indices[1] = size2;
3470  table_indices[2] = size3;
3471  table_indices[3] = size4;
3472  table_indices[4] = size5;
3473  table_indices[5] = size6;
3474 
3475  TableBase<6, T>::reinit(table_indices);
3476 }
3477 
3478 
3479 
3480 template <typename T>
3481 inline ::internal::TableBaseAccessors::Accessor<6, T, true, 5>
3482  Table<6, T>::operator[](const size_type i) const
3483 {
3484  AssertIndexRange(i, this->table_size[0]);
3485  const size_type subobject_size = size_type(this->table_size[1]) *
3486  this->table_size[2] * this->table_size[3] *
3487  this->table_size[4] * this->table_size[5];
3489  *this, this->values.begin() + i * subobject_size));
3490 }
3491 
3492 
3493 
3494 template <typename T>
3495 inline ::internal::TableBaseAccessors::Accessor<6, T, false, 5>
3497 {
3498  AssertIndexRange(i, this->table_size[0]);
3499  const size_type subobject_size = size_type(this->table_size[1]) *
3500  this->table_size[2] * this->table_size[3] *
3501  this->table_size[4] * this->table_size[5];
3503  *this, this->values.begin() + i * subobject_size));
3504 }
3505 
3506 
3507 
3508 template <typename T>
3509 inline typename AlignedVector<T>::const_reference
3511  const size_type j,
3512  const size_type k,
3513  const size_type l,
3514  const size_type m,
3515  const size_type n) const
3516 {
3517  AssertIndexRange(i, this->table_size[0]);
3518  AssertIndexRange(j, this->table_size[1]);
3519  AssertIndexRange(k, this->table_size[2]);
3520  AssertIndexRange(l, this->table_size[3]);
3521  AssertIndexRange(m, this->table_size[4]);
3522  AssertIndexRange(n, this->table_size[5]);
3523  return this
3524  ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3525  k) *
3526  this->table_size[3] +
3527  l) *
3528  this->table_size[4] +
3529  m) *
3530  this->table_size[5] +
3531  n];
3532 }
3533 
3534 
3535 
3536 template <typename T>
3537 inline typename AlignedVector<T>::reference
3539  const size_type j,
3540  const size_type k,
3541  const size_type l,
3542  const size_type m,
3543  const size_type n)
3544 {
3545  AssertIndexRange(i, this->table_size[0]);
3546  AssertIndexRange(j, this->table_size[1]);
3547  AssertIndexRange(k, this->table_size[2]);
3548  AssertIndexRange(l, this->table_size[3]);
3549  AssertIndexRange(m, this->table_size[4]);
3550  AssertIndexRange(n, this->table_size[5]);
3551  return this
3552  ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3553  k) *
3554  this->table_size[3] +
3555  l) *
3556  this->table_size[4] +
3557  m) *
3558  this->table_size[5] +
3559  n];
3560 }
3561 
3562 
3563 
3564 template <typename T>
3565 inline typename AlignedVector<T>::const_reference
3566 Table<6, T>::operator()(const TableIndices<6> &indices) const
3567 {
3568  return TableBase<6, T>::operator()(indices);
3569 }
3570 
3571 
3572 
3573 template <typename T>
3574 inline typename AlignedVector<T>::reference
3576 {
3577  return TableBase<6, T>::operator()(indices);
3578 }
3579 
3580 
3581 
3582 template <typename T>
3583 inline Table<7, T>::Table(const size_type size1,
3584  const size_type size2,
3585  const size_type size3,
3586  const size_type size4,
3587  const size_type size5,
3588  const size_type size6,
3589  const size_type size7)
3590  : TableBase<7, T>()
3591 {
3592  TableIndices<7> table_indices;
3593  table_indices[0] = size1;
3594  table_indices[1] = size2;
3595  table_indices[2] = size3;
3596  table_indices[3] = size4;
3597  table_indices[4] = size5;
3598  table_indices[5] = size6;
3599  table_indices[6] = size7;
3600 
3601  TableBase<7, T>::reinit(table_indices);
3602 }
3603 
3604 
3605 
3606 template <typename T>
3607 inline ::internal::TableBaseAccessors::Accessor<7, T, true, 6>
3608  Table<7, T>::operator[](const size_type i) const
3609 {
3610  AssertIndexRange(i, this->table_size[0]);
3611  const size_type subobject_size =
3612  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3613  this->table_size[4] * this->table_size[5] * this->table_size[6];
3615  *this, this->values.begin() + i * subobject_size));
3616 }
3617 
3618 
3619 
3620 template <typename T>
3621 inline ::internal::TableBaseAccessors::Accessor<7, T, false, 6>
3623 {
3624  AssertIndexRange(i, this->table_size[0]);
3625  const size_type subobject_size =
3626  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3627  this->table_size[4] * this->table_size[5] * this->table_size[6];
3629  *this, this->values.begin() + i * subobject_size));
3630 }
3631 
3632 
3633 
3634 template <typename T>
3635 inline typename AlignedVector<T>::const_reference
3637  const size_type j,
3638  const size_type k,
3639  const size_type l,
3640  const size_type m,
3641  const size_type n,
3642  const size_type o) const
3643 {
3644  AssertIndexRange(i, this->table_size[0]);
3645  AssertIndexRange(j, this->table_size[1]);
3646  AssertIndexRange(k, this->table_size[2]);
3647  AssertIndexRange(l, this->table_size[3]);
3648  AssertIndexRange(m, this->table_size[4]);
3649  AssertIndexRange(n, this->table_size[5]);
3650  AssertIndexRange(o, this->table_size[6]);
3651  return this->values
3652  [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3653  this->table_size[3] +
3654  l) *
3655  this->table_size[4] +
3656  m) *
3657  this->table_size[5] +
3658  n) *
3659  this->table_size[6] +
3660  o];
3661 }
3662 
3663 
3664 
3665 template <typename T>
3666 inline typename AlignedVector<T>::reference
3668  const size_type j,
3669  const size_type k,
3670  const size_type l,
3671  const size_type m,
3672  const size_type n,
3673  const size_type o)
3674 {
3675  AssertIndexRange(i, this->table_size[0]);
3676  AssertIndexRange(j, this->table_size[1]);
3677  AssertIndexRange(k, this->table_size[2]);
3678  AssertIndexRange(l, this->table_size[3]);
3679  AssertIndexRange(m, this->table_size[4]);
3680  AssertIndexRange(n, this->table_size[5]);
3681  AssertIndexRange(o, this->table_size[6]);
3682  return this->values
3683  [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3684  this->table_size[3] +
3685  l) *
3686  this->table_size[4] +
3687  m) *
3688  this->table_size[5] +
3689  n) *
3690  this->table_size[6] +
3691  o];
3692 }
3693 
3694 
3695 
3696 template <typename T>
3697 inline typename AlignedVector<T>::const_reference
3698 Table<7, T>::operator()(const TableIndices<7> &indices) const
3699 {
3700  return TableBase<7, T>::operator()(indices);
3701 }
3702 
3703 
3704 
3705 template <typename T>
3706 inline typename AlignedVector<T>::reference
3708 {
3709  return TableBase<7, T>::operator()(indices);
3710 }
3711 
3712 
3713 #endif // DOXYGEN
3714 
3715 
3716 
3722 template <int N, typename T>
3723 inline void
3725 {
3726  u.swap(v);
3727 }
3728 
3730 
3731 #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:1381
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:821
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:1901
MatrixTableIterators::Iterator< TransposeTable< T >, true, MatrixTableIterators::Storage::column_major > const_iterator
Definition: table.h:1925
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:1701
typename AccessorBase< TableType, true, storage_order >::value_type value_type
Definition: table.h:1008
size_type n_cols() const
typename Types< N, T, C >::iterator iterator
Definition: table.h:165
typename AlignedVector< number >::reference reference
Definition: table.h:1911
typename std::conditional< Constness, const TableType *, TableType * >::type container_pointer_type
Definition: table.h:869
#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:1134
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:710
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:1149
typename Types< N, T, C >::TableType TableType
Definition: table.h:259
typename TableBase< 4, T >::size_type size_type
Definition: table.h:1512
MatrixTableIterators::Iterator< TransposeTable< T >, false, MatrixTableIterators::Storage::column_major > iterator
Definition: table.h:1933
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition: table.h:1014
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:981
#define Assert(cond, exc)
Definition: exceptions.h:1466
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition: table.h:987
Accessor base class for Table<2, T> and TransposeTable.
Definition: table.h:862
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:943
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:394
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:1075
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:907
Accessor class offering read and write access to the elements of a table.
Definition: table.h:1000
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:836
void swap(TableBase< N, T > &u, TableBase< N, T > &v)
Definition: table.h:3724
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:393
VectorType::value_type * begin(VectorType &V)
typename TableBase< 5, T >::size_type size_type
Definition: table.h:1605
void reset_values()
static const char N
typename AlignedVector< T >::reference reference
Definition: table.h:1144
TransposeTable()=default
typename AlignedVector< T >::value_type value_type
Definition: table.h:1139
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:688
bool empty() const
TableIndices< N > table_size
Definition: table.h:667
#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:662
Accessor class template. This class is partially specialized for both values of Constness.
Definition: table.h:843
void copy(const T *begin, const T *end, U *dest)
typename TableBase< 7, T >::size_type size_type
Definition: table.h:1798
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:1916
typename std::conditional< Constness, const TableType *, TableType * >::type container_pointer_type
Definition: table.h:1081
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
static ::ExceptionBase & ExcInternalError()