ÌÝèïäïé Monte Carlo êáé ôï ìïíôÝëï Ising

ÅììáíïõÞë Í. ÊïõêÜñáò
A.M.: 198

2

Ðåñßëçøç
ÐáñïõóéÜæïõìå âáóéêÞ èåùñßá õðïëïãéóìþí ìå ìåèüäïõò Monte Carlo. Åöáñìüæïõìå ãéá ôï ìïíïäéÜóôáôï êáé äéäéÜóôáôï ìïíôÝëï Ising. Ï êþäéêáò åßíáé
ãñáììÝíïò óå C++. Ðáñáôßèåíôáé ôá áðïôåëÝóìáôá ôùí õðïëïãéóìþí êáé
ó÷üëéá áõôþí.

2

Ðåñéå÷üìåíá
1.
2.

3.

ÅéóáãùãÞ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ÁðëÝò åöáñìïãÝò ìåèüäùí Monte Carlo . . . . . . . . . . . . . .
2.1 Õðïëïãéóìüò ïëïêëçñùìÜôùí . . . . . . . . . . . . . . . . .
2.2 Õðïëïãéóìüò ôïõ ð . . . . . . . . . . . . . . . . . . . . . . .
2.3 Õðïëïãéóìüò ïëïêëçñùìÜôùí ìå Importance Sampling MC
ÌïíôÝëï Ising êáé áëãüñéèìïò Metropolis . . . . . . . . . . . . . .
3.1 ÌïíôÝëï Ising . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 ÌåôáôñïðÝò öÜóçò . . . . . . . . . . . . . . . . . . . . . . .
3.3 Áëãüñéèìïò Metropolis . . . . . . . . . . . . . . . . . . . . .
3.4 ÌïíïäéÜóôáôï ìïíôÝëï Ising . . . . . . . . . . . . . . . . . .
3.5 ÄéäéÜóôáôï ìïíôÝëï Ising . . . . . . . . . . . . . . . . . . . .

A Source Code
1. MCINT.CPP .
2. MCPI.CPP . .
3. MCINTIS.CPP
4. ISINGCH.CPP
5. ISINGL.CPP .

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

3

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

5
5
6
7
8
11
11
12
14
15
21
27
28
30
32
35
42

4 .

Ãéá ôçí áíáðáñáãùãÞ ôçò óôï÷áóôéêÞò ÷ñïíïåîÝëéîçò. ðïõ üìùò áðïôåëïýíôáé áðü ôåñÜóôéï ðëÞèïò óùìáôéäßùí. 2. ç ðñïóïìïßùóç êÜíåé ÷ñÞóç øåõäïôõ÷áßùí áñéèìþí ðïõ ðáñÜãïíôáé êáôÜ ôç äéÜñêåéá ôçò ðñïóïìïßùóçò. üðùò ç ðñïóïìïßùóç ðõñçíéêþí åêñÞîåùí üôáí ïé äéåèíåßò íüìïé (ìå ëßãç áéóéïäïîßá) èá áðáãïñåýïõí ôéò ðõñçíéêÝò äïêéìÝò. ç åîÝëéîç ôùí åðéóôçìïíéêþí èåùñéþí âáóéæüôáí áðïêëåéóôéêÜ óôç óõìöùíßá ôïõò ìå ðåéñáìáôéêÜ áðïôåëÝóìáôá. ºóùò âÝâáéá ãé’ áõôü íá åõèýíåôáé ç êáêÞ ìåôáöïñÜ áðü ôï âéâëßï óôïí õðïëïãéóôÞ. Ôï ðñïãñÜììá ãéá ôï ìïíïäéÜóôáôï ìïíôÝëï Ising áõôïý ôïõ âéâëßïõ ðéèáíþò íá åßíáé ðñïâëçìáôéêü êáèþò ç åêôÝëåóÞ ôïõ Ýäùóå ëáíèáóìÝíá áðïôåëÝóìáôá. Óôçí åñãáóßá áõôÞ èá áó÷ïëçèïýìå ìå ðñïóïìïéþóåéò öõóéêþí óõóôçìÜôùí ïé ïðïßåò Ý÷ïõí óôï÷áóôéêü ÷áñáêôÞñá.1. Ìå ôÝôïéá óõóôÞìáôá áó÷ïëåßôáé ç óôáôéóôéêÞ öõóéêÞ. ÁðëÝò åöáñìïãÝò ìåèüäùí Monte Carlo Óôï êåöÜëáéï áõôü èá äïýìå ìåñéêÝò áðëÝò åöáñìïãÝò ìåèüäùí Monte Carlo. Þ ôçí ðñïóïìïßùóç ôçò äéÜóðáóçò ñáäéåíåñãþí áðïâëÞôùí ðïõ åí ãÝíåé Ý÷ïõí ìåãÜëïõò ÷ñüíïõò õðïäéðëáóéáóìïý. Ïé ðñïóïìïéþóåéò öõóéêþí óõóôçìÜôùí Ý÷ïõí ãßíåé äçëáäÞ ìéá íÝá ìïñöÞ ðåéñáìáôéêÞò Ýñåõíáò. Áöïý äþóïõìå ìåñéêÜ áðëÜ ðáñáäåßãìáôá . Ç ÷ñïíéêÞ åîÝëéîç ôùí óõóôçìÜôùí áõôþí äåí áêïëïõèåß Ýíáí áõóôçñÜ ðñïêáèïñéóìÝíï ôñüðï (üðùò ãéá ðáñÜäåéãìá ïé ëýóåéò ôçò åîßóùóçò êßíçóçò ôïõ Newton). ÅéóáãùãÞ Ðñéí ôçí åìöÜíéóç ôùí õðïëïãéóôþí. ÐïëëÝò öïñÝò ìéá ðñïóïìïßùóç åßíáé ìïíüäñïìïò åßôå de juri åßôå de facto. Óðïõäáßåò åöáñìïãÝò Ý÷ïõí ãßíåé óå ðåñéðôþóåéò óõóôçìÜôùí ç ðïëõðëïêüôçôá ôùí ïðïßùí ðçãÜæåé ó÷åäüí áðïêëåéóôéêÜ áðü ôï ìåãÜëï ðëÞèïò âáèìþí åëåõèåñßáò ôïõò. ÌÝóá áðü ôéò åöáñìïãÝò áõôÝò èá ðáñïõóéÜóïõìå âáóéêÝò Ýííïéåò ôùí ìåèüäùí Monte Carlo êáèþò êáé ôï ðþò ìå óôï÷áóôéêÝò ìåèüäïõò ìðïñïýìå íá 5 . Óå êÜèå ðåñßðôùóç üìùò ôá ðñïãñÜììáôá ôïõ âéâëßïõ ÷ñçóéìåýïõí ùò ïäçãüò ãéá ôç óõããñáöÞ íÝïõ êþäéêá.åöáñìïãÝò ìåèüäùí Monte Carlo. Ðñïóïìïéþóåéò áõôïý ôïõ ôýðïõ êáëïýíôáé ðñïóïìïéþóåéò Monte Carlo (Monte Carlo simulations). ðáñïõóéÜæïõí åîáéñåôéêÜ ðïëýðëïêç óõìðåñéöïñÜ. Ìå ôçí Ýëåõóç ôùí øçöéáêþí çëåêôñïíéêþí õðïëïãéóôþí ç êáôÜóôáóç áõôÞ Üëëáîå. Ï åðéóôÞìïíáò áðÝêôçóå Ýíá åñãáëåßï ìå ôï ïðïßï ìðïñåß íá áíáðôýîåé êáé íá åðéëýóåé ðïëýðëïêá ìïíôÝëá êáé íá ðñáãìáôïðïéÞóåé ðñïóïìïéþóåéò ðïõ õðïêáèéóôïýí äýóêïëá ðñáãìáôïðïéÞóéìá ðåéñÜìáôá. Ôá ðñïãñÜììáôá ðïõ ÷ñçóéìïðïéÞèçêáí ãéá ôéò ðñïóïìïéþóåéò ôçò ðáñïýóáò åñãáóßáò åßíáé ãñáììÝíá óå C êáé C++ êáé ìåñéêÜ áðü áõôÜ âáóßóôçêáí óôá ðñïãñÜììáôá ðïõ õðÜñ÷ïõí óôï âéâëßï ôùí Landau êáé Binder [1] (ãñáììÝíá óå Fortran). èá ðñï÷ùñÞóïõìå óôçí ðñïóïìïßùóç ôïõ ìïíïäéÜóôáôïõ êáé äéäéÜóôáôïõ ìïíôÝëïõ Ising. ÌïíôÝëá óõóôçìÜôùí ðïõ ðåñéãñÜöïíôáé áðü áðëÝò ×áìéëôïíéáíÝò.

