[Bf-blender-cvs] [2ebf263f5c3] blender-v2.90-release: Fluid: Updated Mantaflow source files

Sebastián Barschkis noreply at git.blender.org
Sun Jul 26 22:04:10 CEST 2020


Commit: 2ebf263f5c3d23084e09cff02eac138a1fd8619f
Author: Sebastián Barschkis
Date:   Sun Jul 26 21:43:18 2020 +0200
Branches: blender-v2.90-release
https://developer.blender.org/rB2ebf263f5c3d23084e09cff02eac138a1fd8619f

Fluid: Updated Mantaflow source files

New files contain updated sampling function (support for maximum number of particles cap).

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

M	extern/mantaflow/preprocessed/fileio/ioparticles.cpp
M	extern/mantaflow/preprocessed/gitinfo.h
M	extern/mantaflow/preprocessed/particle.cpp
M	extern/mantaflow/preprocessed/particle.h
M	extern/mantaflow/preprocessed/particle.h.reg.cpp

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

diff --git a/extern/mantaflow/preprocessed/fileio/ioparticles.cpp b/extern/mantaflow/preprocessed/fileio/ioparticles.cpp
index 84283a25b07..36e10aa1644 100644
--- a/extern/mantaflow/preprocessed/fileio/ioparticles.cpp
+++ b/extern/mantaflow/preprocessed/fileio/ioparticles.cpp
@@ -322,6 +322,7 @@ template<class T> int readPdataUni(const std::string &name, ParticleDataImpl<T>
     UniPartHeader head;
     assertMsg(gzread(gzf, &head, sizeof(UniPartHeader)) == sizeof(UniPartHeader),
               "can't read file, no header present");
+    pdata->getParticleSys()->resize(head.dim);  // ensure that parent particle system has same size
     pdata->resize(head.dim);
 
     assertMsg(head.dim == pdata->size(), "pdata size doesn't match");
diff --git a/extern/mantaflow/preprocessed/gitinfo.h b/extern/mantaflow/preprocessed/gitinfo.h
index 3271a858911..ce088d6c400 100644
--- a/extern/mantaflow/preprocessed/gitinfo.h
+++ b/extern/mantaflow/preprocessed/gitinfo.h
@@ -1,3 +1,3 @@
 
 
-#define MANTA_GIT_VERSION "commit 3370c2014ad7192041cb4fbed19ed74ae9725fb5"
+#define MANTA_GIT_VERSION "commit 841bfd09c068dfb95637c0ec14fa78305286a433"
diff --git a/extern/mantaflow/preprocessed/particle.cpp b/extern/mantaflow/preprocessed/particle.cpp
index 6e1ef2fa5d8..9561365af3d 100644
--- a/extern/mantaflow/preprocessed/particle.cpp
+++ b/extern/mantaflow/preprocessed/particle.cpp
@@ -29,7 +29,7 @@ using namespace std;
 namespace Manta {
 
 ParticleBase::ParticleBase(FluidSolver *parent)
-    : PbClass(parent), mAllowCompress(true), mFreePdata(false)
+    : PbClass(parent), mAllowCompress(true), mFreePdata(false), mMaxParticles(0)
 {
 }
 
diff --git a/extern/mantaflow/preprocessed/particle.h b/extern/mantaflow/preprocessed/particle.h
index 0be141ed26f..da6733b6845 100644
--- a/extern/mantaflow/preprocessed/particle.h
+++ b/extern/mantaflow/preprocessed/particle.h
@@ -100,6 +100,17 @@ class ParticleBase : public PbClass {
   //! threads)
   inline void addBuffered(const Vec3 &pos, int flag = 0);
 
+  virtual void resize(IndexInt size)
+  {
+    assertMsg(false, "Dont use, override...");
+    return;
+  }
+  virtual void resizeAll(IndexInt size)
+  {
+    assertMsg(false, "Dont use, override...");
+    return;
+  }
+
   //! particle data functions
 
   //! create a particle data object
@@ -152,6 +163,20 @@ class ParticleBase : public PbClass {
     return mPartData[i];
   }
 
+  //! expose maximum number of particles to python
+  int mMaxParticles;
+  static PyObject *_GET_mMaxParticles(PyObject *self, void *cl)
+  {
+    ParticleBase *pbo = dynamic_cast<ParticleBase *>(Pb::objFromPy(self));
+    return toPy(pbo->mMaxParticles);
+  }
+  static int _SET_mMaxParticles(PyObject *self, PyObject *val, void *cl)
+  {
+    ParticleBase *pbo = dynamic_cast<ParticleBase *>(Pb::objFromPy(self));
+    pbo->mMaxParticles = fromPy<int>(val);
+    return 0;
+  }
+
  protected:
   //! new particle candidates
   std::vector<Vec3> mNewBufferPos;
@@ -431,8 +456,14 @@ template<class S> class ParticleSystem : public ParticleBase {
   }
   //! insert buffered positions as new particles, update additional particle data
   void insertBufferedParticles();
+  //! resize only the data vector, only use if you know what you're doing, otherwise use
+  //! resizeAll()
+  virtual void resize(IndexInt size)
+  {
+    mData.resize(size);
+  }
   //! resize data vector, and all pdata fields
-  void resizeAll(IndexInt newsize);
+  virtual void resizeAll(IndexInt size);
 
   //! adding and deleting
   inline void kill(IndexInt idx);
@@ -877,11 +908,6 @@ class ParticleIndexSystem : public ParticleSystem<ParticleIndexData> {
       return -1;
     }
   };
-  //! we only need a resize function...
-  void resize(IndexInt size)
-  {
-    mData.resize(size);
-  }
  public:
   PbArgs _args;
 }
@@ -2479,28 +2505,66 @@ template<class S> void ParticleSystem<S>::insertBufferedParticles()
   for (IndexInt i = 0; i < (IndexInt)mData.size(); ++i)
     mData[i].flag &= ~PNEW;
 
-  if (mNewBufferPos.size() == 0)
+  if (mNewBufferPos.empty())
     return;
-  IndexInt newCnt = mData.size();
-  resizeAll(newCnt + mNewBufferPos.size());
-
-  for (IndexInt i = 0; i < (IndexInt)mNewBufferPos.size(); ++i) {
-    int flag = (mNewBufferFlag.size() > 0) ? mNewBufferFlag[i] : 0;
-    // note, other fields are not initialized here...
-    mData[newCnt].pos = mNewBufferPos[i];
-    mData[newCnt].flag = PNEW | flag;
+  IndexInt bufferSize = mNewBufferPos.size();
+  IndexInt partsSize = mData.size();
+
+  if (mMaxParticles > 0)
+    assertMsg(mMaxParticles >= partsSize,
+              "Particle system cannot contain more particles that the maximum allowed number");
+
+  // max number of new particles that can be inserted, adjusted buffer size when using maxParticles
+  // field
+  IndexInt numNewParts = (mMaxParticles > 0) ? mMaxParticles - mData.size() : bufferSize;
+  if (numNewParts > bufferSize)
+    numNewParts = bufferSize;  // upper clamp
+
+  assertMsg(numNewParts >= 0, "Must not have negative number of new particles");
+
+  // new size of particle system
+  IndexInt newSize = mData.size() + numNewParts;
+  if (mMaxParticles > 0)
+    assertMsg(newSize <= mMaxParticles,
+              "Particle system cannot contain more particles that the maximum allowed number");
+  resizeAll(newSize);
+
+  int insertFlag;
+  Vec3 insertPos;
+  static RandomStream mRand(9832);
+  for (IndexInt i = 0; i < numNewParts; ++i) {
+
+    // get random index in newBuffer vector
+    // we are inserting particles randomly so that they are sampled uniformly in the fluid region
+    // otherwise, regions of fluid can remain completely empty once mData.size() == maxParticles is
+    // reached.
+    int randIndex = floor(mRand.getReal() * mNewBufferPos.size());
+
+    // get elements from new buffers with random index
+    std::swap(mNewBufferPos[randIndex], mNewBufferPos.back());
+    insertPos = mNewBufferPos.back();
+    mNewBufferPos.pop_back();
+
+    insertFlag = 0;
+    if (!mNewBufferFlag.empty()) {
+      std::swap(mNewBufferFlag[randIndex], mNewBufferFlag.back());
+      insertFlag = mNewBufferFlag.back();
+      mNewBufferFlag.pop_back();
+    }
+
+    mData[partsSize].pos = insertPos;
+    mData[partsSize].flag = PNEW | insertFlag;
+
     // now init pdata fields from associated grids...
     for (IndexInt pd = 0; pd < (IndexInt)mPdataReal.size(); ++pd)
-      mPdataReal[pd]->initNewValue(newCnt, mNewBufferPos[i]);
+      mPdataReal[pd]->initNewValue(partsSize, insertPos);
     for (IndexInt pd = 0; pd < (IndexInt)mPdataVec3.size(); ++pd)
-      mPdataVec3[pd]->initNewValue(newCnt, mNewBufferPos[i]);
+      mPdataVec3[pd]->initNewValue(partsSize, insertPos);
     for (IndexInt pd = 0; pd < (IndexInt)mPdataInt.size(); ++pd)
-      mPdataInt[pd]->initNewValue(newCnt, mNewBufferPos[i]);
-    newCnt++;
+      mPdataInt[pd]->initNewValue(partsSize, insertPos);
+    partsSize++;
   }
-  if (mNewBufferPos.size() > 0)
-    debMsg("Added & initialized " << (IndexInt)mNewBufferPos.size() << " particles",
-           2);  // debug info
+  debMsg("Added & initialized " << numNewParts << " particles", 2);  // debug info
   mNewBufferPos.clear();
   mNewBufferFlag.clear();
 }
diff --git a/extern/mantaflow/preprocessed/particle.h.reg.cpp b/extern/mantaflow/preprocessed/particle.h.reg.cpp
index 6e0466d0203..e9e538ad097 100644
--- a/extern/mantaflow/preprocessed/particle.h.reg.cpp
+++ b/extern/mantaflow/preprocessed/particle.h.reg.cpp
@@ -29,279 +29,283 @@ static const Pb::Register _R_21("ParticleBase", "ParticleBase", "PbClass");
 template<> const char *Namify<ParticleBase>::S = "ParticleBase";
 static const Pb::Register _R_22("ParticleBase", "ParticleBase", ParticleBase::_W_0);
 static const Pb::Register _R_23("ParticleBase", "create", ParticleBase::_W_1);
+static const Pb::Register _R_24("ParticleBase",
+                                "maxParticles",
+                                ParticleBase::_GET_mMaxParticles,
+                                ParticleBase::_SET_mMaxParticles);
 #endif
 #ifdef _C_ParticleDataBase
-static const Pb::Register _R_24("ParticleDataBase", "ParticleDataBase", "PbClass");
+static const Pb::Register _R_25("ParticleDataBase", "ParticleDataBase", "PbClass");
 template<> const char *Namify<ParticleDataBase>::S = "ParticleDataBase";
-static const Pb::Register _R_25("ParticleDataBase", "ParticleDataBase", ParticleDataBase::_W_21);
+static const Pb::Register _R_26("ParticleDataBase", "ParticleDataBase", ParticleDataBase::_W_21);
 #endif
 #ifdef _C_ParticleDataImpl
-static const Pb::Register _R_26("ParticleDataImpl<int>",
+static const Pb::Register _R_27("ParticleDataImpl<int>",
                                 "ParticleDataImpl<int>",
                                 "ParticleDataBase");
 template<> const char *Namify<ParticleDataImpl<int>>::S = "ParticleDataImpl<int>";
-static const Pb::Register _R_27("ParticleDataImpl<int>",
+static const Pb::Register _R_28("ParticleDataImpl<int>",
                                 "ParticleDataImpl",
                                 ParticleDataImpl<int>::_W_22);
-static const Pb::Register _R_28("ParticleDataImpl<int>", "clear", ParticleDataImpl<int>::_W_23);
-static const Pb::Register _R_29("ParticleDataImpl<int>",
+static const Pb::Register _R_29("ParticleDataImpl<int>", "clear", ParticleDataImpl<int>::_W_23);
+static const Pb::Register _R_30("ParticleDataImpl<int>",
                                 "setSource",
                                 ParticleDataImpl<int>::_W_24);
-static const Pb::Register _R_30("ParticleDataImpl<int>", "copyFrom", ParticleDataImpl<int>::_W_25);
-static const Pb::Register _R_31("ParticleDataImpl<int>", "setConst", ParticleDataImpl<int>::_W_26);
-static const Pb::Register _R_32("ParticleDataImpl<int>",
+static const Pb::Register _R_31("ParticleDataImpl<int>", "copyFrom", ParticleDataImpl<int>::_W_25);
+static const Pb::Register _R_32("ParticleDataImpl<int>", "setConst", ParticleDataImpl<int>::_W_26);
+static const Pb::Register _R_33("ParticleDataImpl<int>",
                                 "setConstRange",
                                 ParticleDataImpl<int>::_W_27);
-static const Pb::Register _R_33("ParticleDataImpl<int>", "add", ParticleDataImpl<int>::_W_28);
-stat

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list