Welcome to mirror list, hosted at ThFree Co, Russian Federation.

smoke.h « scenarios « intern « smoke « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7678c7e724faef52ba7381e82c5e0e748120d8d4 (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#include <string>
using namespace std;
const string smoke_clean = "";

const string smoke_setup_low ="from manta import *\n\
import os, shutil, math, sys\n\
def transform_back(obj, gs):\n\
  obj.scale(gs/2)\n\
  obj.offset(gs/2)\n\
\n\
def load_once(grid, file, dict):\n\
  if grid not in dict:\n\
    print('Loading file' + file + 'in grid')\n\
    grid.load(file)\n\
    dict[grid] = 1\n\
# solver params\n\
res = $RES$\n\
solver_dim = $SOLVER_DIM$\n\
gs = vec3($RESX$,$RESY$,$RESZ$)\n\
boundConditions = '$BOUNDCONDITIONS$'\n\
if solver_dim == 2:\n\
  gs.z = 1\n\
s = FluidSolver(name='main', gridSize = gs, dim = $SOLVER_DIM$)\n\
s.timestep = $TIMESTEP$\n\
timings = Timings()\n\
\n\
# prepare grids\n\
flags = s.create(FlagGrid)\n\
vel = s.create(MACGrid)\n\
density = s.create(LevelsetGrid)\n\
pressure = s.create(RealGrid)\n\
\n\
# noise field\n\
#noise = s.create(NoiseField, loadFromFile=True)\n\
#noise.posScale = vec3(45)\n\
#noise.clamp = True\n\
#noise.clampNeg = 0\n\
#noise.clampPos = 1\n\
#noise.valScale = 1\n\
#noise.valOffset = 0.75\n\
#noise.timeAnim = 0.2\n\
\n\
flags.initDomain()\n\
flags.fillGrid()\n\
\n\
inflow_grid = s.create(LevelsetGrid)\n\
source = s.create(Mesh)\n\
forces = s.create(MACGrid)\n\
dict_loaded = dict()\n\
manta_using_colors = False\n\
manta_using_heat = False\n\
low_flags_updated = False\n\
";

const string smoke_setup_high = "xl_gs = vec3($HRESX$, $HRESY$, $HRESZ$) \n\
xl = Solver(name = 'larger', gridSize = xl_gs) \n\
uvs =$UVS_CNT$\n\
if $USE_WAVELETS$:\n\
  upres = $UPRES$\n\
  wltStrength = $WLT_STR$\n\
  if $UPRES$ > 0:\n\
    octaves = int( math.log(upres)/ math.log(2.0) + 0.5 ) \n\
  else:\n\
    octaves = 0\n\
if $USE_WAVELETS$ and $UPRES$ > 0:\n\
  xl.timestep = $XL_TIMESTEP$ \n\
  xl_vel = xl.create(MACGrid) \n\
  xl_density = xl.create(RealGrid) \n\
  xl_flags = xl.create(FlagGrid) \n\
  xl_flags.initDomain() \n\
  xl_flags.fillGrid() \n\
  xl_noise = xl.create(NoiseField, fixedSeed=256, loadFromFile=True) \n\
  xl_noise.posScale = vec3(20) \n\
  xl_noise.clamp = False \n\
  xl_noise.clampNeg = $NOISE_CN$ \n\
  xl_noise.clampPos = $NOISE_CP$ \n\
  xl_noise.valScale = $NOISE_VALSCALE$ \n\
  xl_noise.valOffset = $NOISE_VALOFFSET$ \n\
  xl_noise.timeAnim = $NOISE_TIMEANIM$ * $UPRES$ \n\
  xl_wltnoise = xl.create(NoiseField, loadFromFile=True) \n\
  xl_wltnoise.posScale = vec3( int(1.0*gs.x) ) * 0.5 \n\
  xl_wltnoise.posScale = xl_wltnoise.posScale * 0.5\n\
  xl_wltnoise.timeAnim = 0.1 \n\
";

const string smoke_init_colors_low = "print(\"INitializing Colors\")\n\
color_r_low = s.create(RealGrid)\n\
color_g_low = s.create(RealGrid)\n\
color_b_low = s.create(RealGrid)\n\
color_r_low.add(density) \n\
color_r_low.multConst(manta_color_r) \n\
\n\
color_g_low.add(density) \n\
color_g_low.multConst(manta_color_g) \n\
\n\
color_b_low.add(density) \n\
color_b_low.multConst(manta_color_b) \n\
manta_using_colors = True\n";

const string smoke_del_colors_low = "\n\
del color_r_low \n\
del color_g_low \n\
del color_b_low \n\
manta_using_colors = False";

const string smoke_init_colors_high = "print(\"INitializing Colors highres\")\n\
color_r_high = xl.create(RealGrid)\n\
color_g_high = xl.create(RealGrid)\n\
color_b_high = xl.create(RealGrid)\n\
color_r_high.add(xl_density) \n\
color_r_high.multConst(manta_color_r) \n\
\n\
color_g_high.add(xl_density) \n\
color_g_high.multConst(manta_color_g) \n\
\n\
color_b_high.add(xl_density) \n\
color_b_high.multConst(manta_color_b) \n\
manta_using_colors = True\n";

const string smoke_init_heat_low = "print(\"INitializing heat lowres\")\n\
heat_low = s.create(RealGrid)\n\
manta_using_heat = True\n";

const string smoke_del_colors_high = "\n\
del color_r_high \n\
del color_g_high \n\
del color_b_high \n\
manta_using_colors = False";

const string smoke_export_low = "\n\
import os\n\
density.save(os.path.join('$MANTA_EXPORT_PATH$','density.uni'))\n\
flags.save(os.path.join('$MANTA_EXPORT_PATH$','flags.uni'))\n\
inflow_grid.save(os.path.join('$MANTA_EXPORT_PATH$','inflow.uni'))\n\
forces.save(os.path.join('$MANTA_EXPORT_PATH$','forces.uni'))\n\
print('Grids exported')";

const string standalone = "\
if (GUI):\n\
  gui =Gui()\n\
  gui.show()\n\
\n\
for step in range(100):\n\
  sim_step_low(step, True)\n";

const string smoke_step_low = "def sim_step_low(t, standalone = False):\n\
  #applying inflow\n\
  #if standalone and t==0:\n\
  #  density.load('density.uni')\n\
  #  flags.load('flags.uni')\n\
  #  forces.load('forces.uni')\n\
  #if standalone:\n\
  #  inflow_grid.load('inflow.uni')\n\
  #  inflow_grid.multConst(0.1)\n\
  #  density.add(inflow_grid)\n\
  #elif solver_dim == 2:\n\
  #  density.add(inflow_grid)\n\
  print ('Simulating frame ' + str(t))\n\
  if not standalone and t == 1 and solver_dim == 2:\n\
    density.add(inflow_grid)\n\
  if manta_using_heat:\n\
    gravity=vec3(0,0,-0.0981) if solver_dim==3 else vec3(0,-0.0981,0)\n\
    addHeatBuoyancy(density=density, densCoeff = $ALPHA$, vel=vel, gravity=gravity, flags=flags, heat = heat_low, heatCoeff = $BETA$*10)\n\
  else:\n\
    gravity=vec3(0,0,-0.01 * $ALPHA$) if solver_dim==3 else vec3(0,-0.01* $ALPHA$,0)\n\
    addBuoyancy(density=density, vel=vel, gravity=gravity, flags=flags)\n\
  if manta_using_colors:\n\
    advectSemiLagrange(flags=flags, vel=vel, grid=color_r_low, order=$ADVECT_ORDER$)\n\
    advectSemiLagrange(flags=flags, vel=vel, grid=color_g_low, order=$ADVECT_ORDER$)\n\
    advectSemiLagrange(flags=flags, vel=vel, grid=color_b_low, order=$ADVECT_ORDER$)\n\
  print ('Advecting density')\n\
  advectSemiLagrange(flags=flags, vel=vel, grid=density, order=$ADVECT_ORDER$)\n\
  print ('Advecting velocity')\n\
  advectSemiLagrange(flags=flags, vel=vel, grid=vel    , order=$ADVECT_ORDER$, strength=1.0)\n\
  \n\
  print ('Walls')\n\
  setWallBcs(flags=flags, vel=vel)    \n\
  print ('vorticity')\n\
  if $VORTICITY$ > 0.01:\n\
    vorticityConfinement( vel=vel, flags=flags, strength=$VORTICITY$ ) \n\
  print ('forcefield')\n\
  addForceField(flags=flags, vel=vel,force=forces)\n\
  forces.clear()\n\
  \n\
  print ('pressure')\n\
  solvePressure(flags=flags, vel=vel, pressure=pressure, openBound=boundConditions)\n\
  print ('walls')\n\
  setWallBcs(flags=flags, vel=vel)\n\
  \n\
  s.step()\n";

const string liquid_step_low = "def sim_step_low(t):\n\
#update flags form density on first step\n\
  setWallBcs(flags=flags, vel=vel)\n\
  density.multConst(-1.)\n\
  print (manta_using_colors)\n\
  global low_flags_updated\n\
  if not low_flags_updated:\n\
    print ('Updating Flags from Levelset on startup!')\n\
    flags.updateFromLevelset(density)\n\
  low_flags_updated = True \n\
  setWallBcs(flags=flags, vel=vel)\n\
  density.reinitMarching(flags=flags, velTransport=vel)\n\
  advectSemiLagrange(flags=flags, vel=vel, grid=density, order=2)\n\
  flags.updateFromLevelset(density)\n\
  \n\
  advectSemiLagrange(flags=flags, vel=vel, grid=vel, order=2)\n\
  addGravity(flags=flags, vel=vel, gravity=vec3(0,0,-0.981))\n\
  \n\
  # print current maximal velocity\n\
  maxvel = vel.getMaxValue()\n\
  print ('Current max velocity %f ' % maxvel)\n\
  \n\
  # pressure solve\n\
  setWallBcs(flags=flags, vel=vel)\n\
  solvePressure(flags=flags, vel=vel, pressure=pressure, cgMaxIterFac=0.5, useResNorm=True) \n\
  setWallBcs(flags=flags, vel=vel)\n\
  s.step()\n\
  density.multConst(-1.)\n\
";

const string smoke_step_high = "def sim_step_high(t):\n\
  interpolateMACGrid( source=vel, target=xl_vel ) \n\
  sStr = 1.0 * wltStrength  \n\
  sPos = 2.0  \n\
  for o in range(octaves): \n\
    for i in range(uvs): \n\
      uvWeight = getUvWeight(uv[i])  \n\
      applyNoiseVec3( flags=xl_flags, target=xl_vel, noise=xl_wltnoise, scale=sStr * uvWeight, scaleSpatial=sPos , weight=energy, uv=uv[i] ) \n\
    sStr *= 0.06 # magic kolmogorov factor \n\
    sPos *= 2.0 \n\
  for substep in range(upres):  \n\
    advectSemiLagrange(flags=xl_flags, vel=xl_vel, grid=xl_density, order=$ADVECT_ORDER$)  \n\
    if manta_using_colors:\n\
      advectSemiLagrange(flags=xl_flags, vel=xl_vel, grid=color_r_high, order=$ADVECT_ORDER$)\n\
      advectSemiLagrange(flags=xl_flags, vel=xl_vel, grid=color_g_high, order=$ADVECT_ORDER$)\n\
      advectSemiLagrange(flags=xl_flags, vel=xl_vel, grid=color_b_high, order=$ADVECT_ORDER$)\n\
\n\
  xl.step()\n";

const string full_smoke_setup = "from manta import * \n\
import os, shutil, math, sys \n\
def transform_back(obj, gs):\n\
	obj.scale(gs/2)\n\
	obj.offset(gs/2)\n\
\n\
uvs = $UVS_CNT$\n\
solver_dim = $SOLVER_DIM$\n\
velInflow = vec3(0, 0, 1)\n\
if $USE_WAVELETS$:\n\
	upres = $UPRES$\n\
	wltStrength = $WLT_STR$\n\
	if $UPRES$ > 0:\n\
		octaves = int( math.log(upres)/ math.log(2.0) + 0.5 ) \n\
	else:\n\
		octaves = 0\n\
res = $RES$\n\
gs = vec3($RESX$, $RESY$, $RESZ$) \n\
s = Solver(name = 'main', gridSize = gs, dim = solver_dim) \n\
s.timestep = $TIMESTEP$ \n\
noise = s.create(NoiseField, fixedSeed=256, loadFromFile=True) \n\
noise.posScale = vec3(20) \n\
noise.clamp = False \n\
noise.clampNeg = $NOISE_CN$\n\
noise.clampPos = $NOISE_CP$\n\
noise.valScale = $NOISE_VALSCALE$\n\
noise.valOffset = $NOISE_VALOFFSET$\n\
noise.timeAnim = $NOISE_TIMEANIM$ \n\
source = s.create(Mesh)\n\
source.load('manta_flow.obj')\n\
transform_back(source, gs)\n\
sourceVel = s.create(Mesh)\n\
sourceVel.load('manta_flow.obj')\n\
transform_back(sourceVel, gs)\n\
xl_gs = vec3($HRESX$, $HRESY$, $HRESZ$) \n\
xl = Solver(name = 'larger', gridSize = xl_gs, dim = solver_dim) \n\
if $USE_WAVELETS$ and $UPRES$ > 0:\n\
	xl.timestep = $XL_TIMESTEP$ \n\
	xl_vel = xl.create(MACGrid) \n\
	xl_density = xl.create(RealGrid) \n\
	xl_flags = xl.create(FlagGrid) \n\
	xl_flags.initDomain() \n\
	xl_flags.fillGrid() \n\
	xl_source = s.create(Mesh)\n\
	xl_source.load('manta_flow.obj')\n\
	transform_back(xl_source, gs)\n\
	xl_noise = xl.create(NoiseField, fixedSeed=256, loadFromFile=True) \n\
	xl_noise.posScale = vec3(20) \n\
	xl_noise.clamp = False \n\
	xl_noise.clampNeg = $NOISE_CN$ \n\
	xl_noise.clampPos = $NOISE_CP$ \n\
	xl_noise.valScale = $NOISE_VALSCALE$ \n\
	xl_noise.valOffset = $NOISE_VALOFFSET$ \n\
	xl_noise.timeAnim = $NOISE_TIMEANIM$ * $UPRES$ \n\
flags = s.create(FlagGrid) \n\
flags.initDomain() \n\
flags.fillGrid() \n\
uv = [] \n\
for i in range(uvs): \n\
	uvGrid = s.create(VecGrid) \n\
	uv.append(uvGrid) \n\
	resetUvGrid( uv[i] ) \n\
vel = s.create(MACGrid) \n\
density = s.create(RealGrid) \n\
pressure = s.create(RealGrid) \n\
energy = s.create(RealGrid) \n\
tempFlag  = s.create(FlagGrid)\n\
sdf_flow  = s.create(LevelsetGrid)\n\
forces = s.create(MACGrid)\n\
source.meshSDF(source, sdf_flow, 1.1)\n\
source_shape = s.create(Cylinder, center=gs*vec3(0.5,0.1,0.5), radius=res*0.14, z=gs*vec3(0, 0.02, 0))\n\
xl_wltnoise = s.create(NoiseField, loadFromFile=True) \n\
xl_wltnoise.posScale = vec3( int(1.0*gs.x) ) * 0.5 \n\
xl_wltnoise.posScale = xl_wltnoise.posScale * 0.5\n\
xl_wltnoise.timeAnim = 0.1 \n\
\n\
\n\
def sim_step(t):\n\
	forces.load('manta_forces.uni')\n\
	addForceField(flags=flags, vel=vel,force=forces)\n\
	addBuoyancy(density=density, vel=vel, gravity=vec3($BUYO_X$,$BUYO_Y$,$BUYO_Z$), flags=flags) \n\
	advectSemiLagrange(flags=flags, vel=vel, grid=density, order=$ADVECT_ORDER$) \n\
	advectSemiLagrange(flags=flags, vel=vel, grid=vel, order=$ADVECT_ORDER$) \n\
	for i in range(uvs): \n\
		advectSemiLagrange(flags=flags, vel=vel, grid=uv[i], order=$ADVECT_ORDER$) \n\
		updateUvWeight( resetTime=16.5 , index=i, numUvs=uvs, uv=uv[i] )\n\
	applyInflow=False\n\
	if (t>=0 and t<75):\n\
		densityInflowMesh(flags=flags, density=density, mesh=source, value=1)\n\
		applyInflow=True\n\
	setWallBcs(flags=flags, vel=vel) \n\
	vorticityConfinement( vel=vel, flags=flags, strength=0.2 ) \n\
	solvePressure(flags=flags, vel=vel, pressure=pressure, useResNorm=True, openBound='xXyYzZ', cgMaxIterFac=1, cgAccuracy=0.01) \n\
	setWallBcs(flags=flags, vel=vel) \n\
	computeEnergy(flags=flags, vel=vel, energy=energy)\n\
	tempFlag.copyFrom(flags)\n\
	extrapolateSimpleFlags( flags=flags, val=tempFlag, distance=2, flagFrom=FlagObstacle, flagTo=FlagFluid )\n\
	extrapolateSimpleFlags( flags=tempFlag, val=energy, distance=6, flagFrom=FlagFluid, flagTo=FlagObstacle )\n\
	computeWaveletCoeffs(energy)\n\
	print(\"Writing Grid to \" + $DENSITY_MEM$ + \"with size\" + $DENSITY_SIZE$)\n\
	density.writeGridToMemory(memLoc = $DENSITY_MEM$,sizeAllowed = $DENSITY_SIZE$)\n\
	density.save('den%04d_temp.uni' % t) \n\
	os.rename('den%04d_temp.uni' % t, 'den%04d.uni' % t) \n\
	s.step()\n\
	\n\
	interpolateMACGrid( source=vel, target=xl_vel ) \n\
	sStr = 1.0 * wltStrength  \n\
	sPos = 2.0  \n\
	for o in range(octaves): \n\
		for i in range(uvs): \n\
			uvWeight = getUvWeight(uv[i])  \n\
			applyNoiseVec3( flags=xl_flags, target=xl_vel, noise=xl_wltnoise, scale=sStr * uvWeight, scaleSpatial=sPos , weight=energy, uv=uv[i] ) \n\
		sStr *= 0.06 # magic kolmogorov factor \n\
		sPos *= 2.0 \n\
	for substep in range(upres):  \n\
		advectSemiLagrange(flags=xl_flags, vel=xl_vel, grid=xl_density, order=$ADVECT_ORDER$)  \n\
	if (applyInflow): \n\
		densityInflowMesh(flags=xl_flags, density=xl_density, mesh=source, value=1)\n\
	xl_density.save('densityXl_%04d.uni' % t)\n\
	xl.step()\n\
";