[Bf-blender-cvs] [76c1a91cfa5] master: Fluid: Fix for inconsistent behavior with flow and effector objects

Sebastián Barschkis noreply at git.blender.org
Sun Apr 19 21:16:03 CEST 2020


Commit: 76c1a91cfa5a96d4804b90c8ab8d3a92ad8ddd8c
Author: Sebastián Barschkis
Date:   Sun Apr 19 20:15:57 2020 +0200
Branches: master
https://developer.blender.org/rB76c1a91cfa5a96d4804b90c8ab8d3a92ad8ddd8c

Fluid: Fix for inconsistent behavior with flow and effector objects

Fixes issue with flow and effector objects which were not being used after resuming a bake job.
This issue has been reported in T75729 and T75758.

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

M	intern/mantaflow/extern/manta_fluid_API.h
M	intern/mantaflow/intern/MANTA_main.cpp
M	intern/mantaflow/intern/MANTA_main.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
M	source/blender/blenkernel/intern/fluid.c

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

diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 85cc04b4a52..7825ad14d7d 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -107,6 +107,7 @@ float *manta_get_phistatic_in(struct MANTA *fluid);
 float *manta_get_phiobs_in(struct MANTA *fluid);
 float *manta_get_phiobsstatic_in(struct MANTA *fluid);
 float *manta_get_phiout_in(struct MANTA *fluid);
+float *manta_get_phioutstatic_in(struct MANTA *fluid);
 
 /* Smoke functions */
 void manta_smoke_export_script(struct MANTA *smoke, struct FluidModifierData *mmd);
diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp
index 539e3080c54..a56ce4c1f60 100644
--- a/intern/mantaflow/intern/MANTA_main.cpp
+++ b/intern/mantaflow/intern/MANTA_main.cpp
@@ -141,6 +141,7 @@ MANTA::MANTA(int *res, FluidModifierData *mmd) : mCurrentID(++solverID)
   mPhiIn = nullptr;
   mPhiStaticIn = nullptr;
   mPhiOutIn = nullptr;
+  mPhiOutStaticIn = nullptr;
   mPhi = nullptr;
 
   // Mesh
@@ -1926,6 +1927,7 @@ void MANTA::exportSmokeScript(FluidModifierData *mmd)
   bool obstacle = mmd->domain->active_fields & FLUID_DOMAIN_ACTIVE_OBSTACLE;
   bool guiding = mmd->domain->active_fields & FLUID_DOMAIN_ACTIVE_GUIDE;
   bool invel = mmd->domain->active_fields & FLUID_DOMAIN_ACTIVE_INVEL;
+  bool outflow = mmd->domain->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW;
 
   std::string manta_script;
 
@@ -1968,6 +1970,8 @@ void MANTA::exportSmokeScript(FluidModifierData *mmd)
     manta_script += fluid_alloc_obstacle;
   if (invel)
     manta_script += fluid_alloc_invel;
+  if (outflow)
+    manta_script += fluid_alloc_outflow;
 
   // Noise field
   if (noise)
@@ -2032,6 +2036,7 @@ void MANTA::exportLiquidScript(FluidModifierData *mmd)
   bool fractions = mmd->domain->flags & FLUID_DOMAIN_USE_FRACTIONS;
   bool guiding = mmd->domain->active_fields & FLUID_DOMAIN_ACTIVE_GUIDE;
   bool invel = mmd->domain->active_fields & FLUID_DOMAIN_ACTIVE_INVEL;
+  bool outflow = mmd->domain->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW;
 
   std::string manta_script;
 
@@ -2070,6 +2075,8 @@ void MANTA::exportLiquidScript(FluidModifierData *mmd)
     manta_script += fluid_alloc_fractions;
   if (invel)
     manta_script += fluid_alloc_invel;
+  if (outflow)
+    manta_script += fluid_alloc_outflow;
 
   // Domain init
   manta_script += header_gridinit + liquid_init_phi;
