1
0
mirror of https://github.com/TREX-CoE/qmc-lttc.git synced 2024-10-13 11:31:50 +02:00
qmc-lttc/qmc_uniform.f90

50 lines
992 B
Fortran
Raw Normal View History

2021-01-07 10:01:55 +01:00
subroutine uniform_montecarlo(a,nmax,energy)
implicit none
double precision, intent(in) :: a
2021-01-12 10:55:00 +01:00
integer*8 , intent(in) :: nmax
2021-01-07 10:01:55 +01:00
double precision, intent(out) :: energy
2021-01-07 11:07:18 +01:00
2021-01-29 13:23:00 +01:00
integer*8 :: istep
2021-01-07 10:01:55 +01:00
double precision :: norm, r(3), w
double precision, external :: e_loc, psi
energy = 0.d0
norm = 0.d0
2021-01-29 13:23:00 +01:00
2021-01-07 10:01:55 +01:00
do istep = 1,nmax
2021-01-29 13:23:00 +01:00
2021-01-07 10:01:55 +01:00
call random_number(r)
r(:) = -5.d0 + 10.d0*r(:)
2021-01-29 13:23:00 +01:00
2021-01-07 10:01:55 +01:00
w = psi(a,r)
w = w*w
2021-01-29 13:23:00 +01:00
2021-01-07 10:01:55 +01:00
energy = energy + w * e_loc(a,r)
2021-01-29 13:23:00 +01:00
norm = norm + w
2021-01-07 10:01:55 +01:00
end do
2021-01-29 13:23:00 +01:00
2021-01-07 10:01:55 +01:00
energy = energy / norm
2021-01-29 13:23:00 +01:00
2021-01-07 10:01:55 +01:00
end subroutine uniform_montecarlo
program qmc
implicit none
double precision, parameter :: a = 1.2d0
2021-01-29 13:23:00 +01:00
integer*8 , parameter :: nmax = 100000
2021-01-07 10:01:55 +01:00
integer , parameter :: nruns = 30
2021-01-29 13:23:00 +01:00
integer :: irun
2021-01-07 10:01:55 +01:00
double precision :: X(nruns)
double precision :: ave, err
do irun=1,nruns
2021-01-29 13:23:00 +01:00
call uniform_montecarlo(a, nmax, X(irun))
2021-01-07 10:01:55 +01:00
enddo
2021-01-29 13:23:00 +01:00
call ave_error(X, nruns, ave, err)
2021-01-07 10:01:55 +01:00
print *, 'E = ', ave, '+/-', err
end program qmc