Está en la página 1de 68

I HC QUC GIA H NI

TRNG I HC CNG NGH

Phm Quang Nht Minh

P DNG PHNG PHP SVD TNH LC XP


X TRONG BI TON M PHNG NG LC
PHN T

KHA LUN TT NGHIP I HC H CHNH QUY


Ngnh: Cng ngh thng tin

H NI 2006

I HC QUC GIA H NI
TRNG I HC CNG NGH

Phm Quang Nht Minh

P DNG PHNG PHP SVD TNH LC XP


X TRONG BI TON M PHNG NG LC
PHN T

KHA LUN TT NGHIP I HC H CHNH QUY


Ngnh: Cng ngh thng tin

Cn b hng dn: TS Nguyn Hi Chu

H NI 2006

p dng phng php SVD tnh lc xp x trong bi ton m phng ng lc phn t

TM TT KHA LUN
M phng ng lc phn t l mt trong nhng phng php ph bin
nghin cu cc h vt l v ha hc. Trong m phng ng lc phn t, thi gian tnh
ton lc tng tc gia cc ht trong h chim phn ln tng thi gian m phng.
Thut ton khai trin a cc nhanh Fast Multipole Method [5, 7, 8] v cc ci tin ca
n l nhng phng php c s dng ph bin trong m phng ng lc phn t
nhm tng tc tnh ton lc. Trong ci t thut ton khai trin a cc nhanh,
phng php phn tch ma trn SVD (Singular Value Decomposition [17, 18]) c
s dng nhm tng chnh xc ca tnh lc xp x. Mt trong nhng vn cha
c gii quyt trong ci t thut ton khai trin a cc nhanh l nghin cu nh
hng ca phng php SVD n chnh xc ca tnh lc xp x. Kha lun s
nghin cu vn nu trn bng thc nghim, nhm tm ra cch ng dng phng
php SVD hp l lm tng chnh xc v hiu nng ca thut ton khai trin a
cc nhanh trn cc my tnh chuyn dng hoc cc my tnh thng thng. Cc kt
qu thu c trong kha lun l kh quan v s c ng dng trong cc nghin cu
v ci t thut ton khai trin a cc nhanh tip theo.
T kha: Molecular Dynamics Simulation, Fast multipole method, Singular
Value Decomposition, Pseudo-Particle Mutilpole Method.

Trang i

p dng phng php SVD tnh lc xp x trong bi ton m phng ng lc phn t

LI CM N
u tin, em mun gi li cm n su sc n TS. Nguyn Hi Chu, ngi
hng dn v ch bo em tn tnh trong sut qu trnh lm kha lun. Cm n thy
v nhng nh hng, nhng ti liu qu bu v nhng ng vin, khch l, gip em
hon thnh tt kha lun.
Em xin gi li cm n ti TS Nguyn Nng Tm, ging vin trng i hc
S phm H Ni II v nhng h tr v mt ton hc c s dng trong kha lun.
Em xin by t li cm n su sc n cc thy c gio ging dy em trong
bn nm qua, nhng kin thc m em nhn c trn ging ng i hc s gip em
vng bc trong tng lai.
Cui cng, ti xin gi li cm n su sc ti nhng ngi thn trong gia nh,
nhng ngi lun quan tm, ng vin khch l ti trong hc tp v trong cuc sng.

Sinh vin thc hin kha lun


Phm Quang Nht Minh

Trang ii

p dng phng php SVD tnh lc xp x trong bi ton m phng ng lc phn t

MC LC
TM TT KHA LUN................................................................................................i
LI CM N................................................................................................................. ii
MC LC ..................................................................................................................... iii
DANH MC HNH V ..................................................................................................v
DANH MC BNG BIU........................................................................................... vi
BNG THUT NG .................................................................................................. vii
M U .........................................................................................................................1
Chng 1. TNG QUAN V BI TON M PHNG NG LC PHN T ......3
1.1 Bi ton m phng ng lc phn t ....................................................................3
1.1.1 Gii thiu chung .............................................................................................3
a. Cc bc trong m phng ng lc phn t ..................................................3
b. ng dng ca phng php m phng ng lc phn t ..............................4
1.1.2 Bi ton m phng ng lc phn t di gc tnh ton ..........................4
1.2 Cc phng php trong m phng ng lc phn t ............................................5
1.2.1 Phng php tnh trc tip tng tc ht-ht .................................................5
1.2.2 Thut ton cy ................................................................................................6
1.2.3 Phng php khai trin a cc nhanh ............................................................7
1.2.4 Mt s phng php khc ..............................................................................7
1.3 Mc tiu ca kha lun..........................................................................................8
1.4 Tng kt chng....................................................................................................8
Chng 2. THUT TON KHAI TRIN A CC NHANH......................................9
2.1 Thut ton khai trin a cc nhanh FMM .............................................................9
2.1.1 Phng php khai trin a cc .......................................................................9
2.1.2 Thut ton FMM...........................................................................................15
a. Cc pha chnh trong thut ton FMM............................................................16
b. Ci t thut ton FMM ................................................................................19
c. phc tp ca thut ton FMM..................................................................22
2.2 Cc bin th ca thut ton FMM .......................................................................23
2.2.1 Phng php ca Anderson..........................................................................23
2.2.2 Phng php gi ht ca Makino .................................................................26
a. Trong h ta 2 chiu .................................................................................27
b. Trong h ta 3 chiu .................................................................................28
2.3 Tng kt chng..................................................................................................30
Chng 3. P DNG PHNG PHP SVD TRONG M PHNG NG LC
PHN T......................................................................................................................31
3.1 Phng php SVD...............................................................................................31
3.1.1 SVD ca ma trn vung ...............................................................................32
3.1.2 Gii h phng trnh tuyn tnh ...................................................................33
a. Cch gii h phng trnh tuyn tnh bng SVD ..........................................33
b. Vn chn tham s gn 0 trong phng php SVD ...............................35
3.1.3 Ci t phng php SVD trn my tnh .....................................................35
Trang iii

p dng phng php SVD tnh lc xp x trong bi ton m phng ng lc phn t


3.2 ng dng ca phng php SVD trong inner P2M2 ...........................................36
3.2.1 Ci t thut ton FMM trn my GRAPE ..................................................36
a. Chc nng ca my GRAPE .........................................................................36
b. Ci t thut ton FMM trn my GRAPE ...................................................37
3.2.2 ng dng ca SVD trong ci t inner P2M2 ...............................................38
3.3 Tng kt chng..................................................................................................40
Chng 4. KT QU THC NGHIM V NH GI ...........................................41
4.1 Mi trng thc nghim......................................................................................41
4.1.1 Phn cng .....................................................................................................41
4.1.2 Phn mm .....................................................................................................41
4.2 Th nghim phng php khai trin a cc nhanh FMM ..................................41
4.2.1 Thi gian tnh ton ca phng php FMM ................................................41
4.2.2 nh gi kt qu...........................................................................................43
4.3 Th nghim phng php SVD trong bin i A2P...........................................44
4.3.1 chnh xc ca khai trin inner P2M2 v bin i A2P ............................44
a. Phng php thc nghim .............................................................................44
b. Kt qu thc nghim .....................................................................................45
4.3.2 nh hng ca tham s gn khng trong phng php SVD n chnh
xc ca thut ton FMM........................................................................................46
a. Phng php thc nghim .............................................................................46
b. Kt qu thc nghim .....................................................................................47
4.4 Tng kt chng..................................................................................................50
KT LUN ...................................................................................................................51
Kt qu t c........................................................................................................51
Hng pht trin........................................................................................................51
Ph lc A: Ci t SVD bng ngn ng C....................................................................53
A1. Th tc svdcmp()................................................................................................53
A2. Th tc svbksb() .................................................................................................57
A3. Th tc zero_small_values() ..............................................................................57
TI LIU THAM KHO .............................................................................................58

Trang iv

p dng phng php SVD tnh lc xp x trong bi ton m phng ng lc phn t

DANH MC HNH V
Hnh 1: Xp x trong cy (trn) v FMM (di) .............................................................6
Hnh 2: Hai tp hp ht xa trn mt phng ..............................................................12
Hnh 3: Dch chuyn tm ca khai trin a cc. ...........................................................14
Hnh 4: tng tnh lc xp x trong FMM.................................................................16
Hnh 5: Mt vi mc phn chia trong FMM .................................................................17
Hnh 6: Pha M2M trong thut ton FMM .....................................................................17
Hnh 7: Danh sch hng xm v danh sch tng tc ..................................................18
Hnh 8: Pha M2L trong thut ton FMM ......................................................................18
Hnh 9: Pha L2L trong thut ton FMM .......................................................................19
Hnh 10: Phng php ca Anderson............................................................................25
Hnh 11: Phng php gi ht ca Makino...................................................................26
Hnh 12: Tnh th nng v lc t phn phi khi lng ca cc gi ht ......................39
Hnh 13: Thi gian tnh lc ca thut ton trc tip (trn) v FMM (di) .................43
Hnh 14: Sai s trung bnh bnh phng ca th nng c tnh bng khai trin inner
P2M2 v bin i A2P. T trn xung, 8 ng cong tng ng vi cc bc khai trin
p = 1, 2, 3, 4, 5, 6, 7, 8 .................................................................................................46
Hnh 15: Sai s trung bnh bnh phng ca lc c tnh bng khai trin inner P2M2
v bin i A2P. T trn xung, 8 ng cong tng ng vi cc bc khai trin p = 1,
2, 3, 4, 5, 6, 7, 8 .............................................................................................................46
Hnh 16: Sai s trung bnh bnh phng ca th nng ng vi cc tham s gn 0 khc
nhau. T trn xung, cc ng tng ng vi bc khai trin t 1 n 5 ....................48
Hnh 17 : Sai s trung bnh bnh phng ca th nng ng vi cc tham s gn 0 khc
nhau. T trn xung, cc ng tng ng vi bc khai trin t 6 n 10 ..................48
Hnh 18: Sai s trung bnh bnh phng ca lc ng vi cc tham s gn 0 khc nhau.
T trn xung, cc ng tng ng vi bc khai trin t 1 n 5..............................49
Hnh 19 : Sai s trung bnh bnh phng ca lc ng vi cc tham s gn 0 khc nhau.
T trn xung, cc ng tng ng vi bc khai trin t 6 n 10............................49

Trang v

p dng phng php SVD tnh lc xp x trong bi ton m phng ng lc phn t

DANH MC BNG BIU


Bng 1: Cc phn mm m phng ng lc phn t tiu biu .......................................4
Bng 2: Phn tch phc tp ca thut ton FMM.....................................................23
Bng 3: Cng c s dng trong th nghim..................................................................41
Bng 4: Thi gian tnh ton ca FMM vi s ht thay i ...........................................42
Bng 5: Thi gian tnh ton trc tip vi s ht thay i..............................................42
Bng 6: Tham s gn 0 ng vi cc mc khai trin khc nhau ...................................50

Trang vi

p dng phng php SVD tnh lc xp x trong bi ton m phng ng lc phn t

BNG THUT NG
T hoc cm t
Bi ton gi tr bin
Bc thi gian
Coulomb
Danh sch tng tc
Danh sch hng xm
ng lc phn t
Gi ht
Hng
Khai trin a cc
Phng php khai trin a
cc nhanh
Khai trin a phng
M phng ng lc phn t
Nghch o ma trn
Nullspace
Range
S iu kin
SVD
Phng php gi ht
Tng tc ht-ht
Vt l thin vn

T vit tt

MD
Rank
FMM
MD Simulation

SVD
P2M2
PP

Trang vii

Tn ting Anh
boundary value problem
Time step
Lc Coulomb
Interaction list
Neighbor list
Molecular Dynamics
Pseudoparticle
Rank
Multipole expansion
Fast multipole method
Local expansion
Molecular Dynamics Simulation
Matrix inversion
Nullspace
Range
Condition Number
Singular value decomposition
Pseudo-particle multipole method
Particle-Particle
astrophysics

M U

M U
S pht trin nhanh chng ca cng ngh thng tin, c bit l s xut hin
ca cc h thng siu my tnh c tc tnh ton nhanh m ra mt phng php
mi trong nghin cu khoa hc, l phng php m phng bng my tnh. M
phng bng my tnh ng vai tr nh cu ni gia l thuyt vi thc hnh, gia cc
th nghim thc t vi cc th nghim c thc hin trn my tnh. Cc l thuyt c
th c kim nh bng cc h m phng, mt khc tnh chnh xc ca mt h m
phng cng c th c kim nh bng cc kt qu th nghim thc t. Hn th na,
cc th nghim m hin nay con ngi cha th tin hnh c trong phng th nghim
(v d cc th nghim yu cu phi lm vic trong mt mi trng nhit , hay p sut
rt cao) c th c m phng bng my tnh. Nh vy c th ni, m phng bng
my tnh l mt phng php c vai tr quan trng, v ngy cng c s dng nhiu
trong nghin cu khoa hc.
M phng ng lc phn t l mt phng php ph bin nghin cu cc
h vt l v ha hc. Bi ton m phng ng lc phn t xt di trn kha cnh tnh
ton thc cht l bi ton tnh ton tng tc gia cc ht trong mt h phn t. D
thy nu s dng phng php tnh ton trc tip tng tc ca tng cp ht, phc
tp tnh ton s l O( N 2 ) vi N l s ht trong h. Nh vy i cc h c s ht ln
(v d vi triu ht) th thi gian tnh ton l ln n mc khng th chp nhn c
trong thc t.
i vi hu ht cc bi ton m phng ng lc phn t, thi gian tnh ton
lc thng chim ti 95% tng thi gian m phng. Do c nhiu nghin cu
nhm lm gim thi gian tnh ton lc ca bi ton m phng. Cc hng nghin cu
chnh gm c: Pht trin cc thut ton tnh ton nhanh c phc tp tnh ton
O ( N log N ) hoc O (N ) , pht trin cc phn cng c bit tng tc tnh lc v kt

hp hai hng nghin cu trn.


Thut ton khai trin a cc nhanh [5, 7, 8] l thut ton tnh ton nhanh do
Greengard v Rokhlin pht trin c phc tp O(N ) . Thut ton khai trin a cc
nhanh (vit tt FMM) c pht trin trn cc my tnh thng thng nn khng p
dng c trn cc my tnh c bit. Do c nhiu ci tin ca thut ton FMM
nh cc ci tin ca Anderson [2], phng php gi ht ca Makino [16], L. Ying

Trang 1

