source: LMDZ5/branches/LMDZ5_SPLA/libf/dyn3d_common/disvert.F90 @ 5440

Last change on this file since 5440 was 2040, checked in by Ehouarn Millour, 11 years ago

Added a "strato_custom" mode in disvert (for development purposes).
This is triggered by setting "vert_sampling=strato_custom" in a def file.

More work is needed to clean disvert (and merge it with disvert_noterre).
DC+EM

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.1 KB
Line 
1! $Id: disvert.F90 2040 2014-05-09 10:50:34Z evignon $
2
3SUBROUTINE disvert()
4
5#ifdef CPP_IOIPSL
6  use ioipsl, only: getin
7#else
8  USE ioipsl_getincom, only: getin
9#endif
10  use new_unit_m, only: new_unit
11  use assert_m, only: assert
12
13  IMPLICIT NONE
14
15  include "dimensions.h"
16  include "paramet.h"
17  include "comvert.h"
18  include "comconst.h"
19  include "iniprint.h"
20  include "logic.h"
21
22!-------------------------------------------------------------------------------
23! Purpose: Vertical distribution functions for LMDZ.
24!          Triggered by the levels number llm.
25!-------------------------------------------------------------------------------
26! Read    in "comvert.h":
27! pa                         !--- PURE PRESSURE COORDINATE FOR P<pa (in Pascals)
28! preff                      !--- REFERENCE PRESSURE                 (101325 Pa)
29! Written in "comvert.h":
30! ap(llm+1), bp(llm+1)       !--- Ap, Bp HYBRID COEFFICIENTS AT INTERFACES
31! aps(llm),  bps(llm)        !--- Ap, Bp HYBRID COEFFICIENTS AT MID-LAYERS
32! dpres(llm)                 !--- PRESSURE DIFFERENCE FOR EACH LAYER
33! presnivs(llm)              !--- PRESSURE AT EACH MID-LAYER
34! scaleheight                !--- VERTICAL SCALE HEIGHT            (Earth: 8kms)
35! nivsig(llm+1)              !--- SIGMA INDEX OF EACH LAYER INTERFACE
36! nivsigs(llm)               !--- SIGMA INDEX OF EACH MID-LAYER
37!-------------------------------------------------------------------------------
38! Local variables:
39  REAL sig(llm+1), dsig(llm)
40  REAL sig0(llm+1), zz(llm+1)
41  REAL zk, zkm1, dzk1, dzk2, z, k0, k1
42
43  INTEGER l, unit
44  REAL dsigmin
45  REAL alpha, beta, deltaz
46  REAL x
47  character(len=*),parameter :: modname="disvert"
48
49  character(len=24):: vert_sampling
50  ! (allowed values are "param", "tropo", "strato" and "read")
51
52  !-----------------------------------------------------------------------
53
54  WRITE(lunout,*) TRIM(modname)//" starts"
55
56  ! default scaleheight is 8km for earth
57  scaleheight=8.
58
59  vert_sampling = merge("strato", "tropo ", ok_strato) ! default value
60  call getin('vert_sampling', vert_sampling)
61  WRITE(lunout,*) TRIM(modname)//' vert_sampling = ' // vert_sampling
62  if (llm==39 .and. vert_sampling=="strato") then
63     dsigmin=0.3 ! Vieille option par défaut pour CMIP5
64  else
65     dsigmin=1.
66  endif
67  call getin('dsigmin', dsigmin)
68  WRITE(LUNOUT,*) trim(modname), 'Discretisation verticale DSIGMIN=',dsigmin
69
70
71  select case (vert_sampling)
72  case ("param")
73     ! On lit les options dans sigma.def:
74     OPEN(99, file='sigma.def', status='old', form='formatted')
75     READ(99, *) scaleheight ! hauteur d'echelle 8.
76     READ(99, *) deltaz ! epaiseur de la premiere couche 0.04
77     READ(99, *) beta ! facteur d'acroissement en haut 1.3
78     READ(99, *) k0 ! nombre de couches dans la transition surf
79     READ(99, *) k1 ! nombre de couches dans la transition haute
80     CLOSE(99)
81     alpha=deltaz/(llm*scaleheight)
82     write(lunout, *)trim(modname),':scaleheight, alpha, k0, k1, beta', &
83                               scaleheight, alpha, k0, k1, beta
84
85     alpha=deltaz/tanh(1./k0)*2.
86     zkm1=0.
87     sig(1)=1.
88     do l=1, llm
89        sig(l+1)=(cosh(l/k0))**(-alpha*k0/scaleheight) &
90             *exp(-alpha/scaleheight*tanh((llm-k1)/k0) &
91                  *beta**(l-(llm-k1))/log(beta))
92        zk=-scaleheight*log(sig(l+1))
93
94        dzk1=alpha*tanh(l/k0)
95        dzk2=alpha*tanh((llm-k1)/k0)*beta**(l-(llm-k1))/log(beta)
96        write(lunout, *)l, sig(l+1), zk, zk-zkm1, dzk1, dzk2
97        zkm1=zk
98     enddo
99
100     sig(llm+1)=0.
101
102     bp(: llm) = EXP(1. - 1. / sig(: llm)**2)
103     bp(llmp1) = 0.
104
105     ap = pa * (sig - bp)
106  case("sigma")
107     DO l = 1, llm
108        x = 2*asin(1.) * (l - 0.5) / (llm + 1)
109        dsig(l) = dsigmin + 7.0 * SIN(x)**2
110     ENDDO
111     dsig = dsig / sum(dsig)
112     sig(llm+1) = 0.
113     DO l = llm, 1, -1
114        sig(l) = sig(l+1) + dsig(l)
115     ENDDO
116
117     bp(1)=1.
118     bp(2: llm) = sig(2:llm)
119     bp(llmp1) = 0.
120     ap(:)=0.
121  case("tropo")
122     DO l = 1, llm
123        x = 2*asin(1.) * (l - 0.5) / (llm + 1)
124        dsig(l) = dsigmin + 7.0 * SIN(x)**2
125     ENDDO
126     dsig = dsig / sum(dsig)
127     sig(llm+1) = 0.
128     DO l = llm, 1, -1
129        sig(l) = sig(l+1) + dsig(l)
130     ENDDO
131
132     bp(1)=1.
133     bp(2: llm) = EXP(1. - 1. / sig(2: llm)**2)
134     bp(llmp1) = 0.
135
136     ap(1)=0.
137     ap(2: llm + 1) = pa * (sig(2: llm + 1) - bp(2: llm + 1))
138  case("strato")
139     DO l = 1, llm
140        x = 2*asin(1.) * (l - 0.5) / (llm + 1)
141        dsig(l) =(dsigmin + 7. * SIN(x)**2) &
142             *(0.5*(1.-tanh(1.*(x-asin(1.))/asin(1.))))**2
143     ENDDO
144     dsig = dsig / sum(dsig)
145     sig(llm+1) = 0.
146     DO l = llm, 1, -1
147        sig(l) = sig(l+1) + dsig(l)
148     ENDDO
149
150     bp(1)=1.
151     bp(2: llm) = EXP(1. - 1. / sig(2: llm)**2)
152     bp(llmp1) = 0.
153
154     ap(1)=0.
155     ap(2: llm + 1) = pa * (sig(2: llm + 1) - bp(2: llm + 1))
156  CASE("strato_custom")
157    ! custumize strato distribution with specific alpha & beta values and function
158    ! depending on llm (experimental and temporary)!
159    SELECT CASE (llm)
160      CASE(55)
161        alpha=0.45
162        beta=4.0
163      CASE(63)
164        alpha=0.45
165        beta=5.0
166      CASE(71)
167        alpha=3.05
168        beta=65.
169      CASE(79)
170        alpha=3.20
171        ! alpha=2.05 ! FLOTT 79 (PLANTE)
172        beta=70.
173    END SELECT
174    ! Or used values provided by user in def file:
175    CALL getin("strato_alpha",alpha)
176    CALL getin("strato_beta",beta)
177   
178    ! Build geometrical distribution
179    scaleheight=7.
180    zz(1)=0.
181    IF (llm==55.OR.llm==63) THEN
182      DO l=1,llm
183        z=zz(l)/scaleheight
184        zz(l+1)=zz(l)+0.03+z*1.5*(1.-TANH(z-0.5))+alpha*(1.+TANH(z-1.5))     &
185                            +5.0*EXP((l-llm)/beta)
186      ENDDO
187    ELSEIF (llm==71) THEN !.OR.llm==79) THEN      ! FLOTT 79 (PLANTE)
188      DO l=1,llm
189        z=zz(l)
190        zz(l+1)=zz(l)+0.02+0.88*TANH(z/2.5)+alpha*(1.+TANH((z-beta)/15.))
191      ENDDO
192    ELSEIF (llm==79) THEN
193      DO l=1,llm
194        z=zz(l)
195        zz(l+1)=zz(l)+0.02+0.80*TANH(z/3.8)+alpha*(1+TANH((z-beta)/17.))     &
196                            +0.03*TANH(z/.25)
197      ENDDO
198    ENDIF ! of IF (llm==55.OR.llm==63) ...
199   
200    ! Build sigma distribution
201    sig0=EXP(-zz(:)/scaleheight)
202    sig0(llm+1)=0.
203    sig=ridders(sig0)
204   
205    ! Compute ap() and bp()
206    bp(1)=1.
207    bp(2:llm)=EXP(1.-1./sig(2:llm)**2)
208    bp(llm+1)=0.
209    ap=pa*(sig-bp)
210
211  case("read")
212     ! Read "ap" and "bp". First line is skipped (title line). "ap"
213     ! should be in Pa. First couple of values should correspond to
214     ! the surface, that is : "bp" should be in descending order.
215     call new_unit(unit)
216     open(unit, file="hybrid.txt", status="old", action="read", &
217          position="rewind")
218     read(unit, fmt=*) ! skip title line
219     do l = 1, llm + 1
220        read(unit, fmt=*) ap(l), bp(l)
221     end do
222     close(unit)
223     call assert(ap(1) == 0., ap(llm + 1) == 0., bp(1) == 1., &
224          bp(llm + 1) == 0., "disvert: bad ap or bp values")
225  case default
226     call abort_gcm("disvert", 'Wrong value for "vert_sampling"', 1)
227  END select
228
229  DO l=1, llm
230     nivsigs(l) = REAL(l)
231  ENDDO
232
233  DO l=1, llmp1
234     nivsig(l)= REAL(l)
235  ENDDO
236
237  write(lunout, *)  trim(modname),': BP '
238  write(lunout, *) bp
239  write(lunout, *)  trim(modname),': AP '
240  write(lunout, *) ap
241
242  write(lunout, *) 'Niveaux de pressions approximatifs aux centres des'
243  write(lunout, *)'couches calcules pour une pression de surface =', preff
244  write(lunout, *) 'et altitudes equivalentes pour une hauteur d echelle de '
245  write(lunout, *) scaleheight,' km'
246  DO l = 1, llm
247     dpres(l) = bp(l) - bp(l+1)
248     presnivs(l) = 0.5 *( ap(l)+bp(l)*preff + ap(l+1)+bp(l+1)*preff )
249     write(lunout, *)'PRESNIVS(', l, ')=', presnivs(l), ' Z ~ ', &
250          log(preff/presnivs(l))*scaleheight &
251          , ' DZ ~ ', scaleheight*log((ap(l)+bp(l)*preff)/ &
252          max(ap(l+1)+bp(l+1)*preff, 1.e-10))
253  ENDDO
254
255  write(lunout, *) trim(modname),': PRESNIVS '
256  write(lunout, *) presnivs
257
258CONTAINS
259
260!-------------------------------------------------------------------------------
261!
262FUNCTION ridders(sig) RESULT(sg)
263!
264!-------------------------------------------------------------------------------
265  IMPLICIT NONE
266!-------------------------------------------------------------------------------
267! Purpose: Search for s solving (Pa/Preff)*s+(1-Pa/Preff)*EXP(1-1./s**2)=sg
268! Notes:   Uses Ridders' method, quite robust. Initial bracketing: 0<=sg<=1.
269! Reference: Ridders, C. F. J. "A New Algorithm for Computing a Single Root of a
270!       Real Continuous Function" IEEE Trans. Circuits Systems 26, 979-980, 1979
271!-------------------------------------------------------------------------------
272! Arguments:
273  REAL, INTENT(IN)  :: sig(:)
274  REAL              :: sg(SIZE(sig))
275!-------------------------------------------------------------------------------
276! Local variables:
277  INTEGER :: it, ns, maxit
278  REAL :: c1, c2, x1, x2, x3, x4, f1, f2, f3, f4, s, xx, distrib
279!-------------------------------------------------------------------------------
280  ns=SIZE(sig); maxit=9999
281  c1=Pa/Preff; c2=1.-c1
282  DO l=1,ns
283    xx=HUGE(1.)
284    x1=0.0; f1=distrib(x1,c1,c2,sig(l))
285    x2=1.0; f2=distrib(x2,c1,c2,sig(l))
286    DO it=1,maxit
287      x3=0.5*(x1+x2); f3=distrib(x3,c1,c2,sig(l))
288      s=SQRT(f3**2-f1*f2);                 IF(s==0.) EXIT
289      x4=x3+(x3-x1)*(SIGN(1.,f1-f2)*f3/s); IF(ABS(10.*LOG(x4-xx))<=1E-5) EXIT
290      xx=x4; f4=distrib(x4,c1,c2,sig(l));  IF(f4==0.) EXIT
291      IF(SIGN(f3,f4)/=f3) THEN;      x1=x3; f1=f3; x2=xx; f2=f4
292      ELSE IF(SIGN(f1,f4)/=f1) THEN; x2=xx; f2=f4
293      ELSE IF(SIGN(f2,f4)/=f2) THEN; x1=xx; f1=f4
294      ELSE; CALL abort_gcm("ridders",'Algorithm failed (which is odd...')
295      END IF
296      IF(ABS(10.*LOG(ABS(x2-x1)))<=1E-5) EXIT       !--- ERROR ON SIG <= 0.01m           
297    END DO
298    IF(it==maxit+1) WRITE(lunout,'(a,i3)')'WARNING in ridder: failed to converg&
299     &e for level ',l
300    sg(l)=xx
301  END DO
302  sg(1)=1.; sg(ns)=0.
303
304END FUNCTION ridders
305
306END SUBROUTINE disvert
307
308!-------------------------------------------------------------------------------
309
310FUNCTION distrib(x,c1,c2,x0) RESULT(res)
311!
312!-------------------------------------------------------------------------------
313! Arguments:
314  REAL, INTENT(IN) :: x, c1, c2, x0
315  REAL             :: res
316!-------------------------------------------------------------------------------
317  res=c1*x+c2*EXP(1-1/(x**2))-x0
318
319END FUNCTION distrib
320
321
Note: See TracBrowser for help on using the repository browser.