New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
solpcg.F90 in trunk/NEMO/OPA_SRC/SOL – NEMO

source: trunk/NEMO/OPA_SRC/SOL/solpcg.F90 @ 1566

Last change on this file since 1566 was 1528, checked in by rblod, 15 years ago

Suppress rigid-lid option, see ticket #486

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.9 KB
Line 
1MODULE solpcg
2   !!======================================================================
3   !!                     ***  MODULE  solfet
4   !! Ocean solver :  preconditionned conjugate gradient solver
5   !!=====================================================================
6
7   !!----------------------------------------------------------------------
8   !!   sol_pcg    : preconditionned conjugate gradient solver
9   !!----------------------------------------------------------------------
10   !! * Modules used
11   USE oce             ! ocean dynamics and tracers variables
12   USE dom_oce         ! ocean space and time domain variables
13   USE sol_oce         ! ocean solver variables
14   USE lib_mpp         ! distributed memory computing
15   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
16   USE in_out_manager  ! I/O manager
17
18   IMPLICIT NONE
19   PRIVATE
20
21   !! * Routine accessibility
22   PUBLIC sol_pcg              ! ???
23
24   !! * Substitutions
25#  include "vectopt_loop_substitute.h90"
26   !!----------------------------------------------------------------------
27   !!----------------------------------------------------------------------
28   !!  OPA 9.0 , LOCEAN-IPSL (2005)
29   !! $Id$
30   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
31   !!----------------------------------------------------------------------
32CONTAINS
33
34   SUBROUTINE sol_pcg( kindic )
35      !!----------------------------------------------------------------------
36      !!                  ***  ROUTINE sol_pcg  ***
37      !!                   
38      !! ** Purpose :   Solve the ellipic equation for the transport
39      !!      divergence system  using a diagonal preconditionned
40      !!      conjugate gradient method.
41      !!
42      !! ** Method  :   Diagonal preconditionned conjugate gradient method.
43      !!      the algorithm is multitasked. (case of 5 points matrix)
44      !!      define              pa  = q^-1 * a
45      !!                        pgcb  = q^-1 * gcb
46      !!                 < . ; . >_q  = ( . )^t q ( . )
47      !!      where q is the preconditioning matrix = diagonal matrix of the
48      !!                                              diagonal elements of a
49      !!      Initialization  :
50      !!         x(o) = gcx
51      !!         r(o) = d(o) = pgcb - pa.x(o)
52      !!         rr(o)= < r(o) , r(o) >_q
53      !!      Iteration 1     :
54      !!         standard PCG algorithm
55      !!      Iteration n > 1 :
56      !!         s(n)   = pa.r(n)
57      !!         gam(n) = < r(n) , r(n) >_q
58      !!         del(n) = < r(n) , s(n) >_q
59      !!         bet(n) = gam(n) / gam(n-1)
60      !!         d(n)   = r(n) + bet(n) d(n-1)
61      !!         z(n)   = s(n) + bet(n) z(n-1)
62      !!         sig(n) = del(n) - bet(n)*bet(n)*sig(n-1)
63      !!         alp(n) = gam(n) / sig(n)
64      !!         x(n+1) = x(n) + alp(n) d(n)
65      !!         r(n+1) = r(n) - alp(n) z(n)
66      !!      Convergence test :
67      !!         rr(n+1) / < gcb , gcb >_q   =< epsr
68      !!
69      !! ** Action : - niter  : solver number of iteration done
70      !!             - res    : solver residu reached
71      !!             - gcx()  : solution of the elliptic system
72      !!
73      !! References :
74      !!      Madec et al. 1988, Ocean Modelling, issue 78, 1-6.
75      !!      D Azevedo et al. 1993, Computer Science Technical Report, Tennessee U.
76      !!
77      !! History :
78      !!        !  90-10  (G. Madec)  Original code
79      !!        !  91-11  (G. Madec)
80      !!        !  93-04  (M. Guyon)  loops and suppress pointers
81      !!        !  95-09  (M. Imbard, J. Escobar)  mpp exchange
82      !!        !  96-05  (G. Madec)  merge sor and pcg formulations
83      !!        !  96-11  (A. Weaver)  correction to preconditioning
84      !!   8.5  !  02-08  (G. Madec)  F90: Free form
85      !!        !  08-01  (R. Benshila) mpp optimization
86      !!----------------------------------------------------------------------
87      !! * Arguments
88      INTEGER, INTENT( inout ) ::   kindic   ! solver indicator, < 0 if the conver-
89      !                                      ! gence is not reached: the model is
90      !                                      ! stopped in step
91      !                                      ! set to zero before the call of solpcg
92
93      !! * Local declarations
94      INTEGER ::   ji, jj, jn                ! dummy loop indices
95      REAL(wp) ::  zgcad                     ! temporary scalars
96      REAL(wp), DIMENSION(2) :: zsum
97      REAL(wp), DIMENSION(jpi,jpj) :: zgcr
98      !!----------------------------------------------------------------------
99
100      ! Initialization of the algorithm with standard PCG
101      ! -------------------------------------------------
102
103      CALL lbc_lnk( gcx, c_solver_pt, 1. )   ! lateral boundary condition
104
105      ! gcr   = gcb-a.gcx
106      ! gcdes = gcr
107
108      DO jj = 2, jpjm1
109         DO ji = fs_2, fs_jpim1   ! vector opt.
110            zgcad = bmask(ji,jj) * ( gcb(ji,jj  ) -                gcx(ji  ,jj  )   &
111               &                                  - gcp(ji,jj,1) * gcx(ji  ,jj-1)   &
112               &                                  - gcp(ji,jj,2) * gcx(ji-1,jj  )   &
113               &                                  - gcp(ji,jj,3) * gcx(ji+1,jj  )   &
114               &                                  - gcp(ji,jj,4) * gcx(ji  ,jj+1)   )
115            gcr  (ji,jj) = zgcad
116            gcdes(ji,jj) = zgcad
117         END DO
118      END DO
119
120      ! rnorme = (gcr,gcr)
121      rnorme = SUM(  gcr(:,:) * gcdmat(:,:) * gcr(:,:)  )
122      IF( lk_mpp )   CALL mpp_sum( rnorme )   ! sum over the global domain
123
124      CALL lbc_lnk( gcdes, c_solver_pt, 1. )   ! lateral boundary condition
125
126      ! gccd = matrix . gcdes
127      DO jj = 2, jpjm1
128         DO ji = fs_2, fs_jpim1   ! vector opt.
129            gccd(ji,jj) = bmask(ji,jj)*( gcdes(ji,jj)   &
130               &        +gcp(ji,jj,1)*gcdes(ji,jj-1)+gcp(ji,jj,2)*gcdes(ji-1,jj)   &
131               &        +gcp(ji,jj,4)*gcdes(ji,jj+1)+gcp(ji,jj,3)*gcdes(ji+1,jj)   )
132         END DO
133      END DO 
134
135      ! alph = (gcr,gcr)/(gcdes,gccd)
136      radd = SUM(  gcdes(:,:) * gcdmat(:,:) * gccd(:,:)  )
137      IF( lk_mpp )   CALL mpp_sum( radd )   ! sum over the global domain
138      alph = rnorme /radd
139
140      ! gcx = gcx + alph * gcdes
141      ! gcr = gcr - alph * gccd
142      DO jj = 2, jpjm1
143         DO ji = fs_2, fs_jpim1   ! vector opt.
144            gcx(ji,jj) = bmask(ji,jj) * ( gcx(ji,jj) + alph * gcdes(ji,jj) )
145            gcr(ji,jj) = bmask(ji,jj) * ( gcr(ji,jj) - alph * gccd (ji,jj) )
146         END DO
147      END DO
148
149      ! Algorithm wtih Eijkhout rearrangement
150      ! -------------------------------------
151       
152      !                                                !================
153      DO jn = 1, nmax                                  ! Iterative loop
154         !                                             !================
155
156         CALL lbc_lnk( gcr, c_solver_pt, 1. )   ! lateral boundary condition
157
158         ! zgcr = matrix . gcr
159         DO jj = 2, jpjm1
160            DO ji = fs_2, fs_jpim1   ! vector opt.
161               zgcr(ji,jj) = bmask(ji,jj)*( gcr(ji,jj)   &
162                  &        +gcp(ji,jj,1)*gcr(ji,jj-1)+gcp(ji,jj,2)*gcr(ji-1,jj)   &
163                  &        +gcp(ji,jj,4)*gcr(ji,jj+1)+gcp(ji,jj,3)*gcr(ji+1,jj)   )
164            END DO
165         END DO
166 
167         ! rnorme = (gcr,gcr)
168         rr = rnorme
169         zsum(1) = SUM(  gcr(:,:) * gcdmat(:,:) * gcr(:,:)  )
170
171         ! zgcad = (zgcr,gcr)
172         zsum(2) = SUM( gcr(2:jpim1,2:jpjm1) * gcdmat(2:jpim1,2:jpjm1) * zgcr(2:jpim1,2:jpjm1) )
173
174         IF( lk_mpp )   CALL mpp_sum( zsum, 2 )   ! sum over the global domain
175         rnorme = zsum(1) 
176         zgcad  = zsum(2)
177
178         ! test of convergence
179         IF( rnorme < epsr .OR. jn == nmax ) THEN
180            res = SQRT( rnorme )
181            niter = jn
182            ncut = 999
183         ENDIF
184
185         ! beta = (rk+1,rk+1)/(rk,rk)
186         beta = rnorme / rr
187         radd = zgcad - beta*beta*radd
188         alph = rnorme / radd
189
190         ! gcx = gcx + alph * gcdes
191         ! gcr = gcr - alph * gccd
192         DO jj = 2, jpjm1
193            DO ji = fs_2, fs_jpim1   ! vector opt.
194               gcdes(ji,jj) = gcr (ji,jj) + beta * gcdes(ji,jj) 
195               gccd (ji,jj) = zgcr(ji,jj) + beta * gccd (ji,jj) 
196               gcx  (ji,jj) = gcx (ji,jj) + alph * gcdes(ji,jj) 
197               gcr  (ji,jj) = gcr (ji,jj) - alph * gccd (ji,jj) 
198            END DO
199         END DO
200       
201         ! indicator of non-convergence or explosion
202         IF( jn == nmax .OR. SQRT(epsr)/eps > 1.e+20 ) kindic = -2
203         IF( ncut == 999 ) GOTO 999
204
205         !                                             !================
206      END DO                                           !    End Loop
207      !                                                !================
208     
209999   CONTINUE
210     
211     
212      ! Output in gcx with lateral b.c. applied
213      ! ---------------------------------------
214     
215      CALL lbc_lnk( gcx, c_solver_pt, 1. )
216     
217   END SUBROUTINE sol_pcg
218
219   !!=====================================================================
220END MODULE solpcg
Note: See TracBrowser for help on using the repository browser.