source: trunk/LMDZ.PLUTO/libf/phypluto/soil.F90 @ 3978

Last change on this file since 3978 was 3940, checked in by tbertrand, 2 months ago

PLUTO PCM :
Preparing for Triton simulations, implementation of internal heat flux and new North-South convention for the subsolar point
TB

File size: 8.1 KB
Line 
1      subroutine soil(ngrid,nsoil,firstcall,lastcall,   &
2               therm_i, &
3               timestep,tsurf,tsoil,    &
4               capcal,fluxgrd)
5
6      use comsoil_h, only: layer, mlayer, volcapa, inertiedat
7      use comcstfi_mod, only: pi
8      use time_phylmdz_mod, only: daysec
9      use planete_mod, only: year_day
10      use geometry_mod, only: longitude, latitude ! in radians
11      use callkeys_mod, only: changeti,fluxgeo,fluxgeo2,patchflux,assymflux
12
13      implicit none
14
15!-----------------------------------------------------------------------
16!  Author: Ehouarn Millour
17!
18!  Purpose: Compute soil temperature using an implict 1st order scheme
19!
20!  Note: depths of layers and mid-layers, soil thermal inertia and
21!        heat capacity are commons in comsoil.h
22!-----------------------------------------------------------------------
23
24!-----------------------------------------------------------------------
25!  arguments
26!  ---------
27!  inputs:
28      integer,intent(in) :: ngrid       ! number of (horizontal) grid-points
29      integer,intent(in) :: nsoil       ! number of soil layers
30      logical,intent(in) :: firstcall ! identifier for initialization call
31      logical,intent(in) :: lastcall
32      real,intent(in) :: therm_i(ngrid,nsoil) ! thermal inertia
33      real,intent(in) :: timestep           ! time step
34      real,intent(in) :: tsurf(ngrid)   ! surface temperature
35! outputs:
36      real,intent(out) :: tsoil(ngrid,nsoil) ! soil (mid-layer) temperature
37      real,intent(out) :: capcal(ngrid) ! surface specific heat
38      real,intent(out) :: fluxgrd(ngrid) ! surface diffusive heat flux
39
40! local saved variables:
41      real,dimension(:,:),save,allocatable :: mthermdiff ! mid-layer thermal diffusivity
42      real,dimension(:,:),save,allocatable :: thermdiff ! inter-layer thermal diffusivity
43      real,dimension(:),save,allocatable :: coefq ! q_{k+1/2} coefficients
44      real,dimension(:,:),save,allocatable :: coefd ! d_k coefficients
45      real,dimension(:,:),save,allocatable :: alph ! alpha_k coefficients
46      real,dimension(:,:),save,allocatable :: beta ! beta_k coefficients
47      real,save :: mu
48!$OMP THREADPRIVATE(mthermdiff,thermdiff,coefq,coefd,alph,beta,mu)
49
50! local variables:
51      integer ig,ik
52
53! 0. Initialisations and preprocessing step
54      if (firstcall) then
55      ! note: firstcall is set to .true. or .false. by the caller
56      !       and not changed by soil.F
57
58        ALLOCATE(mthermdiff(ngrid,0:nsoil-1)) ! mid-layer thermal diffusivity
59        ALLOCATE(thermdiff(ngrid,nsoil-1))    ! inter-layer thermal diffusivity
60        ALLOCATE(coefq(0:nsoil-1))              ! q_{k+1/2} coefficients
61        ALLOCATE(coefd(ngrid,nsoil-1))        ! d_k coefficients
62        ALLOCATE(alph(ngrid,nsoil-1))         ! alpha_k coefficients
63        ALLOCATE(beta(ngrid,nsoil-1))         ! beta_k coefficients
64
65        ! 0.05 Build coefficients mu, q_{k+1/2}, d_k, alpha_k and capcal
66        ! mu
67        mu=mlayer(0)/(mlayer(1)-mlayer(0))
68
69        ! q_{1/2}
70        coefq(0)=volcapa*layer(1)/timestep
71        ! q_{k+1/2}
72        do ik=1,nsoil-1
73          coefq(ik)=volcapa*(layer(ik+1)-layer(ik)) &
74                      /timestep
75        enddo
76      endif
77
78      if (firstcall.or.changeti) then
79! 0.1 Build mthermdiff(:), the mid-layer thermal diffusivities
80      do ig=1,ngrid
81        do ik=0,nsoil-1
82          mthermdiff(ig,ik)=therm_i(ig,ik+1)*therm_i(ig,ik+1)/volcapa
83          !write(*,*),'soil: ik: ',ik,' mthermdiff:',mthermdiff(ig,ik)
84        enddo
85      enddo
86
87! 0.2 Build thermdiff(:), the "interlayer" thermal diffusivities
88      do ig=1,ngrid
89        do ik=1,nsoil-1
90      thermdiff(ig,ik)=((layer(ik)-mlayer(ik-1))*mthermdiff(ig,ik)  &
91                     +(mlayer(ik)-layer(ik))*mthermdiff(ig,ik-1))   &
92                         /(mlayer(ik)-mlayer(ik-1))
93!       write(*,*),'soil: ik: ',ik,' thermdiff:',thermdiff(ig,ik)
94        enddo
95      enddo
96
97! 0.3 Build coefficients d_k, alpha_k and capcal
98      do ig=1,ngrid
99        ! d_k
100        do ik=1,nsoil-1
101          coefd(ig,ik)=thermdiff(ig,ik)/(mlayer(ik)-mlayer(ik-1))
102        enddo
103
104        ! alph_{N-1}
105        alph(ig,nsoil-1)=coefd(ig,nsoil-1)/ &
106                       (coefq(nsoil-1)+coefd(ig,nsoil-1))
107        ! alph_k
108        do ik=nsoil-2,1,-1
109          alph(ig,ik)=coefd(ig,ik)/(coefq(ik)+coefd(ig,ik+1)*   &
110                                   (1.-alph(ig,ik+1))+coefd(ig,ik))
111        enddo
112
113        ! capcal
114! Cstar
115        capcal(ig)=volcapa*layer(1)+    &
116                   (thermdiff(ig,1)/(mlayer(1)-mlayer(0)))* &
117                   (timestep*(1.-alph(ig,1)))
118! Cs
119        capcal(ig)=capcal(ig)/(1.+mu*(1.0-alph(ig,1))*  &
120                              thermdiff(ig,1)/mthermdiff(ig,0))
121      !write(*,*)'soil: ig=',ig,' capcal(ig)=',capcal(ig)
122      enddo ! of do ig=1,ngrid
123
124      endif ! of if (firstcall)
125
126      if (.not.firstcall) then
127
128!  1. Compute soil temperatures
129! First layer:
130      do ig=1,ngrid
131        tsoil(ig,1)=(tsurf(ig)+mu*beta(ig,1)*   &
132                              thermdiff(ig,1)/mthermdiff(ig,0))/    &
133                   (1.+mu*(1.0-alph(ig,1))* &
134                    thermdiff(ig,1)/mthermdiff(ig,0))
135      enddo
136! Other layers:
137      do ik=1,nsoil-1
138        do ig=1,ngrid
139          tsoil(ig,ik+1)=alph(ig,ik)*tsoil(ig,ik)+beta(ig,ik)
140        enddo
141      enddo
142
143! Flux at the bottom
144      do ig=1,ngrid
145
146       if (assymflux) then
147         if ( (latitude(ig)*180./pi.le.90.).and. &
148                (latitude(ig)*180./pi.ge.0.)  ) then
149            tsoil(ig,nsoil) = tsoil(ig,nsoil)  &
150            + timestep*fluxgeo2/(volcapa*(layer(nsoil)-layer(nsoil-1)))
151         else   
152            tsoil(ig,nsoil) = tsoil(ig,nsoil) &
153            + timestep*fluxgeo/(volcapa*(layer(nsoil)-layer(nsoil-1)))
154         endif
155
156       elseif(patchflux.eq.1) then
157         if ( (longitude(ig)*180./pi.le.180.).and.(longitude(ig)*180./pi.ge.174.) &
158         .and.(((latitude(ig)*180./pi.le.46.).and.(latitude(ig)*180./pi.ge.42.)) &
159         .or.  ((latitude(ig)*180./pi.le.36.).and.(latitude(ig)*180./pi.ge.32.)) &
160         .or.  ((latitude(ig)*180./pi.le.26.).and.(latitude(ig)*180./pi.ge.22.)) &
161         .or.  ((latitude(ig)*180./pi.le.16.).and.(latitude(ig)*180./pi.ge.12.)) &
162         .or.  ((latitude(ig)*180./pi.le.6.).and.(latitude(ig)*180./pi.ge.2.)) &
163                ) ) then
164            tsoil(ig,nsoil) = tsoil(ig,nsoil) &
165            + timestep*fluxgeo2/(volcapa*(layer(nsoil)-layer(nsoil-1)))
166         else   
167            tsoil(ig,nsoil) = tsoil(ig,nsoil) &
168             + timestep*fluxgeo/(volcapa*(layer(nsoil)-layer(nsoil-1)))
169         endif
170
171       else
172         tsoil(ig,nsoil) = tsoil(ig,nsoil) &
173         + timestep*fluxgeo/(volcapa*(layer(nsoil)-layer(nsoil-1)))
174
175       endif
176      enddo
177
178      endif! of if (firstcall)
179
180!  2. Compute beta coefficients (preprocessing for next time step)
181! Bottom layer, beta_{N-1}
182      do ig=1,ngrid
183        beta(ig,nsoil-1)=coefq(nsoil-1)*tsoil(ig,nsoil) &
184                        /(coefq(nsoil-1)+coefd(ig,nsoil-1))
185      enddo
186! Other layers
187      do ik=nsoil-2,1,-1
188        do ig=1,ngrid
189          beta(ig,ik)=(coefq(ik)*tsoil(ig,ik+1)+    &
190                      coefd(ig,ik+1)*beta(ig,ik+1))/    &
191                      (coefq(ik)+coefd(ig,ik+1)*(1.0-alph(ig,ik+1)) &
192                       +coefd(ig,ik))
193        enddo
194      enddo
195
196
197!  3. Compute surface diffusive flux & calorific capacity
198      do ig=1,ngrid
199! Cstar
200!        capcal(ig)=volcapa(ig,1)*layer(ig,1)+
201!     &              (thermdiff(ig,1)/(mlayer(ig,1)-mlayer(ig,0)))*
202!     &              (timestep*(1.-alph(ig,1)))
203! Fstar
204
205!         print*,'this far in soil 1'
206!         print*,'thermdiff=',thermdiff(ig,1)
207!         print*,'mlayer=',mlayer
208!         print*,'beta=',beta(ig,1)
209!         print*,'alph=',alph(ig,1)
210!         print*,'tsoil=',tsoil(ig,1)
211
212        fluxgrd(ig)=(thermdiff(ig,1)/(mlayer(1)-mlayer(0)))*    &
213                   (beta(ig,1)+(alph(ig,1)-1.0)*tsoil(ig,1))
214
215!        mu=mlayer(ig,0)/(mlayer(ig,1)-mlayer(ig,0))
216!        capcal(ig)=capcal(ig)/(1.+mu*(1.0-alph(ig,1))*
217!     &                         thermdiff(ig,1)/mthermdiff(ig,0))
218! Fs
219        fluxgrd(ig)=fluxgrd(ig)+(capcal(ig)/timestep)*  &
220                   (tsoil(ig,1)*(1.+mu*(1.0-alph(ig,1))*    &
221                              thermdiff(ig,1)/mthermdiff(ig,0)) &
222                    -tsurf(ig)-mu*beta(ig,1)*   &
223                               thermdiff(ig,1)/mthermdiff(ig,0))
224      enddo
225
226      end
227
Note: See TracBrowser for help on using the repository browser.