[Bf-blender-cvs] [a1a0e9efef8] fluid-mantaflow: initial tracer particle support
Sebastián Barschkis
noreply at git.blender.org
Fri Jul 21 16:17:41 CEST 2017
Commit: a1a0e9efef8be50079e7b09be206cf6cd5cd72bb
Author: Sebastián Barschkis
Date: Thu Jul 20 22:56:31 2017 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rBa1a0e9efef8be50079e7b09be206cf6cd5cd72bb
initial tracer particle support
===================================================================
M intern/mantaflow/intern/manta_pp/tbb/plugin/flip.cpp
M intern/mantaflow/intern/strings/liquid_script.h
M release/scripts/startup/bl_ui/properties_physics_smoke.py
===================================================================
diff --git a/intern/mantaflow/intern/manta_pp/tbb/plugin/flip.cpp b/intern/mantaflow/intern/manta_pp/tbb/plugin/flip.cpp
index bc43336d4f3..a93e738ab6d 100644
--- a/intern/mantaflow/intern/manta_pp/tbb/plugin/flip.cpp
+++ b/intern/mantaflow/intern/manta_pp/tbb/plugin/flip.cpp
@@ -600,7 +600,7 @@ void combineGridVel( MACGrid& vel, Grid<Vec3>& weight, MACGrid& combineVel, Leve
-void sampleSndParts(BasicParticleSystem& parts, FlagGrid& flags, MACGrid& vel, LevelsetGrid& phi, ParticleDataImpl<Vec3>& partVel, ParticleDataImpl<int>& partType, Real dropVelThresh, Real bubbleRise, int minParticles, int maxParticles, Vec3 gravity, Real radiusFactor=1., bool drops=true, bool floats=false, bool tracers=false, bool bubbles=true) {
+void sampleSndParts(BasicParticleSystem& parts, FlagGrid& flags, MACGrid& vel, LevelsetGrid& phi, ParticleDataImpl<Vec3>& partVel, ParticleDataImpl<int>& partType, Real dropVelThresh, Real bubbleRise, Real tracerAmount, int minParticles, int maxParticles, Vec3 gravity, bool drops=true, bool floats=false, bool tracers=false, bool bubbles=true) {
bool is3D = flags.is3D();
Real dt = flags.getParent()->getDt();
Vec3 grav = gravity * flags.getParent()->getDt() / flags.getDx();
@@ -634,21 +634,6 @@ void sampleSndParts(BasicParticleSystem& parts, FlagGrid& flags, MACGrid& vel, L
parts.setPos(idx, parts.getPos(idx) + direction * phiv * grad );
}
}
-
- // Convert drop to bubble
- if (bubbles && (partType[idx] & ParticleBase::PDROPLET) && phiv < -FLOAT_THRESH)
- {
- // Throttle drop particle, is inside fluid now
- partVel[idx] = partVel[idx] * 0.5;
-
- // TODO (sebbas): Convert to bubble when particle is slow enough or when it is deep enough in fluid?
- // Convert drop particle to bubble when partvel falls below damping factor
-// Vec3 dmpFac = damping * grav;
-// if ( (partVel[idx].x < dmpFac.x) && (partVel[idx].y < dmpFac.y) && (partVel[idx].z < dmpFac.z) ) {
- if (phiv < BUBBLE_THRESH) {
- partType[idx] = ParticleBase::PBUBBLE;
- }
- }
// TODO (sebbas): Currently unreliable. Drop particles might get converted into floats to early
// // Convert bubble to float
@@ -742,21 +727,32 @@ void sampleSndParts(BasicParticleSystem& parts, FlagGrid& flags, MACGrid& vel, L
}
if (bubbles) {
- // Update forces: gravity
+ // Generate bubble particles (converted from drops). Then update forces: gravity and particle velocity
for (IndexInt idx=0; idx<(int)parts.size(); idx++) {
if (parts.isActive(idx)) {
+ Real phiv = phi.getInterpolated( parts.getPos(idx) );
+
+ // Throttle drop particle, is inside fluid now. Is candidate for bubble
+ if (partType[idx] & ParticleBase::PDROPLET && phiv < -FLOAT_THRESH) {
+ partVel[idx] = partVel[idx] * 0.5;
+ }
+
+ // Update particle type (convert to bubble) and set initial velocity (now use fluid vel)
+ if (partType[idx] & ParticleBase::PDROPLET && phiv < BUBBLE_THRESH) {
+ partVel[idx] = vel.getInterpolated( parts[idx].pos );
+ partType[idx] = ParticleBase::PBUBBLE;
+ }
+ // Let bubbles rise up
if (partType[idx] & ParticleBase::PBUBBLE) {
- // Let bubbles rise up
-// partVel[idx] = vel.getInterpolated( parts[idx].pos );
- partVel[idx] -= bubbleRise * grav;
+ partVel[idx] += bubbleRise * grav * (-1);
}
}
}
}
if (floats) {
- // Generate new float particlesd
+ // Generate new float particles
FOR_IJK_BND(phi, 0) {
if ( flags.isObstacle(i,j,k) ) continue;
@@ -803,12 +799,17 @@ void sampleSndParts(BasicParticleSystem& parts, FlagGrid& flags, MACGrid& vel, L
// Generate new tracer particles
FOR_IJK_BND(phi, 0) {
if ( flags.isObstacle(i,j,k) ) continue;
- if ( phi(i,j,k) > 0. ) continue; // Only generate particles inside fluid
+
+ // Only generate particles inside fluid
+ if ( phi(i,j,k) > 0. ) continue;
// Already sufficient particles in cell?
int cnt = tmp(i,j,k);
if (cnt >= minParticles) continue;
+ // Only seed if random num exceeds given amount probability
+ if (mRand.getFloat(0., 1.) > tracerAmount) continue;
+
if ( flags.isFluid(i,j,k) || flags.isEmpty(i,j,k) ) {
// Get phi for next particle position
Vec3 pos = Vec3(i,j,k);
@@ -824,23 +825,22 @@ void sampleSndParts(BasicParticleSystem& parts, FlagGrid& flags, MACGrid& vel, L
parts.doCompress();
parts.insertBufferedParticles();
- // Update forces: gravity and initial particle velocity
+ // Update forces: gravity and particle velocity
for (IndexInt idx=0; idx<(int)parts.size(); idx++) {
if (parts.isActive(idx)) {
- // Initial velocity (only for new particles)
+ // Update particle type
if (parts.getStatus(idx) & ParticleBase::PNEW) {
- partVel[idx] = vel.getInterpolated( parts[idx].pos );
-
- // Need to initialize flag for this particle
partType[idx] = ParticleBase::PTRACER;
}
- if (partType[idx] & ParticleBase::PTRACER)
- partVel[idx] += 0.5 * grav;
+
+ if (partType[idx] & ParticleBase::PTRACER) {
+ partVel[idx] = vel.getInterpolated( parts[idx].pos );
+ }
}
}
}
-} static PyObject* _W_18 (PyObject* _self, PyObject* _linargs, PyObject* _kwds) { try { PbArgs _args(_linargs, _kwds); FluidSolver *parent = _args.obtainParent(); bool noTiming = _args.getOpt<bool>("notiming", -1, 0); pbPreparePlugin(parent, "sampleSndParts" , !noTiming ); PyObject *_retval = 0; { ArgLocker _lock; BasicParticleSystem& parts = *_args.getPtr<BasicParticleSystem >("parts",0,&_lock); FlagGrid& flags = *_args.getPtr<FlagGrid >("flags",1,&_lock); MACGrid& vel = *_args.getPtr<M [...]
+} static PyObject* _W_18 (PyObject* _self, PyObject* _linargs, PyObject* _kwds) { try { PbArgs _args(_linargs, _kwds); FluidSolver *parent = _args.obtainParent(); bool noTiming = _args.getOpt<bool>("notiming", -1, 0); pbPreparePlugin(parent, "sampleSndParts" , !noTiming ); PyObject *_retval = 0; { ArgLocker _lock; BasicParticleSystem& parts = *_args.getPtr<BasicParticleSystem >("parts",0,&_lock); FlagGrid& flags = *_args.getPtr<FlagGrid >("flags",1,&_lock); MACGrid& vel = *_args.getPtr<M [...]
} // namespace
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index 76e59a6c26b..0b125d3adfb 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -204,7 +204,7 @@ def liquid_step_$ID$():\n\
\n\
mantaMsg('Sampling secondary particles')\n\
if (using_drops_s$ID$ or using_bubbles_s$ID$ or using_floats_s$ID$ or using_tracers_s$ID$):\n\
- sampleSndParts(parts=ppSnd_s$ID$, flags=flags_s$ID$, vel=vel_s$ID$, partVel=pVelSnd_pp$ID$, partType=pTypeSnd_pp$ID$, phi=phi_s$ID$, dropVelThresh=$SNDPARTICLE_VEL_THRESH$, bubbleRise=$SNDPARTICLE_BUBBLE_RISE$, minParticles=2, maxParticles=8, gravity=gravity_s$ID$, drops=using_drops_s$ID$, bubbles=using_bubbles_s$ID$, floats=using_floats_s$ID$, tracers=using_tracers_s$ID$)\n\
+ sampleSndParts(parts=ppSnd_s$ID$, flags=flags_s$ID$, vel=vel_s$ID$, partVel=pVelSnd_pp$ID$, partType=pTypeSnd_pp$ID$, phi=phi_s$ID$, dropVelThresh=$SNDPARTICLE_VEL_THRESH$, bubbleRise=$SNDPARTICLE_BUBBLE_RISE$, tracerAmount=0.2, minParticles=2, maxParticles=8, gravity=gravity_s$ID$, drops=using_drops_s$ID$, bubbles=using_bubbles_s$ID$, floats=using_floats_s$ID$, tracers=using_tracers_s$ID$)\n\
\n\
mantaMsg('Pushing particle
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list