source: codes/icosagcm/trunk/src/timeloop_gcm.f90 @ 36

Last change on this file since 36 was 32, checked in by ymipsl, 12 years ago

externalize earth constant in run.def and add scalling factor functionnality

YM

File size: 8.2 KB
Line 
1MODULE timeloop_gcm_mod
2
3 
4CONTAINS
5 
6  SUBROUTINE timeloop
7  USE icosa
8  USE dissip_gcm_mod
9  USE caldyn_mod
10  USE theta2theta_rhodz_mod
11  USE etat0_mod
12  USE guided_mod
13  USE advect_tracer_mod
14 
15  IMPLICIT NONE
16  TYPE(t_field),POINTER :: f_phis(:)
17  TYPE(t_field),POINTER :: f_theta(:)
18  TYPE(t_field),POINTER :: f_q(:)
19  TYPE(t_field),POINTER :: f_dtheta(:)
20  TYPE(t_field),POINTER :: f_ps(:),f_psm1(:), f_psm2(:)
21  TYPE(t_field),POINTER :: f_u(:),f_um1(:),f_um2(:)
22  TYPE(t_field),POINTER :: f_theta_rhodz(:),f_theta_rhodzm1(:),f_theta_rhodzm2(:)
23  TYPE(t_field),POINTER :: f_dps(:),f_dpsm1(:), f_dpsm2(:)
24  TYPE(t_field),POINTER :: f_du(:),f_dum1(:),f_dum2(:)
25  TYPE(t_field),POINTER :: f_dtheta_rhodz(:),f_dtheta_rhodzm1(:),f_dtheta_rhodzm2(:)
26
27  REAL(rstd),POINTER :: phis(:)
28  REAL(rstd),POINTER :: q(:,:,:)
29  REAL(rstd),POINTER :: ps(:) ,psm1(:), psm2(:)
30  REAL(rstd),POINTER :: u(:,:) , um1(:,:), um2(:,:)
31  REAL(rstd),POINTER :: theta_rhodz(:,:) , theta_rhodzm1(:,:), theta_rhodzm2(:,:)
32  REAL(rstd),POINTER :: dps(:), dpsm1(:), dpsm2(:)
33  REAL(rstd),POINTER :: du(:,:), dum1(:,:), dum2(:,:)
34  REAL(rstd),POINTER :: dtheta_rhodz(:,:),dtheta_rhodzm1(:,:),dtheta_rhodzm2(:,:)
35  REAL(rstd) :: dt
36  INTEGER :: ind
37  INTEGER :: it,i,j,n
38  CHARACTER(len=255) :: scheme
39  INTEGER :: matsuno_period
40  INTEGER :: itaumax
41  INTEGER :: write_period 
42  INTEGER :: itau_out
43
44  dt=90.
45  CALL getin('dt',dt)
46  dt=dt/scale_factor
47 
48  itaumax=100
49  CALL getin('itaumax',itaumax)
50
51  write_period=0
52  CALL getin('write_period',write_period)
53  write_period=write_period/scale_factor
54 
55  itau_out=INT(write_period/dt)
56 
57  scheme='adam_bashforth'
58  CALL getin('scheme',scheme)
59 
60  matsuno_period=5
61  CALL getin('matsuno_period',matsuno_period)
62  IF (TRIM(scheme)=='leapfrog') matsuno_period=itaumax+1
63
64  CALL allocate_field(f_phis,field_t,type_real)
65 
66  CALL allocate_field(f_ps,field_t,type_real)
67  CALL allocate_field(f_psm1,field_t,type_real)
68  CALL allocate_field(f_psm2,field_t,type_real)
69  CALL allocate_field(f_dps,field_t,type_real)
70  CALL allocate_field(f_dpsm1,field_t,type_real)
71  CALL allocate_field(f_dpsm2,field_t,type_real)
72
73  CALL allocate_field(f_u,field_u,type_real,llm)
74  CALL allocate_field(f_um1,field_u,type_real,llm)
75  CALL allocate_field(f_um2,field_u,type_real,llm)
76  CALL allocate_field(f_du,field_u,type_real,llm)
77  CALL allocate_field(f_dum1,field_u,type_real,llm)
78  CALL allocate_field(f_dum2,field_u,type_real,llm)
79
80  CALL allocate_field(f_theta,field_t,type_real,llm)
81  CALL allocate_field(f_dtheta,field_t,type_real,llm)
82
83  CALL allocate_field(f_q,field_t,type_real,llm,nqtot)
84
85  CALL allocate_field(f_theta_rhodz,field_t,type_real,llm)
86  CALL allocate_field(f_theta_rhodzm1,field_t,type_real,llm)
87  CALL allocate_field(f_theta_rhodzm2,field_t,type_real,llm)
88  CALL allocate_field(f_dtheta_rhodz,field_t,type_real,llm)
89  CALL allocate_field(f_dtheta_rhodzm1,field_t,type_real,llm)
90  CALL allocate_field(f_dtheta_rhodzm2,field_t,type_real,llm)
91
92  CALL init_dissip(dt)
93  CALL init_caldyn(dt)
94  CALL init_guided(dt)
95  CALL init_advect_tracer(dt)
96 
97  CALL etat0(f_ps,f_phis,f_theta_rhodz,f_u, f_q)
98 
99  CALL writefield('ps',f_ps)
100  CALL writefield('theta_rhodz',f_theta_rhodz)
101 
102  DO it=0,itaumax
103    PRINT *,"It No :",It
104
105    CALL guided(it*dt,f_ps,f_theta_rhodz,f_u,f_q)
106    CALL caldyn(it,f_phis,f_ps,f_theta_rhodz,f_u, f_dps, f_dtheta_rhodz, f_du)
107    CALL advect_tracer(f_ps,f_u,f_q)
108   
109    SELECT CASE (TRIM(scheme))
110      CASE('euler')
111        CALL  euler_scheme
112
113      CASE ('leapfrog')
114        CALL leapfrog_scheme
115
116      CASE ('leapfrog_matsuno')
117        CALL  leapfrog_matsuno_scheme
118
119      CASE ('adam_bashforth')
120        CALL dissip(f_u,f_du,f_ps,f_theta_rhodz,f_dtheta_rhodz)
121        CALL adam_bashforth_scheme
122
123      CASE default
124        PRINT*,'Bad selector for variable scheme : <', TRIM(scheme),             &
125               ' > options are <euler>, <leapfrog>, <leapfrog_matsuno>, <adam_bashforth>'
126        STOP
127       
128    END SELECT
129
130   
131    IF ( itau_out>0 .AND. MOD(it,itau_out)==0) THEN
132      CALL writefield("q",f_q)
133      CALL writefield("ps",f_ps)
134    ENDIF
135
136  ENDDO
137 
138  CONTAINS
139
140    SUBROUTINE Euler_scheme
141    IMPLICIT NONE
142      INTEGER :: ind
143     
144      DO ind=1,ndomain
145        ps=f_ps(ind) ; u=f_u(ind) ; theta_rhodz=f_theta_rhodz(ind)
146        dps=f_dps(ind) ; du=f_du(ind) ; dtheta_rhodz=f_dtheta_rhodz(ind)
147        ps(:)=ps(:)+dt*dps(:)
148        u(:,:)=u(:,:)+dt*du(:,:)
149        theta_rhodz(:,:)=theta_rhodz(:,:)+dt*dtheta_rhodz(:,:)
150      ENDDO
151     
152    END SUBROUTINE Euler_scheme
153   
154    SUBROUTINE leapfrog_scheme
155    IMPLICIT NONE
156      INTEGER :: ind
157
158      DO ind=1,ndomain
159        ps=f_ps(ind)   ; u=f_u(ind)   ; theta_rhodz=f_theta_rhodz(ind)
160        psm1=f_psm1(ind) ; um1=f_um1(ind) ; theta_rhodzm1=f_theta_rhodzm1(ind)
161        psm2=f_psm2(ind) ; um2=f_um2(ind) ; theta_rhodzm2=f_theta_rhodzm2(ind)
162        dps=f_dps(ind) ; du=f_du(ind) ; dtheta_rhodz=f_dtheta_rhodz(ind)
163
164        IF (it==0) THEN
165          psm2(:)=ps(:) ; theta_rhodzm2(:,:)=theta_rhodz(:,:) ; um2(:,:)=u(:,:) 
166
167          ps(:)=ps(:)+dt*dps(:)
168          u(:,:)=u(:,:)+dt*du(:,:)
169          theta_rhodz(:,:)=theta_rhodz(:,:)+dt*dtheta_rhodz(:,:)
170
171          psm1(:)=ps(:) ; theta_rhodzm1(:,:)=theta_rhodz(:,:) ; um1(:,:)=u(:,:) 
172        ELSE
173       
174          ps(:)=psm2(:)+2*dt*dps(:)
175          u(:,:)=um2(:,:)+2*dt*du(:,:)
176          theta_rhodz(:,:)=theta_rhodzm2(:,:)+2*dt*dtheta_rhodz(:,:)
177
178          psm2(:)=psm1(:) ; theta_rhodzm2(:,:)=theta_rhodzm1(:,:) ; um2(:,:)=um1(:,:) 
179          psm1(:)=ps(:) ; theta_rhodzm1(:,:)=theta_rhodz(:,:) ; um1(:,:)=u(:,:) 
180        ENDIF
181         
182      ENDDO
183    END SUBROUTINE leapfrog_scheme 
184 
185    SUBROUTINE leapfrog_matsuno_scheme
186    IMPLICIT NONE
187      INTEGER :: ind
188
189      DO ind=1,ndomain
190        ps=f_ps(ind)   ; u=f_u(ind)   ; theta_rhodz=f_theta_rhodz(ind)
191        psm1=f_psm1(ind) ; um1=f_um1(ind) ; theta_rhodzm1=f_theta_rhodzm1(ind)
192        psm2=f_psm2(ind) ; um2=f_um2(ind) ; theta_rhodzm2=f_theta_rhodzm2(ind)
193        dps=f_dps(ind) ; du=f_du(ind) ; dtheta_rhodz=f_dtheta_rhodz(ind)
194
195       
196        IF (MOD(it,matsuno_period+1)==0) THEN
197          psm1(:)=ps(:) ; um1(:,:)=u(:,:) ; theta_rhodzm1(:,:)=theta_rhodz(:,:)
198          ps(:)=psm1(:)+dt*dps(:)
199          u(:,:)=um1(:,:)+dt*du(:,:)
200          theta_rhodz(:,:)=theta_rhodzm1(:,:)+dt*dtheta_rhodz(:,:)
201
202        ELSE IF (MOD(it,matsuno_period+1)==1) THEN
203
204          ps(:)=psm1(:)+dt*dps(:)
205          u(:,:)=um1(:,:)+dt*du(:,:)
206          theta_rhodz(:,:)=theta_rhodzm1(:,:)+dt*dtheta_rhodz(:,:)
207
208          psm2(:)=psm1(:) ; theta_rhodzm2(:,:)=theta_rhodzm1(:,:) ; um2(:,:)=um1(:,:) 
209          psm1(:)=ps(:) ; theta_rhodzm1(:,:)=theta_rhodz(:,:) ; um1(:,:)=u(:,:) 
210
211        ELSE
212
213          ps(:)=psm2(:)+2*dt*dps(:)
214          u(:,:)=um2(:,:)+2*dt*du(:,:)
215          theta_rhodz(:,:)=theta_rhodzm2(:,:)+2*dt*dtheta_rhodz(:,:)
216
217          psm2(:)=psm1(:) ; theta_rhodzm2(:,:)=theta_rhodzm1(:,:) ; um2(:,:)=um1(:,:) 
218          psm1(:)=ps(:) ; theta_rhodzm1(:,:)=theta_rhodz(:,:) ; um1(:,:)=u(:,:) 
219
220        ENDIF
221     
222      ENDDO
223     
224    END SUBROUTINE leapfrog_matsuno_scheme 
225         
226    SUBROUTINE adam_bashforth_scheme
227    IMPLICIT NONE
228      INTEGER :: ind
229
230      DO ind=1,ndomain
231        ps=f_ps(ind)   ; u=f_u(ind)   ; theta_rhodz=f_theta_rhodz(ind)
232        dps=f_dps(ind) ; du=f_du(ind) ; dtheta_rhodz=f_dtheta_rhodz(ind)
233        dpsm1=f_dpsm1(ind) ; dum1=f_dum1(ind) ; dtheta_rhodzm1=f_dtheta_rhodzm1(ind)
234        dpsm2=f_dpsm2(ind) ; dum2=f_dum2(ind) ; dtheta_rhodzm2=f_dtheta_rhodzm2(ind)
235
236        IF (it==0) THEN
237          dpsm1(:)=dps(:) ; dum1(:,:)=du(:,:) ; dtheta_rhodzm1(:,:)=dtheta_rhodz(:,:)
238          dpsm2(:)=dpsm1(:) ; dum2(:,:)=dum1(:,:) ; dtheta_rhodzm2(:,:)=dtheta_rhodzm1(:,:)
239        ENDIF
240             
241        ps(:)=ps(:)+dt*(23*dps(:)-16*dpsm1(:)+5*dpsm2(:))/12
242        u(:,:)=u(:,:)+dt*(23*du(:,:)-16*dum1(:,:)+5*dum2(:,:))/12
243        theta_rhodz(:,:)=theta_rhodz(:,:)+dt*(23*dtheta_rhodz(:,:)-16*dtheta_rhodzm1(:,:)+5*dtheta_rhodzm2(:,:))/12
244
245        dpsm2(:)=dpsm1(:) ; dum2(:,:)=dum1(:,:) ; dtheta_rhodzm2(:,:)=dtheta_rhodzm1(:,:)
246        dpsm1(:)=dps(:) ; dum1(:,:)=du(:,:) ; dtheta_rhodzm1(:,:)=dtheta_rhodz(:,:)
247
248      ENDDO
249     
250     
251    END SUBROUTINE adam_bashforth_scheme
252
253  END SUBROUTINE timeloop
254   
255   
256 
257END MODULE timeloop_gcm_mod
Note: See TracBrowser for help on using the repository browser.