25 real(real64),
parameter ::
tol = 1e-6_real64
52 real(real64) :: alpha = 0.1_real64
53 real(real64) :: x_current = 0.2_real64
54 real(real64) :: x_next = 1.0_real64
55 real(real64) :: res_expected = 0.8253068685_real64
57 real(real64) :: res_actual
60 res_actual =
qho_prob(alpha, x_current, x_next)
62 if (abs(res_actual - res_expected) .ge.
tol)
then
64 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
89 real(real64) :: alpha = 0.15_real64
90 real(real64) :: x = 0.314_real64
91 real(real64) :: res_expected = 0.19486118_real64
93 real(real64) :: res_actual
98 if (abs(res_actual - res_expected) .ge.
tol)
then
100 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
124 real(real64),
dimension(3) :: r_elec = (/1.5_real64, 0.2_real64, -0.5_real64/)
125 real(real64),
dimension(3) :: r_nuc = (/1.0_real64, 0.0_real64, 0.0_real64/)
126 real(real64) :: res_expected = 0.2705734006_real64
128 real(real64) :: res_actual
131 res_actual =
h1s_wfn(r_elec, r_nuc)
133 if (abs(res_actual - res_expected) .ge.
tol)
then
135 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
159 real(real64),
dimension(3) :: r_elec = (/1.5_real64, 0.2_real64, -0.5_real64/)
160 real(real64),
dimension(3) :: r_nuc = (/1.0_real64, 0.0_real64, 0.0_real64/)
161 real(real64) :: res_expected = 0.08738223907_real64
163 real(real64) :: res_actual
166 res_actual =
h2s_wfn(r_elec, r_nuc)
168 if (abs(res_actual - res_expected) .ge.
tol)
then
170 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
195 real(real64) :: c = 0.5_real64
196 real(real64),
dimension(3) :: r = (/1.5_real64, 0.2_real64, -0.5_real64/)
197 real(real64),
dimension(3) :: r_a = (/1.0_real64, 0.0_real64, 0.0_real64/)
198 real(real64),
dimension(3) :: r_b = (/-1.0_real64, 0.0_real64, 0.0_real64/)
199 real(real64) :: res_expected = 0.1731585063_real64
201 real(real64) :: res_actual
206 if (abs(res_actual - res_expected) .ge.
tol)
then
208 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
233 real(real64) :: c = 0.5_real64
234 real(real64),
dimension(3) :: r_current = (/1.5_real64, 0.2_real64, -0.5_real64/)
235 real(real64),
dimension(3) :: r_next = (/1.2_real64, -0.4_real64, -0.8_real64/)
236 real(real64),
dimension(3) :: r_a = (/1.0_real64, 0.0_real64, 0.0_real64/)
237 real(real64),
dimension(3) :: r_b = (/-1.0_real64, 0.0_real64, 0.0_real64/)
238 real(real64) :: res_expected = 0.835383508_real64
240 real(real64) :: res_actual
245 if (abs(res_actual - res_expected) .ge.
tol)
then
247 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
272 real(real64) :: c = 0.5_real64
273 real(real64),
dimension(3) :: r = (/1.5_real64, 0.2_real64, -0.5_real64/)
274 real(real64),
dimension(3) :: r_a = (/1.0_real64, 0.0_real64, 0.0_real64/)
275 real(real64),
dimension(3) :: r_b = (/-1.0_real64, 0.0_real64, 0.0_real64/)
276 real(real64) :: energy_expected = -0.60313643_real64
277 real(real64) :: grad_expected = 0.24532551_real64
279 real(real64) :: energy_actual, grad_actual
282 h2plus%auto_params = .true.
285 if (abs(energy_actual - energy_expected) .ge.
tol)
then
287 write(*,
"('Expected energy: ' F12.8, ', got energy ', F12.8, ' instead.')") energy_expected, energy_actual
288 else if (abs(grad_actual - grad_expected) .ge.
tol)
then
290 write(*,
"('Expected gradient: ' F12.8, ', got gradient ', F12.8, ' instead.')") grad_expected, grad_actual
315 real(real64) :: c_old = 0.5_real64
316 real(real64) :: grad = 0.8_real64
317 real(real64) :: res_expected = -0.3_real64
319 real(real64) :: res_actual
324 if (abs(res_actual - res_expected) .ge.
tol)
then
326 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
351 real(real64) :: s = 1.0_real64
352 real(real64) :: res_expected = 0.78218836_real64
354 real(real64) :: res_actual
359 if (abs(res_actual - res_expected) .ge.
tol)
then
361 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
386 real(real64) :: a = 1.0_real64
387 real(real64) :: beta = 0.4_real64
388 real(real64),
dimension(3) :: r_1 = (/1.5_real64, 0.2_real64, -0.5_real64/)
389 real(real64),
dimension(3) :: r_2 = (/0.5_real64, -0.2_real64, 1.4_real64/)
390 real(real64),
dimension(3) :: r_a = (/1.0_real64, 0.0_real64, 0.0_real64/)
391 real(real64),
dimension(3) :: r_b = (/-1.0_real64, 0.0_real64, 0.0_real64/)
392 real(real64) :: res_expected = 0.34961993_real64
394 real(real64) :: res_actual
397 res_actual =
h_2_wfn(a, beta, r_1, r_2, r_a, r_b)
399 if (abs(res_actual - res_expected) .ge.
tol)
then
401 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
426 real(real64) :: a = 0.1, beta = 0.4
427 real(real64),
dimension(3) :: r_1_current = (/1.5_real64, 0.2_real64, -0.5_real64/)
428 real(real64),
dimension(3) :: r_2_current = (/1.1_real64, -0.5_real64, 2.1_real64/)
429 real(real64),
dimension(3) :: r_1_next = (/1.2_real64, -0.4_real64, -0.8_real64/)
430 real(real64),
dimension(3) :: r_2_next = (/-0.2_real64, -1.3_real64, 1.0_real64/)
431 real(real64),
dimension(3) :: r_a = (/1.0_real64, 0.0_real64, 0.0_real64/)
432 real(real64),
dimension(3) :: r_b = (/-1.0_real64, 0.0_real64, 0.0_real64/)
433 real(real64) :: res_expected = 26.08521296_real64
435 real(real64) :: res_actual
438 res_actual =
h_2_prob(a, beta, r_1_current, r_2_current, r_1_next, r_2_next, r_a, r_b)
440 if (abs(res_actual - res_expected) .ge.
tol)
then
442 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
467 real(real64) :: a = 0.1, beta = 0.4
468 real(real64),
dimension(3) :: r_1 = (/1.5_real64, 0.2_real64, -0.5_real64/)
469 real(real64),
dimension(3) :: r_2 = (/1.1_real64, -0.5_real64, 2.1_real64/)
470 real(real64),
dimension(3) :: r_a = (/1.0_real64, 0.0_real64, 0.0_real64/)
471 real(real64),
dimension(3) :: r_b = (/-1.0_real64, 0.0_real64, 0.0_real64/)
472 real(real64) :: energy_expected = -81.43386904_real64
473 real(real64) :: grad_expected = -0.84912693_real64
475 real(real64) :: energy_actual
476 real(real64) :: grad_actual
479 call h_2_energy(a, beta, r_1, r_2, r_a, r_b, energy_actual, grad_actual)
481 if (abs(energy_actual - energy_expected) .ge.
tol)
then
483 write(*,
"('Expected energy: ' F12.8, ', got energy ', F12.8, ' instead.')") energy_expected, energy_actual
484 else if (abs(grad_actual - grad_expected) .ge.
tol)
then
486 write(*,
"('Expected gradient: ' F12.8, ', got gradient ', F12.8, ' instead.')") grad_expected, grad_actual
511 real(real64) :: beta_old = 0.5_real64
512 real(real64) :: grad = 0.8_real64
513 real(real64) :: res_expected = -0.3_real64
515 real(real64) :: res_actual
520 if (abs(res_actual - res_expected) .ge.
tol)
then
522 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
552 integer(int64) :: seed_set = -1
553 real(real64) :: res_expected = 0.41599935685098144_real64
555 real(real64) :: res_actual
561 if (abs(res_actual - res_expected) .ge.
tol)
then
563 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
591 real(real64),
dimension(3) :: res_expected = (/1.10941582390076, &
592 -0.734250042177316, &
595 real(real64),
dimension(3) :: res_actual
601 if (norm2(res_actual - res_expected) .ge.
tol)
then
603 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
628 real(real64) :: start = 1.0_real64
629 real(real64) :: end = 3.0_real64
630 real(real64) :: num = 3.0_real64
631 real(real64),
dimension(3) :: res_expected = (/1.0_real64, &
635 real(real64),
dimension(:),
allocatable :: res_actual
639 res_actual =
linspace(start,
end, num)
641 if (norm2(res_actual - res_expected) .ge.
tol)
then
643 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
668 real(real64),
dimension(:),
allocatable :: energy_chain
669 real(real64),
dimension(:),
allocatable :: pos_chain
670 real(real64) :: accept_rate
671 real(real64) :: energy_variance
672 real(real64) :: res_expected = 0.510854650956392_real64
674 real(real64) :: res_actual
678 call vqmc_qho(0.5_real64, 100, 10, 2, &
679 0.4_real64, pos_chain, accept_rate, energy_chain, res_actual, &
682 if (abs(res_actual - res_expected) .ge.
tol)
then
684 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
709 real(real64),
dimension(:),
allocatable :: energy_chain
710 real(real64),
dimension(:,:),
allocatable :: pos_chain
711 real(real64),
dimension(:),
allocatable :: dphidc_chain
712 real(real64) :: accept_rate
713 real(real64) :: energy_variance
714 real(real64),
dimension(3) :: r_a = (/1.0_real64, 0.0_real64, 0.0_real64/)
715 real(real64),
dimension(3) :: r_b = (/-1.0_real64, 0.0_real64, 0.0_real64/)
716 real(real64) :: res_expected = -0.590080460643371_real64
718 real(real64) :: res_actual
722 call vqmc_h_2_plus(h2plus%sigma, 100, 10, 2, &
723 0.7_real64, r_a, r_b, pos_chain, accept_rate, energy_chain, res_actual, &
724 energy_variance, dphidc_chain)
726 if (abs(res_actual - res_expected) .ge.
tol)
then
728 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
753 real(real64),
dimension(:),
allocatable :: energy_chain
754 real(real64),
dimension(:,:),
allocatable :: pos_chain_1, pos_chain_2
755 real(real64),
dimension(:),
allocatable :: dphidbeta_chain
756 real(real64) :: accept_rate
757 real(real64) :: energy_variance
758 real(real64),
dimension(3) :: r_a = (/1.0_real64, 0.0_real64, 0.0_real64/)
759 real(real64),
dimension(3) :: r_b = (/-1.0_real64, 0.0_real64, 0.0_real64/)
760 real(real64) :: res_expected = -2.36644573374483_real64
762 real(real64) :: res_actual
766 call vqmc_h_2(h2plus%sigma, 100, 10, 2, 0.5_real64, 0.5_real64, &
767 r_a, r_b, pos_chain_1, pos_chain_2, accept_rate, energy_chain, res_actual, &
768 energy_variance, dphidbeta_chain)
770 if (abs(res_actual - res_expected) .ge.
tol)
then
772 write(*,
"('Expected result: ' F12.8, ', got result ', F12.8, ' instead.')") res_expected, res_actual
798 integer :: total_tests = 19
799 integer :: fail_counter, test_counter
802 write(0,
"('--------------------------------------------------')")
803 write(0,
"('[PROGRAM NAME] Unit Testing Suite')")
804 write(0,
"('--------------------------------------------------')")
805 write(0,
"('*** ', I2, ' function tests implemented, starting... ***')") total_tests
811 test_counter = test_counter + 1
812 write(0,
"('[', I2, '/', I2, '] test_ran1')") test_counter, total_tests
814 if (ierr .eq. 0)
then
815 write(0,
"(' Unit test successful.')")
817 write(0,
"(' *** Unit test failed. ***')")
818 fail_counter = fail_counter + 1
821 test_counter = test_counter + 1
822 write(0,
"('[', I2, '/', I2, '] test_QHO_Prob')") test_counter, total_tests
824 if (ierr .eq. 0)
then
825 write(0,
"(' Unit test successful.')")
827 write(0,
"(' *** Unit test failed. ***')")
828 fail_counter = fail_counter + 1
831 test_counter = test_counter + 1
832 write(0,
"('[', I2, '/', I2, '] test_QHO_Prob')") test_counter, total_tests
834 if (ierr .eq. 0)
then
835 write(0,
"(' Unit test successful.')")
837 write(0,
"(' *** Unit test failed. ***')")
838 fail_counter = fail_counter + 1
841 test_counter = test_counter + 1
842 write(0,
"('[', I2, '/', I2, '] test_QHO_Energy')") test_counter, total_tests
844 if (ierr .eq. 0)
then
845 write(0,
"(' Unit test successful.')")
847 write(0,
"(' *** Unit test failed. ***')")
848 fail_counter = fail_counter + 1
851 test_counter = test_counter + 1
852 write(0,
"('[', I2, '/', I2, '] test_H1s_wfn')") test_counter, total_tests
854 if (ierr .eq. 0)
then
855 write(0,
"(' Unit test successful.')")
857 write(0,
"(' *** Unit test failed. ***')")
858 fail_counter = fail_counter + 1
861 test_counter = test_counter + 1
862 write(0,
"('[', I2, '/', I2, '] test_H2s_wfn')") test_counter, total_tests
864 if (ierr .eq. 0)
then
865 write(0,
"(' Unit test successful.')")
867 write(0,
"(' *** Unit test failed. ***')")
868 fail_counter = fail_counter + 1
871 test_counter = test_counter + 1
872 write(0,
"('[', I2, '/', I2, '] test_H_2_plus_wfn')") test_counter, total_tests
874 if (ierr .eq. 0)
then
875 write(0,
"(' Unit test successful.')")
877 write(0,
"(' *** Unit test failed. ***')")
878 fail_counter = fail_counter + 1
881 test_counter = test_counter + 1
882 write(0,
"('[', I2, '/', I2, '] test_H_2_plus_Prob')") test_counter, total_tests
884 if (ierr .eq. 0)
then
885 write(0,
"(' Unit test successful.')")
887 write(0,
"(' *** Unit test failed. ***')")
888 fail_counter = fail_counter + 1
891 test_counter = test_counter + 1
892 write(0,
"('[', I2, '/', I2, '] test_H_2_plus_Energy')") test_counter, total_tests
894 if (ierr .eq. 0)
then
895 write(0,
"(' Unit test successful.')")
897 write(0,
"(' *** Unit test failed. ***')")
898 fail_counter = fail_counter + 1
901 test_counter = test_counter + 1
902 write(0,
"('[', I2, '/', I2, '] test_H_2_plus_update_c')") test_counter, total_tests
904 if (ierr .eq. 0)
then
905 write(0,
"(' Unit test successful.')")
907 write(0,
"(' *** Unit test failed. ***')")
908 fail_counter = fail_counter + 1
911 test_counter = test_counter + 1
912 write(0,
"('[', I2, '/', I2, '] test_H_2_cusp')") test_counter, total_tests
914 if (ierr .eq. 0)
then
915 write(0,
"(' Unit test successful.')")
917 write(0,
"(' *** Unit test failed. ***')")
918 fail_counter = fail_counter + 1
921 test_counter = test_counter + 1
922 write(0,
"('[', I2, '/', I2, '] test_H_2_wfn')") test_counter, total_tests
924 if (ierr .eq. 0)
then
925 write(0,
"(' Unit test successful.')")
927 write(0,
"(' *** Unit test failed. ***')")
928 fail_counter = fail_counter + 1
931 test_counter = test_counter + 1
932 write(0,
"('[', I2, '/', I2, '] test_H_2_Prob')") test_counter, total_tests
934 if (ierr .eq. 0)
then
935 write(0,
"(' Unit test successful.')")
937 write(0,
"(' *** Unit test failed. ***')")
938 fail_counter = fail_counter + 1
941 test_counter = test_counter + 1
942 write(0,
"('[', I2, '/', I2, '] test_H_2_Energy')") test_counter, total_tests
944 if (ierr .eq. 0)
then
945 write(0,
"(' Unit test successful.')")
947 write(0,
"(' *** Unit test failed. ***')")
948 fail_counter = fail_counter + 1
951 test_counter = test_counter + 1
952 write(0,
"('[', I2, '/', I2, '] test_H_2_update_beta')") test_counter, total_tests
954 if (ierr .eq. 0)
then
955 write(0,
"(' Unit test successful.')")
957 write(0,
"(' *** Unit test failed. ***')")
958 fail_counter = fail_counter + 1
961 test_counter = test_counter + 1
962 write(0,
"('[', I2, '/', I2, '] test_linspace')") test_counter, total_tests
964 if (ierr .eq. 0)
then
965 write(0,
"(' Unit test successful.')")
967 write(0,
"(' *** Unit test failed. ***')")
968 fail_counter = fail_counter + 1
971 test_counter = test_counter + 1
972 write(0,
"('[', I2, '/', I2, '] test_VQMC_QHO')") test_counter, total_tests
974 if (ierr .eq. 0)
then
975 write(0,
"(' Unit test successful.')")
977 write(0,
"(' *** Unit test failed. ***')")
978 fail_counter = fail_counter + 1
981 test_counter = test_counter + 1
982 write(0,
"('[', I2, '/', I2, '] test_VQMC_H_2_plus')") test_counter, total_tests
984 if (ierr .eq. 0)
then
985 write(0,
"(' Unit test successful.')")
987 write(0,
"(' *** Unit test failed. ***')")
988 fail_counter = fail_counter + 1
991 test_counter = test_counter + 1
992 write(0,
"('[', I2, '/', I2, '] test_VQMC_H_2')") test_counter, total_tests
994 if (ierr .eq. 0)
then
995 write(0,
"(' Unit test successful.')")
997 write(0,
"(' *** Unit test failed. ***')")
998 fail_counter = fail_counter + 1
1002 write(0,
"('--------------------------------------------------')")
1003 write(0,
"('Unit testing results:')")
1004 if (fail_counter .eq. 0)
then
1005 write(0,
"(I2, '/', I2, ' unit tests passed!')") test_counter, total_tests
1007 write(0,
"(I2, '/', I2, ' unit tests failed!')") fail_counter, total_tests
1009 write(0,
"('--------------------------------------------------')")
1012 write(0,
"('Unit testing complete, exiting program...')")
Contains derived types, and global variables to store input values of simulation parameters.
integer(int64) seed
Seed for the random number generator.
type(h2plus_type) h2plus
To store inputs for H2 ion system.
Contains local energy and transition probability solvers for available problems.
real(real64) function h_2_cusp(s)
Calculates a value for a given the bond length s by Newton-Raphson iteration.
subroutine h_2_update_beta(beta_old, gradient, beta_new)
Updates the parameter in the problem by dampened steepest descent.
real(real64) function qho_energy(alpha, x)
Calculates local energy for quantum harmonic oscillator problem.
real(real64) function h_2_plus_prob(c, r_current, r_next, R_a, R_b)
Calculates transition probability for the problem.
real(real64) function h_2_plus_wfn(c, r, R_a, R_b)
Calculates trial wavefunction for the problem.
real(real64) function qho_prob(alpha, x_current, x_next)
Calculates transition probability for quantum harmonic oscillator problem.
real(real64) function h1s_wfn(r_elec, R_nuc)
Calculates value of the wavefunction of a hydrogen 1s orbital.
real(real64) function h2s_wfn(r_elec, R_nuc)
[DEPRECATED] Calculates value of the wavefunction of a hydrogen 2s orbital.
subroutine h_2_energy(a, beta, r_1, r_2, R_a, R_b, E_loc, DphiDbeta)
{UPDATE ME} Calculates local energy for the problem.
subroutine h_2_plus_energy(c, r, R_a, R_b, E_loc, gradient)
Calculates local energy for the problem.
real(real64) function h_2_prob(a, beta, r_1_current, r_2_current, r_1_next, r_2_next, R_a, R_b)
Calculates transition probability for the problem.
real(real64) function h_2_wfn(a, beta, r_1, r_2, R_a, R_b)
Calculates trial wavefunction for the problem.
subroutine h_2_plus_update_c(c_old, gradient, c_new)
Updates the parameter in the problem by dampened steepest descent.
Contains unit tests for all major functions in the program.
integer function test_h_2_update_beta()
Tests the H_2_update_beta function in the solvers module.
integer function test_h1s_wfn()
Tests the H1s_wfn function in the solvers module.
integer function test_h_2_plus_prob()
Tests the H_2_plus_Prob function in the solvers module.
integer function test_vqmc_h_2()
Tests the VQMC_H_2 function in the vqmc module.
integer function test_h_2_energy()
Tests the H_2_Energy function in the solvers module.
integer function test_qho_prob()
Tests the QHO_Prob function in the solvers module.
subroutine unit_tests()
Runs all of the unit tests, reporting successes and failures.
integer function test_qho_energy()
Tests the QHO_Energy function in the solvers module.
integer function test_linspace()
Tests the linspace function in the vqmc module.
integer function test_h_2_wfn()
Tests the H_2_wfn function in the solvers module.
integer function test_h_2_plus_update_c()
Tests the H_2_plus_update_c function in the solvers module.
integer function test_h_2_plus_energy()
Tests the H_2_plus_Energy function in the solvers module.
real(real64), parameter tol
Error tolerance in floating point evaluations.
integer function test_h2s_wfn()
Tests the H2s_wfn function in the solvers module.
integer function test_random_normal()
Tests the random_normal function in the vqmc module.
integer function test_vqmc_h_2_plus()
Tests the VQMC_H_2_plus function in the vqmc module.
integer function test_h_2_prob()
Tests the H_2_Prob function in the solvers module.
integer function test_h_2_plus_wfn()
Tests the H_2_plus_wfn function in the solvers module.
integer function test_ran1()
Tests the ran1 function in the vqmc module.
integer function test_vqmc_qho()
Tests the VQMC_QHO function in the vqmc module.
integer function test_h_2_cusp()
Tests the H_2_cusp function in the solvers module.
Contains routines for handline random number generation, the main VQMC algorithms and routines for de...
subroutine ran1(sample, dseed)
Implementation of Press et al's random number generator.
subroutine random_normal(dim, x)
Draws a sample from a normal distribution using the Box-Muller transform.
real(real64) function, dimension(:), allocatable linspace(start, end, num)
Adaptation of numpy's linspace function.
Contains NetCDF output functions for different problem main & equilibration runs.