# Contents of /trunk/finley/src/Util.c

Revision 2548 - (show annotations)
Mon Jul 20 06:20:06 2009 UTC (10 years, 3 months ago) by jfenwick
File MIME type: text/plain
File size: 18674 byte(s)
```Updating copyright notices
```
 1 2 /******************************************************* 3 * 4 * Copyright (c) 2003-2009 by University of Queensland 5 * Earth Systems Science Computational Center (ESSCC) 6 * http://www.uq.edu.au/esscc 7 * 8 * Primary Business: Queensland, Australia 9 * Licensed under the Open Software License version 3.0 10 * http://www.opensource.org/licenses/osl-3.0.php 11 * 12 *******************************************************/ 13 14 15 /**************************************************************/ 16 17 /* Some utility routines: */ 18 19 /**************************************************************/ 20 21 #include "Finley.h" 22 #include "Util.h" 23 24 #ifdef _OPENMP 25 #include 26 #endif 27 28 /**************************************************************/ 29 30 /* returns true if any of the values in the short array values is not equalt to Zero */ 31 32 bool_t Finley_Util_anyNonZeroDouble(dim_t N, double* values) { 33 dim_t q; 34 for (q=0;q0) return TRUE; 35 return FALSE; 36 } 37 /**************************************************************/ 38 39 /* gathers double values out from in by index: */ 40 41 /* out(1:numData,1:len)=in(1:numData,index(1:len)) */ 42 43 void Finley_Util_Gather_double(dim_t len,index_t* index,dim_t numData,double* in, double * out){ 44 dim_t s,i; 45 for (s=0;s 0 ){ 131 det[q]=D; 132 D=1./D; 133 invA[q]=D; 134 } else { 135 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix"); 136 return; 137 } 138 } 139 break; 140 141 case 2: 142 for (q=0;q 0 ){ 150 det[q]=D; 151 D=1./D; 152 invA[INDEX3(0,0,q,2,2)]= A22*D; 153 invA[INDEX3(1,0,q,2,2)]=-A21*D; 154 invA[INDEX3(0,1,q,2,2)]=-A12*D; 155 invA[INDEX3(1,1,q,2,2)]= A11*D; 156 } else { 157 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix"); 158 return; 159 } 160 } 161 break; 162 163 case 3: 164 for (q=0;q 0 ){ 177 det[q] =D; 178 D=1./D; 179 invA[INDEX3(0,0,q,3,3)]=(A22*A33-A23*A32)*D; 180 invA[INDEX3(1,0,q,3,3)]=(A31*A23-A21*A33)*D; 181 invA[INDEX3(2,0,q,3,3)]=(A21*A32-A31*A22)*D; 182 invA[INDEX3(0,1,q,3,3)]=(A13*A32-A12*A33)*D; 183 invA[INDEX3(1,1,q,3,3)]=(A11*A33-A31*A13)*D; 184 invA[INDEX3(2,1,q,3,3)]=(A12*A31-A11*A32)*D; 185 invA[INDEX3(0,2,q,3,3)]=(A12*A23-A13*A22)*D; 186 invA[INDEX3(1,2,q,3,3)]=(A13*A21-A11*A23)*D; 187 invA[INDEX3(2,2,q,3,3)]=(A11*A22-A12*A21)*D; 188 } else { 189 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix"); 190 return; 191 } 192 } 193 break; 194 195 } 196 return; 197 } 198 199 /* sets the derterminate of a set of dim x dim matrices A(:,:,1:len) with dim=1,2,3 */ 200 201 void Finley_Util_DetOfSmallMat(dim_t len,dim_t dim,double* A, double* det){ 202 dim_t q; 203 register double A11,A12,A13,A21,A22,A23,A31,A32,A33; 204 205 switch(dim) { 206 case 1: 207 for (q=0;q0) { 259 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero."); 260 return; 261 } else { 262 invlength=1./length; 263 Normal[INDEX2(0,q,2)]=A21*invlength; 264 Normal[INDEX2(1,q,2)]=-A11*invlength; 265 } 266 } 267 break; 268 case 3: 269 for (q=0;q0) { 281 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero."); 282 return; 283 } else { 284 invlength=1./length; 285 Normal[INDEX2(0,q,3)]=CO_A13*invlength; 286 Normal[INDEX2(1,q,3)]=CO_A23*invlength; 287 Normal[INDEX2(2,q,3)]=CO_A33*invlength; 288 } 289 290 } 291 break; 292 293 } 294 return; 295 } 296 297 /* return the length of the vector which is orthogonal to the vectors A(:,0,q) and A(:,1,q) in the case of dim=3 */ 298 /* or the vector A(:,0,q) in the case of dim=2 */ 299 300 void Finley_LengthOfNormalVector(dim_t len, dim_t dim, dim_t dim1, double* A,double* length) { 301 dim_t q; 302 double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33; 303 304 switch(dim) { 305 case 1: 306 for (q=0;q=0) invMap[Map[i]]=i; 343 } 344 } 345 346 /* orders a Finley_Util_ValueAndIndex array by value */ 347 /* it is assumed that n is large */ 348 349 int Finley_Util_ValueAndIndex_compar(const void *arg1 , const void *arg2 ) { 350 Finley_Util_ValueAndIndex *e1,*e2; 351 e1=(Finley_Util_ValueAndIndex*) arg1; 352 e2=(Finley_Util_ValueAndIndex*) arg2; 353 if (e1->value < e2->value) return -1; 354 if (e1->value > e2->value) return 1; 355 if (e1->index < e2->index) return -1; 356 if (e1->index > e2->index) return 1; 357 return 0; 358 } 359 360 void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) { 361 /* OMP : needs parallelization !*/ 362 qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar); 363 } 364 365 366 /**************************************************************/ 367 368 /* calculates the minimum value from a dim X N integer array */ 369 370 index_t Finley_Util_getMinInt(dim_t dim,dim_t N,index_t* values) { 371 dim_t i,j; 372 index_t out,out_local; 373 out=INDEX_T_MAX; 374 if (values!=NULL && dim*N>0 ) { 375 out=values[0]; 376 #pragma omp parallel private(out_local) 377 { 378 out_local=out; 379 #pragma omp for private(i,j) schedule(static) 380 for (j=0;j0 ) { 397 out=values[0]; 398 #pragma omp parallel private(out_local) 399 { 400 out_local=out; 401 #pragma omp for private(i,j) schedule(static) 402 for (j=0;j0 ) { 420 out=values[0]; 421 #pragma omp parallel private(out_local) 422 { 423 out_local=out; 424 #pragma omp for private(i,j) schedule(static) 425 for (j=0;j0 ) { 442 out=values[0]; 443 #pragma omp parallel private(out_local) 444 { 445 out_local=out; 446 #pragma omp for private(i,j) schedule(static) 447 for (j=0;j=0) { 465 index[out]=k; 466 out++; 467 } 468 } 469 return out; 470 } 471 472 /* returns true if array contains value */ 473 bool_t Finley_Util_isAny(dim_t N,index_t* array,index_t value) { 474 bool_t out=FALSE; 475 dim_t i; 476 #pragma omp parallel for private(i) schedule(static) reduction(||:out) 477 for (i=0;ilastFoundValue) && (itmpcomm ); 552 #endif 553 /* if we found a new tag we need to add this too the valuesInUseList */ 554 555 if (minFoundValue < INDEX_T_MAX) { 556 newValuesInUse=MEMALLOC(nv+1,index_t); 557 if (*valuesInUse!=NULL) { 558 memcpy(newValuesInUse,*valuesInUse,sizeof(index_t)*nv); 559 MEMFREE(*valuesInUse); 560 } 561 newValuesInUse[nv]=minFoundValue; 562 *valuesInUse=newValuesInUse; 563 newValuesInUse=NULL; 564 nv++; 565 lastFoundValue=minFoundValue; 566 } else { 567 allFound=TRUE; 568 } 569 } 570 *numValuesInUse=nv; 571 } 572 573 574 #ifdef PASO_MPI 575 void Finley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name ) 576 { 577 index_t i; 578 579 if( name ) 580 fprintf( fid, "%s [ ", name ); 581 else 582 fprintf( fid, "[ " ); 583 for( i=0; i<(n<60 ? n : 60); i++ ) 584 fprintf( fid, "%g ", array[i] ); 585 if( n>=30 ) 586 fprintf( fid, "... " ); 587 fprintf( fid, "]\n" ); 588 } 589 void Finley_printIntArray( FILE *fid, dim_t n, int *array, char *name ) 590 { 591 index_t i; 592 593 if( name ) 594 fprintf( fid, "%s [ ", name ); 595 else 596 fprintf( fid, "[ " ); 597 for( i=0; i<(n<60 ? n : 60); i++ ) 598 fprintf( fid, "%d ", array[i] ); 599 if( n>=30 ) 600 fprintf( fid, "... " ); 601 fprintf( fid, "]\n" ); 602 } 603 void Finley_printMaskArray( FILE *fid, dim_t n, int *array, char *name ) 604 { 605 index_t i; 606 607 if( name ) 608 fprintf( fid, "%s [ ", name ); 609 else 610 fprintf( fid, "[ " ); 611 for( i=0; i<(n<60 ? n : 60); i++ ) 612 if( array[i]!=-1 ) 613 fprintf( fid, "%3d ", array[i] ); 614 else 615 fprintf( fid, " * " ); 616 if( n>=30 ) 617 fprintf( fid, "... " ); 618 fprintf( fid, "]\n" ); 619 } 620 #endif

## Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision