avm99963 | 9622dc7 | 2022-04-29 15:44:05 +0200 | [diff] [blame] | 1 | program p2e1 |
| 2 | implicit none |
| 3 | integer*4, PARAMETER :: L = 32 |
| 4 | integer*2 :: S(1:L, 1:L) |
| 5 | real*8 :: MAGNE, ENERG, TEMP, E, DIFE, DELTA, M, SUMA, W(-8:8), genrand_real2 |
| 6 | integer*4 :: PBC(0:L+1), I, J, IMC, MCTOT, IPAS, N, SEED |
| 7 | |
| 8 | ! Inicialitzem algunes variables sobre el problema |
| 9 | TEMP = 1.3d0 |
| 10 | SEED = 234567 |
| 11 | MCTOT = 3000 |
| 12 | N = L*L |
| 13 | |
| 14 | ! Inicialitzem variable que ens fa latent la periodicitat |
| 15 | PBC(0) = L |
| 16 | PBC(L + 1) = 1 |
| 17 | do I = 1, L |
| 18 | PBC(I) = I |
| 19 | enddo |
| 20 | |
| 21 | ! Cache dels valors de l'exponencial |
| 22 | do I = -8, 8 |
| 23 | W(I) = exp(-float(I)/TEMP) |
| 24 | enddo |
| 25 | |
| 26 | ! Inicialitzem la matriu d'spins aleatòriament |
| 27 | call WRITECONFIG(S, L) |
| 28 | |
| 29 | E = ENERG(S, L, PBC) |
| 30 | M = MAGNE(S, L) |
| 31 | print *, "Energia inicial:", E, "Magnet. inicial:", M |
| 32 | |
| 33 | ! Iterem amb el mètode de Montecarlo |
| 34 | do IMC = 1, MCTOT |
| 35 | do IPAS = 1, N |
| 36 | ! LOS LOOPS HACEN COSAS |
| 37 | I = INT(genrand_real2()*L) + 1 |
| 38 | J = INT(genrand_real2()*L) + 1 |
| 39 | SUMA = S(PBC(I - 1), J) + S(PBC(I + 1), J) + S(I, PBC(J - 1)) + S(I, PBC(J + 1)) |
| 40 | DIFE = 2*SUMA*S(I, J) |
| 41 | |
| 42 | if (DIFE > 0) then |
| 43 | DELTA = genrand_real2() |
| 44 | if (DELTA >= W(int(DIFE))) then |
| 45 | ! NO ho acceptem |
| 46 | cycle |
| 47 | endif |
| 48 | endif |
| 49 | |
| 50 | ! Sí ho acceptem: |
| 51 | S(I, J) = -S(I, J) |
| 52 | E = E + DIFE |
| 53 | M = M + 2*S(I, J) |
| 54 | enddo |
| 55 | print *, "Iter:", IMC, "Energia:", E, "Recalc.:", ENERG(S, L, PBC), "Magn:", INT(M), "Recalc.:", INT(MAGNE(S, L)) |
| 56 | enddo |
| 57 | endprogram p2e1 |