From 8dd43ac23ebef30a136e0f7f430a37bdc556e78c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebasti=C3=A1n=20Barschkis?= <sebbas@sebbas.org>
Date: Tue, 18 May 2021 22:32:54 +0200
Subject: [PATCH] Fluid: Updated Mantaflow source files

Includes update for OpenVDB file IO, i.e. fixes an issue with
compression flag combination that resulted in random segfaults.

Other changes: Cleanup and formatting.
---
 extern/mantaflow/preprocessed/fileio/iovdb.cpp      | 13 +++++++------
 extern/mantaflow/preprocessed/fluidsolver.h         |  1 +
 extern/mantaflow/preprocessed/general.h             |  2 +-
 extern/mantaflow/preprocessed/gitinfo.h             |  2 +-
 extern/mantaflow/preprocessed/grid.h                |  1 +
 extern/mantaflow/preprocessed/grid4d.h              |  2 ++
 extern/mantaflow/preprocessed/levelset.h            |  1 +
 extern/mantaflow/preprocessed/mesh.h                |  3 +++
 extern/mantaflow/preprocessed/movingobs.h           |  1 +
 extern/mantaflow/preprocessed/noisefield.h          |  1 +
 extern/mantaflow/preprocessed/particle.h            |  6 ++++++
 .../mantaflow/preprocessed/plugin/meshplugins.cpp   |  8 ++++----
 .../preprocessed/plugin/secondaryparticles.cpp      |  7 ++++---
 extern/mantaflow/preprocessed/shapes.h              |  6 ++++++
 extern/mantaflow/preprocessed/turbulencepart.h      |  1 +
 extern/mantaflow/preprocessed/vortexpart.h          |  1 +
 extern/mantaflow/preprocessed/vortexsheet.h         |  1 +
 17 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/extern/mantaflow/preprocessed/fileio/iovdb.cpp b/extern/mantaflow/preprocessed/fileio/iovdb.cpp
index e615741e0f7..1846ef7ecbb 100644
--- a/extern/mantaflow/preprocessed/fileio/iovdb.cpp
+++ b/extern/mantaflow/preprocessed/fileio/iovdb.cpp
@@ -29,10 +29,10 @@
 
 #if OPENVDB == 1
 #  include "openvdb/openvdb.h"
-#  include <openvdb/points/PointConversion.h>
-#  include <openvdb/points/PointCount.h>
-#  include <openvdb/tools/Clip.h>
-#  include <openvdb/tools/Dense.h>
+#  include "openvdb/points/PointConversion.h"
+#  include "openvdb/points/PointCount.h"
+#  include "openvdb/tools/Clip.h"
+#  include "openvdb/tools/Dense.h"
 #endif
 
 #define POSITION_NAME "P"
@@ -519,7 +519,7 @@ int writeObjectsVDB(const string &filename,
     }
   }
 
