Documentation 6b54b78464
Loading...
Searching...
No Matches
C2DContainer.hpp File Reference

A templated vector/matrix object. More...

#include "../toolboxes/allocation_toolbox.hpp"
#include "../basic_types/datatype_structure.hpp"
#include "../parallelization/vectorization.hpp"
#include <utility>
#include <type_traits>

Go to the source code of this file.

Classes

class  container_details::AccessorImpl< Index_t, Scalar_t, Store, AlignSize, StaticRows, StaticCols >
 Base accessor class and version of template for both sizes known at compile time. More...
 
class  container_details::AccessorImpl< Index_t, Scalar_t, Store, AlignSize, DynamicSize, StaticCols >
 
class  container_details::AccessorImpl< Index_t, Scalar_t, Store, AlignSize, StaticRows, DynamicSize >
 
class  container_details::AccessorImpl< Index_t, Scalar_t, Store, AlignSize, DynamicSize, DynamicSize >
 
class  container_details::AccessorImpl< Index_t, Scalar_t, StorageType::ColumnMajor, AlignSize, StaticRows, 1 >
 
class  container_details::AccessorImpl< Index_t, Scalar_t, StorageType::ColumnMajor, AlignSize, DynamicSize, 1 >
 
class  container_details::AccessorImpl< Index_t, Scalar_t, StorageType::RowMajor, AlignSize, 1, StaticCols >
 
class  container_details::AccessorImpl< Index_t, Scalar_t, StorageType::RowMajor, AlignSize, 1, DynamicSize >
 
class  C2DContainer< Index_t, Scalar_t, Store, AlignSize, StaticRows, StaticCols >
 A templated matrix/vector-like object. More...
 
class  C2DContainer< Index_t, Scalar_t, Store, AlignSize, StaticRows, StaticCols >::CInnerIter
 Scalar iterator to the inner dimension of the container, read-only. More...
 
class  C2DContainer< Index_t, Scalar_t, Store, AlignSize, StaticRows, StaticCols >::CInnerIterGather< IndexSIMD_t >
 SIMD iterator to the inner dimension of the container, read-only, generic non-contiguous access. More...
 

Namespaces

namespace  container_details
 

Macros

#define DUMMY_ALLOCATOR
 
#define REAL_ALLOCATOR(EXTRA)
 
#define CUSTOM_CTOR_AND_DTOR_BASE(INIT, MOVE)
 
#define CUSTOM_CTOR_AND_DTOR(X)   CUSTOM_CTOR_AND_DTOR_BASE(X = 0, X = other.X; other.X = 0)
 
#define UNIV_ACCESSORS
 
#define MATRIX_ACCESSORS(M, N)
 
#define VECTOR_ACCESSORS(M, ROWMAJOR)
 

Typedefs

template<class T >
using su2vector = C2DContainer< unsigned long, T, StorageType::ColumnMajor, 64, DynamicSize, 1 >
 Useful typedefs with default template parameters.
 
template<class T >
using su2matrix = C2DContainer< unsigned long, T, StorageType::RowMajor, 64, DynamicSize, DynamicSize >
 
template<class T >
using ColMajorMatrix = C2DContainer< unsigned long, T, StorageType::ColumnMajor, 64, DynamicSize, DynamicSize >
 
using su2activevector = su2vector< su2double >
 
using su2activematrix = su2matrix< su2double >
 
using su2passivevector = su2vector< passivedouble >
 
using su2passivematrix = su2matrix< passivedouble >
 

Enumerations

enum class  StorageType { StorageType::RowMajor = 0 , StorageType::ColumnMajor = 1 }
 Supported ways to flatten a matrix into an array. Contiguous rows or contiguous columns respectively. More...
 
enum  SizeType : size_t { DynamicSize = 0 }
 Special value "DynamicSize" to indicate a dynamic size. More...
 

Detailed Description

A templated vector/matrix object.

Author
P. Gomes
Version
8.5.0 "Harrier"

SU2 Project Website: https://su2code.github.io

The SU2 Project is maintained by the SU2 Foundation (http://su2foundation.org)

Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)

SU2 is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

SU2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with SU2. If not, see http://www.gnu.org/licenses/.

Macro Definition Documentation

◆ CUSTOM_CTOR_AND_DTOR

#define CUSTOM_CTOR_AND_DTOR (   X)    CUSTOM_CTOR_AND_DTOR_BASE(X = 0, X = other.X; other.X = 0)

