Ejemplo n.º 1
0
def gravity_cluster():

    if not test_pyopencl():
        print("")
        print("Attention !!! ")
        print(
            " This demo works only with PyOpenCL: \n  http://mathema.tician.de/software/pyopencl \n  http://www.khronos.org/opencl/ \n "
        )
        print(" Please install the package: python-pyopencl for continuing")
        print("")
        return

    G = 0.000001
    steps = 100000000

    n = 3000
    dt = 0.04

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

    cs = clu.RandGalaxyCluster()

    print("Building initial galaxy .... ")
    cs.insert3(pset.X, M=pset.M, V=pset.V, G=G)

    try:
        occx = occ.OpenCLcontext(
            pset.size, pset.dim,
            (occ.OCLC_X | occ.OCLC_V | occ.OCLC_A | occ.OCLC_M))
    except:
        print("")
        print("ERROR !!! ")
        print(" Please verify your opencl installation ")
        print(" Probably you must install your GPU OpenCL drivers")
        print("")
        return

    grav = gr.GravityOCL(pset.size, Consts=G, ocl_context=occx)
    grav.set_masses(pset.M)

    grav.update_force(pset)

    solver = els.EulerSolverOCL(grav, pset, dt, ocl_context=occx)

    a = aogl.AnimatedGl()

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

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

    a.build_animation()

    a.start()

    return
Ejemplo n.º 2
0
def gravity_cluster():
    
    if not test_pyopencl() :
        print("")
        print("Attention !!! ")
        print(" This demo works only with PyOpenCL: \n  http://mathema.tician.de/software/pyopencl \n  http://www.khronos.org/opencl/ \n ")
        print(" Please install the package: python-pyopencl for continuing")
        print("")
        return 
        
    
    G = 0.000001
    steps = 100000000
    
    n = 3000
    dt = 0.04
    
    pset = ps.ParticlesSet( n , dtype=np.float32 ) 
        
    cs = clu.RandGalaxyCluster()
    
    print("Building initial galaxy .... ")
    cs.insert3( pset.X, M=pset.M, V=pset.V , G=G )
    
    try :
        occx = occ.OpenCLcontext(  pset.size , pset.dim , (occ.OCLC_X|occ.OCLC_V|occ.OCLC_A|occ.OCLC_M) )
    except :
        print("")
        print("ERROR !!! ")
        print(" Please verify your opencl installation ")
        print(" Probably you must install your GPU OpenCL drivers")
        print("")
        return 
    
    grav = gr.GravityOCL( pset.size , Consts=G , ocl_context=occx  )
    grav.set_masses( pset.M )
    
    grav.update_force( pset )
    
    solver = els.EulerSolverOCL( grav , pset , dt , ocl_context=occx )
    
    a = aogl.AnimatedGl()
        
    a.draw_particles.set_draw_model( a.draw_particles.DRAW_MODEL_VECTOR )
        
    a.ode_solver = solver
    a.pset = pset
    a.steps = steps
    
    a.build_animation()
    
    a.start()
    
    return    
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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
def cube_water():
    """
    Smoothed particle hydrodynamics cube of water exemple
    """

    steps   = 10000000                      # Number of steps
    dt      = 0.005                         # dt should be defined according to a numerical stability parameter, a simple one will be dt<2h/vmax
    dx      = 0.1                           # spacing between particles L/Nx
#    dx      = 0.025                         # spacing between particles L/Nx
    aux     = (int(1.0/dx)-1)
    pcntVol = aux*aux*(aux+1)               # Number of particles in volume
    pcntWall= (aux+2)*(aux+2)               # Number of particles in the bottom
    pcntWall= pcntWall+(aux+1)*(aux+1)*4    # Number of particles in wallls
    pcnt    = pcntVol+pcntWall
    L       =  1.0                          # Water cube size
    g       = -9.8                          # Gravity acceleration

    h_local = .15

    ar = np.arange(0, 1+dx, dx)


    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   (size = np.int64(pcnt), mass = True, density = True, dtype   = np.float64)
    pset.add_property_by_name   (property_name = "pressure",                         to_type = np.float64)

    costrs  = boundaryParticles (pset=pset, pcnt=np.int(pcnt), pcntVol=np.int(pcntVol), pcntWall=np.int(pcntWall), ar=ar, L=L)
    initial_pos                 (pset=pset, pcnt=np.int(pcnt), pcntVol=np.int(pcntVol), pcntWall=np.int(pcntWall), ar=ar, L=L)
    initial_vel                 (pset=pset, pcnt=np.int(pcnt)                                                                )
    initial_pressure            (pset=pset, pcnt=np.int(pcnt),                                                            L=L)

    nstk = ns.HPSNavierStokes   (pset=pset     )
    nstk.calc_density_water_rest(pset=pset, H=L)
    nstk.calc_pressure          (pset=pset, H=L)

    pset.M[:] = 1000.0*L*L*L / pcntVol

    fi      = cfi.ConstrainedForceInteractions(pset)
    sk      = ns.HPSSmothingKernels(pset=pset)
    sk.h    = h_local                                   # RCM, for tests
    h       = sk.h

    point1  = np.array([0.0, 0.0, 0.0], dtype=np.float64)
    point2  = np.array([L,   L,   L  ], dtype=np.float64)
    mesh    = msh.Mesh                  (pset=pset, h = h, corner1 = point1, corner2 = point2)
    mesh.calc_mesh                      ()
    mesh.calc_particles_mesh_locations  (pset=pset, dtype=np.float64)
    f_conn = mesh.calc_particles_that_interact   (pset=pset)
    fi.add_connections                  (fc=f_conn)
    sk.calc_smothing_kernels            (pset=pset)
    grav   = cf.ConstForce( pset.size , dim=pset.dim , u_force=( 0.0 , 0.0 , g ) )

    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.EulerSolverConstrained( multi , pset , dt , costrs )

#    code.interact(local=locals()) # RCM lixo
#    pdb.pm() # RCM lixo
    solver.update_force()

    default_pos.sim_time = solver.get_sim_time()

#    bd = ( -100.0 , 100.0 , -100.0 , 100.0 , 0.0 , 100.0 )
    bd = ( -1.0 , 1.0 , -1.0 , 1.0 , 0.0 , 2.0 ) # RCM
    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
Ejemplo n.º 7
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