1 Õðïëïãéóìüò ïëïêëçñùìÜôùí Ï õðïëïãéóìüò ôïõ ïëïêëçñþìáôïò ìéáò óõíÜñôçóçò f (x) áðïôåëåß ôçí áðëïýóôåñç äõíáôÞ åöáñìïãÞ Monte Carlo. 2. äßíåé ôï ðïóïóôü áðü ôï åìâáäï ôïõ ðáñáëëçëïãñÜììïõ ðïõ áíôéóôïé÷åß óôï ïëïêëÞñùìá (1). Ó÷Þìá 1: Ç ñßøç N óçìåßùí åíôüò ôïõ ðáñáëëçëïãñÜììïõ äßíåé N0 óçìåßá óôç ðåñéï÷Þ êÜôù áðü ôç óõíÜñôçóç f (x). ôï ïëïêëÞñùìá (1) éóïýôáé ìå: I= N0 [y0 (b − a)] N (2) Åöáñìüæïõìå ôçí ðáñáðÜíù ìÝèïäï ãéá ôïí õðïëïãéóãìü ôïõ ïëïêëçñþìáôïò ôçò óõíÜñôçóçò: f (x) = x10 − 1 (3) ÐáñáèÝôïõìå áðïôåëÝóìáôá áðü äýï åêôåëÝóåéò ôïõ ðñïãñÜììáôïò ãéá íá ãßíåé åìöáíÞò ï óôï÷áóôéêüò ÷áñáêôÞñáò ôùí áðïôåëåóìÜôùí. Áðü ôá óçìåßá áõôÜ õðÜñ÷ïõí N0 ðïõ ðÝöôïõí óôçí ðåñéï÷Þ ôïõ ïðïßïõ ôï åìâáäüí èÝëïõìå íá õðïëïãßóïõìå. b] äßíåôáé ôüôå áðü ôçí (2.) ¸ôóé. Z I= b f (x)dx (1) a Ãéá íá õðïëïãßóïõìå ôï åìâáäü ðïõ êáëýðôåé ìéá óõíÜñôçóç ó÷åäéÜæïõìå ìéá ðåñéï÷Þ ðïõ ðåñéêëýåé ôï æçôïýìåíï åìâáäü. Ï ëüãïò ôïõ ðëÞèïõò ôùí óçìåßùí ðïõ Ýðåóáí êÜôù áðü ôç êáìðýëç ôçò f (x) ðñïò ôï óõíïëéêü ðëÞèïò óçìåßùí.ðÜñïõìå áñéèìçôéêÜ áðïôåëÝóìáôá óôá äéÜöïñá ðñïâëÞìáôá. 6 . N0 /N . Ôï ïëïêëÞñùìá ôçò f (x) óôï äéÜóôçìá [a. Óôçí ðåñéï÷Þ áõôÞ ñß÷íïõìå N ôõ÷áßá óçìåßá ðïõ ðñïÝñ÷ïíôáé áðü ïìïéüìïñöç êáôáíïìÞ.

03000 1000000 1.711088e+000% 0.851116e+002 +2. Ãéá íá õðïëïãßóïõìå ôï π áñêåß íá õðïëïãßóïõìå ôï åìâáäüí ôïõ ôåôáñôïêõêëßïõ: 1 1 E = πr2 ⇒ E = π ⇒ π = 4E 4 4 (4) Ó÷Þìá 2: Ôï óêéáóìÝíï åìâáäüí åßíáé áíÜëïãï ôïõ ðëÞèïõò ôùí ôõ÷áßùí óçìåßùí ðïõ ðÝöôïõí ìÝóá óôçí ðåñéï÷Þ áõôÞ ðñïò ôï óýíïëï ôùí óçìåßùí ðïõ ðÝöôïõí óôï ôåôñÜãùíï ðïõ ïñßæïõí ïé Üîïíåò êáé ïé äéáêåêïììÝíåò.678523e-002% 2.00000 1000 1.1 Expected value: 185.92400 100000000 1. 2.827840e+002 -2.93400 100000000 1.963491e+000 2.exe Êáé óôéò äýï ðåñéðôþóåéò ôá áðïôåëÝóìáôá Ý÷ïõí ôçí ßäéá ðåñßðïõ áêñßâåéá. Ôçí áêñéâÞ ôéìÞ ôïõ ïëïêëçñþìáôïò ôçí Ý÷ïõìå üôáí N → ∞. ùóôüóï äéáöÝñïõí ìåôáîý ôïõò.469091e+000 5.126400e+002 -7.819238e+002 -3..051043e-001 5.851811e-003 5.00000 100000 1.539068e-002% 29.629470e+000% 0.224519e-001% 0.Integral evaluation of f(x) = x^10 .246365e+000% 0.101091e+001 5. 7 .090909.850811e+002 -9.851194e+002 +2.806837e-002% 2.844941e+002 -5.306909e+000 1.04000 1000000 1..167069e+000 1.2 Õðïëïãéóìüò ôïõ ð Áò äïýìå ìå ðïéüí ôñüðï ìðïñïýìå íá ÷ñçóéìïðïéÞóïõìå ôç ìÝèïäï áõôÞ ãéá ôïí õðïëïãéóìü ôïõ π.740800e+002 -1.33000 10000000 1. Ó÷åäéÜæïõìå Ýíá ôåôáñôïêýêëéï ìïíáäéáßáò áêôßíáò.851244e+002 +3.802240e+002 -4.857321e+002 +6.322688e-003% 28.866909e+000 2.115285e-002% 0.681650e+000% 0.968291e-001 3.344291e-002 1.245091e+001 3.848675e-002 1.00000 1000 1.945600e+002 +9.464173e-001% 0.32000 10000000 1.115914e+000% 0.900544e+002 +4.411869e-001 3.00000 100000 1. N (MCpoints) Evaluated error err (percent) time (sec) ---------------------------------------------------------------------------100 1.80200 N (MCpoints) Evaluated error err (percent) time (sec) ---------------------------------------------------------------------------100 1.67300 mcint.849858e+002 -1.948919e+000% 0.01000 10000 1.00000 10000 1.064291e-002 1.914342e+001% 0.

000150 0. ÌåãÜëç åîÜñôçóç Ý÷åé åðßóçò êáé áðü ôçí ðïéüôçôá ôçò ãåííÞôñéáò ôùí ôõ÷áßùí áñéèìþí.222544 % 10000 3.3 Õðïëïãéóìüò ïëïêëçñùìÜôùí ìå Importance Sampling MC Óôá ðñïçãïýìåíá ÷ñçóéìïðïéÞèçêáí ïìïéüìïñöá êáôáíåìçìÝíïé ôõ÷áßïé áñéèìïß.000045 0.001461 0.141706 +0.038407 1..145040 +0.003612 % N (MCpoints) Evaluated error err (percent) -------------------------------------------------------100 3.132000 -0. N (MCpoints) Evaluated error err (percent) -------------------------------------------------------100 3.046494 % 10000000 3.Ç ñßøç ôõ÷áßùí óçìåßùí óôçí ðåñéï÷Þ ôïõ ôåôñáãþíïõ ìáò äßíåé ôï óêéáóìÝíï åìâáäüí. yôõ÷ ) áðüqôçí áñ÷Þ ôùí áîüíùí åßíáé ìéêñüôåñç ôçò áêôßíáò ôïõ ôåôáñôïêõêëßïõ. üëá ôá äåßãìáôá åß÷áí ôï ßäéï âÜñïò. Ãéá üëá ôá áðïôåëÝóìáôá ðïõ ðáñïõóéÜæïõìå âñéóêüìáóôå ÷áìçëüôåñá áðü ôï 2% ôçò ðåñéüäïõ ôçò.001431 % 100000000 3.144400 +0.002807 0.160000 +0.004778 % mcpi. ¸ôóé.233795 % 1000 3.585924 % 1000 3.140132 -0.101593 3.305344 % 100000 3.180000 +0.141638 +0. Ðåñéï÷Ýò ðïõ Ý÷ïõí ìçäåíéêÞ ó÷åäüí óõìâïëÞ óôï ôåëéêü áðïôÝëåóìá ëáìâÜíïíôáé åî’ ßóïõ õðüøçí ìå óçìáíôéêüôåñåò ðåñéï÷Ýò.018407 0.000113 0.109732 % 1000000 3.140160 -0.000761 0.000119 0.140832 -0.141743 +0.024212 % 10000000 3.045603 % 1000000 3.141474 -0.009593 0.003790 % 100000000 3. Monte Carlo evaluation of Pi Expected value: 3.089361 % 100000 3.003447 0. Ãéá ôïí õðïëïãéóìü ôïõ ïëïêëçñþìáôïò ìéáò óõíÜñôçóçò ðïõ ðáñïõóéÜæåé Ýíôïíá ìÝãéóôá óå ìéá ìéêñÞ ðåñéï÷Þ åíþ áëëïý Ý÷åé ìéêñÝò 8 . 2.046407 1..1415927.exe ÓõìðåñáóìáôéêÜ ìðïñïýìå íá ðïýìå üôé ç áêñßâåéá åíüò Monte Carlo õðïëïãéóìïý Ý÷åé ìåãÜëç åîÜñôçóç áðü ôï ðëÞèïò N ôùí óçìåßùí.188000 +0. ðïõ éóïýôáé ìå: E= N0 N0 Eôåôñ ⇒ E = N N (5) üðïõ áõîÜíïõìå ôï N0 êáôÜ Ýíá êÜèå öïñÜ ðïõ ç áðüóôáóç ôïõ ôõ÷áßïõ óçìåßïõ (xôõ÷ .477192 % 10000 3.001433 0.040000 -0. Óå üëá ôá ðñïãñÜììáôá ôçò ðáñïýóáò åñãáóßáò ùò ãåííÞôñéá (øåõäï)ôõ÷áßùí áñéèìþí ÷ñçóéìïðïéÞèçêå ç ran1() [2] ðïõ åßíáé ó÷åôéêÜ ãñÞãïñç êáé ìå ìåãÜëç ðåñßïäï. d = 2 <1 x2ôõ÷ + yôõ÷ Ç õëïðïßçóç ôùí ðáñáðÜíù óå ðñüãñáììá ìáò Ýäùóå ôá ðáñáêÜôù áðïôåëÝóìáôá.

Áöïý âñïýìå êáôÜëëçëç óõíÜñôçóç g ðïõ êñáôÜåé ôçí h ó÷åäüí óôáèåñÞ. áëëÜ ìå ôçí áíïìïéïãåíÞ êáôáíïìÞ gdV . ðïõ ôçí óçìåéþíïõìå ìå p(y)dy. èá ðñÝðåé íá öñïíôßóïõìå þóôå ç ìïñöÞ ôçò êáôáíïìÞò íá ôáéñéÜæåé ìå ôç ìïñöÞ ôçò ðñïò ïëïêëÞñùóç óõíÜñôçóçò. äßíåôáé áðü ôï èåìåëéþäç íüìï ìåôáó÷çìáôéóìïý ðéèáíïôÞôùí: |p(y)dy| = |p(x)dx| (9) ¯ ¯ ¯ dx ¯ p(y) = ¯¯ ¯¯ dy (10) Þ 9 . êáé üôé áõôÞ ìðïñåß íá ãñáöåß ùò ôï ãéíüìåíï ìéáò óõíÜñôçóçò h(x) ðïõ ðáñáìÝíåé ó÷åäüí óôáèåñÞ óôçí ðåñéï÷Þ V åðß ìéáò èåôéêÞò óõíÜñôçóçò g(x). ç y(x). Áò èåùñïýìå ôçí ãåíéêÞ ðåñßðôùóç ìéáò óõíÜñôçóçò f (x).ôéìÝò. Äçìéïõñãßá Áíïìïéïãåíïýò êáôáíïìÞò ¸óôù ç ïìïéïãåíÞò êáôáíïìÞ p(x). ü÷é üìùò ìå ôçí ïìïéïãåíÞ êáôáíïìÞ dV . Óôçí ðåñßðôùóç ôçò ISMC âÝâáéá. Ç ìÝèïäïò Monte Carlo ðïõ ÷ñçóéìïðïéåß ðñïóáñìïóìÝíç áíïìïéïãåíÞ êáôáíïìÞ ôõ÷áßùí áñéèìþí êáëåßôáé Importance Sampling Monte Carlo (ISMC). Ç ðéèáíüôçôá p(x)dx íá ìáò äþóåé ôéìÞ ìåôáîý x êáé x + dx åßíáé: ½ p(x)dx = dx 0< x< 1 0 Üëëïôå (7) Ç êáôáíïìÞ p(x) åßíáé êáíïíéêïðïéçìÝíç: Z ∞ p(x)dx = 1 (8) −∞ ¸óôù ôþñá ìéá óõíÜñôçóç ôïõ x. ç ðñïçãïýìåíç ìÝèïäïò áðáéôåß ðïëý ìåãÜëï ðëÞèïò ôõ÷áßùí óçìåßùí ðñïêåéìÝíïõ íá äþóåé áîéïðñåðÞ áðïôåëÝóìáôá. Ç êáôáíïìÞ ôùí y. Ãéá íá áõîÞóïõìå ôç óõìâïëÞ ìéáò ðåñéï÷Þò ôéìþí ÷ñçóéìïðïéïýìå ôõ÷áßïõò áñéèìïýò áðü ìç ïìïãåíÞ êáôáíïìÞ. Ôï ïëïêëÞñùìá ôçò f (x) óôçí ðåñéï÷Þ V èá åßíáé: Z Z f ( )gdV = g f dV = Z hgdV (6) Óýìöùíá ìå ôçí (6) ìðïñïýìå íá ïëïêëçñþóïõìå ôçí f ðáßñíïíôáò ãéá äåßãìáôá ôéìÝò áðü ôçí h áíôß ôçò f . ôï ðñüâëçìá ìåôáöÝñåôáé óôï íá äçìéïõñãÞóïõìå ôçí êáôÜëëçëç áíïìïéïãåíÞ êáôáíïìÞ.

2].850767e+002 -1.402750e-001% 0.850793e+002 -1.451809e-003 4..849930e+002 -9.00000 10000 1. ÅðéëÝãïõìå ãéá g.902364e-003 3. N (MCpoints) Evaluated error err (percent) time (sec) ---------------------------------------------------------------------------10 1.721818e+000 1.278182e-001 3.850853e+002 -5. ìå ôç ìÝèïäï ISMC. ôçí óõíÜñôçóç: g(y) = y 10 (13) ç ïðïßá áöÞíåé ôçí h = f /g ó÷åäüí óôáèåñÞ. èåôéêÞ óõíÜñôçóç ìå ïëïêëÞñùìá ßóï ìå ìïíÜäá. ç áíôßóôñïöç ôçò G.1 Using Importance Sampling Expected value: 185.391945e-001% 0.269646e-002% 0. ï ìåôáó÷çìáôéóìüò ðïõ ìåôáôñÝðåé ìéá ïìïéüìïñöç êáôáíïìÞ óçìåßùí x óå Üëëá óçìåßá y ìå êáôáíïìÞ g(y) åßíáé: y(x) = G−1 (x) (12) üðïõ G−1 .419545e-002 7. üðïõ G(y) ç ðáñÜãïõóá ôçò g. G(b)] = [G(1).00000 100000 1.566302e-003% 8.470530e+000% 0.188900e-003% 0.278182e-001 3.402750e-001% 0.850968e+002 +5.261886e-003% 0.00000 100 1.08000 1000000 1. Áðü ôçí (10) Ý÷ïõìå: ¯ ¯ ¯ dx ¯ ¯ ¯ = g(y) (11) ¯ dy ¯ Ëýóç ôçò ðáñáðÜíù åßíáé x = G(y).823691e+002 -2.350000e-002 1. ¸öáñìïãÞ ãéá f (x) = x10 − 1 Ùò åöáñìïãÞ ôùí ðáñáðÜíù èá õðïëïãßóïõìå ôï ïëïêëÞñùìá ôçò óõíÜñôçóçò f (x) = x10 − 1.402750e-001% 0.Óôçí ðåñßðôùóÞ ìáò.08000 1000000 1. 211 /11] (15) åíþ ôï y0 ôçò (2) ðáßñíåé ôçí ôéìÞ y0 = h(G(b)) = f (G(b))/g(G(b)).74100 10000000 1. Ç õëïðïßçóç ôùí ðáñáðÜíù óå ðñüãñáììá ìáò Ýäùóå ôá ðáñáêÜôù áðïôåëÝóìáôá. óôï äéÜóôçìá [1. Ôá óçìåßá y ôçò áíïìïéïãåíïýò êáôáíïìÞò èá äßíïíôáé áðü ôçí: y(x) = (11x)1/11 (14) Ôá íÝá üñéá ïëïêëÞñùóçò åßíáé: [G(a). üðïõ g.669450e-003% 0.03100 N (MCpoints) Evaluated error err (percent) time (sec) ---------------------------------------------------------------------------10 1. Óõíåðþò. èÝëïõìå áðü ôá x íá äçìéïõñãÞóïõìå óçìåßá y ðïõ áêïëïõèïýí ôçí êáôáíïìÞ p(y) = g(y).857187e+002 +6.653882e-003 3..850674e+002 -2.232727e-002 1.391945e-001% 0.291257e-002% 0.793636e-002 5.exe 10 .850994e+002 +8. G(2)] = [111 /11.851232e+002 +3.00000 100 1. Integral evaluation of f(x) = x^10 .00000 100000 1.857187e+002 +6.860909e+002 +1.74100 10000000 1.00000 1000 1.860909e+002 +1.99100 mcinis.054651e-003% 7.000000e+000 5.746562e-002% 0.000000e+000 5.860909e+002 +1.159018e-002 6.00000 1000 1.00000 10000 1.000000e+000 5.090909.

3. Ãéá ôç äéäéÜóôáôç ðåñßðôùóç. ðñÝðåé íá ëÜâïõìå õð’ üøç ïôé ôï óõãêåêñéìÝíï ðáñÜäåéãìá åßíáé êÜðùò åîéäáíéêåõìÝíï.1 ÌïíôÝëï Ising Ôï ìïíôÝëï Ising áðïôåëåßôáé áðü Ýíá ðëÝãìá ôïõ ïðïßïõ ôá ðëåãìáôéêÜ óçìåßá (lattice sites) Ý÷ïõí spin σi . èá ðáñáèÝôïõìå ëåðôïìÝñåéåò ðïõ áöïñïýí ôï ðñïãñáììáôéóôéêü ìÝñïò ôùí õðïëïãéóìþí. äçëáäÞ ôåßíåé íá åõèõãñáììßóåé ôéò ìáãíçôéêÝò ñïðÝò ôùí spins. áêñéâÞ ëýóç [3] Ý÷ïõìå ãéá ðåñéïäéêÝò óõíïñéáêÝò óõíèÞêåò êáé ìçäåíéêü ðåäßï êáé áðïêáëýðôåôáé ôüôå ç ýðáñîç ìåôáôñïðÞò öÜóçò äåõôÝñáò ôÜîçò. Óôá üóá áêïëïõèïýí èá ìåëåôÞóïõìå ôï ìïíïäéÜóôáôï êáé äéäéÜóôáôï ìïíôÝëï Ising. Ãéá Jnn > 0 Ý÷ïõìå Ising öåñïìáãíÞôç åíþ ãéá Jnn < 0 Ý÷ïõìå Ising áíôéöåñïìáãíÞôç. êáé âñÝèçêå íá ìçí Ý÷åé ìåôáôñïðÞ öÜóçò. ÊÜèå spin áëëçëåðéäñÜ ìå ôïõò åãããýôáôïõò ãåßôïíÝò ôïõ ìÝóïõ ôçò óôáèåñÜò áëëçëåðßäñáóçò J . ç åðéäåêôéêüôçôá (suseptibility χ) êáé ç êñßóéìç èåñìïêñáóßá (Tc ). Ãéá óõãêñßóéìç áêñßâåéá ç ISMC ÷ñåéÜæåôáé äýï ôÜîåéò ìåãÝèïõò ëéãüôåñïõò øåõäïôõ÷áßïõò. Ôá spin σi ðáßñíïõí ôéìÝò +1 êáé -1 ãéá spin ðÜíù êáé spin êÜôù áíôßóôïé÷á. ÂÝâáéá. Åìåßò èá áó÷ïëçèïýìå ìå ôçí áñéèìçôéêÞ åðßëõóç ôïõ ìïíïäéÜóôáôïõ êáé äéäéÜóôáôïõ ìïíôÝëïõ Ising ìå ðåñéïäéêÝò óõíïñéáêÝò óõíèÞêåò (periodic boundary conditions .Ðáñáôçñïýìå üôé óå óýãêñéóç ìå ôçí áðëÞ (Þ áëëéþò crude) Monte Carlo ðïõ åßäáìå íùñßôåñá. áîéïðïéþíôáò êáëýôåñá ôçí ãåííÞôñéá ôõ÷áßùí áñéèìþí êáé áðïöåýãïíôáò Ýôóé ôïí êßíäõíï íá ðëçóéÜóïõìå ôá üñéÜ ôçò (ðëÞèïò äåéãìÜôùí óõãêñßóéìç ìå ôçí ðåñßïäü ôçò). ãíùóôÞ êáé ùò ðåäßï áíôáëëáãÞò. ¼ðïõ êñßíåôáé óêüðéìï. Ç Hamiltonian ôïõ ìïíôÝëïõ åßíáé: H = −Jnn X σi σj − H X nn σi (16) i üðïõ ôï nn óôçí Üèñïéóç äçëþíåé åããýôáôïõò ãåßôïíåò (nearest neighbors) êáé ôï H åßíáé åîùôåñéêü ìáãíçôéêü ðåäßï. Èá äïýìå ðùò õðïëïãßæïíôáé èåñìïäõíáìéêÝò ðïóüôçôåò üðùò ç èåñìï÷ùñçôéêüôçôá (Cv ). ç ìÝèïäïò áõôÞ äßíåé áðïôåëÝóìáôá ìåãáëýôåñçò áêñßâåéáò óå ìéêñüôåñï ÷ñüíï. áöïý ç áíïìïéïãåíÞò êáôáíïìÞ ìáò ðëçóéÜæåé ðïëý ôçí ðñïò ïëïêëÞñùóç óõíÜñôçóç.pbc) êáé ìçäåíéêü ðåäßï. 3. ôï óýóôçìá åìöáíßæåé áõèüñìçôç ìáãíÞôéóç. Ç óôáèåñÜ áëëçëåðßäñáóçò. Ùò áðïôÝëåóìá. ôåßíåé íá åõèõãñáììßóåé ôá spins ìåôáîý ôïõò. Ç Hamiltonian ôïõ óõóôÞìáôïò åßíáé: H = −Jnn X nn 11 σi σj (17) . ¸íá áðü ôá áðëïýóôåñá ðëåãìáôéêÜ ìïíôÝëá ðïõ ìåëåôïýíôáé åßíáé ôï ìïíôÝëï Ising (Ising Model). Ôï ìïíôÝëï Ising Ý÷åé ëõèåß áêñéâþò óå ìéá äéÜóôáóç. ÌïíôÝëï Ising êáé áëãüñéèìïò Metropolis Ç ìÝèïäïò ISMC Ý÷åé âñåé óðïõäáßåò åöáñìïãÝò óôç óôáôéóôéêÞ öõóéêÞ üðïõ ÷ñçóéìïðïéåßôáé ãéá ôç ìåëÝôç ìåôáôñïðþí öÜóçò.

åíþ ãéá T < Tc åßíáé U4 → 2/3. Óå ìåôáôñïðÝò öÜóçò äåõôÝñáò ôÜîçò. ïé êáìðýëåò ôïõ U4 óõíáñôÞóåé ôçò èåñìïêñáóßáò äéáóôáõñþíïíôáé óôç ôéìÞ U4∗ . Ìéá Üëëç ìÝèïäïò ðñïóäéïñéóìïý ôçò èåñìïêñáóßáò ìåôÜâáóçò. Óå ÷áìçëÝò èåñìïêñáóßåò. Ç ìÝèïäïò áõôÞ åßíáé ðïëý áêñéâÞò. Ãéá Ýíá ìïíôÝëï Ising ìå ìçäåíéêü ðåäßï ï åðéóóùñåõôÞò ôåôÜñôçò ôÜîçò åßíáé: U4 = 1 − hm4 i 3hm2 i2 (18) Êáèþò ïé äéáóôÜóåéò ôïõ óõóôÞìáôïò ìåãáëþíïõí. Ç ôéìÞ U4∗ áíôéóôïé÷åß óôç êñßóéìç èåñìïêñáóßá. Óôéò ìåôáôñïðÝò öÜóçò Ý÷ïõìå ôçí åìöÜíéóç êÜðïéáò éäéüôçôáò ôïõ óõóôÞìáôïò ðïõ êáëåßôáé ðáñÜìåôñïò ôÜîçò (order parameter). ïé èåñìéêÝò äéáôáñá÷Ýò (ïé ïðïßåò áíôéôßèåíôáé óôï ðåäßï áíôáëëáãÞò) êáôáóôñÝöïõí ôçí ôÜîç ôùí spin. üðùò áõôÜ ðïõ åîåôÜæïõìå. Óôçí ðåñßðôùóç ðïõ åîåôÜæïõìå. Ç ìÝèïäïò áõôÞ ìáò äßíåé ìéá ðñþôç åêôßìçóç ôçò Tc . åßíáé ìÝóù ôùí èåñìïäõíáìéêþí ðáñáãþãùí üðùò ç åéäéêÞ èåñìüôçôá êáé ç åðéäåêôéêüôçôá. ëïéðüí. Óôïõò öåñïìáãíÞôåò ç èåñìïêñáóßá áõôÞ åßíáé ãíùóôÞ ùò èåñìïêñáóßá Curie êáé óôïõò áíôéöåñïìáãíÞôåò ùò èåñìïêñáóßá N´eel. ÐÜíù áðü ìéá êñßóéìç èåñìïêñáóßá Tc ç ìáãíçôéêÞ ôÜîç åîáöáíßæåôáé.2 ÌåôáôñïðÝò öÜóçò ÁíáöÝñáìå ðñïçãïõìÝíùò üôé óôï äéäéÜóôáôï ìïíôÝëï Ising åìöáíßæåôáé ìåôáôñïðÞ öÜóçò äåõôÝñáò ôÜîçò. ãéá T > Tc åßíáé U4 → 0. Ï ðñïóäéïñéóìüò ôçò êñßóéìçò èåñìïêñáóßáò ìðïñåß íá ãßíåé ìå äéÜöïñïõò ôñüðïõò. äçëáäÞ êáèþò L → ∞. Êáèþò áõîÜíåé ç èåñìïêñáóßá. Ç åéäéêÞ èåñìüôçôá êáé ç åðéäåêôéêüôçôá äßíïíôáé áðü ôéò ó÷Ýóåéò: 12 . ïé ðñþôåò ðáñÜãùãïé åßíáé óõíå÷åßò áëëÜ Ý÷ïõìå ìçäåíéóìü ôùí äåýôåñùí ðáñáãþãùí ôçò åíÝñãåéáò. Ãéá ðëÝãìáôá äéáöïñåôéêþí äéáóôÜóåùí. êáé ìçäåíéêÝò ôéìÝò óôç öÜóç ðïõ áðïõóéÜæåé ôÜîç. Ãéá óõóôÞìáôá üðïõ ïé ìåôáôñïðÝò öÜóçò åßíáé ìåôáîý êáôáóôÜóåùí óå ôÜîç êáé êáôáóôÜóåùí óå áôáîßá. Êñßíáìå óêüðéìï. óôï óçìåßï áõôü íá áíáöåñèïýìå óõãêåíôñùôéêÜ óå ïôéäéðïôå ó÷åôßæåôáé ìå ôéò ìåôáôñïðÝò öÜóçò êáé ðïõ áöïñÜ ôïõò õðïëïãéóìïýò ðïõ Ý÷ïõìå ðñáãìáôïðïéÞóåé. Ïé õðïëïãéóìïß ðïõ èá äïýìå ðáñáêÜôù áöïñïýí ðïóüôçôåò êáé Ýííïéåò ó÷åôéêÝò ìå ôéò ìåôáôñïðÝò öÜóçò. Ç ðáñÜìåôñïò ôÜîçò ðáßñíåé ìç ìçäåíéêÝò ôéìÝò óôç öÜóç ôïõ óõóôÞìáôïò ðïõ ÷áñáêôçñßæåôáé áðü ôÜîç. ç ðáñÜìåôñïò ôÜîçò åßíáé ç áõèüñìçôç ìáãíÞôéóç. ç ìåôáôñïðÞ öÜóçò êáëåßôáé ðñþôçò ôÜîçò üôáí ïé ðñþôåò ðáñÜãùãïé ôçò åíÝñãåéáò åßíáé áóõíå÷åßò óôç êñßóéìç èåñìïêñáóßá. ôï ðåäßï áíôáëëáãÞò åßíáé éêáíü íá åõèõãñáììßóåé ôá spins êáé êáôÜ óõíÝðåéá ç ìáãíÞôéóç ôïõ óõóôÞìáôïò íá ãßíåé ìç ìçäåíéêÞ.3. Ìéá ðñþôç åêôßìçóç ôçò êñßóéìçò èåñìïêñáóßáò ìðïñåß íá ãßíåé ÷ñçóéìïðïéþíôáò ôïí åðéóóùñåõôÞ ôåôÜñôçò ôÜîçò (fourth order cumulant) U4 [4].

Áîßæåé íá áíáöÝñïõìå üôé óå ìáêñïóêïðéêÜ óõóôÞìáôá (ðëÞèïò óùìáôéäßùí N À 1) ïé äéáêõìÜíóåéò áõôÝò åßíáé ðïëý ìéêñÝò. 8 13 γ= 7 4 (23) . Ôï óçìåßï üðïõ ïé Cv êáé χ ðáñïõóéÜæïõí êïñõöÝò áíôéóôïé÷åß óôçí êñßóéìç èåñìïêñáóßá. ÊáôÜ ôç ìåëÝôç ôïõ äéäéÜóôáôïõ ìïíôÝëïõ Ising. Óôéò ðñïóïìïéþóåéò üìùò. ïé åêèÝôåò ôùí ïðïßùí ïíïìÜæïíôáé êñßóéìïé åêèÝôåò (critical exponents): M = M0 ²β χ = χ0 ²−γ C = C0 ² (21) −α üðïõ ¯ ¯ ¯ T ¯¯ ¯ ² = ¯1 − ¯ Tc (22) Ïé áêñéâåßò ôéìÝò ôùí êñßóéìùí åêèåôþí ãéá ôï äéäéÜóôáôï (ôåôñÜãùíï) ìïíôÝëï Ising åßíáé[3]: α = 0. 6]. U ∝ N . ïé ó÷Ýóåéò áõôÝò ãßíïíôáé ðïëý ÷ñÞóéìåò êáèþò ïé äéáóôÜóåéò ôùí óõóôçìÜôùí ðïõ ðñïóïìïéþíïõìå åßíáé åí ãÝíåé ðïëý ìéêñüôåñåò ôùí áíôßóôïé÷ùí ìáêñïóêïðéêþí. óõíåðþò hH2 i ∝ N 2 êáé hHi2 ∝ N 2 . Ç åíÝñãåéá ôïõ óõóôÞìáôïò åßíáé áíÜëïãç ôïõ N . Ïé äéáêõìÜíóåéò óôçí åíÝñãåéá ãßíïíôáé ðïëý ìéêñÝò. Ãéá ìáêñïóêïðéêÜ óõóôÞìáôá (N ≈ 1022 ) ïé äéáêõìÜíóåéò áõôÝò åßíáé ðïëý ìéêñÝò ãéá íá áíé÷íåõôïýí ðåéñáìáôéêÜ. åíþ Ý÷ïõìå ôç äõíáôüôçôá íá ìåôáâÜëïõìå ôï ìÝãåèïò ôïõ õðü ìåëÝôç óõóôÞìáôïò êáôÜ âïýëçóç (õðü ôïõ ðåñéïñéóìïý ðÜíôïôå ôçò õðïëïãéóôéêÞò éó÷ýïò ðïõ Ý÷ïõìå óôç äéÜèåóÞ ìáò).µ Cv = ∂U ∂T ¶ = ¢ 1 ¡ 2 hH i − hHi2 2 kB T (19) = ¢ 1 ¡ 2 hM i − hM i2 kB T (20) V êáé µ χ= ∂hM i ∂H ¶ T ¢ñá. ôçò ôÜîçò ôïõ 1/N . ÷ñçóéìïðïéïýíôáé êáé ïé äýï ìÝèïäïé ãéá ôïí ðñïóäéïñéóìü ôçò êñßóéìçò èåñìïêñáóßáò. 1 β= . ÔÝëïò. ïé ðïóüôçôåò Cv êáé χ ìðïñïýí íá õðïëïãéóôïýí áðü ôéò äéáêõìÜíóåéò ôçò åíÝñãåéáò êáé ôçò ìáãíÞôéóçò áíôßóôïé÷á. ðïõ èá äïýìå ðáñáêÜôù. ïé èåñìïäõíáìéêÝò ðïóüôçôåò ìðïñïýí íá ðåñéãñáöïýí áðü áðëÝò ó÷Ýóåéò ìå äõíÜìåéò[5. áíáöÝñïõìå üôé êïíôÜ óôçí êñßóéìç èåñìïêñáóßá.

4. ç âåëôßùóç Ýãéíå åðéëÝãïíôáò êáôÜëëçëá ôõ÷áßá óçìåßá. äçìéïõñãïýìå ðëåãìáôéêÝò äéáìïñöþóåéò ìå ìåãÜëç óõíåéóöïñÜ óôïõò ìÝóïõò üñïõò. Ìåôáâáßíïõìå óôï åðüìåíï ðëåãìáôéêü óçìåßï êáé îáíÜ óôï (3) 14 . ÅðéëÝãïõìå ìéá áñ÷éêÞ êáôÜóôáóç 2. ãõñßæïõìå ôï spin 6. Áíôßóôïé÷á. äçìéïõñãþíôáò Ýôóé ìéá áëõóßäá êáôáóôÜóåùí Markov (Markov chain of states). Ìå ôï ßäéï óêåðôéêü. Ï áëãüñéèìïò Metropolis ìðïñåß íá ðåñéãñáöåß áðü ôá åîÞò âÞìáôá: Metropolis importance sampling Monte Carlo scheme 1. ÐáñÜãïõìå Ýíáí ôõ÷áßï áñéèìü r: 0< r< 1 5. Ôï ðëÞèïò ôùí áðáéôïýìåíùí äéáìïñöþóåùí êáèéóôÜ ôç óõãêåêñéìÝíç ìåèïäïëïãßá õðïëïãéóôéêÜ áóýìöïñç. ìðïñïýìå íá õðïëïãßóïõìå ôéò äéÜöïñåò èåñìïäõíáìéêÝò ðïóüôçôåò åíüò ðëÝãìáôïò Ising ðáñÜãïíôáò Ýíá óýíïëï ôõ÷áßùí ðëåãìáôéêþí äéáìïñöþóåùí. Ç óõíåéóöïñÜ êÜèå äéáìüñöùóçò óôç ìÝóç ôéìÞ ôùí èåñìïäõíáìéêþí ðïóïôÞôùí êáèïñßæåôáé áðü Ýíáí ðáñÜãïíôá Boltzmann.3. EÜí r< exp(−∆E/kB T ). Åêåß.3 Áëãüñéèìïò Metropolis Åßäáìå íùñßôåñá üôé ìå ôçí áðëÞ (crude) Monte Carlo åßíáé äõíáôüò ï õðïëïãéóìüò åíüò ïëïêëçñþìáôïò ðáñÜãïíôáò Ýíá óýíïëï ôõ÷áßùí óçìåßùí. êáé ç ìÝóç ôéìÞ åíüò ìåãÝèïõò A õðïëïãßæåôáé áðü ôç ó÷Ýóç: X hAi = X Pn An = An e−En /kB T n X n e−En /kB T (24) n Ôï ðñüâëçìá ðïõ åìöáíßæåôáé åßíáé üôé áðáéôåßôáé ðïëý ìåãÜëï ðëÞèïò ôõ÷áßùí äéáìïñöþóåùí ðñïêåéìÝíïõ íá Ý÷ïõìå áêñéâåßò õðïëïãéóìïýò. áíôß íá åðéëÝãïõìå ôõ÷áßåò ðëåãìáôéêÝò äéáìïñöþóåéò. Ðñüêåéôáé ãéá ìÝèïäï ISMC üðùò áõôÞ ðïõ åßäáìå óôïí õðïëïãéóìü ïëïêëçñùìÜôùí. ðñïóáñìïóìÝíç óôï ðñüâëçìá. Ëýóç óôï ðñüâëçìá Ýäùóå ï Metropolis[7] ìå ôïí ïìüíõìï áëãüñéèìü ôïõ. áíïìïéüìïñöç êáôáíïìÞ. Õðïëïãßæïõìå ôçí ìåôáâïëÞ óôçí åíÝñãåéá ∆E ðïõ ðñïêýðôåé åÜí ôï spin óôç èÝóç i áëëÜîåé ðñïóáíáôïëéóìü. ÅðéëÝãïõìå Ýíá ðëåãìáôéêü óçìåßï (site) i 3. Áíôß ôá ôõ÷áßá óçìåßá íá ðñïÝñ÷ïíôáé áðü ïìïéüìïñöç êáôáíïìÞ ÷ñçóéìïðïéÞèçêáí óçìåßá áðü êáôÜëëçëç. ÊÜèå íÝá ðëåãìáôéêÞ äéáìüñöùóç ðñïêýðôåé áðü ôçí áìÝóùò ðñïçãïýìåíç. Óå êÜèå ðëåãìáôéêÞ äéáìüñöùóç áíôéóôïé÷åß ìéá åíÝñãåéá En ôçí ïðïßá ìðïñïýìå íá õðïëïãßóïõìå.

ïé ïðïßåò åßíáé: ↑↑. âÜóç ôçò ó÷Ýóçò E = −Jint σ1 σ2 . ↑↓. ¸÷ïõìå ôÝóóåñéò äõíáôÝò äéáìïñöþóåéò.4 ÌïíïäéÜóôáôï ìïíôÝëï Ising Ãéá ôçí åöáñìïãÞ ôïõ áëãüñéèìïõ Metropolis óôï ìïíïäéÜóôáôï ðëÝãìá Ising ÷ñåéÜæåôáé íá õðïëïãßóïõìå ôçí åíåñãåéáêÞ ìåôáâïëÞ ∆E ðïõ åðéöÝñåé ç áíôéóôñïöÞ åíüò spin óôç èÝóç i. åíþ æåõãÜñéá áíôéðáñÜëëùí spin Ý÷ïõí åíÝñãåéá +1.Ïé ôõ÷áßïé áñéèìïß r ðñÝðåé íá ðñïÝñ÷ïíôáé áðü ïìïéüìïñöç êáôáíïìÞ. ç ìÝóç ôéìÞ hAi = n Pn An åíüò ìåãÝèïõò A ðñïêýðôåé ôåëéêÜ áðü ôïí áñéèìçôéêü ìÝóï üñï óôï óýíïëï ôùí äéáìïñöþóåùí ðïõ Ý÷ïõí äçìéïõñãçèåß: M X hAi = An n=1 M (26) üðïõ M ôï óõíïëéêü ðëÞèïò ôùí äéáìïñöþóåùí ôïõ óõóôÞìáôïò. ÎåêéíÜìå õðïëïãßæïíôáò ôçí åíÝñãåéá åíüò æåýãïõò spin ãéá êÜèå äõíáôÞ äéáìüñöùóç. Ïé ðëåãìáôéêÝò äéáìïñöþóåéò ðïõ ðñïêýðôïõí ìå ôç ìåèïäïëïãßá áõôÞ (ìå åîáßñåóç ôéò áñ÷éêÝò äéáìïñöþóåéò ðïõ èåùñïýíôáé ìåôáâáôéêÝò). Jint = 1. ↓↓. æåõãÜñéá ðáñÜëëçëùí spin Ý÷ïõí åíÝñãåéá -1. ìå áõôü ôùí åããýôáôùí ãåéôüíùí ôïõ (ôï ìåóáßï spin åßíáé óôç èÝóç i): 15 . Ý÷ïõìå: ↑↑: E = −1(+1)(+1) ⇒ E = −1 ↓↓: E = −1(−1)(−1) ⇒ E = −1 ↑↓: E = −1(+1)(−1) ⇒ E = +1 ↓↑: E = −1(−1)(+1) ⇒ E = +1 Óõíåðþò. Ý÷ïõí ðéèáíüôçôá: e−En /kB T Pn = X e−En /kB T (25) n P ¸ôóé. 3. Ç ìåôáâïëÞ óôçí åíÝñãåéá ôçò áëõóßäáò ôùí spin ëüãïõ ôçò áíôéóôñïöÞò åíüò spin èá åîáñôÜôáé áðü ôï ó÷åôéêü ðñïóáíáôïëéóìü ôïõ spin site i. ↓↑. Ãéá ìïíáäéáßá áëëçëåðßäñáóç.

Ôï ßäéï óõìâáßíåé êáé óôï äéäéÜóôáôï ìïíôÝëï Ising. N=1. óýìöùíá ìå ôïí ôñüðï ðïõ ðáñïõóéÜóáìå. äßíåé ∆E = −4 Ìå ôç óýíïøç áõôÞ ï êþäéêáò ðïõ ðñïêýðôåé ãßíåôáé îåêÜèáñïò áëëÜ êáé áðïäïôéêüò êáèþò áñêåß Ýíáò ìüíïí õðïëïãéóìüò åêèåôéêïý üñïõ (óå êÜèå èåñìïêñáóßá). Ìå ôïí ôñüðï áõôü áðïöåýãïõìå ôïí Üóêïðï õðïëïãéóìü åêèåôéêþí üñùí.↑↑↑−→↑↓↑ : ∆E = Ef − Ei = (+2) − (−2) ⇒ ∆E = +4 ↓↑↓−→↓↓↓ : ∆E = Ef − Ei = (−2) − (+2) ⇒ ∆E = −4 ↑↑↓−→↑↓↓ : ∆E = Ef − Ei = (0) − (0) ⇒ ∆E = 0 ↓↑↑−→↓↓↑ : ∆E = Ef − Ei = (0) − (0) ⇒ ∆E = 0 ↑↓↑−→↑↑↑ : ∆E = Ef − Ei = (−2) − (+2) ⇒ ∆E = −4 ↓↓↓−→↓↑↓ : ∆E = Ef − Ei = (+2) − (−2) ⇒ ∆E = +4 ↑↓↓−→↑↑↓ : ∆E = Ef − Ei = (0) − (0) ⇒ ∆E = 0 ↓↓↑−→↓↑↑ : ∆E = Ef − Ei = (0) − (0) ⇒ ∆E = 0 Ôéò ðáñáðÜíù ðåñéðôþóåéò ìðïñïýìå íá ôéò óõãêåíôñþóïõìå óôéò åîÞò ôñåßò: • ÐëÞèïò ãåéôüíùí ìå ßäéï spin. ï êþäéêáò åßíáé ãñáììÝíïò óå C/Cpp. ìïíÜäá ìÝôñçóçò ÷ñüíïõ åßíáé ôï âÞìá Monte Carlo áíÜ ðëåãìáôéêü óçìåßï (Monte Carlo step/site) êáé áíôéóôïé÷åß óå èåþñçóç ôïõ êÜèå site ìßá öïñÜ. óõãêåêñéìÝíá ï prob = exp(−4Jint /T ). Ãéá ôï ëüãï áõôü äåí ëáìâÜíïõìå õðüøç Ýíá ðëÞèïò áðü êýêëïõò Monte Carlo óôïí õðïëïãéóìü ôùí ðïóïôÞôùí áõôþí. Áêïëïõèïýí áðïôåëÝóìáôá ðïõ ðñïÝêõøáí áðü ôçí åêôÝëåóç ôïõ ðñïãñáììÜôïò isingch. ¼ðùò üëá ôá ðñïãñÜììáôá ôçò ðáñïýóáò åñãáóßáò. N=2. ìüíï ðïõ åêåß Ý÷ïõìå êáé Ýíá ãéíüìåíï êáé ìéá äéáßñåóç åðéðëåüí. ïé ïðïßïé Ý÷ïõí ìåãÜëï õðïëïãéóôéêü êüóôïò. 16 . Ç ÷ñïíéêÞ åîÝëéîç ôçò åíÝñãåéáò êáé ôçò ìáãíÞôéóçò ôïõ ìïíïäéÜóôáôïõ óõóôÞìáôïò Ising öáßíåôáé óôá ó÷Þìáôá (3) êáé (4) áíôßóôïé÷á. äßíåé ∆E = 0 • ÐëÞèïò ãåéôüíùí ìå ßäéï spin. Ãéá ìéêñïýò ÷ñüíïõò ôï óýóôçìá äåí âñßóêåôáé óå éóïññïðßá üðùò öáßíåôáé áðü ôéò äéáêõìÜíóåéò óôçí áñ÷Þ ôùí äýï ó÷çìÜôùí. N=0. äßíåé ∆E = +4 • ÐëÞèïò ãåéôüíùí ìå ßäéï spin. Ïé äéáêõìÜíóåéò áõôÝò äåí åßíáé åðéèõìéôÝò êáèþò áëëéþíïõí ôïõò ìÝóïõò üñïõò ôùí ìåãåèþí ðïõ õðïëïãßæïõìå. ÁðïôåëÝóìáôá õðïëïãéóìþí Óå ðñïóïìïéþóåéò Monte Carlo. Óôï ðáñÜñôçìá áõôÞò ôçò åñãáóßáò õðÜñ÷åé ï êþäéêáò ðïõ õëïðïéåß ôç ìÝèïäï Ìetropolis ãéá ôï ìïíïäéÜóôáôï ìïíôÝëï Ising. Ï Üëëïò üñïò ðñïêýðôåé áðü áõôüí ìå áíôéóôñïöÞ prob[0] = 1/prob.exe.

Ï åðéóùñåõôÞò ôåôÜñôçò ôÜîçò Ý÷åé ôçí áíáìåíüìåíç óõìðåñéöïñÜ óôéò áêñáßåò ôïõ ôéìÝò åíþ ç Ýëëåéøç óçìåßïõ ôïìÞò ìåôáîý êáìðýëùí ðïõ áíôéóôïé÷ïýí óå äéáöïñåôéêÜ ìÞêç áëõóßäáò öáíåñþíåé åðßóçò ôçí Ýëëåéøç ìåôáôñïðÞò öÜóçò.20 <E> -0.0 -0. ïé êáìðýëåò ôïõ U4 ðïõ áíôéóôïé÷ïýí óå äéáöïñåôéêÜ ìåãÝèç áëõóßäáò äåí ôÝìíïíôáé. 17 . ¼ðùò öáßíåôáé áðü ôá äéáãñÜììáôá E − T êáé U4 − T . Ï ÷ñüíïò áíáðáñéóôÜíåôáé ìå êýêëïõò Monte Carlo.25 -0.40 0 500 1000 1500 2000 2500 MC-steps Ó÷Þìá 3: ÌÝóç åíÝñãåéá óõíáñôÞóåé ôïõ ÷ñüíïõ ãéá äéÜöïñá ìÞêç áëõóßäáò ãéá Ô=3. åðáëõèåýïíôáò ôï ðñïçãïýìåíï óõìðÝñáóìá ôçò Ýëëåéøçò ìåôáôñïðÞò öÜóçò. ÌåôÜ áðü ìåñéêïýò êýêëïõò MC ïé äéáêõìÜíóåéò ìéêñáßíïõí êáé óôáèåñïðïéïýíôáé ãýñù áðü ìéá ìÝóç ôéìÞ.35 -0. äåí åìöáíßæåôáé ìåôáôñïðÞ öÜóçò. -0.Ïé õðïëïãéóìïß ðïõ ðñáãìáôïðïéÞóáìå åßíáé ãéá äéÜöïñá ìÞêç áëõóßäáò Ising êáé óå èåñìïêñáóßåò T = 3. Áêüìá êáé óôéò ìéêñÝò èåñìïêñáóßåò.15 L=4 L=10 L=20 L=40 L=60 T = 3. Ç åíÝñãåéá åßíáé ãíçóßùò ìïíüôïíç óõíÜñôçóç ôçò èåñìïêñáóßáò ÷ùñßò áëëáãÞ êïßëùí. Óôá äéáãñÜììáôá E − M CST P êáé M − M CST P äéáêñßíïíôáé ôá ìåôáâáôéêÜ öáéíüìåíá óôïõò ìéêñïýò ÷ñüíïõò.0. ðïõ áêïëïõèïýí.0 êáé T = 30.0.30 -0.0 ìå Jnn = 1. ÐáñáèÝôïõìå äýï äéáãñÜììáôá U4 − T åê ôùí ïðïßùí óôï äåýôåñï Ý÷ïõìå ìéêñýíåé ôçí êëßìáêá ãéá íá äéáêñßíïõìå ôé óõìâáßíåé óå ðïëý ìéêñÝò èåñìïêñáóßåò.

04 -0.0 L=4 L=10 L=20 L=40 L=60 <M> 0.0.08 -0.1 -0.02 L=4 L=10 L=20 L=40 L=60 0.2 T = 3.0 0. Ï ÷ñüíïò áíáðáñéóôÜíåôáé ìå êýêëïõò Monte Carlo.02 -0.10 0 500 1000 1500 2000 2500 3000 3500 MC-steps Ó÷Þìá 5: ÌÝóç åíÝñãåéá óõíáñôÞóåé ôïõ ÷ñüíïõ ãéá äéÜöïñá ìÞêç áëõóßäáò ãéá Ô=30.1 0.2 0 500 1000 1500 2000 2500 MC-steps Ó÷Þìá 4: ÌÝóç ìáãíÞôéóç óõíáñôÞóåé ôïõ ÷ñüíïõ ãéá äéÜöïñá ìÞêç áëõóßäáò ãéá Ô=3.0. T = 30.0.06 -0. 18 . Ï ÷ñüíïò áíáðáñéóôÜíåôáé ìå êýêëïõò Monte Carlo.0 -0. Óå ìéêñïýò ÷ñüíïõò Ý÷ïõìå ìåãÜëåò äéáêõìÜíóåéò.00 <E> -0.

0 -1.000 -0.8 -0.0.2 <E> -0.075 0 500 1000 1500 2000 2500 3000 3500 MC-steps Ó÷Þìá 6: ÌÝóç ìáãíÞôéóç óõíáñôÞóåé ôïõ ÷ñüíïõ ãéá äéÜöïñá ìÞêç áëõóßäáò ãéá Ô=30.5 -0.075 L=4 L=10 L=20 L=40 L=60 T = 30.050 <M> 0.3 L=4 L=10 L=20 L=60 L=100 -0. Ï ÷ñüíïò áíáðáñéóôÜíåôáé ìå êýêëïõò Monte Carlo.9 -1. 0.1 -0.1 0 2 4 6 8 10 KBT/Jnn Ó÷Þìá 7: ÌÝóç åíÝñãåéá óõíáñôÞóåé ôïõ ëüãïõ kB T /Jnn ãéá äéÜöïñá ìÞêç áëõóßäáò Ising.050 -0.6 -0. 19 .0 -0.025 -0.4 -0.0.0 0. Ìåôáîý äéáäï÷éêþí êýêëùí MC áðïññßðôïíôáé 1000 MC êýêëïé ðñïêåéìÝíïõ íá åðéôåõ÷èåß íÝá éóïññïðßá.025 0.7 -0.

8 0.50 0.1 0 2 4 6 8 KBT/Jnn 10 Ó÷Þìá 8: ÅðéóùñåõôÞò ôåôÜñôçò ôÜîçò óõíáñôÞóåé ôïõ ëüãïõ kB T /Jnn ãéá äéÜöïñá ìÞêç áëõóßäáò Ising.2 0. 20 .55 0.4 0.9 1.0 KBT/Jnn Ó÷Þìá 9: ÅðéóùñåõôÞò ôåôÜñôçò ôÜîçò óõíáñôÞóåé ôïõ ëüãïõ kB T /Jnn ãéá äéÜöïñá ìÞêç áëõóßäáò Ising.6 U4 0.7 L=4 L=10 L=20 L=60 L=100 0. Óôï ìïíïäéÜóôáôï ìïíôÝëï Ising äåí ðáñáôçñïýìå ìåôÜâáóç öÜóçò. Ìåôáîý äéáäï÷éêþí êýêëùí MC áðïññßðôïíôáé 1000 MC êýêëïé ðñïêåéìÝíïõ íá åðéôåõ÷èåß íÝá éóïññïðßá. üðùò ìáñôõñåß ç Ýëëåéøç óçìåßïõ ôïìÞò ôùí êáìðýëùí. 0.5 0.1 0.7 0.60 L=4 L=10 L=20 L=60 L=100 0.2 0.1 0.4 0. Ìå ôçí áëëáãÞ êëßìáêáò öáßíåôáé åõêñéíþò üôé ïé êáìðýëåò äåí äéáóôáõñùíïíôáé êïíôÜ óôçí áñ÷Þ ôïõò.0.3 0.3 0.6 0.5 0.65 0.0 -0.70 U4 0.

02 0 2 4 6 8 10 KBT/Jnn Ó÷Þìá 10: ÅéäéêÞ èåñìüôçôá óõíáñôÞóåé ôïõ ëüãïõ kB T /Jnn ãéá äéÜöïñá ìÞêç áëõóßäáò Ising.5 ÄéäéÜóôáôï ìïíôÝëï Ising ¼ðùò êáé óôç ìïíïäéÜóôáôç ðåñßðôùóç.02 0.06 0.12 0. Ç äéáöïñÜ ìå ôçí ðñïçãïýìåíç ðåñßðôùóç åßíáé üôé ôï site i ðëåüí Ý÷åé 4 åããýôáôïõò ãåßôïíåò áíôß ãéá 2.14 0. Ðñáãìáôïðïéþíôáò ôçí ßäéá áíÜëõóç óôïõò ðñïóáíáôïëéóìïýò ôùí ãåéôïíôéêþí spin. ðñïêýðôåé üôé: 21 . 3.08 0.20 L=4 L=10 L=20 L=60 L=100 CV 0.00 -0.18 0.04 0.0. ãéá ôçí åöáñìïãÞ ôïõ áëãüñéèìïõ Metropolis óôï äéäéÜóôáôï ðëÝãìá Ising ÷ñåéÜæåôáé íá õðïëïãßóïõìå ôçí åíåñãåéáêÞ ìåôáâïëÞ ∆E ðïõ åðéöÝñåé ç áíôéóôñïöÞ åíüò spin óôç èÝóç i.16 0.10 0.

ÊÜèå spin áíáðáñéóôÜíåôáé ìå +1 ãéá spin up êáé -1 ãéá spin down. Ìéá åðéðëÝïí âåëôßùóç ðïõ êÜíïõìå áöïñÜ óôïí ÷åéñéóìü ôçò ìíÞìçò.3. ãéá N = 4 Ý÷ïõìå prob[4] = 1/(prob ∗ prob). 2 machine cycle êáé xor. óõíåðþò Ý÷ïõìå ôç äõíáôüôçôá áðïèÞêåõóçò 32 ôéìþí spin óå êÜèå èÝóç ìíÞìçò.÷.66. Ç ìÝóç ìáãíÞôéóç åßíáé ç ðáñÜìåôñïò ôÜîçò ðïõ ìåôáâáßíåé áðü ìç ìçäåíéêÞ óå ìçäåíéêÞ ôéìÞ êáôÜ ôç ìåôáôñïðÞ öÜóçò. Åíáò ðñþôïò ðñïóäéïñéóìüò ôïõ óçìåßïõ ðïõ óõìâáßíåé ç ìåôáôñïðÞ öÜóçò ìðïñåß íá ãßíåé ìå ôïí åðéóùñåõôÞ ôåôÜñôçò ôÜîçò. ÁõôÞ ç ìÝèïäïò ìáò äßíåé Tc = 2. 22 . N=4. äßíåé ∆E = 0 • ÐëÞèïò ãåéôüíùí ìå ßäéï spin. Ç êáìðýëç åßíáé óõíå÷Þò ìå êëßóç ðïõ äåí ðáñïõóéÜæåé áóõíÝ÷åéåò.3 ðáñáôçñïýìå áëëáãÞ ôùí êïßëùí ôçò êáìðýëçò. Ç ýðáñîç ìåôáôñïðÞ öÜóçò óôç èåñìïêñáóßá áõôÞ ãßíåôáé åìöáíÞò êáé áðü ôá õðüëïéðá äéáãñÜììáôá ðïõ áêïëïõèïýí. N=1. ôá ïðïßá ðñïò ôï ðáñüí âëÝðïõí 32bit äéåõèýíóåéò ìíÞìçò). ð. Ç ôéìÞ ôçò êñßóéìçò èåñìïêñáóßáò ðïõ ðñïêýðôåé áíáëõôéêÜ åßíáé Tc = 2. áëëÜ ìå ìéêñü áíôßêôõðï óôéò åðéäüóåéò êáèþò ïé áðáéôïýìåíåò åíôïëÝò (instructions) áðáéôïýí åëÜ÷éóôïõò êýêëïõò ìç÷áíÞò (ð. Ìå ôïí ôñüðï áõôü. ÁðïôåëÝóìáôá õðïëïãéóìþí Óôï ó÷Þìá (11) öáßíåôáé ç ìåôáâïëÞ ôçò ìÝóçò åíÝñãåéáò óõíáñôÞóåé ôçò èåñìïêñáóßáò. Óôç ôéìÞ 2. Ïé ñïõôßíåò áðïèÞêåõóçò êáé áíÜêôçóçò åíüò spin ãßíïíôáé ëßãï ðïëõðëïêüôåñåò (bitwise operations). äßíåé ∆E = +4 • ÐëÞèïò ãåéôüíùí ìå ßäéï spin. ç áðüäïóç óôç ÷ñÞóç ôçò ìíÞìçò áõîÜíåé 32 öïñÝò. N=2. 1 machine cycle).3. ìðïñïýìå íá óþæïõìå ôá spin up êáé spin down ìå 1 êáé 0 áíôßóôïé÷á. ÁêñéâÝóôåñïò õðïëïãéóìüò ôçò êñßóéìçò èåñìïêñáóßáò ìðïñåß íá ãßíåé ìÝóù ôùí äéáãñáììÜôùí ôçò åéäéêÞò èåñìüôçôáò êáé ôçò åðéäåêôéêüôçôáò óõíáñôÞóåé ôçò èåñìïêñáóßáò. äßíåé ∆E = +8 • ÐëÞèïò ãåéôüíùí ìå ßäéï spin. ÊïíôÜ óôç èåñìïêñáóßá áõôÞ Ý÷ïõìå êáé ìçäåíéóìü ôçò ìÝóçò ìáãíÞôéóçò. N=3. äßíåé ∆E = −8 Áðïöåýãïõìå êáé ðÜëé ôïí Üóêïðï õðïëïãéóìü åêèåôéêþí üñùí ïñßæïíôáò ôç ìåôáâëçôÞ prob = exp(−4Jint /T ) ïðüôå ïé üñïé ðïõ áíôéóôïé÷ïýí óå äéáöïñåôéêÜ ðëÞèç ãåéôüíùí ßäéïõ spin õðïëïãßæïíôáé ìÝóù ôçò prob.÷. ËáìâÜíïíôáò äå õðüøçí üôé óôá óýã÷ñïíá PC ç åêôÝëåóç åíôïëþí åßíáé pipelined (pipelined instruction execution) ôï õðïëïãéóôéêü êüóôïò ìåéþíåôáé óôï åëÜ÷éóôï.• ÐëÞèïò ãåéôüíùí ìå ßäéï spin. shr. Ìå ôç ìÝèïäï áõôÞ ðáßñíïõìå Tc = 2. Ìéá èÝóç ìíÞìçò áíôéóôïé÷åß óå 32 bits (áíáöåñüìáóôå óå PC. Ôá óçìåßá óôá ïðïßá ðáñïõóéÜæïíôáé êïñõöÝò áíôéóôïé÷ïýí óôç êñßóéìç èåñìïêñáóßá. Ï ìçäåíéóìüò ôçò äåõôÝñáò ðáñáãþãïõ ôçò åíÝñãåéáò åßíáé ÷áñáêôçñéóôéêü ìåôáôñïðÞò öÜóçò äåõôÝñáò ôÜîçò. äßíåé ∆E = −4 • ÐëÞèïò ãåéôüíùí ìå ßäéï spin. Áíôß íá óþæïõìå óå ðßíáêá áêåñáßùí ôá ±1 ãéá êÜèå spin. N=0.

6 0.1 1. Ç áëëáãÞ êïßëùí êïíôÜ óôç èåñìïêñáóßá 2.0 1.3 åßíáé ÷áñáêôçñéóôéêü ìåôáôñïðÞò öÜóçò äåõôÝñáò ôÜîçò.8 -0.0 Tc 2.5 -0.8 0.5 2.3 Ý÷ïõìå ìçäåíéóìü ôçò ìÝóçò ìáãíÞôéóçò.5 3. 23 .2 0.0 -1.9 -1. 1.5 kBT/Jnn Ó÷Þìá 12: ÌÝóç ìáãíÞôéóç óõíáñôÞóåé ôçò èåñìïêñáóßáò.7 L=20 -0.4 <E> -0. ÊïíôÜ óôç èåñìïêñáóßá 2.0 Ó÷Þìá 11: ÌÝóç åíÝñãåéá óõíáñôÞóåé ôçò èåñìïêñáóßáò.6 -0.0 L=4 L=10 L=20 L=60 |M| 0.0 2.0 1.4 0.5 2.-0.5 kBT/Jnn 4.3 -0.0 3.0 3.5 3.

30 2.0010 Cv 0. 0.0 2.0012 L=20 0.55 0.34 kBT/Jnn Ó÷Þìá 13: ÅðéóùñåõôÞò ôåôÜñôçò ôÜîçò óõíáñôÞóåé ôçò èåñìïêñáóßáò.32 2.266 Ý÷ïõìå ôïìÞ ôùí êáìðýëùí ðïõ áíôéóôïé÷ïýí óå äéáöïñåôéêÜ ìåãÝèç ôïõ äéäéÜóôáôïõ ðëÝãìáôïò.0 kBT/Jnn Ó÷Þìá 14: ÅéäéêÞ èåñìüôçôá óõíáñôÞóåé ôçò èåñìïêñáóßáò. Ç êïñõöÞ áíôéóôïé÷åß óôç êñßóéìç èåñìïêñáóßá Tc .0004 0.0002 0. 24 . Óôç èåñìïêñáóßá 2.24 2.3 Ý÷ïõìå ôçí åìöÜíéóç êïñõöÞò.60 0.0006 0.22 2.0 3.20 2.50 0.45 2.5 3.65 0.0000 1.0 1.0008 0. Óôç èåñìïêñáóßá 2.U4 L=10 L=20 L=40 0.5 4.26 2.28 2.5 2.

00 1.0 1. 25 .15 0.20 L=20 χ 0.10 0.0.0 3.5 3. Ç êïñõöÞ áíôéóôïé÷åß óôç êñßóéìç èåñìïêñáóßá Tc .3 Ý÷ïõìå ôçí åìöÜíéóç êïñõöÞò.5 2.5 4.05 0.0 kBT/Jnn Ó÷Þìá 15: Åðéäåêôéêüôçôá óõíáñôÞóåé ôçò èåñìïêñáóßáò. Óôç èåñìïêñáóßá 2.0 2.

26 .

ÐáñÜñôçìá A Source Code 27 .

Computational Physics Physics Dept.l.10) ..x. duration = (double)(finish . if(y<f) N0++.h> <time.1 = 1023. f=pow(x.\n". I=0.I. so arbitraraly 1024 printf("Monte Carlo integral evaluation.b.1..1 #include #include #include #include <stdio.0f "..6e %+10. // x={1.){ printf("Evaluating. printf("Course: Simulation of Physical Systems\n"). finish. University of Patras Course: Simulation of Physical Systems Problem 3.duration). int main(int argc. double N.\n")..I.1\n").2} y=y0*ran1(&dum).ran1(&dum)).1. for(N=100. // Setting x edges (for generality) a=1. I=N0/N*l*y0. ran1(&dum). Koukaras\n").i<N.N0. // Initialize random number generator dum=-time(NULL). printf("\r%10.0/IM) #define IQ 127773 #define IR 2836 #define NTAB 32 #define NDIV (1+(IM-1)/NTAB) #define EPS 1.6e%% %9. l=b-a.0-EPS) double ran1(long *). } 28 . printf("Integral evaluation of f(x) = x^10 . printf("%10. } finish = clock().i++) printf("RND%d: %f\n". A.f. for(i=0.N*=10.N<1e+9./Iexact.M.h> <math.fabs(error)*100. b=2. printf(" N (MCpoints) Evaluated error err (percent) time (sec)\n").h> <stdlib. start = clock().char *argv[]) { clock_t start. printf("----------------------------------------------------------------------------\n").CPP // // // // // // Monte Carlo Integral Evaluation Emmanuel N.Iexact. printf("Problem 3.M..6e %9.2e-7 #define RNMX (1. MCINT. N0=0.. // maxval y0=2^10 .N). /* for(i=0. long dum. error=I-Iexact.i++){ x=ran1(&dum) + 1.error.: 198\n\n"). Koukaras.1\n").i<10.y0. printf("A.h> // Globals used by ran1() #define IA 16807 #define IM 2147483647 #define AM (1.1. */ // Initializing vars Iexact=2047. double a. y0=1024..").6f. double duration. printf("Emmanuel N.start) / CLOCKS_PER_SEC.error.Iexact)./11 . int i.5f\n". printf("Expected value: %10.: 198 Postgraduate Student.i.y.

0 // .return 0. static long iy=0. if(*idum <=0 || !iy){ if(-(*idum)<1) *idum=1. if(j<NTAB)iv[j] = *idum. j=iy/NDIV. *idum=IA*(*idum-k*IQ)-IR*k. } // ------------------------------------------------------------------------// Random number generator of Park and Miller with Bays-Durham shuffle // Returns a uniform random deviate between 0. RNMX should // approximate the largest floating value that is less than 1. long k.j--){ k=(*idum)/IQ. *idum=IA*(*idum-k*IQ)-IR*k. iy=iv[j]. } iy=iv[0]. thereafter. else return temp. if(*idum<0) *idum += IM. iv[j] = *idum. double temp.Call with idum a negative integer to initialize. if(*idum < 0) *idum += IM. for(j=NTAB+7. static long iv[NTAB]. // ------------------------------------------------------------------------double ran1(long *idum) { int j.j>=0. } k=(*idum)/IQ. else *idum = -(*idum). } 29 . if((temp=AM*iy) > RNMX) return RNMX.0 and 1. do not // alter idum between successive deviates in a sequence.

N0=0.: 198 Postgraduate Student.i++){ x=ran1(&dum).M..N*=10){ printf("Evaluating.0/IM) #define IQ 127773 #define IR 2836 #define NTAB 32 #define NDIV (1+(IM-1)/NTAB) #define EPS 1. for(i=0.char *argv[]) { int i. if(d<1) N0++. */ printf("Monte Carlo Pi evaluation.0 and 1. for(N=100. d=sqrt(x*x + y*y).P. MCPI.. } printf("\r%10.N<1e+9. // ------------------------------------------------------------------------double ran1(long *idum) 30 . thereafter. error=P-PI.N0. printf("Monte Carlo evaluation of Pi\n").M.error. printf(" N (MCpoints) Evaluated error err (percent)\n").i++) printf("RND%d: %f\n".: 198\n\n"). University of Patras Course: Simulation of Physical Systems Problem 3. long dum. Koukaras./PI).0f ". double N.6f %+8. printf("Expected value: %11.3\n").").ran1(&dum)). Computational Physics Physics Dept.2e-7 #define RNMX (1.i<10. printf("Problem 3.3 #include #include #include #include <stdio.CPP // // // // // // Monte Carlo Pi Evaluation Emmanuel N.h> <stdlib.h> // Globals used by ran1() #define IA 16807 #define IM 2147483647 #define AM (1. Koukaras\n")..2.y. printf("--------------------------------------------------------\n"). printf("%8.x. /* for(i=0. do not // alter idum between successive deviates in a sequence. d=0. y=ran1(&dum). return 0.0-EPS) //#define N 100000 #define PI 3. P=0.\n").0 // .1415926535897932384626433832795 double ran1(long *). int main(int argc.6f } %8.i<N.N).Call with idum a negative integer to initialize. //Initialize random number generator dum=-time(NULL).7f.\n".h> <time..6f %%\n". double d. printf("A.i. P=4*N0/N.h> <math. } // ------------------------------------------------------------------------// Random number generator of Park and Miller with Bays-Durham shuffle // Returns a uniform random deviate between 0. RNMX should // approximate the largest floating value that is less than 1. printf("Emmanuel N.error. printf("Course: Simulation of Physical Systems\n")..fabs(error)*100.P.PI). A. ran1(&dum).

if(j<NTAB)iv[j] = *idum. if(*idum < 0) *idum += IM. double temp. } iy=iv[0].{ int j. j=iy/NDIV. long k. *idum=IA*(*idum-k*IQ)-IR*k. else *idum = -(*idum). if(*idum <=0 || !iy){ if(-(*idum)<1) *idum=1.j>=0. if((temp=AM*iy) > RNMX) return RNMX. static long iy=0.j--){ k=(*idum)/IQ. iv[j] = *idum. *idum=IA*(*idum-k*IQ)-IR*k. else return temp. if(*idum<0) *idum += IM. iy=iv[j]. for(j=NTAB+7. } 31 . } k=(*idum)/IQ. static long iv[NTAB].

M. // Initialize random number generator dum=-time(NULL). double num.i++) printf("RND%d: %f\n". finish.\n".2 #include #include #include #include <stdio.N++){ printf("%f\n". double N. // redefine it to demonstrate dependence of integral on shooting area printf("Monte Carlo integral evaluation. Computational Physics Physics Dept. // Inverse Paragousa of sampling funcion int main(int argc.x5dev(&dum)). */ // Initializing vars Iexact=2047.h> <math. double duration. //maxval of y0 (now of f/g). long dum. // Paragousa of sampling function aG(double).h> // Globals used by ran1() #define IA 16807 #define IM 2147483647 #define AM (1.N<1000. Koukaras\n").Iexact.i<10. l=b-a. double a. printf("Emmanuel N.char *argv[]) { clock_t start. ran1(&dum). y0=f(b)/g(b).2\n"). a=G(a). printf("A. 32 .: 198\n\n")..N0..6f. // Setting x edges (for generality) a=1. b=2. /* for(N=1.b. printf(" N (MCpoints) Evaluated error err (percent) time (sec)\n").0/IM) #define IQ 127773 #define IR 2836 #define NTAB 32 #define NDIV (1+(IM-1)/NTAB) #define EPS 1. printf("Integral evaluation of f(x) = x^10 . Koukaras.1.y0.\n"). double h. printf("Problem 3.y. g(double). b=G(b).h> <stdlib. double double double double f(double). A. printf("Course: Simulation of Physical Systems\n").: 198 Postgraduate Student.i.10)-1)/pow(b.h> <time...2e-7 #define RNMX (1. printf("Expected value: %10. University of Patras Course: Simulation of Physical Systems Problem 3.0-EPS) double ran1(long *). MCINTIS. // Sampling function G(double).1\n"). /* for(i=0.10). int i. printf("----------------------------------------------------------------------------\n").3.l.error./11 .x.M.Iexact).CPP // // // // // // Monte Carlo Integral Evaluation Emmanuel N. used to define shooting box area //y0=(pow(b.. double cosdev(long *).ran1(&dum)). double x5dev(long *i). printf("Using Importance Sampling\n").I.

RNMX should // approximate the largest floating value that is less than 1.N*=10. // ------------------------------------------------------------------------double ran1(long *idum) { int j.0 // .(1. } return 0.10) .i<N. } */ double g(double x){ return pow(x.Call with idum a negative integer to initialize.){ printf("Evaluating.5f\n"..0)..6e %+10./6. } double f(double x){ return pow(x.I.*x.)/11.. x=aG(num).*x. } double aG(double x){ return pow(6. duration = (double)(finish .)). } // ------------------------------------------------------------------------// Random number generator of Park and Miller with Bays-Durham shuffle // Returns a uniform random deviate between 0. while(num==0. 33 . // Is this conclusion correct? /* double g(double x){ return pow(x.start) / CLOCKS_PER_SEC. } // Conclusion: // We note that the evaluation via MC importance sampleing is // worthwile _only_ when a _very_ good approximation is made for the // probability function. start = clock().fabs(error)*100. error=I-Iexact./Iexact. printf("%10.. } double aG(double x){ return pow(11. I=0.)/6. y=y0*ran1(&dum). h=f(x)/g(x). long k. do not // alter idum between successive deviates in a sequence.)).. thereafter.10).5). } double G(double x){ return pow(x. N0=0./11.6e %9.11. if(y<h) N0+=1.} //exit(0).duration). printf("\r%10.0f ". */ // Change integration variable and edges of integration: // Int_a^b[fdx] = Int_a^b[(f/g)gdx] = Int_Ga^Gb[(f/g)dG] for(N=10. } finish = clock()..0 and 1. // Be sure to use the correct edges when using importance sampling: num=a + (b-a)*num.N).1.i++){ do num=ran1(&dum).error.6.6e%% %9.(1. I=N0/N*l*y0. for(i=0. } double G(double x){ return pow(x.N<1e+8.").

.j>=0. //dum = 1.). if(*idum<0) *idum += IM. //return pow(6. j=iy/NDIV. for(j=NTAB+7. + (2. *idum=IA*(*idum-k*IQ)-IR*k. random deviate // of unit mean.1. {x.static long iy=0. if(*idum <=0 || !iy){ if(-(*idum)<1) *idum=1. 0. // Inverse of Paragousa of f(x) = x^5 return 6.*pow(6. do dum=ran1(idum)./6. *idum=IA*(*idum-k*IQ)-IR*k.1. if(*idum < 0) *idum += IM. positive. } iy=iv[0]. } k=(*idum)/IQ. else *idum = -(*idum).j--){ k=(*idum)/IQ. double temp. using ran1(idum) as the source of uniform deviates // Integrate[x^5. static long iv[NTAB]. 0. } // ---------------------------------------------------------------------// Returns a x^5slly distributed. if((temp=AM*iy) > RNMX) return RNMX. else return temp.).*dum. 1}] = 1/6 /// Integrate[6*x^(1/6).)*dum.0). while(dum==0. if(j<NTAB)iv[j] = *idum.1. {x. // Inverse of Paragousa of f(x) = x^5 } 34 ./6. iv[j] = *idum. 1}] = 36/7 // ---------------------------------------------------------------------double x5dev(long *idum) { double dum.*dum. iy=iv[j].

// Constructor 35 . // Not really needed double avmag2. double. Binder #include #include #include #include <iostream> <iomanip> <cmath> "ran1. // take a measurement double getavE(void). long.CPP // // // // // // // // Monte Carlo Ising chain Emmanuel N. // dump out chain void getchain(char *).h" #include <time. // Constructor ~Chain(). D. // All spins are stored in the unsigned integer pointer *cp. long. University of Patras Course: Simulation of Physical Systems Study of an Ising chain (i. Koukaras. void f_writeres(FILE *. // get number of neighbors with differing spin void dump(void). // average energy * nmeas double avmag. double getCv(void).M. // One spin corresponds to one bit. // magnetic susceptability long nmeas. thus a 32-bit (NBITS) integer stores 32 spins. // Not really needed double U4. // number of measurements */ private: unsigned long* cp. // Not really needed double avmag4.h> using namespace std. // fourth order cumulant of order parameter (magnetization) double Cv. // Access to single spins is achieved by bitwise operations. // Size in NBITS long words }. A. // Destructor unsigned long getspin(long).4. void f_splash(FILE *). Landau & K. // Size of the Ising Chain long Nx.. // # of bits in an unsigned int // Defenition of Chain Class. // average magnetization * nmeas double avmag2. double. // Write output file header void f_writepars(FILE *. // fourth order cumulant of order parameter (magnetization) double Cv. // returns image of ising chain as string of "+" and "-" void measure(double). long.e.long . // Pointer to chain’s spin data long N. // Not really needed double avE2.// get a spin void flipspin(long). // specific heat double chi. double E. // Current configuration Energy double mag. Chain *). // Not really needed double U4. double. void reset(void). // Generate a chain with all spins up void alldown(void). // average magnetization * nmeas double avE2. ISINGCH. 1D problem) ref code: Reinhard M. // Generate a random chain void allup(void). // average energy * nmeas double avmag. // Current configuration Magnetisation double avE. const int NBITS=32. Noack ref book: MC Sims in Statistical Physics. // flip a spin void ranch(int*). // ------------------------------------------------------------------------class Chain{ public: Chain(long). // number of measurements /* double avE. double Jint. Computational Physics Physics Dept. double getU4(void). double getavMag(void). double. // Not really needed double avmag4. double . // Generate a chain with all spins down long getprob(long). // magnetic susceptability long nmeas. // specific heat double chi.: 198 Postgraduate Student. int).

avmag4 = 0. x < Nx . avmag = 0. } // ranch -. for (x = 0 . } // alldown -.generates a random chain // ------------------------------------------------------------------------void Chain::ranch(int* seed){ long x. // Size in NBITS long words cp = new unsigned long[Nx]. x++) // Set all spins down (x counts words) cp[x] = 0.5) flipspin(x).(x % NBITS)-1)) & 01). x < Nx . } // allup -. avmag2 = 0.total : total). for (x = 0 . xp = (x < N-1) ? x+1 : 0. Nx = (N/NBITS) + 1.xp. x++) // Set spins up by random (x counts spins) if (ran1(seed) >= 0.(x%NBITS)-1)). x++) // Set all spins up (x counts words) cp[x] = 0xFFFFFFFF.generates a chain with all spins up // ------------------------------------------------------------------------void Chain::allup(void){ long x. } // Destructor // ------------------------------------------------------------------------Chain::~Chain(){ delete[] cp.flips a spin at x (by XORing) // ------------------------------------------------------------------------inline void Chain::flipspin(long x){ cp[long(x/NBITS)] ^= (01 << (NBITS . // Enforce Periodic Boundary Conditions on chain xm = (x > 0) ? x-1 : N-1. nmeas = 0. } // dump prints out the chain as +(up) and -(down) // ------------------------------------------------------------------------- 36 . avE2 = 0. // Size of the Ising Chain avE = 0. } // getprob counts the number of nearest neighbors with _same_ spin from // the one at (x) // Only nn contribute to change in energy dE when a flipspin occurs. x < Nx .xm. // dE will then be: dE = 2 for each pair that went from same to different // dE = -2 for each pair that went from different to same // ------------------------------------------------------------------------long Chain::getprob(long x){ long total.gets a spin as an unsigned int (0 or 1 for down and up) // ------------------------------------------------------------------------inline unsigned long Chain::getspin(long x){ return((cp[long(x/NBITS)] >> (NBITS . for (x = 0 .// ------------------------------------------------------------------------Chain::Chain(long size){ N = size. } // flipspin -. } // getspin -. x < N .generates a chain with all spins down // ------------------------------------------------------------------------void Chain::alldown(void){ long x. for (x = 0 . x++) // Set all spins down (x counts words) cp[x] = 0. return( (getspin(x) == 0) ? 2 . total = getspin(xp) + getspin(xm).

} else if (val == 0){ buffer[x] = ’-’.average magnetization. 37 . for(i = 0.e. ndown++. } // Takes a measurement. } else{ cerr << "getspin failure at (" << x << ")\n". the current configuration is not taken // into account.m4. for (long x = 0 .). delete[] buffer. mag // . } buffer[N] = 0.magnetization of current configuration. } buffer[N] = 0. i.. } strcpy(string. } else{ cerr << "getspin failure at (" << x << ")\n".mm..dM. x < N . exit(1). im=N. avE2 += E*E. i++){ E = E + (getspin(i)==0 ? -1. E=0.e. avE/nmeas // Warning: if measurement is not taken.m. x++ ){ if ((val = getspin(x)) == 01){ buffer[x] = ’+’. long nup = 0.)*(getspin(im)==0 ? -1. avemag/nmeas // . : 1.. unsigned long val.i < N.ee. x < N . x++ ){ if ((val = getspin(x)) == 01){ buffer[x] = ’+’. exit(1). mag = mag + (getspin(i)==0 ? -1. mag=0. delete[] buffer. long ndown = 0. im = i.energy of current configuration. it does not contribute to avE and avemag // ------------------------------------------------------------------------void Chain::measure(double T){ long i. for (long x = 0 . } // getchain returns a string of the chain as +(up) and -(down) // ------------------------------------------------------------------------void Chain::getchain(char *string){ char* buffer = new char[N+2].average energy. double dE. // increase measurement counter // Calculate sums for averages avE += E. : 1. } // Energy & Magnitisation per spin E = -E/double(N).void Chain::dump(void){ char* buffer = new char[N+2]. evaluates: // . i. mag = mag/double(N). long nup = 0.im. ndown++. unsigned long val. } else if (val == 0){ buffer[x] = ’-’. nup++. double e.). buffer). : 1. } cout << buffer << "\n". nup++. long ndown = 0. nmeas++. E // .

reject..T. nmeas=0. ee = avE2/nmeas. FILE *out. *outim. long itemp.skip.n ne1=ne1+Ispin(j)*Ispin(jm) nh1=nh1+Ispin(j) jm=j 1 continue */ } void Chain::reset(void){ avE=0. char stemp[800]... mcstps.Tf. mm = avmag2/nmeas.0 .. /* code snippet from Landau ne1=0 nh1=0 jm=n do 1 j=1.ballup.. } double Chain::getCv(void){ return 0. chi = dM / T. // Forth Order Cumulant..m*m.e*e..ntoss. // Calculate averages e = avE/nmeas. avmag4 += pow(mag. double double double double Jint. Cv = dE / (T*T). accept. prob. long long long long N... avmag4=0. // ballup: boolean var for allup long i. finish. probs[3].Ti. int dum.m4/(3. m4 = avmag4/nmeas. r.xt.avmag += mag. //double duration. } int main(int argc.x. U4 = 1. dM = mm . double ftemp.4). avmag2 += mag*mag. Specific Heat and Susceptability dE = ee . // Reset all counter for new T and do mcstps at new T avE2=0.0*mm*mm). m = avmag/nmeas. } double Chain::getavMag(void){ return 0.bps. } // Functions members of Chain that return results of measurments double Chain::getavE(void){ return 0. avmag=0. avmag2=0.char *argv[]){ //clock_t start. } double Chain::getU4(void){ return 0. // Initialize vars 38 .beta.

ntoss=1000.&itemp).. [1. stemp[0]=0.Jint).]: "). [3. do{ scanf("%lf". // ---=== Splash credits ===--printf("Monte Carlo Ising Chain.0.3.&ftemp). printf("Emmanuel N.0.Tf).mcstps).bps=0. [3. printf("\nGive the coupling constant 0.N).<=Ti<=10.Ti).<Tf<=1000. || ftemp > 1000. 3.). // Initialize random number generator dum = -time(NULL). do{ scanf("%d". }while(ftemp < 0. if (ftemp != 0. }while(itemp < 1 || itemp > 100000). 0. if(T!=Tf){ printf("\nGive the temperature increment -10. N=80. ballup=1. [0. do{ scanf("%lf". ftemp=T. // T = 300.&ftemp).) Jint = ftemp. // Boolean.: 198\n\n"). Jint=1. printf("A. || ftemp > 1000. ran1(&dum). printf("\nAll spins initially up (. do{ scanf("%lf". ftemp=Tf. Tf=3. if (itemp != 0) ntoss = itemp. printf("Ti=%f\n". do{ scanf("%d". if (ftemp != 0.&itemp). }while(itemp < 10 || itemp > 100000). || Ti > 10. do{ 39 . Default is not to print chain on screen. printf("Course: Simulation of Physical Systems\n"). 30. }while(ftemp < 0. }while(itemp < 0 || itemp > 1000000). printf("\nGive the initial temperature 0. printf("Give the length of chain 0<N<=1000000 [80]: ").<T<=1000.). printf("ntoss=%d\n".\n")... if(itemp==0) break. T=3. if (itemp != 0) N = itemp. do{ scanf("%d".&ftemp). printf("Jint=%f\n". printf("N=%d\n". }while(ftemp < 0. Ti=0. if (itemp != 0) mcstps = itemp. || ftemp > 30.]: ").&itemp). printf("T=%f\n".) Tf = ftemp. if(itemp==0) break..]: "). }while(Ti < -10.M.else random)?: (y/n) [y]: ").). // ---=== Get data from keyboard ===--itemp=N. ftemp=Jint.&Ti). printf("\nGive the number of steps to reach equilibrium 1<=ntoss<=100000 [1000]: "). do{ scanf("%lf". printf("\nGive the final temperature 0.) T = ftemp.T).).<Jint<=30. mcstps=100. if (ftemp != 0. itemp=ntoss. printf("\nGive the number of MC-steps 10<=mcstps<=100000 [100]: "). } itemp=mcstps... printf("Tf=%f\n".ntoss). printf("mcstps=%d\n". Koukaras\n").]: ").

if(N<81){ // f_writepars(outim.. printf("Spins up: %s\n". N. else if (strcmp(stemp. x < N ..ranch(&dum). // Using skip instead of ntoss retains ntoss in loop.stemp).ntoss. }while(strcmp(stemp. // xt=x.Ti."n") !=0). beta=Jint/T.ballup)..Ti. accept++.T.stemp).out".Jint. if (r < probs[Ich. f_writepars(out. Chain Ich(N).stemp). } // ------====== Start Monte Carlo ======-----accept = 0. x++){ // v------====== main MC loop ======------v r = ran1(&dum).."y")!=0 && strcmp(stemp.ballup). no check is done."y")==0 || strcmp(stemp. if(strcmp(stemp. reject = 0.0 nn’s the same spin as the site probs[1] = 1. else if (strcmp(stemp. printf("Simulating. do{ skip=ntoss.out". // ^------====== main MC loop ======------^ } 40 ."n") !=0).allup()."n")==0 || strcmp(stemp. is input for default break.exiting\n")."0")==0) // 0. if(bps && N<81) Ich. Ich. exit(0).getchain(stemp).T. Ich.*beta)."wb"). if(strcmp(stemp. if(N<81) f_splash(outim). "-----------------------.reset(). "%s\n"./prob.out. } else reject++. and other not at all.1. else Ich. stemp[0]=0.Jint. fprintf(outim. // With this double for loop many spins are examined twice.exiting\n"). }while(strcmp(stemp. xt= N*ran1(&dum).ntoss. exit(0). } if(N<81){ outim = fopen("IChainSnaps. for (i=1 .. if(out==NULL){ printf("io error opening IChain. if(outim==NULL){ printf("io error opening IChainSnaps..\n")."0")==0) // 0.. do MC without taking measurements. // Change in Energy depends on num of nn with same spin // On spinflip energy changes by dE = 4 or -4 (for magnetic field =0). // when spins are represented by /sigma_i = +-1. N.ballup==0 ? "no" : "yes"). probs[2] = prob."y")==0) bps=1.out. ntoss times (relax) for (x = 0 . is input for default break.. if(ballup==1) Ich.flipspin(xt). fprintf(outim."n")==0) ballup=0. prob = exp(-4."wb").getprob(xt)]){ Ich.mcstps. } } // ---=== Write output file header ===--f_splash(out).Tf. i++){ // When changing T.\n\n".. // Probabilities for having 2.mcstps. do{ scanf("%s".\n.scanf("%s".\n.Ising Chain snapshots ------------------------\n").bps==0 ? "Not p" : "P"). // ---=== Open output files ===--out = fopen("IChain."y")!=0 && strcmp(stemp.dump(). printf("%srinting chain to screen. i <= (mcstps + ntoss). printf("\nPrint chain to screen?(for chains N<=80): (y/n) [n]: "). probs[0] = 1.

"%s\n". N).Simulation Parameters --------.\n")."-----------------------. } // f_writepars -. long mcstps. T. double T. mcstps).0) ) && (T > 0. fprintf(out.7lf %11.getchain(stemp).Writes credits to output file // ------------------------------------------------------------------------void f_splash(FILE *out){ fprintf(out.\n"). double Jint. long ntoss. ich->U4."Final Temperature Tf = %lf\n". &Ich). Ti)."All spins initially oriented up.stemp).0){ f_writeres(out.7lf %11."Monte Carlo Ising Chain.e. <80) if(bps) Ich.e. } 41 . if(N<81){ // print to screen when chain is small (i.0).) && Ti!=0."------------------------.5lf %11.7lf %11.start --------\n")."-----------------------------. \ mcstp.0 ) || (T >= fabs(Tf+1. ich->Cv.getchain(stemp).: 198\n\n").end -----------\n"). return 0. fprintf(out.skip--. fprintf(out. double T. fprintf(out. if(ballup) fprintf(out. fprintf(out.end ---------\n\n"). Tf)."-----------------------. } T+=Ti."Emmanuel N. ich->avmag/ich->nmeas."%6ld %9.0) f_writeres(out. fprintf(out. double Tf. } // f_splash -. long N. if(N<81){ // print to screen when chain is small (i. double Ti. "%s\n".e-6) && Ti>0. <80) if(bps) Ich.7lf\n". fprintf(out. cout << "Total accept: " << double(accept)/double(reject + accept) << "\n". } } } // ---=== Output results ===--if(Ti!=0. int ballup){ fprintf(out. fclose(out).dump(). i-1.Simulation Results -----------. fprintf(outim.Simulation Parameters ---------."Length of Ising Chain: N = %ld\n".Simulation Results -------------. fprintf(out."Coupling Constant Jint = %lf\n"."Course: Simulation of Physical Systems\n"). fprintf(outim. }while(( (T <= fabs(Tf+1.\n").ntoss)."A.7lf %11." MSCTP T <E> <M> U4 Cv x \n").Writes results to output file // ------------------------------------------------------------------------void f_writeres(FILE *out."Spins initially oriented at random. Chain *ich){ fprintf(out.e-6) && Ti<0. fprintf(out. T.measure(T).long mcstp.start -----------\n"). if(N<81) fclose(outim). Jint)."Temperature Increment Ti = %lf\n".ich->chi)."Initial Temperature T = %lf\n". if(skip<0 && Ti==0. Koukaras\n").stemp). fprintf(out. fprintf(out. T.dump(). Ich. } // f_writeres -.M. else fprintf(out."Number of steps to reach equilibrium ntoss = %ld\n". Ich. fprintf(out. fprintf(out. fprintf(out."----------------------------------------------------------------------------------\n"). &Ich). T)."Number of MC-steps mcstps = %ld\n". i-ntoss. if(skip<0) Ich.Writes starting parameters to output file // ------------------------------------------------------------------------void f_writepars(FILE *out. ich->avE/ich->nmeas. fprintf(out.

double Jint. // Pointer to lattice’s spin data long N. // Generate a 2D lattice with all spins down long getprob(long.: 198 Postgraduate Student.long . // Generate a 2D lattice with all spins up void alldown(void). double double double double getavE(void).long. double. // Write output file header void f_writepars(FILE *. long. getCv(void).h> using namespace std. // Destructor unsigned long getspin(long.M. Lattice2D *). double. Koukaras. getavMag(void).. double . long. const int NBITS=32. // magnetic susceptability long nmeas. // ------------------------------------------------------------------------class Lattice2D{ public: Lattice2D(long. void f_splash(FILE *). // Not really needed double U4. // flip a spin void ranlat(int*).long). // dump out Lattice void getlattice(char *). // Constructor ~Lattice2D(). double. 42 . long. dM. // Not really needed double avmag4. Computational Physics Physics Dept. void f_writeres(FILE *. ISINGL. // take a measurement void Lattice2D::reset(void). // Generate a random 2D lattice void allup(void).h" #include <time.5. getU4(void).long). int). // specific heat double chi. long sizey){ N = sizex*sizey. Noack ref book: MC Sims in Statistical Physics. thus a 32-bit (NBITS) integer stores 32 spins. // average energy * nmeas double avmag. // Constructor // ------------------------------------------------------------------------Lattice2D::Lattice2D(long sizex.long). // Size of each row in NBITS long words long Nx. // # of bits in an unsigned int // Defenition of Chain Class. // Size of the Ising Lattice in spin sites Nx=sizex. long.CPP // // // // // // // // // Monte Carlo Ising 2D lattice Emmanuel N. 1D problem) ref code: Reinhard M. A. double. // All spins are stored in the unsigned integer pointer *cp. // Width of lattice long Ny. // One spin corresponds to one bit. // Hight of lattice // Holding vars of properties to be printed in output // dE. Binder ------------------------------------------------------------------------- #include #include #include #include <iostream> <iomanip> <cmath> "ran1. // Current configuration Energy double mag.long). // fourth order cumulant of order parameter (magnetization) double Cv. // returns image of ising lattice as string of "+" and "-" void measure(double). Landau & K. D. // Current configuration Magnetisation double avE. // Size of the Ising Lattice in spin sites long Nwx. // Access to single spins is achieved by bitwise operations. // average magnetization * nmeas double avmag2. University of Patras Course: Simulation of Physical Systems Study of an Ising chain (i. // number of measurements private: unsigned long** lp. // Not really needed double avE2. // get number of neighbors with differing spin void dump(void). // get a spin void flipspin(long. double E.e. not needed in output and eval on the fly }.

y < Ny . x++) // Set all spins up (x counts words) lp[y][x] = 0xFFFFFFFF. Nwx = (sizex/NBITS) + 1. } // getspin -. for (y = 0 . mag = 0. avE2 = 0. long y){ return((lp[y][long(x/NBITS)] >> (NBITS . delete[] lp.flips a spin at (x. // dE will then be: dE = 2 for each pair that went from same to different // dE = -2 for each pair that went from different to same // ------------------------------------------------------------------------long Lattice2D::getprob(long x.generates a 2D Lattice with all spins up // ------------------------------------------------------------------------void Lattice2D::allup(void){ long x.xp. for (y = 0 . y < Ny . y++ ) { for (x = 0 . y++ ) for (x = 0 .5) flipspin(x. } // Destructor // ------------------------------------------------------------------------Lattice2D::~Lattice2D(){ for (int i = 0 . for (y = 0 .xm. // Size of each row in NBITS long words E = 0.y. } } // allup -.Ny=sizey. x < Nwx . } // alldown -.generates a random 2D lattice // ------------------------------------------------------------------------void Lattice2D::ranlat(int* seed){ long x. for (x = 0 . i++) lp[i] = new unsigned long[Nwx].(x%NBITS)-1)).y. i < Ny . y < Ny . avmag = 0. nmeas = 0. // 2d matrix of form lp[Ny][] for (int i = 0 . long y){ lp[y][long(x/NBITS)] ^= (01 << (NBITS .y.gets the spin at (x. } // flipspin -.y). xp = (x < Nx-1) ? x+1 : 0. y++ ) for (x = 0 .y) (by XORing) // ------------------------------------------------------------------------inline void Lattice2D::flipspin(long x. x < Nwx . x++) // Set spins up by random (x counts spins) if (ran1(seed) >= 0. i++) delete[] lp[i]. x++) // Set all spins down (x counts words) lp[y][x] = 0.y) as an unsigned int (0 or 1 for down and up) // ------------------------------------------------------------------------inline unsigned long Lattice2D::getspin(long x. avE = 0. long y){ long total.(x % NBITS)-1)) & 01). i < Ny . } // getprob counts the number of nearest neighbors with _same_ spin from // the one at (x) // Only nn contribute to change in energy dE when a flipspin occurs.ym.yp. // Enforce Periodic Boundary Conditions on chain 43 . } // ranch -. x < Nx . x < Nwx . avmag2 = 0. lp = new unsigned long*[Ny].generates a chain with all spins down // ------------------------------------------------------------------------void Lattice2D::alldown(void){ long x. avmag4 = 0. x++) // Set all spins down (x counts words) lp[y][x] = 0.

for (y = 0 .. x < Nx . yp = (y < Ny-1) ? y+1 : 0.m4. } else{ cerr << "getspin failure at (" << x << ".y.. the current configuration is not taken // into account. y++ ) for (x = 0 . long nup = 0. buffer). long ndown = 0. x < Nx . nup++. y++ ) for (x = 0 . ndown++.xm = (x > 0) ? x-1 : Nx-1.average magnetization. i. 44 . yp) + getspin(x. i.mm.m.j. unsigned long val. delete[] buffer. y) + getspin(x. } buffer[N] = 0.e. char* buffer = new char[N+2]. it does not contribute to avE and avemag // ------------------------------------------------------------------------void Lattice2D::measure(double T){ long i.magnetization of current configuration.y)) == 01){ buffer[y*Ny + x] = ’+’." << y << ")\n". nup++. E // .y.e.energy of current configuration. x++ ){ if ((val = getspin(x. double dE." << y << ")\n".total : total). y < Ny . delete[] buffer. mag // . } else{ cerr << "getspin failure at (" << x << ". } else if (val == 0){ buffer[y*Ny + x] = ’-’. y < Ny . strcpy(string. avE/nmeas // Warning: if measurement is not taken. long ndown = 0. } cout << buffer << "\n". ym). for (y = 0 . unsigned long val. } // getchain returns a string of the chain as +(up) and -(down) // ------------------------------------------------------------------------void Lattice2D::getlattice(char *string){ long x. } } buffer[N] = 0.y) == 0) ? 4 . } // Takes a measurement.ee. x++ ){ if ((val = getspin(x. double e.im.. long nup = 0. return( (getspin(x. ndown++.dM. evaluates: // . } // dump prints out the chain as +(up) and -(down) // ------------------------------------------------------------------------void Lattice2D::dump(void){ long x. exit(1). ym = (y > 0) ? y-1 : Ny-1.jm. E=0. char* buffer = new char[N+2]. y) + getspin(xm. // Count total neighboring sites with spin up total = getspin(xp. y)) == 01){ buffer[y*Ny + x] = ’+’. } else if (val == 0){ buffer[y*Ny + x] = ’-’.average energy. exit(1). mag=0. avemag/nmeas // .

} // Energy & Magnitisation per spin E = -E/double(N).m4/(3. for(j = 0. FILE *out. } // Functions members of 2D Lattice that return results of measurments double Lattice2D::getavE(void){ return 0.j)==0 ? -1.i < Nx. 45 .n ne1=ne1+Ispin(j)*Ispin(jm) nh1=nh1+Ispin(j) jm=j 1 continue */ } void Lattice2D::reset(void){ avE=0.)*(getspin(i. avmag4=0.char *argv[]){ //clock_t start.j)==0 ? -1. m4 = avmag4/nmeas.m*m. avmag2=0.im=Nx-1... i++){ E = E + (getspin(i.0*mm*mm).) + (getspin(i.jm)==0 ? -1. avmag += mag.j < Ny. } double Lattice2D::getavMag(void){ return 0. // Reset all counter for new T and do mcstps at new T avE2=0.. finish. dM = mm .0 . mm = avmag2/nmeas.. j++) for(i = 0.)*(getspin(im. /* code snippet from Landau ne1=0 nh1=0 jm=n do 1 j=1. // increase measurement counter // Calculate sums for averages avE += E. Specific Heat and Susceptability dE = ee . jm = j. //double duration. m = avmag/nmeas.j)==0 ? -1. nmeas=0. } int main(int argc. mag = mag/double(N). avmag=0. avmag4 += pow(mag. avE2 += E*E.). // Forth Order Cumulant. : 1.e*e..j)==0 ? -1. : 1. } double Lattice2D::getCv(void){ return 0.. : 1. chi = dM / T. *outim. ee = avE2/nmeas. } double Lattice2D::getU4(void){ return 0. avmag2 += mag*mag. // Calculate averages e = avE/nmeas.4). U4 = 1. : 1.).. im = i.. mag = mag + (getspin(i. : 1. / nmeas++. Cv = dE / (T*T).. jm=Ny-1.

}while(ftemp < 0. printf("Jint=%f\n". printf("Ny=%d\n". 46 .char stemp[8000]. long long long long N. // ---=== Get data from keyboard ===--itemp=Nx. }while(ftemp < 0. if (itemp != 0) Ny = itemp. N=Nx*Ny. // Initialize random number generator dum = -time(NULL).) Jint = ftemp.ballup. N=2500. printf("Course: Simulation of Physical Systems\n"). }while(itemp < 0 || itemp > 1000000). [3. Tf=3. reject. ftemp=T.bps.Ti.<T<=1000. ftemp=Jint.&ftemp). if (itemp != 0) Nx = itemp. T=3.&ftemp).Ny. do{ scanf("%lf".Tf. // Boolean. int dum. probs[5].Jint).xt. printf("Give the width of lattice 0<Ny<=1000000 [50]: ")...<Tf<=1000. printf("\nGive the coupling constant 0.&itemp). [1.} printf("Ti=%f\n".y. printf("Emmanuel N.]: ").skip. do{ scanf("%d".Nx). ran1(&dum). printf("N=%d\n". Ti=0.).&itemp).T. printf("\nGive the initial temperature 0. mcstps. double ftemp. long itemp. // ---=== Splash credits ===--printf("Monte Carlo 2D Ising Lattice. printf("\nGive the final temperature 0. // ballup: boolean var for allup long i. if (ftemp != 0.: 198\n\n").M. if (ftemp != 0. printf("Nx=%d\n".<Jint<=30. Jint=1.x. Koukaras\n").&ftemp).]: "). double double double double Jint.T). do{ scanf("%d". Default is not to print chain on screen. printf("Give the width of lattice 0<Nx<=1000000 [50]: "). [3.beta. ntoss=1000. itemp=Ny.Ny). do{ scanf("%lf".N).]: "). Ny=50..Nx. prob. do{ scanf("%lf". printf("A..ntoss.). || ftemp > 1000. accept.) {T = ftemp. // Initialize vars bps=0. }while(itemp < 0 || itemp > 1000000). || ftemp > 30. ftemp=Tf. r. ballup=1. Nx=50.yt. mcstps=100.\n").

.stemp)..]: ").stemp). exit(0). f_writepars(out..ntoss). exit(0)."wb"). } 47 ."y")!=0 && strcmp(stemp.out".&itemp).\n.}while(ftemp < 0. fprintf(outim."n")==0 || strcmp(stemp.). [0.stemp).Ny). do{ scanf("%d". "-----------------------. stemp[0]=0.Ising Lattice snapshots ------------------------\n").mcstps). if(out==NULL){ printf("io error opening ILattice. N.. printf("Tf=%f\n"."n")==0) ballup=0. else if (strcmp(stemp. } if(N<401){ outim = fopen("ILatticeSnaps. itemp=ntoss."y")==0) bps=1.else random)?: (y/n) [y]: "). is input for default break.mcstps."y")!=0 && strcmp(stemp. if(outim==NULL){ printf("io error opening ILatticeSnaps.. if(strcmp(stemp. printf("Simulating. } itemp=mcstps. if(itemp==0) break.\n"). printf("\nGive the number of steps to reach equilibrium 1<=ntoss<=100000 [1000]: ").Ny. printf("Spins up: %s\n". if(itemp==0) break.ballup)."0")==0) // 0. if(bps && N<401) Il. printf("\nGive the number of MC-steps 10<=mcstps<=100000 [100]: ").allup(). printf("mcstps=%d\n". do{ scanf("%lf". is input for default break. printf("\nPrint chain to screen?(for chains N<=80): (y/n) [n]: ").ranlat(&dum).) Tf = ftemp. }while(itemp < 10 || itemp > 100000). stemp[0]=0. else if (strcmp(stemp. if (ftemp != 0.exiting\n"). || ftemp > 1000. if(ballup==1) Il. if (itemp != 0) mcstps = itemp.Tf. do{ scanf("%d". do{ scanf("%s".\n.ntoss.. }while(strcmp(stemp.Ti.Jint. printf("%srinting chain to screen..ballup==0 ? "no" : "yes").T. if(N<401){ f_splash(outim). // ---=== Open output files ===--out = fopen("ILattice. Il. }while(itemp < 1 || itemp > 100000)."y")==0 || strcmp(stemp."n") !=0). if(T!=Tf){ printf("\nGive the temperature increment -10.\n\n"."wb").Ti).out.&Ti).Nx. }while(Ti < -10. }while(strcmp(stemp.<=Ti<=10. Lattice2D Il(Nx. } } // ---=== Write output file header ===--f_splash(out).out". do{ scanf("%s"."0")==0) // 0.&itemp). if(strcmp(stemp. Il.dump().bps==0 ? "Not p" : "P").out."n") !=0).exiting\n"). printf("ntoss=%d\n". || Ti > 10. printf("Ti=%f\n".. else Il. if (itemp != 0) ntoss = itemp. fprintf(outim.Jint=Jint. "%s\n". printf("\nAll spins initially up (.Tf).).getlattice(stemp).

