HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
arrayfunctions.h File Reference

Contains macros and function definitions for common array operations. More...

#include <stdio.h>
#include <stdlib.h>
#include <basic.h>
#include <math.h>

Go to the source code of this file.

Macros

#define _ArrayIndexnD_(N, index, imax, i, ghost)
 
#define _ArrayIndex1D_(N, imax, i, ghost, index)
 
#define _ArrayIndex1D2_(N, imax, i, ghost, index)
 
#define _ArrayIndex1D3_(N, imax, i, ghost, index)
 
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
 
#define _ArrayIndex1DWO2_(N, imax, i, offset, ghost, index)
 
#define _ArrayIndex1DWO3_(N, imax, i, offset, ghost, index)
 
#define _ArrayIncrementIndex_(N, imax, i, done)
 
#define _ArrayIncrementIndexWithLBound_(N, imax, imin, i, done)
 
#define _ArraySetValue_(x, size, value)
 
#define _ArraySum1D_(x, a, size)
 
#define _ArrayScale1D_(x, a, size)
 
#define _ArraySubtract1D_(x, a, b, size)
 
#define _ArrayAdd1D_(x, a, b, size)
 
#define _ArrayMultiply1D_(x, a, b, size)
 
#define _ArrayMultiply3Add1D_(x, a, b, c, d, e, f, size)
 
#define _ArrayConvexCombination1D_(z, a, x, y, size)
 
#define _ArrayAYPX_(x, a, y, size)
 
#define _ArrayAXPY_(x, a, y, size)
 
#define _ArrayAXBY_(z, a, x, b, y, size)
 
#define _ArrayAXBYCZ_(w, a, x, b, y, c, z, size)
 
#define _ArrayScaledAXPY_(x, a, e, y, size)
 
#define _ArrayCopy1D_(x, y, size)
 
#define _ArrayCopy1D2_(x, y, size)
 
#define _ArrayCopy1D3_(x, y, size)
 
#define _ArrayScaleCopy1D_(x, a, y, size)
 
#define _ArrayAddCopy1D_(x, a, y, size)
 
#define _ArrayProduct1D_(x, size, p)
 
#define _ArrayBlockMultiply_(x, a, n, bs)
 
#define INLINE   inline
 

Functions

INLINE int ArrayCopynD (int, const double *, double *, int *, int, int, int *, int)
 
INLINE double ArrayMaxnD (int, int, int *, int, int *, double *)
 
INLINE double ArraySumSquarenD (int, int, int *, int, int *, double *)
 
INLINE double ArraySumAbsnD (int, int, int *, int, int *, double *)
 
INLINE void ArrayCheckEqual (const char *, const double *, const double *, int, int)
 
INLINE void ArrayCheckEqual2 (const char *, const double *, const double *, int)
 
INLINE int ArrayCopynDComponent (int ndims, const double *x, double *y, int *dim, int g1, int g2, int *index, int nvars_from, int nvars_to, int var_from, int var_to)
 

Detailed Description

Contains macros and function definitions for common array operations.

Author
Debojyoti Ghosh

Definition in file arrayfunctions.h.

Macro Definition Documentation

◆ _ArrayIndexnD_

#define _ArrayIndexnD_ (   N,
  index,
  imax,
  i,
  ghost 
)
Value:
{ \
int arraycounter, term=1, index_copy=index; \
for (arraycounter=0; arraycounter<N; arraycounter++) term *= (imax[arraycounter]+2*(ghost));\
for (arraycounter=N-1; arraycounter>=0; arraycounter--) {\
term /= (imax[arraycounter]+2*(ghost)); \
i[arraycounter] = index_copy/term; \
index_copy -= i[arraycounter]*term; \
} \
for (arraycounter=0; arraycounter<N; arraycounter++) i[arraycounter] -= (ghost);\
}

Returns the N -dimensional index i[N] in an N -dimensional array of size imax[N] with ghost number of ghost points, given the 1-dimensional index in the corresponding 1-dimensional array stored in memory.

See also
_ArrayIndex1D_

Definition at line 21 of file arrayfunctions.h.

◆ _ArrayIndex1D_