M U
[21, 22]. Cc thut ton ny n gin ha ci t ca thut ton FMM gc v c th
p dng cc ci t ny trn cc my tnh c bit.
Da trn cc nghin cu ca Anderson v Makino, cc tc gi Chau, Kawai,
Ebisuzaki ([13]) ci t thut ton FMM trn my tnh chuyn dng GRAPE ([15,
20]) trong c s dng phng php SVD (Singular Value Decomposition [17, 18])
tng chnh xc trong tnh lc xp x. Mt vn cha c gii quyt trong ci
t thut ton khai trin a cc nhanh l nghin cu nh hng ca phng php SVD
n chnh xc ca tnh lc xp x. V vy kha lun s nghin cu vn cha
c gii quyt nu trn nhm lm tng chnh xc v hiu nng ca thut ton khai
trin a cc nhanh trn my tnh chuyn dng cng nh cc my tnh thng dng khc.
Phng php nghin cu trong kha lun l da trn thc nghim.
Ngoi phn m u v kt lun, kt cu ca kha lun bao gm bn chng:
Chng 1 Tng quan v bi ton m phng ng lc phn t trnh by c bn
v bi ton m phng ng lc phn t v cc phng php c s dng trong
m phng ng lc phn t.
Chng 2 Thut ton khai trin a cc nhanh s trnh by cc vn c bn
v thut ton khai trin a cc nhanh v cc bin th ca thut ton.
Chng 3 p dng phng php SVD trong m phng ng lc phn t trnh
by v bi ton m kha lun a ra v xut cch gii quyt da trn thc
nghim.
Chng 4 Kt qu thc nghim v nh gi m t qu trnh thc nghim, cc
bng s liu, th, v a ra nh gi v kt qu thu c.

Trang 2

Chng 1: Tng quan v bi ton m phng ng lc phn t

Chng 1. TNG QUAN V BI TON M PHNG


NG LC PHN T
1.1 Bi ton m phng ng lc phn t
1.1.1 Gii thiu chung
ng lc phn t l s m phng hot ng theo thi gian ca mt h phn t.
Phng php m phng ng lc phn t da trn nh lut 2 Newton v chuyn
ng, F = ma , trong F l lc tc dng trn ht, m , a tng ng l khi lng v
gia tc ca ht. T cc thng tin v lc tc dng trn mi ht, xc nh gia tc ca mi
ht trong h. Ly tch phn ca phng trnh chuyn ng sinh ra mt ng cong
m t v tr, vn tc, gia tc ca cc ht ti cc mc thi gian khc nhau. T ng
cong ny, trng thi trong tip theo hay trng thi trc ca mt h phn t s c d
bo.

a. Cc bc trong m phng ng lc phn t


Cc bc chnh trong m phng ng lc phn t nh sau:
1. Chn v tr ban u ca cc ht trong h.
2. Chn mt tp hp ban u vn tc ca cc ht. Cc vn tc ny thng c
chn theo phn phi Boltzmann i vi mt vi nhit , sau c chun
ha sao cho tng ng lng cui cng ca ton h bng 0.
3. Tnh ng lng ca mi ht t vn tc v khi lng ca chng
4. Tnh cc lc tng tc trn mi ht t biu thc nng lng.
5. Tnh v tr mi cho cc ht sau mt khong thi gian ngn sau . Khong thi
gian ny c gi l bc thi gian (time step). Vic tnh ton ny c thc
hin bng tnh tch phn s ca cc phng trnh v chuyn ng s dng cc
thng tin thu c trong bc trc.
6. Tnh ton vn tc v gia tc mi cho cc ht trong h.
7. Lp li cc bc t bc 3 n bc 6.
8. Lp li qu trnh ny lu cho h t ti trng thi cn bng. Trong trng
hp ny, trng thi cn bng khng phi l cu hnh c nng lng thp nht,
n l mt cu hnh chp nhn c cho h vi nng lng c ln cho trc.

Trang 3

Chng 1: Tng quan v bi ton m phng ng lc phn t


9. Mi khi h t ti trng thi cn bng, bt u ghi li ta ca cc ht sau mt
vi vng lp. Cc thng tin ny thng c ghi li sau t 5 n 25 vng lp.
Danh sch cc ta ny to thnh mt qu o chuyn ng ca h ht.
10. Tip tc qu trnh lp i lp li v ghi li d liu cho n khi c d liu c
tp hp a ra cc kt qu vi chnh xc mong mun.
11. Phn tch cc qu o chuyn ng thu c thng tin v h.

b. ng dng ca phng php m phng ng lc phn t


M phng ng lc phn t l mt trong nhng phng php ph bin
nghin cu cc h vt l v ha hc. Hin nay phng php ng lc phn t c s
dng nhiu trong vic nghin cu cu trc, ng lc, nhit ng lc ca cc phn t
sinh hc. Trong vt l, m phng ng lc phn t c s dng kim tra ng lc
hc ca cc hin tng mc phn t m khng th quan st c mt cch trc tip.
N cng c dng kim tra cc c tnh vt l ca cc thit b dng cng ngh
nano m cha hoc khng th quan st bng cc thit b hin ti.
Hin nay trn th gii, c nhiu h phn mm m phng ng lc phn t.
Bng 1 lit k cc h phn mm m phng ng lc phn t tiu biu hin nay:
Bng 1: Cc phn mm m phng ng lc phn t tiu biu
STT
1
2
3
4
5
6
7
8

Tn h m phng
AMBER
CHARMM
DL_POLY
GROMOS
GROMACS
NAMD
LAMMPS
QUANTUM 3.1

Ngun
http://amber.scripps.edu/
http://www.charmm.org/
http://www.cse.clrc.ac.uk/msi/software/DL_POLY/
http://www.igc.ethz.ch/gromos-docs/index.html
http://www.gromacs.org/
http://www.ks.uiuc.edu/Research/namd/
http://www.cs.sandia.gov/%7Esjplimp/lammps.html
http://www.q-pharm.com/home

1.1.2 Bi ton m phng ng lc phn t di gc tnh ton


Xt trn kha cnh tnh ton, bi ton m phng ng lc phn t c m t
nh sau: Cho trc mt h c lp gm N ht phn b trong mt min no (Thng
dng nht l min hnh lp phng trong khng gian 3 chiu). Cc ht ny tng tc
vi nhau theo lc Coulomb hoc lc hp dn. Bi ton m phng ng lc phn t

Trang 4

Chng 1: Tng quan v bi ton m phng ng lc phn t


nghin cu cc h c lp bng cch cp nht v tr ca cc ht sau mt khong thi
gian nht nh th hin qua m bc lp. Ti mi bc lp ta phi tnh lc tc dng
tng hp ln mi ht theo cng thc tnh lc Coulomb hoc hp dn. p dng nh
lut 2 ca Newton tnh c gia tc ri suy ra vn tc ca mi ht. Sau tnh ton
li v tr mi ca ht da trn vn tc ca cc ht . D dng thy rng thut ton n
gin nht gii bi ton ny l tnh lc tng tc cho tt c cc cp ht trong h.
Thut ton ny c phc tp O( N 2 ) . Nh vy i vi cc h c s ht ln (v d vi
triu ht) th thi gian tnh ton l ln n mc khng chp nhn c trong thc t.
i vi hu ht cc bi ton m phng ng lc phn t, thi gian tnh lc
thng chim ti 95% thi tng thi gian m phng. Do c nhiu nghin cu
nhm lm gim thi gian tnh lc ca bi ton m phng. Cc hng nghin cu gm
c: Pht trin cc thut ton c phc tp tnh ton O ( N log N ) hoc O ( N ) , v pht
trin cc phn cng c bit tng tc tnh lc v kt hp c hai hng nghin
cu trn.

1.2 Cc phng php trong m phng ng lc phn t


1.2.1 Phng php tnh trc tip tng tc ht-ht
Phng php tnh ton trc tip tng tc ht-ht l phng php n gin
nht. Trong phng php ny, u tin ta tnh cc lc F (i, j ) ca ht j tc ng ln
ht i . Sau ly tch phn phn ca cc phng trnh chuyn ng v cp nht b
m thi gian. Lp li qu trnh ny cho bc thi gian tip theo.
V d, trong m phng lc hp dn ca mt h gm N ht, mt ht c khi lng M
s ht mt ht khc c khi lng m vi mt lc : (GMm / r 3 ).r , trong G l hng
s hp dn, r l khong cch gia hai ht. Trong h c N ht, do chng ta phi tnh
lc ( N 1) ln. Sau tch cng thc tnh lc thnh hai phng trnh vi phn bc nht
ca gia tc v vn tc. Cui cng, s dng mt phng php gii phng trnh vi phn
s nh Euler hay Runge-Kutta thu c v tr v vn tc ca cc ht.
Phng php tnh trc tip tng tc ht-ht l n gin v kh mm do
nhng c th thy rng phng php ny yu cu phc tp tnh ton cao: O( N 2 )
tnh ton lc cho tt c N ht. Vi h c s lng ht N rt ln, phc tp ny l
khng th chp nhn c. V vy phng php ny c p dng trong cc h c s

Trang 5

Chng 1: Tng quan v bi ton m phng ng lc phn t


lng ht nh (t hn N = 1000 ht) hoc khi ta ch quan tm n cc tng tc gia
cc ht trong mt vng nht nh.

1.2.2 Thut ton cy


tng c bn ca thut ton cy l thay th cc lc hp dn (nu trong
trng hp ta tnh cc tng tc hp dn gia cc ht trong h) t mt cm cc ht
xa bng lc tc dng gy ra t trng tm ca chng, hoc bng khai trin a cc (chi
tit v khai trin a cc s c ni r hn trong phn sau ca kha lun) nu vi
chnh xc cao c yu cu. Cc ht c t chc thnh mt cu trc cy bt phn
(octree structrure) vi gc l ton b h v cc nt l tng ng vi cc ht.
Lc tc dng trn mt ht gy ra bi mt nt c nh ngha (v c tnh)
mt cch quy. Nu nt v ht l xa nhau, lc tc dng t nt ti ht s c
tnh bng khai trin a cc ca nt ti v tr ca ht. Nu chng khng xa nhau,
lc tng tc s c tnh bng cch ly tng cc lc tc tc dng t cc nt con ca
nt . tnh lc tc dng ln mt ht, phc tp s l O (log N ) , v phc tp l t
l thun vi chiu cao ca cy.

M2L

M2M

L2L

Hnh 1: Xp x trong cy (trn) v FMM (di)


Cc khai trin a cc ca cc nt trong cy phi c tnh trc. H s khai trin cho
mt nt c th c tnh quy t cc nt con ca n. phc tp tnh ton trong

Trang 6

Chng 1: Tng quan v bi ton m phng ng lc phn t


phn ny l O ( N ) . Nh vy phc tp tnh lc tc dng ln cc ht trong h s l
O ( N log N )

Chi tit hn v ci t thut ton c trong ti liu tham kho [4].

1.2.3 Phng php khai trin a cc nhanh


Thut ton khai trin a cc nhanh FMM c a ra ln u tin bi
Greengard v Rokhlin [7, 8] tng tc tnh lc trong bi ton m phng ng lc
phn t. Trong thut ton FMM, lc c tnh xp x bng khai trin a cc. Sau
khai trin a cc ny s c chuyn thnh khai trin cc b ti im quan st. Lc ti
mi im s c tnh nh khai trin cc b. Trn hnh 1 chng ta c th thy c s
khc nhau gia hai thut ton cy v thut ton FMM.
phc tp tnh ton trong thut ton ny l O( N ) . Tuy nhin vi cng mt
chnh xc, thi gian tnh ton thc t ca thut ton FMM c in l cao hn so vi
thut ton cy khi s lng ht cha ln. Nh vy FMM c in ch thc s hiu
qu hn khi s lng ht N l rt ln.
C nhiu ci tin ca thut ton FMM nhm lm gim thi gian tnh ton cng
nh cch ci t ca n, in hnh l cc ci tin ca Anderson [2] v ca Makino
[16]. tng chnh ca cc ci tin ny l gi nguyn m hnh, cc pha ca thut ton
FMM nhng thay th vic s dng cc khai trin a cc phc tp bng cc cng thc
n gin hn (Anderson) hay s dng phn phi cc gi ht trn mt cu th hin
cc h s ca khai trin a cc (Makino). Cc ci tin ny gip cho vic ci t ca
thut ton FMM trn my tnh l n gin hn so vi thut ton FMM c in.

1.2.4 Mt s phng php khc


Cc phng php tnh ton trong m phng ng lc phn t l rt nhiu nn
vic trnh by chi tit ht cc phng php ny vt khi khun kh ca mt lun vn
tt nghip i hc. y chng ti lit k mt s phng php khc ngoi cc phng
php trnh by trn: Phng php Particle-Mesh (PM), phng php ParticleParticle/Particle-Mesh (P3M), Particle Multiple-Mesh (PM2), Nested Grid ParticleMesh (NGPM), Tree-code (Top down) v Tree-code (Bottom up), Tree-code Particle
Mesh (TPM), Self-Consistent Field (SCF), phng php Symplectic.

Trang 7

Chng 1: Tng quan v bi ton m phng ng lc phn t

1.3 Mc tiu ca kha lun


Trong bin th ca phng php FMM, Makino dng cc gi ht trn mt
ng trn (mt cu trong khng gian ba chiu) thay cho cc h s trong khai trin a
cc, tnh c phn phi khi lng (in tch) ca cc gi ht ny, cn phi dng
n cc phng php gii h phng trnh tuyn tnh v cc thao tc tnh nghch o
ma trn. Mt gii php cho vn ny l ng dng phng php SVD (Singular Value
Decomposition [17, 18]) trong tnh lc lm tng chnh xc ca thut ton.
Nhng vn cn mt vn cha c nghin cu trong ci t thut ton khai trin a
cc nhanh l nghin cu nh hng phng php SVD n chnh xc ca tnh
lc xp x. Kha lun s nghin cu vn cha c gii quyt ni trn, nhm lm
tng chnh xc v hiu nng ca thut ton khai trin a cc nhanh. Mt khc kha
lun cng trnh by cc kt qu th nghim hiu nng ca thut ton FMM v phng
php tnh lc trc tip.

1.4 Tng kt chng


Trong chng u tin ca kha lun, chng ta c mt ci nhn tng quan
v bi ton m phng ng lc phn t, cc bc trong m phng ng lc phn t,
cc cch tip cn tng tc tnh lc trong bi ton cng nh cc vn cha c
gii quyt trong bi ton ny. Chng 2 ca kha lun s trnh by k hn v phng
php khai trin a cc nhanh v cc ci tin ca n m ang c dng rng ri trong
m phng ng lc phn t.

Trang 8

Chng 2: Thut ton khai trin a cc nhanh

Chng 2. THUT TON KHAI TRIN A CC


