Example #1
0
 def get_force(self):
     """
     Build and return an object for mdeling the force (derived form the abstract class force)
     """
     print("")
     
     self.force = None
     
     if self.force_name == "gravity" :
         self.force = gr.Gravity( self.pset.size , self.pset.dim , Consts=float(self.force_const) )
         
         print( " setup - force - Type:  Gravity " )
         print( " setup - force - G:     %e " % float(self.force_const) )
         
     elif self.force_name == "linear_spring" :
         self.force = ls.LinearSpring( self.pset.size , self.pset.dim , Consts=self.force_const )
         
         print( " setup - force - Type:  Linear spring " )
         print( " setup - force - K:     %e " % float(self.force_const) )
         
     elif self.force_name == "constant_force" :
         fv = read_str_list( self.force_vector )
         
         self.force = cf.ConstForce( self.pset.size , dim=self.pset.dim , u_force=fv )
         
         print( " setup - force - Type:  Constant " )
         print( " setup - force - Vect:  %e  %e  %e " % ( float(fv[0]) , float(fv[1]) , float(fv[2]) )  )
     
     self.force.set_masses( self.pset.M )
     
     return self.force
Example #2
0
def bubble():
    """
    Pseudo bubble simulation
    """

    steps = 1000000
    dt = 0.01

    r_min = 1.5

    rand_c = rc.RandCluster()

    pset = ps.ParticlesSet(1000)

    rand_c.insert3(X=pset.X,
                   M=pset.M,
                   start_indx=0,
                   n=pset.size,
                   radius=5.0,
                   mass_rng=(0.5, 0.8),
                   r_min=0.0)

    bubble = pb.PseudoBubble(pset.size, pset.dim, Consts=(r_min, 10))
    constf = cf.ConstForce(pset.size, dim=pset.dim, u_force=[0, 0, -10])
    drag = dr.Drag(pset.size, pset.dim, Consts=0.01)

    multif = mf.MultipleForce(pset.size, pset.dim)
    multif.append_force(bubble)
    multif.append_force(constf)
    multif.append_force(drag)

    multif.set_masses(pset.M)

    #solver = els.EulerSolver( multif , pset , dt )
    #solver = lps.LeapfrogSolver( lennard_jones , pset , dt )
    solver = svs.StormerVerletSolver(multif, pset, dt)
    #solver = rks.RungeKuttaSolver( lennard_jones , pset , dt )
    #solver = mds.MidpointSolver( lennard_jones , pset , dt )

    bound = rb.ReboundBoundary(bound=(-5.0, 5.0))

    pset.set_boundary(bound)

    a = aogl.AnimatedGl()

    a.ode_solver = solver
    a.pset = pset
    a.steps = steps

    a.build_animation()

    a.start()

    return
Example #3
0
def fountain():
    """
    Fountain demo
    """
    steps = 10000000
    dt = 0.01

    pcnt = 250000

    pset = ps.ParticlesSet(pcnt)

    pset.M[:] = 0.1
    pset.X[:, 2] = 0.7 * np.random.rand(pset.size)

    grav = cf.ConstForce(pset.size, dim=pset.dim, u_force=(0.0, 0.0, -10.0))
    drag = dr.Drag(pset.size, dim=pset.dim, Consts=0.01)

    multi = mf.MultipleForce(pset.size, dim=pset.dim)

    multi.append_force(grav)
    multi.append_force(drag)

    multi.set_masses(pset.M)

    solver = mds.MidpointSolver(multi, pset, dt)
    solver.update_force()

    default_pos.sim_time = solver.get_sim_time()

    bd = (-100.0, 100.0, -100.0, 100.0, 0.0, 100.0)
    bound = db.DefaultBoundary(bd, dim=3, defualt_pos=default_pos)

    pset.set_boundary(bound)

    a = aogl.AnimatedGl()

    a.ode_solver = solver
    a.pset = pset
    a.steps = steps

    a.draw_particles.set_draw_model(a.draw_particles.DRAW_MODEL_VECTOR)

    a.init_rotation(-80, [0.7, 0.05, 0])

    a.build_animation()
    a.start()

    return
