PeriDyno 1.0.0
Loading...
Searching...
No Matches
ParticleRelaxtionOnMesh.cu
Go to the documentation of this file.
1#include "ParticleRelaxtionOnMesh.h"
2#include "Auxiliary/DataSource.h"
3#include "Topology/PointSet.h"
4
5namespace dyno
6{
7 IMPLEMENT_TCLASS(ParticleRelaxtionOnMesh, TDataType)
8
9 template<typename TDataType>
10 ParticleRelaxtionOnMesh<TDataType>::ParticleRelaxtionOnMesh()
11 : PointsBehindMesh<TDataType>()
12 {
13
14
15 auto smoothingLength = std::make_shared<FloatingNumber<TDataType>>();
16 smoothingLength->setName("Smoothing Length");
17 smoothingLength->varValue()->setValue(Real(0.006));
18 this->animationPipeline()->pushModule(smoothingLength);
19
20 auto samplingDistance = std::make_shared<FloatingNumber<TDataType>>();
21 samplingDistance->setName("Sampling Distance");
22 samplingDistance->varValue()->setValue(Real(0.005));
23 this->animationPipeline()->pushModule(samplingDistance);
24
25 //ptr_integrator = std::make_shared<ParticleIntegrator<TDataType>>();
26 //this->stateDelta()->connect(ptr_integrator->inTimeStep());
27 //this->statePosition()->connect(ptr_integrator->inPosition());
28 //this->stateVelocity()->connect(ptr_integrator->inVelocity());
29 //this->stateForce()->connect(ptr_integrator->inForceDensity());
30
31 ptr_nbrQuery = std::make_shared<NeighborPointQuery<TDataType>>();
32 smoothingLength->outFloating()->connect(ptr_nbrQuery->inRadius());
33 this->statePosition()->connect(ptr_nbrQuery->inPosition());
34
35 ptr_density = std::make_shared<IterativeDensitySolver<TDataType>>();
36 smoothingLength->outFloating()->connect(ptr_density->inSmoothingLength());
37 samplingDistance->outFloating()->connect(ptr_density->inSamplingDistance());
38 this->stateDelta()->connect(ptr_density->inTimeStep());
39 this->statePosition()->connect(ptr_density->inPosition());
40 this->stateVelocity()->connect(ptr_density->inVelocity());
41 ptr_nbrQuery->outNeighborIds()->connect(ptr_density->inNeighborIds());
42
43 ptr_viscosity = std::make_shared<ImplicitViscosity<TDataType>>();
44 ptr_viscosity->varViscosity()->setValue(Real(50.0));
45 this->stateDelta()->connect(ptr_viscosity->inTimeStep());
46 smoothingLength->outFloating()->connect(ptr_viscosity->inSmoothingLength());
47 this->statePosition()->connect(ptr_viscosity->inPosition());
48 this->stateVelocity()->connect(ptr_viscosity->inVelocity());
49 ptr_nbrQuery->outNeighborIds()->connect(ptr_viscosity->inNeighborIds());
50
51 auto triangleNeiborLength = std::make_shared<FloatingNumber<TDataType>>();
52 triangleNeiborLength->setName("Triangle Neibor Length");
53 triangleNeiborLength->varValue()->setValue(Real(0.012));
54 this->animationPipeline()->pushModule(triangleNeiborLength);
55
56 ptr_nbrQueryTri = std::make_shared<NeighborTriangleQuery<TDataType>>();
57 triangleNeiborLength->outFloating()->connect(ptr_nbrQueryTri->inRadius());
58 this->statePosition()->connect(ptr_nbrQueryTri->inPosition());
59 this->inTriangleSet()->connect(ptr_nbrQueryTri->inTriangleSet());
60
61 ptr_meshCollision = std::make_shared<TriangularMeshConstraint<TDataType>>();
62 ptr_meshCollision->varThickness()->setValue(0.003);
63 this->stateDelta()->connect(ptr_meshCollision->inTimeStep());
64 this->statePosition()->connect(ptr_meshCollision->inPosition());
65 this->stateVelocity()->connect(ptr_meshCollision->inVelocity());
66 this->inTriangleSet()->connect(ptr_meshCollision->inTriangleSet());
67 ptr_nbrQueryTri->outNeighborIds()->connect(ptr_meshCollision->inTriangleNeighborIds());
68
69 ptr_normalForce = std::make_shared<NormalForce<TDataType >>();
70 this->stateDelta()->connect(ptr_normalForce->inTimeStep());
71 this->statePointNormal()->connect(ptr_normalForce->inParticleNormal());
72 this->inTriangleSet()->connect(ptr_normalForce->inTriangleSet());
73 this->statePosition()->connect(ptr_normalForce->inPosition());
74 this->stateVelocity()->connect(ptr_normalForce->inVelocity());
75 this->statePointBelongTriangleIndex()->connect(ptr_normalForce->inParticleMeshID());
76 ptr_nbrQueryTri->outNeighborIds()->connect(ptr_normalForce->inTriangleNeighborIds());
77
78
79 }
80
81
82 template<typename TDataType>
83 ParticleRelaxtionOnMesh<TDataType>::~ParticleRelaxtionOnMesh()
84 {
85 Log::sendMessage(Log::Info, "ParticleRelaxtionOnMesh released \n");
86 }
87
88
89 template<typename TDataType>
90 void ParticleRelaxtionOnMesh<TDataType>::preUpdateStates()
91 {
92
93 }
94
95
96 template<typename TDataType>
97 void ParticleRelaxtionOnMesh<TDataType>::loadInitialStates()
98 {
99 int num = this->statePosition()->size();
100 this->stateVelocity()->resize(num);
101 this->stateVelocity()->reset();
102 this->stateForce()->resize(num);
103 this->stateForce()->reset();
104 }
105
106 template<typename Real, typename Coord>
107 __global__ void K_UpdatePosition(
108 DArray<Coord> pos,
109 DArray<Coord> vel,
110 Real delta)
111 {
112 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
113 if (pId >= pos.size()) return;
114 pos[pId] += delta * (vel[pId]);
115 }
116
117
118
119
120 template<typename TDataType>
121 void ParticleRelaxtionOnMesh<TDataType>::updatePositions()
122 {
123
124 int num = this->statePosition()->size();
125
126 cuExecute(num,
127 K_UpdatePosition,
128 this->statePosition()->getData(),
129 this->stateVelocity()->getData(),
130 this->stateDelta()->getValue()
131 );
132 }
133
134 template<typename TDataType>
135 void ParticleRelaxtionOnMesh<TDataType>::particleRelaxion()
136 {
137 std::cout << "Particle Relaxion on Mesh";
138
139 for (int i = 0; i < this->varIterationNumber()->getValue(); i++)
140 {
141 if (i % 5 == 0) std::cout << ".";
142 ptr_nbrQuery->inRadius()->setValue(this->varPointNeighborLength()->getValue());
143 ptr_nbrQuery->update();
144
145 ptr_density->varIterationNumber()->setValue(this->varDensityIteration()->getValue());
146 ptr_density->update();
147
148 ptr_viscosity->varViscosity()->setValue(this->varViscosityStrength()->getValue());
149 ptr_viscosity->update();
150
151 this->updatePositions();
152
153 ptr_nbrQueryTri->inRadius()->setValue(this->varMeshNeighborLength()->getValue());
154 ptr_nbrQueryTri->update();
155
156 ptr_meshCollision->varThickness()->setValue(this->varMeshCollisionThickness()->getValue());
157 ptr_meshCollision->update();
158
159 ptr_normalForce->varStrength()->setValue(this->varNormalForceStrength()->getValue());
160 ptr_normalForce->update();
161 }
162
163 std::cout << std::endl;
164 std::cout << "Particle Relaxion Finished." << std::endl;
165 };
166
167 template<typename TDataType>
168 void ParticleRelaxtionOnMesh<TDataType>::resetStates()
169 {
170
171 this->PointsBehindMesh<TDataType>::resetStates();
172
173 loadInitialStates();
174
175 this->particleRelaxion();
176
177 if (!this->statePosition()->isEmpty())
178 {
179 this->statePointSet()->getData().clear();
180 this->statePointSet()->getData().setPoints(this->statePosition()->getData());
181 }
182 else
183 {
184 this->statePointSet()->getData().clear();
185 }
186 }
187
188
189 DEFINE_CLASS(ParticleRelaxtionOnMesh);
190}