Reference documentation for deal.II version 9.3.3
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
table.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2002 - 2021 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_table_h
17#define dealii_table_h
18
19#include <deal.II/base/config.h>
20
27
28#include <algorithm>
29#include <cstddef>
30
32
33// forward declaration
34#ifndef DOXYGEN
35template <int N, typename T>
36class TableBase;
37template <int N, typename T>
38class Table;
39template <typename T>
40class TransposeTable;
41template <typename T>
42class Table<1, T>;
43template <typename T>
44class Table<2, T>;
45template <typename T>
46class Table<3, T>;
47template <typename T>
48class Table<4, T>;
49template <typename T>
50class Table<5, T>;
51template <typename T>
52class Table<6, T>;
53#endif
54
55
56
57namespace internal
58{
73 namespace TableBaseAccessors
74 {
82 template <int N, typename T, bool Constness>
83 struct Types
84 {};
85
91 template <int N, typename T>
92 struct Types<N, T, true>
93 {
94 using value_type = const T;
96
99
102 };
103
109 template <int N, typename T>
110 struct Types<N, T, false>
111 {
112 using value_type = T;
114
117
120 };
121
122
159 template <int N, typename T, bool C, unsigned int P>
161 {
162 public:
164
167
168 using size_type = size_t;
169 using difference_type = ptrdiff_t;
170
171 private:
178
179 public:
188
192 Accessor<N, T, C, P - 1> operator[](const size_type i) const;
193
199 size_type,
200 size_type,
201 size_type,
202 << "Index " << N - P + 1 << "has a value of " << arg1
203 << " but needs to be in the range [" << arg2 << "," << arg3
204 << "[.");
205
206 private:
214
215 // declare some other classes
216 // as friends. make sure to
217 // work around bugs in some
218 // compilers
219 template <int N1, typename T1>
220 friend class ::Table;
221 template <int N1, typename T1, bool C1, unsigned int P1>
222 friend class Accessor;
223 friend class ::Table<N, T>;
224 friend class Accessor<N, T, C, P + 1>;
225 };
226
227
228
236 template <int N, typename T, bool C>
237 class Accessor<N, T, C, 1>
238 {
239 public:
246
249
252
253 using size_type = size_t;
254 using difference_type = ptrdiff_t;
255
260
261 private:
274
275 public:
284
289
295 size() const;
296
301 begin() const;
302
307 end() const;
308
309 private:
317
318 // declare some other classes
319 // as friends. make sure to
320 // work around bugs in some
321 // compilers
322 template <int N1, typename T1>
323 friend class ::Table;
324 template <int N1, typename T1, bool C1, unsigned int P1>
325 friend class Accessor;
326 friend class ::Table<2, T>;
327 friend class Accessor<N, T, C, 2>;
328 };
329 } // namespace TableBaseAccessors
330
331} // namespace internal
332
333
334
437template <int N, typename T>
438class TableBase : public Subscriptor
439{
440public:
441 using value_type = T;
442
447
448
452 TableBase() = default;
453
458 explicit TableBase(const TableIndices<N> &sizes);
459
465 template <typename InputIterator>
467 InputIterator entries,
468 const bool C_style_indexing = true);
469
474
479 template <typename T2>
481
485 TableBase(TableBase<N, T> &&src) noexcept;
486
490 ~TableBase() override = default;
491
502
510 template <typename T2>
513
519 operator=(TableBase<N, T> &&src) noexcept;
520
524 bool
525 operator==(const TableBase<N, T> &T2) const;
526
531 void
533
542 void
543 reinit(const TableIndices<N> &new_size,
544 const bool omit_default_initialization = false);
545
550 size(const unsigned int i) const;
551
555 const TableIndices<N> &
556 size() const;
557
563 n_elements() const;
564
569 bool
570 empty() const;
571
608 template <typename InputIterator>
609 void
610 fill(InputIterator entries, const bool C_style_indexing = true);
611
615 void
616 fill(const T &value);
617
623
632 operator()(const TableIndices<N> &indices) const;
633
718 void
720 const unsigned int root_process);
721
734 void
736
741 std::size_t
743
749 template <class Archive>
750 void
751 serialize(Archive &ar, const unsigned int version);
752
753protected:
759 position(const TableIndices<N> &indices) const;
760
768 el(const TableIndices<N> &indices);
769
781 el(const TableIndices<N> &indices) const;
782
783protected:
788
793
794 // Make all other table classes friends.
795 template <int, typename>
796 friend class TableBase;
797};
798
799
812template <int N, typename T>
813class Table;
814
815
824template <typename T>
825class Table<1, T> : public TableBase<1, T>
826{
827public:
832
836 Table() = default;
837
841 explicit Table(const size_type size);
842
880 template <typename InputIterator>
881 Table(const size_type size,
882 InputIterator entries,
883 const bool C_style_indexing = true);
884
890 operator[](const size_type i) const;
891
897
903 operator()(const size_type i) const;
904
911
916};
917
918
919
928{
933 enum class Storage
934 {
938 row_major,
939
944 };
945
946 // Forward declaration of the iterator class.
947 template <typename TableType, bool Constness, Storage storage_order>
948 class Iterator;
949
954 template <typename TableType, bool Constness, Storage storage_order>
955 class Accessor;
956
973 template <typename TableType, bool Constness, Storage storage_order>
975 {
976 public:
980 using container_pointer_type = typename std::
981 conditional<Constness, const TableType *, TableType *>::type;
982
986 using value_type = typename TableType::value_type;
987
992
997
1002
1007
1012 const std::ptrdiff_t linear_index);
1013
1017 template <bool OtherConstness>
1018 friend bool
1022 {
1023 return left.container == right.container &&
1024 left.linear_index == right.linear_index;
1025 }
1026
1031 const value_type &
1032 value() const;
1033
1037 operator const value_type &() const;
1038
1042 size_type
1043 row() const;
1044
1048 size_type
1049 column() const;
1050
1051 protected:
1056
1060 std::ptrdiff_t linear_index;
1061
1068 void
1070
1071 // Make the const version a friend for copying.
1072 friend class AccessorBase<TableType, true, storage_order>;
1073
1074 // Make the underlying iterator class a friend.
1075 friend class LinearIndexIterator<
1076 Iterator<TableType, Constness, storage_order>,
1077 Accessor<TableType, Constness, storage_order>>;
1078 };
1079
1084 template <typename TableType, Storage storage_order>
1085 class Accessor<TableType, true, storage_order>
1086 : public AccessorBase<TableType, true, storage_order>
1087 {
1088 public:
1094
1100
1105 };
1106
1111 template <typename TableType, Storage storage_order>
1112 class Accessor<TableType, false, storage_order>
1113 : public AccessorBase<TableType, false, storage_order>
1114 {
1115 public:
1121
1127
1132
1138 operator=(const value_type &) const;
1139
1146
1152
1157 value_type &
1158 value() const;
1159
1163 operator value_type &();
1164 };
1165
1178 template <typename TableType, bool Constness, Storage storage_order>
1180 : public LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
1181 Accessor<TableType, Constness, storage_order>>
1182 {
1183 public:
1188
1192 using container_pointer_type = typename std::
1193 conditional<Constness, const TableType *, TableType *>::type;
1194
1199
1204
1209 const size_type row,
1210 const size_type column);
1211
1216
1221 const std::ptrdiff_t linear_index);
1222 };
1223} // namespace MatrixTableIterators
1224
1225
1226
1240template <typename T>
1241class Table<2, T> : public TableBase<2, T>
1242{
1243public:
1248
1253
1258
1263
1268 using const_iterator = MatrixTableIterators::
1269 Iterator<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1270
1274 using iterator = MatrixTableIterators::
1275 Iterator<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1276
1280 Table() = default;
1281
1285 Table(const size_type size1, const size_type size2);
1286
1325 template <typename InputIterator>
1326 Table(const size_type size1,
1327 const size_type size2,
1328 InputIterator entries,
1329 const bool C_style_indexing = true);
1330
1336 void
1337 reinit(const size_type size1,
1338 const size_type size2,
1339 const bool omit_default_initialization = false);
1340
1342
1350 operator[](const size_type i) const;
1351
1360
1368 operator()(const size_type i, const size_type j) const;
1369
1377 operator()(const size_type i, const size_type j);
1378
1383
1388 size_type
1389 n_rows() const;
1390
1395 size_type
1396 n_cols() const;
1397
1401 iterator
1403
1408 begin() const;
1409
1413 iterator
1415
1420 end() const;
1421
1422protected:
1434 el(const size_type i, const size_type j);
1435
1451 el(const size_type i, const size_type j) const;
1452
1453 // Make the AccessorBase class a friend so that it may directly index into
1454 // the array.
1455 friend class MatrixTableIterators::
1456 AccessorBase<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1457 friend class MatrixTableIterators::
1458 AccessorBase<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1459
1460 // Make the mutable accessor class a friend so that we can write to array
1461 // entries with iterators.
1462 friend class MatrixTableIterators::
1463 Accessor<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1464};
1465
1466
1467
1477template <typename T>
1478class Table<3, T> : public TableBase<3, T>
1479{
1480public:
1485
1489 Table() = default;
1490
1494 Table(const size_type size1, const size_type size2, const size_type size3);
1495
1536 template <typename InputIterator>
1537 Table(const size_type size1,
1538 const size_type size2,
1539 const size_type size3,
1540 InputIterator entries,
1541 const bool C_style_indexing = true);
1542
1551 operator[](const size_type i) const;
1552
1562
1570 operator()(const size_type i, const size_type j, const size_type k) const;
1571
1572
1580 operator()(const size_type i, const size_type j, const size_type k);
1581
1586};
1587
1588
1589
1599template <typename T>
1600class Table<4, T> : public TableBase<4, T>
1601{
1602public:
1607
1611 Table() = default;
1612
1616 Table(const size_type size1,
1617 const size_type size2,
1618 const size_type size3,
1619 const size_type size4);
1620
1629 operator[](const size_type i) const;
1630
1640
1649 const size_type j,
1650 const size_type k,
1651 const size_type l) const;
1652
1653
1662 const size_type j,
1663 const size_type k,
1664 const size_type l);
1665
1670};
1671
1672
1673
1683template <typename T>
1684class Table<5, T> : public TableBase<5, T>
1685{
1686public:
1691
1692
1696 Table() = default;
1697
1701 Table(const size_type size1,
1702 const size_type size2,
1703 const size_type size3,
1704 const size_type size4,
1705 const size_type size5);
1706
1715 operator[](const size_type i) const;
1716
1726
1735 const size_type j,
1736 const size_type k,
1737 const size_type l,
1738 const size_type m) const;
1739
1748 const size_type j,
1749 const size_type k,
1750 const size_type l,
1751 const size_type m);
1752
1757};
1758
1759
1760
1770template <typename T>
1771class Table<6, T> : public TableBase<6, T>
1772{
1773public:
1778
1782 Table() = default;
1783
1787 Table(const size_type size1,
1788 const size_type size2,
1789 const size_type size3,
1790 const size_type size4,
1791 const size_type size5,
1792 const size_type size6);
1793
1802 operator[](const size_type i) const;
1803
1813
1822 const size_type j,
1823 const size_type k,
1824 const size_type l,
1825 const size_type m,
1826 const size_type n) const;
1827
1836 const size_type j,
1837 const size_type k,
1838 const size_type l,
1839 const size_type m,
1840 const size_type n);
1841
1846};
1847
1848
1858template <typename T>
1859class Table<7, T> : public TableBase<7, T>
1860{
1861public:
1866
1870 Table() = default;
1871
1875 Table(const size_type size1,
1876 const size_type size2,
1877 const size_type size3,
1878 const size_type size4,
1879 const size_type size5,
1880 const size_type size6,
1881 const size_type size7);
1882
1891 operator[](const size_type i) const;
1892
1902
1911 const size_type j,
1912 const size_type k,
1913 const size_type l,
1914 const size_type m,
1915 const size_type n,
1916 const size_type o) const;
1917
1926 const size_type j,
1927 const size_type k,
1928 const size_type l,
1929 const size_type m,
1930 const size_type n,
1931 const size_type o);
1932
1937};
1938
1939
1952template <typename T>
1953class TransposeTable : public TableBase<2, T>
1954{
1955public:
1960
1965
1970
1975
1982 true,
1984
1988 using iterator =
1990 false,
1992
1996 TransposeTable() = default;
1997
2001 TransposeTable(const size_type size1, const size_type size2);
2002
2008 void
2009 reinit(const size_type size1,
2010 const size_type size2,
2011 const bool omit_default_initialization = false);
2012
2020 operator()(const size_type i, const size_type j) const;
2021
2028 reference
2029 operator()(const size_type i, const size_type j);
2030
2035 size_type
2036 n_rows() const;
2037
2042 size_type
2043 n_cols() const;
2044
2048 iterator
2050
2055 begin() const;
2056
2060 iterator
2062
2067 end() const;
2068
2069protected:
2080 reference
2081 el(const size_type i, const size_type j);
2082
2098 el(const size_type i, const size_type j) const;
2099
2100 // Make the AccessorBase class a friend so that it may directly index into
2101 // the array.
2104 true,
2107 TransposeTable<T>,
2108 false,
2109 MatrixTableIterators::Storage::column_major>;
2110
2111 // Make the mutable accessor class a friend so that we can write to array
2112 // entries with iterators.
2113 friend class MatrixTableIterators::Accessor<
2114 TransposeTable<T>,
2115 false,
2116 MatrixTableIterators::Storage::column_major>;
2117};
2118
2119
2120
2121/* --------------------- Template and inline functions ---------------- */
2122
2123#ifndef DOXYGEN
2124
2125template <int N, typename T>
2126TableBase<N, T>::TableBase(const TableIndices<N> &sizes)
2127{
2128 reinit(sizes);
2129}
2130
2131
2132
2133template <int N, typename T>
2134template <typename InputIterator>
2136 InputIterator entries,
2137 const bool C_style_indexing)
2138{
2139 reinit(sizes);
2140 fill(entries, C_style_indexing);
2141}
2142
2143
2144
2145template <int N, typename T>
2147 : Subscriptor()
2148{
2149 reinit(src.table_size, true);
2150 values = src.values;
2151}
2152
2153
2154
2155template <int N, typename T>
2156template <typename T2>
2158{
2159 reinit(src.table_size);
2160 if (src.n_elements() != 0)
2161 std::copy(src.values.begin(), src.values.end(), values.begin());
2162}
2163
2164
2165
2166template <int N, typename T>
2168 : Subscriptor(std::move(src))
2169 , values(std::move(src.values))
2170 , table_size(src.table_size)
2171{
2173}
2174
2175
2176
2177template <int N, typename T>
2178template <class Archive>
2179inline void
2180TableBase<N, T>::serialize(Archive &ar, const unsigned int)
2181{
2182 ar &static_cast<Subscriptor &>(*this);
2183
2184 ar &values &table_size;
2185}
2186
2187
2188
2189namespace internal
2190{
2191 namespace TableBaseAccessors
2192 {
2193 template <int N, typename T, bool C, unsigned int P>
2194 inline Accessor<N, T, C, P>::Accessor(const TableType &table,
2195 const iterator data)
2196 : table(table)
2197 , data(data)
2198 {}
2199
2200
2201
2202 template <int N, typename T, bool C, unsigned int P>
2203 inline Accessor<N, T, C, P>::Accessor(const Accessor &a)
2204 : table(a.table)
2205 , data(a.data)
2206 {}
2207
2208
2209
2210 template <int N, typename T, bool C, unsigned int P>
2211 inline Accessor<N, T, C, P - 1> Accessor<N, T, C, P>::
2212 operator[](const size_type i) const
2213 {
2214 AssertIndexRange(i, table.size()[N - P]);
2215
2216 // access i-th
2217 // subobject. optimize on the
2218 // case i==0
2219 if (i == 0)
2220 return Accessor<N, T, C, P - 1>(table, data);
2221 else
2222 {
2223 // note: P>1, otherwise the
2224 // specialization would have
2225 // been taken!
2226 size_type subobject_size = table.size()[N - 1];
2227 for (int p = P - 1; p > 1; --p)
2228 subobject_size *= table.size()[N - p];
2229 const iterator new_data = data + i * subobject_size;
2230 return Accessor<N, T, C, P - 1>(table, new_data);
2231 }
2232 }
2233
2234
2235
2236 template <int N, typename T, bool C>
2237 inline Accessor<N, T, C, 1>::Accessor(const TableType &table,
2238 const iterator data)
2239 : table(table)
2240 , data(data)
2241 {}
2242
2243
2244
2245 template <int N, typename T, bool C>
2246 inline Accessor<N, T, C, 1>::Accessor(const Accessor &a)
2247 : table(a.table)
2248 , data(a.data)
2249 {}
2250
2251
2252
2253 template <int N, typename T, bool C>
2254 inline typename Accessor<N, T, C, 1>::reference Accessor<N, T, C, 1>::
2255 operator[](const size_type i) const
2256 {
2257 AssertIndexRange(i, table.size()[N - 1]);
2258 return *(data + i);
2259 }
2260
2261
2262
2263 template <int N, typename T, bool C>
2264 inline typename Accessor<N, T, C, 1>::size_type
2265 Accessor<N, T, C, 1>::size() const
2266 {
2267 return table.size()[N - 1];
2268 }
2269
2270
2271
2272 template <int N, typename T, bool C>
2273 inline typename Accessor<N, T, C, 1>::iterator
2275 {
2276 return data;
2277 }
2278
2279
2280
2281 template <int N, typename T, bool C>
2282 inline typename Accessor<N, T, C, 1>::iterator
2284 {
2285 return data + table.size()[N - 1];
2286 }
2287 } // namespace TableBaseAccessors
2288} // namespace internal
2289
2290
2291
2292template <int N, typename T>
2293inline TableBase<N, T> &
2295{
2296 if (!m.empty())
2297 values = m.values;
2298 reinit(m.size(), true);
2299
2300 return *this;
2301}
2302
2303
2304
2305template <int N, typename T>
2306template <typename T2>
2307inline TableBase<N, T> &
2309{
2310 reinit(m.size(), true);
2311 if (!empty())
2312 std::copy(m.values.begin(),
2313 m.values.begin() + n_elements(),
2314 values.begin());
2315
2316 return *this;
2317}
2318
2319
2320
2321template <int N, typename T>
2322inline TableBase<N, T> &
2324{
2325 static_cast<Subscriptor &>(*this) = std::move(static_cast<Subscriptor &>(m));
2326 values = std::move(m.values);
2327 table_size = m.table_size;
2329
2330 return *this;
2331}
2332
2333
2334
2335template <int N, typename T>
2336inline bool
2338{
2339 return (values == T2.values);
2340}
2341
2342
2343
2344template <int N, typename T>
2345inline void
2347{
2348 // use parallel set operation
2349 if (n_elements() != 0)
2350 values.fill(T());
2351}
2352
2353
2354
2355template <int N, typename T>
2356inline void
2357TableBase<N, T>::fill(const T &value)
2358{
2359 if (n_elements() != 0)
2360 values.fill(value);
2361}
2362
2363
2364
2365template <int N, typename T>
2366inline void
2368 const unsigned int root_process)
2369{
2370 // Replicate first the actual data, then also exchange the
2371 // extents of the table
2372 values.replicate_across_communicator(communicator, root_process);
2373
2374 table_size =
2375 Utilities::MPI::broadcast(communicator, table_size, root_process);
2376}
2377
2378
2379
2380template <int N, typename T>
2381inline void
2383 const bool omit_default_initialization)
2384{
2385 table_size = new_sizes;
2386
2387 const size_type new_size = n_elements();
2388
2389 // if zero size was given: free all memory
2390 if (new_size == 0)
2391 {
2392 values.resize(0);
2393 // set all sizes to zero, even
2394 // if one was previously
2395 // nonzero. This simplifies
2396 // some assertions.
2397 table_size = TableIndices<N>();
2398
2399 return;
2400 }
2401
2402 // adjust values field. If it was empty before, we can simply call resize(),
2403 // which can set all the data fields. Otherwise, select the fast resize and
2404 // manually fill in all the elements as required by the design of this
2405 // class. (Selecting another code for the empty case ensures that we touch
2406 // the memory only once for non-trivial classes that need to initialize the
2407 // memory also in resize_fast.)
2408 if (!omit_default_initialization)
2409 {
2410 if (values.empty())
2411 values.resize(new_size);
2412 else
2413 {
2414 values.resize_fast(new_size);
2415 values.fill();
2416 }
2417 }
2418 else
2419 values.resize_fast(new_size);
2420}
2421
2422
2423
2424template <int N, typename T>
2425inline const TableIndices<N> &
2427{
2428 return table_size;
2429}
2430
2431
2432
2433template <int N, typename T>
2434inline typename TableBase<N, T>::size_type
2435TableBase<N, T>::size(const unsigned int i) const
2436{
2437 AssertIndexRange(i, N);
2438 return table_size[i];
2439}
2440
2441
2442
2443template <int N, typename T>
2444inline typename TableBase<N, T>::size_type
2446{
2447 size_type s = 1;
2448 for (unsigned int n = 0; n < N; ++n)
2449 s *= table_size[n];
2450 return s;
2451}
2452
2453
2454
2455template <int N, typename T>
2456inline bool
2458{
2459 return (n_elements() == 0);
2460}
2461
2462
2463
2464namespace internal
2465{
2466 namespace TableImplementation
2467 {
2468 template <typename InputIterator, typename T>
2469 void
2470 fill_Fortran_style(InputIterator entries, TableBase<1, T> &table)
2471 {
2472 using size_type = typename TableBase<1, T>::size_type;
2473 for (size_type i = 0; i < table.size()[0]; ++i)
2474 table(TableIndices<1>(i)) = *entries++;
2475 }
2476
2477
2478 template <typename InputIterator, typename T>
2479 void
2480 fill_Fortran_style(InputIterator entries, TableBase<2, T> &table)
2481 {
2482 using size_type = typename TableBase<2, T>::size_type;
2483 for (size_type j = 0; j < table.size()[1]; ++j)
2484 for (size_type i = 0; i < table.size()[0]; ++i)
2485 table(TableIndices<2>(i, j)) = *entries++;
2486 }
2487
2488
2489 template <typename InputIterator, typename T>
2490 void
2491 fill_Fortran_style(InputIterator entries, TableBase<3, T> &table)
2492 {
2493 using size_type = typename TableBase<3, T>::size_type;
2494 for (size_type k = 0; k < table.size()[2]; ++k)
2495 for (size_type j = 0; j < table.size()[1]; ++j)
2496 for (size_type i = 0; i < table.size()[0]; ++i)
2497 table(TableIndices<3>(i, j, k)) = *entries++;
2498 }
2499
2500
2501 template <typename InputIterator, typename T, int N>
2502 void
2503 fill_Fortran_style(InputIterator, TableBase<N, T> &)
2504 {
2505 Assert(false, ExcNotImplemented());
2506 }
2507 } // namespace TableImplementation
2508} // namespace internal
2509
2510
2511template <int N, typename T>
2512template <typename InputIterator>
2513inline void
2514TableBase<N, T>::fill(InputIterator entries, const bool C_style_indexing)
2515{
2516 Assert(n_elements() != 0, ExcMessage("Trying to fill an empty matrix."));
2517
2518 if (C_style_indexing)
2519 for (typename AlignedVector<T>::iterator p = values.begin();
2520 p != values.end();
2521 ++p)
2522 *p = *entries++;
2523 else
2524 internal::TableImplementation::fill_Fortran_style(entries, *this);
2525}
2526
2527
2528
2529template <int N, typename T>
2530inline void
2532{
2533 values.swap(v.values);
2534 std::swap(table_size, v.table_size);
2535}
2536
2537
2538
2539template <int N, typename T>
2540inline std::size_t
2542{
2543 return sizeof(*this) + MemoryConsumption::memory_consumption(values);
2544}
2545
2546
2547
2548template <int N, typename T>
2549inline typename TableBase<N, T>::size_type
2550TableBase<N, T>::position(const TableIndices<N> &indices) const
2551{
2552 // specialize this for the
2553 // different numbers of dimensions,
2554 // to make the job somewhat easier
2555 // for the compiler. have the
2556 // general formula nevertheless:
2557 switch (N)
2558 {
2559 case 1:
2560 return indices[0];
2561 case 2:
2562 return size_type(indices[0]) * table_size[1] + indices[1];
2563 case 3:
2564 return ((size_type(indices[0]) * table_size[1] + indices[1]) *
2565 table_size[2] +
2566 indices[2]);
2567 default:
2568 {
2569 unsigned int s = indices[0];
2570 for (unsigned int n = 1; n < N; ++n)
2571 s = s * table_size[n] + indices[n];
2572 return s;
2573 }
2574 }
2575}
2576
2577
2578
2579template <int N, typename T>
2581TableBase<N, T>::operator()(const TableIndices<N> &indices) const
2582{
2583 for (unsigned int n = 0; n < N; ++n)
2584 AssertIndexRange(indices[n], table_size[n]);
2585 return el(indices);
2586}
2587
2588
2589
2590template <int N, typename T>
2591inline typename AlignedVector<T>::reference
2593{
2594 for (unsigned int n = 0; n < N; ++n)
2595 AssertIndexRange(indices[n], table_size[n]);
2596 return el(indices);
2597}
2598
2599
2600
2601template <int N, typename T>
2603TableBase<N, T>::el(const TableIndices<N> &indices) const
2604{
2605 return values[position(indices)];
2606}
2607
2608
2609
2610template <int N, typename T>
2611inline typename AlignedVector<T>::reference
2613{
2614 AssertIndexRange(position(indices), values.size());
2615 return values[position(indices)];
2616}
2617
2618
2619
2620template <typename T>
2621inline Table<1, T>::Table(const size_type size)
2622 : TableBase<1, T>(TableIndices<1>(size))
2623{}
2624
2625
2626
2627template <typename T>
2628template <typename InputIterator>
2629inline Table<1, T>::Table(const size_type size,
2630 InputIterator entries,
2631 const bool C_style_indexing)
2632 : TableBase<1, T>(TableIndices<1>(size), entries, C_style_indexing)
2633{}
2634
2635
2636
2637template <typename T>
2639 operator[](const size_type i) const
2640{
2641 AssertIndexRange(i, this->table_size[0]);
2642 return this->values[i];
2643}
2644
2645
2646
2647template <typename T>
2649 operator[](const size_type i)
2650{
2651 AssertIndexRange(i, this->table_size[0]);
2652 return this->values[i];
2653}
2654
2655
2656
2657template <typename T>
2660{
2661 AssertIndexRange(i, this->table_size[0]);
2662 return this->values[i];
2663}
2664
2665
2666
2667template <typename T>
2668inline typename AlignedVector<T>::reference
2670{
2671 AssertIndexRange(i, this->table_size[0]);
2672 return this->values[i];
2673}
2674
2675
2676//---------------------------------------------------------------------------
2677
2678
2679
2680template <typename T>
2681inline Table<2, T>::Table(const size_type size1, const size_type size2)
2682 : TableBase<2, T>(TableIndices<2>(size1, size2))
2683{}
2684
2685
2686
2687template <typename T>
2688template <typename InputIterator>
2689inline Table<2, T>::Table(const size_type size1,
2690 const size_type size2,
2691 InputIterator entries,
2692 const bool C_style_indexing)
2693 : TableBase<2, T>(TableIndices<2>(size1, size2), entries, C_style_indexing)
2694{}
2695
2696
2697
2698template <typename T>
2699inline void
2700Table<2, T>::reinit(const size_type size1,
2701 const size_type size2,
2702 const bool omit_default_initialization)
2703{
2704 this->TableBase<2, T>::reinit(TableIndices<2>(size1, size2),
2705 omit_default_initialization);
2706}
2707
2708
2709
2710template <typename T>
2711inline ::internal::TableBaseAccessors::Accessor<2, T, true, 1>
2712 Table<2, T>::operator[](const size_type i) const
2713{
2714 AssertIndexRange(i, this->table_size[0]);
2715 return ::internal::TableBaseAccessors::Accessor<2, T, true, 1>(
2716 *this, this->values.begin() + size_type(i) * n_cols());
2717}
2718
2719
2720
2721template <typename T>
2722inline ::internal::TableBaseAccessors::Accessor<2, T, false, 1>
2724{
2725 AssertIndexRange(i, this->table_size[0]);
2726 return ::internal::TableBaseAccessors::Accessor<2, T, false, 1>(
2727 *this, this->values.begin() + size_type(i) * n_cols());
2728}
2729
2730
2731
2732template <typename T>
2734Table<2, T>::operator()(const size_type i, const size_type j) const
2735{
2736 AssertIndexRange(i, this->table_size[0]);
2737 AssertIndexRange(j, this->table_size[1]);
2738 return this->values[size_type(i) * this->table_size[1] + j];
2739}
2740
2741
2742
2743template <typename T>
2744inline typename AlignedVector<T>::reference
2746{
2747 AssertIndexRange(i, this->table_size[0]);
2748 AssertIndexRange(j, this->table_size[1]);
2749 return this->values[size_type(i) * this->table_size[1] + j];
2750}
2751
2752
2753
2754template <typename T>
2756Table<2, T>::el(const size_type i, const size_type j) const
2757{
2758 return this->values[size_type(i) * this->table_size[1] + j];
2759}
2760
2761
2762
2763template <typename T>
2764inline typename AlignedVector<T>::reference
2765Table<2, T>::el(const size_type i, const size_type j)
2766{
2767 return this->values[size_type(i) * this->table_size[1] + j];
2768}
2769
2770
2771
2772template <typename T>
2773inline typename Table<2, T>::size_type
2774Table<2, T>::n_rows() const
2775{
2776 return this->table_size[0];
2777}
2778
2779
2780
2781template <typename T>
2782inline typename Table<2, T>::size_type
2783Table<2, T>::n_cols() const
2784{
2785 return this->table_size[1];
2786}
2787
2788
2789
2790template <typename T>
2791inline typename Table<2, T>::iterator
2793{
2794 return typename Table<2, T>::iterator(this, 0, 0);
2795}
2796
2797
2798
2799template <typename T>
2800inline typename Table<2, T>::const_iterator
2801Table<2, T>::begin() const
2802{
2803 return typename Table<2, T>::const_iterator(this, 0, 0);
2804}
2805
2806
2807
2808template <typename T>
2809inline typename Table<2, T>::iterator
2811{
2812 return typename Table<2, T>::iterator(this);
2813}
2814
2815
2816
2817template <typename T>
2818inline typename Table<2, T>::const_iterator
2819Table<2, T>::end() const
2820{
2821 return typename Table<2, T>::const_iterator(this);
2822}
2823
2824
2825
2826//---------------------------------------------------------------------------
2827namespace MatrixTableIterators
2828{
2829 namespace internal
2830 {
2831 // Internal calculation routines for AccessorBase. These do not do any
2832 // checking whatsoever.
2833 template <typename TableType, Storage storage_order>
2834 inline std::ptrdiff_t
2835 get_row_index(const std::ptrdiff_t linear_index,
2836 const TableType *const container)
2837 {
2838 switch (storage_order)
2839 {
2840 case Storage::row_major:
2841 return linear_index / container->n_cols();
2843 return linear_index % container->n_rows();
2844 default:
2845 Assert(false, ExcInternalError());
2846 }
2847 return {};
2848 }
2849
2850
2851
2852 template <typename TableType, Storage storage_order>
2853 inline std::ptrdiff_t
2854 get_column_index(const std::ptrdiff_t linear_index,
2855 const TableType *const container)
2856 {
2857 switch (storage_order)
2858 {
2859 case Storage::row_major:
2860 return linear_index % container->n_cols();
2862 return linear_index / container->n_rows();
2863 default:
2864 Assert(false, ExcInternalError());
2865 }
2866 return {};
2867 }
2868 } // namespace internal
2869
2870
2871
2872 template <typename TableType, bool Constness, Storage storage_order>
2874 : container(nullptr)
2875 , linear_index(std::numeric_limits<decltype(linear_index)>::max())
2876 {}
2877
2878
2879
2880 template <typename TableType, bool Constness, Storage storage_order>
2881 inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2882 const container_pointer_type table)
2883 : container(table)
2884 , linear_index(container->values.size())
2885 {}
2886
2887
2888
2889 template <typename TableType, bool Constness, Storage storage_order>
2890 inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2891 const AccessorBase<TableType, false, storage_order> &a)
2892 : container(a.container)
2893 , linear_index(a.linear_index)
2894 {}
2895
2896
2897
2898 template <typename TableType, bool Constness, Storage storage_order>
2899 inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2900 const container_pointer_type table,
2901 const std::ptrdiff_t index)
2902 : container(table)
2903 , linear_index(index)
2904 {
2905 Assert(0 <= linear_index &&
2906 std::size_t(linear_index) < container->values.size() + 1,
2907 ExcMessage("The current iterator points outside of the table and is "
2908 "not the end iterator."));
2909 }
2910
2911
2912
2913 template <typename TableType, bool Constness, Storage storage_order>
2914 inline const typename AccessorBase<TableType, Constness, storage_order>::
2915 value_type &
2916 AccessorBase<TableType, Constness, storage_order>::value() const
2917 {
2918 assert_valid_linear_index();
2919 return this->container->values[linear_index];
2920 }
2921
2922
2923
2924 template <typename TableType, bool Constness, Storage storage_order>
2925 inline AccessorBase<TableType, Constness, storage_order>::
2926 operator const value_type &() const
2927 {
2928 assert_valid_linear_index();
2929 return this->container->values[linear_index];
2930 }
2931
2932
2933
2934 template <typename TableType, bool Constness, Storage storage_order>
2936 AccessorBase<TableType, Constness, storage_order>::row() const
2937 {
2938 assert_valid_linear_index();
2939 return static_cast<std::size_t>(
2940 internal::get_row_index<TableType, storage_order>(linear_index,
2941 container));
2942 }
2943
2944
2945
2946 template <typename TableType, bool Constness, Storage storage_order>
2948 AccessorBase<TableType, Constness, storage_order>::column() const
2949 {
2950 assert_valid_linear_index();
2951 return static_cast<std::size_t>(
2952 internal::get_column_index<TableType, storage_order>(linear_index,
2953 container));
2954 }
2955
2956
2957
2958 template <typename TableType, bool Constness, Storage storage_order>
2959 inline void
2960 AccessorBase<TableType, Constness, storage_order>::assert_valid_linear_index()
2961 const
2962 {
2963# ifdef DEBUG // avoid unused variable warnings by guarding everything
2964 Assert(container != nullptr,
2965 ExcMessage("This accessor has been default-constructed and does not "
2966 "have a corresponding table."));
2967 Assert(!container->empty(),
2968 ExcMessage("An empty table has no rows or columns."));
2969 Assert(0 <= linear_index &&
2970 std::size_t(linear_index) < container->values.size(),
2971 ExcMessage("The current iterator points outside of the table."));
2972 const std::ptrdiff_t row_n =
2973 internal::get_row_index<TableType, storage_order>(linear_index,
2974 container);
2975 const std::ptrdiff_t column_n =
2976 internal::get_column_index<TableType, storage_order>(linear_index,
2977 container);
2978 Assert(0 <= column_n && std::size_t(column_n) < container->n_cols(),
2979 ExcMessage("The current iterator points outside the table."));
2980 Assert(0 <= row_n && std::size_t(row_n) < container->n_rows(),
2981 ExcMessage("The current iterator points outside the table."));
2982# endif
2983 }
2984
2985
2986
2987 template <typename TableType, Storage storage_order>
2988 inline const Accessor<TableType, false, storage_order> &
2989 Accessor<TableType, false, storage_order>::operator=(
2990 const typename Accessor<TableType, false, storage_order>::value_type &t)
2991 const
2992 {
2993 this->assert_valid_linear_index();
2994 this->container->values[this->linear_index] = t;
2995 return *this;
2996 }
2997
2998
2999
3000 template <typename TableType, Storage storage_order>
3001 inline const Accessor<TableType, false, storage_order> &
3002 Accessor<TableType, false, storage_order>::operator=(
3003 typename Accessor<TableType, false, storage_order>::value_type &&t) const
3004 {
3005 this->assert_valid_linear_index();
3006 this->container->values[this->linear_index] = t;
3007 return *this;
3008 }
3009
3010
3011
3012 template <typename TableType, Storage storage_order>
3013 inline typename Accessor<TableType, false, storage_order>::value_type &
3014 Accessor<TableType, false, storage_order>::value() const
3015 {
3016 this->assert_valid_linear_index();
3017 return this->container->values[this->linear_index];
3018 }
3019
3020
3021
3022 template <typename TableType, Storage storage_order>
3023 inline Accessor<TableType, false, storage_order>::operator value_type &()
3024 {
3025 this->assert_valid_linear_index();
3026 return this->container->values[this->linear_index];
3027 }
3028
3029
3030
3031 template <typename TableType, bool Constness, Storage storage_order>
3032 inline Iterator<TableType, Constness, storage_order>::Iterator(
3034 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3035 Accessor<TableType, Constness, storage_order>>(a)
3036 {}
3037
3038
3039
3040 template <typename TableType, bool Constness, Storage storage_order>
3041 inline Iterator<TableType, Constness, storage_order>::Iterator(
3042 const container_pointer_type table)
3043 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3044 Accessor<TableType, Constness, storage_order>>(
3045 Accessor<TableType, Constness, storage_order>(table))
3046 {}
3047
3048
3049
3050 template <typename TableType, bool Constness, Storage storage_order>
3051 inline Iterator<TableType, Constness, storage_order>::Iterator(
3052 const Iterator<TableType, false, storage_order> &i)
3053 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3054 Accessor<TableType, Constness, storage_order>>(*i)
3055 {}
3056
3057
3058
3059 template <typename TableType, bool Constness, Storage storage_order>
3060 inline Iterator<TableType, Constness, storage_order>::Iterator(
3061 const container_pointer_type table,
3062 const size_type row_n,
3063 const size_type col_n)
3064 : Iterator(table,
3065 storage_order == Storage::row_major ?
3066 table->n_cols() * row_n + col_n :
3067 table->n_rows() * col_n + row_n)
3068 {}
3069
3070
3071
3072 template <typename TableType, bool Constness, Storage storage_order>
3073 inline Iterator<TableType, Constness, storage_order>::Iterator(
3074 const container_pointer_type table,
3075 const std::ptrdiff_t linear_index)
3076 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3077 Accessor<TableType, Constness, storage_order>>(
3078 Accessor<TableType, Constness, storage_order>(table, linear_index))
3079 {}
3080} // namespace MatrixTableIterators
3081
3082
3083
3084//---------------------------------------------------------------------------
3085template <typename T>
3087 const size_type size2)
3088 : TableBase<2, T>(TableIndices<2>(size2, size1))
3089{}
3090
3091
3092
3093template <typename T>
3094inline void
3096 const size_type size2,
3097 const bool omit_default_initialization)
3098{
3099 this->TableBase<2, T>::reinit(TableIndices<2>(size2, size1),
3100 omit_default_initialization);
3101}
3102
3103
3104
3105template <typename T>
3108{
3109 AssertIndexRange(i, this->table_size[1]);
3110 AssertIndexRange(j, this->table_size[0]);
3111 return this->values[size_type(j) * this->table_size[1] + i];
3112}
3113
3114
3115
3116template <typename T>
3117inline typename TransposeTable<T>::reference
3119{
3120 AssertIndexRange(i, this->table_size[1]);
3121 AssertIndexRange(j, this->table_size[0]);
3122 return this->values[size_type(j) * this->table_size[1] + i];
3123}
3124
3125
3126
3127template <typename T>
3129TransposeTable<T>::el(const size_type i, const size_type j) const
3130{
3131 return this->values[size_type(j) * this->table_size[1] + i];
3132}
3133
3134
3135
3136template <typename T>
3137inline typename TransposeTable<T>::reference
3139{
3140 return this->values[size_type(j) * this->table_size[1] + i];
3141}
3142
3143
3144
3145template <typename T>
3146inline typename TransposeTable<T>::size_type
3148{
3149 return this->table_size[1];
3150}
3151
3152
3153
3154template <typename T>
3155inline typename TransposeTable<T>::size_type
3157{
3158 return this->table_size[0];
3159}
3160
3161
3162
3163template <typename T>
3164inline typename TransposeTable<T>::iterator
3166{
3167 return typename TransposeTable<T>::iterator(this, 0, 0);
3168}
3169
3170
3171
3172template <typename T>
3175{
3176 return typename TransposeTable<T>::const_iterator(this, 0, 0);
3177}
3178
3179
3180
3181template <typename T>
3182inline typename TransposeTable<T>::iterator
3184{
3185 return typename TransposeTable<T>::iterator(this);
3186}
3187
3188
3189
3190template <typename T>
3193{
3194 return typename TransposeTable<T>::const_iterator(this);
3195}
3196//---------------------------------------------------------------------------
3197
3198
3199
3200template <typename T>
3201inline Table<3, T>::Table(const size_type size1,
3202 const size_type size2,
3203 const size_type size3)
3204 : TableBase<3, T>(TableIndices<3>(size1, size2, size3))
3205{}
3206
3207
3208
3209template <typename T>
3210template <typename InputIterator>
3211inline Table<3, T>::Table(const size_type size1,
3212 const size_type size2,
3213 const size_type size3,
3214 InputIterator entries,
3215 const bool C_style_indexing)
3216 : TableBase<3, T>(TableIndices<3>(size1, size2, size3),
3217 entries,
3218 C_style_indexing)
3219{}
3220
3221
3222
3223template <typename T>
3224inline ::internal::TableBaseAccessors::Accessor<3, T, true, 2>
3225 Table<3, T>::operator[](const size_type i) const
3226{
3227 AssertIndexRange(i, this->table_size[0]);
3228 const size_type subobject_size =
3229 size_type(this->table_size[1]) * this->table_size[2];
3231 *this, this->values.begin() + i * subobject_size));
3232}
3233
3234
3235
3236template <typename T>
3237inline ::internal::TableBaseAccessors::Accessor<3, T, false, 2>
3239{
3240 AssertIndexRange(i, this->table_size[0]);
3241 const size_type subobject_size =
3242 size_type(this->table_size[1]) * this->table_size[2];
3244 *this, this->values.begin() + i * subobject_size));
3245}
3246
3247
3248
3249template <typename T>
3252operator()(const size_type i, const size_type j, const size_type k) const
3253{
3254 AssertIndexRange(i, this->table_size[0]);
3255 AssertIndexRange(j, this->table_size[1]);
3256 AssertIndexRange(k, this->table_size[2]);
3257 return this
3258 ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3259 k];
3260}
3261
3262
3263
3264template <typename T>
3265inline typename AlignedVector<T>::reference
3266Table<3, T>::operator()(const size_type i, const size_type j, const size_type k)
3267{
3268 AssertIndexRange(i, this->table_size[0]);
3269 AssertIndexRange(j, this->table_size[1]);
3270 AssertIndexRange(k, this->table_size[2]);
3271 return this
3272 ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3273 k];
3274}
3275
3276
3277
3278template <typename T>
3279inline Table<4, T>::Table(const size_type size1,
3280 const size_type size2,
3281 const size_type size3,
3282 const size_type size4)
3283 : TableBase<4, T>(TableIndices<4>(size1, size2, size3, size4))
3284{}
3285
3286
3287
3288template <typename T>
3289inline ::internal::TableBaseAccessors::Accessor<4, T, true, 3>
3290 Table<4, T>::operator[](const size_type i) const
3291{
3292 AssertIndexRange(i, this->table_size[0]);
3293 const size_type subobject_size =
3294 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3296 *this, this->values.begin() + i * subobject_size));
3297}
3298
3299
3300
3301template <typename T>
3302inline ::internal::TableBaseAccessors::Accessor<4, T, false, 3>
3304{
3305 AssertIndexRange(i, this->table_size[0]);
3306 const size_type subobject_size =
3307 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3309 *this, this->values.begin() + i * subobject_size));
3310}
3311
3312
3313
3314template <typename T>
3317 const size_type j,
3318 const size_type k,
3319 const size_type l) const
3320{
3321 AssertIndexRange(i, this->table_size[0]);
3322 AssertIndexRange(j, this->table_size[1]);
3323 AssertIndexRange(k, this->table_size[2]);
3324 AssertIndexRange(l, this->table_size[3]);
3325 return this
3326 ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3327 k) *
3328 this->table_size[3] +
3329 l];
3330}
3331
3332
3333
3334template <typename T>
3335inline typename AlignedVector<T>::reference
3337 const size_type j,
3338 const size_type k,
3339 const size_type l)
3340{
3341 AssertIndexRange(i, this->table_size[0]);
3342 AssertIndexRange(j, this->table_size[1]);
3343 AssertIndexRange(k, this->table_size[2]);
3344 AssertIndexRange(l, this->table_size[3]);
3345 return this
3346 ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3347 k) *
3348 this->table_size[3] +
3349 l];
3350}
3351
3352
3353
3354template <typename T>
3355inline Table<5, T>::Table(const size_type size1,
3356 const size_type size2,
3357 const size_type size3,
3358 const size_type size4,
3359 const size_type size5)
3360 : TableBase<5, T>(TableIndices<5>(size1, size2, size3, size4, size5))
3361{}
3362
3363
3364
3365template <typename T>
3366inline ::internal::TableBaseAccessors::Accessor<5, T, true, 4>
3367 Table<5, T>::operator[](const size_type i) const
3368{
3369 AssertIndexRange(i, this->table_size[0]);
3370 const size_type subobject_size = size_type(this->table_size[1]) *
3371 this->table_size[2] * this->table_size[3] *
3372 this->table_size[4];
3374 *this, this->values.begin() + i * subobject_size));
3375}
3376
3377
3378
3379template <typename T>
3380inline ::internal::TableBaseAccessors::Accessor<5, T, false, 4>
3382{
3383 AssertIndexRange(i, this->table_size[0]);
3384 const size_type subobject_size = size_type(this->table_size[1]) *
3385 this->table_size[2] * this->table_size[3] *
3386 this->table_size[4];
3388 *this, this->values.begin() + i * subobject_size));
3389}
3390
3391
3392
3393template <typename T>
3396 const size_type j,
3397 const size_type k,
3398 const size_type l,
3399 const size_type m) const
3400{
3401 AssertIndexRange(i, this->table_size[0]);
3402 AssertIndexRange(j, this->table_size[1]);
3403 AssertIndexRange(k, this->table_size[2]);
3404 AssertIndexRange(l, this->table_size[3]);
3405 AssertIndexRange(m, this->table_size[4]);
3406 return this
3407 ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3408 k) *
3409 this->table_size[3] +
3410 l) *
3411 this->table_size[4] +
3412 m];
3413}
3414
3415
3416
3417template <typename T>
3418inline typename AlignedVector<T>::reference
3420 const size_type j,
3421 const size_type k,
3422 const size_type l,
3423 const size_type m)
3424{
3425 AssertIndexRange(i, this->table_size[0]);
3426 AssertIndexRange(j, this->table_size[1]);
3427 AssertIndexRange(k, this->table_size[2]);
3428 AssertIndexRange(l, this->table_size[3]);
3429 AssertIndexRange(m, this->table_size[4]);
3430 return this
3431 ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3432 k) *
3433 this->table_size[3] +
3434 l) *
3435 this->table_size[4] +
3436 m];
3437}
3438
3439
3440
3441template <typename T>
3442inline Table<6, T>::Table(const size_type size1,
3443 const size_type size2,
3444 const size_type size3,
3445 const size_type size4,
3446 const size_type size5,
3447 const size_type size6)
3448 : TableBase<6, T>()
3449{
3450 TableIndices<6> table_indices;
3451 table_indices[0] = size1;
3452 table_indices[1] = size2;
3453 table_indices[2] = size3;
3454 table_indices[3] = size4;
3455 table_indices[4] = size5;
3456 table_indices[5] = size6;
3457
3458 TableBase<6, T>::reinit(table_indices);
3459}
3460
3461
3462
3463template <typename T>
3464inline ::internal::TableBaseAccessors::Accessor<6, T, true, 5>
3465 Table<6, T>::operator[](const size_type i) const
3466{
3467 AssertIndexRange(i, this->table_size[0]);
3468 const size_type subobject_size = size_type(this->table_size[1]) *
3469 this->table_size[2] * this->table_size[3] *
3470 this->table_size[4] * this->table_size[5];
3472 *this, this->values.begin() + i * subobject_size));
3473}
3474
3475
3476
3477template <typename T>
3478inline ::internal::TableBaseAccessors::Accessor<6, T, false, 5>
3480{
3481 AssertIndexRange(i, this->table_size[0]);
3482 const size_type subobject_size = size_type(this->table_size[1]) *
3483 this->table_size[2] * this->table_size[3] *
3484 this->table_size[4] * this->table_size[5];
3486 *this, this->values.begin() + i * subobject_size));
3487}
3488
3489
3490
3491template <typename T>
3494 const size_type j,
3495 const size_type k,
3496 const size_type l,
3497 const size_type m,
3498 const size_type n) const
3499{
3500 AssertIndexRange(i, this->table_size[0]);
3501 AssertIndexRange(j, this->table_size[1]);
3502 AssertIndexRange(k, this->table_size[2]);
3503 AssertIndexRange(l, this->table_size[3]);
3504 AssertIndexRange(m, this->table_size[4]);
3505 AssertIndexRange(n, this->table_size[5]);
3506 return this
3507 ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3508 k) *
3509 this->table_size[3] +
3510 l) *
3511 this->table_size[4] +
3512 m) *
3513 this->table_size[5] +
3514 n];
3515}
3516
3517
3518
3519template <typename T>
3520inline typename AlignedVector<T>::reference
3522 const size_type j,
3523 const size_type k,
3524 const size_type l,
3525 const size_type m,
3526 const size_type n)
3527{
3528 AssertIndexRange(i, this->table_size[0]);
3529 AssertIndexRange(j, this->table_size[1]);
3530 AssertIndexRange(k, this->table_size[2]);
3531 AssertIndexRange(l, this->table_size[3]);
3532 AssertIndexRange(m, this->table_size[4]);
3533 AssertIndexRange(n, this->table_size[5]);
3534 return this
3535 ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3536 k) *
3537 this->table_size[3] +
3538 l) *
3539 this->table_size[4] +
3540 m) *
3541 this->table_size[5] +
3542 n];
3543}
3544
3545
3546
3547template <typename T>
3548inline Table<7, T>::Table(const size_type size1,
3549 const size_type size2,
3550 const size_type size3,
3551 const size_type size4,
3552 const size_type size5,
3553 const size_type size6,
3554 const size_type size7)
3555 : TableBase<7, T>()
3556{
3557 TableIndices<7> table_indices;
3558 table_indices[0] = size1;
3559 table_indices[1] = size2;
3560 table_indices[2] = size3;
3561 table_indices[3] = size4;
3562 table_indices[4] = size5;
3563 table_indices[5] = size6;
3564 table_indices[6] = size7;
3565
3566 TableBase<7, T>::reinit(table_indices);
3567}
3568
3569
3570
3571template <typename T>
3572inline ::internal::TableBaseAccessors::Accessor<7, T, true, 6>
3573 Table<7, T>::operator[](const size_type i) const
3574{
3575 AssertIndexRange(i, this->table_size[0]);
3576 const size_type subobject_size =
3577 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3578 this->table_size[4] * this->table_size[5] * this->table_size[6];
3580 *this, this->values.begin() + i * subobject_size));
3581}
3582
3583
3584
3585template <typename T>
3586inline ::internal::TableBaseAccessors::Accessor<7, T, false, 6>
3588{
3589 AssertIndexRange(i, this->table_size[0]);
3590 const size_type subobject_size =
3591 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3592 this->table_size[4] * this->table_size[5] * this->table_size[6];
3594 *this, this->values.begin() + i * subobject_size));
3595}
3596
3597
3598
3599template <typename T>
3602 const size_type j,
3603 const size_type k,
3604 const size_type l,
3605 const size_type m,
3606 const size_type n,
3607 const size_type o) const
3608{
3609 AssertIndexRange(i, this->table_size[0]);
3610 AssertIndexRange(j, this->table_size[1]);
3611 AssertIndexRange(k, this->table_size[2]);
3612 AssertIndexRange(l, this->table_size[3]);
3613 AssertIndexRange(m, this->table_size[4]);
3614 AssertIndexRange(n, this->table_size[5]);
3615 AssertIndexRange(o, this->table_size[6]);
3616 return this->values
3617 [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3618 this->table_size[3] +
3619 l) *
3620 this->table_size[4] +
3621 m) *
3622 this->table_size[5] +
3623 n) *
3624 this->table_size[6] +
3625 o];
3626}
3627
3628
3629
3630template <typename T>
3631inline typename AlignedVector<T>::reference
3633 const size_type j,
3634 const size_type k,
3635 const size_type l,
3636 const size_type m,
3637 const size_type n,
3638 const size_type o)
3639{
3640 AssertIndexRange(i, this->table_size[0]);
3641 AssertIndexRange(j, this->table_size[1]);
3642 AssertIndexRange(k, this->table_size[2]);
3643 AssertIndexRange(l, this->table_size[3]);
3644 AssertIndexRange(m, this->table_size[4]);
3645 AssertIndexRange(n, this->table_size[5]);
3646 AssertIndexRange(o, this->table_size[6]);
3647 return this->values
3648 [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3649 this->table_size[3] +
3650 l) *
3651 this->table_size[4] +
3652 m) *
3653 this->table_size[5] +
3654 n) *
3655 this->table_size[6] +
3656 o];
3657}
3658
3659
3660#endif // DOXYGEN
3661
3662
3663
3669template <int N, typename T>
3670inline void
3672{
3673 u.swap(v);
3674}
3675
3677
3678#endif
value_type & reference
std::size_t size_type
const value_type * const_iterator
const value_type & const_reference
value_type * iterator
void swap(BlockIndices &u, BlockIndices &v)
Accessor base class for Table<2, T> and TransposeTable.
Definition: table.h:975
AccessorBase(const AccessorBase< TableType, false, storage_order > &)
typename TableType::value_type value_type
Definition: table.h:986
const value_type & value() const
container_pointer_type container
Definition: table.h:1055
AccessorBase(const container_pointer_type table)
AccessorBase(const container_pointer_type table, const std::ptrdiff_t linear_index)
typename std::conditional< Constness, const TableType *, TableType * >::type container_pointer_type
Definition: table.h:981
friend bool operator==(const AccessorBase< TableType, Constness, storage_order > &left, const AccessorBase< TableType, OtherConstness, storage_order > &right)
Definition: table.h:1019
typename TableType::size_type size_type
Definition: table.h:991
Accessor class offering read and write access to the elements of a table.
Definition: table.h:1114
const Accessor< TableType, false, storage_order > & operator=(value_type &&) const
const Accessor< TableType, false, storage_order > & operator=(const value_type &) const
typename AccessorBase< TableType, true, storage_order >::value_type value_type
Definition: table.h:1120
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition: table.h:1126
typename AccessorBase< TableType, true, storage_order >::value_type value_type
Definition: table.h:1093
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition: table.h:1099
Accessor class template. This class is partially specialized for both values of Constness.
Definition: table.h:955
Iterator class for both matrix-like tables, i.e., Table<2, T> and TransposeTable.
Definition: table.h:1182
Iterator(const container_pointer_type object, const size_type row, const size_type column)
Iterator(const Accessor< TableType, Constness, storage_order > &accessor)
Iterator(const container_pointer_type object)
Iterator(const Iterator< TableType, false, storage_order > &i)
typename std::conditional< Constness, const TableType *, TableType * >::type container_pointer_type
Definition: table.h:1193
Iterator(const container_pointer_type container, const std::ptrdiff_t linear_index)
typename TableType::size_type size_type
Definition: table.h:1187
void swap(TableBase< N, T > &v)
void replicate_across_communicator(const MPI_Comm &communicator, const unsigned int root_process)
void fill(const T &value)
friend class TableBase
Definition: table.h:796
std::size_t memory_consumption() const
TableBase< N, T > & operator=(const TableBase< N, T > &src)
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
AlignedVector< T >::const_reference el(const TableIndices< N > &indices) const
AlignedVector< T >::const_reference operator()(const TableIndices< N > &indices) const
AlignedVector< T > values
Definition: table.h:787
TableBase< N, T > & operator=(TableBase< N, T > &&src) noexcept
~TableBase() override=default
typename AlignedVector< T >::size_type size_type
Definition: table.h:446
size_type n_elements() const
TableBase(const TableBase< N, T2 > &src)
TableBase(const TableIndices< N > &sizes, InputIterator entries, const bool C_style_indexing=true)
T value_type
Definition: table.h:441
const TableIndices< N > & size() const
bool operator==(const TableBase< N, T > &T2) const
TableBase()=default
size_type position(const TableIndices< N > &indices) const
TableBase(const TableBase< N, T > &src)
bool empty() const
TableBase< N, T > & operator=(const TableBase< N, T2 > &src)
AlignedVector< T >::reference operator()(const TableIndices< N > &indices)
AlignedVector< T >::reference el(const TableIndices< N > &indices)
void fill(InputIterator entries, const bool C_style_indexing=true)
void serialize(Archive &ar, const unsigned int version)
void reset_values()
TableBase(const TableIndices< N > &sizes)
size_type size(const unsigned int i) const
TableBase(TableBase< N, T > &&src) noexcept
TableIndices< N > table_size
Definition: table.h:792
Table(const size_type size)
AlignedVector< T >::const_reference operator[](const size_type i) const
typename TableBase< 1, T >::size_type size_type
Definition: table.h:831
AlignedVector< T >::reference operator[](const size_type i)
Table()=default
AlignedVector< T >::const_reference operator()(const size_type i) const
AlignedVector< T >::reference operator()(const size_type i)
Table(const size_type size, InputIterator entries, const bool C_style_indexing=true)
size_type n_cols() const
AlignedVector< T >::reference operator()(const size_type i, const size_type j)
AlignedVector< T >::reference el(const size_type i, const size_type j)
typename AlignedVector< T >::const_reference const_reference
Definition: table.h:1262
typename AlignedVector< T >::value_type value_type
Definition: table.h:1252
iterator end()
Table()=default
AlignedVector< T >::const_reference operator()(const size_type i, const size_type j) const
::internal::TableBaseAccessors::Accessor< 2, T, false, 1 > operator[](const size_type i)
typename TableBase< 2, T >::size_type size_type
Definition: table.h:1247
::internal::TableBaseAccessors::Accessor< 2, T, true, 1 > operator[](const size_type i) const
AlignedVector< T >::const_reference el(const size_type i, const size_type j) const
typename AlignedVector< T >::reference reference
Definition: table.h:1257
const_iterator end() const
Table(const size_type size1, const size_type size2, InputIterator entries, const bool C_style_indexing=true)
void reinit(const size_type size1, const size_type size2, const bool omit_default_initialization=false)
const_iterator begin() const
Table(const size_type size1, const size_type size2)
size_type n_rows() const
iterator begin()
::internal::TableBaseAccessors::Accessor< 3, T, true, 2 > operator[](const size_type i) const
AlignedVector< T >::const_reference operator()(const size_type i, const size_type j, const size_type k) const
Table()=default
AlignedVector< T >::reference operator()(const size_type i, const size_type j, const size_type k)
Table(const size_type size1, const size_type size2, const size_type size3)
Table(const size_type size1, const size_type size2, const size_type size3, InputIterator entries, const bool C_style_indexing=true)
typename TableBase< 3, T >::size_type size_type
Definition: table.h:1484
::internal::TableBaseAccessors::Accessor< 3, T, false, 2 > operator[](const size_type i)
::internal::TableBaseAccessors::Accessor< 4, T, true, 3 > operator[](const size_type i) const
Table(const size_type size1, const size_type size2, const size_type size3, const size_type size4)
AlignedVector< T >::const_reference operator()(const size_type i, const size_type j, const size_type k, const size_type l) const
typename TableBase< 4, T >::size_type size_type
Definition: table.h:1606
::internal::TableBaseAccessors::Accessor< 4, T, false, 3 > operator[](const size_type i)
AlignedVector< T >::reference operator()(const size_type i, const size_type j, const size_type k, const size_type l)
Table()=default
typename TableBase< 5, T >::size_type size_type
Definition: table.h:1690
::internal::TableBaseAccessors::Accessor< 5, T, false, 4 > operator[](const size_type i)
AlignedVector< T >::reference operator()(const size_type i, const size_type j, const size_type k, const size_type l, const size_type m)
AlignedVector< T >::const_reference operator()(const size_type i, const size_type j, const size_type k, const size_type l, const size_type m) const
::internal::TableBaseAccessors::Accessor< 5, T, true, 4 > operator[](const size_type i) const
Table()=default
Table(const size_type size1, const size_type size2, const size_type size3, const size_type size4, const size_type size5)
::internal::TableBaseAccessors::Accessor< 6, T, false, 5 > operator[](const size_type i)
Table()=default
AlignedVector< T >::const_reference operator()(const size_type i, const size_type j, const size_type k, const size_type l, const size_type m, const size_type n) const
Table(const size_type size1, const size_type size2, const size_type size3, const size_type size4, const size_type size5, const size_type size6)
AlignedVector< T >::reference operator()(const size_type i, const size_type j, const size_type k, const size_type l, const size_type m, const size_type n)
typename TableBase< 6, T >::size_type size_type
Definition: table.h:1777
::internal::TableBaseAccessors::Accessor< 6, T, true, 5 > operator[](const size_type i) const
::internal::TableBaseAccessors::Accessor< 7, T, false, 6 > operator[](const size_type i)
typename TableBase< 7, T >::size_type size_type
Definition: table.h:1865
::internal::TableBaseAccessors::Accessor< 7, T, true, 6 > operator[](const size_type i) const
AlignedVector< T >::reference operator()(const size_type i, const size_type j, const size_type k, const size_type l, const size_type m, const size_type n, const size_type o)
AlignedVector< T >::const_reference operator()(const size_type i, const size_type j, const size_type k, const size_type l, const size_type m, const size_type n, const size_type o) const
Table()=default
Table(const size_type size1, const size_type size2, const size_type size3, const size_type size4, const size_type size5, const size_type size6, const size_type size7)
void reinit(const size_type size1, const size_type size2, const bool omit_default_initialization=false)
TransposeTable(const size_type size1, const size_type size2)
MatrixTableIterators::Iterator< TransposeTable< T >, false, MatrixTableIterators::Storage::column_major > iterator
Definition: table.h:1991
size_type n_rows() const
reference el(const size_type i, const size_type j)
const_iterator begin() const
size_type n_cols() const
TransposeTable()=default
MatrixTableIterators::Iterator< TransposeTable< T >, true, MatrixTableIterators::Storage::column_major > const_iterator
Definition: table.h:1983
const_iterator end() const
iterator end()
typename AlignedVector< T >::reference reference
Definition: table.h:1969
typename TableBase< 2, T >::size_type size_type
Definition: table.h:1959
iterator begin()
const_reference operator()(const size_type i, const size_type j) const
typename AlignedVector< T >::value_type value_type
Definition: table.h:1964
const_reference el(const size_type i, const size_type j) const
reference operator()(const size_type i, const size_type j)
typename AlignedVector< T >::const_reference const_reference
Definition: table.h:1974
typename Types< N, T, C >::value_type value_type
Definition: table.h:245
typename Types< N, T, C >::const_iterator const_iterator
Definition: table.h:248
typename Types< N, T, C >::TableType TableType
Definition: table.h:259
typename Types< N, T, C >::const_reference const_reference
Definition: table.h:251
typename Types< N, T, C >::iterator iterator
Definition: table.h:247
reference operator[](const size_type) const
typename Types< N, T, C >::reference reference
Definition: table.h:250
Accessor(const TableType &table, const iterator data)
typename Types< N, T, C >::TableType TableType
Definition: table.h:163
typename Types< N, T, C >::iterator iterator
Definition: table.h:165
Accessor< N, T, C, P - 1 > operator[](const size_type i) const
Accessor(const TableType &table, const iterator data)
typename Types< N, T, C >::const_iterator const_iterator
Definition: table.h:166
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcIndexRange(size_type arg1, size_type arg2, size_type arg3)
#define Assert(cond, exc)
Definition: exceptions.h:1465
#define AssertIndexRange(index, range)
Definition: exceptions.h:1690
static ::ExceptionBase & ExcInternalError()
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:561
static ::ExceptionBase & ExcMessage(std::string arg1)
static const char T
static const char N
types::global_dof_index size_type
Definition: cuda_kernels.h:45
Storage
Enumeration describing the storage order (i.e., the in-memory layout) of a table class.
Definition: table.h:934
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
SymmetricTensor< 2, dim, Number > C(const Tensor< 2, dim, Number > &F)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
T broadcast(const MPI_Comm &comm, const T &object_to_send, const unsigned int root_process=0)
void copy(const T *begin, const T *end, U *dest)
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition: matrix_block.h:618
STL namespace.
typename AlignedVector< T >::iterator iterator
Definition: table.h:115
typename AlignedVector< T >::const_iterator const_iterator
Definition: table.h:116
typename AlignedVector< T >::reference reference
Definition: table.h:118
typename AlignedVector< T >::const_reference const_reference
Definition: table.h:119
typename AlignedVector< T >::const_iterator const_iterator
Definition: table.h:98
typename AlignedVector< T >::const_reference const_reference
Definition: table.h:101
typename AlignedVector< T >::const_iterator iterator
Definition: table.h:97
typename AlignedVector< T >::const_reference reference
Definition: table.h:100
void swap(TableBase< N, T > &u, TableBase< N, T > &v)
Definition: table.h:3671