NHANH
2.1 Thut ton khai trin a cc nhanh FMM
2.1.1 Phng php khai trin a cc
Trong bi ton m phng ng lc phn t, sau mi bc thi gian, chng ta
cn phi cp nht li v tr, vn tc, v gia tc ca cc ht. tnh c cc gi tr ny,
chng ta cn tnh lc tng tc trn mi ht. Nh chng ta bit trong vt l, lc
tng tc trn mi ht trong mt h bao gm N ht c tnh theo cng thc:
mi

d 2 xi
= i vi i = 1,, N
dt 2

y mi l khi lng ca ht th i . Lc thu c t gradient ca hm th nng .


Bi ton m phng ng lc phn t c gii thiu trong kha lun ny gii
hn trong trng hp th nng (hoc lc) ti mt im l tng ca cc tng tc tng
i mt. Vi cch tip cn tnh ton thng thng, thut ton tnh tt c cc tng tc
gia cc cp ht c phc tp tnh ton l O( N 2 ) . Vi s lng ht N trong m
phng l rt ln, phc tp ny l kh c th chp nhn.
r rng hn, chng ta biu din th nng ti mt im di dng:
= far + near

vi near l th nng gy ra bi cc ht gn v far l th nng gy ra bi cc ht


xa. Th nng gy ra bi cc ht xa c nh hng nh hn rt nhiu so vi th nng
gy ra bi cc ht gn. Do trong m phng ng lc phn t, gim khi lng
tnh ton trn my tnh, chng ta c th xp x th nng gy ra bi cc ht xa ny vi
mt sai s c th chp nhn c. Phng php thng s dng trong trng hp ny
l phng php khai trin a cc.
tng c bn ca phng php khai trin a cc l cc ht xa c
phn cm li. Vic tnh ton th nng gy ra bi cc ht xa ny c xem nh l tnh
tng tc vi mt ht nhm tng tc tnh ton.

Trang 9

Chng 2: Thut ton khai trin a cc nhanh


minh ha phng php khai trin a cc, chng ta xem xt mt m hnh
vt l hai chiu bao gm mt tp hp gm N ht tch in (thut ton trong khng
gian 3 chiu l tng t v mt tng nhng cng thc phc tp hn nn y
chng ti trnh by trong trng hp 2 chiu). Th nng v lc ti cc ht c tnh t
nh lut Coulomb. Gi s rng mt in tch im vi cng n v c t ti
im ( x 0 , y 0 ) = x0 R 2 . Th th vi mi x = ( x , y ) R 2 m x x0, trng th nng
v in trng gy ra do in tch ny c tnh bng cng thc:
x0 ( x, y ) = log( x x 0 )

v
E x0 ( x , y ) =

( x x0 )
x x0

x0 l hm iu ha trong mi khong m khng cha im x 0 . Hn na, vi mi

hm iu ha u , tn ti mt hm kh vi w : C C sao cho u ( x, y ) = Re( w( x, y )) v w


l duy nht. t x + iy = z C , cng thc s tr thnh:
x0 ( x ) = Re( log( z z 0 ))

Trong cc phn tip theo chng ta s tip tc s dng k hiu hm phc


biu din th nng gy ra bi cc ht trong h.
V c s vt l v ton hc ca phng php khai trin a cc, chng ta xem
xt cc b sau y.
B 2.1: Nu u ( x, y ) = Re( w( x, y )) m t trng th nng ti ( x, y ) th lc tng ng
c cho bi:
u = (u x , u y ) = (Re( w' ), Im(w' )),

y w' l o hm ca w
B (2.1) trn l h qu trc tip ca cc phng trnh Cauchy -Riemann.
B sau y c s dng t c khai trin a cc i vi trng th nng gy
ra bi m in tch
B 2.2. Cho mt in tch im vi cng q t ti z 0 . Vi mi z sao cho z >
z0 ,

Trang 10

Chng 2: Thut ton khai trin a cc nhanh


k

1z
z 0 ( z ) = q log( z z 0 ) = q log( z ) 0

k =1 k z

(2.1)

Chng minh: Ch rng log( z z 0 ) log( z ) = log(1 z 0 / z ) v z 0 / z < 1 . B t


c t khai trin:

wk
,
k =1 k

log(1 ) = (1)

Khai trin ny ng vi mi w tha mn w < 1 (iu phi chng minh)


nh l 2.1 (Khai trin a cc) . Gi s rng m in tch vi cc cng { qi ,
i =1,, m } c t ti cc im { z i , i =1, , m }, vi z i < r . Vi mi z C vi
z > r , th nng ( z ) c cho bi

ak
k
k =1 z

( z ) = Q log( z ) +

(2.2)

y:
m

i =1

i =1

Q= qi , a k =

qi z i
k

(2.3)

Hn na, vi mi p 1
p

a
z
( z ) Q log( z ) kk
r
k =1 z

p +1

A 1


c 1 c

(2.4)

trong :
c=

z
, A=
r

q
i =1

, v =

A
1 r / z

(2.5)

Chng minh
Dng ca khai trin a cc (2.2) l mt h qu trc tip ca cc b 2.1 vi ch l
m

( z ) = zi ( z ) . t c (2.4), ch rng
i =1

ak
=
k
k =1 z

( z ) Q log( z )

ak
k
k = p +1 z

Thay th a k cng thc (2.3) chng ta c

ak
r
rk

A
A

k
k
k = p +1 z
k = p +1 k . z
k = p +1 z

Trang 11

p +1

A 1
=

c 1 c

Chng 2: Thut ton khai trin a cc nhanh


c bit vi c 2 th
p

a
1
( z ) Q log( z ) kk A
2
k =1 z

(2.6)

Chng ti s minh ha, vi mt v d n gin, cch mt khai trin a cc c dng


tng tc tnh ton th nng. Gi s rng cc in tch vi cng q1 , q 2 , ,
q m c t ti cc im x1 , x 2 , , x m C v { y1 , y 2 , , y n } l mt tp cc im

khc trong mt phng phc C (hnh 2). Chng ta ni rng tp hp { xi } v { yi } l


xa nhau nu tn ti cc im x 0 , y 0 C v mt s thc r > 0 sao cho
xi x0 < r vi i =1, , m ,
y i y 0 < r vi i =1, , n ,
x0 y 0 > 3r

.x1

.y1

.x2
.x3

.x0

.xm

.y0
.yn

.y2
.y3

Hnh 2: Hai tp hp ht xa trn mt phng


t c th nng (hoc lc) ti cc im { y j } gy ra bi cc im { xi }
mt cch trc tip, chng ta c th tnh
m

i =1

xi

( y j ) vi j =1, , n

(2.7)

R rng vic tnh ton trn yu cu phc tp bc nm (Tnh m th nng ti


n im). By gi gi s rng u tin chng ta tnh cc h s ca khai trin a cc n

cp p ( p -term) ca th nng gy ra bi cc in tch q1 , q 2 , , q m xung quanh im


x 0 (s dng nh l 2.1). N yu cu mt s lng cc php ton t l vi mp . Vic

tnh khai trin a cc ti tt c cc im y j t khai trin trn c phc tp tnh ton


l np , nh vy phc tp tnh ton tng cng l O ( mp + np ) . Hn na

Trang 12

Chng 2: Thut ton khai trin a cc nhanh


m

i =1

k =1

xi ( y j ) Q log( y j x0 )

ak
y j x0

1
A
2

t c mt chnh xc tng i , bc p phi bng log 2 ( ) . Nh vy khi


chnh xc l xc nh, do p l hng s nn phc tp tnh ton gim xung thnh
O ( m) + O ( n)

phc tp trn l nh hn rt nhiu so vi nm khi n, m ln.

Php dch chuyn v cn trn sai s


Trc khi tm hiu thut ton khai trin a cc nhanh FMM, chng ta cng
nhn ba b dui y. Ba b ny l nhng cng c gii tch bin i khai trin
a cc theo cch thc ph hp vi thut ton FMM. V l do d hiu, cc b ny
c trnh by trong h ta 2 chiu. Trong trng hp 3 chiu, tng ca cc b
ny l tng t, ch khc nhau v cng thc biu din. B (2.3) a ra mt cng
thc dch chuyn tm ca khai trin a cc. B (2.4) m t cch chuyn i mt
khai trin nh th thnh khai trin cc b (khai trin Taylor) trong mt min c dng
hnh trn, v b (2.5) cung cp mt k thut cho vic dch chuyn tm ca khai
trin Taylor. Cc b ny cng a ra cc gii hn v sai s gip chng ta c th tnh
xp x vi bt k chnh xc cho trc.
B 2.3 Gi s rng

ak
k
k =1 ( z z 0 )

( z ) = a0 log( z z 0 ) +

(2.8)

L khai trin a cc ca th nng gy ra bi mt tp m in tch vi cng l


q1 , q 2 ,..., q m , tt c cc in tch ny nm trong mt ng trn D vi bn knh R v c

tm ti z0. Th th i vi z nm ngoi ng trn D1 bn knh (R+ z 0 ) v c tm ti


gc ta , ta c

( z ) = a 0 log( z ) +
l =1

bl
zl

(2.9)

y
l
l 1 a 0 z 0l

bl = a k z 0l 1

k
1
l
=
k
1

Trang 13

(2.10)

Chng 2: Thut ton khai trin a cc nhanh


l

Vi l h s khai trin nh thc. Hn na vi mi p 1


k

b
A
( z ) a0 log( z ) ll
z0 + R
l =1 z

z0 + R

p +1

(2.11)

A c nh ngha nh trong (2.5)

Ch : Khi cc gi tr { a 0 , a1 , , a p } trong khai trin (2.8) xung quanh z 0 c tnh,


chng ta c th thu c { b1 , , b p } mt cch chnh xc bng (2.10). Mt khc
chng ta c th dch chuyn tm ca khai trin a cc c ct ct m khng lm
gim chnh xc.
B 2.4
Gi s rng m in tch vi ln q1, q2,, qm nm bn trong ng trn D1 vi bn
knh R v tm z0, v rng |z0| > (c+1)R vi c>1 (hnh 3). Th th khai trin a cc
tng ng (2.8) hi t bn trong ng trn D2 bn knh R vi tm gc ta . Bn
trong D2, th nng gy ra bi cc in tch c biu din bng chui ly tha

( z ) = bl .z l ,

(2.12)

l =0

y
R
z0

c.R
R

D
s

Hnh 3: Dch chuyn tm ca khai trin a cc.

Trang 14

Chng 2: Thut ton khai trin a cc nhanh

ak
(1) k + a0 log( z 0 )
k
z
k 1 0

b0 =

(2.13)

v
1
bl = l
z0

a
a k l + k 1

(1) k 0l vi l 1 .
k
k =1 0 k 1
l.z 0

(2.14)
Hn na, vi mi p max( 2,2c /(c 1)) , mt cn trn ca sai s cho chui rt gn
c cho bi
A(4e( p + c)(c + 1) + c 2 ) 1
( z ) bl .z <

c(c 1)
c
l =0
p

p +1

,
(2.15)

y A c nh ngha nh trong (2.5) v e l c s ca logarit c s t nhin.


B (2.5) sau y l mt h qu trc tip ca nh l Macloranh. N biu din chnh
xc thao tc dch chuyn tm vi bc khai trin hu hn, v khng yu cu gii hn
no v sai s.
B 2.5 Cho bt k s phc z0, z v {ak}, k=0, 1, 2,, n,
n n

k
k
a k ( z 0 ) k l z l

=
(
)
a
z
z

0
k

k =0
l = 0 k =l
l

(2.16)

2.1.2 Thut ton FMM


Trong phn 2.1.1, chng ta xem xt phng php khai trin a cc tnh
xp x th nng. C nhiu thut ton s dng phng php khai trin a cc nh
phng php cy do Appel [3], Barnes v Hut [4] pht trin vi phc
tp O ( N log N ) , phng php Pannel clustering ca Hackbush v Nowak ([9]) vi
phc tp O( N (log N ) d + 2 ) , phng php ca Beylkin, Coifman, Rokhlin [6] vi phc
tp O ( N log N ) , khai trin a cc nhanh do Greengard v Rokhlin ([7, 8]) pht trin c
phc tp O ( N ) . Trong cc phng php s dng khai trin a cc, phng php
khai trin a cc nhanh l mt phng php c ng dng rng ri trong m phng
ng lc phn t.

Trang 15

Chng 2: Thut ton khai trin a cc nhanh


FMM l mt thut ton xp x tnh th nng (lc) gia cc ht. Trong
trng hp cc ht trong h c phn phi chun, thut ton FMM s gim phc tp
tnh ton t O( N 2 ) xung O( N ) . Chin lc trung tm c s dng l chin lc
phn cm cc ht ti cc di khng gian khc nhau v tnh tng tc vi cc cm
khc m xa theo ngha khai trin a cc. Cc tng tc gia cc ht gn nhau c
tnh trc tip. Tng tc vi cc ht xa nhau s c tnh thng qua tng tc cmcm. Hnh v sau m t tng c bn ca thut ton FMM v cc pha ca trong
thut ton.

M2M
M2L

Khai trin a cc

L2L

Khai trin a phng

Hnh 4: tng tnh lc xp x trong FMM

a. Cc pha chnh trong thut ton FMM


Thut ton u tin c trnh by trong trng hp 2 chiu [7] sau c
m rng i vi trng hp 3 chiu [8]. Trong kha lun ny, chng ta s tm hiu
cch ci t thut ton i vi trng hp 2 chiu. Thut ton c ci t theo cc
pha chnh sau y:

i. To cy
Ban u chng ta nh ngha mt hnh vung ln (Nt gc) cha tt c cc
ht trong h. Chng ta to mt cy t phn (quadtree) bng cch chia nh dn hnh
vung theo cc cp. Th tc phn chia bt u t nt gc ti mc l = 0 bao gm ton
b h. Mc y chnh l su ca cy m chng ta to ra. Vic phn chia c
thc hin quy cho tt c cc nt con, v s dng li cho ti mc l max . Mc
l max c chn sao cho s lng ht trung bnh trong cc nt l bng vi mt s lng

c xc nh trc no (c th c sai s cho php) ti u tc tnh ton.

Trang 16

Chng 2: Thut ton khai trin a cc nhanh

l=0

l=1

l=2

l=3

Hnh 5: Mt vi mc phn chia trong FMM

ii. Bin i M2M


Tip theo chng ta tnh ton khai trin a cc cho mi nt l vi cc ht nm
trong nt theo nh l 2.1.
Sau , chng ta tnh ton khai trin a cc cho tt c cc nt khng phi l
nt l tt c cc mc. Vic tnh ton bt u t nt cha ca cc nt. i vi mi nt,
cc khai trin a cc ca cc nt con ca n s c dch chuyn ti tm hnh hc ca
nt (Bin i M2M dng b 2.3) v sau ly tng ca cc khai trin ny. Th
tc ny tip tc cho n khi ln ti nt gc.

