1 #include "ComputeParticleAnisotropy.h"
2#include "Matrix/MatrixFunc.h"
6 template <typename Real>
7 DYN_FUNC inline Real iso_Weight(const Real r, const Real h)
10 if (q >= 1.0f) return 0.0f;
12 return (1.0f - q*q*q);
16 template <typename Real, typename Coord, typename Transform>
17 __global__ void CalculateTransform(
18 DArray<Transform> transform,
20 DArrayList<int> neighbors,
23 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
24 if (pId >= pos.size()) return;
27 Coord pos_i = pos[pId];
30 List<int>& list_i = neighbors[pId];
31 int nbSize = list_i.size();
32 Real total_weight = 0.0f;
33 Mat3f mat_i = Mat3f(0);
35 Coord W_pos_i = Coord(0);
37 Real total_weight1=0.0f;
38 for (int ne = 0; ne < nbSize; ne++)
41 Real r = (pos_i - pos[j]).norm();
42 Real h = (2.0f)*smoothingLength;
43 Real weight = iso_Weight(r, h);
44 W_pos_i += pos[j] * weight;// smoothingLength;
45 total_weight1 += weight;
47 if (total_weight1> EPSILON)
49 W_pos_i *= (1.0f / total_weight1);
52 for (int ne = 0; ne < nbSize; ne++)
55 Real r = (pos_i - pos[j]).norm();
59 Real h = (1.0f)*smoothingLength;
60 Real weight = iso_Weight(r, h);
61 Coord q = (pos[j] - pos_i)*weight / smoothingLength;
63 mat_i(0, 0) += q[0] * q[0]; mat_i(0, 1) += q[0] * q[1]; mat_i(0, 2) += q[0] * q[2];
64 mat_i(1, 0) += q[1] * q[0]; mat_i(1, 1) += q[1] * q[1]; mat_i(1, 2) += q[1] * q[2];
65 mat_i(2, 0) += q[2] * q[0]; mat_i(2, 1) += q[2] * q[1]; mat_i(2, 2) += q[2] * q[2];
67 total_weight += weight;
71 if (total_weight > EPSILON)
73 mat_i *= (1.0f / total_weight);
76 Mat3f R(0), U(0), D(0), V(0);
78 polarDecomposition(mat_i, R, U, D, V);
84 Real threshold = 0.0001f;
85 Real minD = min(e0, min(e1, e2));
86 Real maxD = max(e0, max(e1, e2));
111 tm.translation() = pos[pId];
113 tm.scale() = 0.02 * Vec3f(D(0, 0), D(1, 1), D(2, 2));
117 template<typename TDataType>
118 ComputeParticleAnisotropy<TDataType>::ComputeParticleAnisotropy()
121 this->varSmoothingLength()->setValue(Real(0.0125));
125 template<typename TDataType>
126 ComputeParticleAnisotropy<TDataType>::~ComputeParticleAnisotropy()
130 template<typename TDataType>
131 void ComputeParticleAnisotropy<TDataType>::compute()
133 int num = this->inPosition()->size();
135 if (this->outTransform()->size() != num) {
136 this->outTransform()->resize(num);
141 this->outTransform()->getData(),
142 this->inPosition()->getData(),
143 this->inNeighborIds()->getData(),
144 this->varSmoothingLength()->getData());
147 DEFINE_CLASS(ComputeParticleAnisotropy);