Example #1
0
 def draw_plane( self , plane="xy", color=( 0.7 , 0.7 , 0.7 , 0.3 ) , leng=None ):
     
     if leng == None :
         leng = self.axis_len
         
     
     t = tr.Transformations()
     t.set_points_tuple_size(2)
     
     if plane == "xy" :
         t.rotX( np.radians(0) )
     elif plane == "yz" :
         t.rotY( np.radians(90) )
     elif plane == "xz" :
         t.rotX( np.radians(90) )
     elif plane == "-yz" :
         t.rotX( np.radians(180) )
         t.rotY( np.radians(90) )
     elif plane == "-y-z" :
         t.rotX( np.radians(180) )
         t.rotY( np.radians(-90) )
     elif plane == "y-z" :
         t.rotY( np.radians(-90) )
     elif plane == "x-y" :
         t.rotX( np.radians(180) )
     elif plane == "-x-y" :
         t.rotX( np.radians(180) )
         t.rotY( np.radians(180) )
     elif plane == "x-z" :
         t.rotX( np.radians(-90) )
     elif plane == "-x-z" :
         t.rotX( np.radians(-90) )
         t.rotZ( np.radians(180) )
     elif plane == "-xz" :
         t.rotX( np.radians(90) )
         t.rotZ( np.radians(180) )
     elif plane == "-x-z" :
         t.rotX( np.radians(-90) )
         t.rotZ( np.radians(180) )
     elif plane == "-xy" :
         t.rotY( np.radians(180) )
     
     for i in range( 1 , int(leng) ):
         t.append_point( [ float(i) ,  0.0 , 0.0 ] )
         t.append_point( [ float(i) , leng , 0.0 ] )
         
         t.append_point( [ 0.0  , float(i) , 0.0 ] )
         t.append_point( [ leng , float(i) , 0.0 ] )
     
     glColor4f( color[0] , color[1] , color[2] , color[3] )
         
     glBegin(GL_LINES)
     
     for pts in t :
         glVertex3fv( pts[0] )
         glVertex3fv( pts[1] )
         
     glEnd()
Example #2
0
 def draw_arrow( self , color , axis , leng=None ):
     
     if leng == None :
         leng = self.axis_len
         
     arrh = leng * 0.1
     arrp = leng - arrh
     
     dash = leng * 0.03
     
     t = tr.Transformations()
     t.set_points_tuple_size(2)
     
     if axis == "x" :
         t.rotX( np.radians(0) ) 
     elif axis == "y" :
         t.rotZ( np.radians(90) ) 
     elif axis == "z" :
         t.rotY( np.radians(-90) ) 
     if axis == "-x" :
         t.rotZ( np.radians(180) ) 
     elif axis == "-y" :
         t.rotZ( np.radians(-90) ) 
     elif axis == "-z" :
         t.rotY( np.radians(90) ) 
             
     t.append_point( np.array( [ 0.0  , 0.0 , 0.0 ] ) )
     t.append_point( np.array( [ leng , 0.0 , 0.0 ] ) )
     
     t.append_point( np.array( [ leng ,   0.0 , 0.0 ] ) )
     t.append_point( np.array( [ arrp , -arrh , 0.0 ] ) )
     
     t.append_point( np.array( [ leng ,  0.0 , 0.0 ] ) )
     t.append_point( np.array( [ arrp , arrh , 0.0 ] ) )        
     
     for i in range( 1 , int(leng) ):
         t.append_point( [ float(i) ,  dash , 0.0 ] )
         t.append_point( [ float(i) , -dash , 0.0 ] )
     
     glColor3f( color[0] , color[1] , color[2] )
     
     glBegin(GL_LINES)
     
     for pts in t :
         glVertex3fv( pts[0] )
         glVertex3fv( pts[1] )
     
         
     glEnd()
     
     
     
     
