[Bf-blender-cvs] [2c4b5e62071] fluid-mantaflow: added first version of decoupled cache - breaks compatibility, blender not fully working right now

Sebastián Barschkis noreply at git.blender.org
Tue Mar 13 13:58:01 CET 2018


Commit: 2c4b5e620719097232595b79d974cea35cd472cb
Author: Sebastián Barschkis
Date:   Tue Mar 13 13:57:44 2018 +0100
Branches: fluid-mantaflow
https://developer.blender.org/rB2c4b5e620719097232595b79d974cea35cd472cb

added first version of decoupled cache - breaks compatibility, blender not fully working right now

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

M	intern/mantaflow/extern/manta_fluid_API.h
M	intern/mantaflow/intern/FLUID.cpp
M	intern/mantaflow/intern/FLUID.h
M	intern/mantaflow/intern/manta_fluid_API.cpp
M	intern/mantaflow/intern/strings/liquid_script.h
M	intern/mantaflow/intern/strings/shared_script.h
M	intern/mantaflow/intern/strings/smoke_script.h
M	release/scripts/startup/bl_ui/properties_physics_smoke.py
M	source/blender/blenkernel/intern/smoke.c
M	source/blender/editors/physics/physics_fluid.c
M	source/blender/editors/physics/physics_intern.h
M	source/blender/editors/physics/physics_ops.c
M	source/blender/makesdna/DNA_smoke_types.h
M	source/blender/makesrna/intern/rna_smoke.c

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

diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 9b688bf6306..79ff2a9622e 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -41,7 +41,7 @@ void smoke_free(struct FLUID *smoke);
 size_t smoke_get_index(int x, int max_x, int y, int max_y, int z /*, int max_z */);
 size_t smoke_get_index2d(int x, int max_x, int y /*, int max_y, int z, int max_z */);
 void smoke_manta_export(struct FLUID* smoke, struct SmokeModifierData *smd);
-void smoke_step(struct FLUID *smoke, int framenr);
+void smoke_step(struct FLUID *smoke, struct SmokeModifierData *smd, int framenr);
 void smoke_dissolve(struct FLUID *smoke, int speed, int log);
 void smoke_dissolve_wavelet(struct FLUID *smoke, int speed, int log);
 void smoke_export(struct FLUID *smoke, float *dt, float *dx, float **dens, float **react, float **flame, float **fuel, float **heat, float **vx, float **vy, float **vz, float **r, float **g, float **b, int **obstacles);
@@ -166,6 +166,20 @@ void fluid_ensure_obstacle(struct FLUID *fluid, struct SmokeModifierData *smd);
 void fluid_ensure_guiding(struct FLUID *fluid, struct SmokeModifierData *smd);
 void fluid_ensure_invelocity(struct FLUID *fluid, struct SmokeModifierData *smd);
 void fluid_ensure_sndparts(struct FLUID *fluid, struct SmokeModifierData *smd);
+int fluid_read_cache(struct FLUID* fluid, struct SmokeModifierData *smd, int framenr);
+void fluid_free_geometry(struct FLUID* fluid, struct SmokeModifierData *smd);
+void fluid_bake_low(struct FLUID* fluid, struct SmokeModifierData *smd);
+void fluid_free_low(struct FLUID* fluid, struct SmokeModifierData *smd);
+void fluid_bake_high(struct FLUID* fluid, struct SmokeModifierData *smd);
+void fluid_free_high(struct FLUID* fluid, struct SmokeModifierData *smd);
+void fluid_bake_mesh_low(struct FLUID* fluid, struct SmokeModifierData *smd);
+void fluid_free_mesh_low(struct FLUID* fluid, struct SmokeModifierData *smd);
+void fluid_bake_mesh_high(struct FLUID* fluid, struct SmokeModifierData *smd);
+void fluid_free_mesh_high(struct FLUID* fluid, struct SmokeModifierData *smd);
+void fluid_bake_particles_low(struct FLUID* fluid, struct SmokeModifierData *smd);
+void fluid_free_particles_low(struct FLUID* fluid, struct SmokeModifierData *smd);
+void fluid_bake_particles_high(struct FLUID* fluid, struct SmokeModifierData *smd);
+void fluid_free_particles_high(struct FLUID* fluid, struct SmokeModifierData *smd);
 
 #ifdef __cplusplus
 }
diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index 630e700c1e1..630cc769462 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -241,6 +241,24 @@ void FLUID::initDomain(SmokeModifierData *smd)
 	std::string tmpString = fluid_variables_low
 		+ fluid_solver_low
 		+ fluid_alloc_low
