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

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

Simplify the management of the module.

YM

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