Example #3
0
    def _draw_field(self, key):

        sz = self.__X.shape[0]

        transf = tr.Transformations()
        transf.set_points_tuple_size(6)

        self.__fields[key]["fun"](self.__V, self.__X)

        # Vector in spherical coordinates
        self.__Vs[:, 0] = np.sqrt(np.sum(self.__V**2, 1))
        self.__Vs[:, 1] = np.arccos(self.__V[:, 2] / self.__Vs[:, 0])
        self.__Vs[:, 2] = np.arctan(np.divide(self.__V[:, 1], self.__V[:, 0]))

        err_nan = np.isnan(self.__Vs[:, 2])
        self.__Vs[err_nan, 2] = np.sign(self.__V[err_nan, 2]) * np.pi / 2.0

        unit = self.__fields[key]["unit"]

        for i in range(sz):

            x = self.__X[i, 0] / self.__density
            y = self.__X[i, 1] / self.__density
            z = self.__X[i, 2] / self.__density

            transf.push_matrix()
            transf.translation(x, y, z)

            transf.rotZ(self.__Vs[i, 2])
            transf.rotY(-(np.pi / 2.0 - self.__Vs[i, 1]))

            le = self.__Vs[i, 0] / unit

            transf.append_point([0, 0, 0])
            transf.append_point([le, 0, 0])

            transf.append_point([le, 0, 0])
            transf.append_point([0.8 * le, 0.1 * le, 0])

            transf.append_point([le, 0, 0])
            transf.append_point([0.8 * le, -0.1 * le, 0])

            transf.pop_matrix()

        color = np.zeros((4))

        glBegin(GL_LINES)

        for pts in transf:
            self.__fields[key]["color_fun"](color, pts[0])

            glColor4f(color[0], color[1], color[2], color[3])

            glVertex3fv(pts[0])
            glVertex3fv(pts[1])

            glVertex3fv(pts[2])
            glVertex3fv(pts[3])

            glVertex3fv(pts[4])
            glVertex3fv(pts[5])

        glEnd()
