-
Notifications
You must be signed in to change notification settings - Fork 43
/
gen
61 lines (55 loc) · 1.16 KB
/
gen
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
BEGIN {
srand(12345)
nstep = 4
npoly = 500
step = 0.08
pi = 3.141592653589793
nbonds = npoly * (nstep - 1)
natoms = npoly * nstep
for (i = 0; i < npoly; i++) {
do {
u = x[i * nstep] = rand()
v = y[i * nstep] = rand()
w = z[i * nstep] = rand()
ready = 1
for (j = 1; j < nstep; j++) {
u += step * rand()
v += step * rand()
w += step * rand()
if (!good(u, v, w)) {
ready = 0
break
}
x[i * nstep + j] = u
y[i * nstep + j] = v
z[i * nstep + j] = w
}
} while (ready == 0)
}
printf \
"LAMMPS data file\n" \
"\n" \
"%d atoms\n" \
"%d bonds\n" \
"1 atom types\n" \
"1 bond types\n" \
"\n" \
"0 1 xlo xhi\n" \
"0 1 ylo yhi\n" \
"0 1 zlo zhi\n" \
"\n" \
"Atoms # bond\n" \
"\n", natoms, nbonds
for (i = 0; i < natoms; i++)
print i + 1, 0, 1, x[i], y[i], z[i], 0, 0, 0
printf \
"\n" \
"Bonds\n" \
"\n"
for (i = k = 0; i < npoly; i++)
for (j = 0; j < nstep - 1; j++)
print ++k, 1, i * nstep + j + 1, i * nstep + j + 2
}
function good(x, y, z) {
return 0 < x && x < 1 && 0 < y && y < 1 && 0 < z && z < 1
}