Révision 163

NBody/NBodyGL.py (revision 163)
416 416
    pass
417 417

  
418 418
def keyboard(k, x, y):
419
    global view_rotz
420 419
    LC_Z = as_8_bit( 'z' )
421 420
    UC_Z = as_8_bit( 'Z' )
422 421

  
423 422
    if k == LC_Z:
424
        view_rotz += 1.0
423
        ViewRZ += 1.0
425 424
    elif k == UC_Z:
426
        view_rotz -= 1.0
425
        ViewRZ -= 1.0
427 426
    elif ord(k) == 27: # Escape
428 427
        glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_CONTINUE_EXECUTION)
429 428
        glutSetOption(GLUT_ACTION_GLUTMAINLOOP_RETURNS,GLUT_ACTION_CONTINUE_EXECUTION) 
......
431 430
        return(False)
432 431
    else:
433 432
        return
434
    glRotatef(view_rotz, 0.0, 0.0, 1.0)
433
    glRotatef(ViewRZ, 0.0, 0.0, 1.0)
435 434
    glutPostRedisplay()
436 435

  
437 436
def special(k, x, y):
438
    global view_rotx, view_roty, view_rotz
437
    global ViewRX, ViewRY, ViewRZ
439 438

  
440 439
    if k == GLUT_KEY_UP:
441
        view_rotx += 1.0
440
        ViewRX += 1.0
442 441
    elif k == GLUT_KEY_DOWN:
443
        view_rotx -= 1.0
442
        ViewRX -= 1.0
444 443
    elif k == GLUT_KEY_LEFT:
445
        view_roty += 1.0
444
        ViewRY += 1.0
446 445
    elif k == GLUT_KEY_RIGHT:
447
        view_roty -= 1.0
446
        ViewRY -= 1.0
448 447
    else:
449 448
        return
450
    glRotatef(view_rotx, 1.0, 0.0, 0.0)
451
    glRotatef(view_roty, 0.0, 1.0, 0.0)
449
    glRotatef(ViewRX, 1.0, 0.0, 0.0)
450
    glRotatef(ViewRY, 0.0, 1.0, 0.0)
452 451
    glutPostRedisplay()
453 452

  
454
def mouse(button, state, x, y):
455
    global angle, delta_angle, halted
456
    if button == GLUT_LEFT_BUTTON:
457
        angle = angle + delta_angle
458
    elif button == GLUT_RIGHT_BUTTON:
459
	angle = angle - delta_angle
460
    elif button == GLUT_MIDDLE_BUTTON and state == GLUT_DOWN:
461
        if halted:
462
	    glutIdleFunc(display)
463
	    halted = 0
464
        else:
465
	    glutIdleFunc(halt)
466
	    halted = 1
467

  
468 453
def setup_viewport():
469 454
    global SizeOfBox
470 455
    glMatrixMode(GL_PROJECTION)
......
504 489
    InitialRandom=False
505 490
    # RNG Marsaglia Method
506 491
    RNG='MWC'
507
    # CheckEnergies
508
    CheckEnergies=False
509
    # Display samples in 3D
510
    GraphSamples=False
511 492
    # Viriel Distribution of stress
512 493
    VirielStress=True
513 494
    
514
    HowToUse='%s -h [Help] -r [InitialRandom] -e [VirielStress] -g [GraphSamples] -c [CheckEnergies] -d <DeviceId> -n <NumberOfParticules> -z <SizeOfBox> -v <Velocity> -s <Step> -i <Iterations> -m <ImplicitEuler|RungeKutta|ExplicitEuler|Heun> -t <FP32|FP64>'
495
    HowToUse='%s -h [Help] -r [InitialRandom] -e [VirielStress] -d <DeviceId> -n <NumberOfParticules> -z <SizeOfBall> -v <Velocity> -s <Step> -m <ImplicitEuler|RungeKutta|ExplicitEuler|Heun> -t <FP32|FP64>'
515 496

  
516 497
    try:
517
        opts, args = getopt.getopt(sys.argv[1:],"rehgcd:n:z:v:i:s:m:t:",["random","viriel","graph","check","device=","number=","size=","velocity=","iterations=","step=","method=","valuetype="])
498
        opts, args = getopt.getopt(sys.argv[1:],"rehd:n:z:v:s:m:t:",["random","viriel","device=","number=","size=","velocity=","step=","method=","valuetype="])
518 499
    except getopt.GetoptError:
519 500
        print(HowToUse % sys.argv[0])
520 501
        sys.exit(2)
......
558 539
            VirielStress=False
559 540
        elif opt in ("-s", "--step"):
560 541
            Step=MyFloat(arg)
561
        elif opt in ("-i", "--iterations"):
562
            Iterations=int(arg)
563 542
        elif opt in ("-r", "--random"):
564 543
            InitialRandom=True
565 544
        elif opt in ("-c", "--check"):
566 545
            CheckEnergies=True
567
        elif opt in ("-g", "--graph"):
568
            GraphSamples=True
569 546
        elif opt in ("-e", "--viriel"):
570 547
            VirielStress=True
571 548
                        
......
575 552
                
576 553
    print("Device choosed : %s" % Device)
577 554
    print("Number of particules : %s" % Number)
