[Bf-blender-cvs] [d607c2a] soc-2014-fluid: manta scene file location, work on 2D smoke

Roman Pogribnyi noreply at git.blender.org
Sun Feb 1 23:59:27 CET 2015


Commit: d607c2a59822b9bcbcb03a5b1b156d1f75ac95f0
Author: Roman Pogribnyi
Date:   Tue Jan 27 23:24:16 2015 +0100
Branches: soc-2014-fluid
https://developer.blender.org/rBd607c2a59822b9bcbcb03a5b1b156d1f75ac95f0

manta scene file location, work on 2D smoke

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

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/scenarios/smoke.h
M	intern/smoke/intern/smoke_API.cpp
M	release/scripts/startup/bl_ui/properties_physics_smoke.py
M	source/blender/blenkernel/intern/smoke.c
M	source/blender/makesdna/DNA_smoke_types.h
M	source/blender/makesrna/intern/rna_smoke.c

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

diff --git a/intern/smoke/extern/smoke_API.h b/intern/smoke/extern/smoke_API.h
index a1ac22a..2229201 100644
--- a/intern/smoke/extern/smoke_API.h
+++ b/intern/smoke/extern/smoke_API.h
@@ -68,6 +68,9 @@ float *smoke_get_force_y(struct FLUID_3D *fluid);
 float *smoke_get_force_z(struct FLUID_3D *fluid);
 	
 int *smoke_get_manta_flags(struct FLUID_3D *fluid);
+float *smoke_get_inflow_grid(struct FLUID_3D *fluid);
+void smoke_manta_export(struct SmokeModifierData *smd);
+
 unsigned char *smoke_get_obstacle(struct FLUID_3D *fluid);
 
 size_t smoke_get_index(int x, int max_x, int y, int max_y, int z);
diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp
index b647b16..8bc9077 100644
--- a/intern/smoke/intern/FLUID_3D.cpp
+++ b/intern/smoke/intern/FLUID_3D.cpp
@@ -505,7 +505,19 @@ _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f)
 	_xForce       = new float[_totalCells];
 	_yForce       = new float[_totalCells];
 	_zForce       = new float[_totalCells];
-	_density      = NULL;
+	/*if two-dimentional, insert manta sim into blender _density field */
+	if (smd->domain->manta_solver_res == 2){
+		_density  = new float[_totalCells];
+		_manta_flags = new int[_totalCells];
+		manta_resoution = 2;
+		_yLocation = _yRes / 2;
+	}
+	else{
+		_density  = NULL;
+		_manta_flags = NULL;
+		manta_resoution = 3;
+		_yLocation = -1;
+	}
 	_manta_inflow = NULL;
 	_densityOld   = new float[_totalCells];
 	_obstacles    = new unsigned char[_totalCells]; // set 0 at end of step
@@ -517,7 +529,6 @@ _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f)
 	_densityTemp   = new float[_totalCells];
 	
 	//initializing manta flag grids
-	_manta_flags = NULL;
 	// DG TODO: check if alloc went fine
 	
 	for (int x = 0; x < _totalCells; x++)
@@ -578,6 +589,7 @@ _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f)
 	smd->domain->fluid = this;
 	std::string final_script = Manta_API::parseScript(smoke_script, smd);
 	ofstream myfile;
+	cout<< "INITIALIZING SMOKE" << endl;
 	myfile.open ("manta_scene.py");
 	myfile << final_script;
 	myfile.close();
diff --git a/intern/smoke/intern/FLUID_3D.h b/intern/smoke/intern/FLUID_3D.h
index 2366a2c..df192c7 100644
--- a/intern/smoke/intern/FLUID_3D.h
+++ b/intern/smoke/intern/FLUID_3D.h
@@ -114,6 +114,8 @@ struct FLUID_3D
 		unsigned char*  _obstaclesAnim;
 		float* _manta_inflow;
 		bool using_heat;
+		int manta_resoution;
+		int _yLocation;/*at which Y-coordinate store the information*/
 
 		// Required for proper threading:
 		float* _xVelocityTemp;
