deal.II version GIT relicensing-2289-g1e5549a87a 2024-12-21 21:30:00+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: LGPL-2.1-or-later
4// Copyright (C) 2002 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_table_h
16#define dealii_table_h
17
18#include <deal.II/base/config.h>
19
26
27#include <algorithm>
28#include <cstddef>
29#include <limits>
30
32
33// forward declaration
34#ifndef DOXYGEN
35template <int N, typename T>
36class TableBase;
37template <int N, typename T>
38class Table;
39template <typename T>
40class TransposeTable;
41template <typename T>
42class Table<1, T>;
43template <typename T>
44class Table<2, T>;
45template <typename T>
46class Table<3, T>;
47template <typename T>
48class Table<4, T>;
49template <typename T>
50class Table<5, T>;
51template <typename T>
52class Table<6, T>;
53#endif
54
55
56
57namespace internal
58{
73 namespace TableBaseAccessors
74 {
82 template <int N, typename T, bool Constness>
83 struct Types
84 {};
85
91 template <int N, typename T>
103
109 template <int N, typename T>
121
122
159 template <int N, typename T, bool C, unsigned int P>
161 {
162 public:
164
167
168 using size_type = size_t;
169 using difference_type = ptrdiff_t;
170
171 private:
178
179 public:
188
192 Accessor<N, T, C, P - 1>
193 operator[](const size_type i) const;
194
200 size_type,
201 size_type,
202 size_type,
203 << "Index " << N - P + 1 << "has a value of " << arg1
204 << " but needs to be in the range [" << arg2 << ',' << arg3
205 << "[.");
206
207 private:
215
216 // declare some other classes
217 // as friends. make sure to
218 // work around bugs in some
219 // compilers
220 template <int N1, typename T1>
221 friend class ::Table;
222 template <int N1, typename T1, bool C1, unsigned int P1>
223 friend class Accessor;
224 friend class ::Table<N, T>;
225 friend class Accessor<N, T, C, P + 1>;
226 };
227
228
229
237 template <int N, typename T, bool C>
238 class Accessor<N, T, C, 1>
239 {
240 public:
247
250
253
254 using size_type = size_t;
255 using difference_type = ptrdiff_t;
256
261
262 private:
275
276 public:
285
290 operator[](const size_type) const;
291
297 size() const;
298
303 begin() const;
304
309 end() const;
310
311 private:
319
320 // declare some other classes
321 // as friends. make sure to
322 // work around bugs in some
323 // compilers
324 template <int N1, typename T1>
325 friend class ::Table;
326 template <int N1, typename T1, bool C1, unsigned int P1>
327 friend class Accessor;
328 friend class ::Table<2, T>;
329 friend class Accessor<N, T, C, 2>;
330 };
331 } // namespace TableBaseAccessors
332
333} // namespace internal
334
335
336
439template <int N, typename T>
441{
442public:
443 using value_type = T;
444
449
450
454 TableBase() = default;
455
460 explicit TableBase(const TableIndices<N> &sizes);
461
467 template <typename InputIterator>
469 InputIterator entries,
470 const bool C_style_indexing = true);
471
476
481 template <typename T2>
483
487 TableBase(TableBase<N, T> &&src) noexcept;
488
492 ~TableBase() override = default;
493
504
512 template <typename T2>
515
521 operator=(TableBase<N, T> &&src) noexcept;
522
526 bool
527 operator==(const TableBase<N, T> &T2) const;
528
533 void
535
544 void
545 reinit(const TableIndices<N> &new_size,
546 const bool omit_default_initialization = false);
547
551 void
553
558 size(const unsigned int i) const;
559
563 const TableIndices<N> &
564 size() const;
565
571 n_elements() const;
572
577 bool
578 empty() const;
579
616 template <typename InputIterator>
617 void
618 fill(InputIterator entries, const bool C_style_indexing = true);
619
623 void
624 fill(const T &value);
625
631
640 operator()(const TableIndices<N> &indices) const;
641
726 void
728 const unsigned int root_process);
729
742 void
743 swap(TableBase<N, T> &v) noexcept;
744
749 std::size_t
751
757 template <class Archive>
758 void
759 serialize(Archive &ar, const unsigned int version);
760
761protected:
767 position(const TableIndices<N> &indices) const;
768
776 el(const TableIndices<N> &indices);
777
789 el(const TableIndices<N> &indices) const;
790
791protected:
796
801
802 // Make all other table classes friends.
803 template <int, typename>
804 friend class TableBase;
805};
806
807
820template <int N, typename T>
821class Table;
822
823
832template <typename T>
833class Table<1, T> : public TableBase<1, T>
834{
835public:
840
844 Table() = default;
845
849 explicit Table(const size_type size);
850
888 template <typename InputIterator>
890 InputIterator entries,
891 const bool C_style_indexing = true);
892
898 operator[](const size_type i) const;
899
906
912 operator()(const size_type i) const;
913
920
924 using TableBase<1, T>::operator();
925};
926
927
928
937{
942 enum class Storage
943 {
947 row_major,
948
953 };
954
955 // Forward declaration of the iterator class.
956 template <typename TableType, bool Constness, Storage storage_order>
957 class Iterator;
958
963 template <typename TableType, bool Constness, Storage storage_order>
964 class Accessor;
965
982 template <typename TableType, bool Constness, Storage storage_order>
984 {
985 public:
990 std::conditional_t<Constness, const TableType *, TableType *>;
991
995 using value_type = typename TableType::value_type;
996
1000 using size_type = typename TableType::size_type;
1001
1006
1011
1016
1021 const std::ptrdiff_t linear_index);
1022
1026 template <bool OtherConstness>
1027 friend bool
1031 {
1032 return left.container == right.container &&
1033 left.linear_index == right.linear_index;
1034 }
1035
1040 const value_type &
1041 value() const;
1042
1046 operator const value_type &() const;
1047
1051 size_type
1052 row() const;
1053
1057 size_type
1058 column() const;
1059
1060 protected:
1065
1069 std::ptrdiff_t linear_index;
1070
1077 void
1079
1080 // Make the const version a friend for copying.
1081 friend class AccessorBase<TableType, true, storage_order>;
1082
1083 // Make the underlying iterator class a friend.
1084 friend class LinearIndexIterator<
1085 Iterator<TableType, Constness, storage_order>,
1086 Accessor<TableType, Constness, storage_order>>;
1087 };
1088
1093 template <typename TableType, Storage storage_order>
1094 class Accessor<TableType, true, storage_order>
1095 : public AccessorBase<TableType, true, storage_order>
1096 {
1097 public:
1103
1109
1113 using AccessorBase<TableType, true, storage_order>::AccessorBase;
1114 };
1115
1120 template <typename TableType, Storage storage_order>
1121 class Accessor<TableType, false, storage_order>
1122 : public AccessorBase<TableType, false, storage_order>
1123 {
1124 public:
1130
1136
1140 using AccessorBase<TableType, false, storage_order>::AccessorBase;
1141
1147 operator=(const value_type &) const;
1148
1155
1160 using AccessorBase<TableType, false, storage_order>::value;
1161
1166 value_type &
1167 value() const;
1168
1172 operator value_type &();
1173 };
1174
1187 template <typename TableType, bool Constness, Storage storage_order>
1189 : public LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
1190 Accessor<TableType, Constness, storage_order>>
1191 {
1192 public:
1196 using size_type = typename TableType::size_type;
1197
1202 std::conditional_t<Constness, const TableType *, TableType *>;
1203
1208
1213
1218 const size_type row,
1219 const size_type column);
1220
1225
1230 const std::ptrdiff_t linear_index);
1231 };
1232} // namespace MatrixTableIterators
1233
1234
1235
1249template <typename T>
1250class Table<2, T> : public TableBase<2, T>
1251{
1252public:
1257
1262
1267
1272
1277 using const_iterator = MatrixTableIterators::
1278 Iterator<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1279
1283 using iterator = MatrixTableIterators::
1284 Iterator<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1285
1289 Table() = default;
1290
1294 Table(const size_type size1, const size_type size2);
1295
1334 template <typename InputIterator>
1335 Table(const size_type size1,
1336 const size_type size2,
1337 InputIterator entries,
1338 const bool C_style_indexing = true);
1339
1345 void
1346 reinit(const size_type size1,
1347 const size_type size2,
1348 const bool omit_default_initialization = false);
1349
1350 using TableBase<2, T>::reinit;
1351
1359 operator[](const size_type i) const;
1360
1369
1377 operator()(const size_type i, const size_type j) const;
1378
1386 operator()(const size_type i, const size_type j);
1387
1391 using TableBase<2, T>::operator();
1392
1397 size_type
1398 n_rows() const;
1399
1404 size_type
1405 n_cols() const;
1406
1410 iterator
1412
1417 begin() const;
1418
1422 iterator
1424
1429 end() const;
1430
1431protected:
1443 el(const size_type i, const size_type j);
1444
1460 el(const size_type i, const size_type j) const;
1461
1462 // Make the AccessorBase class a friend so that it may directly index into
1463 // the array.
1464 friend class MatrixTableIterators::
1465 AccessorBase<Table<2, T>, true, MatrixTableIterators::Storage::row_major>;
1466 friend class MatrixTableIterators::
1467 AccessorBase<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1468
1469 // Make the mutable accessor class a friend so that we can write to array
1470 // entries with iterators.
1471 friend class MatrixTableIterators::
1472 Accessor<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1473};
1474
1475
1476
1486template <typename T>
1487class Table<3, T> : public TableBase<3, T>
1488{
1489public:
1494
1498 Table() = default;
1499
1503 Table(const size_type size1, const size_type size2, const size_type size3);
1504
1545 template <typename InputIterator>
1546 Table(const size_type size1,
1547 const size_type size2,
1548 const size_type size3,
1549 InputIterator entries,
1550 const bool C_style_indexing = true);
1551
1556 void
1557 reinit(const size_type size1,
1558 const size_type size2,
1559 const size_type size3,
1560 const bool omit_default_initialization = false);
1561
1562 using TableBase<3, T>::reinit;
1563
1572 operator[](const size_type i) const;
1573
1583
1591 operator()(const size_type i, const size_type j, const size_type k) const;
1592
1593
1601 operator()(const size_type i, const size_type j, const size_type k);
1602
1606 using TableBase<3, T>::operator();
1607};
1608
1609
1610
1620template <typename T>
1621class Table<4, T> : public TableBase<4, T>
1622{
1623public:
1628
1632 Table() = default;
1633
1637 Table(const size_type size1,
1638 const size_type size2,
1639 const size_type size3,
1640 const size_type size4);
1641
1650 operator[](const size_type i) const;
1651
1661
1670 const size_type j,
1671 const size_type k,
1672 const size_type l) const;
1673
1674
1683 const size_type j,
1684 const size_type k,
1685 const size_type l);
1686
1690 using TableBase<4, T>::operator();
1691};
1692
1693
1694
1704template <typename T>
1705class Table<5, T> : public TableBase<5, T>
1706{
1707public:
1712
1713
1717 Table() = default;
1718
1722 Table(const size_type size1,
1723 const size_type size2,
1724 const size_type size3,
1725 const size_type size4,
1726 const size_type size5);
1727
1736 operator[](const size_type i) const;
1737
1747
1756 const size_type j,
1757 const size_type k,
1758 const size_type l,
1759 const size_type m) const;
1760
1769 const size_type j,
1770 const size_type k,
1771 const size_type l,
1772 const size_type m);
1773
1777 using TableBase<5, T>::operator();
1778};
1779
1780
1781
1791template <typename T>
1792class Table<6, T> : public TableBase<6, T>
1793{
1794public:
1799
1803 Table() = default;
1804
1808 Table(const size_type size1,
1809 const size_type size2,
1810 const size_type size3,
1811 const size_type size4,
1812 const size_type size5,
1813 const size_type size6);
1814
1823 operator[](const size_type i) const;
1824
1834
1843 const size_type j,
1844 const size_type k,
1845 const size_type l,
1846 const size_type m,
1847 const size_type n) const;
1848
1857 const size_type j,
1858 const size_type k,
1859 const size_type l,
1860 const size_type m,
1861 const size_type n);
1862
1866 using TableBase<6, T>::operator();
1867};
1868
1869
1879template <typename T>
1880class Table<7, T> : public TableBase<7, T>
1881{
1882public:
1887
1891 Table() = default;
1892
1896 Table(const size_type size1,
1897 const size_type size2,
1898 const size_type size3,
1899 const size_type size4,
1900 const size_type size5,
1901 const size_type size6,
1902 const size_type size7);
1903
1912 operator[](const size_type i) const;
1913
1923
1932 const size_type j,
1933 const size_type k,
1934 const size_type l,
1935 const size_type m,
1936 const size_type n,
1937 const size_type o) const;
1938
1947 const size_type j,
1948 const size_type k,
1949 const size_type l,
1950 const size_type m,
1951 const size_type n,
1952 const size_type o);
1953
1957 using TableBase<7, T>::operator();
1958};
1959
1960
1973template <typename T>
1974class TransposeTable : public TableBase<2, T>
1975{
1976public:
1981
1986
1991
1996
2003 true,
2005
2009 using iterator =
2011 false,
2013
2017 TransposeTable() = default;
2018
2022 TransposeTable(const size_type size1, const size_type size2);
2023
2029 void
2030 reinit(const size_type size1,
2031 const size_type size2,
2032 const bool omit_default_initialization = false);
2033
2041 operator()(const size_type i, const size_type j) const;
2042
2049 reference
2050 operator()(const size_type i, const size_type j);
2051
2056 size_type
2057 n_rows() const;
2058
2063 size_type
2064 n_cols() const;
2065
2069 iterator
2071
2076 begin() const;
2077
2081 iterator
2083
2088 end() const;
2089
2090protected:
2101 reference
2102 el(const size_type i, const size_type j);
2103
2119 el(const size_type i, const size_type j) const;
2120
2121 // Make the AccessorBase class a friend so that it may directly index into
2122 // the array.
2124 TransposeTable<T>,
2125 true,
2126 MatrixTableIterators::Storage::column_major>;
2128 TransposeTable<T>,
2129 false,
2130 MatrixTableIterators::Storage::column_major>;
2131
2132 // Make the mutable accessor class a friend so that we can write to array
2133 // entries with iterators.
2134 friend class MatrixTableIterators::Accessor<
2135 TransposeTable<T>,
2136 false,
2137 MatrixTableIterators::Storage::column_major>;
2138};
2139
2140
2141
2142/* --------------------- Template and inline functions ---------------- */
2143
2144#ifndef DOXYGEN
2145
2146template <int N, typename T>
2147TableBase<N, T>::TableBase(const TableIndices<N> &sizes)
2148{
2149 reinit(sizes);
2150}
2151
2152
2153
2154template <int N, typename T>
2155template <typename InputIterator>
2157 InputIterator entries,
2158 const bool C_style_indexing)
2159{
2160 reinit(sizes);
2161 fill(entries, C_style_indexing);
2162}
2163
2164
2165
2166template <int N, typename T>
2169 , values(src.values)
2170 , table_size(src.table_size)
2171{}
2172
2173
2174
2175template <int N, typename T>
2176template <typename T2>
2178{
2179 reinit(src.table_size);
2180 if (src.n_elements() != 0)
2181 std::copy(src.values.begin(), src.values.end(), values.begin());
2182}
2183
2184
2185
2186template <int N, typename T>
2188 : EnableObserverPointer(std::move(src))
2189 , values(std::move(src.values))
2190 , table_size(src.table_size)
2191{
2193}
2194
2195
2196
2197template <int N, typename T>
2198template <class Archive>
2199inline void
2200TableBase<N, T>::serialize(Archive &ar, const unsigned int)
2201{
2202 ar &static_cast<EnableObserverPointer &>(*this);
2203
2204 ar &values &table_size;
2205}
2206
2207
2208
2209namespace internal
2210{
2211 namespace TableBaseAccessors
2212 {
2213 template <int N, typename T, bool C, unsigned int P>
2214 inline Accessor<N, T, C, P>::Accessor(const TableType &table,
2215 const iterator data)
2216 : table(table)
2217 , data(data)
2218 {}
2219
2220
2221
2222 template <int N, typename T, bool C, unsigned int P>
2223 inline Accessor<N, T, C, P>::Accessor(const Accessor &a)
2224 : table(a.table)
2225 , data(a.data)
2226 {}
2227
2228
2229
2230 template <int N, typename T, bool C, unsigned int P>
2231 inline Accessor<N, T, C, P - 1>
2232 Accessor<N, T, C, P>::operator[](const size_type i) const
2233 {
2234 AssertIndexRange(i, table.size()[N - P]);
2235
2236 // access i-th
2237 // subobject. optimize on the
2238 // case i==0
2239 if (i == 0)
2240 return Accessor<N, T, C, P - 1>(table, data);
2241 else
2242 {
2243 // note: P>1, otherwise the
2244 // specialization would have
2245 // been taken!
2246 size_type subobject_size = table.size()[N - 1];
2247 for (int p = P - 1; p > 1; --p)
2248 subobject_size *= table.size()[N - p];
2249 const iterator new_data = data + i * subobject_size;
2250 return Accessor<N, T, C, P - 1>(table, new_data);
2251 }
2252 }
2253
2254
2255
2256 template <int N, typename T, bool C>
2257 inline Accessor<N, T, C, 1>::Accessor(const TableType &table,
2258 const iterator data)
2259 : table(table)
2260 , data(data)
2261 {}
2262
2263
2264
2265 template <int N, typename T, bool C>
2266 inline Accessor<N, T, C, 1>::Accessor(const Accessor &a)
2267 : table(a.table)
2268 , data(a.data)
2269 {}
2270
2271
2272
2273 template <int N, typename T, bool C>
2274 inline typename Accessor<N, T, C, 1>::reference
2275 Accessor<N, T, C, 1>::operator[](const size_type i) const
2276 {
2277 AssertIndexRange(i, table.size()[N - 1]);
2278 return *(data + i);
2279 }
2280
2281
2282
2283 template <int N, typename T, bool C>
2284 inline typename Accessor<N, T, C, 1>::size_type
2285 Accessor<N, T, C, 1>::size() const
2286 {
2287 return table.size()[N - 1];
2288 }
2289
2290
2291
2292 template <int N, typename T, bool C>
2293 inline typename Accessor<N, T, C, 1>::iterator
2294 Accessor<N, T, C, 1>::begin() const
2295 {
2296 return data;
2297 }
2298
2299
2300
2301 template <int N, typename T, bool C>
2302 inline typename Accessor<N, T, C, 1>::iterator
2303 Accessor<N, T, C, 1>::end() const
2304 {
2305 return data + table.size()[N - 1];
2306 }
2307 } // namespace TableBaseAccessors
2308} // namespace internal
2309
2310
2311
2312template <int N, typename T>
2313inline TableBase<N, T> &
2315{
2316 if (!m.empty())
2317 values = m.values;
2318 reinit(m.size(), true);
2319
2320 return *this;
2321}
2322
2323
2324
2325template <int N, typename T>
2326template <typename T2>
2327inline TableBase<N, T> &
2329{
2330 reinit(m.size(), true);
2331 if (!empty())
2332 std::copy(m.values.begin(),
2333 m.values.begin() + n_elements(),
2334 values.begin());
2335
2336 return *this;
2337}
2338
2339
2340
2341template <int N, typename T>
2342inline TableBase<N, T> &
2344{
2345 static_cast<EnableObserverPointer &>(*this) =
2346 std::move(static_cast<EnableObserverPointer &>(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 {
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:
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:
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:984
AccessorBase(const AccessorBase< TableType, false, storage_order > &)
std::conditional_t< Constness, const TableType *, TableType * > container_pointer_type
Definition table.h:990
typename TableType::value_type value_type
Definition table.h:995
const value_type & value() const
container_pointer_type container
Definition table.h:1064
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:1028
typename TableType::size_type size_type
Definition table.h:1000
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:1129
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition table.h:1135
typename AccessorBase< TableType, true, storage_order >::value_type value_type
Definition table.h:1102
typename AccessorBase< TableType, true, storage_order >::size_type size_type
Definition table.h:1108
Accessor class template. This class is partially specialized for both values of Constness.
Definition table.h:964
Iterator class for both matrix-like tables, i.e., Table<2, T> and TransposeTable.
Definition table.h:1191
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:1202
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:1196
void fill(const T &value)
friend class TableBase
Definition table.h:804
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:795
TableBase< N, T > & operator=(TableBase< N, T > &&src) noexcept
~TableBase() override=default
typename AlignedVector< T >::size_type size_type
Definition table.h:448
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:443
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:800
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:839
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:1271
typename AlignedVector< T >::value_type value_type
Definition table.h:1261
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:1256
::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:1266
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:1493
::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:1627
::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:1711
::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:1798
::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:1886
::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:2012
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:2004
const_iterator end() const
iterator end()
typename AlignedVector< T >::reference reference
Definition table.h:1990
typename TableBase< 2, T >::size_type size_type
Definition table.h:1980
iterator begin()
const_reference operator()(const size_type i, const size_type j) const
typename AlignedVector< T >::value_type value_type
Definition table.h:1985
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:1995
typename Types< N, T, C >::value_type value_type
Definition table.h:246
typename Types< N, T, C >::const_iterator const_iterator
Definition table.h:249
typename Types< N, T, C >::TableType TableType
Definition table.h:260
typename Types< N, T, C >::const_reference const_reference
Definition table.h:252
typename Types< N, T, C >::iterator iterator
Definition table.h:248
reference operator[](const size_type) const
typename Types< N, T, C >::reference reference
Definition table.h:251
Accessor(const TableType &table, const iterator data)
typename Types< N, T, C >::TableType TableType
Definition table.h:163
typename Types< N, T, C >::iterator iterator
Definition table.h:165
Accessor< N, T, C, P - 1 > operator[](const size_type i) const
Accessor(const TableType &table, const iterator data)
typename Types< N, T, C >::const_iterator const_iterator
Definition table.h:166
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
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)
Definition exceptions.h:557
static ::ExceptionBase & ExcMessage(std::string arg1)
#define DEAL_II_ASSERT_UNREACHABLE()
#define DEAL_II_NOT_IMPLEMENTED()
std::vector< index_type > data
Definition mpi.cc:735
std::size_t size
Definition mpi.cc:734
Storage
Enumeration describing the storage order (i.e., the in-memory layout) of a table class.
Definition table.h:943
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:115
typename AlignedVector< T >::const_iterator const_iterator
Definition table.h:116
typename AlignedVector< T >::reference reference
Definition table.h:118
typename AlignedVector< T >::const_reference const_reference
Definition table.h:119
typename AlignedVector< T >::const_iterator const_iterator
Definition table.h:98
typename AlignedVector< T >::const_reference const_reference
Definition table.h:101
typename AlignedVector< T >::const_iterator iterator
Definition table.h:97
typename AlignedVector< T >::const_reference reference
Definition table.h:100
void swap(TableBase< N, T > &u, TableBase< N, T > &v) noexcept
Definition table.h:3716