[Bf-blender-cvs] [a7b5871ccf4] fluid-mantaflow: added support for liquid moving obstacles

Sebastián Barschkis noreply at git.blender.org
Sun Mar 26 20:41:40 CEST 2017


Commit: a7b5871ccf4e714be7f2120cb2f6707239a68e7c
Author: Sebastián Barschkis
Date:   Sun Mar 26 15:26:12 2017 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rBa7b5871ccf4e714be7f2120cb2f6707239a68e7c

added support for liquid moving obstacles

using same obvel setter as in smoke script. fractions left out for now

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

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	source/blender/blenkernel/intern/smoke.c

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

diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index 20113a59e7e..2e855fc1f90 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -86,7 +86,7 @@ vel_s$ID$        = s$ID$.create(MACGrid)\n\
 x_vel_s$ID$      = s$ID$.create(RealGrid)\n\
 y_vel_s$ID$      = s$ID$.create(RealGrid)\n\
 z_vel_s$ID$      = s$ID$.create(RealGrid)\n\
-obvel_s$ID$      = s$ID$.create(MACGrid)\n\
+obvel_s$ID$      = s$ID$.create(Vec3Grid)\n\
 x_obvel_s$ID$    = s$ID$.create(RealGrid)\n\
 y_obvel_s$ID$    = s$ID$.create(RealGrid)\n\
 z_obvel_s$ID$    = s$ID$.create(RealGrid)\n\
@@ -129,6 +129,11 @@ phiIn_s$ID$.initFromFlags(flags_s$ID$)\n";
 
 const std::string liquid_pre_step_low = "\n\
 def liquid_pre_step_low_$ID$():\n\
+    # translate obvels (world space) to grid space\n\
+    x_obvel_s$ID$.multConst(gs_s$ID$.x)\n\
+    y_obvel_s$ID$.multConst(gs_s$ID$.y)\n\
+    z_obvel_s$ID$.multConst(gs_s$ID$.z)\n\
+    \n\
     copyRealToVec3(sourceX=x_vel_s$ID$, sourceY=y_vel_s$ID$, sourceZ=z_vel_s$ID$, target=vel_s$ID$)\n\
     copyRealToVec3(sourceX=x_obvel_s$ID$, sourceY=y_obvel_s$ID$, sourceZ=z_obvel_s$ID$, target=obvel_s$ID$)\n\
     copyRealToVec3(sourceX=x_force_s$ID$, sourceY=y_force_s$ID$, sourceZ=z_force_s$ID$, target=forces_s$ID$)\n";
@@ -138,9 +143,7 @@ def liquid_post_step_low_$ID$():\n\
     forces_s$ID$.clear()\n\
     obvel_s$ID$.clear()\n\
     \n\
-    phiIn_s$ID$.setConst(0.5)\n\
     phiObs_s$ID$.setConst(0.5)\n\
-    phiObsIn_s$ID$.setConst(0)\n\
     \n\
     copyVec3ToReal(source=vel_s$ID$, targetX=x_vel_s$ID$, targetY=y_vel_s$ID$, targetZ=z_vel_s$ID$)\n";
 
@@ -192,9 +195,11 @@ const std::string liquid_step_low = "\n\
 def liquid_step_$ID$():\n\
     mantaMsg('Liquid step low')\n\
     # FLIP\n\
-    # Create interpolated version of original phi grid for later use in (optional) high-res step\n\
-    if using_highres_s$ID$:\n\
-        interpolateGrid(target=phi_xl$ID$, source=phi_s$ID$)\n\
+    mantaMsg('Adding object velocity')\n\
+    # ensure velocities inside of obs object, slightly add obvels outside of obs object\n\
+    extrapolateVec3Simple(vel=obvel_s$ID$, phi=phiObsIn_s$ID$, distance=int(res_s$ID$/2), inside=True)\n\
+    extrapolateVec3Simple(vel=obvel_s$ID$, phi=phiObsIn_s$ID$, distance=obvelBorderWidth_s$ID$, inside=False)\n\
+    setObstacleVelocity(flags=flags_s$ID$, vel=vel_s$ID$, obvel=obvel_s$ID$, borderWidth=obvelBorderWidth_s$ID$-1)\n\
     \n\
     pp_s$ID$.advectInGrid(flags=flags_s$ID$, vel=vel_s$ID$, integrationMode=IntRK4, deleteInObstacle=False, stopInObstacle=False)\n\
     pushOutofObs(parts=pp_s$ID$, flags=flags_s$ID$, phiObs=phiObs_s$ID$)\n\
@@ -202,6 +207,10 @@ def liquid_step_$ID$():\n\
     advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=phi_s$ID$, order=1, openBounds=doOpen_s$ID$, boundaryWidth=boundaryWidth_s$ID$) # first order is usually enough\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\
+    # Create interpolated version of original phi grid for later use in (optional) high-res step\n\
+    if using_highres_s$ID$:\n\
+        interpolateGrid(target=phi_xl$ID$, source=phi_s$ID$)\n\
+    \n\
     # create level set of particles\n\
     gridParticleIndex(parts=pp_s$ID$, flags=flags_s$ID$, indexSys=pindex_s$ID$, index=gpi_s$ID$)\n\
     unionParticleLevelset(pp_s$ID$, pindex_s$ID$, flags_s$ID$, gpi_s$ID$, phiParts_s$ID$)\n\
@@ -234,10 +243,6 @@ def liquid_step_$ID$():\n\
     extrapolateMACSimple(flags=flags_s$ID$, vel=vel_s$ID$, distance=4, intoObs=True)\n\
     setWallBcs(flags=flags_s$ID$, vel=vel_s$ID$, fractions=fractions_s$ID$, phiObs=phiObs_s$ID$)\n\
     \n\
-    clearInObstacle(flags=flags_s$ID$, grid=phi_s$ID$)\n\
-    clearInObstacle(flags=flags_s$ID$, grid=phiParts_s$ID$)\n\
-    pushOutofObs(parts=pp_s$ID$, flags=flags_s$ID$, phiObs=phiObs_s$ID$)\n\
-    \n\
     if (dim_s$ID$==3):\n\
         # mis-use phiParts as temp grid to close the mesh\n\
         phiParts_s$ID$.copyFrom(phi_s$ID$)\n\
diff --git a/intern/mantaflow/intern/strings/shared_script.h b/intern/mantaflow/intern/strings/shared_script.h
index 212d9ecf660..a899e850087 100644
--- a/intern/mantaflow/intern/strings/shared_script.h
+++ b/intern/mantaflow/intern/strings/shared_script.h
@@ -63,9 +63,10 @@ if dim_s$ID$ == 2:\n\
     gs_s$ID$.z    = 1\n\
     gravity_s$ID$ = vec3($GRAVITY_X$,$GRAVITY_Z$,0)\n\
 \n\
