[Bf-blender-cvs] [4d56dc8de72] fluid-mantaflow: refactored setup for liquid on first frame again

Sebastián Barschkis noreply at git.blender.org
Wed Nov 29 19:12:29 CET 2017


Commit: 4d56dc8de72cb72799c115ffd4633843005cc9fa
Author: Sebastián Barschkis
Date:   Tue Nov 28 12:46:51 2017 +0100
Branches: fluid-mantaflow
https://developer.blender.org/rB4d56dc8de72cb72799c115ffd4633843005cc9fa

refactored setup for liquid on first frame again

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

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	source/blender/blenkernel/intern/smoke.c
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 e01ae92e2c1..e17f533907f 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, bool initOnly);
+void smoke_step(struct FLUID *smoke, 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);
diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index 28dfba2e1b7..f371f4c1727 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -383,7 +383,6 @@ void FLUID::initLiquid(SmokeModifierData *smd)
 			+ liquid_import_low
 			+ liquid_adaptive_step
 			+ liquid_pre_step_low
-			+ liquid_geometry_low
 			+ liquid_step_low
 			+ liquid_post_step_low;
 		std::string finalString = parseScript(tmpString, smd);
@@ -466,18 +465,12 @@ void FLUID::initSndParts(SmokeModifierData *smd)
 	}
 }
 
-void FLUID::step(int framenr, bool initOnly)
+void FLUID::step(int framenr)
 {
 	// Run manta step: regular step or init only (sets up geometry only, no vel update, for first frame)
 	mCommands.clear();
 	std::ostringstream manta_step;
-	if (initOnly) {
-		std::string init = (initOnly) ? "True" : "False";
-		manta_step <<  "manta_geometry_" << mCurrentID << "()";
-	}
-	else {
-		manta_step <<  "manta_step_" << mCurrentID << "(" << framenr << ")";
-	}
+	manta_step <<  "manta_step_" << mCurrentID << "(" << framenr << ")";
 	mCommands.push_back(manta_step.str());
 
 	runPythonString(mCommands);
@@ -967,6 +960,10 @@ void FLUID::exportSmokeScript(SmokeModifierData *smd)
 	if (highres)
 		manta_script += smoke_post_step_high;
 
+	manta_script += fluid_adapt_time_step_low;
+	if (highres)
+		manta_script += fluid_adapt_time_step_high;
+
 	manta_script += smoke_step_low;
 	if (highres)
 		manta_script += smoke_step_high;
@@ -1061,7 +1058,10 @@ void FLUID::exportLiquidScript(SmokeModifierData *smd)
 	manta_script += liquid_pre_step_low;
 	manta_script += liquid_post_step_low;
 
-	manta_script += liquid_geometry_low;
+	manta_script += fluid_adapt_time_step_low;
+	if (highres)
+		manta_script += fluid_adapt_time_step_high;
+
 	manta_script += liquid_step_low;
 	if (highres)
 		manta_script += liquid_step_high;
diff --git a/intern/mantaflow/intern/FLUID.h b/intern/mantaflow/intern/FLUID.h
index 4137462e117..f4f22524d62 100644
--- a/intern/mantaflow/intern/FLUID.h
+++ b/intern/mantaflow/intern/FLUID.h
@@ -45,7 +45,7 @@ public:
 	typedef struct pVel { float pos[3]; } pVel;
 
 	// Manta step, handling everything
-	void step(int startFrame, bool initOnly);
+	void step(int startFrame);
 	
 	// Grid initialization functions
 	void initHeat(struct SmokeModifierData *smd);
diff --git a/intern/mantaflow/intern/manta_fluid_API.cpp b/intern/mantaflow/intern/manta_fluid_API.cpp
index 4be4eda9ac2..4ec010e7cc4 100644
--- a/intern/mantaflow/intern/manta_fluid_API.cpp
+++ b/intern/mantaflow/intern/manta_fluid_API.cpp
@@ -61,9 +61,9 @@ extern "C" void smoke_manta_export(FLUID* smoke, SmokeModifierData *smd)
 	smoke->exportSmokeData(smd);
 }
 
