/[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

trunk/esys2/finley/src/finleyC/Util.c revision 147 by jgs, Fri Aug 12 01:45:47 2005 UTC trunk/finley/src/Util.c revision 1312 by ksteube, Mon Sep 24 06:18:44 2007 UTC
# Line 1  Line 1 
 /* $Id$ */  
1    
2  /**************************************************************/  /* $Id$ */
3    
4  /*   Some utility routines: */  /*******************************************************
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  /*   Copyrights by ACcESS Australia, 2003 */  /*   Some utility routines: */
 /*   author: gross@access.edu.au */  
 /*   Version: $Id$ */  
19    
20  /**************************************************************/  /**************************************************************/
21    
 #include "Common.h"  
22  #include "Finley.h"  #include "Finley.h"
23  #include "Util.h"  #include "Util.h"
24    
25  #ifdef _OPENMP  #ifdef _OPENMP
26  #include <omp.h>  #include <omp.h>
27  #endif  #endif
# Line 63  void Finley_Util_Gather_int(dim_t len,in Line 70  void Finley_Util_Gather_int(dim_t len,in
70    
71  /*   adds a vector in into out using and index. */  /*   adds a vector in into out using and index. */
72    
73  /*        out(1:numData,index(1:len))+=in(1:numData,1:len) */  /*        out(1:numData,index[p])+=in(1:numData,p) where p = {k=1...len , index[k]<upperBound}*/
74    
75  void Finley_Util_AddScatter(dim_t len,index_t* index,dim_t numData,double* in,double * out){  
76    void Finley_Util_AddScatter(dim_t len,index_t* index,dim_t numData,double* in,double * out, index_t upperBound){
77     dim_t i,s;     dim_t i,s;
78     for (s=0;s<len;s++) {     for (s=0;s<len;s++) {
79         for(i=0;i<numData;i++) {         for(i=0;i<numData;i++) {
80            #pragma omp atomic            if( index[s]<upperBound ) {
81            out[INDEX2(i,index[s],numData)]+=in[INDEX2(i,s,numData)];              out[INDEX2(i,index[s],numData)]+=in[INDEX2(i,s,numData)];
82          }
83         }         }
84     }     }
85  }  }
# Line 124  void Finley_Util_InvertSmallMat(dim_t le Line 133  void Finley_Util_InvertSmallMat(dim_t le
133                 D=1./D;                 D=1./D;
134                 invA[q]=D;                 invA[q]=D;
135              } else {              } else {
136                 Finley_ErrorCode=ZERO_DIVISION_ERROR;                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");
                sprintf(Finley_ErrorMsg,"Non-regular matrix");  
137                 return;                 return;
138              }              }
139           }           }
# Line 147  void Finley_Util_InvertSmallMat(dim_t le Line 155  void Finley_Util_InvertSmallMat(dim_t le
155                 invA[INDEX3(0,1,q,2,2)]=-A12*D;                 invA[INDEX3(0,1,q,2,2)]=-A12*D;
156                 invA[INDEX3(1,1,q,2,2)]= A11*D;                 invA[INDEX3(1,1,q,2,2)]= A11*D;
157              } else {              } else {
158                 Finley_ErrorCode=ZERO_DIVISION_ERROR;                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");
                sprintf(Finley_ErrorMsg,"Non-regular matrix");  
159                 return;                 return;
160              }              }
161           }           }
# Line 180  void Finley_Util_InvertSmallMat(dim_t le Line 187  void Finley_Util_InvertSmallMat(dim_t le
187                 invA[INDEX3(1,2,q,3,3)]=(A13*A21-A11*A23)*D;                 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;                 invA[INDEX3(2,2,q,3,3)]=(A11*A22-A12*A21)*D;
189              } else {              } else {
190                 Finley_ErrorCode=ZERO_DIVISION_ERROR;                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");
                sprintf(Finley_ErrorMsg,"Non-regular matrix");  
191                 return;                 return;
192              }              }
193           }           }
# Line 251  void  Finley_NormalVector(dim_t len, dim Line 257  void  Finley_NormalVector(dim_t len, dim
257              A21=A[INDEX3(1,0,q,2,dim1)];              A21=A[INDEX3(1,0,q,2,dim1)];
258              length = sqrt(A11*A11+A21*A21);              length = sqrt(A11*A11+A21*A21);
259              if (! length>0) {              if (! length>0) {
260                 Finley_ErrorCode=ZERO_DIVISION_ERROR;                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero.");
                sprintf(Finley_ErrorMsg,"area equals zero.");  
261                 return;                 return;
262              } else {              } else {
263                 invlength=1./length;                 invlength=1./length;
# Line 274  void  Finley_NormalVector(dim_t len, dim Line 279  void  Finley_NormalVector(dim_t len, dim
279              CO_A33=A11*A22-A21*A12;              CO_A33=A11*A22-A21*A12;
280              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);
281              if (! length>0) {              if (! length>0) {
282                 Finley_ErrorCode=ZERO_DIVISION_ERROR;                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero.");
                sprintf(Finley_ErrorMsg,"area equals zero.");  
283                 return;                 return;
284              } else {              } else {
285                 invlength=1./length;                 invlength=1./length;
# Line 349  int Finley_Util_ValueAndIndex_compar(con Line 353  int Finley_Util_ValueAndIndex_compar(con
353     e2=(Finley_Util_ValueAndIndex*) arg2;     e2=(Finley_Util_ValueAndIndex*) arg2;
354     if (e1->value < e2->value) return -1;     if (e1->value < e2->value) return -1;
355     if (e1->value > e2->value) return  1;     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;     return 0;
359  }  }
360    
361  void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) {  void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) {
362       /* OMP : needs parallelization !*/       /* OMP : needs parallelization !*/
363       qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar);       qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar);
# Line 402  index_t Finley_Util_getMaxInt(dim_t dim, Line 409  index_t Finley_Util_getMaxInt(dim_t dim,
409     }     }
410     return out;     return out;
411  }  }
412    /**************************************************************/
413    
414    /* calculates the minimum value from a dim X N integer array */
415    
416    index_t Finley_Util_getFlaggedMinInt(dim_t dim,dim_t N,index_t* values, index_t ignore) {
417       dim_t i,j;
418       index_t out,out_local;
419       out=INDEX_T_MAX;
420       if (values!=NULL && dim*N>0 ) {
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;j<N;j++) {
427               for (i=0;i<dim;i++) if (values[INDEX2(i,j,dim)]!=ignore) out_local=MIN(out_local,values[INDEX2(i,j,dim)]);
428             }
429             #pragma omp critical
430             out=MIN(out_local,out);
431         }
432       }
433       return out;
434    }
435                                                                                                                                                      
436    /* calculates the maximum value from a dim X N integer array */
437    
438    index_t Finley_Util_getFlaggedMaxInt(dim_t dim,dim_t N,index_t* values, index_t ignore) {
439       dim_t i,j;
440       index_t out,out_local;
441       out=-INDEX_T_MAX;
442       if (values!=NULL && dim*N>0 ) {
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<N;j++) {
449                 for (i=0;i<dim;i++) if (values[INDEX2(i,j,dim)]!=ignore) out_local=MAX(out_local,values[INDEX2(i,j,dim)]);
450             }
451             #pragma omp critical
452             out=MAX(out_local,out);
453          }
454       }
455       return out;
456    }
457    
458  /* 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. */
459    
# Line 467  index_t Finley_Util_cumsum(dim_t N,index Line 519  index_t Finley_Util_cumsum(dim_t N,index
519     return out;     return out;
520  }  }
521    
 void Finley_copyDouble(dim_t n,double* source, double* target) {  
   dim_t i;  
   for (i=0;i<n;i++) target[i]=source[i];  
 }  
