SlideShare une entreprise Scribd logo
1  sur  19
Minh họ a việ c kế t hợ p c ác
c ông c ụ mã nguồ n mở để tìm
   hiể u mộhtlong77@gmail.com v ậ t lý
            t bài toán



             Hà Nộ i, 15/09/2012
Dao Động Tử Điều Hòa Một Chiều
… và trong Cơ học lượng tử
                  2
ω=
  √k
   m
            H=
               P 1   2
                 + mω X
               2m 2
                        2
Trạng thái kích thích tổng quát
Fortran code : Hàm sóng bậc n ứng
              với trị x bất kỳ
    DOUBLE PRECISION FUNCTION ODHON(BETA,X,N)
    PARAMETER (NFMAX=100)
    COMMON/CONSTS/PIO4,PIO2,PI,SQRT2,SQRTN(NFMAX),SQRTNF(NFMAX)
    DOUBLE PRECISION PIO4,PIO2,PI,SQRT2,SQRTN,SQRTNF
    DOUBLE PRECISION BETA,X,BETAX
    DOUBLE PRECISION PHIN,PHINM1,PHINM2
    DOUBLE PRECISION ODHO0,ODHO1
    INTEGER I,N
C
    IF (N.EQ.0) THEN
      ODHON=ODHO0(BETA,X)
    ELSEIF (N.EQ.1) THEN
      ODHON=ODHO1(BETA,X)
    ELSE
      BETAX=BETA*X
      PHINM2=ODHO0(BETA,X)
      PHINM1=ODHO1(BETA,X)
      DO I=2,N
         PHIN=(PHINM1*BETAX*SQRT2-SQRTN(I-1)*PHINM2)/SQRTN(I)
         PHINM2 = PHINM1
         PHINM1 = PHIN
      ENDDO
      ODHON=PHIN
    ENDIF
C
    END
Tạo tệp thực thi với Makefile


     1
Makefile
objects = objs/initialization.o objs/debug.o objs/quadrature.o objs/odho.o objs/main.o
forcomp = gfortran
#forcomp = fort77

run/odho: $(objects)
    time $(forcomp) -o run/odho $(objects)

objs/initialization.o: initialization.f
    time $(forcomp) -c -O4 -o objs/initialization.o initialization.f

objs/debug.o: debug.f
    time $(forcomp) -c -O4 -o objs/debug.o debug.f

objs/quadrature.o: quadrature.f
    time $(forcomp) -c -O4 -o objs/quadrature.o quadrature.f

objs/odho.o: odho.f
    time $(forcomp) -c -O4 -o objs/odho.o odho.f

objs/main.o: main.f
    time $(forcomp) -c -O4 -o objs/main.o main.f

.PHONY: clean run
clean:
    rm -rf run/odho $(objects) *~

run:
       cd run;./odho < input
Chương trình chính, dữ liệu đầu vào
0
                      và kết quả
        #Print initialized values 0=No 1=Yes
20        #Order of the wave-function of Harmonical Oscillator
1        #beta = sqrt(m.omega/hbar) : harmonical oscillator parameter
-10 10        #the domain of the function
1000          #number of sample points of the function
20         #number of Gauss-Hermite sample points
C    ...
                                           -10.000000000000000   3.31402378637182642E-009
     OPEN(UNIT=20,FILE='data')             -9.9800000000000004   3.86975188178886400E-009
C                                          -9.9600000000000009
                                           -9.9400000000000013
                                                                 4.51634903048100019E-009
                                                                 5.26827539296001357E-009
     READ *,BETA                           -9.9200000000000017
                                           -9.9000000000000021
                                                                 6.14222537578560566E-009
                                                                 7.15746188556575456E-009
     READ *,XMIN,XMAX                      -9.8800000000000026   8.33619883446549584E-009
                                           -9.8600000000000030   9.70403858885294332E-009
     READ *,NSP                            -9.8400000000000034   1.12904719391459490E-008
                                           -9.8200000000000038   1.31294491666361272E-008
     READ *,NGH                            -9.8000000000000043   1.52600319051601025E-008
     WRITE(21,100) BETA,NGH                -9.7800000000000047
                                           -9.7600000000000051
                                                                 1.77271367564591956E-008
                                                                 2.05823830339850479E-008
     CALL ROOTHE(HERRTS,NGH)               -9.7400000000000055
                                           -9.7200000000000060
                                                                 2.38850585985262592E-008
                                                                 2.77032195299829601E-008
     WRITE(21,105) (I,HERRTS(I),I=1,NGH)   -9.7000000000000064   3.21149413745403316E-008
                                           -9.6800000000000068   3.72097419392771055E-008
     DX=(XMAX-XMIN)/DBLE(NSP)              -9.6600000000000072   4.30901981031658081E-008
                                           ...
     X=XMIN
     DO I=0,NSP
       WRITE (20,*) X,ODHON(BETA,X,N)
       X=X+DX
     ENDDO
C    ...
Gnuplot để hiển thị kết quả
Python : tăng hiệu suất công việc
#!/usr/bin/env python
import sys,os
#using the executable file in "run" directory       Ra lệnh cho hệ thống
dir='run';os.chdir(dir)                            thực hiện chương trình
cmd = './odho < input'
#Data preparation
#default values of input parameters
print_init_values = 0
order_wave_function = 20
beta = 1.0                                       Chạy chương trình với các
xmin = -10                                           thông số mặc định
xmax = 10
nsp = 1000
ngh = 20
#Read variables from the command line, one by one:
...
failure = os.system(cmd)
if failure:
    print 'running the code failed'; sys.exit(1)