-extern "C" void smoke_step(FLUID *fluid, int framenr, bool initOnly)
+extern "C" void smoke_step(FLUID *fluid, int framenr)
 {
-	fluid->step(framenr, initOnly);
+	fluid->step(framenr);
 	fluid->updatePointers();
 	if (fluid->usingHighRes())
 		fluid->updatePointersHigh();
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index 6f402544629..8dadfa34644 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -166,9 +166,31 @@ def manta_step_$ID$(framenr):\n\
     while s$ID$.frame == last_frame_s$ID$:\n\
         \n\
         mantaMsg('s.frame is ' + str(s$ID$.frame))\n\
+        \n\
+        flags_s$ID$.initDomain(boundaryWidth=boundaryWidth_s$ID$, phiWalls=phiObs_s$ID$, outflow=boundConditions_s$ID$)\n\
+        \n\
+        if using_obstacle_s$ID$:\n\
+            phiObs_s$ID$.join(phiObsIn_s$ID$)\n\
+        phi_s$ID$.join(phiIn_s$ID$)\n\
+        if using_obstacle_s$ID$:\n\
+            phi_s$ID$.subtract(phiObsIn_s$ID$)\n\
+        \n\
+        phiOut_s$ID$.join(phiOutIn_s$ID$)\n\
+        \n\
+        #updateFractions(flags=flags_s$ID$, phiObs=phiObs_s$ID$, fractions=fractions_s$ID$, boundaryWidth=boundaryWidth_s$ID$) # TODO (sebbas): uncomment for fraction support\n\
+        setObstacleFlags(flags=flags_s$ID$, phiObs=phiObs_s$ID$, phiOut=phiOut_s$ID$, fractions=fractions_s$ID$)\n\
+        \n\
+        # add initial velocity: set invel as source grid to ensure const vels in inflow region, sampling makes use of this\n\
+        mapWeights_s$ID$.clear() # mis-use mapWeights\n\
+        if using_invel_s$ID$:\n\
+            resampleVec3ToMac(source=invel_s$ID$, target=mapWeights_s$ID$)\n\
+        pVel_pp$ID$.setSource(mapWeights_s$ID$, isMAC=True)\n\
+        \n\
+        sampleLevelsetWithParticles(phi=phiIn_s$ID$, flags=flags_s$ID$, parts=pp_s$ID$, discretization=particleNumber_s$ID$, randomness=randomness_s$ID$, refillEmpty=True)\n\
+        flags_s$ID$.updateFromLevelset(phi_s$ID$, phiObs_s$ID$)\n\
+        mapWeights_s$ID$.clear() # clean up, mapweights grid used later again\n\
         fluid_adapt_time_step()\n\
         \n\
-        liquid_geometry_$ID$()\n\
         mantaMsg('Low step / s$ID$.frame: ' + str(s$ID$.frame))\n\
         liquid_step_$ID$()\n\
         \n\
@@ -178,44 +200,31 @@ def manta_step_$ID$(framenr):\n\
             liquid_step_high_$ID$()\n\
         s$ID$.step()\n\
     \n\
-    liquid_post_step_low_$ID$()\n\
-\n\
-def manta_geometry_$ID$():\n\
-    mantaMsg('Manta geometry')\n\
-    liquid_geometry_$ID$()\n\
-    \n\
-    if using_sndparts_s$ID$:\n\
-        mantaMsg('Sampling (initial) snd particles')\n\
-        sampleSndParts(phi=phi_s$ID$, phiIn=phiIn_s$ID$, flags=flags_s$ID$, vel=vel_s$ID$, parts=ppSnd_s$ID$, type=$SNDPARTICLE_TYPES$, amountDroplet=$SNDPARTICLE_DROPLET_AMOUNT$, amountFloater=$SNDPARTICLE_FLOATER_AMOUNT$, amountTracer=$SNDPARTICLE_TRACER_AMOUNT$, thresholdDroplet=$SNDPARTICLE_DROPLET_THRESH$)\n\
-    \n\
     liquid_post_step_low_$ID$()\n";
 
-const std::string liquid_geometry_low = "\n\
-def liquid_geometry_$ID$():\n\
-    mantaMsg('Liquid geometry low')\n\
-    \n\
-    flags_s$ID$.initDomain(boundaryWidth=boundaryWidth_s$ID$, phiWalls=phiObs_s$ID$, outflow=boundConditions_s$ID$)\n\
-    \n\
-    if using_obstacle_s$ID$:\n\
-        phiObs_s$ID$.join(phiObsIn_s$ID$)\n\
-    phi_s$ID$.join(phiIn_s$ID$)\n\
-    if using_obstacle_s$ID$:\n\
-        phi_s$ID$.subtract(phiObsIn_s$ID$)\n\
+const std::string liquid_step_low = "\n\
+def liquid_step_$ID$():\n\
+    mantaMsg('Liquid step low')\n\
     \n\
-    phiOut_s$ID$.join(phiOutIn_s$ID$)\n\
+    mantaMsg('Advecting particles')\n\
+    pp_s$ID$.advectInGrid(flags=flags_s$ID$, vel=vel_s$ID$, integrationMode=IntRK4, deleteInObstacle=False, stopInObstacle=False)\n\
     \n\
-    #updateFractions(flags=flags_s$ID$, phiObs=phiObs_s$ID$, fractions=fractions_s$ID$, boundaryWidth=boundaryWidth_s$ID$) # TODO (sebbas): uncomment for fraction support\n\
-    setObstacleFlags(flags=flags_s$ID$, phiObs=phiObs_s$ID$, phiOut=phiOut_s$ID$, fractions=fractions_s$ID$)\n\
+    mantaMsg('Pushing particles out of obstacles')\n\
+    pushOutofObs(parts=pp_s$ID$, flags=flags_s$ID$, phiObs=phiObs_s$ID$)\n\
     \n\
-    # add initial velocity: set invel as source grid to ensure const vels in inflow region, sampling makes use of this\n\
-    mapWeights_s$ID$.clear() # mis-use mapWeights\n\
-    if using_invel_s$ID$:\n\
-        resampleVec3ToMac(source=invel_s$ID$, target=mapWeights_s$ID$)\n\
-    pVel_pp$ID$.setSource(mapWeights_s$ID$, isMAC=True)\n\
+    mantaMsg('Advecting phi')\n\
+    advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=phi_s$ID$, order=1) # first order is usually enough\n\
+    mantaMsg('Advecting velocity')\n\
+    advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=vel_s$ID$, order=2, openBounds=doOpen_s$ID$, boundaryWidth=boundaryWidth_s$ID$)\n\
     \n\