.stemp). } T+=Ti. i-1.3. } // f_splash -. fprintf(out."Emmanuel N.start --------\n"). // xt=x.e.stemp). long nto fprintf(out..0) ) && (T > 0. i <= (mcstps + ntoss). "%s\n". accept++. &Il).getprob(xt. if(N<401){ // print to screen when chain is small (i. if (r < probs[Il.2.M. <80) if(bps) Il.0 ) || (T >= fabs(Tf+1.e-6) && Ti>0."-----------------------------. xt= Nx*ran1(&dum).reset().getlattice(stemp)."A. 48 . and other not at all. probs[0] = 1. i++){ // v------====== main MC loop ======------v for (y = 0 .Writes credits to output file // ------------------------------------------------------------------------void f_splash(FILE *out){ fprintf(out.e-6) && Ti<0. <80) if(bps) Il. // when spins are represented by /sigma_i = +-1.dump(). for (i=1 . // Using skip instead of ntoss retains ntoss in loop. y < Ny . } // f_writepars -.yt)]){ Il. prob = exp(-4. fprintf(out.\n"). } else reject++. &Il).. long mcstps.getlattice(stemp). }while(( (T <= fabs(Tf+1.Simulation Results --------------.1.measure(T)."-----------------------.0 nn’s the same spin as the site probs[1] = 1.Simulation Parameters --------. probs[4] = (prob*prob).yt).0){ f_writeres(out. // yt=y. Il. long N. double Jint. double Ti.// ------====== Start Monte Carlo ======-----accept = 0.*beta). // ^------====== main MC loop ======------^ } skip--. if(skip<=0) Il. Il. if(N<401) fclose(outim). T. fclose(out)."Monte Carlo 2D Ising Lattice.: 198\n\n"). probs[2] = 1. x++){ r = ran1(&dum). long Nx. beta=Jint/T.-8 (for magnetic field =0). double Tf. T. do MC without taking measurements. x < Nx .0.e.0) f_writeres(out. Il. do{ skip=ntoss+1. fprintf(out. return 0.dump(). // With this double for loop many spins are examined twice. reject = 0.0).flipspin(xt. i. ntoss times (relax) for (x = 0 . no check is done. fprintf(out. "%s\n". // Change in Energy depends on num of nn with same spin // On spinflip energy changes by dE = 8. } } } // ---=== Output results ===--if(Ti!=0.4. if(skip<=0 && Ti==0./(prob*prob). fprintf(outim. y++) // When changing T.) && Ti!=0.-4.end ------------\n")."Course: Simulation of Physical Systems\n"). probs[3] = prob.Writes starting parameters to output file // ------------------------------------------------------------------------void f_writepars(FILE *out. Koukaras\n"). double T. long Ny. cout << "Total accept: " << double(accept)/double(reject + accept) << "\n". fprintf(outim. if(N<401){ // print to screen when chain is small (i./prob. yt= Ny*ran1(&dum). // Probabilities for having 4.

