Commit: 26dca6df7898790bf17177c812fd0b772caa3a05
Author: Roman Pogribnyi
Date:   Sun Nov 9 15:39:17 2014 +0100
Branches: soc-2014-fluid
https://developer.blender.org/rB26dca6df7898790bf17177c812fd0b772caa3a05

Buoyancy in Manta using heat from Blender

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

M       intern/smoke/intern/FLUID_3D.cpp
M       intern/smoke/intern/MANTA.cpp
M       intern/smoke/intern/scenarios/smoke.h
M       source/blender/python/manta_pp/plugin/extforces.cpp

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

diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp
index f7ba1a6..c5aaae3 100644
--- a/intern/smoke/intern/FLUID_3D.cpp
+++ b/intern/smoke/intern/FLUID_3D.cpp
@@ -536,6 +536,7 @@ _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f)
        
        /* heat */
        _heat = _heatOld = _heatTemp = NULL;
+       using_heat = false;
        if (init_heat) {
                initHeat();
        }
@@ -551,7 +552,6 @@ _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f)
        _color_b = _color_bOld = _color_bTemp = NULL;
        using_colors = false;
        if (init_colors) {
-               using_colors =true;
                initColors(0.0f, 0.0f, 0.0f);
        }
        
@@ -578,18 +578,17 @@ _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f)
 void FLUID_3D::initHeat()
 {
        if (!_heat) {
-               _heat         = new float[_totalCells];
+               _heat         = NULL;
                _heatOld      = new float[_totalCells];
                _heatTemp      = new float[_totalCells];
                
                for (int x = 0; x < _totalCells; x++)
                {
-                       _heat[x]         = 0.0f;
                        _heatOld[x]      = 0.0f;
                }
                using_heat = true;
                PyGILState_STATE gilstate = PyGILState_Ensure();
-//             PyRun_SimpleString("heat_low = s.create(RealGrid)");
+               PyRun_SimpleString(smoke_init_heat_low.c_str());
                PyGILState_Release(gilstate);
                Manta_API::updatePointers(this, using_colors);
        }
@@ -627,9 +626,7 @@ FLUID_3D::~FLUID_3D()
        if (_xForce) delete[] _xForce;
        if (_yForce) delete[] _yForce;
        if (_zForce) delete[] _zForce;
-       if (_density) delete[] _density;
        if (_densityOld) delete[] _densityOld;
-       if (_heat) delete[] _heat;
        if (_heatOld) delete[] _heatOld;
        if (_obstacles) delete[] _obstacles;
        
@@ -685,8 +682,7 @@ void FLUID_3D::step(float dt, float gravity[3])
                // BLender computes heat buoyancy, not yet impl. in Manta
        Manta_API::updatePointers(this,using_colors);
        diffuseHeat();
-       addBuoyancy(_heat, _density, gravity, 0, _zRes); 
-//     SWAP_POINTERS(_heat, _heatOld);
+
        int sim_frame = 1;
        manta_write_effectors(this);
        PyGILState_STATE gilstate = PyGILState_Ensure();
diff --git a/intern/smoke/intern/MANTA.cpp b/intern/smoke/intern/MANTA.cpp
index 5de2b5e..e7202e7 100644
--- a/intern/smoke/intern/MANTA.cpp
+++ b/intern/smoke/intern/MANTA.cpp
@@ -367,7 +367,7 @@ void Manta_API::addAdaptiveGrid(void * data, string 
gridName, string solverName,
 void Manta_API::export_obstacles(float *data, int x, int y, int z)
 {
        if (data == NULL){
-               cout << "NULL passed to grid export_obstacles " << gridName 
<<endl;  return;
+               cout << "NULL passed to grid export_obstacles " <<endl;  return;
        }
        std::ostringstream stringStream;
        std::string grid_name = "obs_sdf";
@@ -460,8 +460,14 @@ std::string Manta_API::getRealValue( const std::string& 
varName, SmokeModifierDa
                ss << 0.;
        else if (varName == "BUYO_Z")
                ss << (-smd->domain->beta);
+       else if (varName == "ALPHA")
+               ss << (-smd->domain->alpha);
+       else if (varName == "BETA")
+               ss << (-smd->domain->beta);
        else if (varName == "ADVECT_ORDER")
                ss << 2;
+       else if (varName == "GRAVITY")
+               ss << "vec3(0,0,-0.981)";
        else if (varName == "ABS_FLOW")
                ss << (smd->flow->flags & 
MOD_SMOKE_FLOW_ABSOLUTE)?"True":"False";
        else if (varName == "DENSITY_MEM")
@@ -575,13 +581,18 @@ void * Manta_API::pointerFromString(const std::string& s){
 void Manta_API::updatePointers(FLUID_3D *fluid, bool updateColor)
 {
        fluid->_density = (float* )pointerFromString(getGridPointer("density", 
"s"));
-       if (updateColor){
+       if (fluid->using_colors){
                cout<< "POINTER FOR R_LOW" << fluid->_color_r<< endl;
                fluid->_color_r = (float* 
)pointerFromString(getGridPointer("color_r_low", "s"));
                cout<< "POINTER FOR R_LOW" << fluid->_color_r<< endl;
                fluid->_color_g = (float* 
)pointerFromString(getGridPointer("color_g_low", "s"));
                fluid->_color_b = (float* 
)pointerFromString(getGridPointer("color_b_low", "s"));
        }
+       if(fluid->using_heat){
+               cout<< "Updating Heat" << fluid->_heat<< endl;
+               fluid->_heat = (float* 
)pointerFromString(getGridPointer("heat_low", "s"));
+               cout<< "Updating Heat" << fluid->_heat<< endl;
+       }
 }
 
 void Manta_API::updateHighResPointers(WTURBULENCE *wt, bool updateColor)
diff --git a/intern/smoke/intern/scenarios/smoke.h 
b/intern/smoke/intern/scenarios/smoke.h
index 2fd17ef..84d5587 100644
--- a/intern/smoke/intern/scenarios/smoke.h
+++ b/intern/smoke/intern/scenarios/smoke.h
@@ -43,7 +43,8 @@ source_grid = s.create(RealGrid)\n\
 source = s.create(Mesh)\n\
 forces = s.create(MACGrid)\n\
 dict_loaded = dict()\n\
-manta_using_colors = False\n";
+manta_using_colors = False\n\
+manta_using_heat = False\n";
 
 const string smoke_setup_high = "xl_gs = vec3($HRESX$, $HRESY$, $HRESZ$) \n\
 xl = Solver(name = 'larger', gridSize = xl_gs) \n\
@@ -113,6 +114,10 @@ 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\
@@ -121,6 +126,8 @@ manta_using_colors = False";
 
 const string smoke_step_low = "def sim_step_low(t):\n\
   print ('Step:' + str(t))\n\
+  if \"abc123\" in globals():\n\
+    print (abc123)\n\
   #load_once(source,'manta_flow.obj',dict_loaded)\n\
   #if t == 2:#loading data on first sim frame only\n\
   #  print('First frame: loading flows and obstacles')\n\
@@ -130,7 +137,6 @@ const string smoke_step_low = "def sim_step_low(t):\n\
   #load emission data\n\
   #source_grid.load('manta_em_influence.uni')\n\
   #density.add(source_grid)\n\
-  addForceField(flags=flags, vel=vel,force=forces)\n\
   \n\
   if manta_using_colors:\n\
     advectSemiLagrange(flags=flags, vel=vel, grid=color_r_low, 
order=$ADVECT_ORDER$)\n\
@@ -140,7 +146,12 @@ const string smoke_step_low = "def sim_step_low(t):\n\
   advectSemiLagrange(flags=flags, vel=vel, grid=vel    , order=$ADVECT_ORDER$, 
strength=1.0)\n\
   \n\
   setWallBcs(flags=flags, vel=vel)    \n\
-  addBuoyancy(density=density, vel=vel, 
gravity=vec3($BUYO_X$,$BUYO_Y$,$BUYO_Z$), flags=flags)\n\
+      #buoyancy calculated in Blender, from _heat fields\n\
+  #addBuoyancy(density=density, vel=vel, 
gravity=vec3($BUYO_X$,$BUYO_Y$,$BUYO_Z$), flags=flags)\n\
+  if manta_using_heat:\n\
+    addHeatBuoyancy(density=density, densCoeff = $ALPHA$, vel=vel, 
gravity=$GRAVITY$, flags=flags, heat = heat_low, heatCoeff = $BETA$*10)\n\
+  #vorticityConfinement( vel=vel, flags=flags, strength=0.2 ) \n\
+  addForceField(flags=flags, vel=vel,force=forces)\n\
   \n\
   solvePressure(flags=flags, vel=vel, pressure=pressure, useResNorm=True, 
openBound='xXyYzZ')\n\
   setWallBcs(flags=flags, vel=vel)\n\
diff --git a/source/blender/python/manta_pp/plugin/extforces.cpp 
b/source/blender/python/manta_pp/plugin/extforces.cpp
index c8a4c6f..b0de81e 100644
--- a/source/blender/python/manta_pp/plugin/extforces.cpp
+++ b/source/blender/python/manta_pp/plugin/extforces.cpp
@@ -99,6 +99,18 @@ void addBuoyancy(FlagGrid& flags, Grid<Real>& density, 
MACGrid& vel, Vec3 gravit
        KnAddBuoyancy(flags,density, vel, f);
 } static PyObject* _W_2 (PyObject* _self, PyObject* _linargs, PyObject* _kwds) 
{ try { PbArgs _args(_linargs, _kwds); FluidSolver *parent = 
_args.obtainParent(); pbPreparePlugin(parent, "addBuoyancy" ); PyObject 
*_retval = 0; { ArgLocker _lock; FlagGrid& flags = *_args.getPtr<FlagGrid 
>("flags",0,&_lock); Grid<Real>& density = *_args.getPtr<Grid<Real> 
>("density",1,&_lock); MACGrid& vel = *_args.getPtr<MACGrid >("vel",2,&_lock); 
Vec3 gravity = _args.get<Vec3 >("gravity",3,&_lock);   _ret [...]
 
+//! add Buoyancy force based on density and heat field
+ struct KnAddHeatBuoyancy : public KernelBase { KnAddHeatBuoyancy(FlagGrid& 
flags, Grid<Real>& density,float densCoeff, MACGrid& vel, Vec3 strength, 
Grid<Real>& heat, float heatCoeff) :  KernelBase(&flags,1) 
,flags(flags),density(density),densCoeff(densCoeff),vel(vel),strength(strength),heat(heat),heatCoeff(heatCoeff)
   { run(); }  inline void op(int i, int j, int k, FlagGrid& flags, Grid<Real>& 
density,float densCoeff, MACGrid& vel, Vec3 strength, Grid<Real>& heat, float 
heatCoeff )  {    
+       if (!flags.isFluid(i,j,k)) return;
+       vel(i,j,k).x += (strength.x) * (densCoeff * density(i,j,k) - heatCoeff 
* heat(i,j,k));
+       vel(i,j,k).y += (strength.y) * (densCoeff * density(i,j,k) - heatCoeff 
* heat(i,j,k));
+       vel(i,j,k).z += (strength.z) * (densCoeff * density(i,j,k) - heatCoeff 
* heat(i,j,k));    
+}   inline FlagGrid& getArg0() { return flags; } typedef FlagGrid type0;inline 
Grid<Real>& getArg1() { return density; } typedef Grid<Real> type1;inline 
float& getArg2() { return densCoeff; } typedef float type2;inline MACGrid& 
getArg3() { return vel; } typedef MACGrid type3;inline Vec3& getArg4() { return 
strength; } typedef Vec3 type4;inline Grid<Real>& getArg5() { return heat; } 
typedef Grid<Real> type5;inline float& getArg6() { return heatCoeff; } typedef 
float type6; void run() {  c [...]
+//! add Buoyancy force based on density and heat field
+void addHeatBuoyancy(FlagGrid& flags, Grid<Real>& density,float densCoeff, 
MACGrid& vel, Vec3 gravity, Grid<Real>& heat, float heatCoeff) {
+       Vec3 f = - gravity;
+       KnAddHeatBuoyancy(flags,density,densCoeff, vel, f, heat, heatCoeff);
+} static PyObject* _W_3 (PyObject* _self, PyObject* _linargs, PyObject* _kwds) 
{ try { PbArgs _args(_linargs, _kwds); FluidSolver *parent = 
_args.obtainParent(); pbPreparePlugin(parent, "addHeatBuoyancy" ); PyObject 
*_retval = 0; { ArgLocker _lock; FlagGrid& flags = *_args.getPtr<FlagGrid 
>("flags",0,&_lock); Grid<Real>& density = *_args.getPtr<Grid<Real> 
>("density",1,&_lock); float densCoeff = _args.get<float 
>("densCoeff",2,&_lock);

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to