Hnh 6: Pha M2M trong thut ton FMM

iii. Bin i M2L


Trc ht chng ta nh ngha hai thut ng danh sch hng xm (neighbor
list) v danh sch tng tc (interaction list). Danh sch hng xm ca mt nt l tp
hp ca cc nt trong cng mt mc m k vi nt ang xt. Vi mt nt, ta xt cc
hng xm ca nt cha. Tp hp cc nt con ca cc hng xm ny m khng k vi

Trang 17

Chng 2: Thut ton khai trin a cc nhanh


nt ang xt to thnh danh sch tng tc ca nt . Hnh 7 di y th hin
danh sch hng xm v danh sch tng tc ca mt nt trong trng hp 2 chiu.

DS tng tc

DS hng xm

Nt ang xt

x n

Hnh 7: Danh sch hng xm v danh sch tng tc


K hiu n l cc nt thuc danh sch hng xm, i k hiu cc nt thuc danh sch
tng tc
i vi mi nt, chng ta tnh ton khai trin a cc ca tt c cc nt trong
danh sch tng tc. Chng ta chuyn i cc khai trin a cc ny thnh khai trin
a phng (local expansion) ti tm hnh hc ca nt ang xt (M2L s dng b
2.4) sau tnh tng ca chng. Khai trin a phng ca x (trn hnh 7) c s
dng m t th nng trong x gy ra bi cc ht nm trong cc xa vi x.
Trong hnh 5, cc k hiu bng n l cc hng xm vi x, do cc ny khng
phi l cc xa vi x.

M2L

Hnh 8: Pha M2L trong thut ton FMM

Trang 18

Chng 2: Thut ton khai trin a cc nhanh

iv. Bin i L2L


Trong bc tip theo, chng ta s duyt cy theo th t trn xung. Ly tng
ca cc khai trin a phng (Khai trin Taylor) ti cc mc khc nhau t c
tng th nng ti cc nt l. i vi mi nt mc l , chng ta dch chuyn tm ca
khai trin a cc ca nt cha ca nt mc l 1 (Bin i L2L), sau cng khai
trin vo khai trin a phng ca nt ang xt. Bng th tc ny, tt c cc nt
mc l s c khai trin a phng ca th nng gy ra bi cc ht xa (cc ht xa
l cc ht khng nm trong danh sch hng xm ca ht ang xt). Lp li th tc ny
cho tt c cc mc, chng ta thu c trng th nng ca tt c cc nt l.

Hnh 9: Pha L2L trong thut ton FMM

v. Tnh lc
Bc cui cng trong thut ton ny l tnh lc tc dng ln mi ht trong tt
c cc nt l. Nh ta bit, lc tng tc s thu c bng gradient ca th nng. Th
nng tng cng ti v tr cc ht s c tnh bng tng ca th nng gy ra do cc ht
xa c tnh trong cc bc trn v th nng gy ra bi cc ht nm trong
khong cch gn vi v tr ang xt. Th nng gn s c tnh trc tip qua tng
tc tng i gia cc ht.

b. Ci t thut ton FMM


Cc k hiu sau y c dng trong m t ca ci t thut ton FMM:
li : Khai trin a cc cp p (Xung quanh tm ca nt i ) ca trng th nng to ra

bi cc ht nm bn trong nt i ti mc l

Trang 19

Chng 2: Thut ton khai trin a cc nhanh


l ,i : Khai trin cp p xung quanh tm ca nt i ti mc l , m t trng th nng gy

ra bi tt c cc ht bn ngoi nt v bn ngoi cc cc hng xm ca n.


~
l ,i : khai trin a phng (khai trin Taylor) xung quanh tm ca nt i ti mc l , m

t trng th nng gy ra bi tt c cc ht bn ngoi nt cha nt i v bn ngoi cc


hng xm gn nht ca nt cha ca i .
Gi s rng ti mc l 1, khai trin a phng l 1,i c tnh cho tt c
cc nt. S dng b (2.5) dch chuyn (i vi mi i ) khai trin l 1,i ti khai
trin ca cc nt con ca i , chng ta s thu c: vi mi nt j ti mc l , mt khai
trin a phng ca trng th nng gy ra bi cc ht bn ngoi cc hng xm ca
~

cha m j gi l l , j . Sau cng th nng gy ra bi cc nt trong danh sch tng


~

tc ca j vi l, j sinh ra l , j . Th nng gy ra bi cc nt trong danh sch tng


tc ca j nh b (2.4) chuyn khai trin a cc ca cc nt trong danh sch tng
tc ny thnh khai trin a phng ti tm ca nt hin ti. Cng ch rng, 0,i v
1,i l bng 0 bi v khng c cc nt no xa nhau c xem xt v chng ta c th

bt u hnh thnh khai trin a phng mc 2.


Sau y chng ta s m t thut ton di dng gi m cng vi mt s gii
thch.
Khi to
Chn mt mc phn chia n log 4 N , mt chnh xc v chn cp khai trin
p log 2 .

Pha i ln
Bc 1
Gii thch [Tnh khai trin a cc ca trng th nng gy ra bi cc ht bn trong
mi nt xung quanh quanh tm ca nt ti cc nt l]
do ibox=1, , 4 n
To ra khai trin a cc cp p ca n,ibox , bng cch s dng nh l 2.1
enddo
Bc 2
Gii thch [Tnh khai trin a cc xung quanh cc tm ca tt c cc nt cc mc
cao hn, mi khai trin biu din trng th nng gy ra bi tt c cc ht cha
bn trong 1 nt]

Trang 20

Chng 2: Thut ton khai trin a cc nhanh


do l = n-1, , 0
do ibox = 1, , 4 l
Tnh khai trin a cc cp p l ,ibox bng cch s dng nh l (2.3) dch
chuyn tm ca mi mi khai trin ca nt con ti nt hin ti v ly tng ca
chng.
enddo
enddo
Pha i xung
Bc 3
Gii thch [Tnh khai trin a phng ti tm ca mi nt trong li ti mi mc
l n . Khai trin cc b ny m t th nng gy ra ti tm ca nt ang xt bi tt

c cc ht trong h m khng nm trong nt hin ti hoc cc hp hng xm gn


nht ca n]
~

Thit lp 1,1 = 1, 2 = 1,3 = 1, 4 = (0,0,...,0)


do l = 1, , n 1
do ibox = 1,, 4 l
Tnh l ,ibox bng cch s dng b 2.4 bin i khai trin a cc l , j ca
mi nt j trong danh sch tng tc ca nt ibox thnh khai trin a phng
xung quanh tm ca nt ibox, sau ly tng ca nhng khai trin a phng
~

ny v cng kt qu vi l ,ibox .
enddo
do ibox = 1,, 4 l
Dng b 2.5, tnh khai trin l,ibox ti tm ca cc nt con ca ibox ta thu
~

c khai trin l +1, j cho cc nt con ca ibox.


enddo
enddo
Bc 4
Gii thch [Tnh cc tng tc ti mc phn chia mn nht]
do ibox = 1, , 4 n
Tnh l ,ibox bng cch dng b 2.4 bin i khai trin a cc l , j ca mi nt
j trong danh sch tng tc ca nt ibox thnh khai trin a phng xung quanh

Trang 21

Chng 2: Thut ton khai trin a cc nhanh


tm ca nt ibox, cng cc khai trin a phng ny vi nhau, v cng kt qu vi
~
l,ibox

enddo
Gii thch [Khai trin Taylor ti mc phn chia mn nht by gi c tnh. T
khai trin ny chng ta c th tnh c th nng hoc lc gy ra do tt c cc ht
nm bn ngoi cc nt trong danh sch hng xm]
Bc 5
Gii thch [Tnh khai trin a phng ti v tr ca cc ht]
do ibox = 1, , 4 n
enddo

Vi mi ht p j t ti im z j trong hp ibox, tnh n ,ibox ( z j )


Bc 6

Gii thch [Tnh th nng (hoc lc) gy ra bi cc ht thuc cc nt trong danh sch
hng xm mt cch trc tip]
do ibox= 1,, 4 n
Vi mi ht p j trong nt ibox, tnh tng tc vi tt c cc ht khc trong nt v vi
cc hng xm gn nht ca n.
enddo
Bc 7
do ibox = 1, , 4 n
Vi mi ht trong box ibox, ly tng cc th nng tnh trc tip v cc th nng
tnh xp x.
enddo

c. phc tp ca thut ton FMM


Chng ta nh gi phc tp ca thut ton FMM trn hai kha cnh l
phc tp v thi gian v phc tp v khng gian.
Bng di y phn tch ngn gn phc tp v thi gian ca thut ton
FMM

Trang 22

Chng 2: Thut ton khai trin a cc nhanh


Bng 2: Phn tch phc tp ca thut ton FMM
Bc S php tnh
Gii thch
1
Bc Np
Ti cc nt l, tnh khai trin a cc cp p ti N ht.
2
2
Bc Np
Ti mc l , ta phi thc hin 4 l php tnh dch chuyn vi
phc tp l p 2 .
3
Bc 28Np 2 C nhiu nht l 27 nt trong danh sch tng tc ca mi nt
mi mc. Trong vng lp th hai, phc tp tnh ton l Np 2 .
4
Bc 27Np 2 C nhiu nht l 27 nt trong danh sch tng tc i vi mi
nt v c xp x N nt.
2
5
Bc 27Np Ta cn tnh khai trin a cc cp p cho mi ht.
9
6
Cho k n l cn trn ca s lng ht trn mi nt mc l. Ta
Bc Nk n
cn tnh tung tc gia cc ht bn trong hp v bn trong danh
2
sch tng tc, nhng s dng nh lut 3 Newton, ch cn tnh
mt na s tng tc tng i mt
7
Bc N
Trong bc 7 ch cn cng th nng xa v th nng trc tip.
Nh vy ch cn yu cu mt php ly tng hai s hng
Nh vy, c lng thi gian tnh ton ca thut ton FMM s l:
N ( 2a log 2 ( ) + 56b(log 2 ( )) 2 + 4.5k n + e)

trong l cn trn ca sai s, nh ta bit mun c sai s nh hn bc khai


trin phi l: p = log 2 ( ) ; cc hng s a , b , c , d v e c xc nh bi mt h
thng my tnh, ngn ng, ci t,
V phc tp khng gian ca thut ton FMM, trong thut ton cc i
lng l , j v l , j phi c lu tr cng nh l v tr ca cc ht, in tch (hay khi
lng khi xt lc hp dn), v kt qu tnh ton (th nng, hoc in trng). V mi
nt mi mc c mt cp khai trin cp p , v v di ca tt c cc mng
lu tr l t l vi s ht N , nn d thy phc tp v khng gian ca thut ton s
l:
( + . p).N = ( log 2 ( )).N

vi cc h s , ty thuc v h thng my tnh, ngn ng, ci t.

2.2 Cc bin th ca thut ton FMM


2.2.1 Phng php ca Anderson
Phng php FMM gc do Greengard v Rokhlin xut mc d c phc
tp l O(N ) nhng khng thc s a ra nhng u im vt tri hn so vi thut
Trang 23

Chng 2: Thut ton khai trin a cc nhanh


ton cy (Barnes v Hut [4]) khi ci t thc t. Mt trong s nhng l do l c s ton
hc c s dng trong FMM l phc tp hn rt nhiu v ci t thut ton FMM c
in trn my tnh cng kh khn hn so vi ci t thut ton cy. Chnh v vy ch
c mt vi ci t ca thut ton FMM trn my tnh c a ra. Nhng nhng ci
t ny cng khng c s dng mt cch rng ri v khng tht s c c s ti
u cn thit. Thut ton FMM c in l mt thut ton rt phc tp, v ch mt vi sai
st nh trong ci t cng c th dn ti s km hiu qu ca thut ton. Trong khi
thut ton cy l n gin hn rt nhiu v v th rt d dng t c hiu qu cao.
Anderson [2] xut mt ci tin ca thut ton FMM s dng mt cng
thc mi ca khai trin a cc v khai trin a phng. Phng php ca Anderson
da trn cng thc Poisson. Cng thc ny l li gii ca bi ton gi tr bin
(boundary value problem) ca phng trnh Laplace. Trong khng gian ba chiu, nu
th nng trn mt mt cu bn knh a l c cho trc, th nng ti im
r
r = (r , , ) c tnh bng cng thc:

n +1

rr
r
s .r
Pn
(as )ds
r

r
1
(r ) =
4

a
(2n + 1)
S
r
n =0

r
1
(r ) =
4

rr
n
r
s .r
r
(
2
1
)
P
n
+
(as )ds
n
S
r
a
n =0

(2.17)

vi r a v:

(2.18)

vi r a . Trong cc cng thc (2.17) v (2.18) chng ta s dng h ta cu. y


r
( as ) l th nng cho trc trn mt cu. Vng ly tch phn S l mt cu n v c

tm chnh l gc ta . Hm Pn l k hiu ca a thc Legendre bc n :


Pn ( x) = (2 n n!) 1

dn
( x 2 1) n
dx n

s dng cc cng thc (2.17) v (2.18) thay cho cc khai trin a cc v


khai trin a phng, Anderson xut mt phin bn ri rc ca chng,
Anderson rt gn v phi ca phng trnh (2.17)-(2.18) ti gi tr n hu hn, v thay
th tch phn trn mt S vi cc gi tr s phn b theo t - design cu, vi t -design cu
c Hardin v Sloane [10] nh ngha nh di y.
Mt tp hp K im= ( P1 ,, PK ) trn hnh cu n v d= S d 1 = { x =
( x1 ,, x1 ) R d : x.x = 1 } hnh thnh mt t-design hnh cu nu phng trnh:

Trang 24

Chng 2: Thut ton khai trin a cc nhanh

f ( x ) d ( x ) =

1
K

f (P )
i =1

(2.19)

( y l n v chun trn d c chun ha) ng cho tt c cc a thc f vi


bc t .
Ch rng tp tt nht, v d tp nh nht ca t -design l cha c tm ra
vi t tng qut. Trong thc hnh chng ta s dng t -design do Hardin v Sloane tm
thy bng thc nghim. Cc v d v cc ta v tr ca cc tp im nh vy c th
c tm thy ti http://www.research.att.com/~njas/sphdesigns/.
S dng t -design cu. Anderson thu c cng thc c ri rc ha
ca (2.17) v (2.18) nh sau:
p
K
r
a
(r ) (2n + 1)
r
i 1 n = 0

