6 #ifndef _ARRAYFUNCTIONS_H_ 7 #define _ARRAYFUNCTIONS_H_ 21 #define _ArrayIndexnD_(N,index,imax,i,ghost) \ 23 int arraycounter, term=1, index_copy=index; \ 24 for (arraycounter=0; arraycounter<N; arraycounter++) term *= (imax[arraycounter]+2*(ghost));\ 25 for (arraycounter=N-1; arraycounter>=0; arraycounter--) {\ 26 term /= (imax[arraycounter]+2*(ghost)); \ 27 i[arraycounter] = index_copy/term; \ 28 index_copy -= i[arraycounter]*term; \ 30 for (arraycounter=0; arraycounter<N; arraycounter++) i[arraycounter] -= (ghost);\ 40 #define _ArrayIndex1D_(N,imax,i,ghost,index) \ 42 index = i[N-1]+(ghost); \ 44 for (arraycounter = (N)-2; arraycounter > -1; arraycounter--) { \ 45 index = ((index*(imax[arraycounter]+2*(ghost))) + (i[arraycounter]+(ghost))); \ 56 #define _ArrayIndex1D2_(N,imax,i,ghost,index) \ 58 index = i[1]+(ghost); \ 59 index = ((index*(imax[0]+2*(ghost))) + (i[0]+(ghost))); \ 69 #define _ArrayIndex1D3_(N,imax,i,ghost,index) \ 71 index = i[2]+(ghost); \ 72 index = ((index*(imax[1]+2*(ghost))) + (i[1]+(ghost))); \ 73 index = ((index*(imax[0]+2*(ghost))) + (i[0]+(ghost))); \ 83 #define _ArrayIndex1DWO_(N,imax,i,offset,ghost,index) \ 85 index = i[N-1]+(ghost)+ offset[N-1];\ 87 for (arraycounter = (N)-2; arraycounter > -1; arraycounter--) { \ 88 index = ((index*(imax[arraycounter]+2*(ghost))) + (i[arraycounter]+(ghost)+offset[arraycounter]));\ 100 #define _ArrayIndex1DWO2_(N,imax,i,offset,ghost,index) \ 102 index = i[1]+(ghost)+ offset[1];\ 103 index = ((index*(imax[0]+2*(ghost))) + (i[0]+(ghost)+offset[0]));\ 114 #define _ArrayIndex1DWO3_(N,imax,i,offset,ghost,index) \ 116 index = i[2]+(ghost)+ offset[2];\ 117 index = ((index*(imax[1]+2*(ghost))) + (i[1]+(ghost)+offset[1]));\ 118 index = ((index*(imax[0]+2*(ghost))) + (i[0]+(ghost)+offset[0]));\ 126 #define _ArrayIncrementIndex_(N,imax,i,done) \ 128 int arraycounter = 0; \ 129 while (arraycounter < (N)) { \ 130 if (i[arraycounter] == imax[arraycounter]-1) { \ 131 i[arraycounter] = 0; \ 138 if (arraycounter == (N)) done = 1; \ 149 #define _ArrayIncrementIndexWithLBound_(N,imax,imin,i,done) \ 151 int arraycounter = 0; \ 152 while (arraycounter < (N)) { \ 153 if (i[arraycounter] == imax[arraycounter]-1) { \ 154 i[arraycounter] = imin[arraycounter]; \ 161 if (arraycounter == (N)) done = 1; \ 169 #define _ArraySetValue_(x,size,value) \ 172 for (arraycounter = 0; arraycounter < (size); arraycounter++) x[arraycounter] = (value); \ 179 #define _ArraySum1D_(x,a,size) \ 183 for (arraycounter=0; arraycounter<size; arraycounter++) a += x[arraycounter]; \ 190 #define _ArrayScale1D_(x,a,size) \ 193 for (arraycounter=0; arraycounter<size; arraycounter++) x[arraycounter] *= a; \ 201 #define _ArraySubtract1D_(x,a,b,size) \ 204 for (arraycounter=0; arraycounter<size; arraycounter++) x[arraycounter] = a[arraycounter] - b[arraycounter]; \ 212 #define _ArrayAdd1D_(x,a,b,size) \ 215 for (arraycounter=0; arraycounter<size; arraycounter++) x[arraycounter] = a[arraycounter] + b[arraycounter]; \ 223 #define _ArrayMultiply1D_(x,a,b,size) \ 226 for (arraycounter=0; arraycounter<size; arraycounter++) x[arraycounter] = a[arraycounter] * b[arraycounter]; \ 234 #define _ArrayMultiply3Add1D_(x,a,b,c,d,e,f,size) \ 237 for (arraycounter=0; arraycounter<size; arraycounter++) \ 238 x[arraycounter] = a[arraycounter]*b[arraycounter]+c[arraycounter]*d[arraycounter]+e[arraycounter]*f[arraycounter]; \ 245 #define _ArrayConvexCombination1D_(z,a,x,y,size) \ 248 for (arraycounter=0; arraycounter<size; arraycounter++) \ 249 z[arraycounter] = a[arraycounter]*x[arraycounter]+(1.0-a[arraycounter])*y[arraycounter]; \ 258 #define _ArrayAYPX_(x,a,y,size) \ 261 for (arraycounter=0; arraycounter<size; arraycounter++) \ 262 y[arraycounter] = a*y[arraycounter] + x[arraycounter];\ 271 #define _ArrayAXPY_(x,a,y,size) \ 274 for (arraycounter=0; arraycounter<size; arraycounter++) y[arraycounter] += a*x[arraycounter]; \ 283 #define _ArrayAXBY_(z,a,x,b,y,size) \ 286 for (arraycounter=0; arraycounter<size; arraycounter++) z[arraycounter] = a*x[arraycounter]+b*y[arraycounter]; \ 295 #define _ArrayAXBYCZ_(w,a,x,b,y,c,z,size) \ 298 for (arraycounter=0; arraycounter<size; arraycounter++) w[arraycounter] = a*x[arraycounter]+b*y[arraycounter]+c*z[arraycounter]; \ 307 #define _ArrayScaledAXPY_(x,a,e,y,size) \ 310 for (arraycounter=0; arraycounter<size; arraycounter++) \ 311 y[arraycounter] = e*(y[arraycounter]+a*x[arraycounter]); \ 319 #define _ArrayCopy1D_(x,y,size) \ 322 for (arraycounter = 0; arraycounter < size; arraycounter++) y[arraycounter] = x[arraycounter]; \ 331 #define _ArrayCopy1D2_(x,y,size) \ 343 #define _ArrayCopy1D3_(x,y,size) \ 356 #define _ArrayScaleCopy1D_(x,a,y,size) \ 359 for (arraycounter = 0; arraycounter < size; arraycounter++) y[arraycounter] = a*x[arraycounter]; \ 368 #define _ArrayAddCopy1D_(x,a,y,size) \ 371 for (arraycounter = 0; arraycounter < size; arraycounter++) y[arraycounter] = a+x[arraycounter]; \ 377 #define _ArrayProduct1D_(x,size,p) \ 379 int arraycounter = 0; p = 1; \ 380 for (arraycounter=0; arraycounter<size; arraycounter++) p *= x[arraycounter]; \ 388 #define _ArrayBlockMultiply_(x,a,n,bs) \ 390 int arraycounter1,arraycounter2; \ 391 for (arraycounter1=0; arraycounter1<n; arraycounter1++) { \ 392 for (arraycounter2=0; arraycounter2<bs; arraycounter2++) { \ 393 x[bs*arraycounter1+arraycounter2] *= a[arraycounter1]; \ 399 # define INLINE inline 422 fprintf(stderr,
"Error in ArrayCopynD(): array \"y\" not allocated.\n");
426 fprintf(stderr,
"Error in ArrayCopynD(): array \"x\" not allocated.\n");
457 fprintf(stderr,
"Error in ArrayCopynD(): array \"y\" not allocated.\n");
461 fprintf(stderr,
"Error in ArrayCopynD(): array \"x\" not allocated.\n");
464 if ((var_from >= nvars_from) || (var_from < 0)) {
465 fprintf(stderr,
"Error in ArrayCopynD(): specified component exceeds bounds.\n");
468 if ((var_to >= nvars_to) || (var_to < 0)) {
469 fprintf(stderr,
"Error in ArrayCopynD(): specified component exceeds bounds.\n");
479 (y+p2*nvars_to)[var_to] = (x+p1*nvars_from)[var_from];
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;
522 int v;
for (v=0; v<nvars; v++) sum += ( x[p*nvars+v]>0 ? x[p*nvars+v] : -x[p*nvars+v] );
541 int v;
for (v=0; v<nvars; v++)
sum += (x[p*nvars+v]*x[p*nvars+v]);
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;
559 if (max_err > 1e-10) {
560 printf(
"ArrayCheckEqual: %-30s max_err = %e\n", msg, max_err);
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;
576 if (max_err > 1e-10) {
577 printf(
"ArrayCheckEqual: %-30s max_err = %e\n", msg, max_err);
long sum(const std::vector< int > &a_iv)
Some basic definitions and macros.
INLINE void ArrayCheckEqual(const char *, const double *, const double *, int, int)
INLINE double ArraySumAbsnD(int, int, int *, int, int *, double *)
#define _ArrayIndex1D_(N, imax, i, ghost, index)
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)
INLINE int ArrayCopynD(int, const double *, double *, int *, int, int, int *, int)
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
INLINE double ArrayMaxnD(int, int, int *, int, int *, double *)
INLINE void ArrayCheckEqual2(const char *, const double *, const double *, int)
INLINE double ArraySumSquarenD(int, int, int *, int, int *, double *)
#define _ArrayCopy1D_(x, y, size)