PeriDyno 1.0.0
Loading...
Searching...
No Matches
Peridynamics.cpp
Go to the documentation of this file.
1#include "Peridynamics.h"
2
3#include "Collision/NeighborPointQuery.h"
4
5#include "SharedFunc.h"
6
8
9namespace dyno
10{
11 template<typename TDataType>
13 : ParticleSystem<TDataType>()
14 {
15 this->varHorizon()->attach(
16 std::make_shared<FCallBackFunc>(
17 [=]() {
18 this->stateHorizon()->setValue(this->varHorizon()->getValue());
19 })
20 );
21
22 this->varHorizon()->setValue(0.0085);
23
24 auto pointRenderer = std::make_shared<GLPointVisualModule>();
25 pointRenderer->varPointSize()->setValue(0.005);
26 pointRenderer->setColor(Color::Burlywood());
27 pointRenderer->setColorMapMode(GLPointVisualModule::PER_OBJECT_SHADER);
28 this->statePointSet()->connect(pointRenderer->inPointSet());
29 this->stateVelocity()->connect(pointRenderer->inColor());
30 this->graphicsPipeline()->pushModule(pointRenderer);
31
32 this->setDt(0.001f);
33 }
34
35 template<typename TDataType>
40
41 template<typename TDataType>
43 {
44 return "Peridynamics";
45 }
46
47 template<typename TDataType>
49 {
51
52 auto nbrQuery = std::make_shared<NeighborPointQuery<TDataType>>();
53 this->stateHorizon()->connect(nbrQuery->inRadius());
54 this->statePosition()->connect(nbrQuery->inPosition());
55 nbrQuery->update();
56
57 if (!this->statePosition()->isEmpty())
58 {
59 this->stateBonds()->allocate();
60 auto nbrPtr = this->stateBonds()->getDataPtr();
61 nbrPtr->resize(nbrQuery->outNeighborIds()->getData());
62
63 constructRestShape(*nbrPtr, nbrQuery->outNeighborIds()->getData(), this->statePosition()->getData());
64
65 this->stateReferencePosition()->assign(this->statePosition()->getData());
66 }
67
69 }
70
71 template<typename TDataType>
73 {
74 auto particles = this->getSolidParticles();
75
76 //Merge solid particles
77 if (particles.size() > 0)
78 {
79 int totalNum = 0;
80
81 for (int i = 0; i < particles.size(); i++)
82 {
83 totalNum += particles[i]->statePosition()->size();
84 }
85
86 this->statePosition()->resize(totalNum);
87 this->stateVelocity()->resize(totalNum);
88
89 if (totalNum > 0)
90 {
91 DArray<Coord>& new_pos = this->statePosition()->getData();
92 DArray<Coord>& new_vel = this->stateVelocity()->getData();
93
94 int offset = 0;
95 for (int i = 0; i < particles.size(); i++)
96 {
97 auto inPos = particles[i]->statePosition()->getDataPtr();
98 auto inVel = particles[i]->stateVelocity()->getDataPtr();
99 if (!inPos->isEmpty())
100 {
101 uint num = inPos->size();
102
103 new_pos.assign(*inPos, num, offset, 0);
104 new_vel.assign(*inVel, num, offset, 0);
105
106 offset += num;
107 }
108 }
109 }
110 }
111 else {
112 this->statePosition()->clear();
113 this->stateVelocity()->clear();
114 this->stateReferencePosition()->clear();
115 this->stateBonds()->clear();
116 }
117 }
118
120}
#define DEFINE_CLASS(name)
Definition Object.h:140
static Color Burlywood()
Definition Color.h:162
std::shared_ptr< GraphicsPipeline > graphicsPipeline()
Definition Node.cpp:320
void setDt(Real dt)
Definition Node.cpp:98
void resetStates() override
void resetStates() override
~Peridynamics() override
std::string getNodeType() override
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array< T, DeviceType::GPU > DArray
Definition Array.inl:89
void constructRestShape(DArrayList< Bond > &shape, DArrayList< int > &nbr, DArray< Coord > &pos)
unsigned int uint
Definition VkProgram.h:14