/[escript]/trunk/paso/src/MINRES.c
ViewVC logotype

Diff of /trunk/paso/src/MINRES.c

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

revision 1979 by artak, Thu Nov 6 04:29:58 2008 UTC revision 3120 by gross, Mon Aug 30 10:48:00 2010 UTC
# Line 1  Line 1 
1    
2  /*******************************************************  /*******************************************************
3  *  *
4  * Copyright (c) 2003-2008 by University of Queensland  * Copyright (c) 2003-2010 by University of Queensland
5  * Earth Systems Science Computational Center (ESSCC)  * Earth Systems Science Computational Center (ESSCC)
6  * http://www.uq.edu.au/esscc  * http://www.uq.edu.au/esscc
7  *  *
# Line 83  err_t Paso_Solver_MINRES( Line 83  err_t Paso_Solver_MINRES(
83    dim_t n = Paso_SystemMatrix_getTotalNumRows(A);    dim_t n = Paso_SystemMatrix_getTotalNumRows(A);
84    double  *w=NULL, *w1=NULL, *w2=NULL, *r1=NULL, *r2=NULL, *y=NULL, *v=NULL;    double  *w=NULL, *w1=NULL, *w2=NULL, *r1=NULL, *r2=NULL, *y=NULL, *v=NULL;
85    
86    double Anorm,ynorm,oldb,dbar,epsln,phibar,rhs1,rhs2,rnorm,tnorm2,ynorm2,cs,sn,eps,s,alfa,denom,z,beta1,beta;    double Anorm,Arnorm,ynorm,oldb,dbar,epsln,phibar,rhs1,rhs2,rnorm,tnorm2,ynorm2,cs,sn,eps,s,alfa,denom,z,beta1,beta;
87    double gmax,gmin,oldeps,delta,gbar,gamma,phi;    double gmax,gmin,oldeps,delta,gbar,gamma,phi,root,epsx;
88    
89    double norm_of_residual=0;    double norm_of_residual=0;
90        
# Line 118  err_t Paso_Solver_MINRES( Line 118  err_t Paso_Solver_MINRES(
118    Paso_Copy(n,r1,r);    Paso_Copy(n,r1,r);
119        
120    Performance_startMonitor(pp,PERFORMANCE_PRECONDITIONER);    Performance_startMonitor(pp,PERFORMANCE_PRECONDITIONER);
121    Paso_Solver_solvePreconditioner(A,y,r1);    Paso_SystemMatrix_solvePreconditioner(A,y,r1);
122    Performance_stopMonitor(pp,PERFORMANCE_PRECONDITIONER);    Performance_stopMonitor(pp,PERFORMANCE_PRECONDITIONER);
123        
124    beta1=Paso_InnerProduct(n,r1,y,A->mpi_info);    beta1=Paso_InnerProduct(n,r1,y,A->mpi_info);
# Line 135  err_t Paso_Solver_MINRES( Line 135  err_t Paso_Solver_MINRES(
135    Paso_zeroes(n,w);    Paso_zeroes(n,w);
136    Paso_zeroes(n,w2);    Paso_zeroes(n,w2);
137        
138        Paso_zeroes(n,x);
139      
140    Paso_Copy(n,r2,r1);    Paso_Copy(n,r2,r1);
141        
142    Anorm = 0;    Anorm = 0;
# Line 151  err_t Paso_Solver_MINRES( Line 153  err_t Paso_Solver_MINRES(
153    ynorm2 = 0;    ynorm2 = 0;
154    cs     = -1;    cs     = -1;
155    sn     = 0;    sn     = 0;
156    eps    = 0.0001;    eps    = 0.000001;
157    
158    while (!(convergeFlag || maxIterFlag || breakFlag || (status !=SOLVER_NO_ERROR) ))    while (!(convergeFlag || (status !=SOLVER_NO_ERROR) ))
159    {    {
160                        
161       s=1/beta;       s=1/beta;
# Line 176  err_t Paso_Solver_MINRES( Line 178  err_t Paso_Solver_MINRES(
178    
179       Performance_stopMonitor(pp,PERFORMANCE_SOLVER);       Performance_stopMonitor(pp,PERFORMANCE_SOLVER);
180       Performance_startMonitor(pp,PERFORMANCE_PRECONDITIONER);       Performance_startMonitor(pp,PERFORMANCE_PRECONDITIONER);
181       Paso_Solver_solvePreconditioner(A,y,r2);       Paso_SystemMatrix_solvePreconditioner(A,y,r2);
182       Performance_stopMonitor(pp,PERFORMANCE_PRECONDITIONER);       Performance_stopMonitor(pp,PERFORMANCE_PRECONDITIONER);
183       Performance_startMonitor(pp,PERFORMANCE_SOLVER);       Performance_startMonitor(pp,PERFORMANCE_SOLVER);
184    
# Line 204  err_t Paso_Solver_MINRES( Line 206  err_t Paso_Solver_MINRES(
206       epsln  =               sn * beta ;       epsln  =               sn * beta ;
207       dbar   =            -  cs * beta;       dbar   =            -  cs * beta;
208            
209         root   = sqrt(gbar*gbar+dbar*dbar) ;
210         Arnorm = phibar*root;
211        
212       gamma  = sqrt(gbar*gbar+beta*beta) ;       gamma  = sqrt(gbar*gbar+beta*beta) ;
213       gamma  = MAX(gamma,eps) ;       gamma  = MAX(gamma,eps) ;
214       cs     = gbar / gamma ;                   cs     = gbar / gamma ;            
# Line 234  err_t Paso_Solver_MINRES( Line 239  err_t Paso_Solver_MINRES(
239       ynorm  = sqrt( ynorm2 ) ;       ynorm  = sqrt( ynorm2 ) ;
240    
241       rnorm  = phibar;       rnorm  = phibar;
242         epsx   = Anorm*ynorm*eps;
243       maxIterFlag = (num_iter > maxit);      
244       norm_of_residual=rnorm/Anorm*ynorm;      
245       convergeFlag=(norm_of_residual<(*tolerance));       if (status==SOLVER_NO_ERROR) {  
246                maxIterFlag = (num_iter > maxit);
247                norm_of_residual=rnorm;
248       if (maxIterFlag) {          convergeFlag=((norm_of_residual/(Anorm*ynorm))<(*tolerance) || 1+(norm_of_residual/(Anorm*ynorm)) <=1);
249           status = SOLVER_MAXITER_REACHED;          if (maxIterFlag) {
250       } else if (breakFlag) {              status = SOLVER_MAXITER_REACHED;
251           status = SOLVER_BREAKDOWN;          } else if (breakFlag) {
252                status = SOLVER_BREAKDOWN;
253            }
254       }       }
255      ++(num_iter);      ++(num_iter);
256    }    }

Legend:
Removed from v.1979  
changed lines
  Added in v.3120

  ViewVC Help
Powered by ViewVC 1.1.26