23#ifndef VULPES_DATASTRUCTURE_TENSOR_HPP_
24#define VULPES_DATASTRUCTURE_TENSOR_HPP_
59 typename StorageType = std::vector<DataType>>
77 typename = std::enable_if_t<
78 !Tensor && std::is_same_v<StorageType, std::vector<DataType>>,
84 Triangular ? (tri_dim + 1) * tri_dim / 2 : tri_dim * tri_dim),
96 explicit TriMatrix(
const StorageType& data, IndexType tri_dim)
100 Triangular ? (tri_dim + 1) * tri_dim / 2 : tri_dim * tri_dim),
118 typename = std::enable_if_t<
119 Tensor && std::is_same_v<StorageType, std::vector<DataType>>,
121 explicit TriMatrix(IndexType tri_dim, IndexType tensor_size)
125 Triangular ? (tri_dim + 1) * tri_dim / 2 : tri_dim * tri_dim),
143 template <
typename T =
void,
typename = std::enable_if_t<!Tensor, T>>
162 template <
typename T =
void,
typename = std::enable_if_t<Tensor, T>>
163 const DataType&
operator()(IndexType i, IndexType j, IndexType k)
const {
182 typename = std::enable_if_t<
183 !Tensor && std::is_same_v<StorageType, std::vector<DataType>>,
203 template <
typename T =
void,
typename = std::enable_if_t<Tensor, T>>
204 DataType&
operator()(IndexType i, IndexType j, IndexType k) {
261 IndexType
ij(IndexType i, IndexType j)
const {
262 if constexpr (Triangular) {
263 return (i + j) * (i + j + 1) / 2 + j;
278 IndexType
ijk(IndexType i, IndexType j, IndexType k)
const {
306 typename StorageType = std::vector<DataType>>
318 typename = std::enable_if_t<
319 !Tensor && std::is_same_v<StorageType, std::vector<DataType>>,
325 Triangular ? (tri_dim + 2) * (tri_dim + 1) * tri_dim / 6
326 : tri_dim * tri_dim * tri_dim),
342 Triangular ? (tri_dim + 2) * (tri_dim + 1) * tri_dim / 6
343 : tri_dim * tri_dim * tri_dim),
357 typename = std::enable_if_t<
358 Tensor && std::is_same_v<StorageType, std::vector<DataType>>,
364 Triangular ? (tri_dim + 2) * (tri_dim + 1) * tri_dim / 6
365 : tri_dim * tri_dim * tri_dim),
377 template <
typename T =
void,
typename = std::enable_if_t<!Tensor, T>>
378 const DataType&
operator()(IndexType i, IndexType j, IndexType k)
const {
392 template <
typename T =
void,
typename = std::enable_if_t<Tensor, T>>
394 IndexType i, IndexType j, IndexType k, IndexType l)
const {
408 typename = std::enable_if_t<
409 !Tensor && std::is_same_v<StorageType, std::vector<DataType>>,
411 DataType&
operator()(IndexType i, IndexType j, IndexType k) {
424 template <
typename T =
void,
typename = std::enable_if_t<Tensor, T>>
425 DataType&
operator()(IndexType i, IndexType j, IndexType k, IndexType l) {
481 IndexType
ijk(IndexType i, IndexType j, IndexType k)
const {
482 if constexpr (Triangular) {
483 const IndexType j_k = j + k;
484 const IndexType i_j_k = i + j_k;
485 return i_j_k * (i_j_k + 1) * (i_j_k + 2) / 6 + j_k * (j_k + 1) / 2 + k;
501 IndexType
ijkl(IndexType i, IndexType j, IndexType k, IndexType l)
const {
506template <std::
size_t Dim,
bool Simplex,
typename DataType,
typename IndexType>
A class that represents a tetrahedral matrix or tensor, with optional support for higher-dimensional ...
Definition tensor.hpp:307
IndexType ijkl(IndexType i, IndexType j, IndexType k, IndexType l) const
Helper function to compute the flattened index for a 4D tensor matrix.
Definition tensor.hpp:501
IndexType dim() const
Dimension n of the matrix (or one slice of the tensor).
Definition tensor.hpp:433
const DataType & operator()(IndexType i, IndexType j, IndexType k) const
Accessor for non-tensor tetrahedral or cubic matrix (const version).
Definition tensor.hpp:378
TetraTensor(IndexType tri_dim)
Constructor for a non-tensor tetrahedral or cubic matrix.
Definition tensor.hpp:321
IndexType m_tensor_size
Definition tensor.hpp:464
IndexType tdim() const
Dimension along the tensor dimension.
Definition tensor.hpp:437
IndexType m_tri_dim
Definition tensor.hpp:462
IndexType m_tri_size
Definition tensor.hpp:466
auto begin() const
Const begin iterator.
Definition tensor.hpp:454
std::vector< FloatType > m_data
Definition tensor.hpp:470
TetraTensor(IndexType tri_dim, IndexType tensor_size)
Constructor for a tensor-like tetrahedral or cubic matrix.
Definition tensor.hpp:360
DataType & operator()(IndexType i, IndexType j, IndexType k)
Mutator for non-tensor tetrahedral or cubic matrix.
Definition tensor.hpp:411
auto end()
End iterator.
Definition tensor.hpp:450
const DataType & operator()(IndexType i, IndexType j, IndexType k, IndexType l) const
Accessor for tensor-like tetrahedral or cubic matrix (const version).
Definition tensor.hpp:393
DataType & operator()(IndexType i, IndexType j, IndexType k, IndexType l)
Mutator for tensor-like tetrahedral or cubic matrix.
Definition tensor.hpp:425
auto begin()
Begin iterator.
Definition tensor.hpp:446
IndexType m_numel
Definition tensor.hpp:468
IndexType ijk(IndexType i, IndexType j, IndexType k) const
Helper function to compute the flattened index for a 3D tetrahedral or cubic matrix.
Definition tensor.hpp:481
auto end() const
Const end iterator.
Definition tensor.hpp:458
TetraTensor(const StorageType &data, IndexType tri_dim)
Copy-constructor (almost).
Definition tensor.hpp:338
IndexType numel() const
Total number of elements.
Definition tensor.hpp:441
A class that represents a triangular or square matrix, with optional support for tensor-like multi-di...
Definition tensor.hpp:60
IndexType dim() const
Dimension n of the matrix (or one slice of the tensor).
Definition tensor.hpp:212
IndexType m_tri_size
Definition tensor.hpp:245
auto begin()
Begin iterator.
Definition tensor.hpp:225
DataType & operator()(IndexType i, IndexType j, IndexType k)
Mutator for tensor matrices.
Definition tensor.hpp:204
IndexType m_tri_dim
Definition tensor.hpp:241
IndexType tdim() const
Dimension along the tensor dimension.
Definition tensor.hpp:216
DataType & operator()(IndexType i, IndexType j)
Mutator for non-tensor matrices.
Definition tensor.hpp:185
TriMatrix(IndexType tri_dim)
Constructor for a non-tensor matrix.
Definition tensor.hpp:80
TriMatrix(const StorageType &data, IndexType tri_dim)
Copy-constructor (almost).
Definition tensor.hpp:96
auto begin() const
Const begin iterator.
Definition tensor.hpp:233
IndexType numel() const
Total number of elements.
Definition tensor.hpp:220
IndexType ij(IndexType i, IndexType j) const
Helper function to compute the flattened index for a 2D matrix.
Definition tensor.hpp:261
const DataType & operator()(IndexType i, IndexType j) const
Accessor for non-tensor matrices (const version).
Definition tensor.hpp:144
std::vector< FloatType > m_data
Definition tensor.hpp:249
auto end()
End iterator.
Definition tensor.hpp:229
auto end() const
Const end iterator.
Definition tensor.hpp:237
IndexType ijk(IndexType i, IndexType j, IndexType k) const
Helper function to compute the flattened index for a 3D tensor matrix.
Definition tensor.hpp:278
TriMatrix(IndexType tri_dim, IndexType tensor_size)
Constructor for a tensor-like matrix.
Definition tensor.hpp:121
IndexType m_numel
Definition tensor.hpp:247
const DataType & operator()(IndexType i, IndexType j, IndexType k) const
Accessor for tensor matrices (const version).
Definition tensor.hpp:163
IndexType m_tensor_size
Definition tensor.hpp:243
Definition crs_map.hpp:36
std::conditional_t< Dim==2, TriMatrix< Simplex, false, DataType, IndexType, const DataType * >, std::conditional_t< Dim==3, TetraTensor< Simplex, false, DataType, IndexType, const DataType * >, const DataType * > > SimplexDataView
Definition tensor.hpp:507
@ Tensor
Definition fe_space.hpp:48
Definition cell_manager.hpp:38