-    sampleLevelsetWithParticles(phi=phiIn_s$ID$, flags=flags_s$ID$, parts=pp_s$ID$, discretization=particleNumber_s$ID$, randomness=randomness_s$ID$, refillEmpty=True)\n\
-    flags_s$ID$.updateFromLevelset(phi_s$ID$, phiObs_s$ID$)\n\
-    mapWeights_s$ID$.clear() # clean up, mapweights grid used later again\n\
+    if using_sndparts_s$ID$:\n\
+        mantaMsg('Sampling snd particles')\n\
+        sampleSndParts(phi=phi_s$ID$, phiIn=phiIn_s$ID$, flags=flags_s$ID$, vel=vel_s$ID$, parts=ppSnd_s$ID$, type=$SNDPARTICLE_TYPES$, amountDroplet=$SNDPARTICLE_DROPLET_AMOUNT$, amountFloater=$SNDPARTICLE_FLOATER_AMOUNT$, amountTracer=$SNDPARTICLE_TRACER_AMOUNT$, thresholdDroplet=$SNDPARTICLE_DROPLET_THRESH$)\n\
+        mantaMsg('Updating snd particle data (velocity, life count)')\n\
+        updateSndParts(phi=phi_s$ID$, flags=flags_s$ID$, vel=vel_s$ID$, gravity=gravity_s$ID$, parts=ppSnd_s$ID$, partVel=pVelSnd_pp$ID$, partLife=pLifeSnd_pp$ID$, riseBubble=$SNDPARTICLE_BUBBLE_RISE$)\n\
+        mantaMsg('Adjusting snd particles')\n\
+        pushOutofObs(parts=ppSnd_s$ID$, flags=flags_s$ID$, phiObs=phiObs_s$ID$, shift=1.0)\n\
+        adjustSndParts(parts=ppSnd_s$ID$, flags=flags_s$ID$, phi=phi_s$ID$, partVel=pVelSnd_pp$ID$, partLife=pLifeSnd_pp$ID$, lifeDroplet=$SNDPARTICLE_DROPLET_LIFE$, lifeBubble=$SNDPARTICLE_BUBBLE_LIFE$, lifeFloater=$SNDPARTICLE_FLOATER_LIFE$, lifeTracer=$SNDPARTICLE_TRACER_LIFE$, maxDroplet=$SNDPARTICLE_DROPLET_MAX$, maxBubble=$SNDPARTICLE_BUBBLE_MAX$, maxFloater=$SNDPARTICLE_FLOATER_MAX$, maxTr

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list