Пример #1
0
def main():
    # keep track of runtime
    start_time = datetime.now()
    
    # before anything get us into the NormAll directory. this is the directory that will hold the
    # directories with the different data sets. We need to start keeping track of phase diagrams and
    # PC sections

    parser = argparse.ArgumentParser()

    parser.add_argument('--dir', action = 'store', dest = "dir",type = str,required = True)
    parser.add_argument('--file', action = 'store', dest = "file",type = int,required = True)
    parser.add_argument('--totiter', action = 'store', dest = "totIter",type = str, required = True)
    parser.add_argument('--sliced', action = 'store', dest = "sliced",type = str,required = True)
    inargs = parser.parse_args()

    dir = inargs.dir
    file = str(inargs.file)+'poindat.txt'
    if inargs.sliced == 'True':
        sliced = True
    elif inargs.sliced == 'False':
        sliced = False


    print('inargs.totItier: ' +str(inargs.totIter))
    print('inargs.dir: ' +str(inargs.dir))
    print('inargs.file: ' + str(inargs.file))
    print('inargs.sliced: '+str(inargs.sliced))
    totIter = float(inargs.totIter)

    # The reason we add in the inargs.file (which is just an iteger) is becase we need the directory
    # in the /tmp file to be compleately unique for each file. Becasue some files might be handeld
    # by the same node we need to distiguesh. I also want the file being delt with in a directory
    # becasue we also need an info file that goes with it -> if we have two different systems
    # running and the node is handeling both of them then they would end up with the same info file.
    # The same thing could happen with the poindat.txt files too but that is much less likely.
    print('ls /tmp: ' + str(os.listdir('/tmp')))
    print('ls /tmp/dir+inargs.file/: ' + str(os.listdir('/tmp/'+dir+str(inargs.file))))

    #info_file = open("/users/o/m/omyers/Data/EC/2DBlock/Old/"+dir+"/info.txt","r")
    # trying to use /tmp folder to speed things up
    info_file = open("/tmp/"+dir+str(inargs.file)+"/info.txt","r")
    lns = info_file.readlines()

    surface = float(lns[3])
    wave_num = float(lns[5])
    omega = float(lns[7])
    damping = float(lns[9])
    grav = float(lns[11])
    dt = float(lns[13])

    totTime = totIter*dt
    print("dt is: " + str(dt))
    print("totTime is: "+str(totTime))
    time = pl.arange(0.0,totTime,dt)


    # try /tmp/ folder
    os.chdir("/tmp/"+dir+str(inargs.file))
    #os.chdir(os.path.expanduser("~/Data/EC/2DBlock/Old/"+dir))

    # how many cells is till periodicity use x = n*pi/k (n must be even #)
    modNum = 2*pl.pi/wave_num
    
    # get all the initial conditions we age going to do
    cur_file = open(file,"r")
    cur_lines = cur_file.readlines()
    cur_file.close()

    cur_file = open(file,"a")

    # get coef from file
    coefficient = float(cur_lines[0].split()[-1])
    
    # get the new initial conditions as an array in the form
    # arr[i,j]
    # i denotes a particular particle
    # j denotes x,y,vx,vy 
    # j=0 ---> vx
    # j=1 ---> vy
    # j=2 ---> x
    # j=3 ---> y
    # thus function also returns the number of particles so we can loop over it
    init,p_num = get_init_arr(cur_lines)

    all_poin = pl.array([])

    # count the number of poin sections. Needd for reshaping all_poin array
    num_ts = 0
    #print("pnum is : " + str(p_num))
    #print("len(init) : " + str(len(init[:,0])))
    for i in xrange(p_num):

        apx = ec.surfCentreLineApx(coefficient,wave_num,omega,damping)

        # itial conditions to next point
        x0 = init[i,:]

        sol = odeint(apx.f,x0,time)

        if sliced:
            for a in range(len(sol[:,0])):
                sol[a,2] = sol[a,2]%modNum
                if(((a*dt)%(2.0*pl.pi))<dt):
                    all_poin = pl.append(all_poin,sol[a,:]) 
                    if(i==0): 
                        num_ts += 1 
        else: 
            all_poin = pl.append(all_poin,sol)
            num_ts += len(sol)


    # Now reshape all_poin and put it in the file corectly 
    print("p_num is: " +str(p_num))
    print("num_ts is: "+ str(num_ts))
    all_poin = all_poin.reshape(p_num,-1,4)

    # add the poin sections back to file. Starting at 1 because we dont need to repeat the PC
    # section that is already there.
    for a in range(1,num_ts):

        cur_file.write("ZONE   I="+str(len(["used","to","be","filearr"]))+" DATAPACKING=POINT")
        cur_file.write("\n") 
        
        # I think we are reversing the order of the points in a PC section so I'm going to try to
        # write the file backwards (this the strange indexing and the -b).
        for b in range(1,p_num+1):
            # add the first particles solution to the data file
            toadd = "%15.6f %15.6f %15.6f %15.6f"%(all_poin[-b,a,0],all_poin[-b,a,1],all_poin[-b,a,2],all_poin[-b,a,3])
            toadd += "\n"
            cur_file.write(toadd)
           
    cur_file.close()

    print (datetime.now() - start_time)
    
    os.system('gzip /tmp/'+dir+str(inargs.file)+'/'+file)
    os.system('cp /tmp/'+dir+str(inargs.file)+'/'+file+'.gz /users/o/m/omyers/Data/EC/2DBlock/Old/'+dir+'/'+file+'.gz')
    os.system('rm -r /tmp/'+dir+str(inargs.file))
