Skip to content

Storage1DTensor

Storage1DTensor<T, Rank> is the templated dynamic storage container to store one-dimensional, in terms of space dimensions, Tensor data (in each point) in a contiguous memory storage. It provides boundary "ghost" cells to facilitate boundary conditions and provides local linear interpolation between the grid points. The container can store any type of data T in a tensor-like storage of the given Rank. The tensor dimensions can be specified during the run time.

The data inside of the Storage1DTensor container is manipulated using a number of dedicated methods:

Constructors

cpp
Storage1DTensor();

Default constructor. Creates empty container.

cpp
Storage1DTensor(const long int nx,
                const std::array<size_t,Rank> tensor_dims,
                const long int bc);

< Constructor. Creates a container of the specified size. nx is the 1D domain length, tensor_dims are the dimensions of the stored tensor and bc is the number of boundary cells.

cpp
Storage1DTensor(const Storage1DTensor<T,Rank>& rhs);

Copy constructor. Creates and initializes the container with the copy of the rhs.

cpp
void Allocate(const long int nx,
              const std::array<size_t,Rank> tensor_dims,
              const long int bc);

Allocates previously created empty storage container. nx is the 1D domain length, tensor_dims are the dimensions of the stored tensor and bc is the number of boundary cells.

cpp
void Allocate(const Storage1DTensor<T,Rank>& rhs);

Allocates current container to the dimensions of the rhs.

cpp
void AllocateCopy(const Storage1DTensor<T,Rank>& rhs);

Allocates current container and initializes it with the data from the rhs.

cpp
void Reallocate(const long int nx);

Reallocates non-empty container to new size nx while keeping the number of boundary cells.

cpp
Storage1DTensor<T,Rank>& operator=(const Storage1DTensor<T,Rank>& rhs);

Assignment operator. Assigns the copy of the rhs to the current container.

Access operators

cpp
Tensor<T, Rank>& operator()(const long int x);

Random access operator. Returns the reference to the tensor pointed to by the index x.

cpp
Tensor<T, Rank> const& operator()(const long int x) const;

Random access operator. Returns const reference to the tensor pointed to by the index x.

cpp
T& operator()(const long int x, const std::array<size_t, Rank> Position);

Random access operator. Returns the reference to the storage element pointed to by the index x and Position inside of tensor.

cpp
const T& operator()(const long int x, const std::array<size_t, Rank> Position) const;

Random access operator. Returns const reference to the storage element pointed to by the index x and Position inside of tensor.

cpp
Tensor<T, Rank> at(const double x) const;

Arbitrary position access operator. Returns interpolated tensor at arbitrary location inside of the container dimensions.

cpp
Tensor<T, Rank>& operator[](const size_t idx);

Random access operator to the raw storage. Returns the reference to the element pointed to by the index x.

cpp
Tensor<T, Rank>const& operator[](const size_t idx) const;

Random access operator to the raw storage. Returns const reference to the element pointed to by the index x.

cpp
auto* data(void);

Returns pointer to the raw data storage.

Container properties

cpp
bool IsNotAllocated() const;

Returns true if the storage is not allocated.

cpp
bool IsAllocated() const;

Returns true if the storage is allocated.

cpp
bool IsSize(const long int Nx);

Returns true if the current storage is of the specified size Nx.

cpp
size_t sizeX() const;

Returns the size of the current container without boundary cells.

cpp
long int Bcells() const;

Returns the number of boundary cells.

cpp
constexpr size_t tensor_rank(void) const;

Returns the rank of the stored tensors.

cpp
size_t tensor_size(size_t n) const;

Returns the size of the tensor dimension n.

cpp
size_t tensor_size() const;

Returns the size of the storage occupied by the single tensor

cpp
size_t size() const;

Returns total size of the container including boundary cells.

cpp
bool InLimits(const long int idx);

Returns true if the specified idx is inside of the container dimensions.

Data manipulation methods

cpp
void Remesh(const long int nx);

Remeshes the storage to new dimensions while keeping the data. Uses linear interpolation.

cpp
void SetNewBcells(const int new_b_cells);

Sets new number of boundary cells. Scrambles stored data.

cpp
void set_to_value(Tensor<T, Rank>& val);

Sets all entries of the container to the specified value val.

cpp
void Clear(void);

Clears the container while keeping its storage size.

MPI communication methods

cpp
std::vector<double> pack();

Packs (writes) the content of the current container into the MPI communication buffer.

cpp
void unpack(std::vector<double>& buffer);

Unpacks (reads) the content of the current container from the MPI communication buffer.

Released under the GNU GPLv3 License.