# Contents of /branches/domexper/dudley/src/Util.c

Revision 3082 - (show annotations)
Tue Aug 3 06:04:05 2010 UTC (9 years, 6 months ago) by jfenwick
File MIME type: text/plain
File size: 19185 byte(s)
```Builds but does not import properly
```
 1 2 /******************************************************* 3 * 4 * Copyright (c) 2003-2010 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 "Util.h" 22 23 #ifdef _OPENMP 24 #include 25 #endif 26 27 /**************************************************************/ 28 29 /* returns true if any of the values in the short array values is not equalt to Zero */ 30 31 bool_t Finley_Util_anyNonZeroDouble(dim_t N, double* values) { 32 dim_t q; 33 for (q=0;q0) return TRUE; 34 return FALSE; 35 } 36 /**************************************************************/ 37 38 /* gathers double values out from in by index: */ 39 40 /* out(1:numData,1:len)=in(1:numData,index(1:len)) */ 41 42 void Finley_Util_Gather_double(dim_t len,index_t* index,dim_t numData,double* in, double * out){ 43 dim_t s,i; 44 for (s=0;s 0 ){ 147 det[q]=D; 148 D=1./D; 149 invA[q]=D; 150 } else { 151 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix"); 152 return; 153 } 154 } 155 break; 156 157 case 2: 158 for (q=0;q 0 ){ 166 det[q]=D; 167 D=1./D; 168 invA[INDEX3(0,0,q,2,2)]= A22*D; 169 invA[INDEX3(1,0,q,2,2)]=-A21*D; 170 invA[INDEX3(0,1,q,2,2)]=-A12*D; 171 invA[INDEX3(1,1,q,2,2)]= A11*D; 172 } else { 173 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix"); 174 return; 175 } 176 } 177 break; 178 179 case 3: 180 for (q=0;q 0 ){ 193 det[q] =D; 194 D=1./D; 195 invA[INDEX3(0,0,q,3,3)]=(A22*A33-A23*A32)*D; 196 invA[INDEX3(1,0,q,3,3)]=(A31*A23-A21*A33)*D; 197 invA[INDEX3(2,0,q,3,3)]=(A21*A32-A31*A22)*D; 198 invA[INDEX3(0,1,q,3,3)]=(A13*A32-A12*A33)*D; 199 invA[INDEX3(1,1,q,3,3)]=(A11*A33-A31*A13)*D; 200 invA[INDEX3(2,1,q,3,3)]=(A12*A31-A11*A32)*D; 201 invA[INDEX3(0,2,q,3,3)]=(A12*A23-A13*A22)*D; 202 invA[INDEX3(1,2,q,3,3)]=(A13*A21-A11*A23)*D; 203 invA[INDEX3(2,2,q,3,3)]=(A11*A22-A12*A21)*D; 204 } else { 205 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix"); 206 return; 207 } 208 } 209 break; 210 211 } 212 return; 213 } 214 215 /* sets the derterminate of a set of dim x dim matrices A(:,:,1:len) with dim=1,2,3 */ 216 217 void Finley_Util_DetOfSmallMat(dim_t len,dim_t dim,double* A, double* det){ 218 dim_t q; 219 register double A11,A12,A13,A21,A22,A23,A31,A32,A33; 220 221 switch(dim) { 222 case 1: 223 for (q=0;q0) { 275 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero."); 276 return; 277 } else { 278 invlength=1./length; 279 Normal[INDEX2(0,q,2)]=A21*invlength; 280 Normal[INDEX2(1,q,2)]=-A11*invlength; 281 } 282 } 283 break; 284 case 3: 285 for (q=0;q0) { 297 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero."); 298 return; 299 } else { 300 invlength=1./length; 301 Normal[INDEX2(0,q,3)]=CO_A13*invlength; 302 Normal[INDEX2(1,q,3)]=CO_A23*invlength; 303 Normal[INDEX2(2,q,3)]=CO_A33*invlength; 304 } 305 306 } 307 break; 308 309 } 310 return; 311 } 312 313 /* 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 */ 314 /* or the vector A(:,0,q) in the case of dim=2 */ 315 316 void Finley_LengthOfNormalVector(dim_t len, dim_t dim, dim_t dim1, double* A,double* length) { 317 dim_t q; 318 double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33; 319 320 switch(dim) { 321 case 1: 322 for (q=0;q=0) invMap[Map[i]]=i; 359 } 360 } 361 362 /* orders a Finley_Util_ValueAndIndex array by value */ 363 /* it is assumed that n is large */ 364 365 int Finley_Util_ValueAndIndex_compar(const void *arg1 , const void *arg2 ) { 366 Finley_Util_ValueAndIndex *e1,*e2; 367 e1=(Finley_Util_ValueAndIndex*) arg1; 368 e2=(Finley_Util_ValueAndIndex*) arg2; 369 if (e1->value < e2->value) return -1; 370 if (e1->value > e2->value) return 1; 371 if (e1->index < e2->index) return -1; 372 if (e1->index > e2->index) return 1; 373 return 0; 374 } 375 376 void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) { 377 /* OMP : needs parallelization !*/ 378 qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar); 379 } 380 381 382 /**************************************************************/ 383 384 /* calculates the minimum value from a dim X N integer array */ 385 386 index_t Finley_Util_getMinInt(dim_t dim,dim_t N,index_t* values) { 387 dim_t i,j; 388 index_t out,out_local; 389 out=INDEX_T_MAX; 390 if (values!=NULL && dim*N>0 ) { 391 out=values[0]; 392 #pragma omp parallel private(out_local) 393 { 394 out_local=out; 395 #pragma omp for private(i,j) schedule(static) 396 for (j=0;j0 ) { 413 out=values[0]; 414 #pragma omp parallel private(out_local) 415 { 416 out_local=out; 417 #pragma omp for private(i,j) schedule(static) 418 for (j=0;j0 ) { 436 out=values[0]; 437 #pragma omp parallel private(out_local) 438 { 439 out_local=out; 440 #pragma omp for private(i,j) schedule(static) 441 for (j=0;j0 ) { 458 out=values[0]; 459 #pragma omp parallel private(out_local) 460 { 461 out_local=out; 462 #pragma omp for private(i,j) schedule(static) 463 for (j=0;j=0) { 481 index[out]=k; 482 out++; 483 } 484 } 485 return out; 486 } 487 488 /* returns true if array contains value */ 489 bool_t Finley_Util_isAny(dim_t N,index_t* array,index_t value) { 490 bool_t out=FALSE; 491 dim_t i; 492 #pragma omp parallel for private(i) schedule(static) reduction(||:out) 493 for (i=0;ilastFoundValue) && (itmpcomm ); 568 #endif 569 /* if we found a new tag we need to add this too the valuesInUseList */ 570 571 if (minFoundValue < INDEX_T_MAX) { 572 newValuesInUse=MEMALLOC(nv+1,index_t); 573 if (*valuesInUse!=NULL) { 574 memcpy(newValuesInUse,*valuesInUse,sizeof(index_t)*nv); 575 MEMFREE(*valuesInUse); 576 } 577 newValuesInUse[nv]=minFoundValue; 578 *valuesInUse=newValuesInUse; 579 newValuesInUse=NULL; 580 nv++; 581 lastFoundValue=minFoundValue; 582 } else { 583 allFound=TRUE; 584 } 585 } 586 *numValuesInUse=nv; 587 } 588 589 590 #ifdef PASO_MPI 591 void Finley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name ) 592 { 593 index_t i; 594 595 if( name ) 596 fprintf( fid, "%s [ ", name ); 597 else 598 fprintf( fid, "[ " ); 599 for( i=0; i<(n<60 ? n : 60); i++ ) 600 fprintf( fid, "%g ", array[i] ); 601 if( n>=30 ) 602 fprintf( fid, "... " ); 603 fprintf( fid, "]\n" ); 604 } 605 void Finley_printIntArray( FILE *fid, dim_t n, int *array, char *name ) 606 { 607 index_t i; 608 609 if( name ) 610 fprintf( fid, "%s [ ", name ); 611 else 612 fprintf( fid, "[ " ); 613 for( i=0; i<(n<60 ? n : 60); i++ ) 614 fprintf( fid, "%d ", array[i] ); 615 if( n>=30 ) 616 fprintf( fid, "... " ); 617 fprintf( fid, "]\n" ); 618 } 619 void Finley_printMaskArray( FILE *fid, dim_t n, int *array, char *name ) 620 { 621 index_t i; 622 623 if( name ) 624 fprintf( fid, "%s [ ", name ); 625 else 626 fprintf( fid, "[ " ); 627 for( i=0; i<(n<60 ? n : 60); i++ ) 628 if( array[i]!=-1 ) 629 fprintf( fid, "%3d ", array[i] ); 630 else 631 fprintf( fid, " * " ); 632 if( n>=30 ) 633 fprintf( fid, "... " ); 634 fprintf( fid, "]\n" ); 635 } 636 #endif

## Properties

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