fprintf(out.ntoss)."Length of Ising Lattice: Ny = %ld\n"."Temperature Increment Ti = %lf\n".Simulation Parameters ---------. il->Cv."Final Temperature Tf = %lf\n".end ---------\n\n")." MSCTP T <E> <M> U4 Cv x \n"). Lattice2D *il){ fprintf(out. fprintf(out.long mcstp.7lf %11. N). double T. il->avmag/il->nmeas."Spins initially oriented at random. Ti). else fprintf(out."Coupling Constant Jint = %lf\n". fprintf(out. \ mcstp."Width of Ising Lattice: Nx = %ld\n". if(ballup) fprintf(out. Nx). fprintf(out. fprintf(out.7lf %11. Tf). fprintf(out.\n").Writes results to output file // ------------------------------------------------------------------------void f_writeres(FILE *out. T.7lf %11."%6ld %9. mcstps). T). il->chi). fprintf(out."Total number of spins on Ising Lattice: N = %ld\n".\n")."All spins initially oriented up.7lf\n".Simulation Results -------------. il->avE/il->nmeas. Jint)."Initial Temperature T = %lf\n". } 49 . Ny)."-----------------------------."----------------------------------------------------------------------------------\n")."-----------------------. il->U4.7lf %11. fprintf(out.5lf %11. } // f_writeres -.fprintf(out. fprintf(out."Number of steps to reach equilibrium ntoss = %ld\n"."Number of MC-steps mcstps = %ld\n".start -----------\n"). fprintf(out. fprintf(out. fprintf(out.

50 .

[6] M. Mod. 1976. M. N. Prog. Saul A. [3] L. Rosenbluth. Rev. 1992. Cambridge. Fisher. Phys. Thomson Learning.. A. A. 1944. Rev. 2000. A Guide to Monte Carlo Simulations in Statistical Physics. Metropolis. and E. 1974. 2nd edition. Rep. Onsager. Rosenbluth. 46(597). M. Numerical Recipes in C. J. 21(1087). Phys. [4] Kurt Binder. Ashcroft and N. B. and Brian P. Flannery. Teller. Press. 1st edition. Cambridge University Press. Phys. Phys. 65(117). 51 . 1967. 30(615). 1953. E. Phys. [2] William H. 43(119). Vetterling. Z. Landau and Kurt Binder. Teller. 1981. David Mermin. Teukolsky. [8] Neil W.. William T. W. [5] M. E.Âéâëéïãñáößá [1] David P. 1st edition.. [7] N. Fisher. Chem. Solid State Physics.

Sign up to vote on this title
UsefulNot useful