| 1 | PROGRAM testphys1d |
|---|
| 2 | |
|---|
| 3 | use comsoil_h, only: inertiedat, inertiesoil, nsoilmx, tsoil, nqsoil, qsoil |
|---|
| 4 | use surfdat_h, only: albedodat, perennial_co2ice, watercap, tsurf, emis, qsurf |
|---|
| 5 | use comslope_mod, only: def_slope, subslope_dist |
|---|
| 6 | use phyredem, only: physdem0, physdem1 |
|---|
| 7 | use watersat_mod, only: watersat |
|---|
| 8 | use tracer_mod, only: igcm_h2o_vap, igcm_h2o_ice, noms |
|---|
| 9 | use comcstfi_h, only: pi, g, rcp, cpp |
|---|
| 10 | use time_phylmdz_mod, only: daysec |
|---|
| 11 | use dimradmars_mod, only: tauvis, totcloudfrac, albedo |
|---|
| 12 | use dust_param_mod, only: tauscaling |
|---|
| 13 | use comvert_mod, only: ap, bp, aps, bps, pa, preff |
|---|
| 14 | use physiq_mod, only: physiq |
|---|
| 15 | use turb_mod, only: q2 |
|---|
| 16 | use write_output_mod, only: write_output |
|---|
| 17 | use ioipsl_getincom, only: getin ! To use 'getin' |
|---|
| 18 | use init_testphys1d_mod, only: init_testphys1d |
|---|
| 19 | use writerestart1D_mod, only: writerestart1D |
|---|
| 20 | use parse_args_mod, only: parse_args |
|---|
| 21 | use callkeys_mod, only: water |
|---|
| 22 | ! Mostly for XIOS outputs |
|---|
| 23 | use mod_const_mpi, only: init_const_mpi |
|---|
| 24 | use parallel_lmdz, only: init_parallel |
|---|
| 25 | |
|---|
| 26 | implicit none |
|---|
| 27 | |
|---|
| 28 | !======================================================================= |
|---|
| 29 | ! subject: |
|---|
| 30 | ! -------- |
|---|
| 31 | ! PROGRAM useful to run physical part of the martian GCM in a 1D column |
|---|
| 32 | ! |
|---|
| 33 | ! Can be compiled with a command like (e.g. for 25 layers) |
|---|
| 34 | ! "makegcm -p mars -d 25 testphys1d" |
|---|
| 35 | ! It requires the files "testphys1d.def" "callphys.def" |
|---|
| 36 | ! and a 'run.def' file (containing a "INCLUDEDEF=callphys.def" line) |
|---|
| 37 | ! and a file describing the sigma layers (e.g. "z2sig.def") |
|---|
| 38 | ! |
|---|
| 39 | ! author: Frederic Hourdin, R. Fournier, F. Forget |
|---|
| 40 | ! ------- |
|---|
| 41 | ! |
|---|
| 42 | ! update: 12/06/2003, including chemistry (S. Lebonnois) |
|---|
| 43 | ! and water ice (F. Montmessin) |
|---|
| 44 | ! 27/09/2023, upgrade to F90 (JB Clément) |
|---|
| 45 | ! |
|---|
| 46 | !======================================================================= |
|---|
| 47 | |
|---|
| 48 | include "dimensions.h" |
|---|
| 49 | |
|---|
| 50 | !-------------------------------------------------------------- |
|---|
| 51 | ! Declarations |
|---|
| 52 | !-------------------------------------------------------------- |
|---|
| 53 | integer, parameter :: ngrid = 1 ! (2+(jjm-1)*iim - 1/jjm) |
|---|
| 54 | integer, parameter :: nlayer = llm |
|---|
| 55 | real, parameter :: odpref = 610. ! DOD reference pressure (Pa) |
|---|
| 56 | integer :: ndt, ilayer, idt |
|---|
| 57 | logical :: firstcall, lastcall |
|---|
| 58 | integer :: day0 ! initial (sol ; =0 at Ls=0) |
|---|
| 59 | real :: day ! date during the run |
|---|
| 60 | real :: time ! time (0<time<1 ; time=0.5 a midi) |
|---|
| 61 | real :: dttestphys ! testphys1d timestep |
|---|
| 62 | real, dimension(nlayer) :: play ! Pressure at the middle of the layers (Pa) |
|---|
| 63 | real, dimension(nlayer + 1) :: plev ! intermediate pressure levels (Pa) |
|---|
| 64 | real :: psurf ! Surface pressure |
|---|
| 65 | real, dimension(nlayer) :: u, v ! zonal, meridional wind |
|---|
| 66 | real :: gru, grv ! prescribed "geostrophic" background wind |
|---|
| 67 | real, dimension(nlayer) :: temp ! temperature at the middle of the layers |
|---|
| 68 | real, dimension(:,:,:), allocatable :: q ! tracer mixing ratio (e.g. kg/kg) |
|---|
| 69 | real, dimension(1) :: wstar = 0. ! Thermals vertical velocity |
|---|
| 70 | |
|---|
| 71 | ! Physical and dynamical tendencies (e.g. m.s-2, K/s, Pa/s) |
|---|
| 72 | real, dimension(nlayer) :: du, dv, dtemp |
|---|
| 73 | real, dimension(1) :: dpsurf |
|---|
| 74 | real, dimension(:,:,:), allocatable :: dq, dqdyn |
|---|
| 75 | |
|---|
| 76 | ! Various intermediate variables |
|---|
| 77 | real :: zls, pks, ptif |
|---|
| 78 | real, dimension(nlayer) :: phi, h, s, w |
|---|
| 79 | integer :: nq = 1 ! number of tracers |
|---|
| 80 | real, dimension(1) :: latitude, longitude, cell_area |
|---|
| 81 | |
|---|
| 82 | ! Use of starting files for 1D |
|---|
| 83 | logical :: startfiles_1D, therestart1D, therestartfi, there |
|---|
| 84 | |
|---|
| 85 | ! Prescription of atmospheric water/ice profiles |
|---|
| 86 | logical :: ctrl_h2ovap, ctrl_h2oice |
|---|
| 87 | real :: relaxtime_h2ovap, relaxtime_h2oice |
|---|
| 88 | real, dimension(nlayer) :: qref_h2ovap, qref_h2oice |
|---|
| 89 | real, dimension(:), allocatable :: zqsat |
|---|
| 90 | !======================================================================= |
|---|
| 91 | |
|---|
| 92 | !======================================================================= |
|---|
| 93 | ! INITIALISATION |
|---|
| 94 | !======================================================================= |
|---|
| 95 | ! Parse command-line options |
|---|
| 96 | call parse_args() |
|---|
| 97 | |
|---|
| 98 | #ifdef CPP_XIOS |
|---|
| 99 | call init_const_mpi |
|---|
| 100 | call init_parallel |
|---|
| 101 | #endif |
|---|
| 102 | |
|---|
| 103 | ! Initialize "serial/parallel" related stuff |
|---|
| 104 | !call init_phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/)) |
|---|
| 105 | !call init_phys_lmdz(1,1,llm,1,(/1/)) |
|---|
| 106 | !call initcomgeomphy |
|---|
| 107 | |
|---|
| 108 | startfiles_1D = .false. |
|---|
| 109 | !------------------------------------------------------ |
|---|
| 110 | ! Loading run parameters from "run.def" file |
|---|
| 111 | !------------------------------------------------------ |
|---|
| 112 | ! check if 'run.def' file is around. Otherwise reading parameters |
|---|
| 113 | ! from callphys.def via getin() routine won't work. |
|---|
| 114 | inquire(file = 'run.def',exist = there) |
|---|
| 115 | if (.not. there) then |
|---|
| 116 | write(*,*) 'Cannot find required file "run.def"' |
|---|
| 117 | write(*,*) ' (which should contain some input parameters along with the following line: INCLUDEDEF=callphys.def)' |
|---|
| 118 | write(*,*) ' ... might as well stop here ...' |
|---|
| 119 | error stop |
|---|
| 120 | endif |
|---|
| 121 | |
|---|
| 122 | startfiles_1D = .false. ! Default value |
|---|
| 123 | write(*,*) 'Do you want to use starting files and/or to write restarting files?' |
|---|
| 124 | call getin('startfiles_1D',startfiles_1D) |
|---|
| 125 | write(*,*) 'startfiles_1D =', startfiles_1D |
|---|
| 126 | |
|---|
| 127 | therestart1D = .false. ! Default value |
|---|
| 128 | therestartfi = .false. ! Default value |
|---|
| 129 | if (startfiles_1D) then |
|---|
| 130 | inquire(file = 'start1D.txt',exist = therestart1D) |
|---|
| 131 | if (.not. therestart1D) then |
|---|
| 132 | write(*,*) 'There is no "start1D.txt" file!' |
|---|
| 133 | write(*,*) 'Initialization is done with default values.' |
|---|
| 134 | endif |
|---|
| 135 | inquire(file = 'startfi.nc',exist = therestartfi) |
|---|
| 136 | if (.not. therestartfi) then |
|---|
| 137 | write(*,*) 'There is no "startfi.nc" file!' |
|---|
| 138 | write(*,*) 'Initialization is done with default values.' |
|---|
| 139 | endif |
|---|
| 140 | endif |
|---|
| 141 | if (therestart1D .and. .not. therestartfi) error stop 'There is a "start1D.txt" but no "startfi.nc". There might be problems for the initialization (for example ''qsurf'')!' |
|---|
| 142 | |
|---|
| 143 | call init_testphys1d('start1D.txt','startfi.nc',therestart1D,therestartfi,ngrid,nlayer,odpref,nq,q, & |
|---|
| 144 | time,psurf,u,v,temp,ndt,ptif,pks,dttestphys,zqsat,dq,dqdyn,day0,day,gru,grv,w, & |
|---|
| 145 | play,plev,latitude,longitude,cell_area, & |
|---|
| 146 | ctrl_h2ovap,relaxtime_h2ovap,qref_h2ovap,ctrl_h2oice,relaxtime_h2oice,qref_h2oice) |
|---|
| 147 | |
|---|
| 148 | ! Write a "startfi" file |
|---|
| 149 | ! ---------------------- |
|---|
| 150 | ! This file will be read during the first call to "physiq". |
|---|
| 151 | ! It is needed to transfert physics variables to "physiq"... |
|---|
| 152 | if (.not. therestartfi) then |
|---|
| 153 | call physdem0("startfi.nc",longitude,latitude,nsoilmx,ngrid, & |
|---|
| 154 | llm,nq,dttestphys,float(day0),0.,cell_area, & |
|---|
| 155 | albedodat,inertiedat,def_slope,subslope_dist) |
|---|
| 156 | call physdem1("startfi.nc",nsoilmx,ngrid,llm,nq,nqsoil,dttestphys,time, & |
|---|
| 157 | tsurf,tsoil,inertiesoil,albedo,emis,q2,qsurf,qsoil,tauscaling, & |
|---|
| 158 | totcloudfrac,wstar,watercap,perennial_co2ice) |
|---|
| 159 | endif !(.not. therestartfi) |
|---|
| 160 | |
|---|
| 161 | !======================================================================= |
|---|
| 162 | ! 1D MODEL TIME STEPPING LOOP |
|---|
| 163 | !======================================================================= |
|---|
| 164 | firstcall = .true. |
|---|
| 165 | lastcall = .false. |
|---|
| 166 | do idt = 1,ndt |
|---|
| 167 | if (idt == ndt) lastcall = .true. |
|---|
| 168 | ! if (idt == ndt - day_step - 1) then ! test |
|---|
| 169 | ! lastcall = .true. |
|---|
| 170 | ! call solarlong(day*1.0,zls) |
|---|
| 171 | ! write(103,*) 'Ls=',zls*180./pi |
|---|
| 172 | ! write(103,*) 'Lat=', latitude(1)*180./pi |
|---|
| 173 | ! write(103,*) 'Tau=', tauvis/odpref*psurf |
|---|
| 174 | ! write(103,*) 'RunEnd - Atmos. Temp. File' |
|---|
| 175 | ! write(103,*) 'RunEnd - Atmos. Temp. File' |
|---|
| 176 | ! write(104,*) 'Ls=',zls*180./pi |
|---|
| 177 | ! write(104,*) 'Lat=', latitude(1) |
|---|
| 178 | ! write(104,*) 'Tau=', tauvis/odpref*psurf |
|---|
| 179 | ! write(104,*) 'RunEnd - Atmos. Temp. File' |
|---|
| 180 | ! endif |
|---|
| 181 | |
|---|
| 182 | ! Compute geopotential |
|---|
| 183 | ! -------------------- |
|---|
| 184 | s = (aps/psurf + bps)**rcp |
|---|
| 185 | h = cpp*temp/(pks*s) |
|---|
| 186 | |
|---|
| 187 | phi(1) = pks*h(1)*(1. - s(1)) |
|---|
| 188 | do ilayer = 2,nlayer |
|---|
| 189 | phi(ilayer) = phi(ilayer - 1) + pks*(h(ilayer - 1) + h(ilayer))*.5*(s(ilayer - 1) - s(ilayer)) |
|---|
| 190 | enddo |
|---|
| 191 | |
|---|
| 192 | ! Call physics |
|---|
| 193 | ! ------------ |
|---|
| 194 | call physiq(1,llm,nq,firstcall,lastcall,day,time,dttestphys,plev,play,phi,u,v,temp,q,w,du,dv,dtemp,dq,dpsurf) |
|---|
| 195 | ! ^----- outputs -----^ |
|---|
| 196 | |
|---|
| 197 | ! Wind increment: specific for 1D |
|---|
| 198 | ! ------------------------------- |
|---|
| 199 | ! The physics computes the tendencies on u and v, here we just add Coriolos effect |
|---|
| 200 | !do ilayer = 1,nlayer |
|---|
| 201 | ! du(ilayer) = du(ilayer) + ptif*(v(ilayer) - grv) |
|---|
| 202 | ! dv(ilayer) = dv(ilayer) + ptif*(-u(ilayer) + gru) |
|---|
| 203 | !enddo |
|---|
| 204 | ! For some tests: No coriolis force at equator |
|---|
| 205 | !if (latitude(1) == 0.) then |
|---|
| 206 | du = du + (gru - u)/1.e4 |
|---|
| 207 | dv = dv + (grv - v)/1.e4 |
|---|
| 208 | !endif |
|---|
| 209 | |
|---|
| 210 | ! Water tracer increment: specific for 1D |
|---|
| 211 | ! --------------------------------------- |
|---|
| 212 | ! The physics computes the tendency on q for igcm_h2o_vap/igcm_h2o_ice, here we can mimic an effect |
|---|
| 213 | ! of the "3D dynamics" either by forcing a profile or by relaxing towards a prescribed profile |
|---|
| 214 | if (water) then |
|---|
| 215 | if (ctrl_h2ovap) then ! If atmospheric water vapour profile is prescribed |
|---|
| 216 | if (relaxtime_h2ovap < 0.) then ! Forcing |
|---|
| 217 | ! For some tests: unless it reaches saturation (maximal value) |
|---|
| 218 | !call watersat(nlayer,temp,play,zqsat) |
|---|
| 219 | !dq(1,:,igcm_h2o_vap) = (min(zqsat(:),qref_h2ovap(:)) - q(1,:,igcm_h2o_vap))/dttestphys |
|---|
| 220 | dq(1,:,igcm_h2o_vap) = (qref_h2ovap(:) - q(1,:,igcm_h2o_vap))/dttestphys |
|---|
| 221 | else ! Relaxation |
|---|
| 222 | dq(1,:,igcm_h2o_vap) = dq(1,:,igcm_h2o_vap) - (q(1,:,igcm_h2o_vap) - qref_h2ovap(:))/relaxtime_h2ovap |
|---|
| 223 | endif |
|---|
| 224 | endif |
|---|
| 225 | if (ctrl_h2oice) then ! If atmospheric water ice profile is prescribed |
|---|
| 226 | if (relaxtime_h2oice < 0.) then ! Forcing |
|---|
| 227 | dq(1,:,igcm_h2o_ice) = (qref_h2oice(:) - q(1,:,igcm_h2o_ice))/dttestphys |
|---|
| 228 | else ! Relaxation |
|---|
| 229 | dq(1,:,igcm_h2o_ice) = dq(1,:,igcm_h2o_ice) - (q(1,:,igcm_h2o_ice) - qref_h2oice(:))/relaxtime_h2oice |
|---|
| 230 | endif |
|---|
| 231 | endif |
|---|
| 232 | endif |
|---|
| 233 | |
|---|
| 234 | ! Compute time for next time step |
|---|
| 235 | ! ------------------------------- |
|---|
| 236 | firstcall = .false. |
|---|
| 237 | time = time + dttestphys/daysec |
|---|
| 238 | if (time > 1.) then |
|---|
| 239 | time = time - 1. |
|---|
| 240 | day = day + 1 |
|---|
| 241 | endif |
|---|
| 242 | |
|---|
| 243 | ! Compute winds for next time step |
|---|
| 244 | ! -------------------------------- |
|---|
| 245 | u = u + dttestphys*du |
|---|
| 246 | v = v + dttestphys*dv |
|---|
| 247 | |
|---|
| 248 | ! Compute temperature for next time step |
|---|
| 249 | ! -------------------------------------- |
|---|
| 250 | temp = temp + dttestphys*dtemp |
|---|
| 251 | |
|---|
| 252 | ! Compute pressure for next time step |
|---|
| 253 | ! ----------------------------------- |
|---|
| 254 | psurf = psurf + dttestphys*dpsurf(1) ! Surface pressure change |
|---|
| 255 | plev = ap + psurf*bp |
|---|
| 256 | play = aps + psurf*bps |
|---|
| 257 | |
|---|
| 258 | ! Compute tracers for next time step |
|---|
| 259 | ! ---------------------------------- |
|---|
| 260 | q = q + dttestphys*dq |
|---|
| 261 | enddo ! End of time stepping loop (idt=1,ndt) |
|---|
| 262 | |
|---|
| 263 | ! Writing the "restart1D.txt" file for the next run |
|---|
| 264 | if (startfiles_1D) call writerestart1D('restart1D.txt',psurf,pa,preff,tsurf(1,:),nlayer,size(tsurf,2),temp,u,v,nq,noms,q) |
|---|
| 265 | |
|---|
| 266 | write(*,*) "testphys1d: everything is cool!" |
|---|
| 267 | |
|---|
| 268 | END PROGRAM testphys1d |
|---|
| 269 | |
|---|
| 270 | !*********************************************************************** |
|---|
| 271 | !*********************************************************************** |
|---|
| 272 | ! Dummy subroutine used only in 3D, but required to |
|---|
| 273 | ! compile testphys1d (to cleanly use writediagfi) |
|---|
| 274 | SUBROUTINE gr_fi_dyn(nfield,ngrid,im,jm,pfi,pdyn) |
|---|
| 275 | |
|---|
| 276 | implicit none |
|---|
| 277 | |
|---|
| 278 | integer :: im, jm, ngrid, nfield |
|---|
| 279 | real, dimension(im,jm,nfield) :: pdyn |
|---|
| 280 | real, dimension(ngrid,nfield) :: pfi |
|---|
| 281 | |
|---|
| 282 | if (ngrid /= 1) error stop 'gr_fi_dyn error: in 1D ngrid should be 1!!!' |
|---|
| 283 | |
|---|
| 284 | pdyn(1,1,1:nfield) = pfi(1,1:nfield) |
|---|
| 285 | |
|---|
| 286 | END SUBROUTINE gr_fi_dyn |
|---|
| 287 | |
|---|
| 288 | !*********************************************************************** |
|---|
| 289 | !*********************************************************************** |
|---|