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:
Sebastián Barschkis 2020-02-28 15:31:10 +01:00
parent af54bbd61c
commit 21bdeb5cc0
3 changed files with 35 additions and 88 deletions

@ -17,16 +17,13 @@
// link to omp & tbb for now // link to omp & tbb for now
#if OPENMP == 1 || TBB == 1 #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 // allow the preconditioner to be computed in parallel? (can lead to slightly non-deterministic
// results) // results)
# define MANTA_ENABLE_PARALLEL_PC 0 # define MANTA_ENABLE_PARALLEL_PC 0
// use c++11 code?
# define MANTA_USE_CPP11 1
#else #else
# define MANTA_ENABLE_PARALLEL 0 # define MANTA_ENABLE_PARALLEL 0
# define MANTA_ENABLE_PARALLEL_PC 0 # define MANTA_ENABLE_PARALLEL_PC 0
# define MANTA_USE_CPP11 0
#endif #endif
#if MANTA_ENABLE_PARALLEL == 1 #if MANTA_ENABLE_PARALLEL == 1
@ -503,11 +500,7 @@ template<class N, class T> struct RCMatrix {
for (Iterator it = row_begin(i); it; ++it) for (Iterator it = row_begin(i); it; ++it)
result.fix_element(it.index(), i, it.value()); result.fix_element(it.index(), i, it.value());
} }
#if MANTA_USE_CPP11 == 1
return std::move(result);
#else
return result; return result;
#endif
} }
RCMatrix getKtK() const RCMatrix getKtK() const
@ -532,12 +525,7 @@ template<class N, class T> struct RCMatrix {
} }
} }
} }
parallel_end parallel_end return result;
#if MANTA_USE_CPP11 == 1
return std::move(result);
#else
return result;
#endif
} }
RCMatrix operator*(const RCMatrix &m) const RCMatrix operator*(const RCMatrix &m) const
@ -561,12 +549,7 @@ template<class N, class T> struct RCMatrix {
} }
} }
} }
parallel_end parallel_end return result;
#if MANTA_USE_CPP11 == 1
return std::move(result);
#else
return result;
#endif
} }
RCMatrix sqrt() const RCMatrix sqrt() const
@ -581,12 +564,7 @@ template<class N, class T> struct RCMatrix {
result.set_element(i, j, std::sqrt(it_A.value())); result.set_element(i, j, std::sqrt(it_A.value()));
} }
} }
parallel_end parallel_end return result;
#if MANTA_USE_CPP11 == 1
return std::move(result);
#else
return result;
#endif
} }
RCMatrix operator*(const double k) const 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); result.add_to_element(i, j, it_A.value() * k);
} }
} }
parallel_end parallel_end return result;
#if MANTA_USE_CPP11 == 1
return std::move(result);
#else
return result;
#endif
} }
RCMatrix applyKernel(const RCMatrix &kernel, const int nx, const int ny) const 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 parallel_end return result;
#if MANTA_USE_CPP11 == 1
return std::move(result);
#else
return result;
#endif
} }
RCMatrix applyHorizontalKernel(const RCMatrix &kernel, const int nx, const int ny) const 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 parallel_end return result;
#if MANTA_USE_CPP11 == 1
return std::move(result);
#else
return result;
#endif
} }
RCMatrix applyVerticalKernel(const RCMatrix &kernel, const int nx, const int ny) const 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 parallel_end return result;
#if MANTA_USE_CPP11 == 1
return std::move(result);
#else
return result;
#endif
} }
RCMatrix applySeparableKernel(const RCMatrix &kernelH, RCMatrix applySeparableKernel(const RCMatrix &kernelH,
@ -747,11 +705,7 @@ template<class N, class T> struct RCMatrix {
{ {
std::vector<T> result(n, 0.0); std::vector<T> result(n, 0.0);
multiply(rhs, result); multiply(rhs, result);
#if MANTA_USE_CPP11 == 1
return std::move(result);
#else
return result; return result;
#endif
} }
void multiply(const std::vector<T> &rhs, std::vector<T> &result) const 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++) { for (N i = 0; i < result.size(); i++) {
result[i] = std::abs(result[i] - rhs[i]); result[i] = std::abs(result[i] - rhs[i]);
} }
#if MANTA_USE_CPP11 == 1
return std::move(result);
#else
return result; return result;
#endif
} }
T norm() const T norm() const
{ {
@ -1024,11 +974,7 @@ template<class N, class T> struct RCFixedMatrix {
{ {
std::vector<T> result(n, 0.0); std::vector<T> result(n, 0.0);
multiply(rhs, result); multiply(rhs, result);
#if MANTA_USE_CPP11 == 1
return std::move(result);
#else
return result; return result;
#endif
} }
void multiply(const std::vector<T> &rhs, std::vector<T> &result) const 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 parallel_end return result;
#if MANTA_USE_CPP11 == 1
return std::move(result);
#else
return result;
#endif
} }
RCMatrix<N, T> toRCMatrix() const 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]; result.matrix[i]->value[j] = value[rowstart[i] + j];
} }
} }
parallel_end parallel_end return result;
#if MANTA_USE_CPP11 == 1
return std::move(result);
#else
return result;
#endif
} }
}; };

