2021-01-29 13:23:00 +01:00
|
|
|
subroutine metropolis_montecarlo(a,nmax,dt,energy,accep)
|
2021-01-20 18:31:49 +01:00
|
|
|
implicit none
|
|
|
|
double precision, intent(in) :: a
|
|
|
|
integer*8 , intent(in) :: nmax
|
2021-01-29 13:23:00 +01:00
|
|
|
double precision, intent(in) :: dt
|
2021-01-20 18:31:49 +01:00
|
|
|
double precision, intent(out) :: energy
|
|
|
|
double precision, intent(out) :: accep
|
|
|
|
|
2021-01-26 10:02:38 +01:00
|
|
|
double precision :: r_old(3), r_new(3), psi_old, psi_new
|
|
|
|
double precision :: v, ratio
|
|
|
|
integer*8 :: n_accep
|
2021-01-29 13:23:00 +01:00
|
|
|
integer*8 :: istep
|
|
|
|
|
2021-01-20 18:31:49 +01:00
|
|
|
double precision, external :: e_loc, psi, gaussian
|
|
|
|
|
2021-01-29 13:23:00 +01:00
|
|
|
energy = 0.d0
|
2021-01-26 10:02:38 +01:00
|
|
|
n_accep = 0_8
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-20 18:31:49 +01:00
|
|
|
call random_number(r_old)
|
2021-01-29 13:23:00 +01:00
|
|
|
r_old(:) = dt * (2.d0*r_old(:) - 1.d0)
|
2021-01-20 18:31:49 +01:00
|
|
|
psi_old = psi(a,r_old)
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-20 18:31:49 +01:00
|
|
|
do istep = 1,nmax
|
2021-01-29 13:23:00 +01:00
|
|
|
energy = energy + e_loc(a,r_old)
|
|
|
|
|
2021-01-20 18:31:49 +01:00
|
|
|
call random_number(r_new)
|
2021-01-29 13:23:00 +01:00
|
|
|
r_new(:) = r_old(:) + dt*(2.d0*r_new(:) - 1.d0)
|
|
|
|
|
2021-01-20 18:31:49 +01:00
|
|
|
psi_new = psi(a,r_new)
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-20 18:31:49 +01:00
|
|
|
ratio = (psi_new / psi_old)**2
|
|
|
|
call random_number(v)
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-26 10:02:38 +01:00
|
|
|
if (v <= ratio) then
|
2021-01-29 13:23:00 +01:00
|
|
|
|
|
|
|
n_accep = n_accep + 1_8
|
|
|
|
|
2021-01-20 18:31:49 +01:00
|
|
|
r_old(:) = r_new(:)
|
|
|
|
psi_old = psi_new
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-20 18:31:49 +01:00
|
|
|
endif
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-20 18:31:49 +01:00
|
|
|
end do
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-26 10:02:38 +01:00
|
|
|
energy = energy / dble(nmax)
|
|
|
|
accep = dble(n_accep) / dble(nmax)
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-20 18:31:49 +01:00
|
|
|
end subroutine metropolis_montecarlo
|
|
|
|
|
|
|
|
program qmc
|
|
|
|
implicit none
|
2021-02-02 13:57:53 +01:00
|
|
|
double precision, parameter :: a = 1.2d0
|
|
|
|
double precision, parameter :: dt = 1.0d0
|
2021-01-20 18:31:49 +01:00
|
|
|
integer*8 , parameter :: nmax = 100000
|
|
|
|
integer , parameter :: nruns = 30
|
|
|
|
|
2021-01-29 13:23:00 +01:00
|
|
|
integer :: irun
|
2021-01-20 18:31:49 +01:00
|
|
|
double precision :: X(nruns), Y(nruns)
|
|
|
|
double precision :: ave, err
|
|
|
|
|
|
|
|
do irun=1,nruns
|
2021-01-29 13:23:00 +01:00
|
|
|
call metropolis_montecarlo(a,nmax,dt,X(irun),Y(irun))
|
2021-01-20 18:31:49 +01:00
|
|
|
enddo
|
2021-01-26 10:02:38 +01:00
|
|
|
|
2021-01-20 18:31:49 +01:00
|
|
|
call ave_error(X,nruns,ave,err)
|
|
|
|
print *, 'E = ', ave, '+/-', err
|
2021-01-26 10:02:38 +01:00
|
|
|
|
2021-01-20 18:31:49 +01:00
|
|
|
call ave_error(Y,nruns,ave,err)
|
|
|
|
print *, 'A = ', ave, '+/-', err
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-20 18:31:49 +01:00
|
|
|
end program qmc
|