PLUTO  4.4-patch2
Functions
arrays.c File Reference

Memory allocation functions. More...

#include "pluto.h"

Functions

char * Array1D (int nx, size_t dsize)
 
void FreeArray1D (void *v)
 
char ** Array2D (int nx, int ny, size_t dsize)
 
void FreeArray2D (void **m)
 
char *** Array3D (int nx, int ny, int nz, size_t dsize)
 
void FreeArray3D (void ***m)
 
char **** Array4D (int nx, int ny, int nz, int nv, size_t dsize)
 
void FreeArray4D (void ****m)
 
char *** ArrayBox (long int nrl, long int nrh, long int ncl, long int nch, long int ndl, long int ndh, size_t dsize)
 
void FreeArrayBox (double ***t, long nrl, long ncl, long ndl)
 
double *** ArrayMap (int nx, int ny, int nz, double *uptr)
 
void FreeArrayMap (double ***t)
 
double *** ArrayBoxMap (int nrl, int nrh, int ncl, int nch, int ndl, int ndh, double *uptr)
 
void FreeArrayBoxMap (double ***t, int nrl, int nrh, int ncl, int nch, int ndl, int ndh)
 

Detailed Description

Provides essential functions for allocating and deallocating multi-dimensional arrays. The functions Array1D(), Array2D(), Array3D(), Array4D() can be used to allocate storage for 1-D, 2-D, 3-D and 4-D arrays of any data type with indices starting at 0. They are typically invoked from within a corresponding macros that handles type casting automatically, e.g.,

char *s;
double **q;
s = ARRAY_1D(20, char);
q = ARRAY_2D(30,40,double);

will allocate memory for a 1D char array with 20 elements and a 2D double arrays of 30x40 elements

The function ArrayBox() can be used to allocate memory for a double precision array with specified index range.

The functions ArrayMap() can be used to convert a one-dimensional array into a 3D array.

Author
A. Mignone (migno.nosp@m.ne@t.nosp@m.o.inf.nosp@m.n.it)
Date
June 24, 2019

Function Documentation

◆ Array1D()

char* Array1D ( int  nx,
size_t  dsize 
)

Allocate memory for a 1-D array of any basic data type starting at 0.

Parameters
[in]nxnumber of elements to be allocated
[in]dsizedata-type of the array to be allocated
Returns
A pointer of type (char *) to the allocated memory area.

◆ Array2D()

char** Array2D ( int  nx,
int  ny,
size_t  dsize 
)

Allocate memory for a 2-D array of any basic data type.

Parameters
[in]nxnumber of elements in the 2nd dimension
[in]nynumber of elements in the 1st dimension
[in]dsizedata-type of the array to be allocated
Returns
A pointer of type (char **) to the allocated memory area with index range [0...nx-1][0...ny-1]

◆ Array3D()

char*** Array3D ( int  nx,
int  ny,
int  nz,
size_t  dsize 
)

Allocate memory for a 3-D array of any basic data type.

Parameters
[in]nxnumber of elements in the 3rd dimension
[in]nynumber of elements in the 2nd dimension
[in]nznumber of elements in the 1st dimension
[in]dsizedata-type of the array to be allocated
Returns
A pointer of type (char ***) to the allocated memory area with index range [0...nx-1][0...ny-1][0...nz-1]

◆ Array4D()

char**** Array4D ( int  nx,
int  ny,
int  nz,
int  nv,
size_t  dsize 
)

Allocate memory for a 4-D array of any basic data type.

Parameters
[in]nxnumber of elements in the 4th dimension
[in]nynumber of elements in the 3rd dimension
[in]nznumber of elements in the 2nd dimension
[in]nvnumber of elements in the 1st dimension
[in]dsizedata-type of the array to be allocated
Returns
A pointer of type (char ****) to the allocated memory area with index range [0...nx-1][0...ny-1][0...nz-1][0...nv-1]

◆ ArrayBox()

char*** ArrayBox ( long int  nrl,
long int  nrh,
long int  ncl,
long int  nch,
long int  ndl,
long int  ndh,
size_t  dsize 
)

Allocate memory for a 3-D array in double precision with given subscript range [low...high] for each direction. Useful for staggered arrays which do not start at [0].

Parameters
[in]nrllower bound index for the 3rd dimension
[in]nrhupper bound index for the 3rd dimension
[in]ncllower bound index for the 2nd dimension
[in]nchupper bound index for the 2nd dimension
[in]ndllower bound index for the 1st dimension
[in]ndhupper bound index for the 1st dimension
Returns
A pointer of type (double ***) to the allocated memory area with index range [nrl...nhl][ncl...nch][ndl...ndh].

◆ ArrayBoxMap()

double*** ArrayBoxMap ( int  nrl,
int  nrh,
int  ncl,
int  nch,
int  ndl,
int  ndh,
double *  uptr 
)

Convert a one-dimensional array into a 3D array with given subscript range [low...high] for each direction.

◆ ArrayMap()

double*** ArrayMap ( int  nx,
int  ny,
int  nz,
double *  uptr 
)

Convert a one dimensional array with (nx*ny*nz) elements into a 3D array with index range [0..nx-1][0..ny-1][0..nz-1]. This function is similar, conceptually, to Array3D() except that the memory area is already allocated.

Parameters
[in]uptrpointer to 1D array
[in]nxnumber of elements in the 3rd dimension
[in]nynumber of elements in the 2nd dimensions
[in]nznumber of elements in the 1st dimensions
Returns
A pointer to the 3D array.

◆ FreeArray1D()

void FreeArray1D ( void *  v)

Free memory allocated by the pointer *v.

◆ FreeArray2D()

void FreeArray2D ( void **  m)

Free memory allocated by the double pointer **v.

◆ FreeArray3D()

void FreeArray3D ( void ***  m)

Free memory allocated by the pointer ***v.

◆ FreeArray4D()

void FreeArray4D ( void ****  m)

Free memory allocated by the pointer ****v.

◆ FreeArrayBox()

void FreeArrayBox ( double ***  t,
long  nrl,
long  ncl,
long  ndl 
)

Free memory allocated by the ArrayBox function.

Parameters
[in]tpointer to an allocated memory area
[in]nrlstarting index of the array for the 3rd dimension
[in]nclstarting index of the array for the 2nd dimension
[in]ndlstarting index of the array for the 1st dimension

◆ FreeArrayBoxMap()

void FreeArrayBoxMap ( double ***  t,
int  nrl,
int  nrh,
int  ncl,
int  nch,
int  ndl,
int  ndh 
)

Free memory allocated with the ArrayBoxMap () function

◆ FreeArrayMap()

void FreeArrayMap ( double ***  t)

Free memory allocate with ArrayMap()