#define _ArrayIndex1D_ (   N,
  imax,
  i,
  ghost,
  index 
)
Value:
{ \
index = i[N-1]+(ghost); \
int arraycounter; \
for (arraycounter = (N)-2; arraycounter > -1; arraycounter--) { \
index = ((index*(imax[arraycounter]+2*(ghost))) + (i[arraycounter]+(ghost))); \
} \
}

Returns 1-dimensional index in the corresponding 1-dimensional array stored in memory, given the N -dimensional index i[N] in an N -dimensional array of size imax[N] with ghost number of ghost points.

See also
_ArrayIndexnD_, _ArrayIndex1D2_, _ArrayIndex1D3_

Definition at line 40 of file arrayfunctions.h.

◆ _ArrayIndex1D2_

#define _ArrayIndex1D2_ (   N,
  imax,
  i,
  ghost,
  index 
)
Value:
{ \
index = i[1]+(ghost); \
index = ((index*(imax[0]+2*(ghost))) + (i[0]+(ghost))); \
}

Returns 1-dimensional index in the corresponding 1-dimensional array stored in memory, given the 2-dimensional index i[2] in an 2-dimensional array of size imax[2] with ghost number of ghost points. N is not used, but retained for uniformity.

See also
_ArrayIndex1D_, _ArrayIndex1D3_

Definition at line 56 of file arrayfunctions.h.

◆ _ArrayIndex1D3_

#define _ArrayIndex1D3_ (   N,
  imax,
  i,
  ghost,
  index 
)
Value:
{ \
index = i[2]+(ghost); \
index = ((index*(imax[1]+2*(ghost))) + (i[1]+(ghost))); \
index = ((index*(imax[0]+2*(ghost))) + (i[0]+(ghost))); \
}

Returns 1-dimensional index in the corresponding 1-dimensional array stored in memory, given the 3-dimensional index i[3] in an 3-dimensional array of size imax[3] with ghost number of ghost points. N is not used, but retained for uniformity.

See also
_ArrayIndex1D_, _ArrayIndex1D2_

Definition at line 69 of file arrayfunctions.h.

◆ _ArrayIndex1DWO_

#define _ArrayIndex1DWO_ (   N,
  imax,
  i,
  offset,
  ghost,
  index 
)
Value:
{ \
index = i[N-1]+(ghost)+ offset[N-1];\
int arraycounter; \
for (arraycounter = (N)-2; arraycounter > -1; arraycounter--) { \
index = ((index*(imax[arraycounter]+2*(ghost))) + (i[arraycounter]+(ghost)+offset[arraycounter]));\
} \
}

Returns 1-dimensional index in the corresponding 1-dimensional array stored in memory, given the N -dimensional index i[N] + an offset[N] in an N -dimensional array of size imax[N] with ghost number of ghost points.

See also
_ArrayIndexnD_, _ArrayIndex1D_, _ArrayIndex1DWO2_, _ArrayIndex1DWO3_

Definition at line 83 of file arrayfunctions.h.

◆ _ArrayIndex1DWO2_

#define _ArrayIndex1DWO2_ (   N,
  imax,
  i,
  offset,
  ghost,
  index 
)
Value:
{ \
index = i[1]+(ghost)+ offset[1];\
index = ((index*(imax[0]+2*(ghost))) + (i[0]+(ghost)+offset[0]));\
}

Returns 1-dimensional index in the corresponding 1-dimensional array stored in memory, given the 2-dimensional index i[2] + an offset[2] in an 2-dimensional array of size imax[2] with ghost number of ghost points. N is not used, but retained for uniformity.

See also
_ArrayIndex1DWO_, _ArrayIndex1DWO3_

Definition at line 100 of file arrayfunctions.h.

◆ _ArrayIndex1DWO3_

#define _ArrayIndex1DWO3_ (   N,
  imax,
  i,
  offset,
  ghost,
  index 
)
Value:
{ \
index = i[2]+(ghost)+ offset[2];\
index = ((index*(imax[1]+2*(ghost))) + (i[1]+(ghost)+offset[1]));\
index = ((index*(imax[0]+2*(ghost))) + (i[0]+(ghost)+offset[0]));\
}

