-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmod_solver.f90
395 lines (330 loc) · 16.4 KB
/
mod_solver.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
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
module mod_solver
use mod_read_gmsh, only: nbelm
use mod_cell_2D, only: cell, cell_2D, nbfaces, face
use mod_fvm_face_2D, only: fvm_face_2D, face_2D
implicit none
real(8) :: r_gaz, invdt, dt, tmax
real(8), parameter :: cfl = 0.9d0
real(8), dimension(:), allocatable :: rho, ux, uy, t
real(8), dimension(:), allocatable :: p, a, b, e
real(8), dimension(:,:), allocatable :: vect_u, vect_unew, flux, rhs, rhsdummy_symetrie, rhsdummy_entree, rhsdummy_sortie
real(8), dimension(:,:), allocatable :: vardummy_symetrie, vardummy_entree, vardummy_sortie
integer :: nb_symmetry = 0, nb_inlet = 0, nb_outlet = 0, nmax
contains
!----------------------------------------------------------------------
subroutine donnee_initiale
implicit none
if (.not. allocated(rho)) then
allocate(rho(1:nbelm))
endif
if (.not. allocated(ux)) then
allocate(ux(1:nbelm))
endif
if (.not. allocated(uy)) then
allocate(uy(1:nbelm))
endif
if (.not. allocated(t)) then
allocate(t(1:nbelm))
endif
if (.not. allocated(p)) then
allocate(p(1:nbelm))
endif
if (.not. allocated(a)) then
allocate(a(1:nbelm))
endif
if (.not. allocated(b)) then
allocate(b(1:nbelm))
endif
if (.not. allocated(e)) then
allocate(e(1:nbelm))
endif
if (.not. allocated(vect_u)) then
allocate(vect_u(1:nbelm,1:4))
endif
if (.not. allocated(vect_unew)) then
allocate(vect_unew(1:nbelm,1:4))
endif
! hard code, need to be modified
rho = 0.2d-4 !0.2969689477d-4
ux = 500.0d0 !1059.458022d0
uy = 0.0d0
t = 1000.0d0!1295.646765d0
end subroutine donnee_initiale
!----------------------------------------------------------------------
subroutine allocate_vardummy
implicit none
integer :: i
type(fvm_face_2D), pointer :: pfac
if (nb_symmetry > 0) return
! Allocating vardummy
do i = 1, nbfaces
pfac => face_2D(i)%f
if (pfac%bc_typ == 1) then ! Airfoil - symetrie
nb_symmetry = nb_symmetry + 1
endif
if (pfac%bc_typ == 2) then ! Inflow
nb_inlet = nb_inlet + 1
endif
if (pfac%bc_typ == 3) then ! Outflow
nb_outlet = nb_outlet + 1
endif
enddo
if (.not. allocated(vardummy_symetrie)) then
allocate(vardummy_symetrie(1:nb_symmetry,1:8))
vardummy_symetrie = 0.0d0
endif
if (.not. allocated(vardummy_entree)) then
allocate(vardummy_entree(1:nb_inlet,1:8))
vardummy_entree = 0.0d0
endif
if (.not. allocated(vardummy_sortie)) then
allocate(vardummy_sortie(1:nb_outlet,1:8))
vardummy_sortie = 0.0d0
endif
end subroutine allocate_vardummy
!----------------------------------------------------------------------
subroutine conditions_aux_limites
implicit none
integer :: icel, ifac, jfac
integer :: cnt_symmetry, cnt_inlet, cnt_outlet
type(cell_2D), pointer :: pcel
type(face), pointer :: pfac
cnt_symmetry = 0
cnt_inlet = 0
cnt_outlet = 0
do icel = 1, nbelm
pcel => cell(icel)%p
do ifac = 1, 4
pfac => pcel%faces(ifac)
if (pfac%bc_typ == 1) then ! Airfoil - symetrie
cnt_symmetry = cnt_symmetry + 1
vardummy_symetrie(cnt_symmetry, 1) = rho(icel)
vardummy_symetrie(cnt_symmetry, 2) = ux(icel)
vardummy_symetrie(cnt_symmetry, 3) = -uy(icel)
vardummy_symetrie(cnt_symmetry, 4) = t(icel)
endif
if (pfac%bc_typ == 2) then ! Inflow
cnt_inlet = cnt_inlet + 1
vardummy_entree(cnt_inlet, 1) = 0.2969689477d-4
vardummy_entree(cnt_inlet, 2) = 1059.458022d0
vardummy_entree(cnt_inlet, 3) = 0.0d0
vardummy_entree(cnt_inlet, 4) = 1295.646765d0
endif
if (pfac%bc_typ == 3) then ! Outflow
cnt_outlet = cnt_outlet + 1
vardummy_sortie(cnt_outlet, 1) = rho(icel)
vardummy_sortie(cnt_outlet, 2) = ux(icel)
vardummy_sortie(cnt_outlet, 3) = uy(icel)
vardummy_sortie(cnt_outlet, 4) = t(icel)
endif
enddo
enddo
end subroutine conditions_aux_limites
!----------------------------------------------------------------------
!--- calcul des quantités dérivées
subroutine calcul_derived_quantities
implicit none
r_gaz = 1.3806503d-23 / 0.663d-25
p = rho * r_gaz * t
b = sqrt(3.0d0 * r_gaz * t)
a = rho / (8.0d0 * b**3)
e = 0.5d0 * rho * (ux**2 + uy**2) + 3.0d0 /2.0d0 * rho * r_gaz * t
vardummy_symetrie(:, 5) = vardummy_symetrie(:, 1) * r_gaz * vardummy_symetrie(:, 4)
vardummy_symetrie(:, 7) = sqrt(3.0d0 * r_gaz * vardummy_symetrie(:, 4))
vardummy_symetrie(:, 6) = vardummy_symetrie(:, 1) / (8.0d0 * vardummy_symetrie(:, 7)**3)
vardummy_symetrie(:, 8) = 0.5d0 * vardummy_symetrie(:, 1) * (vardummy_symetrie(:, 2)**2 + vardummy_symetrie(:, 3)**2) + 3.0d0 /2.0d0 * vardummy_symetrie(:, 1) * r_gaz * vardummy_symetrie(:, 4)
vardummy_entree(:, 5) = vardummy_entree(:, 1) * r_gaz * vardummy_entree(:, 4)
vardummy_entree(:, 7) = sqrt(3.0d0 * r_gaz * vardummy_entree(:, 4))
vardummy_entree(:, 6) = vardummy_entree(:, 1) / (8.0d0 * vardummy_entree(:, 7)**3)
vardummy_entree(:, 8) = 0.5d0 * vardummy_entree(:, 1) * (vardummy_entree(:, 2)**2 + vardummy_entree(:, 3)**2) + 3.0d0 /2.0d0 * vardummy_entree(:, 1) * r_gaz * vardummy_entree(:, 4)
vardummy_sortie(:, 5) = vardummy_sortie(:, 1) * r_gaz * vardummy_sortie(:, 4)
vardummy_sortie(:, 7) = sqrt(3.0d0 * r_gaz * vardummy_sortie(:, 4))
vardummy_sortie(:, 6) = vardummy_sortie(:, 1) / (8.0d0 * vardummy_sortie(:, 7)**3)
vardummy_sortie(:, 8) = 0.5d0 * vardummy_sortie(:, 1) * (vardummy_sortie(:, 2)**2 + vardummy_sortie(:, 3)**2) + 3.0d0 /2.0d0 * vardummy_sortie(:, 1) * r_gaz * vardummy_sortie(:, 4)
end subroutine calcul_derived_quantities
!----------------------------------------------------------------------
!--- calcul du vecteur des quantités conservatives
subroutine calcul_conservative_vector
implicit none
vect_u(:,1) = rho(:)
vect_u(:,2) = rho(:) * ux(:)
vect_u(:,3) = rho(:) * uy(:)
vect_u(:,4) = e(:)
vect_unew = vect_u
end subroutine calcul_conservative_vector
!----------------------------------------------------------------------
!--- pas de temps et vitesse maximum
subroutine timestep
implicit none
real(8) :: norme_u, perimetre
integer :: i, face1, face2, face3, face4
type(cell_2D), pointer :: pc
type(face), pointer :: pf1, pf2, pf3, pf4
invdt = 0.0d0
do i = 1, nbelm
pc => cell(i)%p
norme_u = sqrt(ux(i)**2 + uy(i)**2)
pf1 => pc%faces(1)
pf2 => pc%faces(2)
pf3 => pc%faces(3)
pf4 => pc%faces(4)
face1 = pf1%idface
face2 = pf2%idface
face3 = pf3%idface
face4 = pf4%idface
if (face1 == 0) then
print*, 'face1 = 0'
print*, 'Please check cell ', i
endif
if (face2 == 0) then
print*, 'face2 = 0'
endif
if (face3 == 0) then
print*, 'face3 = 0'
endif
if (face4 == 0) then
print*, 'face4 = 0'
print*, 'Please check cell ', i
endif
perimetre = face_2D(face1)%f%len_nor + face_2D(face2)%f%len_nor + face_2D(face3)%f%len_nor + face_2D(face4)%f%len_nor
invdt = max(invdt, (norme_u+b(i)*perimetre / pc%vol))
enddo
dt = cfl / invdt
end subroutine timestep
!----------------------------------------------------------------------
subroutine assign_lr_cell
use mod_struct_to_array, only: lr_cell
implicit none
integer :: ifac, icel, fac
integer :: cnt_symmetry, cnt_inlet, cnt_outlet
type(cell_2D), pointer :: pcel
type(face), pointer :: pfac
type(fvm_face_2D), pointer :: pfac_fvm
cnt_symmetry = 0
cnt_inlet = 0
cnt_outlet = 0
! Create left cell - right cell table for boundary faces
do icel = 1, nbelm
pcel => cell(icel)%p
do ifac = 1, 4
pfac => pcel%faces(ifac)
if (pfac%bc_typ == 1) then ! Airfoil - symetrie
cnt_symmetry = cnt_symmetry + 1
fac = pfac%idface
lr_cell(fac, 1) = icel
lr_cell(fac, 2) = cnt_symmetry ! dummy cell for symmetry bc
endif
if (pfac%bc_typ == 2) then ! Inflow
cnt_inlet = cnt_inlet + 1
fac = pfac%idface
lr_cell(fac, 1) = icel
lr_cell(fac, 2) = cnt_inlet ! dummy cell for inlet bc
endif
if (pfac%bc_typ == 3) then ! Outflow
cnt_outlet = cnt_outlet + 1
fac = pfac%idface
lr_cell(fac, 1) = icel
lr_cell(fac, 2) = cnt_outlet ! dummy cell for outlet bc
endif
enddo
enddo
! Create left cell - right cell table for internal faces
do ifac = 1, nbfaces
pfac_fvm => face_2D(ifac)%f
if (associated(pfac_fvm%left_cell) .and. associated(pfac_fvm%right_cell)) then
lr_cell(ifac, 1) = pfac_fvm%left_cell%ident
lr_cell(ifac, 2) = pfac_fvm%right_cell%ident
endif
enddo
end subroutine assign_lr_cell
!----------------------------------------------------------------------
subroutine calcul_flux
use mod_flux
use mod_struct_to_array
implicit none
integer :: ifac, left_cell, right_cell
real(8) :: flux_plus(1:4), flux_minus(1:4)
if (.not. allocated(flux)) then
allocate(flux(1:nbfaces,1:4))
endif
do ifac = 1, nbfaces
left_cell = lr_cell(ifac,1)
right_cell = lr_cell(ifac,2)
if (bc_typ(ifac) == 0) then
flux_plus(:) = fluxp(rho(left_cell), ux(left_cell), uy(left_cell), &
& e(left_cell), p(left_cell), t(left_cell), a(left_cell), b(left_cell), &
& norm_x(ifac), norm_y(ifac))
flux_minus(:) = fluxm(rho(right_cell), ux(right_cell), uy(right_cell), &
& e(right_cell), p(right_cell), t(right_cell), a(right_cell), b(right_cell), &
& norm_x(ifac), norm_y(ifac))
flux(ifac,:) = len_norm(ifac) * (flux_plus(:) + flux_minus(:))
endif
if (bc_typ(ifac) == 1) then !symmetry
flux_plus(:) = fluxp(rho(left_cell), ux(left_cell), uy(left_cell), &
& e(left_cell), p(left_cell), t(left_cell), a(left_cell), b(left_cell), &
& norm_x(ifac), norm_y(ifac))
flux_minus(:) = fluxm(vardummy_symetrie(right_cell,1), vardummy_symetrie(right_cell,2), vardummy_symetrie(right_cell,3), &
& vardummy_symetrie(right_cell,8), vardummy_symetrie(right_cell,5), vardummy_symetrie(right_cell,4), vardummy_symetrie(right_cell,6), vardummy_symetrie(right_cell,7), &
& norm_x(ifac), norm_y(ifac))
flux(ifac,:) = len_norm(ifac) * (flux_plus(:) + flux_minus(:))
endif
if (bc_typ(ifac) == 2) then ! Inflow
flux_plus(:) = fluxp(rho(left_cell), ux(left_cell), uy(left_cell), &
& e(left_cell), p(left_cell), t(left_cell), a(left_cell), b(left_cell), &
& norm_x(ifac), norm_y(ifac))
flux_minus(:) = fluxm(vardummy_entree(right_cell,1), vardummy_entree(right_cell,2), vardummy_entree(right_cell,3), &
& vardummy_entree(right_cell,8), vardummy_entree(right_cell,5), vardummy_entree(right_cell,4), vardummy_entree(right_cell,6), vardummy_entree(right_cell,7), &
& norm_x(ifac), norm_y(ifac))
flux(ifac,:) = len_norm(ifac) * (flux_plus(:) + flux_minus(:))
endif
if (bc_typ(ifac) == 3) then ! Outflow
flux_plus(:) = fluxp(rho(left_cell), ux(left_cell), uy(left_cell), &
& e(left_cell), p(left_cell), t(left_cell), a(left_cell), b(left_cell), &
& norm_x(ifac), norm_y(ifac))
flux_minus(:) = fluxm(vardummy_sortie(right_cell,1), vardummy_sortie(right_cell,2), vardummy_sortie(right_cell,3), &
& vardummy_sortie(right_cell,8), vardummy_sortie(right_cell,5), vardummy_sortie(right_cell,4), vardummy_sortie(right_cell,6), vardummy_sortie(right_cell,7), &
& norm_x(ifac), norm_y(ifac))
flux(ifac,:) = len_norm(ifac) * (flux_plus(:) + flux_minus(:))
endif
enddo
end subroutine calcul_flux
!----------------------------------------------------------------------
subroutine calcul_rhs
use mod_struct_to_array
implicit none
integer :: ifac, left_cell, right_cell
if (.not. allocated(rhs)) then
allocate(rhs(nbelm,4))
endif
rhs = 0.0d0
do ifac = 1, nbfaces
left_cell = lr_cell(ifac,1)
right_cell = lr_cell(ifac,2)
if (bc_typ(ifac) == 0) then
rhs(left_cell,:) = rhs(left_cell,:) - flux(ifac,:)
rhs(right_cell,:) = rhs(right_cell,:) + flux(ifac,:)
endif
if (bc_typ(ifac) /= 0) then
rhs(left_cell,:) = rhs(left_cell,:) - flux(ifac,:)
endif
enddo
end subroutine calcul_rhs
!----------------------------------------------------------------------
subroutine euler_time_iteration
use mod_struct_to_array, only: vol
implicit none
integer :: icel
do icel = 1, nbelm
vect_unew(icel,:) = vect_u(icel,:) + dt / vol(icel) * rhs(icel,:)
enddo
end subroutine euler_time_iteration
!----------------------------------------------------------------------
subroutine calcul_rho_ux_uy_t
implicit none
rho(1:nbelm) = vect_u(1:nbelm,1)
ux(1:nbelm) = vect_u(1:nbelm,2) / rho(1:nbelm)
uy(1:nbelm) = vect_u(1:nbelm,3) / rho(1:nbelm)
t(1:nbelm) = 2.0d0/(3.0d0 * r_gaz * rho(1:nbelm)) *(vect_u(1:nbelm,4)-0.5d0*rho(1:nbelm)*(ux(1:nbelm)**2+uy(1:nbelm)**2))
end subroutine calcul_rho_ux_uy_t
!----------------------------------------------------------------------
end module