文章目录
latticeTemplates3D.h
在src/latticeBoltzmann/latticeTemplates3D.h
这部分来源于latticeTemplates3D.h文件,可以预见主要是在lattice上的操作
template<typename T>
struct latticeTemplates<T, descriptors::ForcedD3Q19Descriptor> {
static void swapAndStreamCell (
Cell<T,descriptors::ForcedD3Q19Descriptor> ***grid,
plint iX, plint iY, plint iZ, plint nX, plint nY, plint nZ, plint iPop, T& fTmp )
{
fTmp = grid[iX][iY][iZ][iPop];
grid[iX][iY][iZ][iPop] = grid[iX][iY][iZ][iPop+9];
grid[iX][iY][iZ][iPop+9] = grid[nX][nY][nZ][iPop];
grid[nX][nY][nZ][iPop] = fTmp;
}
static void swapAndStream3D(Cell<T,descriptors::ForcedD3Q19Descriptor> ***grid,
plint iX, plint iY, plint iZ)
{
T fTmp;
swapAndStreamCell(grid, iX, iY, iZ, iX-1, iY, iZ, 1, fTmp);
swapAndStreamCell(grid, iX, iY, iZ, iX, iY-1, iZ, 2, fTmp);
swapAndStreamCell(grid, iX, iY, iZ, iX, iY , iZ-1, 3, fTmp);
swapAndStreamCell(grid, iX, iY, iZ, iX-1, iY-1, iZ, 4, fTmp);
swapAndStreamCell(grid, iX, iY, iZ, iX-1, iY+1, iZ, 5, fTmp);
swapAndStreamCell(grid, iX, iY, iZ, iX-1, iY , iZ-1, 6, fTmp);
swapAndStreamCell(grid, iX, iY, iZ, iX-1, iY , iZ+1, 7, fTmp);
swapAndStreamCell(grid, iX, iY, iZ, iX , iY-1, iZ-1, 8, fTmp);
swapAndStreamCell(grid, iX, iY, iZ, iX , iY-1, iZ+1, 9, fTmp);
}
};
externalForceTemplates3D.h(主体部分)
在src/latticeBoltzmann/externalForceTemplates3D.h
则涉及到了分布函数的算法。
其中力是如下方法处理的,可见是由externalScalars与forceBeginsAt相加而成。
static const int forceBeginsAt
= descriptors::ForcedD3Q19Descriptor<T>::ExternalField::forceBeginsAt;
T* force = externalScalars + forceBeginsAt;
T& fx = force[0];
T& fy = force[1];
T& fz = force[2];
nearestNeighborLattices3D.hh
在该文件夹的nearestNeighborLattices3D.hh可以找到参数定义的信息
// D3Q19 ///
// 代码部分
template<typename T>
const T D3Q19Constants<T>::invD = (T)1 / (T) d;
template<typename T>
const int D3Q19Constants<T>::vicinity = 1;
template<typename T>
const int D3Q19Constants<T>::c
[D3Q19Constants<T>::q][D3Q19Constants<T>::d] =
{
{ 0, 0, 0},
{-1, 0, 0}, { 0,-1, 0}, { 0, 0,-1},
{-1,-1, 0}, {-1, 1, 0}, {-1, 0,-1},
{-1, 0, 1}, { 0,-1,-1}, { 0,-1, 1},
{ 1, 0, 0}, { 0, 1, 0}, { 0, 0, 1},
{ 1, 1, 0}, { 1,-1, 0}, { 1, 0, 1},
{ 1, 0,-1}, { 0, 1, 1}, { 0, 1,-1}
};
nearestNeighborLattices3D.h
/// D3Q19 lattice
template <typename T> struct D3Q19Constants
{
enum { d = 3, q = 19 }; ///< number of dimensions/distr. functions
static const T invD; ///< 1 / (number of dimensions)
static const int vicinity; ///< size of neighborhood
static const int c[q][d]; ///< lattice directions
static const int cNormSqr[q]; ///< norm-square of the vector c
static const T t[q]; ///< lattice weights
static const T cs2; ///< lattice constant cs2 (in BGK, this is the square-speed-of-sound)
static const T invCs2; ///< 1 / cs2
};
template <typename T> struct D3Q19DescriptorBase
: public D3Q19Constants<T>, public DefaultRoundOffPolicy<T>
{
typedef D3Q19DescriptorBase<T> BaseDescriptor;
enum { numPop=D3Q19Constants<T>::q };
};