Python : Thay đổi tham số trực tiếp
...          trên dòng lệnh
#Read variables from the command line, one by one:
while len(sys.argv)>1:
    option=sys.argv[1];         del sys.argv[1]
    if option == '--print-init-values':
        print_init_values=int(sys.argv[1]);    del sys.argv[1]
    elif option == '--order-wave-function':
        order_wave_function =int(sys.argv[1]);    del sys.argv[1]
    elif option == '--beta':
        beta =float(sys.argv[1]);    del sys.argv[1]
    elif option == '--xmin':
        xmin =float(sys.argv[1]);    del sys.argv[1]
    elif option == '--xmax':
        xmax =float(sys.argv[1]);    del sys.argv[1]
    elif option == '--number-sample-points':
        nsp =int(sys.argv[1]);    del sys.argv[1]
    elif option == '--number-gh-sample-points':
        ngh =int(sys.argv[1]);    del sys.argv[1]
    else:
        print sys.argv[0],': invalid option',option
        sys.exit(1)
#Make input file to the program
...
Vai trò của tham số beta
Python : Tạo dữ liệu đầu vào
...
#Make input file to the program
f = open('input','w')
f.write("""%(print_init_values)g           #Print initialized values 0=No 1=Yes
%(order_wave_function)g         #Order of the wave-function of Harmonical Oscillator
%(beta)g         #beta = sqrt(m.omega/hbar) : harmonical oscillator parameter
%(xmin)g %(xmax)g         #the domain of the function
%(nsp)g           #number of sample points of the function
%(ngh)g          #number of Gauss-Hermite sample points
""" % vars() )
f.close()
...


     0           #Print initialized values 0=No 1=Yes
     2         #Order of the wave-function of Harmonical Oscillator
     0.4         #beta = sqrt(m.omega/hbar) : harmonical oscillator parameter
     -10 10         #the domain of the function
     1000           #number of sample points of the function
     20          #number of Gauss-Hermite sample points
Python : Hiển thị bằng hình ảnh
...
               kết quả tính toán
# make file with gnuplot commands:
gnuplotfile='phi_%i__beta_%g.gnuplot' % (order_wave_function,beta)
f = open(gnuplotfile,'w')
f.write("""reset                   Tạo tệp chứa lệnh vẽ cho gnuplot : phương pháp truyền thống
#
set title "Harmonical Oscillator Wave Function of order %(order_wave_function)g, beta=%(beta)g"
set xlabel "x(fm)"
set ylabel "fm^{-1/2}"
#
set xrange [%(xmin)g:%(xmax)g]
# Line width of the axes
set border linewidth 1.5
# Line styles
set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 2
set style line 2 linecolor rgb '#dd181f' linetype 1 linewidth 2
# make a plot in PNG format:
set term png small                                                          Tạo hình vẽ với đuôi .png
set output 'phi_%(order_wave_function)i__beta_%(beta)g.png';
plot "data" with lines linestyle 2 notitle
# define the postscript output format:                        Tích hợp thông tin tham số sử dụng
set term postscript enhanced 'Times-Roman' 20;                              vào tên tệp
set output 'phi_%(order_wave_function)i__beta_%(beta)g.ps';
set title "Harmonical Oscillator Wave Function of order %(order_wave_function)g, {/Symbol b}=%(beta)g"
plot "data" with lines linestyle 2 notitle
""" % vars() )
f.close()
# make plot
cmd = 'gnuplot -persist '+gnuplotfile
failure = os.system(cmd)
if failure:
    print 'running gnuplot failed'; sys.exit(1)
...
Trạng thái kích thích bậc 100
Cải tiến
●
    Chuyển dữ liệu đầu vào và đầu ra của một
    tính '../odho vào cùng một thư mục
    cmd =
          toán < input'
    ...
    caldir='tmp'
    ...
        elif option == '--calcul-directory':
            caldir =sys.argv[1];        del sys.argv[1]
    ...
    import shutil
    if os.path.isdir(caldir): #does caldir exist
        shutil.rmtree(caldir) # yes, remove old directory
    os.mkdir(caldir)          #make caldir directory
    os.chdir(caldir)          #move to dir
    ...
Tính toàn bộ các trạng thái kích
               thích từ 0 tới 100
#!/usr/bin/env python
import sys,os

for n in range(0,100):
    cmd = "./odho_improved.py --beta 1.5 --order-wave-function %g
 --number-sample-points 1000 --calcul-directory beta1.5n%g" %(n,n)
    failure = os.system(cmd)
    if failure:
        print 'running gnuplot failed'; sys.exit(1)
Còn gì nữa
Thank you for your atte ntion!!!

Contenu connexe

Tendances

Cacbuocthuchien
CacbuocthuchienCacbuocthuchien
CacbuocthuchienHung Vt
 
Hướng dẫn làm bt về chuỗi.doc
Hướng dẫn làm bt về chuỗi.docHướng dẫn làm bt về chuỗi.doc
Hướng dẫn làm bt về chuỗi.docTrần Văn Nam
 
Local sakainame 501127 ktl_trình hlmt1 a01 fall 2013 _ modules
Local sakainame   501127 ktl_trình hlmt1 a01 fall 2013 _ modulesLocal sakainame   501127 ktl_trình hlmt1 a01 fall 2013 _ modules
Local sakainame 501127 ktl_trình hlmt1 a01 fall 2013 _ modulesTrần Văn Nam
 
Nmlt c15 ham_nangcao_phan1_in
Nmlt c15 ham_nangcao_phan1_inNmlt c15 ham_nangcao_phan1_in
Nmlt c15 ham_nangcao_phan1_inHuy Nguyễn
 
đáP án 24 đề tin
đáP án 24 đề tinđáP án 24 đề tin
đáP án 24 đề tinTtx Love
 
Lap trinh c++ có lời giải 3
Lap trinh c++ có lời giải 3Lap trinh c++ có lời giải 3
Lap trinh c++ có lời giải 3Minh Ngoc Tran
 
Lập trình c++ có lời giải 2
Lập trình c++ có lời giải 2Lập trình c++ có lời giải 2
Lập trình c++ có lời giải 2Minh Ngoc Tran
 

