forked from bartvdbraak/blender
Fluid: Updated Manta pp files
Updates include: - std::move() cleanup in rcmatrix.h - Enabled parallelization for fluid guiding (fairly noticeable speed improvement). - More flexible flags setter function with control over boundary width.
This commit is contained in:
parent
af54bbd61c
commit
21bdeb5cc0
84
extern/mantaflow/helper/util/rcmatrix.h
vendored
84
extern/mantaflow/helper/util/rcmatrix.h
vendored
@ -17,16 +17,13 @@
|
||||
|
||||
// link to omp & tbb for now
|
||||
#if OPENMP == 1 || TBB == 1
|
||||
# define MANTA_ENABLE_PARALLEL 0
|
||||
# define MANTA_ENABLE_PARALLEL 1
|
||||
// allow the preconditioner to be computed in parallel? (can lead to slightly non-deterministic
|
||||
// results)
|
||||
# define MANTA_ENABLE_PARALLEL_PC 0
|
||||
// use c++11 code?
|
||||
# define MANTA_USE_CPP11 1
|
||||
#else
|
||||
# define MANTA_ENABLE_PARALLEL 0
|
||||
# define MANTA_ENABLE_PARALLEL_PC 0
|
||||
# define MANTA_USE_CPP11 0
|
||||
#endif
|
||||
|
||||
#if MANTA_ENABLE_PARALLEL == 1
|
||||
@ -503,11 +500,7 @@ template<class N, class T> struct RCMatrix {
|
||||
for (Iterator it = row_begin(i); it; ++it)
|
||||
result.fix_element(it.index(), i, it.value());
|
||||
}
|
||||
#if MANTA_USE_CPP11 == 1
|
||||
return std::move(result);
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
RCMatrix getKtK() const
|
||||
@ -532,12 +525,7 @@ template<class N, class T> struct RCMatrix {
|
||||
}
|
||||
}
|
||||
}
|
||||
parallel_end
|
||||
#if MANTA_USE_CPP11 == 1
|
||||
return std::move(result);
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
parallel_end return result;
|
||||
}
|
||||
|
||||
RCMatrix operator*(const RCMatrix &m) const
|
||||
@ -561,12 +549,7 @@ template<class N, class T> struct RCMatrix {
|
||||
}
|
||||
}
|
||||
}
|
||||
parallel_end
|
||||
#if MANTA_USE_CPP11 == 1
|
||||
return std::move(result);
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
parallel_end return result;
|
||||
}
|
||||
|
||||
RCMatrix sqrt() const
|
||||
@ -581,12 +564,7 @@ template<class N, class T> struct RCMatrix {
|
||||
result.set_element(i, j, std::sqrt(it_A.value()));
|
||||
}
|
||||
}
|
||||
parallel_end
|
||||
#if MANTA_USE_CPP11 == 1
|
||||
return std::move(result);
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
parallel_end return result;
|
||||
}
|
||||
|
||||
RCMatrix operator*(const double k) const
|
||||
@ -601,12 +579,7 @@ template<class N, class T> struct RCMatrix {
|
||||
result.add_to_element(i, j, it_A.value() * k);
|
||||
}
|
||||
}
|
||||
parallel_end
|
||||
#if MANTA_USE_CPP11 == 1
|
||||
return std::move(result);
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
parallel_end return result;
|
||||
}
|
||||
|
||||
RCMatrix applyKernel(const RCMatrix &kernel, const int nx, const int ny) const
|
||||
@ -640,12 +613,7 @@ template<class N, class T> struct RCMatrix {
|
||||
}
|
||||
}
|
||||
}
|
||||
parallel_end
|
||||
#if MANTA_USE_CPP11 == 1
|
||||
return std::move(result);
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
parallel_end return result;
|
||||
}
|
||||
|
||||
RCMatrix applyHorizontalKernel(const RCMatrix &kernel, const int nx, const int ny) const
|
||||
@ -679,12 +647,7 @@ template<class N, class T> struct RCMatrix {
|
||||
}
|
||||
}
|
||||
}
|
||||
parallel_end
|
||||
#if MANTA_USE_CPP11 == 1
|
||||
return std::move(result);
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
parallel_end return result;
|
||||
}
|
||||
|
||||
RCMatrix applyVerticalKernel(const RCMatrix &kernel, const int nx, const int ny) const
|
||||
@ -718,12 +681,7 @@ template<class N, class T> struct RCMatrix {
|
||||
}
|
||||
}
|
||||
}
|
||||
parallel_end
|
||||
#if MANTA_USE_CPP11 == 1
|
||||
return std::move(result);
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
parallel_end return result;
|
||||
}
|
||||
|
||||
RCMatrix applySeparableKernel(const RCMatrix &kernelH,
|
||||
@ -747,11 +705,7 @@ template<class N, class T> struct RCMatrix {
|
||||
{
|
||||
std::vector<T> result(n, 0.0);
|
||||
multiply(rhs, result);
|
||||
#if MANTA_USE_CPP11 == 1
|
||||
return std::move(result);
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
void multiply(const std::vector<T> &rhs, std::vector<T> &result) const
|
||||
{
|
||||
@ -832,11 +786,7 @@ template<class N, class T> struct RCMatrix {
|
||||
for (N i = 0; i < result.size(); i++) {
|
||||
result[i] = std::abs(result[i] - rhs[i]);
|
||||
}
|
||||
#if MANTA_USE_CPP11 == 1
|
||||
return std::move(result);
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
T norm() const
|
||||
{
|
||||
@ -1024,11 +974,7 @@ template<class N, class T> struct RCFixedMatrix {
|
||||
{
|
||||
std::vector<T> result(n, 0.0);
|
||||
multiply(rhs, result);
|
||||
#if MANTA_USE_CPP11 == 1
|
||||
return std::move(result);
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
void multiply(const std::vector<T> &rhs, std::vector<T> &result) const
|
||||
{
|
||||
@ -1064,12 +1010,7 @@ template<class N, class T> struct RCFixedMatrix {
|
||||
}
|
||||
}
|
||||
}
|
||||
parallel_end
|
||||
#if MANTA_USE_CPP11 == 1
|
||||
return std::move(result);
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
parallel_end return result;
|
||||
}
|
||||
|
||||
RCMatrix<N, T> toRCMatrix() const
|
||||
@ -1087,12 +1028,7 @@ template<class N, class T> struct RCFixedMatrix {
|
||||
result.matrix[i]->value[j] = value[rowstart[i] + j];
|
||||
}
|
||||
}
|
||||
parallel_end
|
||||
#if MANTA_USE_CPP11 == 1
|
||||
return std::move(result);
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
parallel_end return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
2
extern/mantaflow/preprocessed/gitinfo.h
vendored
2
extern/mantaflow/preprocessed/gitinfo.h
vendored
@ -1,3 +1,3 @@
|
||||
|
||||
|
||||
#define MANTA_GIT_VERSION "commit ce000bcbd7004e6549ac2f118755fcdc1f679bc3"
|
||||
#define MANTA_GIT_VERSION "commit 1d52e96ad602f1974dfee75bef293bc397e4b41b"
|
||||
|
@ -1829,13 +1829,15 @@ struct KnUpdateFlagsObs : public KernelBase {
|
||||
const MACGrid *fractions,
|
||||
const Grid<Real> &phiObs,
|
||||
const Grid<Real> *phiOut,
|
||||
const Grid<Real> *phiIn)
|
||||
: KernelBase(&flags, 1),
|
||||
const Grid<Real> *phiIn,
|
||||
int boundaryWidth)
|
||||
: KernelBase(&flags, boundaryWidth),
|
||||
flags(flags),
|
||||
fractions(fractions),
|
||||
phiObs(phiObs),
|
||||
phiOut(phiOut),
|
||||
phiIn(phiIn)
|
||||
phiIn(phiIn),
|
||||
boundaryWidth(boundaryWidth)
|
||||
{
|
||||
runMessage();
|
||||
run();
|
||||
@ -1847,7 +1849,8 @@ struct KnUpdateFlagsObs : public KernelBase {
|
||||
const MACGrid *fractions,
|
||||
const Grid<Real> &phiObs,
|
||||
const Grid<Real> *phiOut,
|
||||
const Grid<Real> *phiIn) const
|
||||
const Grid<Real> *phiIn,
|
||||
int boundaryWidth) const
|
||||
{
|
||||
|
||||
bool isObs = false;
|
||||
@ -1910,6 +1913,11 @@ struct KnUpdateFlagsObs : public KernelBase {
|
||||
return phiIn;
|
||||
}
|
||||
typedef Grid<Real> type4;
|
||||
inline int &getArg5()
|
||||
{
|
||||
return boundaryWidth;
|
||||
}
|
||||
typedef int type5;
|
||||
void runMessage()
|
||||
{
|
||||
debMsg("Executing kernel KnUpdateFlagsObs ", 3);
|
||||
@ -1923,15 +1931,15 @@ struct KnUpdateFlagsObs : public KernelBase {
|
||||
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, flags, fractions, phiObs, phiOut, phiIn);
|
||||
for (int j = boundaryWidth; j < _maxY; j++)
|
||||
for (int i = boundaryWidth; i < _maxX; i++)
|
||||
op(i, j, k, flags, fractions, phiObs, phiOut, phiIn, boundaryWidth);
|
||||
}
|
||||
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, flags, fractions, phiObs, phiOut, phiIn);
|
||||
for (int i = boundaryWidth; i < _maxX; i++)
|
||||
op(i, j, k, flags, fractions, phiObs, phiOut, phiIn, boundaryWidth);
|
||||
}
|
||||
}
|
||||
void run()
|
||||
@ -1939,13 +1947,14 @@ struct KnUpdateFlagsObs : public KernelBase {
|
||||
if (maxZ > 1)
|
||||
tbb::parallel_for(tbb::blocked_range<IndexInt>(minZ, maxZ), *this);
|
||||
else
|
||||
tbb::parallel_for(tbb::blocked_range<IndexInt>(1, maxY), *this);
|
||||
tbb::parallel_for(tbb::blocked_range<IndexInt>(boundaryWidth, maxY), *this);
|
||||
}
|
||||
FlagGrid &flags;
|
||||
const MACGrid *fractions;
|
||||
const Grid<Real> &phiObs;
|
||||
const Grid<Real> *phiOut;
|
||||
const Grid<Real> *phiIn;
|
||||
int boundaryWidth;
|
||||
};
|
||||
|
||||
//! update obstacle and outflow flags from levelsets
|
||||
@ -1954,9 +1963,10 @@ void setObstacleFlags(FlagGrid &flags,
|
||||
const Grid<Real> &phiObs,
|
||||
const MACGrid *fractions = NULL,
|
||||
const Grid<Real> *phiOut = NULL,
|
||||
const Grid<Real> *phiIn = NULL)
|
||||
const Grid<Real> *phiIn = NULL,
|
||||
int boundaryWidth = 1)
|
||||
{
|
||||
KnUpdateFlagsObs(flags, fractions, phiObs, phiOut, phiIn);
|
||||
KnUpdateFlagsObs(flags, fractions, phiObs, phiOut, phiIn, boundaryWidth);
|
||||
}
|
||||
static PyObject *_W_18(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
|
||||
{
|
||||
@ -1973,8 +1983,9 @@ static PyObject *_W_18(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
|
||||
const MACGrid *fractions = _args.getPtrOpt<MACGrid>("fractions", 2, NULL, &_lock);
|
||||
const Grid<Real> *phiOut = _args.getPtrOpt<Grid<Real>>("phiOut", 3, NULL, &_lock);
|
||||
const Grid<Real> *phiIn = _args.getPtrOpt<Grid<Real>>("phiIn", 4, NULL, &_lock);
|
||||
int boundaryWidth = _args.getOpt<int>("boundaryWidth", 5, 1, &_lock);
|
||||
_retval = getPyNone();
|
||||
setObstacleFlags(flags, phiObs, fractions, phiOut, phiIn);
|
||||
setObstacleFlags(flags, phiObs, fractions, phiOut, phiIn, boundaryWidth);
|
||||
_args.check();
|
||||
}
|
||||
pbFinalizePlugin(parent, "setObstacleFlags", !noTiming);
|
||||
|
Loading…
Reference in New Issue
Block a user