PeriDyno 1.0.0
Loading...
Searching...
No Matches
TriangularMeshBoundary.cpp
Go to the documentation of this file.
2
4
6
8
9namespace dyno
10{
12
13 template<typename TDataType>
15 : Node()
16 {
17 auto smoothingLength = std::make_shared<FloatingNumber<TDataType>>();
18 smoothingLength->setName("Smoothing Length");
19 smoothingLength->varValue()->setValue(Real(0.012));
20 this->animationPipeline()->pushModule(smoothingLength);
21
22 //triangle neighbor
23 auto nbrQueryTri = std::make_shared<NeighborTriangleQuery<TDataType>>();
24 smoothingLength->outFloating()->connect(nbrQueryTri->inRadius());
25 this->statePosition()->connect(nbrQueryTri->inPosition());
26 this->inTriangleSet()->connect(nbrQueryTri->inTriangleSet());
27 this->animationPipeline()->pushModule(nbrQueryTri);
28
29 //mesh collision
30 auto meshCollision = std::make_shared<TriangularMeshConstraint<TDataType>>();
31 this->stateTimeStep()->connect(meshCollision->inTimeStep());
32 this->statePosition()->connect(meshCollision->inPosition());
33 this->stateVelocity()->connect(meshCollision->inVelocity());
34 this->inTriangleSet()->connect(meshCollision->inTriangleSet());
35 nbrQueryTri->outNeighborIds()->connect(meshCollision->inTriangleNeighborIds());
36 this->animationPipeline()->pushModule(meshCollision);
37
38 this->varNormalFriction()->attach(
39 std::make_shared<FCallBackFunc>(
40 [=]() {
41 meshCollision->varNormalFriction()->setValue(this->varNormalFriction()->getValue());
42 })
43 );
44
45 this->varTangentialFriction()->attach(
46 std::make_shared<FCallBackFunc>(
47 [=]() {
48 meshCollision->varTangentialFriction()->setValue(this->varTangentialFriction()->getValue());
49 })
50 );
51
52 this->varThickness()->attach(
53 std::make_shared<FCallBackFunc>(
54 [=]() {
55 Real thickness = this->varThickness()->getValue();
56 smoothingLength->varValue()->setValue(thickness);
57 meshCollision->varThickness()->setValue(thickness);
58 })
59 );
60 }
61
62 template<typename TDataType>
66
67 template<typename TDataType>
69 {
70 auto& particleSystems = this->getParticleSystems();
71
72 if (particleSystems.size() == 0)
73 return;
74
75 int new_num = 0;
76 for (int i = 0; i < particleSystems.size(); i++) {
77 new_num += particleSystems[i]->statePosition()->size();
78 }
79
80 if (new_num <= 0)
81 return;
82
83 int cur_num = this->statePosition()->size();
84
85 if (new_num != cur_num)
86 {
87 this->statePosition()->resize(new_num);
88 this->stateVelocity()->resize(new_num);
89 }
90
91 auto& new_pos = this->statePosition()->getData();
92 auto& new_vel = this->stateVelocity()->getData();
93
94 int offset = 0;
95 for (int i = 0; i < particleSystems.size(); i++)//update particle system
96 {
97 DArray<Coord>& points = particleSystems[i]->statePosition()->getData();
98 DArray<Coord>& vels = particleSystems[i]->stateVelocity()->getData();
99 int num = points.size();
100
101 new_pos.assign(points, num, offset);
102 new_vel.assign(vels, num, offset);
103
104 offset += num;
105 }
106 }
107
108 template<typename TDataType>
113
114 template<typename TDataType>
116 {
117 auto& particleSystems = this->getParticleSystems();
118
119 if (particleSystems.size() <= 0 || this->statePosition()->size() <= 0)
120 return;
121
122 auto& new_pos = this->statePosition()->getData();
123 auto& new_vel = this->stateVelocity()->getData();
124
125 uint offset = 0;
126 for (int i = 0; i < particleSystems.size(); i++)//extend current particles
127 {
128 DArray<Coord>& points = particleSystems[i]->statePosition()->getData();
129 DArray<Coord>& vels = particleSystems[i]->stateVelocity()->getData();
130
131 int num = points.size();
132
133 points.assign(new_pos, num, 0, offset);
134 vels.assign(new_vel, num, 0, offset);
135
136 offset += num;
137 }
138 }
139
141}
#define DEFINE_CLASS(name)
Definition Object.h:140
#define IMPLEMENT_TCLASS(name, T1)
Definition Object.h:103
virtual void updateStates()
Definition Node.cpp:141
std::shared_ptr< AnimationPipeline > animationPipeline()
Definition Node.cpp:311
A triangular mesh boundary to prevent interpenetration for particles.
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array< T, DeviceType::GPU > DArray
Definition Array.inl:89
unsigned int uint
Definition VkProgram.h:14