Example #4
0
    def build_animation(self):

        self.steps = 3000

        self.pset = ps.ParticlesSet(1, 3)

        self.ip = 0

        self.pset.M[:] = 1.0
        self.pset.V[:] = 0.0

        self.t = np.zeros((self.steps))
        self.x = np.zeros((self.steps, self.pset.dim))

        self.xn = np.zeros((self.steps, self.pset.dim))

        constf = cf.ConstForce(self.pset.size,
                               u_force=[0, 0, -10.0],
                               dim=self.pset.dim)
        drag = dr.Drag(self.pset.size, Consts=1.0)

        multi = mf.MultipleForce(self.pset.size)

        multi.append_force(constf)
        multi.append_force(drag)

        multi.set_masses(self.pset.M)

        dt = 0.001

        self.odes = dict()

        self.odes["Euler      "] = els.EulerSolver(multi, self.pset, dt)
        self.odes["Runge Kutta"] = rks.RungeKuttaSolver(multi, self.pset, dt)
        self.odes["Leap Frog  "] = lps.LeapfrogSolver(multi, self.pset, dt)
        self.odes["MidPoint   "] = mps.MidpointSolver(multi, self.pset, dt)
        self.odes["Verlet     "] = svs.StormerVerletSolver(
            multi, self.pset, dt)
Example #5
0
def fountain():
    """
    Fountain demo
    """
    steps = 10000000
    dt = 0.005
    pcnt = 100000

    fl = True
    if test_pyopencl():
        print("OpenCL is installed and enabled ")
        print(" Try, at least, 200000 particles ")

        while fl:
            try:
                print(" ")
                pcnt = int(raw_input('How many particles: '))
            except:
                print("Please insert a number! ")
            else:
                fl = False

    pset = ps.ParticlesSet(pcnt, dtype=np.float32)

    pset.M[:] = 0.1
    pset.X[:, 2] = 0.7 * np.random.rand(pset.size)

    grav = cf.ConstForce(pset.size, dim=pset.dim, u_force=(0.0, 0.0, -10.0))

    occx = None
    if test_pyopencl():
        occx = occ.OpenCLcontext(
            pset.size, pset.dim,
            (occ.OCLC_X | occ.OCLC_V | occ.OCLC_A | occ.OCLC_M))
        drag = dr.DragOCL(pset.size,
                          dim=pset.dim,
                          Consts=0.01,
                          ocl_context=occx)
    else:
        drag = dr.Drag(pset.size, dim=pset.dim, Consts=0.01)

    multi = mf.MultipleForce(pset.size, dim=pset.dim)

    multi.append_force(grav)
    multi.append_force(drag)

    multi.set_masses(pset.M)

    #solver = mds.MidpointSolver( multi , pset , dt )
    if test_pyopencl():
        solver = els.EulerSolverOCL(multi, pset, dt, ocl_context=occx)
    else:
        solver = els.EulerSolver(multi, pset, dt)

    solver.update_force()

    default_pos.sim_time = solver.get_sim_time()

    bd = (-100.0, 100.0, -100.0, 100.0, 0.0, 100.0)
    bound = db.DefaultBoundary(bd, dim=3, defualt_pos=default_pos)

    pset.set_boundary(bound)

    a = aogl.AnimatedGl()

    a.ode_solver = solver
    a.pset = pset
    a.steps = steps

    a.draw_particles.set_draw_model(a.draw_particles.DRAW_MODEL_VECTOR)

    a.init_rotation(-80, [0.7, 0.05, 0])

    a.build_animation()
    a.start()

    return