Returns 1-dimensional index in the corresponding 1-dimensional array stored in memory, given the 3-dimensional index i[3] + an offset[3] in an 3-dimensional array of size imax[3] with ghost number of ghost points. N is not used, but retained for uniformity.

See also
_ArrayIndex1DWO_, _ArrayIndex1DWO2_

Definition at line 114 of file arrayfunctions.h.

◆ _ArrayIncrementIndex_

#define _ArrayIncrementIndex_ (   N,
  imax,
  i,
  done 
)
Value:
{ \
int arraycounter = 0; \
while (arraycounter < (N)) { \
if (i[arraycounter] == imax[arraycounter]-1) { \
i[arraycounter] = 0; \
arraycounter++; \
} else { \
i[arraycounter]++; \
break; \
} \
} \
if (arraycounter == (N)) done = 1; \
else done = 0; \
}

Increments an N -dimensional index i[N] by one. If it reaches the provided bounds imax[N], i.e., if i[c] = imax[c]-1 for all c = 0,...,N-1), then done = 1; else done = 0.

Definition at line 126 of file arrayfunctions.h.

◆ _ArrayIncrementIndexWithLBound_

#define _ArrayIncrementIndexWithLBound_ (   N,
  imax,
  imin,
  i,
  done 
)
Value:
{ \
int arraycounter = 0; \
while (arraycounter < (N)) { \
if (i[arraycounter] == imax[arraycounter]-1) { \
i[arraycounter] = imin[arraycounter]; \
arraycounter++; \
} else { \
i[arraycounter]++; \
break; \
} \
} \
if (arraycounter == (N)) done = 1; \
else done = 0; \
}

Increments an N -dimensional index i[N] by one. If it reaches the provided bounds imax[N], i.e., if i[c] = imax[c]-1 for all c = 0,...,N-1), then done = 1; else done = 0. This is the same as ArrayIncrementIndex but with a specified lower bound imin instead of 0.

Definition at line 149 of file arrayfunctions.h.

◆ _ArraySetValue_

#define _ArraySetValue_ (   x,
  size,
  value 
)
Value:
{ \
int arraycounter; \
for (arraycounter = 0; arraycounter < (size); arraycounter++) x[arraycounter] = (value); \
}

Set all elements of a 1-dimensional array x (any datatype) of length size to a scalar value

Definition at line 169 of file arrayfunctions.h.

◆ _ArraySum1D_

#define _ArraySum1D_ (   x,
  a,
  size 
)
Value:
{ \
a = 0; \
int arraycounter; \
for (arraycounter=0; arraycounter<size; arraycounter++) a += x[arraycounter]; \
}

Compute the sum of all elements of a 1-dimensional array x of length size.

Definition at line 179 of file arrayfunctions.h.

◆ _ArrayScale1D_

#define _ArrayScale1D_ (   x,
  a,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter=0; arraycounter<size; arraycounter++) x[arraycounter] *= a; \
}

Multiply all elements of a 1-dimensional array x of length size by a scalar value

Definition at line 190 of file arrayfunctions.h.

◆ _ArraySubtract1D_

#define _ArraySubtract1D_ (   x,
  a,
  b,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter=0; arraycounter<size; arraycounter++) x[arraycounter] = a[arraycounter] - b[arraycounter]; \
}

Element-wise subtraction x = a - b, where x, a, and b are 1-dimensional arrays of length size

See also
_ArrayAdd1D_, _ArrayMultiply1D_

Definition at line 201 of file arrayfunctions.h.

◆ _ArrayAdd1D_

#define _ArrayAdd1D_ (   x,
  a,
  b,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter=0; arraycounter<size; arraycounter++) x[arraycounter] = a[arraycounter] + b[arraycounter]; \
}

Element-wise addition x = a + b, where x, a, and b are 1-dimensional arrays of length size

See also
_ArraySubtract1D_, _ArrayMultiply1D_

Definition at line 212 of file arrayfunctions.h.

◆ _ArrayMultiply1D_

#define _ArrayMultiply1D_ (   x,
  a,
  b,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter=0; arraycounter<size; arraycounter++) x[arraycounter] = a[arraycounter] * b[arraycounter]; \
}

