コード例 #1
0
ファイル: CMM.py プロジェクト: neffmallon/pistol
def test_cmm(n = 10000, cutoff = 50, a = 100, nbin = 10, ntrials = 100):
    "Tests multipole approximations to electrostatic potential"

    bindims = (nbin,nbin,nbin)
    bbox = (-a,a,-a,a,-a,a)
    print " n = %d, a = %d, cut = %d, nbin = %d" % (n,a,cutoff,nbin)
    tfull = []
    tbin = []
    tvbin = []
    rms = 0
    
    for i in range(ntrials):
        points = RandomQs(n,bbox)  # Create a random set of charges
        xyz = RandomPosition(bbox) # Select a random position

        t0 = time()
        vfull = full_potential(xyz,points)
        t1 = time()

        tfull.append(t1-t0)

        cmm = CMM(bindims,points)
        t2 = time()
        tbin.append(t2-t1)

        vbin = cmm.pot(xyz)
        t3 = time()
        tvbin.append(t3-t2)
        rms += pow(vfull-vbin,2)
        print "Trial %d: %10.4f %10.4f" % (i,vfull,vbin)
    print "Average times: %10.4f %10.4f %10.4f" %\
          (avg(tfull),avg(tbin),avg(tvbin))
    print "RMS error: ",sqrt(rms/ntrials)
    return
コード例 #2
0
ファイル: CMM.py プロジェクト: neffmallon/pistol
    def full_potential(self,xyz): return full_potential(xyz,self._points)

    def mp_potential(self,xyz):