@@ -3119,6 +3126,8 @@ void MANTA::updatePointers()
 
   if (mUsingOutflow) {
     mPhiOutIn = (float *)pyObjectToPointer(callPythonFunction("phiOutIn" + solver_ext, func));
+    mPhiOutStaticIn = (float *)pyObjectToPointer(
+        callPythonFunction("phiOutSIn" + solver_ext, func));
   }
   if (mUsingObstacle) {
     mPhiObsIn = (float *)pyObjectToPointer(callPythonFunction("phiObsIn" + solver_ext, func));
@@ -3230,7 +3239,7 @@ bool MANTA::hasConfig(FluidModifierData *mmd, int framenr)
 
 bool MANTA::hasData(FluidModifierData *mmd, int framenr)
 {
-  std::string filename = (mUsingSmoke) ? FLUID_DOMAIN_FILE_DENSITY : FLUID_DOMAIN_FILE_PHI;
+  std::string filename = (mUsingSmoke) ? FLUID_DOMAIN_FILE_DENSITY : FLUID_DOMAIN_FILE_PP;
   std::string extension = getCacheFileEnding(mmd->domain->cache_data_format);
   return BLI_exists(getFile(mmd, FLUID_DOMAIN_DIR_DATA, filename, extension, framenr).c_str());
 }
diff --git a/intern/mantaflow/intern/MANTA_main.h b/intern/mantaflow/intern/MANTA_main.h
index caac63d8e39..21946431f28 100644
--- a/intern/mantaflow/intern/MANTA_main.h
+++ b/intern/mantaflow/intern/MANTA_main.h
@@ -405,6 +405,10 @@ struct MANTA {
   {
     return mPhiOutIn;
   }
+  inline float *getPhiOutStaticIn()
+  {
+    return mPhiOutStaticIn;
+  }
   inline float *getPhi()
   {
     return mPhi;
@@ -844,6 +848,7 @@ struct MANTA {
   float *mPhiObsStaticIn;
   float *mPhiGuideIn;
   float *mPhiOutIn;
+  float *mPhiOutStaticIn;
   float *mPhi;
 
   // Mesh fields
diff --git a/intern/mantaflow/intern/manta_fluid_API.cpp b/intern/mantaflow/intern/manta_fluid_API.cpp
index b4582051c3c..49bc224b3fa 100644
--- a/intern/mantaflow/intern/manta_fluid_API.cpp
+++ b/intern/mantaflow/intern/manta_fluid_API.cpp
@@ -390,6 +390,10 @@ float *manta_get_phiout_in(MANTA *fluid)
 {
   return fluid->getPhiOutIn();
 }
+float *manta_get_phioutstatic_in(MANTA *fluid)
+{
+  return fluid->getPhiOutStaticIn();
+}
 
 /* Smoke functions */
 void manta_smoke_export_script(MANTA *smoke, FluidModifierData *mmd)
diff --git a/intern/mantaflow/intern/strings/fluid_script.h b/intern/mantaflow/intern/strings/fluid_script.h
index e81a44109ef..dd2111db7d7 100644
--- a/intern/mantaflow/intern/strings/fluid_script.h
+++ b/intern/mantaflow/intern/strings/fluid_script.h
@@ -261,7 +261,7 @@ const std::string fluid_alloc_obstacle =
     "\n\
 mantaMsg('Allocating obstacle data')\n\
 numObs_s$ID$     = s$ID$.create(RealGrid)\n\
-phiObsSIn_s$ID$  = s$ID$.create(LevelsetGrid) # helper for static obstacles\n\
+phiObsSIn_s$ID$  = s$ID$.create(LevelsetGrid) # helper for static obstacle objects\n\
 phiObsIn_s$ID$   = s$ID$.create(LevelsetGrid)\n\
 obvel_s$ID$      = s$ID$.create(MACGrid)\n\
 obvelC_s$ID$     = s$ID$.create(Vec3Grid)\n\
@@ -311,7 +311,15 @@ 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";
+phiOutSIn_s$ID$ = s$ID$.create(LevelsetGrid) # helper for static outflow objects\n\
+phiOutIn_s$ID$  = s$ID$.create(LevelsetGrid)\n\
+\n\
+# Set some initial values\n\
+phiOutSIn_s$ID$.setConst(9999)\n\
+phiOutIn_s$ID$.setConst(9999)\n\
+\n\
+if 'fluid_data_dict_resume_s$ID$' in globals():\n\
+    fluid_data_dict_resume_s$ID$.update(phiOutIn=phiOutIn_s$ID$)\n";
 
 //////////////////////////////////////////////////////////////////////
 // PRE / POST STEP
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index 34994f115d7..f20b218427c 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -191,6 +191,7 @@ def liquid_adaptive_step_$ID$(framenr):\n\
     phi_s$ID$.join(phiIn_s$ID$)\n\
     \n\
     if using_outflow_s$ID$:\n\
+        phiOutIn_s$ID$.join(phiOutSIn_s$ID$) # Join static outflow map\n\
         phiOut_s$ID$.join(phiOutIn_s$ID$)\n\
     \n\
     if using_fractions_s$ID$:\n\
@@ -206,6 +207,9 @@ def liquid_adaptive_step_$ID$(framenr):\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(invel_s$ID$, isMAC=True)\n\
+    # ensure that pvel has vel as source (important when resuming bake jobs)\n\
+    else:\n\
+        pVel_pp$ID$.setSource(vel_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$)\n\
     flags_s$ID$.updateFromLevelset(phi_s$ID$)\n\
@@ -363,7 +367,7 @@ def liquid_step_particles_$ID$():\n\
         interpolateGrid(target=phiOut_sp$ID$, source=phiOut_s$ID$)\n\
     \n\
     # phiIn not needed, bwidth to 0 because we are omitting flags.initDomain()\n\
-    setObstacleFlags(flags=flags_sp$ID$, phiObs=phiObs_sp$ID$, phiOut=None, phiIn=None, boundaryWidth=0)\n\
+    setObstacleFlags(flags=flags_sp$ID$, phiObs=phiObs_sp$ID$, phiOut=phiOut_sp$ID$, phiIn=None, boundaryWidth=0)\n\
     flags_sp$ID$.updateFromLevelset(levelset=phi_sp$ID$)\n\
     \n\
     # Actual secondary particle simulation\n\
diff --git a/intern/mantaflow/intern/strings/smoke_script.h b/intern/mantaflow/intern/strings/smoke_script.h
index cb651eb40b3..146106fd147 100644
--- a/intern/mantaflow/intern/strings/smoke_script.h
+++ b/intern/mantaflow/intern/strings/smoke_script.h
@@ -296,6 +296,7 @@ def smoke_adaptive_step_$ID$(framenr):\n\
     extrapolateLsSimple(phi=phiIn_s$ID$, distance=3, inside=False)\n\
     \n\
     if using_outflow_s$ID$:\n\
+        phiOutIn_s$ID$.join(phiOutSIn_s$ID$) # Join static outflow map\n\
         phiOut_s$ID$.join(phiOutIn_s$ID$)\n\
     \n\
     setObstacleFlags(flags=flags_s$ID$, phiObs=phiObs_s$ID$, phiOut=phiOut_s$ID$, phiIn=phiIn_s$ID$, boundaryWidth=1)\n\
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index 578a6a13bb7..08b5b788afd 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -1192,32 +1192,50 @@ static void update_obstacleflags(FluidDomainSettings *mds,
   mds->active_fields = active_fields;
 }
 
-static void update_obstacles(Depsgraph *depsgraph,
-                             Scene *scene,
-                             Object *ob,
-                             FluidDomainSettings *mds,
-                             float time_per_frame,
-                             float frame_length,
-                             int frame,
-                             float dt)
+static bool escape_effectorobject(Object *flowobj,
+                                  FluidDomainSettings *mds,
+                                  FluidEffectorSettings *mes,
+                                  int frame)
 {
-  FluidObjectBB *bb_maps = NULL;
-  Object **effecobjs = NULL;
-  uint numeffecobjs = 0, effec_index = 0;
-  bool is_first_frame = (frame == mds->cache_frame_start);
+  bool is_static = is_static_object(flowobj);
 
-  effecobjs = BKE_collision_objects_create(
-      depsgraph, ob, mds->effector_group, &numeffecobjs, eModifierType_Fluid);
+  bool use_effector = (mes->flags & FLUID_EFFECTOR_USE_EFFEC);
 
-  /* Update all effector related flags and ensure that corresponding grids get initialized. */
-  update_obstacleflags(mds, ob, effecobjs, numeffecobjs);
-  ensure_obstaclefields(mds);
+  bool is_resume = (mds->cache_frame_pause_data == frame);
+  bool is_adaptive = (mds->flags & FLUID_DOMAIN_USE_ADAPTIVE_DOMAIN);
+  bool is_first_frame = (frame == mds->cache_frame_start);
 
-  /* Initialize effector maps for each flow. */
-  bb_maps = MEM_callocN(sizeof(struct FluidObjectBB) * numeffecobjs, "fluid_effector_bb_maps");
+  /* Cannot use static mode wit

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list