[Bf-blender-cvs] [cbda5b8] soc-2014-fluid: SMOKE: mantaflow in Fluid_3d object, running wavelets

Roman Pogribnyi noreply at git.blender.org
Tue Nov 11 23:43:11 CET 2014


Commit: cbda5b801b88e9392ec24be73ec8743dd120445f
Author: Roman Pogribnyi
Date:   Wed Nov 5 20:53:08 2014 +0100
Branches: soc-2014-fluid
https://developer.blender.org/rBcbda5b801b88e9392ec24be73ec8743dd120445f

SMOKE: mantaflow in Fluid_3d object, running wavelets

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

M	intern/smoke/extern/smoke_API.h
M	intern/smoke/intern/FLUID_3D.cpp
M	intern/smoke/intern/FLUID_3D.h
M	intern/smoke/intern/MANTA.cpp
M	intern/smoke/intern/MANTA.h
M	intern/smoke/intern/WTURBULENCE.cpp
M	intern/smoke/intern/smoke_API.cpp
M	source/blender/blenkernel/intern/smoke.c
M	source/blender/makesdna/DNA_smoke_types.h

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

diff --git a/intern/smoke/extern/smoke_API.h b/intern/smoke/extern/smoke_API.h
index 0efe035..5d921f8 100644
--- a/intern/smoke/extern/smoke_API.h
+++ b/intern/smoke/extern/smoke_API.h
@@ -36,11 +36,10 @@ extern "C" {
 #endif
 
 	
-#ifndef WITH_MANTA	/*old Blender Solver*/
 struct FLUID_3D;
 
 // low res
-struct FLUID_3D *smoke_init(int *res, float dx, float dtdef, int use_heat, int use_fire, int use_colors);
+struct FLUID_3D *smoke_init(int *res, float dx, float dtdef, int use_heat, int use_fire, int use_colors, struct SmokeModifierData *smd);
 void smoke_free(struct FLUID_3D *fluid);
 
 void smoke_initBlenderRNA(struct FLUID_3D *fluid, float *alpha, float *beta, float *dt_factor, float *vorticity, int *border_colli, float *burning_rate,
@@ -109,92 +108,11 @@ void smoke_ensure_fire(struct FLUID_3D *fluid, struct WTURBULENCE *wt);
 void smoke_ensure_colors(struct FLUID_3D *fluid, struct WTURBULENCE *wt, float init_r, float init_g, float init_b);
 
 
-	
-#else /*		using Mantaflow structures		*/
-	struct Manta_API;
-	struct Manta_API *smoke_init(int *res, float dx, float dtdef, int use_heat, int use_fire, int use_colors, struct SmokeDomainSettings *sds);
-	void smoke_free(struct Manta_API *fluid);
-	
-	void smoke_initBlenderRNA(struct Manta_API *fluid, float *alpha, float *beta, float *dt_factor, float *vorticity, int *border_colli, float *burning_rate,
-							  float *flame_smoke, float *flame_smoke_color, float *flame_vorticity, float *flame_ignition_temp, float *flame_max_temp);
-	void smoke_step(struct Manta_API *fluid, float gravity[3], float dtSubdiv);
-	
-	float *smoke_get_density(struct Manta_API *fluid);
-	float *smoke_get_flame(struct Manta_API *fluid);
-	float *smoke_get_fuel(struct Manta_API *fluid);
-	float *smoke_get_react(struct Manta_API *fluid);
-	float *smoke_get_color_r(struct Manta_API *fluid);
-	float *smoke_get_color_g(struct Manta_API *fluid);
-	float *smoke_get_color_b(struct Manta_API *fluid);
-	void smoke_get_rgba(struct Manta_API *fluid, float *data, int sequential);
-	void smoke_get_rgba_from_density(struct Manta_API *fluid, float color[3], float *data, int sequential);
-	float *smoke_get_heat(struct Manta_API *fluid);
-	float *smoke_get_velocity_x(struct Manta_API *fluid);
-	float *smoke_get_velocity_y(struct Manta_API *fluid);
-	float *smoke_get_velocity_z(struct Manta_API *fluid);
-	
-	/* Moving obstacle velocity provided by blender */
-	void smoke_get_ob_velocity(struct Manta_API *fluid, float **x, float **y, float **z);
-	
-	float *smoke_get_force_x(struct Manta_API *fluid);
-	float *smoke_get_force_y(struct Manta_API *fluid);
-	float *smoke_get_force_z(struct Manta_API *fluid);
-	
-	unsigned char *smoke_get_obstacle(struct Manta_API *fluid);
-	
-	size_t smoke_get_index(int x, int max_x, int y, int max_y, int z);
-	size_t smoke_get_index2d(int x, int max_x, int y);
-	
-	void smoke_dissolve(struct Manta_API *fluid, int speed, int log);
-	
-	// wavelet turbulence functions
-	struct WTURBULENCE *smoke_turbulence_init(int *res, int amplify, int noisetype, const char *noisefile_path, int use_fire, int use_colors,struct SmokeDomainSettings *sds);
-	void smoke_turbulence_free(struct WTURBULENCE *wt);
-	void smoke_turbulence_step(struct WTURBULENCE *wt, struct Manta_API *fluid);
-	
-	float *smoke_turbulence_get_density(struct WTURBULENCE *wt);
-	float *smoke_turbulence_get_color_r(struct WTURBULENCE *wt);
-	float *smoke_turbulence_get_color_g(struct WTURBULENCE *wt);
-	float *smoke_turbulence_get_color_b(struct WTURBULENCE *wt);
-	void smoke_turbulence_get_rgba(struct WTURBULENCE *wt, float *data, int sequential);
-	void smoke_turbulence_get_rgba_from_density(struct WTURBULENCE *wt, float color[3], float *data, int sequential);
-	float *smoke_turbulence_get_flame(struct WTURBULENCE *wt);
-	float *smoke_turbulence_get_fuel(struct WTURBULENCE *wt);
-	float *smoke_turbulence_get_react(struct WTURBULENCE *wt);
-	void smoke_turbulence_get_res(struct WTURBULENCE *wt, int *res);
-	int smoke_turbulence_get_cells(struct WTURBULENCE *wt);
-	void smoke_turbulence_set_noise(struct WTURBULENCE *wt, int type, const char *noisefile_path);
-	void smoke_initWaveletBlenderRNA(struct WTURBULENCE *wt, float *strength);
-	void smoke_dissolve_wavelet(struct WTURBULENCE *wt, int speed, int log);
-	
-	/* export */
-	void smoke_export(struct Manta_API *fluid, float *dt, float *dx, float **dens, float **react, float **flame, float **fuel, float **heat, float **heatold,
-					  float **vx, float **vy, float **vz, float **r, float **g, float **b, unsigned char **obstacles);
-	void smoke_turbulence_export(struct WTURBULENCE *wt, float **dens, float **react, float **flame, float **fuel,
-								 float **r, float **g, float **b, float **tcu, float **tcv, float **tcw);
-	
-	/* flame spectrum */
-	void flame_get_spectrum(unsigned char *spec, int width, float t1, float t2);
-	
-	/* data fields */
-	int smoke_has_heat(struct Manta_API *fluid);
-	int smoke_has_fuel(struct Manta_API *fluid);
-	int smoke_has_colors(struct Manta_API *fluid);
-	int smoke_turbulence_has_fuel(struct WTURBULENCE *wt);
-	int smoke_turbulence_has_colors(struct WTURBULENCE *wt);
-	
-	void smoke_ensure_heat(struct Manta_API *fluid);
-	void smoke_ensure_fire(struct Manta_API *fluid, struct WTURBULENCE *wt);
-	void smoke_ensure_colors(struct Manta_API *fluid, struct WTURBULENCE *wt, float init_r, float init_g, float init_b);
-#endif /*WITH_MANTA*/
-	
-/*Mantaflow functions*/
+	/*Mantaflow functions*/
 int smoke_mantaflow_read(struct SmokeDomainSettings *sds, char* name, bool with_wavelets); //1:success, 0: no file,error
-void smoke_mantaflow_write_scene_file(struct SmokeModifierData *smd);
-void smoke_mantaflow_sim_step(struct Manta_API *fluid);
 //void smoke_mantaflow_sim_step(struct Scene *scene, struct SmokeModifierData *smd);
 void smoke_mantaflow_stop_sim(struct Manta_API *fluid);
-void manta_write_effectors(struct Manta_API *fluid);
+void manta_write_effectors(struct FLUID_3D *fluid);
 void manta_update_effectors(struct Scene *scene, struct Object *ob,struct SmokeDomainSettings *sds, float dt);
 void manta_write_emitters(struct SmokeFlowSettings *sfs, bool highRes, int min_x, int min_y, int min_z, int max_x, int max_y, int max_z, int d_x, int d_y, int d_z,float *influence, float *vel);	
 void manta_export_obstacles(float * influence, int x, int y, int z);
diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp
index a43d94a..c7e03d6 100644
--- a/intern/smoke/intern/FLUID_3D.cpp
+++ b/intern/smoke/intern/FLUID_3D.cpp
@@ -35,11 +35,14 @@
 #include <zlib.h>
 
 #include "float.h"
+#include "MANTA.h"
+#include "scenarios/smoke.h"
 
 #if PARALLEL==1
 #include <omp.h>
 #endif // PARALLEL 
 
+#ifndef WITH_MANTA
 //////////////////////////////////////////////////////////////////////
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
@@ -1641,3 +1644,310 @@ void FLUID_3D::processBurn(float *fuel, float *smoke, float *react, float *flame
 		}
 	}
 }
+/*===============================================================================================*/
+/*===============================================================================================*/
+#else /*USING MANTAFLOW STRUCTURES*/
+/*===============================================================================================*/
+/*===============================================================================================*/
+
+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      = new float[_totalCells];
+	_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++)
+	{
+		_density[x]      = 0.0f;
+		_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;
+	}
+	
+	/* heat */
+	_heat = _heatOld = _heatTemp = NULL;
+	if (init_heat) {
+		initHeat();
+	}
+	// 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;
+	_

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list