[Bf-blender-cvs] [a1a1d4300ec] fluid-mantaflow: Mantaflow: Improved allocation of fluid outflow objects

Sebastián Barschkis noreply at git.blender.org
Sat Apr 6 22:12:47 CEST 2019


Commit: a1a1d4300ecd50da274752d2ebb3618baf51961c
Author: Sebastián Barschkis
Date:   Tue Nov 6 15:24:04 2018 +0100
Branches: fluid-mantaflow
https://developer.blender.org/rBa1a1d4300ecd50da274752d2ebb3618baf51961c

Mantaflow: Improved allocation of fluid outflow objects

Similarly to flow and obstacle objects, the outflow grid now only gets allocated when outflow objects are actually present. Commit also includes improved vector (mesh, particles) cleanup (fixes issue with particles being visible although domain is empty in simulation).

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

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/fluid_script.h
M	intern/mantaflow/intern/strings/liquid_script.h
M	intern/mantaflow/intern/strings/smoke_script.h

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

diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 07e54f1fa7c..89994c382be 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -42,6 +42,7 @@ void fluid_free(struct FLUID *fluid);
 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_outflow(struct FLUID *fluid, struct SmokeModifierData *smd);
 int fluid_write_data(struct FLUID* fluid, struct SmokeModifierData *smd, int framenr);
 int fluid_read_data(struct FLUID* fluid, struct SmokeModifierData *smd, int framenr);
 int fluid_read_noise(struct FLUID* fluid, struct SmokeModifierData *smd, int framenr);
diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index 3e788102e98..4d36b523348 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -64,6 +64,7 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : mCurrentID(++solverID)
 	mUsingColors   = smd->domain->active_fields & FLUID_DOMAIN_ACTIVE_COLORS;
 	mUsingObstacle = smd->domain->active_fields & FLUID_DOMAIN_ACTIVE_OBSTACLE;
 	mUsingInvel    = smd->domain->active_fields & FLUID_DOMAIN_ACTIVE_INVEL;
+	mUsingOutflow  = smd->domain->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW;
 	mUsingNoise    = smd->domain->flags & FLUID_DOMAIN_USE_NOISE;
 	mUsingMesh     = smd->domain->flags & FLUID_DOMAIN_USE_MESH;
 	mUsingMVel     = smd->domain->flags & FLUID_DOMAIN_USE_SPEED_VECTORS;
@@ -167,6 +168,7 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : mCurrentID(++solverID)
 		initLiquid(smd);
 		if (mUsingObstacle) initObstacle(smd);
 		if (mUsingInvel)    initInVelocity(smd);
+		if (mUsingOutflow)  initOutflow(smd);
 
 		if (mUsingDrops || mUsingBubbles || mUsingFloats || mUsingTracers) {
 			mUpresParticle       = smd->domain->particle_scale;
@@ -209,6 +211,7 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : mCurrentID(++solverID)
 		if (mUsingColors)   initColors(smd);
 		if (mUsingObstacle) initObstacle(smd);
 		if (mUsingInvel)    initInVelocity(smd);
+		if (mUsingOutflow)  initOutflow(smd);
 
 		if (mUsingGuiding) {
 			mResGuiding = (smd->domain->guiding_parent) ? smd->domain->guide_res : smd->domain->res;
@@ -483,6 +486,20 @@ void FLUID::initInVelocity(SmokeModifierData *smd)
 	}
 }
 
