PandA-2024.02
generate.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8 #include <assert.h>
9 
10 #include "md.h"
11 
12 // LJ1=4e(s^12), LJ2=4e(s^6) -> s=1.049
13 #define van_der_Waals_thresh (1.049*1.049)
14 
15 static inline TYPE dist_sq( dvector_t p, dvector_t q ) {
16  TYPE dx, dy, dz;
17  dx = p.x - q.x;
18  dy = p.y - q.y;
19  dz = p.z - q.z;
20  return dx*dx + dy*dy + dz*dz;
21 }
22 
23 int main(int argc, char **argv)
24 {
25  struct bench_args_t data;
26  int fd, reject;
27  int32_t i;
28  dvector_t p, q;
29  ivector_t b;
31  int idx, entry;
32  struct prng_rand_t state;
33  //const TYPE infinity = (domainEdge*domainEdge*3.)*1000;//(max length)^2 * 1000
34 
35  // Create random positions in the box [0,domainEdge]^3
36  prng_srand(1,&state);
37  i=0;
38  while( i<nAtoms ) {
39  // Generate a new point
40  p.x = domainEdge*(((TYPE)prng_rand(&state))/((TYPE)PRNG_RAND_MAX));
41  p.y = domainEdge*(((TYPE)prng_rand(&state))/((TYPE)PRNG_RAND_MAX));
42  p.z = domainEdge*(((TYPE)prng_rand(&state))/((TYPE)PRNG_RAND_MAX));
43  // Assure that it's not directly on top of another atom
44  reject = 0;
45  for( idx=0; idx<nAtoms; idx++ ) {
46  q = points[idx];
47  if( dist_sq(p,q)<van_der_Waals_thresh ) {
48  reject=1;
49  break;
50  }
51  }
52  if(!reject) {
53  points[i] = p;
54  //printf("%lf %lf %lf\n", points[i].x, points[i].y, points[i].z );
55  ++i;
56  }
57  }
58 
59  // Insert points into blocks
60  memset(data.n_points, 0, blockSide*blockSide*blockSide*sizeof(int32_t));
61  memset(data.position, 0, 3*blockSide*blockSide*blockSide*densityFactor*sizeof(TYPE));
62  for( idx=0; idx<nAtoms; idx++ ) {
63  b.x = (int32_t) (points[idx].x / blockEdge);
64  b.y = (int32_t) (points[idx].y / blockEdge);
65  b.z = (int32_t) (points[idx].z / blockEdge);
66  entry = data.n_points[b.x][b.y][b.z];
67  data.position[b.x][b.y][b.z][entry].x = points[idx].x;
68  data.position[b.x][b.y][b.z][entry].y = points[idx].y;
69  data.position[b.x][b.y][b.z][entry].z = points[idx].z;
70  ++data.n_points[b.x][b.y][b.z];
71  assert(data.n_points[b.x][b.y][b.z]<densityFactor && "block overflow");
72  }
73  //for( b.x=0; b.x<blockSide; b.x++ ) {
74  //for( b.y=0; b.y<blockSide; b.y++ ) {
75  //for( b.z=0; b.z<blockSide; b.z++ ) {
76  // printf("grid[%d][%d][%d]: %d points\n", b.x, b.y, b.z, data.n_points[b.x][b.y][b.z]);
77  //}}}
78 
79  // Open and write
80  fd = open("input.data", O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
81  assert( fd>0 && "Couldn't open input data file" );
82  data_to_input(fd, (void *)(&data));
83 
84  return 0;
85 }
#define domainEdge
Definition: generate.c:12
static uint64_t prng_rand(struct prng_rand_t *state)
Definition: support.h:85
#define blockEdge
Definition: md.h:14
void data_to_input(int fd, void *vdata)
Definition: local_support.c:34
#define blockSide
Definition: md.h:11
TYPE z
Definition: md.h:24
#define TYPE
Definition: backprop.h:21
int32_t z
Definition: md.h:27
Definition: md.h:26
Definition: md.h:23
uint_fast16_t i
Definition: support.h:78
int32_t x
Definition: md.h:27
dvector_t position[blockSide][blockSide][blockSide][densityFactor]
Definition: md.h:40
int32_t n_points[blockSide][blockSide][blockSide]
Definition: md.h:38
static TYPE dist_sq(dvector_t p, dvector_t q)
Definition: generate.c:15
#define nAtoms
Definition: md.h:9
TYPE x
Definition: md.h:24
int main(int argc, char **argv)
Definition: generate.c:12
#define densityFactor
Definition: md.h:18
static void prng_srand(uint64_t seed, struct prng_rand_t *state)
Definition: support.h:106
TYPE y
Definition: md.h:24
x
Return the smallest n such that 2^n >= _x.
int32_t y
Definition: md.h:27
int b[SIZE]
Definition: sort.h:34
#define van_der_Waals_thresh
Definition: generate.c:13
#define PRNG_RAND_MAX
Definition: support.h:82

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