[Bf-blender-cvs] [6cfc411] fluid-mantaflow: refactoring fluid_3d constructor setup

Sebastián Barschkis noreply at git.blender.org
Thu Jan 28 12:36:48 CET 2016


Commit: 6cfc4110cdd7066b823d1bd240f06f387d531f3b
Author: Sebastián Barschkis
Date:   Sat Sep 19 20:28:09 2015 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB6cfc4110cdd7066b823d1bd240f06f387d531f3b

refactoring fluid_3d constructor setup

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

M	intern/smoke/intern/FLUID_3D.cpp
M	intern/smoke/intern/MANTA.cpp
M	intern/smoke/intern/MANTA.h
M	intern/smoke/intern/WTURBULENCE.cpp
M	source/blender/python/manta_pp/pwrapper/pymain.cpp

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

diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp
index 247b8dd..80b778c 100644
--- a/intern/smoke/intern/FLUID_3D.cpp
+++ b/intern/smoke/intern/FLUID_3D.cpp
@@ -654,22 +654,12 @@ _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f)
 	
 	_colloPrev = 1;	// default value
 	
-	string smoke_script = "";
-	if (smd->domain->flags & MOD_SMOKE_MANTA_USE_LIQUID)
-		smoke_script = smoke_setup_low  + liquid_step_low;
-	else
-		smoke_script = smoke_setup_low  + smoke_step_low;
-	
 	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();
-	vector<string> a;
-	a.push_back("manta_scene.py");
-	runMantaScript(final_script,a); /*need this to delete previous solvers and grids*/
+	vector<string> args;
+	args.push_back("manta_scene.py");
+	initializeMantaflow(args); /*need this to delete previous solvers and grids*/
+	
+	Manta_API::run_manta_sim_file_lowRes(smd);
 	Manta_API::updatePointers(this);
 }
 
diff --git a/intern/smoke/intern/MANTA.cpp b/intern/smoke/intern/MANTA.cpp
index 84a421e..f65f8d4 100644
--- a/intern/smoke/intern/MANTA.cpp
+++ b/intern/smoke/intern/MANTA.cpp
@@ -396,7 +396,22 @@ void Manta_API::run_manta_sim_highRes(WTURBULENCE *wt)
 	updateHighResPointers(wt/*,false*/);
 }
 
