[Bf-blender-cvs] [9a964c3f34a] fluid-mantaflow: Mantaflow: More manta / smoke renaming and added some sanity checks for the adaptive domain

Sebastián Barschkis noreply at git.blender.org
Thu Jul 18 23:55:27 CEST 2019


Commit: 9a964c3f34a938f08a5340df8155e85f5bfdddce
Author: Sebastián Barschkis
Date:   Sun Jun 23 17:51:05 2019 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB9a964c3f34a938f08a5340df8155e85f5bfdddce

Mantaflow: More manta / smoke renaming and added some sanity checks for the adaptive domain

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

M	intern/mantaflow/intern/MANTA_main.cpp
M	intern/mantaflow/intern/strings/fluid_script.h
M	source/blender/blenkernel/intern/manta.c

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

diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp
index 5fdcd352974..fb63b59240d 100644
--- a/intern/mantaflow/intern/MANTA_main.cpp
+++ b/intern/mantaflow/intern/MANTA_main.cpp
@@ -1136,6 +1136,8 @@ int MANTA::writeConfiguration(MantaModifierData *mmd, int framenr)
                 FLUID_DOMAIN_DIR_CONFIG,
                 NULL);
   BLI_path_make_safe(cacheDir);
+  BLI_dir_create_recursive(cacheDir); /* Create 'config' subdir if it does not exist already */
+
   ss << "config_####" << dformat;
   BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
   BLI_path_frame(targetFile, framenr, 0);
diff --git a/intern/mantaflow/intern/strings/fluid_script.h b/intern/mantaflow/intern/strings/fluid_script.h
index dbaa4b861a0..0c280a10e70 100644
--- a/intern/mantaflow/intern/strings/fluid_script.h
+++ b/intern/mantaflow/intern/strings/fluid_script.h
@@ -643,6 +643,8 @@ const std::string fluid_file_export =
 def fluid_file_export_s$ID$(dict, path, framenr, file_format, mode_override=True):\n\
     try:\n\
         framenr = fluid_cache_get_framenr_formatted_$ID$(framenr)\n\
+        if not os.path.exists(path):\n\
+            os.makedirs(path)\n\
         for name, object in dict.items():\n\
             file = os.path.join(path, name + '_' + framenr + file_format)\n\
             if not os.path.isfile(file) or mode_override: object.save(file)\n\
diff --git a/source/blender/blenkernel/intern/manta.c b/source/blender/blenkernel/intern/manta.c
index 2338bd94851..c32eac94a21 100644
--- a/source/blender/blenkernel/intern/manta.c
+++ b/source/blender/blenkernel/intern/manta.c
@@ -126,7 +126,7 @@ void BKE_manta_reallocate_fluid(MantaDomainSettings *mds, int res[3], int free_o
 }
 
 /* convert global position to domain cell space */
-static void manta_smoke_pos_to_cell(MantaDomainSettings *mds, float pos[3])
+static void manta_pos_to_cell(MantaDomainSettings *mds, float pos[3])
 {
   mul_m4_v3(mds->imat, pos);
   sub_v3_v3(pos, mds->p0);
@@ -136,7 +136,7 @@ static void manta_smoke_pos_to_cell(MantaDomainSettings *mds, float pos[3])
 }
 
 /* set domain transformations and base resolution from object mesh */
