Commit: 15ba8ec5af90aea5e3ace6cafb68e0ac8a15cd8b
Author: Roman Pogribnyi
Date:   Sun Nov 9 14:38:01 2014 +0100
Branches: soc-2014-fluid
https://developer.blender.org/rB15ba8ec5af90aea5e3ace6cafb68e0ac8a15cd8b

shrinking Fluid_3d class

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

M       intern/smoke/intern/FLUID_3D.cpp
M       intern/smoke/intern/FLUID_3D.h

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

diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp
index 5dcf781..f7ba1a6 100644
--- a/intern/smoke/intern/FLUID_3D.cpp
+++ b/intern/smoke/intern/FLUID_3D.cpp
@@ -170,30 +170,6 @@ void FLUID_3D::initHeat()
        }
 }
 
-void FLUID_3D::initFire()
-{
-       if (!_flame) {
-               _flame          = new float[_totalCells];
-               _fuel           = new float[_totalCells];
-               _fuelTemp       = new float[_totalCells];
-               _fuelOld        = new float[_totalCells];
-               _react          = new float[_totalCells];
-               _reactTemp      = new float[_totalCells];
-               _reactOld       = new float[_totalCells];
-
-               for (int x = 0; x < _totalCells; x++)
-               {
-                       _flame[x]               = 0.0f;
-                       _fuel[x]                = 0.0f;
-                       _fuelTemp[x]    = 0.0f;
-                       _fuelOld[x]             = 0.0f;
-                       _react[x]               = 0.0f;
-                       _reactTemp[x]   = 0.0f;
-                       _reactOld[x]    = 0.0f;
-               }
-       }
-}
-
 void FLUID_3D::initColors(float init_r, float init_g, float init_b)
 {
        if (!_color_r) {
@@ -219,47 +195,6 @@ void FLUID_3D::initColors(float init_r, float init_g, 
float init_b)
        }
 }
 
-void FLUID_3D::setBorderObstacles()
-{
-       
-       // set side obstacles
-       unsigned int index;
-       for (int y = 0; y < _yRes; y++)
-       for (int x = 0; x < _xRes; x++)
-       {
-               // bottom slab
-               index = x + y * _xRes;
-               if(_domainBcBottom) _obstacles[index] = 1;
-
-               // top slab
-               index += _totalCells - _slabSize;
-               if(_domainBcTop) _obstacles[index] = 1;
-       }
-
-       for (int z = 0; z < _zRes; z++)
-       for (int x = 0; x < _xRes; x++)
-       {
-               // front slab
-               index = x + z * _slabSize;
-               if(_domainBcFront) _obstacles[index] = 1;
-
-               // back slab
-               index += _slabSize - _xRes;
-               if(_domainBcBack) _obstacles[index] = 1;
-       }
-
-       for (int z = 0; z < _zRes; z++)
-       for (int y = 0; y < _yRes; y++)
-       {
-               // left slab
-               index = y * _xRes + z * _slabSize;
-               if(_domainBcLeft) _obstacles[index] = 1;
-
-               // right slab
-               index += _xRes - 1;
-               if(_domainBcRight) _obstacles[index] = 1;
-       }
-}
 
 FLUID_3D::~FLUID_3D()
 {
@@ -517,173 +452,495 @@ void FLUID_3D::step(float dt, float gravity[3])
 
 }
 
+/*===============================================================================================*/
+/*===============================================================================================*/
+#else /*USING MANTAFLOW STRUCTURES*/
+/*===============================================================================================*/
+/*===============================================================================================*/
 
