1
0
mirror of https://github.com/TREX-CoE/qmc-lttc.git synced 2024-07-17 08:30:45 +02:00
qmc-lttc/qmc_metropolis.f90

59 lines
1.6 KiB
Fortran
Raw Normal View History

2021-01-20 18:31:49 +01:00
subroutine metropolis_montecarlo(a,nmax,tau,energy,accep)
implicit none
double precision, intent(in) :: a
integer*8 , intent(in) :: nmax
double precision, intent(in) :: tau
double precision, intent(out) :: energy
double precision, intent(out) :: accep
integer*8 :: istep
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-20 18:31:49 +01:00
double precision, external :: e_loc, psi, gaussian
energy = 0.d0
2021-01-26 10:02:38 +01:00
n_accep = 0_8
2021-01-20 18:31:49 +01:00
call random_number(r_old)
r_old(:) = tau * (2.d0*r_old(:) - 1.d0)
psi_old = psi(a,r_old)
do istep = 1,nmax
call random_number(r_new)
r_new(:) = r_old(:) + tau * (2.d0*r_new(:) - 1.d0)
psi_new = psi(a,r_new)
ratio = (psi_new / psi_old)**2
call random_number(v)
2021-01-26 10:02:38 +01:00
if (v <= ratio) then
2021-01-20 18:31:49 +01:00
r_old(:) = r_new(:)
psi_old = psi_new
2021-01-26 10:02:38 +01:00
n_accep = n_accep + 1_8
2021-01-20 18:31:49 +01:00
endif
energy = energy + e_loc(a,r_old)
end do
2021-01-26 10:02:38 +01:00
energy = energy / dble(nmax)
accep = dble(n_accep) / dble(nmax)
2021-01-20 18:31:49 +01:00
end subroutine metropolis_montecarlo
program qmc
implicit none
double precision, parameter :: a = 0.9d0
double precision, parameter :: tau = 1.3d0
integer*8 , parameter :: nmax = 100000
integer , parameter :: nruns = 30
integer :: irun
double precision :: X(nruns), Y(nruns)
double precision :: ave, err
do irun=1,nruns
call metropolis_montecarlo(a,nmax,tau,X(irun),Y(irun))
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
end program qmc