diff --git a/intern/smoke/intern/MANTA.cpp b/intern/smoke/intern/MANTA.cpp
index b1d4553..75c5abf 100644
--- a/intern/smoke/intern/MANTA.cpp
+++ b/intern/smoke/intern/MANTA.cpp
@@ -288,6 +288,7 @@ string Manta_API::gridNameFromType(const string &type)
 void Manta_API::addGrid(void * data, string name, string type, int x, int y, int z)
 {
 	if (data == NULL || name == "" || gridNameFromType(type) == "") return;
+	cout << "Adding Grid:" << name<<endl; 
 	std::ostringstream stringStream;
 	stringStream << "temp_" << name;
 	std::string grid_name = stringStream.str();
@@ -295,6 +296,7 @@ void Manta_API::addGrid(void * data, string name, string type, int x, int y, int
 	stringStream << grid_name << " = s.create(" << gridNameFromType(type) << ")";
 	const std::string command_1 = stringStream.str();
 	stringStream.str("");
+
 	stringStream << grid_name << ".readGridFromMemory(\'"<< data << "\', " << x << "," << y << "," << z << ")";
 	const std::string command_2 = stringStream.str();
 	const std::string command_3 = name + ".add(" + grid_name + ")";
@@ -343,6 +345,7 @@ void Manta_API::export_obstacles(float *data, int x, int y, int z)
 	stringStream << grid_name << " = s.create(RealGrid)";
 	const std::string command_1 = stringStream.str();
 	stringStream.str("");
+	cout<<"Exporting obstacles"<<endl;
 	stringStream << grid_name << ".readGridFromMemory(\'"<< data << "\', " << x << "," << y << "," << z << ")";
 	const std::string command_2 = stringStream.str();
 	const std::string command_3 = grid_name + ".applyToGrid(grid = flags, value = FlagObstacle)";
@@ -434,13 +437,24 @@ std::string Manta_API::getRealValue( const std::string& varName, SmokeModifierDa
 		ss << (-smd->domain->beta);
 	else if (varName == "ADVECT_ORDER")
 		ss << 2;
+	else if (varName == "MANTA_EXPORT_PATH"){
+		char parent_dir[1024];
+		BLI_split_dir_part(smd->domain->_manta_filepath, parent_dir, sizeof(parent_dir));
+		ss << parent_dir;
+	}
 	else if (varName == "VORTICITY"){
 		cout << "Vorticity :" << smd->domain->vorticity / smd->domain->fluid->_constantScaling << endl;	
 		ss << smd->domain->vorticity / smd->domain->fluid->_constantScaling;
 	}else if (varName == "BOUNDCONDITIONS"){
-		if(smd->domain->border_collisions == SM_BORDER_OPEN) ss << "xXyYz";
-		else if (smd->domain->border_collisions == SM_BORDER_VERTICAL) ss << "xXyYz";
-		else if (smd->domain->border_collisions == SM_BORDER_CLOSED) ss << "xXyYzZ";
+		if(smd->domain->border_collisions == SM_BORDER_OPEN) ss << "xXyY";
+		else if (smd->domain->border_collisions == SM_BORDER_VERTICAL) ss << "xXyY";
+		else if (smd->domain->border_collisions == SM_BORDER_CLOSED) ss << "xXyY";
+		
+		if (smd->domain->manta_solver_res == 3){
+			if(smd->domain->border_collisions == SM_BORDER_OPEN) ss << "z";
+			else if (smd->domain->border_collisions == SM_BORDER_VERTICAL) ss << "z";
+			else if (smd->domain->border_collisions == SM_BORDER_CLOSED) ss << "zZ";
+		}
 	}
 	else if (varName == "GRAVITY")
 		ss << "vec3(0,0,-0.981)";
@@ -502,12 +516,12 @@ void Manta_API::manta_export_grids(SmokeModifierData *smd){
 		smoke_script = smoke_setup_low  + smoke_step_low;
 	std::string final_script = Manta_API::parseScript(smoke_script, smd) + standalone;
 	ofstream myfile;
-	myfile.open ("manta_scene.py");
+	myfile.open (smd->domain->_manta_filepath);
 	myfile << final_script;
 	myfile.close();
 	
 	PyGILState_STATE gilstate = PyGILState_Ensure();
-	PyRun_SimpleString(smoke_export_low.c_str());
+	PyRun_SimpleString(Manta_API::parseScript(smoke_export_low,smd).c_str());
 	PyGILState_Release(gilstate);
 }
 
@@ -562,9 +576,36 @@ void * Manta_API::pointerFromString(const std::string& s){
 
 void Manta_API::updatePointers(FLUID_3D *fluid, bool updateColor)
 {
-	fluid->_density = (float* )pointerFromString(getGridPointer("density", "s"));
-	fluid->_manta_flags = (int* )pointerFromString(getGridPointer("flags", "s"));
+	/*in 2D case, we want to copy in the Z-axis field that is in the middle of X and Y axes */
+	//x + y * max_x + z * max_x*max_y
+//	int position_to_copy_from(0 + (fluid->xRes()/2) * fluid->xRes() + (fluid->zRes()/2) * fluid->xRes()*fluid->yRes());
+//	float *whereToCopy = &fluid->_density[position_to_copy_from]; 
+	if (fluid->manta_resoution == 2)
+	{
+		float* manta_fluid_density = (float* )pointerFromString(getGridPointer("density", "s")); 
+		int* manta_fluid_flags = (int* )pointerFromString(getGridPointer("flags", "s"));
+		if (fluid->_density != NULL){
+			for (int cnt(0); cnt < fluid->xRes() * fluid->yRes() * fluid->zRes(); ++cnt){
+				fluid->_density[cnt] = 0.;
+				fluid->_manta_flags[cnt] = 2;
+			}
+		}
+		int step = 0;
+		for (int cnt(0); cnt < fluid->xRes() * fluid->zRes()-1; ++cnt){
+			assert(fluid->_yLocation != -1);
+			step = (fluid->_yLocation) + cnt * fluid->yRes();
+			fluid->_density[step] = manta_fluid_density[cnt];
+			fluid->_manta_flags[step] = manta_fluid_flags[cnt];
+		}		
+	}
+	else{
+		fluid->_density = (float* )pointerFromString(getGridPointer("density", "s"));	
+		fluid->_manta_flags = (int* )pointerFromString(getGridPointer("flags", "s"));
+	}
+//	fluid->_density = (float* )pointerFromString(getGridPointer("density", "s"));
+	
 	fluid->_manta_inflow = (float* )pointerFromString(getGridPointer("inflow_grid", "s"));
+	if (fluid-> manta_resoution == 2){return;}
 	if (fluid->using_colors){
 		cout<< "POINTER FOR R_LOW" << fluid->_color_r<< endl;
 		fluid->_color_r = (float* )pointerFromString(getGridPointer("color_r_low", "s"));
diff --git a/intern/smoke/intern/scenarios/smoke.h b/intern/smoke/intern/scenarios/smoke.h
index 10bce98..37835a6 100644
--- a/intern/smoke/intern/scenarios/smoke.h
+++ b/intern/smoke/intern/scenarios/smoke.h
@@ -15,8 +15,12 @@ def load_once(grid, file, dict):\n\
     dict[grid] = 1\n\
 # solver params\n\
 res = $RES$\n\
+solver_dim = $SOLVER_DIM$\n\
 gs = vec3($RESX$,$RESY$,$RESZ$)\n\
-s = FluidSolver(name='main', gridSize = gs)\n\
+boundConditions = '$BOUNDCONDITIONS$'\n\
+if solver_dim == 2:\n\
+  gs.z = 1\n\
+s = FluidSolver(name='main', gridSize = gs, dim = $SOLVER_DIM$)\n\
 s.timestep = 0.1\n\
 timings = Timings()\n\
 \n\
@@ -124,10 +128,11 @@ del color_b_high \n\
 manta_using_colors = False";
 
 const string smoke_export_low = "\n\
-density.save('density.uni')\n\
-flags.save('flags.uni')\n\
-inflow_grid.save('inflow.uni')\n\
-forces.save('forces.uni')\n\
+import os\n\
+density.save(os.path.join('$MANTA_EXPORT_PATH$','density.uni'))\n\
+flags.save(os.path.join('$MANTA_EXPORT_PATH$','flags.uni'))\n\
+inflow_grid.save(os.path.join('$MANTA_EXPORT_PATH$','inflow.uni'))\n\
+forces.save(os.path.join('$MANTA_EXPORT_PATH$','forces.uni'))\n\
 print('Grids exported')";
 
 const string standalone = "\
@@ -148,6 +153,8 @@ const string smoke_step_low = "def sim_step_low(t, standalone = False):\n\
     inflow_grid.load('inflow.uni')\n\
     inflow_grid.multConst(0.1)\n\
     density.add(inflow_grid)\n\
+  elif solver_dim == 2:\n\
+    density.add(inflow_grid)\n\
   if manta_using_heat:\n\
     addHeatBuoyancy(density=density, densCoeff = 0.001, vel=vel, gravity=vec3(0,0,-0.981), flags=flags, heat = heat_low, heatCoeff = -0.1*10)\n\
   else:\n\
@@ -156,15 +163,22 @@ const string smoke_step_low = "def sim_step_low(t, standalone = False):\n\
     advectSemiLagrange(flags=flags, vel=vel, grid=color_r_low, order=$ADVECT_ORDER$)\n\
     advectSemiLagrange(flags=flags, vel=vel, grid=color_g_low, order=$ADVECT_ORDER$)\n\
     advectSemiLagrange(flags=flags, vel=vel, grid=color_b_low, order=$ADVECT_ORDER$)\n\
+  print ('Advecting density')\n\
   advectSemiLagrange(flags=flags, vel=vel, grid=density, order=$ADVECT_ORDER$)\n\
+  print ('Advecting velocity')\n\
   advectSemiLagrange(flags=flags, vel=vel, grid=vel    , or

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list