OOPS
qg_model_mod.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 
10 
11 use duration_mod
12 use fckit_configuration_module, only: fckit_configuration
13 use fckit_log_module,only: fckit_log
14 use iso_c_binding
15 use kinds
21 use qg_fields_mod
22 use random_mod
23 
24 implicit none
25 
26 private
27 public :: qg_model_config
28 public :: qg_model_registry
30 ! ------------------------------------------------------------------------------
32  real(kind_real) :: dt !< Time step (seconds)
33 end type qg_model_config
34 
35 #define LISTED_TYPE qg_model_config
36 
37 !> Linked list interface - defines registry_t type
38 #include "oops/util/linkedList_i.f"
39 
40 !> Global registry
41 type(registry_t) :: qg_model_registry
42 ! ------------------------------------------------------------------------------
43 contains
44 ! ------------------------------------------------------------------------------
45 ! Public
46 ! ------------------------------------------------------------------------------
47 !> Linked list implementation
48 #include "oops/util/linkedList_c.f"
49 ! ------------------------------------------------------------------------------
50 !> Setup model
51 subroutine qg_model_setup(self,f_conf)
52 
53 implicit none
54 
55 ! Passed variables
56 type(qg_model_config),intent(inout) :: self !< Model configuration
57 type(fckit_configuration),intent(in) :: f_conf !< FCKIT configuration
58 
59 ! Local variables
60 type(duration) :: dtstep
61 character(len=20) :: ststep
62 character(len=160) :: record
63 character(len=:),allocatable :: str
64 
65 ! Define time step
66 call f_conf%get_or_die("tstep",str)
67 ststep = str
68 dtstep = trim(ststep)
69 self%dt = duration_seconds(dtstep)
70 write(record,*) 'qg_model_setup: dt = ',self%dt
71 call fckit_log%info(record)
72 
73 end subroutine qg_model_setup
74 ! ------------------------------------------------------------------------------
75 !> Perform a timestep of the QG model
76 subroutine qg_model_propagate(conf,fld)
77 
78 implicit none
79 
80 ! Passed variables
81 type(qg_model_config),intent(in) :: conf !< Model configuration
82 type(qg_fields),intent(inout) :: fld !< State fields
83 
84 ! Local variables
85 real(kind_real) :: x(fld%geom%nx,fld%geom%ny,fld%geom%nz),q(fld%geom%nx,fld%geom%ny,fld%geom%nz)
86 real(kind_real) :: u(fld%geom%nx,fld%geom%ny,fld%geom%nz),v(fld%geom%nx,fld%geom%ny,fld%geom%nz)
87 real(kind_real) :: qnew(fld%geom%nx,fld%geom%ny,fld%geom%nz)
88 
89 ! Initialize streamfunction and potential vorticity
90 if (fld%lq) then
91  q = fld%gfld3d
92  call convert_q_to_x(fld%geom,q,fld%x_north,fld%x_south,x)
93 else
94  x = fld%gfld3d
95  call convert_x_to_q(fld%geom,x,fld%x_north,fld%x_south,q)
96 endif
97 
98 ! Initialize wind
99 call convert_x_to_uv(fld%geom,x,fld%x_north,fld%x_south,u,v)
100 
101 ! Advect potential vorticity
102 call advect_q(fld%geom,conf%dt,u,v,q,fld%q_north,fld%q_south,qnew)
103 
104 ! Save streamfunction or potential vorticity
105 if (fld%lq) then
106  fld%gfld3d = qnew
107 else
108  call convert_q_to_x(fld%geom,qnew,fld%x_north,fld%x_south,x)
109  fld%gfld3d = x
110 endif
111 
112 end subroutine qg_model_propagate
113 ! ------------------------------------------------------------------------------
114 !> Perform a timestep of the QG model - tangent linear
115 subroutine qg_model_propagate_tl(conf,traj,fld)
116 
117 implicit none
118 
119 ! Passed variables
120 type(qg_model_config),intent(in) :: conf !< Model configuration
121 type(qg_fields),intent(in) :: traj !< Trajectory fields
122 type(qg_fields),intent(inout) :: fld !< Increment fields
123 
124 ! Local variables
125 real(kind_real) :: x_traj(fld%geom%nx,fld%geom%ny,fld%geom%nz),q_traj(fld%geom%nx,fld%geom%ny,fld%geom%nz)
126 real(kind_real) :: u_traj(fld%geom%nx,fld%geom%ny,fld%geom%nz),v_traj(fld%geom%nx,fld%geom%ny,fld%geom%nz)
127 real(kind_real) :: x(fld%geom%nx,fld%geom%ny,fld%geom%nz),q(fld%geom%nx,fld%geom%ny,fld%geom%nz)
128 real(kind_real) :: u(fld%geom%nx,fld%geom%ny,fld%geom%nz),v(fld%geom%nx,fld%geom%ny,fld%geom%nz)
129 real(kind_real) :: qnew(fld%geom%nx,fld%geom%ny,fld%geom%nz)
130 
131 ! Trajectory
132 
133 ! Initialize streamfunction and potential vorticity
134 if (traj%lq) then
135  q_traj = traj%gfld3d
136  call convert_q_to_x(fld%geom,q_traj,traj%x_north,traj%x_south,x_traj)
137 else
138  x_traj = traj%gfld3d
139  call convert_x_to_q(fld%geom,x_traj,traj%x_north,traj%x_south,q_traj)
140 endif
141 
142 ! Compute wind
143 call convert_x_to_uv(fld%geom,x_traj,traj%x_north,traj%x_south,u_traj,v_traj)
144 
145 ! Perturbation
146 
147 ! Initialize streamfunction and potential vorticity
148 if (fld%lq) then
149  q = fld%gfld3d
150  call convert_q_to_x_tl(fld%geom,q,x)
151 else
152  x = fld%gfld3d
153  call convert_x_to_q_tl(fld%geom,x,q)
154 endif
155 
156 ! Compute wind
157 call convert_x_to_uv_tl(fld%geom,x,u,v)
158 
159 ! Advect PV
160 call advect_q_tl(fld%geom,conf%dt,u_traj,v_traj,q_traj,traj%q_north,traj%q_south,u,v,q,qnew)
161 
162 ! Save streamfunction or potential vorticity
163 if (fld%lq) then
164  fld%gfld3d = qnew
165 else
166  call convert_q_to_x_tl(fld%geom,qnew,x)
167  fld%gfld3d = x
168 endif
169 
170 end subroutine qg_model_propagate_tl
171 ! ------------------------------------------------------------------------------
172 !> Perform a timestep of the QG model - adjoint
173 subroutine qg_model_propagate_ad(conf,traj,fld)
174 
175 implicit none
176 
177 ! Passed variables
178 type(qg_model_config),intent(in) :: conf !< Model configuration
179 type(qg_fields),intent(in) :: traj !< Trajectory fields
180 type(qg_fields),intent(inout) :: fld !< Increment fields
181 
182 ! Local variables
183 real(kind_real) :: x_traj(fld%geom%nx,fld%geom%ny,fld%geom%nz),q_traj(fld%geom%nx,fld%geom%ny,fld%geom%nz)
184 real(kind_real) :: u_traj(fld%geom%nx,fld%geom%ny,fld%geom%nz),v_traj(fld%geom%nx,fld%geom%ny,fld%geom%nz)
185 real(kind_real) :: x(fld%geom%nx,fld%geom%ny,fld%geom%nz),q(fld%geom%nx,fld%geom%ny,fld%geom%nz)
186 real(kind_real) :: u(fld%geom%nx,fld%geom%ny,fld%geom%nz),v(fld%geom%nx,fld%geom%ny,fld%geom%nz)
187 real(kind_real) :: qnew(fld%geom%nx,fld%geom%ny,fld%geom%nz)
188 
189 ! Trajectory
190 
191 ! Initialize streamfunction and potential vorticity
192 if (traj%lq) then
193  q_traj = traj%gfld3d
194  call convert_q_to_x(fld%geom,q_traj,traj%x_north,traj%x_south,x_traj)
195 else
196  x_traj = traj%gfld3d
197  call convert_x_to_q(fld%geom,x_traj,traj%x_north,traj%x_south,q_traj)
198 endif
199 
200 ! Compute wind
201 call convert_x_to_uv(fld%geom,x_traj,traj%x_north,traj%x_south,u_traj,v_traj)
202 
203 ! Perturbation
204 
205 ! Initialization
206 x = 0.0
207 q = 0.0
208 u = 0.0
209 v = 0.0
210 qnew = 0.0
211 
212 ! Save streamfunction or potential vorticity
213 if (fld%lq) then
214  qnew = fld%gfld3d
215 else
216  x = fld%gfld3d
217  call convert_q_to_x_ad(fld%geom,x,qnew)
218 endif
219 
220 ! Advect PV
221 call advect_q_ad(fld%geom,conf%dt,u_traj,v_traj,q_traj,traj%q_north,traj%q_south,qnew,u,v,q)
222 
223 ! Compute wind
224 x = 0.0
225 call convert_x_to_uv_ad(fld%geom,u,v,x)
226 
227 ! Initialize streamfunction and potential vorticity
228 if (fld%lq) then
229  call convert_q_to_x_ad(fld%geom,x,q)
230  fld%gfld3d = q
231 else
232  call convert_x_to_q_ad(fld%geom,q,x)
233  fld%gfld3d = x
234 endif
235 
236 end subroutine qg_model_propagate_ad
237 ! ------------------------------------------------------------------------------
238 end module qg_model_mod
239 
qg_fields_mod
Definition: qg_fields_mod.F90:9
qg_fields_mod::qg_fields
Definition: qg_fields_mod.F90:51
qg_convert_x_to_q_mod
Definition: qg_convert_x_to_q_mod.F90:9
qg_convert_q_to_x_mod::convert_q_to_x_tl
subroutine, public convert_q_to_x_tl(geom, q, x)
Convert potential vorticity to streamfunction - tangent linear.
Definition: qg_convert_q_to_x_mod.F90:86
qg_model_mod::qg_model_config
Definition: qg_model_mod.F90:31
qg_model_mod
Definition: qg_model_mod.F90:9
qg_model_mod::qg_model_setup
subroutine, public qg_model_setup(self, f_conf)
Linked list implementation.
Definition: qg_model_mod.F90:52
qg_advect_q_mod::advect_q
subroutine, public advect_q(geom, dt, u, v, q, q_north, q_south, qnew)
Advect potential vorticity.
Definition: qg_advect_q_mod.F90:26
qg_convert_x_to_q_mod::convert_x_to_q_tl
subroutine, public convert_x_to_q_tl(geom, x, q)
Convert streamfunction to potential vorticity - tangent linear.
Definition: qg_convert_x_to_q_mod.F90:73
qg_convert_q_to_x_mod
Definition: qg_convert_q_to_x_mod.F90:9
qg_constants_mod
Definition: qg_constants_mod.F90:9
qg_convert_x_to_q_mod::convert_x_to_q
subroutine, public convert_x_to_q(geom, x, x_north, x_south, q)
Convert streamfunction to potential vorticity.
Definition: qg_convert_x_to_q_mod.F90:25
qg_convert_x_to_uv_mod::convert_x_to_uv
subroutine, public convert_x_to_uv(geom, x, x_north, x_south, u, v)
Convert streafunction to wind components.
Definition: qg_convert_x_to_uv_mod.F90:23
qg_convert_x_to_q_mod::convert_x_to_q_ad
subroutine, public convert_x_to_q_ad(geom, q, x)
Convert streamfunction to potential vorticity - adjoint.
Definition: qg_convert_x_to_q_mod.F90:107
qg_model_mod::qg_model_propagate_tl
subroutine, public qg_model_propagate_tl(conf, traj, fld)
Perform a timestep of the QG model - tangent linear.
Definition: qg_model_mod.F90:116
qg_model_mod::qg_model_propagate
subroutine, public qg_model_propagate(conf, fld)
Perform a timestep of the QG model.
Definition: qg_model_mod.F90:77
qg_advect_q_mod
Definition: qg_advect_q_mod.F90:9
qg_convert_x_to_uv_mod::convert_x_to_uv_tl
subroutine, public convert_x_to_uv_tl(geom, x, u, v)
Convert streafunction to wind components - tangent Linear.
Definition: qg_convert_x_to_uv_mod.F90:61
qg_convert_x_to_uv_mod
Definition: qg_convert_x_to_uv_mod.F90:9
qg_model_mod::qg_model_propagate_ad
subroutine, public qg_model_propagate_ad(conf, traj, fld)
Perform a timestep of the QG model - adjoint.
Definition: qg_model_mod.F90:174
qg_convert_q_to_x_mod::convert_q_to_x
subroutine, public convert_q_to_x(geom, q, x_north, x_south, x)
Convert potential vorticity to streamfunction.
Definition: qg_convert_q_to_x_mod.F90:25
qg_convert_x_to_uv_mod::convert_x_to_uv_ad
subroutine, public convert_x_to_uv_ad(geom, u, v, x)
Convert streafunction to wind components - adjoint.
Definition: qg_convert_x_to_uv_mod.F90:96
qg_convert_q_to_x_mod::convert_q_to_x_ad
subroutine, public convert_q_to_x_ad(geom, x, q)
Convert potential vorticity to streamfunction - adjoint.
Definition: qg_convert_q_to_x_mod.F90:133
qg_model_mod::qg_model_registry
type(registry_t), public qg_model_registry
Linked list interface - defines registry_t type.
Definition: qg_model_mod.F90:41
qg_advect_q_mod::advect_q_ad
subroutine, public advect_q_ad(geom, dt, u_traj, v_traj, q_traj, q_traj_north, q_traj_south, qnew, u, v, q)
Advect potential vorticity - adjoint.
Definition: qg_advect_q_mod.F90:130
qg_advect_q_mod::advect_q_tl
subroutine, public advect_q_tl(geom, dt, u_traj, v_traj, q_traj, q_traj_north, q_traj_south, u, v, q, qnew)
Advect potential vorticity - tangent linear.
Definition: qg_advect_q_mod.F90:71