578
    print("Size of Box : %s" % SizeOfBox)
555
    print("Size of Ball : %s" % SizeOfBox)
579 556
    print("Initial velocity : %s" % Velocity)
580
    print("Number of iterations : %s" % Iterations)
581 557
    print("Step of iteration : %s" % Step)
582 558
    print("Method of resolution : %s" % Method)
583 559
    print("Initial Random for RNG Seed : %s" % InitialRandom)
584
    print("Check for Energies : %s" % CheckEnergies)
585
    print("Graph for Samples : %s" % GraphSamples)
586 560
    print("ValueType is : %s" % ValueType)
587 561
    print("Viriel distribution of stress %s" % VirielStress)
588 562

  
......
667 641
        CLLaunch=MyRoutines.SplutterStress(queue,(Number,1),None,clDataX,clDataV,clCoM,Velocity,np.uint32(110271),np.uint32(250173))
668 642
    CLLaunch.wait()
669 643

  
670
    if GraphSamples:
671
        cl.enqueue_copy(queue, MyDataX, clDataX)
672
        # t0=np.array([[MyDataX[0][0],MyDataX[0][1],MyDataX[0][2]]])
673
        # t1=np.array([[MyDataX[1][0],MyDataX[1][1],MyDataX[1][2]]])
674
        # tL=np.array([[MyDataX[-1][0],MyDataX[-1][1],MyDataX[-1][2]]])
675

  
676 644
    CLLaunch=MyRoutines.Potential(queue,(Number,1),None,clDataX,clPotential)
677 645
    CLLaunch=MyRoutines.Kinetic(queue,(Number,1),None,clDataV,clKinetic)
678 646
    CLLaunch.wait()
......
680 648
    cl.enqueue_copy(queue,MyKinetic,clKinetic)
681 649
    print('Viriel=%s Potential=%s Kinetic=%s'% (np.sum(MyPotential)+2*np.sum(MyKinetic),np.sum(MyPotential),np.sum(MyKinetic)))
682 650
 
683
    if GraphSamples:
684
        cl.enqueue_copy(queue, MyDataX, clDataX)
685
        # t0=np.array([[MyDataX[0][0],MyDataX[0][1],MyDataX[0][2]]])
686
        # t1=np.array([[MyDataX[1][0],MyDataX[1][1],MyDataX[1][2]]])
687
        # tL=np.array([[MyDataX[-1][0],MyDataX[-1][1],MyDataX[-1][2]]])
688

  
689 651
    wall_time_start=time.time()
690 652

  
691
    print("Use the mouse buttons to control some of the dots.")
692
    print("Hit any key to quit.")
693
    global view_rotx,view_roty,view_rotz,Iterations
694
    (view_rotx,view_roty,view_rotz)=(0.0, 0.0, 0.0)
653
    # Launch OpenGL Loop
654
    global Iterations
655
    #    (view_rotx,view_roty,view_rotz)=(0.0, 0.0, 0.0)
695 656
    Iterations=0
696 657
    glutInit(sys.argv)
697 658
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
......
703 664
    glutIdleFunc(display)
704 665
#   glutMouseFunc(mouse)
705 666
    glutSpecialFunc(special)
706
    Loop=glutKeyboardFunc(keyboard)
667
    glutKeyboardFunc(keyboard)
707 668
    glutMainLoop()
708 669
    
709
    print("\nWall Duration on %s for each %s\n" % (Device,(time.time()-wall_time_start)/Iterations))
670
    print("\nWall Duration on device %s for each iteration: %s\n" % (Device,(time.time()-wall_time_start)/Iterations))
710 671
    
711 672
    MyRoutines.CenterOfMass(queue,(1,1),None,clDataX,clCoM,np.int32(Number))
712 673
    CLLaunch=MyRoutines.Potential(queue,(Number,1),None,clDataX,clPotential)
......
718 679
    print('Center Of Mass: (%s,%s,%s)' % (MyCoM[0],MyCoM[1],MyCoM[2]))
719 680
    print('Viriel=%s Potential=%s Kinetic=%s'% (np.sum(MyPotential)+2.*np.sum(MyKinetic),np.sum(MyPotential),np.sum(MyKinetic)))
720 681
    
721
    if GraphSamples:    
722
        t0=np.transpose(np.reshape(t0,(Iterations+1,3)))
723
        t1=np.transpose(np.reshape(t1,(Iterations+1,3)))
724
        tL=np.transpose(np.reshape(tL,(Iterations+1,3)))
725
    
726
        import matplotlib.pyplot as plt
727
        from mpl_toolkits.mplot3d import Axes3D
728
    
729
        fig = plt.figure()
730
        ax = fig.gca(projection='3d')
731
        ax.scatter(t0[0],t0[1],t0[2], marker='^',color='blue')
732
        ax.scatter(t1[0],t1[1],t1[2], marker='o',color='red')
733
        ax.scatter(tL[0],tL[1],tL[2], marker='D',color='green')
734
   
735
        ax.set_xlabel('X Label')
736
        ax.set_ylabel('Y Label')
737
        ax.set_zlabel('Z Label')
738

  
739
        plt.show()
740
    
741 682
    clDataX.release()
742 683
    clDataV.release()
743 684
    clKinetic.release()

Formats disponibles : Unified diff