39 subroutine c_qg_setup(c_confspec, c_key_geom, c_key_confdata) bind (c,name='qg_setup_f90')
48 use fckit_log_module,
only : fckit_log
51 type(c_ptr),
intent(in) :: c_confspec
52 integer(c_int),
intent(in) :: c_key_geom
53 integer(c_int),
intent(inout) :: c_key_confdata
55 type(qg_config),
pointer :: config
56 type(qg_geom),
pointer :: geom
58 integer :: icentre, jcentre, ii, jj
59 real(kind=kind_real) :: distx, disty
60 type(duration) :: dtstep
61 character(len=20) :: ststep
62 character(len=160) :: record
63 character(len=30) :: otype
74 write(record,*)
'c_qg_setup: nx, ny=',config%nx,config%ny
75 call fckit_log%info(record)
77 config%d1 = config_get_real(c_confspec,
"top_layer_depth")
78 config%d2 = config_get_real(c_confspec,
"bottom_layer_depth")
79 write(record,*)
'c_qg_setup: d1, d2=',config%d1,config%d2
80 call fckit_log%info(record)
82 ststep = config_get_string(c_confspec,len(ststep),
"tstep")
84 config%dt0 = duration_seconds(dtstep)
85 write(record,*)
'c_qg_setup: dt0=',config%dt0
86 call fckit_log%info(record)
99 allocate(config%rs(config%nx,config%ny))
101 if (config_element_exists(c_confspec,
"orography"))
then 102 otype = trim(config_get_string(c_confspec,len(otype),
"orography"))
108 write(record,*)
"qg_geom_mod: orography = "//otype
109 call fckit_log%info(record)
111 if (otype ==
"flat")
then 113 config%rs=0.0_kind_real
119 jcentre=3*config%ny/4
122 distx =
real(min(icentre-ii,config%nx-(icentre-ii)),kind_real) &
124 disty = real(abs(jj-jcentre),kind_real) * config%deltay0
125 config%rs(ii,jj) = config%rsmax &
126 & *exp(-(distx*distx+disty*disty)/(
worog*
worog))
138 subroutine c_qg_delete(c_key_conf) bind (c,name='qg_delete_f90')
144 integer(c_int),
intent(inout) :: c_key_conf
145 type(qg_config),
pointer :: conf
164 & bind(c,name=
'qg_prepare_integration_f90')
173 integer(c_int),
intent(in) :: c_key_conf
174 integer(c_int),
intent(in) :: c_key_state
176 type(qg_config),
pointer :: conf
177 type(qg_field),
pointer :: flds
184 call calc_pv(flds%geom%nx,flds%geom%ny,flds%q,flds%x,flds%x_north,flds%x_south, &
186 call zonal_wind(flds%u,flds%x,flds%x_north,flds%x_south,flds%geom%nx,flds%geom%ny, &
196 bind(c,name=
'qg_prepare_integration_ad_f90')
204 integer(c_int),
intent(in) :: c_key_conf
205 integer(c_int),
intent(in) :: c_key_incr
207 type(qg_config),
pointer :: conf
208 type(qg_field),
pointer :: flds
217 call calc_pv_ad(flds%q,flds%x,flds%geom%nx,flds%geom%ny, &
219 flds%q=0.0_kind_real;
220 flds%u=0.0_kind_real;
221 flds%v=0.0_kind_real;
230 bind(c,name=
'qg_prepare_integration_tl_f90')
237 integer(c_int),
intent(in) :: c_key_conf
238 integer(c_int),
intent(in) :: c_key_incr
240 type(qg_config),
pointer :: conf
241 type(qg_field),
pointer :: flds
248 call calc_pv_tl(flds%q,flds%x,flds%geom%nx,flds%geom%ny, &
258 subroutine c_qg_propagate(c_key_conf, c_key_state) bind(c,name='qg_propagate_f90')
265 integer(c_int),
intent(in) :: c_key_conf
266 integer(c_int),
intent(in) :: c_key_state
268 type(qg_config),
pointer :: conf
269 type(qg_field),
pointer :: flds
284 bind(c,name=
'qg_propagate_ad_f90')
295 integer(c_int),
intent(in) :: c_key_conf
296 integer(c_int),
intent(in) :: c_key_incr
297 integer(c_int),
intent(in) :: c_key_traj
299 type(qg_config),
pointer :: conf
300 type(qg_field),
pointer :: flds
301 type(qg_trajectory),
pointer :: traj
303 real(kind=kind_real),
allocatable :: qnew(:,:,:), x_traj(:,:,:)
304 real(kind=kind_real),
allocatable :: q_traj(:,:,:), u_traj(:,:,:), v_traj(:,:,:)
305 real(kind=kind_real),
allocatable :: qn_traj(:,:), qs_traj(:,:)
306 real(kind=kind_real) :: xn_traj(2), xs_traj(2)
313 allocate(qnew(flds%geom%nx,flds%geom%ny,2))
314 allocate(x_traj(flds%geom%nx,flds%geom%ny,2))
315 allocate(qn_traj(flds%geom%nx,2))
316 allocate(qs_traj(flds%geom%nx,2))
317 allocate(q_traj(flds%geom%nx,flds%geom%ny,2))
318 allocate(u_traj(flds%geom%nx,flds%geom%ny,2))
319 allocate(v_traj(flds%geom%nx,flds%geom%ny,2))
320 call get_traj(traj,flds%geom%nx,flds%geom%ny,x_traj,xn_traj,xs_traj,qn_traj,qs_traj)
324 call calc_pv(flds%geom%nx,flds%geom%ny,q_traj,x_traj,xn_traj,xs_traj, &
326 call zonal_wind (u_traj,x_traj,xn_traj,xs_traj,flds%geom%nx,flds%geom%ny,
conf%deltay)
333 qnew(:,:,:) = flds%q(:,:,:)
337 call invert_pv_ad(flds%x,qnew,flds%geom%nx,flds%geom%ny, &
343 & flds%u,u_traj,flds%v,v_traj,flds%geom%nx,flds%geom%ny, &
363 bind(c,name=
'qg_propagate_tl_f90')
374 integer(c_int),
intent(in) :: c_key_conf
375 integer(c_int),
intent(in) :: c_key_incr
376 integer(c_int),
intent(in) :: c_key_traj
378 type(qg_config),
pointer :: conf
379 type(qg_field),
pointer :: flds
380 type(qg_trajectory),
pointer :: traj
382 real(kind_real),
allocatable :: qnew(:,:,:), x_traj(:,:,:)
383 real(kind_real),
allocatable :: q_traj(:,:,:), u_traj(:,:,:), v_traj(:,:,:)
384 real(kind_real),
allocatable :: qn_traj(:,:), qs_traj(:,:)
385 real(kind_real) :: xn_traj(2), xs_traj(2)
392 allocate(qnew(flds%geom%nx,flds%geom%ny,2))
393 allocate(x_traj(flds%geom%nx,flds%geom%ny,2))
394 allocate(qn_traj(flds%geom%nx,2))
395 allocate(qs_traj(flds%geom%nx,2))
396 allocate(q_traj(flds%geom%nx,flds%geom%ny,2))
397 allocate(u_traj(flds%geom%nx,flds%geom%ny,2))
398 allocate(v_traj(flds%geom%nx,flds%geom%ny,2))
399 call get_traj(traj,flds%geom%nx,flds%geom%ny,x_traj,xn_traj,xs_traj,qn_traj,qs_traj)
403 call calc_pv(flds%geom%nx,flds%geom%ny,q_traj,x_traj,xn_traj,xs_traj, &
405 call zonal_wind (u_traj,x_traj,xn_traj,xs_traj,flds%geom%nx,flds%geom%ny,
conf%deltay)
410 qnew(:,:,:)=0.0_kind_real
412 & flds%u,u_traj,flds%v,v_traj,flds%geom%nx,flds%geom%ny,&
417 call invert_pv_tl(flds%x,qnew,flds%geom%nx,flds%geom%ny, &
422 flds%q(:,:,:) = qnew(:,:,:)
441 subroutine c_qg_prop_traj(c_key_conf, c_key_state, c_key_traj) bind(c,name='qg_prop_traj_f90')
449 integer(c_int),
intent(in) :: c_key_conf
450 integer(c_int),
intent(in) :: c_key_state
451 integer(c_int),
intent(inout) :: c_key_traj
453 type(qg_config),
pointer :: conf
454 type(qg_field),
pointer :: flds
455 type(qg_trajectory),
pointer :: traj
463 call set_traj(traj,flds%geom%nx,flds%geom%ny, &
464 & flds%x,flds%x_north,flds%x_south,flds%q_north,flds%q_south)
472 subroutine c_qg_wipe_traj(c_key_traj) bind(c,name='qg_wipe_traj_f90')
478 integer(c_int),
intent(inout) :: c_key_traj
479 type(qg_trajectory),
pointer :: traj
real(kind=kind_real), parameter domain_meridional
meridional model domain (m)
subroutine advect_pv_tl(qnew, q, q_traj, q_north, q_south, u, u_traj, v, v_traj, nx, ny, deltax, deltay, dt)
Advect potential vorticity - Tangent Linear.
real(kind=kind_real), parameter horog
height of orography (m)
subroutine invert_pv_tl(x, pv, nx, ny, deltax, deltay, F1, F2)
Invert potential vorticity - Tangent Linear.
type(registry_t), public qg_field_registry
Linked list interface - defines registry_t type.
subroutine c_qg_delete(c_key_conf)
Delete the QG model.
real(kind=kind_real), parameter f0
Coriolis parameter at southern boundary.
Handle the trajectory for the QG model.
real(kind=kind_real), parameter g
gravity (m^2 s^{-2})
subroutine calc_pv_tl(pv, x, nx, ny, f1, f2, deltax, deltay)
Calculate potential vorticity - Tangent Linear.
subroutine, public set_traj(self, kx, ky, px, pxn, pxs, pqn, pqs)
Linked list implementation.
subroutine zonal_wind_tl(u, x, nx, ny, deltay)
Calculate zonal wind - Tangent Linear.
type(registry_t), public qg_geom_registry
Linked list interface - defines registry_t type.
Constants for the QG model.
subroutine c_qg_prepare_integration(c_key_conf, c_key_state)
Prepare for an integration of the QG model.
subroutine, public get_traj(self, kx, ky, px, pxn, pxs, pqn, pqs)
real(kind=kind_real), parameter rossby_number
subroutine c_qg_wipe_traj(c_key_traj)
Wipe out trajectory of the QG model.
subroutine c_qg_prepare_integration_ad(c_key_conf, c_key_incr)
Prepare for an integration of the QG model - Adjoint.
subroutine c_qg_propagate(c_key_conf, c_key_state)
Perform a timestep of the QG model.
real(kind=kind_real), parameter bet
subroutine calc_pv(kx, ky, pv, x, x_north, x_south, f1, f2, deltax, deltay, bet, rs, lbc)
Calculate potential vorticity from streamfunction.
Fortran module handling geometry for the QG model.
subroutine calc_pv_ad(pv, x, nx, ny, f1, f2, deltax, deltay)
Calculate potential vorticity - Adjoint.
type(registry_t), public qg_config_registry
Linked list interface - defines registry_t type.
subroutine c_qg_prop_traj(c_key_conf, c_key_state, c_key_traj)
Save trajectory and perform a timestep of the QG model.
subroutine invert_pv_ad(x, pv, nx, ny, deltax, deltay, F1, F2)
Invert potential vorticity - Adjoint.
subroutine c_qg_propagate_ad(c_key_conf, c_key_incr, c_key_traj)
Perform a timestep of the QG model - Adjoint This routine is called from C++ to propagate the adjoint...
subroutine advect_pv_ad(qnew, q, q_traj, q_north, q_south, u, u_traj, v, v_traj, nx, ny, deltax, deltay, dt)
Advect potential vorticity - Adjoint.
subroutine c_qg_setup(c_confspec, c_key_geom, c_key_confdata)
Setup the QG model.
type(registry_t), public qg_traj_registry
Linked list interface - defines registry_t type.
subroutine c_qg_prepare_integration_tl(c_key_conf, c_key_incr)
Prepare for an integration of the QG model - Tangent Linear.
subroutine zonal_wind(u, x, x_north, x_south, nx, ny, deltay)
Calculate zonal wind component from the streamfunction.
subroutine meridional_wind_tl(v, x, nx, ny, deltax)
Calculate meridional wind component - Tangent Linear.
Structure holding configuration variables for the QG model.
Handle fields for the QG model.
subroutine propagate(flds, config)
Perform a timestep of the QG model.
subroutine c_qg_propagate_tl(c_key_conf, c_key_incr, c_key_traj)
Perform a timestep of the QG model - Tangent Linear This routine is called from C++ to propagate the ...
subroutine meridional_wind_ad(v, x, nx, ny, deltax)
Calculate meridional wind component - Adjoint.
subroutine zonal_wind_ad(u, x, nx, ny, deltay)
Calculate zonal wind - Adjoint.
real(kind=kind_real), parameter domain_zonal
model domain (m) in zonal direction
real(kind=kind_real), parameter dlogtheta
difference in log(pot. T) across boundary
subroutine meridional_wind(v, x, nx, ny, deltax)
Calculate meridional wind component from the streamfunction.
real(kind=kind_real), parameter ubar
typical verlocity (m/s)
subroutine, public delete_traj(self)
real(kind=kind_real), parameter worog
e-folding width of orography (m)
real(kind=kind_real), parameter scale_length
horizontal length scale (m)