-void Manta_API::generate_manta_sim_file_highRes(SmokeModifierData *smd)
+void Manta_API::run_manta_sim_file_lowRes(SmokeModifierData *smd)
+{
+	// Get either liquid or smoke setup string
+	string smoke_script = "";
+	if (smd->domain->flags & MOD_SMOKE_MANTA_USE_LIQUID)
+		smoke_script = smoke_setup_low  + liquid_step_low;
+	else
+		smoke_script = smoke_setup_low  + smoke_step_low;
+
+	std::string final_script = parseScript(smoke_script, smd);
+	PyGILState_STATE gilstate = PyGILState_Ensure();
+	PyRun_SimpleString(final_script.c_str());
+	PyGILState_Release(gilstate);
+}
+
+void Manta_API::run_manta_sim_file_highRes(SmokeModifierData *smd)
 {
 	string smoke_script = smoke_setup_high + smoke_step_high;		
 	std::string final_script = parseScript(smoke_script, smd);
diff --git a/intern/smoke/intern/MANTA.h b/intern/smoke/intern/MANTA.h
index cb2cb2e..54cb40d 100644
--- a/intern/smoke/intern/MANTA.h
+++ b/intern/smoke/intern/MANTA.h
@@ -21,7 +21,7 @@
 void export_force_fields(int size_x, int size_y, int size_z, float *f_x, float*f_y, float*f_z);/*defined in pymain.cpp*/
 void export_em_fields(float *em_map, float flow_density, 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 *inf, float *vel);/*defined in pymain.cpp*/
 extern "C" void manta_write_effectors(struct FLUID_3D *fluid); /*defined in smoke_api.cpp*/
-void runMantaScript(const string& ss,vector<string>& args);//defined in manta_pp/pwrapper/pymain.cpp
+void initializeMantaflow(vector<string>& args);//defined in manta_pp/pwrapper/pymain.cpp
 
 /*for passing to detached thread*/
 struct manta_arg_struct {
@@ -105,7 +105,9 @@ public:
 	
 	void stop_manta_sim();
 	
-	static void generate_manta_sim_file_highRes(SmokeModifierData *smd);
+	static void run_manta_sim_file_lowRes(SmokeModifierData *smd);
+	
+	static void run_manta_sim_file_highRes(SmokeModifierData *smd);
 	
 	void manta_sim_step(int frame);
 	
diff --git a/intern/smoke/intern/WTURBULENCE.cpp b/intern/smoke/intern/WTURBULENCE.cpp
index 29cccbd..1c96b22 100644
--- a/intern/smoke/intern/WTURBULENCE.cpp
+++ b/intern/smoke/intern/WTURBULENCE.cpp
@@ -1293,7 +1293,7 @@ WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int no
 	_noiseTile = new float[noiseTileSize * noiseTileSize * noiseTileSize];
 	setNoise(noisetype, noisefile_path);
 	sds->smd->domain->wt = this;
-	Manta_API::generate_manta_sim_file_highRes(sds->smd);
+	Manta_API::run_manta_sim_file_highRes(sds->smd);
 	Manta_API::updateHighResPointers(this);
 }
 
diff --git a/source/blender/python/manta_pp/pwrapper/pymain.cpp b/source/blender/python/manta_pp/pwrapper/pymain.cpp
index 83bc587..dce1042 100644
--- a/source/blender/python/manta_pp/pwrapper/pymain.cpp
+++ b/source/blender/python/manta_pp/pwrapper/pymain.cpp
@@ -166,22 +166,46 @@ void export_force_fields(int size_x, int size_y, int size_z, float *f_x, float*f
 {
 	export_fields(size_x, size_y, size_z, f_x, f_y, f_z, "manta_forces.uni");	
 }
-		   
-void runMantaScript(const string& ss,vector<string>& args) {
+
+/* Called from Blender for internal use */
+void initializeMantaflow(vector<string>& args) {
 	string filename = args[0];
 	
 	// Initialize extension classes and wrappers
 	srand(0);
 	PyGILState_STATE gilstate = PyGILState_Ensure();
 	/*cleaning possible previous setups*/
-	PyRun_SimpleString(clean_code1.c_str());
+	//PyRun_SimpleString(clean_code1.c_str());
 	
 	if (! manta_initialized)
 	{	
 		debMsg("running manta init?", 0);
 		Pb::setup(filename, args);
 		manta_initialized = true;
-	}	
+	}
+
+	// Pass through the command line arguments
+	// for Py3k compatability, convert to wstring
+	vector<pyString> pyArgs(args.size());
+	const pyChar ** cargs = new const pyChar*  [args.size()];
+	for (size_t i=0; i<args.size(); i++) {
+		pyArgs[i] = pyString(args[i].begin(), args[i].end());
+		cargs[i] = pyArgs[i].c_str();
+	}
+	PySys_SetArgv( args.size(), (pyChar**) cargs);
+	PyGILState_Release(gilstate);
+
+	delete [] cargs;
+}
+
+
+void runScript(vector<string>& args) {
+	string filename = args[0];
+	
+	// Initialize extension classes and wrappers
+	srand(0);
+	Pb::setup(filename, args);
+		
 	// Pass through the command line arguments
 	// for Py3k compatability, convert to wstring
 	vector<pyString> pyArgs(args.size());
@@ -193,12 +217,12 @@ void runMantaScript(const string& ss,vector<string>& args) {
 	PySys_SetArgv( args.size(), (pyChar**) cargs);
 	
 	// Try to load python script
-//	FILE* fp = fopen(filename.c_str(),"rb");
-//	if (fp == NULL) {
-//		debMsg("Cannot open '" << filename << "'", 0);
-//		Pb::finalize();
-//		return;
-//	}
+	FILE* fp = fopen(filename.c_str(),"rb");
+	if (fp == NULL) {
+		debMsg("Cannot open '" << filename << "'", 0);
+		Pb::finalize();
+		return;
+	}
 	
 	// Run the python script file
 	debMsg("Loading script '" << filename << "'", 0);
@@ -215,50 +239,37 @@ void runMantaScript(const string& ss,vector<string>& args) {
 	delete[] buf;    
 #else
 	// for linux, use this as it produces nicer error messages
-	string toExec = "";
-	
-	PyRun_SimpleString(ss.c_str());
-//	PyRun_SimpleFileEx(fp, filename.c_str(), 0);    
-//	for (int frame=0; frame < 4; ++frame)
-//	{
-//		std::string frame_str = static_cast<ostringstream*>( &(ostringstream() << frame) )->str();
-//		std::string py_string_0 = string("sim_step(").append(frame_str);
-//		std::string py_string_1 = py_string_0.append(")\0");
-//		PyRun_SimpleString(py_string_1.c_str());
-//	}
-//	if (fp != NULL){
-//		fclose(fp);    
-//	}
+	PyRun_SimpleFileEx(fp, filename.c_str(), 0);  
+	fclose(fp);    
 #endif
 	
 	debMsg("Script finished.", 0);
 #ifdef GUI
-//	guiWaitFinish();
+	guiWaitFinish();
 #endif
 
 	// finalize
-//	Pb::finalize();
-	PyGILState_Release(gilstate);
-
+	Pb::finalize();
+	
 	delete [] cargs;
 }
 
-//int manta_main(int argc,char* argv[]) {
-//	debMsg("Version: "<< buildInfoString() , 1);
-//
-//#ifdef GUI
-//	guiMain(argc, argv);    
-//#else
-//	if (argc<=1) {
-//		cerr << "Usage : Syntax is 'manta <config.py>'" << endl;  
-//		return 1;
-//	}
-//
-//	vector<string> args;
-//	for (int i=1; i<argc; i++) args.push_back(argv[i]);
-//	runMantaScript(args);
-//#endif        		
-//
-//	return 0;
-//}
+int mainManta(int argc,char* argv[]) {
+	debMsg("Version: "<< buildInfoString() , 1);
+
+#ifdef GUI
+	guiMain(argc, argv);    
+#else
+	if (argc<=1) {
+		cerr << "Usage : Syntax is 'manta <config.py>'" << endl;  
+		return 1;
+	}
+
+	vector<string> args;
+	for (int i=1; i<argc; i++) args.push_back(argv[i]);
+	runScript(args);
+#endif        		
+
+	return 0;
+}
 #endif
\ No newline at end of file




More information about the Bf-blender-cvs mailing list