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

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

Preliminary modifs for the optical coupling of haze
+ Moved inits of setspi/v before init of mufi
+ Added access to tarcers in optci/v
+ Some coherence in call to directories
JVO

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