Tendances (17)

C đến C++ phần 1
C đến C++ phần 1C đến C++ phần 1
C đến C++ phần 1
 
Neural Network from Scratch
Neural Network from ScratchNeural Network from Scratch
Neural Network from Scratch
 
Cacbuocthuchien
CacbuocthuchienCacbuocthuchien
Cacbuocthuchien
 
Hướng dẫn làm bt về chuỗi.doc
Hướng dẫn làm bt về chuỗi.docHướng dẫn làm bt về chuỗi.doc
Hướng dẫn làm bt về chuỗi.doc
 
Tn ktlt
Tn ktltTn ktlt
Tn ktlt
 
Chuong1 c
Chuong1 c Chuong1 c
Chuong1 c
 
Nmlt c05 cau_lenhlap
Nmlt c05 cau_lenhlapNmlt c05 cau_lenhlap
Nmlt c05 cau_lenhlap
 
Pointer
PointerPointer
Pointer
 
Local sakainame 501127 ktl_trình hlmt1 a01 fall 2013 _ modules
Local sakainame   501127 ktl_trình hlmt1 a01 fall 2013 _ modulesLocal sakainame   501127 ktl_trình hlmt1 a01 fall 2013 _ modules
Local sakainame 501127 ktl_trình hlmt1 a01 fall 2013 _ modules
 
Nmlt c15 ham_nangcao_phan1_in
Nmlt c15 ham_nangcao_phan1_inNmlt c15 ham_nangcao_phan1_in
Nmlt c15 ham_nangcao_phan1_in
 
Lesson08
Lesson08Lesson08
Lesson08
 
đáP án 24 đề tin
đáP án 24 đề tinđáP án 24 đề tin
đáP án 24 đề tin
 
Lap trinh c++ có lời giải 3
Lap trinh c++ có lời giải 3Lap trinh c++ có lời giải 3
Lap trinh c++ có lời giải 3
 
Giáo trình MSWLOGO Lớp 5
Giáo trình MSWLOGO Lớp 5Giáo trình MSWLOGO Lớp 5
Giáo trình MSWLOGO Lớp 5
 
Lập trình c++ có lời giải 2
Lập trình c++ có lời giải 2Lập trình c++ có lời giải 2
Lập trình c++ có lời giải 2
 
Ctdl lab01
Ctdl lab01Ctdl lab01
Ctdl lab01
 
Stack &amp; queue
Stack &amp; queueStack &amp; queue
Stack &amp; queue
 

En vedette

Sfd hanoi2012 nguyen the hung vinades - phat trien pmnm tai vn - kinh nghie...
Sfd hanoi2012 nguyen the hung   vinades - phat trien pmnm tai vn - kinh nghie...Sfd hanoi2012 nguyen the hung   vinades - phat trien pmnm tai vn - kinh nghie...
Sfd hanoi2012 nguyen the hung vinades - phat trien pmnm tai vn - kinh nghie...Vu Hung Nguyen
 
Sfd hanoi2012 nguyen nang thang sfd-2012_chroot_apache
Sfd hanoi2012 nguyen nang thang   sfd-2012_chroot_apacheSfd hanoi2012 nguyen nang thang   sfd-2012_chroot_apache
Sfd hanoi2012 nguyen nang thang sfd-2012_chroot_apacheVu Hung Nguyen
 
Information Management with Redmine
Information Management with RedmineInformation Management with Redmine
Information Management with RedmineVu Hung Nguyen
 
Ghi nhận về OpenStack - Nguyễn Hoàng
Ghi nhận về OpenStack - Nguyễn HoàngGhi nhận về OpenStack - Nguyễn Hoàng
Ghi nhận về OpenStack - Nguyễn HoàngVu Hung Nguyen
 
Jong Won Koh - HP apollo reinventing HPC to accelerate the world of tomorrow
Jong Won Koh - HP apollo reinventing HPC to accelerate the world of tomorrowJong Won Koh - HP apollo reinventing HPC to accelerate the world of tomorrow
Jong Won Koh - HP apollo reinventing HPC to accelerate the world of tomorrowVu Hung Nguyen
 
Introduction to Microsoft Office
Introduction to Microsoft OfficeIntroduction to Microsoft Office
Introduction to Microsoft OfficeTHickox
 
Fpt's human resource strategies in 2009 (a look back)
Fpt's human resource strategies in 2009 (a look back)Fpt's human resource strategies in 2009 (a look back)
Fpt's human resource strategies in 2009 (a look back)Vu Hung Nguyen
 