Element-wise multiplication x = a . b, where x, a, and b are 1-dimensional arrays of length size (a.k.a. dot product).

See also
_ArraySubtract1D_, _ArrayAdd1D_

Definition at line 223 of file arrayfunctions.h.

◆ _ArrayMultiply3Add1D_

#define _ArrayMultiply3Add1D_ (   x,
  a,
  b,
  c,
  d,
  e,
  f,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter=0; arraycounter<size; arraycounter++) \
x[arraycounter] = a[arraycounter]*b[arraycounter]+c[arraycounter]*d[arraycounter]+e[arraycounter]*f[arraycounter]; \
}

Element-wise x =a . b + c . d + e . f, where x, a, b, c, d, e, and f, are 1-dimensional arrays of length size.

See also
_ArrayMultiply1D_

Definition at line 234 of file arrayfunctions.h.

◆ _ArrayConvexCombination1D_

#define _ArrayConvexCombination1D_ (   z,
  a,
  x,
  y,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter=0; arraycounter<size; arraycounter++) \
z[arraycounter] = a[arraycounter]*x[arraycounter]+(1.0-a[arraycounter])*y[arraycounter]; \
}

Element-wise convex combination z = a . x + (1-a) . y, where a, x, y, z are 1-dimensional arrays of length size.

Definition at line 245 of file arrayfunctions.h.

◆ _ArrayAYPX_

#define _ArrayAYPX_ (   x,
  a,
  y,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter=0; arraycounter<size; arraycounter++) \
y[arraycounter] = a*y[arraycounter] + x[arraycounter];\
}

Element-wise AYPX y = a y + x, where a is a scalar, and x, y, z are 1-dimensional arrays of length size.

See also
_ArrayAXPY_, _ArrayAXBY_, _ArrayAXBYCZ_, _ArrayScaledAXPY_

Definition at line 258 of file arrayfunctions.h.

◆ _ArrayAXPY_

#define _ArrayAXPY_ (   x,
  a,
  y,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter=0; arraycounter<size; arraycounter++) y[arraycounter] += a*x[arraycounter]; \
}

Element-wise AXPY y = a x + y, where a is a scalar, and x, y, z are 1-dimensional arrays of length size.

See also
_ArrayAYPX_, _ArrayAXBY_, _ArrayAXBYCZ_, _ArrayScaledAXPY_

Definition at line 271 of file arrayfunctions.h.

◆ _ArrayAXBY_

#define _ArrayAXBY_ (   z,
  a,
  x,
  b,
  y,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter=0; arraycounter<size; arraycounter++) z[arraycounter] = a*x[arraycounter]+b*y[arraycounter]; \
}

Element-wise AXPY z = a x + b y, where a , b are scalars, and x, y, z are 1-dimensional arrays of length size.

See also
_ArrayAYPX_, _ArrayAXPY_, _ArrayAXBYCZ_, _ArrayScaledAXPY_

Definition at line 283 of file arrayfunctions.h.

◆ _ArrayAXBYCZ_

#define _ArrayAXBYCZ_ (   w,
  a,
  x,
  b,
  y,
  c,
  z,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter=0; arraycounter<size; arraycounter++) w[arraycounter] = a*x[arraycounter]+b*y[arraycounter]+c*z[arraycounter]; \
}

Element-wise AXPY w = a x + b y + c z, where a, b, c are scalars, and x, y, z, w are 1-dimensional arrays of length size.

See also
_ArrayAYPX_, _ArrayAXPY_, _ArrayScaledAXPY_

Definition at line 295 of file arrayfunctions.h.

◆ _ArrayScaledAXPY_

#define _ArrayScaledAXPY_ (   x,
  a,
  e,
  y,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter=0; arraycounter<size; arraycounter++) \
y[arraycounter] = e*(y[arraycounter]+a*x[arraycounter]); \
}

Element-wise Scaled AXPY y = e * (y + a * x), where a, e are scalars, and x, y are 1-dimensional arrays of length size.

See also
_ArrayAYPX_, _ArrayAXPY_, _ArrayAXBYCZ_

Definition at line 307 of file arrayfunctions.h.

