Reference documentation for deal.II version 9.1.0-pre
table.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2002 - 2018 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 
21 #include <deal.II/base/aligned_vector.h>
22 #include <deal.II/base/exceptions.h>
23 #include <deal.II/base/linear_index_iterator.h>
24 #include <deal.II/base/memory_consumption.h>
25 #include <deal.II/base/subscriptor.h>
26 #include <deal.II/base/table_indices.h>
27 
28 #include <algorithm>
29 #include <cstddef>
30 
31 DEAL_II_NAMESPACE_OPEN
32 
33 // forward declaration
34 template <int N, typename T>
35 class TableBase;
36 template <int N, typename T>
37 class Table;
38 template <typename T>
40 template <typename T>
41 class Table<1, T>;
42 template <typename T>
43 class Table<2, T>;
44 template <typename T>
45 class Table<3, T>;
46 template <typename T>
47 class Table<4, T>;
48 template <typename T>
49 class Table<5, T>;
50 template <typename T>
51 class Table<6, T>;
52 
53 
54 
55 namespace internal
56 {
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 
97  using iterator = typename AlignedVector<T>::const_iterator;
98  using const_iterator = typename AlignedVector<T>::const_iterator;
99 
100  using reference = typename AlignedVector<T>::const_reference;
101  using const_reference = typename AlignedVector<T>::const_reference;
102  };
103 
109  template <int N, typename T>
110  struct Types<N, T, false>
111  {
112  using value_type = T;
113  using TableType = TableBase<N, T>;
114 
115  using iterator = typename AlignedVector<T>::iterator;
116  using const_iterator = typename AlignedVector<T>::const_iterator;
117 
118  using reference = typename AlignedVector<T>::reference;
119  using const_reference = typename AlignedVector<T>::const_reference;
120  };
121 
122 
161  template <int N, typename T, bool C, unsigned int P>
162  class Accessor
163  {
164  public:
165  using TableType = typename Types<N, T, C>::TableType;
166 
167  using iterator = typename Types<N, T, C>::iterator;
168  using const_iterator = typename Types<N, T, C>::const_iterator;
169 
170  using size_type = size_t;
171  using difference_type = ptrdiff_t;
172 
173  private:
179  Accessor(const TableType &table, const iterator data);
180 
184  Accessor() = delete;
185 
186  public:
194  Accessor(const Accessor &a);
195 
199  Accessor<N, T, C, P - 1> operator[](const size_type i) const;
200 
206  size_type,
207  size_type,
208  size_type,
209  << "Index " << N - P + 1 << "has a value of " << arg1
210  << " but needs to be in the range [" << arg2 << "," << arg3
211  << "[.");
212 
213  private:
219  const TableType &table;
220  const iterator data;
221 
222  // declare some other classes
223  // as friends. make sure to
224  // work around bugs in some
225  // compilers
226  template <int N1, typename T1>
227  friend class ::Table;
228  template <int N1, typename T1, bool C1, unsigned int P1>
229  friend class Accessor;
230 #ifndef DEAL_II_TEMPL_SPEC_FRIEND_BUG
231  friend class ::Table<N, T>;
232  friend class Accessor<N, T, C, P + 1>;
233 #endif
234  };
235 
236 
237 
247  template <int N, typename T, bool C>
248  class Accessor<N, T, C, 1>
249  {
250  public:
256  using value_type = typename Types<N, T, C>::value_type;
257 
258  using iterator = typename Types<N, T, C>::iterator;
259  using const_iterator = typename Types<N, T, C>::const_iterator;
260 
261  using reference = typename Types<N, T, C>::reference;
262  using const_reference = typename Types<N, T, C>::const_reference;
263 
264  using size_type = size_t;
265  using difference_type = ptrdiff_t;
266 
270  using TableType = typename Types<N, T, C>::TableType;
271 
272  private:
284  Accessor(const TableType &table, const iterator data);
285 
289  Accessor() = delete;
290 
291  public:
299  Accessor(const Accessor &a);
300 
301 
305  reference operator[](const size_type) const;
306 
311  size_type
312  size() const;
313 
317  iterator
318  begin() const;
319 
323  iterator
324  end() const;
325 
326  private:
332  const TableType &table;
333  const iterator data;
334 
335  // declare some other classes
336  // as friends. make sure to
337  // work around bugs in some
338  // compilers
339  template <int N1, typename T1>
340  friend class ::Table;
341  template <int N1, typename T1, bool C1, unsigned int P1>
342  friend class Accessor;
343 #ifndef DEAL_II_TEMPL_SPEC_FRIEND_BUG
344  friend class ::Table<2, T>;
345  friend class Accessor<N, T, C, 2>;
346 #endif
347  };
348  } // namespace TableBaseAccessors
349 
350 } // namespace internal
351 
352 
353 
420 template <int N, typename T>
421 class TableBase : public Subscriptor
422 {
423 public:
424  using value_type = T;
425 
429  using size_type = typename AlignedVector<T>::size_type;
430 
431 
435  TableBase() = default;
436 
441  TableBase(const TableIndices<N> &sizes);
442 
448  template <typename InputIterator>
449  TableBase(const TableIndices<N> &sizes,
450  InputIterator entries,
451  const bool C_style_indexing = true);
452 
456  TableBase(const TableBase<N, T> &src);
457 
462  template <typename T2>
463  TableBase(const TableBase<N, T2> &src);
464 
468  TableBase(TableBase<N, T> &&src) noexcept;
469 
473  ~TableBase() override = default;
474 
483  TableBase<N, T> &
484  operator=(const TableBase<N, T> &src);
485 
493  template <typename T2>
494  TableBase<N, T> &
495  operator=(const TableBase<N, T2> &src);
496 
501  TableBase<N, T> &
502  operator=(TableBase<N, T> &&src) noexcept;
503 
507  bool
508  operator==(const TableBase<N, T> &T2) const;
509 
514  void
515  reset_values();
516 
525  void
526  reinit(const TableIndices<N> &new_size,
527  const bool omit_default_initialization = false);
528 
532  size_type
533  size(const unsigned int i) const;
534 
538  const TableIndices<N> &
539  size() const;
540 
545  size_type
546  n_elements() const;
547 
552  bool
553  empty() const;
554 
591  template <typename InputIterator>
592  void
593  fill(InputIterator entries, const bool C_style_indexing = true);
594 
598  void
599  fill(const T &value);
600 
604  typename AlignedVector<T>::reference
605  operator()(const TableIndices<N> &indices);
606 
614  typename AlignedVector<T>::const_reference
615  operator()(const TableIndices<N> &indices) const;
616 
629  void
630  swap(TableBase<N, T> &v);
631 
636  std::size_t
637  memory_consumption() const;
638 
643  template <class Archive>
644  void
645  serialize(Archive &ar, const unsigned int version);
646 
647 protected:
652  size_type
653  position(const TableIndices<N> &indices) const;
654 
661  typename AlignedVector<T>::reference
662  el(const TableIndices<N> &indices);
663 
674  typename AlignedVector<T>::const_reference
675  el(const TableIndices<N> &indices) const;
676 
677 protected:
681  AlignedVector<T> values;
682 
686  TableIndices<N> table_size;
687 
691  template <int, typename>
692  friend class TableBase;
693 };
694 
695 
709 template <int N, typename T>
710 class Table : public TableBase<N, T>
711 {};
712 
713 
726 template <typename T>
727 class Table<1, T> : public TableBase<1, T>
728 {
729 public:
734 
738  Table() = default;
739 
743  Table(const size_type size);
744 
782  template <typename InputIterator>
783  Table(const size_type size,
784  InputIterator entries,
785  const bool C_style_indexing = true);
786 
791  typename AlignedVector<T>::const_reference
792  operator[](const size_type i) const;
793 
798  typename AlignedVector<T>::reference operator[](const size_type i);
799 
804  typename AlignedVector<T>::const_reference
805  operator()(const size_type i) const;
806 
811  typename AlignedVector<T>::reference
812  operator()(const size_type i);
813 
818  typename AlignedVector<T>::reference
819  operator()(const TableIndices<1> &indices);
820 
825  typename AlignedVector<T>::const_reference
826  operator()(const TableIndices<1> &indices) const;
827 };
828 
829 
830 
844 template <typename T>
845 class Table<2, T> : public TableBase<2, T>
846 {
847 public:
852 
856  Table() = default;
857 
861  Table(const size_type size1, const size_type size2);
862 
901  template <typename InputIterator>
902  Table(const size_type size1,
903  const size_type size2,
904  InputIterator entries,
905  const bool C_style_indexing = true);
906 
912  void
913  reinit(const size_type size1,
914  const size_type size2,
915  const bool omit_default_initialization = false);
916 
918 
925  ::internal::TableBaseAccessors::Accessor<2, T, true, 1>
926  operator[](const size_type i) const;
927 
934  ::internal::TableBaseAccessors::Accessor<2, T, false, 1>
935  operator[](const size_type i);
936 
943  typename AlignedVector<T>::const_reference
944  operator()(const size_type i, const size_type j) const;
945 
946 
953  typename AlignedVector<T>::reference
954  operator()(const size_type i, const size_type j);
955 
960  typename AlignedVector<T>::reference
961  operator()(const TableIndices<2> &indices);
962 
967  typename AlignedVector<T>::const_reference
968  operator()(const TableIndices<2> &indices) const;
969 
970 
975  size_type
976  n_rows() const;
977 
982  size_type
983  n_cols() const;
984 
985 protected:
996  typename AlignedVector<T>::reference
997  el(const size_type i, const size_type j);
998 
1013  typename AlignedVector<T>::const_reference
1014  el(const size_type i, const size_type j) const;
1015 };
1016 
1017 
1018 
1029 template <typename T>
1030 class Table<3, T> : public TableBase<3, T>
1031 {
1032 public:
1037 
1041  Table() = default;
1042 
1046  Table(const size_type size1, const size_type size2, const size_type size3);
1047 
1088  template <typename InputIterator>
1089  Table(const size_type size1,
1090  const size_type size2,
1091  const size_type size3,
1092  InputIterator entries,
1093  const bool C_style_indexing = true);
1094 
1102  ::internal::TableBaseAccessors::Accessor<3, T, true, 2>
1103  operator[](const size_type i) const;
1104 
1112  ::internal::TableBaseAccessors::Accessor<3, T, false, 2>
1113  operator[](const size_type i);
1114 
1121  typename AlignedVector<T>::const_reference
1122  operator()(const size_type i, const size_type j, const size_type k) const;
1123 
1124 
1131  typename AlignedVector<T>::reference
1132  operator()(const size_type i, const size_type j, const size_type k);
1133 
1138  typename AlignedVector<T>::reference
1139  operator()(const TableIndices<3> &indices);
1140 
1145  typename AlignedVector<T>::const_reference
1146  operator()(const TableIndices<3> &indices) const;
1147 };
1148 
1149 
1150 
1161 template <typename T>
1162 class Table<4, T> : public TableBase<4, T>
1163 {
1164 public:
1169 
1173  Table() = default;
1174 
1178  Table(const size_type size1,
1179  const size_type size2,
1180  const size_type size3,
1181  const size_type size4);
1182 
1190  ::internal::TableBaseAccessors::Accessor<4, T, true, 3>
1191  operator[](const size_type i) const;
1192 
1200  ::internal::TableBaseAccessors::Accessor<4, T, false, 3>
1201  operator[](const size_type i);
1202 
1209  typename AlignedVector<T>::const_reference
1210  operator()(const size_type i,
1211  const size_type j,
1212  const size_type k,
1213  const size_type l) const;
1214 
1215 
1222  typename AlignedVector<T>::reference
1223  operator()(const size_type i,
1224  const size_type j,
1225  const size_type k,
1226  const size_type l);
1227 
1232  typename AlignedVector<T>::reference
1233  operator()(const TableIndices<4> &indices);
1234 
1239  typename AlignedVector<T>::const_reference
1240  operator()(const TableIndices<4> &indices) const;
1241 };
1242 
1243 
1244 
1255 template <typename T>
1256 class Table<5, T> : public TableBase<5, T>
1257 {
1258 public:
1263 
1264 
1268  Table() = default;
1269 
1273  Table(const size_type size1,
1274  const size_type size2,
1275  const size_type size3,
1276  const size_type size4,
1277  const size_type size5);
1278 
1286  ::internal::TableBaseAccessors::Accessor<5, T, true, 4>
1287  operator[](const size_type i) const;
1288 
1296  ::internal::TableBaseAccessors::Accessor<5, T, false, 4>
1297  operator[](const size_type i);
1298 
1305  typename AlignedVector<T>::const_reference
1306  operator()(const size_type i,
1307  const size_type j,
1308  const size_type k,
1309  const size_type l,
1310  const size_type m) const;
1311 
1318  typename AlignedVector<T>::reference
1319  operator()(const size_type i,
1320  const size_type j,
1321  const size_type k,
1322  const size_type l,
1323  const size_type m);
1324 
1329  typename AlignedVector<T>::reference
1330  operator()(const TableIndices<5> &indices);
1331 
1336  typename AlignedVector<T>::const_reference
1337  operator()(const TableIndices<5> &indices) const;
1338 };
1339 
1340 
1341 
1352 template <typename T>
1353 class Table<6, T> : public TableBase<6, T>
1354 {
1355 public:
1360 
1364  Table() = default;
1365 
1369  Table(const size_type size1,
1370  const size_type size2,
1371  const size_type size3,
1372  const size_type size4,
1373  const size_type size5,
1374  const size_type size6);
1375 
1383  ::internal::TableBaseAccessors::Accessor<6, T, true, 5>
1384  operator[](const size_type i) const;
1385 
1393  ::internal::TableBaseAccessors::Accessor<6, T, false, 5>
1394  operator[](const size_type i);
1395 
1402  typename AlignedVector<T>::const_reference
1403  operator()(const size_type i,
1404  const size_type j,
1405  const size_type k,
1406  const size_type l,
1407  const size_type m,
1408  const size_type n) const;
1409 
1416  typename AlignedVector<T>::reference
1417  operator()(const size_type i,
1418  const size_type j,
1419  const size_type k,
1420  const size_type l,
1421  const size_type m,
1422  const size_type n);
1423 
1428  typename AlignedVector<T>::reference
1429  operator()(const TableIndices<6> &indices);
1430 
1435  typename AlignedVector<T>::const_reference
1436  operator()(const TableIndices<6> &indices) const;
1437 };
1438 
1439 
1450 template <typename T>
1451 class Table<7, T> : public TableBase<7, T>
1452 {
1453 public:
1458 
1462  Table() = default;
1463 
1467  Table(const size_type size1,
1468  const size_type size2,
1469  const size_type size3,
1470  const size_type size4,
1471  const size_type size5,
1472  const size_type size6,
1473  const size_type size7);
1474 
1482  ::internal::TableBaseAccessors::Accessor<7, T, true, 6>
1483  operator[](const size_type i) const;
1484 
1492  ::internal::TableBaseAccessors::Accessor<7, T, false, 6>
1493  operator[](const size_type i);
1494 
1501  typename AlignedVector<T>::const_reference
1502  operator()(const size_type i,
1503  const size_type j,
1504  const size_type k,
1505  const size_type l,
1506  const size_type m,
1507  const size_type n,
1508  const size_type o) const;
1509 
1516  typename AlignedVector<T>::reference
1517  operator()(const size_type i,
1518  const size_type j,
1519  const size_type k,
1520  const size_type l,
1521  const size_type m,
1522  const size_type n,
1523  const size_type o);
1524 
1529  typename AlignedVector<T>::reference
1530  operator()(const TableIndices<7> &indices);
1531 
1536  typename AlignedVector<T>::const_reference
1537  operator()(const TableIndices<7> &indices) const;
1538 };
1539 
1540 
1541 
1547 {
1548  // Forward declaration of the iterator class.
1549  template <typename T, bool Constness>
1550  class Iterator;
1551 
1556  template <typename T, bool Constness>
1557  class Accessor;
1558 
1563  template <typename T, bool Constness>
1565  {
1566  public:
1570  using container_pointer_type =
1571  typename std::conditional<Constness,
1572  const TransposeTable<T> *,
1573  TransposeTable<T> *>::type;
1574 
1578  AccessorBase();
1579 
1583  AccessorBase(const container_pointer_type table);
1584 
1589 
1595  const std::ptrdiff_t linear_index);
1596 
1601  const T &
1602  value() const;
1603 
1608 
1612  size_type
1613  row() const;
1614 
1618  size_type
1619  column() const;
1620 
1621  protected:
1626 
1630  std::ptrdiff_t linear_index;
1631 
1635  friend class AccessorBase<T, true>;
1636 
1640  friend class LinearIndexIterator<Iterator<T, Constness>,
1641  Accessor<T, Constness>>;
1642  };
1643 
1647  template <typename T>
1648  class Accessor<T, true> : public AccessorBase<T, true>
1649  {
1650  public:
1655  };
1656 
1661  template <typename T>
1662  class Accessor<T, false> : public AccessorBase<T, false>
1663  {
1664  public:
1669 
1674  const Accessor<T, false> &
1675  operator=(const T &) const;
1676 
1681  const Accessor<T, false> &
1682  operator=(T &&) const;
1683 
1689 
1694  T &
1695  value() const;
1696  };
1697 
1701  template <typename T, bool Constness>
1702  class Iterator
1703  : public LinearIndexIterator<Iterator<T, Constness>, Accessor<T, Constness>>
1704  {
1705  public:
1710 
1714  using container_pointer_type =
1715  typename std::conditional<Constness,
1716  const TransposeTable<T> *,
1717  TransposeTable<T> *>::type;
1718 
1722  Iterator(const Accessor<T, Constness> &accessor);
1723 
1727  Iterator(const container_pointer_type object);
1728 
1732  Iterator(const container_pointer_type object,
1733  const size_type row,
1734  const size_type column);
1735 
1739  Iterator(const Iterator<T, false> &i);
1740 
1744  Iterator(const container_pointer_type container,
1745  const std::ptrdiff_t linear_index);
1746  };
1747 } // namespace TransposeTableIterators
1748 
1749 
1763 template <typename T>
1764 class TransposeTable : public TableBase<2, T>
1765 {
1766 public:
1771 
1775  using value_type = typename AlignedVector<T>::value_type;
1776 
1780  using reference = typename AlignedVector<T>::reference;
1781 
1785  using const_reference = typename AlignedVector<T>::const_reference;
1786 
1792 
1797 
1801  TransposeTable() = default;
1802 
1806  TransposeTable(const size_type size1, const size_type size2);
1807 
1813  void
1814  reinit(const size_type size1,
1815  const size_type size2,
1816  const bool omit_default_initialization = false);
1817 
1825  operator()(const size_type i, const size_type j) const;
1826 
1833  reference
1834  operator()(const size_type i, const size_type j);
1835 
1840  size_type
1841  n_rows() const;
1842 
1847  size_type
1848  n_cols() const;
1849 
1853  iterator
1854  begin();
1855 
1860  begin() const;
1861 
1865  iterator
1866  end();
1867 
1872  end() const;
1873 
1874 protected:
1885  reference
1886  el(const size_type i, const size_type j);
1887 
1903  el(const size_type i, const size_type j) const;
1904 
1910  friend class TransposeTableIterators::AccessorBase<T, false>;
1911 
1916  friend class TransposeTableIterators::Accessor<T, false>;
1917 };
1918 
1919 
1920 
1921 /* --------------------- Template and inline functions ---------------- */
1922 
1923 #ifndef DOXYGEN
1924 
1925 template <int N, typename T>
1927 {
1928  reinit(sizes);
1929 }
1930 
1931 
1932 
1933 template <int N, typename T>
1934 template <typename InputIterator>
1936  InputIterator entries,
1937  const bool C_style_indexing)
1938 {
1939  reinit(sizes);
1940  fill(entries, C_style_indexing);
1941 }
1942 
1943 
1944 
1945 template <int N, typename T>
1947  : Subscriptor()
1948 {
1949  reinit(src.table_size, true);
1950  values = src.values;
1951 }
1952 
1953 
1954 
1955 template <int N, typename T>
1956 template <typename T2>
1958 {
1959  reinit(src.table_size);
1960  if (src.n_elements() != 0)
1961  std::copy(src.values.begin(), src.values.end(), values.begin());
1962 }
1963 
1964 
1965 
1966 template <int N, typename T>
1968  : Subscriptor(std::move(src))
1969  , values(std::move(src.values))
1970  , table_size(src.table_size)
1971 {
1972  src.table_size = TableIndices<N>();
1973 }
1974 
1975 
1976 
1977 template <int N, typename T>
1978 template <class Archive>
1979 inline void
1980 TableBase<N, T>::serialize(Archive &ar, const unsigned int)
1981 {
1982  ar &static_cast<Subscriptor &>(*this);
1983 
1984  ar &values &table_size;
1985 }
1986 
1987 
1988 
1989 namespace internal
1990 {
1991  namespace TableBaseAccessors
1992  {
1993  template <int N, typename T, bool C, unsigned int P>
1994  inline Accessor<N, T, C, P>::Accessor(const TableType &table,
1995  const iterator data)
1996  : table(table)
1997  , data(data)
1998  {}
1999 
2000 
2001 
2002  template <int N, typename T, bool C, unsigned int P>
2003  inline Accessor<N, T, C, P>::Accessor(const Accessor &a)
2004  : table(a.table)
2005  , data(a.data)
2006  {}
2007 
2008 
2009 
2010  template <int N, typename T, bool C, unsigned int P>
2011  inline Accessor<N, T, C, P - 1> Accessor<N, T, C, P>::
2012  operator[](const size_type i) const
2013  {
2014  Assert(i < table.size()[N - P], ExcIndexRange(i, 0, table.size()[N - P]));
2015 
2016  // access i-th
2017  // subobject. optimize on the
2018  // case i==0
2019  if (i == 0)
2020  return Accessor<N, T, C, P - 1>(table, data);
2021  else
2022  {
2023  // note: P>1, otherwise the
2024  // specialization would have
2025  // been taken!
2026  size_type subobject_size = table.size()[N - 1];
2027  for (int p = P - 1; p > 1; --p)
2028  subobject_size *= table.size()[N - p];
2029  const iterator new_data = data + i * subobject_size;
2030  return Accessor<N, T, C, P - 1>(table, new_data);
2031  }
2032  }
2033 
2034 
2035 
2036  template <int N, typename T, bool C>
2037  inline Accessor<N, T, C, 1>::Accessor(const TableType &table,
2038  const iterator data)
2039  : table(table)
2040  , data(data)
2041  {}
2042 
2043 
2044 
2045  template <int N, typename T, bool C>
2046  inline Accessor<N, T, C, 1>::Accessor(const Accessor &a)
2047  : table(a.table)
2048  , data(a.data)
2049  {}
2050 
2051 
2052 
2053  template <int N, typename T, bool C>
2054  inline typename Accessor<N, T, C, 1>::reference Accessor<N, T, C, 1>::
2055  operator[](const size_type i) const
2056  {
2057  AssertIndexRange(i, table.size()[N - 1]);
2058  return *(data + i);
2059  }
2060 
2061 
2062 
2063  template <int N, typename T, bool C>
2064  inline typename Accessor<N, T, C, 1>::size_type
2065  Accessor<N, T, C, 1>::size() const
2066  {
2067  return table.size()[N - 1];
2068  }
2069 
2070 
2071 
2072  template <int N, typename T, bool C>
2073  inline typename Accessor<N, T, C, 1>::iterator
2074  Accessor<N, T, C, 1>::begin() const
2075  {
2076  return data;
2077  }
2078 
2079 
2080 
2081  template <int N, typename T, bool C>
2082  inline typename Accessor<N, T, C, 1>::iterator
2083  Accessor<N, T, C, 1>::end() const
2084  {
2085  return data + table.size()[N - 1];
2086  }
2087  } // namespace TableBaseAccessors
2088 } // namespace internal
2089 
2090 
2091 
2092 template <int N, typename T>
2093 inline TableBase<N, T> &
2095 {
2096  if (!m.empty())
2097  values = m.values;
2098  reinit(m.size(), true);
2099 
2100  return *this;
2101 }
2102 
2103 
2104 
2105 template <int N, typename T>
2106 template <typename T2>
2107 inline TableBase<N, T> &
2109 {
2110  reinit(m.size(), true);
2111  if (!empty())
2112  std::copy(m.values.begin(),
2113  m.values.begin() + n_elements(),
2114  values.begin());
2115 
2116  return *this;
2117 }
2118 
2119 
2120 
2121 template <int N, typename T>
2122 inline TableBase<N, T> &
2124 {
2125  static_cast<Subscriptor &>(*this) = std::move(m);
2126  values = std::move(m.values);
2127  table_size = m.table_size;
2129 
2130  return *this;
2131 }
2132 
2133 
2134 
2135 template <int N, typename T>
2136 inline bool
2138 {
2139  return (values == T2.values);
2140 }
2141 
2142 
2143 
2144 template <int N, typename T>
2145 inline void
2147 {
2148  // use parallel set operation
2149  if (n_elements() != 0)
2150  values.fill(T());
2151 }
2152 
2153 
2154 
2155 template <int N, typename T>
2156 inline void
2157 TableBase<N, T>::fill(const T &value)
2158 {
2159  if (n_elements() != 0)
2160  values.fill(value);
2161 }
2162 
2163 
2164 
2165 template <int N, typename T>
2166 inline void
2167 TableBase<N, T>::reinit(const TableIndices<N> &new_sizes,
2168  const bool omit_default_initialization)
2169 {
2170  table_size = new_sizes;
2171 
2172  const size_type new_size = n_elements();
2173 
2174  // if zero size was given: free all memory
2175  if (new_size == 0)
2176  {
2177  values.resize(0);
2178  // set all sizes to zero, even
2179  // if one was previously
2180  // nonzero. This simplifies
2181  // some assertions.
2183 
2184  return;
2185  }
2186 
2187  // adjust values field. If it was empty before, we can simply call resize(),
2188  // which can set all the data fields. Otherwise, select the fast resize and
2189  // manually fill in all the elements as required by the design of this
2190  // class. (Selecting another code for the empty case ensures that we touch
2191  // the memory only once for non-trivial classes that need to initialize the
2192  // memory also in resize_fast.)
2193  if (!omit_default_initialization)
2194  {
2195  if (values.empty())
2196  values.resize(new_size);
2197  else
2198  {
2199  values.resize_fast(new_size);
2200  values.fill();
2201  }
2202  }
2203  else
2204  values.resize_fast(new_size);
2205 }
2206 
2207 
2208 
2209 template <int N, typename T>
2210 inline const TableIndices<N> &
2211 TableBase<N, T>::size() const
2212 {
2213  return table_size;
2214 }
2215 
2216 
2217 
2218 template <int N, typename T>
2219 inline typename TableBase<N, T>::size_type
2220 TableBase<N, T>::size(const unsigned int i) const
2221 {
2222  Assert(i < N, ExcIndexRange(i, 0, N));
2223  return table_size[i];
2224 }
2225 
2226 
2227 
2228 template <int N, typename T>
2229 inline typename TableBase<N, T>::size_type
2231 {
2232  size_type s = 1;
2233  for (unsigned int n = 0; n < N; ++n)
2234  s *= table_size[n];
2235  return s;
2236 }
2237 
2238 
2239 
2240 template <int N, typename T>
2241 inline bool
2242 TableBase<N, T>::empty() const
2243 {
2244  return (n_elements() == 0);
2245 }
2246 
2247 
2248 
2249 namespace internal
2250 {
2251  namespace TableImplementation
2252  {
2253  template <typename InputIterator, typename T>
2254  void
2255  fill_Fortran_style(InputIterator entries, TableBase<1, T> &table)
2256  {
2257  using size_type = typename TableBase<1, T>::size_type;
2258  for (size_type i = 0; i < table.size()[0]; ++i)
2259  table(TableIndices<1>(i)) = *entries++;
2260  }
2261 
2262 
2263  template <typename InputIterator, typename T>
2264  void
2265  fill_Fortran_style(InputIterator entries, TableBase<2, T> &table)
2266  {
2267  using size_type = typename TableBase<2, T>::size_type;
2268  for (size_type j = 0; j < table.size()[1]; ++j)
2269  for (size_type i = 0; i < table.size()[0]; ++i)
2270  table(TableIndices<2>(i, j)) = *entries++;
2271  }
2272 
2273 
2274  template <typename InputIterator, typename T>
2275  void
2276  fill_Fortran_style(InputIterator entries, TableBase<3, T> &table)
2277  {
2278  using size_type = typename TableBase<3, T>::size_type;
2279  for (size_type k = 0; k < table.size()[2]; ++k)
2280  for (size_type j = 0; j < table.size()[1]; ++j)
2281  for (size_type i = 0; i < table.size()[0]; ++i)
2282  table(TableIndices<3>(i, j, k)) = *entries++;
2283  }
2284 
2285 
2286  template <typename InputIterator, typename T, int N>
2287  void
2288  fill_Fortran_style(InputIterator, TableBase<N, T> &)
2289  {
2290  Assert(false, ExcNotImplemented());
2291  }
2292  } // namespace TableImplementation
2293 } // namespace internal
2294 
2295 
2296 template <int N, typename T>
2297 template <typename InputIterator>
2298 inline void
2299 TableBase<N, T>::fill(InputIterator entries, const bool C_style_indexing)
2300 {
2301  Assert(n_elements() != 0, ExcMessage("Trying to fill an empty matrix."));
2302 
2303  if (C_style_indexing)
2304  for (typename AlignedVector<T>::iterator p = values.begin();
2305  p != values.end();
2306  ++p)
2307  *p = *entries++;
2308  else
2309  internal::TableImplementation::fill_Fortran_style(entries, *this);
2310 }
2311 
2312 
2313 
2314 template <int N, typename T>
2315 inline void
2317 {
2318  values.swap(v.values);
2320 }
2321 
2322 
2323 
2324 template <int N, typename T>
2325 inline std::size_t
2327 {
2328  return sizeof(*this) + MemoryConsumption::memory_consumption(values);
2329 }
2330 
2331 
2332 
2333 template <int N, typename T>
2334 inline typename TableBase<N, T>::size_type
2335 TableBase<N, T>::position(const TableIndices<N> &indices) const
2336 {
2337  // specialize this for the
2338  // different numbers of dimensions,
2339  // to make the job somewhat easier
2340  // for the compiler. have the
2341  // general formula nevertheless:
2342  switch (N)
2343  {
2344  case 1:
2345  return indices[0];
2346  case 2:
2347  return size_type(indices[0]) * table_size[1] + indices[1];
2348  case 3:
2349  return ((size_type(indices[0]) * table_size[1] + indices[1]) *
2350  table_size[2] +
2351  indices[2]);
2352  default:
2353  {
2354  unsigned int s = indices[0];
2355  for (unsigned int n = 1; n < N; ++n)
2356  s = s * table_size[n] + indices[n];
2357  return s;
2358  }
2359  }
2360 }
2361 
2362 
2363 
2364 template <int N, typename T>
2365 inline typename AlignedVector<T>::const_reference
2366 TableBase<N, T>::operator()(const TableIndices<N> &indices) const
2367 {
2368  for (unsigned int n = 0; n < N; ++n)
2369  AssertIndexRange(indices[n], table_size[n]);
2370  return el(indices);
2371 }
2372 
2373 
2374 
2375 template <int N, typename T>
2376 inline typename AlignedVector<T>::reference
2378 {
2379  for (unsigned int n = 0; n < N; ++n)
2380  AssertIndexRange(indices[n], table_size[n]);
2381  return el(indices);
2382 }
2383 
2384 
2385 
2386 template <int N, typename T>
2387 inline typename AlignedVector<T>::const_reference
2388 TableBase<N, T>::el(const TableIndices<N> &indices) const
2389 {
2390  return values[position(indices)];
2391 }
2392 
2393 
2394 
2395 template <int N, typename T>
2396 inline typename AlignedVector<T>::reference
2397 TableBase<N, T>::el(const TableIndices<N> &indices)
2398 {
2399  AssertIndexRange(position(indices), values.size());
2400  return values[position(indices)];
2401 }
2402 
2403 
2404 
2405 template <typename T>
2406 inline Table<1, T>::Table(const size_type size)
2407  : TableBase<1, T>(TableIndices<1>(size))
2408 {}
2409 
2410 
2411 
2412 template <typename T>
2413 template <typename InputIterator>
2414 inline Table<1, T>::Table(const size_type size,
2415  InputIterator entries,
2416  const bool C_style_indexing)
2417  : TableBase<1, T>(TableIndices<1>(size), entries, C_style_indexing)
2418 {}
2419 
2420 
2421 
2422 template <typename T>
2423 inline typename AlignedVector<T>::const_reference Table<1, T>::
2424  operator[](const size_type i) const
2425 {
2426  AssertIndexRange(i, this->table_size[0]);
2427  return this->values[i];
2428 }
2429 
2430 
2431 
2432 template <typename T>
2433 inline typename AlignedVector<T>::reference Table<1, T>::
2434  operator[](const size_type i)
2435 {
2436  AssertIndexRange(i, this->table_size[0]);
2437  return this->values[i];
2438 }
2439 
2440 
2441 
2442 template <typename T>
2443 inline typename AlignedVector<T>::const_reference
2444 Table<1, T>::operator()(const size_type i) const
2445 {
2446  AssertIndexRange(i, this->table_size[0]);
2447  return this->values[i];
2448 }
2449 
2450 
2451 
2452 template <typename T>
2453 inline typename AlignedVector<T>::reference
2455 {
2456  AssertIndexRange(i, this->table_size[0]);
2457  return this->values[i];
2458 }
2459 
2460 
2461 
2462 template <typename T>
2463 inline typename AlignedVector<T>::const_reference
2464 Table<1, T>::operator()(const TableIndices<1> &indices) const
2465 {
2466  return TableBase<1, T>::operator()(indices);
2467 }
2468 
2469 
2470 
2471 template <typename T>
2472 inline typename AlignedVector<T>::reference
2474 {
2475  return TableBase<1, T>::operator()(indices);
2476 }
2477 
2478 
2479 //---------------------------------------------------------------------------
2480 
2481 
2482 
2483 template <typename T>
2484 inline Table<2, T>::Table(const size_type size1, const size_type size2)
2485  : TableBase<2, T>(TableIndices<2>(size1, size2))
2486 {}
2487 
2488 
2489 
2490 template <typename T>
2491 template <typename InputIterator>
2492 inline Table<2, T>::Table(const size_type size1,
2493  const size_type size2,
2494  InputIterator entries,
2495  const bool C_style_indexing)
2496  : TableBase<2, T>(TableIndices<2>(size1, size2), entries, C_style_indexing)
2497 {}
2498 
2499 
2500 
2501 template <typename T>
2502 inline void
2503 Table<2, T>::reinit(const size_type size1,
2504  const size_type size2,
2505  const bool omit_default_initialization)
2506 {
2507  this->TableBase<2, T>::reinit(TableIndices<2>(size1, size2),
2508  omit_default_initialization);
2509 }
2510 
2511 
2512 
2513 template <typename T>
2514 inline ::internal::TableBaseAccessors::Accessor<2, T, true, 1>
2515  Table<2, T>::operator[](const size_type i) const
2516 {
2517  AssertIndexRange(i, this->table_size[0]);
2518  return ::internal::TableBaseAccessors::Accessor<2, T, true, 1>(
2519  *this, this->values.begin() + size_type(i) * n_cols());
2520 }
2521 
2522 
2523 
2524 template <typename T>
2525 inline ::internal::TableBaseAccessors::Accessor<2, T, false, 1>
2527 {
2528  AssertIndexRange(i, this->table_size[0]);
2529  return ::internal::TableBaseAccessors::Accessor<2, T, false, 1>(
2530  *this, this->values.begin() + size_type(i) * n_cols());
2531 }
2532 
2533 
2534 
2535 template <typename T>
2536 inline typename AlignedVector<T>::const_reference
2537 Table<2, T>::operator()(const size_type i, const size_type j) const
2538 {
2539  AssertIndexRange(i, this->table_size[0]);
2540  AssertIndexRange(j, this->table_size[1]);
2541  return this->values[size_type(i) * this->table_size[1] + j];
2542 }
2543 
2544 
2545 
2546 template <typename T>
2547 inline typename AlignedVector<T>::reference
2549 {
2550  AssertIndexRange(i, this->table_size[0]);
2551  AssertIndexRange(j, this->table_size[1]);
2552  return this->values[size_type(i) * this->table_size[1] + j];
2553 }
2554 
2555 
2556 
2557 template <typename T>
2558 inline typename AlignedVector<T>::const_reference
2559 Table<2, T>::operator()(const TableIndices<2> &indices) const
2560 {
2561  return TableBase<2, T>::operator()(indices);
2562 }
2563 
2564 
2565 
2566 template <typename T>
2567 inline typename AlignedVector<T>::reference
2569 {
2570  return TableBase<2, T>::operator()(indices);
2571 }
2572 
2573 
2574 
2575 template <typename T>
2576 inline typename AlignedVector<T>::const_reference
2577 Table<2, T>::el(const size_type i, const size_type j) const
2578 {
2579  return this->values[size_type(i) * this->table_size[1] + j];
2580 }
2581 
2582 
2583 
2584 template <typename T>
2585 inline typename AlignedVector<T>::reference
2586 Table<2, T>::el(const size_type i, const size_type j)
2587 {
2588  return this->values[size_type(i) * this->table_size[1] + j];
2589 }
2590 
2591 
2592 
2593 template <typename T>
2594 inline typename Table<2, T>::size_type
2595 Table<2, T>::n_rows() const
2596 {
2597  return this->table_size[0];
2598 }
2599 
2600 
2601 
2602 template <typename T>
2603 inline typename Table<2, T>::size_type
2604 Table<2, T>::n_cols() const
2605 {
2606  return this->table_size[1];
2607 }
2608 
2609 
2610 
2611 //---------------------------------------------------------------------------
2612 namespace TransposeTableIterators
2613 {
2614  template <typename T, bool Constness>
2615  inline AccessorBase<T, Constness>::AccessorBase()
2616  : container(nullptr)
2617  , linear_index(std::numeric_limits<decltype(linear_index)>::max())
2618  {}
2619 
2620 
2621 
2622  template <typename T, bool Constness>
2623  inline AccessorBase<T, Constness>::AccessorBase(
2624  const container_pointer_type table)
2625  : container(table)
2626  , linear_index(container->values.size())
2627  {}
2628 
2629 
2630 
2631  template <typename T, bool Constness>
2632  inline AccessorBase<T, Constness>::AccessorBase(
2633  const AccessorBase<T, false> &a)
2634  : container(a.container)
2635  , linear_index(a.linear_index)
2636  {}
2637 
2638 
2639 
2640  template <typename T, bool Constness>
2641  inline AccessorBase<T, Constness>::AccessorBase(
2642  const container_pointer_type table,
2643  const std::ptrdiff_t index)
2644  : container(table)
2645  , linear_index(index)
2646  {
2647  Assert(0 <= linear_index && linear_index < container->values.size() + 1,
2648  ExcMessage("The current iterator points outside of the table and is "
2649  "not the end iterator."));
2650  }
2651 
2652 
2653 
2654  template <typename T, bool Constness>
2655  inline const T &
2656  AccessorBase<T, Constness>::value() const
2657  {
2658  Assert(0 <= linear_index && linear_index < container->values.size(),
2659  ExcMessage("The current iterator points outside of the table."));
2660  return this->container->values[linear_index];
2661  }
2662 
2663 
2664 
2665  template <typename T, bool Constness>
2666  inline typename AccessorBase<T, Constness>::size_type
2667  AccessorBase<T, Constness>::AccessorBase::row() const
2668  {
2669  Assert(!container->empty(),
2670  ExcMessage("An empty table has no rows or columns."));
2671  const auto row_n = linear_index % container->n_rows();
2672  Assert(0 <= row_n && row_n < container->n_rows(),
2673  ExcMessage("The current iterator points outside the table."));
2674  return row_n;
2675  }
2676 
2677 
2678 
2679  template <typename T, bool Constness>
2680  inline typename AccessorBase<T, Constness>::size_type
2681  AccessorBase<T, Constness>::AccessorBase::column() const
2682  {
2683  Assert(!container->empty(),
2684  ExcMessage("An empty table has no rows or columns."));
2685  const auto column_n = linear_index / container->n_rows();
2686  Assert(0 <= column_n && column_n < container->n_cols(),
2687  ExcMessage("The current iterator points outside the table."));
2688  return column_n;
2689  }
2690 
2691 
2692  template <typename T>
2693  inline const Accessor<T, false> &
2694  Accessor<T, false>::operator=(const T &t) const
2695  {
2696  Assert(0 <= this->linear_index &&
2697  this->linear_index < this->container->values.size(),
2698  ExcMessage("The current iterator points outside of the table."));
2699  this->container->values[this->linear_index] = t;
2700  return *this;
2701  }
2702 
2703 
2704 
2705  template <typename T>
2706  inline const Accessor<T, false> &
2707  Accessor<T, false>::operator=(T &&t) const
2708  {
2709  Assert(0 <= this->linear_index &&
2710  this->linear_index < this->container->values.size(),
2711  ExcMessage("The current iterator points outside of the table."));
2712  this->container->values[this->linear_index] = t;
2713  return *this;
2714  }
2715 
2716 
2717 
2718  template <typename T>
2719  inline T &
2720  Accessor<T, false>::value() const
2721  {
2722  Assert(0 <= this->linear_index &&
2723  this->linear_index < this->container->values.size(),
2724  ExcMessage("The current iterator points outside of the table."));
2725  return this->container->values[this->linear_index];
2726  }
2727 
2728 
2729 
2730  template <typename T, bool Constness>
2731  Iterator<T, Constness>::Iterator(const Accessor<T, Constness> &a)
2732  : LinearIndexIterator<Iterator<T, Constness>, Accessor<T, Constness>>(a)
2733  {}
2734 
2735 
2736 
2737  template <typename T, bool Constness>
2738  Iterator<T, Constness>::Iterator(const container_pointer_type table)
2739  : LinearIndexIterator<Iterator<T, Constness>, Accessor<T, Constness>>(
2740  Accessor<T, Constness>(table))
2741  {}
2742 
2743 
2744 
2745  template <typename T, bool Constness>
2746  Iterator<T, Constness>::Iterator(const Iterator<T, false> &i)
2747  : LinearIndexIterator<Iterator<T, Constness>, Accessor<T, Constness>>(*i)
2748  {}
2749 
2750 
2751 
2752  template <typename T, bool Constness>
2753  Iterator<T, Constness>::Iterator(const container_pointer_type table,
2754  const size_type row_n,
2755  const size_type col_n)
2756  : Iterator(table, table->n_rows() * col_n + row_n)
2757  {}
2758 
2759 
2760 
2761  template <typename T, bool Constness>
2762  Iterator<T, Constness>::Iterator(const container_pointer_type table,
2763  const std::ptrdiff_t linear_index)
2764  : LinearIndexIterator<Iterator<T, Constness>, Accessor<T, Constness>>(
2765  Accessor<T, Constness>(table, linear_index))
2766  {}
2767 } // namespace TransposeTableIterators
2768 
2769 
2770 
2771 //---------------------------------------------------------------------------
2772 template <typename T>
2773 inline TransposeTable<T>::TransposeTable(const size_type size1,
2774  const size_type size2)
2775  : TableBase<2, T>(TableIndices<2>(size2, size1))
2776 {}
2777 
2778 
2779 
2780 template <typename T>
2781 inline void
2783  const size_type size2,
2784  const bool omit_default_initialization)
2785 {
2786  this->TableBase<2, T>::reinit(TableIndices<2>(size2, size1),
2787  omit_default_initialization);
2788 }
2789 
2790 
2791 
2792 template <typename T>
2793 inline typename TransposeTable<T>::const_reference
2794 TransposeTable<T>::operator()(const size_type i, const size_type j) const
2795 {
2796  AssertIndexRange(i, this->table_size[1]);
2797  AssertIndexRange(j, this->table_size[0]);
2798  return this->values[size_type(j) * this->table_size[1] + i];
2799 }
2800 
2801 
2802 
2803 template <typename T>
2804 inline typename TransposeTable<T>::reference
2806 {
2807  AssertIndexRange(i, this->table_size[1]);
2808  AssertIndexRange(j, this->table_size[0]);
2809  return this->values[size_type(j) * this->table_size[1] + i];
2810 }
2811 
2812 
2813 
2814 template <typename T>
2815 inline typename TransposeTable<T>::const_reference
2816 TransposeTable<T>::el(const size_type i, const size_type j) const
2817 {
2818  return this->values[size_type(j) * this->table_size[1] + i];
2819 }
2820 
2821 
2822 
2823 template <typename T>
2824 inline typename TransposeTable<T>::reference
2825 TransposeTable<T>::el(const size_type i, const size_type j)
2826 {
2827  return this->values[size_type(j) * this->table_size[1] + i];
2828 }
2829 
2830 
2831 
2832 template <typename T>
2833 inline typename TransposeTable<T>::size_type
2835 {
2836  return this->table_size[1];
2837 }
2838 
2839 
2840 
2841 template <typename T>
2842 inline typename TransposeTable<T>::size_type
2844 {
2845  return this->table_size[0];
2846 }
2847 
2848 
2849 
2850 template <typename T>
2851 inline typename TransposeTable<T>::iterator
2853 {
2854  return typename TransposeTable<T>::iterator(this, 0, 0);
2855 }
2856 
2857 
2858 
2859 template <typename T>
2860 inline typename TransposeTable<T>::const_iterator
2862 {
2863  return typename TransposeTable<T>::const_iterator(this, 0, 0);
2864 }
2865 
2866 
2867 
2868 template <typename T>
2869 inline typename TransposeTable<T>::iterator
2871 {
2872  return typename TransposeTable<T>::iterator(this);
2873 }
2874 
2875 
2876 
2877 template <typename T>
2878 inline typename TransposeTable<T>::const_iterator
2879 TransposeTable<T>::end() const
2880 {
2881  return typename TransposeTable<T>::const_iterator(this);
2882 }
2883 //---------------------------------------------------------------------------
2884 
2885 
2886 
2887 template <typename T>
2888 inline Table<3, T>::Table(const size_type size1,
2889  const size_type size2,
2890  const size_type size3)
2891  : TableBase<3, T>(TableIndices<3>(size1, size2, size3))
2892 {}
2893 
2894 
2895 
2896 template <typename T>
2897 template <typename InputIterator>
2898 inline Table<3, T>::Table(const size_type size1,
2899  const size_type size2,
2900  const size_type size3,
2901  InputIterator entries,
2902  const bool C_style_indexing)
2903  : TableBase<3, T>(TableIndices<3>(size1, size2, size3),
2904  entries,
2905  C_style_indexing)
2906 {}
2907 
2908 
2909 
2910 template <typename T>
2911 inline ::internal::TableBaseAccessors::Accessor<3, T, true, 2>
2912  Table<3, T>::operator[](const size_type i) const
2913 {
2914  AssertIndexRange(i, this->table_size[0]);
2915  const size_type subobject_size =
2916  size_type(this->table_size[1]) * this->table_size[2];
2917  return (::internal::TableBaseAccessors::Accessor<3, T, true, 2>(
2918  *this, this->values.begin() + i * subobject_size));
2919 }
2920 
2921 
2922 
2923 template <typename T>
2924 inline ::internal::TableBaseAccessors::Accessor<3, T, false, 2>
2926 {
2927  AssertIndexRange(i, this->table_size[0]);
2928  const size_type subobject_size =
2929  size_type(this->table_size[1]) * this->table_size[2];
2930  return (::internal::TableBaseAccessors::Accessor<3, T, false, 2>(
2931  *this, this->values.begin() + i * subobject_size));
2932 }
2933 
2934 
2935 
2936 template <typename T>
2937 inline typename AlignedVector<T>::const_reference
2939 operator()(const size_type i, const size_type j, const size_type k) const
2940 {
2941  AssertIndexRange(i, this->table_size[0]);
2942  AssertIndexRange(j, this->table_size[1]);
2943  AssertIndexRange(k, this->table_size[2]);
2944  return this
2945  ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
2946  k];
2947 }
2948 
2949 
2950 
2951 template <typename T>
2952 inline typename AlignedVector<T>::reference
2953 Table<3, T>::operator()(const size_type i, const size_type j, const size_type k)
2954 {
2955  AssertIndexRange(i, this->table_size[0]);
2956  AssertIndexRange(j, this->table_size[1]);
2957  AssertIndexRange(k, this->table_size[2]);
2958  return this
2959  ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
2960  k];
2961 }
2962 
2963 
2964 
2965 template <typename T>
2966 inline typename AlignedVector<T>::const_reference
2967 Table<3, T>::operator()(const TableIndices<3> &indices) const
2968 {
2969  return TableBase<3, T>::operator()(indices);
2970 }
2971 
2972 
2973 
2974 template <typename T>
2975 inline typename AlignedVector<T>::reference
2977 {
2978  return TableBase<3, T>::operator()(indices);
2979 }
2980 
2981 
2982 
2983 template <typename T>
2984 inline Table<4, T>::Table(const size_type size1,
2985  const size_type size2,
2986  const size_type size3,
2987  const size_type size4)
2988  : TableBase<4, T>(TableIndices<4>(size1, size2, size3, size4))
2989 {}
2990 
2991 
2992 
2993 template <typename T>
2994 inline ::internal::TableBaseAccessors::Accessor<4, T, true, 3>
2995  Table<4, T>::operator[](const size_type i) const
2996 {
2997  AssertIndexRange(i, this->table_size[0]);
2998  const size_type subobject_size =
2999  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3000  return (::internal::TableBaseAccessors::Accessor<4, T, true, 3>(
3001  *this, this->values.begin() + i * subobject_size));
3002 }
3003 
3004 
3005 
3006 template <typename T>
3007 inline ::internal::TableBaseAccessors::Accessor<4, T, false, 3>
3009 {
3010  AssertIndexRange(i, this->table_size[0]);
3011  const size_type subobject_size =
3012  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3013  return (::internal::TableBaseAccessors::Accessor<4, T, false, 3>(
3014  *this, this->values.begin() + i * subobject_size));
3015 }
3016 
3017 
3018 
3019 template <typename T>
3020 inline typename AlignedVector<T>::const_reference
3022  const size_type j,
3023  const size_type k,
3024  const size_type l) const
3025 {
3026  AssertIndexRange(i, this->table_size[0]);
3027  AssertIndexRange(j, this->table_size[1]);
3028  AssertIndexRange(k, this->table_size[2]);
3029  AssertIndexRange(l, this->table_size[3]);
3030  return this
3031  ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3032  k) *
3033  this->table_size[3] +
3034  l];
3035 }
3036 
3037 
3038 
3039 template <typename T>
3040 inline typename AlignedVector<T>::reference
3042  const size_type j,
3043  const size_type k,
3044  const size_type l)
3045 {
3046  AssertIndexRange(i, this->table_size[0]);
3047  AssertIndexRange(j, this->table_size[1]);
3048  AssertIndexRange(k, this->table_size[2]);
3049  AssertIndexRange(l, this->table_size[3]);
3050  return this
3051  ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3052  k) *
3053  this->table_size[3] +
3054  l];
3055 }
3056 
3057 
3058 
3059 template <typename T>
3060 inline typename AlignedVector<T>::const_reference
3061 Table<4, T>::operator()(const TableIndices<4> &indices) const
3062 {
3063  return TableBase<4, T>::operator()(indices);
3064 }
3065 
3066 
3067 
3068 template <typename T>
3069 inline typename AlignedVector<T>::reference
3071 {
3072  return TableBase<4, T>::operator()(indices);
3073 }
3074 
3075 
3076 
3077 template <typename T>
3078 inline Table<5, T>::Table(const size_type size1,
3079  const size_type size2,
3080  const size_type size3,
3081  const size_type size4,
3082  const size_type size5)
3083  : TableBase<5, T>(TableIndices<5>(size1, size2, size3, size4, size5))
3084 {}
3085 
3086 
3087 
3088 template <typename T>
3089 inline ::internal::TableBaseAccessors::Accessor<5, T, true, 4>
3090  Table<5, T>::operator[](const size_type i) const
3091 {
3092  AssertIndexRange(i, this->table_size[0]);
3093  const size_type subobject_size = size_type(this->table_size[1]) *
3094  this->table_size[2] * this->table_size[3] *
3095  this->table_size[4];
3096  return (::internal::TableBaseAccessors::Accessor<5, T, true, 4>(
3097  *this, this->values.begin() + i * subobject_size));
3098 }
3099 
3100 
3101 
3102 template <typename T>
3103 inline ::internal::TableBaseAccessors::Accessor<5, T, false, 4>
3105 {
3106  AssertIndexRange(i, this->table_size[0]);
3107  const size_type subobject_size = size_type(this->table_size[1]) *
3108  this->table_size[2] * this->table_size[3] *
3109  this->table_size[4];
3110  return (::internal::TableBaseAccessors::Accessor<5, T, false, 4>(
3111  *this, this->values.begin() + i * subobject_size));
3112 }
3113 
3114 
3115 
3116 template <typename T>
3117 inline typename AlignedVector<T>::const_reference
3119  const size_type j,
3120  const size_type k,
3121  const size_type l,
3122  const size_type m) const
3123 {
3124  AssertIndexRange(i, this->table_size[0]);
3125  AssertIndexRange(j, this->table_size[1]);
3126  AssertIndexRange(k, this->table_size[2]);
3127  AssertIndexRange(l, this->table_size[3]);
3128  AssertIndexRange(m, this->table_size[4]);
3129  return this
3130  ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3131  k) *
3132  this->table_size[3] +
3133  l) *
3134  this->table_size[4] +
3135  m];
3136 }
3137 
3138 
3139 
3140 template <typename T>
3141 inline typename AlignedVector<T>::reference
3143  const size_type j,
3144  const size_type k,
3145  const size_type l,
3146  const size_type m)
3147 {
3148  AssertIndexRange(i, this->table_size[0]);
3149  AssertIndexRange(j, this->table_size[1]);
3150  AssertIndexRange(k, this->table_size[2]);
3151  AssertIndexRange(l, this->table_size[3]);
3152  AssertIndexRange(m, this->table_size[4]);
3153  return this
3154  ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3155  k) *
3156  this->table_size[3] +
3157  l) *
3158  this->table_size[4] +
3159  m];
3160 }
3161 
3162 
3163 
3164 template <typename T>
3165 inline typename AlignedVector<T>::const_reference
3166 Table<5, T>::operator()(const TableIndices<5> &indices) const
3167 {
3168  return TableBase<5, T>::operator()(indices);
3169 }
3170 
3171 
3172 
3173 template <typename T>
3174 inline typename AlignedVector<T>::reference
3176 {
3177  return TableBase<5, T>::operator()(indices);
3178 }
3179 
3180 
3181 
3182 template <typename T>
3183 inline Table<6, T>::Table(const size_type size1,
3184  const size_type size2,
3185  const size_type size3,
3186  const size_type size4,
3187  const size_type size5,
3188  const size_type size6)
3189  : TableBase<6, T>()
3190 {
3191  TableIndices<6> table_indices;
3192  table_indices[0] = size1;
3193  table_indices[1] = size2;
3194  table_indices[2] = size3;
3195  table_indices[3] = size4;
3196  table_indices[4] = size5;
3197  table_indices[5] = size6;
3198 
3199  TableBase<6, T>::reinit(table_indices);
3200 }
3201 
3202 
3203 
3204 template <typename T>
3205 inline ::internal::TableBaseAccessors::Accessor<6, T, true, 5>
3206  Table<6, T>::operator[](const size_type i) const
3207 {
3208  AssertIndexRange(i, this->table_size[0]);
3209  const size_type subobject_size = size_type(this->table_size[1]) *
3210  this->table_size[2] * this->table_size[3] *
3211  this->table_size[4] * this->table_size[5];
3212  return (::internal::TableBaseAccessors::Accessor<6, T, true, 5>(
3213  *this, this->values.begin() + i * subobject_size));
3214 }
3215 
3216 
3217 
3218 template <typename T>
3219 inline ::internal::TableBaseAccessors::Accessor<6, T, false, 5>
3221 {
3222  AssertIndexRange(i, this->table_size[0]);
3223  const size_type subobject_size = size_type(this->table_size[1]) *
3224  this->table_size[2] * this->table_size[3] *
3225  this->table_size[4] * this->table_size[5];
3226  return (::internal::TableBaseAccessors::Accessor<6, T, false, 5>(
3227  *this, this->values.begin() + i * subobject_size));
3228 }
3229 
3230 
3231 
3232 template <typename T>
3233 inline typename AlignedVector<T>::const_reference
3235  const size_type j,
3236  const size_type k,
3237  const size_type l,
3238  const size_type m,
3239  const size_type n) const
3240 {
3241  AssertIndexRange(i, this->table_size[0]);
3242  AssertIndexRange(j, this->table_size[1]);
3243  AssertIndexRange(k, this->table_size[2]);
3244  AssertIndexRange(l, this->table_size[3]);
3245  AssertIndexRange(m, this->table_size[4]);
3246  AssertIndexRange(n, this->table_size[5]);
3247  return this
3248  ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3249  k) *
3250  this->table_size[3] +
3251  l) *
3252  this->table_size[4] +
3253  m) *
3254  this->table_size[5] +
3255  n];
3256 }
3257 
3258 
3259 
3260 template <typename T>
3261 inline typename AlignedVector<T>::reference
3263  const size_type j,
3264  const size_type k,
3265  const size_type l,
3266  const size_type m,
3267  const size_type n)
3268 {
3269  AssertIndexRange(i, this->table_size[0]);
3270  AssertIndexRange(j, this->table_size[1]);
3271  AssertIndexRange(k, this->table_size[2]);
3272  AssertIndexRange(l, this->table_size[3]);
3273  AssertIndexRange(m, this->table_size[4]);
3274  AssertIndexRange(n, this->table_size[5]);
3275  return this
3276  ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3277  k) *
3278  this->table_size[3] +
3279  l) *
3280  this->table_size[4] +
3281  m) *
3282  this->table_size[5] +
3283  n];
3284 }
3285 
3286 
3287 
3288 template <typename T>
3289 inline typename AlignedVector<T>::const_reference
3290 Table<6, T>::operator()(const TableIndices<6> &indices) const
3291 {
3292  return TableBase<6, T>::operator()(indices);
3293 }
3294 
3295 
3296 
3297 template <typename T>
3298 inline typename AlignedVector<T>::reference
3300 {
3301  return TableBase<6, T>::operator()(indices);
3302 }
3303 
3304 
3305 
3306 template <typename T>
3307 inline Table<7, T>::Table(const size_type size1,
3308  const size_type size2,
3309  const size_type size3,
3310  const size_type size4,
3311  const size_type size5,
3312  const size_type size6,
3313  const size_type size7)
3314  : TableBase<7, T>()
3315 {
3316  TableIndices<7> table_indices;
3317  table_indices[0] = size1;
3318  table_indices[1] = size2;
3319  table_indices[2] = size3;
3320  table_indices[3] = size4;
3321  table_indices[4] = size5;
3322  table_indices[5] = size6;
3323  table_indices[6] = size7;
3324 
3325  TableBase<7, T>::reinit(table_indices);
3326 }
3327 
3328 
3329 
3330 template <typename T>
3331 inline ::internal::TableBaseAccessors::Accessor<7, T, true, 6>
3332  Table<7, T>::operator[](const size_type i) const
3333 {
3334  AssertIndexRange(i, this->table_size[0]);
3335  const size_type subobject_size =
3336  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3337  this->table_size[4] * this->table_size[5] * this->table_size[6];
3338  return (::internal::TableBaseAccessors::Accessor<7, T, true, 6>(
3339  *this, this->values.begin() + i * subobject_size));
3340 }
3341 
3342 
3343 
3344 template <typename T>
3345 inline ::internal::TableBaseAccessors::Accessor<7, T, false, 6>
3347 {
3348  AssertIndexRange(i, this->table_size[0]);
3349  const size_type subobject_size =
3350  size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3351  this->table_size[4] * this->table_size[5] * this->table_size[6];
3352  return (::internal::TableBaseAccessors::Accessor<7, T, false, 6>(
3353  *this, this->values.begin() + i * subobject_size));
3354 }
3355 
3356 
3357 
3358 template <typename T>
3359 inline typename AlignedVector<T>::const_reference
3361  const size_type j,
3362  const size_type k,
3363  const size_type l,
3364  const size_type m,
3365  const size_type n,
3366  const size_type o) const
3367 {
3368  AssertIndexRange(i, this->table_size[0]);
3369  AssertIndexRange(j, this->table_size[1]);
3370  AssertIndexRange(k, this->table_size[2]);
3371  AssertIndexRange(l, this->table_size[3]);
3372  AssertIndexRange(m, this->table_size[4]);
3373  AssertIndexRange(n, this->table_size[5]);
3374  AssertIndexRange(o, this->table_size[6]);
3375  return this->values
3376  [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3377  this->table_size[3] +
3378  l) *
3379  this->table_size[4] +
3380  m) *
3381  this->table_size[5] +
3382  n) *
3383  this->table_size[6] +
3384  o];
3385 }
3386 
3387 
3388 
3389 template <typename T>
3390 inline typename AlignedVector<T>::reference
3392  const size_type j,
3393  const size_type k,
3394  const size_type l,
3395  const size_type m,
3396  const size_type n,
3397  const size_type o)
3398 {
3399  AssertIndexRange(i, this->table_size[0]);
3400  AssertIndexRange(j, this->table_size[1]);
3401  AssertIndexRange(k, this->table_size[2]);
3402  AssertIndexRange(l, this->table_size[3]);
3403  AssertIndexRange(m, this->table_size[4]);
3404  AssertIndexRange(n, this->table_size[5]);
3405  AssertIndexRange(o, this->table_size[6]);
3406  return this->values
3407  [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3408  this->table_size[3] +
3409  l) *
3410  this->table_size[4] +
3411  m) *
3412  this->table_size[5] +
3413  n) *
3414  this->table_size[6] +
3415  o];
3416 }
3417 
3418 
3419 
3420 template <typename T>
3421 inline typename AlignedVector<T>::const_reference
3422 Table<7, T>::operator()(const TableIndices<7> &indices) const
3423 {
3424  return TableBase<7, T>::operator()(indices);
3425 }
3426 
3427 
3428 
3429 template <typename T>
3430 inline typename AlignedVector<T>::reference
3432 {
3433  return TableBase<7, T>::operator()(indices);
3434 }
3435 
3436 
3437 #endif // DOXYGEN
3438 
3439 
3440 
3448 template <int N, typename T>
3449 inline void
3451 {
3452  u.swap(v);
3453 }
3454 
3455 DEAL_II_NAMESPACE_CLOSE
3456 
3457 #endif
size_type n_rows() const
typename TableBase< 3, T >::size_type size_type
Definition: table.h:1036
typename std::conditional< Constness, const TransposeTable< T > *, TransposeTable< T > * >::type container_pointer_type
Definition: table.h:1717
void serialize(Archive &ar, const unsigned int version)
void swap(TableBase< N, T > &v)
typename TableBase< 2, T >::size_type size_type
Definition: table.h:1770
typename TableBase< 6, T >::size_type size_type
Definition: table.h:1359
typename std::conditional< Constness, const TransposeTable< T > *, TransposeTable< T > * >::type container_pointer_type
Definition: table.h:1573
typename AlignedVector< T >::reference reference
Definition: table.h:1780
#define AssertIndexRange(index, range)
Definition: exceptions.h:1407
STL namespace.
typename TableBase< 2, T >::size_type size_type
Definition: table.h:851
static::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
typename AlignedVector< T >::value_type value_type
Definition: table.h:1775
typename TableBase< 1, T >::size_type size_type
Definition: table.h:733
TransposeTableIterators::Iterator< T, false > iterator
Definition: table.h:1796
container_pointer_type container
Definition: table.h:1625
const TableIndices< N > & size() const
typename TableBase< 4, T >::size_type size_type
Definition: table.h:1168
static::ExceptionBase & ExcMessage(std::string arg1)
iterator end()
iterator begin()
typename TransposeTable< T >::size_type size_type
Definition: table.h:1607
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
size_type size(const unsigned int i) const
#define Assert(cond, exc)
Definition: exceptions.h:1227
typename TransposeTable< T >::size_type size_type
Definition: table.h:1709
void reinit(const size_type size1, const size_type size2, const bool omit_default_initialization=false)
AlignedVector< T >::reference el(const TableIndices< N > &indices)
std::size_t memory_consumption() const
TableBase()=default
void swap(Vector< Number > &u, Vector< Number > &v)
Definition: vector.h:1353
size_type n_elements() const
size_type position(const TableIndices< N > &indices) const
const_reference operator()(const size_type i, const size_type j) const
TableBase< N, T > & operator=(const TableBase< N, T > &src)
typename AlignedVector< T >::size_type size_type
Definition: table.h:429
TransposeTableIterators::Iterator< T, true > const_iterator
Definition: table.h:1791
typename TableBase< 5, T >::size_type size_type
Definition: table.h:1262
void reset_values()
TransposeTable()=default
reference el(const size_type i, const size_type j)
static::ExceptionBase & ExcNotImplemented()
Definition: table.h:37
TableIndices< N > table_size
Definition: table.h:686
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:432
size_type n_cols() const
AlignedVector< T >::reference operator()(const TableIndices< N > &indices)
AlignedVector< T > values
Definition: table.h:681
typename TableBase< 7, T >::size_type size_type
Definition: table.h:1457
void fill(InputIterator entries, const bool C_style_indexing=true)
bool empty() const
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
typename AlignedVector< T >::const_reference const_reference
Definition: table.h:1785
bool operator==(const TableBase< N, T > &T2) const