source: trunk/LMDZ.TITAN/libf/phytitan/optcv.F90 @ 3026

Last change on this file since 3026 was 2366, checked in by jvatant, 5 years ago

Titan GCM : Major maintenance catching up commits from the generic including :

  • r2356 and 2354 removing obsolete old dynamical core
  • various minor addition to physics and gestion of phys_state_var_mode, especially in dyn1d
  • adding MESOSCALE CPP keys around chemistry and microphysics (disabled in mesoscale for now)
  • Property svn:executable set to *
File size: 14.6 KB
Line 
1SUBROUTINE OPTCV(PQMO,NLAY,PLEV,TMID,PMID,  &
2     DTAUV,TAUV,TAUCUMV,WBARV,COSBV,TAURAY,TAUGSURF,SEASHAZEFACT)
3
4  use radinc_h
5  use radcommon_h, only: gasv,gasv_recomb,tlimit,Cmk,gzlat_ig, &
6                         tgasref,pfgasref,wnov,scalep,indv
7  use gases_h
8  use datafile_mod, only: haze_opt_file
9  use comcstfi_mod, only: r
10  use callkeys_mod, only: continuum,graybody,callgasvis,corrk_recombin,     &
11                          callclouds,callmufi,seashaze,uncoupl_optic_haze
12  use tracer_h, only: nmicro,nice
13
14  implicit none
15
16  !==================================================================
17  !     
18  !     Purpose
19  !     -------
20  !     Calculates shortwave optical constants at each level.
21  !     
22  !     Authors
23  !     -------
24  !     Adapted from the NASA Ames code by R. Wordsworth (2009)
25  !     Clean and adaptation to Titan by J. Vatant d'Ollone (2016-17)
26  !     
27  !==================================================================
28  !     
29  !     THIS SUBROUTINE SETS THE OPTICAL CONSTANTS IN THE VISUAL 
30  !     IT CALCULATES FOR EACH LAYER, FOR EACH SPECTRAL INTERVAL IN THE VISUAL
31  !     LAYER: WBAR, DTAU, COSBAR
32  !     LEVEL: TAU
33  !     
34  !     TAUV(L,NW,NG) is the cumulative optical depth at the top of radiation code
35  !     layer L. NW is spectral wavelength interval, ng the Gauss point index.
36  !     
37  !     TLEV(L) - Temperature at the layer boundary
38  !     PLEV(L) - Pressure at the layer boundary (i.e. level)
39  !     GASV(NT,NPS,NW,NG) - Visible k-coefficients
40  !     
41  !-------------------------------------------------------------------
42
43
44  !==========================================================
45  ! Input/Output
46  !==========================================================
47  REAL*8, INTENT(IN)  :: PQMO(nlay,nmicro)  ! Tracers for microphysics optics (X/m2).
48  INTEGER, INTENT(IN) :: NLAY               ! Number of pressure layers (for pqmo)
49  REAL*8, INTENT(IN)  :: PLEV(L_LEVELS)
50  REAL*8, INTENT(IN)  :: TMID(L_LEVELS), PMID(L_LEVELS)
51  REAL*8, INTENT(IN)  :: TAURAY(L_NSPECTV)
52  REAL*8, INTENT(IN)  :: SEASHAZEFACT(L_LEVELS)
53 
54  REAL*8, INTENT(OUT) :: DTAUV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
55  REAL*8, INTENT(OUT) :: TAUV(L_NLEVRAD,L_NSPECTV,L_NGAUSS)
56  REAL*8, INTENT(OUT) :: TAUCUMV(L_LEVELS,L_NSPECTV,L_NGAUSS)
57  REAL*8, INTENT(OUT) :: COSBV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
58  REAL*8, INTENT(OUT) :: WBARV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
59  REAL*8, INTENT(OUT) :: TAUGSURF(L_NSPECTV,L_NGAUSS-1)
60  ! ==========================================================
61 
62  real*8 DTAUKV(L_LEVELS,L_NSPECTV,L_NGAUSS)
63
64  ! Titan customisation
65  ! J. Vatant d'Ollone (2016)
66  real*8 DHAZE_T(L_LEVELS,L_NSPECTI)
67  real*8 DHAZES_T(L_LEVELS,L_NSPECTI)
68  real*8 SSA_T(L_LEVELS,L_NSPECTI)
69  real*8 ASF_T(L_LEVELS,L_NSPECTI)
70  ! ==========================
71
72  integer L, NW, NG, K, LK, IAER
73  integer MT(L_LEVELS), MP(L_LEVELS), NP(L_LEVELS)
74  real*8  ANS, TAUGAS
75  real*8  TRAY(L_LEVELS,L_NSPECTV)
76  real*8  DPR(L_LEVELS), U(L_LEVELS)
77  real*8  LCOEF(4), LKCOEF(L_LEVELS,4)
78
79  real*8 DCONT
80  real*8 DRAYAER
81  double precision wn_cont, p_cont, p_air, T_cont, dtemp, dtempc
82  double precision p_cross
83
84  real*8  KCOEF(4)
85 
86  ! temporary variable to reduce memory access time to gasv
87  real*8 tmpk(2,2)
88
89  ! temporary variables for multiple aerosol calculation
90  real*8 atemp(L_NLAYRAD,L_NSPECTV)
91  real*8 btemp(L_NLAYRAD,L_NSPECTV)
92  real*8 ctemp(L_NLAYRAD,L_NSPECTV)
93
94  ! variables for k in units m^-1
95  real*8 dz(L_LEVELS)
96
97  integer igas, jgas, ilay
98
99  integer interm
100
101  ! Variables for haze optics
102  character(len=200) file_path
103  logical file_ok
104  integer dumch
105  real*8  dumwvl
106
107  real*8 m3as,m3af
108  real*8 dtauaer_s,dtauaer_f
109  real*8,save :: rhoaer_s(L_NSPECTV),ssa_s(L_NSPECTV),asf_s(L_NSPECTV)
110  real*8,save :: rhoaer_f(L_NSPECTV),ssa_f(L_NSPECTV),asf_f(L_NSPECTV)
111!$OMP THREADPRIVATE(rhoaer_s,rhoaer_f,ssa_s,ssa_f,asf_s,asf_f)
112 
113  logical,save :: firstcall=.true.
114!$OMP THREADPRIVATE(firstcall)
115
116
117  !! AS: to save time in computing continuum (see bilinearbig)
118  IF (.not.ALLOCATED(indv)) THEN
119      ALLOCATE(indv(L_NSPECTV,ngasmx,ngasmx))
120      indv = -9999 ! this initial value means "to be calculated"
121  ENDIF
122 
123  ! Some initialisation beacause there's a pb with disr_haze at the limits (nw=1)
124  ! I should check this - For now we set vars to zero : better than nans - JVO 2017
125  DHAZE_T(:,:) = 0.0
126  SSA_T(:,:)   = 0.0
127  ASF_T(:,:)   = 0.0
128 
129  ! Load tabulated haze optical properties if needed.
130  ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131  IF (firstcall .AND. callmufi .AND. (.NOT. uncoupl_optic_haze)) THEN
132     OPEN(12,file=TRIM(haze_opt_file),form='formatted') ! The file has been inquired in physiq_mod firstcall
133     READ(12,*) ! dummy header
134     DO NW=1,L_NSPECTI
135       READ(12,*) ! there's IR 1st
136     ENDDO
137     DO NW=1,L_NSPECTV
138       READ(12,*) dumch, dumwvl, rhoaer_f(nw), ssa_f(nw), asf_f(nw), rhoaer_s(nw), ssa_s(nw), asf_s(nw)
139     ENDDO
140     CLOSE(12)
141  ENDIF
142
143  !=======================================================================
144  !     Determine the total gas opacity throughout the column, for each
145  !     spectral interval, NW, and each Gauss point, NG.
146  !     Calculate the continuum opacities, i.e., those that do not depend on
147  !     NG, the Gauss index.
148
149  taugsurf(:,:) = 0.0
150  dpr(:)        = 0.0
151  lkcoef(:,:)   = 0.0
152
153  do K=2,L_LEVELS
154 
155     ilay = L_NLAYRAD+1 - k/2 ! int. arithmetic => gives the gcm layer index (reversed)
156 
157     DPR(k) = PLEV(K)-PLEV(K-1)
158
159     ! if we have continuum opacities, we need dz
160
161      dz(k) = dpr(k)*R*TMID(K)/(gzlat_ig(ilay)*PMID(K))
162      U(k)  = Cmk(ilay)*DPR(k)     ! only Cmk line in optcv.F     
163
164     call tpindex(PMID(K),TMID(K),pfgasref,tgasref,LCOEF,MT(K),MP(K))
165
166     do LK=1,4
167        LKCOEF(K,LK) = LCOEF(LK)
168     end do
169  end do                    ! levels
170
171  ! Rayleigh scattering
172  do NW=1,L_NSPECTV
173     TRAY(1:4,NW)   = 1.d-30
174     do K=5,L_LEVELS
175        TRAY(K,NW)   = TAURAY(NW) * DPR(K)
176     end do                    ! levels
177  end do
178 
179  !     we ignore K=1...
180  do K=2,L_LEVELS
181 
182     ilay = L_NLAYRAD+1 - k/2 ! int. arithmetic => gives the gcm layer index (reversed)
183
184     do NW=1,L_NSPECTV
185     
186        IF (callmufi .AND. (.NOT. uncoupl_optic_haze)) THEN
187          m3as = pqmo(ilay,2) / 2.0
188          m3af = pqmo(ilay,4) / 2.0
189         
190          IF ( ilay .lt. 18 ) THEN
191            m3as = pqmo(18,2) / 2.0 * dz(k) / dz(18)
192            m3af = pqmo(18,4) / 2.0 * dz(k) / dz(18)
193          ENDIF
194
195          dtauaer_s     = m3as*rhoaer_s(nw)
196          dtauaer_f     = m3af*rhoaer_f(nw)
197          DHAZE_T(k,nw) = dtauaer_s + dtauaer_f
198
199          IF ( dtauaer_s + dtauaer_f .GT. 1.D-30 ) THEN
200            SSA_T(k,nw)   = ( dtauaer_s*ssa_s(nw) + dtauaer_f*ssa_f(nw) ) / ( dtauaer_s+dtauaer_f )
201            ASF_T(k,nw)   = ( dtauaer_s*ssa_s(nw)*asf_s(nw) + dtauaer_f*ssa_f(nw)*asf_f(nw) )  &
202                            / ( ssa_s(nw)*dtauaer_s + ssa_f(nw)*dtauaer_f )
203          ELSE
204             DHAZE_T(k,nw) = 0.D0
205             SSA_T(k,nw)   = 1.0
206             ASF_T(k,nw)   = 1.0
207          ENDIF
208         
209          IF (callclouds.and.firstcall) &
210            WRITE(*,*) 'WARNING: In optcv, optical properties &
211                       &calculations are not implemented yet'
212        ELSE
213          ! Call fixed vertical haze profile of extinction - same for all columns
214          call disr_haze(dz(k),plev(k),wnov(nw),DHAZE_T(k,nw),SSA_T(k,nw),ASF_T(k,nw))
215          if (seashaze) DHAZE_T(k,nw) = DHAZE_T(k,nw)*seashazefact(k)
216        ENDIF
217       
218        !JL18 It seems to be good to have aerosols in the first "radiative layer" of the gcm in the IR
219        !   but visible does not handle very well diffusion in first layer.
220        !   The tauaero and tauray are thus set to 0 (a small value for rayleigh because the code crashes otherwise)
221        !   in the 4 first semilayers in optcv, but not optci.
222        !   This solves random variations of the sw heating at the model top.
223        if (k<5)  DHAZE_T(K,:) = 0.0
224         
225        DRAYAER = TRAY(K,NW)
226        !     DRAYAER is Tau RAYleigh scattering, plus AERosol opacity
227        DRAYAER = DRAYAER + DHAZE_T(K,NW) ! Titan's aerosol
228
229        DCONT = 0.0 ! continuum absorption
230
231        if(continuum.and.(.not.graybody).and.callgasvis)then
232           ! include continua if necessary
233           wn_cont = dble(wnov(nw))
234           T_cont  = dble(TMID(k))
235           do igas=1,ngasmx
236
237              p_cont  = dble(PMID(k)*scalep*gfrac(igas,ilay))
238
239              dtemp=0.0
240              if(igas.eq.igas_N2)then
241
242                 interm = indv(nw,igas,igas)
243!                 call interpolateN2N2(wn_cont,T_cont,p_cont,dtemp,.false.,interm)
244                 indv(nw,igas,igas) = interm
245                 ! only goes to 500 cm^-1, so unless we're around a cold brown dwarf, this is irrelevant in the visible
246
247              elseif(igas.eq.igas_H2)then
248
249                 ! first do self-induced absorption
250                 interm = indv(nw,igas,igas)
251                 call interpolateH2H2(wn_cont,T_cont,p_cont,dtemp,.false.,interm)
252                 indv(nw,igas,igas) = interm
253
254                 ! then cross-interactions with other gases
255                 do jgas=1,ngasmx
256                    p_cross = dble(PMID(k)*scalep*gfrac(jgas,ilay))
257                    dtempc  = 0.0
258                    if(jgas.eq.igas_N2)then
259                       interm = indv(nw,igas,jgas)
260                       call interpolateN2H2(wn_cont,T_cont,p_cross,p_cont,dtempc,.false.,interm)
261                       indv(nw,igas,jgas) = interm
262                       ! should be irrelevant in the visible
263                    endif
264                    dtemp = dtemp + dtempc
265                 enddo
266
267               elseif(igas.eq.igas_CH4)then
268
269                 ! first do self-induced absorption
270                 interm = indv(nw,igas,igas)
271                 call interpolateCH4CH4(wn_cont,T_cont,p_cont,dtemp,.false.,interm)
272                 indv(nw,igas,igas) = interm
273
274                 ! then cross-interactions with other gases
275                 do jgas=1,ngasmx
276                    p_cross = dble(PMID(k)*scalep*gfrac(jgas,ilay))
277                    dtempc  = 0.0
278                    if(jgas.eq.igas_N2)then
279                       interm = indv(nw,igas,jgas)
280                       call interpolateN2CH4(wn_cont,T_cont,p_cross,p_cont,dtempc,.false.,interm)
281                       indv(nw,igas,jgas) = interm
282                    endif
283                    dtemp = dtemp + dtempc
284                 enddo
285
286              endif
287
288              DCONT = DCONT + dtemp
289
290           enddo
291
292           DCONT = DCONT*dz(k)
293
294        endif
295
296        do ng=1,L_NGAUSS-1
297
298           ! Now compute TAUGAS
299
300           ! JVO 2017 : added tmpk because the repeated calls to gasi/v increased dramatically
301           ! the execution time of optci/v -> ~ factor 2 on the whole radiative
302           ! transfer on the tested simulations !
303
304           if (corrk_recombin) then
305             tmpk = GASV_RECOMB(MT(K):MT(K)+1,MP(K):MP(K)+1,NW,NG)
306           else
307             tmpk = GASV(MT(K):MT(K)+1,MP(K):MP(K)+1,1,NW,NG)
308           endif
309             
310           KCOEF(1) = tmpk(1,1) ! KCOEF(1) = GASV(MT(K),MP(K),1,NW,NG)
311           KCOEF(2) = tmpk(1,2) ! KCOEF(2) = GASV(MT(K),MP(K)+1,1,NW,NG)
312           KCOEF(3) = tmpk(2,2) ! KCOEF(3) = GASV(MT(K)+1,MP(K)+1,1,NW,NG)
313           KCOEF(4) = tmpk(2,1) ! KCOEF(4) = GASV(MT(K)+1,MP(K),1,NW,NG)
314
315           ! Interpolate the gaseous k-coefficients to the requested T,P values
316
317           ANS = LKCOEF(K,1)*KCOEF(1) + LKCOEF(K,2)*KCOEF(2) +            &
318                LKCOEF(K,3)*KCOEF(3) + LKCOEF(K,4)*KCOEF(4)
319
320
321           TAUGAS  = U(k)*ANS
322
323           TAUGSURF(NW,NG) = TAUGSURF(NW,NG) + TAUGAS + DCONT
324           DTAUKV(K,nw,ng) = TAUGAS &
325                             + DRAYAER & ! DRAYAER includes all scattering contributions
326                             + DCONT ! For parameterized continuum aborption
327
328        end do
329
330        ! Now fill in the "clear" part of the spectrum (NG = L_NGAUSS),
331        ! which holds continuum opacity only
332
333        NG              = L_NGAUSS
334        DTAUKV(K,nw,ng) = DRAYAER + DCONT ! Scattering + parameterized continuum absorption, including Titan's haze
335
336     end do
337  end do
338
339
340  !=======================================================================
341  !     Now the full treatment for the layers, where besides the opacity
342  !     we need to calculate the scattering albedo and asymmetry factors
343  ! ======================================================================
344
345  ! Haze scattering
346            !JL18 It seems to be good to have aerosols in the first "radiative layer" of the gcm in the IR
347            !   but not in the visible
348            !   The dhaze_s is thus set to 0 in the 4 first semilayers in optcv, but not optci.
349            !   This solves random variations of the sw heating at the model top.
350  DO NW=1,L_NSPECTV
351    DHAZES_T(1:4,NW) = 0.d0
352    DO K=5,L_LEVELS
353      DHAZES_T(K,NW) = DHAZE_T(K,NW) * SSA_T(K,NW) ! effect of scattering albedo on haze
354    ENDDO
355  ENDDO
356
357
358  DO NW=1,L_NSPECTV
359     DO L=1,L_NLAYRAD-1
360        K              = 2*L+1
361        atemp(L,NW) = ASF_T(K,NW)*DHAZES_T(K,NW) + ASF_T(K+1,NW)*DHAZES_T(K+1,NW)
362        btemp(L,NW) = DHAZES_T(K,NW) + DHAZES_T(K+1,NW)
363        ctemp(L,NW) = btemp(L,NW) + 0.9999*(TRAY(K,NW) + TRAY(K+1,NW)) ! JVO 2017 : does this 0.999 is really meaningful ?
364        btemp(L,NW) = btemp(L,NW) + TRAY(K,NW) + TRAY(K+1,NW)
365        COSBV(L,NW,1:L_NGAUSS) = atemp(L,NW)/btemp(L,NW)
366     END DO ! L vertical loop
367     
368     ! Last level
369     L           = L_NLAYRAD
370     K           = 2*L+1
371     atemp(L,NW) = ASF_T(K,NW)*DHAZES_T(K,NW)
372     btemp(L,NW) = DHAZES_T(K,NW)
373     ctemp(L,NW) = btemp(L,NW) + 0.9999*TRAY(K,NW) ! JVO 2017 : does this 0.999 is really meaningful ?
374     btemp(L,NW) = btemp(L,NW) + TRAY(K,NW)
375     COSBV(L,NW,1:L_NGAUSS) = atemp(L,NW)/btemp(L,NW)
376     
377     
378  END DO                    ! NW spectral loop
379
380  DO NG=1,L_NGAUSS
381    DO NW=1,L_NSPECTV
382     DO L=1,L_NLAYRAD-1
383
384        K              = 2*L+1
385        DTAUV(L,nw,ng) = DTAUKV(K,NW,NG) + DTAUKV(K+1,NW,NG)
386        WBARV(L,nw,ng) = ctemp(L,NW) / DTAUV(L,nw,ng)
387
388      END DO ! L vertical loop
389
390        ! Last level
391
392        L              = L_NLAYRAD
393        K              = 2*L+1
394        DTAUV(L,nw,ng) = DTAUKV(K,NW,NG)
395
396        WBARV(L,NW,NG) = ctemp(L,NW) / DTAUV(L,NW,NG)
397
398     END DO                 ! NW spectral loop
399  END DO                    ! NG Gauss loop
400
401  ! Total extinction optical depths
402
403  DO NG=1,L_NGAUSS       ! full gauss loop
404     DO NW=1,L_NSPECTV       
405        TAUCUMV(1,NW,NG)=0.0D0
406        DO K=2,L_LEVELS
407           TAUCUMV(K,NW,NG)=TAUCUMV(K-1,NW,NG)+DTAUKV(K,NW,NG)
408        END DO
409
410        DO L=1,L_NLAYRAD
411           TAUV(L,NW,NG)=TAUCUMV(2*L,NW,NG)
412        END DO
413        TAUV(L,NW,NG)=TAUCUMV(2*L_NLAYRAD+1,NW,NG)
414     END DO           
415  END DO                 ! end full gauss loop
416
417  if(firstcall) firstcall = .false.
418
419  return
420
421
422end subroutine optcv
Note: See TracBrowser for help on using the repository browser.