Example #4
0
def my_test() :
    
    
    pset = ps.ParticlesSet( 10 )
    
    lo = log.Logger( pset , 10 )
    
    for i in range( 105 ) :
        pset.X[:] =  float(i) 
        lo.log()
        
        print( lo.get_particles_log( 3 ) )
    
    exit()
        
    t = tr.Transformations()
    
    t.set_points_tuple_size(1)
        
    t.rotate( np.radians(90) , 1 , 0 , 0 )
    #t.rotX( np.radians(90) )
    
    t.append_point( list( [1,0,0] ) )
    t.append_point( np.array( [1,1,0] ) )
    t.append_point( np.array( [1,1,1] ) )
    t.append_point( np.array( [0,1,1] ) )    
    
    t.push_matrix()
    t.identity()
    t.translation( 10 , 2 , 2 )
    #t.rotate( np.radians(20) , 1 , 1 , 1 )
    
    t.append_point( [1,1,1] )
    t.append_point( np.matrix( [0,1,1] ).T ) 
    
    t.pop_matrix()
    
    t.append_point( np.array( [1,0,0] ) )
    t.append_point( [1,1,0] )
    t.append_point( np.array( [1,1,1] ) )
    t.append_point( [0,1,1] )   
    
    #print( t.transform(pt[0] , pt[1] , pt[2] ) )
    
    print("")
    
    for (p) in t :
        print( p )
    
    exit()
    
    n = 10
    dt = 0.005
    #dt = 0.0023453
    
    steps = 1000000
    
    G = 0.001
    #G = 6.67384e-11
    
    FLOOR = -10
    CEILING = 10
    


    #ff = fc.FileCluster()
    #ff.open( options.path_name )
    
    pset = ps.ParticlesSet( n , label=True )
    
    pset.label[8] = "tttt"
    pset.label[9] = "tzzzttt"
    
    pset.add_property_by_name("ciao",dim=1 , model="list")
    
    pset.get_by_name("ciao")[3] = 100
    pset.get_by_name("X")[3,:] = 101
    
    sz = 15
    pset.resize( sz )
    
    tree = ot.OcTree()
    
    pset.get_by_name("X")[:] = np.random.rand(sz,3)
    pset.get_by_name("M")[:] = 1.0
    
    pset.update_centre_of_mass()
    
    print(" C O M pset")
    print( pset.centre_of_mass() )
    print("")
    
    csrt = ct.ConstrainedX( pset )
    
    cfit = cfi.ConstrainedForceInteractions( pset )
    
    cfit.add_connections( [[12,3],[4,4],[6,8],[1,1]] )
    cfit.remove_connections( [[12,3]] )
    
    print( cfit.dense )
    print( cfit.sparse )
    print( cfit.items )
    
    cc = np.array( [[1,2,3],[3,3,3]] )
    cc = np.array( [[1,2,3],[3,3,5]] )
    
    csrt.add_x_constraint( [2,5] , cc )
    csrt.add_x_constraint( [7,10] , cc )
    
    print( csrt.get_cx_indicies() )
    print( csrt.cX )
    
    csrt.remove_x_constraint( [2,10] )
    
    print( csrt.get_cx_indicies() )
    print( csrt.cX )
    
    exit() 
    
    tree.set_global_boundary()
    
    a = time.time()
    tree.build_tree( pset )
    b = time.time()
    
    print( "Tot time: % f" %(b-a) )
    
    C = np.array([0.5,0.4,0.3])
    R = 0.05
    
    a = time.time()
    for ix in range( pset.size ):
        nl = tree.search_neighbour( pset.X[ix,:] , R )
    b = time.time()
    
    print( "Tot time octree : % f" %(b-a) )
    
    nl = np.sort( nl )
    
    print("")
    print("nl:")
    print( nl )
    
    print("")
    print("dd:")
    
    a = time.time()
    for ix in range( pset.size ):
        dd = np.sqrt(  np.sum( (pset.X[ix,:] - pset.X)**2 , 1 ) ) 
        din, = np.where( dd <= R )
    b = time.time()
    
    print( "Tot time numpy : % f" %(b-a) )
    
    print( din )
    
    print(" C O M")
    print( tree.centre_of_mass )
    print("")
    
    print ( np.all( nl == din ) )
    
    #tree.print_tree()
    
    
    #print( pset.get_by_name( "ciao" ) )
    #print( pset.get_by_name( "X" ) )
    #print("")
    #print( pset.X )
    #print( pset.label )
    
    
    exit()
    return
    
    #ff.insert3( pset )
    #ff.close()  
        
    #pset.unit = 149597870700.0
    #pset.mass_unit = 5.9736e24
    
    
    cs = clu.RandCluster()
    
    cs.insert3( pset.X , M=pset.M , V=pset.V ,
                n = n/2 , centre=(-1.5,1,0.5) , mass_rng=(0.5,5.0) ,
                vel_rng=(0,0) , vel_mdl="bomb" )
    
    cs.insert3( pset.X , M=pset.M , V=pset.V ,
                start_indx=int(n/2) , n = int(n/2) , centre=(1.5,-0.5,0.5) ,
                vel_rng=(0.2,0.4) , vel_mdl="const" , vel_dir=[-1.0,0.0,0.0] )
    #
    
    grav = gr.Gravity( pset.size , Consts=G )
    #grav = cf.ConstForce(n , u_force=[0,0,-1.0] )
    #grav = MyField( pset.size , dim=3 )
    #grav = ls.LinearSpring( pset.size , Consts=10e8 )
    
    grav.set_masses( pset.M )
    
    
    bound = None
    #bound = pb.PeriodicBoundary( (-50.0 , 50.0) )
    #bound = rb.ReboundBoundary(  (-10.0 , 10.0)  )
    
    pset.set_boundary( bound )
    grav.update_force( pset )
    
    solver = els.EulerSolver( grav , pset , dt )
    #solver = lps.LeapfrogSolver( grav , pset , dt )
    #solver = svs.StormerVerletSolver( grav , pset , dt )
    #solver = rks.RungeKuttaSolver( grav , pset , dt )    
        
    a = aogl.AnimatedGl()
    # a = anim.AnimatedScatter()
        
    
    a.xlim = ( FLOOR , CEILING )
    a.ylim = ( FLOOR , CEILING )
    a.zlim = ( FLOOR , CEILING )
    
    a.ode_solver = solver
    a.pset = pset
    a.steps = steps
    
    a.build_animation()
    
    a.start()
    
    return