Blender  V3.3
smoke_script.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2016 Blender Foundation. All rights reserved. */
3 
8 #include <string>
9 
11 // VARIABLES
13 
14 const std::string smoke_variables =
15  "\n\
16 mantaMsg('Smoke variables low')\n\
17 preconditioner_s$ID$ = PcMGStatic\n\
18 using_colors_s$ID$ = $USING_COLORS$\n\
19 using_heat_s$ID$ = $USING_HEAT$\n\
20 using_fire_s$ID$ = $USING_FIRE$\n\
21 using_noise_s$ID$ = $USING_NOISE$\n\
22 vorticity_s$ID$ = $VORTICITY$\n\
23 buoyancy_dens_s$ID$ = float($BUOYANCY_ALPHA$) / float($FLUID_DOMAIN_SIZE$)\n\
24 buoyancy_heat_s$ID$ = float($BUOYANCY_BETA$) / float($FLUID_DOMAIN_SIZE$)\n\
25 dissolveSpeed_s$ID$ = $DISSOLVE_SPEED$\n\
26 using_logdissolve_s$ID$ = $USING_LOG_DISSOLVE$\n\
27 using_dissolve_s$ID$ = $USING_DISSOLVE$\n\
28 flameVorticity_s$ID$ = $FLAME_VORTICITY$\n\
29 burningRate_s$ID$ = $BURNING_RATE$\n\
30 flameSmoke_s$ID$ = $FLAME_SMOKE$\n\
31 ignitionTemp_s$ID$ = $IGNITION_TEMP$\n\
32 maxTemp_s$ID$ = $MAX_TEMP$\n\
33 flameSmokeColor_s$ID$ = vec3($FLAME_SMOKE_COLOR_X$,$FLAME_SMOKE_COLOR_Y$,$FLAME_SMOKE_COLOR_Z$)\n";
34 
35 const std::string smoke_variables_noise =
36  "\n\
37 mantaMsg('Smoke variables noise')\n\
38 wltStrength_s$ID$ = $WLT_STR$\n\
39 uvs_s$ID$ = 2\n\
40 uvs_offset_s$ID$ = vec3($MIN_RESX$, $MIN_RESY$, $MIN_RESZ$)\n\
41 octaves_s$ID$ = int(math.log(upres_sn$ID$) / math.log(2.0) + 0.5) if (upres_sn$ID$ > 1) else 1\n";
42 
43 const std::string smoke_wavelet_noise =
44  "\n\
45 # wavelet noise params\n\
46 wltnoise_sn$ID$.posScale = vec3(int($BASE_RESX$), int($BASE_RESY$), int($BASE_RESZ$)) * (1. / $NOISE_POSSCALE$)\n\
47 wltnoise_sn$ID$.timeAnim = $NOISE_TIMEANIM$\n";
48 
49 const std::string smoke_with_heat =
50  "\n\
51 using_heat_s$ID$ = True\n";
52 
53 const std::string smoke_with_colors =
54  "\n\
55 using_colors_s$ID$ = True\n";
56 
57 const std::string smoke_with_fire =
58  "\n\
59 using_fire_s$ID$ = True\n";
60 
62 // GRIDS
64 
65 const std::string smoke_alloc =
66  "\n\
67 mantaMsg('Smoke alloc')\n\
68 shadow_s$ID$ = s$ID$.create(RealGrid, name='$NAME_SHADOW$', sparse=False)\n\
69 emission_s$ID$ = s$ID$.create(RealGrid, name='$NAME_EMISSION$', sparse=True)\n\
70 emissionIn_s$ID$ = s$ID$.create(RealGrid, name='$NAME_EMISSIONIN$')\n\
71 density_s$ID$ = s$ID$.create(RealGrid, name='$NAME_DENSITY$', sparse=True)\n\
72 densityIn_s$ID$ = s$ID$.create(RealGrid, name='$NAME_DENSITYIN$', sparse=True)\n\
73 heat_s$ID$ = None # allocated dynamically\n\
74 heatIn_s$ID$ = None\n\
75 flame_s$ID$ = None\n\
76 fuel_s$ID$ = None\n\
77 react_s$ID$ = None\n\
78 fuelIn_s$ID$ = None\n\
79 reactIn_s$ID$ = None\n\
80 color_r_s$ID$ = None\n\
81 color_g_s$ID$ = None\n\
82 color_b_s$ID$ = None\n\
83 color_r_in_s$ID$ = None\n\
84 color_g_in_s$ID$ = None\n\
85 color_b_in_s$ID$ = None\n\
86 \n\
87 # Set some initial values\n\
88 shadow_s$ID$.setConst(-1)\n\
89 \n\
90 # Keep track of important objects in dict to load them later on\n\
91 smoke_data_dict_final_s$ID$ = { 'density' : density_s$ID$, 'shadow' : shadow_s$ID$ }\n\
92 smoke_data_dict_resume_s$ID$ = { 'densityIn' : densityIn_s$ID$, 'emission' : emission_s$ID$ }\n";
93 
94 const std::string smoke_alloc_noise =
95  "\n\
96 mantaMsg('Smoke alloc noise')\n\
97 vel_sn$ID$ = sn$ID$.create(MACGrid, name='$NAME_VELOCITY_NOISE$')\n\
98 density_sn$ID$ = sn$ID$.create(RealGrid, name='$NAME_DENSITY_NOISE$', sparse=True)\n\
99 phiIn_sn$ID$ = sn$ID$.create(LevelsetGrid, name='$NAME_PHIIN_NOISE$')\n\
100 phiOut_sn$ID$ = sn$ID$.create(LevelsetGrid, name='$NAME_PHIOUT_NOISE$')\n\
101 phiObs_sn$ID$ = sn$ID$.create(LevelsetGrid, name='$NAME_PHIOBS_NOISE$')\n\
102 flags_sn$ID$ = sn$ID$.create(FlagGrid, name='$NAME_FLAGS_NOISE$')\n\
103 tmpIn_sn$ID$ = sn$ID$.create(RealGrid, name='$NAME_TMPIN_NOISE$')\n\
104 emissionIn_sn$ID$ = sn$ID$.create(RealGrid, name='$NAME_EMISSIONIN_NOISE$')\n\
105 energy_s$ID$ = s$ID$.create(RealGrid, name='$NAME_ENERGY$')\n\
106 tmpFlags_s$ID$ = s$ID$.create(FlagGrid, name='$NAME_TMPFLAGS$')\n\
107 texture_u_s$ID$ = s$ID$.create(RealGrid, name='$NAME_TEXTURE_U$')\n\
108 texture_v_s$ID$ = s$ID$.create(RealGrid, name='$NAME_TEXTURE_V$')\n\
109 texture_w_s$ID$ = s$ID$.create(RealGrid, name='$NAME_TEXTURE_W$')\n\
110 texture_u2_s$ID$ = s$ID$.create(RealGrid, name='$NAME_TEXTURE_U2$')\n\
111 texture_v2_s$ID$ = s$ID$.create(RealGrid, name='$NAME_TEXTURE_V2$')\n\
112 texture_w2_s$ID$ = s$ID$.create(RealGrid, name='$NAME_TEXTURE_W2$')\n\
113 flame_sn$ID$ = None\n\
114 fuel_sn$ID$ = None\n\
115 react_sn$ID$ = None\n\
116 color_r_sn$ID$ = None\n\
117 color_g_sn$ID$ = None\n\
118 color_b_sn$ID$ = None\n\
119 wltnoise_sn$ID$ = sn$ID$.create(NoiseField, fixedSeed=265, loadFromFile=True)\n\
120 \n\
121 mantaMsg('Initializing UV Grids')\n\
122 uvGrid0_s$ID$ = s$ID$.create(VecGrid, name='$NAME_UV0$', sparse=False)\n\
123 uvGrid1_s$ID$ = s$ID$.create(VecGrid, name='$NAME_UV1$', sparse=False)\n\
124 resetUvGrid(target=uvGrid0_s$ID$, offset=uvs_offset_s$ID$)\n\
125 resetUvGrid(target=uvGrid1_s$ID$, offset=uvs_offset_s$ID$)\n\
126 \n\
127 # Sync UV and texture grids\n\
128 copyVec3ToReal(source=uvGrid0_s$ID$, targetX=texture_u_s$ID$, targetY=texture_v_s$ID$, targetZ=texture_w_s$ID$)\n\
129 copyVec3ToReal(source=uvGrid1_s$ID$, targetX=texture_u2_s$ID$, targetY=texture_v2_s$ID$, targetZ=texture_w2_s$ID$)\n\
130 \n\
131 # Keep track of important objects in dict to load them later on\n\
132 smoke_noise_dict_final_s$ID$ = { 'density_noise' : density_sn$ID$ }\n\
133 smoke_noise_dict_resume_s$ID$ = { 'uv0_noise' : uvGrid0_s$ID$, 'uv1_noise' : uvGrid1_s$ID$ }\n";
134 
136 // ADDITIONAL GRIDS
138 
139 const std::string smoke_alloc_colors =
140  "\n\
141 # Sanity check, clear grids first\n\
142 if 'color_r_s$ID$' in globals(): del color_r_s$ID$\n\
143 if 'color_g_s$ID$' in globals(): del color_g_s$ID$\n\
144 if 'color_b_s$ID$' in globals(): del color_b_s$ID$\n\
145 \n\
146 mantaMsg('Allocating colors')\n\
147 color_r_s$ID$ = s$ID$.create(RealGrid, name='$NAME_COLORR$', sparse=True)\n\
148 color_g_s$ID$ = s$ID$.create(RealGrid, name='$NAME_COLORG$', sparse=True)\n\
149 color_b_s$ID$ = s$ID$.create(RealGrid, name='$NAME_COLORB$', sparse=True)\n\
150 color_r_in_s$ID$ = s$ID$.create(RealGrid, name='$NAME_COLORRIN$', sparse=True)\n\
151 color_g_in_s$ID$ = s$ID$.create(RealGrid, name='$NAME_COLORGIN$', sparse=True)\n\
152 color_b_in_s$ID$ = s$ID$.create(RealGrid, name='$NAME_COLORBIN$', sparse=True)\n\
153 \n\
154 # Add objects to dict to load them later on\n\
155 if 'smoke_data_dict_final_s$ID$' in globals():\n\
156  smoke_data_dict_final_s$ID$.update(color_r=color_r_s$ID$, color_g=color_g_s$ID$, color_b=color_b_s$ID$)\n\
157 if 'smoke_data_dict_resume_s$ID$' in globals():\n\
158  smoke_data_dict_resume_s$ID$.update(color_r_in=color_r_in_s$ID$, color_g_in=color_g_in_s$ID$, color_b_in=color_b_in_s$ID$)\n";
159 
160 const std::string smoke_alloc_colors_noise =
161  "\n\
162 # Sanity check, clear grids first\n\
163 if 'color_r_sn$ID$' in globals(): del color_r_sn$ID$\n\
164 if 'color_g_sn$ID$' in globals(): del color_g_sn$ID$\n\
165 if 'color_b_sn$ID$' in globals(): del color_b_sn$ID$\n\
166 \n\
167 mantaMsg('Allocating colors noise')\n\
168 color_r_sn$ID$ = sn$ID$.create(RealGrid, name='$NAME_COLORR_NOISE$', sparse=True)\n\
169 color_g_sn$ID$ = sn$ID$.create(RealGrid, name='$NAME_COLORG_NOISE$', sparse=True)\n\
170 color_b_sn$ID$ = sn$ID$.create(RealGrid, name='$NAME_COLORB_NOISE$', sparse=True)\n\
171 \n\
172 # Add objects to dict to load them later on\n\
173 if 'smoke_noise_dict_final_s$ID$' in globals():\n\
174  smoke_noise_dict_final_s$ID$.update(color_r_noise=color_r_sn$ID$, color_g_noise=color_g_sn$ID$, color_b_noise=color_b_sn$ID$)\n";
175 
176 const std::string smoke_init_colors =
177  "\n\
178 mantaMsg('Initializing colors')\n\
179 color_r_s$ID$.copyFrom(density_s$ID$) \n\
180 color_r_s$ID$.multConst($COLOR_R$) \n\
181 color_g_s$ID$.copyFrom(density_s$ID$) \n\
182 color_g_s$ID$.multConst($COLOR_G$) \n\
183 color_b_s$ID$.copyFrom(density_s$ID$) \n\
184 color_b_s$ID$.multConst($COLOR_B$)\n";
185 
186 const std::string smoke_init_colors_noise =
187  "\n\
188 mantaMsg('Initializing colors noise')\n\
189 color_r_sn$ID$.copyFrom(density_sn$ID$) \n\
190 color_r_sn$ID$.multConst($COLOR_R$) \n\
191 color_g_sn$ID$.copyFrom(density_sn$ID$) \n\
192 color_g_sn$ID$.multConst($COLOR_G$) \n\
193 color_b_sn$ID$.copyFrom(density_sn$ID$) \n\
194 color_b_sn$ID$.multConst($COLOR_B$)\n";
195 
196 const std::string smoke_alloc_heat =
197  "\n\
198 # Sanity check, clear grids first\n\
199 if 'heat_s$ID$' in globals(): del heat_s$ID$\n\
200 if 'heatIn_s$ID$' in globals(): del heatIn_s$ID$\n\
201 \n\
202 mantaMsg('Allocating heat')\n\
203 heat_s$ID$ = s$ID$.create(RealGrid, name='$NAME_TEMPERATURE$', sparse=True)\n\
204 heatIn_s$ID$ = s$ID$.create(RealGrid, name='$NAME_TEMPERATUREIN$', sparse=True)\n\
205 \n\
206 # Add objects to dict to load them later on\n\
207 if 'smoke_data_dict_final_s$ID$' in globals():\n\
208  smoke_data_dict_final_s$ID$.update(heat=heat_s$ID$)\n\
209 if 'smoke_data_dict_resume_s$ID$' in globals():\n\
210  smoke_data_dict_resume_s$ID$.update(heatIn=heatIn_s$ID$)\n";
211 
212 const std::string smoke_alloc_fire =
213  "\n\
214 # Sanity check, clear grids first\n\
215 if 'flame_s$ID$' in globals(): del flame_s$ID$\n\
216 if 'fuel_s$ID$' in globals(): del fuel_s$ID$\n\
217 if 'react_s$ID$' in globals(): del react_s$ID$\n\
218 if 'fuelIn_s$ID$' in globals(): del fuelIn_s$ID$\n\
219 if 'reactIn_s$ID$' in globals(): del reactIn_s$ID$\n\
220 \n\
221 mantaMsg('Allocating fire')\n\
222 flame_s$ID$ = s$ID$.create(RealGrid, name='$NAME_FLAME$', sparse=True)\n\
223 fuel_s$ID$ = s$ID$.create(RealGrid, name='$NAME_FUEL$', sparse=True)\n\
224 react_s$ID$ = s$ID$.create(RealGrid, name='$NAME_REACT$', sparse=True)\n\
225 fuelIn_s$ID$ = s$ID$.create(RealGrid, name='$NAME_FUELIN$', sparse=True)\n\
226 reactIn_s$ID$ = s$ID$.create(RealGrid, name='$NAME_REACTIN$', sparse=True)\n\
227 \n\
228 # Add objects to dict to load them later on\n\
229 if 'smoke_data_dict_final_s$ID$' in globals():\n\
230  smoke_data_dict_final_s$ID$.update(flame=flame_s$ID$)\n\
231 if 'smoke_data_dict_resume_s$ID$' in globals():\n\
232  smoke_data_dict_resume_s$ID$.update(fuel=fuel_s$ID$, react=react_s$ID$, fuelIn=fuelIn_s$ID$, reactIn=reactIn_s$ID$)\n";
233 
234 const std::string smoke_alloc_fire_noise =
235  "\n\
236 # Sanity check, clear grids first\n\
237 if 'flame_sn$ID$' in globals(): del flame_sn$ID$\n\
238 if 'fuel_sn$ID$' in globals(): del fuel_sn$ID$\n\
239 if 'react_sn$ID$' in globals(): del react_sn$ID$\n\
240 \n\
241 mantaMsg('Allocating fire noise')\n\
242 flame_sn$ID$ = sn$ID$.create(RealGrid, name='$NAME_FLAME_NOISE$', sparse=True)\n\
243 fuel_sn$ID$ = sn$ID$.create(RealGrid, name='$NAME_FUEL_NOISE$', sparse=True)\n\
244 react_sn$ID$ = sn$ID$.create(RealGrid, name='$NAME_REACT_NOISE$', sparse=True)\n\
245 \n\
246 # Add objects to dict to load them later on\n\
247 if 'smoke_noise_dict_final_s$ID$' in globals():\n\
248  smoke_noise_dict_final_s$ID$.update(flame_noise=flame_sn$ID$)\n\
249 if 'smoke_noise_dict_resume_s$ID$' in globals():\n\
250  smoke_noise_dict_resume_s$ID$.update(fuel_noise=fuel_sn$ID$, react_noise=react_sn$ID$)\n";
251 
253 // STEP FUNCTIONS
255 
256 const std::string smoke_adaptive_step =
257  "\n\
258 def smoke_adaptive_step_$ID$(framenr):\n\
259  mantaMsg('Manta step, frame ' + str(framenr))\n\
260  s$ID$.frame = framenr\n\
261  \n\
262  fluid_pre_step_$ID$()\n\
263  \n\
264  flags_s$ID$.initDomain(boundaryWidth=0, phiWalls=phiObs_s$ID$, outflow=boundConditions_s$ID$)\n\
265  \n\
266  if using_obstacle_s$ID$:\n\
267  mantaMsg('Extrapolating object velocity')\n\
268  # ensure velocities inside of obs object, slightly add obvels outside of obs object\n\
269  # extrapolate with phiObsIn before joining (static) phiObsSIn grid to prevent flows into static obs\n\
270  extrapolateVec3Simple(vel=obvelC_s$ID$, phi=phiObsIn_s$ID$, distance=6, inside=True)\n\
271  extrapolateVec3Simple(vel=obvelC_s$ID$, phi=phiObsIn_s$ID$, distance=3, inside=False)\n\
272  resampleVec3ToMac(source=obvelC_s$ID$, target=obvel_s$ID$)\n\
273  \n\
274  mantaMsg('Initializing obstacle levelset')\n\
275  phiObsIn_s$ID$.join(phiObsSIn_s$ID$) # Join static obstacle map\n\
276  phiObsIn_s$ID$.floodFill(boundaryWidth=1)\n\
277  extrapolateLsSimple(phi=phiObsIn_s$ID$, distance=6, inside=True)\n\
278  extrapolateLsSimple(phi=phiObsIn_s$ID$, distance=3, inside=False)\n\
279  phiObs_s$ID$.join(phiObsIn_s$ID$)\n\
280  \n\
281  # Additional sanity check: fill holes in phiObs which can result after joining with phiObsIn\n\
282  phiObs_s$ID$.floodFill(boundaryWidth=1)\n\
283  extrapolateLsSimple(phi=phiObs_s$ID$, distance=6, inside=True)\n\
284  extrapolateLsSimple(phi=phiObs_s$ID$, distance=3, inside=False)\n\
285  \n\
286  mantaMsg('Initializing fluid levelset')\n\
287  phiIn_s$ID$.join(phiSIn_s$ID$) # Join static flow map\n\
288  extrapolateLsSimple(phi=phiIn_s$ID$, distance=6, inside=True)\n\
289  extrapolateLsSimple(phi=phiIn_s$ID$, distance=3, inside=False)\n\
290  \n\
291  if using_outflow_s$ID$:\n\
292  phiOutIn_s$ID$.join(phiOutSIn_s$ID$) # Join static outflow map\n\
293  phiOut_s$ID$.join(phiOutIn_s$ID$)\n\
294  \n\
295  setObstacleFlags(flags=flags_s$ID$, phiObs=phiObs_s$ID$, phiOut=phiOut_s$ID$, phiIn=phiIn_s$ID$, boundaryWidth=1)\n\
296  flags_s$ID$.fillGrid()\n\
297  \n\
298  # reset emission accumulation at the beginning of an adaptive frame\n\
299  if not s$ID$.timePerFrame:\n\
300  emission_s$ID$.setConst(0.)\n\
301  # accumulate emission value per adaptive step for later use in noise computation\n\
302  emission_s$ID$.join(emissionIn_s$ID$)\n\
303  \n\
304  applyEmission(flags=flags_s$ID$, target=density_s$ID$, source=densityIn_s$ID$, emissionTexture=emissionIn_s$ID$, type=FlagInflow|FlagOutflow)\n\
305  if using_heat_s$ID$:\n\
306  applyEmission(flags=flags_s$ID$, target=heat_s$ID$, source=heatIn_s$ID$, emissionTexture=emissionIn_s$ID$, type=FlagInflow|FlagOutflow)\n\
307  \n\
308  if using_colors_s$ID$:\n\
309  applyEmission(flags=flags_s$ID$, target=color_r_s$ID$, source=color_r_in_s$ID$, emissionTexture=emissionIn_s$ID$, type=FlagInflow|FlagOutflow)\n\
310  applyEmission(flags=flags_s$ID$, target=color_g_s$ID$, source=color_g_in_s$ID$, emissionTexture=emissionIn_s$ID$, type=FlagInflow|FlagOutflow)\n\
311  applyEmission(flags=flags_s$ID$, target=color_b_s$ID$, source=color_b_in_s$ID$, emissionTexture=emissionIn_s$ID$, type=FlagInflow|FlagOutflow)\n\
312  \n\
313  if using_fire_s$ID$:\n\
314  applyEmission(flags=flags_s$ID$, target=fuel_s$ID$, source=fuelIn_s$ID$, emissionTexture=emissionIn_s$ID$, type=FlagInflow|FlagOutflow)\n\
315  applyEmission(flags=flags_s$ID$, target=react_s$ID$, source=reactIn_s$ID$, emissionTexture=emissionIn_s$ID$, type=FlagInflow|FlagOutflow)\n\
316  \n\
317  mantaMsg('Smoke step / s$ID$.frame: ' + str(s$ID$.frame))\n\
318  if using_fire_s$ID$:\n\
319  process_burn_$ID$()\n\
320  smoke_step_$ID$()\n\
321  if using_fire_s$ID$:\n\
322  update_flame_$ID$()\n\
323  \n\
324  s$ID$.step()\n\
325  \n\
326  fluid_post_step_$ID$()\n";
327 
328 const std::string smoke_step =
329  "\n\
330 def smoke_step_$ID$():\n\
331  mantaMsg('Smoke step low')\n\
332  \n\
333  # save original state for later (used during noise creation)\n\
334  velTmp_s$ID$.copyFrom(vel_s$ID$)\n\
335  \n\
336  if using_dissolve_s$ID$:\n\
337  mantaMsg('Dissolving smoke')\n\
338  dissolveSmoke(flags=flags_s$ID$, density=density_s$ID$, heat=heat_s$ID$, red=color_r_s$ID$, green=color_g_s$ID$, blue=color_b_s$ID$, speed=dissolveSpeed_s$ID$, logFalloff=using_logdissolve_s$ID$)\n\
339  \n\
340  mantaMsg('Advecting density')\n\
341  advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=density_s$ID$, order=2)\n\
342  \n\
343  if using_heat_s$ID$:\n\
344  mantaMsg('Advecting heat')\n\
345  advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=heat_s$ID$, order=2)\n\
346  \n\
347  if using_fire_s$ID$:\n\
348  mantaMsg('Advecting fire')\n\
349  advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=fuel_s$ID$, order=2)\n\
350  advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=react_s$ID$, order=2)\n\
351  \n\
352  if using_colors_s$ID$:\n\
353  mantaMsg('Advecting colors')\n\
354  advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=color_r_s$ID$, order=2)\n\
355  advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=color_g_s$ID$, order=2)\n\
356  advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=color_b_s$ID$, order=2)\n\
357  \n\
358  mantaMsg('Advecting velocity')\n\
359  advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=vel_s$ID$, order=2)\n\
360  \n\
361  if not domainClosed_s$ID$ or using_outflow_s$ID$:\n\
362  resetOutflow(flags=flags_s$ID$, real=density_s$ID$)\n\
363  \n\
364  mantaMsg('Vorticity')\n\
365  if using_fire_s$ID$:\n\
366  flame_s$ID$.copyFrom(fuel_s$ID$) # temporarily misuse flame grid as vorticity storage\n\
367  flame_s$ID$.multConst(flameVorticity_s$ID$)\n\
368  vorticityConfinement(vel=vel_s$ID$, flags=flags_s$ID$, strength=vorticity_s$ID$, strengthCell=flame_s$ID$ if using_fire_s$ID$ else None)\n\
369  \n\
370  if using_heat_s$ID$:\n\
371  mantaMsg('Adding heat buoyancy')\n\
372  addBuoyancy(flags=flags_s$ID$, density=heat_s$ID$, vel=vel_s$ID$, gravity=gravity_s$ID$, coefficient=buoyancy_heat_s$ID$, scale=False)\n\
373  mantaMsg('Adding buoyancy')\n\
374  addBuoyancy(flags=flags_s$ID$, density=density_s$ID$, vel=vel_s$ID$, gravity=gravity_s$ID$, coefficient=buoyancy_dens_s$ID$, scale=False)\n\
375  \n\
376  mantaMsg('Adding forces')\n\
377  addForceField(flags=flags_s$ID$, vel=vel_s$ID$, force=forces_s$ID$)\n\
378  \n\
379  # Cells inside obstacle should not contain any density, fire, etc.\n\
380  if deleteInObstacle_s$ID$:\n\
381  resetInObstacle(flags=flags_s$ID$, density=density_s$ID$, vel=vel_s$ID$, heat=heat_s$ID$, fuel=fuel_s$ID$, flame=flame_s$ID$, red=color_r_s$ID$, green=color_g_s$ID$, blue=color_b_s$ID$)\n\
382  \n\
383  # add initial velocity\n\
384  if using_invel_s$ID$:\n\
385  # Using cell centered invels, will be converted to MAC within the function\n\
386  setInitialVelocity(flags=flags_s$ID$, vel=vel_s$ID$, invel=invelC_s$ID$)\n\
387  \n\
388  mantaMsg('Walls')\n\
389  setWallBcs(flags=flags_s$ID$, vel=vel_s$ID$, obvel=obvel_s$ID$ if using_obstacle_s$ID$ else None)\n\
390  \n\
391  preconditioner_s$ID$ = PcMGDynamic if using_obstacle_s$ID$ and obvel_s$ID$.getMax() > 0 else PcMGStatic\n\
392  mantaMsg('Using preconditioner: ' + str(preconditioner_s$ID$))\n\
393  if using_guiding_s$ID$:\n\
394  mantaMsg('Guiding and pressure')\n\
395  PD_fluid_guiding(vel=vel_s$ID$, velT=velT_s$ID$, flags=flags_s$ID$, weight=weightGuide_s$ID$, blurRadius=beta_sg$ID$, pressure=pressure_s$ID$, tau=tau_sg$ID$, sigma=sigma_sg$ID$, theta=theta_sg$ID$, preconditioner=preconditioner_s$ID$, zeroPressureFixing=domainClosed_s$ID$)\n\
396  else:\n\
397  mantaMsg('Pressure')\n\
398  solvePressure(flags=flags_s$ID$, vel=vel_s$ID$, pressure=pressure_s$ID$, preconditioner=preconditioner_s$ID$, zeroPressureFixing=domainClosed_s$ID$) # closed domains require pressure fixing\n\
399 \n\
400 def process_burn_$ID$():\n\
401  mantaMsg('Process burn')\n\
402  processBurn(fuel=fuel_s$ID$, density=density_s$ID$, react=react_s$ID$, red=color_r_s$ID$, green=color_g_s$ID$, blue=color_b_s$ID$, heat=heat_s$ID$, burningRate=burningRate_s$ID$, flameSmoke=flameSmoke_s$ID$, ignitionTemp=ignitionTemp_s$ID$, maxTemp=maxTemp_s$ID$, flameSmokeColor=flameSmokeColor_s$ID$)\n\
403 \n\
404 def update_flame_$ID$():\n\
405  mantaMsg('Update flame')\n\
406  updateFlame(react=react_s$ID$, flame=flame_s$ID$)\n";
407 
408 const std::string smoke_step_noise =
409  "\n\
410 def smoke_step_noise_$ID$(framenr):\n\
411  mantaMsg('Manta step noise, frame ' + str(framenr))\n\
412  sn$ID$.frame = framenr\n\
413  \n\
414  copyRealToVec3(sourceX=texture_u_s$ID$, sourceY=texture_v_s$ID$, sourceZ=texture_w_s$ID$, target=uvGrid0_s$ID$)\n\
415  copyRealToVec3(sourceX=texture_u2_s$ID$, sourceY=texture_v2_s$ID$, sourceZ=texture_w2_s$ID$, target=uvGrid1_s$ID$)\n\
416  \n\
417  flags_sn$ID$.initDomain(boundaryWidth=0, phiWalls=phiObs_sn$ID$, outflow=boundConditions_s$ID$)\n\
418  \n\
419  mantaMsg('Interpolating grids')\n\
420  # Join big obstacle levelset after initDomain() call as it overwrites everything in phiObs\n\
421  if using_obstacle_s$ID$:\n\
422  phiIn_sn$ID$.copyFrom(phiObsIn_s$ID$) if upres_sn$ID$ <= 1 else interpolateGrid(target=phiIn_sn$ID$, source=phiObsIn_s$ID$) # mis-use phiIn_sn\n\
423  phiObs_sn$ID$.join(phiIn_sn$ID$)\n\
424  if using_outflow_s$ID$:\n\
425  phiOut_sn$ID$.copyFrom(phiOut_s$ID$) if upres_sn$ID$ <= 1 else interpolateGrid(target=phiOut_sn$ID$, source=phiOut_s$ID$)\n\
426  phiIn_sn$ID$.copyFrom(phiIn_s$ID$) if upres_sn$ID$ <= 1 else interpolateGrid(target=phiIn_sn$ID$, source=phiIn_s$ID$)\n\
427  vel_sn$ID$.copyFrom(velTmp_s$ID$) if upres_sn$ID$ <= 1 else interpolateMACGrid(target=vel_sn$ID$, source=velTmp_s$ID$)\n\
428  \n\
429  setObstacleFlags(flags=flags_sn$ID$, phiObs=phiObs_sn$ID$, phiOut=phiOut_sn$ID$, phiIn=phiIn_sn$ID$, boundaryWidth=1)\n\
430  flags_sn$ID$.fillGrid()\n\
431  \n\
432  # Interpolate emission grids and apply them to big noise grids\n\
433  tmpIn_sn$ID$.copyFrom(densityIn_s$ID$) if upres_sn$ID$ <= 1 else interpolateGrid(source=densityIn_s$ID$, target=tmpIn_sn$ID$)\n\
434  emissionIn_sn$ID$.copyFrom(emission_s$ID$) if upres_sn$ID$ <= 1 else interpolateGrid(source=emission_s$ID$, target=emissionIn_sn$ID$)\n\
435  \n\
436  # Higher-res noise grid needs scaled emission values\n\
437  tmpIn_sn$ID$.multConst(float(upres_sn$ID$))\n\
438  applyEmission(flags=flags_sn$ID$, target=density_sn$ID$, source=tmpIn_sn$ID$, emissionTexture=emissionIn_sn$ID$, type=FlagInflow|FlagOutflow)\n\
439  \n\
440  if using_colors_s$ID$:\n\
441  tmpIn_sn$ID$.copyFrom(color_r_in_s$ID$) if upres_sn$ID$ <= 1 else interpolateGrid(source=color_r_in_s$ID$, target=tmpIn_sn$ID$)\n\
442  applyEmission(flags=flags_sn$ID$, target=color_r_sn$ID$, source=tmpIn_sn$ID$, emissionTexture=emissionIn_sn$ID$, type=FlagInflow|FlagOutflow)\n\
443  tmpIn_sn$ID$.copyFrom(color_g_in_s$ID$) if upres_sn$ID$ <= 1 else interpolateGrid(source=color_g_in_s$ID$, target=tmpIn_sn$ID$)\n\
444  applyEmission(flags=flags_sn$ID$, target=color_g_sn$ID$, source=tmpIn_sn$ID$, emissionTexture=emissionIn_sn$ID$, type=FlagInflow|FlagOutflow)\n\
445  tmpIn_sn$ID$.copyFrom(color_b_in_s$ID$) if upres_sn$ID$ <= 1 else interpolateGrid(source=color_b_in_s$ID$, target=tmpIn_sn$ID$)\n\
446  applyEmission(flags=flags_sn$ID$, target=color_b_sn$ID$, source=tmpIn_sn$ID$, emissionTexture=emissionIn_sn$ID$, type=FlagInflow|FlagOutflow)\n\
447  \n\
448  if using_fire_s$ID$:\n\
449  tmpIn_sn$ID$.copyFrom(fuelIn_s$ID$) if upres_sn$ID$ <= 1 else interpolateGrid(source=fuelIn_s$ID$, target=tmpIn_sn$ID$)\n\
450  applyEmission(flags=flags_sn$ID$, target=fuel_sn$ID$, source=tmpIn_sn$ID$, emissionTexture=emissionIn_sn$ID$, type=FlagInflow|FlagOutflow)\n\
451  tmpIn_sn$ID$.copyFrom(reactIn_s$ID$) if upres_sn$ID$ <= 1 else interpolateGrid(source=reactIn_s$ID$, target=tmpIn_sn$ID$)\n\
452  applyEmission(flags=flags_sn$ID$, target=react_sn$ID$, source=tmpIn_sn$ID$, emissionTexture=emissionIn_sn$ID$, type=FlagInflow|FlagOutflow)\n\
453  \n\
454  mantaMsg('Noise step / sn$ID$.frame: ' + str(sn$ID$.frame))\n\
455  if using_fire_s$ID$:\n\
456  process_burn_noise_$ID$()\n\
457  step_noise_$ID$()\n\
458  if using_fire_s$ID$:\n\
459  update_flame_noise_$ID$()\n\
460  \n\
461  sn$ID$.step()\n\
462  \n\
463  copyVec3ToReal(source=uvGrid0_s$ID$, targetX=texture_u_s$ID$, targetY=texture_v_s$ID$, targetZ=texture_w_s$ID$)\n\
464  copyVec3ToReal(source=uvGrid1_s$ID$, targetX=texture_u2_s$ID$, targetY=texture_v2_s$ID$, targetZ=texture_w2_s$ID$)\n\
465 \n\
466 def step_noise_$ID$():\n\
467  mantaMsg('Smoke step noise')\n\
468  \n\
469  if using_dissolve_s$ID$:\n\
470  mantaMsg('Dissolving noise')\n\
471  dissolveSmoke(flags=flags_sn$ID$, density=density_sn$ID$, heat=None, red=color_r_sn$ID$, green=color_g_sn$ID$, blue=color_b_sn$ID$, speed=dissolveSpeed_s$ID$, logFalloff=using_logdissolve_s$ID$)\n\
472  \n\
473  mantaMsg('Advecting UVs and updating UV weight')\n\
474  advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=uvGrid0_s$ID$, order=2)\n\
475  updateUvWeight(resetTime=sn$ID$.timestep*10.0 , index=0, numUvs=uvs_s$ID$, uv=uvGrid0_s$ID$, offset=uvs_offset_s$ID$)\n\
476  advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=uvGrid1_s$ID$, order=2)\n\
477  updateUvWeight(resetTime=sn$ID$.timestep*10.0 , index=1, numUvs=uvs_s$ID$, uv=uvGrid1_s$ID$, offset=uvs_offset_s$ID$)\n\
478  \n\
479  if not domainClosed_s$ID$ or using_outflow_s$ID$:\n\
480  resetOutflow(flags=flags_sn$ID$, real=density_sn$ID$)\n\
481  \n\
482  mantaMsg('Energy')\n\
483  computeEnergy(flags=flags_s$ID$, vel=vel_s$ID$, energy=energy_s$ID$)\n\
484  \n\
485  tmpFlags_s$ID$.copyFrom(flags_s$ID$)\n\
486  extrapolateSimpleFlags(flags=flags_s$ID$, val=tmpFlags_s$ID$, distance=2, flagFrom=FlagObstacle, flagTo=FlagFluid)\n\
487  extrapolateSimpleFlags(flags=tmpFlags_s$ID$, val=energy_s$ID$, distance=6, flagFrom=FlagFluid, flagTo=FlagObstacle)\n\
488  computeWaveletCoeffs(energy_s$ID$)\n\
489  \n\
490  sStr_s$ID$ = 1.0 * wltStrength_s$ID$\n\
491  sPos_s$ID$ = 2.0\n\
492  \n\
493  mantaMsg('Applying noise vec')\n\
494  for o in range(octaves_s$ID$):\n\
495  uvWeight_s$ID$ = getUvWeight(uvGrid0_s$ID$)\n\
496  applyNoiseVec3(flags=flags_sn$ID$, target=vel_sn$ID$, noise=wltnoise_sn$ID$, scale=sStr_s$ID$ * uvWeight_s$ID$, scaleSpatial=sPos_s$ID$ , weight=energy_s$ID$, uv=uvGrid0_s$ID$)\n\
497  uvWeight_s$ID$ = getUvWeight(uvGrid1_s$ID$)\n\
498  applyNoiseVec3(flags=flags_sn$ID$, target=vel_sn$ID$, noise=wltnoise_sn$ID$, scale=sStr_s$ID$ * uvWeight_s$ID$, scaleSpatial=sPos_s$ID$ , weight=energy_s$ID$, uv=uvGrid1_s$ID$)\n\
499  \n\
500  sStr_s$ID$ *= 0.06 # magic kolmogorov factor \n\
501  sPos_s$ID$ *= 2.0 \n\
502  \n\
503  for substep in range(int(upres_sn$ID$)):\n\
504  if using_colors_s$ID$: \n\
505  mantaMsg('Advecting colors noise')\n\
506  advectSemiLagrange(flags=flags_sn$ID$, vel=vel_sn$ID$, grid=color_r_sn$ID$, order=2)\n\
507  advectSemiLagrange(flags=flags_sn$ID$, vel=vel_sn$ID$, grid=color_g_sn$ID$, order=2)\n\
508  advectSemiLagrange(flags=flags_sn$ID$, vel=vel_sn$ID$, grid=color_b_sn$ID$, order=2)\n\
509  \n\
510  if using_fire_s$ID$: \n\
511  mantaMsg('Advecting fire noise')\n\
512  advectSemiLagrange(flags=flags_sn$ID$, vel=vel_sn$ID$, grid=fuel_sn$ID$, order=2)\n\
513  advectSemiLagrange(flags=flags_sn$ID$, vel=vel_sn$ID$, grid=react_sn$ID$, order=2)\n\
514  \n\
515  mantaMsg('Advecting density noise')\n\
516  advectSemiLagrange(flags=flags_sn$ID$, vel=vel_sn$ID$, grid=density_sn$ID$, order=2)\n\
517 \n\
518 def process_burn_noise_$ID$():\n\
519  mantaMsg('Process burn noise')\n\
520  processBurn(fuel=fuel_sn$ID$, density=density_sn$ID$, react=react_sn$ID$, red=color_r_sn$ID$, green=color_g_sn$ID$, blue=color_b_sn$ID$, burningRate=burningRate_s$ID$, flameSmoke=flameSmoke_s$ID$, ignitionTemp=ignitionTemp_s$ID$, maxTemp=maxTemp_s$ID$, flameSmokeColor=flameSmokeColor_s$ID$)\n\
521 \n\
522 def update_flame_noise_$ID$():\n\
523  mantaMsg('Update flame noise')\n\
524  updateFlame(react=react_sn$ID$, flame=flame_sn$ID$)\n";
525 
527 // IMPORT
529 
530 const std::string smoke_load_data =
531  "\n\
532 def smoke_load_data_$ID$(path, framenr, file_format, resumable):\n\
533  mantaMsg('Smoke load data')\n\
534  dict = { **fluid_data_dict_final_s$ID$, **fluid_data_dict_resume_s$ID$, **smoke_data_dict_final_s$ID$, **smoke_data_dict_resume_s$ID$ } if resumable else { **fluid_data_dict_final_s$ID$, **smoke_data_dict_final_s$ID$ }\n\
535  fluid_file_import_s$ID$(dict=dict, path=path, framenr=framenr, file_format=file_format, file_name=file_data_s$ID$)\n\
536  \n\
537  copyVec3ToReal(source=vel_s$ID$, targetX=x_vel_s$ID$, targetY=y_vel_s$ID$, targetZ=z_vel_s$ID$)\n";
538 
539 const std::string smoke_load_noise =
540  "\n\
541 def smoke_load_noise_$ID$(path, framenr, file_format, resumable):\n\
542  mantaMsg('Smoke load noise')\n\
543  dict = { **smoke_noise_dict_final_s$ID$, **smoke_noise_dict_resume_s$ID$ } if resumable else { **smoke_noise_dict_final_s$ID$ } \n\
544  fluid_file_import_s$ID$(dict=dict, path=path, framenr=framenr, file_format=file_format, file_name=file_noise_s$ID$)\n\
545  \n\
546  if resumable:\n\
547  # Fill up xyz texture grids, important when resuming a bake\n\
548  copyVec3ToReal(source=uvGrid0_s$ID$, targetX=texture_u_s$ID$, targetY=texture_v_s$ID$, targetZ=texture_w_s$ID$)\n\
549  copyVec3ToReal(source=uvGrid1_s$ID$, targetX=texture_u2_s$ID$, targetY=texture_v2_s$ID$, targetZ=texture_w2_s$ID$)\n";
550 
552 // EXPORT
554 
555 const std::string smoke_save_data =
556  "\n\
557 def smoke_save_data_$ID$(path, framenr, file_format, resumable):\n\
558  mantaMsg('Smoke save data')\n\
559  start_time = time.time()\n\
560  dict = { **fluid_data_dict_final_s$ID$, **fluid_data_dict_resume_s$ID$, **smoke_data_dict_final_s$ID$, **smoke_data_dict_resume_s$ID$ } if resumable else { **fluid_data_dict_final_s$ID$, **smoke_data_dict_final_s$ID$ } \n\
561  if not withMPSave or isWindows:\n\
562  fluid_file_export_s$ID$(dict=dict, path=path, framenr=framenr, file_format=file_format, file_name=file_data_s$ID$, clipGrid=density_s$ID$)\n\
563  else:\n\
564  fluid_cache_multiprocessing_start_$ID$(function=fluid_file_export_s$ID$, file_name=file_data_s$ID$, framenr=framenr, format_data=file_format, path_data=path, dict=dict, do_join=False)\n\
565  mantaMsg('--- Save: %s seconds ---' % (time.time() - start_time))\n";
566 
567 const std::string smoke_save_noise =
568  "\n\
569 def smoke_save_noise_$ID$(path, framenr, file_format, resumable):\n\
570  mantaMsg('Smoke save noise')\n\
571  dict = { **smoke_noise_dict_final_s$ID$, **smoke_noise_dict_resume_s$ID$ } if resumable else { **smoke_noise_dict_final_s$ID$ } \n\
572  if not withMPSave or isWindows:\n\
573  fluid_file_export_s$ID$(dict=dict, framenr=framenr, file_format=file_format, path=path, file_name=file_noise_s$ID$, clipGrid=density_sn$ID$)\n\
574  else:\n\
575  fluid_cache_multiprocessing_start_$ID$(function=fluid_file_export_s$ID$, file_name=file_noise_s$ID$, framenr=framenr, format_data=file_format, path_data=path, dict=dict, do_join=False)\n";
576 
578 // STANDALONE MODE
580 
581 const std::string smoke_standalone =
582  "\n\
583 # Helper function to call cache load functions\n\
584 def load_data(frame, cache_resumable):\n\
585  smoke_load_data_$ID$(os.path.join(cache_dir, 'data'), frame, file_format_data, cache_resumable)\n\
586  if using_noise_s$ID$:\n\
587  smoke_load_noise_$ID$(os.path.join(cache_dir, 'noise'), frame, file_format_data, cache_resumable)\n\
588  if using_guiding_s$ID$:\n\
589  fluid_load_guiding_$ID$(os.path.join(cache_dir, 'guiding'), frame, file_format_data)\n\
590 \n\
591 # Helper function to call step functions\n\
592 def step(frame):\n\
593  smoke_adaptive_step_$ID$(frame)\n\
594  if using_noise_s$ID$:\n\
595  smoke_step_noise_$ID$(frame)\n";
const std::string smoke_alloc_noise
Definition: smoke_script.h:94
const std::string smoke_alloc_heat
Definition: smoke_script.h:196
const std::string smoke_alloc_colors
Definition: smoke_script.h:139
const std::string smoke_alloc_fire_noise
Definition: smoke_script.h:234
const std::string smoke_save_noise
Definition: smoke_script.h:567
const std::string smoke_adaptive_step
Definition: smoke_script.h:256
const std::string smoke_standalone
Definition: smoke_script.h:581
const std::string smoke_with_colors
Definition: smoke_script.h:53
const std::string smoke_load_data
Definition: smoke_script.h:530
const std::string smoke_with_fire
Definition: smoke_script.h:57
const std::string smoke_with_heat
Definition: smoke_script.h:49
const std::string smoke_variables
Definition: smoke_script.h:14
const std::string smoke_variables_noise
Definition: smoke_script.h:35
const std::string smoke_save_data
Definition: smoke_script.h:555
const std::string smoke_alloc_colors_noise
Definition: smoke_script.h:160
const std::string smoke_load_noise
Definition: smoke_script.h:539
const std::string smoke_init_colors_noise
Definition: smoke_script.h:186
const std::string smoke_step_noise
Definition: smoke_script.h:408
const std::string smoke_init_colors
Definition: smoke_script.h:176
const std::string smoke_wavelet_noise
Definition: smoke_script.h:43
const std::string smoke_alloc_fire
Definition: smoke_script.h:212
const std::string smoke_alloc
Definition: smoke_script.h:65
const std::string smoke_step
Definition: smoke_script.h:328