◆ _ArrayCopy1D_

#define _ArrayCopy1D_ (   x,
  y,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter = 0; arraycounter < size; arraycounter++) y[arraycounter] = x[arraycounter]; \
}

Element-wise copy y = x, where x, y are 1-dimensional arrays of length size.

See also
_ArrayCopy1D2_, _ArrayCopy1D3_, _ArrayScaleCopy1D_, _ArrayAddCopy1D_

Definition at line 319 of file arrayfunctions.h.

◆ _ArrayCopy1D2_

#define _ArrayCopy1D2_ (   x,
  y,
  size 
)
Value:
{ \
y[0] = x[0]; \
y[1] = x[1]; \
}

Element-wise copy y = x, where x, y are 1-dimensional arrays of length 2. size is not used but retained for uniformity.

See also
_ArrayCopy1D_, _ArrayCopy1D3_

Definition at line 331 of file arrayfunctions.h.

◆ _ArrayCopy1D3_

#define _ArrayCopy1D3_ (   x,
  y,
  size 
)
Value:
{ \
y[0] = x[0]; \
y[1] = x[1]; \
y[2] = x[2]; \
}

Element-wise copy y = x, where x, y are 1-dimensional arrays of length 3. size is not used but retained for uniformity.

See also
_ArrayCopy1D_, _ArrayCopy1D2_

Definition at line 343 of file arrayfunctions.h.

◆ _ArrayScaleCopy1D_

#define _ArrayScaleCopy1D_ (   x,
  a,
  y,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter = 0; arraycounter < size; arraycounter++) y[arraycounter] = a*x[arraycounter]; \
}

Element-wise scale and copy y = a * x, where is a scalar, and x, y are one-dimensional arrays of length size.

See also
_ArrayCopy1D_, _ArrayAddCopy1D_

Definition at line 356 of file arrayfunctions.h.

◆ _ArrayAddCopy1D_

#define _ArrayAddCopy1D_ (   x,
  a,
  y,
  size 
)
Value:
{ \
int arraycounter; \
for (arraycounter = 0; arraycounter < size; arraycounter++) y[arraycounter] = a+x[arraycounter]; \
}

Element-wise add and copy y = a + x, where x,y are one-dimensional arrays of length size, and a is a scalar.

See also
_ArrayCopy1D_, _ArrayScaleCopy1D_

Definition at line 368 of file arrayfunctions.h.

◆ _ArrayProduct1D_

#define _ArrayProduct1D_ (   x,
  size,
 
)
Value:
{ \
int arraycounter = 0; p = 1; \
for (arraycounter=0; arraycounter<size; arraycounter++) p *= x[arraycounter]; \
}

p is the product of all the elements of the one-dimensional array x of length size.

Definition at line 377 of file arrayfunctions.h.

◆ _ArrayBlockMultiply_

#define _ArrayBlockMultiply_ (   x,
  a,
  n,
  bs 
)
Value:
{ \
int arraycounter1,arraycounter2; \
for (arraycounter1=0; arraycounter1<n; arraycounter1++) { \
for (arraycounter2=0; arraycounter2<bs; arraycounter2++) { \
x[bs*arraycounter1+arraycounter2] *= a[arraycounter1]; \
} \
}\
}

Given two arrays: x of size n*bs, and a of size n, this macro implements: x[i][j] *= a[i] where i = 1,...,n, j = 1,...,bs, and x is stored as a 1D array in row-major format, i.e., x[i][j] = x[i*bs+j].

Definition at line 388 of file arrayfunctions.h.

◆ INLINE

#define INLINE   inline

Definition at line 399 of file arrayfunctions.h.

Function Documentation

◆ ArrayCopynD()

INLINE int ArrayCopynD ( int  ndims,
const double *  x,
double *  y,
int *  dim,
int  g1,
int  g2,
int *  index,
int  nvars 
)

Copy one n-D array to another n-D array (both of which are stored in memory as 1D arrays)

Parameters
ndimsnumber of dimensions
xcopy-from array
ycopy-to array
diminteger array of size in each dimension
g1number of ghost points in copy-from array x
g2number of ghost points in copy-to array y
indexpre-allocated (by the calling function) integer array of size ndims
nvarsnumber of elements at one array location, can be > 1 for systems of equations)