-static void manta_smoke_set_domain_from_mesh(MantaDomainSettings *mds,
+static void manta_set_domain_from_mesh(MantaDomainSettings *mds,
                                        Object *ob,
                                        Mesh *me,
                                        bool init_resolution)
@@ -218,7 +218,7 @@ static void manta_smoke_set_domain_from_mesh(MantaDomainSettings *mds,
   mds->cell_size[2] /= (float)mds->base_res[2];
 }
 
-static void manta_smoke_set_domain_gravity(Scene *scene, MantaDomainSettings *mds)
+static void manta_set_domain_gravity(Scene *scene, MantaDomainSettings *mds)
 {
   float gravity[3] = {0.0f, 0.0f, -1.0f};
   float gravity_mag;
@@ -250,9 +250,9 @@ static int mantaModifier_init(
     MantaDomainSettings *mds = mmd->domain;
     int res[3];
     /* set domain dimensions from mesh */
-    manta_smoke_set_domain_from_mesh(mds, ob, me, true);
+    manta_set_domain_from_mesh(mds, ob, me, true);
     /* set domain gravity */
-    manta_smoke_set_domain_gravity(scene, mds);
+    manta_set_domain_gravity(scene, mds);
     /* reset domain values */
     zero_v3_int(mds->shift);
     zero_v3(mds->shift_f);
@@ -262,7 +262,9 @@ static int mantaModifier_init(
     copy_m4_m4(mds->obmat, ob->obmat);
 
     /* set resolutions */
-    if (mmd->domain->flags & FLUID_DOMAIN_USE_ADAPTIVE_DOMAIN) {
+    if (mmd->domain->type == FLUID_DOMAIN_TYPE_GAS &&
+        mmd->domain->flags & FLUID_DOMAIN_USE_ADAPTIVE_DOMAIN)
+    {
       res[0] = res[1] = res[2] = 1; /* use minimum res for adaptive init */
     }
     else {
@@ -298,7 +300,7 @@ static int mantaModifier_init(
     mmd->time = scene_framenr;
     return 1;
   }
-  return 2;
+  return 0;
 }
 
 static void mantaModifier_freeDomain(MantaModifierData *mmd)
@@ -1081,14 +1083,14 @@ static void obstacles_from_mesh(Object *coll_ob,
      * Make vert_vel init optional?
      * code is in trouble if the object moves but is declared as "does not move" */
     {
-      vert_vel = MEM_callocN(sizeof(float) * numverts * 3, "smoke_obs_velocity");
+      vert_vel = MEM_callocN(sizeof(float) * numverts * 3, "manta_obs_velocity");
 
       if (scs->numverts != numverts || !scs->verts_old) {
         if (scs->verts_old) {
           MEM_freeN(scs->verts_old);
         }
 
-        scs->verts_old = MEM_callocN(sizeof(float) * numverts * 3, "smoke_obs_verts_old");
+        scs->verts_old = MEM_callocN(sizeof(float) * numverts * 3, "manta_obs_verts_old");
         scs->numverts = numverts;
       }
       else {
@@ -1104,7 +1106,7 @@ static void obstacles_from_mesh(Object *coll_ob,
 
       /* vert pos */
       mul_m4_v3(coll_ob->obmat, mvert[i].co);
-      manta_smoke_pos_to_cell(mds, mvert[i].co);
+      manta_pos_to_cell(mds, mvert[i].co);
 
       /* vert normal */
       normal_short_to_float_v3(n, mvert[i].no);
@@ -1414,9 +1416,9 @@ static void em_allocateData(EmissionMap *em, bool use_velocity, int hires_mul)
   em->total_cells = res[0] * res[1] * res[2];
   copy_v3_v3_int(em->res, res);
 
-  em->influence = MEM_callocN(sizeof(float) * em->total_cells, "smoke_flow_influence");
+  em->influence = MEM_callocN(sizeof(float) * em->total_cells, "manta_flow_influence");
   if (use_velocity) {
-    em->velocity = MEM_callocN(sizeof(float) * em->total_cells * 3, "smoke_flow_velocity");
+    em->velocity = MEM_callocN(sizeof(float) * em->total_cells * 3, "manta_flow_velocity");
   }
 
   em->distances = MEM_callocN(sizeof(float) * em->total_cells, "fluid_flow_distances");
@@ -1433,9 +1435,9 @@ static void em_allocateData(EmissionMap *em, bool use_velocity, int hires_mul)
     }
 
     em->influence_high = MEM_callocN(sizeof(float) * total_cells_high,
-                                     "smoke_flow_influence_high");
+                                     "manta_flow_influence_high");
     em->distances_high = MEM_callocN(sizeof(float) * total_cells_high,
-                                     "fluid_flow_distances_high");
+                                     "manta_flow_distances_high");
     memset(em->distances_high, 0x7f7f7f7f, sizeof(float) * total_cells_high);  // init to inf
   }
   em->valid = 1;
@@ -1719,8 +1721,8 @@ static void emit_from_particles(Object *flow_ob,
       totchild = psys->totchild * psys->part->disp / 100;
     }
 
-    particle_pos = MEM_callocN(sizeof(float) * (totpart + totchild) * 3, "smoke_flow_particles");
-    particle_vel = MEM_callocN(sizeof(float) * (totpart + totchild) * 3, "smoke_flow_particles");
+    particle_pos = MEM_callocN(sizeof(float) * (totpart + totchild) * 3, "manta_flow_particles");
+    particle_vel = MEM_callocN(sizeof(float) * (totpart + totchild) * 3, "manta_flow_particles");
 
     /* setup particle radius emission if enabled */
     if (sfs->flags & FLUID_FLOW_USE_PART_SIZE) {
@@ -1759,7 +1761,7 @@ static void emit_from_particles(Object *flow_ob,
       /* location */
       pos = &particle_pos[valid_particles * 3];
       copy_v3_v3(pos, state.co);
-      manta_smoke_pos_to_cell(mds, pos);
+      manta_pos_to_cell(mds, pos);
 
       /* velocity */
       copy_v3_v3(&particle_vel[valid_particles * 3], state.vel);
@@ -2246,13 +2248,13 @@ static void emit_from_mesh(
     mloopuv = CustomData_get_layer_named(&me->ldata, CD_MLOOPUV, sfs->uvlayer_name);
 
     if (sfs->flags & FLUID_FLOW_INITVELOCITY) {
-      vert_vel = MEM_callocN(sizeof(float) * numverts * 3, "smoke_flow_velocity");
+      vert_vel = MEM_callocN(sizeof(float) * numverts * 3, "manta_flow_velocity");
 
       if (sfs->numverts != numverts || !sfs->verts_old) {
         if (sfs->verts_old) {
           MEM_freeN(sfs->verts_old);
         }
-        sfs->verts_old = MEM_callocN(sizeof(float) * numverts * 3, "smoke_flow_verts_old");
+        sfs->verts_old = MEM_callocN(sizeof(float) * numverts * 3, "manta_flow_verts_old");
         sfs->numverts = numverts;
       }
       else {
@@ -2267,7 +2269,7 @@ static void emit_from_mesh(
 
       /* vert pos */
       mul_m4_v3(flow_ob->obmat, mvert[i].co);
-      manta_smoke_pos_to_cell(mds, mvert[i].co);
+      manta_pos_to_cell(mds, mvert[i].co);
 
       /* vert normal */
       normal_short_to_float_v3(n, mvert[i].no);
@@ -2291,7 +2293,7 @@ static void emit_from_mesh(
       em_boundInsert(em, mvert[i].co);
     }
     mul_m4_v3(flow_ob->obmat, flow_center);
-    manta_smoke_pos_to_cell(mds, flow_center);
+    manta_pos_to_cell(mds, flow_center);
 
     /* check need for high resolution map */
     if ((mds->flags & FLUID_DOMAIN_USE_NOISE) && (mds->highres_sampling == SM_HRES_FULLSAMPLE)) {
@@ -3016,7 +3018,7 @@ static void update_flowsfluids(struct Depsgraph *depsgraph,
   update_flowsflags(mds, flowobjs, numflowobj);
 
   /* init emission maps for each flow */
-  emaps = MEM_callocN(sizeof(struct EmissionMap) * numflowobj, "smoke_flow_maps");
+  emaps = MEM_callocN(sizeof(struct EmissionMap) * numflowobj, "manta_flow_maps");
 
   /* Prepare flow emission maps */
   for (flowIndex = 0; flowIndex < numflowobj; flowIndex++) {
@@ -3091,7 +3093,7 @@ static void update_flowsfluids(struct Depsgraph *depsgraph,
         /* Emission from mesh */
         else if (sfs->source == FLUID_FLOW_SOURCE_MESH) {
           /* Update flow object frame */
-          // BLI_mutex_lock() called in smoke_step(), so safe to update subframe here
+          // BLI_mutex_lock() called in manta_step(), so safe to update subframe here
 
           /* TODO (sebbas): Using BKE_scene_frame_get(scene) instead of new DEG_get_ctime(depsgraph) as subframes dont work with the latter yet */
           BKE_object_modifier_update_subframe(
@@ -3152,10 +3154,33 @@ static void update_flowsfluids(struct Depsgraph *depsgraph,
   /* Grid reset before writing again */
   for (z = 0; z < mds->res[0] * mds->res[1] * mds->res[2]; z++) {
     if (phi_in) {
-      phi_in[z] = 9999;
+      phi_in[z] = 9999.0f;
     }
     if (phiout_in) {
-      phiout_in[z] = 9999;
+      phiout_in[z] = 9999.0f;
+    }
+    if (density_in) {
+      density_in[z] = 0.0f;
+    }
+    if (heat_in) {
+      heat_in[z] = 0.0f;
+    }
+    if (colo

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list