Nguyen Vu Hung: Beyond Agile - Practices and Mindset - Agile Tour Vietnam (Ha...
Nguyen Vu Hung: Beyond Agile - Practices and Mindset - Agile Tour Vietnam (Ha...Nguyen Vu Hung: Beyond Agile - Practices and Mindset - Agile Tour Vietnam (Ha...
Nguyen Vu Hung: Beyond Agile - Practices and Mindset - Agile Tour Vietnam (Ha...Vu Hung Nguyen
 
Thói ngụy biện ở người Việt
Thói ngụy biện ở người ViệtThói ngụy biện ở người Việt
Thói ngụy biện ở người ViệtVu Hung Nguyen
 
Vietlug: Thay doi the gioi bang foss va bitcoin - le xuan thao
Vietlug: Thay doi the gioi bang foss va bitcoin - le xuan thaoVietlug: Thay doi the gioi bang foss va bitcoin - le xuan thao
Vietlug: Thay doi the gioi bang foss va bitcoin - le xuan thaoVu Hung Nguyen
 
Lourenço Mutarelli e A Hora Errada
Lourenço Mutarelli e A Hora ErradaLourenço Mutarelli e A Hora Errada
Lourenço Mutarelli e A Hora ErradaTom Souza
 
Maite marzana hardwareak eta monitoreak
Maite marzana hardwareak eta monitoreakMaite marzana hardwareak eta monitoreak
Maite marzana hardwareak eta monitoreakmaitemay
 
Espiritismo para crianças
Espiritismo para criançasEspiritismo para crianças
Espiritismo para criançasanaccc2013
 
Kafer dan daftar izi
Kafer dan daftar iziKafer dan daftar izi
Kafer dan daftar iziUiyo Marieno
 
Revista espírita 1867
Revista espírita   1867Revista espírita   1867
Revista espírita 1867anaccc2013
 
Madewithlove
MadewithloveMadewithlove
MadewithlovePierinavr
 
LA AMISTAD
LA AMISTADLA AMISTAD
LA AMISTADErika
 

En vedette (20)

Sfd hanoi2012 nguyen the hung vinades - phat trien pmnm tai vn - kinh nghie...
Sfd hanoi2012 nguyen the hung   vinades - phat trien pmnm tai vn - kinh nghie...Sfd hanoi2012 nguyen the hung   vinades - phat trien pmnm tai vn - kinh nghie...
Sfd hanoi2012 nguyen the hung vinades - phat trien pmnm tai vn - kinh nghie...
 
Sfd hanoi2012 nguyen nang thang sfd-2012_chroot_apache
Sfd hanoi2012 nguyen nang thang   sfd-2012_chroot_apacheSfd hanoi2012 nguyen nang thang   sfd-2012_chroot_apache
Sfd hanoi2012 nguyen nang thang sfd-2012_chroot_apache
 
Information Management with Redmine
Information Management with RedmineInformation Management with Redmine
Information Management with Redmine
 
Ghi nhận về OpenStack - Nguyễn Hoàng
Ghi nhận về OpenStack - Nguyễn HoàngGhi nhận về OpenStack - Nguyễn Hoàng
Ghi nhận về OpenStack - Nguyễn Hoàng
 
Jong Won Koh - HP apollo reinventing HPC to accelerate the world of tomorrow
Jong Won Koh - HP apollo reinventing HPC to accelerate the world of tomorrowJong Won Koh - HP apollo reinventing HPC to accelerate the world of tomorrow
Jong Won Koh - HP apollo reinventing HPC to accelerate the world of tomorrow
 
Introduction to Microsoft Office
Introduction to Microsoft OfficeIntroduction to Microsoft Office
Introduction to Microsoft Office
 
Fpt's human resource strategies in 2009 (a look back)
Fpt's human resource strategies in 2009 (a look back)Fpt's human resource strategies in 2009 (a look back)
Fpt's human resource strategies in 2009 (a look back)
 
Nguyen Vu Hung: Beyond Agile - Practices and Mindset - Agile Tour Vietnam (Ha...
Nguyen Vu Hung: Beyond Agile - Practices and Mindset - Agile Tour Vietnam (Ha...Nguyen Vu Hung: Beyond Agile - Practices and Mindset - Agile Tour Vietnam (Ha...
Nguyen Vu Hung: Beyond Agile - Practices and Mindset - Agile Tour Vietnam (Ha...
 
Thói ngụy biện ở người Việt
Thói ngụy biện ở người ViệtThói ngụy biện ở người Việt
Thói ngụy biện ở người Việt
 
Vietlug: Thay doi the gioi bang foss va bitcoin - le xuan thao
Vietlug: Thay doi the gioi bang foss va bitcoin - le xuan thaoVietlug: Thay doi the gioi bang foss va bitcoin - le xuan thao
Vietlug: Thay doi the gioi bang foss va bitcoin - le xuan thao
 
Mhst12 04
Mhst12 04Mhst12 04
Mhst12 04
 
Lourenço Mutarelli e A Hora Errada
Lourenço Mutarelli e A Hora ErradaLourenço Mutarelli e A Hora Errada
Lourenço Mutarelli e A Hora Errada
 
Maite marzana hardwareak eta monitoreak
Maite marzana hardwareak eta monitoreakMaite marzana hardwareak eta monitoreak
Maite marzana hardwareak eta monitoreak
 
Espiritismo para crianças
Espiritismo para criançasEspiritismo para crianças
Espiritismo para crianças
 
Propuesta de Solucion
Propuesta de SolucionPropuesta de Solucion
Propuesta de Solucion
 
Red de computadora
Red de computadoraRed de computadora
Red de computadora
 
Kafer dan daftar izi
Kafer dan daftar iziKafer dan daftar izi
Kafer dan daftar izi
 
Revista espírita 1867
Revista espírita   1867Revista espírita   1867
Revista espírita 1867
 
Madewithlove
MadewithloveMadewithlove
Madewithlove
 
LA AMISTAD
LA AMISTADLA AMISTAD
LA AMISTAD
 

Similaire à Sfd2012Hanoi - Hà Thụy Long - Odho: Mã nguồn mở và các bài toán vật lý

Bài tập mẫu C và C++ có giải
Bài tập mẫu C và C++ có giảiBài tập mẫu C và C++ có giải
Bài tập mẫu C và C++ có giảiTrung Thanh Nguyen
 
Bài tập ôn lập trình
Bài tập ôn lập trìnhBài tập ôn lập trình
Bài tập ôn lập trìnhThai Hoc Vu
 
Giao trinh bai tap c va c++
Giao trinh bai tap c va c++Giao trinh bai tap c va c++
Giao trinh bai tap c va c++Congdat Le
 
C10 generic algorithms
C10 generic algorithmsC10 generic algorithms
C10 generic algorithmsHồ Lợi
 
Lap trinh c++ có lời giải 1
Lap trinh c++ có lời giải 1Lap trinh c++ có lời giải 1
Lap trinh c++ có lời giải 1Minh Ngoc Tran
 
Slide Python Bai 2 pythonvietnam.info
Slide Python Bai 2   pythonvietnam.infoSlide Python Bai 2   pythonvietnam.info
Slide Python Bai 2 pythonvietnam.infoKhánh Nguyễn
 
Chapter04_Array_chinhsua
Chapter04_Array_chinhsuaChapter04_Array_chinhsua
Chapter04_Array_chinhsuaThnhNguynHong5
 
Cac ham va thu tuc trong pascal
Cac ham va thu tuc trong pascalCac ham va thu tuc trong pascal
Cac ham va thu tuc trong pascalVõ Tâm Long
 
Đo khoảng cách bằng MSP430 Launchpad
Đo khoảng cách bằng MSP430 LaunchpadĐo khoảng cách bằng MSP430 Launchpad
Đo khoảng cách bằng MSP430 LaunchpadFPT Telecom
 
Đo khoảng cách bằng kit launchpad + srf05
Đo khoảng cách bằng kit launchpad + srf05Đo khoảng cách bằng kit launchpad + srf05
Đo khoảng cách bằng kit launchpad + srf05locbachkhoa
 
Lec3. Ham.pdf
Lec3. Ham.pdfLec3. Ham.pdf
Lec3. Ham.pdfKinHongnh
 
Nmlt C06 Ham
Nmlt C06 HamNmlt C06 Ham
Nmlt C06 HamCuong
 
Lap trinh huong_doi_tuong_cpp_dhct_lesson07
Lap trinh huong_doi_tuong_cpp_dhct_lesson07Lap trinh huong_doi_tuong_cpp_dhct_lesson07
Lap trinh huong_doi_tuong_cpp_dhct_lesson07xcode_esvn
 
Session 4
Session 4Session 4
Session 4pnanhvn
 
Sang tao4
Sang tao4Sang tao4
Sang tao4hieusui
 

Similaire à Sfd2012Hanoi - Hà Thụy Long - Odho: Mã nguồn mở và các bài toán vật lý (20)

Bài tập mẫu C và C++ có giải
Bài tập mẫu C và C++ có giảiBài tập mẫu C và C++ có giải
Bài tập mẫu C và C++ có giải
 
Bài tập ôn lập trình
Bài tập ôn lập trìnhBài tập ôn lập trình
Bài tập ôn lập trình
 
Giao trinh bai tap c va c++
Giao trinh bai tap c va c++Giao trinh bai tap c va c++
Giao trinh bai tap c va c++
 
Giao trinh bai tap c va c++
Giao trinh bai tap c va c++Giao trinh bai tap c va c++
Giao trinh bai tap c va c++
 
C10 generic algorithms
C10 generic algorithmsC10 generic algorithms
C10 generic algorithms
 
Lap trinh c++ có lời giải 1
Lap trinh c++ có lời giải 1Lap trinh c++ có lời giải 1
Lap trinh c++ có lời giải 1
 
Slide Python Bai 2 pythonvietnam.info
Slide Python Bai 2   pythonvietnam.infoSlide Python Bai 2   pythonvietnam.info
Slide Python Bai 2 pythonvietnam.info
 
Chapter04_Array_chinhsua
Chapter04_Array_chinhsuaChapter04_Array_chinhsua
Chapter04_Array_chinhsua
 
Báo cáo môn học phương pháp phần tử hữu hạn
Báo cáo môn học phương pháp phần tử hữu hạnBáo cáo môn học phương pháp phần tử hữu hạn
Báo cáo môn học phương pháp phần tử hữu hạn
 
Bai de quy
Bai de quyBai de quy
Bai de quy
 
Cac ham va thu tuc trong pascal
Cac ham va thu tuc trong pascalCac ham va thu tuc trong pascal
Cac ham va thu tuc trong pascal
 
Đo khoảng cách bằng MSP430 Launchpad
Đo khoảng cách bằng MSP430 LaunchpadĐo khoảng cách bằng MSP430 Launchpad
Đo khoảng cách bằng MSP430 Launchpad
 
Đo khoảng cách bằng kit launchpad + srf05
Đo khoảng cách bằng kit launchpad + srf05Đo khoảng cách bằng kit launchpad + srf05
Đo khoảng cách bằng kit launchpad + srf05
 
Bai tap java
Bai tap javaBai tap java
Bai tap java
 
Lec3. Ham.pdf
Lec3. Ham.pdfLec3. Ham.pdf
Lec3. Ham.pdf
 
Nmlt C06 Ham
Nmlt C06 HamNmlt C06 Ham
Nmlt C06 Ham
 
Lap trinh huong_doi_tuong_cpp_dhct_lesson07
Lap trinh huong_doi_tuong_cpp_dhct_lesson07Lap trinh huong_doi_tuong_cpp_dhct_lesson07
Lap trinh huong_doi_tuong_cpp_dhct_lesson07
 
Session 4
Session 4Session 4
Session 4
 
Sang tao4
Sang tao4Sang tao4
Sang tao4
 
Chuyen doi he so
Chuyen doi he soChuyen doi he so
Chuyen doi he so
 

Plus de Vu Hung Nguyen

Co ban horenso - Tai lieu training noi bo
Co ban horenso - Tai lieu training noi boCo ban horenso - Tai lieu training noi bo
Co ban horenso - Tai lieu training noi boVu Hung Nguyen
 
Funix techtalk: Tự học hiệu quả thời 4.0
Funix techtalk: Tự học hiệu quả thời 4.0Funix techtalk: Tự học hiệu quả thời 4.0
Funix techtalk: Tự học hiệu quả thời 4.0Vu Hung Nguyen
 
Học cờ cùng con - Nguyễn Vỹ Kỳ Anh [U8]
Học cờ cùng con - Nguyễn Vỹ Kỳ Anh [U8]Học cờ cùng con - Nguyễn Vỹ Kỳ Anh [U8]
Học cờ cùng con - Nguyễn Vỹ Kỳ Anh [U8]Vu Hung Nguyen
 
Japanese for it bridge engineers
Japanese for it bridge engineersJapanese for it bridge engineers
Japanese for it bridge engineersVu Hung Nguyen
 
Basic IT Project Management Terminologies
Basic IT Project Management TerminologiesBasic IT Project Management Terminologies
Basic IT Project Management TerminologiesVu Hung Nguyen
 
2018 Học cờ cùng con - Nguyễn Vũ Kỳ Anh [U7]
2018 Học cờ cùng con - Nguyễn Vũ Kỳ Anh [U7]2018 Học cờ cùng con - Nguyễn Vũ Kỳ Anh [U7]
2018 Học cờ cùng con - Nguyễn Vũ Kỳ Anh [U7]Vu Hung Nguyen
 
Làm việc hiệu quả với sếp Nhật (2017)
Làm việc hiệu quả với sếp Nhật (2017)Làm việc hiệu quả với sếp Nhật (2017)
Làm việc hiệu quả với sếp Nhật (2017)Vu Hung Nguyen
 
Problem Solving Skills (for IT Engineers)
Problem Solving Skills (for IT Engineers)Problem Solving Skills (for IT Engineers)
Problem Solving Skills (for IT Engineers)Vu Hung Nguyen
 
Using Shader in cocos2d-x
Using Shader in cocos2d-xUsing Shader in cocos2d-x
Using Shader in cocos2d-xVu Hung Nguyen
 
Pham Anh Tu - TK Framework
Pham Anh Tu - TK FrameworkPham Anh Tu - TK Framework
Pham Anh Tu - TK FrameworkVu Hung Nguyen
 
My idol: Magnus Carlsen vs. Ky Anh 2G1 NGS Newton
My idol: Magnus Carlsen vs. Ky Anh 2G1 NGS NewtonMy idol: Magnus Carlsen vs. Ky Anh 2G1 NGS Newton
My idol: Magnus Carlsen vs. Ky Anh 2G1 NGS NewtonVu Hung Nguyen
 
Basic advanced scrum framework
Basic advanced scrum frameworkBasic advanced scrum framework
Basic advanced scrum frameworkVu Hung Nguyen
 
FPT Univ. Talkshow IT khong chi la lap trinh
FPT Univ. Talkshow IT khong chi la lap trinhFPT Univ. Talkshow IT khong chi la lap trinh
FPT Univ. Talkshow IT khong chi la lap trinhVu Hung Nguyen
 
Basic & Advanced Scrum Framework
Basic & Advanced Scrum FrameworkBasic & Advanced Scrum Framework
Basic & Advanced Scrum FrameworkVu Hung Nguyen
 
Agile Vietnam Conference 2016: Recap
Agile Vietnam Conference 2016: RecapAgile Vietnam Conference 2016: Recap
Agile Vietnam Conference 2016: RecapVu Hung Nguyen
 
IT Public Speaking Guidelines
IT Public Speaking GuidelinesIT Public Speaking Guidelines
IT Public Speaking GuidelinesVu Hung Nguyen
 
Kanban: Cơ bản và Nâng cao
Kanban: Cơ bản và Nâng caoKanban: Cơ bản và Nâng cao
Kanban: Cơ bản và Nâng caoVu Hung Nguyen
 
Học cờ vua cùng con Nguyễn Vũ Kỳ Anh (U6)
Học cờ vua cùng con Nguyễn Vũ Kỳ Anh (U6)Học cờ vua cùng con Nguyễn Vũ Kỳ Anh (U6)
Học cờ vua cùng con Nguyễn Vũ Kỳ Anh (U6)Vu Hung Nguyen
 
Fuji Technology Workshop: Learning Skills
Fuji Technology Workshop: Learning SkillsFuji Technology Workshop: Learning Skills
Fuji Technology Workshop: Learning SkillsVu Hung Nguyen
 
Anti patterns in it project management
Anti patterns in it project managementAnti patterns in it project management
Anti patterns in it project managementVu Hung Nguyen
 

Plus de Vu Hung Nguyen (20)

Co ban horenso - Tai lieu training noi bo
Co ban horenso - Tai lieu training noi boCo ban horenso - Tai lieu training noi bo
Co ban horenso - Tai lieu training noi bo
 
Funix techtalk: Tự học hiệu quả thời 4.0
Funix techtalk: Tự học hiệu quả thời 4.0Funix techtalk: Tự học hiệu quả thời 4.0
Funix techtalk: Tự học hiệu quả thời 4.0
 
Học cờ cùng con - Nguyễn Vỹ Kỳ Anh [U8]
Học cờ cùng con - Nguyễn Vỹ Kỳ Anh [U8]Học cờ cùng con - Nguyễn Vỹ Kỳ Anh [U8]
Học cờ cùng con - Nguyễn Vỹ Kỳ Anh [U8]
 
Japanese for it bridge engineers
Japanese for it bridge engineersJapanese for it bridge engineers
Japanese for it bridge engineers
 
Basic IT Project Management Terminologies
Basic IT Project Management TerminologiesBasic IT Project Management Terminologies
Basic IT Project Management Terminologies
 
2018 Học cờ cùng con - Nguyễn Vũ Kỳ Anh [U7]
2018 Học cờ cùng con - Nguyễn Vũ Kỳ Anh [U7]2018 Học cờ cùng con - Nguyễn Vũ Kỳ Anh [U7]
2018 Học cờ cùng con - Nguyễn Vũ Kỳ Anh [U7]
 
Làm việc hiệu quả với sếp Nhật (2017)
Làm việc hiệu quả với sếp Nhật (2017)Làm việc hiệu quả với sếp Nhật (2017)
Làm việc hiệu quả với sếp Nhật (2017)
 
Problem Solving Skills (for IT Engineers)
Problem Solving Skills (for IT Engineers)Problem Solving Skills (for IT Engineers)
Problem Solving Skills (for IT Engineers)
 
Using Shader in cocos2d-x
Using Shader in cocos2d-xUsing Shader in cocos2d-x
Using Shader in cocos2d-x
 
Pham Anh Tu - TK Framework
Pham Anh Tu - TK FrameworkPham Anh Tu - TK Framework
Pham Anh Tu - TK Framework
 
My idol: Magnus Carlsen vs. Ky Anh 2G1 NGS Newton
My idol: Magnus Carlsen vs. Ky Anh 2G1 NGS NewtonMy idol: Magnus Carlsen vs. Ky Anh 2G1 NGS Newton
My idol: Magnus Carlsen vs. Ky Anh 2G1 NGS Newton
 
Basic advanced scrum framework
Basic advanced scrum frameworkBasic advanced scrum framework
Basic advanced scrum framework
 
FPT Univ. Talkshow IT khong chi la lap trinh
FPT Univ. Talkshow IT khong chi la lap trinhFPT Univ. Talkshow IT khong chi la lap trinh
FPT Univ. Talkshow IT khong chi la lap trinh
 
Basic & Advanced Scrum Framework
Basic & Advanced Scrum FrameworkBasic & Advanced Scrum Framework
Basic & Advanced Scrum Framework
 
Agile Vietnam Conference 2016: Recap
Agile Vietnam Conference 2016: RecapAgile Vietnam Conference 2016: Recap
Agile Vietnam Conference 2016: Recap
 
IT Public Speaking Guidelines
IT Public Speaking GuidelinesIT Public Speaking Guidelines
IT Public Speaking Guidelines
 
Kanban: Cơ bản và Nâng cao
Kanban: Cơ bản và Nâng caoKanban: Cơ bản và Nâng cao
Kanban: Cơ bản và Nâng cao
 
Học cờ vua cùng con Nguyễn Vũ Kỳ Anh (U6)
Học cờ vua cùng con Nguyễn Vũ Kỳ Anh (U6)Học cờ vua cùng con Nguyễn Vũ Kỳ Anh (U6)
Học cờ vua cùng con Nguyễn Vũ Kỳ Anh (U6)
 
Fuji Technology Workshop: Learning Skills
Fuji Technology Workshop: Learning SkillsFuji Technology Workshop: Learning Skills
Fuji Technology Workshop: Learning Skills
 
Anti patterns in it project management
Anti patterns in it project managementAnti patterns in it project management
Anti patterns in it project management
 

Sfd2012Hanoi - Hà Thụy Long - Odho: Mã nguồn mở và các bài toán vật lý

  • 1. Minh họ a việ c kế t hợ p c ác c ông c ụ mã nguồ n mở để tìm hiể u mộhtlong77@gmail.com v ậ t lý t bài toán Hà Nộ i, 15/09/2012
  • 2. Dao Động Tử Điều Hòa Một Chiều
  • 3. … và trong Cơ học lượng tử 2 ω= √k m H= P 1 2 + mω X 2m 2 2
  • 4. Trạng thái kích thích tổng quát
  • 5. Fortran code : Hàm sóng bậc n ứng với trị x bất kỳ DOUBLE PRECISION FUNCTION ODHON(BETA,X,N) PARAMETER (NFMAX=100) COMMON/CONSTS/PIO4,PIO2,PI,SQRT2,SQRTN(NFMAX),SQRTNF(NFMAX) DOUBLE PRECISION PIO4,PIO2,PI,SQRT2,SQRTN,SQRTNF DOUBLE PRECISION BETA,X,BETAX DOUBLE PRECISION PHIN,PHINM1,PHINM2 DOUBLE PRECISION ODHO0,ODHO1 INTEGER I,N C IF (N.EQ.0) THEN ODHON=ODHO0(BETA,X) ELSEIF (N.EQ.1) THEN ODHON=ODHO1(BETA,X) ELSE BETAX=BETA*X PHINM2=ODHO0(BETA,X) PHINM1=ODHO1(BETA,X) DO I=2,N PHIN=(PHINM1*BETAX*SQRT2-SQRTN(I-1)*PHINM2)/SQRTN(I) PHINM2 = PHINM1 PHINM1 = PHIN ENDDO ODHON=PHIN ENDIF C END
  • 6. Tạo tệp thực thi với Makefile 1
  • 7. Makefile objects = objs/initialization.o objs/debug.o objs/quadrature.o objs/odho.o objs/main.o forcomp = gfortran #forcomp = fort77 run/odho: $(objects) time $(forcomp) -o run/odho $(objects) objs/initialization.o: initialization.f time $(forcomp) -c -O4 -o objs/initialization.o initialization.f objs/debug.o: debug.f time $(forcomp) -c -O4 -o objs/debug.o debug.f objs/quadrature.o: quadrature.f time $(forcomp) -c -O4 -o objs/quadrature.o quadrature.f objs/odho.o: odho.f time $(forcomp) -c -O4 -o objs/odho.o odho.f objs/main.o: main.f time $(forcomp) -c -O4 -o objs/main.o main.f .PHONY: clean run clean: rm -rf run/odho $(objects) *~ run: cd run;./odho < input
  • 8. Chương trình chính, dữ liệu đầu vào 0 và kết quả #Print initialized values 0=No 1=Yes 20 #Order of the wave-function of Harmonical Oscillator 1 #beta = sqrt(m.omega/hbar) : harmonical oscillator parameter -10 10 #the domain of the function 1000 #number of sample points of the function 20 #number of Gauss-Hermite sample points C ... -10.000000000000000 3.31402378637182642E-009 OPEN(UNIT=20,FILE='data') -9.9800000000000004 3.86975188178886400E-009 C -9.9600000000000009 -9.9400000000000013 4.51634903048100019E-009 5.26827539296001357E-009 READ *,BETA -9.9200000000000017 -9.9000000000000021 6.14222537578560566E-009 7.15746188556575456E-009 READ *,XMIN,XMAX -9.8800000000000026 8.33619883446549584E-009 -9.8600000000000030 9.70403858885294332E-009 READ *,NSP -9.8400000000000034 1.12904719391459490E-008 -9.8200000000000038 1.31294491666361272E-008 READ *,NGH -9.8000000000000043 1.52600319051601025E-008 WRITE(21,100) BETA,NGH -9.7800000000000047 -9.7600000000000051 1.77271367564591956E-008 2.05823830339850479E-008 CALL ROOTHE(HERRTS,NGH) -9.7400000000000055 -9.7200000000000060 2.38850585985262592E-008 2.77032195299829601E-008 WRITE(21,105) (I,HERRTS(I),I=1,NGH) -9.7000000000000064 3.21149413745403316E-008 -9.6800000000000068 3.72097419392771055E-008 DX=(XMAX-XMIN)/DBLE(NSP) -9.6600000000000072 4.30901981031658081E-008 ... X=XMIN DO I=0,NSP WRITE (20,*) X,ODHON(BETA,X,N) X=X+DX ENDDO C ...
  • 9. Gnuplot để hiển thị kết quả
  • 10. Python : tăng hiệu suất công việc #!/usr/bin/env python import sys,os #using the executable file in "run" directory Ra lệnh cho hệ thống dir='run';os.chdir(dir) thực hiện chương trình cmd = './odho < input' #Data preparation #default values of input parameters print_init_values = 0 order_wave_function = 20 beta = 1.0 Chạy chương trình với các xmin = -10 thông số mặc định xmax = 10 nsp = 1000 ngh = 20 #Read variables from the command line, one by one: ... failure = os.system(cmd) if failure: print 'running the code failed'; sys.exit(1)
  • 11. Python : Thay đổi tham số trực tiếp ... trên dòng lệnh #Read variables from the command line, one by one: while len(sys.argv)>1: option=sys.argv[1]; del sys.argv[1] if option == '--print-init-values': print_init_values=int(sys.argv[1]); del sys.argv[1] elif option == '--order-wave-function': order_wave_function =int(sys.argv[1]); del sys.argv[1] elif option == '--beta': beta =float(sys.argv[1]); del sys.argv[1] elif option == '--xmin': xmin =float(sys.argv[1]); del sys.argv[1] elif option == '--xmax': xmax =float(sys.argv[1]); del sys.argv[1] elif option == '--number-sample-points': nsp =int(sys.argv[1]); del sys.argv[1] elif option == '--number-gh-sample-points': ngh =int(sys.argv[1]); del sys.argv[1] else: print sys.argv[0],': invalid option',option sys.exit(1) #Make input file to the program ...
  • 12. Vai trò của tham số beta
  • 13. Python : Tạo dữ liệu đầu vào ... #Make input file to the program f = open('input','w') f.write("""%(print_init_values)g #Print initialized values 0=No 1=Yes %(order_wave_function)g #Order of the wave-function of Harmonical Oscillator %(beta)g #beta = sqrt(m.omega/hbar) : harmonical oscillator parameter %(xmin)g %(xmax)g #the domain of the function %(nsp)g #number of sample points of the function %(ngh)g #number of Gauss-Hermite sample points """ % vars() ) f.close() ... 0 #Print initialized values 0=No 1=Yes 2 #Order of the wave-function of Harmonical Oscillator 0.4 #beta = sqrt(m.omega/hbar) : harmonical oscillator parameter -10 10 #the domain of the function 1000 #number of sample points of the function 20 #number of Gauss-Hermite sample points
  • 14. Python : Hiển thị bằng hình ảnh ... kết quả tính toán # make file with gnuplot commands: gnuplotfile='phi_%i__beta_%g.gnuplot' % (order_wave_function,beta) f = open(gnuplotfile,'w') f.write("""reset Tạo tệp chứa lệnh vẽ cho gnuplot : phương pháp truyền thống # set title "Harmonical Oscillator Wave Function of order %(order_wave_function)g, beta=%(beta)g" set xlabel "x(fm)" set ylabel "fm^{-1/2}" # set xrange [%(xmin)g:%(xmax)g] # Line width of the axes set border linewidth 1.5 # Line styles set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 2 set style line 2 linecolor rgb '#dd181f' linetype 1 linewidth 2 # make a plot in PNG format: set term png small Tạo hình vẽ với đuôi .png set output 'phi_%(order_wave_function)i__beta_%(beta)g.png'; plot "data" with lines linestyle 2 notitle # define the postscript output format: Tích hợp thông tin tham số sử dụng set term postscript enhanced 'Times-Roman' 20; vào tên tệp set output 'phi_%(order_wave_function)i__beta_%(beta)g.ps'; set title "Harmonical Oscillator Wave Function of order %(order_wave_function)g, {/Symbol b}=%(beta)g" plot "data" with lines linestyle 2 notitle """ % vars() ) f.close() # make plot cmd = 'gnuplot -persist '+gnuplotfile failure = os.system(cmd) if failure: print 'running gnuplot failed'; sys.exit(1) ...
  • 15. Trạng thái kích thích bậc 100
  • 16. Cải tiến ● Chuyển dữ liệu đầu vào và đầu ra của một tính '../odho vào cùng một thư mục cmd = toán < input' ... caldir='tmp' ... elif option == '--calcul-directory': caldir =sys.argv[1]; del sys.argv[1] ... import shutil if os.path.isdir(caldir): #does caldir exist shutil.rmtree(caldir) # yes, remove old directory os.mkdir(caldir) #make caldir directory os.chdir(caldir) #move to dir ...
  • 17. Tính toàn bộ các trạng thái kích thích từ 0 tới 100 #!/usr/bin/env python import sys,os for n in range(0,100): cmd = "./odho_improved.py --beta 1.5 --order-wave-function %g --number-sample-points 1000 --calcul-directory beta1.5n%g" %(n,n) failure = os.system(cmd) if failure: print 'running gnuplot failed'; sys.exit(1)
  • 19. Thank you for your atte ntion!!!