[Bf-blender-cvs] [aa547ce88b9] master: Fluid: Update Mantaflow source files

Sebastián Barschkis noreply at git.blender.org
Thu Jul 16 16:39:57 CEST 2020


Commit: aa547ce88b9c4607e070f8b76341ae2076f28ec7
Author: Sebastián Barschkis
Date:   Thu Jul 16 16:39:14 2020 +0200
Branches: master
https://developer.blender.org/rBaa547ce88b9c4607e070f8b76341ae2076f28ec7

Fluid: Update Mantaflow source files

Refactored various functions after noticing new warnings when compiling on Apple DTK devices - there should now be fewer warnings when building.

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

M	extern/mantaflow/helper/util/vectorbase.h
M	extern/mantaflow/preprocessed/gitinfo.h
M	extern/mantaflow/preprocessed/mesh.cpp
M	extern/mantaflow/preprocessed/particle.cpp
M	extern/mantaflow/preprocessed/plugin/initplugins.cpp
M	extern/mantaflow/preprocessed/registration.cpp

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

diff --git a/extern/mantaflow/helper/util/vectorbase.h b/extern/mantaflow/helper/util/vectorbase.h
index 9ccf445f42c..9b4d9c83f0b 100644
--- a/extern/mantaflow/helper/util/vectorbase.h
+++ b/extern/mantaflow/helper/util/vectorbase.h
@@ -439,6 +439,36 @@ inline Real normSquare(const int v)
   return square(v);
 }
 
+//! Compute sum of all components, allow use of int, Real too
+template<class S> inline S sum(const S v)
+{
+  return v;
+}
+template<class S> inline S sum(const Vector3D<S> &v)
+{
+  return v.x + v.y + v.z;
+}
+
+//! Get absolute representation of vector, allow use of int, Real too
+inline Real abs(const Real v)
+{
+  return std::fabs(v);
+}
+inline int abs(const int v)
+{
+  return std::abs(v);
+}
+
+template<class S> inline Vector3D<S> abs(const Vector3D<S> &v)
+{
+  Vector3D<S> cp(v.x, v.y, v.z);
+  for (int i = 0; i < 3; ++i) {
+    if (cp[i] < 0)
+      cp[i] *= (-1.0);
+  }
+  return cp;
+}
+
 //! Returns a normalized vector
 template<class S> inline Vector3D<S> getNormalized(const Vector3D<S> &v)
 {
diff --git a/extern/mantaflow/preprocessed/gitinfo.h b/extern/mantaflow/preprocessed/gitinfo.h
index 03dcbb3d9c5..67cede606da 100644
--- a/extern/mantaflow/preprocessed/gitinfo.h
+++ b/extern/mantaflow/preprocessed/gitinfo.h
@@ -1,3 +1,3 @@
 
 
-#define MANTA_GIT_VERSION "commit 7395d36e3f504edbdabe34b30edc855b422c7baa"
+#define MANTA_GIT_VERSION "commit 1881a368ed10797e84b470645d7c738ef75ad6d8"
diff --git a/extern/mantaflow/preprocessed/mesh.cpp b/extern/mantaflow/preprocessed/mesh.cpp
index d93c2ac04c0..c99d621d2bd 100644
--- a/extern/mantaflow/preprocessed/mesh.cpp
+++ b/extern/mantaflow/preprocessed/mesh.cpp
@@ -1339,8 +1339,8 @@ template<class T> void MeshDataImpl<T>::setSource(Grid<T> *grid, bool isMAC)
 {
   mpGridSource = grid;
   mGridSourceMAC = isMAC;
-  if (isMAC)
-    assertMsg(dynamic_cast<MACGrid *>(grid) != NULL, "Given grid is not a valid MAC grid");
+  if (grid && isMAC)
+    assertMsg(grid->getType() & GridBase::TypeMAC, "Given grid is not a valid MAC grid");
 }
 
 template<class T> void MeshDataImpl<T>::initNewValue(IndexInt idx, Vec3 pos)
diff --git a/extern/mantaflow/preprocessed/particle.cpp b/extern/mantaflow/preprocessed/particle.cpp
index c719fc8f27d..6e1ef2fa5d8 100644
--- a/extern/mantaflow/preprocessed/particle.cpp
+++ b/extern/mantaflow/preprocessed/particle.cpp
@@ -359,8 +359,8 @@ template<class T> void ParticleDataImpl<T>::setSource(Grid<T> *grid, bool isMAC)
 {
   mpGridSource = grid;
   mGridSourceMAC = isMAC;
-  if (isMAC)
-    assertMsg(dynamic_cast<MACGrid *>(grid) != NULL, "Given grid is not a valid MAC grid");
+  if (grid && isMAC)
+    assertMsg(grid->getType() & GridBase::TypeMAC, "Given grid is not a valid MAC grid");
 }
 
 template<class T> void ParticleDataImpl<T>::initNewValue(IndexInt idx, Vec3 pos)
diff --git a/extern/mantaflow/preprocessed/plugin/initplugins.cpp b/extern/mantaflow/preprocessed/plugin/initplugins.cpp
index 7a765813f9f..6ccd3afc8d1 100644
--- a/extern/mantaflow/preprocessed/plugin/initplugins.cpp
+++ b/extern/mantaflow/preprocessed/plugin/initplugins.cpp
@@ -1479,48 +1479,24 @@ void PbRegister_addTestParts()
 }
 
 //! calculate the difference between two pdata fields (note - slow!, not parallelized)