Example #6
0
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
Example #7
0
def springs():
    """
    Springs demo
    """

    dt = 0.02
    steps = 1000000

    G = 0.5

    pset = ps.ParticlesSet(3, 3, label=True)

    pset.label[0] = "1"
    pset.label[1] = "2"
    pset.label[2] = "3"

    pset.X[:] = np.array([
        [2.0, 4.0, 1.0],  # 1
        [-2.0, -2.0, 1.0],  # 2
        [3.0, -3.0, 2.0]  # 3
    ])

    pset.M[:] = np.array([[1.0], [1.0], [1.5]])

    pset.V[:] = np.array([[0., 0., 0.], [0., 0, 0.], [0., 0, 0.]])

    springs = ls.LinearSpring(pset.size, Consts=G)
    constf = cf.ConstForce(pset.size, u_force=[0, 0, -1.5])
    drag = dr.Drag(pset.size, Consts=0.2)

    mlf = mf.MultipleForce(pset.size, 3)

    mlf.append_force(springs)
    #mlf.append_force( constf )
    #mlf.append_force( drag )

    pot = epe.ElasticPotentialEnergy(pset, springs)
    ken = ke.KineticEnergy(pset, springs)
    tot = te.TotalEnergy(ken, pot)

    #
    pot.update_measure()
    ken.update_measure()
    tot.update_measure()

    #
    #print( "Potential = %f " % pot.value() )
    #print( "Kinetic = %f " % ken.value() )

    #P = mm.MomentumParticles( pset , subset=np.array([1,2]) , model="part_by_part")
    #
    #P.update_measure()
    #
    #print( P.value() )

    bound = rb.ReboundBoundary(bound=(-10, 10))
    pset.set_boundary(bound)

    mlf.set_masses(pset.M)
    springs.set_masses(pset.M)

    springs.update_force(pset)
    mlf.update_force(pset)

    #solver = rks.RungeKuttaSolver( springs , pset , dt )
    solver = rks.RungeKuttaSolver(mlf, pset, dt)

    pset.enable_log(True, log_max_size=1000)

    a = aogl.AnimatedGl()

    a.trajectory = True
    a.trajectory_step = 1

    a.ode_solver = solver
    a.pset = pset
    a.steps = steps

    a.add_measure(ken)
    a.add_measure(pot)
    a.add_measure(tot)

    a.build_animation()

    a.start()

    return
Example #8
0
def bubble():
    """
    Pseudo bubble simulation
    """

    ocl_ok = test_pyopencl()

    if ocl_ok:
        pcnt = 9000
        r_min = 0.5
        occx = occ.OpenCLcontext(pcnt, 3)
    else:
        pcnt = 700
        r_min = 1.5

    steps = 1000000
    dt = 0.01

    rand_c = rc.RandCluster()

    pset = ps.ParticlesSet(pcnt, dtype=np.float32)

    rand_c.insert3(X=pset.X,
                   M=pset.M,
                   start_indx=0,
                   n=pset.size,
                   radius=3.0,
                   mass_rng=(0.5, 0.8),
                   r_min=0.0)

    if ocl_ok:
        bubble = pb.PseudoBubbleOCL(pset.size, pset.dim, Consts=(r_min, 10))
        drag = dr.DragOCL(pset.size, pset.dim, Consts=0.01)
    else:
        bubble = pb.PseudoBubble(pset.size, pset.dim, Consts=(r_min, 10))
        drag = dr.Drag(pset.size, pset.dim, Consts=0.01)

    constf = cf.ConstForce(pset.size, dim=pset.dim, u_force=[0, 0, -10.0])

    multif = mf.MultipleForce(pset.size, pset.dim)
    multif.append_force(bubble)
    multif.append_force(constf)
    multif.append_force(drag)

    multif.set_masses(pset.M)

    #solver = els.EulerSolver( multif , pset , dt )
    #solver = lps.LeapfrogSolver( multif , pset , dt )
    solver = svs.StormerVerletSolver(multif, pset, dt)
    #solver = rks.RungeKuttaSolver( lennard_jones , pset , dt )
    #solver = mds.MidpointSolver( lennard_jones , pset , dt )

    bound = rb.ReboundBoundary(bound=(-5.0, 5.0))

    pset.set_boundary(bound)

    a = aogl.AnimatedGl()

    a.ode_solver = solver
    a.pset = pset
    a.steps = steps

    if ocl_ok:
        a.draw_particles.set_draw_model(a.draw_particles.DRAW_MODEL_VECTOR)

    a.init_rotation(-80, [0.7, 0.05, 0])

    a.build_animation()

    a.start()

    return