-doOpen_s$ID$          = $DO_OPEN$\n\
-boundConditions_s$ID$ = '$BOUNDCONDITIONS$'\n\
-boundaryWidth_s$ID$   = 1\n\
+doOpen_s$ID$              = $DO_OPEN$\n\
+boundConditions_s$ID$     = '$BOUNDCONDITIONS$'\n\
+boundaryWidth_s$ID$       = 1\n\
+obvelBorderWidth_s$ID$    = 2\n\
 \n\
 using_highres_s$ID$   = $USING_HIGHRES$\n\
 using_adaptTime_s$ID$ = True # adaptive time stepping disabled for now\n";
@@ -91,7 +92,7 @@ s$ID$.frameLength = dt0_s$ID$\n\
 s$ID$.timestepMin = dt0_s$ID$ / 10\n\
 s$ID$.timestepMax = dt0_s$ID$\n\
 s$ID$.cfl         = 4.0\n\
-s$ID$.timestep    = dt0_s$ID$\n";
+s$ID$.timestep    = (s$ID$.timestepMax+s$ID$.timestepMin)*0.5\n";
 
 const std::string fluid_adaptive_time_stepping_high = "\n\
 mantaMsg('Adaptive time stepping high')\n\
@@ -106,17 +107,18 @@ xl$ID$.cfl         = s$ID$.cfl\n";
 
 const std::string fluid_delete_variables_low = "\n\
 mantaMsg('Deleting fluid variables low')\n\
-if 'dim_s$ID$'             in globals() : del dim_s$ID$\n\
-if 'res_s$ID$'             in globals() : del res_s$ID$\n\
-if 'gs_s$ID$'              in globals() : del gs_s$ID$\n\
-if 'gravity_s$ID$'         in globals() : del gravity_s$ID$\n\
-if 'doOpen_s$ID$'          in globals() : del doOpen_s$ID$\n\
-if 'boundConditions_s$ID$' in globals() : del boundConditions_s$ID$\n\
-if 'boundaryWidth_s$ID$'   in globals() : del boundaryWidth_s$ID$\n\
-if 'dt_default_s$ID$'      in globals() : del dt_default_s$ID$\n\
-if 'dt_factor_s$ID$'       in globals() : del dt_factor_s$ID$\n\
-if 'fps_s$ID$'             in globals() : del fps_s$ID$\n\
-if 'dt0_s$ID$'             in globals() : del dt0_s$ID$\n";
+if 'dim_s$ID$'              in globals() : del dim_s$ID$\n\
+if 'res_s$ID$'              in globals() : del res_s$ID$\n\
+if 'gs_s$ID$'               in globals() : del gs_s$ID$\n\
+if 'gravity_s$ID$'          in globals() : del gravity_s$ID$\n\
+if 'doOpen_s$ID$'           in globals() : del doOpen_s$ID$\n\
+if 'boundConditions_s$ID$'  in globals() : del boundConditions_s$ID$\n\
+if 'boundaryWidth_s$ID$'    in globals() : del boundaryWidth_s$ID$\n\
+if 'dt_default_s$ID$'       in globals() : del dt_default_s$ID$\n\
+if 'dt_factor_s$ID$'        in globals() : del dt_factor_s$ID$\n\
+if 'fps_s$ID$'              in globals() : del fps_s$ID$\n\
+if 'dt0_s$ID$'              in globals() : del dt0_s$ID$\n\
+if 'obvelBorderWidth_s$ID$' in globals() : del obvelBorderWidth_s$ID$";
 
 const std::string fluid_delete_variables_high = "\n\
 mantaMsg('Deleting fluid variables high')\n\
diff --git a/intern/mantaflow/intern/strings/smoke_script.h b/intern/mantaflow/intern/strings/smoke_script.h
index 412d7b2d067..0d78c45b38a 100644
--- a/intern/mantaflow/intern/strings/smoke_script.h
+++ b/intern/mantaflow/intern/strings/smoke_script.h
@@ -58,8 +58,7 @@ mantaMsg('Smoke variables low')\n\
 using_colors_s$ID$    = $USING_COLORS$\n\
 using_heat_s$ID$      = $USING_HEAT$\n\
 using_fire_s$ID$      = $USING_FIRE$\n\
