Reference documentation for deal.II version Git 1dc1051882 2021-04-22 23:57:03 +0200
\(\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 
378 template <int N, typename T>
379 class TableBase : public Subscriptor
380 {
381 public:
382  using value_type = T;
383 
388 
389 
393  TableBase() = default;
394 
399  explicit TableBase(const TableIndices<N> &sizes);
400 
406  template <typename InputIterator>
407  TableBase(const TableIndices<N> &sizes,
408  InputIterator entries,
409  const bool C_style_indexing = true);
410 
414  TableBase(const TableBase<N, T> &src);
415 
420  template <typename T2>
421  TableBase(const TableBase<N, T2> &src);
422 
426  TableBase(TableBase<N, T> &&src) noexcept;
427 
431  ~TableBase() override = default;
432 
442  operator=(const TableBase<N, T> &src);
443 
451  template <typename T2>
453  operator=(const TableBase<N, T2> &src);
454 
460  operator=(TableBase<N, T> &&src) noexcept;
461 
465  bool
466  operator==(const TableBase<N, T> &T2) const;
467 
472  void
473  reset_values();
474 
483  void
484  reinit(const TableIndices<N> &new_size,
485  const bool omit_default_initialization = false);
486 
490  size_type
491  size(const unsigned int i) const;
492 
496  const TableIndices<N> &
497  size() const;
498 
503  size_type
504  n_elements() const;
505 
510  bool
511  empty() const;
512 
549  template <typename InputIterator>
550  void
551  fill(InputIterator entries, const bool C_style_indexing = true);
552 
556  void
557  fill(const T &value);
558 
563  operator()(const TableIndices<N> &indices);
564 
573  operator()(const TableIndices<N> &indices) const;
574 
587  void
588  swap(TableBase<N, T> &v);
589 
594  std::size_t
595  memory_consumption() const;
596 
602  template <class Archive>
603  void
604  serialize(Archive &ar, const unsigned int version);
605 
606 protected:
611  size_type
612  position(const TableIndices<N> &indices) const;
613 
621  el(const TableIndices<N> &indices);
622 
634  el(const TableIndices<N> &indices) const;
635 
636 protected:
641 
646 
647  // Make all other table classes friends.
648  template <int, typename>
649  friend class TableBase;
650 };
651 
652 
665 template <int N, typename T>
666 class Table : public TableBase<N, T>
667 {};
668 
669 
681 template <typename T>
682 class Table<1, T> : public TableBase<1, T>
683 {
684 public:
689 
693  Table() = default;
694 
698  explicit Table(const size_type size);
699 
737  template <typename InputIterator>
738  Table(const size_type size,
739  InputIterator entries,
740  const bool C_style_indexing = true);
741 
747  operator[](const size_type i) const;
748 
753  typename AlignedVector<T>::reference operator[](const size_type i);
754 
760  operator()(const size_type i) const;
761 
767  operator()(const size_type i);
768 
774  operator()(const TableIndices<1> &indices);
775 
781  operator()(const TableIndices<1> &indices) const;
782 };
783 
784 
785 
794 {
799  enum class Storage
800  {
804  row_major,
805 
810  };
811 
812  // Forward declaration of the iterator class.
813  template <typename TableType, bool Constness, Storage storage_order>
814  class Iterator;
815 
820  template <typename TableType, bool Constness, Storage storage_order>
821  class Accessor;
822 
839  template <typename TableType, bool Constness, Storage storage_order>
841  {
842  public:
846  using container_pointer_type = typename std::
847  conditional<Constness, const TableType *, TableType *>::type;
848 
852  using value_type = typename TableType::value_type;
853 
857  using size_type = typename TableType::size_type;
858 
862  AccessorBase();
863 
868 
873 
878  const std::ptrdiff_t linear_index);
879 
883  template <bool OtherConstness>
884  friend bool
888  {
889  return left.container == right.container &&
890  left.linear_index == right.linear_index;
891  }
892 
897  const value_type &
898  value() const;
899 
903  operator const value_type &() const;
904 
908  size_type
909  row() const;
910 
914  size_type
915  column() const;
916 
917  protected:
922 
926  std::ptrdiff_t linear_index;
927 
934  void
935  assert_valid_linear_index() const;
936 
937  // Make the const version a friend for copying.
938  friend class AccessorBase<TableType, true, storage_order>;
939 
940  // Make the underlying iterator class a friend.
941  friend class LinearIndexIterator<
942  Iterator<TableType, Constness, storage_order>,
943  Accessor<TableType, Constness, storage_order>>;
944  };
945 
950  template <typename TableType, Storage storage_order>
951  class Accessor<TableType, true, storage_order>
952  : public AccessorBase<TableType, true, storage_order>
953  {
954  public:
958  using value_type =
960 
964  using size_type =
966 
971  };
972 
977  template <typename TableType, Storage storage_order>
978  class Accessor<TableType, false, storage_order>
979  : public AccessorBase<TableType, false, storage_order>
980  {
981  public:
985  using value_type =
987 
991  using size_type =
993 
998 
1004  operator=(const value_type &) const;
1005 
1011  operator=(value_type &&) const;
1012 
1018 
1023  value_type &
1024  value() const;
1025 
1029  operator value_type &();
1030  };
1031 
1044  template <typename TableType, bool Constness, Storage storage_order>
1045  class Iterator
1046  : public LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
1047  Accessor<TableType, Constness, storage_order>>
1048  {
1049  public:
1054 
1058  using container_pointer_type = typename std::
1059  conditional<Constness, const TableType *, TableType *>::type;
1060 
1065 
1069  Iterator(const container_pointer_type object);
1070 
1074  Iterator(const container_pointer_type object,
1075  const size_type row,
1076  const size_type column);
1077 
1082 
1086  Iterator(const container_pointer_type container,
1087  const std::ptrdiff_t linear_index);
1088  };
1089 } // namespace MatrixTableIterators
1090 
1091 
1092 
1105 template <typename T>
1106 class Table<2, T> : public TableBase<2, T>
1107 {
1108 public:
1113 
1118 
1123 
1128 
1133  using const_iterator = MatrixTableIterators::
1134  Iterator<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1135 
1139  using iterator = MatrixTableIterators::
1140  Iterator<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1141 
1145  Table() = default;
1146 
1150  Table(const size_type size1, const size_type size2);
1151 
1190  template <typename InputIterator>
1191  Table(const size_type size1,
1192  const size_type size2,
1193  InputIterator entries,
1194  const bool C_style_indexing = true);
1195 
1201  void
1202  reinit(const size_type size1,
1203  const size_type size2,
1204  const bool omit_default_initialization = false);
1205 
1207 
1215  operator[](const size_type i) const;
1216 
1224  operator[](const size_type i);
1225 
1233  operator()(const size_type i, const size_type j) const;
1234 
1242  operator()(const size_type i, const size_type j);
1243 
1249  operator()(const TableIndices<2> &indices);
1250 
1256  operator()(const TableIndices<2> &indices) const;
1257 
1258 
1263  size_type
1264  n_rows() const;
1265 
1270  size_type
1271  n_cols() const;
1272 
1276  iterator
1277  begin();
1278 
1283  begin() const;
1284 
1288  iterator
1289  end();
1290 
1295  end() const;
1296 
1297 protected:
1309  el(const size_type i, const size_type j);
1310 
1326  el(const size_type i, const size_type j) const;
1327 
1328  // Make the AccessorBase class a friend so that it may directly index into
1329  // the array.
1330  friend class MatrixTableIterators::
1331  AccessorBase<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1332  friend class MatrixTableIterators::
1333  AccessorBase<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1334 
1335  // Make the mutable accessor class a friend so that we can write to array
1336  // entries with iterators.
1337  friend class MatrixTableIterators::
1338  Accessor<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1339 };
1340 
1341 
1342 
1352 template <typename T>
1353 class Table<3, T> : public TableBase<3, T>
1354 {
1355 public:
1360 
1364  Table() = default;
1365 
1369  Table(const size_type size1, const size_type size2, const size_type size3);
1370 
1411  template <typename InputIterator>
1412  Table(const size_type size1,
1413  const size_type size2,
1414  const size_type size3,
1415  InputIterator entries,
1416  const bool C_style_indexing = true);
1417 
1426  operator[](const size_type i) const;
1427 
1436  operator[](const size_type i);
1437 
1445  operator()(const size_type i, const size_type j, const size_type k) const;
1446 
1447 
1455  operator()(const size_type i, const size_type j, const size_type k);
1456 
1462  operator()(const TableIndices<3> &indices);
1463 
1469  operator()(const TableIndices<3> &indices) const;
1470 };
1471 
1472 
1473 
1483 template <typename T>
1484 class Table<4, T> : public TableBase<4, T>
1485 {
1486 public:
1491 
1495  Table() = default;
1496 
1500  Table(const size_type size1,
1501  const size_type size2,
1502  const size_type size3,
1503  const size_type size4);
1504 
1513  operator[](const size_type i) const;
1514 
1523  operator[](const size_type i);
1524 
1532  operator()(const size_type i,
1533  const size_type j,
1534  const size_type k,
1535  const size_type l) const;
1536 
1537 
1545  operator()(const size_type i,
1546  const size_type j,
1547  const size_type k,
1548  const size_type l);
1549 
1555  operator()(const TableIndices<4> &indices);
1556 
1562  operator()(const TableIndices<4> &indices) const;
1563 };
1564 
1565 
1566 
1576 template <typename T>
1577 class Table<5, T> : public TableBase<5, T>
1578 {
1579 public:
1584 
1585 
1589  Table() = default;
1590 
1594  Table(const size_type size1,
1595  const size_type size2,
1596  const size_type size3,
1597  const size_type size4,
1598  const size_type size5);
1599 
1608  operator[](const size_type i) const;
1609 
1618  operator[](const size_type i);
1619 
1627  operator()(const size_type i,
1628  const size_type j,
1629  const size_type k,
1630  const size_type l,
1631  const size_type m) const;
1632 
1640  operator()(const size_type i,
1641  const size_type j,
1642  const size_type k,
1643  const size_type l,
1644  const size_type m);
1645 
1651  operator()(const TableIndices<5> &indices);
1652 
1658  operator()(const TableIndices<5> &indices) const;
1659 };
1660 
1661 
1662 
1672 template <typename T>
1673 class Table<6, T> : public TableBase<6, T>
1674 {
1675 public:
1680 
1684  Table() = default;
1685 
1689  Table(const size_type size1,
1690  const size_type size2,
1691  const size_type size3,
1692  const size_type size4,
1693  const size_type size5,
1694  const size_type size6);
1695 
1704  operator[](const size_type i) const;
1705 
1714  operator[](const size_type i);
1715 
1723  operator()(const size_type i,
1724  const size_type j,
1725  const size_type k,
1726  const size_type l,
1727  const size_type m,
1728  const size_type n) const;
1729 
1737  operator()(const size_type i,
1738  const size_type j,
1739  const size_type k,
1740  const size_type l,
1741  const size_type m,
1742  const size_type n);
1743 
1749  operator()(const TableIndices<6> &indices);
1750 
1756  operator()(const TableIndices<6> &indices) const;
1757 };
1758 
1759 
1769 template <typename T>
1770 class Table<7, T> : public TableBase<7, T>
1771 {
1772 public:
1777 
1781  Table() = default;
1782 
1786  Table(const size_type size1,
1787  const size_type size2,
1788  const size_type size3,
1789  const size_type size4,
1790  const size_type size5,
1791  const size_type size6,
1792  const size_type size7);
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,
1827  const size_type o) const;
1828 
1836  operator()(const size_type i,
1837  const size_type j,
1838  const size_type k,
1839  const size_type l,
1840  const size_type m,
1841  const size_type n,
1842  const size_type o);
1843 
1849  operator()(const TableIndices<7> &indices);
1850 
1856  operator()(const TableIndices<7> &indices) const;
1857 };
1858 
1859 
1872 template <typename T>
1873 class TransposeTable : public TableBase<2, T>
1874 {
1875 public:
1880 
1885 
1890 
1895 
1900  using const_iterator =
1902  true,
1904 
1908  using iterator =
1910  false,
1912 
1916  TransposeTable() = default;
1917 
1921  TransposeTable(const size_type size1, const size_type size2);
1922 
1928  void
1929  reinit(const size_type size1,
1930  const size_type size2,
1931  const bool omit_default_initialization = false);
1932 
1940  operator()(const size_type i, const size_type j) const;
1941 
1948  reference
1949  operator()(const size_type i, const size_type j);
1950 
1955  size_type
1956  n_rows() const;
1957 
1962  size_type
1963  n_cols() const;
1964 
1968  iterator
1969  begin();
1970 
1975  begin() const;
1976 
1980  iterator
1981  end();
1982 
1987  end() const;
1988 
1989 protected:
2000  reference
2001  el(const size_type i, const size_type j);
2002 
2018  el(const size_type i, const size_type j) const;
2019 
2020  // Make the AccessorBase class a friend so that it may directly index into
2021  // the array.
2023  TransposeTable<T>,
2024  true,
2027  TransposeTable<T>,
2028  false,
2029  MatrixTableIterators::Storage::column_major>;
2030 
2031  // Make the mutable accessor class a friend so that we can write to array
2032  // entries with iterators.
2033  friend class MatrixTableIterators::Accessor<
2034  TransposeTable<T>,
2035  false,
2036  MatrixTableIterators::Storage::column_major>;
2037 };
2038 
2039 
2040 
2041 /* --------------------- Template and inline functions ---------------- */
2042 
2043 #ifndef DOXYGEN
2044 
2045 template <int N, typename T>
2046 TableBase<N, T>::TableBase(const TableIndices<N> &sizes)
2047 {
2048  reinit(sizes);
2049 }
2050 
2051 
2052 
2053 template <int N, typename T>
2054 template <typename InputIterator>
2056  InputIterator entries,
2057  const bool C_style_indexing)
2058 {
2059  reinit(sizes);
2060  fill(entries, C_style_indexing);
2061 }
2062 
2063 
2064 
2065 template <int N, typename T>
2067  : Subscriptor()
2068 {
2069  reinit(src.table_size, true);
2070  values = src.values;
2071 }
2072 
2073 
2074 
2075 template <int N, typename T>
2076 template <typename T2>
2078 {
2079  reinit(src.table_size);
2080  if (src.n_elements() != 0)
2081  std::copy(src.values.begin(), src.values.end(), values.begin());
2082 }
2083 
2084 
2085 
2086 template <int N, typename T>
2088  : Subscriptor(std::move(src))
2089  , values(std::move(src.values))
2090  , table_size(src.table_size)
2091 {
2092  src.table_size = TableIndices<N>();
2093 }
2094 
2095 
2096 
2097 template <int N, typename T>
2098 template <class Archive>
2099 inline void
2100 TableBase<N, T>::serialize(Archive &ar, const unsigned int)
2101 {
2102  ar &static_cast<Subscriptor &>(*this);
2103 
2104  ar &values &table_size;
2105 }
2106 
2107 
2108 
2109 namespace internal
2110 {
2111  namespace TableBaseAccessors
2112  {
2113  template <int N, typename T, bool C, unsigned int P>
2114  inline Accessor<N, T, C, P>::Accessor(const TableType &table,
2115  const iterator data)
2116  : table(table)
2117  , data(data)
2118  {}
2119 
2120 
2121 
2122  template <int N, typename T, bool C, unsigned int P>
2123  inline Accessor<N, T, C, P>::Accessor(const Accessor &a)
2124  : table(a.table)
2125  , data(a.data)
2126  {}
2127 
2128 
2129 
2130  template <int N, typename T, bool C, unsigned int P>
2131  inline Accessor<N, T, C, P - 1> Accessor<N, T, C, P>::
2132  operator[](const size_type i) const
2133  {
2134  AssertIndexRange(i, table.size()[N - P]);
2135 
2136  // access i-th
2137  // subobject. optimize on the
2138  // case i==0
2139  if (i == 0)
2140  return Accessor<N, T, C, P - 1>(table, data);
2141  else
2142  {
2143  // note: P>1, otherwise the
2144  // specialization would have
2145  // been taken!
2146  size_type subobject_size = table.size()[N - 1];
2147  for (int p = P - 1; p > 1; --p)
2148  subobject_size *= table.size()[N - p];
2149  const iterator new_data = data + i * subobject_size;
2150  return Accessor<N, T, C, P - 1>(table, new_data);
2151  }
2152  }
2153 
2154 
2155 
2156  template <int N, typename T, bool C>
2157  inline Accessor<N, T, C, 1>::Accessor(const TableType &table,
2158  const iterator data)
2159  : table(table)
2160  , data(data)
2161  {}
2162 
2163 
2164 
2165  template <int N, typename T, bool C>
2166  inline Accessor<N, T, C, 1>::Accessor(const Accessor &a)
2167  : table(a.table)
2168  , data(a.data)
2169  {}
2170 
2171 
2172 
2173  template <int N, typename T, bool C>
2175  operator[](const size_type i) const
2176  {
2177  AssertIndexRange(i, table.size()[N - 1]);
2178  return *(data + i);
2179  }
2180 
2181 
2182 
2183  template <int N, typename T, bool C>
2184  inline typename Accessor<N, T, C, 1>::size_type
2186  {
2187  return table.size()[N - 1];
2188  }
2189 
2190 
2191 
2192  template <int N, typename T, bool C>
2193  inline typename Accessor<N, T, C, 1>::iterator
2195  {
2196  return data;
2197  }
2198 
2199 
2200 
2201  template <int N, typename T, bool C>
2202  inline typename Accessor<N, T, C, 1>::iterator
2204  {
2205  return data + table.size()[N - 1];
2206  }
2207  } // namespace TableBaseAccessors
2208 } // namespace internal
2209 
2210 
2211 
2212 template <int N, typename T>
2213 inline TableBase<N, T> &
2215 {
2216  if (!m.empty())
2217  values = m.values;
2218  reinit(m.size(), true);
2219 
2220  return *this;
2221 }
2222 
2223 
2224 
2225 template <int N, typename T>
2226 template <typename T2>
2227 inline TableBase<N, T> &
2229 {
2230  reinit(m.size(), true);
2231  if (!empty())
2232  std::copy(m.values.begin(),
2233  m.values.begin() + n_elements(),
2234  values.begin());
2235 
2236  return *this;
2237 }
2238 
2239 
2240 
2241 template <int N, typename T>
2242 inline TableBase<N, T> &
2244 {
2245  static_cast<Subscriptor &>(*this) = std::move(static_cast<Subscriptor &>(m));
2246  values = std::move(m.values);
2247  table_size = m.table_size;
2249 
2250  return *this;
2251 }
2252 
2253 
2254 
2255 template <int N, typename T>
2256 inline bool
2258 {
2259  return (values == T2.values);
2260 }
2261 
2262 
2263 
2264 template <int N, typename T>
2265 inline void
2267 {
2268  // use parallel set operation
2269  if (n_elements() != 0)
2270  values.fill(T());
2271 }
2272 
2273 
2274 
2275 template <int N, typename T>
2276 inline void
2277 TableBase<N, T>::fill(const T &value)
2278 {
2279  if (n_elements() != 0)
2280  values.fill(value);
2281 }
2282 
2283 
2284 
2285 template <int N, typename T>
2286 inline void
2287 TableBase<N, T>::reinit(const TableIndices<N> &new_sizes,
2288  const bool omit_default_initialization)
2289 {
2290  table_size = new_sizes;
2291 
2292  const size_type new_size = n_elements();
2293 
2294  // if zero size was given: free all memory
2295  if (new_size == 0)
2296  {
2297  values.resize(0);
2298  // set all sizes to zero, even
2299  // if one was previously
2300  // nonzero. This simplifies
2301  // some assertions.
2302  table_size = TableIndices<N>();
2303 
2304  return;
2305  }
2306 
2307  // adjust values field. If it was empty before, we can simply call resize(),
2308  // which can set all the data fields. Otherwise, select the fast resize and
2309  // manually fill in all the elements as required by the design of this
2310  // class. (Selecting another code for the empty case ensures that we touch
2311  // the memory only once for non-trivial classes that need to initialize the
2312  // memory also in resize_fast.)
2313  if (!omit_default_initialization)
2314  {
2315  if (values.empty())
2316  values.resize(new_size);
2317  else
2318  {
2319  values.resize_fast(new_size);
2320  values.fill();
2321  }
2322  }
2323  else
2324  values.resize_fast(new_size);
2325 }
2326 
2327 
2328 
2329 template <int N, typename T>
2330 inline const TableIndices<N> &
2331 TableBase<N, T>::size() const
2332 {
2333  return table_size;
2334 }
2335 
2336 
2337 
2338 template <int N, typename T>
2339 inline typename TableBase<N, T>::size_type
2340 TableBase<N, T>::size(const unsigned int i) const
2341 {
2342  AssertIndexRange(i, N);
2343  return table_size[i];
2344 }
2345 
2346 
2347 
2348 template <int N, typename T>
2349 inline typename TableBase<N, T>::size_type
2351 {
2352  size_type s = 1;
2353  for (unsigned int n = 0; n < N; ++n)
2354  s *= table_size[n];
2355  return s;
2356 }
2357 
2358 
2359 
2360 template <int N, typename T>
2361 inline bool
2362 TableBase<N, T>::empty() const
2363 {
2364  return (n_elements() == 0);
2365 }
2366 
2367 
2368 
2369 namespace internal
2370 {
2371  namespace TableImplementation
2372  {
2373  template <typename InputIterator, typename T>
2374  void
2375  fill_Fortran_style(InputIterator entries, TableBase<1, T> &table)
2376  {
2377  using size_type = typename TableBase<1, T>::size_type;
2378  for (size_type i = 0; i < table.size()[0]; ++i)
2379  table(TableIndices<1>(i)) = *entries++;
2380  }
2381 
2382 
2383  template <typename InputIterator, typename T>
2384  void
2385  fill_Fortran_style(InputIterator entries, TableBase<2, T> &table)
2386  {
2387  using size_type = typename TableBase<2, T>::size_type;
2388  for (size_type j = 0; j < table.size()[1]; ++j)
2389  for (size_type i = 0; i < table.size()[0]; ++i)
2390  table(TableIndices<2>(i, j)) = *entries++;
2391  }
2392 
2393 
2394  template <typename InputIterator, typename T>
2395  void
2396  fill_Fortran_style(InputIterator entries, TableBase<3, T> &table)
2397  {
2398  using size_type = typename TableBase<3, T>::size_type;
2399  for (size_type k = 0; k < table.size()[2]; ++k)
2400  for (size_type j = 0; j < table.size()[1]; ++j)
2401  for (size_type i = 0; i < table.size()[0]; ++i)
2402  table(TableIndices<3>(i, j, k)) = *entries++;
2403  }
2404 
2405 
2406  template <typename InputIterator, typename T, int N>
2407  void
2408  fill_Fortran_style(InputIterator, TableBase<N, T> &)
2409  {
2410  Assert(false, ExcNotImplemented());
2411  }
2412  } // namespace TableImplementation
2413 } // namespace internal
2414 
2415 
2416 template <int N, typename T>
2417 template <typename InputIterator>
2418 inline void
2419 TableBase<N, T>::fill(InputIterator entries, const bool C_style_indexing)
2420 {
2421  Assert(n_elements() != 0, ExcMessage("Trying to fill an empty matrix."));
2422 
2423  if (C_style_indexing)
2424  for (typename AlignedVector<T>::iterator p = values.begin();
2425  p != values.end();
2426  ++p)
2427  *p = *entries++;
2428  else
2429  internal::TableImplementation::fill_Fortran_style(entries, *this);
2430 }
2431 
2432 
2433 
2434 template <int N, typename T>
2435 inline void
2437 {
2438  values.swap(v.values);
2439  std::swap(table_size, v.table_size);
2440 }
2441 
2442 
2443 
2444 template <int N, typename T>
2445 inline std::size_t
2447 {
2448  return sizeof(*this) + MemoryConsumption::memory_consumption(values);
2449 }
2450 
2451 
2452 
2453 template <int N, typename T>
2454 inline typename TableBase<N, T>::size_type
2455 TableBase<N, T>::position(const TableIndices<N> &indices) const
2456 {
2457  // specialize this for the
2458  // different numbers of dimensions,
2459  // to make the job somewhat easier
2460  // for the compiler. have the
2461  // general formula nevertheless:
2462  switch (N)
2463  {
2464  case 1:
2465  return indices[0];
2466  case 2:
2467  return size_type(indices[0]) * table_size[1] + indices[1];
2468  case 3:
2469  return ((size_type(indices[0]) * table_size[1] + indices[1]) *
2470  table_size[2] +
2471  indices[2]);
2472  default:
2473  {
2474  unsigned int s = indices[0];
2475  for (unsigned int n = 1; n < N; ++n)
2476  s = s * table_size[n] + indices[n];
2477  return s;
2478  }
2479  }
2480 }
2481 
2482 
2483 
2484 template <int N, typename T>
2485 inline typename AlignedVector<T>::const_reference
2486 TableBase<N, T>::operator()(const TableIndices<N> &indices) const
2487 {
2488  for (unsigned int n = 0; n < N; ++n)
2489  AssertIndexRange(indices[n], table_size[n]);
2490  return el(indices);
2491 }
2492 
2493 
2494 
2495 template <int N, typename T>
2496 inline typename AlignedVector<T>::reference
2498 {
2499  for (unsigned int n = 0; n < N; ++n)
2500  AssertIndexRange(indices[n], table_size[n]);
2501  return el(indices);
2502 }
2503 
2504 
2505 
2506 template <int N, typename T>
2507 inline typename AlignedVector<T>::const_reference
2508 TableBase<N, T>::el(const TableIndices<N> &indices) const
2509 {
2510  return values[position(indices)];
2511 }
2512 
2513 
2514 
2515 template <int N, typename T>
2516 inline typename AlignedVector<T>::reference
2517 TableBase<N, T>::el(const TableIndices<N> &indices)
2518 {
2519  AssertIndexRange(position(indices), values.size());
2520  return values[position(indices)];
2521 }
2522 
2523 
2524 
2525 template <typename T>
2526 inline Table<1, T>::Table(const size_type size)
2528 {}
2529 
2530 
2531 
2532 template <typename T>
2533 template <typename InputIterator>
2534 inline Table<1, T>::Table(const size_type size,
2535  InputIterator entries,
2536  const bool C_style_indexing)
2537  : TableBase<1, T>(TableIndices<1>(size), entries, C_style_indexing)
2538 {}
2539 
2540 
2541 
2542 template <typename T>
2544  operator[](const size_type i) const
2545 {
2546  AssertIndexRange(i, this->table_size[0]);
2547  return this->values[i];
2548 }
2549 
2550 
2551 
2552 template <typename T>
2554  operator[](const size_type i)
2555 {
2556  AssertIndexRange(i, this->table_size[0]);
2557  return this->values[i];
2558 }
2559 
2560 
2561 
2562 template <typename T>
2563 inline typename AlignedVector<T>::const_reference
2564 Table<1, T>::operator()(const size_type i) const
2565 {
2566  AssertIndexRange(i, this->table_size[0]);
2567  return this->values[i];
2568 }
2569 
2570 
2571 
2572 template <typename T>
2573 inline typename AlignedVector<T>::reference
2575 {
2576  AssertIndexRange(i, this->table_size[0]);
2577  return this->values[i];
2578 }
2579 
2580 
2581 
2582 template <typename T>
2583 inline typename AlignedVector<T>::const_reference
2584 Table<1, T>::operator()(const TableIndices<1> &indices) const
2585 {
2586  return TableBase<1, T>::operator()(indices);
2587 }
2588 
2589 
2590 
2591 template <typename T>
2592 inline typename AlignedVector<T>::reference
2594 {
2595  return TableBase<1, T>::operator()(indices);
2596 }
2597 
2598 
2599 //---------------------------------------------------------------------------
2600 
2601 
2602 
2603 template <typename T>
2604 inline Table<2, T>::Table(const size_type size1, const size_type size2)
2605  : TableBase<2, T>(TableIndices<2>(size1, size2))
2606 {}
2607 
2608 
2609 
2610 template <typename T>
2611 template <typename InputIterator>
2612 inline Table<2, T>::Table(const size_type size1,
2613  const size_type size2,
2614  InputIterator entries,
2615  const bool C_style_indexing)
2616  : TableBase<2, T>(TableIndices<2>(size1, size2), entries, C_style_indexing)
2617 {}
2618 
2619 
2620 
2621 template <typename T>
2622 inline void
2623 Table<2, T>::reinit(const size_type size1,
2624  const size_type size2,
2625  const bool omit_default_initialization)
2626 {
2627  this->TableBase<2, T>::reinit(TableIndices<2>(size1, size2),
2628  omit_default_initialization);
2629 }
2630 
2631 
2632 
2633 template <typename T>
2634 inline ::internal::TableBaseAccessors::Accessor<2, T, true, 1>
2635  Table<2, T>::operator[](const size_type i) const
2636 {
2637  AssertIndexRange(i, this->table_size[0]);
2638  return ::internal::TableBaseAccessors::Accessor<2, T, true, 1>(
2639  *this, this->values.begin() + size_type(i) * n_cols());
2640 }
2641 
2642 
2643 
2644 template <typename T>
2645 inline ::internal::TableBaseAccessors::Accessor<2, T, false, 1>
2647 {
2648  AssertIndexRange(i, this->table_size[0]);
2649  return ::internal::TableBaseAccessors::Accessor<2, T, false, 1>(
2650  *this, this->values.begin() + size_type(i) * n_cols());
2651 }
2652 
2653 
2654 
2655 template <typename T>
2656 inline typename AlignedVector<T>::const_reference
2657 Table<2, T>::operator()(const size_type i, const size_type j) const
2658 {
2659  AssertIndexRange(i, this->table_size[0]);
2660  AssertIndexRange(j, this->table_size[1]);
2661  return this->values[size_type(i) * this->table_size[1] + j];
2662 }
2663 
2664 
2665 
2666 template <typename T>
2667 inline typename AlignedVector<T>::reference
2669 {
2670  AssertIndexRange(i, this->table_size[0]);
2671  AssertIndexRange(j, this->table_size[1]);
2672  return this->values[size_type(i) * this->table_size[1] + j];
2673 }
2674 
2675 
2676 
2677 template <typename T>
2678 inline typename AlignedVector<T>::const_reference
2679 Table<2, T>::operator()(const TableIndices<2> &indices) const
2680 {
2681  return TableBase<2, T>::operator()(indices);
2682 }
2683 
2684 
2685 
2686 template <typename T>
2687 inline typename AlignedVector<T>::reference
2689 {
2690  return TableBase<2, T>::operator()(indices);
2691 }
2692 
2693 
2694 
2695 template <typename T>
2696 inline typename AlignedVector<T>::const_reference
2697 Table<2, T>::el(const size_type i, const size_type j) const
2698 {
2699  return this->values[size_type(i) * this->table_size[1] + j];
2700 }
2701 
2702 
2703 
2704 template <typename T>
2705 inline typename AlignedVector<T>::reference
2706 Table<2, T>::el(const size_type i, const size_type j)
2707 {
2708  return this->values[size_type(i) * this->table_size[1] + j];
2709 }
2710 
2711 
2712 
2713 template <typename T>
2714 inline typename Table<2, T>::size_type
2715 Table<2, T>::n_rows() const
2716 {
2717  return this->table_size[0];
2718 }
2719 
2720 
2721 
2722 template <typename T>
2723 inline typename Table<2, T>::size_type
2724 Table<2, T>::n_cols() const
2725 {
2726  return this->table_size[1];
2727 }
2728 
2729 
2730 
2731 template <typename T>
2732 inline typename Table<2, T>::iterator
2734 {
2735  return typename Table<2, T>::iterator(this, 0, 0);
2736 }
2737 
2738 
2739 
2740 template <typename T>
2741 inline typename Table<2, T>::const_iterator
2742 Table<2, T>::begin() const
2743 {
2744  return typename Table<2, T>::const_iterator(this, 0, 0);
2745 }
2746 
2747 
2748 
2749 template <typename T>
2750 inline typename Table<2, T>::iterator
2752 {
2753  return typename Table<2, T>::iterator(this);
2754 }
2755 
2756 
2757 
2758 template <typename T>
2759 inline typename Table<2, T>::const_iterator
2760 Table<2, T>::end() const
2761 {
2762  return typename Table<2, T>::const_iterator(this);
2763 }
2764 
2765 
2766 
2767 //---------------------------------------------------------------------------
2768 namespace MatrixTableIterators
2769 {
2770  namespace internal
2771  {
2772  // Internal calculation routines for AccessorBase. These do not do any
2773  // checking whatsoever.
2774  template <typename TableType, Storage storage_order>
2775  inline std::ptrdiff_t
2776  get_row_index(const std::ptrdiff_t linear_index,
2777  const TableType *const container)
2778  {
2779  switch (storage_order)
2780  {
2781  case Storage::row_major:
2782  return linear_index / container->n_cols();
2783  case Storage::column_major:
2784  return linear_index % container->n_rows();
2785  default:
2786  Assert(false, ExcInternalError());
2787  }
2788  return {};
2789  }
2790 
2791 
2792 
2793  template <typename TableType, Storage storage_order>
2794  inline std::ptrdiff_t
2795  get_column_index(const std::ptrdiff_t linear_index,
2796  const TableType *const container)
2797  {
2798  switch (storage_order)
2799  {
2800  case Storage::row_major:
2801  return linear_index % container->n_cols();
2802  case Storage::column_major:
2803  return linear_index / container->n_rows();
2804  default:
2805  Assert(false, ExcInternalError());
2806  }
2807  return {};
2808  }
2809  } // namespace internal
2810 
2811 
2812 
2813  template <typename TableType, bool Constness, Storage storage_order>
2814  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase()
2815  : container(nullptr)
2816  , linear_index(std::numeric_limits<decltype(linear_index)>::max())
2817  {}
2818 
2819 
2820 
2821  template <typename TableType, bool Constness, Storage storage_order>
2822  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2823  const container_pointer_type table)
2824  : container(table)
2825  , linear_index(container->values.size())
2826  {}
2827 
2828 
2829 
2830  template <typename TableType, bool Constness, Storage storage_order>
2831  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2832  const AccessorBase<TableType, false, storage_order> &a)
2833  : container(a.container)
2834  , linear_index(a.linear_index)
2835  {}
2836 
2837 
2838 
2839  template <typename TableType, bool Constness, Storage storage_order>
2840  inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2841  const container_pointer_type table,
2842  const std::ptrdiff_t index)
2843  : container(table)
2844  , linear_index(index)
2845  {
2846  Assert(0 <= linear_index &&
2847  std::size_t(linear_index) < container->values.size() + 1,
2848  ExcMessage("The current iterator points outside of the table and is "
2849  "not the end iterator."));
2850  }
2851 
2852 
2853 
2854  template <typename TableType, bool Constness, Storage storage_order>
2855  inline const typename AccessorBase<TableType, Constness, storage_order>::
2856  value_type &
2858  {
2859  assert_valid_linear_index();
2860  return this->container->values[linear_index];
2861  }
2862 
2863 
2864 
2865  template <typename TableType, bool Constness, Storage storage_order>
2866  inline AccessorBase<TableType, Constness, storage_order>::
2867  operator const value_type &() const
2868  {
2869  assert_valid_linear_index();
2870  return this->container->values[linear_index];
2871  }
2872 
2873 
2874 
2875  template <typename TableType, bool Constness, Storage storage_order>
2877  AccessorBase<TableType, Constness, storage_order>::row() const
2878  {
2879  assert_valid_linear_index();
2880  return static_cast<std::size_t>(
2881  internal::get_row_index<TableType, storage_order>(linear_index,
2882  container));
2883  }
2884 
2885 
2886 
2887  template <typename TableType, bool Constness, Storage storage_order>
2889  AccessorBase<TableType, Constness, storage_order>::column() const
2890  {
2891  assert_valid_linear_index();
2892  return static_cast<std::size_t>(
2893  internal::get_column_index<TableType, storage_order>(linear_index,
2894  container));
2895  }
2896 
2897 
2898 
2899  template <typename TableType, bool Constness, Storage storage_order>
2900  inline void
2901  AccessorBase<TableType, Constness, storage_order>::assert_valid_linear_index()
2902  const
2903  {
2904 # ifdef DEBUG // avoid unused variable warnings by guarding everything
2905  Assert(container != nullptr,
2906  ExcMessage("This accessor has been default-constructed and does not "
2907  "have a corresponding table."));
2908  Assert(!container->empty(),
2909  ExcMessage("An empty table has no rows or columns."));
2910  Assert(0 <= linear_index &&
2911  std::size_t(linear_index) < container->values.size(),
2912  ExcMessage("The current iterator points outside of the table."));
2913  const std::ptrdiff_t row_n =
2914  internal::get_row_index<TableType, storage_order>(linear_index,
2915  container);
2916  const std::ptrdiff_t column_n =
2917  internal::get_column_index<TableType, storage_order>(linear_index,
2918  container);
2919  Assert(0 <= column_n && std::size_t(column_n) < container->n_cols(),
2920  ExcMessage("The current iterator points outside the table."));
2921  Assert(0 <= row_n && std::size_t(row_n) < container->n_rows(),
2922  ExcMessage("The current iterator points outside the table."));
2923 # endif
2924  }
2925 
2926 
2927 
2928  template <typename TableType, Storage storage_order>
2929  inline const Accessor<TableType, false, storage_order> &
2930  Accessor<TableType, false, storage_order>::operator=(
2931  const typename Accessor<TableType, false, storage_order>::value_type &t)
2932  const
2933  {
2934  this->assert_valid_linear_index();
2935  this->container->values[this->linear_index] = t;
2936  return *this;
2937  }
2938 
2939 
2940 
2941  template <typename TableType, Storage storage_order>
2942  inline const Accessor<TableType, false, storage_order> &
2943  Accessor<TableType, false, storage_order>::operator=(
2944  typename Accessor<TableType, false, storage_order>::value_type &&t) const
2945  {
2946  this->assert_valid_linear_index();
2947  this->container->values[this->linear_index] = t;
2948  return *this;
2949  }
2950 
2951 
2952 
2953  template <typename TableType, Storage storage_order>
2954  inline typename Accessor<TableType, false, storage_order>::value_type &
2956  {
2957  this->assert_valid_linear_index();
2958  return this->container->values[this->linear_index];
2959  }
2960 
2961 
2962 
2963  template <typename TableType, Storage storage_order>
2964  inline Accessor<TableType, false, storage_order>::operator value_type &()
2965  {
2966  this->assert_valid_linear_index();
2967  return this->container->values[this->linear_index];
2968  }
2969 
2970 
2971 
2972  template <typename TableType, bool Constness, Storage storage_order>
2973  inline Iterator<TableType, Constness, storage_order>::Iterator(
2977  {}
2978 
2979 
2980 
2981  template <typename TableType, bool Constness, Storage storage_order>
2982  inline Iterator<TableType, Constness, storage_order>::Iterator(
2983  const container_pointer_type table)
2987  {}
2988 
2989 
2990 
2991  template <typename TableType, bool Constness, Storage storage_order>
2992  inline Iterator<TableType, Constness, storage_order>::Iterator(
2993  const Iterator<TableType, false, storage_order> &i)
2996  {}
2997 
2998 
2999 
3000  template <typename TableType, bool Constness, Storage storage_order>
3001  inline Iterator<TableType, Constness, storage_order>::Iterator(
3002  const container_pointer_type table,
3003  const size_type row_n,
3004  const size_type col_n)
3005  : Iterator(table,
3006  storage_order == Storage::row_major ?
3007  table->n_cols() * row_n + col_n :
3008  table->n_rows() * col_n + row_n)
3009  {}
3010 
3011 
3012 
3013  template <typename TableType, bool Constness, Storage storage_order>
3014  inline Iterator<TableType, Constness, storage_order>::Iterator(
3015  const container_pointer_type table,
3016  const std::ptrdiff_t linear_index)
3019  Accessor<TableType, Constness, storage_order>(table, linear_index))
3020  {}
3021 } // namespace MatrixTableIterators
3022 
3023 
3024 
3025 //---------------------------------------------------------------------------
3026 template <typename T>
3027 inline TransposeTable<T>::TransposeTable(const size_type size1,
3028  const size_type size2)
3029  : TableBase<2, T>(TableIndices<2>(size2, size1))
3030 {}
3031 
3032 
3033 
3034 template <typename T>
3035 inline void
3037  const size_type size2,
3038  const bool omit_default_initialization)
3039 {
3040  this->TableBase<2, T>::reinit(TableIndices<2>(size2, size1),
3041  omit_default_initialization);
3042 }
3043 
3044 
3045 
3046 template <typename T>
3047 inline typename TransposeTable<T>::const_reference
3048 TransposeTable<T>::operator()(const size_type i, const size_type j) const
3049 {
3050  AssertIndexRange(i, this->table_size[1]);
3051  AssertIndexRange(j, this->table_size[0]);
3052  return this->values[size_type(j) * this->table_size[1] + i];
3053 }
3054 
3055 
3056 
3057 template <typename T>
3058 inline typename TransposeTable<T>::reference
3060 {
3061  AssertIndexRange(i, this->table_size[1]);
3062  AssertIndexRange(j, this->table_size[0]);
3063  return this->values[size_type(j) * this->table_size[1] + i];
3064 }
3065 
3066 
3067 
3068 template <typename T>
3069 inline typename TransposeTable<T>::const_reference
3070 TransposeTable<T>::el(const size_type i, const size_type j) const
3071 {
3072  return this->values[size_type(j) * this->table_size[1] + i];
3073 }
3074 
3075 
3076 
3077 template <typename T>
3078 inline typename TransposeTable<T>::reference
3079 TransposeTable<T>::el(const size_type i, const size_type j)
3080 {
3081  return this->values[size_type(j) * this->table_size[1] + i];
3082 }
3083 
3084 
3085 
3086 template <typename T>
3087 inline typename TransposeTable<T>::size_type
3089 {
3090  return this->table_size[1];
3091 }
3092 
3093 
3094 
3095 template <typename T>
3096 inline typename TransposeTable<T>::size_type
3098 {
3099  return this->table_size[0];
3100 }
3101 
3102 
3103 
3104 template <typename T>
3105 inline typename TransposeTable<T>::iterator
3107 {
3108  return typename TransposeTable<T>::iterator(this, 0, 0);
3109 }
3110 
3111 
3112 
3113 template <typename T>
3114 inline typename TransposeTable<T>::const_iterator
3116 {
3117  return typename TransposeTable<T>::const_iterator(this, 0, 0);
3118 }
3119 
3120 
3121 
3122 template <typename T>
3123 inline typename TransposeTable<T>::iterator
3125 {
3126  return typename TransposeTable<T>::iterator(this);
3127 }
3128 
3129 
3130 
3131 template <typename T>
3132 inline typename TransposeTable<T>::const_iterator
3133 TransposeTable<T>::end() const
3134 {
3135  return typename TransposeTable<T>::const_iterator(this);
3136 }
3137 //---------------------------------------------------------------------------
3138 
3139 
3140 
3141 template <typename T>
3142 inline Table<3, T>::Table(const size_type size1,
3143  const size_type size2,
3144  const size_type size3)
3145  : TableBase<3, T>(TableIndices<3>(size1, size2, size3))
3146 {}
3147 
3148 
3149 
3150 template <typename T>
3151 template <typename InputIterator>
3152 inline Table<3, T>::Table(const size_type size1,
3153  const size_type size2,
3154  const size_type size3,
3155  InputIterator entries,
3156  const bool C_style_indexing)
3157  : TableBase<3, T>(TableIndices<3>(size1, size2, size3),
3158  entries,
3159  C_style_indexing)
3160 {}
3161 
3162 
3163 
3164 template <typename T>
3165 inline ::internal::TableBaseAccessors::Accessor<3, T, true, 2>
3166  Table<3, T>::operator[](const size_type i) const
3167 {
3168  AssertIndexRange(i, this->table_size[0]);
3169  const size_type subobject_size =
3170  size_type(this->table_size[1]) * this->table_size[2];
3172  *this, this->values.begin() + i * subobject_size));
3173 }
3174 
3175 
3176 
3177 template <typename T>
3178 inline ::internal::TableBaseAccessors::Accessor<3, T, false, 2>
3180 {
3181  AssertIndexRange(i, this->table_size[0]);
3182  const size_type subobject_size =
3183  size_type(this->table_size[1]) * this->table_size[2];
3185  *this, this->values.begin() + i * subobject_size));
3186 }
3187 
3188 
3189 
3190 template <typename T>
3191 inline typename AlignedVector<T>::const_reference
3193 operator()(const size_type i, const size_type j, const size_type k) const
3194 {
3195  AssertIndexRange(i, this->table_size[0]);
3196  AssertIndexRange(j, this->table_size[1]);
3197  AssertIndexRange(k, this->table_size[2]);
3198  return this
3199  ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3200  k];
3201 }
3202 
3203 
3204 
3205 template <typename T>
3206 inline typename AlignedVector<T>::reference
3207 Table<3, T>::operator()(const size_type i, const size_type j, const size_type k)
3208 {
3209  AssertIndexRange(i, this->table_size[0]);
3210  AssertIndexRange(j, this->table_size[1]);
3211  AssertIndexRange(k, this->table_size[2]);
3212  return this
3213  ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3214  k];
3215 }
3216 
3217 
3218 
3219 template <typename T>
3220 inline typename AlignedVector<T>::const_reference
3221 Table<3, T>::operator()(const TableIndices<3> &indices) const
3222 {
3223  return TableBase<3, T>::operator()(indices);
3224 }
3225 
3226 
3227 
3228 template <typename T>
3229 inline typename AlignedVector<T>::reference
3231 {
3232  return TableBase<3, T>::operator()(indices);
3233 }
3234 
3235 
3236 
3237 template <typename T>
3238 inline Table<4, T>::Table(const size_type size1,
3239  const size_type size2,
3240  const size_type size3,
3241  const size_type size4)
3242  : TableBase<4, T>(TableIndices<4>(size1, size2, size3, size4))
3243 {}
3244 
3245 
3246 
3247 template <typename T>
3248 inline ::internal::TableBaseAccessors::Accessor<4, T, true, 3>
3249  Table<4, T>::operator[](const size_type i) const
3250 {
3251  AssertIndexRange(i, this->table_size[0]);
3252  const size_type subobject_size =
3253  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3255  *this, this->values.begin() + i * subobject_size));
3256 }
3257 
3258 
3259 
3260 template <typename T>
3261 inline ::internal::TableBaseAccessors::Accessor<4, T, false, 3>
3263 {
3264  AssertIndexRange(i, this->table_size[0]);
3265  const size_type subobject_size =
3266  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3268  *this, this->values.begin() + i * subobject_size));
3269 }
3270 
3271 
3272 
3273 template <typename T>
3274 inline typename AlignedVector<T>::const_reference
3276  const size_type j,
3277  const size_type k,
3278  const size_type l) const
3279 {
3280  AssertIndexRange(i, this->table_size[0]);
3281  AssertIndexRange(j, this->table_size[1]);
3282  AssertIndexRange(k, this->table_size[2]);
3283  AssertIndexRange(l, this->table_size[3]);
3284  return this
3285  ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3286  k) *
3287  this->table_size[3] +
3288  l];
3289 }
3290 
3291 
3292 
3293 template <typename T>
3294 inline typename AlignedVector<T>::reference
3296  const size_type j,
3297  const size_type k,
3298  const size_type l)
3299 {
3300  AssertIndexRange(i, this->table_size[0]);
3301  AssertIndexRange(j, this->table_size[1]);
3302  AssertIndexRange(k, this->table_size[2]);
3303  AssertIndexRange(l, this->table_size[3]);
3304  return this
3305  ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3306  k) *
3307  this->table_size[3] +
3308  l];
3309 }
3310 
3311 
3312 
3313 template <typename T>
3314 inline typename AlignedVector<T>::const_reference
3315 Table<4, T>::operator()(const TableIndices<4> &indices) const
3316 {
3317  return TableBase<4, T>::operator()(indices);
3318 }
3319 
3320 
3321 
3322 template <typename T>
3323 inline typename AlignedVector<T>::reference
3325 {
3326  return TableBase<4, T>::operator()(indices);
3327 }
3328 
3329 
3330 
3331 template <typename T>
3332 inline Table<5, T>::Table(const size_type size1,
3333  const size_type size2,
3334  const size_type size3,
3335  const size_type size4,
3336  const size_type size5)
3337  : TableBase<5, T>(TableIndices<5>(size1, size2, size3, size4, size5))
3338 {}
3339 
3340 
3341 
3342 template <typename T>
3343 inline ::internal::TableBaseAccessors::Accessor<5, T, true, 4>
3344  Table<5, T>::operator[](const size_type i) const
3345 {
3346  AssertIndexRange(i, this->table_size[0]);
3347  const size_type subobject_size = size_type(this->table_size[1]) *
3348  this->table_size[2] * this->table_size[3] *
3349  this->table_size[4];
3351  *this, this->values.begin() + i * subobject_size));
3352 }
3353 
3354 
3355 
3356 template <typename T>
3357 inline ::internal::TableBaseAccessors::Accessor<5, T, false, 4>
3359 {
3360  AssertIndexRange(i, this->table_size[0]);
3361  const size_type subobject_size = size_type(this->table_size[1]) *
3362  this->table_size[2] * this->table_size[3] *
3363  this->table_size[4];
3365  *this, this->values.begin() + i * subobject_size));
3366 }
3367 
3368 
3369 
3370 template <typename T>
3371 inline typename AlignedVector<T>::const_reference
3373  const size_type j,
3374  const size_type k,
3375  const size_type l,
3376  const size_type m) const
3377 {
3378  AssertIndexRange(i, this->table_size[0]);
3379  AssertIndexRange(j, this->table_size[1]);
3380  AssertIndexRange(k, this->table_size[2]);
3381  AssertIndexRange(l, this->table_size[3]);
3382  AssertIndexRange(m, this->table_size[4]);
3383  return this
3384  ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3385  k) *
3386  this->table_size[3] +
3387  l) *
3388  this->table_size[4] +
3389  m];
3390 }
3391 
3392 
3393 
3394 template <typename T>
3395 inline typename AlignedVector<T>::reference
3397  const size_type j,
3398  const size_type k,
3399  const size_type l,
3400  const size_type m)
3401 {
3402  AssertIndexRange(i, this->table_size[0]);
3403  AssertIndexRange(j, this->table_size[1]);
3404  AssertIndexRange(k, this->table_size[2]);
3405  AssertIndexRange(l, this->table_size[3]);
3406  AssertIndexRange(m, this->table_size[4]);
3407  return this
3408  ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3409  k) *
3410  this->table_size[3] +
3411  l) *
3412  this->table_size[4] +
3413  m];
3414 }
3415 
3416 
3417 
3418 template <typename T>
3419 inline typename AlignedVector<T>::const_reference
3420 Table<5, T>::operator()(const TableIndices<5> &indices) const
3421 {
3422  return TableBase<5, T>::operator()(indices);
3423 }
3424 
3425 
3426 
3427 template <typename T>
3428 inline typename AlignedVector<T>::reference
3430 {
3431  return TableBase<5, T>::operator()(indices);
3432 }
3433 
3434 
3435 
3436 template <typename T>
3437 inline Table<6, T>::Table(const size_type size1,
3438  const size_type size2,
3439  const size_type size3,
3440  const size_type size4,
3441  const size_type size5,
3442  const size_type size6)
3443  : TableBase<6, T>()
3444 {
3445  TableIndices<6> table_indices;
3446  table_indices[0] = size1;
3447  table_indices[1] = size2;
3448  table_indices[2] = size3;
3449  table_indices[3] = size4;
3450  table_indices[4] = size5;
3451  table_indices[5] = size6;
3452 
3453  TableBase<6, T>::reinit(table_indices);
3454 }
3455 
3456 
3457 
3458 template <typename T>
3459 inline ::internal::TableBaseAccessors::Accessor<6, T, true, 5>
3460  Table<6, T>::operator[](const size_type i) const
3461 {
3462  AssertIndexRange(i, this->table_size[0]);
3463  const size_type subobject_size = size_type(this->table_size[1]) *
3464  this->table_size[2] * this->table_size[3] *
3465  this->table_size[4] * this->table_size[5];
3467  *this, this->values.begin() + i * subobject_size));
3468 }
3469 
3470 
3471 
3472 template <typename T>
3473 inline ::internal::TableBaseAccessors::Accessor<6, T, false, 5>
3475 {
3476  AssertIndexRange(i, this->table_size[0]);
3477  const size_type subobject_size = size_type(this->table_size[1]) *
3478  this->table_size[2] * this->table_size[3] *
3479  this->table_size[4] * this->table_size[5];
3481  *this, this->values.begin() + i * subobject_size));
3482 }
3483 
3484 
3485 
3486 template <typename T>
3487 inline typename AlignedVector<T>::const_reference
3489  const size_type j,
3490  const size_type k,
3491  const size_type l,
3492  const size_type m,
3493  const size_type n) const
3494 {
3495  AssertIndexRange(i, this->table_size[0]);
3496  AssertIndexRange(j, this->table_size[1]);
3497  AssertIndexRange(k, this->table_size[2]);
3498  AssertIndexRange(l, this->table_size[3]);
3499  AssertIndexRange(m, this->table_size[4]);
3500  AssertIndexRange(n, this->table_size[5]);
3501  return this
3502  ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3503  k) *
3504  this->table_size[3] +
3505  l) *
3506  this->table_size[4] +
3507  m) *
3508  this->table_size[5] +
3509  n];
3510 }
3511 
3512 
3513 
3514 template <typename T>
3515 inline typename AlignedVector<T>::reference
3517  const size_type j,
3518  const size_type k,
3519  const size_type l,
3520  const size_type m,
3521  const size_type n)
3522 {
3523  AssertIndexRange(i, this->table_size[0]);
3524  AssertIndexRange(j, this->table_size[1]);
3525  AssertIndexRange(k, this->table_size[2]);
3526  AssertIndexRange(l, this->table_size[3]);
3527  AssertIndexRange(m, this->table_size[4]);
3528  AssertIndexRange(n, this->table_size[5]);
3529  return this
3530  ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3531  k) *
3532  this->table_size[3] +
3533  l) *
3534  this->table_size[4] +
3535  m) *
3536  this->table_size[5] +
3537  n];
3538 }
3539 
3540 
3541 
3542 template <typename T>
3543 inline typename AlignedVector<T>::const_reference
3544 Table<6, T>::operator()(const TableIndices<6> &indices) const
3545 {
3546  return TableBase<6, T>::operator()(indices);
3547 }
3548 
3549 
3550 
3551 template <typename T>
3552 inline typename AlignedVector<T>::reference
3554 {
3555  return TableBase<6, T>::operator()(indices);
3556 }
3557 
3558 
3559 
3560 template <typename T>
3561 inline Table<7, T>::Table(const size_type size1,
3562  const size_type size2,
3563  const size_type size3,
3564  const size_type size4,
3565  const size_type size5,
3566  const size_type size6,
3567  const size_type size7)
3568  : TableBase<7, T>()
3569 {
3570  TableIndices<7> table_indices;
3571  table_indices[0] = size1;
3572  table_indices[1] = size2;
3573  table_indices[2] = size3;
3574  table_indices[3] = size4;
3575  table_indices[4] = size5;
3576  table_indices[5] = size6;
3577  table_indices[6] = size7;
3578 
3579  TableBase<7, T>::reinit(table_indices);
3580 }
3581 
3582 
3583 
3584 template <typename T>
3585 inline ::internal::TableBaseAccessors::Accessor<7, T, true, 6>
3586  Table<7, T>::operator[](const size_type i) const
3587 {
3588  AssertIndexRange(i, this->table_size[0]);
3589  const size_type subobject_size =
3590  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3591  this->table_size[4] * this->table_size[5] * this->table_size[6];
3593  *this, this->values.begin() + i * subobject_size));
3594 }
3595 
3596 
3597 
3598 template <typename T>
3599 inline ::internal::TableBaseAccessors::Accessor<7, T, false, 6>
3601 {
3602  AssertIndexRange(i, this->table_size[0]);
3603  const size_type subobject_size =
3604  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3605  this->table_size[4] * this->table_size[5] * this->table_size[6];
3607  *this, this->values.begin() + i * subobject_size));
3608 }
3609 
3610 
3611 
3612 template <typename T>
3613 inline typename AlignedVector<T>::const_reference
3615  const size_type j,
3616  const size_type k,
3617  const size_type l,
3618  const size_type m,
3619  const size_type n,
3620  const size_type o) const
3621 {
3622  AssertIndexRange(i, this->table_size[0]);
3623  AssertIndexRange(j, this->table_size[1]);
3624  AssertIndexRange(k, this->table_size[2]);
3625  AssertIndexRange(l, this->table_size[3]);
3626  AssertIndexRange(m, this->table_size[4]);
3627  AssertIndexRange(n, this->table_size[5]);
3628  AssertIndexRange(o, this->table_size[6]);
3629  return this->values
3630  [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3631  this->table_size[3] +
3632  l) *
3633  this->table_size[4] +
3634  m) *
3635  this->table_size[5] +
3636  n) *
3637  this->table_size[6] +
3638  o];
3639 }
3640 
3641 
3642 
3643 template <typename T>
3644 inline typename AlignedVector<T>::reference
3646  const size_type j,
3647  const size_type k,
3648  const size_type l,
3649  const size_type m,
3650  const size_type n,
3651  const size_type o)
3652 {
3653  AssertIndexRange(i, this->table_size[0]);
3654  AssertIndexRange(j, this->table_size[1]);
3655  AssertIndexRange(k, this->table_size[2]);
3656  AssertIndexRange(l, this->table_size[3]);
3657  AssertIndexRange(m, this->table_size[4]);
3658  AssertIndexRange(n, this->table_size[5]);
3659  AssertIndexRange(o, this->table_size[6]);
3660  return this->values
3661  [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3662  this->table_size[3] +
3663  l) *
3664  this->table_size[4] +
3665  m) *
3666  this->table_size[5] +
3667  n) *
3668  this->table_size[6] +
3669  o];
3670 }
3671 
3672 
3673 
3674 template <typename T>
3675 inline typename AlignedVector<T>::const_reference
3676 Table<7, T>::operator()(const TableIndices<7> &indices) const
3677 {
3678  return TableBase<7, T>::operator()(indices);
3679 }
3680 
3681 
3682 
3683 template <typename T>
3684 inline typename AlignedVector<T>::reference
3686 {
3687  return TableBase<7, T>::operator()(indices);
3688 }
3689 
3690 
3691 #endif // DOXYGEN
3692 
3693 
3694 
3700 template <int N, typename T>
3701 inline void
3703 {
3704  u.swap(v);
3705 }
3706 
3708 
3709 #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:1359
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:799
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:1879
MatrixTableIterators::Iterator< TransposeTable< T >, true, MatrixTableIterators::Storage::column_major > const_iterator
Definition: table.h:1903
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:1679
typename AccessorBase< TableType, true, storage_order >::value_type value_type
Definition: table.h:986
size_type n_cols() const
typename Types< N, T, C >::iterator iterator
Definition: table.h:165
typename AlignedVector< number >::reference reference
Definition: table.h:1889
typename std::conditional< Constness, const TableType *, TableType * >::type container_pointer_type
Definition: table.h:847
#define AssertIndexRange(index, range)
Definition: exceptions.h:1698
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:1112
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:688
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:1127
typename Types< N, T, C >::TableType TableType
Definition: table.h:259
typename TableBase< 4, T >::size_type size_type
Definition: table.h:1490
MatrixTableIterators::Iterator< TransposeTable< T >, false, MatrixTableIterators::Storage::column_major > iterator
Definition: table.h:1911
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition: table.h:992
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:959
#define Assert(cond, exc)
Definition: exceptions.h:1473
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition: table.h:965
Accessor base class for Table<2, T> and TransposeTable.
Definition: table.h:840
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:921
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:396
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:1053
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:885
Accessor class offering read and write access to the elements of a table.
Definition: table.h:978
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:814
void swap(TableBase< N, T > &u, TableBase< N, T > &v)
Definition: table.h:3702
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:387
std::size_t memory_consumption() const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:395
VectorType::value_type * begin(VectorType &V)
typename TableBase< 5, T >::size_type size_type
Definition: table.h:1583
void reset_values()
static const char N
typename AlignedVector< T >::reference reference
Definition: table.h:1122
TransposeTable()=default
typename AlignedVector< T >::value_type value_type
Definition: table.h:1117
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:645
#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:640
Accessor class template. This class is partially specialized for both values of Constness.
Definition: table.h:821
void copy(const T *begin, const T *end, U *dest)
typename TableBase< 7, T >::size_type size_type
Definition: table.h:1776
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:1894
typename std::conditional< Constness, const TableType *, TableType * >::type container_pointer_type
Definition: table.h:1059
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
static ::ExceptionBase & ExcInternalError()