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

Last change on this file since 1819 was 1792, checked in by jvatant, 8 years ago

+ Found a bug for the limit cases in disr_haze leading to uninit. value.

Fixed by init to zero but should be relooked at.

+ Also added omp instructions in disr_haze
--JVO

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