Пример #2
0
def main():
    
    # before anything get us into the NormAll directory. this is the directory that will hold the
    # directories with the different data sets. We need to start keeping track of phase diagrams and
    # PC sections

    parser = argparse.ArgumentParser()

    parser.add_argument('--dir', action = 'store', dest = "dir",type = str,required = True)
    parser.add_argument('--file', action = 'store', dest = "file",type = str,required = True)

    parser.add_argument("--surf", action = "store", dest =  "surf", type = float,required = True) 
    parser.add_argument("--k"   , action = "store", dest =  "k"   , type = float,required = True) 
    parser.add_argument("--w"   , action = "store", dest =  "w"   , type = float,required = True)  
    parser.add_argument("--damp", action = "store", dest =  "damp", type = float,required = True) 
    parser.add_argument("--g"   , action = "store", dest =  "g"   , type = float,required = True)  
    parser.add_argument("--dt"  , action = "store", dest =  "dt"   , type = float,required = True)  

    inargs = parser.parse_args()

    dt = inargs.dt
    # total number of iterations to perform
    totIter = 40000
    totTime = totIter*dt
    print("dt is: " + str(dt))
    print("totTime is: "+str(totTime))
    time = pl.arange(0.0,totTime,dt)


    os.chdir(os.path.expanduser("~/Data/EC/2DBlock/Old/"+inargs.dir))

    # parameters for what should be chaotic but orderd trajectories
    surface = inargs.surf
    wave_num    = inargs.k   
    omega    = inargs.w   
    damping = inargs.damp
    grav    = inargs.g   


    # how many cells is till periodicity use x = n*pi/k (n must be even #)
    modNum = 2*pl.pi/wave_num
    
    # make ec object
    elc = ec.electricCurtain()
    
    
    # get all the initial conditions we age going to do
    cur_file = open(inargs.file,"r")
    cur_lines = cur_file.readlines()
    cur_file.close()

    cur_file = open(inargs.file,"a")

    # get coef from file
    coefficient = float(cur_lines[0].split()[-1])
    
    # get the new initial conditions as an array in the form
    # arr[i,j]
    # i denotes a particular particle
    # j denotes x,y,vx,vy 
    # j=0 ---> vx
    # j=1 ---> vy
    # j=2 ---> x
    # j=3 ---> y
    # thus function also returns the number of particles so we can loop over it
    init,p_num = get_init_arr(cur_lines)

    
    all_poin = pl.array([])

    # count the number of poin sections. Needd for reshaping all_poin array
    num_ts = 0
    print("pnum is : " + str(p_num))
    print("len(init) : " + str(len(init[:,0])))
    for i in xrange(p_num):

        apx = ec.surfCentreLineApx(coefficient,wave_num,omega,damping)

        # itial conditions to next point
        x0 = init[i,:]

        sol = odeint(apx.f,x0,time)

        
        for a in range(len(sol[:,0])):
            sol[a,2] = sol[a,2]%modNum
            if(((a*dt)%(2.0*pl.pi/omega))<dt):
                print(((a*dt)%(2.0*pl.pi/omega)))
                all_poin = pl.append(all_poin,sol[a,:])
                
                if(i==0):
                    num_ts += 1

    # Now reshape all_poin and put it in the file corectly 
    print("p_num is: " +str(p_num))
    print("num_ts is: "+ str(num_ts))
    all_poin = all_poin.reshape(p_num,num_ts,4)

    # add the poin sections back to file. Starting at 1 because we dont need to repeat the PC
    # section that is already there.
    for a in range(1,num_ts):

        cur_file.write("ZONE   I="+str(len(["used","to","be","filearr"]))+" DATAPACKING=POINT")
        cur_file.write("\n") 
        
        # I think we are reversing the order of the points in a PC section so I'm going to try to
        # write the file backwards (this the strange indexing and the -b).
        for b in range(1,p_num+1):
            # add the first particles solution to the data file
            toadd = "%15.6f %15.6f %15.6f %15.6f"%(all_poin[-b,a,0],all_poin[-b,a,1],all_poin[-b,a,2],all_poin[-b,a,3])
            toadd += "\n"
            cur_file.write(toadd)

           
    cur_file.close()
