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

Last change on this file since 1899 was 1897, checked in by jvatant, 7 years ago

Making Titan's hazy again - part II
+ Major updates of J.Burgalat YAMMS library and optical coupling, including :
++ Added the routines for haze optics inside YAMMS
++ Calling rad. transf. with interactive haze is plugged
in but should stay unactive as long as the microphysics is
in test phase : cf "uncoupl_optic_haze" flag : true for now !
++ Also some sanity checks for negative tendencies and
some others upkeep of YAMMS model
+ Also added a temporary CPP key USE_QTEST in physiq_mod
that enables to have microphysical tendencies separated
from dynamics for debugging and test phases
-- JVO and JB

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