forked from spoonacular/LBM_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulticomponent_2D.py
95 lines (71 loc) · 2.22 KB
/
multicomponent_2D.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
import numpy
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from LBM_python import *
#parameters
numpy.set_printoptions(3)
nx = 200
ny = 200
center_x = 5
center_y = 5
radius = 2
omega1 = 1
omega2 = 1
#define geometry
circle = Indicator.circle(center_x,center_y,radius)
centerBox = Indicator.cuboid(80,80,120,120)
cGeometry = CuboidGeometry2D(0,0,nx,ny)
cGeometry.setPeriodicity()
superG = SuperGeometry(cGeometry)
superG.rename(0,1)
superG.rename(1,2,centerBox)
print('================================================')
#lattice
rho = 1
rhoZero = 0
u = [0,0.]
sLattice1 = SuperLattice2D(superG)
sLattice2 = SuperLattice2D(superG)
sLattice1.defineRhoU(superG,1,rho,u)
sLattice1.defineRhoU(superG,2,rhoZero,u)
sLattice2.defineRhoU(superG,1,rhoZero,u)
sLattice2.defineRhoU(superG,2,rho,u)
bulk1 = ShanChenBGKdynamics(omega1)
bulk2 = ShanChenBGKdynamics(omega2)
sLattice1.defineDynamics(superG,1,bulk1)# SuperGeometry, materialNum, dynamics
sLattice1.defineDynamics(superG,2,bulk1)
sLattice2.defineDynamics(superG,1,bulk2)
sLattice2.defineDynamics(superG,2,bulk2)
outputDirectory = 'data'
if not os.path.exists(outputDirectory):
os.makedirs(outputDirectory)
print('initial average rho1: {0:.5f}'.format(sLattice1.getAverageRho())) #initialize
print('initial average rho2: {0:.5f}'.format(sLattice2.getAverageRho()))
G = 3
sLattice1.addLatticeCoupling(superG,G,sLattice2)
# MAIN LOOP
fig = plt.figure()
ims = []
for iT in numpy.arange( 1000 ):
if iT%50==0:
im = plt.imshow(sLattice1.rhoMap, animated=True)
ims.append([im])
plt.draw()
plt.pause(0.00001)
# plt.draw()
# plt.pause(0.01)
# numpy.savetxt('{}/rho1_{}'.format(outputDirectory,iT),sLattice1.getRhoMap())
print('{}/1000'.format(iT))
sLattice1.prepareCoupling()
sLattice2.prepareCoupling()
sLattice1.executeCoupling(sLattice2)
sLattice1.collide()
sLattice2.collide()
sLattice1.stream()
sLattice2.stream()
ani = animation.ArtistAnimation(fig, ims, interval=100, blit=True, repeat_delay=1000)
plt.show()
# print('===============================final Ux:\n{}\n'.format(sLattice1.getUxMap()))
print('final average rho1: {0:.5f}'.format(sLattice1.getAverageRho()))
print('final average rho2: {0:.5f}'.format(sLattice2.getAverageRho()))
plt.show()