PeriDyno 1.0.0
Loading...
Searching...
No Matches
ImplicitViscosity.cu
Go to the documentation of this file.
1#include "ImplicitViscosity.h"
2#include "Node.h"
3
4namespace dyno
5{
6 template<typename TDataType>
7 ImplicitViscosity<TDataType>::ImplicitViscosity()
8 :ParticleApproximation<TDataType>()
9 {
10 this->varKernelType()->setCurrentKey(ParticleApproximation<TDataType>::EKernelType::KT_Smooth);
11 this->varViscosity()->setValue(Real(0.05));
12 }
13
14 template<typename TDataType>
15 ImplicitViscosity<TDataType>::~ImplicitViscosity()
16 {
17 mVelOld.clear();
18 mVelBuf.clear();
19 }
20
21 template<typename Real, typename Coord, typename Kernel>
22 __global__ void IV_ApplyViscosity(
23 DArray<Coord> velNew,
24 DArray<Coord> posArr,
25 DArray<Coord> velOld,
26 DArray<Coord> velBuf,
27 DArrayList<int> neighbors,
28 Real viscosity,
29 Real smoothingLength,
30 Real dt,
31 Kernel weight,
32 Real scale)
33 {
34 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
35 if (pId >= velNew.size()) return;
36
37 Coord dv_i(0);
38 Coord pos_i = posArr[pId];
39 Coord vel_i = velBuf[pId];
40 Real totalWeight = 0.0f;
41
42 List<int>& list_i = neighbors[pId];
43 int nbSize = list_i.size();
44 for (int ne = 0; ne < nbSize; ne++)
45 {
46 int j = list_i[ne];
47 Real r = (pos_i - posArr[j]).norm();
48
49 if (r > EPSILON)
50 {
51 Real w = weight(r, smoothingLength, scale);
52 totalWeight += w;
53 dv_i += w * velBuf[j];
54 }
55 }
56
57 Real b = dt * viscosity / smoothingLength;
58 b = totalWeight < EPSILON ? 0.0f : b;
59
60 totalWeight = totalWeight < EPSILON ? 1.0f : totalWeight;
61
62 dv_i /= totalWeight;
63
64 velNew[pId] = velOld[pId] / (1.0f + b) + dv_i * b / (1.0f + b);
65 }
66
67 template<typename TDataType>
68 void ImplicitViscosity<TDataType>::compute()
69 {
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();
75
76 int num = vels.size();
77 uint pDims = cudaGridSize(num, BLOCK_SIZE);
78
79 mVelOld.resize(num);
80 mVelBuf.resize(num);
81
82 Real vis = this->varViscosity()->getData();
83
84 int iterNum = this->varInterationNumber()->getData();
85
86 mVelOld.assign(vels);
87 for (int t = 0; t < iterNum; t++)
88 {
89 mVelBuf.assign(vels);
90 cuZerothOrder(num, this->varKernelType()->getDataPtr()->currentKey(), this->mScalingFactor,
91 IV_ApplyViscosity,
92 vels,
93 poss,
94 mVelOld,
95 mVelBuf,
96 nbrIds,
97 vis,
98 h,
99 dt);
100 }
101 }
102
103 DEFINE_CLASS(ImplicitViscosity);
104}