[Bf-blender-cvs] [166c3db1e79] fluid-mantaflow: added support for smoke initial velocity
Sebastián Barschkis
noreply at git.blender.org
Sat Jul 8 11:42:56 CEST 2017
Commit: 166c3db1e794793e624c7aa2082a3670ec51bbd4
Author: Sebastián Barschkis
Date: Fri Jul 7 20:03:15 2017 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB166c3db1e794793e624c7aa2082a3670ec51bbd4
added support for smoke initial velocity
===================================================================
M intern/mantaflow/extern/manta_fluid_API.h
M intern/mantaflow/intern/FLUID.cpp
M intern/mantaflow/intern/FLUID.h
M intern/mantaflow/intern/manta_fluid_API.cpp
M intern/mantaflow/intern/manta_pp/tbb/plugin/extforces.cpp
M intern/mantaflow/intern/manta_pp/tbb/registration.cpp
M intern/mantaflow/intern/strings/smoke_script.h
M source/blender/blenkernel/intern/smoke.c
===================================================================
diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 75824b3ad42..812634a9f94 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -57,6 +57,9 @@ float *smoke_get_velocity_z(struct FLUID *smoke);
float *smoke_get_ob_velocity_x(struct FLUID *fluid);
float *smoke_get_ob_velocity_y(struct FLUID *fluid);
float *smoke_get_ob_velocity_z(struct FLUID *fluid);
+float *smoke_get_in_velocity_x(struct FLUID *fluid);
+float *smoke_get_in_velocity_y(struct FLUID *fluid);
+float *smoke_get_in_velocity_z(struct FLUID *fluid);
float *smoke_get_force_x(struct FLUID *smoke);
float *smoke_get_force_y(struct FLUID *smoke);
float *smoke_get_force_z(struct FLUID *smoke);
diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index e0c8074476e..9ec24c42de8 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -87,6 +87,9 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : mCurrentID(++solverID)
mObVelocityX = NULL;
mObVelocityY = NULL;
mObVelocityZ = NULL;
+ mInVelocityX = NULL;
+ mInVelocityY = NULL;
+ mInVelocityZ = NULL;
mForceX = NULL;
mForceY = NULL;
mForceZ = NULL;
@@ -447,6 +450,9 @@ FLUID::~FLUID()
mObVelocityX = NULL;
mObVelocityY = NULL;
mObVelocityZ = NULL;
+ mInVelocityX = NULL;
+ mInVelocityY = NULL;
+ mInVelocityZ = NULL;
mForceX = NULL;
mForceY = NULL;
mForceZ = NULL;
@@ -1097,7 +1103,11 @@ void FLUID::updatePointers()
if (mUsingSmoke) {
mDensity = (float*) getDataPointer("density" + solver_ext, solver);
mInflow = (float*) getDataPointer("inflow" + solver_ext, solver);
-
+
+ mInVelocityX = (float*) getDataPointer("x_invel" + solver_ext, solver);
+ mInVelocityY = (float*) getDataPointer("y_invel" + solver_ext, solver);
+ mInVelocityZ = (float*) getDataPointer("z_invel" + solver_ext, solver);
+
if (mUsingHeat) {
mHeat = (float*) getDataPointer("heat" + solver_ext, solver);
}
diff --git a/intern/mantaflow/intern/FLUID.h b/intern/mantaflow/intern/FLUID.h
index f2887d8d9df..d6d08be28d8 100644
--- a/intern/mantaflow/intern/FLUID.h
+++ b/intern/mantaflow/intern/FLUID.h
@@ -101,6 +101,9 @@ public:
inline float* getObVelocityX() { return mObVelocityX; }
inline float* getObVelocityY() { return mObVelocityY; }
inline float* getObVelocityZ() { return mObVelocityZ; }
+ inline float* getInVelocityX() { return mInVelocityX; }
+ inline float* getInVelocityY() { return mInVelocityY; }
+ inline float* getInVelocityZ() { return mInVelocityZ; }
inline float* getForceX() { return mForceX; }
inline float* getForceY() { return mForceY; }
inline float* getForceZ() { return mForceZ; }
@@ -228,6 +231,9 @@ private:
float* mObVelocityX;
float* mObVelocityY;
float* mObVelocityZ;
+ float* mInVelocityX;
+ float* mInVelocityY;
+ float* mInVelocityZ;
float* mForceX;
float* mForceY;
float* mForceZ;
diff --git a/intern/mantaflow/intern/manta_fluid_API.cpp b/intern/mantaflow/intern/manta_fluid_API.cpp
index 8b32be6a6d7..0e6b0619f77 100644
--- a/intern/mantaflow/intern/manta_fluid_API.cpp
+++ b/intern/mantaflow/intern/manta_fluid_API.cpp
@@ -252,6 +252,21 @@ extern "C" float *smoke_get_ob_velocity_z(FLUID *fluid)
return fluid->getObVelocityZ();
}
+extern "C" float *smoke_get_in_velocity_x(FLUID *fluid)
+{
+ return fluid->getInVelocityX();
+}
+
+extern "C" float *smoke_get_in_velocity_y(FLUID *fluid)
+{
+ return fluid->getInVelocityY();
+}
+
+extern "C" float *smoke_get_in_velocity_z(FLUID *fluid)
+{
+ return fluid->getInVelocityZ();
+}
+
extern "C" float *smoke_get_force_x(FLUID *smoke)
{
return smoke->getForceX();
diff --git a/intern/mantaflow/intern/manta_pp/tbb/plugin/extforces.cpp b/intern/mantaflow/intern/manta_pp/tbb/plugin/extforces.cpp
index bb03e007399..48b2e5ffcba 100644
--- a/intern/mantaflow/intern/manta_pp/tbb/plugin/extforces.cpp
+++ b/intern/mantaflow/intern/manta_pp/tbb/plugin/extforces.cpp
@@ -33,6 +33,35 @@ using namespace std;
namespace Manta {
//! add Forces between fl/fl and fl/em cells (interpolate cell centered forces to MAC grid)
+ struct KnAddForceIfLower : public KernelBase { KnAddForceIfLower(FlagGrid& flags, MACGrid& vel, Grid<Vec3>& force) : KernelBase(&flags,1) ,flags(flags),vel(vel),force(force) { runMessage(); run(); } inline void op(int i, int j, int k, FlagGrid& flags, MACGrid& vel, Grid<Vec3>& force ) const {
+ bool curFluid = flags.isFluid(i,j,k);
+ bool curEmpty = flags.isEmpty(i,j,k);
+ if (!curFluid && !curEmpty) return;
+
+ if (flags.isFluid(i-1,j,k) || (curFluid && flags.isEmpty(i-1,j,k))) {
+ Real forceMACX = 0.5*(force(i-1,j,k).x + force(i,j,k).x);
+ Real min = std::min(vel(i,j,k).x, forceMACX);
+ Real max = std::max(vel(i,j,k).x, forceMACX);
+ Real sum = vel(i,j,k).x + forceMACX;
+ vel(i,j,k).x = (forceMACX > 0) ? std::min(sum, max) : std::max(sum, min);
+ }
+ if (flags.isFluid(i,j-1,k) || (curFluid && flags.isEmpty(i,j-1,k))) {
+ Real forceMACY = 0.5*(force(i,j-1,k).y + force(i,j,k).y);
+ Real min = std::min(vel(i,j,k).y, forceMACY);
+ Real max = std::max(vel(i,j,k).y, forceMACY);
+ Real sum = vel(i,j,k).y + forceMACY;
+ vel(i,j,k).y = (forceMACY > 0) ? std::min(sum, max) : std::max(sum, min);
+ }
+ if (vel.is3D() && (flags.isFluid(i,j,k-1) || (curFluid && flags.isEmpty(i,j,k-1)))) {
+ Real forceMACZ = 0.5*(force(i,j,k-1).z + force(i,j,k).z);
+ Real min = std::min(vel(i,j,k).z, forceMACZ);
+ Real max = std::max(vel(i,j,k).z, forceMACZ);
+ Real sum = vel(i,j,k).z + forceMACZ;
+ vel(i,j,k).z = (forceMACZ > 0) ? std::min(sum, max) : std::max(sum, min);
+ }
+} inline FlagGrid& getArg0() { return flags; } typedef FlagGrid type0;inline MACGrid& getArg1() { return vel; } typedef MACGrid type1;inline Grid<Vec3>& getArg2() { return force; } typedef Grid<Vec3> type2; void runMessage() { debMsg("Executing kernel KnAddForceIfLower ", 3); debMsg("Kernel range" << " x "<< maxX << " y "<< maxY << " z "<< minZ<<" - "<< maxZ << " " , 4); }; void operator() (const tbb::blocked_range<IndexInt>& __r) const { const int _maxX = maxX; const int _maxY [...]
+
+//! add Forces between fl/fl and fl/em cells (interpolate cell centered forces to MAC grid)
struct KnAddForceField : public KernelBase { KnAddForceField(FlagGrid& flags, MACGrid& vel, Grid<Vec3>& force) : KernelBase(&flags,1) ,flags(flags),vel(vel),force(force) { runMessage(); run(); } inline void op(int i, int j, int k, FlagGrid& flags, MACGrid& vel, Grid<Vec3>& force ) const {
bool curFluid = flags.isFluid(i,j,k);
bool curEmpty = flags.isEmpty(i,j,k);
@@ -347,6 +376,10 @@ void addForceField(FlagGrid& flags, MACGrid& vel, Grid<Vec3>& force) {
KnAddForceField(flags, vel, force);
} static PyObject* _W_7 (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, "addForceField" , !noTiming ); PyObject *_retval = 0; { ArgLocker _lock; FlagGrid& flags = *_args.getPtr<FlagGrid >("flags",0,&_lock); MACGrid& vel = *_args.getPtr<MACGrid >("vel",1,&_lock); Grid<Vec3>& force = *_args.getPtr<Grid<Vec3> >("force",2,&_l [...]
+void setInitialVelocity(FlagGrid& flags, MACGrid& vel, Grid<Vec3>& invel) {
+ KnAddForceIfLower(flags, vel, invel);
+} static PyObject* _W_8 (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, "setInitialVelocity" , !noTiming ); PyObject *_retval = 0; { ArgLocker _lock; FlagGrid& flags = *_args.getPtr<FlagGrid >("flags",0,&_lock); MACGrid& vel = *_args.getPtr<MACGrid >("vel",1,&_lock); Grid<Vec3>& invel = *_args.getPtr<Grid<Vec3> >("invel", [...]
+
} // namespace
diff --git a/intern/mantaflow/intern/manta_pp/tbb/registration.cpp b/intern/mantaflow/intern/manta_pp/tbb/registration.cpp
index 948331e25b6..4d4879a443e 100644
--- a/intern/mantaflow/intern/manta_pp/tbb/registration.cpp
+++ b/intern/mantaflow/intern/manta_pp/tbb/registration.cpp
@@ -49,6 +49,7 @@ extern "C" {
extern void PbRegister_setWallBcs() ;
extern void PbRegister_vorticityConfinement() ;
extern void PbRegister_addForceField() ;
+ extern void PbRegister_setInitialVelocity() ;
extern void PbRegister_sampleFlagsWithParticles() ;
extern void PbRegister_sampleLevelsetWithParticles() ;
extern void PbRegister_markFluidCells() ;
@@ -203,6 +204,7 @@ namespace Pb {
PbRegister_setWallBcs() ;
PbRegister_vorticityConfinement() ;
PbRegister_addForceField() ;
+ PbRegister_setInitialVelocity() ;
PbRegister_sampleFlagsWithParticles() ;
PbRegister_sampleLevelsetWithParticles() ;
PbRegister_markFluidCells() ;
d
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list