[Bf-blender-cvs] [bfb2f4db1af] fluid-mantaflow: Mantaflow: Implemented adaptive domain for manta smoke

Sebastián Barschkis noreply at git.blender.org
Sun May 19 22:01:57 CEST 2019


Commit: bfb2f4db1af037336b9476c2acedd79fa9b71e02
Author: Sebastián Barschkis
Date:   Sun May 19 21:04:04 2019 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rBbfb2f4db1af037336b9476c2acedd79fa9b71e02

Mantaflow: Implemented adaptive domain for manta smoke

This functionality exists in the vanilla build already but had to be disabled in the manta build. Now it is back.

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

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/smoke_script.h
M	release/scripts/startup/bl_ui/properties_physics_smoke.py
M	source/blender/blenkernel/BKE_smoke.h
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/blenkernel/intern/smoke.c
M	source/blender/draw/modes/object_mode.c
M	source/blender/editors/physics/physics_manta.c
M	source/blender/makesdna/DNA_smoke_types.h

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

diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index dab80f3d7f1..51bee4fd96b 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -43,7 +43,9 @@ 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_config(struct FLUID *fluid, struct SmokeModifierData *smd, int framenr);
 int fluid_write_data(struct FLUID *fluid, struct SmokeModifierData *smd, int framenr);
+int fluid_read_config(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);
 int fluid_read_mesh(struct FLUID *fluid, struct SmokeModifierData *smd, int framenr);
@@ -68,6 +70,7 @@ void fluid_update_variables(struct FLUID *fluid, struct SmokeModifierData *smd);
 int fluid_get_frame(struct FLUID *fluid);
 float fluid_get_timestep(struct FLUID *fluid);
 void fluid_adapt_timestep(struct FLUID *fluid);
+bool fluid_needs_realloc(struct FLUID *fluid, struct SmokeModifierData *smd);
 
 /* Fluid accessors */
 size_t fluid_get_index(int x, int max_x, int y, int max_y, int z /*, int max_z */);
@@ -116,7 +119,8 @@ void smoke_export(struct FLUID *smoke,
                   float **g,
                   float **b,
                   int **obstacles,
-                  float **shadow);
+                  float **shadow,
+                  float **phiin);
 void smoke_turbulence_export(struct FLUID *smoke,
                              float **dens,
                              float **react,
diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index fc3f1045c08..bbb67cc5cc4 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -1111,6 +1111,53 @@ static std::string escapeSlashes(std::string const &s)
   return result;
 }
 
+int FLUID::writeConfiguration(SmokeModifierData *smd, int framenr)
+{
+  if (with_debug)
+    std::cout << "FLUID::writeConfiguration()" << std::endl;
+
+  SmokeDomainSettings *sds = smd->domain;
+  std::ostringstream ss;
+  char cacheDir[FILE_MAX], targetFile[FILE_MAX];;
+  cacheDir[0] = '\0';
+  targetFile[0] = '\0';
+
+  std::string dformat = getCacheFileEnding(smd->domain->cache_data_format);
+
+  BLI_path_join(cacheDir,
+                sizeof(cacheDir),
+                smd->domain->cache_directory,
+                FLUID_DOMAIN_DIR_CONFIG,
+                NULL);
+  BLI_path_make_safe(cacheDir);
+  ss << "config_####" << dformat;
+  BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
+  BLI_path_frame(targetFile, framenr, 0);
+
+  gzFile gzf = gzopen(targetFile, "wb1"); // do some compression
+  if (!gzf)
+    std::cerr << "writeConfiguration: can't open file: " << targetFile << std::endl;
+
+  gzwrite(gzf, &sds->active_fields, sizeof(int));
+  gzwrite(gzf, &sds->res, 3*sizeof(int));
+  gzwrite(gzf, &sds->dx, sizeof(float));
+  gzwrite(gzf, &sds->dt, sizeof(float));
+  gzwrite(gzf, &sds->p0, 3*sizeof(float));
+  gzwrite(gzf, &sds->p1, 3*sizeof(float));
+  gzwrite(gzf, &sds->dp0, 3*sizeof(float));
+  gzwrite(gzf, &sds->shift, 3*sizeof(int));
+  gzwrite(gzf, &sds->obj_shift_f, 3*sizeof(float));
+  gzwrite(gzf, &sds->obmat, 16*sizeof(float));
+  gzwrite(gzf, &sds->base_res, 3*sizeof(int));
+  gzwrite(gzf, &sds->res_min, 3*sizeof(int));
+  gzwrite(gzf, &sds->res_max, 3*sizeof(int));
+  gzwrite(gzf, &sds->active_color, 3*sizeof(float));
+
+  gzclose(gzf);
+
+  return 1;
+}
+
 int FLUID::writeData(SmokeModifierData *smd, int framenr)
 {
   if (with_debug)
@@ -1156,6 +1203,57 @@ int FLUID::writeData(SmokeModifierData *smd, int framenr)
   return 1;
 }
 
