-
Notifications
You must be signed in to change notification settings - Fork 12
/
integration.f90
325 lines (301 loc) · 13.1 KB
/
integration.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
module integration
use control
use constant
use omp_lib
contains
subroutine time_integration(ua,va,za,u,v,z,uc,vc,zc,ts,option)
implicit none
real ,intent(in) :: ua(grid%x_grd_num_u ,grid%y_grd_num_u) ,&
va(grid%x_grd_num_v ,grid%y_grd_num_v) ,&
za(grid%x_grd_num ,grid%y_grd_num) ,&
u(grid%x_grd_num_u ,grid%y_grd_num_u) ,&
v(grid%x_grd_num_v ,grid%y_grd_num_v) ,&
z(grid%x_grd_num ,grid%y_grd_num) ,&
ts
integer ,intent(in) :: option
real ,intent(out):: uc(grid%x_grd_num_u ,grid%y_grd_num_u) ,&
vc(grid%x_grd_num_v ,grid%y_grd_num_v) ,&
zc(grid%x_grd_num ,grid%y_grd_num)
if(integration_option==1)then
call time_integration_Square_Conservation(ua,va,za,u,v,z,uc,vc,zc,ts,option)
elseif(integration_option==2)then
call time_integration_Energe_Conservation(ua,va,za,u,v,z,uc,vc,zc,ts,option)
endif
end subroutine time_integration
!time integrations
!When option==1, uc=ua+u_t*delta_t
!When option==2, uc=u_t*delta_t
!When option==3, uc=u_t
!ts is the time step
subroutine time_integration_Square_Conservation(ua,va,za,u,v,z,uc,vc,zc,ts,option)
implicit none
real ,intent(in) :: ua(grid%x_grd_num_u ,grid%y_grd_num_u) ,&
va(grid%x_grd_num_v ,grid%y_grd_num_v) ,&
za(grid%x_grd_num ,grid%y_grd_num) ,&
u(grid%x_grd_num_u ,grid%y_grd_num_u) ,&
v(grid%x_grd_num_v ,grid%y_grd_num_v) ,&
z(grid%x_grd_num ,grid%y_grd_num) ,&
ts
integer ,intent(in) :: option
real ,intent(out):: uc(grid%x_grd_num_u ,grid%y_grd_num_u) ,&
vc(grid%x_grd_num_v ,grid%y_grd_num_v) ,&
zc(grid%x_grd_num ,grid%y_grd_num)
real zm(grid%x_grd_num ,grid%y_grd_num)
real u_t(grid%x_grd_num_u,grid%y_grd_num_u),&
v_t(grid%x_grd_num_v,grid%y_grd_num_v),&
z_t(grid%x_grd_num ,grid%y_grd_num)
real fu(grid%x_grd_num_u,grid%y_grd_num_u) ,&
fv(grid%x_grd_num_v,grid%y_grd_num_v) ,&
m(grid%x_grd_num ,grid%y_grd_num) ,&
mu(grid%x_grd_num_u,grid%y_grd_num_u) ,&
mv(grid%x_grd_num_v,grid%y_grd_num_v)
real c
integer i,j
integer u_xs,&
u_xe,&
u_ys,&
u_ye,&
v_xs,&
v_xe,&
v_ys,&
v_ye,&
m_xs,&
m_xe,&
m_ys,&
m_ye
u_xs = 2
u_xe = grid%x_grd_num_u-1
u_ys = 2
u_ye = grid%y_grd_num_u-1
v_xs = 2
v_xe = grid%x_grd_num_v-1
v_ys = 2
v_ye = grid%y_grd_num_v-1
m_xs = 2
m_xe = grid%x_grd_num-1
m_ys = 2
m_ye = grid%y_grd_num-1
fu = grid%f_u
fv = grid%f_v
m = grid%mapfac_m
mu = grid%mapfac_u
mv = grid%mapfac_v
c=0.25d0/grid%dx
u_t=0.d0
v_t=0.d0
z_t=0.d0
zm=z/m
!Loop solve
!$omp parallel private(i)
!$omp do
do j=u_ys,u_ye
do i=u_xs,u_xe
u_t(i,j)=-mu(i,j)*c*((u(i+1,j)+u(i,j))*(u(i+1,j)-u(i,j)) &
+(u(i,j)+u(i-1,j))*(u(i,j)-u(i-1,j)) &
+(v(i,j+1)+v(i-1,j+1))*(u(i,j+1)-u(i,j)) &
+(v(i,j)+v(i-1,j))*(u(i,j)-u(i,j-1)) &
+4.d0*g*(z(i,j)-z(i-1,j))) &
+0.25d0*(fu(i,j) &
+c*((u(i+1,j)+u(i,j))*(mv(i,j+1)-mv(i,j)) &
+(u(i,j)+u(i-1,j))*(mv(i-1,j+1)-mv(i,j)) &
-(v(i,j+1)+v(i,j))*(mu(i+1,j)-mu(i,j)) &
-(v(i-1,j+1)+v(i-1,j))*(mu(i,j)-mu(i-1,j))))&
*(v(i,j+1)+v(i-1,j+1)+v(i,j)+v(i-1,j))
enddo
enddo
!$omp end do
!$omp do
do j=v_ys,v_ye
do i=v_xs,v_xe
v_t(i,j)=-mv(i,j)*c*((u(i+1,j)+u(i+1,j-1))*(v(i+1,j)-v(i,j)) &
+(u(i,j)+u(i,j-1))*(v(i,j)-v(i-1,j)) &
+(v(i,j+1)+v(i,j))*(v(i,j+1)-v(i,j)) &
+(v(i,j)+v(i,j-1))*(v(i,j)-v(i,j-1)) &
+4.d0*g*(z(i,j)-z(i,j-1))) &
-0.25d0*(fv(i,j) &
+c*((u(i+1,j)+u(i,j))*(mv(i,j+1)-mv(i,j)) &
+(u(i+1,j-1)+u(i,j-1))*(mv(i,j)-mv(i,j-1)) &
-(v(i,j+1)+v(i,j))*(mu(i+1,j)-mu(i,j)) &
-(v(i,j)+v(i,j-1))*(mu(i+1,j-1)-mu(i,j-1))))&
*(u(i+1,j)+u(i,j)+u(i+1,j-1)+u(i,j-1))
enddo
enddo
!$omp end do
!$omp do
do j=m_ys,m_ye
do i=m_xs,m_xe
z_t(i,j)=-m(i,j)**2*2.d0*c*(u(i+1,j)*(zm(i+1,j)-zm(i,j)) &
+u(i,j)*(zm(i,j)-zm(i-1,j)) &
+v(i,j+1)*(zm(i,j+1)-zm(i,j)) &
+v(i,j)*(zm(i,j)-zm(i,j-1)) &
+2.d0*zm(i,j) &
*(u(i+1,j)-u(i,j)+v(i,j+1)-v(i,j)))
enddo
enddo
!$omp end do
!$omp end parallel
if(option==1)then
uc=ua+u_t*ts
vc=va+v_t*ts
zc=za+z_t*ts
elseif(option==2)then
uc=u_t*ts
vc=v_t*ts
zc=z_t*ts
elseif(option==3)then
uc=u_t
vc=v_t
zc=z_t
endif
end subroutine time_integration_Square_Conservation
subroutine time_integration_Energe_Conservation(ua,va,za,u,v,z,uc,vc,zc,ts,option)
implicit none
real ,intent(in) :: ua(grid%x_grd_num_u ,grid%y_grd_num_u) ,&
va(grid%x_grd_num_v ,grid%y_grd_num_v) ,&
za(grid%x_grd_num ,grid%y_grd_num) ,&
u(grid%x_grd_num_u ,grid%y_grd_num_u) ,&
v(grid%x_grd_num_v ,grid%y_grd_num_v) ,&
z(grid%x_grd_num ,grid%y_grd_num) ,&
ts
integer ,intent(in) :: option
real ,intent(out):: uc(grid%x_grd_num_u ,grid%y_grd_num_u) ,&
vc(grid%x_grd_num_v ,grid%y_grd_num_v) ,&
zc(grid%x_grd_num ,grid%y_grd_num)
real zm(grid%x_grd_num ,grid%y_grd_num)
real u_t(grid%x_grd_num_u,grid%y_grd_num_u) ,&
v_t(grid%x_grd_num_v,grid%y_grd_num_v) ,&
zu_t(grid%x_grd_num_u,grid%y_grd_num_u),&
zv_t(grid%x_grd_num_v,grid%y_grd_num_v),&
z_t(grid%x_grd_num ,grid%y_grd_num)
real fu(grid%x_grd_num_u,grid%y_grd_num_u) ,&
fv(grid%x_grd_num_v,grid%y_grd_num_v) ,&
m(grid%x_grd_num ,grid%y_grd_num) ,&
mu(grid%x_grd_num_u,grid%y_grd_num_u) ,&
mv(grid%x_grd_num_v,grid%y_grd_num_v)
real c1,c2,c3,c4
integer i,j
integer u_xs,&
u_xe,&
u_ys,&
u_ye,&
v_xs,&
v_xe,&
v_ys,&
v_ye,&
m_xs,&
m_xe,&
m_ys,&
m_ye
u_xs = 3
u_xe = grid%x_grd_num_u-2
u_ys = 2
u_ye = grid%y_grd_num_u-1
v_xs = 2
v_xe = grid%x_grd_num_v-1
v_ys = 3
v_ye = grid%y_grd_num_v-2
m_xs = 2
m_xe = grid%x_grd_num-1
m_ys = 2
m_ye = grid%y_grd_num-1
fu = grid%f_u
fv = grid%f_v
m = grid%mapfac_m
mu = grid%mapfac_u
mv = grid%mapfac_v
c1=0.125/grid%dx
c2=g/(2.*grid%dx)
c3=0.25/grid%dx
c4=0.5/grid%dx
u_t=0.d0
v_t=0.d0
zu_t=0.d0
zv_t=0.d0
z_t=0.d0
zm=z/m
!Loop solve
!$omp parallel private(i)
!$omp do
do j=u_ys,u_ye
do i=u_xs,u_xe
zu_t(i,j)=-mu(i,j)**2*(c1*(((zm(i+1,j)+zm(i,j))*u(i+1,j)+(zm(i,j)+zm(i-1,j))*u(i,j))*(u(i+1,j)+u(i,j)) &
-((zm(i,j)+zm(i-1,j))*u(i,j)+(zm(i-1,j)+zm(i-2,j))*u(i-1,j))*(u(i,j)+u(i-1,j)) &
+((zm(i,j+1)+zm(i,j))*v(i,j+1)+(zm(i-1,j+1)+zm(i-1,j))*v(i-1,j+1))*(u(i,j+1)+u(i,j))&
-((zm(i,j)+zm(i,j-1))*v(i,j)+(zm(i-1,j)+zm(i-1,j-1))*v(i-1,j))*(u(i,j)+u(i,j-1))) &
+c2*(zm(i,j)+zm(i-1,j))*(z(i,j)-z(i-1,j))) &
+0.125*(fu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ddo
!$omp end do
!$omp do
do j=m_ys,m_ye
do i=m_xs,m_xe
z_t(i,j)=-m(i,j)**2*c4*((zm(i+1,j)+zm(i,j))*u(i+1,j)&
-(zm(i,j)+zm(i-1,j))*u(i,j) &
+(zm(i,j+1)+zm(i,j))*v(i,j+1)&
-(zm(i,j)+zm(i,j-1))*v(i,j))
enddo
enddo
!$omp end do
!$omp end parallel
!$omp parallel private(i)
!$omp do
do j=u_ys,u_ye
do i=u_xs,u_xe
u_t(i,j)=2./(z(i,j)+z(i-1,j))*(zu_t(i,j)-u(i,j)*(z_t(i,j)+z_t(i-1,j))*0.5)
enddo
enddo
!$omp end do
!$omp do
do j=v_ys,v_ye
do i=v_xs,v_xe
v_t(i,j)=2./(z(i,j)+z(i,j-1))*(zv_t(i,j)-v(i,j)*(z_t(i,j)+z_t(i,j-1))*0.5)
enddo
enddo
!$omp end do
!$omp end parallel
!print*,'max u_t = ',maxval(abs(u_t)),' max v_t = ',maxval(abs(v_t)),' max z_t = ',maxval(abs(z_t)),' maxloc=',maxloc(z_t)
!pause
if(option==1)then
uc=ua+u_t*ts
vc=va+v_t*ts
zc=za+z_t*ts
elseif(option==2)then
uc=u_t*ts
vc=v_t*ts
zc=z_t*ts
elseif(option==3)then
uc=u_t
vc=v_t
zc=z_t
endif
end subroutine time_integration_Energe_Conservation
end module integration