-  // Write only if the is at least one grid, optionally write with compression.
+  // Write only if there is at least one grid, optionally write with compression.
   if (gridsVDB.size()) {
     int vdb_flags = openvdb::io::COMPRESS_ACTIVE_MASK;
     switch (compression) {
@@ -534,7 +534,8 @@ int writeObjectsVDB(const string &filename,
       }
       case COMPRESSION_BLOSC: {
 #  if OPENVDB_BLOSC == 1
-        vdb_flags |= openvdb::io::COMPRESS_BLOSC;
+        // Cannot use |= here, causes segfault with blosc 1.5.0 (== recommended version)
+        vdb_flags = openvdb::io::COMPRESS_BLOSC;
 #  else
         debMsg("OpenVDB was built without Blosc support, using Zip compression instead", 1);
         vdb_flags |= openvdb::io::COMPRESS_ZIP;
diff --git a/extern/mantaflow/preprocessed/fluidsolver.h b/extern/mantaflow/preprocessed/fluidsolver.h
index 0c871bca3a1..6770f8b7b05 100644
--- a/extern/mantaflow/preprocessed/fluidsolver.h
+++ b/extern/mantaflow/preprocessed/fluidsolver.h
@@ -384,6 +384,7 @@ class FluidSolver : public PbClass {
   GridStorage<Real> mGrids4dReal;
   GridStorage<Vec3> mGrids4dVec;
   GridStorage<Vec4> mGrids4dVec4;
+
  public:
   PbArgs _args;
 }
diff --git a/extern/mantaflow/preprocessed/general.h b/extern/mantaflow/preprocessed/general.h
index 50eac71e87e..8bf1c2e25de 100644
--- a/extern/mantaflow/preprocessed/general.h
+++ b/extern/mantaflow/preprocessed/general.h
@@ -42,7 +42,7 @@ inline void updateQtGui(bool full, int frame, float time, const std::string &cur
 #  ifdef _DEBUG
 #    define DEBUG 1
 #  endif  // _DEBUG
-#endif  // DEBUG
+#endif    // DEBUG
 
 // Standard exception
 class Error : public std::exception {
diff --git a/extern/mantaflow/preprocessed/gitinfo.h b/extern/mantaflow/preprocessed/gitinfo.h
index 1bb96fe3baa..03fd0112095 100644
--- a/extern/mantaflow/preprocessed/gitinfo.h
+++ b/extern/mantaflow/preprocessed/gitinfo.h
@@ -1,3 +1,3 @@
 
 
-#define MANTA_GIT_VERSION "commit 39b7a415721ecbf6643612a24e8eadd221aeb934"
+#define MANTA_GIT_VERSION "commit 9c505cd22e289b98c9aa717efba8ef3201c7e458"
diff --git a/extern/mantaflow/preprocessed/grid.h b/extern/mantaflow/preprocessed/grid.h
index 9c3d954771e..2c4296e78dd 100644
--- a/extern/mantaflow/preprocessed/grid.h
+++ b/extern/mantaflow/preprocessed/grid.h
@@ -389,6 +389,7 @@ class GridBase : public PbClass {
   Real mDx;
   bool m3D;  // precomputed Z shift: to ensure 2D compatibility, always use this instead of sx*sy !
   IndexInt mStrideZ;
+
  public:
   PbArgs _args;
 }
diff --git a/extern/mantaflow/preprocessed/grid4d.h b/extern/mantaflow/preprocessed/grid4d.h
index 9b64116fc9d..1741db590b7 100644
--- a/extern/mantaflow/preprocessed/grid4d.h
+++ b/extern/mantaflow/preprocessed/grid4d.h
@@ -326,6 +326,7 @@ class Grid4dBase : public PbClass {
   // precomputed Z,T shift: to ensure 2D compatibility, always use this instead of sx*sy !
   IndexInt mStrideZ;
   IndexInt mStrideT;
+
  public:
   PbArgs _args;
 }
@@ -950,6 +951,7 @@ template<class T> class Grid4d : public Grid4dBase {
 
  protected:
   T *mData;
+
  public:
   PbArgs _args;
 }
diff --git a/extern/mantaflow/preprocessed/levelset.h b/extern/mantaflow/preprocessed/levelset.h
index db542bb1fe6..ae162f73c3d 100644
--- a/extern/mantaflow/preprocessed/levelset.h
+++ b/extern/mantaflow/preprocessed/levelset.h
@@ -266,6 +266,7 @@ class LevelsetGrid : public Grid<Real> {
   }
 
   static Real invalidTimeValue();
+
  public:
   PbArgs _args;
 }
diff --git a/extern/mantaflow/preprocessed/mesh.h b/extern/mantaflow/preprocessed/mesh.h
index d3a69abc4ea..b5de66ce095 100644
--- a/extern/mantaflow/preprocessed/mesh.h
+++ b/extern/mantaflow/preprocessed/mesh.h
@@ -796,6 +796,7 @@ class Mesh : public PbClass {
   std::vector<MeshDataImpl<int> *>
       mMdataInt;  //! indicate that mdata of this mesh is copied, and needs to be freed
   bool mFreeMdata;
+
  public:
   PbArgs _args;
 }
@@ -881,6 +882,7 @@ class MeshDataBase : public PbClass {
 
  protected:
   Mesh *mMesh;
+
  public:
   PbArgs _args;
 }
@@ -1645,6 +1647,7 @@ template<class T> class MeshDataImpl : public MeshDataBase {
   //! optionally , we might have an associated grid from which to grab new data
   Grid<T> *mpGridSource;  //! unfortunately , we need to distinguish mac vs regular vec3
   bool mGridSourceMAC;
+
  public:
   PbArgs _args;
 }
diff --git a/extern/mantaflow/preprocessed/movingobs.h b/extern/mantaflow/preprocessed/movingobs.h
index 0661ddf5b37..83ef6ed0c9f 100644
--- a/extern/mantaflow/preprocessed/movingobs.h
+++ b/extern/mantaflow/preprocessed/movingobs.h
@@ -154,6 +154,7 @@ class MovingObstacle : public PbClass {
   int mEmptyType;
   int mID;
   static int sIDcnt;
+
  public:
   PbArgs _args;
 }
diff --git a/extern/mantaflow/preprocessed/noisefield.h b/extern/mantaflow/preprocessed/noisefield.h
index 73c9de779ef..6ed8ac0012d 100644
--- a/extern/mantaflow/preprocessed/noisefield.h
+++ b/extern/mantaflow/preprocessed/noisefield.h
@@ -236,6 +236,7 @@ class WaveletNoiseField : public PbClass {
   static int randomSeed;
   // global reference count for noise tile
   static std::atomic<int> mNoiseReferenceCount;
+
  public:
   PbArgs _args;
 }
diff --git a/extern/mantaflow/preprocessed/particle.h b/extern/mantaflow/preprocessed/particle.h
index 7fcc7e5ca32..7e0c64e6d03 100644
--- a/extern/mantaflow/preprocessed/particle.h
+++ b/extern/mantaflow/preprocessed/particle.h
@@ -205,6 +205,7 @@ class ParticleBase : public PbClass {
   //! custom seed for particle systems, used by plugins
   int mSeed;  //! fix global random seed storage, used mainly by functions in this class
   static int globalSeed;
+
  public:
   PbArgs _args;
 }
@@ -628,6 +629,7 @@ template<class S> class ParticleSystem : public ParticleBase {
   std::vector<S> mData;
   //! reduce storage , called by doCompress
   virtual void compress();
+
  public:
   PbArgs _args;
 }
@@ -918,6 +920,7 @@ class ParticleIndexSystem : public ParticleSystem<ParticleIndexData> {
       return -1;
     }
   };
+
  public:
   PbArgs _args;
 }
@@ -982,6 +985,7 @@ template<class DATA, class CON> class ConnectedParticleSystem : public ParticleS
  protected:
   std::vector<CON> mSegments;
   virtual void compress();
+
  public:
   PbArgs _args;
 }
@@ -1071,6 +1075,7 @@ class ParticleDataBase : public PbClass {
 
  protected:
   ParticleBase *mpParticleSys;
+
  public:
   PbArgs _args;
 }
@@ -1843,6 +1848,7 @@ template<class T> class ParticleDataImpl : public ParticleDataBase {
   //! optionally , we might have an associated grid from which to grab new data
   Grid<T> *mpGridSource;  //! unfortunately , we need to distinguish mac vs regular vec3
   bool mGridSourceMAC;
+
  public:
   PbArgs _args;
 }
diff --git a/extern/mantaflow/preprocessed/plugin/meshplugins.cpp b/extern/mantaflow/preprocessed/plugin/meshplugins.cpp
index 043660db20b..cf315429d65 100644
--- a/extern/mantaflow/preprocessed/plugin/meshplugins.cpp
+++ b/extern/mantaflow/preprocessed/plugin/meshplugins.cpp
@@ -234,10 +234,10 @@ void subdivideMesh(
       normalize(ne2);
 
       // Real thisArea = sqrMag(cross(-e2,e0));
-      // small angle approximation says sin(x) = arcsin(x) = x,
-      // arccos(x) = pi/2 - arcsin(x),
-      // cos(x) = dot(A,B),
-      // so angle is approximately 1 - dot(A,B).
+      //  small angle approximation says sin(x) = arcsin(x) = x,
+      //  arccos(x) = pi/2 - arcsin(x),
+      //  cos(x) = dot(A,B),
+      //  so angle is approximately 1 - dot(A,B).
       Real angle[3];
       angle[0] = 1.0 - dot(ne0, -ne2);
       angle[1] = 1.0 - dot(ne1, -ne0);
diff --git a/extern/mantaflow/preprocessed/plugin/secondaryparticles.cpp b/extern/mantaflow/preprocessed/plugin/secondaryparticles.cpp
index 7a1d8224d94..2f876376f53 100644
--- a/extern/mantaflow/preprocessed/plugin/secondaryparticles.cpp
+++ b/extern/mantaflow/preprocessed/plugin/secondaryparticles.cpp
@@ -2287,9 +2287,10 @@ struct knFlipComputePotentialTrappedAir : public KernelBase {
           const Vec3 &vj = scaleFromManta * v.getCentered(x, y, z);
           const Vec3 xij = xi - xj;
           const Vec3 vij = vi - vj;
-          Real h = !pot.is3D() ? 1.414 * radius :
-                                 1.732 * radius;  // estimate sqrt(2)*radius resp. sqrt(3)*radius
-                                                  // for h, due to squared resp. cubic neighbor area
+          Real h = !pot.is3D() ?
+                       1.414 * radius :
+                       1.732 * radius;  // estimate sqrt(2)*radius resp. sqrt(3)*radius for h, due
+                                        // to squared resp. cubic neighbor area
           vdiff += norm(vij) * (1 - dot(getNormalized(vij), getNormalized(xij))) *
                    (1 - norm(xij) / h);
         }
diff --git a/extern/mantaflow/preprocessed/shapes.h b/extern/mantaflow/preprocessed/shapes.h
index fa645389bfe..5a400eaed09 100644
--- a/extern/mantaflow/preprocessed/shapes.h
+++ b/extern/mantaflow/preprocessed/shapes.h
@@ -269,6 +269,7 @@ class Shape : public PbClass {
 
  protected:
   GridType mType;
+
  public:
   PbArgs _args;
 }
@@ -319,6 +320,7 @@ class NullShape : public Shape {
   {
     gridSetConst<Real>(phi, 1000.0f);
   }
+
  public:
   PbArgs _args;
 }
@@ -394,6 +396,7 @@ class Box : public Shape {
 
  protected:
   Vec3 mP0, mP1;
+
  public:
   PbArgs _args;
 }
@@ -455,6 +458,7 @@ class Sphere : public Shape {
  protected:
   Vec3 mCenter, mScale;
   Real mRadius;
+
  public:
   PbArgs _args;
 }
@@ -579,6 +583,7 @@ class Cylinder : public Shape {
  protected:
   Vec3 mCenter, mZDir;
   Real mRadius, mZ;
+
  public:
   PbArgs _args;
 }
@@ -655,6 +660,7 @@ class Slope : public Shape {
   Real mAnglexy, mAngleyz;
   Real mOrigin;
   Vec3 mGs;
+
  public:
   PbArgs _args;
 }
diff --git a/extern/mantaflow/preprocessed/turbulencepart.h b/extern/mantaflow/preprocessed/turbulencepart.h
index 81c94d77722..5177aeb2d96 100644
--- a/extern/mantaflow/preprocessed/turbulencepart.h
+++ b/extern/mantaflow/preprocessed/turbulencepart.h
@@ -199,6 +199,7 @@ class TurbulenceParticleSystem : public ParticleSystem<TurbulenceParticleData> {
 
  private:
   WaveletNoiseField &noise;
+
  public:
   PbArgs _args;
 }
diff --git a/extern/mantaflow/preprocessed/vortexpart.h b/extern/mantaflow/preprocessed/vortexpart.h
index e48fbc7f507..8f80cf910eb 100644
--- a/extern/mantaflow/preprocessed/vortexpart.h
+++ b/extern/mantaflow/preprocessed/vortexpart.h
@@ -127,6 +127,7 @@ class VortexParticleSystem : public ParticleSystem<VortexParticleData> {
   }
 
   virtual ParticleBase *clone();
+
  public:
   PbArgs _args;
 }
diff --git a/extern/mantaflow/preprocessed/vortexsheet.h b/extern/mantaflow/preprocessed/vortexsheet.h
index 01c32e4e806..0fc0f3a1258 100644
--- a/extern/mantaflow/preprocessed/vortexsheet.h
+++ b/extern/mantaflow/preprocessed/vortexsheet.h
@@ -240,6 +240,7 @@ class VortexSheetMesh : public Mesh {
   VorticityChannel mVorticity;
   TexCoord3Channel mTex1, mTex2;
   TurbulenceChannel mTurb;
+
  public:
   PbArgs _args;
 }
-- 
GitLab