n +1

r r
r
si .r
Pn
(a.si ) wi
r

(2.20)

i vi r a (khai trin ngoi) v


r r
n
p
K
r
r
r si .r
(r ) (2n + 1) Pn
(a.si ) wi
a r
i 1 n = 0

(2.21)

vi r a (khai trin trong). y wi l cc gi tr trng lc hng s v p l s cc s


hng khng b lm trn. Trong cc phn sau chng ta ni ti p nh bc ca khai trin
Phng php Anderson s dng phng trnh (2.20) v (2.21) tng ng cho
cc bin i M2M v L2L. Cc th tc ca cc pha khc l ging nh trong FMM gc.
Hnh 10 m t tng c bn phng php ca Anderson:
Xp x ngoi
(2)

(1)

(3)

Xp x ngoi

Cc gi tr th nng
Xp x trong

Hnh 10: Phng php ca Anderson

Trang 25

Chng 2: Thut ton khai trin a cc nhanh


u im chnh trong phng php ca Anderson trong thc hnh l vic ci
t kh n gin. Thut ton FMM c in trong h ta 3 chiu s dng cc cng
thc kh phc tp ci t cc thao tc nh dch chuyn tm ca khai trin a cc
(M2M), chuyn i khai trin a cc thnh khai trin a phng (M2L) v dch
chuyn tm ca khai trin a phng (L2L). Trong phng php ca Anderson, tt c
cc thao tc dch chuyn v bin i c tin hnh bng cch tnh cc th nng ti cc
im ly mu trn mt cu. V th c s ton hc ca phng php c gii hn
trong hai cng thc (2.20) v (2.21).

2.2.2 Phng php gi ht ca Makino


Trong phng php ca Anderson, khai trin a cc ca th nng gy ra bi
mt nhm ht c biu din bng cc gi tr th nng trn mt mt cu bao quanh cc
ht . Th nng ti mt im bt k bn ngoi mt cu s c tnh bng tch phn
trn mt cu . Trong thc hnh, tch phn ni trn c tnh xp x bng tng trn
cc ht mu nm trn mt cu. Makino [16] xut mt ci tin khc kh ging vi
phng php ca Anderson. tng c bn ca phng php ny l s dng mt s
lng nh cc gi ht trong biu din khai trin a cc. Thay v s dng phn phi th
nng trn mt cu, Makino s dng phn phi khi lng. Phng php ny ca
Makino khi kt hp vi my chuyn dng GRAPE (GRAPE, Makino v Taiji 1998
[15]; Sugimoto 1999 [20]) tng tc tnh lc t 100-1000 ln so vi cc my
thng thng.

(2)

