Blender  V3.3
liquid_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 liquid_variables =
15  "\n\
16 mantaMsg('Liquid variables')\n\
17 narrowBandWidth_s$ID$ = 3\n\
18 combineBandWidth_s$ID$ = narrowBandWidth_s$ID$ - 1\n\
19 adjustedNarrowBandWidth_s$ID$ = $PARTICLE_BAND_WIDTH$ # only used in adjustNumber to control band width\n\
20 particleNumber_s$ID$ = $PARTICLE_NUMBER$\n\
21 minParticles_s$ID$ = $PARTICLE_MINIMUM$\n\
22 maxParticles_s$ID$ = $PARTICLE_MAXIMUM$\n\
23 radiusFactor_s$ID$ = $PARTICLE_RADIUS$\n\
24 using_mesh_s$ID$ = $USING_MESH$\n\
25 using_final_mesh_s$ID$ = $USING_IMPROVED_MESH$\n\
26 using_fractions_s$ID$ = $USING_FRACTIONS$\n\
27 using_apic_s$ID$ = $USING_APIC$\n\
28 using_viscosity_s$ID$ = $USING_VISCOSITY$\n\
29 fracThreshold_s$ID$ = $FRACTIONS_THRESHOLD$\n\
30 fracDistance_s$ID$ = $FRACTIONS_DISTANCE$\n\
31 flipRatio_s$ID$ = $FLIP_RATIO$\n\
32 concaveUpper_s$ID$ = $MESH_CONCAVE_UPPER$\n\
33 concaveLower_s$ID$ = $MESH_CONCAVE_LOWER$\n\
34 meshRadiusFactor_s$ID$ = $MESH_PARTICLE_RADIUS$\n\
35 smoothenPos_s$ID$ = $MESH_SMOOTHEN_POS$\n\
36 smoothenNeg_s$ID$ = $MESH_SMOOTHEN_NEG$\n\
37 randomness_s$ID$ = $PARTICLE_RANDOMNESS$\n\
38 surfaceTension_s$ID$ = $LIQUID_SURFACE_TENSION$\n\
39 maxSysParticles_s$ID$ = $PP_PARTICLE_MAXIMUM$\n\
40 viscosityValue_s$ID$ = $VISCOSITY_VALUE$\n";
41 
42 const std::string liquid_variables_particles =
43  "\n\
44 tauMin_wc_sp$ID$ = $SNDPARTICLE_TAU_MIN_WC$\n\
45 tauMax_wc_sp$ID$ = $SNDPARTICLE_TAU_MAX_WC$\n\
46 tauMin_ta_sp$ID$ = $SNDPARTICLE_TAU_MIN_TA$\n\
47 tauMax_ta_sp$ID$ = $SNDPARTICLE_TAU_MAX_TA$\n\
48 tauMin_k_sp$ID$ = $SNDPARTICLE_TAU_MIN_K$\n\
49 tauMax_k_sp$ID$ = $SNDPARTICLE_TAU_MAX_K$\n\
50 k_wc_sp$ID$ = $SNDPARTICLE_K_WC$\n\
51 k_ta_sp$ID$ = $SNDPARTICLE_K_TA$\n\
52 k_b_sp$ID$ = $SNDPARTICLE_K_B$\n\
53 k_d_sp$ID$ = $SNDPARTICLE_K_D$\n\
54 lMin_sp$ID$ = $SNDPARTICLE_L_MIN$\n\
55 lMax_sp$ID$ = $SNDPARTICLE_L_MAX$\n\
56 c_s_sp$ID$ = 0.4 # classification constant for snd parts\n\
57 c_b_sp$ID$ = 0.77 # classification constant for snd parts\n\
58 pot_radius_sp$ID$ = $SNDPARTICLE_POTENTIAL_RADIUS$\n\
59 update_radius_sp$ID$ = $SNDPARTICLE_UPDATE_RADIUS$\n\
60 using_snd_pushout_sp$ID$ = $SNDPARTICLE_BOUNDARY_PUSHOUT$\n";
61 
63 // GRIDS & MESH & PARTICLESYSTEM
65 
66 const std::string liquid_alloc =
67  "\n\
68 mantaMsg('Liquid alloc')\n\
69 phiParts_s$ID$ = s$ID$.create(LevelsetGrid, name='$NAME_PHIPARTS$')\n\
70 phi_s$ID$ = s$ID$.create(LevelsetGrid, name='$NAME_PHI$')\n\
71 phiTmp_s$ID$ = s$ID$.create(LevelsetGrid, name='$NAME_PHITMP$')\n\
72 velOld_s$ID$ = s$ID$.create(MACGrid, name='$NAME_VELOLD$')\n\
73 velParts_s$ID$ = s$ID$.create(MACGrid, name='$NAME_VELPARTS$')\n\
74 mapWeights_s$ID$ = s$ID$.create(MACGrid, name='$NAME_MAPWEIGHTS$')\n\
75 fractions_s$ID$ = None # allocated dynamically\n\
76 curvature_s$ID$ = None\n\
77 \n\
78 pp_s$ID$ = s$ID$.create(BasicParticleSystem, name='$NAME_PARTS$')\n\
79 pVel_pp$ID$ = pp_s$ID$.create(PdataVec3, name='$NAME_PARTSVELOCITY$')\n\
80 \n\
81 pCx_pp$ID$ = None\n\
82 pCy_pp$ID$ = None\n\
83 pCz_pp$ID$ = None\n\
84 if using_apic_s$ID$:\n\
85  pCx_pp$ID$ = pp_s$ID$.create(PdataVec3)\n\
86  pCy_pp$ID$ = pp_s$ID$.create(PdataVec3)\n\
87  pCz_pp$ID$ = pp_s$ID$.create(PdataVec3)\n\
88 \n\
89 # Acceleration data for particle nbs\n\
90 pindex_s$ID$ = s$ID$.create(ParticleIndexSystem, name='$NAME_PINDEX$')\n\
91 gpi_s$ID$ = s$ID$.create(IntGrid, name='$NAME_GPI$')\n\
92 \n\
93 # Keep track of important objects in dict to load them later on\n\
94 liquid_data_dict_final_s$ID$ = { 'pVel' : pVel_pp$ID$, 'pp' : pp_s$ID$ }\n\
95 liquid_data_dict_resume_s$ID$ = { 'phiParts' : phiParts_s$ID$, 'phi' : phi_s$ID$, 'phiTmp' : phiTmp_s$ID$ }\n";
96 
97 const std::string liquid_alloc_mesh =
98  "\n\
99 mantaMsg('Liquid alloc mesh')\n\
100 phiParts_sm$ID$ = sm$ID$.create(LevelsetGrid, name='$NAME_PHIPARTS_MESH$')\n\
101 phi_sm$ID$ = sm$ID$.create(LevelsetGrid, name='$NAME_PHI_MESH$')\n\
102 pp_sm$ID$ = sm$ID$.create(BasicParticleSystem, name='$NAME_PP_MESH$')\n\
103 flags_sm$ID$ = sm$ID$.create(FlagGrid, name='$NAME_FLAGS_MESH$')\n\
104 mesh_sm$ID$ = sm$ID$.create(Mesh, name='$NAME_MESH$')\n\
105 \n\
106 if using_speedvectors_s$ID$:\n\
107  mVel_mesh$ID$ = mesh_sm$ID$.create(MdataVec3, name='$NAME_VELOCITYVEC_MESH$')\n\
108  vel_sm$ID$ = sm$ID$.create(MACGrid, name='$NAME_VELOCITY_MESH$')\n\
109 \n\
110 # Acceleration data for particle nbs\n\
111 pindex_sm$ID$ = sm$ID$.create(ParticleIndexSystem, name='$NAME_PINDEX_MESH$')\n\
112 gpi_sm$ID$ = sm$ID$.create(IntGrid, name='$NAME_GPI_MESH$')\n\
113 \n\
114 # Set some initial values\n\
115 phiParts_sm$ID$.setConst(9999)\n\
116 phi_sm$ID$.setConst(9999)\n\
117 \n\
118 # Keep track of important objects in dict to load them later on\n\
119 liquid_mesh_dict_s$ID$ = { 'lMesh' : mesh_sm$ID$ }\n\
120 \n\
121 if using_speedvectors_s$ID$:\n\
122  liquid_meshvel_dict_s$ID$ = { 'lVelMesh' : mVel_mesh$ID$ }\n";
123 
124 const std::string liquid_alloc_viscosity =
125  "\n\
126 # Viscosity grids\n\
127 volumes_s$ID$ = sv$ID$.create(RealGrid)\n\
128 viscosity_s$ID$ = s$ID$.create(RealGrid)\n\
129 viscosity_s$ID$.setConst(viscosityValue_s$ID$)\n";
130 
131 const std::string liquid_alloc_curvature =
132  "\n\
133 mantaMsg('Liquid alloc curvature')\n\
134 curvature_s$ID$ = s$ID$.create(RealGrid, name='$NAME_CURVATURE$')\n";
135 
136 const std::string liquid_alloc_particles =
137  "\n\
138 ppSnd_sp$ID$ = sp$ID$.create(BasicParticleSystem, name='$NAME_PARTS_PARTICLES$')\n\
139 pVelSnd_pp$ID$ = ppSnd_sp$ID$.create(PdataVec3, name='$NAME_PARTSVEL_PARTICLES$')\n\
140 pForceSnd_pp$ID$ = ppSnd_sp$ID$.create(PdataVec3, name='$NAME_PARTSFORCE_PARTICLES$')\n\
141 pLifeSnd_pp$ID$ = ppSnd_sp$ID$.create(PdataReal, name='$NAME_PARTSLIFE_PARTICLES$')\n\
142 vel_sp$ID$ = sp$ID$.create(MACGrid, name='$NAME_VELOCITY_PARTICLES$')\n\
143 flags_sp$ID$ = sp$ID$.create(FlagGrid, name='$NAME_FLAGS_PARTICLES$')\n\
144 phi_sp$ID$ = sp$ID$.create(LevelsetGrid, name='$NAME_PHI_PARTICLES$')\n\
145 phiObs_sp$ID$ = sp$ID$.create(LevelsetGrid, name='$NAME_PHIOBS_PARTICLES$')\n\
146 phiOut_sp$ID$ = sp$ID$.create(LevelsetGrid, name='$NAME_PHIOUT_PARTICLES$')\n\
147 normal_sp$ID$ = sp$ID$.create(VecGrid, name='$NAME_NORMAL_PARTICLES$')\n\
148 neighborRatio_sp$ID$ = sp$ID$.create(RealGrid, name='$NAME_NEIGHBORRATIO_PARTICLES$')\n\
149 trappedAir_sp$ID$ = sp$ID$.create(RealGrid, name='$NAME_TRAPPEDAIR_PARTICLES$')\n\
150 waveCrest_sp$ID$ = sp$ID$.create(RealGrid, name='$NAME_WAVECREST_PARTICLES$')\n\
151 kineticEnergy_sp$ID$ = sp$ID$.create(RealGrid, name='$NAME_KINETICENERGY_PARTICLES$')\n\
152 \n\
153 # Set some initial values\n\
154 phi_sp$ID$.setConst(9999)\n\
155 phiObs_sp$ID$.setConst(9999)\n\
156 phiOut_sp$ID$.setConst(9999)\n\
157 \n\
158 # Keep track of important objects in dict to load them later on\n\
159 liquid_particles_dict_final_s$ID$ = { 'pVelSnd' : pVelSnd_pp$ID$, 'pLifeSnd' : pLifeSnd_pp$ID$, 'ppSnd' : ppSnd_sp$ID$ }\n\
160 liquid_particles_dict_resume_s$ID$ = { 'trappedAir' : trappedAir_sp$ID$, 'waveCrest' : waveCrest_sp$ID$, 'kineticEnergy' : kineticEnergy_sp$ID$ }\n";
161 
162 const std::string liquid_init_phi =
163  "\n\
164 # Prepare domain\n\
165 phi_s$ID$.initFromFlags(flags_s$ID$)\n\
166 phiIn_s$ID$.initFromFlags(flags_s$ID$)\n";
167 
169 // STEP FUNCTIONS
171 
172 const std::string liquid_adaptive_step =
173  "\n\
174 def liquid_adaptive_step_$ID$(framenr):\n\
175  mantaMsg('Manta step, frame ' + str(framenr))\n\
176  s$ID$.frame = framenr\n\
177  \n\
178  fluid_pre_step_$ID$()\n\
179  \n\
180  flags_s$ID$.initDomain(boundaryWidth=1 if using_fractions_s$ID$ else 0, phiWalls=phiObs_s$ID$, outflow=boundConditions_s$ID$)\n\
181  \n\
182  if using_obstacle_s$ID$:\n\
183  mantaMsg('Extrapolating object velocity')\n\
184  # ensure velocities inside of obs object, slightly add obvels outside of obs object\n\
185  # extrapolate with phiObsIn before joining (static) phiObsSIn grid to prevent flows into static obs\n\
186  extrapolateVec3Simple(vel=obvelC_s$ID$, phi=phiObsIn_s$ID$, distance=6, inside=True)\n\
187  extrapolateVec3Simple(vel=obvelC_s$ID$, phi=phiObsIn_s$ID$, distance=3, inside=False)\n\
188  resampleVec3ToMac(source=obvelC_s$ID$, target=obvel_s$ID$)\n\
189  \n\
190  mantaMsg('Initializing obstacle levelset')\n\
191  phiObsIn_s$ID$.join(phiObsSIn_s$ID$) # Join static obstacle map\n\
192  phiObsIn_s$ID$.floodFill(boundaryWidth=1)\n\
193  extrapolateLsSimple(phi=phiObsIn_s$ID$, distance=6, inside=True)\n\
194  extrapolateLsSimple(phi=phiObsIn_s$ID$, distance=3, inside=False)\n\
195  phiObs_s$ID$.join(phiObsIn_s$ID$)\n\
196  \n\
197  # Additional sanity check: fill holes in phiObs which can result after joining with phiObsIn\n\
198  phiObs_s$ID$.floodFill(boundaryWidth=2 if using_fractions_s$ID$ else 1)\n\
199  extrapolateLsSimple(phi=phiObs_s$ID$, distance=6, inside=True)\n\
200  extrapolateLsSimple(phi=phiObs_s$ID$, distance=3)\n\
201  \n\
202  mantaMsg('Initializing fluid levelset')\n\
203  phiIn_s$ID$.join(phiSIn_s$ID$) # Join static flow map\n\
204  extrapolateLsSimple(phi=phiIn_s$ID$, distance=6, inside=True)\n\
205  extrapolateLsSimple(phi=phiIn_s$ID$, distance=3)\n\
206  phi_s$ID$.join(phiIn_s$ID$)\n\
207  \n\
208  if using_outflow_s$ID$:\n\
209  phiOutIn_s$ID$.join(phiOutSIn_s$ID$) # Join static outflow map\n\
210  phiOut_s$ID$.join(phiOutIn_s$ID$)\n\
211  \n\
212  if using_fractions_s$ID$:\n\
213  updateFractions(flags=flags_s$ID$, phiObs=phiObs_s$ID$, fractions=fractions_s$ID$, boundaryWidth=boundaryWidth_s$ID$, fracThreshold=fracThreshold_s$ID$)\n\
214  setObstacleFlags(flags=flags_s$ID$, phiObs=phiObs_s$ID$, phiOut=phiOut_s$ID$, fractions=fractions_s$ID$, phiIn=phiIn_s$ID$)\n\
215  \n\
216  if using_obstacle_s$ID$:\n\
217  # TODO(sebbas): Enable flags check again, currently produces unstable particle behavior\n\
218  phi_s$ID$.subtract(o=phiObsIn_s$ID$) #, flags=flags_s$ID$, subtractType=FlagObstacle)\n\
219  \n\
220  # add initial velocity: set invel as source grid to ensure const vels in inflow region, sampling makes use of this\n\
221  if using_invel_s$ID$:\n\
222  extrapolateVec3Simple(vel=invelC_s$ID$, phi=phiIn_s$ID$, distance=6, inside=True)\n\
223  # Using cell centered invels, a false isMAC flag ensures correct interpolation\n\
224  pVel_pp$ID$.setSource(grid=invelC_s$ID$, isMAC=False)\n\
225  # reset pvel grid source before sampling new particles - ensures that new particles are initialized with 0 velocity\n\
226  else:\n\
227  pVel_pp$ID$.setSource(grid=None, isMAC=False)\n\
228  \n\
229  pp_s$ID$.maxParticles = maxSysParticles_s$ID$ # remember, 0 means no particle cap\n\
230  sampleLevelsetWithParticles(phi=phiIn_s$ID$, flags=flags_s$ID$, parts=pp_s$ID$, discretization=particleNumber_s$ID$, randomness=randomness_s$ID$)\n\
231  flags_s$ID$.updateFromLevelset(phi_s$ID$)\n\
232  \n\
233  mantaMsg('Liquid step / s$ID$.frame: ' + str(s$ID$.frame))\n\
234  liquid_step_$ID$()\n\
235  \n\
236  s$ID$.step()\n\
237  \n\
238  fluid_post_step_$ID$()\n";
239 
240 const std::string liquid_step =
241  "\n\
242 def liquid_step_$ID$():\n\
243  mantaMsg('Liquid step')\n\
244  \n\
245  mantaMsg('Advecting particles')\n\
246  pp_s$ID$.advectInGrid(flags=flags_s$ID$, vel=vel_s$ID$, integrationMode=IntRK4, deleteInObstacle=deleteInObstacle_s$ID$, stopInObstacle=False, skipNew=True)\n\
247  \n\
248  mantaMsg('Pushing particles out of obstacles')\n\
249  if using_obstacle_s$ID$ and using_fractions_s$ID$ and fracDistance_s$ID$ > 0:\n\
250  # Optional: Increase distance between fluid and obstacles (only obstacles, not borders)\n\
251  pushOutofObs(parts=pp_s$ID$, flags=flags_s$ID$, phiObs=phiObsIn_s$ID$, thresh=fracDistance_s$ID$)\n\
252  pushOutofObs(parts=pp_s$ID$, flags=flags_s$ID$, phiObs=phiObs_s$ID$)\n\
253  \n\
254  # save original states for later (used during mesh / secondary particle creation)\n\
255  # but only save the state at the beginning of an adaptive frame\n\
256  if not s$ID$.timePerFrame:\n\
257  phiTmp_s$ID$.copyFrom(phi_s$ID$)\n\
258  velTmp_s$ID$.copyFrom(vel_s$ID$)\n\
259  \n\
260  mantaMsg('Advecting phi')\n\
261  advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=phi_s$ID$, order=1) # first order is usually enough\n\
262  mantaMsg('Advecting velocity')\n\
263  advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=vel_s$ID$, order=2)\n\
264  \n\
265  # create level set of particles\n\
266  gridParticleIndex(parts=pp_s$ID$, flags=flags_s$ID$, indexSys=pindex_s$ID$, index=gpi_s$ID$)\n\
267  unionParticleLevelset(parts=pp_s$ID$, indexSys=pindex_s$ID$, flags=flags_s$ID$, index=gpi_s$ID$, phi=phiParts_s$ID$, radiusFactor=radiusFactor_s$ID$)\n\
268  \n\
269  # combine level set of particles with grid level set\n\
270  phi_s$ID$.addConst(1.) # shrink slightly\n\
271  phi_s$ID$.join(phiParts_s$ID$)\n\
272  extrapolateLsSimple(phi=phi_s$ID$, distance=narrowBandWidth_s$ID$+2, inside=True)\n\
273  extrapolateLsSimple(phi=phi_s$ID$, distance=3)\n\
274  phi_s$ID$.setBoundNeumann(0) # make sure no particles are placed at outer boundary\n\
275  \n\
276  if not domainClosed_s$ID$ or using_outflow_s$ID$:\n\
277  resetOutflow(flags=flags_s$ID$, phi=phi_s$ID$, parts=pp_s$ID$, index=gpi_s$ID$, indexSys=pindex_s$ID$)\n\
278  flags_s$ID$.updateFromLevelset(phi_s$ID$)\n\
279  \n\
280  # combine particle velocities with advected grid velocities\n\
281  if using_apic_s$ID$:\n\
282  apicMapPartsToMAC(flags=flags_s$ID$, vel=vel_s$ID$, parts=pp_s$ID$, partVel=pVel_pp$ID$, cpx=pCx_pp$ID$, cpy=pCy_pp$ID$, cpz=pCz_pp$ID$)\n\
283  else:\n\
284  mapPartsToMAC(vel=velParts_s$ID$, flags=flags_s$ID$, velOld=velOld_s$ID$, parts=pp_s$ID$, partVel=pVel_pp$ID$, weight=mapWeights_s$ID$)\n\
285  \n\
286  extrapolateMACFromWeight(vel=velParts_s$ID$, distance=2, weight=mapWeights_s$ID$)\n\
287  combineGridVel(vel=velParts_s$ID$, weight=mapWeights_s$ID$, combineVel=vel_s$ID$, phi=phi_s$ID$, narrowBand=combineBandWidth_s$ID$, thresh=0)\n\
288  velOld_s$ID$.copyFrom(vel_s$ID$)\n\
289  \n\
290  # forces & pressure solve\n\
291  addGravity(flags=flags_s$ID$, vel=vel_s$ID$, gravity=gravity_s$ID$, scale=False)\n\
292  \n\
293  mantaMsg('Adding external forces')\n\
294  addForceField(flags=flags_s$ID$, vel=vel_s$ID$, force=forces_s$ID$)\n\
295  \n\
296  extrapolateMACSimple(flags=flags_s$ID$, vel=vel_s$ID$, distance=2, intoObs=True if using_fractions_s$ID$ else False)\n\
297  \n\
298  # vel diffusion / viscosity!\n\
299  if using_diffusion_s$ID$:\n\
300  mantaMsg('Viscosity')\n\
301  # diffusion param for solve = const * dt / dx^2\n\
302  alphaV = kinViscosity_s$ID$ * s$ID$.timestep * float(res_s$ID$*res_s$ID$)\n\
303  setWallBcs(flags=flags_s$ID$, vel=vel_s$ID$, obvel=None if using_fractions_s$ID$ else obvel_s$ID$, phiObs=phiObs_s$ID$, fractions=fractions_s$ID$)\n\
304  cgSolveDiffusion(flags_s$ID$, vel_s$ID$, alphaV)\n\
305  \n\
306  mantaMsg('Curvature')\n\
307  getLaplacian(laplacian=curvature_s$ID$, grid=phi_s$ID$)\n\
308  curvature_s$ID$.clamp(-1.0, 1.0)\n\
309  \n\
310  setWallBcs(flags=flags_s$ID$, vel=vel_s$ID$, obvel=None if using_fractions_s$ID$ else obvel_s$ID$, phiObs=phiObs_s$ID$, fractions=fractions_s$ID$)\n\
311  if using_viscosity_s$ID$:\n\
312  viscosity_s$ID$.setConst(viscosityValue_s$ID$)\n\
313  applyViscosity(flags=flags_s$ID$, phi=phi_s$ID$, vel=vel_s$ID$, volumes=volumes_s$ID$, viscosity=viscosity_s$ID$)\n\
314  \n\
315  setWallBcs(flags=flags_s$ID$, vel=vel_s$ID$, obvel=None if using_fractions_s$ID$ else obvel_s$ID$, phiObs=phiObs_s$ID$, fractions=fractions_s$ID$)\n\
316  if using_guiding_s$ID$:\n\
317  mantaMsg('Guiding and pressure')\n\
318  PD_fluid_guiding(vel=vel_s$ID$, velT=velT_s$ID$, flags=flags_s$ID$, phi=phi_s$ID$, curv=curvature_s$ID$, surfTens=surfaceTension_s$ID$, fractions=fractions_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$, zeroPressureFixing=domainClosed_s$ID$)\n\
319  else:\n\
320  mantaMsg('Pressure')\n\
321  solvePressure(flags=flags_s$ID$, vel=vel_s$ID$, pressure=pressure_s$ID$, curv=curvature_s$ID$, surfTens=surfaceTension_s$ID$, fractions=fractions_s$ID$, obvel=obvel_s$ID$ if using_fractions_s$ID$ else None, zeroPressureFixing=domainClosed_s$ID$)\n\
322  \n\
323  extrapolateMACSimple(flags=flags_s$ID$, vel=vel_s$ID$, distance=4, intoObs=True if using_fractions_s$ID$ else False)\n\
324  setWallBcs(flags=flags_s$ID$, vel=vel_s$ID$, obvel=None if using_fractions_s$ID$ else obvel_s$ID$, phiObs=phiObs_s$ID$, fractions=fractions_s$ID$)\n\
325  \n\
326  if not using_fractions_s$ID$:\n\
327  extrapolateMACSimple(flags=flags_s$ID$, vel=vel_s$ID$)\n\
328  \n\
329  # set source grids for resampling, used in adjustNumber!\n\
330  pVel_pp$ID$.setSource(grid=vel_s$ID$, isMAC=True)\n\
331  adjustNumber(parts=pp_s$ID$, vel=vel_s$ID$, flags=flags_s$ID$, minParticles=minParticles_s$ID$, maxParticles=maxParticles_s$ID$, phi=phi_s$ID$, exclude=phiObs_s$ID$, radiusFactor=radiusFactor_s$ID$, narrowBand=adjustedNarrowBandWidth_s$ID$)\n\
332  \n\
333  if using_apic_s$ID$:\n\
334  apicMapMACGridToParts(partVel=pVel_pp$ID$, cpx=pCx_pp$ID$, cpy=pCy_pp$ID$, cpz=pCz_pp$ID$, parts=pp_s$ID$, vel=vel_s$ID$, flags=flags_s$ID$)\n\
335  else:\n\
336  flipVelocityUpdate(vel=vel_s$ID$, velOld=velOld_s$ID$, flags=flags_s$ID$, parts=pp_s$ID$, partVel=pVel_pp$ID$, flipRatio=flipRatio_s$ID$)\n";
337 
338 const std::string liquid_step_mesh =
339  "\n\
340 def liquid_step_mesh_$ID$():\n\
341  mantaMsg('Liquid step mesh')\n\
342  \n\
343  # no upres: just use the loaded grids\n\
344  if upres_sm$ID$ <= 1:\n\
345  phi_sm$ID$.copyFrom(phi_s$ID$)\n\
346  \n\
347  # with upres: recreate grids\n\
348  else:\n\
349  interpolateGrid(target=phi_sm$ID$, source=phi_s$ID$)\n\
350  \n\
351  # create surface\n\
352  pp_sm$ID$.readParticles(pp_s$ID$)\n\
353  gridParticleIndex(parts=pp_sm$ID$, flags=flags_sm$ID$, indexSys=pindex_sm$ID$, index=gpi_sm$ID$)\n\
354  \n\
355  if using_final_mesh_s$ID$:\n\
356  mantaMsg('Liquid using improved particle levelset')\n\
357  improvedParticleLevelset(pp_sm$ID$, pindex_sm$ID$, flags_sm$ID$, gpi_sm$ID$, phiParts_sm$ID$, meshRadiusFactor_s$ID$, smoothenPos_s$ID$, smoothenNeg_s$ID$, concaveLower_s$ID$, concaveUpper_s$ID$)\n\
358  else:\n\
359  mantaMsg('Liquid using union particle levelset')\n\
360  unionParticleLevelset(pp_sm$ID$, pindex_sm$ID$, flags_sm$ID$, gpi_sm$ID$, phiParts_sm$ID$, meshRadiusFactor_s$ID$)\n\
361  \n\
362  phi_sm$ID$.addConst(1.) # shrink slightly\n\
363  phi_sm$ID$.join(phiParts_sm$ID$)\n\
364  extrapolateLsSimple(phi=phi_sm$ID$, distance=narrowBandWidth_s$ID$+2, inside=True)\n\
365  extrapolateLsSimple(phi=phi_sm$ID$, distance=3)\n\
366  phi_sm$ID$.setBoundNeumann(0) # make sure no particles are placed at outer boundary\n\
367  \n\
368  # Vert vel vector needs to pull data from vel grid with correct dim\n\
369  if using_speedvectors_s$ID$:\n\
370  interpolateMACGrid(target=vel_sm$ID$, source=vel_s$ID$)\n\
371  mVel_mesh$ID$.setSource(grid=vel_sm$ID$, isMAC=True)\n\
372  \n\
373  # Set 0.5 boundary at walls + account for extra wall thickness in fractions mode + account for grid scaling:\n\
374  # E.g. at upres=1 we expect 1 cell border (or 2 with fractions), at upres=2 we expect 2 cell border (or 4 with fractions), etc.\n\
375  # Use -1 since setBound() starts counting at 0 (and additional -1 for fractions to account for solid/fluid interface cells)\n\
376  phi_sm$ID$.setBound(value=0.5, boundaryWidth=(upres_sm$ID$*2)-2 if using_fractions_s$ID$ else upres_sm$ID$-1)\n\
377  phi_sm$ID$.createMesh(mesh_sm$ID$)\n";
378 
379 const std::string liquid_step_particles =
380  "\n\
381 def liquid_step_particles_$ID$():\n\
382  mantaMsg('Secondary particles step')\n\
383  \n\
384  # no upres: just use the loaded grids\n\
385  if upres_sp$ID$ <= 1:\n\
386  vel_sp$ID$.copyFrom(velTmp_s$ID$)\n\
387  phiObs_sp$ID$.copyFrom(phiObs_s$ID$)\n\
388  phi_sp$ID$.copyFrom(phiTmp_s$ID$)\n\
389  phiOut_sp$ID$.copyFrom(phiOut_s$ID$)\n\
390  \n\
391  # with upres: recreate grids\n\
392  else:\n\
393  # create highres grids by interpolation\n\
394  interpolateMACGrid(target=vel_sp$ID$, source=velTmp_s$ID$)\n\
395  interpolateGrid(target=phiObs_sp$ID$, source=phiObs_s$ID$)\n\
396  interpolateGrid(target=phi_sp$ID$, source=phiTmp_s$ID$)\n\
397  interpolateGrid(target=phiOut_sp$ID$, source=phiOut_s$ID$)\n\
398  \n\
399  # phiIn not needed, bwidth to 0 because we are omitting flags.initDomain()\n\
400  setObstacleFlags(flags=flags_sp$ID$, phiObs=phiObs_sp$ID$, phiOut=phiOut_sp$ID$, phiIn=None, boundaryWidth=0)\n\
401  flags_sp$ID$.updateFromLevelset(levelset=phi_sp$ID$)\n\
402  \n\
403  # Actual secondary particle simulation\n\
404  flipComputeSecondaryParticlePotentials(potTA=trappedAir_sp$ID$, potWC=waveCrest_sp$ID$, potKE=kineticEnergy_sp$ID$, neighborRatio=neighborRatio_sp$ID$, flags=flags_sp$ID$, v=vel_sp$ID$, normal=normal_sp$ID$, phi=phi_sp$ID$, radius=pot_radius_sp$ID$, tauMinTA=tauMin_ta_sp$ID$, tauMaxTA=tauMax_ta_sp$ID$, tauMinWC=tauMin_wc_sp$ID$, tauMaxWC=tauMax_wc_sp$ID$, tauMinKE=tauMin_k_sp$ID$, tauMaxKE=tauMax_k_sp$ID$, scaleFromManta=ratioMetersToRes_s$ID$)\n\
405  flipSampleSecondaryParticles(mode='single', flags=flags_sp$ID$, v=vel_sp$ID$, pts_sec=ppSnd_sp$ID$, v_sec=pVelSnd_pp$ID$, l_sec=pLifeSnd_pp$ID$, lMin=lMin_sp$ID$, lMax=lMax_sp$ID$, potTA=trappedAir_sp$ID$, potWC=waveCrest_sp$ID$, potKE=kineticEnergy_sp$ID$, neighborRatio=neighborRatio_sp$ID$, c_s=c_s_sp$ID$, c_b=c_b_sp$ID$, k_ta=k_ta_sp$ID$, k_wc=k_wc_sp$ID$)\n\
406  flipUpdateSecondaryParticles(mode='linear', pts_sec=ppSnd_sp$ID$, v_sec=pVelSnd_pp$ID$, l_sec=pLifeSnd_pp$ID$, f_sec=pForceSnd_pp$ID$, flags=flags_sp$ID$, v=vel_sp$ID$, neighborRatio=neighborRatio_sp$ID$, radius=update_radius_sp$ID$, gravity=gravity_s$ID$, scale=False, k_b=k_b_sp$ID$, k_d=k_d_sp$ID$, c_s=c_s_sp$ID$, c_b=c_b_sp$ID$)\n\
407  if using_snd_pushout_sp$ID$:\n\
408  pushOutofObs(parts=ppSnd_sp$ID$, flags=flags_sp$ID$, phiObs=phiObs_sp$ID$, shift=1.0)\n\
409  flipDeleteParticlesInObstacle(pts=ppSnd_sp$ID$, flags=flags_sp$ID$) # delete particles inside obstacle and outflow cells\n\
410  \n\
411  # Print debug information in the console\n\
412  if 0:\n\
413  debugGridInfo(flags=flags_sp$ID$, grid=trappedAir_sp$ID$, name='Trapped Air')\n\
414  debugGridInfo(flags=flags_sp$ID$, grid=waveCrest_sp$ID$, name='Wave Crest')\n\
415  debugGridInfo(flags=flags_sp$ID$, grid=kineticEnergy_sp$ID$, name='Kinetic Energy')\n";
416 
418 // IMPORT
420 
421 const std::string liquid_load_data =
422  "\n\
423 def liquid_load_data_$ID$(path, framenr, file_format, resumable):\n\
424  mantaMsg('Liquid load data')\n\
425  dict = { **fluid_data_dict_final_s$ID$, **fluid_data_dict_resume_s$ID$, **liquid_data_dict_final_s$ID$, **liquid_data_dict_resume_s$ID$ } if resumable else { **fluid_data_dict_final_s$ID$, **liquid_data_dict_final_s$ID$ }\n\
426  fluid_file_import_s$ID$(dict=dict, path=path, framenr=framenr, file_format=file_format, file_name=file_data_s$ID$)\n\
427  \n\
428  copyVec3ToReal(source=vel_s$ID$, targetX=x_vel_s$ID$, targetY=y_vel_s$ID$, targetZ=z_vel_s$ID$)\n";
429 
430 const std::string liquid_load_mesh =
431  "\n\
432 def liquid_load_mesh_$ID$(path, framenr, file_format):\n\
433  mantaMsg('Liquid load mesh')\n\
434  dict = liquid_mesh_dict_s$ID$\n\
435  fluid_file_import_s$ID$(dict=dict, path=path, framenr=framenr, file_format=file_format, file_name=file_mesh_s$ID$)\n\
436 \n\
437 def liquid_load_meshvel_$ID$(path, framenr, file_format):\n\
438  mantaMsg('Liquid load meshvel')\n\
439  dict = liquid_meshvel_dict_s$ID$\n\
440  fluid_file_import_s$ID$(dict=dict, path=path, framenr=framenr, file_format=file_format, file_name=file_meshvel_s$ID$)\n";
441 
442 const std::string liquid_load_particles =
443  "\n\
444 def liquid_load_particles_$ID$(path, framenr, file_format, resumable):\n\
445  mantaMsg('Liquid load particles')\n\
446  dict = { **liquid_particles_dict_final_s$ID$, **liquid_particles_dict_resume_s$ID$ } if resumable else { **liquid_particles_dict_final_s$ID$ }\n\
447  fluid_file_import_s$ID$(dict=dict, path=path, framenr=framenr, file_format=file_format, file_name=file_particles_s$ID$)\n";
448 
450 // EXPORT
452 
453 const std::string liquid_save_data =
454  "\n\
455 def liquid_save_data_$ID$(path, framenr, file_format, resumable):\n\
456  mantaMsg('Liquid save data')\n\
457  dict = { **fluid_data_dict_final_s$ID$, **fluid_data_dict_resume_s$ID$, **liquid_data_dict_final_s$ID$, **liquid_data_dict_resume_s$ID$ } if resumable else { **fluid_data_dict_final_s$ID$, **liquid_data_dict_final_s$ID$ }\n\
458  if not withMPSave or isWindows:\n\
459  fluid_file_export_s$ID$(dict=dict, path=path, framenr=framenr, file_format=file_format, file_name=file_data_s$ID$)\n\
460  else:\n\
461  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";
462 
463 const std::string liquid_save_mesh =
464  "\n\
465 def liquid_save_mesh_$ID$(path, framenr, file_format):\n\
466  mantaMsg('Liquid save mesh')\n\
467  dict = liquid_mesh_dict_s$ID$\n\
468  if not withMPSave or isWindows:\n\
469  fluid_file_export_s$ID$(dict=dict, path=path, framenr=framenr, file_format=file_format, file_name=file_mesh_s$ID$)\n\
470  else:\n\
471  fluid_cache_multiprocessing_start_$ID$(function=fluid_file_export_s$ID$, file_name=file_mesh_s$ID$, framenr=framenr, format_data=file_format, path_data=path, dict=dict, do_join=False)\n\
472 \n\
473 def liquid_save_meshvel_$ID$(path, framenr, file_format):\n\
474  mantaMsg('Liquid save mesh vel')\n\
475  dict = liquid_meshvel_dict_s$ID$\n\
476  if not withMPSave or isWindows:\n\
477  fluid_file_export_s$ID$(dict=dict, path=path, framenr=framenr, file_format=file_format)\n\
478  else:\n\
479  fluid_cache_multiprocessing_start_$ID$(function=fluid_file_export_s$ID$, framenr=framenr, format_data=file_format, path_data=path, dict=dict, do_join=False)\n";
480 
481 const std::string liquid_save_particles =
482  "\n\
483 def liquid_save_particles_$ID$(path, framenr, file_format, resumable):\n\
484  mantaMsg('Liquid save particles')\n\
485  dict = { **liquid_particles_dict_final_s$ID$, **liquid_particles_dict_resume_s$ID$ } if resumable else { **liquid_particles_dict_final_s$ID$ }\n\
486  if not withMPSave or isWindows:\n\
487  fluid_file_export_s$ID$(dict=dict, path=path, framenr=framenr, file_format=file_format, file_name=file_particles_s$ID$)\n\
488  else:\n\
489  fluid_cache_multiprocessing_start_$ID$(function=fluid_file_export_s$ID$, file_name=file_particles_s$ID$, framenr=framenr, format_data=file_format, path_data=path, dict=dict, do_join=False)\n";
490 
492 // STANDALONE MODE
494 
495 const std::string liquid_standalone =
496  "\n\
497 # Helper function to call cache load functions\n\
498 def load_data(frame, cache_resumable):\n\
499  liquid_load_data_$ID$(os.path.join(cache_dir, 'data'), frame, file_format_data, cache_resumable)\n\
500  if using_sndparts_s$ID$:\n\
501  liquid_load_particles_$ID$(os.path.join(cache_dir, 'particles'), frame, file_format_data, cache_resumable)\n\
502  if using_mesh_s$ID$:\n\
503  liquid_load_mesh_$ID$(os.path.join(cache_dir, 'mesh'), frame, file_format_mesh)\n\
504  if using_guiding_s$ID$:\n\
505  fluid_load_guiding_$ID$(os.path.join(cache_dir, 'guiding'), frame, file_format_data)\n\
506 \n\
507 # Helper function to call step functions\n\
508 def step(frame):\n\
509  liquid_adaptive_step_$ID$(frame)\n\
510  if using_mesh_s$ID$:\n\
511  liquid_step_mesh_$ID$()\n\
512  if using_sndparts_s$ID$:\n\
513  liquid_step_particles_$ID$()\n";
const std::string liquid_load_data
const std::string liquid_save_data
const std::string liquid_alloc_viscosity
const std::string liquid_variables
Definition: liquid_script.h:14
const std::string liquid_save_particles
const std::string liquid_standalone
const std::string liquid_variables_particles
Definition: liquid_script.h:42
const std::string liquid_load_mesh
const std::string liquid_alloc_particles
const std::string liquid_step
const std::string liquid_alloc
Definition: liquid_script.h:66
const std::string liquid_alloc_curvature
const std::string liquid_adaptive_step
const std::string liquid_load_particles
const std::string liquid_step_mesh
const std::string liquid_step_particles
const std::string liquid_alloc_mesh
Definition: liquid_script.h:97
const std::string liquid_init_phi
const std::string liquid_save_mesh