-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathsmoke_example_01.py
More file actions
80 lines (69 loc) · 2.29 KB
/
Copy pathsmoke_example_01.py
File metadata and controls
80 lines (69 loc) · 2.29 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
from pyCubbyFlow import (
FDMGaussSeidelSolver2,
Frame,
GridFractionalSinglePhasePressureSolver2,
GridSmokeSolver2,
Logging,
Sphere2,
VolumeGridEmitter2,
)
import sys
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
ANIM_NUM_FRAMES = 360
ANIM_FPS = 60
def main():
# Create smoke solver
resX = 100
solver = GridSmokeSolver2(resolution=(resX, 2 * resX), domainSizeX=1.0)
# Customize pressure solver for real-time sim (less accurate, but much faster)
pressureSolver = GridFractionalSinglePhasePressureSolver2()
pressureSolver.linearSystemSolver = FDMGaussSeidelSolver2(20, 20, 0.001)
solver.pressureSolver = pressureSolver
# Setup emitter
sphere = Sphere2(center=(0.5, 0.5), radius=0.15)
emitter = VolumeGridEmitter2(sourceRegion=sphere)
solver.emitter = emitter
emitter.AddStepFunctionTarget(solver.smokeDensity, 0.0, 1.0)
emitter.AddStepFunctionTarget(solver.temperature, 0.0, 1.0)
# Visualization
fig = plt.figure()
den = np.array(solver.smokeDensity.GetDataAccessor(), copy=False)
im = plt.imshow(
den,
vmin=0,
vmax=1,
cmap=plt.cm.gray,
interpolation="nearest",
animated=True,
origin="lower",
)
# Animation
frame = Frame(0, 1.0 / ANIM_FPS)
def updateFig(*args):
solver.Update(frame)
frame.Advance()
den = np.array(solver.smokeDensity.GetDataAccessor(), copy=False)
im.set_data(den)
return (im,)
if len(sys.argv) > 1:
output_format = sys.argv[1]
if output_format == "gif":
anim = animation.FuncAnimation(
fig, updateFig, frames=ANIM_NUM_FRAMES, interval=ANIM_FPS, blit=True
)
anim.Save("SmokeExample1.gif", fps=ANIM_FPS, dpi=72, writer="imagemagick")
elif output_format == "mp4":
anim = animation.FuncAnimation(
fig, updateFig, frames=ANIM_NUM_FRAMES, interval=ANIM_FPS, blit=True
)
anim.Save("SmokeExample1.mp4", fps=ANIM_FPS, writer="ffmpeg")
else:
animation.FuncAnimation(
fig, updateFig, frames=ANIM_NUM_FRAMES, interval=1, blit=True
)
plt.show()
if __name__ == "__main__":
Logging.Mute()
main()