forked from jviquerat/lbm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cavity_1.py
executable file
·102 lines (82 loc) · 2.34 KB
/
cavity_1.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
# Generic imports
import math
import time
# Custom imports
from lattice import *
###############################################
### LBM lid-driven cavity
###############################################
### Free parameters
Re_lbm = 1000.0
u_lbm = 0.03
L_lbm = 600
t_max = 20.0
# Deduce other parameters
Cs = 1.0/math.sqrt(3.0)
nx = L_lbm
nu_lbm = u_lbm*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)
# Other parameters
output_freq = 500
dpi = 200
# Initialize lattice
lattice = Lattice(nx = nx,
ny = nx,
dx = 1.0/nx,
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,
dpi = dpi,
t_max = t_max,
it_max = it_max)
# Initialize fields
lattice.set_cavity(u_lbm)
lattice.rho *= rho_lbm
# 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()
# 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_velocity()
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.cavity_error(u_lbm)
# Output streamlines
lattice.output_fields(1, 1,
u_norm = False,
u_stream = True)