/[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 888 by gross, Tue Nov 7 08:31:26 2006 UTC
# Line 1  Line 1 
1  /* $Id$ */  /*
2     ************************************************************
3     *          Copyright 2006 by ACcESS MNRF                   *
4     *                                                          *
5     *              http://www.access.edu.au                    *
6     *       Primary Business: Queensland, Australia            *
7     *  Licensed under the Open Software License version 3.0    *
8     *     http://www.opensource.org/licenses/osl-3.0.php       *
9     *                                                          *
10     ************************************************************
11    */
12    
13  /**************************************************************/  /**************************************************************/
14    
# Line 6  Line 16 
16    
17  /**************************************************************/  /**************************************************************/
18    
 /*   Copyrights by ACcESS Australia, 2003 */  
19  /*   author: gross@access.edu.au */  /*   author: gross@access.edu.au */
20  /*   Version: $Id$ */  /*   Version: $Id$ */
21    
22  /**************************************************************/  /**************************************************************/
23    
 #include "Common.h"  
24  #include "Finley.h"  #include "Finley.h"
25  #include "Util.h"  #include "Util.h"
26    
27  #ifdef _OPENMP  #ifdef _OPENMP
28  #include <omp.h>  #include <omp.h>
29  #endif  #endif
# Line 63  void Finley_Util_Gather_int(dim_t len,in Line 72  void Finley_Util_Gather_int(dim_t len,in
72    
73  /*   adds a vector in into out using and index. */  /*   adds a vector in into out using and index. */
74    
75  /*        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}*/
76    
77  void Finley_Util_AddScatter(dim_t len,index_t* index,dim_t numData,double* in,double * out){  
78    void Finley_Util_AddScatter(dim_t len,index_t* index,dim_t numData,double* in,double * out, index_t upperBound){
79     dim_t i,s;     dim_t i,s;
80     for (s=0;s<len;s++) {     for (s=0;s<len;s++) {
81         for(i=0;i<numData;i++) {         for(i=0;i<numData;i++) {
82            #pragma omp atomic            if( index[s]<upperBound ) {
83            out[INDEX2(i,index[s],numData)]+=in[INDEX2(i,s,numData)];              #pragma omp atomic
84                out[INDEX2(i,index[s],numData)]+=in[INDEX2(i,s,numData)];
85          }
86         }         }
87     }     }
88  }  }
# Line 124  void Finley_Util_InvertSmallMat(dim_t le Line 136  void Finley_Util_InvertSmallMat(dim_t le
136                 D=1./D;                 D=1./D;
137                 invA[q]=D;                 invA[q]=D;
138              } else {              } else {
139                 Finley_ErrorCode=ZERO_DIVISION_ERROR;                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");
                sprintf(Finley_ErrorMsg,"Non-regular matrix");  
140                 return;                 return;
141              }              }
142           }           }
# Line 147  void Finley_Util_InvertSmallMat(dim_t le Line 158  void Finley_Util_InvertSmallMat(dim_t le
158                 invA[INDEX3(0,1,q,2,2)]=-A12*D;                 invA[INDEX3(0,1,q,2,2)]=-A12*D;
159                 invA[INDEX3(1,1,q,2,2)]= A11*D;                 invA[INDEX3(1,1,q,2,2)]= A11*D;
160              } else {              } else {
161                 Finley_ErrorCode=ZERO_DIVISION_ERROR;                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");
                sprintf(Finley_ErrorMsg,"Non-regular matrix");  
162                 return;                 return;
163              }              }
164           }           }
# Line 180  void Finley_Util_InvertSmallMat(dim_t le Line 190  void Finley_Util_InvertSmallMat(dim_t le
190                 invA[INDEX3(1,2,q,3,3)]=(A13*A21-A11*A23)*D;                 invA[INDEX3(1,2,q,3,3)]=(A13*A21-A11*A23)*D;
191                 invA[INDEX3(2,2,q,3,3)]=(A11*A22-A12*A21)*D;                 invA[INDEX3(2,2,q,3,3)]=(A11*A22-A12*A21)*D;
192              } else {              } else {
193                 Finley_ErrorCode=ZERO_DIVISION_ERROR;                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");
                sprintf(Finley_ErrorMsg,"Non-regular matrix");  
194                 return;                 return;
195              }              }
196           }           }
# Line 251  void  Finley_NormalVector(dim_t len, dim Line 260  void  Finley_NormalVector(dim_t len, dim
260              A21=A[INDEX3(1,0,q,2,dim1)];              A21=A[INDEX3(1,0,q,2,dim1)];
261              length = sqrt(A11*A11+A21*A21);              length = sqrt(A11*A11+A21*A21);
262              if (! length>0) {              if (! length>0) {
263                 Finley_ErrorCode=ZERO_DIVISION_ERROR;                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero.");
                sprintf(Finley_ErrorMsg,"area equals zero.");  
264                 return;                 return;
265              } else {              } else {
266                 invlength=1./length;                 invlength=1./length;
# Line 274  void  Finley_NormalVector(dim_t len, dim Line 282  void  Finley_NormalVector(dim_t len, dim
282              CO_A33=A11*A22-A21*A12;              CO_A33=A11*A22-A21*A12;
283              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);
284              if (! length>0) {              if (! length>0) {
285                 Finley_ErrorCode=ZERO_DIVISION_ERROR;                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero.");
                sprintf(Finley_ErrorMsg,"area equals zero.");  
286                 return;                 return;
287              } else {              } else {
288                 invlength=1./length;                 invlength=1./length;
# Line 349  int Finley_Util_ValueAndIndex_compar(con Line 356  int Finley_Util_ValueAndIndex_compar(con
356     e2=(Finley_Util_ValueAndIndex*) arg2;     e2=(Finley_Util_ValueAndIndex*) arg2;
357     if (e1->value < e2->value) return -1;     if (e1->value < e2->value) return -1;
358     if (e1->value > e2->value) return  1;     if (e1->value > e2->value) return  1;
359       if (e1->index < e2->index) return -1;
360       if (e1->index > e2->index) return  1;
361     return 0;     return 0;
362  }  }
363    
364  void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) {  void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) {
365       /* OMP : needs parallelization !*/       /* OMP : needs parallelization !*/
366       qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar);       qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar);
# Line 472  void Finley_copyDouble(dim_t n,double* s Line 482  void Finley_copyDouble(dim_t n,double* s
482    for (i=0;i<n;i++) target[i]=source[i];    for (i=0;i<n;i++) target[i]=source[i];
483  }  }
484    
485    #ifdef PASO_MPI
486    void Finley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name  )
487    {
488      index_t i;
489      
490      if( name )
491        fprintf( fid, "%s [ ", name );
492      else
493        fprintf( fid, "[ " );  
494      for( i=0; i<(n<60 ? n : 60); i++ )
495        fprintf( fid, "%g ", array[i] );
496      if( n>=30 )
497        fprintf( fid, "... " );
498      fprintf( fid, "]\n" );
499    }
500    void Finley_printIntArray( FILE *fid, dim_t n, int *array, char *name  )
501    {
502      index_t i;
503      
504      if( name )
505        fprintf( fid, "%s [ ", name );
506      else
507        fprintf( fid, "[ " );  
508      for( i=0; i<(n<60 ? n : 60); i++ )
509        fprintf( fid, "%d ", array[i] );
510      if( n>=30 )
511        fprintf( fid, "... " );
512      fprintf( fid, "]\n" );
513    }
514    void Finley_printMaskArray( FILE *fid, dim_t n, int *array, char *name  )
515    {
516      index_t i;
517      
518      if( name )
519        fprintf( fid, "%s [ ", name );
520      else
521        fprintf( fid, "[ " );  
522      for( i=0; i<(n<60 ? n : 60); i++ )
523        if( array[i]!=-1 )
524          fprintf( fid, "%3d ", array[i] );
525        else
526          fprintf( fid, "  * " );
527      if( n>=30 )
528        fprintf( fid, "... " );
529      fprintf( fid, "]\n" );
530    }
531    #endif
532    
533  /*  /*
  * $Log$  
534   * Revision 1.8  2005/08/12 01:45:43  jgs   * Revision 1.8  2005/08/12 01:45:43  jgs
535   * erge of development branch dev-02 back to main trunk on 2005-08-12   *
536     * Revision 1.7.2.2  2005/09/07 06:26:22  gross
537     * the solver from finley are put into the standalone package paso now
538   *   *
539   * Revision 1.7.2.1  2005/08/04 22:41:11  gross   * Revision 1.7.2.1  2005/08/04 22:41:11  gross
540   * some extra routines for finley that might speed-up RHS assembling in some cases (not actived right now)   * some extra routines for finley that might speed-up RHS assembling in some cases (not actived right now)

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

  ViewVC Help
Powered by ViewVC 1.1.26