From aa547ce88b9c4607e070f8b76341ae2076f28ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastia=CC=81n=20Barschkis?= Date: Thu, 16 Jul 2020 16:39:14 +0200 Subject: 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. --- extern/mantaflow/helper/util/vectorbase.h | 30 +++++ extern/mantaflow/preprocessed/gitinfo.h | 2 +- extern/mantaflow/preprocessed/mesh.cpp | 4 +- extern/mantaflow/preprocessed/particle.cpp | 4 +- .../mantaflow/preprocessed/plugin/initplugins.cpp | 144 ++++++++++++++------- extern/mantaflow/preprocessed/registration.cpp | 4 + 6 files changed, 134 insertions(+), 54 deletions(-) (limited to 'extern/mantaflow') 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 inline S sum(const S v) +{ + return v; +} +template inline S sum(const Vector3D &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 inline Vector3D abs(const Vector3D &v) +{ + Vector3D 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 inline Vector3D getNormalized(const Vector3D &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 void MeshDataImpl::setSource(Grid *grid, bool isMAC) { mpGridSource = grid; mGridSourceMAC = isMAC; - if (isMAC) - assertMsg(dynamic_cast(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 void MeshDataImpl::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 void ParticleDataImpl::setSource(Grid *grid, bool isMAC) { mpGridSource = grid; mGridSourceMAC = isMAC; - if (isMAC) - assertMsg(dynamic_cast(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 void ParticleDataImpl::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 Real getPdataMaxDiff(const ParticleDataImpl *a, const ParticleDataImpl *b) { - double maxVal = 0.; - // debMsg(" PD "<< a->getType()<<" as"<getSizeSlow()<<" bs"<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 &av = *dynamic_cast *>(a); - const ParticleDataImpl &bv = *dynamic_cast *>(b); - FOR_PARTS(av) - { - maxVal = std::max(maxVal, (double)fabs(av[idx] - bv[idx])); - } - } - else if (a->getType() & ParticleDataBase::TypeInt) { - const ParticleDataImpl &av = *dynamic_cast *>(a); - const ParticleDataImpl &bv = *dynamic_cast *>(b); - FOR_PARTS(av) - { - maxVal = std::max(maxVal, (double)fabs((double)av[idx] - bv[idx])); - } - } - else if (a->getType() & ParticleDataBase::TypeVec3) { - const ParticleDataImpl &av = *dynamic_cast *>(a); - const ParticleDataImpl &bv = *dynamic_cast *>(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 *a, const ParticleDataImpl *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("a", 0, &_lock); - const ParticleDataBase *b = _args.getPtr("b", 1, &_lock); + const ParticleDataImpl *a = _args.getPtr>("a", 0, &_lock); + const ParticleDataImpl *b = _args.getPtr>("b", 1, &_lock); _retval = toPy(pdataMaxDiff(a, b)); _args.check(); } @@ -1552,6 +1528,76 @@ void PbRegister_pdataMaxDiff() } } +Real pdataMaxDiffInt(const ParticleDataImpl *a, const ParticleDataImpl *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("notiming", -1, 0); + pbPreparePlugin(parent, "pdataMaxDiffInt", !noTiming); + PyObject *_retval = 0; + { + ArgLocker _lock; + const ParticleDataImpl *a = _args.getPtr>("a", 0, &_lock); + const ParticleDataImpl *b = _args.getPtr>("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 *a, const ParticleDataImpl *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("notiming", -1, 0); + pbPreparePlugin(parent, "pdataMaxDiffVec3", !noTiming); + PyObject *_retval = 0; + { + ArgLocker _lock; + const ParticleDataImpl *a = _args.getPtr>("a", 0, &_lock); + const ParticleDataImpl *b = _args.getPtr>("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 &density) @@ -1567,7 +1613,7 @@ Vec3 calcCenterOfMass(const Grid &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::Register _RP_setObstacleFlags("", "setObstacleFlags", _W_20); extern "C" { void PbRegister_setObstacleFlags() { @@ -2113,7 +2159,7 @@ void initVortexVelocity(const Grid &phiObs, { kninitVortexVelocity(phiObs, vel, center, radius); } -static PyObject *_W_19(PyObject *_self, PyObject *_linargs, PyObject *_kwds) +static PyObject *_W_21(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); @@ -2139,7 +2185,7 @@ static PyObject *_W_19(PyObject *_self, PyObject *_linargs, PyObject *_kwds) return 0; } } -static const Pb::Register _RP_initVortexVelocity("", "initVortexVelocity", _W_19); +static const Pb::Register _RP_initVortexVelocity("", "initVortexVelocity", _W_21); extern "C" { void PbRegister_initVortexVelocity() { @@ -2465,7 +2511,7 @@ int blurMacGrid(MACGrid &oG, MACGrid &tG, float si) } return tmGK.mDim; } -static PyObject *_W_20(PyObject *_self, PyObject *_linargs, PyObject *_kwds) +static PyObject *_W_22(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); @@ -2489,7 +2535,7 @@ static PyObject *_W_20(PyObject *_self, PyObject *_linargs, PyObject *_kwds) return 0; } } -static const Pb::Register _RP_blurMacGrid("", "blurMacGrid", _W_20); +static const Pb::Register _RP_blurMacGrid("", "blurMacGrid", _W_22); extern "C" { void PbRegister_blurMacGrid() { @@ -2501,7 +2547,7 @@ int blurRealGrid(Grid &oG, Grid &tG, float si) { return blurGrid(oG, tG, si); } -static PyObject *_W_21(PyObject *_self, PyObject *_linargs, PyObject *_kwds) +static PyObject *_W_23(PyObject *_self, PyObject *_linargs, PyObject *_kwds) { try { PbArgs _args(_linargs, _kwds); @@ -2525,7 +2571,7 @@ static PyObject *_W_21(PyObject *_self, PyObject *_linargs, PyObject *_kwds) return 0; } } -static const Pb::Register _RP_blurRealGrid("", "blurRealGrid", _W_21); +static const Pb::Register _RP_blurRealGrid("", "blurRealGrid", _W_23); extern "C" { void PbRegister_blurRealGrid() { diff --git a/extern/mantaflow/preprocessed/registration.cpp b/extern/mantaflow/preprocessed/registration.cpp index 6c1e68e6523..d5dae479f0e 100644 --- a/extern/mantaflow/preprocessed/registration.cpp +++ b/extern/mantaflow/preprocessed/registration.cpp @@ -111,6 +111,8 @@ extern void PbRegister_checkSymmetryVec3(); extern void PbRegister_projectPpmFull(); extern void PbRegister_addTestParts(); extern void PbRegister_pdataMaxDiff(); +extern void PbRegister_pdataMaxDiffInt(); +extern void PbRegister_pdataMaxDiffVec3(); extern void PbRegister_calcCenterOfMass(); extern void PbRegister_updateFractions(); extern void PbRegister_setObstacleFlags(); @@ -306,6 +308,8 @@ void MantaEnsureRegistration() PbRegister_projectPpmFull(); PbRegister_addTestParts(); PbRegister_pdataMaxDiff(); + PbRegister_pdataMaxDiffInt(); + PbRegister_pdataMaxDiffVec3(); PbRegister_calcCenterOfMass(); PbRegister_updateFractions(); PbRegister_setObstacleFlags(); -- cgit v1.2.3