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