Пример #3
0
def main():

    
    # before anything get us into the NormAll directory. this is the directory that will hold the
    # directories with the different data sets. We need to start keeping track of phase diagrams and
    # PC sections

    parser = argparse.ArgumentParser()

    parser.add_argument('--dir', action = 'store', dest = "dir",type = str,required = True)

    parser.add_argument("--surf", action = "store", dest =  "surf", type = float,required = True) 
    parser.add_argument("--coef", action = "store", dest =  "coef", type = float,required = True) 
    parser.add_argument("--k"   , action = "store", dest =  "k"   , type = float,required = True) 
    parser.add_argument("--w"   , action = "store", dest =  "w"   , type = float,required = True)  
    parser.add_argument("--damp", action = "store", dest =  "damp", type = float,required = True) 
    parser.add_argument("--g"   , action = "store", dest =  "g"   , type = float,required = True)  
    parser.add_argument("--dt"  , action = "store", dest =  "dt"   , type = float,required = True)  
    parser.add_argument("--bnum"   , action = "store", dest =  "bnum"   , type = int,required = True)  

    inargs = parser.parse_args()

    # define the lower left corner of block
    initvx = -4.0
    initx = 0

    # define dimensions of block
    xby = 6.0
    vxby = 8.0

    # define number of points in each direction
    numx =  30.0
    numvx = 30.0

    #numx =  80.0
    #numvx = 80.0

    # distance between points
    incx = xby/numx
    incvx = vxby/numvx


    dt = inargs.dt
    # total number of iterations to perform
    #totIter = 1000
    totIter = 3
    totTime = totIter*dt
    time = pl.arange(0.0,totTime,dt)


    os.chdir(os.path.expanduser("~/Data/EC/2DBlock/"+inargs.dir))

    # parameters for what should be chaotic but orderd trajectories
    surface = inargs.surf
    coefficient = inargs.coef
    wave_num    = inargs.k   
    omega    = inargs.w   
    damping = inargs.damp
    grav    = inargs.g   

    # how many cells is till periodicity use x = n*pi/k (n must be even #)
    modNum = 2*pl.pi/wave_num
    
    # make ec object
    elc = ec.electricCurtain()
    
    # define the lower left corner of block
    initialvx = initvx
    initialvy = 0.0
    initialx  = initx 
    initialy  = 1.0

    # define number of points in each direction
    num_of_x  = numx  
    num_of_vx = numvx 

    # distance between points
    increment_x  = incx  
    increment_vx = incvx 

    # initial conditions vector
    # set up: [xdot,ydot,x,y]
    x0 = pl.array([initialvx,initialvy,initialx,initialy])

    # a simple count variable to be used as file names. (was having repeat issues with file names
    # whun i was uing the sum of the indicies. silly owen.
    curp = 0 

    filearr = pl.array([])

    for kapa in range (int(num_of_vx)):
        for alpha in range(int(num_of_x)):

            # make a file for the curent particles solution
            curp += 1
            curpstr = str(inargs.bnum) +"_"+ str(curp)

            # keeptrack of the fiels for later
            filearr = pl.append(filearr,curpstr)
            
            curpdatfile = open(curpstr,"a")
            
            apx = ec.surfCentreLineApx(coefficient,wave_num,omega,damping)

            # itial conditions to next point
            x0 = pl.array([initialvx+kapa*increment_vx,initialvy,initialx+alpha*increment_x,initialy])

            sol = odeint(apx.f,x0,time)
            
            for a in range(len(sol[:,0])):
                sol[a,2] = sol[a,2]%modNum

            for i in range(len(sol)):
                # add the first particles solution to the data file
                toadd = "%15.6f %15.6f %15.6f %15.6f"%(sol[i,0],sol[i,1],sol[i,2],sol[i,3])
                toadd += "\n"
                curpdatfile.write(toadd)

            curpdatfile.close()