deal.II version GIT relicensing-6816-g8d70a4508a 2026-09-28 16:30:01+00:00
\(\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// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2002 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_table_h
14#define dealii_table_h
15
16#include <deal.II/base/config.h>
17
24
25#include <algorithm>
26#include <cstddef>
27#include <limits>
28
30
31// forward declaration
32#ifndef DOXYGEN
33template <int N, typename T>
34class TableBase;
35template <int N, typename T>
36class Table;
37template <typename T>
38class TransposeTable;
39template <typename T>
40class Table<1, T>;
41template <typename T>
42class Table<2, T>;
43template <typename T>
44class Table<3, T>;
45template <typename T>
46class Table<4, T>;
47template <typename T>
48class Table<5, T>;
49template <typename T>
50class Table<6, T>;
51#endif
52
53
54
55namespace internal
56{
71 namespace TableBaseAccessors
72 {
80 template <int N, typename T, bool Constness>
81 struct Types
82 {};
83
89 template <int N, typename T>
101
107 template <int N, typename T>
119
120
157 template <int N, typename T, bool C, unsigned int P>
159 {
160 public:
162
165
166 using size_type = std::size_t;
167 using difference_type = std::ptrdiff_t;
168
169 private:
176
177 public:
186
190 Accessor<N, T, C, P - 1>
191 operator[](const size_type i) const;
192
198 size_type,
199 size_type,
200 size_type,
201 << "Index " << N - P + 1 << "has a value of " << arg1
202 << " but needs to be in the range [" << arg2 << ',' << arg3
203 << "[.");
204
205 private:
213
214 // declare some other classes
215 // as friends. make sure to
216 // work around bugs in some
217 // compilers
218 template <int N1, typename T1>
219 friend class ::Table;
220 template <int N1, typename T1, bool C1, unsigned int P1>
221 friend class Accessor;
222 friend class ::Table<N, T>;
223 friend class Accessor<N, T, C, P + 1>;
224 };
225
226
227
235 template <int N, typename T, bool C>
236 class Accessor<N, T, C, 1>
237 {
238 public:
245
248
251
252 using size_type = std::size_t;
253 using difference_type = std::ptrdiff_t;
254
259
260 private:
273
274 public:
283
288 operator[](const size_type) const;
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>
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
549 void
551
556 size(const unsigned int i) const;
557
561 const TableIndices<N> &
562 size() const;
563
569 n_elements() const;
570
575 bool
576 empty() const;
577
614 template <typename InputIterator>
615 void
616 fill(InputIterator entries, const bool C_style_indexing = true);
617
621 void
622 fill(const T &value);
623
629
638 operator()(const TableIndices<N> &indices) const;
639
724 void
726 const unsigned int root_process);
727
740 void
741 swap(TableBase<N, T> &v) noexcept;
742
747 std::size_t
749
755 template <class Archive>
756 void
757 serialize(Archive &ar, const unsigned int version);
758
759protected:
765 position(const TableIndices<N> &indices) const;
766
774 el(const TableIndices<N> &indices);
775
787 el(const TableIndices<N> &indices) const;
788
789protected:
794
799
800 // Make all other table classes friends.
801 template <int, typename>
802 friend class TableBase;
803};
804
805
818template <int N, typename T>
819class Table;
820
821
830template <typename T>
831class Table<1, T> : public TableBase<1, T>
832{
833public:
838
842 Table() = default;
843
847 explicit Table(const size_type size);
848
886 template <typename InputIterator>
888 InputIterator entries,
889 const bool C_style_indexing = true);
890
896 operator[](const size_type i) const;
897
904
910 operator()(const size_type i) const;
911
918
922 using TableBase<1, T>::operator();
923};
924
925
926
935{
940 enum class Storage
941 {
945 row_major,
946
951 };
952
953 // Forward declaration of the iterator class.
954 template <typename TableType, bool Constness, Storage storage_order>
955 class Iterator;
956
961 template <typename TableType, bool Constness, Storage storage_order>
962 class Accessor;
963
980 template <typename TableType, bool Constness, Storage storage_order>
982 {
983 public:
988 std::conditional_t<Constness, const TableType *, TableType *>;
989
993 using value_type = typename TableType::value_type;
994
998 using size_type = typename TableType::size_type;
999
1004
1009
1014
1019 const std::ptrdiff_t linear_index);
1020
1024 template <bool OtherConstness>
1025 friend bool
1029 {
1030 return left.container == right.container &&
1031 left.linear_index == right.linear_index;
1032 }
1033
1038 const value_type &
1039 value() const;
1040
1044 operator const value_type &() const;
1045
1049 size_type
1050 row() const;
1051
1055 size_type
1056 column() const;
1057
1058 protected:
1063
1067 std::ptrdiff_t linear_index;
1068
1075 void
1077
1078 // Make the const version a friend for copying.
1079 friend class AccessorBase<TableType, true, storage_order>;
1080
1081 // Make the underlying iterator class a friend.
1082 friend class LinearIndexIterator<
1083 Iterator<TableType, Constness, storage_order>,
1084 Accessor<TableType, Constness, storage_order>>;
1085 };
1086
1091 template <typename TableType, Storage storage_order>
1092 class Accessor<TableType, true, storage_order>
1093 : public AccessorBase<TableType, true, storage_order>
1094 {
1095 public:
1101
1107
1111 using AccessorBase<TableType, true, storage_order>::AccessorBase;
1112 };
1113
1118 template <typename TableType, Storage storage_order>
1119 class Accessor<TableType, false, storage_order>
1120 : public AccessorBase<TableType, false, storage_order>
1121 {
1122 public:
1128
1134
1138 using AccessorBase<TableType, false, storage_order>::AccessorBase;
1139
1145 operator=(const value_type &) const;
1146
1153
1158 using AccessorBase<TableType, false, storage_order>::value;
1159
1164 value_type &
1165 value() const;
1166
1170 operator value_type &();
1171 };
1172
1185 template <typename TableType, bool Constness, Storage storage_order>
1187 : public LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
1188 Accessor<TableType, Constness, storage_order>>
1189 {
1190 public:
1194 using size_type = typename TableType::size_type;
1195
1200 std::conditional_t<Constness, const TableType *, TableType *>;
1201
1206
1211
1216 const size_type row,
1217 const size_type column);
1218
1223
1228 const std::ptrdiff_t linear_index);
1229 };
1230} // namespace MatrixTableIterators
1231
1232
1233
1247template <typename T>
1248class Table<2, T> : public TableBase<2, T>
1249{
1250public:
1255
1260
1265
1270
1275 using const_iterator = MatrixTableIterators::
1276 Iterator<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1277
1281 using iterator = MatrixTableIterators::
1282 Iterator<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1283
1287 Table() = default;
1288
1292 Table(const size_type size1, const size_type size2);
1293
1332 template <typename InputIterator>
1333 Table(const size_type size1,
1334 const size_type size2,
1335 InputIterator entries,
1336 const bool C_style_indexing = true);
1337
1343 void
1344 reinit(const size_type size1,
1345 const size_type size2,
1346 const bool omit_default_initialization = false);
1347
1348 using TableBase<2, T>::reinit;
1349
1357 operator[](const size_type i) const;
1358
1367
1375 operator()(const size_type i, const size_type j) const;
1376
1384 operator()(const size_type i, const size_type j);
1385
1389 using TableBase<2, T>::operator();
1390
1395 size_type
1396 n_rows() const;
1397
1402 size_type
1403 n_cols() const;
1404
1408 iterator
1410
1415 begin() const;
1416
1420 iterator
1422
1427 end() const;
1428
1429protected:
1441 el(const size_type i, const size_type j);
1442
1458 el(const size_type i, const size_type j) const;
1459
1460 // Make the AccessorBase class a friend so that it may directly index into
1461 // the array.
1462 friend class MatrixTableIterators::
1463 AccessorBase<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1464 friend class MatrixTableIterators::
1465 AccessorBase<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1466
1467 // Make the mutable accessor class a friend so that we can write to array
1468 // entries with iterators.
1469 friend class MatrixTableIterators::
1470 Accessor<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1471};
1472
1473
1474
1484template <typename T>
1485class Table<3, T> : public TableBase<3, T>
1486{
1487public:
1492
1496 Table() = default;
1497
1501 Table(const size_type size1, const size_type size2, const size_type size3);
1502
1543 template <typename InputIterator>
1544 Table(const size_type size1,
1545 const size_type size2,
1546 const size_type size3,
1547 InputIterator entries,
1548 const bool C_style_indexing = true);
1549
1554 void
1555 reinit(const size_type size1,
1556 const size_type size2,
1557 const size_type size3,
1558 const bool omit_default_initialization = false);
1559
1560 using TableBase<3, T>::reinit;
1561
1570 operator[](const size_type i) const;
1571
1581
1589 operator()(const size_type i, const size_type j, const size_type k) const;
1590
1591
1599 operator()(const size_type i, const size_type j, const size_type k);
1600
1604 using TableBase<3, T>::operator();
1605};
1606
1607
1608
1618template <typename T>
1619class Table<4, T> : public TableBase<4, T>
1620{
1621public:
1626
1630 Table() = default;
1631
1635 Table(const size_type size1,
1636 const size_type size2,
1637 const size_type size3,
1638 const size_type size4);
1639
1648 operator[](const size_type i) const;
1649
1659
1668 const size_type j,
1669 const size_type k,
1670 const size_type l) const;
1671
1672
1681 const size_type j,
1682 const size_type k,
1683 const size_type l);
1684
1688 using TableBase<4, T>::operator();
1689};
1690
1691
1692
1702template <typename T>
1703class Table<5, T> : public TableBase<5, T>
1704{
1705public:
1710
1711
1715 Table() = default;
1716
1720 Table(const size_type size1,
1721 const size_type size2,
1722 const size_type size3,
1723 const size_type size4,
1724 const size_type size5);
1725
1734 operator[](const size_type i) const;
1735
1745
1754 const size_type j,
1755 const size_type k,
1756 const size_type l,
1757 const size_type m) const;
1758
1767 const size_type j,
1768 const size_type k,
1769 const size_type l,
1770 const size_type m);
1771
1775 using TableBase<5, T>::operator();
1776};
1777
1778
1779
1789template <typename T>
1790class Table<6, T> : public TableBase<6, T>
1791{
1792public:
1797
1801 Table() = default;
1802
1806 Table(const size_type size1,
1807 const size_type size2,
1808 const size_type size3,
1809 const size_type size4,
1810 const size_type size5,
1811 const size_type size6);
1812
1821 operator[](const size_type i) const;
1822
1832
1841 const size_type j,
1842 const size_type k,
1843 const size_type l,
1844 const size_type m,
1845 const size_type n) const;
1846
1855 const size_type j,
1856 const size_type k,
1857 const size_type l,
1858 const size_type m,
1859 const size_type n);
1860
1864 using TableBase<6, T>::operator();
1865};
1866
1867
1877template <typename T>
1878class Table<7, T> : public TableBase<7, T>
1879{
1880public:
1885
1889 Table() = default;
1890
1894 Table(const size_type size1,
1895 const size_type size2,
1896 const size_type size3,
1897 const size_type size4,
1898 const size_type size5,
1899 const size_type size6,
1900 const size_type size7);
1901
1910 operator[](const size_type i) const;
1911
1921
1930 const size_type j,
1931 const size_type k,
1932 const size_type l,
1933 const size_type m,
1934 const size_type n,
1935 const size_type o) const;
1936
1945 const size_type j,
1946 const size_type k,
1947 const size_type l,
1948 const size_type m,
1949 const size_type n,
1950 const size_type o);
1951
1955 using TableBase<7, T>::operator();
1956};
1957
1958
1971template <typename T>
1972class TransposeTable : public TableBase<2, T>
1973{
1974public:
1979
1984
1989
1994
2001 true,
2003
2007 using iterator =
2009 false,
2011
2015 TransposeTable() = default;
2016
2020 TransposeTable(const size_type size1, const size_type size2);
2021
2027 void
2028 reinit(const size_type size1,
2029 const size_type size2,
2030 const bool omit_default_initialization = false);
2031
2039 operator()(const size_type i, const size_type j) const;
2040
2047 reference
2048 operator()(const size_type i, const size_type j);
2049
2054 size_type
2055 n_rows() const;
2056
2061 size_type
2062 n_cols() const;
2063
2067 iterator
2069
2074 begin() const;
2075
2079 iterator
2081
2086 end() const;
2087
2088protected:
2099 reference
2100 el(const size_type i, const size_type j);
2101
2117 el(const size_type i, const size_type j) const;
2118
2119 // Make the AccessorBase class a friend so that it may directly index into
2120 // the array.
2122 TransposeTable<T>,
2123 true,
2124 MatrixTableIterators::Storage::column_major>;
2126 TransposeTable<T>,
2127 false,
2128 MatrixTableIterators::Storage::column_major>;
2129
2130 // Make the mutable accessor class a friend so that we can write to array
2131 // entries with iterators.
2132 friend class MatrixTableIterators::Accessor<
2133 TransposeTable<T>,
2134 false,
2135 MatrixTableIterators::Storage::column_major>;
2136};
2137
2138
2139
2140/* --------------------- Template and inline functions ---------------- */
2141
2142#ifndef DOXYGEN
2143
2144template <int N, typename T>
2145TableBase<N, T>::TableBase(const TableIndices<N> &sizes)
2146{
2147 reinit(sizes);
2148}
2149
2150
2151
2152template <int N, typename T>
2153template <typename InputIterator>
2155 InputIterator entries,
2156 const bool C_style_indexing)
2157{
2158 reinit(sizes);
2159 fill(entries, C_style_indexing);
2160}
2161
2162
2163
2164template <int N, typename T>
2167 , values(src.values)
2168 , table_size(src.table_size)
2169{}
2170
2171
2172
2173template <int N, typename T>
2174template <typename T2>
2176{
2177 reinit(src.table_size);
2178 if (src.n_elements() != 0)
2179 std::copy(src.values.begin(), src.values.end(), values.begin());
2180}
2181
2182
2183
2184template <int N, typename T>
2186 : EnableObserverPointer(std::move(src))
2187 , values(std::move(src.values))
2188 , table_size(src.table_size)
2189{
2191}
2192
2193
2194
2195template <int N, typename T>
2196template <class Archive>
2197inline void
2198TableBase<N, T>::serialize(Archive &ar, const unsigned int)
2199{
2200 ar &static_cast<EnableObserverPointer &>(*this);
2201
2202 ar &values &table_size;
2203}
2204
2205
2206
2207namespace internal
2208{
2209 namespace TableBaseAccessors
2210 {
2211 template <int N, typename T, bool C, unsigned int P>
2212 inline Accessor<N, T, C, P>::Accessor(const TableType &table,
2213 const iterator data)
2214 : table(table)
2215 , data(data)
2216 {}
2217
2218
2219
2220 template <int N, typename T, bool C, unsigned int P>
2221 inline Accessor<N, T, C, P>::Accessor(const Accessor &a)
2222 : table(a.table)
2223 , data(a.data)
2224 {}
2225
2226
2227
2228 template <int N, typename T, bool C, unsigned int P>
2229 inline Accessor<N, T, C, P - 1>
2230 Accessor<N, T, C, P>::operator[](const size_type i) const
2231 {
2232 AssertIndexRange(i, table.size()[N - P]);
2233
2234 // access i-th
2235 // subobject. optimize on the
2236 // case i==0
2237 if (i == 0)
2238 return Accessor<N, T, C, P - 1>(table, data);
2239 else
2240 {
2241 // note: P>1, otherwise the
2242 // specialization would have
2243 // been taken!
2244 size_type subobject_size = table.size()[N - 1];
2245 for (int p = P - 1; p > 1; --p)
2246 subobject_size *= table.size()[N - p];
2247 const iterator new_data = data + i * subobject_size;
2248 return Accessor<N, T, C, P - 1>(table, new_data);
2249 }
2250 }
2251
2252
2253
2254 template <int N, typename T, bool C>
2255 inline Accessor<N, T, C, 1>::Accessor(const TableType &table,
2256 const iterator data)
2257 : table(table)
2258 , data(data)
2259 {}
2260
2261
2262
2263 template <int N, typename T, bool C>
2264 inline Accessor<N, T, C, 1>::Accessor(const Accessor &a)
2265 : table(a.table)
2266 , data(a.data)
2267 {}
2268
2269
2270
2271 template <int N, typename T, bool C>
2272 inline typename Accessor<N, T, C, 1>::reference
2273 Accessor<N, T, C, 1>::operator[](const size_type i) const
2274 {
2275 AssertIndexRange(i, table.size()[N - 1]);
2276 return *(data + i);
2277 }
2278
2279
2280
2281 template <int N, typename T, bool C>
2282 inline typename Accessor<N, T, C, 1>::size_type
2283 Accessor<N, T, C, 1>::size() const
2284 {
2285 return table.size()[N - 1];
2286 }
2287
2288
2289
2290 template <int N, typename T, bool C>
2291 inline typename Accessor<N, T, C, 1>::iterator
2292 Accessor<N, T, C, 1>::begin() const
2293 {
2294 return data;
2295 }
2296
2297
2298
2299 template <int N, typename T, bool C>
2300 inline typename Accessor<N, T, C, 1>::iterator
2301 Accessor<N, T, C, 1>::end() const
2302 {
2303 return data + table.size()[N - 1];
2304 }
2305 } // namespace TableBaseAccessors
2306} // namespace internal
2307
2308
2309
2310template <int N, typename T>
2311inline TableBase<N, T> &
2313{
2314 if (!m.empty())
2315 values = m.values;
2316 reinit(m.size(), true);
2317
2318 return *this;
2319}
2320
2321
2322
2323template <int N, typename T>
2324template <typename T2>
2325inline TableBase<N, T> &
2327{
2328 reinit(m.size(), true);
2329 if (!empty())
2330 std::copy(m.values.begin(),
2331 m.values.begin() + n_elements(),
2332 values.begin());
2333
2334 return *this;
2335}
2336
2337
2338
2339template <int N, typename T>
2340inline TableBase<N, T> &
2342{
2343 static_cast<EnableObserverPointer &>(*this) =
2344 std::move(static_cast<EnableObserverPointer &>(m));
2345 values = std::move(m.values);
2346 table_size = m.table_size;
2348
2349 return *this;
2350}
2351
2352
2353
2354template <int N, typename T>
2355inline bool
2357{
2358 return (values == T2.values);
2359}
2360
2361
2362
2363template <int N, typename T>
2364inline void
2366{
2367 // use parallel set operation
2368 if (n_elements() != 0)
2369 values.fill(T());
2370}
2371
2372
2373
2374template <int N, typename T>
2375inline void
2376TableBase<N, T>::fill(const T &value)
2377{
2378 if (n_elements() != 0)
2379 values.fill(value);
2380}
2381
2382
2383
2384template <int N, typename T>
2385inline void
2387 const unsigned int root_process)
2388{
2389 // Replicate first the actual data, then also exchange the
2390 // extents of the table
2391 values.replicate_across_communicator(communicator, root_process);
2392
2393 table_size =
2394 Utilities::MPI::broadcast(communicator, table_size, root_process);
2395}
2396
2397
2398
2399template <int N, typename T>
2400inline void
2402 const bool omit_default_initialization)
2403{
2404 table_size = new_sizes;
2405
2406 const size_type new_size = n_elements();
2407
2408 // if zero size was given: free all memory
2409 if (new_size == 0)
2410 {
2411 values.resize(0);
2412 // set all sizes to zero, even
2413 // if one was previously
2414 // nonzero. This simplifies
2415 // some assertions.
2416 table_size = TableIndices<N>();
2417
2418 return;
2419 }
2420
2421 // adjust values field. If it was empty before, we can simply call resize(),
2422 // which can set all the data fields. Otherwise, select the fast resize and
2423 // manually fill in all the elements as required by the design of this
2424 // class. (Selecting another code for the empty case ensures that we touch
2425 // the memory only once for non-trivial classes that need to initialize the
2426 // memory also in resize_fast.)
2427 if (!omit_default_initialization)
2428 {
2429 if (values.empty())
2430 values.resize(new_size);
2431 else
2432 {
2433 values.resize_fast(new_size);
2434 values.fill();
2435 }
2436 }
2437 else
2438 values.resize_fast(new_size);
2439}
2440
2441
2442
2443template <int N, typename T>
2444inline void
2446{
2447 values.clear();
2448 table_size = TableIndices<N>();
2449}
2450
2451
2452
2453template <int N, typename T>
2454inline const TableIndices<N> &
2456{
2457 return table_size;
2458}
2459
2460
2461
2462template <int N, typename T>
2463inline typename TableBase<N, T>::size_type
2464TableBase<N, T>::size(const unsigned int i) const
2465{
2466 AssertIndexRange(i, N);
2467 return table_size[i];
2468}
2469
2470
2471
2472template <int N, typename T>
2473inline typename TableBase<N, T>::size_type
2475{
2476 size_type s = 1;
2477 for (unsigned int n = 0; n < N; ++n)
2478 s *= table_size[n];
2479 return s;
2480}
2481
2482
2483
2484template <int N, typename T>
2485inline bool
2487{
2488 return (n_elements() == 0);
2489}
2490
2491
2492
2493namespace internal
2494{
2495 namespace TableImplementation
2496 {
2497 template <typename InputIterator, typename T>
2498 void
2499 fill_Fortran_style(InputIterator entries, TableBase<1, T> &table)
2500 {
2501 using size_type = typename TableBase<1, T>::size_type;
2502 for (size_type i = 0; i < table.size()[0]; ++i)
2503 table(TableIndices<1>(i)) = *entries++;
2504 }
2505
2506
2507 template <typename InputIterator, typename T>
2508 void
2509 fill_Fortran_style(InputIterator entries, TableBase<2, T> &table)
2510 {
2511 using size_type = typename TableBase<2, T>::size_type;
2512 for (size_type j = 0; j < table.size()[1]; ++j)
2513 for (size_type i = 0; i < table.size()[0]; ++i)
2514 table(TableIndices<2>(i, j)) = *entries++;
2515 }
2516
2517
2518 template <typename InputIterator, typename T>
2519 void
2520 fill_Fortran_style(InputIterator entries, TableBase<3, T> &table)
2521 {
2522 using size_type = typename TableBase<3, T>::size_type;
2523 for (size_type k = 0; k < table.size()[2]; ++k)
2524 for (size_type j = 0; j < table.size()[1]; ++j)
2525 for (size_type i = 0; i < table.size()[0]; ++i)
2526 table(TableIndices<3>(i, j, k)) = *entries++;
2527 }
2528
2529
2530 template <typename InputIterator, typename T, int N>
2531 void
2532 fill_Fortran_style(InputIterator, TableBase<N, T> &)
2533 {
2535 }
2536 } // namespace TableImplementation
2537} // namespace internal
2538
2539
2540template <int N, typename T>
2541template <typename InputIterator>
2542inline void
2543TableBase<N, T>::fill(InputIterator entries, const bool C_style_indexing)
2544{
2545 Assert(n_elements() != 0, ExcMessage("Trying to fill an empty matrix."));
2546
2547 if (C_style_indexing)
2548 for (typename AlignedVector<T>::iterator p = values.begin();
2549 p != values.end();
2550 ++p)
2551 *p = *entries++;
2552 else
2553 internal::TableImplementation::fill_Fortran_style(entries, *this);
2554}
2555
2556
2557
2558template <int N, typename T>
2559inline void
2561{
2562 values.swap(v.values);
2563 std::swap(table_size, v.table_size);
2564}
2565
2566
2567
2568template <int N, typename T>
2569inline std::size_t
2571{
2572 return sizeof(*this) + MemoryConsumption::memory_consumption(values);
2573}
2574
2575
2576
2577template <int N, typename T>
2578inline typename TableBase<N, T>::size_type
2579TableBase<N, T>::position(const TableIndices<N> &indices) const
2580{
2581 // specialize this for the
2582 // different numbers of dimensions,
2583 // to make the job somewhat easier
2584 // for the compiler. have the
2585 // general formula nevertheless:
2586 switch (N)
2587 {
2588 case 1:
2589 return indices[0];
2590 case 2:
2591 return size_type(indices[0]) * table_size[1] + indices[1];
2592 case 3:
2593 return ((size_type(indices[0]) * table_size[1] + indices[1]) *
2594 table_size[2] +
2595 indices[2]);
2596 default:
2597 {
2598 unsigned int s = indices[0];
2599 for (unsigned int n = 1; n < N; ++n)
2600 s = s * table_size[n] + indices[n];
2601 return s;
2602 }
2603 }
2604}
2605
2606
2607
2608template <int N, typename T>
2610TableBase<N, T>::operator()(const TableIndices<N> &indices) const
2611{
2612 for (unsigned int n = 0; n < N; ++n)
2613 AssertIndexRange(indices[n], table_size[n]);
2614 return el(indices);
2615}
2616
2617
2618
2619template <int N, typename T>
2620inline typename AlignedVector<T>::reference
2622{
2623 for (unsigned int n = 0; n < N; ++n)
2624 AssertIndexRange(indices[n], table_size[n]);
2625 return el(indices);
2626}
2627
2628
2629
2630template <int N, typename T>
2632TableBase<N, T>::el(const TableIndices<N> &indices) const
2633{
2634 return values[position(indices)];
2635}
2636
2637
2638
2639template <int N, typename T>
2640inline typename AlignedVector<T>::reference
2642{
2643 AssertIndexRange(position(indices), values.size());
2644 return values[position(indices)];
2645}
2646
2647
2648
2649template <typename T>
2650inline Table<1, T>::Table(const size_type size)
2651 : TableBase<1, T>(TableIndices<1>(size))
2652{}
2653
2654
2655
2656template <typename T>
2657template <typename InputIterator>
2658inline Table<1, T>::Table(const size_type size,
2659 InputIterator entries,
2660 const bool C_style_indexing)
2661 : TableBase<1, T>(TableIndices<1>(size), entries, C_style_indexing)
2662{}
2663
2664
2665
2666template <typename T>
2668Table<1, T>::operator[](const size_type i) const
2669{
2670 AssertIndexRange(i, this->table_size[0]);
2671 return this->values[i];
2672}
2673
2674
2675
2676template <typename T>
2677inline typename AlignedVector<T>::reference
2678Table<1, T>::operator[](const size_type i)
2679{
2680 AssertIndexRange(i, this->table_size[0]);
2681 return this->values[i];
2682}
2683
2684
2685
2686template <typename T>
2688Table<1, T>::operator()(const size_type i) const
2689{
2690 AssertIndexRange(i, this->table_size[0]);
2691 return this->values[i];
2692}
2693
2694
2695
2696template <typename T>
2697inline typename AlignedVector<T>::reference
2698Table<1, T>::operator()(const size_type i)
2699{
2700 AssertIndexRange(i, this->table_size[0]);
2701 return this->values[i];
2702}
2703
2704
2705//---------------------------------------------------------------------------
2706
2707
2708
2709template <typename T>
2710inline Table<2, T>::Table(const size_type size1, const size_type size2)
2711 : TableBase<2, T>(TableIndices<2>(size1, size2))
2712{}
2713
2714
2715
2716template <typename T>
2717template <typename InputIterator>
2718inline Table<2, T>::Table(const size_type size1,
2719 const size_type size2,
2720 InputIterator entries,
2721 const bool C_style_indexing)
2722 : TableBase<2, T>(TableIndices<2>(size1, size2), entries, C_style_indexing)
2723{}
2724
2725
2726
2727template <typename T>
2728inline void
2729Table<2, T>::reinit(const size_type size1,
2730 const size_type size2,
2731 const bool omit_default_initialization)
2732{
2733 this->TableBase<2, T>::reinit(TableIndices<2>(size1, size2),
2734 omit_default_initialization);
2735}
2736
2737
2738
2739template <typename T>
2740inline ::internal::TableBaseAccessors::Accessor<2, T, true, 1>
2741Table<2, T>::operator[](const size_type i) const
2742{
2743 AssertIndexRange(i, this->table_size[0]);
2744 return ::internal::TableBaseAccessors::Accessor<2, T, true, 1>(
2745 *this, this->values.begin() + size_type(i) * n_cols());
2746}
2747
2748
2749
2750template <typename T>
2751inline ::internal::TableBaseAccessors::Accessor<2, T, false, 1>
2752Table<2, T>::operator[](const size_type i)
2753{
2754 AssertIndexRange(i, this->table_size[0]);
2755 return ::internal::TableBaseAccessors::Accessor<2, T, false, 1>(
2756 *this, this->values.begin() + size_type(i) * n_cols());
2757}
2758
2759
2760
2761template <typename T>
2763Table<2, T>::operator()(const size_type i, const size_type j) const
2764{
2765 AssertIndexRange(i, this->table_size[0]);
2766 AssertIndexRange(j, this->table_size[1]);
2767 return this->values[size_type(i) * this->table_size[1] + j];
2768}
2769
2770
2771
2772template <typename T>
2773inline typename AlignedVector<T>::reference
2774Table<2, T>::operator()(const size_type i, const size_type j)
2775{
2776 AssertIndexRange(i, this->table_size[0]);
2777 AssertIndexRange(j, this->table_size[1]);
2778 return this->values[size_type(i) * this->table_size[1] + j];
2779}
2780
2781
2782
2783template <typename T>
2785Table<2, T>::el(const size_type i, const size_type j) const
2786{
2787 return this->values[size_type(i) * this->table_size[1] + j];
2788}
2789
2790
2791
2792template <typename T>
2793inline typename AlignedVector<T>::reference
2794Table<2, T>::el(const size_type i, const size_type j)
2795{
2796 return this->values[size_type(i) * this->table_size[1] + j];
2797}
2798
2799
2800
2801template <typename T>
2802inline typename Table<2, T>::size_type
2803Table<2, T>::n_rows() const
2804{
2805 return this->table_size[0];
2806}
2807
2808
2809
2810template <typename T>
2811inline typename Table<2, T>::size_type
2812Table<2, T>::n_cols() const
2813{
2814 return this->table_size[1];
2815}
2816
2817
2818
2819template <typename T>
2820inline typename Table<2, T>::iterator
2822{
2823 return typename Table<2, T>::iterator(this, 0, 0);
2824}
2825
2826
2827
2828template <typename T>
2829inline typename Table<2, T>::const_iterator
2830Table<2, T>::begin() const
2831{
2832 return typename Table<2, T>::const_iterator(this, 0, 0);
2833}
2834
2835
2836
2837template <typename T>
2838inline typename Table<2, T>::iterator
2840{
2841 return typename Table<2, T>::iterator(this);
2842}
2843
2844
2845
2846template <typename T>
2847inline typename Table<2, T>::const_iterator
2848Table<2, T>::end() const
2849{
2850 return typename Table<2, T>::const_iterator(this);
2851}
2852
2853
2854
2855//---------------------------------------------------------------------------
2856namespace MatrixTableIterators
2857{
2858 namespace internal
2859 {
2860 // Internal calculation routines for AccessorBase. These do not do any
2861 // checking whatsoever.
2862 template <typename TableType, Storage storage_order>
2863 inline std::ptrdiff_t
2864 get_row_index(const std::ptrdiff_t linear_index,
2865 const TableType *const container)
2866 {
2867 switch (storage_order)
2868 {
2869 case Storage::row_major:
2870 return linear_index / container->n_cols();
2871 case Storage::column_major:
2872 return linear_index % container->n_rows();
2873 default:
2875 }
2876 return {};
2877 }
2878
2879
2880
2881 template <typename TableType, Storage storage_order>
2882 inline std::ptrdiff_t
2883 get_column_index(const std::ptrdiff_t linear_index,
2884 const TableType *const container)
2885 {
2886 switch (storage_order)
2887 {
2888 case Storage::row_major:
2889 return linear_index % container->n_cols();
2890 case Storage::column_major:
2891 return linear_index / container->n_rows();
2892 default:
2894 }
2895 return {};
2896 }
2897 } // namespace internal
2898
2899
2900
2901 template <typename TableType, bool Constness, Storage storage_order>
2903 : container(nullptr)
2904 , linear_index(std::numeric_limits<decltype(linear_index)>::max())
2905 {}
2906
2907
2908
2909 template <typename TableType, bool Constness, Storage storage_order>
2910 inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2911 const container_pointer_type table)
2912 : container(table)
2913 , linear_index(container->values.size())
2914 {}
2915
2916
2917
2918 template <typename TableType, bool Constness, Storage storage_order>
2919 inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2920 const AccessorBase<TableType, false, storage_order> &a)
2921 : container(a.container)
2922 , linear_index(a.linear_index)
2923 {}
2924
2925
2926
2927 template <typename TableType, bool Constness, Storage storage_order>
2928 inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2929 const container_pointer_type table,
2930 const std::ptrdiff_t index)
2931 : container(table)
2932 , linear_index(index)
2933 {
2934 Assert(0 <= linear_index &&
2935 std::size_t(linear_index) < container->values.size() + 1,
2936 ExcMessage("The current iterator points outside of the table and is "
2937 "not the end iterator."));
2938 }
2939
2940
2941
2942 template <typename TableType, bool Constness, Storage storage_order>
2943 inline const typename AccessorBase<TableType, Constness, storage_order>::
2944 value_type &
2945 AccessorBase<TableType, Constness, storage_order>::value() const
2946 {
2947 assert_valid_linear_index();
2948 return this->container->values[linear_index];
2949 }
2950
2951
2952
2953 template <typename TableType, bool Constness, Storage storage_order>
2954 inline AccessorBase<TableType, Constness, storage_order>::
2955 operator const value_type &() const
2956 {
2957 assert_valid_linear_index();
2958 return this->container->values[linear_index];
2959 }
2960
2961
2962
2963 template <typename TableType, bool Constness, Storage storage_order>
2964 inline typename AccessorBase<TableType, Constness, storage_order>::size_type
2965 AccessorBase<TableType, Constness, storage_order>::row() const
2966 {
2967 assert_valid_linear_index();
2968 return static_cast<std::size_t>(
2969 internal::get_row_index<TableType, storage_order>(linear_index,
2970 container));
2971 }
2972
2973
2974
2975 template <typename TableType, bool Constness, Storage storage_order>
2976 inline typename AccessorBase<TableType, Constness, storage_order>::size_type
2977 AccessorBase<TableType, Constness, storage_order>::column() const
2978 {
2979 assert_valid_linear_index();
2980 return static_cast<std::size_t>(
2981 internal::get_column_index<TableType, storage_order>(linear_index,
2982 container));
2983 }
2984
2985
2986
2987 template <typename TableType, bool Constness, Storage storage_order>
2988 inline void
2989 AccessorBase<TableType, Constness, storage_order>::assert_valid_linear_index()
2990 const
2991 {
2992# ifdef DEBUG // avoid unused variable warnings by guarding everything
2993 Assert(container != nullptr,
2994 ExcMessage("This accessor has been default-constructed and does not "
2995 "have a corresponding table."));
2996 Assert(!container->empty(),
2997 ExcMessage("An empty table has no rows or columns."));
2998 Assert(0 <= linear_index &&
2999 std::size_t(linear_index) < container->values.size(),
3000 ExcMessage("The current iterator points outside of the table."));
3001 const std::ptrdiff_t row_n =
3002 internal::get_row_index<TableType, storage_order>(linear_index,
3003 container);
3004 const std::ptrdiff_t column_n =
3005 internal::get_column_index<TableType, storage_order>(linear_index,
3006 container);
3007 Assert(0 <= column_n && std::size_t(column_n) < container->n_cols(),
3008 ExcMessage("The current iterator points outside the table."));
3009 Assert(0 <= row_n && std::size_t(row_n) < container->n_rows(),
3010 ExcMessage("The current iterator points outside the table."));
3011# endif
3012 }
3013
3014
3015
3016 template <typename TableType, Storage storage_order>
3017 inline const Accessor<TableType, false, storage_order> &
3018 Accessor<TableType, false, storage_order>::operator=(
3019 const typename Accessor<TableType, false, storage_order>::value_type &t)
3020 const
3021 {
3022 this->assert_valid_linear_index();
3023 this->container->values[this->linear_index] = t;
3024 return *this;
3025 }
3026
3027
3028
3029 template <typename TableType, Storage storage_order>
3030 inline const Accessor<TableType, false, storage_order> &
3031 Accessor<TableType, false, storage_order>::operator=(
3032 typename Accessor<TableType, false, storage_order>::value_type &&t) const
3033 {
3034 this->assert_valid_linear_index();
3035 this->container->values[this->linear_index] = t;
3036 return *this;
3037 }
3038
3039
3040
3041 template <typename TableType, Storage storage_order>
3042 inline typename Accessor<TableType, false, storage_order>::value_type &
3043 Accessor<TableType, false, storage_order>::value() const
3044 {
3045 this->assert_valid_linear_index();
3046 return this->container->values[this->linear_index];
3047 }
3048
3049
3050
3051 template <typename TableType, Storage storage_order>
3052 inline Accessor<TableType, false, storage_order>::operator value_type &()
3053 {
3054 this->assert_valid_linear_index();
3055 return this->container->values[this->linear_index];
3056 }
3057
3058
3059
3060 template <typename TableType, bool Constness, Storage storage_order>
3061 inline Iterator<TableType, Constness, storage_order>::Iterator(
3062 const Accessor<TableType, Constness, storage_order> &a)
3063 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3064 Accessor<TableType, Constness, storage_order>>(a)
3065 {}
3066
3067
3068
3069 template <typename TableType, bool Constness, Storage storage_order>
3070 inline Iterator<TableType, Constness, storage_order>::Iterator(
3071 const container_pointer_type table)
3072 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3073 Accessor<TableType, Constness, storage_order>>(
3074 Accessor<TableType, Constness, storage_order>(table))
3075 {}
3076
3077
3078
3079 template <typename TableType, bool Constness, Storage storage_order>
3080 inline Iterator<TableType, Constness, storage_order>::Iterator(
3081 const Iterator<TableType, false, storage_order> &i)
3082 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3083 Accessor<TableType, Constness, storage_order>>(*i)
3084 {}
3085
3086
3087
3088 template <typename TableType, bool Constness, Storage storage_order>
3089 inline Iterator<TableType, Constness, storage_order>::Iterator(
3090 const container_pointer_type table,
3091 const size_type row_n,
3092 const size_type col_n)
3093 : Iterator(table,
3094 storage_order == Storage::row_major ?
3095 table->n_cols() * row_n + col_n :
3096 table->n_rows() * col_n + row_n)
3097 {}
3098
3099
3100
3101 template <typename TableType, bool Constness, Storage storage_order>
3102 inline Iterator<TableType, Constness, storage_order>::Iterator(
3103 const container_pointer_type table,
3104 const std::ptrdiff_t linear_index)
3105 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3106 Accessor<TableType, Constness, storage_order>>(
3107 Accessor<TableType, Constness, storage_order>(table, linear_index))
3108 {}
3109} // namespace MatrixTableIterators
3110
3111
3112
3113//---------------------------------------------------------------------------
3114template <typename T>
3115inline TransposeTable<T>::TransposeTable(const size_type size1,
3116 const size_type size2)
3117 : TableBase<2, T>(TableIndices<2>(size2, size1))
3118{}
3119
3120
3121
3122template <typename T>
3123inline void
3124TransposeTable<T>::reinit(const size_type size1,
3125 const size_type size2,
3126 const bool omit_default_initialization)
3127{
3128 this->TableBase<2, T>::reinit(TableIndices<2>(size2, size1),
3129 omit_default_initialization);
3130}
3131
3132
3133
3134template <typename T>
3136TransposeTable<T>::operator()(const size_type i, const size_type j) const
3137{
3138 AssertIndexRange(i, this->table_size[1]);
3139 AssertIndexRange(j, this->table_size[0]);
3140 return this->values[size_type(j) * this->table_size[1] + i];
3141}
3142
3143
3144
3145template <typename T>
3146inline typename TransposeTable<T>::reference
3147TransposeTable<T>::operator()(const size_type i, const size_type j)
3148{
3149 AssertIndexRange(i, this->table_size[1]);
3150 AssertIndexRange(j, this->table_size[0]);
3151 return this->values[size_type(j) * this->table_size[1] + i];
3152}
3153
3154
3155
3156template <typename T>
3158TransposeTable<T>::el(const size_type i, const size_type j) const
3159{
3160 return this->values[size_type(j) * this->table_size[1] + i];
3161}
3162
3163
3164
3165template <typename T>
3166inline typename TransposeTable<T>::reference
3167TransposeTable<T>::el(const size_type i, const size_type j)
3168{
3169 return this->values[size_type(j) * this->table_size[1] + i];
3170}
3171
3172
3173
3174template <typename T>
3175inline typename TransposeTable<T>::size_type
3177{
3178 return this->table_size[1];
3179}
3180
3181
3182
3183template <typename T>
3184inline typename TransposeTable<T>::size_type
3186{
3187 return this->table_size[0];
3188}
3189
3190
3191
3192template <typename T>
3193inline typename TransposeTable<T>::iterator
3195{
3196 return typename TransposeTable<T>::iterator(this, 0, 0);
3197}
3198
3199
3200
3201template <typename T>
3204{
3205 return typename TransposeTable<T>::const_iterator(this, 0, 0);
3206}
3207
3208
3209
3210template <typename T>
3211inline typename TransposeTable<T>::iterator
3213{
3214 return typename TransposeTable<T>::iterator(this);
3215}
3216
3217
3218
3219template <typename T>
3222{
3223 return typename TransposeTable<T>::const_iterator(this);
3224}
3225//---------------------------------------------------------------------------
3226
3227
3228
3229template <typename T>
3230inline Table<3, T>::Table(const size_type size1,
3231 const size_type size2,
3232 const size_type size3)
3233 : TableBase<3, T>(TableIndices<3>(size1, size2, size3))
3234{}
3235
3236
3237
3238template <typename T>
3239template <typename InputIterator>
3240inline Table<3, T>::Table(const size_type size1,
3241 const size_type size2,
3242 const size_type size3,
3243 InputIterator entries,
3244 const bool C_style_indexing)
3245 : TableBase<3, T>(TableIndices<3>(size1, size2, size3),
3246 entries,
3247 C_style_indexing)
3248{}
3249
3250
3251
3252template <typename T>
3253inline void
3254Table<3, T>::reinit(const size_type size1,
3255 const size_type size2,
3256 const size_type size3,
3257 const bool omit_default_initialization)
3258{
3259 this->TableBase<3, T>::reinit(TableIndices<3>(size1, size2, size3),
3260 omit_default_initialization);
3261}
3262
3263
3264
3265template <typename T>
3266inline ::internal::TableBaseAccessors::Accessor<3, T, true, 2>
3267Table<3, T>::operator[](const size_type i) const
3268{
3269 AssertIndexRange(i, this->table_size[0]);
3270 const size_type subobject_size =
3271 size_type(this->table_size[1]) * this->table_size[2];
3273 *this, this->values.begin() + i * subobject_size));
3274}
3275
3276
3277
3278template <typename T>
3279inline ::internal::TableBaseAccessors::Accessor<3, T, false, 2>
3280Table<3, T>::operator[](const size_type i)
3281{
3282 AssertIndexRange(i, this->table_size[0]);
3283 const size_type subobject_size =
3284 size_type(this->table_size[1]) * this->table_size[2];
3286 *this, this->values.begin() + i * subobject_size));
3287}
3288
3289
3290
3291template <typename T>
3293Table<3, T>::operator()(const size_type i,
3294 const size_type j,
3295 const size_type k) const
3296{
3297 AssertIndexRange(i, this->table_size[0]);
3298 AssertIndexRange(j, this->table_size[1]);
3299 AssertIndexRange(k, this->table_size[2]);
3300 return this
3301 ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3302 k];
3303}
3304
3305
3306
3307template <typename T>
3308inline typename AlignedVector<T>::reference
3309Table<3, T>::operator()(const size_type i, const size_type j, const size_type k)
3310{
3311 AssertIndexRange(i, this->table_size[0]);
3312 AssertIndexRange(j, this->table_size[1]);
3313 AssertIndexRange(k, this->table_size[2]);
3314 return this
3315 ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3316 k];
3317}
3318
3319
3320
3321template <typename T>
3322inline Table<4, T>::Table(const size_type size1,
3323 const size_type size2,
3324 const size_type size3,
3325 const size_type size4)
3326 : TableBase<4, T>(TableIndices<4>(size1, size2, size3, size4))
3327{}
3328
3329
3330
3331template <typename T>
3332inline ::internal::TableBaseAccessors::Accessor<4, T, true, 3>
3333Table<4, T>::operator[](const size_type i) const
3334{
3335 AssertIndexRange(i, this->table_size[0]);
3336 const size_type subobject_size =
3337 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3339 *this, this->values.begin() + i * subobject_size));
3340}
3341
3342
3343
3344template <typename T>
3345inline ::internal::TableBaseAccessors::Accessor<4, T, false, 3>
3346Table<4, T>::operator[](const size_type i)
3347{
3348 AssertIndexRange(i, this->table_size[0]);
3349 const size_type subobject_size =
3350 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3352 *this, this->values.begin() + i * subobject_size));
3353}
3354
3355
3356
3357template <typename T>
3359Table<4, T>::operator()(const size_type i,
3360 const size_type j,
3361 const size_type k,
3362 const size_type l) const
3363{
3364 AssertIndexRange(i, this->table_size[0]);
3365 AssertIndexRange(j, this->table_size[1]);
3366 AssertIndexRange(k, this->table_size[2]);
3367 AssertIndexRange(l, this->table_size[3]);
3368 return this
3369 ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3370 k) *
3371 this->table_size[3] +
3372 l];
3373}
3374
3375
3376
3377template <typename T>
3378inline typename AlignedVector<T>::reference
3379Table<4, T>::operator()(const size_type i,
3380 const size_type j,
3381 const size_type k,
3382 const size_type l)
3383{
3384 AssertIndexRange(i, this->table_size[0]);
3385 AssertIndexRange(j, this->table_size[1]);
3386 AssertIndexRange(k, this->table_size[2]);
3387 AssertIndexRange(l, this->table_size[3]);
3388 return this
3389 ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3390 k) *
3391 this->table_size[3] +
3392 l];
3393}
3394
3395
3396
3397template <typename T>
3398inline Table<5, T>::Table(const size_type size1,
3399 const size_type size2,
3400 const size_type size3,
3401 const size_type size4,
3402 const size_type size5)
3403 : TableBase<5, T>(TableIndices<5>(size1, size2, size3, size4, size5))
3404{}
3405
3406
3407
3408template <typename T>
3409inline ::internal::TableBaseAccessors::Accessor<5, T, true, 4>
3410Table<5, T>::operator[](const size_type i) const
3411{
3412 AssertIndexRange(i, this->table_size[0]);
3413 const size_type subobject_size = size_type(this->table_size[1]) *
3414 this->table_size[2] * this->table_size[3] *
3415 this->table_size[4];
3417 *this, this->values.begin() + i * subobject_size));
3418}
3419
3420
3421
3422template <typename T>
3423inline ::internal::TableBaseAccessors::Accessor<5, T, false, 4>
3424Table<5, T>::operator[](const size_type i)
3425{
3426 AssertIndexRange(i, this->table_size[0]);
3427 const size_type subobject_size = size_type(this->table_size[1]) *
3428 this->table_size[2] * this->table_size[3] *
3429 this->table_size[4];
3431 *this, this->values.begin() + i * subobject_size));
3432}
3433
3434
3435
3436template <typename T>
3438Table<5, T>::operator()(const size_type i,
3439 const size_type j,
3440 const size_type k,
3441 const size_type l,
3442 const size_type m) const
3443{
3444 AssertIndexRange(i, this->table_size[0]);
3445 AssertIndexRange(j, this->table_size[1]);
3446 AssertIndexRange(k, this->table_size[2]);
3447 AssertIndexRange(l, this->table_size[3]);
3448 AssertIndexRange(m, this->table_size[4]);
3449 return this
3450 ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3451 k) *
3452 this->table_size[3] +
3453 l) *
3454 this->table_size[4] +
3455 m];
3456}
3457
3458
3459
3460template <typename T>
3461inline typename AlignedVector<T>::reference
3462Table<5, T>::operator()(const size_type i,
3463 const size_type j,
3464 const size_type k,
3465 const size_type l,
3466 const size_type m)
3467{
3468 AssertIndexRange(i, this->table_size[0]);
3469 AssertIndexRange(j, this->table_size[1]);
3470 AssertIndexRange(k, this->table_size[2]);
3471 AssertIndexRange(l, this->table_size[3]);
3472 AssertIndexRange(m, this->table_size[4]);
3473 return this
3474 ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3475 k) *
3476 this->table_size[3] +
3477 l) *
3478 this->table_size[4] +
3479 m];
3480}
3481
3482
3483
3484template <typename T>
3485inline Table<6, T>::Table(const size_type size1,
3486 const size_type size2,
3487 const size_type size3,
3488 const size_type size4,
3489 const size_type size5,
3490 const size_type size6)
3491 : TableBase<6, T>()
3492{
3493 TableIndices<6> table_indices;
3494 table_indices[0] = size1;
3495 table_indices[1] = size2;
3496 table_indices[2] = size3;
3497 table_indices[3] = size4;
3498 table_indices[4] = size5;
3499 table_indices[5] = size6;
3500
3501 TableBase<6, T>::reinit(table_indices);
3502}
3503
3504
3505
3506template <typename T>
3507inline ::internal::TableBaseAccessors::Accessor<6, T, true, 5>
3508Table<6, T>::operator[](const size_type i) const
3509{
3510 AssertIndexRange(i, this->table_size[0]);
3511 const size_type subobject_size = size_type(this->table_size[1]) *
3512 this->table_size[2] * this->table_size[3] *
3513 this->table_size[4] * this->table_size[5];
3515 *this, this->values.begin() + i * subobject_size));
3516}
3517
3518
3519
3520template <typename T>
3521inline ::internal::TableBaseAccessors::Accessor<6, T, false, 5>
3522Table<6, T>::operator[](const size_type i)
3523{
3524 AssertIndexRange(i, this->table_size[0]);
3525 const size_type subobject_size = size_type(this->table_size[1]) *
3526 this->table_size[2] * this->table_size[3] *
3527 this->table_size[4] * this->table_size[5];
3529 *this, this->values.begin() + i * subobject_size));
3530}
3531
3532
3533
3534template <typename T>
3536Table<6, T>::operator()(const size_type i,
3537 const size_type j,
3538 const size_type k,
3539 const size_type l,
3540 const size_type m,
3541 const size_type n) const
3542{
3543 AssertIndexRange(i, this->table_size[0]);
3544 AssertIndexRange(j, this->table_size[1]);
3545 AssertIndexRange(k, this->table_size[2]);
3546 AssertIndexRange(l, this->table_size[3]);
3547 AssertIndexRange(m, this->table_size[4]);
3548 AssertIndexRange(n, this->table_size[5]);
3549 return this
3550 ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3551 k) *
3552 this->table_size[3] +
3553 l) *
3554 this->table_size[4] +
3555 m) *
3556 this->table_size[5] +
3557 n];
3558}
3559
3560
3561
3562template <typename T>
3563inline typename AlignedVector<T>::reference
3564Table<6, T>::operator()(const size_type i,
3565 const size_type j,
3566 const size_type k,
3567 const size_type l,
3568 const size_type m,
3569 const size_type n)
3570{
3571 AssertIndexRange(i, this->table_size[0]);
3572 AssertIndexRange(j, this->table_size[1]);
3573 AssertIndexRange(k, this->table_size[2]);
3574 AssertIndexRange(l, this->table_size[3]);
3575 AssertIndexRange(m, this->table_size[4]);
3576 AssertIndexRange(n, this->table_size[5]);
3577 return this
3578 ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3579 k) *
3580 this->table_size[3] +
3581 l) *
3582 this->table_size[4] +
3583 m) *
3584 this->table_size[5] +
3585 n];
3586}
3587
3588
3589
3590template <typename T>
3591inline Table<7, T>::Table(const size_type size1,
3592 const size_type size2,
3593 const size_type size3,
3594 const size_type size4,
3595 const size_type size5,
3596 const size_type size6,
3597 const size_type size7)
3598 : TableBase<7, T>()
3599{
3600 TableIndices<7> table_indices;
3601 table_indices[0] = size1;
3602 table_indices[1] = size2;
3603 table_indices[2] = size3;
3604 table_indices[3] = size4;
3605 table_indices[4] = size5;
3606 table_indices[5] = size6;
3607 table_indices[6] = size7;
3608
3609 TableBase<7, T>::reinit(table_indices);
3610}
3611
3612
3613
3614template <typename T>
3615inline ::internal::TableBaseAccessors::Accessor<7, T, true, 6>
3616Table<7, T>::operator[](const size_type i) const
3617{
3618 AssertIndexRange(i, this->table_size[0]);
3619 const size_type subobject_size =
3620 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3621 this->table_size[4] * this->table_size[5] * this->table_size[6];
3623 *this, this->values.begin() + i * subobject_size));
3624}
3625
3626
3627
3628template <typename T>
3629inline ::internal::TableBaseAccessors::Accessor<7, T, false, 6>
3630Table<7, T>::operator[](const size_type i)
3631{
3632 AssertIndexRange(i, this->table_size[0]);
3633 const size_type subobject_size =
3634 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3635 this->table_size[4] * this->table_size[5] * this->table_size[6];
3637 *this, this->values.begin() + i * subobject_size));
3638}
3639
3640
3641
3642template <typename T>
3644Table<7, T>::operator()(const size_type i,
3645 const size_type j,
3646 const size_type k,
3647 const size_type l,
3648 const size_type m,
3649 const size_type n,
3650 const size_type o) const
3651{
3652 AssertIndexRange(i, this->table_size[0]);
3653 AssertIndexRange(j, this->table_size[1]);
3654 AssertIndexRange(k, this->table_size[2]);
3655 AssertIndexRange(l, this->table_size[3]);
3656 AssertIndexRange(m, this->table_size[4]);
3657 AssertIndexRange(n, this->table_size[5]);
3658 AssertIndexRange(o, this->table_size[6]);
3659 return this->values
3660 [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3661 this->table_size[3] +
3662 l) *
3663 this->table_size[4] +
3664 m) *
3665 this->table_size[5] +
3666 n) *
3667 this->table_size[6] +
3668 o];
3669}
3670
3671
3672
3673template <typename T>
3674inline typename AlignedVector<T>::reference
3675Table<7, T>::operator()(const size_type i,
3676 const size_type j,
3677 const size_type k,
3678 const size_type l,
3679 const size_type m,
3680 const size_type n,
3681 const size_type o)
3682{
3683 AssertIndexRange(i, this->table_size[0]);
3684 AssertIndexRange(j, this->table_size[1]);
3685 AssertIndexRange(k, this->table_size[2]);
3686 AssertIndexRange(l, this->table_size[3]);
3687 AssertIndexRange(m, this->table_size[4]);
3688 AssertIndexRange(n, this->table_size[5]);
3689 AssertIndexRange(o, this->table_size[6]);
3690 return this->values
3691 [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3692 this->table_size[3] +
3693 l) *
3694 this->table_size[4] +
3695 m) *
3696 this->table_size[5] +
3697 n) *
3698 this->table_size[6] +
3699 o];
3700}
3701
3702
3703#endif // DOXYGEN
3704
3705
3706
3712template <int N, typename T>
3713inline void
3715{
3716 u.swap(v);
3717}
3718
3720
3721#endif
*  *  iterator()=default
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:982
AccessorBase(const AccessorBase< TableType, false, storage_order > &)
std::conditional_t< Constness, const TableType *, TableType * > container_pointer_type
Definition table.h:988
typename TableType::value_type value_type
Definition table.h:993
const value_type & value() const
container_pointer_type container
Definition table.h:1062
AccessorBase(const container_pointer_type table)
AccessorBase(const container_pointer_type table, const std::ptrdiff_t linear_index)
friend bool operator==(const AccessorBase< TableType, Constness, storage_order > &left, const AccessorBase< TableType, OtherConstness, storage_order > &right)
Definition table.h:1026
typename TableType::size_type size_type
Definition table.h:998
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:1127
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition table.h:1133
typename AccessorBase< TableType, true, storage_order >::value_type value_type
Definition table.h:1100
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition table.h:1106
Accessor class template. This class is partially specialized for both values of Constness.
Definition table.h:962
Iterator class for both matrix-like tables, i.e., Table<2, T> and TransposeTable.
Definition table.h:1189
Iterator(const container_pointer_type object, const size_type row, const size_type column)
std::conditional_t< Constness, const TableType *, TableType * > container_pointer_type
Definition table.h:1200
Iterator(const Accessor< TableType, Constness, storage_order > &accessor)
Iterator(const container_pointer_type object)
Iterator(const Iterator< TableType, false, storage_order > &i)
Iterator(const container_pointer_type container, const std::ptrdiff_t linear_index)
typename TableType::size_type size_type
Definition table.h:1194
void fill(const T &value)
friend class TableBase
Definition table.h:802
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:793
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
void clear()
TableBase(const TableBase< N, T2 > &src)
void swap(TableBase< N, T > &v) noexcept
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 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:798
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:837
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:1269
typename AlignedVector< T >::value_type value_type
Definition table.h:1259
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:1254
::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:1264
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:1491
::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:1625
::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:1709
::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:1796
::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:1884
::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:2010
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:2002
const_iterator end() const
iterator end()
typename AlignedVector< T >::reference reference
Definition table.h:1988
typename TableBase< 2, T >::size_type size_type
Definition table.h:1978
iterator begin()
const_reference operator()(const size_type i, const size_type j) const
typename AlignedVector< T >::value_type value_type
Definition table.h:1983
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:1993
typename Types< N, T, C >::value_type value_type
Definition table.h:244
typename Types< N, T, C >::const_iterator const_iterator
Definition table.h:247
typename Types< N, T, C >::TableType TableType
Definition table.h:258
typename Types< N, T, C >::const_reference const_reference
Definition table.h:250
typename Types< N, T, C >::iterator iterator
Definition table.h:246
reference operator[](const size_type) const
typename Types< N, T, C >::reference reference
Definition table.h:249
Accessor(const TableType &table, const iterator data)
typename Types< N, T, C >::TableType TableType
Definition table.h:161
typename Types< N, T, C >::iterator iterator
Definition table.h:163
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:164
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_ASSERT_UNREACHABLE()
#define DEAL_II_NOT_IMPLEMENTED()
static ::ExceptionBase & ExcIndexRange(size_type arg1, size_type arg2, size_type arg3)
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
static ::ExceptionBase & ExcMessage(std::string arg1)
std::vector< index_type > data
Definition mpi.cc:734
std::size_t size
Definition mpi.cc:733
constexpr char N
constexpr char T
Storage
Enumeration describing the storage order (i.e., the in-memory layout) of a table class.
Definition table.h:941
std::enable_if_t< std::is_fundamental_v< T >, 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)
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:113
typename AlignedVector< T >::const_iterator const_iterator
Definition table.h:114
typename AlignedVector< T >::reference reference
Definition table.h:116
typename AlignedVector< T >::const_reference const_reference
Definition table.h:117
typename AlignedVector< T >::const_iterator const_iterator
Definition table.h:96
typename AlignedVector< T >::const_reference const_reference
Definition table.h:99
typename AlignedVector< T >::const_iterator iterator
Definition table.h:95
typename AlignedVector< T >::const_reference reference
Definition table.h:98
void swap(TableBase< N, T > &u, TableBase< N, T > &v) noexcept
Definition table.h:3714