PLUTO  4.4-patch2
Macros
macros.h File Reference

PLUTO header file for function-like macros. More...

Go to the source code of this file.

Macros

#define BOX_LOOP(B, k, j, i)
 
#define FOR_EACH(nv, list)
 
#define INT_FLOOR(z)   ((int)((z) + 32768.) - 32768)
 
#define MAX(a, b)   ( (a) >= (b) ? (a) : (b) )
 
#define MIN(a, b)   ( (a) <= (b) ? (a) : (b) )
 
#define ABS_MIN(a, b)   (fabs(a) < fabs(b) ? (a):(b))
 
#define DSIGN(x)   ( (x) >= 0.0 ? (1.0) : (-1.0))
 
#define MINMOD_LIMITER(a, b)   ((a)*(b) > 0.0 ? (fabs(a) < fabs(b) ? (a):(b)):0.0)
 
#define QUIT_PLUTO(e_code)
 
#define DIM_EXPAND(a, b, c)   a b c
 
#define DIM_SELECT(a, b, c)   c
 
Spatial loop macros.

The following macros provide a compact way to perform 1D or multi-D loops in selected regions of the (local) computational domain. The *BEG_LOOP and *END_LOOP macros are used to loop in the leftmost or rightmost boundary ghost zones in the corresponding direction I, J or K. The *DOM_LOOP macros are used to loop inside the computational domain (boundaries excluded) while the *TOT_LOOP macros are used to loop across the entire domain (inside+boundary).

#define IBEG_LOOP(i)   for ((i) = IBEG; (i)--; )
 
#define JBEG_LOOP(j)   for ((j) = JBEG; (j)--; )
 
#define KBEG_LOOP(k)   for ((k) = KBEG; (k)--; )
 
#define IEND_LOOP(i)   for ((i) = IEND + 1; (i) < NX1_TOT; (i)++)
 
#define JEND_LOOP(j)   for ((j) = JEND + 1; (j) < NX2_TOT; (j)++)
 
#define KEND_LOOP(k)   for ((k) = KEND + 1; (k) < NX3_TOT; (k)++)
 
#define IDOM_LOOP(i)   for ((i) = IBEG; (i) <= IEND; (i)++)
 
#define JDOM_LOOP(j)   for ((j) = JBEG; (j) <= JEND; (j)++)
 
#define KDOM_LOOP(k)   for ((k) = KBEG; (k) <= KEND; (k)++)
 
#define ITOT_LOOP(i)   for ((i) = 0; (i) < NX1_TOT; (i)++)
 
#define JTOT_LOOP(j)   for ((j) = 0; (j) < NX2_TOT; (j)++)
 
#define KTOT_LOOP(k)   for ((k) = 0; (k) < NX3_TOT; (k)++)
 
#define DOM_LOOP(k, j, i)   KDOM_LOOP(k) JDOM_LOOP(j) IDOM_LOOP(i)
 
#define TOT_LOOP(k, j, i)   KTOT_LOOP(k) JTOT_LOOP(j) ITOT_LOOP(i)
 
#define X1_BEG_LOOP(k, j, i)   KTOT_LOOP(k) JTOT_LOOP(j) IBEG_LOOP(i)
 
#define X2_BEG_LOOP(k, j, i)   KTOT_LOOP(k) JBEG_LOOP(j) ITOT_LOOP(i)
 
#define X3_BEG_LOOP(k, j, i)   KBEG_LOOP(k) JTOT_LOOP(j) ITOT_LOOP(i)
 
#define X1_END_LOOP(k, j, i)   KTOT_LOOP(k) JTOT_LOOP(j) IEND_LOOP(i)
 
#define X2_END_LOOP(k, j, i)   KTOT_LOOP(k) JEND_LOOP(j) ITOT_LOOP(i)
 
#define X3_END_LOOP(k, j, i)   KEND_LOOP(k) JTOT_LOOP(j) ITOT_LOOP(i)
 
Forward and central finite differences macros.

The following set of macros provide a compact way to perform two-point, undivided finite difference operations in a specified direction. Differences can be either forward or central. For instance, FDIFF_X2(Q,k,j,i) will compute a forward difference of Q in the y direction, (Q[j+1]-Q[j]), while CDIFF_X3(Q,k,j,i) will compute a central different approximation of Q in the z direction: (Q[k+1] - Q[k-1])/2.

#define FDIFF_X1(Q, k, j, i)   (0.0)
 
#define CDIFF_X1(Q, k, j, i)   (0.0)
 
#define FDIFF_X2(Q, k, j, i)   (0.0)
 
#define CDIFF_X2(Q, k, j, i)   (0.0)
 
#define FDIFF_X3(Q, k, j, i)   (0.0)
 
#define CDIFF_X3(Q, k, j, i)   (0.0)
 
Spatial averages macros.

