Reference documentation for deal.II version 9.0.0
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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_table_h
17 #define dealii_table_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/base/exceptions.h>
21 #include <deal.II/base/subscriptor.h>
22 #include <deal.II/base/table_indices.h>
23 #include <deal.II/base/memory_consumption.h>
24 #include <deal.II/base/aligned_vector.h>
25 #include <deal.II/base/linear_index_iterator.h>
26 
27 #include <cstddef>
28 #include <algorithm>
29 
30 DEAL_II_NAMESPACE_OPEN
31 
32 // forward declaration
33 template <int N, typename T> class TableBase;
34 template <int N, typename T> class Table;
35 template <typename T> class TransposeTable;
36 template <typename T> class Table<1,T>;
37 template <typename T> class Table<2,T>;
38 template <typename T> class Table<3,T>;
39 template <typename T> class Table<4,T>;
40 template <typename T> class Table<5,T>;
41 template <typename T> class Table<6,T>;
42 
43 
44 
45 namespace internal
46 {
47 
64  namespace TableBaseAccessors
65  {
73  template <int N, typename T, bool Constness>
74  struct Types
75  {};
76 
82  template <int N, typename T> struct Types<N,T,true>
83  {
84  typedef const T value_type;
85  typedef const TableBase<N,T> TableType;
86 
87  typedef typename AlignedVector<T>::const_iterator iterator;
88  typedef typename AlignedVector<T>::const_iterator const_iterator;
89 
90  typedef typename AlignedVector<T>::const_reference reference;
91  typedef typename AlignedVector<T>::const_reference const_reference;
92  };
93 
99  template <int N, typename T> struct Types<N,T,false>
100  {
101  typedef T value_type;
102  typedef TableBase<N,T> TableType;
103 
104  typedef typename AlignedVector<T>::iterator iterator;
105  typedef typename AlignedVector<T>::const_iterator const_iterator;
106 
107  typedef typename AlignedVector<T>::reference reference;
108  typedef typename AlignedVector<T>::const_reference const_reference;
109  };
110 
111 
150  template <int N, typename T, bool C, unsigned int P>
151  class Accessor
152  {
153  public:
154  typedef typename Types<N,T,C>::TableType TableType;
155 
156  typedef typename Types<N,T,C>::iterator iterator;
157  typedef typename Types<N,T,C>::const_iterator const_iterator;
158 
159  typedef size_t size_type;
160  typedef ptrdiff_t difference_type;
161  private:
167  Accessor (const TableType &table,
168  const iterator data);
169 
173  Accessor () = delete;
174 
175  public:
176 
184  Accessor (const Accessor &a);
185 
189  Accessor<N,T,C,P-1> operator [] (const size_type i) const;
190 
195  DeclException3 (ExcIndexRange, size_type, size_type, size_type,
196  << "Index " << N-P+1 << "has a value of "
197  << arg1 << " but needs to be in the range ["
198  << arg2 << "," << arg3 << "[.");
199  private:
205  const TableType &table;
206  const iterator data;
207 
208  // declare some other classes
209  // as friends. make sure to
210  // work around bugs in some
211  // compilers
212  template <int N1, typename T1> friend class ::Table;
213  template <int N1, typename T1, bool C1, unsigned int P1>
214  friend class Accessor;
215 # ifndef DEAL_II_TEMPL_SPEC_FRIEND_BUG
216  friend class ::Table<N,T>;
217  friend class Accessor<N,T,C,P+1>;
218 # endif
219  };
220 
221 
222 
232  template <int N, typename T, bool C>
233  class Accessor<N,T,C,1>
234  {
235  public:
241  typedef typename Types<N,T,C>::value_type value_type;
242 
243  typedef typename Types<N,T,C>::iterator iterator;
244  typedef typename Types<N,T,C>::const_iterator const_iterator;
245 
246  typedef typename Types<N,T,C>::reference reference;
247  typedef typename Types<N,T,C>::const_reference const_reference;
248 
249  typedef size_t size_type;
250  typedef ptrdiff_t difference_type;
251 
255  typedef typename Types<N,T,C>::TableType TableType;
256 
257  private:
258 
270  Accessor (const TableType &table,
271  const iterator data);
272 
276  Accessor () = delete;
277 
278  public:
286  Accessor (const Accessor &a);
287 
288 
292  reference operator [] (const size_type) const;
293 
298  size_type size () const;
299 
303  iterator begin () const;
304 
308  iterator end () const;
309 
310  private:
316  const TableType &table;
317  const iterator data;
318 
319  // declare some other classes
320  // as friends. make sure to
321  // work around bugs in some
322  // compilers
323  template <int N1, typename T1> friend class ::Table;
324  template <int N1, typename T1, bool C1, unsigned int P1>
325  friend class Accessor;
326 # ifndef DEAL_II_TEMPL_SPEC_FRIEND_BUG
327  friend class ::Table<2,T>;
328  friend class Accessor<N,T,C,2>;
329 # endif
330  };
331  }
332 
333 } // namespace internal
334 
335 
336 
337 
404 template <int N, typename T>
405 class TableBase : public Subscriptor
406 {
407 public:
408  typedef T value_type;
409 
413  typedef typename AlignedVector<T>::size_type size_type;
414 
415 
419  TableBase () = default;
420 
425  TableBase (const TableIndices<N> &sizes);
426 
432  template <typename InputIterator>
433  TableBase (const TableIndices<N> &sizes,
434  InputIterator entries,
435  const bool C_style_indexing = true);
436 
440  TableBase (const TableBase<N,T> &src);
441 
446  template <typename T2>
447  TableBase (const TableBase<N,T2> &src);
448 
452  TableBase (TableBase<N,T> &&src) noexcept;
453 
457  ~TableBase () = default;
458 
468 
476  template <typename T2>
478 
483  TableBase<N,T> &operator = (TableBase<N,T> &&src) noexcept;
484 
488  bool operator == (const TableBase<N,T> &T2) const;
489 
494  void reset_values ();
495 
504  void reinit (const TableIndices<N> &new_size,
505  const bool omit_default_initialization = false);
506 
510  size_type size (const unsigned int i) const;
511 
515  const TableIndices<N> &size () const;
516 
521  size_type n_elements () const;
522 
527  bool empty () const;
528 
565  template <typename InputIterator>
566  void fill (InputIterator entries,
567  const bool C_style_indexing = true);
568 
572  void fill (const T &value);
573 
577  typename AlignedVector<T>::reference
578  operator () (const TableIndices<N> &indices);
579 
587  typename AlignedVector<T>::const_reference
588  operator () (const TableIndices<N> &indices) const;
589 
602  void swap (TableBase<N,T> &v);
603 
608  std::size_t memory_consumption () const;
609 
614  template <class Archive>
615  void serialize (Archive &ar, const unsigned int version);
616 
617 protected:
622  size_type position (const TableIndices<N> &indices) const;
623 
630  typename AlignedVector<T>::reference el (const TableIndices<N> &indices);
631 
642  typename AlignedVector<T>::const_reference el (const TableIndices<N> &indices) const;
643 
644 protected:
649 
654 
658  template <int, typename> friend class TableBase;
659 };
660 
661 
675 template <int N,typename T>
676 class Table : public TableBase<N,T>
677 {
678 };
679 
680 
693 template <typename T>
694 class Table<1,T> : public TableBase<1,T>
695 {
696 public:
701 
705  Table () = default;
706 
710  Table (const size_type size);
711 
749  template <typename InputIterator>
750  Table (const size_type size,
751  InputIterator entries,
752  const bool C_style_indexing = true);
753 
758  typename AlignedVector<T>::const_reference
759  operator [] (const size_type i) const;
760 
765  typename AlignedVector<T>::reference
766  operator [] (const size_type i);
767 
772  typename AlignedVector<T>::const_reference
773  operator () (const size_type i) const;
774 
779  typename AlignedVector<T>::reference
780  operator () (const size_type i);
781 
786  typename AlignedVector<T>::reference
787  operator () (const TableIndices<1> &indices);
788 
793  typename AlignedVector<T>::const_reference
794  operator () (const TableIndices<1> &indices) const;
795 };
796 
797 
798 
812 template <typename T>
813 class Table<2,T> : public TableBase<2,T>
814 {
815 public:
820 
824  Table () = default;
825 
829  Table (const size_type size1,
830  const size_type size2);
831 
870  template <typename InputIterator>
871  Table (const size_type size1,
872  const size_type size2,
873  InputIterator entries,
874  const bool C_style_indexing = true);
875 
881  void reinit (const size_type size1,
882  const size_type size2,
883  const bool omit_default_initialization = false);
884 
886 
893  ::internal::TableBaseAccessors::Accessor<2,T,true,1>
894  operator [] (const size_type i) const;
895 
902  ::internal::TableBaseAccessors::Accessor<2,T,false,1>
903  operator [] (const size_type i);
904 
911  typename AlignedVector<T>::const_reference
912  operator () (const size_type i,
913  const size_type j) const;
914 
915 
922  typename AlignedVector<T>::reference
923  operator () (const size_type i,
924  const size_type j);
925 
930  typename AlignedVector<T>::reference
931  operator () (const TableIndices<2> &indices);
932 
937  typename AlignedVector<T>::const_reference
938  operator () (const TableIndices<2> &indices) const;
939 
940 
945  size_type n_rows () const;
946 
951  size_type n_cols () const;
952 
953 protected:
964  typename AlignedVector<T>::reference el (const size_type i,
965  const size_type j);
966 
981  typename AlignedVector<T>::const_reference el (const size_type i,
982  const size_type j) const;
983 };
984 
985 
986 
997 template <typename T>
998 class Table<3,T> : public TableBase<3,T>
999 {
1000 public:
1005 
1009  Table () = default;
1010 
1014  Table (const size_type size1,
1015  const size_type size2,
1016  const size_type size3);
1017 
1058  template <typename InputIterator>
1059  Table (const size_type size1,
1060  const size_type size2,
1061  const size_type size3,
1062  InputIterator entries,
1063  const bool C_style_indexing = true);
1064 
1072  ::internal::TableBaseAccessors::Accessor<3,T,true,2>
1073  operator [] (const size_type i) const;
1074 
1082  ::internal::TableBaseAccessors::Accessor<3,T,false,2>
1083  operator [] (const size_type i);
1084 
1091  typename AlignedVector<T>::const_reference operator () (const size_type i,
1092  const size_type j,
1093  const size_type k) const;
1094 
1095 
1102  typename AlignedVector<T>::reference operator () (const size_type i,
1103  const size_type j,
1104  const size_type k);
1105 
1110  typename AlignedVector<T>::reference operator () (const TableIndices<3> &indices);
1111 
1116  typename AlignedVector<T>::const_reference operator () (const TableIndices<3> &indices) const;
1117 };
1118 
1119 
1120 
1131 template <typename T>
1132 class Table<4,T> : public TableBase<4,T>
1133 {
1134 public:
1139 
1143  Table () = default;
1144 
1148  Table (const size_type size1,
1149  const size_type size2,
1150  const size_type size3,
1151  const size_type size4);
1152 
1160  ::internal::TableBaseAccessors::Accessor<4,T,true,3>
1161  operator [] (const size_type i) const;
1162 
1170  ::internal::TableBaseAccessors::Accessor<4,T,false,3>
1171  operator [] (const size_type i);
1172 
1179  typename AlignedVector<T>::const_reference operator () (const size_type i,
1180  const size_type j,
1181  const size_type k,
1182  const size_type l) const;
1183 
1184 
1191  typename AlignedVector<T>::reference operator () (const size_type i,
1192  const size_type j,
1193  const size_type k,
1194  const size_type l);
1195 
1200  typename AlignedVector<T>::reference
1201  operator () (const TableIndices<4> &indices);
1202 
1207  typename AlignedVector<T>::const_reference
1208  operator () (const TableIndices<4> &indices) const;
1209 };
1210 
1211 
1212 
1223 template <typename T>
1224 class Table<5,T> : public TableBase<5,T>
1225 {
1226 public:
1231 
1232 
1236  Table () = default;
1237 
1241  Table (const size_type size1,
1242  const size_type size2,
1243  const size_type size3,
1244  const size_type size4,
1245  const size_type size5);
1246 
1254  ::internal::TableBaseAccessors::Accessor<5,T,true,4>
1255  operator [] (const size_type i) const;
1256 
1264  ::internal::TableBaseAccessors::Accessor<5,T,false,4>
1265  operator [] (const size_type i);
1266 
1273  typename AlignedVector<T>::const_reference operator () (const size_type i,
1274  const size_type j,
1275  const size_type k,
1276  const size_type l,
1277  const size_type m) const;
1278 
1285  typename AlignedVector<T>::reference operator () (const size_type i,
1286  const size_type j,
1287  const size_type k,
1288  const size_type l,
1289  const size_type m);
1290 
1295  typename AlignedVector<T>::reference
1296  operator () (const TableIndices<5> &indices);
1297 
1302  typename AlignedVector<T>::const_reference
1303  operator () (const TableIndices<5> &indices) const;
1304 };
1305 
1306 
1307 
1318 template <typename T>
1319 class Table<6,T> : public TableBase<6,T>
1320 {
1321 public:
1326 
1330  Table () = default;
1331 
1335  Table (const size_type size1,
1336  const size_type size2,
1337  const size_type size3,
1338  const size_type size4,
1339  const size_type size5,
1340  const size_type size6);
1341 
1349  ::internal::TableBaseAccessors::Accessor<6,T,true,5>
1350  operator [] (const size_type i) const;
1351 
1359  ::internal::TableBaseAccessors::Accessor<6,T,false,5>
1360  operator [] (const size_type i);
1361 
1368  typename AlignedVector<T>::const_reference operator () (const size_type i,
1369  const size_type j,
1370  const size_type k,
1371  const size_type l,
1372  const size_type m,
1373  const size_type n) const;
1374 
1381  typename AlignedVector<T>::reference operator () (const size_type i,
1382  const size_type j,
1383  const size_type k,
1384  const size_type l,
1385  const size_type m,
1386  const size_type n);
1387 
1392  typename AlignedVector<T>::reference
1393  operator () (const TableIndices<6> &indices);
1394 
1399  typename AlignedVector<T>::const_reference
1400  operator () (const TableIndices<6> &indices) const;
1401 };
1402 
1403 
1414 template <typename T>
1415 class Table<7,T> : public TableBase<7,T>
1416 {
1417 public:
1422 
1426  Table () = default;
1427 
1431  Table (const size_type size1,
1432  const size_type size2,
1433  const size_type size3,
1434  const size_type size4,
1435  const size_type size5,
1436  const size_type size6,
1437  const size_type size7);
1438 
1446  ::internal::TableBaseAccessors::Accessor<7,T,true,6>
1447  operator [] (const size_type i) const;
1448 
1456  ::internal::TableBaseAccessors::Accessor<7,T,false,6>
1457  operator [] (const size_type i);
1458 
1465  typename AlignedVector<T>::const_reference operator () (const size_type i,
1466  const size_type j,
1467  const size_type k,
1468  const size_type l,
1469  const size_type m,
1470  const size_type n,
1471  const size_type o) const;
1472 
1479  typename AlignedVector<T>::reference operator () (const size_type i,
1480  const size_type j,
1481  const size_type k,
1482  const size_type l,
1483  const size_type m,
1484  const size_type n,
1485  const size_type o);
1486 
1491  typename AlignedVector<T>::reference
1492  operator () (const TableIndices<7> &indices);
1493 
1498  typename AlignedVector<T>::const_reference
1499  operator () (const TableIndices<7> &indices) const;
1500 };
1501 
1502 
1503 
1509 {
1510  // Forward declaration of the iterator class.
1511  template <typename T, bool Constness>
1512  class Iterator;
1513 
1518  template <typename T, bool Constness>
1519  class Accessor;
1520 
1525  template <typename T, bool Constness>
1527  {
1528  public:
1532  typedef typename std::conditional<Constness, const TransposeTable<T>*, TransposeTable<T>*>::type
1534 
1538  AccessorBase();
1539 
1543  AccessorBase(const container_pointer_type table);
1544 
1549 
1555  const std::ptrdiff_t linear_index);
1556 
1561  const T &value() const;
1562 
1567 
1571  size_type row() const;
1572 
1576  size_type column() const;
1577 
1578  protected:
1583 
1587  std::ptrdiff_t linear_index;
1588 
1592  friend class AccessorBase<T, true>;
1593 
1597  friend class LinearIndexIterator<Iterator<T, Constness>, Accessor<T, Constness>>;
1598  };
1599 
1603  template <typename T>
1604  class Accessor<T, true> : public AccessorBase<T, true>
1605  {
1606  public:
1611  };
1612 
1617  template <typename T>
1618  class Accessor<T, false> : public AccessorBase<T, false>
1619  {
1620  public:
1625 
1630  const Accessor<T, false> &operator = (const T &) const;
1631 
1636  const Accessor<T, false> &operator = (T&&) const;
1637 
1643 
1648  T &value() const;
1649  };
1650 
1654  template <typename T, bool Constness>
1655  class Iterator : public LinearIndexIterator<Iterator<T, Constness>, Accessor<T, Constness>>
1656  {
1657  public:
1662 
1666  typedef typename std::conditional<Constness, const TransposeTable<T>*, TransposeTable<T>*>::type
1668 
1673 
1677  Iterator (const container_pointer_type object);
1678 
1682  Iterator (const container_pointer_type object,
1683  const size_type row,
1684  const size_type column);
1685 
1689  Iterator(const Iterator<T, false> &i);
1690 
1694  Iterator (const container_pointer_type container,
1695  const std::ptrdiff_t linear_index);
1696  };
1697 }
1698 
1699 
1713 template <typename T>
1714 class TransposeTable : public TableBase<2,T>
1715 {
1716 public:
1721 
1726 
1730  typedef typename AlignedVector<T>::reference reference;
1731 
1735  typedef typename AlignedVector<T>::const_reference const_reference;
1736 
1742 
1747 
1751  TransposeTable () = default;
1752 
1756  TransposeTable (const size_type size1,
1757  const size_type size2);
1758 
1764  void reinit (const size_type size1,
1765  const size_type size2,
1766  const bool omit_default_initialization = false);
1767 
1775  const size_type j) const;
1776 
1784  const size_type j);
1785 
1790  size_type n_rows () const;
1791 
1796  size_type n_cols () const;
1797 
1801  iterator begin ();
1802 
1806  const_iterator begin () const;
1807 
1811  iterator end ();
1812 
1816  const_iterator end () const;
1817 
1818 protected:
1829  reference el (const size_type i,
1830  const size_type j);
1831 
1846  const_reference el (const size_type i,
1847  const size_type j) const;
1848 
1854  friend class TransposeTableIterators::AccessorBase<T, false>;
1855 
1860  friend class TransposeTableIterators::Accessor<T, false>;
1861 };
1862 
1863 
1864 
1865 
1866 /* --------------------- Template and inline functions ---------------- */
1867 
1868 #ifndef DOXYGEN
1869 
1870 template <int N, typename T>
1872 {
1873  reinit (sizes);
1874 }
1875 
1876 
1877 
1878 template <int N, typename T>
1879 template <typename InputIterator>
1881 TableBase (const TableIndices<N> &sizes,
1882  InputIterator entries,
1883  const bool C_style_indexing)
1884 {
1885  reinit (sizes);
1886  fill (entries, C_style_indexing);
1887 }
1888 
1889 
1890 
1891 
1892 template <int N, typename T>
1894  :
1895  Subscriptor ()
1896 {
1897  reinit (src.table_size, true);
1898  values = src.values;
1899 }
1900 
1901 
1902 
1903 template <int N, typename T>
1904 template <typename T2>
1906 {
1907  reinit (src.table_size);
1908  if (src.n_elements() != 0)
1909  std::copy (src.values.begin(), src.values.end(), values.begin());
1910 }
1911 
1912 
1913 
1914 template <int N, typename T>
1916 :
1917 Subscriptor (std::move(src)),
1918  values (std::move(src.values)),
1919  table_size (src.table_size)
1920 {
1921  src.table_size = TableIndices<N>();
1922 }
1923 
1924 
1925 
1926 template <int N, typename T>
1927 template <class Archive>
1928 inline
1929 void
1930 TableBase<N,T>::serialize (Archive &ar, const unsigned int)
1931 {
1932  ar &static_cast<Subscriptor &>(*this);
1933 
1934  ar &values &table_size;
1935 }
1936 
1937 
1938 
1939 namespace internal
1940 {
1941  namespace TableBaseAccessors
1942  {
1943  template <int N, typename T, bool C, unsigned int P>
1944  inline
1945  Accessor<N,T,C,P>::Accessor (const TableType &table,
1946  const iterator data)
1947  :
1948  table (table),
1949  data (data)
1950  {}
1951 
1952 
1953 
1954  template <int N, typename T, bool C, unsigned int P>
1955  inline
1956  Accessor<N,T,C,P>::Accessor (const Accessor &a)
1957  :
1958  table (a.table),
1959  data (a.data)
1960  {}
1961 
1962 
1963 
1964  template <int N, typename T, bool C, unsigned int P>
1965  inline
1966  Accessor<N,T,C,P-1>
1967  Accessor<N,T,C,P>::operator [] (const size_type i) const
1968  {
1969  Assert (i < table.size()[N-P],
1970  ExcIndexRange (i, 0, table.size()[N-P]));
1971 
1972  // access i-th
1973  // subobject. optimize on the
1974  // case i==0
1975  if (i==0)
1976  return Accessor<N,T,C,P-1> (table, data);
1977  else
1978  {
1979  // note: P>1, otherwise the
1980  // specialization would have
1981  // been taken!
1982  size_type subobject_size = table.size()[N-1];
1983  for (int p=P-1; p>1; --p)
1984  subobject_size *= table.size()[N-p];
1985  const iterator new_data = data + i*subobject_size;
1986  return Accessor<N,T,C,P-1> (table, new_data);
1987  }
1988  }
1989 
1990 
1991 
1992  template <int N, typename T, bool C>
1993  inline
1994  Accessor<N,T,C,1>::Accessor (const TableType &table,
1995  const iterator data)
1996  :
1997  table (table),
1998  data (data)
1999  {}
2000 
2001 
2002 
2003  template <int N, typename T, bool C>
2004  inline
2005  Accessor<N,T,C,1>::Accessor (const Accessor &a)
2006  :
2007  table (a.table),
2008  data (a.data)
2009  {}
2010 
2011 
2012 
2013  template <int N, typename T, bool C>
2014  inline
2015  typename Accessor<N,T,C,1>::reference
2016  Accessor<N,T,C,1>::operator [] (const size_type i) const
2017  {
2018  AssertIndexRange (i, table.size()[N-1]);
2019  return *(data+i);
2020  }
2021 
2022 
2023 
2024  template <int N, typename T, bool C>
2025  inline
2026  typename Accessor<N,T,C,1>::size_type
2027  Accessor<N,T,C,1>::size () const
2028  {
2029  return table.size()[N-1];
2030  }
2031 
2032 
2033 
2034  template <int N, typename T, bool C>
2035  inline
2036  typename Accessor<N,T,C,1>::iterator
2037  Accessor<N,T,C,1>::begin () const
2038  {
2039  return data;
2040  }
2041 
2042 
2043 
2044  template <int N, typename T, bool C>
2045  inline
2046  typename Accessor<N,T,C,1>::iterator
2047  Accessor<N,T,C,1>::end () const
2048  {
2049  return data+table.size()[N-1];
2050  }
2051  }
2052 }
2053 
2054 
2055 
2056 template <int N, typename T>
2057 inline
2060 {
2061  if (!m.empty())
2062  values = m.values;
2063  reinit (m.size(), true);
2064 
2065  return *this;
2066 }
2067 
2068 
2069 
2070 template <int N, typename T>
2071 template <typename T2>
2072 inline
2075 {
2076  reinit (m.size(), true);
2077  if (!empty())
2078  std::copy (m.values.begin(), m.values.begin() + n_elements(),
2079  values.begin());
2080 
2081  return *this;
2082 }
2083 
2084 
2085 
2086 template <int N, typename T>
2087 inline
2090 {
2091  static_cast<Subscriptor &>(*this) = std::move(m);
2092  values = std::move(m.values);
2093  table_size = m.table_size;
2095 
2096  return *this;
2097 }
2098 
2099 
2100 
2101 template <int N, typename T>
2102 inline
2103 bool
2105 {
2106  return (values == T2.values);
2107 }
2108 
2109 
2110 
2111 template <int N, typename T>
2112 inline
2113 void
2115 {
2116  // use parallel set operation
2117  if (n_elements() != 0)
2118  values.fill(T());
2119 }
2120 
2121 
2122 
2123 template <int N, typename T>
2124 inline
2125 void
2126 TableBase<N,T>::fill (const T &value)
2127 {
2128  if (n_elements() != 0)
2129  values.fill(value);
2130 }
2131 
2132 
2133 
2134 
2135 template <int N, typename T>
2136 inline
2137 void
2138 TableBase<N,T>::reinit (const TableIndices<N> &new_sizes,
2139  const bool omit_default_initialization)
2140 {
2141  table_size = new_sizes;
2142 
2143  const size_type new_size = n_elements();
2144 
2145  // if zero size was given: free all memory
2146  if (new_size == 0)
2147  {
2148  values.resize (0);
2149  // set all sizes to zero, even
2150  // if one was previously
2151  // nonzero. This simplifies
2152  // some assertions.
2153  table_size = TableIndices<N>();
2154 
2155  return;
2156  }
2157 
2158  // adjust values field. If it was empty before, we can simply call resize(),
2159  // which can set all the data fields. Otherwise, select the fast resize and
2160  // manually fill in all the elements as required by the design of this
2161  // class. (Selecting another code for the empty case ensures that we touch
2162  // the memory only once for non-trivial classes that need to initialize the
2163  // memory also in resize_fast.)
2164  if (!omit_default_initialization)
2165  {
2166  if (values.empty())
2167  values.resize(new_size);
2168  else
2169  {
2170  values.resize_fast(new_size);
2171  values.fill();
2172  }
2173  }
2174  else
2175  values.resize_fast (new_size);
2176 }
2177 
2178 
2179 
2180 template <int N, typename T>
2181 inline
2182 const TableIndices<N> &
2183 TableBase<N,T>::size () const
2184 {
2185  return table_size;
2186 }
2187 
2188 
2189 
2190 template <int N, typename T>
2191 inline
2193 TableBase<N,T>::size (const unsigned int i) const
2194 {
2195  Assert (i<N, ExcIndexRange(i,0,N));
2196  return table_size[i];
2197 }
2198 
2199 
2200 
2201 template <int N, typename T>
2202 inline
2205 {
2206  size_type s = 1;
2207  for (unsigned int n=0; n<N; ++n)
2208  s *= table_size[n];
2209  return s;
2210 }
2211 
2212 
2213 
2214 template <int N, typename T>
2215 inline
2216 bool
2217 TableBase<N,T>::empty () const
2218 {
2219  return (n_elements() == 0);
2220 }
2221 
2222 
2223 
2224 namespace internal
2225 {
2226  namespace TableImplementation
2227  {
2228  template <typename InputIterator, typename T>
2229  void fill_Fortran_style (InputIterator entries,
2230  TableBase<1,T> &table)
2231  {
2232  using size_type = typename TableBase<1,T>::size_type;
2233  for (size_type i=0; i<table.size()[0]; ++i)
2234  table(TableIndices<1>(i)) = *entries++;
2235  }
2236 
2237 
2238  template <typename InputIterator, typename T>
2239  void fill_Fortran_style (InputIterator entries,
2240  TableBase<2,T> &table)
2241  {
2242  using size_type = typename TableBase<2,T>::size_type;
2243  for (size_type j=0; j<table.size()[1]; ++j)
2244  for (size_type i=0; i<table.size()[0]; ++i)
2245  table(TableIndices<2>(i,j)) = *entries++;
2246  }
2247 
2248 
2249  template <typename InputIterator, typename T>
2250  void fill_Fortran_style (InputIterator entries,
2251  TableBase<3,T> &table)
2252  {
2253  using size_type = typename TableBase<3,T>::size_type;
2254  for (size_type k=0; k<table.size()[2]; ++k)
2255  for (size_type j=0; j<table.size()[1]; ++j)
2256  for (size_type i=0; i<table.size()[0]; ++i)
2257  table(TableIndices<3>(i,j,k)) = *entries++;
2258  }
2259 
2260 
2261  template <typename InputIterator, typename T, int N>
2262  void fill_Fortran_style (InputIterator,
2263  TableBase<N,T> &)
2264  {
2265  Assert (false, ExcNotImplemented());
2266  }
2267  }
2268 }
2269 
2270 
2271 template <int N, typename T>
2272 template <typename InputIterator>
2273 inline
2274 void
2275 TableBase<N,T>::fill (InputIterator entries,
2276  const bool C_style_indexing)
2277 {
2278  Assert (n_elements() != 0,
2279  ExcMessage("Trying to fill an empty matrix."));
2280 
2281  if (C_style_indexing)
2282  for (typename AlignedVector<T>::iterator p = values.begin();
2283  p != values.end(); ++p)
2284  *p = *entries++;
2285  else
2286  internal::TableImplementation::fill_Fortran_style (entries, *this);
2287 }
2288 
2289 
2290 
2291 template <int N, typename T>
2292 inline
2293 void
2295 {
2296  values.swap(v.values);
2297  std::swap (table_size, v.table_size);
2298 }
2299 
2300 
2301 
2302 template <int N, typename T>
2303 inline
2304 std::size_t
2306 {
2307  return sizeof(*this) + MemoryConsumption::memory_consumption(values);
2308 }
2309 
2310 
2311 
2312 template <int N, typename T>
2313 inline
2315 TableBase<N,T>::position (const TableIndices<N> &indices) const
2316 {
2317  // specialize this for the
2318  // different numbers of dimensions,
2319  // to make the job somewhat easier
2320  // for the compiler. have the
2321  // general formula nevertheless:
2322  switch (N)
2323  {
2324  case 1:
2325  return indices[0];
2326  case 2:
2327  return size_type(indices[0])*table_size[1] + indices[1];
2328  case 3:
2329  return ((size_type(indices[0])*table_size[1] + indices[1])*table_size[2]
2330  + indices[2]);
2331  default:
2332  {
2333  unsigned int s = indices[0];
2334  for (unsigned int n=1; n<N; ++n)
2335  s = s*table_size[n] + indices[n];
2336  return s;
2337  }
2338  }
2339 }
2340 
2341 
2342 
2343 template <int N, typename T>
2344 inline
2345 typename AlignedVector<T>::const_reference
2346 TableBase<N,T>::operator () (const TableIndices<N> &indices) const
2347 {
2348  for (unsigned int n=0; n<N; ++n)
2349  AssertIndexRange (indices[n], table_size[n]);
2350  return el(indices);
2351 }
2352 
2353 
2354 
2355 template <int N, typename T>
2356 inline
2357 typename AlignedVector<T>::reference
2359 {
2360  for (unsigned int n=0; n<N; ++n)
2361  AssertIndexRange (indices[n], table_size[n]);
2362  return el(indices);
2363 }
2364 
2365 
2366 
2367 template <int N, typename T>
2368 inline
2369 typename AlignedVector<T>::const_reference
2370 TableBase<N,T>::el (const TableIndices<N> &indices) const
2371 {
2372  return values[position(indices)];
2373 }
2374 
2375 
2376 
2377 template <int N, typename T>
2378 inline
2379 typename AlignedVector<T>::reference
2380 TableBase<N,T>::el (const TableIndices<N> &indices)
2381 {
2382  AssertIndexRange (position(indices), values.size());
2383  return values[position(indices)];
2384 }
2385 
2386 
2387 
2388 template <typename T>
2389 inline
2390 Table<1,T>::Table (const size_type size)
2391  :
2392  TableBase<1,T> (TableIndices<1> (size))
2393 {}
2394 
2395 
2396 
2397 template <typename T>
2398 template <typename InputIterator>
2399 inline
2400 Table<1,T>::Table (const size_type size,
2401  InputIterator entries,
2402  const bool C_style_indexing)
2403  :
2404  TableBase<1,T> (TableIndices<1> (size),
2405  entries,
2406  C_style_indexing)
2407 {}
2408 
2409 
2410 
2411 template <typename T>
2412 inline
2413 typename AlignedVector<T>::const_reference
2414 Table<1,T>::operator [] (const size_type i) const
2415 {
2416  AssertIndexRange (i, this->table_size[0]);
2417  return this->values[i];
2418 }
2419 
2420 
2421 
2422 template <typename T>
2423 inline
2424 typename AlignedVector<T>::reference
2425 Table<1,T>::operator [] (const size_type i)
2426 {
2427  AssertIndexRange (i, this->table_size[0]);
2428  return this->values[i];
2429 }
2430 
2431 
2432 
2433 template <typename T>
2434 inline
2435 typename AlignedVector<T>::const_reference
2436 Table<1,T>::operator () (const size_type i) const
2437 {
2438  AssertIndexRange (i, this->table_size[0]);
2439  return this->values[i];
2440 }
2441 
2442 
2443 
2444 template <typename T>
2445 inline
2446 typename AlignedVector<T>::reference
2447 Table<1,T>::operator () (const size_type i)
2448 {
2449  AssertIndexRange (i, this->table_size[0]);
2450  return this->values[i];
2451 }
2452 
2453 
2454 
2455 template <typename T>
2456 inline
2457 typename AlignedVector<T>::const_reference
2458 Table<1,T>::operator () (const TableIndices<1> &indices) const
2459 {
2460  return TableBase<1,T>::operator () (indices);
2461 }
2462 
2463 
2464 
2465 template <typename T>
2466 inline
2467 typename AlignedVector<T>::reference
2469 {
2470  return TableBase<1,T>::operator () (indices);
2471 }
2472 
2473 
2474 //---------------------------------------------------------------------------
2475 
2476 
2477 
2478 template <typename T>
2479 inline
2480 Table<2,T>::Table (const size_type size1,
2481  const size_type size2)
2482  :
2483  TableBase<2,T> (TableIndices<2> (size1, size2))
2484 {}
2485 
2486 
2487 
2488 template <typename T>
2489 template <typename InputIterator>
2490 inline
2491 Table<2,T>::Table (const size_type size1,
2492  const size_type size2,
2493  InputIterator entries,
2494  const bool C_style_indexing)
2495  :
2496  TableBase<2,T> (TableIndices<2> (size1, size2),
2497  entries,
2498  C_style_indexing)
2499 {}
2500 
2501 
2502 
2503 template <typename T>
2504 inline
2505 void
2506 Table<2,T>::reinit (const size_type size1,
2507  const size_type size2,
2508  const bool omit_default_initialization)
2509 {
2510  this->TableBase<2,T>::reinit (TableIndices<2> (size1, size2),omit_default_initialization);
2511 }
2512 
2513 
2514 
2515 template <typename T>
2516 inline
2517 ::internal::TableBaseAccessors::Accessor<2,T,true,1>
2518 Table<2,T>::operator [] (const size_type i) const
2519 {
2520  AssertIndexRange (i, this->table_size[0]);
2521  return ::internal::TableBaseAccessors::Accessor<2,T,true,1>(*this,
2522  this->values.begin()+size_type(i)*n_cols());
2523 }
2524 
2525 
2526 
2527 template <typename T>
2528 inline
2529 ::internal::TableBaseAccessors::Accessor<2,T,false,1>
2530 Table<2,T>::operator [] (const size_type i)
2531 {
2532  AssertIndexRange (i, this->table_size[0]);
2533  return ::internal::TableBaseAccessors::Accessor<2,T,false,1>(*this,
2534  this->values.begin()+size_type(i)*n_cols());
2535 }
2536 
2537 
2538 
2539 template <typename T>
2540 inline
2541 typename AlignedVector<T>::const_reference
2542 Table<2,T>::operator () (const size_type i,
2543  const size_type j) const
2544 {
2545  AssertIndexRange (i, this->table_size[0]);
2546  AssertIndexRange (j, this->table_size[1]);
2547  return this->values[size_type(i)*this->table_size[1]+j];
2548 }
2549 
2550 
2551 
2552 template <typename T>
2553 inline
2554 typename AlignedVector<T>::reference
2555 Table<2,T>::operator () (const size_type i,
2556  const size_type j)
2557 {
2558  AssertIndexRange (i, this->table_size[0]);
2559  AssertIndexRange (j, this->table_size[1]);
2560  return this->values[size_type(i)*this->table_size[1]+j];
2561 }
2562 
2563 
2564 
2565 template <typename T>
2566 inline
2567 typename AlignedVector<T>::const_reference
2568 Table<2,T>::operator () (const TableIndices<2> &indices) const
2569 {
2570  return TableBase<2,T>::operator () (indices);
2571 }
2572 
2573 
2574 
2575 template <typename T>
2576 inline
2577 typename AlignedVector<T>::reference
2579 {
2580  return TableBase<2,T>::operator () (indices);
2581 }
2582 
2583 
2584 
2585 template <typename T>
2586 inline
2587 typename AlignedVector<T>::const_reference
2588 Table<2,T>::el (const size_type i,
2589  const size_type j) const
2590 {
2591  return this->values[size_type(i)*this->table_size[1]+j];
2592 }
2593 
2594 
2595 
2596 template <typename T>
2597 inline
2598 typename AlignedVector<T>::reference
2599 Table<2,T>::el (const size_type i,
2600  const size_type j)
2601 {
2602  return this->values[size_type(i)*this->table_size[1]+j];
2603 }
2604 
2605 
2606 
2607 template <typename T>
2608 inline
2609 typename Table<2,T>::size_type
2610 Table<2,T>::n_rows () const
2611 {
2612  return this->table_size[0];
2613 }
2614 
2615 
2616 
2617 template <typename T>
2618 inline
2619 typename Table<2,T>::size_type
2620 Table<2,T>::n_cols () const
2621 {
2622  return this->table_size[1];
2623 }
2624 
2625 
2626 
2627 //---------------------------------------------------------------------------
2628 namespace TransposeTableIterators
2629 {
2630  template <typename T, bool Constness>
2631  inline
2633  :
2634  container(nullptr),
2635  linear_index(std::numeric_limits<decltype(linear_index)>::max())
2636  {}
2637 
2638 
2639 
2640  template <typename T, bool Constness>
2641  inline
2642  AccessorBase<T, Constness>::AccessorBase(const container_pointer_type table)
2643  :
2644  container(table),
2645  linear_index(container->values.size())
2646  {}
2647 
2648 
2649 
2650  template <typename T, bool Constness>
2651  inline
2652  AccessorBase<T, Constness>::AccessorBase(const AccessorBase<T, false> &a)
2653  :
2654  container(a.container),
2655  linear_index(a.linear_index)
2656  {}
2657 
2658 
2659 
2660  template <typename T, bool Constness>
2661  inline
2662  AccessorBase<T, Constness>::AccessorBase(const container_pointer_type table,
2663  const std::ptrdiff_t index)
2664  :
2665  container(table),
2666  linear_index(index)
2667  {
2668  Assert(0 <= linear_index && linear_index < container->values.size() + 1,
2669  ExcMessage("The current iterator points outside of the table and is "
2670  "not the end iterator."));
2671  }
2672 
2673 
2674 
2675  template <typename T, bool Constness>
2676  inline
2677  const T &
2678  AccessorBase<T, Constness>::value() const
2679  {
2680  Assert(0 <= linear_index && linear_index < container->values.size(),
2681  ExcMessage("The current iterator points outside of the table."));
2682  return this->container->values[linear_index];
2683  }
2684 
2685 
2686 
2687  template <typename T, bool Constness>
2688  inline
2689  typename AccessorBase<T, Constness>::size_type
2690  AccessorBase<T, Constness>::AccessorBase::row() const
2691  {
2692  Assert(!container->empty(), ExcMessage("An empty table has no rows or columns."));
2693  const auto row_n = linear_index % container->n_rows();
2694  Assert(0 <= row_n && row_n < container->n_rows(),
2695  ExcMessage("The current iterator points outside the table."));
2696  return row_n;
2697  }
2698 
2699 
2700 
2701  template <typename T, bool Constness>
2702  inline
2703  typename AccessorBase<T, Constness>::size_type
2704  AccessorBase<T, Constness>::AccessorBase::column() const
2705  {
2706  Assert(!container->empty(), ExcMessage("An empty table has no rows or columns."));
2707  const auto column_n = linear_index/container->n_rows();
2708  Assert(0 <= column_n && column_n < container->n_cols(),
2709  ExcMessage("The current iterator points outside the table."));
2710  return column_n;
2711  }
2712 
2713 
2714  template <typename T>
2715  inline
2716  const Accessor<T, false> &
2717  Accessor<T, false>::operator = (const T &t) const
2718  {
2719  Assert(0 <= this->linear_index && this->linear_index < this->container->values.size(),
2720  ExcMessage("The current iterator points outside of the table."));
2721  this->container->values[this->linear_index] = t;
2722  return *this;
2723  }
2724 
2725 
2726 
2727  template <typename T>
2728  inline
2729  const Accessor<T, false> &
2730  Accessor<T, false>::operator = (T &&t) const
2731  {
2732  Assert(0 <= this->linear_index && this->linear_index < this->container->values.size(),
2733  ExcMessage("The current iterator points outside of the table."));
2734  this->container->values[this->linear_index] = t;
2735  return *this;
2736  }
2737 
2738 
2739 
2740  template <typename T>
2741  inline
2742  T &
2743  Accessor<T, false>::value() const
2744  {
2745  Assert(0 <= this->linear_index && this->linear_index < this->container->values.size(),
2746  ExcMessage("The current iterator points outside of the table."));
2747  return this->container->values[this->linear_index];
2748  }
2749 
2750 
2751 
2752  template <typename T, bool Constness>
2753  Iterator<T, Constness>::Iterator(const Accessor<T, Constness> &a)
2754  :
2755  LinearIndexIterator<Iterator<T, Constness>, Accessor<T, Constness>>(a)
2756  {}
2757 
2758 
2759 
2760  template <typename T, bool Constness>
2761  Iterator<T, Constness>::Iterator(const container_pointer_type table)
2762  :
2763  LinearIndexIterator<Iterator<T, Constness>, Accessor<T, Constness>>(Accessor<T, Constness>(table))
2764  {}
2765 
2766 
2767 
2768  template <typename T, bool Constness>
2769  Iterator<T, Constness>::Iterator(const Iterator<T, false> &i)
2770  :
2771  LinearIndexIterator<Iterator<T, Constness>, Accessor<T, Constness>>(*i)
2772  {}
2773 
2774 
2775 
2776 
2777  template <typename T, bool Constness>
2778  Iterator<T, Constness>::Iterator(const container_pointer_type table,
2779  const size_type row_n,
2780  const size_type col_n)
2781  :
2782  Iterator(table, table->n_rows()*col_n + row_n)
2783  {}
2784 
2785 
2786 
2787  template <typename T, bool Constness>
2788  Iterator<T, Constness>::Iterator
2789  (const container_pointer_type table,
2790  const std::ptrdiff_t linear_index)
2791  :
2792  LinearIndexIterator<Iterator<T, Constness>, Accessor<T, Constness>>
2793  (Accessor<T, Constness>(table, linear_index))
2794  {}
2795 }
2796 
2797 
2798 
2799 //---------------------------------------------------------------------------
2800 template <typename T>
2801 inline
2802 TransposeTable<T>::TransposeTable (const size_type size1,
2803  const size_type size2)
2804  :
2805  TableBase<2,T> (TableIndices<2> (size2, size1))
2806 {}
2807 
2808 
2809 
2810 template <typename T>
2811 inline
2812 void
2813 TransposeTable<T>::reinit (const size_type size1,
2814  const size_type size2,
2815  const bool omit_default_initialization)
2816 {
2817  this->TableBase<2,T>::reinit (TableIndices<2> (size2, size1), omit_default_initialization);
2818 }
2819 
2820 
2821 
2822 template <typename T>
2823 inline
2825 TransposeTable<T>::operator () (const size_type i,
2826  const size_type j) const
2827 {
2828  AssertIndexRange (i, this->table_size[1]);
2829  AssertIndexRange (j, this->table_size[0]);
2830  return this->values[size_type(j)*this->table_size[1]+i];
2831 }
2832 
2833 
2834 
2835 template <typename T>
2836 inline
2838 TransposeTable<T>::operator () (const size_type i,
2839  const size_type j)
2840 {
2841  AssertIndexRange (i, this->table_size[1]);
2842  AssertIndexRange (j, this->table_size[0]);
2843  return this->values[size_type(j)*this->table_size[1]+i];
2844 }
2845 
2846 
2847 
2848 template <typename T>
2849 inline
2851 TransposeTable<T>::el (const size_type i,
2852  const size_type j) const
2853 {
2854  return this->values[size_type(j)*this->table_size[1]+i];
2855 }
2856 
2857 
2858 
2859 template <typename T>
2860 inline
2862 TransposeTable<T>::el (const size_type i,
2863  const size_type j)
2864 {
2865  return this->values[size_type(j)*this->table_size[1]+i];
2866 }
2867 
2868 
2869 
2870 template <typename T>
2871 inline
2874 {
2875  return this->table_size[1];
2876 }
2877 
2878 
2879 
2880 template <typename T>
2881 inline
2884 {
2885  return this->table_size[0];
2886 }
2887 
2888 
2889 
2890 template <typename T>
2891 inline
2894 {
2895  return typename TransposeTable<T>::iterator(this, 0, 0);
2896 }
2897 
2898 
2899 
2900 template <typename T>
2901 inline
2903 TransposeTable<T>::begin () const
2904 {
2905  return typename TransposeTable<T>::const_iterator(this, 0, 0);
2906 }
2907 
2908 
2909 
2910 template <typename T>
2911 inline
2914 {
2915  return typename TransposeTable<T>::iterator(this);
2916 }
2917 
2918 
2919 
2920 template <typename T>
2921 inline
2923 TransposeTable<T>::end () const
2924 {
2925  return typename TransposeTable<T>::const_iterator(this);
2926 }
2927 //---------------------------------------------------------------------------
2928 
2929 
2930 
2931 template <typename T>
2932 inline
2933 Table<3,T>::Table (const size_type size1,
2934  const size_type size2,
2935  const size_type size3)
2936  :
2937  TableBase<3,T> (TableIndices<3> (size1, size2, size3))
2938 {}
2939 
2940 
2941 
2942 template <typename T>
2943 template <typename InputIterator>
2944 inline
2945 Table<3,T>::Table (const size_type size1,
2946  const size_type size2,
2947  const size_type size3,
2948  InputIterator entries,
2949  const bool C_style_indexing)
2950  :
2951  TableBase<3,T> (TableIndices<3> (size1, size2, size3),
2952  entries,
2953  C_style_indexing)
2954 {}
2955 
2956 
2957 
2958 template <typename T>
2959 inline
2960 ::internal::TableBaseAccessors::Accessor<3,T,true,2>
2961 Table<3,T>::operator [] (const size_type i) const
2962 {
2963  AssertIndexRange (i, this->table_size[0]);
2964  const size_type subobject_size = size_type(this->table_size[1]) *
2965  this->table_size[2];
2966  return (::internal::TableBaseAccessors::Accessor<3,T,true,2>
2967  (*this,
2968  this->values.begin() + i*subobject_size));
2969 }
2970 
2971 
2972 
2973 template <typename T>
2974 inline
2975 ::internal::TableBaseAccessors::Accessor<3,T,false,2>
2976 Table<3,T>::operator [] (const size_type i)
2977 {
2978  AssertIndexRange (i, this->table_size[0]);
2979  const size_type subobject_size = size_type(this->table_size[1]) *
2980  this->table_size[2];
2981  return (::internal::TableBaseAccessors::Accessor<3,T,false,2>
2982  (*this,
2983  this->values.begin() + i*subobject_size));
2984 }
2985 
2986 
2987 
2988 template <typename T>
2989 inline
2990 typename AlignedVector<T>::const_reference
2991 Table<3,T>::operator () (const size_type i,
2992  const size_type j,
2993  const size_type k) const
2994 {
2995  AssertIndexRange (i, this->table_size[0]);
2996  AssertIndexRange (j, this->table_size[1]);
2997  AssertIndexRange (k, this->table_size[2]);
2998  return this->values[(size_type(i)*this->table_size[1]+j)
2999  *this->table_size[2] + k];
3000 }
3001 
3002 
3003 
3004 template <typename T>
3005 inline
3006 typename AlignedVector<T>::reference
3007 Table<3,T>::operator () (const size_type i,
3008  const size_type j,
3009  const size_type k)
3010 {
3011  AssertIndexRange (i, this->table_size[0]);
3012  AssertIndexRange (j, this->table_size[1]);
3013  AssertIndexRange (k, this->table_size[2]);
3014  return this->values[(size_type(i)*this->table_size[1]+j)
3015  *this->table_size[2] + k];
3016 }
3017 
3018 
3019 
3020 template <typename T>
3021 inline
3022 typename AlignedVector<T>::const_reference
3023 Table<3,T>::operator () (const TableIndices<3> &indices) const
3024 {
3025  return TableBase<3,T>::operator () (indices);
3026 }
3027 
3028 
3029 
3030 template <typename T>
3031 inline
3032 typename AlignedVector<T>::reference
3034 {
3035  return TableBase<3,T>::operator () (indices);
3036 }
3037 
3038 
3039 
3040 template <typename T>
3041 inline
3042 Table<4,T>::Table (const size_type size1,
3043  const size_type size2,
3044  const size_type size3,
3045  const size_type size4)
3046  :
3047  TableBase<4,T> (TableIndices<4> (size1, size2, size3, size4))
3048 {}
3049 
3050 
3051 
3052 template <typename T>
3053 inline
3054 ::internal::TableBaseAccessors::Accessor<4,T,true,3>
3055 Table<4,T>::operator [] (const size_type i) const
3056 {
3057  AssertIndexRange (i, this->table_size[0]);
3058  const size_type subobject_size = size_type(this->table_size[1]) *
3059  this->table_size[2] *
3060  this->table_size[3];
3061  return (::internal::TableBaseAccessors::Accessor<4,T,true,3>
3062  (*this,
3063  this->values.begin() + i*subobject_size));
3064 }
3065 
3066 
3067 
3068 template <typename T>
3069 inline
3070 ::internal::TableBaseAccessors::Accessor<4,T,false,3>
3071 Table<4,T>::operator [] (const size_type i)
3072 {
3073  AssertIndexRange (i, this->table_size[0]);
3074  const size_type subobject_size = size_type(this->table_size[1]) *
3075  this->table_size[2] *
3076  this->table_size[3];
3077  return (::internal::TableBaseAccessors::Accessor<4,T,false,3>
3078  (*this,
3079  this->values.begin() + i*subobject_size));
3080 }
3081 
3082 
3083 
3084 template <typename T>
3085 inline
3086 typename AlignedVector<T>::const_reference
3087 Table<4,T>::operator () (const size_type i,
3088  const size_type j,
3089  const size_type k,
3090  const size_type l) const
3091 {
3092  AssertIndexRange (i, this->table_size[0]);
3093  AssertIndexRange (j, this->table_size[1]);
3094  AssertIndexRange (k, this->table_size[2]);
3095  AssertIndexRange (l, this->table_size[3]);
3096  return this->values[((size_type(i)*this->table_size[1]+j)
3097  *this->table_size[2] + k)
3098  *this->table_size[3] + l];
3099 }
3100 
3101 
3102 
3103 template <typename T>
3104 inline
3105 typename AlignedVector<T>::reference
3106 Table<4,T>::operator () (const size_type i,
3107  const size_type j,
3108  const size_type k,
3109  const size_type l)
3110 {
3111  AssertIndexRange (i, this->table_size[0]);
3112  AssertIndexRange (j, this->table_size[1]);
3113  AssertIndexRange (k, this->table_size[2]);
3114  AssertIndexRange (l, this->table_size[3]);
3115  return this->values[((size_type(i)*this->table_size[1]+j)
3116  *this->table_size[2] + k)
3117  *this->table_size[3] + l];
3118 }
3119 
3120 
3121 
3122 template <typename T>
3123 inline
3124 typename AlignedVector<T>::const_reference
3125 Table<4,T>::operator () (const TableIndices<4> &indices) const
3126 {
3127  return TableBase<4,T>::operator () (indices);
3128 }
3129 
3130 
3131 
3132 template <typename T>
3133 inline
3134 typename AlignedVector<T>::reference
3136 {
3137  return TableBase<4,T>::operator () (indices);
3138 }
3139 
3140 
3141 
3142 template <typename T>
3143 inline
3144 Table<5,T>::Table (const size_type size1,
3145  const size_type size2,
3146  const size_type size3,
3147  const size_type size4,
3148  const size_type size5)
3149  :
3150  TableBase<5,T> (TableIndices<5> (size1, size2, size3, size4, size5))
3151 {}
3152 
3153 
3154 
3155 template <typename T>
3156 inline
3157 ::internal::TableBaseAccessors::Accessor<5,T,true,4>
3158 Table<5,T>::operator [] (const size_type i) const
3159 {
3160  AssertIndexRange (i, this->table_size[0]);
3161  const size_type subobject_size = size_type(this->table_size[1]) *
3162  this->table_size[2] *
3163  this->table_size[3] *
3164  this->table_size[4];
3165  return (::internal::TableBaseAccessors::Accessor<5,T,true,4>
3166  (*this,
3167  this->values.begin() + i*subobject_size));
3168 }
3169 
3170 
3171 
3172 template <typename T>
3173 inline
3174 ::internal::TableBaseAccessors::Accessor<5,T,false,4>
3175 Table<5,T>::operator [] (const size_type i)
3176 {
3177  AssertIndexRange (i, this->table_size[0]);
3178  const size_type subobject_size = size_type(this->table_size[1]) *
3179  this->table_size[2] *
3180  this->table_size[3] *
3181  this->table_size[4];
3182  return (::internal::TableBaseAccessors::Accessor<5,T,false,4>
3183  (*this,
3184  this->values.begin() + i*subobject_size));
3185 }
3186 
3187 
3188 
3189 template <typename T>
3190 inline
3191 typename AlignedVector<T>::const_reference
3192 Table<5,T>::operator () (const size_type i,
3193  const size_type j,
3194  const size_type k,
3195  const size_type l,
3196  const size_type m) const
3197 {
3198  AssertIndexRange (i, this->table_size[0]);
3199  AssertIndexRange (j, this->table_size[1]);
3200  AssertIndexRange (k, this->table_size[2]);
3201  AssertIndexRange (l, this->table_size[3]);
3202  AssertIndexRange (m, this->table_size[4]);
3203  return this->values[(((size_type(i)*this->table_size[1]+j)
3204  *this->table_size[2] + k)
3205  *this->table_size[3] + l)
3206  *this->table_size[4] + m];
3207 }
3208 
3209 
3210 
3211 template <typename T>
3212 inline
3213 typename AlignedVector<T>::reference
3214 Table<5,T>::operator () (const size_type i,
3215  const size_type j,
3216  const size_type k,
3217  const size_type l,
3218  const size_type m)
3219 {
3220  AssertIndexRange (i, this->table_size[0]);
3221  AssertIndexRange (j, this->table_size[1]);
3222  AssertIndexRange (k, this->table_size[2]);
3223  AssertIndexRange (l, this->table_size[3]);
3224  AssertIndexRange (m, this->table_size[4]);
3225  return this->values[(((size_type(i)*this->table_size[1]+j)
3226  *this->table_size[2] + k)
3227  *this->table_size[3] + l)
3228  *this->table_size[4] + m];
3229 }
3230 
3231 
3232 
3233 template <typename T>
3234 inline
3235 typename AlignedVector<T>::const_reference
3236 Table<5,T>::operator () (const TableIndices<5> &indices) const
3237 {
3238  return TableBase<5,T>::operator () (indices);
3239 }
3240 
3241 
3242 
3243 template <typename T>
3244 inline
3245 typename AlignedVector<T>::reference
3247 {
3248  return TableBase<5,T>::operator () (indices);
3249 }
3250 
3251 
3252 
3253 template <typename T>
3254 inline
3255 Table<6,T>::Table (const size_type size1,
3256  const size_type size2,
3257  const size_type size3,
3258  const size_type size4,
3259  const size_type size5,
3260  const size_type size6)
3261  :
3262  TableBase<6,T> ()
3263 {
3264  TableIndices<6> table_indices;
3265  table_indices[0] = size1;
3266  table_indices[1] = size2;
3267  table_indices[2] = size3;
3268  table_indices[3] = size4;
3269  table_indices[4] = size5;
3270  table_indices[5] = size6;
3271 
3272  TableBase<6,T>::reinit(table_indices);
3273 }
3274 
3275 
3276 
3277 template <typename T>
3278 inline
3279 ::internal::TableBaseAccessors::Accessor<6,T,true,5>
3280 Table<6,T>::operator [] (const size_type i) const
3281 {
3282  AssertIndexRange (i, this->table_size[0]);
3283  const size_type subobject_size = size_type(this->table_size[1]) *
3284  this->table_size[2] *
3285  this->table_size[3] *
3286  this->table_size[4] *
3287  this->table_size[5];
3288  return (::internal::TableBaseAccessors::Accessor<6,T,true,5>
3289  (*this,
3290  this->values.begin() + i*subobject_size));
3291 }
3292 
3293 
3294 
3295 template <typename T>
3296 inline
3297 ::internal::TableBaseAccessors::Accessor<6,T,false,5>
3298 Table<6,T>::operator [] (const size_type i)
3299 {
3300  AssertIndexRange (i, this->table_size[0]);
3301  const size_type subobject_size = size_type(this->table_size[1]) *
3302  this->table_size[2] *
3303  this->table_size[3] *
3304  this->table_size[4] *
3305  this->table_size[5];
3306  return (::internal::TableBaseAccessors::Accessor<6,T,false,5>
3307  (*this,
3308  this->values.begin() + i*subobject_size));
3309 }
3310 
3311 
3312 
3313 template <typename T>
3314 inline
3315 typename AlignedVector<T>::const_reference
3316 Table<6,T>::operator () (const size_type i,
3317  const size_type j,
3318  const size_type k,
3319  const size_type l,
3320  const size_type m,
3321  const size_type n) const
3322 {
3323  AssertIndexRange (i, this->table_size[0]);
3324  AssertIndexRange (j, this->table_size[1]);
3325  AssertIndexRange (k, this->table_size[2]);
3326  AssertIndexRange (l, this->table_size[3]);
3327  AssertIndexRange (m, this->table_size[4]);
3328  AssertIndexRange (n, this->table_size[5]);
3329  return this->values[((((size_type(i)*this->table_size[1]+j)
3330  *this->table_size[2] + k)
3331  *this->table_size[3] + l)
3332  *this->table_size[4] + m)
3333  *this->table_size[5] + n];
3334 }
3335 
3336 
3337 
3338 template <typename T>
3339 inline
3340 typename AlignedVector<T>::reference
3341 Table<6,T>::operator () (const size_type i,
3342  const size_type j,
3343  const size_type k,
3344  const size_type l,
3345  const size_type m,
3346  const size_type n)
3347 {
3348  AssertIndexRange (i, this->table_size[0]);
3349  AssertIndexRange (j, this->table_size[1]);
3350  AssertIndexRange (k, this->table_size[2]);
3351  AssertIndexRange (l, this->table_size[3]);
3352  AssertIndexRange (m, this->table_size[4]);
3353  AssertIndexRange (n, this->table_size[5]);
3354  return this->values[((((size_type(i)*this->table_size[1]+j)
3355  *this->table_size[2] + k)
3356  *this->table_size[3] + l)
3357  *this->table_size[4] + m)
3358  *this->table_size[5] + n];
3359 }
3360 
3361 
3362 
3363 template <typename T>
3364 inline
3365 typename AlignedVector<T>::const_reference
3366 Table<6,T>::operator () (const TableIndices<6> &indices) const
3367 {
3368  return TableBase<6,T>::operator () (indices);
3369 }
3370 
3371 
3372 
3373 template <typename T>
3374 inline
3375 typename AlignedVector<T>::reference
3377 {
3378  return TableBase<6,T>::operator () (indices);
3379 }
3380 
3381 
3382 
3383 template <typename T>
3384 inline
3385 Table<7,T>::Table (const size_type size1,
3386  const size_type size2,
3387  const size_type size3,
3388  const size_type size4,
3389  const size_type size5,
3390  const size_type size6,
3391  const size_type size7)
3392  :
3393  TableBase<7,T> ()
3394 {
3395  TableIndices<7> table_indices;
3396  table_indices[0] = size1;
3397  table_indices[1] = size2;
3398  table_indices[2] = size3;
3399  table_indices[3] = size4;
3400  table_indices[4] = size5;
3401  table_indices[5] = size6;
3402  table_indices[6] = size7;
3403 
3404  TableBase<7,T>::reinit(table_indices);
3405 }
3406 
3407 
3408 
3409 template <typename T>
3410 inline
3411 ::internal::TableBaseAccessors::Accessor<7,T,true,6>
3412 Table<7,T>::operator [] (const size_type i) const
3413 {
3414  AssertIndexRange (i, this->table_size[0]);
3415  const size_type subobject_size = size_type(this->table_size[1]) *
3416  this->table_size[2] *
3417  this->table_size[3] *
3418  this->table_size[4] *
3419  this->table_size[5] *
3420  this->table_size[6];
3421  return (::internal::TableBaseAccessors::Accessor<7,T,true,6>
3422  (*this,
3423  this->values.begin() + i*subobject_size));
3424 }
3425 
3426 
3427 
3428 template <typename T>
3429 inline
3430 ::internal::TableBaseAccessors::Accessor<7,T,false,6>
3431 Table<7,T>::operator [] (const size_type i)
3432 {
3433  AssertIndexRange (i, this->table_size[0]);
3434  const size_type subobject_size = size_type(this->table_size[1]) *
3435  this->table_size[2] *
3436  this->table_size[3] *
3437  this->table_size[4] *
3438  this->table_size[5] *
3439  this->table_size[6];
3440  return (::internal::TableBaseAccessors::Accessor<7,T,false,6>
3441  (*this,
3442  this->values.begin() + i*subobject_size));
3443 }
3444 
3445 
3446 
3447 template <typename T>
3448 inline
3449 typename AlignedVector<T>::const_reference
3450 Table<7,T>::operator () (const size_type i,
3451  const size_type j,
3452  const size_type k,
3453  const size_type l,
3454  const size_type m,
3455  const size_type n,
3456  const size_type o) const
3457 {
3458  AssertIndexRange (i, this->table_size[0]);
3459  AssertIndexRange (j, this->table_size[1]);
3460  AssertIndexRange (k, this->table_size[2]);
3461  AssertIndexRange (l, this->table_size[3]);
3462  AssertIndexRange (m, this->table_size[4]);
3463  AssertIndexRange (n, this->table_size[5]);
3464  AssertIndexRange (o, this->table_size[6]);
3465  return this->values[(((((size_type(i)*this->table_size[1]+j)
3466  *this->table_size[2] + k)
3467  *this->table_size[3] + l)
3468  *this->table_size[4] + m)
3469  *this->table_size[5] + n)
3470  *this->table_size[6] + o];
3471 }
3472 
3473 
3474 
3475 template <typename T>
3476 inline
3477 typename AlignedVector<T>::reference
3478 Table<7,T>::operator () (const size_type i,
3479  const size_type j,
3480  const size_type k,
3481  const size_type l,
3482  const size_type m,
3483  const size_type n,
3484  const size_type o)
3485 {
3486  AssertIndexRange (i, this->table_size[0]);
3487  AssertIndexRange (j, this->table_size[1]);
3488  AssertIndexRange (k, this->table_size[2]);
3489  AssertIndexRange (l, this->table_size[3]);
3490  AssertIndexRange (m, this->table_size[4]);
3491  AssertIndexRange (n, this->table_size[5]);
3492  AssertIndexRange (o, this->table_size[6]);
3493  return this->values[(((((size_type(i)*this->table_size[1]+j)
3494  *this->table_size[2] + k)
3495  *this->table_size[3] + l)
3496  *this->table_size[4] + m)
3497  *this->table_size[5] + n)
3498  *this->table_size[6] + o];
3499 }
3500 
3501 
3502 
3503 template <typename T>
3504 inline
3505 typename AlignedVector<T>::const_reference
3506 Table<7,T>::operator () (const TableIndices<7> &indices) const
3507 {
3508  return TableBase<7,T>::operator () (indices);
3509 }
3510 
3511 
3512 
3513 template <typename T>
3514 inline
3515 typename AlignedVector<T>::reference
3517 {
3518  return TableBase<7,T>::operator () (indices);
3519 }
3520 
3521 
3522 #endif // DOXYGEN
3523 
3524 
3525 
3533 template <int N, typename T>
3534 inline
3535 void swap (TableBase<N,T> &u, TableBase<N,T> &v)
3536 {
3537  u.swap (v);
3538 }
3539 
3540 DEAL_II_NAMESPACE_CLOSE
3541 
3542 #endif
bool operator==(const TableBase< N, T > &T2) const
AlignedVector< T >::value_type value_type
Definition: table.h:1725
TransposeTableIterators::Iterator< T, false > iterator
Definition: table.h:1746
TableBase< 6, T >::size_type size_type
Definition: table.h:1325
size_type position(const TableIndices< N > &indices) const
void serialize(Archive &ar, const unsigned int version)
void swap(TableBase< N, T > &v)
AlignedVector< T >::reference reference
Definition: table.h:1730
TransposeTableIterators::Iterator< T, true > const_iterator
Definition: table.h:1741
const TableIndices< N > & size() const
size_type n_cols() const
~TableBase()=default
#define AssertIndexRange(index, range)
Definition: exceptions.h:1284
size_type n_rows() const
std::conditional< Constness, const TransposeTable< T > *, TransposeTable< T > * >::type container_pointer_type
Definition: table.h:1533
TableBase< N, T > & operator=(const TableBase< N, T > &src)
STL namespace.
TableBase< 7, T >::size_type size_type
Definition: table.h:1421
Iterator(const Accessor< T, Constness > &accessor)
TableBase< 4, T >::size_type size_type
Definition: table.h:1138
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
size_type n_elements() const
SymmetricTensor< 2, dim, Number > C(const Tensor< 2, dim, Number > &F)
std::conditional< Constness, const TransposeTable< T > *, TransposeTable< T > * >::type container_pointer_type
Definition: table.h:1667
TransposeTable< T >::size_type size_type
Definition: table.h:1566
TableBase< 2, T >::size_type size_type
Definition: table.h:819
container_pointer_type container
Definition: table.h:1582
static ::ExceptionBase & ExcMessage(std::string arg1)
TableBase< 5, T >::size_type size_type
Definition: table.h:1230
TableBase< 2, T >::size_type size_type
Definition: table.h:1720
iterator end()
void swap(BlockIndices &u, BlockIndices &v)
iterator begin()
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
#define Assert(cond, exc)
Definition: exceptions.h:1142
void reinit(const size_type size1, const size_type size2, const bool omit_default_initialization=false)
AlignedVector< T >::reference el(const TableIndices< N > &indices)
TableBase()=default
AlignedVector< T >::const_reference const_reference
Definition: table.h:1735
void swap(Vector< Number > &u, Vector< Number > &v)
Definition: vector.h:1312
TransposeTable< T >::size_type size_type
Definition: table.h:1661
size_type size(const unsigned int i) const
std::size_t memory_consumption() const
void reset_values()
TableBase< 3, T >::size_type size_type
Definition: table.h:1004
TransposeTable()=default
reference el(const size_type i, const size_type j)
static ::ExceptionBase & ExcNotImplemented()
Definition: table.h:34
bool empty() const
TableIndices< N > table_size
Definition: table.h:653
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:370
AlignedVector< T >::size_type size_type
Definition: table.h:413
const_reference operator()(const size_type i, const size_type j) const
TableBase< 1, T >::size_type size_type
Definition: table.h:700
AlignedVector< T >::reference operator()(const TableIndices< N > &indices)
AlignedVector< T > values
Definition: table.h:648
void fill(InputIterator entries, const bool C_style_indexing=true)
T max(const T &t, const MPI_Comm &mpi_communicator)
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)