~ubuntu-branches/ubuntu/trusty/nwchem/trusty-proposed

« back to all changes in this revision

Viewing changes to src/tools/ga-5-2/python/benchmarks/from_distnumpy/nbody.py

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Daniel Leidert, Andreas Tille, Michael Banck
  • Date: 2013-07-04 12:14:55 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130704121455-5tvsx2qabor3nrui
Tags: 6.3-1
* New upstream release.
* Fixes anisotropic properties (Closes: #696361).
* New features include:
  + Multi-reference coupled cluster (MRCC) approaches
  + Hybrid DFT calculations with short-range HF 
  + New density-functionals including Minnesota (M08, M11) and HSE hybrid
    functionals
  + X-ray absorption spectroscopy (XAS) with TDDFT
  + Analytical gradients for the COSMO solvation model
  + Transition densities from TDDFT 
  + DFT+U and Electron-Transfer (ET) methods for plane wave calculations
  + Exploitation of space group symmetry in plane wave geometry optimizations
  + Local density of states (LDOS) collective variable added to Metadynamics
  + Various new XC functionals added for plane wave calculations, including
    hybrid and range-corrected ones
  + Electric field gradients with relativistic corrections 
  + Nudged Elastic Band optimization method
  + Updated basis sets and ECPs 

[ Daniel Leidert ]
* debian/watch: Fixed.

[ Andreas Tille ]
* debian/upstream: References

[ Michael Banck ]
* debian/upstream (Name): New field.
* debian/patches/02_makefile_flags.patch: Refreshed.
* debian/patches/06_statfs_kfreebsd.patch: Likewise.
* debian/patches/07_ga_target_force_linux.patch: Likewise.
* debian/patches/05_avoid_inline_assembler.patch: Removed, no longer needed.
* debian/patches/09_backported_6.1.1_fixes.patch: Likewise.
* debian/control (Build-Depends): Added gfortran-4.7 and gcc-4.7.
* debian/patches/10_force_gcc-4.7.patch: New patch, explicitly sets
  gfortran-4.7 and gcc-4.7, fixes test suite hang with gcc-4.8 (Closes:
  #701328, #713262).
* debian/testsuite: Added tests for COSMO analytical gradients and MRCC.
* debian/rules (MRCC_METHODS): New variable, required to enable MRCC methods.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#import numpy as np
 
2
import sys
 
3
import time
 
4
 
 
5
d = int(sys.argv[1]) #Distributed
 
6
n = int(sys.argv[2]) #Number of bodies
 
7
k = int(sys.argv[3]) #Number of iterations
 
8
 
 
9
if d:
 
10
    import ga.gain as np
 
11
    print "GAiN"
 
12
else:
 
13
    import numpy as np
 
14
    print "NumPy"
 
15
 
 
16
G = 1     #Gravitational constant
 
17
dT = 0.01 #Time increment
 
18
 
 
19
#M  = np.empty((n,1))
 
20
#np.ufunc_random(M,M)
 
21
M   = np.random.random_sample((n,1))
 
22
#MT = np.empty((1,n))
 
23
#np.ufunc_random(MT,MT)
 
24
MT  = np.random.random_sample((1,n))
 
25
#Px = np.empty((n,1))
 
26
#np.ufunc_random(Px,Px)
 
27
Px  = np.random.random_sample((n,1))
 
28
#Py = np.empty((n,1))
 
29
#np.ufunc_random(Py,Py)
 
30
Py  = np.random.random_sample((n,1))
 
31
#Pz = np.empty((n,1))
 
32
#np.ufunc_random(Pz,Pz)
 
33
Pz  = np.random.random_sample((n,1))
 
34
#PxT= np.empty((1,n))
 
35
#np.ufunc_random(PxT,PxT)
 
36
PxT = np.random.random_sample((1,n))
 
37
#PyT= np.empty((1,n))
 
38
#np.ufunc_random(PyT,PyT)
 
39
PyT = np.random.random_sample((1,n))
 
40
#PzT= np.empty((1,n))
 
41
#np.ufunc_random(PzT,PzT)
 
42
PzT = np.random.random_sample((1,n))
 
43
#Vx = np.empty((n,1))
 
44
#np.ufunc_random(Vx,Vx)
 
45
Vx  = np.random.random_sample((n,1))
 
46
#Vy = np.empty((n,1))
 
47
#np.ufunc_random(Vy,Vy)
 
48
Vy  = np.random.random_sample((n,1))
 
49
#Vz = np.empty((n,1))
 
50
#np.ufunc_random(Vz,Vz)
 
51
Vz  = np.random.random_sample((n,1))
 
52
 
 
53
OnesCol = np.zeros((n,1), dtype=float)+1.0
 
54
OnesRow = np.zeros((1,n), dtype=float)+1.0
 
55
#Identity= array(diag([1]*n), dtype=double)
 
56
 
 
57
#np.timer_reset()
 
58
#np.evalflush()
 
59
stime = time.time()
 
60
for i in xrange(k):
 
61
    #distance between all pairs of objects
 
62
    Fx = np.dot(OnesCol, PxT) - np.dot(Px, OnesRow)
 
63
    Fy = np.dot(OnesCol, PyT) - np.dot(Py, OnesRow)
 
64
    Fz = np.dot(OnesCol, PzT) - np.dot(Pz, OnesRow)
 
65
 
 
66
    Dsq = Fx * Fx
 
67
    Dsq += Fy * Fy
 
68
    Dsq += Fz * Fz
 
69
    #Dsq += Identity
 
70
    D = np.sqrt(Dsq)
 
71
 
 
72
    #mutual forces between all pairs of objects
 
73
    F = np.dot(M, MT)
 
74
    F *= G
 
75
    F /= Dsq
 
76
    del Dsq
 
77
    #F = F - diag(diag(F))#set 'self attraction' to 0
 
78
    Fx /= D
 
79
    Fx *= F
 
80
    Fy /= D
 
81
    Fy *= F
 
82
    Fz /= D
 
83
    Fz *= F
 
84
    del D
 
85
    del F
 
86
 
 
87
    #net force on each body
 
88
    Fnet_x = np.add.reduce(Fx,1)
 
89
    Fnet_y = np.add.reduce(Fy,1)
 
90
    Fnet_z = np.add.reduce(Fz,1)
 
91
 
 
92
    Fnet_x = Fnet_x[:,np.newaxis]
 
93
    Fnet_y = Fnet_y[:,np.newaxis]
 
94
    Fnet_z = Fnet_z[:,np.newaxis]
 
95
 
 
96
    Fnet_x *= dT
 
97
    Fnet_y *= dT
 
98
    Fnet_z *= dT
 
99
 
 
100
    #change in velocity:
 
101
    Vx += Fnet_x / M
 
102
    Vy += Fnet_y / M
 
103
    Vz += Fnet_z / M
 
104
    del Fnet_x
 
105
    del Fnet_y
 
106
    del Fnet_z
 
107
 
 
108
    #change in position
 
109
    Px += Vx * dT
 
110
    Py += Vy * dT
 
111
    Pz += Vz * dT
 
112
 
 
113
#np.evalflush()
 
114
print 'nbody with #bodies: ', n,', iter: ', i+1, 'in sec: ', time.time() - stime,
 
115
if d:
 
116
    print " (Dist) notes: %s"%sys.argv[4]
 
117
else:
 
118
    print " (Non-Dist) notes: %s"%sys.argv[4]
 
119
 
 
120
 
 
121
 
 
122
 
 
123
"""Paper version:
 
124
    #distance between all pairs of objects
 
125
    Fx = dot(OnesCol, PxT) - dot(Px, OnesRow)
 
126
    Fy = dot(OnesCol, PyT) - dot(Py, OnesRow)
 
127
    Fz = dot(OnesCol, PzT) - dot(Pz, OnesRow)
 
128
 
 
129
    Dsq = Fx * Fx + Fy * Fy + Fx * Fz #+ Identity
 
130
    D = sqrt(Dsq)
 
131
 
 
132
    #mutual forces between all pairs of objects
 
133
    F = G * dot(M, MT) / Dsq
 
134
 
 
135
    #F = F - diag(diag(F))#set 'self attraction' to 0
 
136
    Fx = (Fx / D) * F
 
137
    Fy = (Fy / D) * F
 
138
    Fz = (Fz / D) * F
 
139
 
 
140
    #net force on each body
 
141
    Fnet_x = add.reduce(Fx,1)
 
142
    Fnet_x = add.reduce(Fy,1)
 
143
    Fnet_x = add.reduce(Fz,1)
 
144
 
 
145
    #change in velocity:
 
146
    Vx += Fnet_x[:,newaxis] * dT / M
 
147
    Vy += Fnet_y[:,newaxis] * dT / M
 
148
    Vz += Fnet_z[:,newaxis] * dT / M
 
149
 
 
150
    #change in position
 
151
    Px += Vx * dT
 
152
    Py += Vy * dT
 
153
    Pz += Vz * dT
 
154
"""