(1

Cc gi ht
Hnh 11: Phng php gi ht ca Makino

Trang 26

F,

Chng 2: Thut ton khai trin a cc nhanh

a. Trong h ta 2 chiu
Trong h ta 2 chiu, khai trin a cc ca th nng hp dn do mt ht gy
ra c cho bi:
( z0 / z) k
k
k =1

z 0 ( z ) = m log( z z 0 ) = m log( z ) m

(2.22)

y z 0 v z l v tr ca ht v v tr ca im tnh th nng trong mt phng phc,


v m l khi lng ca ht. Cng thc trn s hi t nu z > z 0 .
Nu chng ta c N ht vi khi lng mi ti cc v tr z i ( z i < a) , cng thc
tnh th nng bn ngoi ng trn bn knh a l:

k =1

( z ) = M log( z )

(a / z ) k

(2.23)

vi M l tng khi lng ca cc ht v h s k :


N

k = mi ( z i / a ) k

(2.24)

i =1

Ta cn xc nh phn phi khi lng ca cc gi ht trn ng trn bn knh


a . Cc h s ca khai trin a cc s c xc nh bng cng thc:
2

k = (r / a) k e ik ( ).d

(2.25)

y l mt ca khi lng ti ta cc (r , ) . V th t cc h s khai trin


k , ( ) c th tnh t chui Fourier:
1
( ) =
2

a

r

k =0

e ik

(2.26)

Makino xp x khi lng m lin tc ny bng 2 p + 1 im ri rc ti


j = 0 , 2 /( 2 p + 1) , 4 /( 2 p + 1) , khi lng m j c cho bi cng thc:
1 a
mj =

2 p +1 r

k =0

ik j

(2.27)

Do tnh cht ca chui Fourier, cc phn phi khi lng m j ny s biu din
chnh xc cc khai trin a cc ti cp p . tnh th nng bn ngoi ng trn, ta
ly tng cc th nng do nhng ht ny gy ra:

Trang 27

Chng 2: Thut ton khai trin a cc nhanh


( z ) =

2 p +1

m
j =1

log( z z j )

(2.28)

trong z j = re 2ij /( 2 p +1) .


i vi pha M2M c hai thut ton cy v FMM, chng ta vn phi tnh khai
trin a cc hoc biu din di dng ht ti tm ca mt nt t nhng nt con ca n.
V cc nt con c biu din di dng ht nn chng ta c th s dng phng
trnh (2.24) thu c h s khai trin ca cc nt cha.
Trong ci tin ca mnh, thay v vic s dng cc h s khai trin a cc,
Makino tnh khi lng ca cc gi ht trc tip t khi lng ca cc ht vt l
(hoc t khi lng ca cc gi ht trong cc nt con). Kt hp hai phng trnh
(2.24) v (2.27) ta c cng thc tnh trc tip m j t mi nh sau:
mj =

p n
n
1 ( z i / z j ) p +1
1
1
k
=
m
(
z
/
z
)
m
i i j 2 p + 1
i
1 zi / z j
2 p + 1 k =0 i =1
i =1

(2.29)

Cui cng cn phi xc nh thut ton cho pha M2L v L2L. Chng ta c th
s dng phng php ca Anderson hoc khai trin a cc. i vi khai trin a
phng, phng php ca Anderson d ci t hn so vi khai trin a cc.

b. Trong h ta 3 chiu
Cc cng thc trong h ta 3 chiu v c bn l ging vi trng hp 2
chiu ngoi tr vic chng ta dng iu ha cu thay cho z k . Biu thc ca h s khai
trin ml l:
N

lm = mi ril Yl m ( i , i )

(2.30)

i =1

trong mi l khi lng ca ht th i v (ri , i , i ) l ta cc ca n. Hm s


Yl m ( , ) l iu ha cu bc l , c cng thc l:

Yl m = (1)

2l + 1 (l m )! m
Pl (cos )e im
4 (l + m )!

(2.31)

v l Pl m hm s Legendre kt hp gia cp l v bc m . Vi cc h s khai trin ml ,


ta tnh c th nng ti im ( r , , ) l:

(r , , ) =

l =0 m = l

lm
r

l +1

Trang 28

Yl m ( , )

(2.32)

Chng 2: Thut ton khai trin a cc nhanh


Mc ch ca chng ta l tnh phn phi khi lng ( , ) trn mt hnh cu
bn knh a m tha mn:
lm = ( , )Yl m ( , )dS
S

(2.33)

trong l k hiu ca b mt hnh cu. V iu ha cu cha mt h trc giao nn


c biu din bng cng thc sau:

= lm Yl* m

(2.34)

l =0 m = l

Nu chng ta s dng K im trn hnh cu, khi lng ca chng l:


1
mj =
4K

p
l =0

m=l

m * m
l
l

(2.35)

Khai trin chui ny phi c ct ct mt gi tr hu hn nh chng ta


thy trong trng hp 2 chiu. Nh ni trong phng php ca Anderson, bc ct
ct phi l [ t /2] nu K im to thnh mt t -design.
Nh trnh by trong trng hp 2 chiu, chng ta c th bin i trc tip
cc v tr v khi lng ca cc ht vt l thnh v tr v khi lng ca cc gi ht.
Biu thc chun s l mt tng xichma gm 3 phn trn i , l , v m . n gin gin
ha cng thc ny chng ta s dng mt nh l v iu ha cu. nh l l:
Pl (cos ) =

4 l m
Yl ( , ).Yl m ( ' , ' )

2l + 1 m = l

(2.36)

trong l gc gia hai vector c hng l ( , ) v ( ' , ' ) . S dng nh l ta tnh


c cc khi lng m j nh sau:
l

2l + 1 ri
m j = mi
Pl (cos ij )
K a
i =1
l =0
N

(2.37)

trong ij l gc gia hai vector tng ng vi hai ht vt l i v gi ht j .


Nh vy th nng gy ra bi cc ht vt l s c tnh xp x bng th nng
gy ra bi cc gi ht ny.
Phng trnh (2.37) a ra mt gii php cho trng hp khai trin ngoi, ng
dng trong pha M2M ca thut ton FMM. i vi pha M2L l mt pha chim phn
ln thi gian tnh ton ca thut ton, phng php ca Makino cha cp n, v
trong thc hnh, cng thc khai trin trong ca Anderson c s dng.

Trang 29

Chng 2: Thut ton khai trin a cc nhanh


Vi cch tip cn tng t Chau, Kawai v Ebisuzaki [13] t c gii
php i vi khai trin trong:
2l + 1 a

m j = mi
K ri
i =1
l =0
N

l +1

Pl (cos ij )

(2.38)

Tm li, phng php gi ht P2M2 (Pseudo-Particle Multipole Method) ca


Makino a ra c hai u im so vi phng php FMM chun s dng khai trin a
cc mt cch trc tip. u im th nht l s n gin. Nh chng ta thy, cc cng
thc bin i s dng trong P2M2 l n gin hn rt nhiu so vi cc cng thc ca
FMM. S n gin y c ngha l s thay i trong ci t v s song song ha l
d dng, mc d chi ph tnh ton ca hai phng php l gn tng ng i vi
cng mt chnh xc.
Mt u im na l P2M2 tn dng c u th ca my tnh chuyn dng
GRAPE. GRAPE l mt my tnh c b x l theo kiu pipeline tnh lc gia cc
ht. Mc d thut ton cy c ci t trn my tnh GRAPE, nhng n kh t
c chnh xc cao do my tnh GRAPE ch c th tnh c khai trin n cc.
Vi P2M2 chng ta c th tnh ton cc cp cao hn s dng my tnh GRAPE, v cc
s hng c biu din bng s phn b ca cc gi ht

2.3 Tng kt chng


Trong chng 2 ca kha lun chng ta tm hiu v c s ton hc, ci t
ca thut ton FMM c in v cc ci tin ca Anderson v Makino. Thut ton
FMM ging nh tn ca n th hin l mt thut ton nhanh c s dng tng tc
tnh lc trong bi ton m phng ng lc phn t. Nhng trong thut ton FMM
gc, do cc cng thc ton hc phc tp nn vic ci t FMM trn my tnh cn hn
ch v km ph bin hn so vi thut ton cy. Anderson v Makino vi cc ci tin
ca mnh lm cho vic ci t FMM tr nn d dng hn v t hiu nng tt hn
so vi thut ton gc. Trong chng 3 ca kha lun, chng ta s tm hiu v cch ng
dng phng php SVD trong bi ton m phng ng lc phn t.

Trang 30

Chng 3: p dng phng php SVD trong m phng ng lc phn t

Chng 3. P DNG PHNG PHP SVD TRONG


M PHNG NG LC PHN T
3.1 Phng php SVD
Phn tch SVD [17, 18], l mt phng php i s rt mnh v hu dng vi
nhiu ng dng trong x l tn hiu s v khoa hc thng k. Phng php SVD c
s dng nhiu trong nhiu bi ton c lin quan n vic tnh ton ma trn m nu p
dng cc phng php thng thng nh phng php kh Gauss hay phng php
phn tch LU s cho kt qu vi sai s ln.
Phng php SVD da trn nh l sau y trong i s tuyn tnh: bt k ma
trn A kch thc MxN no m s M N , c th c vit di dng tch ca mt ma
trn U trc giao theo ct c kch thc MxN , mt ma trn cho W c kch thc
NxN vi cc s trn ng cho l khng m, v ma trn chuyn v ca mt ma trn

trc giao V c kch thc NxN :

w1

w2

.
...

...

w N

(3.1)

Ma trn U v ma trn V trc giao theo ngha: cc ct ca chng l trc giao:


M

U
i =1

ik

V
j =1

jk

U in = kn

U jn = kn

1 k N

1 n N
1 k N

1 n N

(3.2)
(3.3)

trong kn = 1 nu k = n v bng 0 nu k n . Hoc biu din di dng ma trn:

(3.4)

V V l ma trn vung nn V ng thi l ma trn trc giao theo hng: V .V T = 1 .

Trang 31

Chng 3: p dng phng php SVD trong m phng ng lc phn t


Nu k hiu u i v vi tng ng l cc ct ca U v V, th phng trnh (3.1) c vit
di dng cc tch ngoi nh sau:
n

A = wi u i viT

(3.5)

i =1

Cc gi tr wi c gi l cc gi tr k d ca A . Khng mt tnh tng qut, chng ta


quy c rng cc gi tr k d ny c sp xp theo th t gim dn:
w1 w2 ... wn 0 . Ch s ca gi tr k d khc 0 cui cng trong dy c k hiu

l 0 , tc l wi = 0 vi i > 0 v wi > 0 vi i 0 .

3.1.1 SVD ca ma trn vung


Nu ma trn A l vung, c kch thc NxN th U , V v W tt c u l ma
trn vung cng c. Chng ta d dng tm c ma trn nghch o ca chng: U v
V l cc ma trn trc giao nn cc ma trn nghch o ca chng chnh l cc ma trn

chuyn v tng ng; W l ma trn cho v th ma trn nghch o ca W l ma trn


cho vi cc phn t l nghch o ca cc phn t w j . T phng trnh (3.1) suy ra
ma trn nghch o ca A l:
A 1 = V .[diag (1 / w j )].U T

(3.6)

Cng thc (3.6) s khng cn ng nu cc tn ti mt gi tr w j bng 0. Khi


ci t trn my tnh, nu gi tr w j gn ti 0, th nghch o ca gi tr ny s vt
qua gi tr cho php ca my tnh.
Ta nh ngha s iu kin ca ma ma trn A l t l gia s w j ln nht vi
s w j b nht. Ma trn A c gi l suy bin nu s iu kin ny l v hn v c
gi l c iu kin xu (ill-conditioned) nu s iu kin l qu ln theo ngha l s
nghch o ca n vt qu gi tr sai s ca my tnh (khong 10 6 vi chnh xc
n v 10 12 vi chnh xc kp).
Vi cc ma trn suy bin, c hai khi nim quan trng l range v nullspace.
Xt mt h phng trnh tuyn tnh biu din di dng ma trn sau y:
A.x = b

(3.7)

trong A l ma trn vung, b v x l cc vector. Phng trnh (3.7) nh ngha A


ging nh mt nh x tuyn tnh t khng gian vector x ti khng gian vector b . Nu
ma trn A l suy bin th tn ti mt khng gian con ca x , gi l nullspace c nh

Trang 32

Chng 3: p dng phng php SVD trong m phng ng lc phn t


x ti 0, A.x = 0 . S chiu ca nullspace (S cc vector x c lp tp tuyn tnh
trong ) c gi l nullity ca A .
Range ca A l mt khng gian con ca khng gian vector b sao cho vi mi
vector b thuc khng gian vector ny, tn ti vector x sao cho A.x = b . S chiu ca
khng gian con Range ny c gi l hng (rank) ca A .
i vi ma trn vung A R n.n ta c: rank ( A) + nullity ( A) = n . Nu ma trn A
khng suy bin th rank ( A) = n .
Bng phng php SVD, chng ta xc nh c c s trc giao cho
nullspace v range ca A . Tp cc ct j ca ma trn U tng ng vi cc s w j khc
khng to thnh c s trc giao ca range, vi quy c ni trong phn u,
{u1 ,..., u 0 } s to thnh c s trc giao ca range ( A) ; tp cc ct ct j ca V c cc s
w j bng 0 tc l tp {v 0 +1 ,..., v n } to thnh c s trc giao ca nullspace.

3.1.2 Gii h phng trnh tuyn tnh


a. Cch gii h phng trnh tuyn tnh bng SVD
Nh trnh by, phng php SVD c th c s dng gii h phng
trnh tuyn tnh. Xt h phng trnh di dng ma trn (3.7):
A.x = b

trong A l ma trn vung, x , b l cc vector. Nu A l khng suy bin (cc gi tr


wi khc 0 trong phn tch SVD), phng trnh (3.7) s c nghim duy nht l:
x = A 1 b

A 1 l ma trn nghch o ca ma trn A c tnh bng cng thc (3.6).

Nhng nu ma trn A l ma trn suy bin (tn ti mt hay nhiu cc gi tr k d wi


bng 0 hoc rt nh), h phng trnh s khng ch c nghim duy nht. Chng ta xt
hai trng hp:
Nu h phng trnh l thun nht tc l b = 0 , h c th c gii trc tip
nh SVD: cc ct ca ma trn V tng ng vi gi tr k d w j = 0 s l nghim ca
h.
Nu h phng trnh l khng thun nht, tc l vector b v phi ca (3.7)
khc vector 0, th h s v nghim (nu b range ( A) ) hoc c v s nghim (nu

Trang 33

Chng 3: p dng phng php SVD trong m phng ng lc phn t


b range ( A) , khi t hp tuyn tnh ca bt k cc vector nm trong khng gian

nullspace ca A v mt nghim c bit x 0 ca h s sinh ra mt nghim khc).


Trong trng hp mun tm mt vector nghim c bit x sao cho: di x

b nht, c th s dng phn tch SVD theo cch, thay th cc gi tr 1 / w j bi 0 nu


w j = 0 , sau tnh:

x = V .[diag (1 / w j )].(U T b)

(3.8)

Chng minh: Xem xt x + x' , y x' nm trong nullspace ca A . Gi W 1 l ma


trn nghch o ca ma trn W sau khi thay 1 / w j = 0 nu w j = 0 . Ta c:
(1)

( 2)

( 3)

x + x' = V .W 1 .U T .b + x ' = V .(W 1 .U T .b + V T .x ' ) = W 1 .U T .b + V T .x '

(3.9)

ng thc (1) ca (3.9) c suy ra t (3.8) v cc ng thc (2), (3) c suy ra do


tnh trc giao ma trn V .
Xt hai s hng ca v phi trong (3.9), ta thy s hng u c phn t th j khc
khng khi v ch khi w j 0 , trong khi s hng th hai, do x' nm trong nullspace ca
A nn c thnh phn th j khc khng khi v ch khi w j = 0 . Do di ca vector
( x + x ' ) b nht khi x' l vector khng. (iu phi chng minh)

Nu vector b khng nm trong khng gian range ca ma trn suy bin A , h


phng trnh (3.7) s v nghim. Nhng ta c th s dng cng thc (3.8) tnh
nghim xp x x . Vector ny s khng tha mn phng trnh ma trn (3.7). Nhng n
s cho nghim gn ng theo ngha bnh phng ti thiu tc l vi x xc nh bng
cng thc (3.8), ta c:
r = A.x b

(3.10)

s c gi tr cc tiu. S r c gi l phn d hay sai s ca nghim.


Vic chng minh nh l trn l tng t (3.9): Gi s ta thm cng thm vo
vector x mt vector x' bt k. Khi Ax b = A.x b + b' vi b' = A.x' . R rng l b'
nm trong range ca A . Ta c:
A.x b + b' = (U .W .V T ).(V .W 1 .U T .b) b + b'
= (U .W .W 1 .U T 1).b + b'

= U .[(W .W 1 1).U T .b + U T .b' ]


= (W .W 1 1).U T .b + U T .b'

Trang 34

(3.11)

Chng 3: p dng phng php SVD trong m phng ng lc phn t


Trong bin i trn (W .W 1 1) l mt ma trn cho vi cc thnh phn j khc 0 khi
v ch khi w j = 0 , trong khi U T .b' c cc thnh phn w j khc 0 khi v ch khi w j 0 ,
v b' nm trong range ca ma trn A . Do gi tr cc tiu s t c vi b'= 0 (iu
phi chng minh).

b. Vn chn tham s gn 0 trong phng php SVD


Trong phng trnh (3.7), gi s ma trn A c mt tt c cc gi tr k d w j
khc khng, nhng c mt vi gi tr rt nh, sao cho ma trn A c iu kin xu, tc
l t l ca gi tr k d w j b nht v gi tr k d w j ln nht nh hn sai s ca my
tnh. Khi phng php phn tch LU v phng php kh Gauss c th a ra
nghim cho h phng trnh, nhng khi nhn A vi vector nghim ca chng, kt qu
s c sai s rt ln so vi v phi b ca h. Trong trng hp , chng ta s khng
ha cc gi tr k d w j < vi l mt gi tr cho trc , tc l gn cc gi tr
w j = 0 trong trng hp w j < v s dng cng thc (3.8) tnh ra vector nghim

xp x. Vector nghim xp x ny s tt hn (theo ngha phn d A.x b nh hn) so


vi phng php trc tip v phng php SVD khi ta cha x l cc gi tr k d gn
0.
Trong p dng SVD trong thc hnh, chng ta phi xc nh r tham s gn
0 bng bao nhiu khng ha cc gi tr k d, v gi tr ca phn d A.x b bng
bao nhiu l chp nhn c. Vn chn tham s gn 0 cha c ch ra bng cng
thc hay l thuyt, do ty tng ng dng tham s gn 0 s c chn da trn thc
nghim.

3.1.3 Ci t phng php SVD trn my tnh


Trong kha lun, chng ti s dng li bn ci t SVD bng ngn ng C
trong ti liu tham kho [19]. C hai th tc chnh c s dng l:
(1) void svdcmp(float** a, int m, int n, float w[], float **v)

Input: Ma trn A c xc nh bng mng a[1...m][1...n] , m , n tng ng l s dng


v ct ca ma trn.
Output: Phn tch SVD, A = U .W .V T , trong ma trn a[1...m][1...n] l ma trn U
trong phn tch, ma trn cho W c ghi vo mng w[1...n] cc phn t trn ng

Trang 35

Chng 3: p dng phng php SVD trong m phng ng lc phn t


cho, v ma trn v[1..n][1..n] l ma trn V (khng phi l ma trn chuyn v ca V )
trong khai trin.
(2) void svbksb(float** u, loat w[], int m, int n, float b[],
float x[])

Th tc ny gii phng trnh dng A.x = b , y ma trn A c xc nh bng


mng hai chiu a[1...m][1...n] , mng w[1...n] v v[1..n][1..n] . y l cc output tr v t
th tc svdcmp(). b[1..m] l vector v phi ca phng trnh. x[1..n] l vector
nghim.
Trc khi p dng th tc svbksb() thu c nghim ca h phng trnh, cn gi
th tc zero_small_value(float** w, int n, double threshold) x
l cc gi tr gn 0 trong ma trn cho W . Vic chn gi tr threshold l ty tng ng
dng v c chn da trn thc nghim.
Chi tit v cc th tc trn c trong phn Ph lc A ca kha lun.

3.2 ng dng ca phng php SVD trong inner P2M2


3.2.1 Ci t thut ton FMM trn my GRAPE
a. Chc nng ca my GRAPE
r r

Chc nng ch yu ca GRAPE l tnh lc f (ri ) trn ht i ti v tr ri , v


r

th nng (ri ) . Mc d c nhiu cc loi my GRAPE khc nhau cho cc ng dng


khc nhau trong vt l thin vn (astrophysics) v ng lc phn t (Molecular
dynamics) nhng cc chc nng c bn ca chng l ging nhau.
r r

Lc f (ri ) v th nng (ri ) c biu din bng cng thc:


r r
N m (r r )
r r
j i
j
f (ri ) =
3
rs
j =1

(3.12)

v
N q
r
j
(ri ) =
j =1 rs

(3.13)

vi N l s lng cc ht trong h, r j v m j l v tr v khi lng ca ht j , v rs


c gi l khong cch c mm ha gia ht i v ht j c nh ngha:
r r
rs = r i r j

+ 2 y l tham s lm mm.

Trang 36

Chng 3: p dng phng php SVD trong m phng ng lc phn t


r r

r r

tnh lc f (ri ) , cn gi cc d liu cn thit ri , r j , q j , v N t my tnh


r r

thng thng ti my GRAPE. GRAPE s tnh cc lc f (ri ) vi mi i sau gi tr


r

li kt qu n my tnh thng thng. Th nng (ri ) c tnh theo cch tng t.

b. Ci t thut ton FMM trn my GRAPE


Thut ton FMM bao gm 5 pha (xem phn 2.1.2 a), c th l: to cy, chuyn
i M2M, bin i M2L, bin i L2L, v tnh lc. Pha tnh lc bao gm tnh cc lc
gy ra bi cc ht gn v cc ht xa.
Trong thut ton FMM gc, ch c phn tnh lc trc tip do cc ht gn gy
ra l c th thc hin trn my tnh GRAPE. Trong phn ny, GRAPE s tnh trc tip
cc lc tc dng trn mi hng c dng nh (3.12).
Chau, Kawai, Ebisuzaki [13] ci tin thut ton FMM gc my GRAPE
c th thc hin tnh ton trong pha M2L, pha chim hu ht thi gian tnh ton. Vi
ci tin ny, GRAPE c th thc hin tnh ton trong pha M2L thng qua tnh gi tr
th nng t cc gi ht. Trong pha L2L, gi tr th nng c khai trin a phng v
c dch chuyn tm khai trin, s dng phng php ca Anderson.
Sau y l m t ngn gn ca ci t ny:

i. To cy
Pha to cy khng c g thay i. Phn ny c thc hin ging nh trong
phng php FMM gc.

ii. Bin i M2M


Ti pha M2M, tnh cc v tr v khi lng (in tch) ca cc gi ht thay cho
vic tnh khai trin a cc nh trong thut ton FMM gc.
Th tc bt u t cc nt l. T v tr v khi lng ca cc ht vt l, ta tnh
cc v tr v khi lng ca cc nt l. Sau cc nt khng phi l nt l c tnh t
cc v tr v cc khi lng ca cc gi ht ca cc nt con. Th tc ny tip tc cho
n khi t ti nt gc. Th tc ny hon ton c thc hin trn my tnh thng.

iii. Bin i M2L


Pha M2L c thc hin trn my tnh GRAPE. S khc nhau gia phng
php FMM gc v phng php ny l chng ta khng s dng cng thc

Trang 37

Chng 3: p dng phng php SVD trong m phng ng lc phn t


chuyn khai trin a cc thnh khai trin cc b. Chng ta tnh trc tip cc gi tr th
nng gy ra do cc gi ht trong danh sch tng tc ca mi nt.

iv. Bin i L2L


Pha L2L c thc hin ging nh phng php ca Anderson thc hin.
Chng ta s dng cng thc khai trin trong (2.21) (phn 2.2.1) chuyn khai trin
a phng ca mi nt thnh khai trin a phng ca nt con.

v. Tnh lc (gn)
Lc do cc ht gn gy ra c tnh trc tip bng tnh cc lc tng tc
ht-ht. Phn ny c thc hin trn my chuyn dng GRAPE.

vi. Tnh lc (xa)


S dng cng thc khai trin trong (2.21) (phn 2.2.1), th nng xa trn mt
r

ht v tr r c th c tnh t tp cc gi tr th nng ca nt l cha cc ht . C


ngha l lc xa c tnh bng o hm ca cng thc (2.22):
r r
p
K

ur s i r
r
r
r
r n2

Pn (u ) ( 2n + 1) n g ( as i ) wi
(r ) = nr Pn (u ) +
2
a
i =1 n = 0
1 u

(3.14)

r r

trong u = si .r / r .
Tt c cc tnh ton trong pha ny c thc hin trn my tnh thng.

3.2.2 ng dng ca SVD trong ci t inner P2M2


Ci tin trn gii quyt tnh trng tht c chai trong phng php FMM,
v pha bin i M2L c thc hin trn my tnh GRAPE. By gi, phn chim nhiu
thi gian tnh ton nht l tnh ton lc xa. Cng thc (3.14) l phc tp, v th s
chim thi gian ln trong ton b thi gian tnh ton.
Trong [13], Chau, Kawai, Ebisuzaki a ra mt cch ci t khc tnh
ton cc lc xa. tng chnh ca ci tin ny l s dng bin i A2P tnh phn
b ca cc gi ht sinh ra trng th nng cho bi cng thc khai trin trong ca
Anderson (cng thc 2.21 phn 2.2.1). Khi cc phn b ca cc gi ht c tnh, pha
L2L c th c thc hin dng cng thc khai trin trong P2M2 (cng thc 2.38 phn
2.22 b).

Trang 38

Chng 3: p dng phng php SVD trong m phng ng lc phn t


2l + 1 a

m j = mi
K ri
i =1
l =0
p

l +1

Pl (cos ij )

Sau pha tnh lc s c thc hin hon ton trn my GRAPE.

r
F,

a
b

Cc gi tr th nng

Gi ht

Hnh 12: Tnh th nng v lc t phn phi khi lng ca cc gi ht


Trong bin i A2P, bc u tin, chng ta phn phi cc gi ht trn mt
mt cu vi bn knh b s dng t -design cu. y, b ln hn bn knh a ca hnh
r

cu trong gi tr th nng g ( as ) c nh ngha trong cng thc khai trin ca


Anderson. Theo cng thc (2.38), c th thay i khi lng ca cc ht. V th quan
h:
mj

Rr
j =1

r
r = (asi )
asi

(3.15)
r

tha mn vi mi i = 1,, K . S dng mt ma trn R = {1 / R j asi } v vector


r
r
r
r
r
M = [m1 , m2 ,..., mk ]T v P = [ (as1 ), ( as 2 ),..., ( as K )] , chng ta c th vit li cng

thc (3.15) di dng:


r
r
RM = P

(3.16)

Trong bc tip theo, chng ta gii h phng trnh (3.16) thu c cc khi lng
m j . Do s sai khc ln ca cc bn knh b v a , nn h phng trnh (3.16) tr nn

gn suy bin vi bc khai trin cao. Vi h phng trnh nh vy, phng php kh
Gauss cho kt qu khng tt, v nh ni trn p dng phng php phn tch
SVD s cho kt qu vi sai s nh hn.

Trang 39

Chng 3: p dng phng php SVD trong m phng ng lc phn t


Tuy nhin, chng ta vn c th ci tin tng chnh xc ca cc tnh ton
xp x. l chn tham s gn 0 thch hp trong phng php SVD v chn bn
knh b no l tt. Trong [13], cc tc gi tm ra bn knh b = 6,0 bng thc nghim
vi bc khai trin p = 5,0 khi cc ht nm trong mt hnh hp lp phng vi kch
thc bng 1,0 . Anderson ([2]) cng xc nh bn knh nh a thch hp l khong
0,4. Trong kha lun ny, chng ti s a ra cch kho st bng thc nghim
nghin cu nh hng ca tham s gn 0 i vi chnh xc trong tnh ton lc
xp x.

3.3 Tng kt chng


Trong chng 3 ca kha lun, chng ta tm hiu v phng php phn tch
SVD, cc p dng ca SVD trong tnh ton ma trn. Nu mt h phng trnh tuyn
tnh l k d, hoc gn k d theo ngha cc gi tr k d ca ma trn h s xp x gi tr
0, trong khi phng php kh Gauss khng th p dng hoc cho kt qu vi sai s
ln th phng php SVD a ra vector nghim vi sai s nh nht theo ngha bnh
phng ti thiu.
Chng 3 cng trnh by mt phng php ci t FMM trn my tnh
GRAPE c a ra trong [13], cc ci tin s dng khai trin inner P2M2, v cch
p dng phng php phn tch SVD tnh phn phi khi lng ca cc gi ht.
Tuy nhin, vn c th ci tin ci t ny hn na. l vn chn tham s
gn 0 trong SVD trong bin i A2P. Vn ny s c nghin cu qua thc
nghim.

Trang 40

Chng 4: Kt qu thc nghim v nh gi

Chng 4. KT QU THC NGHIM V NH GI


4.1 Mi trng thc nghim
4.1.1 Phn cng
My Pentium IV, chip 2.8 GHz, Ram 512 MB

4.1.2 Phn mm
Cc th nghim c thc hin bng ngn ng lp trnh C trn h iu hnh
Linux, phin bn Fedora Core 3. u im ca ngn ng lp trnh C l: y l mt
ngn ng rt mnh vi th vin ton hc phong ph, thch hp cho tnh ton khoa hc.
trnh by cc kt qu th nghim, chng ti s dng chng trnh gnuplot, mt
chng trnh phn mm m ngun m c pht trin bi t chc GNU, dng v
th hm s, trnh by kt qu thc nghim di dng th, biu bng trong khng
gian 2 v 3 chiu. Ngoi ra chng ti c s dng li ci t phng php FMM do
Chau, Kawai, Ebisuzaki [13] thc hin.
Bng 3: Cng c s dng trong th nghim
STT
1
2
3
4

Tn phn mm (cng c) s dng


Ngn ng lp trnh C
H iu hnh Linux Fedora Core 3
Chng trnh Gnuplot
Ci t thut ton FMM

Ngun
http://fedora.redhat.com/
http://gnuplot.info/
Ti liu tham kho [13]

4.2 Th nghim phng php khai trin a cc nhanh FMM


4.2.1 Thi gian tnh ton ca phng php FMM
th nghim phng php FMM, chng ti cho s ht trong h thay i, sau ghi
li thi gian tnh ton trong mi bc m phng, v so snh vi phng php tnh ton
trc tip tng tc ht-ht. Trong th nghim cp khai trin s dng cp 4.
Kt qu thu c nh trong bng sau. K hiu mK c ngha l s ht N = m*1024 ht.

Trang 41

Chng 4: Kt qu thc nghim v nh gi


Bng 4: Thi gian tnh ton ca FMM vi s ht thay i
S ht (N)
1K
2K
4K
8K
16K
32K
64K
128K
256K
512K
1024K
2048K
4096K

Tng (s)
0,077240
0,232300
0,544597
1,137916
3,472888
7,503617
13,427825
40,955762
94,450049
213,114363
479,507316
1021,350584
2042,701169

Bng 5: Thi gian tnh ton trc tip vi s ht thay i


S ht (N)
1K
2K
4K
8K
16K
32K
64K
128K
256K
512K
1024K
2048K
4096K

Thi gian tnh ton (s)


0,05956
0,20723
0,79719
3,18779
12,69657
53,63753
213,04669
852,18676
3408,74704
13634,98816
54539,95264
218159,81056
872639,24224

V l do thi gian (Thi gian cho th nghim vi s ht ln rt di), s ht th nghim


trong phng php FMM ch gii hn n 512K ht, v s ht th nghim trong
phng php tnh ton trc tip ch n 64K ht. Cc s liu i vi s lng ht ln
hn, c nh gi trn c s l thuyt: thut ton FMM c phc tp O (N ) v
thut ton tnh lc trc tip c phc tp l O( N 2 ) .

Trang 42

Chng 4: Kt qu thc nghim v nh gi


th sau y so snh thi gian tnh lc ca hai thut ton.

Hnh 13: Thi gian tnh lc ca thut ton trc tip (trn) v FMM (di)

4.2.2 nh gi kt qu
T kt qu tnh ton trn c th rt ra nhn xt:

Vi s lng ht nh, thi gian tnh ton gia hai phng php FMM v
phng php tnh ton trc tip l chnh lch khng ng k. Trong trng hp
s ht t hn 5000 ht, hai phng php gn nh tng ng v thi gian tnh
ton.

Vi s lng ht ln, thi gian tnh ton ca FMM tt hn thi gian tnh ton
ca phng php trc tip vi cng s ht. Nu thc thi trn my tnh chuyn
dng GRAPE, thi gian tnh ton ca FMM c th nhanh hn t 100 n 1000
ln so vi phng php trc tip.

Trang 43

Chng 4: Kt qu thc nghim v nh gi

4.3 Th nghim phng php SVD trong bin i A2P


4.3.1 chnh xc ca khai trin inner P2M2 v bin i A2P
Nh trnh by chng 3, vic tnh cc lc bi cc ht xa dng cng
thc o hm (3.14) l phc tp v chim nhiu thi gian tnh ton. V vy thay v
dng cng thc o hm ny, chng ta dng bin i A2P vi cng thc khai trin
inner P2M2 (cng thc 2.38). Bin i A2P c u im l d ci t, bng bin i
ny pha L2L c th c thc hin trn my tnh chuyn dng GRAPE. Mt vn
cn nghin cu l chnh xc ca bin i A2P v khai trin inner P2M2. y
chng ti a ra kt qu th nghim nh gi chnh xc ca cc bin i ny.

a. Phng php thc nghim


Cc bc chnh ca trong th nghim l:
1. t mt ht L ti ta (r , , / 2) , ht L c khi lng m = 1,0. Cho r chy
t 1,0 n 10,0 .
2. Ly phn phi chun ha ca cc ht trong hnh lp phng n v c tm
gc ta . Trong th nghim ny, chng ti s dng s ht l 1000 ht.
3. Tnh ton th nng, lc gy ra bi ht L ti 1000 ht trn bng phng php
tnh ton trc tip.
4. Tnh cc gi tr th nng gy ra bi ht L ti cc v tr c nh ngha bi t design cu trn b mt ca mt hnh cu c bn knh a = 0,4 c tm ti gc ta
. S lng cc im cn tnh ton ph thuc vo cp khai trin p . Trong th
nghim ny, bc khai trin ln lt c th t 1 n 8.
5. S dng bin i A2P cho khai trin cc b thu c bc 4, tc l s dng
cng thc (3.16) trong chng 3 thu c cc khi lng ca cc gi ht
M j trn b mt ca mt hnh cu c bn knh b = 6 v c tm gc ta . S

lng v v tr ca cc gi ht ph thuc vo bc khai trin p .


6. Tnh ton lc v th nng gy ra bi cc gi ht ti 1000 ht c phn phi
trong bc 2.

Trang 44

Chng 4: Kt qu thc nghim v nh gi


7. So snh kt qu vi lc v th nng tnh bng phng php trc tip. a ra sai
s theo ngha trung bnh bnh phng (root mean square). Sai s trung bnh
bnh phng ny c tnh bng cng thc:
=

pi p'i
pi

r
r
f i f 'i
v 2
fi

F =

(4.1)
2

(4.2)

trong , F l cc sai s trung bnh bnh phng ca th nng v lc tnh


r

bng phng php xp x; p i , f i , p' i , f 'i ln lt l th nng v lc c tnh


bng phng php trc tip v tnh xp x.
8. V th lin h gia r v chnh xc ca th nng v lc trong phng php
tnh xp x.

b. Kt qu thc nghim
Sai s trung bnh bnh phng ca th nng v lc tng ng c v trn
hnh 14 v 15.

Trang 45

Chng 4: Kt qu thc nghim v nh gi


Hnh 14: Sai s trung bnh bnh phng ca th nng c tnh bng khai trin
inner P2M2 v bin i A2P. T trn xung, 8 ng cong tng ng vi cc bc
khai trin p = 1, 2, 3, 4, 5, 6, 7, 8

Hnh 15: Sai s trung bnh bnh phng ca lc c tnh bng khai trin inner
P2M2 v bin i A2P. T trn xung, 8 ng cong tng ng vi cc bc khai
trin p = 1, 2, 3, 4, 5, 6, 7, 8
T hnh 14, 15, c th thy vi bc khai trin p = 7 v p = 8 , sai s bt u
ngng gim khi r 6 .

4.3.2 nh hng ca tham s gn khng trong phng php SVD n


chnh xc ca thut ton FMM
Nh trnh by trong phng php SVD, vic chn tham s gn 0 s nh
hng n chnh xc trong vic tnh nghim xp x. Vic chn tham s gn 0 ph
thuc vo ng dng. V vy chng ti xc nh tham s gn 0 theo thc nghim.

a. Phng php thc nghim


Trong phng php SVD, s iu kin c nh ngha l t s gia s w j ln
nht v s w j b nht, trong w j l cc phn t trn ng cho ca ma trn cho

Trang 46

Chng 4: Kt qu thc nghim v nh gi


W thu c t phn tch SVD. Nu s iu kin qu ln, theo ngha nghch o ca

n xp x vi chnh xc cho php trong tnh ton du phy ng ca my tnh (xp


x 10 6 vi chnh xc n v 10 12 vi chnh xc kp), ma trn A c gi l c
iu kin xu. Xt h cho di dng ma trn:
A.x = b

trong A l ma trn vung, x v b l cc vector.


Trong trng hp ma trn A c iu kin xu, cch tip cn chng ti s dng
trong thc nghim l xc nh trc mt tham s gn 0 . Vi cc s w j sao cho
w j / max < , ta gn w j = 0 . y max l gi tr ln nht trong cc s trn ng cho

ca ma trn W trong phn tch SVD ca ma trn A . Sau khi x l cc gi tr ny, gi


th tc svbksb (xem chi tit trong ph lc A) gii h phng trnh.
Cc bc th nghim tm tham s gn 0 thch hp nh sau:
T bc 1 n bc 4, tng t nh trong phn (4.3.1 a), trong bc 1 chng
ti chn bn knh r = 6,0 , trong bc 4 cp khai trin l t 1 n 10.
Trong bc 5, trong phn tnh khi lng ca cc gi ht trn hnh cu bn
knh b = 6,0 , trc khi gi th tc svbksb(), chng ti x l cc gi tr k d gn khng
vi cc tham s gn 0 thay i t = 10 6 gim dn n 10 14 . Kt qu tnh sai s
trong bc 7 c ghi vo file phn tch. Sau v th lin h gia tham s gn
0 vi sai s tnh ton.

b. Kt qu thc nghim
Hnh 16, 17, 18, 19 th hin m t quan h gia tham s gn 0 vi sai s ca tnh th
nng v tnh lc xp x.
T kt qu thc nghim ta c nhn xt:
Vi cc bc khai trin thp (bc khai trin nh hn 4), chn tham s gn 0 khng
nh hng n chnh xc tnh ton.
Vi bc khai trin cao, th tham s gn 0 cng nh thu c chnh xc tt.
Nu chn tham s gn 0 qu nh (khong 1,0e-14), chnh xc khng thay i
so vi phng php SVD khi cha x l cc gi tr k d gn 0.
Bng 6 th hin cc tham s gn 0 c chn vi tng bc khai trin. Tham s gn 0
c chn vi bc khai trin t 4 tr ln.
Trang 47

Chng 4: Kt qu thc nghim v nh gi

Hnh 16: Sai s trung bnh bnh phng ca th nng ng vi cc tham s gn 0


khc nhau. T trn xung, cc ng tng ng vi bc khai trin t 1 n 5

Hnh 17 : Sai s trung bnh bnh phng ca th nng ng vi cc tham s gn 0


khc nhau. T trn xung, cc ng tng ng vi bc khai trin t 6 n 10

Trang 48

Chng 4: Kt qu thc nghim v nh gi

Hnh 18: Sai s trung bnh bnh phng ca lc ng vi cc tham s gn 0 khc


nhau. T trn xung, cc ng tng ng vi bc khai trin t 1 n 5

Hnh 19 : Sai s trung bnh bnh phng ca lc ng vi cc tham s gn 0 khc


nhau. T trn xung, cc ng tng ng vi bc khai trin t 6 n 10

Trang 49

Chng 4: Kt qu thc nghim v nh gi


Bng 6: Tham s gn 0 ng vi cc mc khai trin khc nhau
Bc khai trin
4
5
6
7
8
9
10

Tham s gn 0
2,0e-08
4,0e-09
5,0e-12
2,0e-13
2,0e-13
2,0e-13
2,0e-13

4.4 Tng kt chng


Trong chng 4 ca kha lun, chng ti trnh by cc thc nghim ca
mnh trong vic nh gi hiu nng ca thut ton FMM, chnh xc ca khai trin
inner P2M2 v bin i A2P c s dng phng php SVD. nh hng ca phng
php SVD n chnh xc ca thut ton cng c kho st. Cc tham s gn
0 c tm bng thc nghim. Tuy nhin do nhng hn ch v phn cng, cc th
nghim cn b gii hn v s lng ht trong h. Nu c iu kin, chng ti hy vng
s c th nghim trn cc my chuyn dng cho m phng ng lc phn t
nh gi kt qu vi s lng ht ln hn.

Trang 50

KT LUN

KT LUN
Kt qu t c
Trong kha lun, chng ti h thng ha mt s vn l thuyt trong bi
ton m phng ng lc phn t, cc cch tip cn trong bi ton tng tc tnh lc
trong m phng ng lc phn t. Cc nghin cu gn y v phng php khai trin
a cc nhanh FMM nh cc ci tin ca Anderson, Makino cng c trnh by
trong kha lun.Chng ti nghin cu phng php phn tch SVD v cch p dng
phng php SVD trong bin i A2P v khai trin inner P2M2. Trong kha lun
chng ti cng a ra phng php nh gi v chnh xc ca phng php bin
i A2P v khai trin inner P2M2.
Sau mt qu trnh tm hiu v nghin cu chng ti a ra c ci tin
trong vn p dng phng php SVD, l vic x l cc gi tr k d gn khng
tng chnh xc trong tnh lc xp x. Kt qu cho thy i vi cp khai trin cao,
vic p dng ci tin ny cho kt qu tt.
Cng trong qu trnh nghin cu, chng ti thu c nhng kin thc v k
nng qu bu v s dng ngn ng lp trnh C, tnh ton du phy ng v k nng s
dng h iu hnh Linux.

Hng pht trin


M ci t ca thut ton FMM m chng ti c c vit trn ngn ng C
nn rt kh bo tr v nng cp. V vy trong thi gian ti, chng ti d nh s chuyn
m ny sang ngn ng hng i tng C++.
Trong phng php bin i A2P, cn mt ci tin khc na l thay i v tr
cc im trong t design cu. Chng ti nghin cu ci tin ny, nhng do nhng
hn ch v mt thi gian v l thuyt nn kt qu thu c cha tt. Chng ti s tip
tc nghin cu v mt l thuyt v thc hnh ci tin ny. Ngoi ra, chng ti s tm
hiu thm v cc bin th ca thut ton FMM ang c nghin cu trong thi gian
gn y, nh ci tin ca Ying [21, 22] v tin hnh song song ha thut ton FMM.
Cc ng dng m phng ng lc phn t trn th gii l kh ph bin
nhng Vit Nam l cn kh hn ch. V vy mt hng nghin cu tip theo ca

Trang 51

KT LUN
chng ti l ng dng cc phng php m phng ng lc phn t xy dng
cc h m phng vt l, ha hc s dng trong nghin cu khoa hc v trong gio dc.

Trang 52

Ph lc A: Ci t SVD bng ngn ng C

Ph lc A: Ci t SVD bng ngn ng C


A1. Th tc svdcmp()
#include <math.h>
#define NRANSI
#include "nrutil.h"
void svdcmp(float **a, int m, int n, float w[], float **v)
{
float pythag(float a, float b);
int flag,i,its,j,jj,k,l,nm;
float anorm,c,f,g,h,s,scale,x,y,z,*rv1;
rv1=vector(1,n);
g=scale=anorm=0.0;
for (i=1;i<=n;i++) {
l=i+1;
rv1[i]=scale*g;
g=s=scale=0.0;
if (i <= m) {
for (k=i;k<=m;k++) scale += fabs(a[k][i]);
if (scale) {
for (k=i;k<=m;k++) {
a[k][i] /= scale;
s += a[k][i]*a[k][i];
}
f=a[i][i];
g = -SIGN(sqrt(s),f);
h=f*g-s;
a[i][i]=f-g;
for (j=l;j<=n;j++) {
for (s=0.0,k=i;k<=m;k++)
s += a[k][i]*a[k][j];
f=s/h;
for (k=i;k<=m;k++)
a[k][j] += f*a[k][i];
}
for (k=i;k<=m;k++) a[k][i] *= scale;
}
}
w[i]=scale *g;
g=s=scale=0.0;
if (i <= m && i != n) {
for (k=l;k<=n;k++) scale += fabs(a[i][k]);
if (scale) {
for (k=l;k<=n;k++) {
a[i][k] /= scale;
s += a[i][k]*a[i][k];
}

Trang 53

Ph lc A: Ci t SVD bng ngn ng C


f=a[i][l];
g = -SIGN(sqrt(s),f);
h=f*g-s;
a[i][l]=f-g;
for (k=l;k<=n;k++) rv1[k]=a[i][k]/h;
for (j=l;j<=m;j++) {
for (s=0.0,k=l;k<=n;k++)
s += a[j][k]*a[i][k];
for (k=l;k<=n;k++)
a[j][k] += s*rv1[k];
}
for (k=l;k<=n;k++) a[i][k] *= scale;

}
}
anorm=FMAX(anorm,(fabs(w[i])+fabs(rv1[i])));

}
for (i=n;i>=1;i--) {
if (i < n) {
if (g) {
for (j=l;j<=n;j++)
v[j][i]=(a[i][j]/a[i][l])/g;
for (j=l;j<=n;j++) {
for (s=0.0,k=l;k<=n;k++)
s += a[i][k]*v[k][j];
for (k=l;k<=n;k++)
v[k][j] += s*v[k][i];
}
}
for (j=l;j<=n;j++) v[i][j]=v[j][i]=0.0;
}
v[i][i]=1.0;
g=rv1[i];
l=i;
}
for (i=IMIN(m,n);i>=1;i--) {
l=i+1;
g=w[i];
for (j=l;j<=n;j++) a[i][j]=0.0;
if (g) {
g=1.0/g;
for (j=l;j<=n;j++) {
for (s=0.0,k=l;k<=m;k++)
s += a[k][i]*a[k][j];
f=(s/a[i][i])*g;
for (k=i;k<=m;k++) a[k][j] += f*a[k][i];
}
for (j=i;j<=m;j++) a[j][i] *= g;
} else for (j=i;j<=m;j++) a[j][i]=0.0;
++a[i][i];
}
for (k=n;k>=1;k--) {
for (its=1;its<=30;its++) {
flag=1;

Trang 54

Ph lc A: Ci t SVD bng ngn ng C


for (l=k;l>=1;l--) {
nm=l-1;
if ((float)(fabs(rv1[l])+anorm)== anorm)
{
flag=0;
break;
}
if ((float)(fabs(w[nm])+anorm) == anorm)
break;
}
if (flag) {
c=0.0;
s=1.0;
for (i=l;i<=k;i++) {
f=s*rv1[i];
rv1[i]=c*rv1[i];
if ((float)(fabs(f)+anorm)== norm)
break;
g=w[i];
h=pythag(f,g);
w[i]=h;
h=1.0/h;
c=g*h;
s = -f*h;
for (j=1;j<=m;j++) {
y=a[j][nm];
z=a[j][i];
a[j][nm]=y*c+z*s;
a[j][i]=z*c-y*s;
}
}
}
z=w[k];
if (l == k) {
if (z < 0.0) {
w[k] = -z;
for (j=1;j<=n;j++)
v[j][k] = -v[j][k];
}
break;
}
if (its == 30)
nrerror("no convergence in 30 svdcmp
iterations");
x=w[l];
nm=k-1;
y=w[nm];
g=rv1[nm];
h=rv1[k];
f=((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y);
g=pythag(f,1.0);
f=((x-z)*(x+z)+h*((y/(f+SIGN(g,f)))-h))/x;
c=s=1.0;

Trang 55

Ph lc A: Ci t SVD bng ngn ng C


for (j=l;j<=nm;j++) {
i=j+1;
g=rv1[i];
y=w[i];
h=s*g;
g=c*g;
z=pythag(f,h);
rv1[j]=z;
c=f/z;
s=h/z;
f=x*c+g*s;
g = g*c-x*s;
h=y*s;
y *= c;
for (jj=1;jj<=n;jj++) {
x=v[jj][j];
z=v[jj][i];
v[jj][j]=x*c+z*s;
v[jj][i]=z*c-x*s;
}
z=pythag(f,h);
w[j]=z;
if (z) {
z=1.0/z;
c=f*z;
s=h*z;
}
f=c*g+s*y;
x=c*y-s*g;
for (jj=1;jj<=m;jj++) {
y=a[jj][j];
z=a[jj][i];
a[jj][j]=y*c+z*s;
a[jj][i]=z*c-y*s;
}
}
rv1[l]=0.0;
rv1[k]=f;
w[k]=x;
}
}
free_vector(rv1,1,n);
}
#undef NRANSI
float pythag(float a, float b)
/* Tnh (a 2 + b 2 )1 / 2 m khng b li trn s */
{
float absa, absb;
absa=fabs(a);
absb=fabs(b);
if (absa > absb)
return absa*sqrt(1.0+SQR(absb/absa));

Trang 56

Ph lc A: Ci t SVD bng ngn ng C


else return (absb == 0.0 ? 0.0 :
absb*sqrt(1.0+SQR(absa/absb));
}

A2. Th tc svbksb()
#include "nrutil.h"
void svbksb(double **u, double w[], double **v, int m, int n,
double b[], double x[])
{
int jj,j,i;
double s,*tmp;
tmp=dvector(1,n);
for (j=1;j<=n;j++) {
s=0.0;
if (w[j]) {
for (i=1;i<=m;i++) s += u[i][j]*b[i];
s /= w[j];
}
tmp[j]=s;
}
for (j=1;j<=n;j++) {
s=0.0;
for (jj=1;jj<=n;jj++) s += v[j][jj]*tmp[jj];
x[j]=s;
}
free_dvector(tmp,1,n);
}

A3. Th tc zero_small_values()
void zero_small_values(double* w, int n, double threshold) {
int i;
double wmin, wmax;
wmax= 0.0;
for(i=1; i<= n; i++)
if( w[i] > wmax) wmax= w[i];
//Gi tr threshold cchn ty tng ng dng
wmin= wmax*threshold;
for(i=1; i <= n; i++)
if(w[i] < wmin) w[i]=0.0;
}

Trang 57

TI LIU THAM KHO

TI LIU THAM KHO


[1] Michael P. Allen, Introduction to Molecular Dynamics Simulation, John von
Neumann Institute for Computing (2004), p. 1-28
[2] C. R. Anderson, An implementation of the fast multipole method without
multipoles, SIAM J. Sci. Stat. Comput. vol 13, (1992), p. 923-947
[3] A. W. Appel, An efficient program for many-body simulation. SIAM J. Sci. Stat.
Comput. vol. 16, n. 1, (1985), p. 85-103
[4] J. Barnes and P. Hut, A hierarchical O(NlogN) force calculation algorithm, Nature
324, (1986), p. 446-449
[5] Rick Beatson, Leslie Greengard, A short cource on fast multipole methods, Oxford
University Press, (1997)
[6] G. Beylkin, R. Coifman, and V. Rokhlin. The fast wavelet transform and numerical
algorithms. Comm. Pure and Appl. Math, (1991), 44, p. 141-183
[7] L. Greengard, V. Rokhlin, A fast Algorithm for Particle Simulations, Journal of
Computational Physics (ISSN 0021-9991), vol. 73, Dec. 1987, p. 325-348
[8] L. Greengard, V. Rokhlin, A new version of the fast multipole method for the
Laplace equation in three dimension, Acta Numerica 6 (1997), p. 229-269
[9] W. Hackbush, Z. P. Nowak, On the fast matrix multiplication in the boundary
element method by panel clustering, Numer. Math., 54, (1989), p. 463-491
[10] R. H. Hardin and N. J. Sloane, MacLarens improved snub cube and other new
spherical designs in three dimensions, Discrete and Computational Geometry, 15,
(1996), p. 429-441
[11] Pieter Heres, An introduction to Fast Multipole Method, Seminar Scientific
Computing, March 6, 2002
[12] A. Kawai, J. Makino, A simple Formulation of the Fast Multipole Method:
Pseudo-Particle Multipole Method, eprint arXiv:astro-ph/9812431, (1998), p. 1-13

Trang 58

TI LIU THAM KHO


[13] N. H. Chau, A. Kawai, T. Ebisuzaki, A new implementation of fast multipole
algorithm on special-purpose computer MDGRAPE-2, Proceeding of Annual Meeting
of Molecular Simulation Society of Japan, Niigata, Dec 16-18, 2002
[14] A. Kawai, J. Makino, T. Ebisuzaki, Performance analysis of high-accuracy tree
code based on the pseudoparticle multipole method, The Astrophysical Journal
Supplement 151 (2004), p. 13-33
[15] J. Makino and M. Taiji, Special purpose computer for scientific simulations the
GRAPE system, John Wiley and Sons, Chichester, 1998
[16] J. Makino, Yet another fast multipole method without multipoles-pseudoparticles
multipole method, Journal of Computational Physics, 151 (1999), p. 910-920
[17] Thomas Melzer, SVD and its Application to Generalized Egienvalue problems,
June 8, 2004, p. 1-15
[18] William. H. Press, Saul A. Teukolsky, William T. Vertterling, Brian P. Flannery
Numerical in C, The Art of Sientific computing Second Edition, Cambridge University
Pres, 1988-1992, chapter 15
[19] Robin Schoemaker, An implementation of the Fast Multipole Methods without
multipoles, Seminar Computing Group Seminar, Spring 2002
[20] D. Sugimoto, Y. Chikada, J. Makino, T. Ito, T. Ebisuzaki, and M. Umemura, A
special-purpose computer for gravitational many-body problems, Nature, 345 (1990),
p. 33-35
[21] L. Ying, G. Biros, D. Zorin, H. Langston, A new parallel kernel-independent fast
multipole method, Proceedings of the ACM/IEEE SC2003, Phoenix, Arizona, USA,
November, 2003, p. 15-21
[22] L. Ying, G. Biros, D. Zorin, A kernel-independent adaptive fast multipole
algorithm in two and three dimensions, Journal of Computational Physics, 196 (2004)
p. 591-626
[23] David C. Young, Computational Chemistry: A practice guide for Applying
Techniques to Real-World Problems, John Willey & Sons. Inc (2001), p. 60-62
[24] Website: http://www.amara.com/papers/nbody.html

Trang 59