[Bf-blender-cvs] [1bdf2152e11] fluid-mantaflow: added first version of secondary particle function to mantaflow files

Sebastián Barschkis noreply at git.blender.org
Sat Jul 1 00:51:44 CEST 2017


Commit: 1bdf2152e115dd670300ff63bfb3870cda310e8d
Author: Sebastián Barschkis
Date:   Sat Jun 24 19:55:49 2017 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB1bdf2152e115dd670300ff63bfb3870cda310e8d

added first version of secondary particle function to mantaflow files

liquid script now also has additional particle system (for all secondary particles)

===================================================================

M	intern/mantaflow/intern/manta_pp/omp/plugin/flip.cpp
M	intern/mantaflow/intern/manta_pp/omp/registration.cpp
M	intern/mantaflow/intern/manta_pp/tbb/plugin/flip.cpp
M	intern/mantaflow/intern/manta_pp/tbb/registration.cpp
M	intern/mantaflow/intern/strings/liquid_script.h

===================================================================

diff --git a/intern/mantaflow/intern/manta_pp/omp/plugin/flip.cpp b/intern/mantaflow/intern/manta_pp/omp/plugin/flip.cpp
index c591c8dbc87..e4629d291c5 100644
--- a/intern/mantaflow/intern/manta_pp/omp/plugin/flip.cpp
+++ b/intern/mantaflow/intern/manta_pp/omp/plugin/flip.cpp
@@ -715,6 +715,74 @@ void combineGridVel( MACGrid& vel, Grid<Vec3>& weight, MACGrid& combineVel, Leve
 	knCombineVels(vel, weight, combineVel, phi, narrowBand, thresh);
 } static PyObject* _W_17 (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, "combineGridVel" , !noTiming ); PyObject *_retval = 0; { ArgLocker _lock; MACGrid& vel = *_args.getPtr<MACGrid >("vel",0,&_lock); Grid<Vec3>& weight = *_args.getPtr<Grid<Vec3> >("weight",1,&_lock); MACGrid& combineVel = *_args.getPtr<MACGrid >("combi [...]
 
+void sampleSndParts(BasicParticleSystem& parts, FlagGrid& flags, MACGrid& vel, ParticleDataImpl<Vec3>& partVel, LevelsetGrid& phi, Real thresh, int minParticles, int maxParticles, Vec3 gravity) {
+
+	Real dt = flags.getParent()->getDt();
+	Vec3 grav = gravity * flags.getParent()->getDt() / flags.getDx();
+	Grid<int> tmp( vel.getParent() );
+	RandomStream mRand(9832);
+
+	// Delete drop particles inside fluid. Then set new position to those that survived
+	for (IndexInt idx=0; idx<(int)parts.size(); idx++) {
+		if (parts.isActive(idx)) {
+			Vec3i p = toVec3i(parts.getPos(idx));
+			if (!tmp.isInBounds(p)) {
+				parts.kill(idx); // out of domain, remove
+				continue;
+			}
+			Real phiv = phi.getInterpolated( parts.getPos(idx) );
+			if( phiv < 0 ) { parts.kill(idx); continue; }
+
+			int num = tmp(p);
+			if (num > maxParticles) {
+				parts.kill(idx);
+			} else {
+				tmp(p) = num+1;
+			}
+			
+			// This particle is valid. Set its next position
+			const Vec3 p2 = parts.getPos(idx) + partVel[idx] * dt; // euler step
+			parts.setPos(idx, p2);
+		}
+	}
+
+	// Generate new drop particles
+	FOR_IJK_BND(phi, 0) {
+		if ( flags.isObstacle(i,j,k) ) continue;
+		if ( phi(i,j,k) > 0.3f && phi(i,j,k) < 0.7f ) continue; // Only generate particles at surface
+		if ( fabs(vel(i,j,k).x) < thresh || fabs(vel(i,j,k).y) < thresh || fabs(vel(i,j,k).z) < thresh ) continue;
+
+		int cnt = tmp(i,j,k);
+		if (cnt >= minParticles) continue;
+
+		if ( flags.isFluid(i,j,k) || flags.isEmpty(i,j,k) ) {
+			Vec3 pos = Vec3(i,j,k);
+			const Vec3 pos2 = pos + vel(i,j,k) * dt; // next particle position
+			Real phiv = phi.getInterpolated(pos2);
+			
+			// Ensure that new particle is only added if its next position is valid
+			if (phiv > 0) {
+				parts.addBuffered(pos + mRand.getVec3());
+			}
+		}
+	}
+	parts.doCompress();
+	parts.insertBufferedParticles();
+
+	// Update forces: gravity and initial particle velocity
+	for (IndexInt idx=0; idx<(int)parts.size(); idx++) {
+		if (parts.isActive(idx)) {
+
+			// Initial velocity (only for new particles)
+			if (parts.getStatus(idx) & ParticleBase::PNEW) {
+				partVel[idx] = vel.getInterpolated( parts[idx].pos );
+			}
+
+			partVel[idx] += grav;
+		}
+	}
+} 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/manta_pp/omp/registration.cpp b/intern/mantaflow/intern/manta_pp/omp/registration.cpp
index a51a5a987f8..948331e25b6 100644
--- a/intern/mantaflow/intern/manta_pp/omp/registration.cpp
+++ b/intern/mantaflow/intern/manta_pp/omp/registration.cpp
@@ -67,6 +67,7 @@ extern "C" {
 		extern void PbRegister_mapMACToParts() ;
 		extern void PbRegister_flipVelocityUpdate() ;
 		extern void PbRegister_combineGridVel() ;
+		extern void PbRegister_sampleSndParts() ;
 		extern void PbRegister_processBurn() ;
 		extern void PbRegister_updateFlame() ;
 		extern void PbRegister_getSpiralVelocity2D() ;
@@ -220,6 +221,7 @@ namespace Pb {
 		PbRegister_mapMACToParts() ;
 		PbRegister_flipVelocityUpdate() ;
 		PbRegister_combineGridVel() ;
+		PbRegister_sampleSndParts() ;
 		PbRegister_processBurn() ;
 		PbRegister_updateFlame() ;
 		PbRegister_getSpiralVelocity2D() ;
diff --git a/intern/mantaflow/intern/manta_pp/tbb/plugin/flip.cpp b/intern/mantaflow/intern/manta_pp/tbb/plugin/flip.cpp
index 394f2d18c52..15b8beef970 100644
--- a/intern/mantaflow/intern/manta_pp/tbb/plugin/flip.cpp
+++ b/intern/mantaflow/intern/manta_pp/tbb/plugin/flip.cpp
@@ -596,6 +596,74 @@ void combineGridVel( MACGrid& vel, Grid<Vec3>& weight, MACGrid& combineVel, Leve
 	knCombineVels(vel, weight, combineVel, phi, narrowBand, thresh);
 } static PyObject* _W_17 (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, "combineGridVel" , !noTiming ); PyObject *_retval = 0; { ArgLocker _lock; MACGrid& vel = *_args.getPtr<MACGrid >("vel",0,&_lock); Grid<Vec3>& weight = *_args.getPtr<Grid<Vec3> >("weight",1,&_lock); MACGrid& combineVel = *_args.getPtr<MACGrid >("combi [...]
 
+void sampleSndParts(BasicParticleSystem& parts, FlagGrid& flags, MACGrid& vel, ParticleDataImpl<Vec3>& partVel, LevelsetGrid& phi, Real thresh, int minParticles, int maxParticles, Vec3 gravity) {
+
+	Real dt = flags.getParent()->getDt();
+	Vec3 grav = gravity * flags.getParent()->getDt() / flags.getDx();
+	Grid<int> tmp( vel.getParent() );
+	RandomStream mRand(9832);
+
+	// Delete drop particles inside fluid. Then set new position to those that survived
+	for (IndexInt idx=0; idx<(int)parts.size(); idx++) {
+		if (parts.isActive(idx)) {
+			Vec3i p = toVec3i(parts.getPos(idx));
+			if (!tmp.isInBounds(p)) {
+				parts.kill(idx); // out of domain, remove
+				continue;
+			}
+			Real phiv = phi.getInterpolated( parts.getPos(idx) );
+			if( phiv < 0 ) { parts.kill(idx); continue; }
+
+			int num = tmp(p);
+			if (num > maxParticles) {
+				parts.kill(idx);
+			} else {
+				tmp(p) = num+1;
+			}
+			
+			// This particle is valid. Set its next position
+			const Vec3 p2 = parts.getPos(idx) + partVel[idx] * dt; // euler step
+			parts.setPos(idx, p2);
+		}
+	}
+
+	// Generate new drop particles
+	FOR_IJK_BND(phi, 0) {
+		if ( flags.isObstacle(i,j,k) ) continue;
+		if ( phi(i,j,k) > 0.3f && phi(i,j,k) < 0.7f ) continue; // Only generate particles at surface
+		if ( fabs(vel(i,j,k).x) < thresh || fabs(vel(i,j,k).y) < thresh || fabs(vel(i,j,k).z) < thresh ) continue;
+
+		int cnt = tmp(i,j,k);
+		if (cnt >= minParticles) continue;
+
+		if ( flags.isFluid(i,j,k) || flags.isEmpty(i,j,k) ) {
+			Vec3 pos = Vec3(i,j,k);
+			const Vec3 pos2 = pos + vel(i,j,k) * dt; // next particle position
+			Real phiv = phi.getInterpolated(pos2);
+			
+			// Ensure that new particle is only added if its next position is valid
+			if (phiv > 0) {
+				parts.addBuffered(pos + mRand.getVec3());
+			}
+		}
+	}
+	parts.doCompress();
+	parts.insertBufferedParticles();
+
+	// Update forces: gravity and initial particle velocity
+	for (IndexInt idx=0; idx<(int)parts.size(); idx++) {
+		if (parts.isActive(idx)) {
+
+			// Initial velocity (only for new particles)
+			if (parts.getStatus(idx) & ParticleBase::PNEW) {
+				partVel[idx] = vel.getInterpolated( parts[idx].pos );
+			}
+
+			partVel[idx] += grav;
+		}
+	}
+} 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 >

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list