+void FLUID::initOutflow(SmokeModifierData *smd)
+{
+	if (!mPhiOutIn) {
+		std::vector<std::string> pythonCommands;
+		std::string tmpString = fluid_alloc_outflow
+			+ fluid_with_outflow;
+		std::string finalString = parseScript(tmpString, smd);
+		pythonCommands.push_back(finalString);
+
+		runPythonString(pythonCommands);
+		mUsingOutflow = true;
+	}
+}
+
 void FLUID::initSndParts(SmokeModifierData *smd)
 {
 	std::vector<std::string> pythonCommands;
@@ -619,6 +636,8 @@ std::string FLUID::getRealValue(const std::string& varName,  SmokeModifierData *
 		ss << (smd->domain->flags & FLUID_DOMAIN_USE_GUIDING ? "True" : "False");
 	else if (varName == "USING_INVEL")
 		ss << (smd->domain->active_fields & FLUID_DOMAIN_ACTIVE_INVEL ? "True" : "False");
+	else if (varName == "USING_OUTFLOW")
+		ss << (smd->domain->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW ? "True" : "False");
 	else if (varName == "SOLVER_DIM")
 		ss << smd->domain->solver_res;
 	else if (varName == "DO_OPEN") {
@@ -903,6 +922,10 @@ int FLUID::updateFlipStructures(SmokeModifierData *smd, int framenr)
 	if (FLUID::with_debug)
 		std::cout << "FLUID::updateFlipStructures()" << std::endl;
 
+	// Ensure empty data structures at start
+	if (mFlipParticleData) mFlipParticleData->clear();
+	if (mFlipParticleVelocity) mFlipParticleVelocity->clear();
+
 	if (!mUsingLiquid) return 0;
 	if (BLI_path_is_rel(smd->domain->cache_directory)) return 0;
 
@@ -943,6 +966,11 @@ int FLUID::updateMeshStructures(SmokeModifierData *smd, int framenr)
 	if (!mUsingMesh) return 0;
 	if (BLI_path_is_rel(smd->domain->cache_directory)) return 0;
 
+	// Ensure empty data structures at start
+	if (mMeshNodes) mMeshNodes->clear();
+	if (mMeshTriangles) mMeshTriangles->clear();
+	if (mMeshVelocities) mMeshVelocities->clear();
+
 	std::ostringstream ss;
 	char cacheDir[FILE_MAX], targetFile[FILE_MAX];
 	cacheDir[0] = '\0';
@@ -981,6 +1009,11 @@ int FLUID::updateParticleStructures(SmokeModifierData *smd, int framenr)
 	if (!mUsingDrops && !mUsingBubbles && !mUsingFloats && !mUsingTracers) return 0;
 	if (BLI_path_is_rel(smd->domain->cache_directory)) return 0;
 
+	// Ensure empty data structures at start
+	if (mSndParticleData) mSndParticleData->clear();
+	if (mSndParticleVelocity) mSndParticleVelocity->clear();
+	if (mSndParticleLife) mSndParticleLife->clear();
+
 	std::ostringstream ss;
 	char cacheDir[FILE_MAX], targetFile[FILE_MAX];
 	cacheDir[0] = '\0';
@@ -1749,9 +1782,6 @@ void FLUID::updateMeshFromBobj(const char* filename)
 	int ibuffer[3];
 	int numBuffer = 0;
 
-	mMeshNodes->clear();
-	mMeshTriangles->clear();
-
 	gzf = (gzFile) BLI_gzopen(filename, "rb1"); // do some compression
 	if (!gzf)
 		std::cerr << "updateMeshData: unable to open file: " << filename << std::endl;
@@ -1824,9 +1854,6 @@ void FLUID::updateMeshFromObj(const char* filename)
 	int ibuffer[3];
 	int cntVerts = 0, cntNormals = 0, cntTris = 0;
 
-	mMeshNodes->clear();
-	mMeshTriangles->clear();
-
 	if (!ifs.good())
 		std::cerr << "updateMeshDataFromObj: unable to open file: " << filename << std::endl;
 
@@ -1901,8 +1928,6 @@ void FLUID::updateMeshFromUni(const char* filename)
 	float fbuffer[4];
 	int ibuffer[4];
 
-	mMeshVelocities->clear();
-
 	gzf = (gzFile) BLI_gzopen(filename, "rb1"); // do some compression
 	if (!gzf)
 		std::cout << "updateMeshFromUni: unable to open file" << std::endl;
@@ -2006,9 +2031,10 @@ void FLUID::updateParticlesFromUni(const char* filename, bool isSecondarySys, bo
 	}
 
 	// Pointer to FLIP system or to secondary particle system
-	std::vector<pData>* dataPointer;
-	std::vector<pVel>* velocityPointer;
-	std::vector<float>* lifePointer;
+	std::vector<pData>* dataPointer = NULL;
+	std::vector<pVel>* velocityPointer = NULL;
+	std::vector<float>* lifePointer = NULL;
+
 	if (isSecondarySys) {
 		dataPointer = mSndParticleData;
 		velocityPointer = mSndParticleVelocity;
@@ -2120,7 +2146,9 @@ void FLUID::updatePointers()
 	mForceY    = (float*) stringToPointer(pyObjectToString(callPythonFunction("y_force" + solver_ext, func)));
 	mForceZ    = (float*) stringToPointer(pyObjectToString(callPythonFunction("z_force" + solver_ext, func)));
 
-	mPhiOutIn  = (float*) stringToPointer(pyObjectToString(callPythonFunction("phiOutIn"   + solver_ext, func)));
+	if (mUsingOutflow) {
+		mPhiOutIn = (float*) stringToPointer(pyObjectToString(callPythonFunction("phiOutIn" + solver_ext, func)));
+	}
 
 	if (mUsingObstacle) {
 		mPhiObsIn    = (float*) stringToPointer(pyObjectToString(callPythonFunction("phiObsIn" + solver_ext, func)));
diff --git a/intern/mantaflow/intern/FLUID.h b/intern/mantaflow/intern/FLUID.h
index 68e9a187a61..735d87f2fab 100644
--- a/intern/mantaflow/intern/FLUID.h
+++ b/intern/mantaflow/intern/FLUID.h
@@ -62,6 +62,7 @@ public:
 	void initObstacle(SmokeModifierData *smd);
 	void initGuiding(SmokeModifierData *smd);
 	void initInVelocity(SmokeModifierData *smd);
+	void initOutflow(SmokeModifierData *smd);
 	void initSndParts(SmokeModifierData *smd);
 	void initLiquidSndParts(SmokeModifierData *smd);
 
@@ -240,6 +241,7 @@ private:
 	bool mUsingObstacle;
 	bool mUsingGuiding;
 	bool mUsingInvel;
+	bool mUsingOutflow;
 	bool mUsingNoise;
 	bool mUsingMesh;
 	bool mUsingMVel;
diff --git a/intern/mantaflow/intern/manta_fluid_API.cpp b/intern/mantaflow/intern/manta_fluid_API.cpp
index d58bc98ef00..53bb6e6e531 100644
--- a/intern/mantaflow/intern/manta_fluid_API.cpp
+++ b/intern/mantaflow/intern/manta_fluid_API.cpp
@@ -57,6 +57,13 @@ extern "C" void fluid_ensure_invelocity(FLUID *fluid, struct SmokeModifierData *
 		fluid->updatePointers();
 	}
 }
+extern "C" void fluid_ensure_outflow(FLUID *fluid, struct SmokeModifierData *smd)
+{
+	if (fluid) {
+		fluid->initOutflow(smd);
+		fluid->updatePointers();
+	}
+}
 
 extern "C" int fluid_write_data(FLUID* fluid, SmokeModifierData *smd, int framenr)
 {
diff --git a/intern/mantaflow/intern/strings/fluid_script.h b/intern/mantaflow/intern/strings/fluid_script.h
index 76972b6a280..9d45998bf3d 100644
--- a/intern/mantaflow/intern/strings/fluid_script.h
+++ b/intern/mantaflow/intern/strings/fluid_script.h
@@ -104,6 +104,7 @@ using_adaptTime_s$ID$    = $USING_ADAPTIVETIME$\n\
 using_obstacle_s$ID$     = $USING_OBSTACLE$\n\
 using_guiding_s$ID$      = $USING_GUIDING$\n\
 using_invel_s$ID$        = $USING_INVEL$\n\
+using_outflow_s$ID$      = $USING_OUTFLOW$\n\
 using_sndparts_s$ID$     = $USING_SNDPARTS$\n\
 using_speedvectors_s$ID$ = $USING_SPEEDVECTORS$\n\
 \n\
@@ -154,6 +155,9 @@ using_guiding_s$ID$ = True\n";
 const std::string fluid_with_invel = "\n\
 using_invel_s$ID$ = True\n";
 
+const std::string fluid_with_outflow = "\n\
+using_outflow_s$ID$ = True\n";
+
 const std::string fluid_with_sndparts = "\n\
 using_sndparts_s$ID$ = True\n";
 
@@ -210,7 +214,6 @@ z_vel_s$ID$       = s$ID$.create(RealGrid)\n\
 pressure_s$ID$    = s$ID$.create(RealGrid)\n\
 phiObs_s$ID$      = s$ID$.create(LevelsetGrid)\n\
 phiOut_s$ID$      = s$ID$.create(LevelsetGrid)\n\
-phiOutIn_s$ID$    = s$ID$.create(LevelsetGrid) # TODO (sebbas): Move phiOutIn to separate init - similarly to phiObsIn\n\
 forces_s$ID$      = s$ID$.create(Vec3Grid)\n\
 x_force_s$ID$     = s$ID$.create(RealGrid)\n\
 y_force_s$ID$     = s$ID$.create(RealGrid)\n\
@@ -258,6 +261,10 @@ x_invel_s$ID$ = s$ID$.create(RealGrid)\n\
 y_invel_s$ID$ = s$ID$.create(RealGrid)\n\
 z_invel_s$ID$ = s$ID$.create(RealGrid)\n";
 
+const std::string fluid_alloc_outflow = "\n\
+mantaMsg('Allocating outflow data')\n\
+phiOutIn_s$ID$ = s$ID$.create(LevelsetGrid)\n";
+
 const std::string fluid_alloc_sndparts = "\n\
 mantaMsg('Allocating snd parts low')\n\
 ppSnd_sp$ID$     = sp$ID$.create(BasicParticleSystem)\n\
@@ -337,7 +344,7 @@ def fluid_post_step_$ID$():\n\
         invelC_s$ID$.clear()\n\
     \n\


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list