1#include <cuda_runtime.h>
2#include "ParticleIntegrator.h"
4#include "SceneGraphFactory.h"
8 IMPLEMENT_TCLASS(ParticleIntegrator, TDataType)
10 template<typename TDataType>
11 ParticleIntegrator<TDataType>::ParticleIntegrator()
14 this->inAttribute()->tagOptional(true);
17 template<typename Real, typename Coord>
18 __global__ void K_UpdateVelocity(
23 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
24 if (pId >= vel.size()) return;
26 vel[pId] += dt * (gravity);
32 template<typename Real, typename Coord>
33 __global__ void K_UpdateVelocity(
35 DArray<Attribute> atts,
39 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
40 if (pId >= vel.size()) return;
42 Attribute att = atts[pId];
46 vel[pId] += dt * (gravity);
53 template<typename TDataType>
54 bool ParticleIntegrator<TDataType>::updateVelocity()
56 Real dt = this->inTimeStep()->getData();
58 auto scn = dyno::SceneGraphFactory::instance()->active();
59 Coord gravity = scn->getGravity();
61 int total_num = this->inPosition()->size();
63 if (this->inAttribute()->isEmpty())
67 this->inVelocity()->getData(),
75 this->inVelocity()->getData(),
76 this->inAttribute()->getData(),
85 template<typename Real, typename Coord>
86 __global__ void K_UpdatePosition(
91 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
92 if (pId >= pos.size()) return;
94 pos[pId] += dt * vel[pId];
97 template<typename Real, typename Coord>
98 __global__ void K_UpdatePosition(
101 DArray<Attribute> att,
104 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
105 if (pId >= pos.size()) return;
107 Attribute att_i = att[pId];
109 if (!att_i.isFixed())
111 pos[pId] += dt * vel[pId];
115 template<typename TDataType>
116 bool ParticleIntegrator<TDataType>::updatePosition()
118 Real dt = this->inTimeStep()->getData();
120 int total_num = this->inPosition()->getDataPtr()->size();
123 if (this->inAttribute()->isEmpty())
127 this->inPosition()->getData(),
128 this->inVelocity()->getData(),
135 this->inPosition()->getData(),
136 this->inVelocity()->getData(),
137 this->inAttribute()->getData(),
145 template<typename TDataType>
146 void ParticleIntegrator<TDataType>::compute()
152 DEFINE_CLASS(ParticleIntegrator);