[Bf-blender-cvs] [97ec16d68f3] master: Fluid: Refactor for initial velocities

Sebastián Barschkis noreply at git.blender.org
Tue Sep 22 14:04:40 CEST 2020


Commit: 97ec16d68f3cf0f81b3de52a7b7c51b8977e943c
Author: Sebastián Barschkis
Date:   Tue Sep 22 11:39:25 2020 +0200
Branches: master
https://developer.blender.org/rB97ec16d68f3cf0f81b3de52a7b7c51b8977e943c

Fluid: Refactor for initial velocities

Removed invel MAC grid since it is sufficient to use the cell centered vec3 representation. When setting initial velocities these will be interpolated by the setter functions.

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

M	intern/mantaflow/intern/MANTA_main.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
M	source/blender/makesdna/DNA_fluid_types.h

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

diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp
index 9d5b3efb0bc..cc702b82151 100644
--- a/intern/mantaflow/intern/MANTA_main.cpp
+++ b/intern/mantaflow/intern/MANTA_main.cpp
@@ -907,7 +907,6 @@ void MANTA::initializeRNAMap(FluidModifierData *fmd)
   mRNAMap["NAME_OBVEL_Z"] = FLUID_NAME_OBVEL_Z;
   mRNAMap["NAME_FRACTIONS"] = FLUID_NAME_FRACTIONS;
   mRNAMap["NAME_INVELC"] = FLUID_NAME_INVELC;
-  mRNAMap["NAME_INVEL"] = FLUID_NAME_INVEL;
   mRNAMap["NAME_INVEL_X"] = FLUID_NAME_INVEL_X;
   mRNAMap["NAME_INVEL_Y"] = FLUID_NAME_INVEL_Y;
   mRNAMap["NAME_INVEL_Z"] = FLUID_NAME_INVEL_Z;
diff --git a/intern/mantaflow/intern/strings/fluid_script.h b/intern/mantaflow/intern/strings/fluid_script.h
index 41816648dd3..73b92a76ec4 100644
--- a/intern/mantaflow/intern/strings/fluid_script.h
+++ b/intern/mantaflow/intern/strings/fluid_script.h
@@ -343,7 +343,6 @@ const std::string fluid_alloc_invel =
     "\n\
 mantaMsg('Allocating initial velocity data')\n\
 invelC_s$ID$  = s$ID$.create(VecGrid, name='$NAME_INVELC$')\n\
-invel_s$ID$   = s$ID$.create(MACGrid, name='$NAME_INVEL$')\n\
 x_invel_s$ID$ = s$ID$.create(RealGrid, name='$NAME_INVEL_X$')\n\
 y_invel_s$ID$ = s$ID$.create(RealGrid, name='$NAME_INVEL_Y$')\n\
 z_invel_s$ID$ = s$ID$.create(RealGrid, name='$NAME_INVEL_Z$')\n";
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index cef1483657a..13b8c0a9c78 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -177,6 +177,13 @@ def liquid_adaptive_step_$ID$(framenr):\n\
     flags_s$ID$.initDomain(boundaryWidth=1 if using_fractions_s$ID$ else 0, phiWalls=phiObs_s$ID$, outflow=boundConditions_s$ID$)\n\
     \n\
     if using_obstacle_s$ID$:\n\
+        mantaMsg('Extrapolating object velocity')\n\
+        # ensure velocities inside of obs object, slightly add obvels outside of obs object\n\
+        # extrapolate with phiObsIn before joining (static) phiObsSIn grid to prevent flows into static obs\n\
+        extrapolateVec3Simple(vel=obvelC_s$ID$, phi=phiObsIn_s$ID$, distance=6, inside=True)\n\
+        extrapolateVec3Simple(vel=obvelC_s$ID$, phi=phiObsIn_s$ID$, distance=3, inside=False)\n\
+        resampleVec3ToMac(source=obvelC_s$ID$, target=obvel_s$ID$)\n\
+        \n\
         mantaMsg('Initializing obstacle levelset')\n\
         phiObsIn_s$ID$.join(phiObsSIn_s$ID$) # Join static obstacle map\n\
         phiObsIn_s$ID$.fillHoles(maxDepth=int(res_s$ID$), boundaryWidth=1)\n\
@@ -211,8 +218,8 @@ def liquid_adaptive_step_$ID$(framenr):\n\
     # add initial velocity: set invel as source grid to ensure const vels in inflow region, sampling makes use of this\n\
     if using_invel_s$ID$:\n\
         extrapolateVec3Simple(vel=invelC_s$ID$, phi=phiIn_s$ID$, distance=6, inside=True)\n\
-        resampleVec3ToMac(source=invelC_s$ID$, target=invel_s$ID$)\n\
-        pVel_pp$ID$.setSource(grid=invel_s$ID$, isMAC=True)\n\
+        # Using cell centered invels, a false isMAC flag ensures correct interpolation\n\
+        pVel_pp$ID$.setSource(grid=invelC_s$ID$, isMAC=False)\n\
     # reset pvel grid source before sampling new particles - ensures that new particles are initialized with 0 velocity\n\
     else:\n\
         pVel_pp$ID$.setSource(grid=None, isMAC=False)\n\
@@ -275,13 +282,6 @@ def liquid_step_$ID$():\n\
     mantaMsg('Adding external forces')\n\
     addForceField(flags=flags_s$ID$, vel=vel_s$ID$, force=forces_s$ID$)\n\
     \n\