+		+ fluid_bake_helper
+		+ fluid_bake_geometry
+		+ fluid_free_geometry
+		+ fluid_bake_low
+		+ fluid_free_low
+		+ fluid_bake_high
+		+ fluid_free_high
+		+ fluid_bake_mesh_low
+		+ fluid_free_mesh_low
+		+ fluid_bake_mesh_high
+		+ fluid_free_mesh_high
+		+ fluid_bake_particles_low
+		+ fluid_free_particles_low
+		+ fluid_bake_particles_high
+		+ fluid_free_particles_high
+		+ fluid_save_geometry_low
+		+ fluid_save_data_low
+		+ fluid_load_data_low
 		+ fluid_obstacle_export_low
 		+ fluid_guiding_export_low
 		+ fluid_invel_export_low
@@ -259,6 +277,8 @@ void FLUID::initDomainHigh(SmokeModifierData *smd)
 		+ fluid_solver_high
 		+ fluid_alloc_high
 		+ fluid_adapt_time_step_high
+		+ fluid_save_data_high
+		+ fluid_load_data_high
 		+ fluid_adaptive_time_stepping_high;
 	std::string finalString = parseScript(tmpString, smd);
 	mCommands.clear();
@@ -272,8 +292,9 @@ void FLUID::initSmoke(SmokeModifierData *smd)
 	std::string tmpString = smoke_alloc_low
 		+ smoke_variables_low
 		+ smoke_bounds_low
-		+ smoke_adaptive_step
-		+ smoke_export_low
+		+ smoke_adaptive_step_low
+		+ smoke_save_geometry_low
+		+ smoke_save_data_low
 		+ smoke_pre_step_low
 		+ smoke_step_low
 		+ smoke_post_step_low;
@@ -290,7 +311,8 @@ void FLUID::initSmokeHigh(SmokeModifierData *smd)
 		+ smoke_variables_high
 		+ smoke_bounds_high
 		+ smoke_wavelet_turbulence_noise
-		+ smoke_export_high
+		+ smoke_adaptive_step_high
+		+ smoke_save_data_high
 		+ smoke_pre_step_high
 		+ smoke_step_high
 		+ smoke_post_step_high;
@@ -380,15 +402,18 @@ void FLUID::initLiquid(SmokeModifierData *smd)
 		std::string tmpString = liquid_alloc_low
 			+ liquid_variables_low
 			+ liquid_init_phi
+			+ liquid_save_geometry_low
 			+ liquid_save_mesh_low
 			+ liquid_save_particles_low
-			+ liquid_save_particle_velocities
-			+ liquid_export_low
-			+ liquid_import_low
-			+ liquid_adaptive_step
+			+ liquid_save_data_low
+			+ liquid_load_mesh_low
+			+ liquid_load_particles_low
+			+ liquid_load_data_low
+			+ liquid_adaptive_step_low
 			+ liquid_pre_step_low
 			+ liquid_step_low
-			+ liquid_post_step_low;
+			+ liquid_post_step_low
+			+ liquid_step_particles_low;
 		std::string finalString = parseScript(tmpString, smd);
 		mCommands.clear();
 		mCommands.push_back(finalString);
@@ -403,8 +428,8 @@ void FLUID::initLiquidHigh(SmokeModifierData *smd)
 	std::string tmpString = liquid_alloc_high
 		+ liquid_variables_high
 		+ liquid_save_mesh_high
-		+ liquid_export_high
-		+ liquid_import_high
+		+ liquid_load_mesh_high
+		+ liquid_adaptive_step_high
 		+ liquid_step_high;
 	std::string finalString = parseScript(tmpString, smd);
 	mCommands.clear();
@@ -469,13 +494,23 @@ void FLUID::initSndParts(SmokeModifierData *smd)
 	}
 }
 
-void FLUID::step(int framenr)
+void FLUID::step(SmokeModifierData *smd, int framenr)
 {
+	// TODO (sebbas): Use geometry bake instead of fluid_step
+//	std::string path(smd->domain->cache_directory);
+//
+//	mCommands.clear();
+//	std::ostringstream ss;
+//	ss <<  "bake_geometry_" << mCurrentID << "(r'" << path << "'," << framenr << ")";
+//	mCommands.push_back(ss.str());
+//
+//	runPythonString(mCommands);
+
 	// Run manta step: regular step or init only (sets up geometry only, no vel update, for first frame)
 	mCommands.clear();
-	std::ostringstream manta_step;
-	manta_step <<  "manta_step_" << mCurrentID << "(" << framenr << ")";
-	mCommands.push_back(manta_step.str());
+	std::ostringstream ss;
+	ss <<  "fluid_step_low_" << mCurrentID << "(" << framenr << ")";
+	mCommands.push_back(ss.str());
 
 	runPythonString(mCommands);
 }
@@ -634,7 +669,11 @@ std::string FLUID::getRealValue(const std::string& varName,  SmokeModifierData *
 		md = ((ModifierData*) smd);
 	}
 
