[Bf-blender-cvs] [b8af5e10620] master: Fluid: Updated manta pp files
Sebastián Barschkis
noreply at git.blender.org
Fri Feb 21 15:32:52 CET 2020
Commit: b8af5e10620fe92f45c5e5003bfb6ef8d91e29bb
Author: Sebastián Barschkis
Date: Fri Feb 21 15:29:32 2020 +0100
Branches: master
https://developer.blender.org/rBb8af5e10620fe92f45c5e5003bfb6ef8d91e29bb
Fluid: Updated manta pp files
Updates include:
- A fix from Jacques that changed the loop order in the mesh creation function (the fix speeds up the function significantly due to fewer cache misses).
- Some of the grid copy helper functions are now multithreaded.
- A fix for Windows file IO. Now it possible to load files with non ASCII characters on Windows too.
===================================================================
M extern/mantaflow/preprocessed/fileio/ioutil.cpp
M extern/mantaflow/preprocessed/gitinfo.h
M extern/mantaflow/preprocessed/grid.cpp
M extern/mantaflow/preprocessed/levelset.cpp
===================================================================
diff --git a/extern/mantaflow/preprocessed/fileio/ioutil.cpp b/extern/mantaflow/preprocessed/fileio/ioutil.cpp
index 0bbbc7b6d11..e04633c5634 100644
--- a/extern/mantaflow/preprocessed/fileio/ioutil.cpp
+++ b/extern/mantaflow/preprocessed/fileio/ioutil.cpp
@@ -23,21 +23,36 @@ extern "C" {
# include <zlib.h>
}
+# if defined(WIN32) || defined(_WIN32)
+# include <windows.h>
+# include <string>
+# endif
+
+using namespace std;
+
namespace Manta {
-//! helper to handle non ascii filenames correctly, mainly problematic on windows
+# if defined(WIN32) || defined(_WIN32)
+static wstring stringToWstring(const char *str)
+{
+ const int length_wc = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
+ wstring strWide(length_wc, 0);
+ MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), &strWide[0], length_wc);
+ return strWide;
+}
+# endif
+
void *safeGzopen(const char *filename, const char *mode)
{
gzFile gzfile;
-# if 0
- UTF16_ENCODE(filename);
- // gzopen_w() is supported since zlib v1.2.7
- gzfile = gzopen_w(filename_16, mode);
- UTF16_UN_ENCODE(filename);
+# if defined(WIN32) || defined(_WIN32)
+ wstring filenameWide = stringToWstring(filename);
+ gzfile = gzopen_w(filenameWide.c_str(), mode);
# else
gzfile = gzopen(filename, mode);
# endif
+
return gzfile;
}
#endif
diff --git a/extern/mantaflow/preprocessed/gitinfo.h b/extern/mantaflow/preprocessed/gitinfo.h
index 0e84563eae3..614bf2b91c4 100644
--- a/extern/mantaflow/preprocessed/gitinfo.h
+++ b/extern/mantaflow/preprocessed/gitinfo.h
@@ -1,3 +1,3 @@
-#define MANTA_GIT_VERSION "commit 7b9e0d841274c65dce911ec578bd0b4779971422"
+#define MANTA_GIT_VERSION "commit ce000bcbd7004e6549ac2f118755fcdc1f679bc3"
diff --git a/extern/mantaflow/preprocessed/grid.cpp b/extern/mantaflow/preprocessed/grid.cpp
index c21d56d8879..f10052349d5 100644
--- a/extern/mantaflow/preprocessed/grid.cpp
+++ b/extern/mantaflow/preprocessed/grid.cpp
@@ -1244,15 +1244,67 @@ void PbRegister_gridMaxDiffVec3()
}
}
+struct knCopyMacToVec3 : public KernelBase {
+ knCopyMacToVec3(MACGrid &source, Grid<Vec3> &target)
+ : KernelBase(&source, 0), source(source), target(target)
+ {
+ runMessage();
+ run();
+ }
+ inline void op(int i, int j, int k, MACGrid &source, Grid<Vec3> &target) const
+ {
+ target(i, j, k) = source(i, j, k);
+ }
+ inline MACGrid &getArg0()
+ {
+ return source;
+ }
+ typedef MACGrid type0;
+ inline Grid<Vec3> &getArg1()
+ {
+ return target;
+ }
+ typedef Grid<Vec3> type1;
+ void runMessage()
+ {
+ debMsg("Executing kernel knCopyMacToVec3 ", 3);
+ debMsg("Kernel range"
+ << " x " << maxX << " y " << maxY << " z " << minZ << " - " << maxZ << " ",
+ 4);
+ };
+ void operator()(const tbb::blocked_range<IndexInt> &__r) const
+ {
+ const int _maxX = maxX;
+ const int _maxY = maxY;
+ if (maxZ > 1) {
+ for (int k = __r.begin(); k != (int)__r.end(); k++)
+ for (int j = 0; j < _maxY; j++)
+ for (int i = 0; i < _maxX; i++)
+ op(i, j, k, source, target);
+ }
+ else {
+ const int k = 0;
+ for (int j = __r.begin(); j != (int)__r.end(); j++)
+ for (int i = 0; i < _maxX; i++)
+ op(i, j, k, source, target);
+ }
+ }
+ void run()
+ {
+ if (maxZ > 1)
+ tbb::parallel_for(tbb::blocked_range<IndexInt>(minZ, maxZ), *this);
+ else
+ tbb::parallel_for(tbb::blocked_range<IndexInt>(0, maxY), *this);
+ }
+ MACGrid &source;
+ Grid<Vec3> ⌖
+};
// simple helper functions to copy (convert) mac to vec3 , and levelset to real grids
// (are assumed to be the same for running the test cases - in general they're not!)
void copyMacToVec3(MACGrid &source, Grid<Vec3> &target)
{
- FOR_IJK(target)
- {
- target(i, j, k) = source(i, j, k);
- }
+ knCopyMacToVec3(source, target);
}
static PyObject *_W_3(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
{
@@ -1323,10 +1375,14 @@ void PbRegister_convertMacToVec3()
}
}
-//! vec3->mac grid conversion , but with full resampling
-void resampleVec3ToMac(Grid<Vec3> &source, MACGrid &target)
-{
- FOR_IJK_BND(target, 1)
+struct knResampleVec3ToMac : public KernelBase {
+ knResampleVec3ToMac(Grid<Vec3> &source, MACGrid &target)
+ : KernelBase(&source, 1), source(source), target(target)
+ {
+ runMessage();
+ run();
+ }
+ inline void op(int i, int j, int k, Grid<Vec3> &source, MACGrid &target) const
{
target(i, j, k)[0] = 0.5 * (source(i - 1, j, k)[0] + source(i, j, k))[0];
target(i, j, k)[1] = 0.5 * (source(i, j - 1, k)[1] + source(i, j, k))[1];
@@ -1334,6 +1390,55 @@ void resampleVec3ToMac(Grid<Vec3> &source, MACGrid &target)
target(i, j, k)[2] = 0.5 * (source(i, j, k - 1)[2] + source(i, j, k))[2];
}
}
+ inline Grid<Vec3> &getArg0()
+ {
+ return source;
+ }
+ typedef Grid<Vec3> type0;
+ inline MACGrid &getArg1()
+ {
+ return target;
+ }
+ typedef MACGrid type1;
+ void runMessage()
+ {
+ debMsg("Executing kernel knResampleVec3ToMac ", 3);
+ debMsg("Kernel range"
+ << " x " << maxX << " y " << maxY << " z " << minZ << " - " << maxZ << " ",
+ 4);
+ };
+ void operator()(const tbb::blocked_range<IndexInt> &__r) const
+ {
+ const int _maxX = maxX;
+ const int _maxY = maxY;
+ if (maxZ > 1) {
+ for (int k = __r.begin(); k != (int)__r.end(); k++)
+ for (int j = 1; j < _maxY; j++)
+ for (int i = 1; i < _maxX; i++)
+ op(i, j, k, source, target);
+ }
+ else {
+ const int k = 0;
+ for (int j = __r.begin(); j != (int)__r.end(); j++)
+ for (int i = 1; i < _maxX; i++)
+ op(i, j, k, source, target);
+ }
+ }
+ void run()
+ {
+ if (maxZ > 1)
+ tbb::parallel_for(tbb::blocked_range<IndexInt>(minZ, maxZ), *this);
+ else
+ tbb::parallel_for(tbb::blocked_range<IndexInt>(1, maxY), *this);
+ }
+ Grid<Vec3> &source;
+ MACGrid ⌖
+};
+//! vec3->mac grid conversion , but with full resampling
+
+void resampleVec3ToMac(Grid<Vec3> &source, MACGrid &target)
+{
+ knResampleVec3ToMac(source, target);
}
static PyObject *_W_5(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
{
@@ -1367,13 +1472,66 @@ void PbRegister_resampleVec3ToMac()
}
}
-//! mac->vec3 grid conversion , with full resampling
-void resampleMacToVec3(MACGrid &source, Grid<Vec3> &target)
-{
- FOR_IJK_BND(target, 1)
+struct knResampleMacToVec3 : public KernelBase {
+ knResampleMacToVec3(MACGrid &source, Grid<Vec3> &target)
+ : KernelBase(&source, 1), source(source), target(target)
+ {
+ runMessage();
+ run();
+ }
+ inline void op(int i, int j, int k, MACGrid &source, Grid<Vec3> &target) const
{
target(i, j, k) = source.getCentered(i, j, k);
}
+ inline MACGrid &getArg0()
+ {
+ return source;
+ }
+ typedef MACGrid type0;
+ inline Grid<Vec3> &getArg1()
+ {
+ return target;
+ }
+ typedef Grid<Vec3> type1;
+ void runMessage()
+ {
+ debMsg("Executing kernel knResampleMacToVec3 ", 3);
+ debMsg("Kernel range"
+ << " x " << maxX << " y " << maxY << " z " << minZ << " - " << maxZ << " ",
+ 4);
+ };
+ void operator()(const tbb::blocked_range<IndexInt> &__r) const
+ {
+ const int _maxX = maxX;
+ const int _maxY = maxY;
+ if (maxZ > 1) {
+ for (int k = __r.begin(); k != (int)__r.end(); k++)
+ for (int j = 1; j < _maxY; j++)
+ for (int i = 1; i < _maxX; i++)
+ op(i, j, k, source, target);
+ }
+ else {
+ const int k = 0;
+ for (int j = __r.begin(); j != (int)__r.end(); j++)
+ for (int i = 1; i < _maxX; i++)
+ op(i, j, k, source, target);
+ }
+ }
+ void run()
+ {
+ if (maxZ > 1)
+ tbb::parallel_for(tbb::blocked_range<IndexInt>(minZ, maxZ), *this);
+ else
+ tbb::parallel_for(tbb::blocked_range<IndexInt>(1, maxY), *this);
+ }
+ MACGrid &source;
+ Grid<Vec3> ⌖
+};
+//! mac->vec3 grid conversion , with full resampling
+
+void resampleMacToVec3(MACGrid &source, Grid<Vec3> &target)
+{
+ knResampleMacToVec3(source, target);
}
static PyObject *_W_6(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
{
@@ -1407,12 +1565,65 @@ void PbRegister_resampleMacToVec3()
}
}
-void copyLevelsetToReal(LevelsetGrid &source, Grid<Real> &target)
-{
- FOR_IJK(target)
+struct knCopyLevelsetToReal : public KernelBase {
+ knCopyLevelsetToReal(LevelsetGrid &source, Grid<Real> &target)
+ : KernelBase(&source, 0), source(source), target(target)
+ {
+ runMessage();
+ run();
+ }
+ inline void op(int i, int j, int k, LevelsetGrid &source, Grid<Real> &target) const
{
target(i, j, k) = source(i, j, k);
}
+ inline LevelsetGrid &getArg0()
+ {
+ return source;
+ }
+ typedef LevelsetGrid type0;
+ inline Grid<Real> &getArg1()
+ {
+ return target;
+ }
+ typedef Grid<Real> type1;
+ void runMessage()
+ {
+ debMsg("Executing kernel knCopyLevelsetToReal ", 3);
+ debMsg("Kernel range"
+ << " x " << maxX << " y " << maxY << " z " << minZ << " - " << maxZ << " ",
+ 4);
+ };
+ void operator()(const tbb::blocked_range<IndexInt> &__r) const
+ {
+ const int _maxX = maxX;
+ const int _maxY = maxY;
+ if (maxZ > 1) {
+ for (int k = __r.begin(); k != (int)__r.end(); k++)
+ for (int j = 0; j < _maxY; j++)
+ for (int i = 0; i < _maxX; i++)
+ op(i, j, k, source, target);
+ }
+ else {
+ const int k = 0;
+ for (int j = __r.begin(); j != (int)__r.end(); j++)
+ for (int i = 0; i < _maxX; i++)
+ op(i, j, k, source, target);
+ }
+ }
+ void run()
+ {
+ if (maxZ > 1)
+ tbb::parallel_for(tbb::blocked_range<IndexInt>(minZ, maxZ), *this);
+ else
+ tbb::parallel_for(tbb::blocked_range<IndexInt>(0, maxY), *this);
+ }
+ LevelsetGrid &source;
+ Grid<Real> ⌖
+};
+
+void copyLevelsetToReal(LevelsetGrid &source, Grid<Real> &target)
+{
+ knCopyLevelsetToReal(source, target);
}
static PyObject *_W_7(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
{
@@ -1446,17 +1657,95 @@ void PbRegister_copyLevelsetToReal()
}
}
-void copyVec3ToReal(Grid<Vec3> &source,
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list