Reference documentation for deal.II version 8.4.1
table.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2002 - 2016 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 
26 #include <cstddef>
27 #include <algorithm>
28 
29 DEAL_II_NAMESPACE_OPEN
30 
31 // forward declaration
32 template <int N, typename T> class TableBase;
33 template <int N, typename T> class Table;
34 template <typename T> class Table<1,T>;
35 template <typename T> class Table<2,T>;
36 template <typename T> class Table<3,T>;
37 template <typename T> class Table<4,T>;
38 template <typename T> class Table<5,T>;
39 template <typename T> class Table<6,T>;
40 
41 
42 
43 namespace internal
44 {
45 
62  namespace TableBaseAccessors
63  {
71  template <int N, typename T, bool Constness>
72  struct Types
73  {};
74 
80  template <int N, typename T> struct Types<N,T,true>
81  {
82  typedef const T value_type;
83  typedef const TableBase<N,T> TableType;
84 
85  typedef typename AlignedVector<T>::const_iterator iterator;
86  typedef typename AlignedVector<T>::const_iterator const_iterator;
87 
88  typedef typename AlignedVector<T>::const_reference reference;
89  typedef typename AlignedVector<T>::const_reference const_reference;
90  };
91 
97  template <int N, typename T> struct Types<N,T,false>
98  {
99  typedef T value_type;
100  typedef TableBase<N,T> TableType;
101 
102  typedef typename AlignedVector<T>::iterator iterator;
103  typedef typename AlignedVector<T>::const_iterator const_iterator;
104 
105  typedef typename AlignedVector<T>::reference reference;
106  typedef typename AlignedVector<T>::const_reference const_reference;
107  };
108 
109 
148  template <int N, typename T, bool C, unsigned int P>
149  class Accessor
150  {
151  public:
152  typedef typename Types<N,T,C>::TableType TableType;
153 
154  typedef typename Types<N,T,C>::iterator iterator;
155  typedef typename Types<N,T,C>::const_iterator const_iterator;
156 
157  typedef size_t size_type;
158  typedef ptrdiff_t difference_type;
159  private:
165  Accessor (const TableType &table,
166  const iterator data);
167 
171  Accessor ();
172 
173  public:
174 
182  Accessor (const Accessor &a);
183 
187  Accessor<N,T,C,P-1> operator [] (const unsigned int i) const;
188 
193  DeclException3 (ExcIndexRange, int, int, int,
194  << "Index " << N-P+1 << "has a value of "
195  << arg1 << " but needs to be in the range ["
196  << arg2 << "," << arg3 << "[.");
197  private:
203  const TableType &table;
204  const iterator data;
205 
206  // declare some other classes
207  // as friends. make sure to
208  // work around bugs in some
209  // compilers
210  template <int N1, typename T1> friend class ::Table;
211  template <int N1, typename T1, bool C1, unsigned int P1>
212  friend class Accessor;
213 # ifndef DEAL_II_TEMPL_SPEC_FRIEND_BUG
214  friend class ::Table<N,T>;
215  friend class Accessor<N,T,C,P+1>;
216 # endif
217  };
218 
219 
220 
230  template <int N, typename T, bool C>
231  class Accessor<N,T,C,1>
232  {
233  public:
239  typedef typename Types<N,T,C>::value_type value_type;
240 
241  typedef typename Types<N,T,C>::iterator iterator;
242  typedef typename Types<N,T,C>::const_iterator const_iterator;
243 
244  typedef typename Types<N,T,C>::reference reference;
245  typedef typename Types<N,T,C>::const_reference const_reference;
246 
247  typedef size_t size_type;
248  typedef ptrdiff_t difference_type;
249 
253  typedef typename Types<N,T,C>::TableType TableType;
254 
255  private:
256 
268  Accessor (const TableType &table,
269  const iterator data);
270 
274  Accessor ();
275 
276  public:
284  Accessor (const Accessor &a);
285 
286 
290  reference operator [] (const unsigned int) const;
291 
296  unsigned int size () const;
297 
301  iterator begin () const;
302 
306  iterator end () const;
307 
308  private:
314  const TableType &table;
315  const iterator data;
316 
317  // declare some other classes
318  // as friends. make sure to
319  // work around bugs in some
320  // compilers
321  template <int N1, typename T1> friend class ::Table;
322  template <int N1, typename T1, bool C1, unsigned int P1>
323  friend class Accessor;
324 # ifndef DEAL_II_TEMPL_SPEC_FRIEND_BUG
325  friend class ::Table<2,T>;
326  friend class Accessor<N,T,C,2>;
327 # endif
328  };
329  }
330 
331 } // namespace internal
332 
333 
334 
335 
402 template <int N, typename T>
403 class TableBase : public Subscriptor
404 {
405 public:
406  typedef T value_type;
407 
411  typedef typename AlignedVector<T>::size_type size_type;
412 
413 
417  TableBase ();
418 
423  TableBase (const TableIndices<N> &sizes);
424 
430  template <typename InputIterator>
431  TableBase (const TableIndices<N> &sizes,
432  InputIterator entries,
433  const bool C_style_indexing = true);
434 
438  TableBase (const TableBase<N,T> &src);
439 
444  template <typename T2>
445  TableBase (const TableBase<N,T2> &src);
446 
450  ~TableBase ();
451 
461 
469  template<typename T2>
471 
475  bool operator == (const TableBase<N,T> &T2) const;
476 
481  void reset_values ();
482 
491  void reinit (const TableIndices<N> &new_size,
492  const bool omit_default_initialization = false);
493 
497  unsigned int size (const unsigned int i) const;
498 
502  const TableIndices<N> &size () const;
503 
508  size_type n_elements () const;
509 
514  bool empty () const;
515 
552  template <typename InputIterator>
553  void fill (InputIterator entries,
554  const bool C_style_indexing = true);
555 
559  void fill (const T &value);
560 
564  typename AlignedVector<T>::reference
565  operator () (const TableIndices<N> &indices);
566 
574  typename AlignedVector<T>::const_reference
575  operator () (const TableIndices<N> &indices) const;
576 
588  void swap (TableBase<N,T> &v);
589 
594  std::size_t memory_consumption () const;
595 
600  template <class Archive>
601  void serialize (Archive &ar, const unsigned int version);
602 
603 protected:
608  size_type position (const TableIndices<N> &indices) const;
609 
616  typename AlignedVector<T>::reference el (const TableIndices<N> &indices);
617 
628  typename AlignedVector<T>::const_reference el (const TableIndices<N> &indices) const;
629 
630 protected:
635 
640 
644  template <int, typename> friend class TableBase;
645 };
646 
647 
661 template <int N,typename T>
662 class Table : public TableBase<N,T>
663 {
664 };
665 
666 
679 template <typename T>
680 class Table<1,T> : public TableBase<1,T>
681 {
682 public:
687 
691  Table ();
692 
696  Table (const unsigned int size);
697 
735  template <typename InputIterator>
736  Table (const unsigned int size,
737  InputIterator entries,
738  const bool C_style_indexing = true);
739 
744  typename AlignedVector<T>::const_reference
745  operator [] (const unsigned int i) const;
746 
751  typename AlignedVector<T>::reference
752  operator [] (const unsigned int i);
753 
758  typename AlignedVector<T>::const_reference
759  operator () (const unsigned int i) const;
760 
765  typename AlignedVector<T>::reference
766  operator () (const unsigned int i);
767 
772  typename AlignedVector<T>::reference
773  operator () (const TableIndices<1> &indices);
774 
779  typename AlignedVector<T>::const_reference
780  operator () (const TableIndices<1> &indices) const;
781 };
782 
783 
784 
798 template <typename T>
799 class Table<2,T> : public TableBase<2,T>
800 {
801 public:
806 
810  Table ();
811 
815  Table (const unsigned int size1,
816  const unsigned int size2);
817 
856  template <typename InputIterator>
857  Table (const unsigned int size1,
858  const unsigned int size2,
859  InputIterator entries,
860  const bool C_style_indexing = true);
861 
867  void reinit (const unsigned int size1,
868  const unsigned int size2,
869  const bool omit_default_initialization = false);
870 
872 
879  ::internal::TableBaseAccessors::Accessor<2,T,true,1>
880  operator [] (const unsigned int i) const;
881 
888  ::internal::TableBaseAccessors::Accessor<2,T,false,1>
889  operator [] (const unsigned int i);
890 
897  typename AlignedVector<T>::const_reference
898  operator () (const unsigned int i,
899  const unsigned int j) const;
900 
901 
908  typename AlignedVector<T>::reference
909  operator () (const unsigned int i,
910  const unsigned int j);
911 
916  typename AlignedVector<T>::reference
917  operator () (const TableIndices<2> &indices);
918 
923  typename AlignedVector<T>::const_reference
924  operator () (const TableIndices<2> &indices) const;
925 
926 
931  unsigned int n_rows () const;
932 
937  unsigned int n_cols () const;
938 
939 protected:
950  typename AlignedVector<T>::reference el (const unsigned int i,
951  const unsigned int j);
952 
967  typename AlignedVector<T>::const_reference el (const unsigned int i,
968  const unsigned int j) const;
969 };
970 
971 
972 
983 template <typename T>
984 class Table<3,T> : public TableBase<3,T>
985 {
986 public:
991 
995  Table ();
996 
1000  Table (const unsigned int size1,
1001  const unsigned int size2,
1002  const unsigned int size3);
1003 
1044  template <typename InputIterator>
1045  Table (const unsigned int size1,
1046  const unsigned int size2,
1047  const unsigned int size3,
1048  InputIterator entries,
1049  const bool C_style_indexing = true);
1050 
1058  ::internal::TableBaseAccessors::Accessor<3,T,true,2>
1059  operator [] (const unsigned int i) const;
1060 
1068  ::internal::TableBaseAccessors::Accessor<3,T,false,2>
1069  operator [] (const unsigned int i);
1070 
1077  typename AlignedVector<T>::const_reference operator () (const unsigned int i,
1078  const unsigned int j,
1079  const unsigned int k) const;
1080 
1081 
1088  typename AlignedVector<T>::reference operator () (const unsigned int i,
1089  const unsigned int j,
1090  const unsigned int k);
1091 
1096  typename AlignedVector<T>::reference operator () (const TableIndices<3> &indices);
1097 
1102  typename AlignedVector<T>::const_reference operator () (const TableIndices<3> &indices) const;
1103 };
1104 
1105 
1106 
1117 template <typename T>
1118 class Table<4,T> : public TableBase<4,T>
1119 {
1120 public:
1125 
1129  Table ();
1130 
1134  Table (const unsigned int size1,
1135  const unsigned int size2,
1136  const unsigned int size3,
1137  const unsigned int size4);
1138 
1146  ::internal::TableBaseAccessors::Accessor<4,T,true,3>
1147  operator [] (const unsigned int i) const;
1148 
1156  ::internal::TableBaseAccessors::Accessor<4,T,false,3>
1157  operator [] (const unsigned int i);
1158 
1165  typename AlignedVector<T>::const_reference operator () (const unsigned int i,
1166  const unsigned int j,
1167  const unsigned int k,
1168  const unsigned int l) const;
1169 
1170 
1177  typename AlignedVector<T>::reference operator () (const unsigned int i,
1178  const unsigned int j,
1179  const unsigned int k,
1180  const unsigned int l);
1181 
1186  typename AlignedVector<T>::reference
1187  operator () (const TableIndices<4> &indices);
1188 
1193  typename AlignedVector<T>::const_reference
1194  operator () (const TableIndices<4> &indices) const;
1195 };
1196 
1197 
1198 
1209 template <typename T>
1210 class Table<5,T> : public TableBase<5,T>
1211 {
1212 public:
1217 
1218 
1222  Table ();
1223 
1227  Table (const unsigned int size1,
1228  const unsigned int size2,
1229  const unsigned int size3,
1230  const unsigned int size4,
1231  const unsigned int size5);
1232 
1240  ::internal::TableBaseAccessors::Accessor<5,T,true,4>
1241  operator [] (const unsigned int i) const;
1242 
1250  ::internal::TableBaseAccessors::Accessor<5,T,false,4>
1251  operator [] (const unsigned int i);
1252 
1259  typename AlignedVector<T>::const_reference operator () (const unsigned int i,
1260  const unsigned int j,
1261  const unsigned int k,
1262  const unsigned int l,
1263  const unsigned int m) const;
1264 
1271  typename AlignedVector<T>::reference operator () (const unsigned int i,
1272  const unsigned int j,
1273  const unsigned int k,
1274  const unsigned int l,
1275  const unsigned int m);
1276 
1281  typename AlignedVector<T>::reference
1282  operator () (const TableIndices<5> &indices);
1283 
1288  typename AlignedVector<T>::const_reference
1289  operator () (const TableIndices<5> &indices) const;
1290 };
1291 
1292 
1293 
1304 template <typename T>
1305 class Table<6,T> : public TableBase<6,T>
1306 {
1307 public:
1312 
1316  Table ();
1317 
1321  Table (const unsigned int size1,
1322  const unsigned int size2,
1323  const unsigned int size3,
1324  const unsigned int size4,
1325  const unsigned int size5,
1326  const unsigned int size6);
1327 
1335  ::internal::TableBaseAccessors::Accessor<6,T,true,5>
1336  operator [] (const unsigned int i) const;
1337 
1345  ::internal::TableBaseAccessors::Accessor<6,T,false,5>
1346  operator [] (const unsigned int i);
1347 
1354  typename AlignedVector<T>::const_reference operator () (const unsigned int i,
1355  const unsigned int j,
1356  const unsigned int k,
1357  const unsigned int l,
1358  const unsigned int m,
1359  const unsigned int n) const;
1360 
1367  typename AlignedVector<T>::reference operator () (const unsigned int i,
1368  const unsigned int j,
1369  const unsigned int k,
1370  const unsigned int l,
1371  const unsigned int m,
1372  const unsigned int n);
1373 
1378  typename AlignedVector<T>::reference
1379  operator () (const TableIndices<6> &indices);
1380 
1385  typename AlignedVector<T>::const_reference
1386  operator () (const TableIndices<6> &indices) const;
1387 };
1388 
1389 
1400 template <typename T>
1401 class Table<7,T> : public TableBase<7,T>
1402 {
1403 public:
1408 
1412  Table ();
1413 
1417  Table (const unsigned int size1,
1418  const unsigned int size2,
1419  const unsigned int size3,
1420  const unsigned int size4,
1421  const unsigned int size5,
1422  const unsigned int size6,
1423  const unsigned int size7);
1424 
1432  ::internal::TableBaseAccessors::Accessor<7,T,true,6>
1433  operator [] (const unsigned int i) const;
1434 
1442  ::internal::TableBaseAccessors::Accessor<7,T,false,6>
1443  operator [] (const unsigned int i);
1444 
1451  typename AlignedVector<T>::const_reference operator () (const unsigned int i,
1452  const unsigned int j,
1453  const unsigned int k,
1454  const unsigned int l,
1455  const unsigned int m,
1456  const unsigned int n,
1457  const unsigned int o) const;
1458 
1465  typename AlignedVector<T>::reference operator () (const unsigned int i,
1466  const unsigned int j,
1467  const unsigned int k,
1468  const unsigned int l,
1469  const unsigned int m,
1470  const unsigned int n,
1471  const unsigned int o);
1472 
1477  typename AlignedVector<T>::reference
1478  operator () (const TableIndices<7> &indices);
1479 
1484  typename AlignedVector<T>::const_reference
1485  operator () (const TableIndices<7> &indices) const;
1486 };
1487 
1488 
1489 
1503 template <typename T>
1504 class TransposeTable : public TableBase<2,T>
1505 {
1506 public:
1511 
1515  TransposeTable ();
1516 
1520  TransposeTable (const unsigned int size1,
1521  const unsigned int size2);
1522 
1528  void reinit (const unsigned int size1,
1529  const unsigned int size2,
1530  const bool omit_default_initialization = false);
1531 
1538  typename AlignedVector<T>::const_reference operator () (const unsigned int i,
1539  const unsigned int j) const;
1540 
1547  typename AlignedVector<T>::reference operator () (const unsigned int i,
1548  const unsigned int j);
1549 
1554  unsigned int n_rows () const;
1555 
1560  unsigned int n_cols () const;
1561 
1562 protected:
1573  typename AlignedVector<T>::reference el (const unsigned int i,
1574  const unsigned int j);
1575 
1590  typename AlignedVector<T>::const_reference el (const unsigned int i,
1591  const unsigned int j) const;
1592 };
1593 
1594 
1595 
1596 
1597 /* --------------------- Template and inline functions ---------------- */
1598 
1599 #ifndef DOXYGEN
1600 
1601 template <int N, typename T>
1603 {}
1604 
1605 
1606 
1607 template <int N, typename T>
1609 {
1610  reinit (sizes);
1611 }
1612 
1613 
1614 
1615 template <int N, typename T>
1616 template <typename InputIterator>
1618 TableBase (const TableIndices<N> &sizes,
1619  InputIterator entries,
1620  const bool C_style_indexing)
1621 {
1622  reinit (sizes);
1623  fill (entries, C_style_indexing);
1624 }
1625 
1626 
1627 
1628 
1629 template <int N, typename T>
1631  :
1632  Subscriptor ()
1633 {
1634  reinit (src.table_size, true);
1635  values = src.values;
1636 }
1637 
1638 
1639 
1640 template <int N, typename T>
1641 template <typename T2>
1643 {
1644  reinit (src.table_size);
1645  if (src.n_elements() != 0)
1646  std::copy (src.values.begin(), src.values.end(), values.begin());
1647 }
1648 
1649 
1650 
1651 template <int N, typename T>
1652 template <class Archive>
1653 inline
1654 void
1655 TableBase<N,T>::serialize (Archive &ar, const unsigned int)
1656 {
1657  ar &static_cast<Subscriptor &>(*this);
1658 
1659  ar &values &table_size;
1660 }
1661 
1662 
1663 
1664 namespace internal
1665 {
1666  namespace TableBaseAccessors
1667  {
1668  template <int N, typename T, bool C, unsigned int P>
1669  inline
1670  Accessor<N,T,C,P>::Accessor (const TableType &table,
1671  const iterator data)
1672  :
1673  table (table),
1674  data (data)
1675  {}
1676 
1677 
1678 
1679  template <int N, typename T, bool C, unsigned int P>
1680  inline
1681  Accessor<N,T,C,P>::Accessor (const Accessor &a)
1682  :
1683  table (a.table),
1684  data (a.data)
1685  {}
1686 
1687 
1688 
1689  template <int N, typename T, bool C, unsigned int P>
1690  inline
1691  Accessor<N,T,C,P>::Accessor ()
1692  :
1693  table (*static_cast<const TableType *>(0)),
1694  data (0)
1695  {
1696  // accessor objects are only
1697  // temporary objects, so should
1698  // not need to be copied around
1699  Assert (false, ExcInternalError());
1700  }
1701 
1702 
1703 
1704  template <int N, typename T, bool C, unsigned int P>
1705  inline
1706  Accessor<N,T,C,P-1>
1707  Accessor<N,T,C,P>::operator [] (const unsigned int i) const
1708  {
1709  Assert (i < table.size()[N-P],
1710  ExcIndexRange (i, 0, table.size()[N-P]));
1711 
1712  // access i-th
1713  // subobject. optimize on the
1714  // case i==0
1715  if (i==0)
1716  return Accessor<N,T,C,P-1> (table, data);
1717  else
1718  {
1719  // note: P>1, otherwise the
1720  // specialization would have
1721  // been taken!
1722  size_type subobject_size = table.size()[N-1];
1723  for (int p=P-1; p>1; --p)
1724  subobject_size *= table.size()[N-p];
1725  const iterator new_data = data + i*subobject_size;
1726  return Accessor<N,T,C,P-1> (table, new_data);
1727  }
1728  }
1729 
1730 
1731 
1732  template <int N, typename T, bool C>
1733  inline
1734  Accessor<N,T,C,1>::Accessor (const TableType &table,
1735  const iterator data)
1736  :
1737  table (table),
1738  data (data)
1739  {}
1740 
1741 
1742 
1743  template <int N, typename T, bool C>
1744  inline
1745  Accessor<N,T,C,1>::Accessor ()
1746  :
1747  table (*static_cast<const TableType *>(0)),
1748  data (0)
1749  {
1750  // accessor objects are only
1751  // temporary objects, so should
1752  // not need to be copied around
1753  Assert (false, ExcInternalError());
1754  }
1755 
1756 
1757 
1758  template <int N, typename T, bool C>
1759  inline
1760  Accessor<N,T,C,1>::Accessor (const Accessor &a)
1761  :
1762  table (a.table),
1763  data (a.data)
1764  {}
1765 
1766 
1767 
1768  template <int N, typename T, bool C>
1769  inline
1770  typename Accessor<N,T,C,1>::reference
1771  Accessor<N,T,C,1>::operator [] (const unsigned int i) const
1772  {
1773  Assert (i < table.size()[N-1],
1774  ExcIndexRange (i, 0, table.size()[N-1]));
1775  return *(data+i);
1776  }
1777 
1778 
1779 
1780  template <int N, typename T, bool C>
1781  inline
1782  unsigned int
1783  Accessor<N,T,C,1>::size () const
1784  {
1785  return table.size()[N-1];
1786  }
1787 
1788 
1789 
1790  template <int N, typename T, bool C>
1791  inline
1792  typename Accessor<N,T,C,1>::iterator
1793  Accessor<N,T,C,1>::begin () const
1794  {
1795  return data;
1796  }
1797 
1798 
1799 
1800  template <int N, typename T, bool C>
1801  inline
1802  typename Accessor<N,T,C,1>::iterator
1803  Accessor<N,T,C,1>::end () const
1804  {
1805  return data+table.size()[N-1];
1806  }
1807  }
1808 }
1809 
1810 
1811 
1812 template <int N, typename T>
1813 inline
1815 {}
1816 
1817 
1818 
1819 template <int N, typename T>
1820 inline
1823 {
1824  if (!m.empty())
1825  values = m.values;
1826  reinit (m.size(), true);
1827 
1828  return *this;
1829 }
1830 
1831 
1832 
1833 template <int N, typename T>
1834 template <typename T2>
1835 inline
1838 {
1839  reinit (m.size(), true);
1840  if (!empty())
1841  std::copy (m.values.begin(), m.values.begin() + n_elements(),
1842  values.begin());
1843 
1844  return *this;
1845 }
1846 
1847 
1848 template <int N, typename T>
1849 inline
1850 bool
1852 {
1853  return (values == T2.values);
1854 }
1855 
1856 
1857 
1858 template <int N, typename T>
1859 inline
1860 void
1862 {
1863  // use parallel set operation
1864  if (n_elements() != 0)
1865  values.fill(T());
1866 }
1867 
1868 
1869 
1870 template <int N, typename T>
1871 inline
1872 void
1873 TableBase<N,T>::fill (const T &value)
1874 {
1875  if (n_elements() != 0)
1876  values.fill(value);
1877 }
1878 
1879 
1880 
1881 
1882 template <int N, typename T>
1883 inline
1884 void
1885 TableBase<N,T>::reinit (const TableIndices<N> &new_sizes,
1886  const bool omit_default_initialization)
1887 {
1888  table_size = new_sizes;
1889 
1890  const size_type new_size = n_elements();
1891 
1892  // if zero size was given: free all memory
1893  if (new_size == 0)
1894  {
1895  values.resize (0);
1896  // set all sizes to zero, even
1897  // if one was previously
1898  // nonzero. This simplifies
1899  // some assertions.
1900  table_size = TableIndices<N>();
1901 
1902  return;
1903  }
1904 
1905  // adjust values field. If it was empty before, we can simply call resize(),
1906  // which can set all the data fields. Otherwise, select the fast resize and
1907  // manually fill in all the elements as required by the design of this
1908  // class. (Selecting another code for the empty case ensures that we touch
1909  // the memory only once for non-trivial classes that need to initialize the
1910  // memory also in resize_fast.)
1911  if (!omit_default_initialization)
1912  {
1913  if (values.empty())
1914  values.resize(new_size, T());
1915  else
1916  {
1917  values.resize_fast(new_size);
1918  values.fill(T());
1919  }
1920  }
1921  else
1922  values.resize_fast (new_size);
1923 }
1924 
1925 
1926 
1927 template <int N, typename T>
1928 inline
1929 const TableIndices<N> &
1930 TableBase<N,T>::size () const
1931 {
1932  return table_size;
1933 }
1934 
1935 
1936 
1937 template <int N, typename T>
1938 inline
1939 unsigned int
1940 TableBase<N,T>::size (const unsigned int i) const
1941 {
1942  Assert (i<N, ExcIndexRange(i,0,N));
1943  return table_size[i];
1944 }
1945 
1946 
1947 
1948 template <int N, typename T>
1949 inline
1952 {
1953  size_type s = 1;
1954  for (unsigned int n=0; n<N; ++n)
1955  s *= table_size[n];
1956  return s;
1957 }
1958 
1959 
1960 
1961 template <int N, typename T>
1962 inline
1963 bool
1964 TableBase<N,T>::empty () const
1965 {
1966  return (n_elements() == 0);
1967 }
1968 
1969 
1970 
1971 namespace internal
1972 {
1973  namespace Table
1974  {
1975  template <typename InputIterator, typename T>
1976  void fill_Fortran_style (InputIterator entries,
1977  TableBase<1,T> &table)
1978  {
1979  for (unsigned int i=0; i<table.size()[0]; ++i)
1980  table(TableIndices<1>(i)) = *entries++;
1981  }
1982 
1983 
1984  template <typename InputIterator, typename T>
1985  void fill_Fortran_style (InputIterator entries,
1986  TableBase<2,T> &table)
1987  {
1988  for (unsigned int j=0; j<table.size()[1]; ++j)
1989  for (unsigned int i=0; i<table.size()[0]; ++i)
1990  table(TableIndices<2>(i,j)) = *entries++;
1991  }
1992 
1993 
1994  template <typename InputIterator, typename T>
1995  void fill_Fortran_style (InputIterator entries,
1996  TableBase<3,T> &table)
1997  {
1998  for (unsigned int k=0; k<table.size()[2]; ++k)
1999  for (unsigned int j=0; j<table.size()[1]; ++j)
2000  for (unsigned int i=0; i<table.size()[0]; ++i)
2001  table(TableIndices<3>(i,j,k)) = *entries++;
2002  }
2003 
2004 
2005  template <typename InputIterator, typename T, int N>
2006  void fill_Fortran_style (InputIterator,
2007  TableBase<N,T> &)
2008  {
2009  Assert (false, ExcNotImplemented());
2010  }
2011  }
2012 }
2013 
2014 
2015 template <int N, typename T>
2016 template <typename InputIterator>
2017 inline
2018 void
2019 TableBase<N,T>::fill (InputIterator entries,
2020  const bool C_style_indexing)
2021 {
2022  Assert (n_elements() != 0,
2023  ExcMessage("Trying to fill an empty matrix."));
2024 
2025  if (C_style_indexing)
2026  for (typename AlignedVector<T>::iterator p = values.begin();
2027  p != values.end(); ++p)
2028  *p = *entries++;
2029  else
2030  internal::Table::fill_Fortran_style (entries, *this);
2031 }
2032 
2033 
2034 
2035 template <int N, typename T>
2036 inline
2037 void
2039 {
2040  values.swap(v.values);
2041  std::swap (table_size, v.table_size);
2042 }
2043 
2044 
2045 
2046 template <int N, typename T>
2047 inline
2048 std::size_t
2050 {
2051  return sizeof(*this) + MemoryConsumption::memory_consumption(values);
2052 }
2053 
2054 
2055 
2056 template <int N, typename T>
2057 inline
2059 TableBase<N,T>::position (const TableIndices<N> &indices) const
2060 {
2061  // specialize this for the
2062  // different numbers of dimensions,
2063  // to make the job somewhat easier
2064  // for the compiler. have the
2065  // general formula nevertheless:
2066  switch (N)
2067  {
2068  case 1:
2069  return indices[0];
2070  case 2:
2071  return size_type(indices[0])*table_size[1] + indices[1];
2072  case 3:
2073  return ((size_type(indices[0])*table_size[1] + indices[1])*table_size[2]
2074  + indices[2]);
2075  default:
2076  {
2077  size_type s = indices[0];
2078  for (unsigned int n=1; n<N; ++n)
2079  s = s*table_size[n] + indices[n];
2080  return s;
2081  }
2082  }
2083 }
2084 
2085 
2086 
2087 template <int N, typename T>
2088 inline
2089 typename AlignedVector<T>::const_reference
2090 TableBase<N,T>::operator () (const TableIndices<N> &indices) const
2091 {
2092  for (unsigned int n=0; n<N; ++n)
2093  Assert (indices[n] < table_size[n],
2094  ExcIndexRange (indices[n], 0, table_size[n]));
2095  return el(indices);
2096 }
2097 
2098 
2099 
2100 template <int N, typename T>
2101 inline
2102 typename AlignedVector<T>::reference
2104 {
2105  for (unsigned int n=0; n<N; ++n)
2106  Assert (indices[n] < table_size[n],
2107  ExcIndexRange (indices[n], 0, table_size[n]));
2108  return el(indices);
2109 }
2110 
2111 
2112 
2113 template <int N, typename T>
2114 inline
2115 typename AlignedVector<T>::const_reference
2116 TableBase<N,T>::el (const TableIndices<N> &indices) const
2117 {
2118  return values[position(indices)];
2119 }
2120 
2121 
2122 
2123 template <int N, typename T>
2124 inline
2125 typename AlignedVector<T>::reference
2126 TableBase<N,T>::el (const TableIndices<N> &indices)
2127 {
2128  Assert (position(indices) < values.size(),
2129  ExcIndexRange (position(indices), 0, values.size()));
2130  return values[position(indices)];
2131 }
2132 
2133 
2134 
2135 template <typename T>
2136 inline
2138 {}
2139 
2140 
2141 
2142 template <typename T>
2143 inline
2144 Table<1,T>::Table (const unsigned int size)
2145  :
2146  TableBase<1,T> (TableIndices<1> (size))
2147 {}
2148 
2149 
2150 
2151 template <typename T>
2152 template <typename InputIterator>
2153 inline
2154 Table<1,T>::Table (const unsigned int size,
2155  InputIterator entries,
2156  const bool C_style_indexing)
2157  :
2158  TableBase<1,T> (TableIndices<1> (size),
2159  entries,
2160  C_style_indexing)
2161 {}
2162 
2163 
2164 
2165 template <typename T>
2166 inline
2167 typename AlignedVector<T>::const_reference
2168 Table<1,T>::operator [] (const unsigned int i) const
2169 {
2170  Assert (i < this->table_size[0],
2171  ExcIndexRange (i, 0, this->table_size[0]));
2172  return this->values[i];
2173 }
2174 
2175 
2176 
2177 template <typename T>
2178 inline
2179 typename AlignedVector<T>::reference
2180 Table<1,T>::operator [] (const unsigned int i)
2181 {
2182  Assert (i < this->table_size[0],
2183  ExcIndexRange (i, 0, this->table_size[0]));
2184  return this->values[i];
2185 }
2186 
2187 
2188 
2189 template <typename T>
2190 inline
2191 typename AlignedVector<T>::const_reference
2192 Table<1,T>::operator () (const unsigned int i) const
2193 {
2194  Assert (i < this->table_size[0],
2195  ExcIndexRange (i, 0, this->table_size[0]));
2196  return this->values[i];
2197 }
2198 
2199 
2200 
2201 template <typename T>
2202 inline
2203 typename AlignedVector<T>::reference
2204 Table<1,T>::operator () (const unsigned int i)
2205 {
2206  Assert (i < this->table_size[0],
2207  ExcIndexRange (i, 0, this->table_size[0]));
2208  return this->values[i];
2209 }
2210 
2211 
2212 
2213 template <typename T>
2214 inline
2215 typename AlignedVector<T>::const_reference
2216 Table<1,T>::operator () (const TableIndices<1> &indices) const
2217 {
2218  return TableBase<1,T>::operator () (indices);
2219 }
2220 
2221 
2222 
2223 template <typename T>
2224 inline
2225 typename AlignedVector<T>::reference
2227 {
2228  return TableBase<1,T>::operator () (indices);
2229 }
2230 
2231 
2232 //---------------------------------------------------------------------------
2233 
2234 template <typename T>
2235 inline
2237 {}
2238 
2239 
2240 
2241 template <typename T>
2242 inline
2243 Table<2,T>::Table (const unsigned int size1,
2244  const unsigned int size2)
2245  :
2246  TableBase<2,T> (TableIndices<2> (size1, size2))
2247 {}
2248 
2249 
2250 
2251 template <typename T>
2252 template <typename InputIterator>
2253 inline
2254 Table<2,T>::Table (const unsigned int size1,
2255  const unsigned int size2,
2256  InputIterator entries,
2257  const bool C_style_indexing)
2258  :
2259  TableBase<2,T> (TableIndices<2> (size1, size2),
2260  entries,
2261  C_style_indexing)
2262 {}
2263 
2264 
2265 
2266 template <typename T>
2267 inline
2268 void
2269 Table<2,T>::reinit (const unsigned int size1,
2270  const unsigned int size2,
2271  const bool omit_default_initialization)
2272 {
2273  this->TableBase<2,T>::reinit (TableIndices<2> (size1, size2),omit_default_initialization);
2274 }
2275 
2276 
2277 
2278 template <typename T>
2279 inline
2280 ::internal::TableBaseAccessors::Accessor<2,T,true,1>
2281 Table<2,T>::operator [] (const unsigned int i) const
2282 {
2283  Assert (i < this->table_size[0],
2284  ExcIndexRange (i, 0, this->table_size[0]));
2285  return ::internal::TableBaseAccessors::Accessor<2,T,true,1>(*this,
2286  this->values.begin()+size_type(i)*n_cols());
2287 }
2288 
2289 
2290 
2291 template <typename T>
2292 inline
2293 ::internal::TableBaseAccessors::Accessor<2,T,false,1>
2294 Table<2,T>::operator [] (const unsigned int i)
2295 {
2296  Assert (i < this->table_size[0],
2297  ExcIndexRange (i, 0, this->table_size[0]));
2298  return ::internal::TableBaseAccessors::Accessor<2,T,false,1>(*this,
2299  this->values.begin()+size_type(i)*n_cols());
2300 }
2301 
2302 
2303 
2304 template <typename T>
2305 inline
2306 typename AlignedVector<T>::const_reference
2307 Table<2,T>::operator () (const unsigned int i,
2308  const unsigned int j) const
2309 {
2310  Assert (i < this->table_size[0],
2311  ExcIndexRange (i, 0, this->table_size[0]));
2312  Assert (j < this->table_size[1],
2313  ExcIndexRange (j, 0, this->table_size[1]));
2314  return this->values[size_type(i)*this->table_size[1]+j];
2315 }
2316 
2317 
2318 
2319 template <typename T>
2320 inline
2321 typename AlignedVector<T>::reference
2322 Table<2,T>::operator () (const unsigned int i,
2323  const unsigned int j)
2324 {
2325  Assert (i < this->table_size[0],
2326  ExcIndexRange (i, 0, this->table_size[0]));
2327  Assert (j < this->table_size[1],
2328  ExcIndexRange (j, 0, this->table_size[1]));
2329  return this->values[size_type(i)*this->table_size[1]+j];
2330 }
2331 
2332 
2333 
2334 template <typename T>
2335 inline
2336 typename AlignedVector<T>::const_reference
2337 Table<2,T>::operator () (const TableIndices<2> &indices) const
2338 {
2339  return TableBase<2,T>::operator () (indices);
2340 }
2341 
2342 
2343 
2344 template <typename T>
2345 inline
2346 typename AlignedVector<T>::reference
2348 {
2349  return TableBase<2,T>::operator () (indices);
2350 }
2351 
2352 
2353 
2354 template <typename T>
2355 inline
2356 typename AlignedVector<T>::const_reference
2357 Table<2,T>::el (const unsigned int i,
2358  const unsigned int j) const
2359 {
2360  return this->values[size_type(i)*this->table_size[1]+j];
2361 }
2362 
2363 
2364 
2365 template <typename T>
2366 inline
2367 typename AlignedVector<T>::reference
2368 Table<2,T>::el (const unsigned int i,
2369  const unsigned int j)
2370 {
2371  return this->values[size_type(i)*this->table_size[1]+j];
2372 }
2373 
2374 
2375 
2376 template <typename T>
2377 inline
2378 unsigned int
2379 Table<2,T>::n_rows () const
2380 {
2381  return this->table_size[0];
2382 }
2383 
2384 
2385 
2386 template <typename T>
2387 inline
2388 unsigned int
2389 Table<2,T>::n_cols () const
2390 {
2391  return this->table_size[1];
2392 }
2393 
2394 
2395 
2396 //---------------------------------------------------------------------------
2397 
2398 template <typename T>
2399 inline
2401 {}
2402 
2403 
2404 
2405 template <typename T>
2406 inline
2407 TransposeTable<T>::TransposeTable (const unsigned int size1,
2408  const unsigned int size2)
2409  :
2410  TableBase<2,T> (TableIndices<2> (size2, size1))
2411 {}
2412 
2413 
2414 
2415 template <typename T>
2416 inline
2417 void
2418 TransposeTable<T>::reinit (const unsigned int size1,
2419  const unsigned int size2,
2420  const bool omit_default_initialization)
2421 {
2422  this->TableBase<2,T>::reinit (TableIndices<2> (size2, size1), omit_default_initialization);
2423 }
2424 
2425 
2426 
2427 template <typename T>
2428 inline
2429 typename AlignedVector<T>::const_reference
2430 TransposeTable<T>::operator () (const unsigned int i,
2431  const unsigned int j) const
2432 {
2433  Assert (i < this->table_size[1],
2434  ExcIndexRange (i, 0, this->table_size[1]));
2435  Assert (j < this->table_size[0],
2436  ExcIndexRange (j, 0, this->table_size[0]));
2437  return this->values[size_type(j)*this->table_size[1]+i];
2438 }
2439 
2440 
2441 
2442 template <typename T>
2443 inline
2444 typename AlignedVector<T>::reference
2445 TransposeTable<T>::operator () (const unsigned int i,
2446  const unsigned int j)
2447 {
2448  Assert (i < this->table_size[1],
2449  ExcIndexRange (i, 0, this->table_size[1]));
2450  Assert (j < this->table_size[0],
2451  ExcIndexRange (j, 0, this->table_size[0]));
2452  return this->values[size_type(j)*this->table_size[1]+i];
2453 }
2454 
2455 
2456 
2457 template <typename T>
2458 inline
2459 typename AlignedVector<T>::const_reference
2460 TransposeTable<T>::el (const unsigned int i,
2461  const unsigned int j) const
2462 {
2463  return this->values[size_type(j)*this->table_size[1]+i];
2464 }
2465 
2466 
2467 
2468 template <typename T>
2469 inline
2470 typename AlignedVector<T>::reference
2471 TransposeTable<T>::el (const unsigned int i,
2472  const unsigned int j)
2473 {
2474  return this->values[size_type(j)*this->table_size[1]+i];
2475 }
2476 
2477 
2478 
2479 template <typename T>
2480 inline
2481 unsigned int
2483 {
2484  return this->table_size[1];
2485 }
2486 
2487 
2488 
2489 template <typename T>
2490 inline
2491 unsigned int
2493 {
2494  return this->table_size[0];
2495 }
2496 
2497 
2498 
2499 //---------------------------------------------------------------------------
2500 
2501 
2502 template <typename T>
2503 inline
2505 {}
2506 
2507 
2508 
2509 template <typename T>
2510 inline
2511 Table<3,T>::Table (const unsigned int size1,
2512  const unsigned int size2,
2513  const unsigned int size3)
2514  :
2515  TableBase<3,T> (TableIndices<3> (size1, size2, size3))
2516 {}
2517 
2518 
2519 
2520 template <typename T>
2521 template <typename InputIterator>
2522 inline
2523 Table<3,T>::Table (const unsigned int size1,
2524  const unsigned int size2,
2525  const unsigned int size3,
2526  InputIterator entries,
2527  const bool C_style_indexing)
2528  :
2529  TableBase<3,T> (TableIndices<3> (size1, size2, size3),
2530  entries,
2531  C_style_indexing)
2532 {}
2533 
2534 
2535 
2536 template <typename T>
2537 inline
2538 ::internal::TableBaseAccessors::Accessor<3,T,true,2>
2539 Table<3,T>::operator [] (const unsigned int i) const
2540 {
2541  Assert (i < this->table_size[0],
2542  ExcIndexRange (i, 0, this->table_size[0]));
2543  const size_type subobject_size = size_type(this->table_size[1]) *
2544  this->table_size[2];
2545  return (::internal::TableBaseAccessors::Accessor<3,T,true,2>
2546  (*this,
2547  this->values.begin() + i*subobject_size));
2548 }
2549 
2550 
2551 
2552 template <typename T>
2553 inline
2554 ::internal::TableBaseAccessors::Accessor<3,T,false,2>
2555 Table<3,T>::operator [] (const unsigned int i)
2556 {
2557  Assert (i < this->table_size[0],
2558  ExcIndexRange (i, 0, this->table_size[0]));
2559  const size_type subobject_size = size_type(this->table_size[1]) *
2560  this->table_size[2];
2561  return (::internal::TableBaseAccessors::Accessor<3,T,false,2>
2562  (*this,
2563  this->values.begin() + i*subobject_size));
2564 }
2565 
2566 
2567 
2568 template <typename T>
2569 inline
2570 typename AlignedVector<T>::const_reference
2571 Table<3,T>::operator () (const unsigned int i,
2572  const unsigned int j,
2573  const unsigned int k) const
2574 {
2575  Assert (i < this->table_size[0],
2576  ExcIndexRange (i, 0, this->table_size[0]));
2577  Assert (j < this->table_size[1],
2578  ExcIndexRange (j, 0, this->table_size[1]));
2579  Assert (k < this->table_size[2],
2580  ExcIndexRange (k, 0, this->table_size[2]));
2581  return this->values[(size_type(i)*this->table_size[1]+j)
2582  *this->table_size[2] + k];
2583 }
2584 
2585 
2586 
2587 template <typename T>
2588 inline
2589 typename AlignedVector<T>::reference
2590 Table<3,T>::operator () (const unsigned int i,
2591  const unsigned int j,
2592  const unsigned int k)
2593 {
2594  Assert (i < this->table_size[0],
2595  ExcIndexRange (i, 0, this->table_size[0]));
2596  Assert (j < this->table_size[1],
2597  ExcIndexRange (j, 0, this->table_size[1]));
2598  Assert (k < this->table_size[2],
2599  ExcIndexRange (k, 0, this->table_size[2]));
2600  return this->values[(size_type(i)*this->table_size[1]+j)
2601  *this->table_size[2] + k];
2602 }
2603 
2604 
2605 
2606 template <typename T>
2607 inline
2608 typename AlignedVector<T>::const_reference
2609 Table<3,T>::operator () (const TableIndices<3> &indices) const
2610 {
2611  return TableBase<3,T>::operator () (indices);
2612 }
2613 
2614 
2615 
2616 template <typename T>
2617 inline
2618 typename AlignedVector<T>::reference
2620 {
2621  return TableBase<3,T>::operator () (indices);
2622 }
2623 
2624 
2625 
2626 template <typename T>
2627 inline
2629 {}
2630 
2631 
2632 
2633 template <typename T>
2634 inline
2635 Table<4,T>::Table (const unsigned int size1,
2636  const unsigned int size2,
2637  const unsigned int size3,
2638  const unsigned int size4)
2639  :
2640  TableBase<4,T> (TableIndices<4> (size1, size2, size3, size4))
2641 {}
2642 
2643 
2644 
2645 template <typename T>
2646 inline
2647 ::internal::TableBaseAccessors::Accessor<4,T,true,3>
2648 Table<4,T>::operator [] (const unsigned int i) const
2649 {
2650  Assert (i < this->table_size[0],
2651  ExcIndexRange (i, 0, this->table_size[0]));
2652  const size_type subobject_size = size_type(this->table_size[1]) *
2653  this->table_size[2] *
2654  this->table_size[3];
2655  return (::internal::TableBaseAccessors::Accessor<4,T,true,3>
2656  (*this,
2657  this->values.begin() + i*subobject_size));
2658 }
2659 
2660 
2661 
2662 template <typename T>
2663 inline
2664 ::internal::TableBaseAccessors::Accessor<4,T,false,3>
2665 Table<4,T>::operator [] (const unsigned int i)
2666 {
2667  Assert (i < this->table_size[0],
2668  ExcIndexRange (i, 0, this->table_size[0]));
2669  const size_type subobject_size = size_type(this->table_size[1]) *
2670  this->table_size[2] *
2671  this->table_size[3];
2672  return (::internal::TableBaseAccessors::Accessor<4,T,false,3>
2673  (*this,
2674  this->values.begin() + i*subobject_size));
2675 }
2676 
2677 
2678 
2679 template <typename T>
2680 inline
2681 typename AlignedVector<T>::const_reference
2682 Table<4,T>::operator () (const unsigned int i,
2683  const unsigned int j,
2684  const unsigned int k,
2685  const unsigned int l) const
2686 {
2687  Assert (i < this->table_size[0],
2688  ExcIndexRange (i, 0, this->table_size[0]));
2689  Assert (j < this->table_size[1],
2690  ExcIndexRange (j, 0, this->table_size[1]));
2691  Assert (k < this->table_size[2],
2692  ExcIndexRange (k, 0, this->table_size[2]));
2693  Assert (l < this->table_size[3],
2694  ExcIndexRange (l, 0, this->table_size[3]));
2695  return this->values[((size_type(i)*this->table_size[1]+j)
2696  *this->table_size[2] + k)
2697  *this->table_size[3] + l];
2698 }
2699 
2700 
2701 
2702 template <typename T>
2703 inline
2704 typename AlignedVector<T>::reference
2705 Table<4,T>::operator () (const unsigned int i,
2706  const unsigned int j,
2707  const unsigned int k,
2708  const unsigned int l)
2709 {
2710  Assert (i < this->table_size[0],
2711  ExcIndexRange (i, 0, this->table_size[0]));
2712  Assert (j < this->table_size[1],
2713  ExcIndexRange (j, 0, this->table_size[1]));
2714  Assert (k < this->table_size[2],
2715  ExcIndexRange (k, 0, this->table_size[2]));
2716  Assert (l < this->table_size[3],
2717  ExcIndexRange (l, 0, this->table_size[3]));
2718  return this->values[((size_type(i)*this->table_size[1]+j)
2719  *this->table_size[2] + k)
2720  *this->table_size[3] + l];
2721 }
2722 
2723 
2724 
2725 template <typename T>
2726 inline
2727 typename AlignedVector<T>::const_reference
2728 Table<4,T>::operator () (const TableIndices<4> &indices) const
2729 {
2730  return TableBase<4,T>::operator () (indices);
2731 }
2732 
2733 
2734 
2735 template <typename T>
2736 inline
2737 typename AlignedVector<T>::reference
2739 {
2740  return TableBase<4,T>::operator () (indices);
2741 }
2742 
2743 
2744 
2745 template <typename T>
2746 inline
2748 {}
2749 
2750 
2751 
2752 template <typename T>
2753 inline
2754 Table<5,T>::Table (const unsigned int size1,
2755  const unsigned int size2,
2756  const unsigned int size3,
2757  const unsigned int size4,
2758  const unsigned int size5)
2759  :
2760  TableBase<5,T> (TableIndices<5> (size1, size2, size3, size4, size5))
2761 {}
2762 
2763 
2764 
2765 template <typename T>
2766 inline
2767 ::internal::TableBaseAccessors::Accessor<5,T,true,4>
2768 Table<5,T>::operator [] (const unsigned int i) const
2769 {
2770  Assert (i < this->table_size[0],
2771  ExcIndexRange (i, 0, this->table_size[0]));
2772  const size_type subobject_size = size_type(this->table_size[1]) *
2773  this->table_size[2] *
2774  this->table_size[3] *
2775  this->table_size[4];
2776  return (::internal::TableBaseAccessors::Accessor<5,T,true,4>
2777  (*this,
2778  this->values.begin() + i*subobject_size));
2779 }
2780 
2781 
2782 
2783 template <typename T>
2784 inline
2785 ::internal::TableBaseAccessors::Accessor<5,T,false,4>
2786 Table<5,T>::operator [] (const unsigned int i)
2787 {
2788  Assert (i < this->table_size[0],
2789  ExcIndexRange (i, 0, this->table_size[0]));
2790  const size_type subobject_size = size_type(this->table_size[1]) *
2791  this->table_size[2] *
2792  this->table_size[3] *
2793  this->table_size[4];
2794  return (::internal::TableBaseAccessors::Accessor<5,T,false,4>
2795  (*this,
2796  this->values.begin() + i*subobject_size));
2797 }
2798 
2799 
2800 
2801 template <typename T>
2802 inline
2803 typename AlignedVector<T>::const_reference
2804 Table<5,T>::operator () (const unsigned int i,
2805  const unsigned int j,
2806  const unsigned int k,
2807  const unsigned int l,
2808  const unsigned int m) const
2809 {
2810  Assert (i < this->table_size[0],
2811  ExcIndexRange (i, 0, this->table_size[0]));
2812  Assert (j < this->table_size[1],
2813  ExcIndexRange (j, 0, this->table_size[1]));
2814  Assert (k < this->table_size[2],
2815  ExcIndexRange (k, 0, this->table_size[2]));
2816  Assert (l < this->table_size[3],
2817  ExcIndexRange (l, 0, this->table_size[3]));
2818  Assert (m < this->table_size[4],
2819  ExcIndexRange (m, 0, this->table_size[4]));
2820  return this->values[(((size_type(i)*this->table_size[1]+j)
2821  *this->table_size[2] + k)
2822  *this->table_size[3] + l)
2823  *this->table_size[4] + m];
2824 }
2825 
2826 
2827 
2828 template <typename T>
2829 inline
2830 typename AlignedVector<T>::reference
2831 Table<5,T>::operator () (const unsigned int i,
2832  const unsigned int j,
2833  const unsigned int k,
2834  const unsigned int l,
2835  const unsigned int m)
2836 {
2837  Assert (i < this->table_size[0],
2838  ExcIndexRange (i, 0, this->table_size[0]));
2839  Assert (j < this->table_size[1],
2840  ExcIndexRange (j, 0, this->table_size[1]));
2841  Assert (k < this->table_size[2],
2842  ExcIndexRange (k, 0, this->table_size[2]));
2843  Assert (l < this->table_size[3],
2844  ExcIndexRange (l, 0, this->table_size[3]));
2845  Assert (m < this->table_size[4],
2846  ExcIndexRange (m, 0, this->table_size[4]));
2847  return this->values[(((size_type(i)*this->table_size[1]+j)
2848  *this->table_size[2] + k)
2849  *this->table_size[3] + l)
2850  *this->table_size[4] + m];
2851 }
2852 
2853 
2854 
2855 template <typename T>
2856 inline
2857 typename AlignedVector<T>::const_reference
2858 Table<5,T>::operator () (const TableIndices<5> &indices) const
2859 {
2860  return TableBase<5,T>::operator () (indices);
2861 }
2862 
2863 
2864 
2865 template <typename T>
2866 inline
2867 typename AlignedVector<T>::reference
2869 {
2870  return TableBase<5,T>::operator () (indices);
2871 }
2872 
2873 
2874 
2875 template <typename T>
2876 inline
2878 {}
2879 
2880 
2881 
2882 template <typename T>
2883 inline
2884 Table<6,T>::Table (const unsigned int size1,
2885  const unsigned int size2,
2886  const unsigned int size3,
2887  const unsigned int size4,
2888  const unsigned int size5,
2889  const unsigned int size6)
2890  :
2891  TableBase<6,T> (TableIndices<6> (size1, size2, size3, size4, size5, size6))
2892 {}
2893 
2894 
2895 
2896 template <typename T>
2897 inline
2898 ::internal::TableBaseAccessors::Accessor<6,T,true,5>
2899 Table<6,T>::operator [] (const unsigned int i) const
2900 {
2901  Assert (i < this->table_size[0],
2902  ExcIndexRange (i, 0, this->table_size[0]));
2903  const size_type subobject_size = size_type(this->table_size[1]) *
2904  this->table_size[2] *
2905  this->table_size[3] *
2906  this->table_size[4] *
2907  this->table_size[5];
2908  return (::internal::TableBaseAccessors::Accessor<6,T,true,5>
2909  (*this,
2910  this->values.begin() + i*subobject_size));
2911 }
2912 
2913 
2914 
2915 template <typename T>
2916 inline
2917 ::internal::TableBaseAccessors::Accessor<6,T,false,5>
2918 Table<6,T>::operator [] (const unsigned int i)
2919 {
2920  Assert (i < this->table_size[0],
2921  ExcIndexRange (i, 0, this->table_size[0]));
2922  const size_type subobject_size = size_type(this->table_size[1]) *
2923  this->table_size[2] *
2924  this->table_size[3] *
2925  this->table_size[4] *
2926  this->table_size[5];
2927  return (::internal::TableBaseAccessors::Accessor<6,T,false,5>
2928  (*this,
2929  this->values.begin() + i*subobject_size));
2930 }
2931 
2932 
2933 
2934 template <typename T>
2935 inline
2936 typename AlignedVector<T>::const_reference
2937 Table<6,T>::operator () (const unsigned int i,
2938  const unsigned int j,
2939  const unsigned int k,
2940  const unsigned int l,
2941  const unsigned int m,
2942  const unsigned int n) const
2943 {
2944  Assert (i < this->table_size[0],
2945  ExcIndexRange (i, 0, this->table_size[0]));
2946  Assert (j < this->table_size[1],
2947  ExcIndexRange (j, 0, this->table_size[1]));
2948  Assert (k < this->table_size[2],
2949  ExcIndexRange (k, 0, this->table_size[2]));
2950  Assert (l < this->table_size[3],
2951  ExcIndexRange (l, 0, this->table_size[3]));
2952  Assert (m < this->table_size[4],
2953  ExcIndexRange (m, 0, this->table_size[4]));
2954  Assert (n < this->table_size[5],
2955  ExcIndexRange (n, 0, this->table_size[5]));
2956  return this->values[((((size_type(i)*this->table_size[1]+j)
2957  *this->table_size[2] + k)
2958  *this->table_size[3] + l)
2959  *this->table_size[4] + m)
2960  *this->table_size[5] + n];
2961 }
2962 
2963 
2964 
2965 template <typename T>
2966 inline
2967 typename AlignedVector<T>::reference
2968 Table<6,T>::operator () (const unsigned int i,
2969  const unsigned int j,
2970  const unsigned int k,
2971  const unsigned int l,
2972  const unsigned int m,
2973  const unsigned int n)
2974 {
2975  Assert (i < this->table_size[0],
2976  ExcIndexRange (i, 0, this->table_size[0]));
2977  Assert (j < this->table_size[1],
2978  ExcIndexRange (j, 0, this->table_size[1]));
2979  Assert (k < this->table_size[2],
2980  ExcIndexRange (k, 0, this->table_size[2]));
2981  Assert (l < this->table_size[3],
2982  ExcIndexRange (l, 0, this->table_size[3]));
2983  Assert (m < this->table_size[4],
2984  ExcIndexRange (m, 0, this->table_size[4]));
2985  Assert (n < this->table_size[5],
2986  ExcIndexRange (n, 0, this->table_size[5]));
2987  return this->values[((((size_type(i)*this->table_size[1]+j)
2988  *this->table_size[2] + k)
2989  *this->table_size[3] + l)
2990  *this->table_size[4] + m)
2991  *this->table_size[5] + n];
2992 }
2993 
2994 
2995 
2996 template <typename T>
2997 inline
2998 typename AlignedVector<T>::const_reference
2999 Table<6,T>::operator () (const TableIndices<6> &indices) const
3000 {
3001  return TableBase<6,T>::operator () (indices);
3002 }
3003 
3004 
3005 
3006 template <typename T>
3007 inline
3008 typename AlignedVector<T>::reference
3010 {
3011  return TableBase<6,T>::operator () (indices);
3012 }
3013 
3014 
3015 
3016 template <typename T>
3017 inline
3019 {}
3020 
3021 
3022 
3023 template <typename T>
3024 inline
3025 Table<7,T>::Table (const unsigned int size1,
3026  const unsigned int size2,
3027  const unsigned int size3,
3028  const unsigned int size4,
3029  const unsigned int size5,
3030  const unsigned int size6,
3031  const unsigned int size7)
3032  :
3033  TableBase<7,T> (TableIndices<7> (size1, size2, size3, size4, size5, size6, size7))
3034 {}
3035 
3036 
3037 
3038 template <typename T>
3039 inline
3040 ::internal::TableBaseAccessors::Accessor<7,T,true,6>
3041 Table<7,T>::operator [] (const unsigned int i) const
3042 {
3043  Assert (i < this->table_size[0],
3044  ExcIndexRange (i, 0, this->table_size[0]));
3045  const size_type subobject_size = size_type(this->table_size[1]) *
3046  this->table_size[2] *
3047  this->table_size[3] *
3048  this->table_size[4] *
3049  this->table_size[5] *
3050  this->table_size[6];
3051  return (::internal::TableBaseAccessors::Accessor<7,T,true,6>
3052  (*this,
3053  this->values.begin() + i*subobject_size));
3054 }
3055 
3056 
3057 
3058 template <typename T>
3059 inline
3060 ::internal::TableBaseAccessors::Accessor<7,T,false,6>
3061 Table<7,T>::operator [] (const unsigned int i)
3062 {
3063  Assert (i < this->table_size[0],
3064  ExcIndexRange (i, 0, this->table_size[0]));
3065  const size_type subobject_size = size_type(this->table_size[1]) *
3066  this->table_size[2] *
3067  this->table_size[3] *
3068  this->table_size[4] *
3069  this->table_size[5] *
3070  this->table_size[6];
3071  return (::internal::TableBaseAccessors::Accessor<7,T,false,6>
3072  (*this,
3073  this->values.begin() + i*subobject_size));
3074 }
3075 
3076 
3077 
3078 template <typename T>
3079 inline
3080 typename AlignedVector<T>::const_reference
3081 Table<7,T>::operator () (const unsigned int i,
3082  const unsigned int j,
3083  const unsigned int k,
3084  const unsigned int l,
3085  const unsigned int m,
3086  const unsigned int n,
3087  const unsigned int o) const
3088 {
3089  Assert (i < this->table_size[0],
3090  ExcIndexRange (i, 0, this->table_size[0]));
3091  Assert (j < this->table_size[1],
3092  ExcIndexRange (j, 0, this->table_size[1]));
3093  Assert (k < this->table_size[2],
3094  ExcIndexRange (k, 0, this->table_size[2]));
3095  Assert (l < this->table_size[3],
3096  ExcIndexRange (l, 0, this->table_size[3]));
3097  Assert (m < this->table_size[4],
3098  ExcIndexRange (m, 0, this->table_size[4]));
3099  Assert (n < this->table_size[5],
3100  ExcIndexRange (n, 0, this->table_size[5]));
3101  Assert (o < this->table_size[6],
3102  ExcIndexRange (o, 0, this->table_size[6]));
3103  return this->values[(((((size_type(i)*this->table_size[1]+j)
3104  *this->table_size[2] + k)
3105  *this->table_size[3] + l)
3106  *this->table_size[4] + m)
3107  *this->table_size[5] + n)
3108  *this->table_size[6] + o];
3109 }
3110 
3111 
3112 
3113 template <typename T>
3114 inline
3115 typename AlignedVector<T>::reference
3116 Table<7,T>::operator () (const unsigned int i,
3117  const unsigned int j,
3118  const unsigned int k,
3119  const unsigned int l,
3120  const unsigned int m,
3121  const unsigned int n,
3122  const unsigned int o)
3123 {
3124  Assert (i < this->table_size[0],
3125  ExcIndexRange (i, 0, this->table_size[0]));
3126  Assert (j < this->table_size[1],
3127  ExcIndexRange (j, 0, this->table_size[1]));
3128  Assert (k < this->table_size[2],
3129  ExcIndexRange (k, 0, this->table_size[2]));
3130  Assert (l < this->table_size[3],
3131  ExcIndexRange (l, 0, this->table_size[3]));
3132  Assert (m < this->table_size[4],
3133  ExcIndexRange (m, 0, this->table_size[4]));
3134  Assert (n < this->table_size[5],
3135  ExcIndexRange (n, 0, this->table_size[5]));
3136  Assert (o < this->table_size[5],
3137  ExcIndexRange (o, 0, this->table_size[6]));
3138  return this->values[(((((size_type(i)*this->table_size[1]+j)
3139  *this->table_size[2] + k)
3140  *this->table_size[3] + l)
3141  *this->table_size[4] + m)
3142  *this->table_size[5] + n)
3143  *this->table_size[6] + o];
3144 }
3145 
3146 
3147 
3148 template <typename T>
3149 inline
3150 typename AlignedVector<T>::const_reference
3151 Table<7,T>::operator () (const TableIndices<7> &indices) const
3152 {
3153  return TableBase<7,T>::operator () (indices);
3154 }
3155 
3156 
3157 
3158 template <typename T>
3159 inline
3160 typename AlignedVector<T>::reference
3162 {
3163  return TableBase<7,T>::operator () (indices);
3164 }
3165 
3166 
3167 #endif // DOXYGEN
3168 
3169 
3170 
3178 template <int N, typename T>
3179 inline
3180 void swap (TableBase<N,T> &u, TableBase<N,T> &v)
3181 {
3182  u.swap (v);
3183 }
3184 
3185 DEAL_II_NAMESPACE_CLOSE
3186 
3187 #endif
unsigned int n_rows() const
TableBase< 6, T >::size_type size_type
Definition: table.h:1311
void serialize(Archive &ar, const unsigned int version)
void swap(TableBase< N, T > &v)
AlignedVector< T >::reference el(const unsigned int i, const unsigned int j)
::ExceptionBase & ExcMessage(std::string arg1)
TableBase< N, T > & operator=(const TableBase< N, T > &src)
TableBase< 7, T >::size_type size_type
Definition: table.h:1407
TableBase< 4, T >::size_type size_type
Definition: table.h:1124
TableBase< 2, T >::size_type size_type
Definition: table.h:805
const TableIndices< N > & size() const
TableBase< 5, T >::size_type size_type
Definition: table.h:1216
TableBase< 2, T >::size_type size_type
Definition: table.h:1510
void swap(BlockIndices &u, BlockIndices &v)
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
#define Assert(cond, exc)
Definition: exceptions.h:294
AlignedVector< T >::reference el(const TableIndices< N > &indices)
std::size_t memory_consumption() const
std_cxx11::enable_if< std_cxx11::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
size_type n_elements() const
size_type position(const TableIndices< N > &indices) const
void reset_values()
TableBase< 3, T >::size_type size_type
Definition: table.h:990
Definition: table.h:33
TableIndices< N > table_size
Definition: table.h:639
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:562
AlignedVector< T >::size_type size_type
Definition: table.h:411
TableBase< 1, T >::size_type size_type
Definition: table.h:686
unsigned int size(const unsigned int i) const
AlignedVector< T >::reference operator()(const TableIndices< N > &indices)
AlignedVector< T > values
Definition: table.h:634
void reinit(const unsigned int size1, const unsigned int size2, const bool omit_default_initialization=false)
AlignedVector< T >::const_reference operator()(const unsigned int i, const unsigned int j) const
unsigned int n_cols() const
void fill(InputIterator entries, const bool C_style_indexing=true)
bool empty() const
bool operator==(const TableBase< N, T > &T2) const