-	if (varName == "USING_COLORS")
+	if (varName == "USING_SMOKE")
+		ss << ((smd->domain->type == MOD_SMOKE_DOMAIN_TYPE_GAS) ? "True" : "False");
+	else if (varName == "USING_LIQUID")
+		ss << ((smd->domain->type == MOD_SMOKE_DOMAIN_TYPE_LIQUID) ? "True" : "False");
+	else if (varName == "USING_COLORS")
 		ss << (smd->domain->active_fields & SM_ACTIVE_COLORS ? "True" : "False");
 	else if (varName == "USING_HEAT")
 		ss << (smd->domain->active_fields & SM_ACTIVE_HEAT ? "True" : "False");
@@ -906,7 +945,7 @@ void FLUID::exportSmokeScript(SmokeModifierData *smd)
 			manta_script += smoke_alloc_fire_high;
 	}
 	
-	manta_script += smoke_import_low;
+	manta_script += smoke_load_data_low;
 	if (obstacle)
 		manta_script += fluid_obstacle_import_low;
 	if (guiding)
@@ -914,7 +953,7 @@ void FLUID::exportSmokeScript(SmokeModifierData *smd)
 	if (invel)
 		manta_script += fluid_invel_import_low;
 	if (highres)
-		manta_script += smoke_import_high;
+		manta_script += smoke_load_data_high;
 	
 	manta_script += smoke_pre_step_low;
 	if (highres)
@@ -932,7 +971,7 @@ void FLUID::exportSmokeScript(SmokeModifierData *smd)
 	if (highres)
 		manta_script += smoke_step_high;
 	
-	manta_script += smoke_adaptive_step
+	manta_script += smoke_adaptive_step_low
 			+ smoke_inflow_low
 			+ smoke_standalone_load
 			+ fluid_standalone_load
@@ -948,6 +987,208 @@ void FLUID::exportSmokeScript(SmokeModifierData *smd)
 	myfile.close();
 }
 
+/* BEGIN TODO (sebbas): read decoupled uni cache */
+int FLUID::readCache(SmokeModifierData *smd, int framenr)
+{
+	std::string path(smd->domain->cache_directory);
+	std::ostringstream ss;
+
+	try {
+		mCommands.clear();
+		ss <<  "fluid_load_data_low_" << mCurrentID << "(r'" << path << "'," << framenr << ")";
+		mCommands.push_back(ss.str());
+
+		if (mUsingSmoke) {
+			ss.str("");
+			ss <<  "smoke_load_data_low_" << mCurrentID << "(r'" << path << "'," << framenr << ")";
+			mCommands.push_back(ss.str());
+		}
+
+		if (mUsingLiquid) {
+			ss.str("");
+			ss <<  "liquid_load_data_low_" << mCurrentID << "(r'" << path << "'," << framenr << ")";
+			mCommands.push_back(ss.str());
+		}
+
+		mCommands.push_back(ss.str());
+
+		runPythonString(mCommands);
+	} catch (const std::runtime_error& error) {
+		std::cout << "Missing cache files. Continue with simulation" << std::endl;
+		return 0;
+	}
+	return 1;
+}
+
+void FLUID::freeGeometry(SmokeModifierData *smd)
+{
+	std::string path(smd->domain->cache_directory);
+
+	mCommands.clear();
+	std::ostringstream ss;
+	ss <<  "free_geometry_" << mCurrentID << "(r'" << path << "')";
+	mCommands.push_back(ss.str());
+
+	runPythonString(mCommands);
+}
+/* END TODO (sebbas) */
+
+void FLUID::bakeSimulationLow(SmokeModifierData *smd)
+{
+	int start_frame = smd->domain->cache_frame_start;
+	int end_frame = smd->domain->cache_frame_end;
+	std::string path(smd->domain->cache_directory);
+
+	mCommands.clear();
+	std::ostringstream ss;
+	ss <<  "bake_fluid_low_" << mCurrentID << "(r'" << path << "'," << start_frame << ", " << end_frame << ")";
+	mCommands.push_back(ss.str());
+
+	runPythonString(mCommands);
+}
+
+void FLUID::freeSimulationLow(SmokeModifierData *smd)
+{
+	std::string path(smd->domain->cache_directory);
+
+	mCommands.clear();
+	std::ostringstream ss;
+	ss <<  "free_fluid_low_" << mCurrentID << "(r'" << path << "')";
+	mCommands.push_back(ss.str());
+
+	runPythonString(mCommands);
+}
+
+void FLUID::bakeSimulationHigh(SmokeModifierData *smd)
+{
+	int start_frame = smd->domain->cache_frame_start;
+	int end_frame = smd->domain->cache_frame_end;
+	std::string path(smd->domain->cache_directory);
+
+	mCommands.clear();
+	std::o

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list