FV3 Bundle
invent_state.f90
Go to the documentation of this file.
1 ! (C) Copyright 2009-2016 ECMWF.
2 !
3 ! This software is licensed under the terms of the Apache Licence Version 2.0
4 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5 ! In applying this licence, ECMWF does not waive the privileges and immunities
6 ! granted to it by virtue of its status as an intergovernmental organisation nor
7 ! does it submit to any jurisdiction.
8 
9 !> Invent an initial state for the QG model.
10 
11 !> This routine invent an initial state for the QG model. It is used to
12 !! initialise the "truth run". The initial state consists of a horizontally
13 !! uniform wind in each layer, with a vertical shear sufficient to produce
14 !! baroclinic instability. Povided the orography is non-zero and is not
15 !! symmetrically place in the domain, this is sufficient to generate a
16 !! non-trivial flow after a few days of integration.
17 !!
18 !! Two slightly different initial states may be created (according to whether
19 !! or not ctype is set to 'f').
20 
21 subroutine invent_state(flds,config)
22 
23 use qg_configs
24 use qg_fields
25 use iso_c_binding
26 use config_mod
27 use fckit_log_module, only : fckit_log
30 use calculate_pv, only : calc_pv
31 use kinds
32 
33 implicit none
34 
35 type(qg_field), intent(inout) :: flds !< Model fields
36 type(c_ptr), intent(in) :: config !< Configuration structure
37 
38 integer :: jx,jy,icentre,jcentre,ii,jj,ipert
39 real(kind=kind_real) :: distx,disty,d1,d2,f1,f2,rsmax,deltax0,deltay0,deltax,deltay,zz
40 real(kind=kind_real), allocatable :: pv(:,:,:), rs(:,:)
41 character(len=160) :: record
42 
43 ! ------------------------------------------------------------------------------
44 
45 d1 = config_get_real(config,"top_layer_depth")
46 d2 = config_get_real(config,"bottom_layer_depth")
47 
50 rsmax = horog/(rossby_number*d2)
51 deltax0 = domain_zonal/real(flds%geom%nx,kind_real)
52 deltay0 = domain_meridional/real(flds%geom%ny+1,kind_real)
53 deltax = deltax0/scale_length
54 deltay = deltay0/scale_length
55 
56 allocate(pv(flds%geom%nx,flds%geom%ny,2))
57 allocate(rs(flds%geom%nx,flds%geom%ny))
58 
59 !--- Uniform wind in each layer. A vertical shear outside the range
60 !--- -bet/F1 to bet/F2 should produce baroclinic instability.
61 
62 flds%x_south(1) = 0.0_kind_real
63 flds%x_south(2) = 0.0_kind_real
64 flds%x_north(1) = -real(flds%geom%ny+1,kind_real)*deltay*u1
65 flds%x_north(2) = -real(flds%geom%ny+1,kind_real)*deltay*u2
66 
67 do jy=1,flds%geom%ny
68 do jx=1,flds%geom%nx
69  flds%x(jx,jy,1) = -real(jy,kind_real)*deltay*u1
70  flds%x(jx,jy,2) = -real(jy,kind_real)*deltay*u2
71 enddo
72 enddo
73 
74 ipert = config_get_int(config,"perturb")
75 if (ipert/=0) then
76  write(record,*)"qg_invent_state_f90: Perturbing invented state by ",ipert,"%."
77  call fckit_log%info(record)
78  zz=real(ipert,kind_real)/100.0_kind_real
79  do jy=1,flds%geom%ny
80  do jx=1,flds%geom%nx
81  flds%x(jx,jy,1) = (1.0_kind_real+zz)*flds%x(jx,jy,1)
82  flds%x(jx,jy,2) = (1.0_kind_real-zz)*flds%x(jx,jy,2)
83  enddo
84  enddo
85 endif
86 
87 icentre=flds%geom%nx/4
88 jcentre=3*flds%geom%ny/4
89 do jj=1,flds%geom%ny
90  do ii=1,flds%geom%nx
91  distx = real(min(icentre-ii,flds%geom%nx-(icentre-ii)),kind_real) * deltax0
92  disty = real(abs(jj-jcentre),kind_real) * deltay0
93  rs(ii,jj) = rsmax*exp(-(distx*distx+disty*disty)/(worog*worog))
94  enddo
95 enddo
96 
97 call calc_pv(flds%geom%nx,flds%geom%ny,pv,flds%x,flds%x_north,flds%x_south, &
98  & f1,f2,deltax,deltay,bet,rs)
99 
100 do jx=1,flds%geom%nx
101  flds%q_south(jx,1) = 2.0_kind_real*pv(jx,1,1)-pv(jx,2,1)
102  flds%q_south(jx,2) = 2.0_kind_real*pv(jx,1,2)-pv(jx,2,2)
103 enddo
104 do jx=1,flds%geom%nx
105  flds%q_north(jx,1) = 2.0_kind_real*pv(jx,flds%geom%ny,1)-pv(jx,flds%geom%ny-1,1)
106  flds%q_north(jx,2) = 2.0_kind_real*pv(jx,flds%geom%ny,2)-pv(jx,flds%geom%ny-1,2)
107 enddo
108 
109 deallocate(pv,rs)
110 ! ------------------------------------------------------------------------------
111 
112 return
113 end subroutine invent_state
real(kind=kind_real), parameter domain_meridional
meridional model domain (m)
real(kind=kind_real), parameter horog
height of orography (m)
real(kind=kind_real), parameter f0
Coriolis parameter at southern boundary.
real(kind=kind_real), parameter g
gravity (m^2 s^{-2})
Constants for the QG model.
real(kind=kind_real), parameter rossby_number
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.
Definition: calc_pv.f90:21
real(kind=kind_real), parameter u1
subroutine invent_state(flds, config)
Invent an initial state for the QG model.
Structure holding configuration variables for the QG model.
Definition: qg_configs.F90:11
Handle fields for the QG model.
Definition: qg_fields.F90:11
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
real(kind=kind_real), parameter u2
real(kind=kind_real), parameter worog
e-folding width of orography (m)
real(kind=kind_real), parameter scale_length
horizontal length scale (m)