def spring_constr(): """ Constrained catenary springs demo """ dt = 0.01 steps = 1000000 K = 60 x = list([]) m = list([]) #v = list([]) d = 0.1 ar = np.arange(-4.0, 4.0 + d, d) for i in ar: x.append(list([i, i, 3.0])) m.append(list([1.0 / float(len(ar))])) #v.append( list([0.0]) ) pset = ps.ParticlesSet(len(ar), 3) pset.X[:] = np.array(x, np.float64) pset.M[:] = np.array(m, np.float64) pset.V[:] = 0.0 pset.X[10:12, 2] = 4 pset.X[15:20, 1] = 4 #pset.X[10:15,1] = 6 ci = np.array([0, len(ar) - 1]) cx = np.array([[-4.0, -4.0, 3.0], [4.0, 4.0, 3.0]]) f_conn = list([]) for i in range(len(ar) - 1): f_conn.append(list([i, i + 1])) f_conn = np.array(f_conn, np.float64) costrs = csx.ConstrainedX(pset) costrs.add_x_constraint(ci, cx) fi = cfi.ConstrainedForceInteractions(pset) fi.add_connections(f_conn) spring = lsc.LinearSpringConstrained(pset.size, pset.dim, pset.M, Consts=K, f_inter=fi) constf = cf.ConstForce(pset.size, dim=pset.dim, u_force=[0, 0, -10]) drag = dr.Drag(pset.size, pset.dim, Consts=0.003) #damp = da.Damping( pset.size , pset.dim , Consts=0.003 ) multif = mf.MultipleForce(pset.size, pset.dim) multif.append_force(spring) multif.append_force(constf) multif.append_force(drag) multif.set_masses(pset.M) solver = els.EulerSolverConstrained(multif, pset, dt, costrs) #solver = lpc.LeapfrogSolverConstrained( multif , pset , dt , costrs ) #solver = svc.StormerVerletSolverConstrained( multif , pset , dt , costrs ) #solver = rkc.RungeKuttaSolverConstrained( multif , pset , dt , costrs ) #solver = mdc.MidpointSolverConstrained( multif , pset , dt , costrs ) a = aogl.AnimatedGl() pset.enable_log(True, log_max_size=1000) a.trajectory = False a.trajectory_step = 1 a.ode_solver = solver a.pset = pset a.steps = steps a.init_rotation(-80, [0.7, 0.05, 0]) a.build_animation() a.start() return
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