522    
523  /*  #ifdef PASO_MPI
524   * $Log$  void Finley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name  )
525   * Revision 1.8  2005/08/12 01:45:43  jgs  {
526   * erge of development branch dev-02 back to main trunk on 2005-08-12    index_t i;
527   *    
528   * Revision 1.7.2.1  2005/08/04 22:41:11  gross    if( name )
529   * some extra routines for finley that might speed-up RHS assembling in some cases (not actived right now)      fprintf( fid, "%s [ ", name );
530   *    else
531   * Revision 1.7  2005/07/08 04:07:59  jgs      fprintf( fid, "[ " );  
532   * Merge of development branch back to main trunk on 2005-07-08    for( i=0; i<(n<60 ? n : 60); i++ )
533   *      fprintf( fid, "%g ", array[i] );
534   * Revision 1.1.1.1.2.4  2005/06/29 02:34:57  gross    if( n>=30 )
535   * some changes towards 64 integers in finley      fprintf( fid, "... " );
536   *    fprintf( fid, "]\n" );
537   * Revision 1.1.1.1.2.3  2005/03/02 23:35:06  gross  }
538   * reimplementation of the ILU in Finley. block size>1 still needs some testing  void Finley_printIntArray( FILE *fid, dim_t n, int *array, char *name  )
539   *  {
540   * Revision 1.1.1.1.2.2  2005/02/18 02:27:31  gross    index_t i;
541   * two function that will be used for a reimplementation of the ILU preconditioner    
542   *    if( name )
543   * Revision 1.1.1.1.2.1  2004/11/12 06:58:19  gross      fprintf( fid, "%s [ ", name );
544   * a lot of changes to get the linearPDE class running: most important change is that there is no matrix format exposed to the user anymore. the format is chosen by the Domain according to the solver and symmetry    else
545   *      fprintf( fid, "[ " );  
546   * Revision 1.1.1.1  2004/10/26 06:53:57  jgs    for( i=0; i<(n<60 ? n : 60); i++ )
547   * initial import of project esys2      fprintf( fid, "%d ", array[i] );
548   *    if( n>=30 )
549   * Revision 1.3  2004/08/26 12:03:52  gross      fprintf( fid, "... " );
550   * Some other bug in Finley_Assemble_gradient fixed.    fprintf( fid, "]\n" );
551   *  }
552   * Revision 1.2  2004/07/02 04:21:13  gross  void Finley_printMaskArray( FILE *fid, dim_t n, int *array, char *name  )
553   * Finley C code has been included  {
554   *    index_t i;
555   * Revision 1.1.1.1  2004/06/24 04:00:40  johng    
556   * Initial version of eys using boost-python.    if( name )
557   *      fprintf( fid, "%s [ ", name );
558   *    else
559   */      fprintf( fid, "[ " );  
560      for( i=0; i<(n<60 ? n : 60); i++ )
561        if( array[i]!=-1 )
562          fprintf( fid, "%3d ", array[i] );
563        else
564          fprintf( fid, "  * " );
565      if( n>=30 )
566        fprintf( fid, "... " );
567      fprintf( fid, "]\n" );
568    }
569    #endif

Legend:
Removed from v.147  
changed lines
  Added in v.1312

  ViewVC Help
Powered by ViewVC 1.1.26