HDK
|
#include <CE_Multigrid.h>
Public Member Functions | |
CE_Multigrid () | |
~CE_Multigrid () override | |
CE_Multigrid (const CE_Multigrid &)=default | |
CE_Multigrid & | operator= (const CE_Multigrid &)=default |
void | init (const UT_Vector3I &res, const UT_Vector3 &spacing, const UT_Vector3I &boundariesNeg, const UT_Vector3I &boundariesPos, int level=0, UT_Vector3I oddCoarsenings=UT_Vector3I(0, 0, 0)) |
Initialize array to given size, spacing, and boundary conditions. More... | |
void | initFromVoxels (const UT_VoxelArrayF &f, const UT_Vector3 &spacing, const UT_Vector3I &boundariesNeg, const UT_Vector3I &boundariesPos) |
void | updateBoundaryConditions (bool struts=false) const |
int | getMaxCoarse (int minPerAxis) const |
int | getLevel () const |
Returns a grid's level within the multigrid hierarchy. More... | |
UT_Vector3I | getParity () const |
Returns a vector containing the odd/even parity for each axis. More... | |
void | match (const CE_Multigrid &src) |
void | subtractApplyLaplacian (CE_Multigrid &x, CE_Multigrid &r) const |
Computes rhe residual r = b - A * x, where b == *this. More... | |
void | computeResidualNorms (const CE_Multigrid &x, fpreal64 &norminf, fpreal64 &norm2) const |
void | smoothLaplacianGaussSeidel (CE_Multigrid &x, int iterations=1, bool useSmall=true) const |
bool | smoothLaplacianGaussSeidelSmall (CE_Multigrid &x, int iterations=1) const |
void | directSolve (CE_Multigrid &x) const |
void | coarsenAlongAxis (CE_Multigrid &uh, int axis) const |
UT_Vector3I | coarsen (int minPerAxis, CE_Multigrid &uh) const |
Coarsen this grid into a lower resolution version of the grid. More... | |
void | interpolateAlongAxis (CE_Multigrid &u, int axis) const |
void | interpolate (const UT_Vector3I &coarsenAxis, const UT_Vector3I &parity, CE_Multigrid &u) const |
void | vcycle (int minPerAxis, int nSmoothDown, int nSmoothUp, CE_Multigrid &x, bool smoothTopLevelDown=true) const |
void | fullMultigrid (int minPerAxis, int nSmoothDown, int nSmoothUp, CE_Multigrid &x) const |
int | solvePoisson (fpreal64 abstol, fpreal64 reltol, int miniter, int maxiter, CE_Multigrid &x, UT_ValArray< fpreal64 > *resnorminf, UT_ValArray< fpreal64 > *resnorm2, bool finishBetweenIters=false, bool startFMG=true) const |
Public Member Functions inherited from CE_Grid | |
CE_Grid () | |
CE_Grid (const CE_Grid &src) | |
virtual | ~CE_Grid () |
const cl::Buffer & | buffer () const |
bool | hasBuffer () const |
If the current OpenCL buffer is valid. More... | |
void | size (int xres, int yres, int zres, int xghost=1, int yghost=1, int zghost=1, int xpad=1, int ypad=1, int zpad=1) |
int | getXRes () const |
int | getYRes () const |
int | getZRes () const |
int | getRes (int dim) const |
UT_Vector3I | getRes () const |
UT_Vector3I | getGhostRes () const |
int | getGhostRes (int dim) const |
UT_Vector3I | getPadding () const |
int | getPadding (int dim) const |
int | getOffset () const |
int | getGhostOffset () const |
void | setBorder (UT_VoxelBorderType type, fpreal32 t) |
UT_VoxelBorderType | getBorder () const |
fpreal32 | getBorderValue () const |
void | setBorderScale (fpreal32 scalex, fpreal32 scaley, fpreal32 scalez) |
fpreal32 | getBorderScale (int axis) const |
bool | indexToPos (int x, int y, int z, UT_Vector3F &pos) const |
void | updateBorderCells () const |
int64 | numVoxels () const |
Returns the number of data voxels in the grid. More... | |
int64 | numTotalVoxels () const |
int64 | totalVoxelMemory () const |
void | initFromVoxels (const UT_VoxelArrayF &src, int xghost=1, int yghost=1, int zghost=1, int xpad=1, int ypad=1, int zpad=1) |
void | matchAndCopyToVoxels (UT_VoxelArrayF &dest, bool includeGhostCells=false) const |
void | match (const CE_Grid &src) |
Match the src CE_Grid in terms of size and border conditions. More... | |
bool | isMatching (const CE_Grid &src) const |
bool | isCongruent (const CE_Grid &src) const |
Returns true if this CE_Grid matches src in terms of offset and strides. More... | |
int | getXStride () const |
int | getYStride () const |
int | getZStride () const |
int | getStride (int dim) const |
UT_Vector3I | getStrides () const |
int | getGhostStride (int axis) const |
Returns the stride along axis including ghost cells. More... | |
bool | isAxis2D (int axis) const |
Returns whether the specified axis is 2-dimensional. More... | |
int | getAxis2D () const |
Returns the 2-dimensional axis of this grid, or -1 if there is none. More... | |
int | getXStride2D (int axis2d) const |
2D strides. More... | |
int | getYStride2D (int axis2d) const |
int | getXStride2D3D () const |
int | getYStride2D3D () const |
int | getZStride2D3D () const |
Returns the true Z-stride if the grid is 3D, or 0 if 2D. More... | |
int | getXRes2D3D () const |
int | getYRes2D3D () const |
int | getZRes2D3D () const |
Returns the true z resolution if the grid is 3D, or 1 if 2D. More... | |
void | constant (fpreal32 v) |
void | zero () |
bool | isConstant (fpreal32 *cval=0, bool checkBorders=false) const |
void | copyData (const CE_Grid &src) |
CE_Grid & | operator= (const CE_Grid &src) |
Assign to this, equivalent to match(src), followed by copyData(src). More... | |
void | stealBuffer (CE_Grid &src) |
Steal the buffer from the other grid, leaving it unitialized. More... | |
CE_Grid & | operator+= (const CE_Grid &src) |
cl::NDRange | getGlobalRange () const |
cl::NDRange | getGlobalRange2D (int axis2d) const |
cl::NDRange | getGlobalRange2D3D () const |
cl::NDRange | getLocalRange2D3D () const |
cl::KernelFunctor | bind (cl::Kernel k, const cl::NDRange *lrange=nullptr, int n=1) const |
cl::KernelFunctor | bind (cl::Program prog, const char *kernelname) const |
cl::KernelFunctor | bind2D (int axis, cl::Kernel k) const |
cl::KernelFunctor | bind2D (int axis, cl::Program prog, const char *kernelname) const |
cl::KernelFunctor | bind2D3D (cl::Kernel k) const |
cl::KernelFunctor | bind2D3D (cl::Program prog, const char *kernelname) const |
void | scaledAddCornerFromCenter (fpreal32 c1, const CE_Grid &g1) |
void | linearCombination (fpreal32 c0, const CE_Grid &g0, fpreal32 d) |
void | linearCombination (fpreal32 c0, const CE_Grid &g0, fpreal32 c1, const CE_Grid &g1, fpreal32 d) |
void | linearCombination (fpreal32 c0, const CE_Grid &g0, fpreal32 c1, const CE_Grid &g1, fpreal32 c2, const CE_Grid &g2, fpreal32 d) |
void | divergence (const CE_Grid &x, const CE_Grid &y, const CE_Grid &z, fpreal32 scale, UT_Vector3 voxelSize) |
void | divergenceCenterToCorner (const CE_Grid &x, const CE_Grid &y, const CE_Grid &z, fpreal32 scale, UT_Vector3 voxelSize) |
void | applyGradient (const CE_Grid &p, fpreal32 scale, fpreal32 voxelSize, int axis) |
void | applyGradientCornerToCenter (const CE_Grid &p, fpreal32 scale, fpreal32 voxelsize, int axis) |
fpreal64 | sum () const |
Reductions of the grid to a single value. More... | |
fpreal64 | sumAbs () const |
fpreal64 | sumSqr () const |
fpreal64 | min () const |
fpreal64 | minAbs () const |
fpreal64 | max () const |
fpreal64 | maxAbs () const |
fpreal64 | average () const |
fpreal64 | localAverage (UT_Vector3I &radius) |
fpreal64 | localSum (UT_Vector3I &radius) |
fpreal64 | localSumSqr (UT_Vector3I &radius) |
fpreal64 | localSumAbs (UT_Vector3I &radius) |
fpreal64 | localMin (UT_Vector3I &radius) |
fpreal64 | localMinAbs (UT_Vector3I &radius) |
fpreal64 | localMax (UT_Vector3I &radius) |
fpreal64 | localMaxAbs (UT_Vector3I &radius) |
void | boxBlur (int passes, UT_Vector3 radius) |
void | computeNorms (fpreal64 &norminf, fpreal64 &norm2) const |
Compute the infinity-norm and 2-norm of the grid. More... | |
Protected Member Functions | |
UT_Vector3I | coarsenByAxis (int minPerAxis, CE_Multigrid &uh) const |
void | interpolateByAxis (const UT_Vector3I &coarsenAxis, const UT_Vector3I &parity, CE_Multigrid &u) const |
void | initLaplacian () |
Protected Member Functions inherited from CE_Grid | |
const cl::Buffer & | allocBuffer () const |
void | releaseBuffer () |
void | setValue (fpreal32 cval) const |
void | getReductionRanges (const cl::Kernel &k, cl::NDRange &globalRange, cl::NDRange &localRange, uint &groupsize, uint &ngroups, size_t &accumsize) const |
fpreal64 | reduceFlat (cl::Buffer outgrid, uint groupsize, uint ngroups, size_t accumsize, const char *reduceFlags) const |
fpreal64 | doReduce (const char *reduceFlags) const |
bool | doLocalReduce (const char *options, UT_Vector3I &radius) |
Additional Inherited Members | |
Static Public Member Functions inherited from CE_Grid | |
static int | getXAxis2D (int axis2d) |
static int | getYAxis2D (int axis2d) |
static cl::NDRange | getLocalRange (const cl::NDRange &g) |
Create a local work item range for the supplied global range. More... | |
This class provides a specializaion of CE_Grid that can solve the 2D or 3D Poisson equation using the multigrid algorithm, running on an OpenCL device. It's interface closely matches that of UT_MultigridArray.
Definition at line 23 of file CE_Multigrid.h.
CE_Multigrid::CE_Multigrid | ( | ) |
|
override |
|
default |
UT_Vector3I CE_Multigrid::coarsen | ( | int | minPerAxis, |
CE_Multigrid & | uh | ||
) | const |
Coarsen this grid into a lower resolution version of the grid.
void CE_Multigrid::coarsenAlongAxis | ( | CE_Multigrid & | uh, |
int | axis | ||
) | const |
Performs coarsening using full-weighting along one axis. On output
|
protected |
Coarsen this grid into a lower resolution version of the grid, by explicitly coarsening each axis sequentially.
void CE_Multigrid::computeResidualNorms | ( | const CE_Multigrid & | x, |
fpreal64 & | norminf, | ||
fpreal64 & | norm2 | ||
) | const |
Computes the inf and 2-norm of the residual r = b - A * x, where b == *this.
void CE_Multigrid::directSolve | ( | CE_Multigrid & | x | ) | const |
Directly solve the Poisson equation that this grid represents. This function should only be called for small grids. At the moment this always calls smoothLaplacianGaussSeidelSmall() with a large number of iterations.
void CE_Multigrid::fullMultigrid | ( | int | minPerAxis, |
int | nSmoothDown, | ||
int | nSmoothUp, | ||
CE_Multigrid & | x | ||
) | const |
Performs recursive Full Multigrid to generate an initial guess for the solution of the Poisson equation represented by this array. At each level, nSmoothDown and nSmoothUp iterations of smoothing are done.
|
inline |
Returns a grid's level within the multigrid hierarchy.
Definition at line 64 of file CE_Multigrid.h.
Calculates the maximum coarse grid elements in the coarsest grid, based on the minPerAxis parameter.
|
inline |
Returns a vector containing the odd/even parity for each axis.
Definition at line 67 of file CE_Multigrid.h.
void CE_Multigrid::init | ( | const UT_Vector3I & | res, |
const UT_Vector3 & | spacing, | ||
const UT_Vector3I & | boundariesNeg, | ||
const UT_Vector3I & | boundariesPos, | ||
int | level = 0 , |
||
UT_Vector3I | oddCoarsenings = UT_Vector3I(0, 0, 0) |
||
) |
Initialize array to given size, spacing, and boundary conditions.
void CE_Multigrid::initFromVoxels | ( | const UT_VoxelArrayF & | f, |
const UT_Vector3 & | spacing, | ||
const UT_Vector3I & | boundariesNeg, | ||
const UT_Vector3I & | boundariesPos | ||
) |
Initializes this grid from the provided UT_VoxelArray, assuming the provided grid spacing.
|
protected |
void CE_Multigrid::interpolate | ( | const UT_Vector3I & | coarsenAxis, |
const UT_Vector3I & | parity, | ||
CE_Multigrid & | u | ||
) | const |
Interpolate this grid into a fine version of the grid. coarsenAxis is a vector of booleans specifying which axes to interpolate Where interpolateAxis[axis] is true, ensure that
void CE_Multigrid::interpolateAlongAxis | ( | CE_Multigrid & | u, |
int | axis | ||
) | const |
Interpolate this array into u using inverse of full-weighting along one axis. On output
|
protected |
Interpolate this grid into a fine version of the grid. This version explicitly interpolates each axis sequentially.
void CE_Multigrid::match | ( | const CE_Multigrid & | src | ) |
Initializes this to be the same dimensions, boundary conditions, etc, of the given grid.
|
default |
void CE_Multigrid::smoothLaplacianGaussSeidel | ( | CE_Multigrid & | x, |
int | iterations = 1 , |
||
bool | useSmall = true |
||
) | const |
Performs red-black Gauss-Seidel smoothing, where b == *this, and the implicit matrix is the Laplacian operator. If useSmall is true, this use callsmoothLaplacianGaussSeidelSmall() if possible.
bool CE_Multigrid::smoothLaplacianGaussSeidelSmall | ( | CE_Multigrid & | x, |
int | iterations = 1 |
||
) | const |
Performs red-black Gauss-Seidel smoothing, using a kernel that only works when the entire grid can fit in one workgroup on the OpenCL device. Returns false if the criteria to run are not met.
int CE_Multigrid::solvePoisson | ( | fpreal64 | abstol, |
fpreal64 | reltol, | ||
int | miniter, | ||
int | maxiter, | ||
CE_Multigrid & | x, | ||
UT_ValArray< fpreal64 > * | resnorminf, | ||
UT_ValArray< fpreal64 > * | resnorm2, | ||
bool | finishBetweenIters = false , |
||
bool | startFMG = true |
||
) | const |
Iteratively solve the Poisson equation, assuming *this is the right hand side. This function will do at least miniter iterations, then continue to iterate until the 2-norm of the residual has been reduced by reltol, the inf-norm of the residual is below abstol, or maxiters is reached. The optional resnorm0 and resnorm2 parameters will contain the 0- and 2-norms of the residuals for each iteration. If startFMG is true, the first iteration will be full-multigrid; otherwise, only v-cycles are used.
void CE_Multigrid::subtractApplyLaplacian | ( | CE_Multigrid & | x, |
CE_Multigrid & | r | ||
) | const |
Computes rhe residual r = b - A * x, where b == *this.
void CE_Multigrid::updateBoundaryConditions | ( | bool | struts = false | ) | const |
Update the grid's ghost cells with values that enforce the boundary conditions at its particular level in the multigrid hierarchy. If struts is true, ghost cells that are outside two or more of the axes are also updated (like + in the following diagram, where * represent the ghost cells that are filled in regardless of the value of struts). +*************+
void CE_Multigrid::vcycle | ( | int | minPerAxis, |
int | nSmoothDown, | ||
int | nSmoothUp, | ||
CE_Multigrid & | x, | ||
bool | smoothTopLevelDown = true |
||
) | const |
Perform recursive V-cycle for multigrid algorithm, until reaching numElements() < maxcoarse, at which point a direct solve is done using directSolve.. At each level, nSmoothDown and nSmoothUp iterations of Gauss-Seidel smoothing are done, unless smoothTopLevelDown is false, in which case no smoothing is done for the top-level grid on the down-cycle. This can be used as an optimization when calling vcycle iteratively; the previous vcycle call will have smoothed the top-level grid as its last step, so you can often skip smoothing that same grid on the next vcycle without loss of convergence.
|
protected |
Definition at line 182 of file CE_Multigrid.h.
|
protected |
Definition at line 182 of file CE_Multigrid.h.
|
protected |
Definition at line 179 of file CE_Multigrid.h.
|
protected |
Definition at line 179 of file CE_Multigrid.h.
|
protected |
Definition at line 177 of file CE_Multigrid.h.
|
protected |
Definition at line 177 of file CE_Multigrid.h.
|
protected |
Definition at line 178 of file CE_Multigrid.h.
|
protected |
Definition at line 178 of file CE_Multigrid.h.
|
protected |
Definition at line 175 of file CE_Multigrid.h.
|
protected |
Definition at line 180 of file CE_Multigrid.h.
|
protected |
Definition at line 180 of file CE_Multigrid.h.
|
protected |
Definition at line 176 of file CE_Multigrid.h.
|
protected |
Definition at line 181 of file CE_Multigrid.h.
|
protected |
Definition at line 183 of file CE_Multigrid.h.
|
protected |
Definition at line 175 of file CE_Multigrid.h.
|
protected |
Definition at line 176 of file CE_Multigrid.h.