+int FLUID::readConfiguration(SmokeModifierData *smd, int framenr)
+{
+  if (with_debug)
+    std::cout << "FLUID::readConfiguration()" << std::endl;
+
+  SmokeDomainSettings *sds = smd->domain;
+  std::ostringstream ss;
+  char cacheDir[FILE_MAX], targetFile[FILE_MAX];;
+  cacheDir[0] = '\0';
+  targetFile[0] = '\0';
+
+  std::string dformat = getCacheFileEnding(smd->domain->cache_data_format);
+
+  BLI_path_join(cacheDir,
+                sizeof(cacheDir),
+                smd->domain->cache_directory,
+                FLUID_DOMAIN_DIR_CONFIG,
+                NULL);
+  BLI_path_make_safe(cacheDir);
+
+  if (!BLI_exists(cacheDir))
+    return 0;
+
+  ss << "config_####" << dformat;
+  BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
+  BLI_path_frame(targetFile, framenr, 0);
+
+  gzFile gzf = gzopen(targetFile, "rb"); // do some compression
+  if (!gzf)
+    std::cerr << "readConfiguration: can't open file: " << targetFile << std::endl;
+
+  gzread(gzf, &sds->active_fields, sizeof(int));
+  gzread(gzf, &sds->res, 3*sizeof(int));
+  gzread(gzf, &sds->dx, sizeof(float));
+  gzread(gzf, &sds->dt, sizeof(float));
+  gzread(gzf, &sds->p0, 3*sizeof(float));
+  gzread(gzf, &sds->p1, 3*sizeof(float));
+  gzread(gzf, &sds->dp0, 3*sizeof(float));
+  gzread(gzf, &sds->shift, 3*sizeof(int));
+  gzread(gzf, &sds->obj_shift_f, 3*sizeof(float));
+  gzread(gzf, &sds->obmat, 16*sizeof(float));
+  gzread(gzf, &sds->base_res, 3*sizeof(int));
+  gzread(gzf, &sds->res_min, 3*sizeof(int));
+  gzread(gzf, &sds->res_max, 3*sizeof(int));
+  gzread(gzf, &sds->active_color, 3*sizeof(float));
+  sds->total_cells = sds->res[0] * sds->res[1] * sds->res[2];
+
+  gzclose(gzf);
+  return 1;
+}
+
 int FLUID::readData(SmokeModifierData *smd, int framenr)
 {
   if (with_debug)
@@ -1834,6 +1932,12 @@ float FLUID::getTimestep()
   return pyObjectToDouble(callPythonFunction(solver, func, true));
 }
 
