-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.f90
More file actions
364 lines (224 loc) · 13.4 KB
/
Copy pathmain.f90
File metadata and controls
364 lines (224 loc) · 13.4 KB
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
! y=1 ______________
! / /| | Author : Zi-Hsuan Wei
! / / | | Version : 1.8
! /____________ / | | Web : http://smetana.me.ntust.edu.tw/
! | | | |
! | | | |
! | | x=y=z=0 | |
! | |_________|___|x=1
! | / | /
! | / | /
! |/___________|/
! z=1
!
program main
use variables
use mpi
use omp_lib
implicit none
!------------------- OPENMP ------------------------!
nthreads = 4
call omp_set_num_threads(nthreads)
!------------------- OPENMP ------------------------!
!------------------------ MPI ------------------------!
call MPI_INIT(ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr)
call Mpi_division()
!------------------------ MPI ------------------------!
!--------for nz--------!
istart = gstart(myid) !
iend = gend0(myid) !
igcount = gcount(myid) !
!--------for nz--------!
!-----------------Parameters for the simulation------------------!
omega = 1.5 ! Set value for SOR method
zeta = 1.e-4 ! zeta for solving pressure matrix
itmax = 3000 ! maximum for zeta in Gauss Seidel subroutines
zeta_vel = 1.e-10 ! convergence condition for velocity field
time = 0.0 ! initialize time of simulation
AOA1 = 5.D0 ! initialize AOA of simulation
nstep = 100000 ! number of timesteps for the simulation
isto = 100 ! data stored every 'isto' steps
LES = 0 ! the LES mode. 1 : on ; 0 : off
steadiness = 2 ! steady : 1 ; unsteady : 2
totalcosttime = 0 ! initialize wall time
inputfile = '0000.Q' !input first q file
StartDynamic = 1000000
NACA_filename = 'NACA0012.DAT'
!-----------------Parameters for the simulation------------------!
!--------------------------------------------------------------------!
call reading_data() ! define dx, dy, dz, nu = 1./Re
!--------------------------------------------------------------------!
!--------------------------------------------------------------------!
if(Gridder=='non-uniform')then
call gridder_unequal() ! define unequal mesh
else if(Gridder=='uniform')then
call gridder_equal() ! define equal mesh
end if
!--------------------------------------------------------------------!
!--------------------------------------------------------------------!
call initial_conditions() !call initial conditions
!--------------------------------------------------------------------!
!--------------------------------------------------------------------!
!call reading_variables() !input first q file
!--------------------------------------------------------------------!
!--------------------------------------------------------------------!
call boundary_conditions() !call boundary conditions
!--------------------------------------------------------------------!
!--------------------------------------------------------------------!
!call MATRIX_PARSEC(myid,zc,yc,AOA,poly) ! Creat function of NACA0012
!call MPI_BARRIER(MPI_COMM_WORLD, ierr)
!--------------------------------------------------------------------!
!--------------------------------------------------------------------!
AOA = AOA1
call RayCasting() ! Creat ETA of airfoil
!--------------------------------------------------------------------!
if(myid==master)then
call filereachtime()
call filerInfo()
end if
!----------------------------for sendrecv----------------------------!
l_nbr = myid - 1 !
r_nbr = myid + 1 !
if(myid == 0) then; l_nbr=MPI_PROC_NULL; end if !
if(myid == (nproc-1)) then; r_nbr=MPI_PROC_NULL; end if !
!----------------------------for sendrecv----------------------------!
write(*,*) myid, 'istart = ', istart, 'iend = ', iend, 'gcount = ', igcount
call MPI_BARRIER(MPI_COMM_WORLD, ierr)
!-------------------------main loop on the timesteps----------------------!
do istep=1,nstep
totalstarttime = MPI_WTIME()
if( istep >= StartDynamic )then
!--------------------------------------------------------------------!
call dynamic_AOA() ! Change AOA
!--------------------------------------------------------------------!
!--------------------------------------------------------------------!
call RayCasting() ! Creat ETA of airfoil
!--------------------------------------------------------------------!
end if
!----------data transformation among nodes----------!
icount = 2*(nx+4)*(ny+4)
itag = 110
call MPI_SENDRECV( u(-1,-1,istart), icount, MPI_REAL8, l_nbr, itag, &
u(-1,-1,iend+1), icount, MPI_REAL8, r_nbr, itag, MPI_COMM_WORLD, status, ierr )
itag = 120
call MPI_SENDRECV( v(-1,-1,istart), icount, MPI_REAL8, l_nbr, itag, &
v(-1,-1,iend+1), icount, MPI_REAL8, r_nbr, itag, MPI_COMM_WORLD, status, ierr )
itag = 130
call MPI_SENDRECV( w(-1,-1,istart), icount, MPI_REAL8, l_nbr, itag, &
w(-1,-1,iend+1), icount, MPI_REAL8, r_nbr, itag, MPI_COMM_WORLD, status, ierr )
itag = 140
call MPI_SENDRECV( u(-1,-1,iend-1), icount, MPI_REAL8, r_nbr, itag, &
u(-1,-1,istart-2), icount, MPI_REAL8, l_nbr, itag, MPI_COMM_WORLD, status, ierr )
itag = 150
call MPI_SENDRECV( v(-1,-1,iend-1), icount, MPI_REAL8, r_nbr, itag, &
v(-1,-1,istart-2), icount, MPI_REAL8, l_nbr, itag, MPI_COMM_WORLD, status, ierr )
itag = 160
call MPI_SENDRECV( w(-1,-1,iend-1), icount, MPI_REAL8, r_nbr, itag, &
w(-1,-1,istart-2), icount, MPI_REAL8, l_nbr, itag, MPI_COMM_WORLD, status, ierr )
icount = 2
itag = 170
call MPI_SENDRECV( iDz(istart), icount, MPI_REAL8, l_nbr, itag, &
iDz(iend+1), icount, MPI_REAL8, r_nbr, itag, MPI_COMM_WORLD, status, ierr )
itag = 180
call MPI_SENDRECV( Dzs(istart), icount, MPI_REAL8, l_nbr, itag, &
Dzs(iend+1), icount, MPI_REAL8, r_nbr, itag, MPI_COMM_WORLD, status, ierr )
itag = 190
call MPI_SENDRECV( iDz(iend-1), icount, MPI_REAL8, r_nbr, itag, &
iDz(istart-2), icount, MPI_REAL8, l_nbr, itag, MPI_COMM_WORLD, status, ierr )
itag = 200
call MPI_SENDRECV( Dzs(iend-1), icount, MPI_REAL8, r_nbr, itag, &
Dzs(istart-2), icount, MPI_REAL8, l_nbr, itag, MPI_COMM_WORLD, status, ierr )
call MPI_BARRIER(MPI_COMM_WORLD, ierr)
!----------data transformation among nodes----------!
!------------------------------------------------------------------------------------------------------!
call CalculateSmagorinskyViscosity() ! calculate Smagorinsky Viscosity
!------------------------------------------------------------------------------------------------------!
!------------------------------------------------------------------------------------------------------!
call discretisation_QUICK_centre() ! calculate velocity field
!------------------------------------------------------------------------------------------------------!
!----------data transformation among nodes----------!
icount = (nx+4)*(ny+4)
itag = 240
call MPI_SENDRECV( w_star(-1,-1,iend), icount, MPI_REAL8, r_nbr, itag, &
w_star(-1,-1,istart-1), icount, MPI_REAL8, l_nbr, itag, MPI_COMM_WORLD, status, ierr )
call MPI_BARRIER(MPI_COMM_WORLD, ierr)
!----------data transformation among nodes----------!
!------------------------------------------------------------------------------------------------------!
call gauss_seidel() ! calculate pressure field
!------------------------------------------------------------------------------------------------------!
!----------data transformation among nodes----------!
icount = (nx+4)*(ny+4)
itag = 270
call MPI_SENDRECV( p(-1,-1,istart), icount, MPI_REAL8, l_nbr, itag, &
p(-1,-1,iend+1), icount, MPI_REAL8, r_nbr, itag, MPI_COMM_WORLD, status, ierr )
call MPI_BARRIER(MPI_COMM_WORLD, ierr)
!----------data transformation among nodes----------!
!------------------------------------------------------------------------------------------------------!
call calcul_new_velocity() ! update velocity field
!------------------------------------------------------------------------------------------------------!
!------------------------------------------------------------------------------------------------------!
call virtualForceIntegrator() ! COEFFICIENTS: CD and Center_CL,Distance,Velocity for solid
!------------------------------------------------------------------------------------------------------!
!------------------------------------------------------------------------------------------------------!
call Updating_velocity() ! update velocity field
!------------------------------------------------------------------------------------------------------!
!------------------------------------------------------------------------------------------------------!
call boundary_conditions() ! recall boundary conditions to update them
!------------------------------------------------------------------------------------------------------!
time = time + dt
!----------data collect among nodes for filer----------!
icount = igcount*(nx)*(ny)
!Send my results back to the master
if(myid>master)then
itag = 10
call MPI_SEND( pre(1,1,istart), icount, MPI_REAL8, master, itag, MPI_COMM_WORLD, ierr )
itag = 20
call MPI_SEND( uc(1,1,istart), icount, MPI_REAL8, master, itag, MPI_COMM_WORLD, ierr )
itag = 30
call MPI_SEND( vc(1,1,istart), icount, MPI_REAL8, master, itag, MPI_COMM_WORLD, ierr )
itag = 40
call MPI_SEND( wc(1,1,istart), icount, MPI_REAL8, master, itag, MPI_COMM_WORLD, ierr )
end if
!call MPI_BARRIER(MPI_COMM_WORLD, ierr)
!Wait to receive results from each task
if(myid==master)then
do i = 1, (nproc-1)
itag = 10
call MPI_RECV( pre(1,1,gstart(i)), icount, MPI_REAL8, i, itag, MPI_COMM_WORLD, status, ierr )
itag = 20
call MPI_RECV( uc(1,1,gstart(i)), icount, MPI_REAL8, i, itag, MPI_COMM_WORLD, status, ierr )
itag = 30
call MPI_RECV( vc(1,1,gstart(i)), icount, MPI_REAL8, i, itag, MPI_COMM_WORLD, status, ierr )
itag = 40
call MPI_RECV( wc(1,1,gstart(i)), icount, MPI_REAL8, i, itag, MPI_COMM_WORLD, status, ierr )
end do
end if
call MPI_BARRIER(MPI_COMM_WORLD, ierr)
!----------data collect among nodes for filer----------!
if(myid==master)then
write(*,*) 'time = ',time
call filerProcess()
end if
VelocityDifference = 1024
if (mod(istep,isto)==0) then ! write results if isto = istep
if(myid==master)then
call filereachtime()
end if
call check_steady()
end if
!----------calculate wall time----------!
totalfinaltime = MPI_WTIME()
totalcosttime = totalcosttime + (totalfinaltime-totalstarttime)
if(myid==master)then
write(*,*) 'each cost = ', totalfinaltime-totalstarttime, 'total cost = ', totalcosttime, &
'AOA = ', AOA
end if
!----------calculate wall time----------!
end do
istep = istep - 1
!-------------------------main loop on the timesteps----------------------!
if(myid==master)then; call filer_final(); end if
call MPI_FINALIZE(ierr)
end program main