/[escript]/branches/domexper/dudley/src/Util.c
ViewVC logotype

Diff of /branches/domexper/dudley/src/Util.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3082 by jfenwick, Tue Aug 3 06:04:05 2010 UTC revision 3086 by jfenwick, Thu Aug 5 05:07:58 2010 UTC
# Line 28  Line 28 
28    
29  /*   returns true if any of the values in the short array values is not equalt to Zero */  /*   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) {  bool_t Dudley_Util_anyNonZeroDouble(dim_t N, double* values) {
32     dim_t q;     dim_t q;
33     for (q=0;q<N;++q) if (ABS(values[q])>0) return TRUE;     for (q=0;q<N;++q) if (ABS(values[q])>0) return TRUE;
34     return FALSE;     return FALSE;
# Line 39  bool_t Finley_Util_anyNonZeroDouble(dim_ Line 39  bool_t Finley_Util_anyNonZeroDouble(dim_
39    
40  /*        out(1:numData,1:len)=in(1:numData,index(1:len)) */  /*        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){  void Dudley_Util_Gather_double(dim_t len,index_t* index,dim_t numData,double* in, double * out){
43      dim_t s,i;      dim_t s,i;
44      for (s=0;s<len;s++) {      for (s=0;s<len;s++) {
45         for (i=0;i<numData;i++) {         for (i=0;i<numData;i++) {
# Line 55  void Finley_Util_Gather_double(dim_t len Line 55  void Finley_Util_Gather_double(dim_t len
55    
56  /*        out(1:numData,1:len)=in(1:numData,index(1:len)) */  /*        out(1:numData,1:len)=in(1:numData,index(1:len)) */
57    
58  void Finley_Util_Gather_int(dim_t len,index_t* index,dim_t numData, index_t* in, index_t * out){  void Dudley_Util_Gather_int(dim_t len,index_t* index,dim_t numData, index_t* in, index_t * out){
59      dim_t s,i;      dim_t s,i;
60      for (s=0;s<len;s++) {      for (s=0;s<len;s++) {
61         for (i=0;i<numData;i++) {         for (i=0;i<numData;i++) {
# Line 71  void Finley_Util_Gather_int(dim_t len,in Line 71  void Finley_Util_Gather_int(dim_t len,in
71  /*        out(1:numData,index[p])+=in(1:numData,p) where p = {k=1...len , index[k]<upperBound}*/  /*        out(1:numData,index[p])+=in(1:numData,p) where p = {k=1...len , index[k]<upperBound}*/
72    
73    
74  void Finley_Util_AddScatter(dim_t len,index_t* index,dim_t numData,double* in,double * out, index_t upperBound){  void Dudley_Util_AddScatter(dim_t len,index_t* index,dim_t numData,double* in,double * out, index_t upperBound){
75     dim_t i,s;     dim_t i,s;
76     for (s=0;s<len;s++) {     for (s=0;s<len;s++) {
77         for(i=0;i<numData;i++) {         for(i=0;i<numData;i++) {
# Line 86  void Finley_Util_AddScatter(dim_t len,in Line 86  void Finley_Util_AddScatter(dim_t len,in
86    
87  /*          A(1:A1,1:A2)=B(1:A1,1:B2)*C(1:B2,1:A2) */  /*          A(1:A1,1:A2)=B(1:A1,1:B2)*C(1:B2,1:A2) */
88    
89  void Finley_Util_SmallMatMult(dim_t A1,dim_t A2, double* A, dim_t B2, double*B, double* C) {  void Dudley_Util_SmallMatMult(dim_t A1,dim_t A2, double* A, dim_t B2, double*B, double* C) {
90      dim_t i,j,s;      dim_t i,j,s;
91      register double rtmp;      register double rtmp;
92         for (i=0;i<A1;i++) {         for (i=0;i<A1;i++) {
# Line 102  void Finley_Util_SmallMatMult(dim_t A1,d Line 102  void Finley_Util_SmallMatMult(dim_t A1,d
102    
103  /*        A(1:A1,1:A2,i)=B(1:A1,1:B2,i)*C(1:B2,1:A2,i) i=1,len */  /*        A(1:A1,1:A2,i)=B(1:A1,1:B2,i)*C(1:B2,1:A2,i) i=1,len */
104    
105  void Finley_Util_SmallMatSetMult(dim_t len,dim_t A1,dim_t A2, double* A, dim_t B2, double*B, double* C) {  void Dudley_Util_SmallMatSetMult(dim_t len,dim_t A1,dim_t A2, double* A, dim_t B2, double*B, double* C) {
106      dim_t q,i,j,s;      dim_t q,i,j,s;
107      register double rtmp;      register double rtmp;
108      for (q=0;q<len;q++) {      for (q=0;q<len;q++) {
# Line 119  void Finley_Util_SmallMatSetMult(dim_t l Line 119  void Finley_Util_SmallMatSetMult(dim_t l
119    
120  /*        A(1:A1,1:A2,i)=B(1:A1,1:B2,i)*C(1:B2,1:A2) i=1,len */  /*        A(1:A1,1:A2,i)=B(1:A1,1:B2,i)*C(1:B2,1:A2) i=1,len */
121    
122  void Finley_Util_SmallMatSetMult1(dim_t len,dim_t A1,dim_t A2, double* A, dim_t B2, double*B, double* C) {  void Dudley_Util_SmallMatSetMult1(dim_t len,dim_t A1,dim_t A2, double* A, dim_t B2, double*B, double* C) {
123      dim_t q,i,j,s;      dim_t q,i,j,s;
124      register double rtmp;      register double rtmp;
125      for (q=0;q<len;q++) {      for (q=0;q<len;q++) {
# Line 135  void Finley_Util_SmallMatSetMult1(dim_t Line 135  void Finley_Util_SmallMatSetMult1(dim_t
135  /*    inverts the set of dim x dim matrices A(:,:,1:len) with dim=1,2,3 */  /*    inverts the set of dim x dim matrices A(:,:,1:len) with dim=1,2,3 */
136  /*    the determinante is returned. */  /*    the determinante is returned. */
137    
138  void Finley_Util_InvertSmallMat(dim_t len,dim_t dim,double* A,double *invA, double* det){  void Dudley_Util_InvertSmallMat(dim_t len,dim_t dim,double* A,double *invA, double* det){
139     dim_t q;     dim_t q;
140     register double D,A11,A12,A13,A21,A22,A23,A31,A32,A33;     register double D,A11,A12,A13,A21,A22,A23,A31,A32,A33;
141    
# Line 148  void Finley_Util_InvertSmallMat(dim_t le Line 148  void Finley_Util_InvertSmallMat(dim_t le
148                 D=1./D;                 D=1./D;
149                 invA[q]=D;                 invA[q]=D;
150              } else {              } else {
151                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");                 Dudley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");
152                 return;                 return;
153              }              }
154           }           }
# Line 170  void Finley_Util_InvertSmallMat(dim_t le Line 170  void Finley_Util_InvertSmallMat(dim_t le
170                 invA[INDEX3(0,1,q,2,2)]=-A12*D;                 invA[INDEX3(0,1,q,2,2)]=-A12*D;
171                 invA[INDEX3(1,1,q,2,2)]= A11*D;                 invA[INDEX3(1,1,q,2,2)]= A11*D;
172              } else {              } else {
173                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");                 Dudley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");
174                 return;                 return;
175              }              }
176           }           }
# Line 202  void Finley_Util_InvertSmallMat(dim_t le Line 202  void Finley_Util_InvertSmallMat(dim_t le
202                 invA[INDEX3(1,2,q,3,3)]=(A13*A21-A11*A23)*D;                 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;                 invA[INDEX3(2,2,q,3,3)]=(A11*A22-A12*A21)*D;
204              } else {              } else {
205                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");                 Dudley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");
206                 return;                 return;
207              }              }
208           }           }
# Line 214  void Finley_Util_InvertSmallMat(dim_t le Line 214  void Finley_Util_InvertSmallMat(dim_t le
214    
215  /*    sets the derterminate of a set of dim x dim matrices A(:,:,1:len) with dim=1,2,3 */  /*    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){  void Dudley_Util_DetOfSmallMat(dim_t len,dim_t dim,double* A, double* det){
218     dim_t q;     dim_t q;
219     register double A11,A12,A13,A21,A22,A23,A31,A32,A33;     register double A11,A12,A13,A21,A22,A23,A31,A32,A33;
220    
# Line 258  void Finley_Util_DetOfSmallMat(dim_t len Line 258  void Finley_Util_DetOfSmallMat(dim_t len
258  /*    returns the normalized vector Normal[dim,len] orthogonal to A(:,0,q) and A(:,1,q) in the case of dim=3  */  /*    returns the normalized vector Normal[dim,len] orthogonal to A(:,0,q) and A(:,1,q) in the case of dim=3  */
259  /*    or the vector A(:,0,q) in the case of dim=2                                             */  /*    or the vector A(:,0,q) in the case of dim=2                                             */
260    
261  void  Finley_NormalVector(dim_t len, dim_t dim, dim_t dim1, double* A,double* Normal) {  void  Dudley_NormalVector(dim_t len, dim_t dim, dim_t dim1, double* A,double* Normal) {
262     dim_t q;     dim_t q;
263     register double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33,length,invlength;     register double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33,length,invlength;
264    
# Line 272  void  Finley_NormalVector(dim_t len, dim Line 272  void  Finley_NormalVector(dim_t len, dim
272              A21=A[INDEX3(1,0,q,2,dim1)];              A21=A[INDEX3(1,0,q,2,dim1)];
273              length = sqrt(A11*A11+A21*A21);              length = sqrt(A11*A11+A21*A21);
274              if (! length>0) {              if (! length>0) {
275                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero.");                 Dudley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero.");
276                 return;                 return;
277              } else {              } else {
278                 invlength=1./length;                 invlength=1./length;
# Line 294  void  Finley_NormalVector(dim_t len, dim Line 294  void  Finley_NormalVector(dim_t len, dim
294              CO_A33=A11*A22-A21*A12;              CO_A33=A11*A22-A21*A12;
295              length=sqrt(CO_A13*CO_A13+CO_A23*CO_A23+CO_A33*CO_A33);              length=sqrt(CO_A13*CO_A13+CO_A23*CO_A23+CO_A33*CO_A33);
296              if (! length>0) {              if (! length>0) {
297                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero.");                 Dudley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero.");
298                 return;                 return;
299              } else {              } else {
300                 invlength=1./length;                 invlength=1./length;
# Line 313  void  Finley_NormalVector(dim_t len, dim Line 313  void  Finley_NormalVector(dim_t len, dim
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 */  /*    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                                                                   */  /*    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) {  void  Dudley_LengthOfNormalVector(dim_t len, dim_t dim, dim_t dim1, double* A,double* length) {
317     dim_t q;     dim_t q;
318     double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33;     double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33;
319    
# Line 351  void  Finley_LengthOfNormalVector(dim_t Line 351  void  Finley_LengthOfNormalVector(dim_t
351  /* there is no range checking! */  /* there is no range checking! */
352  /* at output Map[invMap[i]]=i for i=0:lenInvMap */  /* at output Map[invMap[i]]=i for i=0:lenInvMap */
353    
354  void Finley_Util_InvertMap(dim_t lenInvMap, index_t* invMap,dim_t lenMap, index_t* Map) {  void Dudley_Util_InvertMap(dim_t lenInvMap, index_t* invMap,dim_t lenMap, index_t* Map) {
355     dim_t i;     dim_t i;
356     for (i=0;i<lenInvMap;i++) invMap[i]=0;     for (i=0;i<lenInvMap;i++) invMap[i]=0;
357     for (i=0;i<lenMap;i++) {     for (i=0;i<lenMap;i++) {
# Line 359  void Finley_Util_InvertMap(dim_t lenInvM Line 359  void Finley_Util_InvertMap(dim_t lenInvM
359     }     }
360  }  }
361    
362  /* orders a Finley_Util_ValueAndIndex array by value */  /* orders a Dudley_Util_ValueAndIndex array by value */
363  /* it is assumed that n is large */  /* it is assumed that n is large */
364    
365  int Finley_Util_ValueAndIndex_compar(const void *arg1 , const void *arg2 ) {  int Dudley_Util_ValueAndIndex_compar(const void *arg1 , const void *arg2 ) {
366     Finley_Util_ValueAndIndex *e1,*e2;     Dudley_Util_ValueAndIndex *e1,*e2;
367     e1=(Finley_Util_ValueAndIndex*) arg1;     e1=(Dudley_Util_ValueAndIndex*) arg1;
368     e2=(Finley_Util_ValueAndIndex*) arg2;     e2=(Dudley_Util_ValueAndIndex*) arg2;
369     if (e1->value < e2->value) return -1;     if (e1->value < e2->value) return -1;
370     if (e1->value > e2->value) return  1;     if (e1->value > e2->value) return  1;
371     if (e1->index < e2->index) return -1;     if (e1->index < e2->index) return -1;
# Line 373  int Finley_Util_ValueAndIndex_compar(con Line 373  int Finley_Util_ValueAndIndex_compar(con
373     return 0;     return 0;
374  }  }
375    
376  void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) {  void Dudley_Util_sortValueAndIndex(dim_t n,Dudley_Util_ValueAndIndex* array) {
377       /* OMP : needs parallelization !*/       /* OMP : needs parallelization !*/
378       qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar);       qsort(array,n,sizeof(Dudley_Util_ValueAndIndex),Dudley_Util_ValueAndIndex_compar);
379  }  }
380    
381    
# Line 383  void Finley_Util_sortValueAndIndex(dim_t Line 383  void Finley_Util_sortValueAndIndex(dim_t
383    
384  /* calculates the minimum value from a dim X N integer array */  /* 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) {  index_t Dudley_Util_getMinInt(dim_t dim,dim_t N,index_t* values) {
387     dim_t i,j;     dim_t i,j;
388     index_t out,out_local;     index_t out,out_local;
389     out=INDEX_T_MAX;     out=INDEX_T_MAX;
# Line 405  index_t Finley_Util_getMinInt(dim_t dim, Line 405  index_t Finley_Util_getMinInt(dim_t dim,
405                                                                                                                                                                                                                                                                                                        
406  /* calculates the maximum value from a dim X N integer array */  /* calculates the maximum value from a dim X N integer array */
407    
408  index_t Finley_Util_getMaxInt(dim_t dim,dim_t N,index_t* values) {  index_t Dudley_Util_getMaxInt(dim_t dim,dim_t N,index_t* values) {
409     dim_t i,j;     dim_t i,j;
410     index_t out,out_local;     index_t out,out_local;
411     out=-INDEX_T_MAX;     out=-INDEX_T_MAX;
# Line 428  index_t Finley_Util_getMaxInt(dim_t dim, Line 428  index_t Finley_Util_getMaxInt(dim_t dim,
428    
429  /* calculates the minimum value from a dim X N integer array */  /* calculates the minimum value from a dim X N integer array */
430    
431  index_t Finley_Util_getFlaggedMinInt(dim_t dim,dim_t N,index_t* values, index_t ignore) {  index_t Dudley_Util_getFlaggedMinInt(dim_t dim,dim_t N,index_t* values, index_t ignore) {
432     dim_t i,j;     dim_t i,j;
433     index_t out,out_local;     index_t out,out_local;
434     out=INDEX_T_MAX;     out=INDEX_T_MAX;
# Line 450  index_t Finley_Util_getFlaggedMinInt(dim Line 450  index_t Finley_Util_getFlaggedMinInt(dim
450                                                                                                                                                                                                                                                                                                        
451  /* calculates the maximum value from a dim X N integer array */  /* calculates the maximum value from a dim X N integer array */
452    
453  index_t Finley_Util_getFlaggedMaxInt(dim_t dim,dim_t N,index_t* values, index_t ignore) {  index_t Dudley_Util_getFlaggedMaxInt(dim_t dim,dim_t N,index_t* values, index_t ignore) {
454     dim_t i,j;     dim_t i,j;
455     index_t out,out_local;     index_t out,out_local;
456     out=-INDEX_T_MAX;     out=-INDEX_T_MAX;
# Line 472  index_t Finley_Util_getFlaggedMaxInt(dim Line 472  index_t Finley_Util_getFlaggedMaxInt(dim
472    
473  /* set the index of the positive entries in mask. The length of index is returned. */  /* set the index of the positive entries in mask. The length of index is returned. */
474    
475  dim_t Finley_Util_packMask(dim_t N,index_t* mask,index_t* index) {  dim_t Dudley_Util_packMask(dim_t N,index_t* mask,index_t* index) {
476        dim_t out,k;        dim_t out,k;
477        out=0;        out=0;
478        /*OMP */        /*OMP */
# Line 486  dim_t Finley_Util_packMask(dim_t N,index Line 486  dim_t Finley_Util_packMask(dim_t N,index
486  }  }
487    
488  /* returns true if array contains value */  /* returns true if array contains value */
489  bool_t Finley_Util_isAny(dim_t N,index_t* array,index_t value) {  bool_t Dudley_Util_isAny(dim_t N,index_t* array,index_t value) {
490     bool_t out=FALSE;     bool_t out=FALSE;
491     dim_t i;     dim_t i;
492     #pragma omp parallel for private(i) schedule(static) reduction(||:out)     #pragma omp parallel for private(i) schedule(static) reduction(||:out)
# Line 494  bool_t Finley_Util_isAny(dim_t N,index_t Line 494  bool_t Finley_Util_isAny(dim_t N,index_t
494     return out;     return out;
495  }  }
496  /* calculates the cummultative sum in array and returns the total sum */  /* calculates the cummultative sum in array and returns the total sum */
497  index_t Finley_Util_cumsum(dim_t N,index_t* array) {  index_t Dudley_Util_cumsum(dim_t N,index_t* array) {
498     index_t out=0,tmp;     index_t out=0,tmp;
499     dim_t i;     dim_t i;
500     #ifdef _OPENMP     #ifdef _OPENMP
# Line 535  index_t Finley_Util_cumsum(dim_t N,index Line 535  index_t Finley_Util_cumsum(dim_t N,index
535     #endif     #endif
536     return out;     return out;
537  }  }
538  void Finley_Util_setValuesInUse(const index_t *values, const dim_t numValues, dim_t *numValuesInUse, index_t **valuesInUse, Paso_MPIInfo* mpiinfo)  void Dudley_Util_setValuesInUse(const index_t *values, const dim_t numValues, dim_t *numValuesInUse, index_t **valuesInUse, Paso_MPIInfo* mpiinfo)
539  {  {
540     dim_t i;     dim_t i;
541     index_t lastFoundValue=INDEX_T_MIN, minFoundValue, local_minFoundValue, *newValuesInUse=NULL;     index_t lastFoundValue=INDEX_T_MIN, minFoundValue, local_minFoundValue, *newValuesInUse=NULL;
# Line 588  void Finley_Util_setValuesInUse(const in Line 588  void Finley_Util_setValuesInUse(const in
588    
589    
590  #ifdef PASO_MPI  #ifdef PASO_MPI
591  void Finley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name  )  void Dudley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name  )
592  {  {
593    index_t i;    index_t i;
594        
# Line 602  void Finley_printDoubleArray( FILE *fid, Line 602  void Finley_printDoubleArray( FILE *fid,
602      fprintf( fid, "... " );      fprintf( fid, "... " );
603    fprintf( fid, "]\n" );    fprintf( fid, "]\n" );
604  }  }
605  void Finley_printIntArray( FILE *fid, dim_t n, int *array, char *name  )  void Dudley_printIntArray( FILE *fid, dim_t n, int *array, char *name  )
606  {  {
607    index_t i;    index_t i;
608        
# Line 616  void Finley_printIntArray( FILE *fid, di Line 616  void Finley_printIntArray( FILE *fid, di
616      fprintf( fid, "... " );      fprintf( fid, "... " );
617    fprintf( fid, "]\n" );    fprintf( fid, "]\n" );
618  }  }
619  void Finley_printMaskArray( FILE *fid, dim_t n, int *array, char *name  )  void Dudley_printMaskArray( FILE *fid, dim_t n, int *array, char *name  )
620  {  {
621    index_t i;    index_t i;
622        

Legend:
Removed from v.3082  
changed lines
  Added in v.3086

  ViewVC Help
Powered by ViewVC 1.1.26