2021-01-29 13:23:00 +01:00
|
|
|
subroutine variational_montecarlo(a,dt,nmax,energy,accep)
|
2021-01-13 18:11:13 +01:00
|
|
|
implicit none
|
2021-01-29 13:23:00 +01:00
|
|
|
double precision, intent(in) :: a, dt
|
2021-01-13 18:11:13 +01:00
|
|
|
integer*8 , intent(in) :: nmax
|
2021-01-29 13:23:00 +01:00
|
|
|
double precision, intent(out) :: energy, accep
|
2021-01-13 18:11:13 +01:00
|
|
|
|
2021-01-29 13:23:00 +01:00
|
|
|
integer*8 :: istep
|
|
|
|
integer*8 :: n_accep
|
|
|
|
double precision :: sq_dt, chi(3), d2_old, prod, u
|
2021-01-13 18:11:13 +01:00
|
|
|
double precision :: psi_old, psi_new, d2_new, argexpo, q
|
|
|
|
double precision :: r_old(3), r_new(3)
|
|
|
|
double precision :: d_old(3), d_new(3)
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
double precision, external :: e_loc, psi
|
|
|
|
|
2021-01-29 13:23:00 +01:00
|
|
|
sq_dt = dsqrt(dt)
|
2021-01-20 21:18:22 +01:00
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
! Initialization
|
2021-01-29 13:23:00 +01:00
|
|
|
energy = 0.d0
|
|
|
|
n_accep = 0_8
|
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
call random_gauss(r_old,3)
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
call drift(a,r_old,d_old)
|
2021-01-29 13:23:00 +01:00
|
|
|
d2_old = d_old(1)*d_old(1) + &
|
|
|
|
d_old(2)*d_old(2) + &
|
|
|
|
d_old(3)*d_old(3)
|
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
psi_old = psi(a,r_old)
|
|
|
|
|
|
|
|
do istep = 1,nmax
|
2021-01-29 13:23:00 +01:00
|
|
|
energy = energy + e_loc(a,r_old)
|
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
call random_gauss(chi,3)
|
2021-01-29 13:23:00 +01:00
|
|
|
r_new(:) = r_old(:) + dt*d_old(:) + chi(:)*sq_dt
|
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
call drift(a,r_new,d_new)
|
2021-01-29 13:23:00 +01:00
|
|
|
d2_new = d_new(1)*d_new(1) + &
|
|
|
|
d_new(2)*d_new(2) + &
|
|
|
|
d_new(3)*d_new(3)
|
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
psi_new = psi(a,r_new)
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
! Metropolis
|
|
|
|
prod = (d_new(1) + d_old(1))*(r_new(1) - r_old(1)) + &
|
2021-01-26 13:11:57 +01:00
|
|
|
(d_new(2) + d_old(2))*(r_new(2) - r_old(2)) + &
|
|
|
|
(d_new(3) + d_old(3))*(r_new(3) - r_old(3))
|
2021-01-29 13:23:00 +01:00
|
|
|
|
|
|
|
argexpo = 0.5d0 * (d2_new - d2_old)*dt + prod
|
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
q = psi_new / psi_old
|
|
|
|
q = dexp(-argexpo) * q*q
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
call random_number(u)
|
2021-01-29 13:23:00 +01:00
|
|
|
|
|
|
|
if (u <= q) then
|
|
|
|
|
|
|
|
n_accep = n_accep + 1_8
|
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
r_old(:) = r_new(:)
|
|
|
|
d_old(:) = d_new(:)
|
2021-01-29 13:23:00 +01:00
|
|
|
d2_old = d2_new
|
|
|
|
psi_old = psi_new
|
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
end if
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
end do
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-26 13:11:57 +01:00
|
|
|
energy = energy / dble(nmax)
|
2021-01-29 13:23:00 +01:00
|
|
|
accep = dble(n_accep) / dble(nmax)
|
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
end subroutine variational_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-29 13:23:00 +01:00
|
|
|
integer*8 , parameter :: nmax = 100000
|
2021-01-13 18:11:13 +01:00
|
|
|
integer , parameter :: nruns = 30
|
|
|
|
|
2021-01-29 13:23:00 +01:00
|
|
|
integer :: irun
|
2021-01-13 18:11:13 +01:00
|
|
|
double precision :: X(nruns), accep(nruns)
|
|
|
|
double precision :: ave, err
|
|
|
|
|
|
|
|
do irun=1,nruns
|
2021-01-29 13:23:00 +01:00
|
|
|
call variational_montecarlo(a,dt,nmax,X(irun),accep(irun))
|
2021-01-13 18:11:13 +01:00
|
|
|
enddo
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
call ave_error(X,nruns,ave,err)
|
|
|
|
print *, 'E = ', ave, '+/-', err
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
call ave_error(accep,nruns,ave,err)
|
|
|
|
print *, 'A = ', ave, '+/-', err
|
2021-01-29 13:23:00 +01:00
|
|
|
|
2021-01-13 18:11:13 +01:00
|
|
|
end program qmc
|