Example #1
0
 def get_ode_solver(self):
     """
     Build and return an object for solving the Newton Law of motion (derived form the abstract class ode_solver)
     """
     print("")
     
     self.ode_solver = None
     
     if self.ode_solver_name == "euler" :
         self.ode_solver = els.EulerSolver( self.force , self.pset , self.time_step )
         
         print( " setup - Integration method:  EULER "  )
            
     elif self.ode_solver_name == "runge_kutta" :
         self.ode_solver = rks.RungeKuttaSolver( self.force , self.pset , self.time_step )
         
         print( " setup - Integration method:  Runge Kutta "  )
         
     elif self.ode_solver_name == "leap_frog" :
         self.ode_solver = lps.LeapfrogSolver( self.force , self.pset , self.time_step )            
         
         print( " setup - Integration method:  Leap Frog "  )
     
     elif self.ode_solver_name == "stormer_verlet" :
         self.ode_solver = svs.StormerVerletSolver( self.force , self.pset , self.time_step )
     
         print( " setup - Integration method:  Stormer Verlet " )
         
     elif self.ode_solver_name == "midpoint" :
         self.ode_solver = mds.MidpointSolver( self.force , self.pset , self.time_step )
     
         print( " setup - Integration method:  Midpoint " )
     
     print( " setup - Integration method - time step: %e " %  self.time_step )   
     return self.ode_solver
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 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 #4
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