kcom.br 5.08 KB
Newer Older
Mark Friedrichs's avatar
Mark Friedrichs committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

/* Portions copyright (c) 2006 Stanford University and Simbios.
 * Contributors: Pande Group
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject
 * to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/**---------------------------------------------------------------------------------------

   This kernel calculates the linear momentum

   @param mass           stream of masses
   @param velocities     stream of velocities
   @param linearMomentum output stream of linear momentum

   --------------------------------------------------------------------------------------- */

kernel void kCalculateLinearMomentum( float mass<>, float3 velocities<>, out float3 linearMomentum<> ){
   linearMomentum = mass*velocities;
}

/**---------------------------------------------------------------------------------------

   This kernel scales the linear momentum

   @param scale              scale factor
   @param linearMomentumIn   input linearMomentum
   @param linearMomentumOut  output linearMomentum

   --------------------------------------------------------------------------------------- */

kernel void kScale( float scale, float3 linearMomentumIn<>, out float3 linearMomentumOut<> ){
   linearMomentumOut = scale*linearMomentumIn;
}

/**---------------------------------------------------------------------------------------

   This kernel calculates the total linear momentum via a reduction

   @param momentum       momentum
   @param linearMomentum total momentum

   Note: treating the output linearMomentum as non-stream did not compile, even though
   I found examples in Brook testing code that had that construct -- MSF 3/6/08

   --------------------------------------------------------------------------------------- */

reduce void kReduceLinearMomentum( float3 momentum<>, reduce float3 linearMomentum<> ){
   linearMomentum += momentum;
}

/**---------------------------------------------------------------------------------------

   This kernel calculates the total linear momentum via a reduction

   @param atomStrWidth   atom stream width
   @param numberOfAtoms  number of atoms
   @param momentum       momentum
   @param linearMomentum total momentum

   --------------------------------------------------------------------------------------- */

kernel void kSumLinearMomentum( float atomStrWidth, float numberOfAtoms, float3 momentum[][],
                                out float3 linearMomentum<> ){

   float atomCount;
   float2 atomIndex;

   atomCount      = 0.0f;
   linearMomentum = float3( 0.0f, 0.0f, 0.0f );
   atomIndex.y    =  0.0f;
   atomIndex.x    =  0.0f;

   while( atomCount < numberOfAtoms ){

      linearMomentum += momentum[atomIndex];

      atomIndex.x    += 1.0f;
      if( atomIndex.x == atomStrWidth ){
         atomIndex.x  = 0.0f; 
         atomIndex.y += 1.0f;
      }

      atomCount += 1.0f;
   } 
}

/**---------------------------------------------------------------------------------------

   This kernel calculates the total linear momentum via a reduction

   @param momentum       momentum
   @param linearMomentum total momentum

   Note: treating the output linearMomentum as non-stream did not compile, even though
   I found examples in Brook testing code that had that construct -- MSF 3/6/08

   --------------------------------------------------------------------------------------- */

reduce void kSum( float3 array<>, reduce float3 sum<> ){
   //sum += array;
   //sum += array.x + array.y + array.z;
   //sum += float3( 1.0, 1.0, 1.0 );
/*
   sum.x += 1.0;
   sum.y += 1.0;
   sum.z += 1.0;
*/
   sum += array;
   //sum += 1.0;
}

/**---------------------------------------------------------------------------------------

   This kernel subtracts the (total linear momentum)/totalMass from the velocities 

   @param linearMomentum  normalized linear momentum
   @param velocities      stream of velocities
   @param velocitiesOut   output stream of velocities

   --------------------------------------------------------------------------------------- */

kernel void kRemoveLinearMomentum( float3 linearMomentum[], float3 velocities<>, out float3 velocitiesOut<> ){
   velocitiesOut = velocities - linearMomentum[0];
}