-
-Real pdataMaxDiff(const ParticleDataBase *a, const ParticleDataBase *b)
+template<class T> Real getPdataMaxDiff(const ParticleDataImpl<T> *a, const ParticleDataImpl<T> *b)
 {
-  double maxVal = 0.;
-  // debMsg(" PD "<< a->getType()<<"  as"<<a->getSizeSlow()<<"  bs"<<b->getSizeSlow() , 1);
   assertMsg(a->getType() == b->getType(), "pdataMaxDiff problem - different pdata types!");
   assertMsg(a->getSizeSlow() == b->getSizeSlow(), "pdataMaxDiff problem - different pdata sizes!");
 
-  if (a->getType() & ParticleDataBase::TypeReal) {
-    const ParticleDataImpl<Real> &av = *dynamic_cast<const ParticleDataImpl<Real> *>(a);
-    const ParticleDataImpl<Real> &bv = *dynamic_cast<const ParticleDataImpl<Real> *>(b);
-    FOR_PARTS(av)
-    {
-      maxVal = std::max(maxVal, (double)fabs(av[idx] - bv[idx]));
-    }
-  }
-  else if (a->getType() & ParticleDataBase::TypeInt) {
-    const ParticleDataImpl<int> &av = *dynamic_cast<const ParticleDataImpl<int> *>(a);
-    const ParticleDataImpl<int> &bv = *dynamic_cast<const ParticleDataImpl<int> *>(b);
-    FOR_PARTS(av)
-    {
-      maxVal = std::max(maxVal, (double)fabs((double)av[idx] - bv[idx]));
-    }
-  }
-  else if (a->getType() & ParticleDataBase::TypeVec3) {
-    const ParticleDataImpl<Vec3> &av = *dynamic_cast<const ParticleDataImpl<Vec3> *>(a);
-    const ParticleDataImpl<Vec3> &bv = *dynamic_cast<const ParticleDataImpl<Vec3> *>(b);
-    FOR_PARTS(av)
-    {
-      double d = 0.;
-      for (int c = 0; c < 3; ++c) {
-        d += fabs((double)av[idx][c] - (double)bv[idx][c]);
-      }
-      maxVal = std::max(maxVal, d);
-    }
-  }
-  else {
-    errMsg("pdataMaxDiff: Grid Type is not supported (only Real, Vec3, int)");
+  Real maxVal = 0.;
+  FOR_PARTS(*a)
+  {
+    T diff = a->get(idx) - b->get(idx);
+    Real s = (Real)sum(abs(diff));
+    maxVal = std::max(maxVal, s);
   }
-
   return maxVal;
 }
+Real pdataMaxDiff(const ParticleDataImpl<Real> *a, const ParticleDataImpl<Real> *b)
+{
+  return getPdataMaxDiff(a, b);
+}
 static PyObject *_W_15(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
 {
   try {
@@ -1531,8 +1507,8 @@ static PyObject *_W_15(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
     PyObject *_retval = 0;
     {
       ArgLocker _lock;
-      const ParticleDataBase *a = _args.getPtr<ParticleDataBase>("a", 0, &_lock);
-      const ParticleDataBase *b = _args.getPtr<ParticleDataBase>("b", 1, &_lock);
+      const ParticleDataImpl<Real> *a = _args.getPtr<ParticleDataImpl<Real>>("a", 0, &_lock);
+      const ParticleDataImpl<Real> *b = _args.getPtr<ParticleDataImpl<Real>>("b", 1, &_lock);
       _retval = toPy(pdataMaxDiff(a, b));
       _args.check();
     }
@@ -1552,6 +1528,76 @@ void PbRegister_pdataMaxDiff()
 }
 }
 
+Real pdataMaxDiffInt(const ParticleDataImpl<int> *a, const ParticleDataImpl<int> *b)
+{
+  return getPdataMaxDiff(a, b);
+}
+static PyObject *_W_16(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
+{
+  try {
+    PbArgs _args(_linargs, _kwds);
+    FluidSolver *parent = _args.obtainParent();
+    bool noTiming = _args.getOpt<bool>("notiming", -1, 0);
+    pbPreparePlugin(parent, "pdataMaxDiffInt", !noTiming);
+    PyObject *_retval = 0;
+    {
+      ArgLocker _lock;
+      const ParticleDataImpl<int> *a = _args.getPtr<ParticleDataImpl<int>>("a", 0, &_lock);
+      const ParticleDataImpl<int> *b = _args.getPtr<ParticleDataImpl<int>>("b", 1, &_lock);
+      _retval = toPy(pdataMaxDiffInt(a, b));
+      _args.check();
+    }
+    pbFinalizePlugin(parent, "pdataMaxDiffInt", !noTiming);
+    return _retval;
+  }
+  catch (std::exception &e) {
+    pbSetError("pdataMaxDiffInt", e.what());
+    return 0;
+  }
+}
+static const Pb::Register _RP_pdataMaxDiffInt("", "pdataMaxDiffInt", _W_16);
+extern "C" {
+void PbRegister_pdataMaxDiffInt()
+{
+  KEEP_UNUSED(_RP_pdataMaxDiffInt);
+}
+}
+
+Real pdataMaxDiffVec3(const ParticleDataImpl<Vec3> *a, const ParticleDataImpl<Vec3> *b)
+{
+  return getPdataMaxDiff(a, b);
+}
+static PyObject *_W_17(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
+{
+  try {
+    PbArgs _args(_linargs, _kwds);
+    FluidSolver *parent = _args.obtainParent();
+    bool noTiming = _args.getOpt<bool>("notiming", -1, 0);
+    pbPreparePlugin(parent, "pdataMaxDiffVec3", !noTiming);
+    PyObject *_retval = 0;
+    {
+      ArgLocker _lock;
+      const ParticleDataImpl<Vec3> *a = _args.getPtr<ParticleDataImpl<Vec3>>("a", 0, &_lock);
+      const ParticleDataImpl<Vec3> *b = _args.getPtr<ParticleDataImpl<Vec3>>("b", 1, &_lock);
+      _retval = toPy(pdataMaxDiffVec3(a, b));
+      _args.check();
+    }
+    pbFinalizePlugin(parent, "pdataMaxDiffVec3", !noTiming);
+    return _retval;
+  }
+  catch (std::exception &e) {
+    pbSetError("pdataMaxDiffVec3", e.what());
+    return 0;
+  }
+}
+static const Pb::Register _RP_pdataMaxDiffVec3("", "pdataMaxDiffVec3", _W_17);
+extern "C" {
+void PbRegister_pdataMaxDiffVec3()
+{
+  KEEP_UNUSED(_RP_pdataMaxDiffVec3);
+}
+}
+
 //! calculate center of mass given density grid, for re-centering
 
 Vec3 calcCenterOfMass(const Grid<Real> &density)
@@ -1567,7 +1613,7 @@ Vec3 calcCenterOfMass(const Grid<Real> &density)
     p /= w;
   return p;
 }
-static PyObject *_W_16(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
+static PyObject *_W_18(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
 {
   try {
     PbArgs _args(_linargs, _kwds);
@@ -1589,7 +1635,7 @@ static PyObject *_W_16(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
     return 0;
   }
 }
-static const Pb::Register _RP_calcCenterOfMass("", "calcCenterOfMass", _W_16);
+static const Pb::Register _RP_calcCenterOfMass("", "calcCenterOfMass", _W_18);
 extern "C" {
 void PbRegister_calcCenterOfMass()
 {
@@ -1789,7 +1835,7 @@ void updateFractions(const FlagGrid &flags,
   fractions.setConst(Vec3(0.));
   KnUpdateFractions(flags, phiObs, fractions, boundaryWidth, fracThreshold);
 }
-static PyObject *_W_17(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
+static PyObject *_W_19(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
 {
   try {
     PbArgs _args(_linargs, _kwds);
@@ -1816,7 +1862,7 @@ static PyObject *_W_17(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
     return 0;
   }
 }
-static const Pb::Register _RP_updateFractions("", "updateFractions", _W_17);
+static const Pb::Register _RP_updateFractions("", "updateFractions", _W_19);
 extern "C" {
 void PbRegister_updateFractions()
 {
@@ -1968,7 +2014,7 @@ void setObstacleFlags(FlagGrid &flags,
 {
   KnUpdateFlagsObs(flags, fractions, phiObs, phiOut, phiIn, boundaryWidth);
 }
-static PyObject *_W_18(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
+static PyObject *_W_20(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
 {
   try {
     PbArgs _args(_linargs, _kwds);
@@ -1996,7 +2042,7 @@ static PyObject *_W_18(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
     return 0;
   }
 }
-static const Pb::Register _RP_setObstacleFlags("", "setObstacleFlags", _W_18);
+static const Pb:

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list