PeriDyno 1.0.0
Loading...
Searching...
No Matches
SharedFunc.cu
Go to the documentation of this file.
1#include "SharedFunc.h"
2
3namespace dyno
4{
5 template <typename Coord, typename Bond>
6 __global__ void K_UpdateRestShape(
7 DArrayList<Bond> bonds,
8 DArrayList<int> nbr,
9 DArray<Coord> pos)
10 {
11 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
12 if (pId >= pos.size()) return;
13
14 Bond np;
15
16 List<Bond>& bonds_i = bonds[pId];
17 List<int>& list_id_i = nbr[pId];
18 int nbSize = list_id_i.size();
19 for (int ne = 0; ne < nbSize; ne++)
20 {
21 int j = list_id_i[ne];
22 np.idx = j;
23 np.xi = pos[j] - pos[pId];
24// np.weight = 1;
25
26 bonds_i.insert(np);
27// if (pId == j)
28// {
29// Bond np_0 = rest_shape_i[0];
30// rest_shape_i[0] = np;
31// rest_shape_i[ne] = np_0;
32// }
33 }
34 }
35
36
37 template<typename Coord, typename Bond>
38 void constructRestShape(DArrayList<Bond>& shape, DArrayList<int>& nbr, DArray<Coord>& pos)
39 {
40 cuExecute(nbr.size(),
41 K_UpdateRestShape,
42 shape,
43 nbr,
44 pos);
45 }
46
47 __global__ void K_AddOne(
48 DArray<uint> num,
49 DArrayList<int> nbr)
50 {
51 int tId = threadIdx.x + (blockIdx.x * blockDim.x);
52 if (tId >= nbr.size()) return;
53
54 num[tId] = nbr[tId].size();
55 }
56
57// template <typename Coord, typename Bond>
58// __global__ void K_UpdateRestShapeSelf(
59// DArrayList<Bond> shape,
60// DArray<Coord> pos)
61// {
62// int tId = threadIdx.x + (blockIdx.x * blockDim.x);
63// if (tId >= pos.size()) return;
64//
65// Bond np;
66// np.index = tId;
67// np.pos = pos[tId];
68// np.weight = 1;
69//
70// shape[tId].insert(np);
71// }
72
73 template<typename Coord, typename Bond>
74 void constructRestShapeWithSelf(DArrayList<Bond>& shape, DArrayList<int>& nbr, DArray<Coord>& pos)
75 {
76 DArray<uint> num(nbr.size());
77
78 cuExecute(nbr.size(),
79 K_AddOne,
80 num,
81 nbr);
82
83 shape.resize(num);
84
85// cuExecute(nbr.size(),
86// K_UpdateRestShapeSelf,
87// shape,
88// pos);
89
90 cuExecute(nbr.size(),
91 K_UpdateRestShape,
92 shape,
93 nbr,
94 pos);
95
96 num.clear();
97 }
98
99 template void constructRestShape<Vec3f, TBond<DataType3f>>(DArrayList<TBond<DataType3f>>& shape, DArrayList<int>& nbr, DArray<Vec3f>& pos);
100 template void constructRestShapeWithSelf<Vec3f, TBond<DataType3f>>(DArrayList<TBond<DataType3f>>& shape, DArrayList<int>& nbr, DArray<Vec3f>& pos);
101}