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

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

## Properties

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