1#include "SummationDensity.h"
5 template<typename TDataType>
6 SummationDensity<TDataType>::SummationDensity()
7 : ParticleApproximation<TDataType>()
10 this->varRestDensity()->setValue(Real(1000));
12 auto callback = std::make_shared<FCallBackFunc>(
13 std::bind(&SummationDensity<TDataType>::calculateParticleMass, this));
15 this->varRestDensity()->attach(callback);
16 this->inSamplingDistance()->attach(callback);
18 this->inOther()->tagOptional(true);
19 //calculateParticleMass();
22 template<typename TDataType>
23 void SummationDensity<TDataType>::compute()
25 int p_num = this->inPosition()->getDataPtr()->size();
26 int n_num = this->inNeighborIds()->getDataPtr()->size();
28 Log::sendMessage(Log::Error, "The input array sizes of DensitySummation are not compatible!");
32 if (this->outDensity()->size() != p_num) {
33 this->outDensity()->resize(p_num);
36 if (this->inOther()->isEmpty()) {
38 this->outDensity()->getData(),
39 this->inPosition()->getData(),
40 this->inNeighborIds()->getData(),
41 this->inSmoothingLength()->getData(),
46 this->outDensity()->getData(),
47 this->inPosition()->getData(),
48 this->inOther()->getData(),
49 this->inNeighborIds()->getData(),
50 this->inSmoothingLength()->getData(),
55 template<typename Real, typename Coord, typename Kernel>
56 __global__ void SD_ComputeDensity(
59 DArrayList<int> neighbors,
65 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
66 if (pId >= posArr.size()) return;
70 Coord pos_i = posArr[pId];
71 List<int>& list_i = neighbors[pId];
72 int nbSize = list_i.size();
73 for (int ne = 0; ne < nbSize; ne++)
76 r = (pos_i - posArr[j]).norm();
77 rho_i += mass * weight(r, smoothingLength, scale);
83 template<typename Real, typename Coord, typename Kernel>
84 __global__ void SD_ComputeDensity(
87 DArray<Coord> posQueried,
88 DArrayList<int> neighbors,
94 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
95 if (pId >= posArr.size()) return;
99 Coord pos_i = posArr[pId];
100 List<int>& list_i = neighbors[pId];
101 int nbSize = list_i.size();
102 for (int ne = 0; ne < nbSize; ne++)
105 r = (pos_i - posQueried[j]).norm();
106 rho_i += mass * weight(r, smoothingLength, scale);
112 template<typename TDataType>
113 void SummationDensity<TDataType>::compute(
116 DArrayList<int>& neighbors,
117 Real smoothingLength,
120 cuZerothOrder(rho.size(), this->varKernelType()->getDataPtr()->currentKey(), this->mScalingFactor,
129 template<typename TDataType>
130 void SummationDensity<TDataType>::compute(DArray<Real>& rho, DArray<Coord>& pos, DArray<Coord>& posQueried, DArrayList<int>& neighbors, Real smoothingLength, Real mass)
132 cuZerothOrder(rho.size(), this->varKernelType()->getDataPtr()->currentKey(), this->mScalingFactor,
142 template<typename TDataType>
143 void SummationDensity<TDataType>::calculateParticleMass()
145 Real rho_0 = this->varRestDensity()->getData();
146 Real d = this->inSamplingDistance()->getData();
148 m_particle_mass = d * d*d*rho_0;
151 DEFINE_CLASS(SummationDensity);