Reference documentation for deal.II version GIT 7b2de2f2f9 2023-09-24 11:00:02+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\}}\)
ndarray.h File Reference
#include <deal.II/base/config.h>
#include <deal.II/base/exceptions.h>
#include <array>

Go to the source code of this file.


template<typename T , std::size_t... Ns>
using ndarray = typename internal::ndarray::HelperArray< T, Ns... >::type

Typedef Documentation

◆ ndarray

template<typename T , std::size_t... Ns>
using ndarray = typename internal::ndarray::HelperArray<T, Ns...>::type

A (variadic template) type alias for conveniently defining multidimensional std::arrays.

The problem we try to address with the type alias is the following. Suppose you want to create a multdimensional array of doubles of, for example, rank 3, with sizes 2, 3, 4 for the first, middle, and last index. Then using C-style arrays you could simply write

double my_array[2][3][4] = { ... };

There are a number of good reasons why using C-style arrays is generally discouraged (ranging from incompatibilities with STL functions requiring awkward wrappers, surprises when comparing for equality, etc.). If you want to do the same, however, using the more modern (and encouraged) std::array class, then you would have to declare

std::array<std::array<std::array<double, 4>, 3>, 2> = { ... };

The repetitions of std::array look awkward and, worse, the index ranges have reversed: the leftmost index has range [0,2), the middle index has range [0,3) and the rightmost index has range [0,4). We address this issue by providing a class ndarray that allows to you declare the above stacked std::array type by simply writing:

::ndarray<double, 2, 3, 4> my_array = { ... };
typename internal::ndarray::HelperArray< T, Ns... >::type ndarray
Definition: ndarray.h:108
ndarray is merely syntactic sugar in the form of a type alias (using declaration). It is not a deal.II specific class, but merely a helper to cleanly define multidimensional arrays realized by "stacked" std::array classes.

Definition at line 108 of file ndarray.h.