-vorticity_s$ID$       = $VORTICITY$\n\
-obvel_border_s$ID$    = 2\n";
+vorticity_s$ID$       = $VORTICITY$\n";
 
 const std::string smoke_variables_high = "\n\
 mantaMsg('Smoke variables high')\n\
@@ -94,7 +93,7 @@ vel_s$ID$         = s$ID$.create(MACGrid)\n\
 x_vel_s$ID$       = s$ID$.create(RealGrid)\n\
 y_vel_s$ID$       = s$ID$.create(RealGrid)\n\
 z_vel_s$ID$       = s$ID$.create(RealGrid)\n\
-obvel_s$ID$       = s$ID$.create(MACGrid)\n\
+obvel_s$ID$       = s$ID$.create(Vec3Grid)\n\
 x_obvel_s$ID$     = s$ID$.create(RealGrid)\n\
 y_obvel_s$ID$     = s$ID$.create(RealGrid)\n\
 z_obvel_s$ID$     = s$ID$.create(RealGrid)\n\
@@ -254,25 +253,11 @@ def step_low_$ID$():\n\
     setObstacleFlags(flags=flags_s$ID$, phiObs=phiObsIn_s$ID$, fractions=fractions_s$ID$, phiOut=phiOut_s$ID$)\n\
     flags_s$ID$.fillGrid()\n\
     \n\
-    mantaMsg('Clearing cells')\n\
-    clearInObstacle(flags=flags_s$ID$, grid=density_s$ID$)\n\
-    clearInObstacle(flags=flags_s$ID$, grid=vel_s$ID$)\n\
-    clearInObstacle(flags=flags_s$ID$, grid=pressure_s$ID$)\n\
-    if (using_fire_s$ID$):\n\
-        clearInObstacle(flags=flags_s$ID$, grid=fuel_s$ID$)\n\
-        clearInObstacle(flags=flags_s$ID$, grid=flame_s$ID$)\n\
-        clearInObstacle(flags=flags_s$ID$, grid=react_s$ID$)\n\
-    if (using_colors_s$ID$):\n\
-        clearInObstacle(flags=flags_s$ID$, grid=color_r_s$ID$)\n\
-        clearInObstacle(flags=flags_s$ID$, grid=color_g_s$ID$)\n\
-        clearInObstacle(flags=flags_s$ID$, grid=color_b_s$ID$)\n\
-    \n\
     mantaMsg('Adding object velocity')\n\
-    averageGrid(grid=obvel_s$ID$, num=numObs_s$ID$)\n\
     # ensure velocities inside of obs object, slightly add obvels outside of obs object\n\
     extrapolateVec3Simple(vel=obvel_s$ID$, phi=phiObsIn_s$ID$, distance=int(res_s$ID$/2), inside=True)\n\
-    extrapolateVec3Simple(vel=obvel_s$ID$, phi=phiObsIn_s$ID$, distance=obvel_border_s$ID$, inside=False)\n\
-    setObstacleVelocity(flags=flags_s$ID$, vel=vel_s$ID$, obvel=obvel_s$ID$, borderWidth=obvel_border_s$ID$-1)\n\
+    extrapolateVec3Simple(vel=obvel_s$ID$, phi=phiObsIn_s$ID$, distance=obvelBorderWidth_s$ID$, inside=False)\n\
+    setObstacleVelocity(flags=flags_s$ID$, vel=vel_s$ID$, obvel=obvel_s$ID$, borderWidth=obvelBorderWidth_s$ID$-1)\n\
     \n\
     mantaMsg('Advecting density')\n\
     advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=density_s$ID$, order=$ADVECT_ORDER$)\n\
@@ -320,7 +305,7 @@ def step_low_$ID$():\n\
     setWallBcs(flags=flags_s$ID$, vel=vel_s$ID$)\n\
     \n\
     mantaMsg('Pressure')\n\
-    solvePressure(flags=flags_s$ID$, vel=vel_s$ID$, pressure=pressure_s$ID$, preconditioner=$PRECONDITIONER$)\n\
+    solvePressure(flags=flags_s$ID$, vel=vel_s$ID$, pressure=pressure_s$ID$)\n\
  

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list