First, load the python module:
from pNbody import *
Create an empty pNbody object and get info
nb = Nbody()
nb.info()
Create a pNbody object from positions:
pos = np.ones((10,3),np.float32)
nb = Nbody(pos=pos)
nb.info()
Create a pNbody object using the ic module:
from pNbody import ic
nb = ic.plummer(10000,1,1,1,1,rmax=20.,M=1,name='plummer.dat',ftype='gadget')
comovingintegration = False
nb.write() # writes the nBody object to file 'plummer.dat' with the 'gadget' format (as specified in the Nbody object)
nb = Nbody('plummer.dat',ftype='gadget')
comovingintegration = False
nb.info()
Particle properties are numpy arrays of size nb.nbody:
nb.pos
nb.vel
nb.mass
nb.num
nb.tpe
Get the list of particle properties:
nb.get_list_of_array()
nb.show(size=(10,10))
nb.show(size=(20,20),shape=(256,256),palette='rainbow4')
positins x coordinates:
nb.x()
center of mass
nb.cm()
angular momentum:
nb.Ltot()
Compute potential and acceleration:
r = nb.rxyz()
pot = nb.Pot(nb.pos,eps=0.1)
acc = nb.Accel(nb.pos,eps=0.1)
alternatively, you can use a treecode algorithm to compute the potential and acceleration (which is much faster):
pot = nb.TreePot(nb.pos,eps=0.1)
acc = nb.TreeAccel(nb.pos,eps=0.1)
Plot:
import pylab as pt
pt.scatter(r, pot)
pt.show(); # for some reason the plot doesn't show up unless you put the semicolon here.