| program main |
| implicit none |
| integer*4, PARAMETER :: L = 32 |
| integer*2 :: S(1:L, 1:L) |
| real*8 :: MAGNE, ENERG, TEMP, E, DIFE, DELTA, M, SUMA, W(-8:8), genrand_real2 |
| integer*4 :: PBC(0:L+1), I, J, IMC, MCTOT, IPAS, N, SEED |
| character :: TEMPSTRING*100, str*20 |
| |
| if (command_argument_count() < 1) then |
| print *, "Error: please supply a command-line argument with the" |
| print *, "temperature, via './mc1 {TEMPERATURE}', where {TEMPERATURE}" |
| print *, "is the temperature." |
| stop |
| endif |
| |
| ! Inicialitzem algunes variables sobre el problema |
| call get_command_argument(1, TEMPSTRING) ! Ex: 2.0d0 |
| TEMPSTRING = trim(adjustl(TEMPSTRING)) |
| read (TEMPSTRING, *) TEMP |
| SEED = 234567 |
| MCTOT = 10000 |
| N = L*L |
| |
| ! Obrim el fitxer on escriurem els resultats a cada iteració |
| open(unit = 12, file = "out_data/" // "SIM-L-" // trim(str(L)) // "-TEMP-" // & |
| trim(str(int(1000*TEMP))) // "-MCTOT-" // trim(str(MCTOT)) //".out") |
| |
| ! Inicialitzem variable que ens fa latent la periodicitat |
| PBC(0) = L |
| PBC(L + 1) = 1 |
| do I = 1, L |
| PBC(I) = I |
| enddo |
| |
| ! Cache dels valors de l'exponencial |
| do I = -8, 8 |
| W(I) = exp(-float(I)/TEMP) |
| enddo |
| |
| ! Inicialitzem la matriu d'spins aleatòriament |
| call WRITECONFIG(S, L) |
| |
| E = ENERG(S, L, PBC) |
| M = MAGNE(S, L) |
| print *, "Energia inicial:", E, "Magnet. inicial:", M |
| write (12, *) "0", E, M |
| |
| ! Iterem amb el mètode de Montecarlo |
| do IMC = 1, MCTOT |
| do IPAS = 1, N |
| ! LOS LOOPS HACEN COSAS |
| I = INT(genrand_real2()*L) + 1 |
| J = INT(genrand_real2()*L) + 1 |
| SUMA = S(PBC(I - 1), J) + S(PBC(I + 1), J) + S(I, PBC(J - 1)) + S(I, PBC(J + 1)) |
| DIFE = 2*SUMA*S(I, J) |
| |
| if (DIFE > 0) then |
| DELTA = genrand_real2() |
| if (DELTA >= W(int(DIFE))) then |
| ! NO ho acceptem |
| cycle |
| endif |
| endif |
| |
| ! Sí ho acceptem: |
| S(I, J) = -S(I, J) |
| E = E + DIFE |
| M = M + 2*S(I, J) |
| enddo |
| if (mod(IMC, 1000) == 0) then |
| print *, "Iter:", IMC, "Energia:", E, "Magn:", INT(M) |
| endif |
| write (12, *) IMC, E, M |
| enddo |
| |
| ! Tanquem el fitxer de sortida |
| close(12) |
| endprogram main |