HDK
|
#include <UT_MGOperator.h>
Classes | |
struct | utMGCoordAndCoeff |
struct | utMGTileMap |
Public Member Functions | |
UT_MGOperatorT (int threshold=100) | |
template<typename S > | |
void | init (const UT_VoxelArray< S > &ref, S inactive, const UT_Vector3T< T > &spacing, const UT_Vector3I &boundariesNeg, const UT_Vector3I &boundariesPos) |
template<typename S > | |
void | init (const UT_VoxelArray< S > &ref, const UT_Vector3T< T > &spacing, const UT_Vector3I &boundariesNeg, const UT_Vector3I &boundariesPos) |
template<typename S > | |
void | initFromStencil (const UT_VoxelArray< S > &stencil, const UT_Vector3T< T > &spacing, const UT_Vector3I &boundariesNeg, const UT_Vector3I &boundariesPos) |
void | mgRestrict (const UT_VectorT< T > &src, UT_VectorT< T > &dst, int l) const |
Applies the restriction operator from level l to level l+1. More... | |
void | mgProlong (const UT_VectorT< T > &src, UT_VectorT< T > &dst, int l) const |
Applies the prolongation operator from level l+1 to level l. More... | |
void | copyFromVoxels (const UT_VoxelArray< T > &src, UT_VectorT< T > &dst) const |
Flattens contents of the given voxel array into the vector. More... | |
void | copyToVoxels (const UT_VectorT< T > &src, UT_VoxelArray< T > &dst, bool topad) const |
int | solvePoisson (fpreal64 abstol, fpreal64 reltol, int maxiter, UT_VoxelArray< T > &x, const UT_VoxelArray< T > &b, UT_ValArray< fpreal64 > *resnorminf, UT_ValArray< fpreal64 > *resnorm2, bool startFMG=true) |
void | subtractApplyLaplacian (const UT_VectorT< T > &x, const UT_VectorT< T > &b, UT_VectorT< T > &d, int level) const |
void | applyLaplacian (const UT_VectorT< T > &x, UT_VectorT< T > &b, int level) const |
Calculates Lx at the given level and puts the answer in b. More... | |
void | fullMultigrid (UT_VectorT< T > &x, const UT_VectorT< T > &b, UT_VectorT< T > &t0, UT_VectorT< T > &t1, int level) |
void | vcycle (UT_VectorT< T > &x, UT_VectorT< T > &t, const UT_VectorT< T > &b, int level) |
template<bool ZERO_GUESS = false> | |
void | smoothLaplacian (UT_VectorT< T > &x, const UT_VectorT< T > &x0, const UT_VectorT< T > &b, T omega, int level, bool redFirst) const |
void | smoothLaplacianHomogeneous (UT_VectorT< T > &x, const UT_VectorT< T > &x0, int level) const |
void | directSolve (UT_VectorT< T > &x, const UT_VectorT< T > &b) const |
Performs a direct solve at the coarsest level. More... | |
UT_Vector3i | getTileMapResolution (int level) const |
Returns the tile map's resolution at the given level. More... | |
exint | getNumVoxels (int level) const |
Returns the number of voxels at the given level. More... | |
int | getNumTiles (int level) const |
Returns the number of active tiles at the given level. More... | |
int | getNumLevels () const |
Returns the number of tile map levels (depth of the operator). More... | |
int | buildMatrix (UT_MatrixT< T > &M, int level) const |
Public Attributes | |
int | mySmoothingPasses |
Number of pre- and post-smoothing passes to perform in a V-cycle. More... | |
int | myDiffusionPasses |
T | myAmplificationFactor |
Amplification factor after prolongation (for V- and full multigrid cycles). More... | |
T | myJacobiOmega |
Damping parameter for Jacobi smoothing passes. More... | |
T | myGSOmega |
Overrelaxation parameter for Gauss-Seidel smoothing passes. More... | |
Protected Member Functions | |
template<typename S > | |
void | initTileMap0 (const UT_VoxelArray< S > &ref, S inactive, bool tileMap) |
void | addTileMapLevel () |
Adds a tile map one level coarser than the coarsest in the atlas. More... | |
void | factorFinalLevel () |
void | finishInit () |
T | getEdgeWeight (int x, int y, int z, int level, int axis) const |
T | getDiagonalWeight (int x, int y, int z, int level) const |
Returns the diagonal value in the matrix at the given voxel and level. More... | |
template<bool RESTRICT, int LEVEL> | |
void | mgRestrictProlongN (const UT_VectorT< T > &src, UT_VectorT< T > &dst) const |
template<bool RESTRICT> | |
void | mgRestrictProlongP (const UT_VectorT< T > &src, UT_VectorT< T > &dst, int level) const |
template<int LEVEL, bool SUBTRACT> | |
void | applyLaplacianInternalN (const UT_VectorT< T > &x, const UT_VectorT< T > &b, UT_VectorT< T > &d) const |
template<bool SUBTRACT> | |
void | applyLaplacianInternalP (const UT_VectorT< T > &x, const UT_VectorT< T > &b, UT_VectorT< T > &d, int level) const |
template<int LEVEL, bool ZERO_GUESS, bool FIRST_PASS> | |
void | smoothLaplacianInternalGS (UT_VectorT< T > &x, const UT_VectorT< T > &b, T omega, int parity) const |
template<bool ZERO_GUESS, bool FIRST_PASS> | |
void | smoothLaplacianInternalGS_V1 (UT_VectorT< T > &x, const UT_VectorT< T > &b, T omega, int parity) const |
template<bool ZERO_GUESS, bool FIRST_PASS> | |
void | smoothLaplacianInternalGS_V2 (UT_VectorT< T > &x, const UT_VectorT< T > &b, T omega, int parity) const |
template<int LEVEL, bool ZERO_GUESS, bool FIRST_PASS> | |
void | smoothLaplacianInternalGS_V34 (UT_VectorT< T > &x, const UT_VectorT< T > &b, T omega, int parity) const |
template<int LEVEL, bool HOMOGENEOUS> | |
void | smoothLaplacianInternalJN (UT_VectorT< T > &x, const UT_VectorT< T > &x0, const UT_VectorT< T > &b, T omega) const |
template<bool HOMOGENEOUS> | |
void | smoothLaplacianInternalJN_V1 (UT_VectorT< T > &x, const UT_VectorT< T > &x0, const UT_VectorT< T > &b, T omega) const |
template<int LEVEL, bool HOMOGENEOUS> | |
void | smoothLaplacianInternalJN_V234 (UT_VectorT< T > &x, const UT_VectorT< T > &x0, const UT_VectorT< T > &b, T omega) const |
template<bool HOMOGENEOUS, bool ZERO_GUESS> | |
void | smoothLaplacianInternalJP (UT_VectorT< T > &x, const UT_VectorT< T > &x0, const UT_VectorT< T > &b, T omega, int level) const |
template<int LEVEL> | |
void | getTilePointers (int tile, const UT_VectorT< T > &b, T *data[7], T border[6]) const |
THREADED_METHOD3_CONST (UT_MGOperatorT, dst.numTiles() > 500, copyToVoxelsHelper, const UT_VectorT< T > &, src, UT_VoxelArray< T > &, dst, bool, topad) | |
void | copyToVoxelsHelperPartial (const UT_VectorT< T > &src, UT_VoxelArray< T > &dst, bool toPad, const UT_JobInfo &info) const |
Protected Attributes | |
UT_Vector4T< T > | myInternalCoeff |
UT_Vector3I | myBoundariesNeg |
Conditions at the lower/left/back boundaries of the map. More... | |
UT_Vector3I | myBoundariesPos |
Conditions at the upper/right/front boundaries of the map. More... | |
UT_Array< utMGTileMap > | myAtlas |
Array of tile map levels. More... | |
UT_MatrixT< T > | myCoarseCholeskyL |
UT_VectorT< T > | myCoarseCholeskyD |
const int | myVoxelCountThreshold |
UT_Array< UT_VectorT< T > > | myScratchpad |
Definition at line 27 of file UT_MGOperator.h.
|
inline |
Once initialized, this operator is algebraically coarsened until the number of degrees of freedom does not exceed the provided threshold.
Definition at line 32 of file UT_MGOperator.h.
|
protected |
Adds a tile map one level coarser than the coarsest in the atlas.
void UT_MGOperatorT< T >::applyLaplacian | ( | const UT_VectorT< T > & | x, |
UT_VectorT< T > & | b, | ||
int | level | ||
) | const |
Calculates Lx at the given level and puts the answer in b.
|
inlineprotected |
Helper function for applying the Laplacian operator. LEVEL must be pre-negated (so it is positive). If SUBTRACT is true computes b-Lx, otherwise calculates Lx.
|
inlineprotected |
Helper function for subtractApplyLaplacian(), for non-negative levels. If SUBTRACT is true, computes b-Lx, otherwise calculates Lx.
int UT_MGOperatorT< T >::buildMatrix | ( | UT_MatrixT< T > & | M, |
int | level | ||
) | const |
Build the tile Laplacian matrix at the specified level. Only works for non- negative levels. Returns the number of rows/columns.
void UT_MGOperatorT< T >::copyFromVoxels | ( | const UT_VoxelArray< T > & | src, |
UT_VectorT< T > & | dst | ||
) | const |
Flattens contents of the given voxel array into the vector.
void UT_MGOperatorT< T >::copyToVoxels | ( | const UT_VectorT< T > & | src, |
UT_VoxelArray< T > & | dst, | ||
bool | topad | ||
) | const |
Copies the contents of the flattened vector into the voxel array. If topad is true, then destination array will have an extra layer of voxels compared to the internal tile map, whose entries will be set to 0.
|
protected |
void UT_MGOperatorT< T >::directSolve | ( | UT_VectorT< T > & | x, |
const UT_VectorT< T > & | b | ||
) | const |
Performs a direct solve at the coarsest level.
|
protected |
Builds the coefficient matrix for the linear system at the last level. Also factors it to allow for fast linear solves.
|
protected |
Helper function to for initialization. Coarsens the map until the degrees of freedom are sufficiently reduced, factors the final level, and allocates the scratchpad.
void UT_MGOperatorT< T >::fullMultigrid | ( | UT_VectorT< T > & | x, |
const UT_VectorT< T > & | b, | ||
UT_VectorT< T > & | t0, | ||
UT_VectorT< T > & | t1, | ||
int | level | ||
) |
Does a full multigrid solve to get an approximation for the solution to the equation Lx=b at the given level. Note that x must be pre-initialized, but its incoming contents are irrelevant. t0 and t1 are used to perform intermediate work and must be pre-allocated.
|
inlineprotected |
Returns the diagonal value in the matrix at the given voxel and level.
|
inlineprotected |
Returns the off-diagonal value in the matrix between the node at the given location and the next one along the supplied axis; works at the provided level. Note that axis must be in [0, 5], coresponding to -X, +X, -Y, +Y, -Z, +Z.
int UT_MGOperatorT< T >::getNumLevels | ( | ) | const |
Returns the number of tile map levels (depth of the operator).
int UT_MGOperatorT< T >::getNumTiles | ( | int | level | ) | const |
Returns the number of active tiles at the given level.
exint UT_MGOperatorT< T >::getNumVoxels | ( | int | level | ) | const |
Returns the number of voxels at the given level.
UT_Vector3i UT_MGOperatorT< T >::getTileMapResolution | ( | int | level | ) | const |
Returns the tile map's resolution at the given level.
|
protected |
Puts pointers to the blocks from the given vector into the data array. Border compensations for adjusting the diagonal value are also placed in the border array.
void UT_MGOperatorT< T >::init | ( | const UT_VoxelArray< S > & | ref, |
S | inactive, | ||
const UT_Vector3T< T > & | spacing, | ||
const UT_Vector3I & | boundariesNeg, | ||
const UT_Vector3I & | boundariesPos | ||
) |
Initializes this operator to the Laplacian matrix with the given spacing and boundary conditions. This method also takes care of setting up the coarser operators. Tiles in the operator corresponds to tiles of the reference array. Active tiles are non-constant or different from inactive. All dimensions of the reference array must be divisible by 16.
void UT_MGOperatorT< T >::init | ( | const UT_VoxelArray< S > & | ref, |
const UT_Vector3T< T > & | spacing, | ||
const UT_Vector3I & | boundariesNeg, | ||
const UT_Vector3I & | boundariesPos | ||
) |
This version of initialization takes a validity map (whose resolution should match that of the finest tile map) and performs the necessary setup. Active tiles have a non-zero value in the reference voxel array. Resolution of this operator will be 16 times the resolution of the reference array.
void UT_MGOperatorT< T >::initFromStencil | ( | const UT_VoxelArray< S > & | stencil, |
const UT_Vector3T< T > & | spacing, | ||
const UT_Vector3I & | boundariesNeg, | ||
const UT_Vector3I & | boundariesPos | ||
) |
This version of initialization accepts a stencil array. Tiles in the operator are activated if the corresponding tile in the stencil array has at least one voxel whose value exceeds 0.5. All dimension of the reference array must be divisible by 16.
|
protected |
Helper function to create the finest level tile map from the given reference voxel array. If tileMap is false, tiles of the array are considered active if they are not constant and equal to the inactive argument. If tileMap is true, ref is assumed to be the same resolution as the finest tile map, and a tile is active if its value in ref is non-zero. Spacing and boundary conditions must be set prior to calling this function.
void UT_MGOperatorT< T >::mgProlong | ( | const UT_VectorT< T > & | src, |
UT_VectorT< T > & | dst, | ||
int | l | ||
) | const |
Applies the prolongation operator from level l+1 to level l.
void UT_MGOperatorT< T >::mgRestrict | ( | const UT_VectorT< T > & | src, |
UT_VectorT< T > & | dst, | ||
int | l | ||
) | const |
Applies the restriction operator from level l to level l+1.
|
inlineprotected |
Helper function for mgRestrict() and mgProlong(), for negative levels. If RESTRICT is true, src is restricted to a coarser level and stored in dst. If RESTRICT is false, src is prolongated to a finer level and stored in dst. LEVEL must be pre-negated (so it is positive).
|
inlineprotected |
Helper function for mgRestrict(), for non-negative levels. If RESTRICT is true, src is restricted to a coarser level and stored in dst. If RESTRICT is false, src is prolongated to a finer level and stored in dst.
void UT_MGOperatorT< T >::smoothLaplacian | ( | UT_VectorT< T > & | x, |
const UT_VectorT< T > & | x0, | ||
const UT_VectorT< T > & | b, | ||
T | omega, | ||
int | level, | ||
bool | redFirst | ||
) | const |
Does a single iteration of relaxation on the solution vector at the given level. For positive levels, uses Jacobi relaxation; for negative levels, performs red-black Gauss-Seidel, with redFirst indicating which color to smooth first. For Jacobi smoothing (non-negative levels) x0 is the vector to relax, x will hold the result. These vectors must be distinct! For Gauss-Seidel smoothing (negative levels), x holds the input and output solutions, so x0 is unused. If ZERO_GUESS is true, it is assumed that the incoming vector is zero.
void UT_MGOperatorT< T >::smoothLaplacianHomogeneous | ( | UT_VectorT< T > & | x, |
const UT_VectorT< T > & | x0, | ||
int | level | ||
) | const |
Does a single iteration of homogeneous relaxation (smoothing for the system Lx=0). Uses Jacobi relaxation without damping. x0 is the vector to relax, x will hold the results; these vectors must be distinct!
|
inlineprotected |
Performs a single step of red-black Gauss-Seidel relaxation for voxels of the given parity. Note that this helper function is intended for negative levels (multiple voxels per tile). The template parameter must be pre-negated (so it is positive). If ZERO_GUESS is true, FIRST_PASS signals whether or not one of the colors has already been processed. The difference is that on the second pass, values of the previous color must be used, but colors of the current color are still assumed to be zero. This generic function implements the relaxation for all types and negative levels.
|
inlineprotected |
Performs a single step of red-black Gauss-Seidel relaxation for voxels of the given parity at level -1. This is a specialized method that either calls the generic function or does the work itself using SIMD.
|
inlineprotected |
Performs a single step of red-black Gauss-Seidel relaxation for voxels of the given parity at level -2. This is a specialized method that either calls the generic function or does the work itself using SIMD.
|
inlineprotected |
Performs a single step of red-black Gauss-Seidel relaxation for voxels of the given parity at level -3 or -4. This is a specialized method that either calls the generic function or does the work itself using SIMD.
|
inlineprotected |
Performs a single step of Jacobi relaxation. This helper function is intended for negative levels (the template parameter must be pre-negated so it is positive. CAUTION: x and x0 must be distinct! b vector is unused if relaxation is homogeneous. Likewise, omega is unused (no damping). This generic function implements the relaxation for all types and negative levels.
|
inlineprotected |
Performs a single step of Jacobi relaxation at level -1. This is a specialized method that either calls the generic function or does the work itself using SIMD.
|
inlineprotected |
Performs a single step of Jacobi relaxation at levels -2, -3, or -4. This is a specialized method that either calls the generic function or does the work itself using SIMD.
|
inlineprotected |
Performs a single step of Jacobi relaxation. This helper function is intended for non-negative levels. CAUTION: x and x0 must be distinct! b vector is unused if relaxation is homogeneous. Likewise, omega is unused (no damping).
int UT_MGOperatorT< T >::solvePoisson | ( | fpreal64 | abstol, |
fpreal64 | reltol, | ||
int | maxiter, | ||
UT_VoxelArray< T > & | x, | ||
const UT_VoxelArray< T > & | b, | ||
UT_ValArray< fpreal64 > * | resnorminf, | ||
UT_ValArray< fpreal64 > * | resnorm2, | ||
bool | startFMG = true |
||
) |
Solves the linear system using multigrid. The solution is stored in x, which will be initialized to the appropriate size. If b has incomplete tiles, x will be padded with an extra layer of voxels along every dimension. If startFMG is true, the first iteration will be full-multigrid; otherwise, only v-cycles are used.
void UT_MGOperatorT< T >::subtractApplyLaplacian | ( | const UT_VectorT< T > & | x, |
const UT_VectorT< T > & | b, | ||
UT_VectorT< T > & | d, | ||
int | level | ||
) | const |
Calculates b-Lx at the given level and puts the answer in d (note that b and d can be the same vector).
|
protected |
Multithreaded helper for copyToVoxels. dst should be set to the correct size before calling this.
void UT_MGOperatorT< T >::vcycle | ( | UT_VectorT< T > & | x, |
UT_VectorT< T > & | t, | ||
const UT_VectorT< T > & | b, | ||
int | level | ||
) |
Approximates a solution for the equation Lx=b using a single V-cycle. Note that x will be re-initialized, so its incoming contents are irrelevant. t is a temporary vector that must be allocated to the same size as x.
T UT_MGOperatorT< T >::myAmplificationFactor |
Amplification factor after prolongation (for V- and full multigrid cycles).
Definition at line 333 of file UT_MGOperator.h.
|
protected |
Array of tile map levels.
Definition at line 311 of file UT_MGOperator.h.
|
protected |
Conditions at the lower/left/back boundaries of the map.
Definition at line 306 of file UT_MGOperator.h.
|
protected |
Conditions at the upper/right/front boundaries of the map.
Definition at line 308 of file UT_MGOperator.h.
|
protected |
Definition at line 316 of file UT_MGOperator.h.
|
protected |
The factored coefficient matrix for the linear system at the coarsest tile level.
Definition at line 315 of file UT_MGOperator.h.
int UT_MGOperatorT< T >::myDiffusionPasses |
Number of homogeneous smoothing passes to perform after prolongation in a V- and full multigrid cycles.
Definition at line 331 of file UT_MGOperator.h.
T UT_MGOperatorT< T >::myGSOmega |
Overrelaxation parameter for Gauss-Seidel smoothing passes.
Definition at line 337 of file UT_MGOperator.h.
|
protected |
Internal coefficients for the Laplacian operator; first three hold the weights along each axis, followed by the diagonal weight.
Definition at line 304 of file UT_MGOperator.h.
T UT_MGOperatorT< T >::myJacobiOmega |
Damping parameter for Jacobi smoothing passes.
Definition at line 335 of file UT_MGOperator.h.
|
protected |
Array of pre-allocated temporary vectors for use in the Poisson solve (2 per level).
Definition at line 324 of file UT_MGOperator.h.
int UT_MGOperatorT< T >::mySmoothingPasses |
Number of pre- and post-smoothing passes to perform in a V-cycle.
Definition at line 328 of file UT_MGOperator.h.
|
protected |
The tile map is coarsened until its number of voxels is smaller than this value.
Definition at line 320 of file UT_MGOperator.h.