Shorthand for when specialization has only one more member than m_data.

◆ CUSTOM_CTOR_AND_DTOR_BASE

#define CUSTOM_CTOR_AND_DTOR_BASE (   INIT,
  MOVE 
)
Value:
AccessorImpl() noexcept : m_data(nullptr) { INIT; } \
\
AccessorImpl(AccessorImpl&& other) noexcept { \
MOVE; \
m_data = other.m_data; \
other.m_data = nullptr; \
} \
\
AccessorImpl& operator=(AccessorImpl&& other) noexcept { \
m_destroy(); \
MOVE; \
m_data = other.m_data; \
other.m_data = nullptr; \
return *this; \
} \
\
~AccessorImpl() noexcept { m_destroy(); }

Dynamic types need to manage internal data as the derived class would not compile if it tried to set m_data to null on static specializations. Move construct/assign are enabled by transferring ownership of data pointer, the rvalue is left in the empty state. The default ctor needs to "INIT" some fields. The move ctor/assign need to "MOVE" those fields, i.e. copy and set "other" appropriately.

◆ DUMMY_ALLOCATOR

#define DUMMY_ALLOCATOR
Value:
void m_allocate(size_t sz, Index_t rows, Index_t cols) noexcept {} \
void m_destroy() noexcept {}

Static size specializations use this do-nothing allocation macro.

◆ MATRIX_ACCESSORS

#define MATRIX_ACCESSORS (   M,
  N 
)

Operator (,) gives pointwise access, operator [] returns a pointer to the first element of the row/column of a row/column-major matrix respectively.

◆ REAL_ALLOCATOR

#define REAL_ALLOCATOR (   EXTRA)
Value:
static_assert(MemoryAllocation::is_power_of_two(AlignSize), "AlignSize is not a power of two."); \
\
void m_allocate(size_t sz, Index_t rows, Index_t cols) noexcept { \
EXTRA; \
m_data = MemoryAllocation::aligned_alloc<Scalar_t>(AlignSize, sz); \
if (!std::is_trivial<Scalar_t>::value) \
for (size_t i = 0; i < size(); ++i) new (m_data + i) Scalar_t(); \
} \
\
void m_destroy() noexcept { \
if (!std::is_trivial<Scalar_t>::value) \
for (size_t i = 0; i < size(); ++i) m_data[i].~Scalar_t(); \
MemoryAllocation::aligned_free<Scalar_t>(m_data); \
}
constexpr bool is_power_of_two(size_t x)
Definition allocation_toolbox.hpp:49

Dynamic size specializations use this one, EXTRA is used to set some runtime internal value that depend on the number of rows/columns. What values need setting depends on the specialization as not all have members for e.g. number of rows and cols (static size optimization). Because aligned allocation is used, "placement new" is used after to default construct the elements of non-trivial type. Such types also need to be destructed explicitly before freeing the memory.

◆ UNIV_ACCESSORS

#define UNIV_ACCESSORS
Value:
bool empty() const noexcept { return size() == 0; } \
Scalar_t* data() noexcept { return m_data; } \
const Scalar_t* data() const noexcept { return m_data; } \
Scalar_t* begin() noexcept { return data(); } \
const Scalar_t* begin() const noexcept { return data(); } \
Scalar_t* end() noexcept { return data() + size(); } \
const Scalar_t* end() const noexcept { return data() + size(); }

Universal accessors return a raw pointer to the data.

◆ VECTOR_ACCESSORS

#define VECTOR_ACCESSORS (   M,
  ROWMAJOR 
)
Value:
UNIV_ACCESSORS \
Index_t rows() const noexcept { return ROWMAJOR ? 1 : M; } \
Index_t cols() const noexcept { return ROWMAJOR ? M : 1; } \
size_t size() const noexcept { return M; } \
\
Scalar_t& operator()(const Index_t i) noexcept { \
assert(i >= 0 && i < M); \
return m_data[i]; \
} \
\
const Scalar_t& operator()(const Index_t i) const noexcept { \
assert(i >= 0 && i < M); \
return m_data[i]; \
} \
\
Scalar_t& operator[](const Index_t i) noexcept { \
assert(i >= 0 && i < M); \
return m_data[i]; \
} \
\
const Scalar_t& operator[](const Index_t i) const noexcept { \
assert(i >= 0 && i < M); \
return m_data[i]; \
}
#define M(I, J)

Vectors provide both [] and () with the same behavior.