@ -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 MACGrid *fractions,
const Grid<Real> &phiObs, const Grid<Real> &phiObs,
const Grid<Real> *phiOut, const Grid<Real> *phiOut,
const Grid<Real> *phiIn) const Grid<Real> *phiIn,
: KernelBase(&flags, 1), int boundaryWidth)
: KernelBase(&flags, boundaryWidth),
flags(flags), flags(flags),
fractions(fractions), fractions(fractions),
phiObs(phiObs), phiObs(phiObs),
phiOut(phiOut), phiOut(phiOut),
phiIn(phiIn) phiIn(phiIn),
boundaryWidth(boundaryWidth)
{ {
runMessage(); runMessage();
run(); run();
@ -1847,7 +1849,8 @@ struct KnUpdateFlagsObs : public KernelBase {
const MACGrid *fractions, const MACGrid *fractions,
const Grid<Real> &phiObs, const Grid<Real> &phiObs,
const Grid<Real> *phiOut, const Grid<Real> *phiOut,
const Grid<Real> *phiIn) const const Grid<Real> *phiIn,
int boundaryWidth) const
{ {
bool isObs = false; bool isObs = false;
@ -1910,6 +1913,11 @@ struct KnUpdateFlagsObs : public KernelBase {
return phiIn; return phiIn;
} }
typedef Grid<Real> type4; typedef Grid<Real> type4;
inline int &getArg5()
{
return boundaryWidth;
}
typedef int type5;
void runMessage() void runMessage()
{ {
debMsg("Executing kernel KnUpdateFlagsObs ", 3); debMsg("Executing kernel KnUpdateFlagsObs ", 3);
@ -1923,15 +1931,15 @@ struct KnUpdateFlagsObs : public KernelBase {
const int _maxY = maxY; const int _maxY = maxY;
if (maxZ > 1) { if (maxZ > 1) {
for (int k = __r.begin(); k != (int)__r.end(); k++) for (int k = __r.begin(); k != (int)__r.end(); k++)
for (int j = 1; j < _maxY; j++) for (int j = boundaryWidth; j < _maxY; j++)
for (int i = 1; i < _maxX; i++) for (int i = boundaryWidth; i < _maxX; i++)
op(i, j, k, flags, fractions, phiObs, phiOut, phiIn); op(i, j, k, flags, fractions, phiObs, phiOut, phiIn, boundaryWidth);
} }
else { else {
const int k = 0; const int k = 0;
for (int j = __r.begin(); j != (int)__r.end(); j++) for (int j = __r.begin(); j != (int)__r.end(); j++)
for (int i = 1; i < _maxX; i++) for (int i = boundaryWidth; i < _maxX; i++)
op(i, j, k, flags, fractions, phiObs, phiOut, phiIn); op(i, j, k, flags, fractions, phiObs, phiOut, phiIn, boundaryWidth);
} }
} }
void run() void run()
@ -1939,13 +1947,14 @@ struct KnUpdateFlagsObs : public KernelBase {
if (maxZ > 1) if (maxZ > 1)
tbb::parallel_for(tbb::blocked_range<IndexInt>(minZ, maxZ), *this); tbb::parallel_for(tbb::blocked_range<IndexInt>(minZ, maxZ), *this);
else else
tbb::parallel_for(tbb::blocked_range<IndexInt>(1, maxY), *this); tbb::parallel_for(tbb::blocked_range<IndexInt>(boundaryWidth, maxY), *this);
} }
FlagGrid &flags; FlagGrid &flags;
const MACGrid *fractions; const MACGrid *fractions;
const Grid<Real> &phiObs; const Grid<Real> &phiObs;
const Grid<Real> *phiOut; const Grid<Real> *phiOut;
const Grid<Real> *phiIn; const Grid<Real> *phiIn;
int boundaryWidth;
}; };
//! update obstacle and outflow flags from levelsets //! update obstacle and outflow flags from levelsets
@ -1954,9 +1963,10 @@ void setObstacleFlags(FlagGrid &flags,
const Grid<Real> &phiObs, const Grid<Real> &phiObs,
const MACGrid *fractions = NULL, const MACGrid *fractions = NULL,
const Grid<Real> *phiOut = 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) 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 MACGrid *fractions = _args.getPtrOpt<MACGrid>("fractions", 2, NULL, &_lock);
const Grid<Real> *phiOut = _args.getPtrOpt<Grid<Real>>("phiOut", 3, 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); const Grid<Real> *phiIn = _args.getPtrOpt<Grid<Real>>("phiIn", 4, NULL, &_lock);
int boundaryWidth = _args.getOpt<int>("boundaryWidth", 5, 1, &_lock);
_retval = getPyNone(); _retval = getPyNone();
setObstacleFlags(flags, phiObs, fractions, phiOut, phiIn); setObstacleFlags(flags, phiObs, fractions, phiOut, phiIn, boundaryWidth);
_args.check(); _args.check();
} }
pbFinalizePlugin(parent, "setObstacleFlags", !noTiming); pbFinalizePlugin(parent, "setObstacleFlags", !noTiming);