-// Set border collision model from RNA setting
-
-void FLUID_3D::setBorderCollisions() {
-
-
-       _colloPrev = *_borderColli;             // saving the current value
-
-       // boundary conditions of the fluid domain
-       if (_colloPrev == 0)
+FLUID_3D::FLUID_3D(int *res, float dx, float dtdef, int init_heat, int 
init_fire, int init_colors, SmokeModifierData *smd) :
+_xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f)
+{
+       // set simulation consts
+       _dt = dtdef;    // just in case. set in step from a RNA factor
+       
+       _iterations = 100;
+       _tempAmb = 0; 
+       _heatDiffusion = 1e-3;
+       _totalTime = 0.0f;
+       _totalSteps = 0;
+       _res = Vec3Int(_xRes,_yRes,_zRes);
+       _maxRes = MAX3(_xRes, _yRes, _zRes);
+       
+       // initialize wavelet turbulence
+       /*
+        if(amplify)
+        _wTurbulence = new WTURBULENCE(_res[0],_res[1],_res[2], amplify, 
noisetype);
+        else
+        _wTurbulence = NULL;
+        */
+       
+       // scale the constants according to the refinement of the grid
+       if (!dx)
+               _dx = 1.0f / (float)_maxRes;
+       else
+               _dx = dx;
+       _constantScaling = 64.0f / _maxRes;
+       _constantScaling = (_constantScaling < 1.0f) ? 1.0f : _constantScaling;
+       _vorticityEps = 2.0f / _constantScaling; // Just in case set a default 
value
+       
+       // allocate arrays
+       _totalCells   = _xRes * _yRes * _zRes;
+       _slabSize = _xRes * _yRes;
+       _xVelocity    = new float[_totalCells];
+       _yVelocity    = new float[_totalCells];
+       _zVelocity    = new float[_totalCells];
+       _xVelocityOb  = new float[_totalCells];
+       _yVelocityOb  = new float[_totalCells];
+       _zVelocityOb  = new float[_totalCells];
+       _xVelocityOld = new float[_totalCells];
+       _yVelocityOld = new float[_totalCells];
+       _zVelocityOld = new float[_totalCells];
+       _xForce       = new float[_totalCells];
+       _yForce       = new float[_totalCells];
+       _zForce       = new float[_totalCells];
+       _density      = NULL;
+       _densityOld   = new float[_totalCells];
+       _obstacles    = new unsigned char[_totalCells]; // set 0 at end of step
+       
+       // For threaded version:
+       _xVelocityTemp = new float[_totalCells];
+       _yVelocityTemp = new float[_totalCells];
+       _zVelocityTemp = new float[_totalCells];
+       _densityTemp   = new float[_totalCells];
+       
+       // DG TODO: check if alloc went fine
+       
+       for (int x = 0; x < _totalCells; x++)
        {
-               // No collisions
-               _domainBcFront = false;
-               _domainBcTop = false;
-               _domainBcLeft = false;
+               _densityOld[x]   = 0.0f;
+               _xVelocity[x]    = 0.0f;
+               _yVelocity[x]    = 0.0f;
+               _zVelocity[x]    = 0.0f;
+               _xVelocityOb[x]  = 0.0f;
+               _yVelocityOb[x]  = 0.0f;
+               _zVelocityOb[x]  = 0.0f;
+               _xVelocityOld[x] = 0.0f;
+               _yVelocityOld[x] = 0.0f;
+               _zVelocityOld[x] = 0.0f;
+               _xForce[x]       = 0.0f;
+               _yForce[x]       = 0.0f;
+               _zForce[x]       = 0.0f;
+               _obstacles[x]    = false;
        }
-       else if (_colloPrev == 2)
-       {
-               // Collide with all sides
-               _domainBcFront = true;
-               _domainBcTop = true;
-               _domainBcLeft = true;
+       
+       /* heat */
+       _heat = _heatOld = _heatTemp = NULL;
+       if (init_heat) {
+               initHeat();
        }
-       else
-       {
-               // Default values: Collide with "walls", but not top and bottom
-               _domainBcFront = true;
-               _domainBcTop = false;
-               _domainBcLeft = true;
+       // Fire simulation
+       _flame = _fuel = _fuelTemp = _fuelOld = NULL;
+       _react = _reactTemp = _reactOld = NULL;
+       if (init_fire) {
+               initFire();
        }
-
+       // Smoke color
+       _color_r = _color_rOld = _color_rTemp = NULL;
+       _color_g = _color_gOld = _color_gTemp = NULL;
+       _color_b = _color_bOld = _color_bTemp = NULL;
+       using_colors = false;
+       if (init_colors) {
+               using_colors =true;
+               initColors(0.0f, 0.0f, 0.0f);
+       }
+       
+       // boundary conditions of the fluid domain
+       // set default values -> vertically non-colliding
+       _domainBcFront = true;
+       _domainBcTop = false;
+       _domainBcLeft = true;
        _domainBcBack = _domainBcFront;
        _domainBcBottom = _domainBcTop;
        _domainBcRight  = _domainBcLeft;
-
-
-
-       // set side obstacles
-       setBorderObstacles();
+       
+       _colloPrev = 1; // default value
+       
+       string smoke_script = smoke_setup_low  + smoke_step_low;
+       smd->domain->fluid = this;
+       std::string final_script = Manta_API::parseScript(smoke_script, smd);
+       vector<string> a;
+       a.push_back("manta_scene.py");
+       runMantaScript(final_script,a); /*need this to delete previous solvers 
and grids*/
+       Manta_API::updatePointers(this, using_colors);
 }
 
-//////////////////////////////////////////////////////////////////////
-// helper function to dampen co-located grid artifacts of given arrays in 
intervals
-// (only needed for velocity, strength (w) depends on testcase...
-//////////////////////////////////////////////////////////////////////
-
-
-void FLUID_3D::artificialDampingSL(int zBegin, int zEnd) {
-       const float w = 0.9;
-
-       memmove(_xForce+(_slabSize*zBegin), _xVelocityTemp+(_slabSize*zBegin), 
sizeof(float)*_slabSize*(zEnd-zBegin));
-       memmove(_yForce+(_slabSize*zBegin), _yVelocityTemp+(_slabSize*zBegin), 
sizeof(float)*_slabSize*(zEnd-zBegin));
-       memmove(_zForce+(_slabSize*zBegin), _zVelocityTemp+(_slabSize*zBegin), 
sizeof(float)*_slabSize*(zEnd-zBegin));
-
-
-       if(_totalSteps % 4 == 1) {
-               for (int z = zBegin+1; z < zEnd-1; z++)
-                       for (int y = 1; y < _res[1]-1; y++)
-                               for (int x = 1+(y+z)%2; x < _res[0]-1; x+=2) {
-                                       const int index = x + y*_res[0] + z * 
_slabSize;
-                                       _xForce[index] = 
(1-w)*_xVelocityTemp[index] + 1.0f/6.0f * w*(
-                                                       _xVelocityTemp[index+1] 
+ _xVelocityTemp[index-1] +
-                                                       
_xVelocityTemp[index+_res[0]] + _xVelocityTemp[index-_res[0]] +
-                                                       
_xVelocityTemp[index+_slabSize] + _xVelocityTemp[index-_slabSize] );
-
-                                       _yForce[index] = 
(1-w)*_yVelocityTemp[index] + 1.0f/6.0f * w*(
-                                                       _yVelocityTemp[index+1] 
+ _yVelocityTemp[index-1] +
-                                                       
_yVelocityTemp[index+_res[0]] + _yVelocityTemp[index-_res[0]] +
-                                                       
_yVelocityTemp[index+_slabSize] + _yVelocityTemp[index-_slabSize] );
-
-                                       _zForce[index] = 
(1-w)*_zVelocityTemp[index] + 1.0f/6.0f * w*(
-                                                       _zVelocityTemp[index+1] 
+ _zVelocityTemp[index-1] +
-                                                       
_zVelocityTemp[index+_res[0]] + _zVelocityTemp[index-_res[0]] +
-                                                       
_zVelocityTemp[index+_slabSize] + _zVelocityTemp[index-_slabSize] );
-                               }
+void FLUID_3D::initHeat()
+{
+       if (!_heat) {
+               _heat         = new float[_totalCells];
+               _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)");
+               PyGILState_Release(gilstate);
+               Manta_API::updatePointers(this, using_colors);
        }
+}
 
-       if(_totalSteps % 4 == 3) {
-               for (int z = zBegin+1; z < zEnd-1; z++)
-                       for (int y = 1; y < _res[1]-1; y++)
-                               for (int x = 1+(y+z+1)%2; x < _res[0]-1; x+=2) {
-                                       const int index = x + y*_res[0] + z * 
_slabSize;
-                                       _xForce[index] = 
(1-w)*_xVelocityTemp[index] + 1.0f/6.0f * w*(
-                                                       _xVelocityTemp[index+1] 
+ _xVelocityTemp[index-1] +
-                                                       
_xVelocityTemp[index+_res[0]] + _xVelocityTemp[index-_res[0]] +
-                                                       
_xVelocityTemp[index+_slabSize] + _xVelocityTemp[index-_slabSize] );
-
-                                       _yForce[index] = 
(1-w)*_yVelocityTemp[index] + 1.0f/6.0f * w*(
-                                                       _yVelocityTemp[index+1] 
+ _yVelocityTemp[index-1] +
-                                                       
_yVelocityTemp[index+_res[0]] + _yVelocityTemp[index-_res[0]] +
-                                                       
_yVelocityTemp[index+_slabSize] + _yVelocityTemp[index-_slabSize] );
-
-                                       _zForce[index] = 
(1-w)*_zVelocityTemp[index] + 1.0f/6.0f * w*(
-                                                       _zVelocityTemp[index+1] 
+ _zVelocityTemp[index-1] +
-                                                       
_zVelocityTemp[index+_res[0]] + _zVelocityTemp[index-_res[0]] +
-                                                       
_zVelocityTemp[index+_slabSize] + _zVelocityTemp[index-_slabSize] );
-                               }
 
+void FLUID_3D::initColors(float init_r, float init_g, float init_b)
+{
+       if (!_color_r){
+               using_colors = true;
+               PyGILState_STATE gilstate = PyGILState_Ensure();
+               stringstream ss;
+               ss << "manta_color_r = " << init_r << endl;


@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to