deal.II version GIT relicensing-1941-ga9013bea74 2024-10-08 06:50: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>
440class TableBase : public Subscriptor
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>
889 Table(const size_type size,
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>
2168 : Subscriptor()
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 : Subscriptor(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<Subscriptor &>(*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<Subscriptor &>(*this) = std::move(static_cast<Subscriptor &>(m));
2346 values = std::move(m.values);
2347 table_size = m.table_size;
2349
2350 return *this;
2351}
2352
2353
2354
2355template <int N, typename T>
2356inline bool
2358{
2359 return (values == T2.values);
2360}
2361
2362
2363
2364template <int N, typename T>
2365inline void
2367{
2368 // use parallel set operation
2369 if (n_elements() != 0)
2370 values.fill(T());
2371}
2372
2373
2374
2375template <int N, typename T>
2376inline void
2377TableBase<N, T>::fill(const T &value)
2378{
2379 if (n_elements() != 0)
2380 values.fill(value);
2381}
2382
2383
2384
2385template <int N, typename T>
2386inline void
2388 const unsigned int root_process)
2389{
2390 // Replicate first the actual data, then also exchange the
2391 // extents of the table
2392 values.replicate_across_communicator(communicator, root_process);
2393
2394 table_size =
2395 Utilities::MPI::broadcast(communicator, table_size, root_process);
2396}
2397
2398
2399
2400template <int N, typename T>
2401inline void
2403 const bool omit_default_initialization)
2404{
2405 table_size = new_sizes;
2406
2407 const size_type new_size = n_elements();
2408
2409 // if zero size was given: free all memory
2410 if (new_size == 0)
2411 {
2412 values.resize(0);
2413 // set all sizes to zero, even
2414 // if one was previously
2415 // nonzero. This simplifies
2416 // some assertions.
2417 table_size = TableIndices<N>();
2418
2419 return;
2420 }
2421
2422 // adjust values field. If it was empty before, we can simply call resize(),
2423 // which can set all the data fields. Otherwise, select the fast resize and
2424 // manually fill in all the elements as required by the design of this
2425 // class. (Selecting another code for the empty case ensures that we touch
2426 // the memory only once for non-trivial classes that need to initialize the
2427 // memory also in resize_fast.)
2428 if (!omit_default_initialization)
2429 {
2430 if (values.empty())
2431 values.resize(new_size);
2432 else
2433 {
2434 values.resize_fast(new_size);
2435 values.fill();
2436 }
2437 }
2438 else
2439 values.resize_fast(new_size);
2440}
2441
2442
2443
2444template <int N, typename T>
2445inline void
2447{
2448 values.clear();
2449 table_size = TableIndices<N>();
2450}
2451
2452
2453
2454template <int N, typename T>
2455inline const TableIndices<N> &
2457{
2458 return table_size;
2459}
2460
2461
2462
2463template <int N, typename T>
2464inline typename TableBase<N, T>::size_type
2465TableBase<N, T>::size(const unsigned int i) const
2466{
2467 AssertIndexRange(i, N);
2468 return table_size[i];
2469}
2470
2471
2472
2473template <int N, typename T>
2474inline typename TableBase<N, T>::size_type
2476{
2477 size_type s = 1;
2478 for (unsigned int n = 0; n < N; ++n)
2479 s *= table_size[n];
2480 return s;
2481}
2482
2483
2484
2485template <int N, typename T>
2486inline bool
2488{
2489 return (n_elements() == 0);
2490}
2491
2492
2493
2494namespace internal
2495{
2496 namespace TableImplementation
2497 {
2498 template <typename InputIterator, typename T>
2499 void
2500 fill_Fortran_style(InputIterator entries, TableBase<1, T> &table)
2501 {
2502 using size_type = typename TableBase<1, T>::size_type;
2503 for (size_type i = 0; i < table.size()[0]; ++i)
2504 table(TableIndices<1>(i)) = *entries++;
2505 }
2506
2507
2508 template <typename InputIterator, typename T>
2509 void
2510 fill_Fortran_style(InputIterator entries, TableBase<2, T> &table)
2511 {
2512 using size_type = typename TableBase<2, T>::size_type;
2513 for (size_type j = 0; j < table.size()[1]; ++j)
2514 for (size_type i = 0; i < table.size()[0]; ++i)
2515 table(TableIndices<2>(i, j)) = *entries++;
2516 }
2517
2518
2519 template <typename InputIterator, typename T>
2520 void
2521 fill_Fortran_style(InputIterator entries, TableBase<3, T> &table)
2522 {
2523 using size_type = typename TableBase<3, T>::size_type;
2524 for (size_type k = 0; k < table.size()[2]; ++k)
2525 for (size_type j = 0; j < table.size()[1]; ++j)
2526 for (size_type i = 0; i < table.size()[0]; ++i)
2527 table(TableIndices<3>(i, j, k)) = *entries++;
2528 }
2529
2530
2531 template <typename InputIterator, typename T, int N>
2532 void
2533 fill_Fortran_style(InputIterator, TableBase<N, T> &)
2534 {
2536 }
2537 } // namespace TableImplementation
2538} // namespace internal
2539
2540
2541template <int N, typename T>
2542template <typename InputIterator>
2543inline void
2544TableBase<N, T>::fill(InputIterator entries, const bool C_style_indexing)
2545{
2546 Assert(n_elements() != 0, ExcMessage("Trying to fill an empty matrix."));
2547
2548 if (C_style_indexing)
2549 for (typename AlignedVector<T>::iterator p = values.begin();
2550 p != values.end();
2551 ++p)
2552 *p = *entries++;
2553 else
2554 internal::TableImplementation::fill_Fortran_style(entries, *this);
2555}
2556
2557
2558
2559template <int N, typename T>
2560inline void
2562{
2563 values.swap(v.values);
2564 std::swap(table_size, v.table_size);
2565}
2566
2567
2568
2569template <int N, typename T>
2570inline std::size_t
2572{
2573 return sizeof(*this) + MemoryConsumption::memory_consumption(values);
2574}
2575
2576
2577
2578template <int N, typename T>
2579inline typename TableBase<N, T>::size_type
2580TableBase<N, T>::position(const TableIndices<N> &indices) const
2581{
2582 // specialize this for the
2583 // different numbers of dimensions,
2584 // to make the job somewhat easier
2585 // for the compiler. have the
2586 // general formula nevertheless:
2587 switch (N)
2588 {
2589 case 1:
2590 return indices[0];
2591 case 2:
2592 return size_type(indices[0]) * table_size[1] + indices[1];
2593 case 3:
2594 return ((size_type(indices[0]) * table_size[1] + indices[1]) *
2595 table_size[2] +
2596 indices[2]);
2597 default:
2598 {
2599 unsigned int s = indices[0];
2600 for (unsigned int n = 1; n < N; ++n)
2601 s = s * table_size[n] + indices[n];
2602 return s;
2603 }
2604 }
2605}
2606
2607
2608
2609template <int N, typename T>
2611TableBase<N, T>::operator()(const TableIndices<N> &indices) const
2612{
2613 for (unsigned int n = 0; n < N; ++n)
2614 AssertIndexRange(indices[n], table_size[n]);
2615 return el(indices);
2616}
2617
2618
2619
2620template <int N, typename T>
2621inline typename AlignedVector<T>::reference
2623{
2624 for (unsigned int n = 0; n < N; ++n)
2625 AssertIndexRange(indices[n], table_size[n]);
2626 return el(indices);
2627}
2628
2629
2630
2631template <int N, typename T>
2633TableBase<N, T>::el(const TableIndices<N> &indices) const
2634{
2635 return values[position(indices)];
2636}
2637
2638
2639
2640template <int N, typename T>
2641inline typename AlignedVector<T>::reference
2643{
2644 AssertIndexRange(position(indices), values.size());
2645 return values[position(indices)];
2646}
2647
2648
2649
2650template <typename T>
2651inline Table<1, T>::Table(const size_type size)
2652 : TableBase<1, T>(TableIndices<1>(size))
2653{}
2654
2655
2656
2657template <typename T>
2658template <typename InputIterator>
2659inline Table<1, T>::Table(const size_type size,
2660 InputIterator entries,
2661 const bool C_style_indexing)
2662 : TableBase<1, T>(TableIndices<1>(size), entries, C_style_indexing)
2663{}
2664
2665
2666
2667template <typename T>
2669Table<1, T>::operator[](const size_type i) const
2670{
2671 AssertIndexRange(i, this->table_size[0]);
2672 return this->values[i];
2673}
2674
2675
2676
2677template <typename T>
2678inline typename AlignedVector<T>::reference
2679Table<1, T>::operator[](const size_type i)
2680{
2681 AssertIndexRange(i, this->table_size[0]);
2682 return this->values[i];
2683}
2684
2685
2686
2687template <typename T>
2689Table<1, T>::operator()(const size_type i) const
2690{
2691 AssertIndexRange(i, this->table_size[0]);
2692 return this->values[i];
2693}
2694
2695
2696
2697template <typename T>
2698inline typename AlignedVector<T>::reference
2699Table<1, T>::operator()(const size_type i)
2700{
2701 AssertIndexRange(i, this->table_size[0]);
2702 return this->values[i];
2703}
2704
2705
2706//---------------------------------------------------------------------------
2707
2708
2709
2710template <typename T>
2711inline Table<2, T>::Table(const size_type size1, const size_type size2)
2712 : TableBase<2, T>(TableIndices<2>(size1, size2))
2713{}
2714
2715
2716
2717template <typename T>
2718template <typename InputIterator>
2719inline Table<2, T>::Table(const size_type size1,
2720 const size_type size2,
2721 InputIterator entries,
2722 const bool C_style_indexing)
2723 : TableBase<2, T>(TableIndices<2>(size1, size2), entries, C_style_indexing)
2724{}
2725
2726
2727
2728template <typename T>
2729inline void
2730Table<2, T>::reinit(const size_type size1,
2731 const size_type size2,
2732 const bool omit_default_initialization)
2733{
2734 this->TableBase<2, T>::reinit(TableIndices<2>(size1, size2),
2735 omit_default_initialization);
2736}
2737
2738
2739
2740template <typename T>
2741inline ::internal::TableBaseAccessors::Accessor<2, T, true, 1>
2742Table<2, T>::operator[](const size_type i) const
2743{
2744 AssertIndexRange(i, this->table_size[0]);
2745 return ::internal::TableBaseAccessors::Accessor<2, T, true, 1>(
2746 *this, this->values.begin() + size_type(i) * n_cols());
2747}
2748
2749
2750
2751template <typename T>
2752inline ::internal::TableBaseAccessors::Accessor<2, T, false, 1>
2753Table<2, T>::operator[](const size_type i)
2754{
2755 AssertIndexRange(i, this->table_size[0]);
2756 return ::internal::TableBaseAccessors::Accessor<2, T, false, 1>(
2757 *this, this->values.begin() + size_type(i) * n_cols());
2758}
2759
2760
2761
2762template <typename T>
2764Table<2, T>::operator()(const size_type i, const size_type j) const
2765{
2766 AssertIndexRange(i, this->table_size[0]);
2767 AssertIndexRange(j, this->table_size[1]);
2768 return this->values[size_type(i) * this->table_size[1] + j];
2769}
2770
2771
2772
2773template <typename T>
2774inline typename AlignedVector<T>::reference
2775Table<2, T>::operator()(const size_type i, const size_type j)
2776{
2777 AssertIndexRange(i, this->table_size[0]);
2778 AssertIndexRange(j, this->table_size[1]);
2779 return this->values[size_type(i) * this->table_size[1] + j];
2780}
2781
2782
2783
2784template <typename T>
2786Table<2, T>::el(const size_type i, const size_type j) const
2787{
2788 return this->values[size_type(i) * this->table_size[1] + j];
2789}
2790
2791
2792
2793template <typename T>
2794inline typename AlignedVector<T>::reference
2795Table<2, T>::el(const size_type i, const size_type j)
2796{
2797 return this->values[size_type(i) * this->table_size[1] + j];
2798}
2799
2800
2801
2802template <typename T>
2803inline typename Table<2, T>::size_type
2804Table<2, T>::n_rows() const
2805{
2806 return this->table_size[0];
2807}
2808
2809
2810
2811template <typename T>
2812inline typename Table<2, T>::size_type
2813Table<2, T>::n_cols() const
2814{
2815 return this->table_size[1];
2816}
2817
2818
2819
2820template <typename T>
2821inline typename Table<2, T>::iterator
2823{
2824 return typename Table<2, T>::iterator(this, 0, 0);
2825}
2826
2827
2828
2829template <typename T>
2830inline typename Table<2, T>::const_iterator
2831Table<2, T>::begin() const
2832{
2833 return typename Table<2, T>::const_iterator(this, 0, 0);
2834}
2835
2836
2837
2838template <typename T>
2839inline typename Table<2, T>::iterator
2841{
2842 return typename Table<2, T>::iterator(this);
2843}
2844
2845
2846
2847template <typename T>
2848inline typename Table<2, T>::const_iterator
2849Table<2, T>::end() const
2850{
2851 return typename Table<2, T>::const_iterator(this);
2852}
2853
2854
2855
2856//---------------------------------------------------------------------------
2857namespace MatrixTableIterators
2858{
2859 namespace internal
2860 {
2861 // Internal calculation routines for AccessorBase. These do not do any
2862 // checking whatsoever.
2863 template <typename TableType, Storage storage_order>
2864 inline std::ptrdiff_t
2865 get_row_index(const std::ptrdiff_t linear_index,
2866 const TableType *const container)
2867 {
2868 switch (storage_order)
2869 {
2870 case Storage::row_major:
2871 return linear_index / container->n_cols();
2872 case Storage::column_major:
2873 return linear_index % container->n_rows();
2874 default:
2876 }
2877 return {};
2878 }
2879
2880
2881
2882 template <typename TableType, Storage storage_order>
2883 inline std::ptrdiff_t
2884 get_column_index(const std::ptrdiff_t linear_index,
2885 const TableType *const container)
2886 {
2887 switch (storage_order)
2888 {
2889 case Storage::row_major:
2890 return linear_index % container->n_cols();
2891 case Storage::column_major:
2892 return linear_index / container->n_rows();
2893 default:
2895 }
2896 return {};
2897 }
2898 } // namespace internal
2899
2900
2901
2902 template <typename TableType, bool Constness, Storage storage_order>
2904 : container(nullptr)
2905 , linear_index(std::numeric_limits<decltype(linear_index)>::max())
2906 {}
2907
2908
2909
2910 template <typename TableType, bool Constness, Storage storage_order>
2911 inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2912 const container_pointer_type table)
2913 : container(table)
2914 , linear_index(container->values.size())
2915 {}
2916
2917
2918
2919 template <typename TableType, bool Constness, Storage storage_order>
2920 inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2921 const AccessorBase<TableType, false, storage_order> &a)
2922 : container(a.container)
2923 , linear_index(a.linear_index)
2924 {}
2925
2926
2927
2928 template <typename TableType, bool Constness, Storage storage_order>
2929 inline AccessorBase<TableType, Constness, storage_order>::AccessorBase(
2930 const container_pointer_type table,
2931 const std::ptrdiff_t index)
2932 : container(table)
2933 , linear_index(index)
2934 {
2935 Assert(0 <= linear_index &&
2936 std::size_t(linear_index) < container->values.size() + 1,
2937 ExcMessage("The current iterator points outside of the table and is "
2938 "not the end iterator."));
2939 }
2940
2941
2942
2943 template <typename TableType, bool Constness, Storage storage_order>
2944 inline const typename AccessorBase<TableType, Constness, storage_order>::
2945 value_type &
2946 AccessorBase<TableType, Constness, storage_order>::value() const
2947 {
2948 assert_valid_linear_index();
2949 return this->container->values[linear_index];
2950 }
2951
2952
2953
2954 template <typename TableType, bool Constness, Storage storage_order>
2955 inline AccessorBase<TableType, Constness, storage_order>::
2956 operator const value_type &() const
2957 {
2958 assert_valid_linear_index();
2959 return this->container->values[linear_index];
2960 }
2961
2962
2963
2964 template <typename TableType, bool Constness, Storage storage_order>
2965 inline typename AccessorBase<TableType, Constness, storage_order>::size_type
2966 AccessorBase<TableType, Constness, storage_order>::row() const
2967 {
2968 assert_valid_linear_index();
2969 return static_cast<std::size_t>(
2970 internal::get_row_index<TableType, storage_order>(linear_index,
2971 container));
2972 }
2973
2974
2975
2976 template <typename TableType, bool Constness, Storage storage_order>
2977 inline typename AccessorBase<TableType, Constness, storage_order>::size_type
2978 AccessorBase<TableType, Constness, storage_order>::column() const
2979 {
2980 assert_valid_linear_index();
2981 return static_cast<std::size_t>(
2982 internal::get_column_index<TableType, storage_order>(linear_index,
2983 container));
2984 }
2985
2986
2987
2988 template <typename TableType, bool Constness, Storage storage_order>
2989 inline void
2990 AccessorBase<TableType, Constness, storage_order>::assert_valid_linear_index()
2991 const
2992 {
2993# ifdef DEBUG // avoid unused variable warnings by guarding everything
2994 Assert(container != nullptr,
2995 ExcMessage("This accessor has been default-constructed and does not "
2996 "have a corresponding table."));
2997 Assert(!container->empty(),
2998 ExcMessage("An empty table has no rows or columns."));
2999 Assert(0 <= linear_index &&
3000 std::size_t(linear_index) < container->values.size(),
3001 ExcMessage("The current iterator points outside of the table."));
3002 const std::ptrdiff_t row_n =
3003 internal::get_row_index<TableType, storage_order>(linear_index,
3004 container);
3005 const std::ptrdiff_t column_n =
3006 internal::get_column_index<TableType, storage_order>(linear_index,
3007 container);
3008 Assert(0 <= column_n && std::size_t(column_n) < container->n_cols(),
3009 ExcMessage("The current iterator points outside the table."));
3010 Assert(0 <= row_n && std::size_t(row_n) < container->n_rows(),
3011 ExcMessage("The current iterator points outside the table."));
3012# endif
3013 }
3014
3015
3016
3017 template <typename TableType, Storage storage_order>
3018 inline const Accessor<TableType, false, storage_order> &
3019 Accessor<TableType, false, storage_order>::operator=(
3020 const typename Accessor<TableType, false, storage_order>::value_type &t)
3021 const
3022 {
3023 this->assert_valid_linear_index();
3024 this->container->values[this->linear_index] = t;
3025 return *this;
3026 }
3027
3028
3029
3030 template <typename TableType, Storage storage_order>
3031 inline const Accessor<TableType, false, storage_order> &
3032 Accessor<TableType, false, storage_order>::operator=(
3033 typename Accessor<TableType, false, storage_order>::value_type &&t) const
3034 {
3035 this->assert_valid_linear_index();
3036 this->container->values[this->linear_index] = t;
3037 return *this;
3038 }
3039
3040
3041
3042 template <typename TableType, Storage storage_order>
3043 inline typename Accessor<TableType, false, storage_order>::value_type &
3044 Accessor<TableType, false, storage_order>::value() const
3045 {
3046 this->assert_valid_linear_index();
3047 return this->container->values[this->linear_index];
3048 }
3049
3050
3051
3052 template <typename TableType, Storage storage_order>
3053 inline Accessor<TableType, false, storage_order>::operator value_type &()
3054 {
3055 this->assert_valid_linear_index();
3056 return this->container->values[this->linear_index];
3057 }
3058
3059
3060
3061 template <typename TableType, bool Constness, Storage storage_order>
3062 inline Iterator<TableType, Constness, storage_order>::Iterator(
3063 const Accessor<TableType, Constness, storage_order> &a)
3064 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3065 Accessor<TableType, Constness, storage_order>>(a)
3066 {}
3067
3068
3069
3070 template <typename TableType, bool Constness, Storage storage_order>
3071 inline Iterator<TableType, Constness, storage_order>::Iterator(
3072 const container_pointer_type table)
3073 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3074 Accessor<TableType, Constness, storage_order>>(
3075 Accessor<TableType, Constness, storage_order>(table))
3076 {}
3077
3078
3079
3080 template <typename TableType, bool Constness, Storage storage_order>
3081 inline Iterator<TableType, Constness, storage_order>::Iterator(
3082 const Iterator<TableType, false, storage_order> &i)
3083 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3084 Accessor<TableType, Constness, storage_order>>(*i)
3085 {}
3086
3087
3088
3089 template <typename TableType, bool Constness, Storage storage_order>
3090 inline Iterator<TableType, Constness, storage_order>::Iterator(
3091 const container_pointer_type table,
3092 const size_type row_n,
3093 const size_type col_n)
3094 : Iterator(table,
3095 storage_order == Storage::row_major ?
3096 table->n_cols() * row_n + col_n :
3097 table->n_rows() * col_n + row_n)
3098 {}
3099
3100
3101
3102 template <typename TableType, bool Constness, Storage storage_order>
3103 inline Iterator<TableType, Constness, storage_order>::Iterator(
3104 const container_pointer_type table,
3105 const std::ptrdiff_t linear_index)
3106 : LinearIndexIterator<Iterator<TableType, Constness, storage_order>,
3107 Accessor<TableType, Constness, storage_order>>(
3108 Accessor<TableType, Constness, storage_order>(table, linear_index))
3109 {}
3110} // namespace MatrixTableIterators
3111
3112
3113
3114//---------------------------------------------------------------------------
3115template <typename T>
3116inline TransposeTable<T>::TransposeTable(const size_type size1,
3117 const size_type size2)
3118 : TableBase<2, T>(TableIndices<2>(size2, size1))
3119{}
3120
3121
3122
3123template <typename T>
3124inline void
3125TransposeTable<T>::reinit(const size_type size1,
3126 const size_type size2,
3127 const bool omit_default_initialization)
3128{
3129 this->TableBase<2, T>::reinit(TableIndices<2>(size2, size1),
3130 omit_default_initialization);
3131}
3132
3133
3134
3135template <typename T>
3137TransposeTable<T>::operator()(const size_type i, const size_type j) const
3138{
3139 AssertIndexRange(i, this->table_size[1]);
3140 AssertIndexRange(j, this->table_size[0]);
3141 return this->values[size_type(j) * this->table_size[1] + i];
3142}
3143
3144
3145
3146template <typename T>
3147inline typename TransposeTable<T>::reference
3148TransposeTable<T>::operator()(const size_type i, const size_type j)
3149{
3150 AssertIndexRange(i, this->table_size[1]);
3151 AssertIndexRange(j, this->table_size[0]);
3152 return this->values[size_type(j) * this->table_size[1] + i];
3153}
3154
3155
3156
3157template <typename T>
3159TransposeTable<T>::el(const size_type i, const size_type j) const
3160{
3161 return this->values[size_type(j) * this->table_size[1] + i];
3162}
3163
3164
3165
3166template <typename T>
3167inline typename TransposeTable<T>::reference
3168TransposeTable<T>::el(const size_type i, const size_type j)
3169{
3170 return this->values[size_type(j) * this->table_size[1] + i];
3171}
3172
3173
3174
3175template <typename T>
3176inline typename TransposeTable<T>::size_type
3178{
3179 return this->table_size[1];
3180}
3181
3182
3183
3184template <typename T>
3185inline typename TransposeTable<T>::size_type
3187{
3188 return this->table_size[0];
3189}
3190
3191
3192
3193template <typename T>
3194inline typename TransposeTable<T>::iterator
3196{
3197 return typename TransposeTable<T>::iterator(this, 0, 0);
3198}
3199
3200
3201
3202template <typename T>
3205{
3206 return typename TransposeTable<T>::const_iterator(this, 0, 0);
3207}
3208
3209
3210
3211template <typename T>
3212inline typename TransposeTable<T>::iterator
3214{
3215 return typename TransposeTable<T>::iterator(this);
3216}
3217
3218
3219
3220template <typename T>
3223{
3224 return typename TransposeTable<T>::const_iterator(this);
3225}
3226//---------------------------------------------------------------------------
3227
3228
3229
3230template <typename T>
3231inline Table<3, T>::Table(const size_type size1,
3232 const size_type size2,
3233 const size_type size3)
3234 : TableBase<3, T>(TableIndices<3>(size1, size2, size3))
3235{}
3236
3237
3238
3239template <typename T>
3240template <typename InputIterator>
3241inline Table<3, T>::Table(const size_type size1,
3242 const size_type size2,
3243 const size_type size3,
3244 InputIterator entries,
3245 const bool C_style_indexing)
3246 : TableBase<3, T>(TableIndices<3>(size1, size2, size3),
3247 entries,
3248 C_style_indexing)
3249{}
3250
3251
3252
3253template <typename T>
3254inline void
3255Table<3, T>::reinit(const size_type size1,
3256 const size_type size2,
3257 const size_type size3,
3258 const bool omit_default_initialization)
3259{
3260 this->TableBase<3, T>::reinit(TableIndices<3>(size1, size2, size3),
3261 omit_default_initialization);
3262}
3263
3264
3265
3266template <typename T>
3267inline ::internal::TableBaseAccessors::Accessor<3, T, true, 2>
3268Table<3, T>::operator[](const size_type i) const
3269{
3270 AssertIndexRange(i, this->table_size[0]);
3271 const size_type subobject_size =
3272 size_type(this->table_size[1]) * this->table_size[2];
3274 *this, this->values.begin() + i * subobject_size));
3275}
3276
3277
3278
3279template <typename T>
3280inline ::internal::TableBaseAccessors::Accessor<3, T, false, 2>
3281Table<3, T>::operator[](const size_type i)
3282{
3283 AssertIndexRange(i, this->table_size[0]);
3284 const size_type subobject_size =
3285 size_type(this->table_size[1]) * this->table_size[2];
3287 *this, this->values.begin() + i * subobject_size));
3288}
3289
3290
3291
3292template <typename T>
3294Table<3, T>::operator()(const size_type i,
3295 const size_type j,
3296 const size_type k) const
3297{
3298 AssertIndexRange(i, this->table_size[0]);
3299 AssertIndexRange(j, this->table_size[1]);
3300 AssertIndexRange(k, this->table_size[2]);
3301 return this
3302 ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3303 k];
3304}
3305
3306
3307
3308template <typename T>
3309inline typename AlignedVector<T>::reference
3310Table<3, T>::operator()(const size_type i, const size_type j, const size_type k)
3311{
3312 AssertIndexRange(i, this->table_size[0]);
3313 AssertIndexRange(j, this->table_size[1]);
3314 AssertIndexRange(k, this->table_size[2]);
3315 return this
3316 ->values[(size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3317 k];
3318}
3319
3320
3321
3322template <typename T>
3323inline Table<4, T>::Table(const size_type size1,
3324 const size_type size2,
3325 const size_type size3,
3326 const size_type size4)
3327 : TableBase<4, T>(TableIndices<4>(size1, size2, size3, size4))
3328{}
3329
3330
3331
3332template <typename T>
3333inline ::internal::TableBaseAccessors::Accessor<4, T, true, 3>
3334Table<4, T>::operator[](const size_type i) const
3335{
3336 AssertIndexRange(i, this->table_size[0]);
3337 const size_type subobject_size =
3338 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3340 *this, this->values.begin() + i * subobject_size));
3341}
3342
3343
3344
3345template <typename T>
3346inline ::internal::TableBaseAccessors::Accessor<4, T, false, 3>
3347Table<4, T>::operator[](const size_type i)
3348{
3349 AssertIndexRange(i, this->table_size[0]);
3350 const size_type subobject_size =
3351 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3353 *this, this->values.begin() + i * subobject_size));
3354}
3355
3356
3357
3358template <typename T>
3360Table<4, T>::operator()(const size_type i,
3361 const size_type j,
3362 const size_type k,
3363 const size_type l) const
3364{
3365 AssertIndexRange(i, this->table_size[0]);
3366 AssertIndexRange(j, this->table_size[1]);
3367 AssertIndexRange(k, this->table_size[2]);
3368 AssertIndexRange(l, this->table_size[3]);
3369 return this
3370 ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3371 k) *
3372 this->table_size[3] +
3373 l];
3374}
3375
3376
3377
3378template <typename T>
3379inline typename AlignedVector<T>::reference
3380Table<4, T>::operator()(const size_type i,
3381 const size_type j,
3382 const size_type k,
3383 const size_type l)
3384{
3385 AssertIndexRange(i, this->table_size[0]);
3386 AssertIndexRange(j, this->table_size[1]);
3387 AssertIndexRange(k, this->table_size[2]);
3388 AssertIndexRange(l, this->table_size[3]);
3389 return this
3390 ->values[((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3391 k) *
3392 this->table_size[3] +
3393 l];
3394}
3395
3396
3397
3398template <typename T>
3399inline Table<5, T>::Table(const size_type size1,
3400 const size_type size2,
3401 const size_type size3,
3402 const size_type size4,
3403 const size_type size5)
3404 : TableBase<5, T>(TableIndices<5>(size1, size2, size3, size4, size5))
3405{}
3406
3407
3408
3409template <typename T>
3410inline ::internal::TableBaseAccessors::Accessor<5, T, true, 4>
3411Table<5, T>::operator[](const size_type i) const
3412{
3413 AssertIndexRange(i, this->table_size[0]);
3414 const size_type subobject_size = size_type(this->table_size[1]) *
3415 this->table_size[2] * this->table_size[3] *
3416 this->table_size[4];
3418 *this, this->values.begin() + i * subobject_size));
3419}
3420
3421
3422
3423template <typename T>
3424inline ::internal::TableBaseAccessors::Accessor<5, T, false, 4>
3425Table<5, T>::operator[](const size_type i)
3426{
3427 AssertIndexRange(i, this->table_size[0]);
3428 const size_type subobject_size = size_type(this->table_size[1]) *
3429 this->table_size[2] * this->table_size[3] *
3430 this->table_size[4];
3432 *this, this->values.begin() + i * subobject_size));
3433}
3434
3435
3436
3437template <typename T>
3439Table<5, T>::operator()(const size_type i,
3440 const size_type j,
3441 const size_type k,
3442 const size_type l,
3443 const size_type m) const
3444{
3445 AssertIndexRange(i, this->table_size[0]);
3446 AssertIndexRange(j, this->table_size[1]);
3447 AssertIndexRange(k, this->table_size[2]);
3448 AssertIndexRange(l, this->table_size[3]);
3449 AssertIndexRange(m, this->table_size[4]);
3450 return this
3451 ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3452 k) *
3453 this->table_size[3] +
3454 l) *
3455 this->table_size[4] +
3456 m];
3457}
3458
3459
3460
3461template <typename T>
3462inline typename AlignedVector<T>::reference
3463Table<5, T>::operator()(const size_type i,
3464 const size_type j,
3465 const size_type k,
3466 const size_type l,
3467 const size_type m)
3468{
3469 AssertIndexRange(i, this->table_size[0]);
3470 AssertIndexRange(j, this->table_size[1]);
3471 AssertIndexRange(k, this->table_size[2]);
3472 AssertIndexRange(l, this->table_size[3]);
3473 AssertIndexRange(m, this->table_size[4]);
3474 return this
3475 ->values[(((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3476 k) *
3477 this->table_size[3] +
3478 l) *
3479 this->table_size[4] +
3480 m];
3481}
3482
3483
3484
3485template <typename T>
3486inline Table<6, T>::Table(const size_type size1,
3487 const size_type size2,
3488 const size_type size3,
3489 const size_type size4,
3490 const size_type size5,
3491 const size_type size6)
3492 : TableBase<6, T>()
3493{
3494 TableIndices<6> table_indices;
3495 table_indices[0] = size1;
3496 table_indices[1] = size2;
3497 table_indices[2] = size3;
3498 table_indices[3] = size4;
3499 table_indices[4] = size5;
3500 table_indices[5] = size6;
3501
3502 TableBase<6, T>::reinit(table_indices);
3503}
3504
3505
3506
3507template <typename T>
3508inline ::internal::TableBaseAccessors::Accessor<6, T, true, 5>
3509Table<6, T>::operator[](const size_type i) const
3510{
3511 AssertIndexRange(i, this->table_size[0]);
3512 const size_type subobject_size = size_type(this->table_size[1]) *
3513 this->table_size[2] * this->table_size[3] *
3514 this->table_size[4] * this->table_size[5];
3516 *this, this->values.begin() + i * subobject_size));
3517}
3518
3519
3520
3521template <typename T>
3522inline ::internal::TableBaseAccessors::Accessor<6, T, false, 5>
3523Table<6, T>::operator[](const size_type i)
3524{
3525 AssertIndexRange(i, this->table_size[0]);
3526 const size_type subobject_size = size_type(this->table_size[1]) *
3527 this->table_size[2] * this->table_size[3] *
3528 this->table_size[4] * this->table_size[5];
3530 *this, this->values.begin() + i * subobject_size));
3531}
3532
3533
3534
3535template <typename T>
3537Table<6, T>::operator()(const size_type i,
3538 const size_type j,
3539 const size_type k,
3540 const size_type l,
3541 const size_type m,
3542 const size_type n) const
3543{
3544 AssertIndexRange(i, this->table_size[0]);
3545 AssertIndexRange(j, this->table_size[1]);
3546 AssertIndexRange(k, this->table_size[2]);
3547 AssertIndexRange(l, this->table_size[3]);
3548 AssertIndexRange(m, this->table_size[4]);
3549 AssertIndexRange(n, this->table_size[5]);
3550 return this
3551 ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3552 k) *
3553 this->table_size[3] +
3554 l) *
3555 this->table_size[4] +
3556 m) *
3557 this->table_size[5] +
3558 n];
3559}
3560
3561
3562
3563template <typename T>
3564inline typename AlignedVector<T>::reference
3565Table<6, T>::operator()(const size_type i,
3566 const size_type j,
3567 const size_type k,
3568 const size_type l,
3569 const size_type m,
3570 const size_type n)
3571{
3572 AssertIndexRange(i, this->table_size[0]);
3573 AssertIndexRange(j, this->table_size[1]);
3574 AssertIndexRange(k, this->table_size[2]);
3575 AssertIndexRange(l, this->table_size[3]);
3576 AssertIndexRange(m, this->table_size[4]);
3577 AssertIndexRange(n, this->table_size[5]);
3578 return this
3579 ->values[((((size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3580 k) *
3581 this->table_size[3] +
3582 l) *
3583 this->table_size[4] +
3584 m) *
3585 this->table_size[5] +
3586 n];
3587}
3588
3589
3590
3591template <typename T>
3592inline Table<7, T>::Table(const size_type size1,
3593 const size_type size2,
3594 const size_type size3,
3595 const size_type size4,
3596 const size_type size5,
3597 const size_type size6,
3598 const size_type size7)
3599 : TableBase<7, T>()
3600{
3601 TableIndices<7> table_indices;
3602 table_indices[0] = size1;
3603 table_indices[1] = size2;
3604 table_indices[2] = size3;
3605 table_indices[3] = size4;
3606 table_indices[4] = size5;
3607 table_indices[5] = size6;
3608 table_indices[6] = size7;
3609
3610 TableBase<7, T>::reinit(table_indices);
3611}
3612
3613
3614
3615template <typename T>
3616inline ::internal::TableBaseAccessors::Accessor<7, T, true, 6>
3617Table<7, T>::operator[](const size_type i) const
3618{
3619 AssertIndexRange(i, this->table_size[0]);
3620 const size_type subobject_size =
3621 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3622 this->table_size[4] * this->table_size[5] * this->table_size[6];
3624 *this, this->values.begin() + i * subobject_size));
3625}
3626
3627
3628
3629template <typename T>
3630inline ::internal::TableBaseAccessors::Accessor<7, T, false, 6>
3631Table<7, T>::operator[](const size_type i)
3632{
3633 AssertIndexRange(i, this->table_size[0]);
3634 const size_type subobject_size =
3635 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3636 this->table_size[4] * this->table_size[5] * this->table_size[6];
3638 *this, this->values.begin() + i * subobject_size));
3639}
3640
3641
3642
3643template <typename T>
3645Table<7, T>::operator()(const size_type i,
3646 const size_type j,
3647 const size_type k,
3648 const size_type l,
3649 const size_type m,
3650 const size_type n,
3651 const size_type o) const
3652{
3653 AssertIndexRange(i, this->table_size[0]);
3654 AssertIndexRange(j, this->table_size[1]);
3655 AssertIndexRange(k, this->table_size[2]);
3656 AssertIndexRange(l, this->table_size[3]);
3657 AssertIndexRange(m, this->table_size[4]);
3658 AssertIndexRange(n, this->table_size[5]);
3659 AssertIndexRange(o, this->table_size[6]);
3660 return this->values
3661 [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3662 this->table_size[3] +
3663 l) *
3664 this->table_size[4] +
3665 m) *
3666 this->table_size[5] +
3667 n) *
3668 this->table_size[6] +
3669 o];
3670}
3671
3672
3673
3674template <typename T>
3675inline typename AlignedVector<T>::reference
3676Table<7, T>::operator()(const size_type i,
3677 const size_type j,
3678 const size_type k,
3679 const size_type l,
3680 const size_type m,
3681 const size_type n,
3682 const size_type o)
3683{
3684 AssertIndexRange(i, this->table_size[0]);
3685 AssertIndexRange(j, this->table_size[1]);
3686 AssertIndexRange(k, this->table_size[2]);
3687 AssertIndexRange(l, this->table_size[3]);
3688 AssertIndexRange(m, this->table_size[4]);
3689 AssertIndexRange(n, this->table_size[5]);
3690 AssertIndexRange(o, this->table_size[6]);
3691 return this->values
3692 [(((((size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3693 this->table_size[3] +
3694 l) *
3695 this->table_size[4] +
3696 m) *
3697 this->table_size[5] +
3698 n) *
3699 this->table_size[6] +
3700 o];
3701}
3702
3703
3704#endif // DOXYGEN
3705
3706
3707
3713template <int N, typename T>
3714inline void
3716{
3717 u.swap(v);
3718}
3719
3721
3722#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()
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:3715