1#include "ImplicitViscosity.h"
6 template<typename TDataType>
7 ImplicitViscosity<TDataType>::ImplicitViscosity()
8 :ParticleApproximation<TDataType>()
10 this->varKernelType()->setCurrentKey(ParticleApproximation<TDataType>::EKernelType::KT_Smooth);
11 this->varViscosity()->setValue(Real(0.05));
14 template<typename TDataType>
15 ImplicitViscosity<TDataType>::~ImplicitViscosity()
21 template<typename Real, typename Coord, typename Kernel>
22 __global__ void IV_ApplyViscosity(
27 DArrayList<int> neighbors,
34 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
35 if (pId >= velNew.size()) return;
38 Coord pos_i = posArr[pId];
39 Coord vel_i = velBuf[pId];
40 Real totalWeight = 0.0f;
42 List<int>& list_i = neighbors[pId];
43 int nbSize = list_i.size();
44 for (int ne = 0; ne < nbSize; ne++)
47 Real r = (pos_i - posArr[j]).norm();
51 Real w = weight(r, smoothingLength, scale);
53 dv_i += w * velBuf[j];
57 Real b = dt * viscosity / smoothingLength;
58 b = totalWeight < EPSILON ? 0.0f : b;
60 totalWeight = totalWeight < EPSILON ? 1.0f : totalWeight;
64 velNew[pId] = velOld[pId] / (1.0f + b) + dv_i * b / (1.0f + b);
67 template<typename TDataType>
68 void ImplicitViscosity<TDataType>::compute()
70 auto& poss = this->inPosition()->getData();
71 auto& vels = this->inVelocity()->getData();
72 auto& nbrIds = this->inNeighborIds()->getData();
73 Real h = this->inSmoothingLength()->getData();
74 Real dt = this->inTimeStep()->getData();
76 int num = vels.size();
77 uint pDims = cudaGridSize(num, BLOCK_SIZE);
82 Real vis = this->varViscosity()->getData();
84 int iterNum = this->varInterationNumber()->getData();
87 for (int t = 0; t < iterNum; t++)
90 cuZerothOrder(num, this->varKernelType()->getDataPtr()->currentKey(), this->mScalingFactor,
103 DEFINE_CLASS(ImplicitViscosity);