forked from jviquerat/lbm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poiseuille.py
executable file
·116 lines (95 loc) · 2.76 KB
/
poiseuille.py
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
# Generic imports
import math
import time
# Custom imports
from lattice import *
###############################################
### LBM poiseuille
###############################################
# Domain size
x_min =-0.2
x_max = 2.0
y_min =-0.2
y_max = 0.2
# Free parameters
# L_lbm corresponds to y length
# u_lbm corresponds to max velocity
Re_lbm = 100.0
u_lbm = 0.1
L_lbm = 100
t_max = 8.0
# Deduce other parameters
Cs = 1.0/math.sqrt(3.0)
ny = L_lbm
u_avg = u_lbm/2.0
nu_lbm = u_avg*L_lbm/Re_lbm
tau_lbm = 0.5 + nu_lbm/(Cs**2)
rho_lbm = 1.0
dt = Re_lbm*nu_lbm/L_lbm**2
it_max = math.floor(t_max/dt)
dx = (y_max-y_min)/ny
dy = dx
nx = math.floor(ny*(x_max-x_min)/(y_max-y_min))
# Other parameters
output_freq = 500
dpi = 200
sigma = math.floor(it_max/5)
# Initialize lattice
lattice = Lattice(nx = nx,
ny = ny,
dx = dx,
dt = dt,
tau_lbm = tau_lbm,
Re_lbm = Re_lbm,
u_lbm = u_lbm,
L_lbm = L_lbm,
nu_lbm = nu_lbm,
rho_lbm = rho_lbm,
x_min = x_min,
x_max = x_max,
y_min = y_min,
y_max = y_max,
dpi = dpi,
t_max = t_max,
it_max = it_max)
# Initialize fields
lattice.set_inlet_poiseuille(u_lbm, rho_lbm, 0, sigma)
# Set initial distributions
lattice.equilibrium()
lattice.g = lattice.g_eq.copy()
# Count time
start_time = time.time()
# Solve
print('### Solving')
while (lattice.compute):
# Printings
lattice.it_printings()
# Progressively impose Poiseuille
lattice.set_inlet_poiseuille(u_lbm, rho_lbm, lattice.it, sigma)
# Compute macroscopic fields
lattice.macro()
# Output field
lattice.output_fields(lattice.it,
output_freq,
u_norm = True,
u_stream = False)
# Compute equilibrium state
lattice.equilibrium()
# Streaming
lattice.collision_stream()
# Boundary conditions
lattice.zou_he_bottom_wall_velocity()
lattice.zou_he_left_wall_velocity()
lattice.zou_he_right_wall_pressure()
lattice.zou_he_top_wall_velocity()
lattice.zou_he_bottom_left_corner()
lattice.zou_he_top_left_corner()
lattice.zou_he_top_right_corner()
lattice.zou_he_bottom_right_corner()
# Check stopping criterion
lattice.check_stop()
# Count time
end_time = time.time()
print("# Loop time = {:f}".format(end_time - start_time))
# Output error with exact solution
lattice.poiseuille_error(u_lbm)