2021-01-29 13:23:00 +01:00
|
|
|
subroutine variational_montecarlo(a,dt,nmax,energy)
|
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
|
|
|
|
double precision, intent(out) :: energy
|
|
|
|
|
|
|
|
integer*8 :: istep
|
2021-01-29 13:23:00 +01:00
|
|
|
double precision :: norm, r_old(3), r_new(3), d_old(3), sq_dt, chi(3)
|
2021-01-13 18:11:13 +01:00
|
|
|
double precision, external :: e_loc
|
|
|
|
|
2021-01-29 13:23:00 +01:00
|
|
|
sq_dt = dsqrt(dt)
|
2021-01-13 18:11:13 +01:00
|
|
|
|
|
|
|
! Initialization
|
|
|
|
energy = 0.d0
|
|
|
|
norm = 0.d0
|
|
|
|
call random_gauss(r_old,3)
|
|
|
|
|
|
|
|
do istep = 1,nmax
|
|
|
|
call drift(a,r_old,d_old)
|
|
|
|
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
|
|
|
norm = norm + 1.d0
|
|
|
|
energy = energy + e_loc(a,r_new)
|
|
|
|
r_old(:) = r_new(:)
|
|
|
|
end do
|
|
|
|
energy = energy / norm
|
|
|
|
end subroutine variational_montecarlo
|
|
|
|
|
|
|
|
program qmc
|
|
|
|
implicit none
|
|
|
|
double precision, parameter :: a = 0.9
|
2021-01-29 13:23:00 +01:00
|
|
|
double precision, parameter :: dt = 0.2
|
2021-01-13 18:11:13 +01:00
|
|
|
integer*8 , parameter :: nmax = 100000
|
|
|
|
integer , parameter :: nruns = 30
|
|
|
|
|
|
|
|
integer :: irun
|
|
|
|
double precision :: X(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))
|
2021-01-13 18:11:13 +01:00
|
|
|
enddo
|
|
|
|
call ave_error(X,nruns,ave,err)
|
|
|
|
print *, 'E = ', ave, '+/-', err
|
|
|
|
end program qmc
|