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