PandA-2024.02
md.c
Go to the documentation of this file.
1 #include "md.h"
2 
3 #define MIN(x,y) ( (x)<(y) ? (x) : (y) )
4 #define MAX(x,y) ( (x)>(y) ? (x) : (y) )
5 
6 void md( int n_points[blockSide][blockSide][blockSide],
7  dvector_t force[blockSide][blockSide][blockSide][densityFactor],
8  dvector_t position[blockSide][blockSide][blockSide][densityFactor] )
9 {
10  ivector_t b0, b1; // b0 is the current block, b1 is b0 or a neighboring block
11  dvector_t p, q; // p is a point in b0, q is a point in either b0 or b1
12  int32_t p_idx, q_idx;
13  TYPE dx, dy, dz, r2inv, r6inv, potential, f;
14 
15  // Iterate over the grid, block by block
16  loop_grid0_x: for( b0.x=0; b0.x<blockSide; b0.x++ ) {
17  loop_grid0_y: for( b0.y=0; b0.y<blockSide; b0.y++ ) {
18  loop_grid0_z: for( b0.z=0; b0.z<blockSide; b0.z++ ) {
19  // Iterate over the 3x3x3 (modulo boundary conditions) cube of blocks around b0
20  loop_grid1_x: for( b1.x=MAX(0,b0.x-1); b1.x<MIN(blockSide,b0.x+2); b1.x++ ) {
21  loop_grid1_y: for( b1.y=MAX(0,b0.y-1); b1.y<MIN(blockSide,b0.y+2); b1.y++ ) {
22  loop_grid1_z: for( b1.z=MAX(0,b0.z-1); b1.z<MIN(blockSide,b0.z+2); b1.z++ ) {
23  // For all points in b0
24  dvector_t *base_q = position[b1.x][b1.y][b1.z];
25  int q_idx_range = n_points[b1.x][b1.y][b1.z];
26  loop_p: for( p_idx=0; p_idx<n_points[b0.x][b0.y][b0.z]; p_idx++ ) {
27  p = position[b0.x][b0.y][b0.z][p_idx];
28  TYPE sum_x = force[b0.x][b0.y][b0.z][p_idx].x;
29  TYPE sum_y = force[b0.x][b0.y][b0.z][p_idx].y;
30  TYPE sum_z = force[b0.x][b0.y][b0.z][p_idx].z;
31  // For all points in b1
32  loop_q: for( q_idx=0; q_idx< q_idx_range ; q_idx++ ) {
33  q = *(base_q + q_idx);
34 
35  // Don't compute our own
36  if( q.x!=p.x || q.y!=p.y || q.z!=p.z ) {
37  // Compute the LJ-potential
38  dx = p.x - q.x;
39  dy = p.y - q.y;
40  dz = p.z - q.z;
41  r2inv = 1.0/( dx*dx + dy*dy + dz*dz );
42  r6inv = r2inv*r2inv*r2inv;
43  potential = r6inv*(lj1*r6inv - lj2);
44  // Update forces
45  f = r2inv*potential;
46  sum_x += f*dx;
47  sum_y += f*dy;
48  sum_z += f*dz;
49  }
50  } // loop_q
51  force[b0.x][b0.y][b0.z][p_idx].x = sum_x ;
52  force[b0.x][b0.y][b0.z][p_idx].y = sum_y ;
53  force[b0.x][b0.y][b0.z][p_idx].z = sum_z ;
54  } // loop_p
55  }}} // loop_grid1_*
56  }}} // loop_grid0_*
57 }
#define blockSide
Definition: md.h:11
#define MIN(x, y)
Definition: md.c:3
TVMArray b0[1]
TYPE z
Definition: md.h:24
#define TYPE
Definition: backprop.h:21
void md(int n_points[blockSide][blockSide][blockSide], dvector_t force[blockSide][blockSide][blockSide][densityFactor], dvector_t position[blockSide][blockSide][blockSide][densityFactor])
Definition: md.c:6
int32_t z
Definition: md.h:27
#define lj1
Definition: md.h:20
Definition: md.h:26
Definition: md.h:23
int32_t x
Definition: md.h:27
#define lj2
Definition: md.h:21
TYPE x
Definition: md.h:24
TVMArray b1[1]
#define densityFactor
Definition: md.h:18
TYPE y
Definition: md.h:24
int32_t y
Definition: md.h:27
#define MAX(x, y)
Definition: md.c:4

Generated on Mon Feb 12 2024 13:02:50 for PandA-2024.02 by doxygen 1.8.13