Definition at line 410 of file arrayfunctions.h.

420 {
421  if (!y) {
422  fprintf(stderr,"Error in ArrayCopynD(): array \"y\" not allocated.\n");
423  return(1);
424  }
425  if (!x) {
426  fprintf(stderr,"Error in ArrayCopynD(): array \"x\" not allocated.\n");
427  return(1);
428  }
429  int done = 0;
430  _ArraySetValue_(index,ndims,0);
431  while (!done) {
432  int p1, p2;
433  _ArrayIndex1D_(ndims,dim,index,g1,p1);
434  _ArrayIndex1D_(ndims,dim,index,g2,p2);
435  _ArrayCopy1D_((x+p1*nvars),(y+p2*nvars),nvars);
436  _ArrayIncrementIndex_(ndims,dim,index,done);
437  }
438  return(0);
439 }
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _ArrayCopy1D_(x, y, size)

◆ ArrayMaxnD()

INLINE double ArrayMaxnD ( int  nvars,
int  ndims,
int *  dim,
int  ghosts,
int *  index,
double *  x 
)

Returns the maximum magnitude element in an n-D array (useful for L_inf norm)

Parameters
nvarsnumber of elements at one array location, can be > 1 for systems of equations
ndimsnumber of dimensions
diminteger array containing the size of x in each dimension
ghostsnumber of ghost points in the array x
indexpre-allocated (by the calling function) integer array of size ndims
xthe array

Definition at line 486 of file arrayfunctions.h.

494 {
495  double sum = 0;
496  int done = 0; _ArraySetValue_(index,ndims,0);
497  while (!done) {
498  int p; _ArrayIndex1D_(ndims,dim,index,ghosts,p);
499  int v;
500  for (v=0; v<nvars; v++) {
501  double term = ( x[p*nvars+v]>0 ? x[p*nvars+v] : -x[p*nvars+v] );
502  if (term > sum) sum = term;
503  }
504  _ArrayIncrementIndex_(ndims,dim,index,done);
505  }
506  return(sum);
507 }
long sum(const std::vector< int > &a_iv)
Definition: std_vec_ops.h:18
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)

◆ ArraySumSquarenD()

INLINE double ArraySumSquarenD ( int  nvars,
int  ndims,
int *  dim,
int  ghosts,
int *  index,
double *  x 
)

Returns the sum-of-squares of the elements in an n-D array (useful for L_2 norm)

Parameters
nvarsnumber of elements at one array location, can be > 1 for systems of equations
ndimsnumber of dimensions
diminteger array of size in each dimension
ghostsnumber of ghost points in the array x
indexpre-allocated (by the calling function) integer array of size ndims
xthe array

Definition at line 529 of file arrayfunctions.h.

536 {
537  double sum = 0;
538  int done = 0; _ArraySetValue_(index,ndims,0);
539  while (!done) {
540  int p; _ArrayIndex1D_(ndims,dim,index,ghosts,p);
541  int v; for (v=0; v<nvars; v++) sum += (x[p*nvars+v]*x[p*nvars+v]);
542  _ArrayIncrementIndex_(ndims,dim,index,done);
543  }
544  return(sum);
545 }
long sum(const std::vector< int > &a_iv)
Definition: std_vec_ops.h:18
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)

◆ ArraySumAbsnD()

INLINE double ArraySumAbsnD ( int  nvars,
int  ndims,
int *  dim,
int  ghosts,
int *  index,
double *  x 
)

Returns the sum-of-magnitudes of the elements in an n-D array (useful for L_1 norm)

Parameters
nvarsnumber of elements at one array location, can be > 1 for systems of equations
ndimsnumber of dimensions
diminteger array of size in each dimension
ghostsnumber of ghost points in the array x
indexpre-allocated (by the calling function) integer array of size ndims
xthe array

Definition at line 510 of file arrayfunctions.h.