+bool FLUID::needsRealloc(SmokeModifierData *smd)
+{
+  SmokeDomainSettings *sds = smd->domain;
+  return (sds->res[0] != mResX || sds->res[1] != mResY || sds->res[2] != mResZ);
+}
+
 void FLUID::adaptTimestep()
 {
   if (with_debug)
diff --git a/intern/mantaflow/intern/FLUID.h b/intern/mantaflow/intern/FLUID.h
index bb9330b43a6..d3de662e0a2 100644
--- a/intern/mantaflow/intern/FLUID.h
+++ b/intern/mantaflow/intern/FLUID.h
@@ -82,10 +82,12 @@ struct FLUID {
   void updatePointersNoise();
 
   // Write cache
+  int writeConfiguration(SmokeModifierData *smd, int framenr);
   int writeData(SmokeModifierData *smd, int framenr);
   // write call for noise, mesh and particles were left in bake calls for now
 
   // Read cache (via Manta save/load)
+  int readConfiguration(SmokeModifierData *smd, int framenr);
   int readData(SmokeModifierData *smd, int framenr);
   int readNoise(SmokeModifierData *smd, int framenr);
   int readMesh(SmokeModifierData *smd, int framenr);
@@ -628,6 +630,8 @@ struct FLUID {
   float getTimestep();
   void adaptTimestep();
 
+  bool needsRealloc(SmokeModifierData *smd);
+
  private:
   // simulation constants
   size_t mTotalCells;
diff --git a/intern/mantaflow/intern/manta_fluid_API.cpp b/intern/mantaflow/intern/manta_fluid_API.cpp
index 486c0a406d6..a73021fd73d 100644
--- a/intern/mantaflow/intern/manta_fluid_API.cpp
+++ b/intern/mantaflow/intern/manta_fluid_API.cpp
@@ -72,6 +72,13 @@ extern "C" void fluid_ensure_outflow(FLUID *fluid, struct SmokeModifierData *smd
   }
 }
 
+extern "C" int fluid_write_config(FLUID *fluid, SmokeModifierData *smd, int framenr)
+{
+  if (!fluid || !smd)
+    return 0;
+  return fluid->writeConfiguration(smd, framenr);
+}
+
 extern "C" int fluid_write_data(FLUID *fluid, SmokeModifierData *smd, int framenr)
 {
   if (!fluid || !smd)
@@ -79,6 +86,13 @@ extern "C" int fluid_write_data(FLUID *fluid, SmokeModifierData *smd, int framen
   return fluid->writeData(smd, framenr);
 }
 
+extern "C" int fluid_read_config(FLUID *fluid, SmokeModifierData *smd, int framenr)
+{
+  if (!fluid || !smd)
+    return 0;
+  return fluid->readConfiguration(smd, framenr);
+}
+
 extern "C" int fluid_read_data(FLUID *fluid, SmokeModifierData *smd, int framenr)
 {
   if (!fluid || !smd)
@@ -199,6 +213,13 @@ extern "C" void fluid_adapt_timestep(FLUID *fluid)
     fluid->adaptTimestep();
 }
 
+extern "C" bool fluid_needs_realloc(FLUID *fluid, SmokeModifierData *smd)
+{
+  if (fluid)
+    return fluid->needsRealloc(smd);
+  return false;
+}
+
 /* Fluid accessors */
 extern "C" size_t fluid_get_index(int x, int max_x, int y, int max_y, int z /*, int max_z */)
 {
@@ -416,7 +437,8 @@ extern "C" void smoke_export(FLUID *smoke,
                              float **g,
                              float **b,
                              int **obstacle,
-                             float **shadow)
+                             float **shadow,
+                             float **phiin)
 {
   if (dens)
     *dens = smoke->getDensity();
@@ -439,6 +461,8 @@ extern "C" void smoke_export(FLUID *smoke,
     *b = smoke->getColorB();
   *obstacle = smoke->getObstacle();
   *shadow = smoke->getShadow();
+  if (phiin)
+    *phiin = smoke->getPhiIn();
   *dt = 1;  //dummy value, not needed for smoke
   *dx = 1;  //dummy value, not needed for smoke
 }
diff --git a/intern/mantaflow/intern/strings/fluid_script.h b/intern/mantaflow/intern/strings/fluid_script.h
index 41df28f2fad..dbaa4b861a0 100644
--- a/intern/mantaflow/intern/strings/fluid_script.h
+++ b/intern/mantaflow/intern/strings/fluid_script.h
@@ -317,9 +317,11 @@ const std::string fluid_pre_step =
     "\n\
 def fluid_pre_step_$ID$():\n\
     mantaMsg('Fluid pre step')\n\
-    x_vel_s$ID$.clear()\n\
-    y_vel_s$ID$.clear()\n\
-    z_vel_s$ID$.clear()\n\
+    # TODO (sebbas): Not sure if copying into vel grid could have any weird side effects - long term will show\n\
+    #x_vel_s$ID$.clear()\n\
+    #y_vel_s$ID$.clear()\n\
+    #z_vel_s$ID$.clear()\n\
+    copyRealToVec3(sourceX=x_vel_s$ID$, sourceY=y_vel_s$ID$, sourceZ=z_vel_s$ID$, target=vel_s$ID$)\n\
     \n\
     # translate obvels (world space) to grid space\n\
     if using_obstacle_s$ID$:\n\
diff --git a/intern/mantaflow/intern/strings/smoke_script.h b/intern/mantaf

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list