1#include "SemiAnalyticalSummationDensity.h"
3#include "IntersectionArea.h"
7 IMPLEMENT_TCLASS(SemiAnalyticalSummationDensity, TDataType)
9 template<typename TDataType>
10 SemiAnalyticalSummationDensity<TDataType>::SemiAnalyticalSummationDensity()
11 : ParticleApproximation<TDataType>()
14 this->varRestDensity()->setValue(Real(1000));//1000
16 auto callback = std::make_shared<FCallBackFunc>(
17 std::bind(&SemiAnalyticalSummationDensity<TDataType>::calculateParticleMass, this));
19 this->varRestDensity()->attach(callback);
20 this->inSamplingDistance()->attach(callback);
23 template<typename TDataType>
24 void SemiAnalyticalSummationDensity<TDataType>::compute()
26 auto ts = this->inTriangleSet()->constDataPtr();
27 auto& triVertex = ts->getPoints();
28 auto& triIndex = ts->getTriangles();
30 int p_num = this->inPosition()->getDataPtr()->size();
31 int n_num = this->inNeighborIds()->getDataPtr()->size();
32 int t_num = triIndex.size();
33 int tn_num = this->inNeighborTriIds()->getDataPtr()->size();
35 //printf("tn_num: %d\n", tn_num);
37 if (p_num != n_num ) {
38 Log::sendMessage(Log::Error, "The input array sizes of DensitySummation are not compatible!");
42 if (this->outDensity()->size() != p_num) {
43 this->outDensity()->resize(p_num);
47 this->outDensity()->getData(),
48 this->inPosition()->getData(),
51 this->inNeighborIds()->getData(),
52 this->inNeighborTriIds()->getData(),
53 this->inSmoothingLength()->getData(),
55 this->inSamplingDistance()->getData());
59 template<typename TDataType>
60 void SemiAnalyticalSummationDensity<TDataType>::compute(DArray<Real>& rho)
62 auto ts = this->inTriangleSet()->constDataPtr();
63 auto& triVertex = ts->getPoints();
64 auto& triIndex = ts->getTriangles();
68 this->inPosition()->getData(),
71 this->inNeighborIds()->getData(),
72 this->inNeighborTriIds()->getData(),
73 this->inSmoothingLength()->getData(),
75 this->inSamplingDistance()->getData());
78 template<typename Real, typename Coord, typename Kernel>
79 __global__ void SD_ComputeDensity(
82 DArrayList<int> neighbors,
85 Real sampling_distance,
89 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
90 if (pId >= posArr.size()) return;
92 SpikyKernel<Real> kern;
96 Coord pos_i = posArr[pId];
98 List<int>& list_i = neighbors[pId];
100 int nbSize = list_i.size();
101 for (int ne = 0; ne < nbSize; ne++)
104 r = (pos_i - posArr[j]).norm();
105 rho_i += mass * kernel(r, smoothingLength, scale);
111 template<typename Real, typename Coord, typename Kernel>
112 __global__ void SD_BoundaryIntegral(
114 DArray<Coord> posArr,
115 DArray<TopologyModule::Triangle> Tri,
116 DArray<Coord> positionTri,
117 DArrayList<int> neighborsTri,
118 Real smoothingLength,
123 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
124 if (pId >= rhoArr.size()) return;
126 Real rho_i = Real(0);
127 Coord pos_i = posArr[pId];
129 List<int>& nbrTriIds_i = neighborsTri[pId];
130 int nbSizeTri = nbrTriIds_i.size();
133 for (int ne = 0; ne < nbSizeTri; ne++)
135 int j = nbrTriIds_i[ne];
138 Triangle3D t3d(positionTri[Tri[j][0]], positionTri[Tri[j][1]], positionTri[Tri[j][2]]);
139 Plane3D PL(positionTri[Tri[j][0]], t3d.normal());
141 Point3D nearest_pt = p3d.project(PL);
142 Real r = (nearest_pt.origin - pos_i).norm();
144 float d = p3d.distance(PL);
146 if (smoothingLength - d > EPSILON&& smoothingLength* smoothingLength - d * d > EPSILON&& d > EPSILON)
150 kernel(r, smoothingLength, scale)
151 * 2.0 * (M_PI) * (1 - d / smoothingLength)
152 * calculateIntersectionArea(p3d, t3d, smoothingLength)
153 / ((M_PI) * (smoothingLength * smoothingLength - d * d));
154 rho_i += mass * a_ij;
158 //printf("Boundary: %f \n", rho_i);
161 rhoArr[pId] += rho_i;
164 template<typename TDataType>
165 void SemiAnalyticalSummationDensity<TDataType>::compute(
168 DArray<TopologyModule::Triangle>& Tri,
169 DArray<Coord>& positionTri,
170 DArrayList<int>& neighbors,
171 DArrayList<int>& neighborsTri,
172 Real smoothingLength,
174 Real sampling_distance)
176 cuZerothOrder(rho.size(), this->varKernelType()->getDataPtr()->currentKey(), this->mScalingFactor,
185 if (neighborsTri.size() > 0)
187 cuIntegral(rho.size(), this->varKernelType()->getDataPtr()->currentKey(), this->mScalingFactor,
199 template<typename TDataType>
200 void SemiAnalyticalSummationDensity<TDataType>::calculateParticleMass()
202 Real rho_0 = this->varRestDensity()->getData();
203 Real d = this->inSamplingDistance()->getData();
205 m_particle_mass = d*d*d*rho_0;
208 DEFINE_CLASS(SemiAnalyticalSummationDensity);