517 {
518  double sum = 0;
519  int done = 0; _ArraySetValue_(index,ndims,0);
520  while (!done) {
521  int p; _ArrayIndex1D_(ndims,dim,index,ghosts,p);
522  int v; for (v=0; v<nvars; v++) sum += ( x[p*nvars+v]>0 ? x[p*nvars+v] : -x[p*nvars+v] );
523  _ArrayIncrementIndex_(ndims,dim,index,done);
524  }
525  return(sum);
526 }
long sum(const std::vector< int > &a_iv)
Definition: std_vec_ops.h:18
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)

◆ ArrayCheckEqual()

INLINE void ArrayCheckEqual ( const char *  msg,
const double *  var_adj,
const double *  var_sep,
int  npoints,
int  nvars 
)

Definition at line 547 of file arrayfunctions.h.

548 {
549  double max_err = 0.0;
550  for (int j=0; j<npoints; j++) {
551  for (int v=0; v<nvars; v++) {
552  if (var_sep[j+v*npoints] != var_adj[j*nvars+v]) {
553  double diff = fabs(var_sep[j+v*npoints]-var_adj[j*nvars+v]);
554  max_err = (max_err < diff) ? diff : max_err;
555  }
556  }
557  }
558 
559  if (max_err > 1e-10) {
560  printf("ArrayCheckEqual: %-30s max_err = %e\n", msg, max_err);
561  exit(0);
562  }
563  return;
564 }

◆ ArrayCheckEqual2()

INLINE void ArrayCheckEqual2 ( const char *  msg,
const double *  var_adj,
const double *  var_sep,
int  npoints 
)

Definition at line 566 of file arrayfunctions.h.

567 {
568  double max_err = 0.0;
569  for (int j=0; j<npoints; j++) {
570  if (var_sep[j] != var_adj[j]) {
571  double diff = fabs(var_sep[j]-var_adj[j]);
572  max_err = (max_err < diff) ? diff : max_err;
573  }
574  }
575 
576  if (max_err > 1e-10) {
577  printf("ArrayCheckEqual: %-30s max_err = %e\n", msg, max_err);
578  exit(0);
579  }
580  return;
581 }

◆ ArrayCopynDComponent()

INLINE int ArrayCopynDComponent ( int  ndims,
const double *  x,
double *  y,
int *  dim,
int  g1,
int  g2,
int *  index,
int  nvars_from,
int  nvars_to,
int  var_from,
int  var_to 
)

Copies a component of an n-D array to another n-D array of at least one component (both of which are stored in memory as 1D arrays); the two arrays must be of the same n-dimensional size (locally and globally)

Parameters
ndimsnumber of dimensions
xcopy-from array
ycopy-to array
diminteger array of size in each dimension
g1number of ghost points in copy-from array x
g2number of ghost points in copy-to array y
indexpre-allocated (by the calling function) integer array of size ndims
nvars_fromnumber of components/variables in copy-from array
nvars_tonumber of components/variables in copy-from array
var_fromcomponent to copy from in x
var_tocomponent to copy to in y

Definition at line 444 of file arrayfunctions.h.

455 {
456  if (!y) {
457  fprintf(stderr,"Error in ArrayCopynD(): array \"y\" not allocated.\n");
458  return(1);
459  }
460  if (!x) {
461  fprintf(stderr,"Error in ArrayCopynD(): array \"x\" not allocated.\n");
462  return(1);
463  }
464  if ((var_from >= nvars_from) || (var_from < 0)) {
465  fprintf(stderr,"Error in ArrayCopynD(): specified component exceeds bounds.\n");
466  return(1);
467  }
468  if ((var_to >= nvars_to) || (var_to < 0)) {
469  fprintf(stderr,"Error in ArrayCopynD(): specified component exceeds bounds.\n");
470  return(1);
471  }
472 
473  int done = 0;
474  _ArraySetValue_(index,ndims,0);
475  while (!done) {
476  int p1, p2;
477  _ArrayIndex1D_(ndims,dim,index,g1,p1);
478  _ArrayIndex1D_(ndims,dim,index,g2,p2);
479  (y+p2*nvars_to)[var_to] = (x+p1*nvars_from)[var_from];
480  _ArrayIncrementIndex_(ndims,dim,index,done);
481  }
482  return(0);
483 }
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)