Reference documentation for deal.II version 9.5.0
\(\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\}}\)
Loading...
Searching...
No Matches
table.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2002 - 2023 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#include <limits>
31
33
34// forward declaration
35#ifndef DOXYGEN
36template <int N, typename T>
37class TableBase;
38template <int N, typename T>
39class Table;
40template <typename T>
41class TransposeTable;
42template <typename T>
43class Table<1, T>;
44template <typename T>
45class Table<2, T>;
46template <typename T>
47class Table<3, T>;
48template <typename T>
49class Table<4, T>;
50template <typename T>
51class Table<5, T>;
52template <typename T>
53class Table<6, T>;
54#endif
55
56
57
58namespace internal
59{
74 namespace TableBaseAccessors
75 {
83 template <int N, typename T, bool Constness>
84 struct Types
85 {};
86
92 template <int N, typename T>
93 struct Types<N, T, true>
94 {
95 using value_type = const T;
97
100
103 };
104
110 template <int N, typename T>
111 struct Types<N, T, false>
112 {
113 using value_type = T;
115
118
121 };
122
123
160 template <int N, typename T, bool C, unsigned int P>
162 {
163 public:
165
168
169 using size_type = size_t;
170 using difference_type = ptrdiff_t;
171
172 private:
179
180 public:
189
193 Accessor<N, T, C, P - 1>
194 operator[](const size_type i) const;
195
201 size_type,
202 size_type,
203 size_type,
204 << "Index " << N - P + 1 << "has a value of " << arg1
205 << " but needs to be in the range [" << arg2 << ',' << arg3
206 << "[.");
207
208 private:
216
217 // declare some other classes
218 // as friends. make sure to
219 // work around bugs in some
220 // compilers
221 template <int N1, typename T1>
222 friend class ::Table;
223 template <int N1, typename T1, bool C1, unsigned int P1>
224 friend class Accessor;
225 friend class ::Table<N, T>;
226 friend class Accessor<N, T, C, P + 1>;
227 };
228
229
230
238 template <int N, typename T, bool C>
239 class Accessor<N, T, C, 1>
240 {
241 public:
248
251
254
255 using size_type = size_t;
256 using difference_type = ptrdiff_t;
257
262
263 private:
276
277 public:
286
291 operator[](const size_type) const;
292
298 size() const;
299
304 begin() const;
305
310 end() const;
311
312 private:
320
321 // declare some other classes
322 // as friends. make sure to
323 // work around bugs in some
324 // compilers
325 template <int N1, typename T1>
326 friend class ::Table;
327 template <int N1, typename T1, bool C1, unsigned int P1>
328 friend class Accessor;
329 friend class ::Table<2, T>;
330 friend class Accessor<N, T, C, 2>;
331 };
332 } // namespace TableBaseAccessors
333
334} // namespace internal
335
336
337
440template <int N, typename T>
441class TableBase : public Subscriptor
442{
443public:
444 using value_type = T;
445
450
451
455 TableBase() = default;
456
461 explicit TableBase(const TableIndices<N> &sizes);
462
468 template <typename InputIterator>
470 InputIterator entries,
471 const bool C_style_indexing = true);
472
477
482 template <typename T2>
484
488 TableBase(TableBase<N, T> &&src) noexcept;
489
493 ~TableBase() override = default;
494
505
513 template <typename T2>
516
522 operator=(TableBase<N, T> &&src) noexcept;
523
527 bool
528 operator==(const TableBase<N, T> &T2) const;
529
534 void
536
545 void
546 reinit(const TableIndices<N> &new_size,
547 const bool omit_default_initialization = false);
548
552 void
554
559 size(const unsigned int i) const;
560
564 const TableIndices<N> &
565 size() const;
566
572 n_elements() const;
573
578 bool
579 empty() const;
580
617 template <typename InputIterator>
618 void
619 fill(InputIterator entries, const bool C_style_indexing = true);
620
624 void
625 fill(const T &value);
626
632
641 operator()(const TableIndices<N> &indices) const;
642
727 void
729 const unsigned int root_process);
730
743 void
745
750 std::size_t
752
758 template <class Archive>
759 void
760 serialize(Archive &ar, const unsigned int version);
761
762protected:
768 position(const TableIndices<N> &indices) const;
769
777 el(const TableIndices<N> &indices);
778
790 el(const TableIndices<N> &indices) const;
791
792protected:
797
802
803 // Make all other table classes friends.
804 template <int, typename>
805 friend class TableBase;
806};
807
808
821template <int N, typename T>
822class Table;
823
824
833template <typename T>
834class Table<1, T> : public TableBase<1, T>
835{
836public:
841
845 Table() = default;
846
850 explicit Table(const size_type size);
851
889 template <typename InputIterator>
890 Table(const size_type size,
891 InputIterator entries,
892 const bool C_style_indexing = true);
893
899 operator[](const size_type i) const;
900
907
913 operator()(const size_type i) const;
914
921
925 using TableBase<1, T>::operator();
926};
927
928
929
938{
943 enum class Storage
944 {
948 row_major,
949
954 };
955
956 // Forward declaration of the iterator class.
957 template <typename TableType, bool Constness, Storage storage_order>
958 class Iterator;
959
964 template <typename TableType, bool Constness, Storage storage_order>
965 class Accessor;
966
983 template <typename TableType, bool Constness, Storage storage_order>
985 {
986 public:
990 using container_pointer_type = typename std::
991 conditional<Constness, const TableType *, TableType *>::type;
992
996 using value_type = typename TableType::value_type;
997
1001 using size_type = typename TableType::size_type;
1002
1007
1012
1017
1022 const std::ptrdiff_t linear_index);
1023
1027 template <bool OtherConstness>
1028 friend bool
1032 {
1033 return left.container == right.container &&
1034 left.linear_index == right.linear_index;
1035 }
1036
1041 const value_type &
1042 value() const;
1043
1047 operator const value_type &() const;
1048
1052 size_type
1053 row() const;
1054
1058 size_type
1059 column() const;
1060
1061 protected:
1066
1070 std::ptrdiff_t linear_index;
1071
1078 void
1080
1081 // Make the const version a friend for copying.
1082 friend class AccessorBase<TableType, true, storage_order>;
1083
1084 // Make the underlying iterator class a friend.
1085 friend class LinearIndexIterator<
1086 Iterator<TableType, Constness, storage_order>,
1087 Accessor<TableType, Constness, storage_order>>;
1088 };
1089
1094 template <typename TableType, Storage storage_order>
1095 class Accessor<TableType, true, storage_order>
1096 : public AccessorBase<TableType, true, storage_order>
1097 {
1098 public:
1104
1110
1114 using AccessorBase<TableType, true, storage_order>::AccessorBase;
1115 };
1116
1121 template <typename TableType, Storage storage_order>
1122 class Accessor<TableType, false, storage_order>
1123 : public AccessorBase<TableType, false, storage_order>
1124 {
1125 public:
1131
1137
1141 using AccessorBase<TableType, false, storage_order>::AccessorBase;
1142
1148 operator=(const value_type &) const;
1149
1156
1161 using AccessorBase<TableType, false, storage_order>::value;
1162
1167 value_type &
1168 value() const;
1169
1173 operator value_type &();
1174 };
1175
1188 template <typename TableType, bool Constness, Storage storage_order>
1190 : public LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
1191 Accessor<TableType, Constness, storage_order>>
1192 {
1193 public:
1197 using size_type = typename TableType::size_type;
1198
1202 using container_pointer_type = typename std::
1203 conditional<Constness, const TableType *, TableType *>::type;
1204
1209
1214
1219 const size_type row,
1220 const size_type column);
1221
1226
1231 const std::ptrdiff_t linear_index);
1232 };
1233} // namespace MatrixTableIterators
1234
1235
1236
1250template <typename T>
1251class Table<2, T> : public TableBase<2, T>
1252{
1253public:
1258
1263
1268
1273
1278 using const_iterator = MatrixTableIterators::
1279 Iterator<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1280
1284 using iterator = MatrixTableIterators::
1285 Iterator<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1286
1290 Table() = default;
1291
1295 Table(const size_type size1, const size_type size2);
1296
1335 template <typename InputIterator>
1336 Table(const size_type size1,
1337 const size_type size2,
1338 InputIterator entries,
1339 const bool C_style_indexing = true);
1340
1346 void
1347 reinit(const size_type size1,
1348 const size_type size2,
1349 const bool omit_default_initialization = false);
1350
1351 using TableBase<2, T>::reinit;
1352
1360 operator[](const size_type i) const;
1361
1370
1378 operator()(const size_type i, const size_type j) const;
1379
1387 operator()(const size_type i, const size_type j);
1388
1392 using TableBase<2, T>::operator();
1393
1398 size_type
1399 n_rows() const;
1400
1405 size_type
1406 n_cols() const;
1407
1411 iterator
1413
1418 begin() const;
1419
1423 iterator
1425
1430 end() const;
1431
1432protected:
1444 el(const size_type i, const size_type j);
1445
1461 el(const size_type i, const size_type j) const;
1462
1463 // Make the AccessorBase class a friend so that it may directly index into
1464 // the array.
1465 friend class MatrixTableIterators::
1466 AccessorBase<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1467 friend class MatrixTableIterators::
1468 AccessorBase<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1469
1470 // Make the mutable accessor class a friend so that we can write to array
1471 // entries with iterators.
1472 friend class MatrixTableIterators::
1473 Accessor<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1474};
1475
1476
1477
1487template <typename T>
1488class Table<3, T> : public TableBase<3, T>
1489{
1490public:
1495
1499 Table() = default;
1500
1504 Table(const size_type size1, const size_type size2, const size_type size3);
1505
1546 template <typename InputIterator>
1547 Table(const size_type size1,
1548 const size_type size2,
1549 const size_type size3,
1550 InputIterator entries,
1551 const bool C_style_indexing = true);
1552
1557 void
1558 reinit(const size_type size1,
1559 const size_type size2,
1560 const size_type size3,
1561 const bool omit_default_initialization = false);
1562
1563 using TableBase<3, T>::reinit;
1564
1573 operator[](const size_type i) const;
1574
1584
1592 operator()(const size_type i, const size_type j, const size_type k) const;
1593
1594
1602 operator()(const size_type i, const size_type j, const size_type k);
1603
1607 using TableBase<3, T>::operator();
1608};
1609
1610
1611
1621template <typename T>
1622class Table<4, T> : public TableBase<4, T>
1623{
1624public:
1629
1633 Table() = default;
1634
1638 Table(const size_type size1,
1639 const size_type size2,
1640 const size_type size3,
1641 const size_type size4);
1642
1651 operator[](const size_type i) const;
1652
1662
1671 const size_type j,
1672 const size_type k,
1673 const size_type l) const;
1674
1675
1684 const size_type j,
1685 const size_type k,
1686 const size_type l);
1687
1691 using TableBase<4, T>::operator();
1692};
1693
1694
1695
1705template <typename T>
1706class Table<5, T> : public TableBase<5, T>
1707{
1708public:
1713
1714
1718 Table() = default;
1719
1723 Table(const size_type size1,
1724 const size_type size2,
1725 const size_type size3,
1726 const size_type size4,
1727 const size_type size5);
1728
1737 operator[](const size_type i) const;
1738
1748
1757 const size_type j,
1758 const size_type k,
1759 const size_type l,
1760 const size_type m) const;
1761
1770 const size_type j,
1771 const size_type k,
1772 const size_type l,
1773 const size_type m);
1774
1778 using TableBase<5, T>::operator();
1779};
1780
1781
1782
1792template <typename T>
1793class Table<6, T> : public TableBase<6, T>
1794{
1795public:
1800
1804 Table() = default;
1805
1809 Table(const size_type size1,
1810 const size_type size2,
1811 const size_type size3,
1812 const size_type size4,
1813 const size_type size5,
1814 const size_type size6);
1815
1824 operator[](const size_type i) const;
1825
1835
1844 const size_type j,
1845 const size_type k,
1846 const size_type l,
1847 const size_type m,
1848 const size_type n) const;
1849
1858 const size_type j,
1859 const size_type k,
1860 const size_type l,
1861 const size_type m,
1862 const size_type n);
1863
1867 using TableBase<6, T>::operator();
1868};
1869
1870
1880template <typename T>
1881class Table<7, T> : public TableBase<7, T>
1882{
1883public:
1888
1892 Table() = default;
1893
1897 Table(const size_type size1,
1898 const size_type size2,
1899 const size_type size3,
1900 const size_type size4,
1901 const size_type size5,
1902 const size_type size6,
1903 const size_type size7);
1904
1913 operator[](const size_type i) const;
1914
1924
1933 const size_type j,
1934 const size_type k,
1935 const size_type l,
1936 const size_type m,
1937 const size_type n,
1938 const size_type o) const;
1939
1948 const size_type j,
1949 const size_type k,
1950 const size_type l,
1951 const size_type m,
1952 const size_type n,
1953 const size_type o);
1954
1958 using TableBase<7, T>::operator();
1959};
1960
1961
1974template <typename T>
1975class TransposeTable : public TableBase<2, T>
1976{
1977public:
1982
1987
1992
1997
2004 true,
2006
2010 using iterator =
2012 false,
2014
2018 TransposeTable() = default;
2019
2023 TransposeTable(const size_type size1, const size_type size2);
2024
2030 void
2031 reinit(const size_type size1,
2032 const size_type size2,
2033 const bool omit_default_initialization = false);
2034
2042 operator()(const size_type i, const size_type j) const;
2043
2050 reference
2051 operator()(const size_type i, const size_type j);
2052
2057 size_type
2058 n_rows() const;
2059
2064 size_type
2065 n_cols() const;
2066
2070 iterator
2072
2077 begin() const;
2078
2082 iterator
2084
2089 end() const;
2090
2091protected:
2102 reference
2103 el(const size_type i, const size_type j);
2104
2120 el(const size_type i, const size_type j) const;
2121
2122 // Make the AccessorBase class a friend so that it may directly index into
2123 // the array.
2125 TransposeTable<T>,
2126 true,
2127 MatrixTableIterators::Storage::column_major>;
2129 TransposeTable<T>,
2130 false,
2131 MatrixTableIterators::Storage::column_major>;
2132
2133 // Make the mutable accessor class a friend so that we can write to array
2134 // entries with iterators.
2135 friend class MatrixTableIterators::Accessor<
2136 TransposeTable<T>,
2137 false,
2138 MatrixTableIterators::Storage::column_major>;
2139};
2140
2141
2142
2143/* --------------------- Template and inline functions ---------------- */
2144
2145#ifndef DOXYGEN
2146
2147template <int N, typename T>
2148TableBase<N, T>::TableBase(const TableIndices<N> &sizes)
2149{
2150 reinit(sizes);
2151}
2152
2153
2154
2155template <int N, typename T>
2156template <typename InputIterator>
2158 InputIterator entries,
2159 const bool C_style_indexing)
2160{
2161 reinit(sizes);
2162 fill(entries, C_style_indexing);
2163}
2164
2165
2166
2167template <int N, typename T>
2169 : Subscriptor()
2170 , values(src.values)
2171 , table_size(src.table_size)
2172{}
2173
2174
2175
2176template <int N, typename T>
2177template <typename T2>
2179{
2180 reinit(src.table_size);
2181 if (src.n_elements() != 0)
2182 std::copy(src.values.begin(), src.values.end(), values.begin());
2183}
2184
2185
2186
2187template <int N, typename T>
2189 : Subscriptor(std::move(src))
2190 , values(std::move(src.values))
2191 , table_size(src.table_size)
2192{
2194}
2195
2196
2197
2198template <int N, typename T>
2199template <class Archive>
2200inline void
2201TableBase<N, T>::serialize(Archive &ar, const unsigned int)
2202{
2203 ar &static_cast<Subscriptor &>(*this);
2204
2205 ar &values &table_size;
2206}
2207
2208
2209
2210namespace internal
2211{
2212 namespace TableBaseAccessors
2213 {
2214 template <int N, typename T, bool C, unsigned int P>
2215 inline Accessor<N, T, C, P>::Accessor(const TableType &table,
2216 const iterator data)
2217 : table(table)
2218 , data(data)
2219 {}
2220
2221
2222
2223 template <int N, typename T, bool C, unsigned int P>
2224 inline Accessor<N, T, C, P>::Accessor(const Accessor &a)
2225 : table(a.table)
2226 , data(a.data)
2227 {}
2228
2229
2230
2231 template <int N, typename T, bool C, unsigned int P>
2232 inline Accessor<N, T, C, P - 1>
2233 Accessor<N, T, C, P>::operator[](const size_type i) const
2234 {
2235 AssertIndexRange(i, table.size()[N - P]);
2236
2237 // access i-th
2238 // subobject. optimize on the
2239 // case i==0
2240 if (i == 0)
2241 return Accessor<N, T, C, P - 1>(table, data);
2242 else
2243 {
2244 // note: P>1, otherwise the
2245 // specialization would have
2246 // been taken!
2247 size_type subobject_size = table.size()[N - 1];
2248 for (int p = P - 1; p > 1; --p)
2249 subobject_size *= table.size()[N - p];
2250 const iterator new_data = data + i * subobject_size;
2251 return Accessor<N, T, C, P - 1>(table, new_data);
2252 }
2253 }
2254
2255
2256
2257 template <int N, typename T, bool C>
2258 inline Accessor<N, T, C, 1>::Accessor(const TableType &table,
2259 const iterator data)
2260 : table(table)
2261 , data(data)
2262 {}
2263
2264
2265
2266 template <int N, typename T, bool C>
2267 inline Accessor<N, T, C, 1>::Accessor(const Accessor &a)
2268 : table(a.table)
2269 , data(a.data)
2270 {}
2271
2272
2273
2274 template <int N, typename T, bool C>
2275 inline typename Accessor<N, T, C, 1>::reference
2276 Accessor<N, T, C, 1>::operator[](const size_type i) const
2277 {
2278 AssertIndexRange(i, table.size()[N - 1]);
2279 return *(data + i);
2280 }
2281
2282
2283
2284 template <int N, typename T, bool C>
2285 inline typename Accessor<N, T, C, 1>::size_type
2286 Accessor<N, T, C, 1>::size() const
2287 {
2288 return table.size()[N - 1];
2289 }
2290
2291
2292
2293 template <int N, typename T, bool C>
2294 inline typename Accessor<N, T, C, 1>::iterator
2295 Accessor<N, T, C, 1>::begin() const
2296 {
2297 return data;
2298 }
2299
2300
2301
2302 template <int N, typename T, bool C>
2303 inline typename Accessor<N, T, C, 1>::iterator
2304 Accessor<N, T, C, 1>::end() const
2305 {
2306 return data + table.size()[N - 1];
2307 }
2308 } // namespace TableBaseAccessors
2309} // namespace internal
2310
2311
2312
2313template <int N, typename T>
2314inline TableBase<N, T> &
2316{
2317 if (!m.empty())
2318 values = m.values;
2319 reinit(m.size(), true);
2320
2321 return *this;
2322}
2323
2324
2325
2326template <int N, typename T>
2327template <typename T2>
2328inline TableBase<N, T> &
2330{
2331 reinit(m.size(), true);
2332 if (!empty())
2333 std::copy(m.values.begin(),
2334 m.values.begin() + n_elements(),
2335 values.begin());
2336
2337 return *this;
2338}
2339
2340
2341
2342template <int N, typename T>
2343inline TableBase<N, T> &
2345{
2346 static_cast<Subscriptor &>(*this) = std::move(static_cast<Subscriptor &>(m));
2347 values = std::move(m.values);
2348 table_size = m.table_size;
2350
2351 return *this;
2352}
2353
2354
2355
2356template <int N, typename T>
2357inline bool
2359{
2360 return (values == T2.values);
2361}
2362
2363
2364
2365template <int N, typename T>
2366inline void
2368{
2369 // use parallel set operation
2370 if (n_elements() != 0)
2371 values.fill(T());
2372}
2373
2374
2375
2376template <int N, typename T>
2377inline void
2378TableBase<N, T>::fill(const T &value)
2379{
2380 if (n_elements() != 0)
2381 values.fill(value);
2382}
2383
2384
2385
2386template <int N, typename T>
2387inline void
2389 const unsigned int root_process)
2390{
2391 // Replicate first the actual data, then also exchange the
2392 // extents of the table
2393 values.replicate_across_communicator(communicator, root_process);
2394
2395 table_size =
2396 Utilities::MPI::broadcast(communicator, table_size, root_process);
2397}
2398
2399
2400
2401template <int N, typename T>
2402inline void
2404 const bool omit_default_initialization)
2405{
2406 table_size = new_sizes;
2407
2408 const size_type new_size = n_elements();
2409
2410 // if zero size was given: free all memory
2411 if (new_size == 0)
2412 {
2413 values.resize(0);
2414 // set all sizes to zero, even
2415 // if one was previously
2416 // nonzero. This simplifies
2417 // some assertions.
2418 table_size = TableIndices<N>();
2419
2420 return;
2421 }
2422
2423 // adjust values field. If it was empty before, we can simply call resize(),
2424 // which can set all the data fields. Otherwise, select the fast resize and
2425 // manually fill in all the elements as required by the design of this
2426 // class. (Selecting another code for the empty case ensures that we touch
2427 // the memory only once for non-trivial classes that need to initialize the
2428 // memory also in resize_fast.)
2429 if (!omit_default_initialization)
2430 {
2431 if (values.empty())
2432 values.resize(new_size);
2433 else
2434 {
2435 values.resize_fast(new_size);
2436 values.fill();
2437 }
2438 }
2439 else
2440 values.resize_fast(new_size);
2441}
2442
2443
2444
2445template <int N, typename T>
2446inline void
2448{
2449 values.clear();
2450 table_size = TableIndices<N>();
2451}
2452
2453
2454
2455template <int N, typename T>
2456inline const TableIndices<N> &
2458{
2459 return table_size;
2460}
2461
2462
2463
2464template <int N, typename T>
2465inline typename TableBase<N, T>::size_type
2466TableBase<N, T>::size(const unsigned int i) const
2467{
2468 AssertIndexRange(i, N);
2469 return table_size[i];
2470}
2471
2472
2473
2474template <int N, typename T>
2475inline typename TableBase<N, T>::size_type
2477{
2478 size_type s = 1;
2479 for (unsigned int n = 0; n < N; ++n)
2480 s *= table_size[n];
2481 return s;
2482}
2483
2484
2485
2486template <int N, typename T>
2487inline bool
2489{
2490 return (n_elements() == 0);
2491}
2492
2493
2494
2495namespace internal
2496{
2497 namespace TableImplementation
2498 {
2499 template <typename InputIterator, typename T>
2500 void
2501 fill_Fortran_style(InputIterator entries, TableBase<1, T> &table)
2502 {
2503 using size_type = typename TableBase<1, T>::size_type;
2504 for (size_type i = 0; i < table.size()[0]; ++i)
2505 table(TableIndices<1>(i)) = *entries++;
2506 }
2507
2508
2509 template <typename InputIterator, typename T>
2510 void
2511 fill_Fortran_style(InputIterator entries, TableBase<2, T> &table)
2512 {
2513 using size_type = typename TableBase<2, T>::size_type;
2514 for (size_type j = 0; j < table.size()[1]; ++j)
2515 for (size_type i = 0; i < table.size()[0]; ++i)
2516 table(TableIndices<2>(i, j)) = *entries++;
2517 }
2518
2519
2520 template <typename InputIterator, typename T>
2521 void
2522 fill_Fortran_style(InputIterator entries, TableBase<3, T> &table)
2523 {
2524 using size_type = typename TableBase<3, T>::size_type;
2525 for (size_type k = 0; k < table.size()[2]; ++k)
2526 for (size_type j = 0; j < table.size()[1]; ++j)
2527 for (size_type i = 0; i < table.size()[0]; ++i)
2528 table(TableIndices<3>(i, j, k)) = *entries++;
2529 }
2530
2531
2532 template <typename InputIterator, typename T, int N>
2533 void
2534 fill_Fortran_style(InputIterator, TableBase<N, T> &)
2535 {
2536 Assert(false, ExcNotImplemented());
2537 }
2538 } // namespace TableImplementation
2539} // namespace internal
2540
2541
2542template <int N, typename T>
2543template <typename InputIterator>
2544inline void
2545TableBase<N, T>::fill(InputIterator entries, const bool C_style_indexing)
2546{
2547 Assert(n_elements() != 0, ExcMessage("Trying to fill an empty matrix."));
2548
2549 if (C_style_indexing)
2550 for (typename AlignedVector<T>::iterator p = values.begin();
2551 p != values.end();
2552 ++p)
2553 *p = *entries++;
2554 else
2555 internal::TableImplementation::fill_Fortran_style(entries, *this);
2556}
2557
2558
2559
2560template <int N, typename T>
2561inline void
2563{
2564 values.swap(v.values);
2565 std::swap(table_size, v.table_size);
2566}
2567
2568
2569
2570template <int N, typename T>
2571inline std::size_t
2573{
2574 return sizeof(*this) + MemoryConsumption::memory_consumption(values);
2575}
2576
2577
2578
2579template <int N, typename T>
2580inline typename TableBase<N, T>::size_type
2581TableBase<N, T>::position(const TableIndices<N> &indices) const
2582{
2583 // specialize this for the
2584 // different numbers of dimensions,
2585 // to make the job somewhat easier
2586 // for the compiler. have the
2587 // general formula nevertheless:
2588 switch (N)
2589 {
2590 case 1:
2591 return indices[0];
2592 case 2:
2593 return size_type(indices[0]) * table_size[1] + indices[1];
2594 case 3:
2595 return ((size_type(indices[0]) * table_size[1] + indices[1]) *
2596 table_size[2] +
2597 indices[2]);
2598 default:
2599 {
2600 unsigned int s = indices[0];
2601 for (unsigned int n = 1; n < N; ++n)
2602 s = s * table_size[n] + indices[n];
2603 return s;
2604 }
2605 }
2606}
2607
2608
2609
2610template <int N, typename T>
2612TableBase<N, T>::operator()(const TableIndices<N> &indices) const
2613{
2614 for (unsigned int n = 0; n < N; ++n)
2615 AssertIndexRange(indices[n], table_size[n]);
2616 return el(indices);
2617}
2618
2619
2620
2621template <int N, typename T>
2622inline typename AlignedVector<T>::reference
2624{
2625 for (unsigned int n = 0; n < N; ++n)
2626 AssertIndexRange(indices[n], table_size[n]);
2627 return el(indices);
2628}
2629
2630
2631
2632template <int N, typename T>
2634TableBase<N, T>::el(const TableIndices<N> &indices) const
2635{
2636 return values[position(indices)];
2637}
2638
2639
2640
2641template <int N, typename T>
2642inline typename AlignedVector<T>::reference
2644{
2645 AssertIndexRange(position(indices), values.size());
2646 return values[position(indices)];
2647}
2648
2649
2650
2651template <typename T>
2652inline Table<1, T>::Table(const size_type size)
2653 : TableBase<1, T>(TableIndices<1>(size))
2654{}
2655
2656
2657
2658template <typename T>
2659template <typename InputIterator>
2660inline Table<1, T>::Table(const size_type size,
2661 InputIterator entries,
2662 const bool C_style_indexing)
2663 : TableBase<1, T>(TableIndices<1>(size), entries, C_style_indexing)
2664{}
2665
2666
2667
2668template <typename T>
2670Table<1, T>::operator[](const size_type i) const
2671{
2672 AssertIndexRange(i, this->table_size[0]);
2673 return this->values[i];
2674}
2675
2676
2677
2678template <typename T>
2679inline typename AlignedVector<T>::reference
2680Table<1, T>::operator[](const size_type i)
2681{
2682 AssertIndexRange(i, this->table_size[0]);
2683 return this->values[i];
2684}
2685
2686
2687
2688template <typename T>
2690Table<1, T>::operator()(const size_type i) const
2691{
2692 AssertIndexRange(i, this->table_size[0]);
2693 return this->values[i];
2694}
2695
2696
2697
2698template <typename T>
2699inline typename AlignedVector<T>::reference
2700Table<1, T>::operator()(const size_type i)
2701{
2702 AssertIndexRange(i, this->table_size[0]);
2703 return this->values[i];
2704}
2705
2706
2707//---------------------------------------------------------------------------
2708
2709
2710
2711template <typename T>
2712inline Table<2, T>::Table(const size_type size1, const size_type size2)
2713 : TableBase<2, T>(TableIndices<2>(size1, size2))
2714{}
2715
2716
2717
2718template <typename T>
2719template <typename InputIterator>
2720inline Table<2, T>::Table(const size_type size1,
2721 const size_type size2,
2722 InputIterator entries,
2723 const bool C_style_indexing)
2724 : TableBase<2, T>(TableIndices<2>(size1, size2), entries, C_style_indexing)
2725{}
2726
2727
2728
2729template <typename T>
2730inline void
2731Table<2, T>::reinit(const size_type size1,
2732 const size_type size2,
2733 const bool omit_default_initialization)
2734{
2735 this->TableBase<2, T>::reinit(TableIndices<2>(size1, size2),
2736 omit_default_initialization);
2737}
2738
2739
2740
2741template <typename T>
2742inline ::internal::TableBaseAccessors::Accessor<2, T, true, 1>
2743Table<2, T>::operator[](const size_type i) const
2744{
2745 AssertIndexRange(i, this->table_size[0]);
2746 return ::internal::TableBaseAccessors::Accessor<2, T, true, 1>(
2747 *this, this->values.begin() + size_type(i) * n_cols());
2748}
2749
2750
2751
2752template <typename T>
2753inline ::internal::TableBaseAccessors::Accessor<2, T, false, 1>
2754Table<2, T>::operator[](const size_type i)
2755{
2756 AssertIndexRange(i, this->table_size[0]);
2757 return ::internal::TableBaseAccessors::Accessor<2, T, false, 1>(
2758 *this, this->values.begin() + size_type(i) * n_cols());
2759}
2760
2761
2762
2763template <typename T>
2765Table<2, T>::operator()(const size_type i, const size_type j) const
2766{
2767 AssertIndexRange(i, this->table_size[0]);
2768 AssertIndexRange(j, this->table_size[1]);
2769 return this->values[size_type(i) * this->table_size[1] + j];
2770}
2771
2772
2773
2774template <typename T>
2775inline typename AlignedVector<T>::reference
2776Table<2, T>::operator()(const size_type i, const size_type j)
2777{
2778 AssertIndexRange(i, this->table_size[0]);
2779 AssertIndexRange(j, this->table_size[1]);
2780 return this->values[size_type(i) * this->table_size[1] + j];
2781}
2782
2783
2784
2785template <typename T>
2787Table<2, T>::el(const size_type i, const size_type j) const
2788{
2789 return this->values[size_type(i) * this->table_size[1] + j];
2790}
2791
2792
2793
2794template <typename T>
2795inline typename AlignedVector<T>::reference
2796Table<2, T>::el(const size_type i, const size_type j)
2797{
2798 return this->values[size_type(i) * this->table_size[1] + j];
2799}
2800
2801
2802
2803template <typename T>
2804inline typename Table<2, T>::size_type
2805Table<2, T>::n_rows() const
2806{
2807 return this->table_size[0];
2808}
2809
2810
2811
2812template <typename T>
2813inline typename Table<2, T>::size_type
2814Table<2, T>::n_cols() const
2815{
2816 return this->table_size[1];
2817}
2818
2819
2820
2821template <typename T>
2822inline typename Table<2, T>::iterator
2824{
2825 return typename Table<2, T>::iterator(this, 0, 0);
2826}
2827
2828
2829
2830template <typename T>
2831inline typename Table<2, T>::const_iterator
2832Table<2, T>::begin() const
2833{
2834 return typename Table<2, T>::const_iterator(this, 0, 0);
2835}
2836
2837
2838
2839template <typename T>
2840inline typename Table<2, T>::iterator
2842{
2843 return typename Table<2, T>::iterator(this);
2844}
2845
2846
2847
2848template <typename T>
2849inline typename Table<2, T>::const_iterator
2850Table<2, T>::end() const
2851{
2852 return typename Table<2, T>::const_iterator(this);
2853}
2854
2855
2856
2857//---------------------------------------------------------------------------
2858namespace MatrixTableIterators
2859{
2860 namespace internal
2861 {
2862 // Internal calculation routines for AccessorBase. These do not do any
2863 // checking whatsoever.
2864 template <typename TableType, Storage storage_order>
2865 inline std::ptrdiff_t
2866 get_row_index(const std::ptrdiff_t linear_index,
2867 const TableType *const container)
2868 {
2869 switch (storage_order)
2870 {
2871 case Storage::row_major:
2872 return linear_index / container->n_cols();
2873 case Storage::column_major:
2874 return linear_index % container->n_rows();
2875 default:
2876 Assert(false, ExcInternalError());
2877 }
2878 return {};
2879 }
2880
2881
2882
2883 template <typename TableType, Storage storage_order>
2884 inline std::ptrdiff_t
2885 get_column_index(const std::ptrdiff_t linear_index,
2886 const TableType *const container)
2887 {
2888 switch (storage_order)
2889 {
2890 case Storage::row_major:
2891 return linear_index % container->n_cols();
2892 case Storage::column_major:
2893 return linear_index / container->n_rows();
2894 default:
2895 Assert(false, ExcInternalError());
2896 }
2897 return {};
2898 }
2899 } // namespace internal
2900
2901
2902
2903 template <typename TableType, bool Constness, Storage storage_order>
2905 : container(nullptr)
2906 , linear_index(std::numeric_limits<decltype(linear_index)>::max())
2907 {}
2908
2909
2910
2911 template <typename TableType, bool Constness, Storage storage_order>
2912 inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2913 const container_pointer_type table)
2914 : container(table)
2915 , linear_index(container->values.size())
2916 {}
2917
2918
2919
2920 template <typename TableType, bool Constness, Storage storage_order>
2921 inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2922 const AccessorBase<TableType, false, storage_order> &a)
2923 : container(a.container)
2924 , linear_index(a.linear_index)
2925 {}
2926
2927
2928
2929 template <typename TableType, bool Constness, Storage storage_order>
2930 inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2931 const container_pointer_type table,
2932 const std::ptrdiff_t index)
2933 : container(table)
2934 , linear_index(index)
2935 {
2936 Assert(0 <= linear_index &&
2937 std::size_t(linear_index) < container->values.size() + 1,
2938 ExcMessage("The current iterator points outside of the table and is "
2939 "not the end iterator."));
2940 }
2941
2942
2943
2944 template <typename TableType, bool Constness, Storage storage_order>
2945 inline const typename AccessorBase<TableType, Constness, storage_order>::
2946 value_type &
2947 AccessorBase<TableType, Constness, storage_order>::value() const
2948 {
2949 assert_valid_linear_index();
2950 return this->container->values[linear_index];
2951 }
2952
2953
2954
2955 template <typename TableType, bool Constness, Storage storage_order>
2956 inline AccessorBase<TableType, Constness, storage_order>::
2957 operator const value_type &() const
2958 {
2959 assert_valid_linear_index();
2960 return this->container->values[linear_index];
2961 }
2962
2963
2964
2965 template <typename TableType, bool Constness, Storage storage_order>
2966 inline typename AccessorBase<TableType, Constness, storage_order>::size_type
2967 AccessorBase<TableType, Constness, storage_order>::row() const
2968 {
2969 assert_valid_linear_index();
2970 return static_cast<std::size_t>(
2971 internal::get_row_index<TableType, storage_order>(linear_index,
2972 container));
2973 }
2974
2975
2976
2977 template <typename TableType, bool Constness, Storage storage_order>
2978 inline typename AccessorBase<TableType, Constness, storage_order>::size_type
2979 AccessorBase<TableType, Constness, storage_order>::column() const
2980 {
2981 assert_valid_linear_index();
2982 return static_cast<std::size_t>(
2983 internal::get_column_index<TableType, storage_order>(linear_index,
2984 container));
2985 }
2986
2987
2988
2989 template <typename TableType, bool Constness, Storage storage_order>
2990 inline void
2991 AccessorBase<TableType, Constness, storage_order>::assert_valid_linear_index()
2992 const
2993 {
2994# ifdef DEBUG // avoid unused variable warnings by guarding everything
2995 Assert(container != nullptr,
2996 ExcMessage("This accessor has been default-constructed and does not "
2997 "have a corresponding table."));
2998 Assert(!container->empty(),
2999 ExcMessage("An empty table has no rows or columns."));
3000 Assert(0 <= linear_index &&
3001 std::size_t(linear_index) < container->values.size(),
3002 ExcMessage("The current iterator points outside of the table."));
3003 const std::ptrdiff_t row_n =
3004 internal::get_row_index<TableType, storage_order>(linear_index,
3005 container);
3006 const std::ptrdiff_t column_n =
3007 internal::get_column_index<TableType, storage_order>(linear_index,
3008 container);
3009 Assert(0 <= column_n && std::size_t(column_n) < container->n_cols(),
3010 ExcMessage("The current iterator points outside the table."));
3011 Assert(0 <= row_n && std::size_t(row_n) < container->n_rows(),
3012 ExcMessage("The current iterator points outside the table."));
3013# endif
3014 }
3015
3016
3017
3018 template <typename TableType, Storage storage_order>
3019 inline const Accessor<TableType, false, storage_order> &
3020 Accessor<TableType, false, storage_order>::operator=(
3021 const typename Accessor<TableType, false, storage_order>::value_type &t)
3022 const
3023 {
3024 this->assert_valid_linear_index();
3025 this->container->values[this->linear_index] = t;
3026 return *this;
3027 }
3028
3029
3030
3031 template <typename TableType, Storage storage_order>
3032 inline const Accessor<TableType, false, storage_order> &
3033 Accessor<TableType, false, storage_order>::operator=(
3034 typename Accessor<TableType, false, storage_order>::value_type &&t) const
3035 {
3036 this->assert_valid_linear_index();
3037 this->container->values[this->linear_index] = t;
3038 return *this;
3039 }
3040
3041
3042
3043 template <typename TableType, Storage storage_order>
3044 inline typename Accessor<TableType, false, storage_order>::value_type &
3045 Accessor<TableType, false, storage_order>::value() const
3046 {
3047 this->assert_valid_linear_index();
3048 return this->container->values[this->linear_index];
3049 }
3050
3051
3052
3053 template <typename TableType, Storage storage_order>
3054 inline Accessor<TableType, false, storage_order>::operator value_type &()
3055 {
3056 this->assert_valid_linear_index();
3057 return this->container->values[this->linear_index];
3058 }
3059
3060
3061
3062 template <typename TableType, bool Constness, Storage storage_order>
3063 inline Iterator<TableType, Constness, storage_order>::Iterator(
3064 const Accessor<TableType, Constness, storage_order> &a)
3065 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3066 Accessor<TableType, Constness, storage_order>>(a)
3067 {}
3068
3069
3070
3071 template <typename TableType, bool Constness, Storage storage_order>
3072 inline Iterator<TableType, Constness, storage_order>::Iterator(
3073 const container_pointer_type table)
3074 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3075 Accessor<TableType, Constness, storage_order>>(
3076 Accessor<TableType, Constness, storage_order>(table))
3077 {}
3078
3079
3080
3081 template <typename TableType, bool Constness, Storage storage_order>
3082 inline Iterator<TableType, Constness, storage_order>::Iterator(
3083 const Iterator<TableType, false, storage_order> &i)
3084 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3085 Accessor<TableType, Constness, storage_order>>(*i)
3086 {}
3087
3088
3089
3090 template <typename TableType, bool Constness, Storage storage_order>
3091 inline Iterator<TableType, Constness, storage_order>::Iterator(
3092 const container_pointer_type table,
3093 const size_type row_n,
3094 const size_type col_n)
3095 : Iterator(table,
3096 storage_order == Storage::row_major ?
3097 table->n_cols() * row_n + col_n :
3098 table->n_rows() * col_n + row_n)
3099 {}
3100
3101
3102
3103 template <typename TableType, bool Constness, Storage storage_order>
3104 inline Iterator<TableType, Constness, storage_order>::Iterator(
3105 const container_pointer_type table,
3106 const std::ptrdiff_t linear_index)
3107 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3108 Accessor<TableType, Constness, storage_order>>(
3109 Accessor<TableType, Constness, storage_order>(table, linear_index))
3110 {}
3111} // namespace MatrixTableIterators
3112
3113
3114
3115//---------------------------------------------------------------------------
3116template <typename T>
3117inline TransposeTable<T>::TransposeTable(const size_type size1,
3118 const size_type size2)
3119 : TableBase<2, T>(TableIndices<2>(size2, size1))
3120{}
3121
3122
3123
3124template <typename T>
3125inline void
3126TransposeTable<T>::reinit(const size_type size1,
3127 const size_type size2,
3128 const bool omit_default_initialization)
3129{
3130 this->TableBase<2, T>::reinit(TableIndices<2>(size2, size1),
3131 omit_default_initialization);
3132}
3133
3134
3135
3136template <typename T>
3138TransposeTable<T>::operator()(const size_type i, const size_type j) const
3139{
3140 AssertIndexRange(i, this->table_size[1]);
3141 AssertIndexRange(j, this->table_size[0]);
3142 return this->values[size_type(j) * this->table_size[1] + i];
3143}
3144
3145
3146
3147template <typename T>
3148inline typename TransposeTable<T>::reference
3149TransposeTable<T>::operator()(const size_type i, const size_type j)
3150{
3151 AssertIndexRange(i, this->table_size[1]);
3152 AssertIndexRange(j, this->table_size[0]);
3153 return this->values[size_type(j) * this->table_size[1] + i];
3154}
3155
3156
3157
3158template <typename T>
3160TransposeTable<T>::el(const size_type i, const size_type j) const
3161{
3162 return this->values[size_type(j) * this->table_size[1] + i];
3163}
3164
3165
3166
3167template <typename T>
3168inline typename TransposeTable<T>::reference
3169TransposeTable<T>::el(const size_type i, const size_type j)
3170{
3171 return this->values[size_type(j) * this->table_size[1] + i];
3172}
3173
3174
3175
3176template <typename T>
3177inline typename TransposeTable<T>::size_type
3179{
3180 return this->table_size[1];
3181}
3182
3183
3184
3185template <typename T>
3186inline typename TransposeTable<T>::size_type
3188{
3189 return this->table_size[0];
3190}
3191
3192
3193
3194template <typename T>
3195inline typename TransposeTable<T>::iterator
3197{
3198 return typename TransposeTable<T>::iterator(this, 0, 0);
3199}
3200
3201
3202
3203template <typename T>
3206{
3207 return typename TransposeTable<T>::const_iterator(this, 0, 0);
3208}
3209
3210
3211
3212template <typename T>
3213inline typename TransposeTable<T>::iterator
3215{
3216 return typename TransposeTable<T>::iterator(this);
3217}
3218
3219
3220
3221template <typename T>
3224{
3225 return typename TransposeTable<T>::const_iterator(this);
3226}
3227//---------------------------------------------------------------------------
3228
3229
3230
3231template <typename T>
3232inline Table<3, T>::Table(const size_type size1,
3233 const size_type size2,
3234 const size_type size3)
3235 : TableBase<3, T>(TableIndices<3>(size1, size2, size3))
3236{}
3237
3238
3239
3240template <typename T>
3241template <typename InputIterator>
3242inline Table<3, T>::Table(const size_type size1,
3243 const size_type size2,
3244 const size_type size3,
3245 InputIterator entries,
3246 const bool C_style_indexing)
3247 : TableBase<3, T>(TableIndices<3>(size1, size2, size3),
3248 entries,
3249 C_style_indexing)
3250{}
3251
3252
3253
3254template <typename T>
3255inline void
3256Table<3, T>::reinit(const size_type size1,
3257 const size_type size2,
3258 const size_type size3,
3259 const bool omit_default_initialization)
3260{
3261 this->TableBase<3, T>::reinit(TableIndices<3>(size1, size2, size3),
3262 omit_default_initialization);
3263}
3264
3265
3266
3267template <typename T>
3268inline ::internal::TableBaseAccessors::Accessor<3, T, true, 2>
3269Table<3, T>::operator[](const size_type i) const
3270{
3271 AssertIndexRange(i, this->table_size[0]);
3272 const size_type subobject_size =
3273 size_type(this->table_size[1]) * this->table_size[2];
3275 *this, this->values.begin() + i * subobject_size));
3276}
3277
3278
3279
3280template <typename T>
3281inline ::internal::TableBaseAccessors::Accessor<3, T, false, 2>
3282Table<3, T>::operator[](const size_type i)
3283{
3284 AssertIndexRange(i, this->table_size[0]);
3285 const size_type subobject_size =
3286 size_type(this->table_size[1]) * this->table_size[2];
3288 *this, this->values.begin() + i * subobject_size));
3289}
3290
3291
3292
3293template <typename T>
3295Table<3, T>::operator()(const size_type i,
3296 const size_type j,
3297 const size_type k) const
3298{
3299 AssertIndexRange(i, this->table_size[0]);
3300 AssertIndexRange(j, this->table_size[1]);
3301 AssertIndexRange(k, this->table_size[2]);
3302 return this
3303 ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3304 k];
3305}
3306
3307
3308
3309template <typename T>
3310inline typename AlignedVector<T>::reference
3311Table<3, T>::operator()(const size_type i, const size_type j, const size_type k)
3312{
3313 AssertIndexRange(i, this->table_size[0]);
3314 AssertIndexRange(j, this->table_size[1]);
3315 AssertIndexRange(k, this->table_size[2]);
3316 return this
3317 ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3318 k];
3319}
3320
3321
3322
3323template <typename T>
3324inline Table<4, T>::Table(const size_type size1,
3325 const size_type size2,
3326 const size_type size3,
3327 const size_type size4)
3328 : TableBase<4, T>(TableIndices<4>(size1, size2, size3, size4))
3329{}
3330
3331
3332
3333template <typename T>
3334inline ::internal::TableBaseAccessors::Accessor<4, T, true, 3>
3335Table<4, T>::operator[](const size_type i) const
3336{
3337 AssertIndexRange(i, this->table_size[0]);
3338 const size_type subobject_size =
3339 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3341 *this, this->values.begin() + i * subobject_size));
3342}
3343
3344
3345
3346template <typename T>
3347inline ::internal::TableBaseAccessors::Accessor<4, T, false, 3>
3348Table<4, T>::operator[](const size_type i)
3349{
3350 AssertIndexRange(i, this->table_size[0]);
3351 const size_type subobject_size =
3352 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3354 *this, this->values.begin() + i * subobject_size));
3355}
3356
3357
3358
3359template <typename T>
3361Table<4, T>::operator()(const size_type i,
3362 const size_type j,
3363 const size_type k,
3364 const size_type l) const
3365{
3366 AssertIndexRange(i, this->table_size[0]);
3367 AssertIndexRange(j, this->table_size[1]);
3368 AssertIndexRange(k, this->table_size[2]);
3369 AssertIndexRange(l, this->table_size[3]);
3370 return this
3371 ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3372 k) *
3373 this->table_size[3] +
3374 l];
3375}
3376
3377
3378
3379template <typename T>
3380inline typename AlignedVector<T>::reference
3381Table<4, T>::operator()(const size_type i,
3382 const size_type j,
3383 const size_type k,
3384 const size_type l)
3385{
3386 AssertIndexRange(i, this->table_size[0]);
3387 AssertIndexRange(j, this->table_size[1]);
3388 AssertIndexRange(k, this->table_size[2]);
3389 AssertIndexRange(l, this->table_size[3]);
3390 return this
3391 ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3392 k) *
3393 this->table_size[3] +
3394 l];
3395}
3396
3397
3398
3399template <typename T>
3400inline Table<5, T>::Table(const size_type size1,
3401 const size_type size2,
3402 const size_type size3,
3403 const size_type size4,
3404 const size_type size5)
3405 : TableBase<5, T>(TableIndices<5>(size1, size2, size3, size4, size5))
3406{}
3407
3408
3409
3410template <typename T>
3411inline ::internal::TableBaseAccessors::Accessor<5, T, true, 4>
3412Table<5, T>::operator[](const size_type i) const
3413{
3414 AssertIndexRange(i, this->table_size[0]);
3415 const size_type subobject_size = size_type(this->table_size[1]) *
3416 this->table_size[2] * this->table_size[3] *
3417 this->table_size[4];
3419 *this, this->values.begin() + i * subobject_size));
3420}
3421
3422
3423
3424template <typename T>
3425inline ::internal::TableBaseAccessors::Accessor<5, T, false, 4>
3426Table<5, T>::operator[](const size_type i)
3427{
3428 AssertIndexRange(i, this->table_size[0]);
3429 const size_type subobject_size = size_type(this->table_size[1]) *
3430 this->table_size[2] * this->table_size[3] *
3431 this->table_size[4];
3433 *this, this->values.begin() + i * subobject_size));
3434}
3435
3436
3437
3438template <typename T>
3440Table<5, T>::operator()(const size_type i,
3441 const size_type j,
3442 const size_type k,
3443 const size_type l,
3444 const size_type m) const
3445{
3446 AssertIndexRange(i, this->table_size[0]);
3447 AssertIndexRange(j, this->table_size[1]);
3448 AssertIndexRange(k, this->table_size[2]);
3449 AssertIndexRange(l, this->table_size[3]);
3450 AssertIndexRange(m, this->table_size[4]);
3451 return this
3452 ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3453 k) *
3454 this->table_size[3] +
3455 l) *
3456 this->table_size[4] +
3457 m];
3458}
3459
3460
3461
3462template <typename T>
3463inline typename AlignedVector<T>::reference
3464Table<5, T>::operator()(const size_type i,
3465 const size_type j,
3466 const size_type k,
3467 const size_type l,
3468 const size_type m)
3469{
3470 AssertIndexRange(i, this->table_size[0]);
3471 AssertIndexRange(j, this->table_size[1]);
3472 AssertIndexRange(k, this->table_size[2]);
3473 AssertIndexRange(l, this->table_size[3]);
3474 AssertIndexRange(m, this->table_size[4]);
3475 return this
3476 ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3477 k) *
3478 this->table_size[3] +
3479 l) *
3480 this->table_size[4] +
3481 m];
3482}
3483
3484
3485
3486template <typename T>
3487inline Table<6, T>::Table(const size_type size1,
3488 const size_type size2,
3489 const size_type size3,
3490 const size_type size4,
3491 const size_type size5,
3492 const size_type size6)
3493 : TableBase<6, T>()
3494{
3495 TableIndices<6> table_indices;
3496 table_indices[0] = size1;
3497 table_indices[1] = size2;
3498 table_indices[2] = size3;
3499 table_indices[3] = size4;
3500 table_indices[4] = size5;
3501 table_indices[5] = size6;
3502
3503 TableBase<6, T>::reinit(table_indices);
3504}
3505
3506
3507
3508template <typename T>
3509inline ::internal::TableBaseAccessors::Accessor<6, T, true, 5>
3510Table<6, T>::operator[](const size_type i) const
3511{
3512 AssertIndexRange(i, this->table_size[0]);
3513 const size_type subobject_size = size_type(this->table_size[1]) *
3514 this->table_size[2] * this->table_size[3] *
3515 this->table_size[4] * this->table_size[5];
3517 *this, this->values.begin() + i * subobject_size));
3518}
3519
3520
3521
3522template <typename T>
3523inline ::internal::TableBaseAccessors::Accessor<6, T, false, 5>
3524Table<6, T>::operator[](const size_type i)
3525{
3526 AssertIndexRange(i, this->table_size[0]);
3527 const size_type subobject_size = size_type(this->table_size[1]) *
3528 this->table_size[2] * this->table_size[3] *
3529 this->table_size[4] * this->table_size[5];
3531 *this, this->values.begin() + i * subobject_size));
3532}
3533
3534
3535
3536template <typename T>
3538Table<6, T>::operator()(const size_type i,
3539 const size_type j,
3540 const size_type k,
3541 const size_type l,
3542 const size_type m,
3543 const size_type n) const
3544{
3545 AssertIndexRange(i, this->table_size[0]);
3546 AssertIndexRange(j, this->table_size[1]);
3547 AssertIndexRange(k, this->table_size[2]);
3548 AssertIndexRange(l, this->table_size[3]);
3549 AssertIndexRange(m, this->table_size[4]);
3550 AssertIndexRange(n, this->table_size[5]);
3551 return this
3552 ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3553 k) *
3554 this->table_size[3] +
3555 l) *
3556 this->table_size[4] +
3557 m) *
3558 this->table_size[5] +
3559 n];
3560}
3561
3562
3563
3564template <typename T>
3565inline typename AlignedVector<T>::reference
3566Table<6, T>::operator()(const size_type i,
3567 const size_type j,
3568 const size_type k,
3569 const size_type l,
3570 const size_type m,
3571 const size_type n)
3572{
3573 AssertIndexRange(i, this->table_size[0]);
3574 AssertIndexRange(j, this->table_size[1]);
3575 AssertIndexRange(k, this->table_size[2]);
3576 AssertIndexRange(l, this->table_size[3]);
3577 AssertIndexRange(m, this->table_size[4]);
3578 AssertIndexRange(n, this->table_size[5]);
3579 return this
3580 ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3581 k) *
3582 this->table_size[3] +
3583 l) *
3584 this->table_size[4] +
3585 m) *
3586 this->table_size[5] +
3587 n];
3588}
3589
3590
3591
3592template <typename T>
3593inline Table<7, T>::Table(const size_type size1,
3594 const size_type size2,
3595 const size_type size3,
3596 const size_type size4,
3597 const size_type size5,
3598 const size_type size6,
3599 const size_type size7)
3600 : TableBase<7, T>()
3601{
3602 TableIndices<7> table_indices;
3603 table_indices[0] = size1;
3604 table_indices[1] = size2;
3605 table_indices[2] = size3;
3606 table_indices[3] = size4;
3607 table_indices[4] = size5;
3608 table_indices[5] = size6;
3609 table_indices[6] = size7;
3610
3611 TableBase<7, T>::reinit(table_indices);
3612}
3613
3614
3615
3616template <typename T>
3617inline ::internal::TableBaseAccessors::Accessor<7, T, true, 6>
3618Table<7, T>::operator[](const size_type i) const
3619{
3620 AssertIndexRange(i, this->table_size[0]);
3621 const size_type subobject_size =
3622 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3623 this->table_size[4] * this->table_size[5] * this->table_size[6];
3625 *this, this->values.begin() + i * subobject_size));
3626}
3627
3628
3629
3630template <typename T>
3631inline ::internal::TableBaseAccessors::Accessor<7, T, false, 6>
3632Table<7, T>::operator[](const size_type i)
3633{
3634 AssertIndexRange(i, this->table_size[0]);
3635 const size_type subobject_size =
3636 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3637 this->table_size[4] * this->table_size[5] * this->table_size[6];
3639 *this, this->values.begin() + i * subobject_size));
3640}
3641
3642
3643
3644template <typename T>
3646Table<7, T>::operator()(const size_type i,
3647 const size_type j,
3648 const size_type k,
3649 const size_type l,
3650 const size_type m,
3651 const size_type n,
3652 const size_type o) const
3653{
3654 AssertIndexRange(i, this->table_size[0]);
3655 AssertIndexRange(j, this->table_size[1]);
3656 AssertIndexRange(k, this->table_size[2]);
3657 AssertIndexRange(l, this->table_size[3]);
3658 AssertIndexRange(m, this->table_size[4]);
3659 AssertIndexRange(n, this->table_size[5]);
3660 AssertIndexRange(o, this->table_size[6]);
3661 return this->values
3662 [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3663 this->table_size[3] +
3664 l) *
3665 this->table_size[4] +
3666 m) *
3667 this->table_size[5] +
3668 n) *
3669 this->table_size[6] +
3670 o];
3671}
3672
3673
3674
3675template <typename T>
3676inline typename AlignedVector<T>::reference
3677Table<7, T>::operator()(const size_type i,
3678 const size_type j,
3679 const size_type k,
3680 const size_type l,
3681 const size_type m,
3682 const size_type n,
3683 const size_type o)
3684{
3685 AssertIndexRange(i, this->table_size[0]);
3686 AssertIndexRange(j, this->table_size[1]);
3687 AssertIndexRange(k, this->table_size[2]);
3688 AssertIndexRange(l, this->table_size[3]);
3689 AssertIndexRange(m, this->table_size[4]);
3690 AssertIndexRange(n, this->table_size[5]);
3691 AssertIndexRange(o, this->table_size[6]);
3692 return this->values
3693 [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3694 this->table_size[3] +
3695 l) *
3696 this->table_size[4] +
3697 m) *
3698 this->table_size[5] +
3699 n) *
3700 this->table_size[6] +
3701 o];
3702}
3703
3704
3705#endif // DOXYGEN
3706
3707
3708
3714template <int N, typename T>
3715inline void
3717{
3718 u.swap(v);
3719}
3720
3722
3723#endif
value_type & reference
std::size_t size_type
const value_type * const_iterator
const value_type & const_reference
value_type * iterator
Accessor base class for Table<2, T> and TransposeTable.
Definition table.h:985
AccessorBase(const AccessorBase< TableType, false, storage_order > &)
typename TableType::value_type value_type
Definition table.h:996
const value_type & value() const
container_pointer_type container
Definition table.h:1065
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:991
friend bool operator==(const AccessorBase< TableType, Constness, storage_order > &left, const AccessorBase< TableType, OtherConstness, storage_order > &right)
Definition table.h:1029
typename TableType::size_type size_type
Definition table.h:1001
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:1130
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition table.h:1136
typename AccessorBase< TableType, true, storage_order >::value_type value_type
Definition table.h:1103
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition table.h:1109
Accessor class template. This class is partially specialized for both values of Constness.
Definition table.h:965
Iterator class for both matrix-like tables, i.e., Table<2, T> and TransposeTable.
Definition table.h:1192
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:1203
Iterator(const container_pointer_type container, const std::ptrdiff_t linear_index)
typename TableType::size_type size_type
Definition table.h:1197
void swap(TableBase< N, T > &v)
void fill(const T &value)
friend class TableBase
Definition table.h:805
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:796
TableBase< N, T > & operator=(TableBase< N, T > &&src) noexcept
~TableBase() override=default
typename AlignedVector< T >::size_type size_type
Definition table.h:449
size_type n_elements() const
void clear()
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:444
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 replicate_across_communicator(const MPI_Comm communicator, const unsigned int root_process)
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:801
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:840
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:1272
typename AlignedVector< T >::value_type value_type
Definition table.h:1262
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:1257
::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:1267
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)
void reinit(const size_type size1, const size_type size2, const size_type size3, const bool omit_default_initialization=false)
typename TableBase< 3, T >::size_type size_type
Definition table.h:1494
::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:1628
::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:1712
::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:1799
::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:1887
::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:2013
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:2005
const_iterator end() const
iterator end()
typename AlignedVector< T >::reference reference
Definition table.h:1991
typename TableBase< 2, T >::size_type size_type
Definition table.h:1981
iterator begin()
const_reference operator()(const size_type i, const size_type j) const
typename AlignedVector< T >::value_type value_type
Definition table.h:1986
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:1996
typename Types< N, T, C >::value_type value_type
Definition table.h:247
typename Types< N, T, C >::const_iterator const_iterator
Definition table.h:250
typename Types< N, T, C >::TableType TableType
Definition table.h:261
typename Types< N, T, C >::const_reference const_reference
Definition table.h:253
typename Types< N, T, C >::iterator iterator
Definition table.h:249
reference operator[](const size_type) const
typename Types< N, T, C >::reference reference
Definition table.h:252
Accessor(const TableType &table, const iterator data)
typename Types< N, T, C >::TableType TableType
Definition table.h:164
typename Types< N, T, C >::iterator iterator
Definition table.h:166
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:167
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcIndexRange(size_type arg1, size_type arg2, size_type arg3)
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition exceptions.h:556
static ::ExceptionBase & ExcMessage(std::string arg1)
types::global_dof_index size_type
Storage
Enumeration describing the storage order (i.e., the in-memory layout) of a table class.
Definition table.h:944
std::enable_if_t< std::is_fundamental< T >::value, std::size_t > 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)
std::enable_if_t< is_mpi_type< T >==false, T > broadcast(const MPI_Comm comm, const T &object_to_send, const unsigned int root_process=0)
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
STL namespace.
typename AlignedVector< T >::iterator iterator
Definition table.h:116
typename AlignedVector< T >::const_iterator const_iterator
Definition table.h:117
typename AlignedVector< T >::reference reference
Definition table.h:119
typename AlignedVector< T >::const_reference const_reference
Definition table.h:120
typename AlignedVector< T >::const_iterator const_iterator
Definition table.h:99
typename AlignedVector< T >::const_reference const_reference
Definition table.h:102
typename AlignedVector< T >::const_iterator iterator
Definition table.h:98
typename AlignedVector< T >::const_reference reference
Definition table.h:101
void swap(TableBase< N, T > &u, TableBase< N, T > &v)
Definition table.h:3716