-    if using_obstacle_s$ID$:\n\
-        mantaMsg('Extrapolating object velocity')\n\
-        # ensure velocities inside of obs object, slightly add obvels outside of obs object\n\
-        extrapolateVec3Simple(vel=obvelC_s$ID$, phi=phiObsIn_s$ID$, distance=6, inside=True)\n\
-        extrapolateVec3Simple(vel=obvelC_s$ID$, phi=phiObsIn_s$ID$, distance=3, inside=False)\n\
-        resampleVec3ToMac(source=obvelC_s$ID$, target=obvel_s$ID$)\n\
-    \n\
     extrapolateMACSimple(flags=flags_s$ID$, vel=vel_s$ID$, distance=2, intoObs=True if using_fractions_s$ID$ else False)\n\
     \n\
     # vel diffusion / viscosity!\n\
diff --git a/intern/mantaflow/intern/strings/smoke_script.h b/intern/mantaflow/intern/strings/smoke_script.h
index f81259115c5..0d50a730b2d 100644
--- a/intern/mantaflow/intern/strings/smoke_script.h
+++ b/intern/mantaflow/intern/strings/smoke_script.h
@@ -280,6 +280,13 @@ def smoke_adaptive_step_$ID$(framenr):\n\
     flags_s$ID$.initDomain(boundaryWidth=0, phiWalls=phiObs_s$ID$, outflow=boundConditions_s$ID$)\n\
     \n\
     if using_obstacle_s$ID$:\n\
+        mantaMsg('Extrapolating object velocity')\n\
+        # ensure velocities inside of obs object, slightly add obvels outside of obs object\n\
+        # extrapolate with phiObsIn before joining (static) phiObsSIn grid to prevent flows into static obs\n\
+        extrapolateVec3Simple(vel=obvelC_s$ID$, phi=phiObsIn_s$ID$, distance=6, inside=True)\n\
+        extrapolateVec3Simple(vel=obvelC_s$ID$, phi=phiObsIn_s$ID$, distance=3, inside=False)\n\
+        resampleVec3ToMac(source=obvelC_s$ID$, target=obvel_s$ID$)\n\
+        \n\
         mantaMsg('Initializing obstacle levelset')\n\
         phiObsIn_s$ID$.join(phiObsSIn_s$ID$) # Join static obstacle map\n\
         phiObsIn_s$ID$.fillHoles(maxDepth=int(res_s$ID$), boundaryWidth=1)\n\
@@ -386,21 +393,14 @@ def smoke_step_$ID$():\n\
     mantaMsg('Adding forces')\n\
     addForceField(flags=flags_s$ID$, vel=vel_s$ID$, force=forces_s$ID$)\n\
     \n\
-    if using_obstacle_s$ID$:\n\
-        mantaMsg('Extrapolating object velocity')\n\
-        # ensure velocities inside of obs object, slightly add obvels outside of obs object\n\
-        extrapolateVec3Simple(vel=obvelC_s$ID$, phi=phiObsIn_s$ID$, distance=6, inside=True)\n\
-        extrapolateVec3Simple(vel=obvelC_s$ID$, phi=phiObsIn_s$ID$, distance=3, inside=False)\n\
-        resampleVec3ToMac(source=obvelC_s$ID$, target=obvel_s$ID$)\n\
-    \n\
     # Cells inside obstacle should not contain any density, fire, etc.\n\
     if deleteInObstacle_s$ID$:\n\
         resetInObstacle(flags=flags_s$ID$, density=density_s$ID$, vel=vel_s$ID$, heat=heat_s$ID$, fuel=fuel_s$ID$, flame=flame_s$ID$, red=color_r_s$ID$, green=color_g_s$ID$, blue=color_b_s$ID$)\n\
     \n\
     # add initial velocity\n\
     if using_invel_s$ID$:\n\
-        resampleVec3ToMac(source=invelC_s$ID$, target=invel_s$ID$)\n\
-        setInitialVelocity(flags=flags_s$ID$, vel=vel_s$ID$, invel=invel_s$ID$)\n\
+        # Using cell centered invels, will be converted to MAC within the function\n\
+        setInitialVelocity(flags=flags_s$ID$, vel=vel_s$ID$, invel=invelC_s$ID$)\n\
     \n\
     mantaMsg('Walls')\n\
     setWallBcs(flags=flags_s$ID$, vel=vel_s$ID$, obvel=obvel_s$ID$ if using_obstacle_s$ID$ else None)\n\
diff --git a/source/blender/makesdna/DNA_fluid_types.h b/source/blender/makesdna/DNA_fluid_types.h
index 20d6cd8342f..8f67cd060e9 100644
--- a/source/blender/makesdna/DNA_fluid_types.h
+++ b/source/blender/makesdna/DNA_fluid_types.h
@@ -311,7 +311,6 @@ enum {
 #define FLUID_NAME_OBVEL_Z "z_obvel"
 #define FLUID_NAME_FRACTIONS "fractions"
 #define FLUID_NAME_INVELC "invelC"
-#define FLUID_NAME_INVEL "invel"
 #define FLUID_NAME_INVEL_X "x_invel"
 #define FLUID_NAME_INVEL_Y "y_invel"
 #define FLUID_NAME_INVEL_Z "z_invel"



More information about the Bf-blender-cvs mailing list