PLUTO  4.2
 All Data Structures Files Functions Variables Enumerations Macros Pages
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, beg, 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 QUIT_PLUTO(e_code)   {MPI_Abort(MPI_COMM_WORLD, e_code);MPI_Finalize(); exit(e_code);}
 
#define EXPAND(a, b, c)   a b c
 
#define SELECT(a, b, c)   c
 
#define D_EXPAND(a, b, c)   a b c
 
#define D_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)
 
#define TRANSVERSE_LOOP(indx, ip, i, j, k)
 

Detailed Description

Author
A. Mignone (migno.nosp@m.ne@p.nosp@m.h.uni.nosp@m.to.i.nosp@m.t)
Date
July 31, 2014

Macro Definition Documentation

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

Return the number with the smaller absolute value.

#define BOX_LOOP (   B,
  k,
  j,
 
)
Value:
for ((B)->dk = ((k=(B)->kb) <= (B)->ke ? 1:-1); k != (B)->ke+(B)->dk; k += (B)->dk)\
for ((B)->dj = ((j=(B)->jb) <= (B)->je ? 1:-1); j != (B)->je+(B)->dj; j += (B)->dj)\
for ((B)->di = ((i=(B)->ib) <= (B)->ie ? 1:-1); i != (B)->ie+(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).

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

Similar to the EXPAND() macro but the expansion depends on DIMENSIONS.

#define D_SELECT (   a,
  b,
 
)    c

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

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

Return the sign of x.

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

Allows to write component-independent expressions involving vectors by evaluating as many arguments as the value of COMPONENTS. 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:

1 EXPAND( v[VX1] = 1.0; ,
2  v[VX2] = 5.0; ,
3  v[VX3] = -4.0; )

becomes

1 v[VX1] = 1.0;

when COMPONENTS is equal to 1 or

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

when COMPONENTS is equal to 2 or

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

when COMPONENTS is equal to 3.

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

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

Example:

1 intList list;
2 list.nvar = 3;
3 list.indx[0] = 2;
4 list.indx[1] = 5;
5 list.indx[2] = 17;
6 FOR_EACH(nv, 0, list) printf ("value is = %d\n",nv);
#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.

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

Return the maximum between two numbers.

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

Return the minimum between two numbers.

#define QUIT_PLUTO (   e_code)    {MPI_Abort(MPI_COMM_WORLD, e_code);MPI_Finalize(); exit(e_code);}

Exit macro. For Chombo it is defined elsewhere.

#define SELECT (   a,
  b,
 
)    c

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