The following set of macros provide a compact way to perform multi-D averages from cell centered values to interfaces. For instance, AVERAGE_X(q,k,j,i) will simply take the arithmetic average betwen q(i) and q(i+1) at the i+1/2 interface. Likewise, AVERAGE_YZ(q,k,j,i) will produce an average at the j+1/2 and k+1/2 edge.

#define AVERAGE_X(q, k, j, i)   (q[k][j][i])
 
#define AVERAGE_Y(q, k, j, i)   (q[k][0][i])
 
#define AVERAGE_XY(q, k, j, i)   AVERAGE_X(q,k,0,i)
 
#define AVERAGE_Z(q, k, j, i)   (q[0][j][i])
 
#define AVERAGE_XZ(q, k, j, i)   AVERAGE_X(q,0,j,i)
 
#define AVERAGE_YZ(q, k, j, i)   AVERAGE_Y(q,0,j,i)
 
#define AVERAGE_XYZ(q, k, j, i)   AVERAGE_XY(q,0,j,i)
 

Detailed Description

Author
A. Mignone (migno.nosp@m.ne@t.nosp@m.o.inf.nosp@m.n.it)
Date
Sep 17, 2020

Macro Definition Documentation

◆ ABS_MIN

#define ABS_MIN (   a,
 
)    (fabs(a) < fabs(b) ? (a):(b))

Return the number with the smaller absolute value.

◆ BOX_LOOP

#define BOX_LOOP (   B,
  k,
  j,
 
)
Value:
for ((B)->dk = ((k=(B)->kbeg) <= (B)->kend ? 1:-1); k != (B)->kend+(B)->dk; k += (B)->dk)\
for ((B)->dj = ((j=(B)->jbeg) <= (B)->jend ? 1:-1); j != (B)->jend+(B)->dj; j += (B)->dj)\
for ((B)->di = ((i=(B)->ibeg) <= (B)->iend ? 1:-1); i != (B)->iend+(B)->di; i += (B)->di)

The BOX_LOOP() macro implements a loop over (i,j,k) in a rectangular portion of the domain with indices defined by the (pointer to) RBox structure B. The loop increments (di,dj,dk) are members of the structure which are here initialized to either 1 or -1 depending on whether the lower corner index lies below or above the upper index (e.g. B->ib <= B->ie or not).

◆ DIM_EXPAND

#define DIM_EXPAND (   a,
  b,
 
)    a b c

Allows to write dimension-ndependent expressions involving vectors by evaluating as many arguments as the number of DIMENSIONS. The result is that only the first argument will be compiled in 1D, the first two arguments in 2D and all of them in 3D. As an example:

DIM_EXPAND(v[VX1] = 1.0; ,
v[VX2] = 5.0; ,
v[VX3] = -4.0; )

becomes

v[VX1] = 1.0;

when DIMENSIONS is equal to 1 or

v[VX1] = 1.0;
v[VX2] = 5.0;

when DIMENSIONS is equal to 2 or

v[VX1] = 1.0;
v[VX2] = 5.0;
v[VX3] = -4.0;

when DIMENSIONS is equal to 3.

◆ DIM_SELECT

#define DIM_SELECT (   a,
  b,
 
)    c

Expand only the 1st, 2nd or 3rd argument based on the value of DIMENSIONS.

◆ DSIGN

#define DSIGN (   x)    ( (x) >= 0.0 ? (1.0) : (-1.0))

Return the sign of x.

◆ FOR_EACH

#define FOR_EACH (   nv,
  list 
)
Value:
for ((list)->i = 0, nv = (list)->indx[0]; \
(list)->i < (list)->nvar; \
nv = (list)->indx[++((list)->i)])

The FOR_EACH(p, intList) macro implements a loop over the elements of the array intList->indx (in a similar way to Python lists).

Example:

intList list;
list.nvar = 3;
list.indx[0] = 2;
list.indx[1] = 5;
list.indx[2] = 17;
FOR_EACH(nv, &list) printf ("value is = %d\n",nv);

◆ INT_FLOOR

#define INT_FLOOR (   z)    ((int)((z) + 32768.) - 32768)

Faster implementation than stdlib floor() function. It returns the largest integer value less than or equal to z.

◆ MAX

#define MAX (   a,
 
)    ( (a) >= (b) ? (a) : (b) )

Return the maximum between two numbers.

◆ MIN

#define MIN (   a,
 
)    ( (a) <= (b) ? (a) : (b) )

Return the minimum between two numbers.

◆ MINMOD_LIMITER

#define MINMOD_LIMITER (   a,
 
)    ((a)*(b) > 0.0 ? (fabs(a) < fabs(b) ? (a):(b)):0.0)

Quick limiting macros (more general ones are found in States/plm_coeffs.h)

◆ QUIT_PLUTO

#define QUIT_PLUTO (   e_code)
Value:
{printLog ("! Abort\n"); \
LogFileFlush(); \
MPI_Abort(MPI_COMM_WORLD, e_code); \
MPI_Finalize(); \
exit(e_code);}
void printLog(const char *fmt,...)
Definition: output_log.c:254

Exit macro. For Chombo it is defined elsewhere.