mirror of
https://gitlab.com/scemama/QCaml.git
synced 2025-01-03 01:55:40 +01:00
Recursive Boys function + removed zerom cache
This commit is contained in:
parent
7ee34f3c9f
commit
08df6eddec
@ -325,9 +325,6 @@ let contracted_class_shell_pairs ~zero_m ?schwartz_p ?schwartz_q shell_p shell_q
|
||||
|
||||
(* Compute all integrals in the shell for each pair of significant shell pairs *)
|
||||
|
||||
let zero_m_cache =
|
||||
Hashtbl.create 129
|
||||
in
|
||||
for ab=0 to (Array.length shell_p - 1) do
|
||||
let cab = shell_p.(ab).Shell_pair.coef in
|
||||
let b = shell_p.(ab).Shell_pair.j in
|
||||
@ -352,19 +349,8 @@ let contracted_class_shell_pairs ~zero_m ?schwartz_p ?schwartz_q shell_p shell_q
|
||||
in
|
||||
|
||||
let zero_m_array =
|
||||
let key = (maxm, expo_pq_inv, norm_pq_sq) in
|
||||
try
|
||||
let result =
|
||||
Hashtbl.find zero_m_cache key
|
||||
in
|
||||
result
|
||||
with
|
||||
| Not_found ->
|
||||
let result =
|
||||
zero_m ~maxm ~expo_pq_inv ~norm_pq_sq
|
||||
in
|
||||
(Hashtbl.add zero_m_cache key result ; result)
|
||||
in
|
||||
begin
|
||||
match Contracted_shell.(totAngMom shell_a, totAngMom shell_b,
|
||||
totAngMom shell_c, totAngMom shell_d) with
|
||||
|
@ -306,9 +306,6 @@ let contracted_class_shell_pairs ~zero_m ?schwartz_p ?schwartz_q shell_p shell_q
|
||||
Array.make (Array.length class_indices) 0.;
|
||||
in
|
||||
|
||||
let zero_m_cache =
|
||||
Hashtbl.create 129
|
||||
in
|
||||
(* Compute all integrals in the shell for each pair of significant shell pairs *)
|
||||
|
||||
begin
|
||||
@ -338,19 +335,8 @@ let contracted_class_shell_pairs ~zero_m ?schwartz_p ?schwartz_q shell_p shell_q
|
||||
in
|
||||
|
||||
let zero_m_array =
|
||||
let key = (0, expo_pq_inv, norm_pq_sq) in
|
||||
try
|
||||
let result =
|
||||
Hashtbl.find zero_m_cache key
|
||||
in
|
||||
result
|
||||
with
|
||||
| Not_found ->
|
||||
let result =
|
||||
zero_m ~maxm:0 ~expo_pq_inv ~norm_pq_sq
|
||||
in
|
||||
(Hashtbl.add zero_m_cache key result ; result)
|
||||
in
|
||||
|
||||
accu +. coef_prod *. zero_m_array.(0)
|
||||
with NullQuartet -> accu
|
||||
@ -377,19 +363,8 @@ let contracted_class_shell_pairs ~zero_m ?schwartz_p ?schwartz_q shell_p shell_q
|
||||
in
|
||||
|
||||
let zero_m_array =
|
||||
let key = (maxm, expo_pq_inv, norm_pq_sq) in
|
||||
try
|
||||
let result =
|
||||
Hashtbl.find zero_m_cache key
|
||||
in
|
||||
result
|
||||
with
|
||||
| Not_found ->
|
||||
let result =
|
||||
zero_m ~maxm ~expo_pq_inv ~norm_pq_sq
|
||||
in
|
||||
(Hashtbl.add zero_m_cache key result ; result)
|
||||
in
|
||||
|
||||
let d = shell_cd.Shell_pair.j in
|
||||
|
||||
|
@ -10,15 +10,17 @@ let factmax = 150
|
||||
|
||||
|
||||
|
||||
(*reference - Haruhiko Okumura: C-gengo niyoru saishin algorithm jiten
|
||||
|
||||
(* Incomplete gamma function : Int_0^x exp(-t) t^(a-1) dt
|
||||
p: 1 / Gamma(a) * Int_0^x exp(-t) t^(a-1) dt
|
||||
q: 1 / Gamma(a) * Int_x^inf exp(-t) t^(a-1) dt
|
||||
|
||||
reference - Haruhiko Okumura: C-gengo niyoru saishin algorithm jiten
|
||||
(New Algorithm handbook in C language) (Gijyutsu hyouron
|
||||
sha, Tokyo, 1991) p.227 [in Japanese] *)
|
||||
|
||||
(* Incomplete gamma function
|
||||
p: 1 / Gamma(a) * Int_0^x exp(-t) t^(a-1) dt
|
||||
q: 1 / Gamma(a) * Int_x^inf exp(-t) t^(a-1) dt *)
|
||||
|
||||
let rec p_gamma a x loggamma_a =
|
||||
let incomplete_gamma ~alpha x =
|
||||
let rec p_gamma a x loggamma_a =
|
||||
if x >= 1. +. a then 1. -. q_gamma a x loggamma_a
|
||||
else if x = 0. then 0.
|
||||
else
|
||||
@ -50,46 +52,11 @@ let rec p_gamma a x loggamma_a =
|
||||
let w = exp (a *. log x -. x -. loggamma_a) in
|
||||
let lb = (1. +. x -. a) in
|
||||
qg_loop min_float (w /. lb) 1. lb w 2.0
|
||||
|
||||
|
||||
(** Generalized Boys function. Uses GSL's incomplete Gamma function.
|
||||
maxm : Maximum total angular momentum
|
||||
*)
|
||||
let rec boys_function ~maxm t =
|
||||
match maxm with
|
||||
| 0 ->
|
||||
begin
|
||||
if t = 0. then [| 1. |] else
|
||||
let sq_t = sqrt t in
|
||||
[| (sq_pi_over_two /. sq_t) *. erf_float sq_t |]
|
||||
end
|
||||
| _ ->
|
||||
begin
|
||||
if t = 0. then
|
||||
Array.init (maxm+1) (fun m -> 1. /. float_of_int (m+m+1))
|
||||
else
|
||||
let incomplete_gamma ~alpha x =
|
||||
in
|
||||
let gf = gamma_float alpha in
|
||||
gf *. p_gamma alpha x (log gf)
|
||||
in
|
||||
let t_inv =
|
||||
1. /. t
|
||||
in
|
||||
let factor =
|
||||
Array.make (maxm+1) (0.5, sqrt t_inv);
|
||||
in
|
||||
for i=1 to maxm
|
||||
do
|
||||
let (dm, f) = factor.(i-1) in
|
||||
factor.(i) <- (dm +. 1., f *. t_inv);
|
||||
done;
|
||||
Array.map (fun (dm, f) ->
|
||||
if dm = 0.5 then
|
||||
(boys_function ~maxm:0 t).(0)
|
||||
else
|
||||
(incomplete_gamma dm t ) *. 0.5 *. f
|
||||
) factor
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -139,3 +106,37 @@ let chop f g =
|
||||
|
||||
|
||||
|
||||
(** Generalized Boys function.
|
||||
maxm : Maximum total angular momentum
|
||||
*)
|
||||
let boys_function ~maxm t =
|
||||
match maxm with
|
||||
| 0 ->
|
||||
begin
|
||||
if t = 0. then [| 1. |] else
|
||||
let sq_t = sqrt t in
|
||||
[| (sq_pi_over_two /. sq_t) *. erf_float sq_t |]
|
||||
end
|
||||
| _ ->
|
||||
begin
|
||||
let result =
|
||||
Array.init (maxm+1) (fun m -> 1. /. float_of_int (2*m+1))
|
||||
in
|
||||
if t <> 0. then
|
||||
begin
|
||||
let fmax =
|
||||
let t_inv = sqrt (1. /. t) in
|
||||
let n = float_of_int maxm in
|
||||
let dm = 0.5 +. n in
|
||||
let f = (pow t_inv (maxm+maxm+1) ) in
|
||||
(incomplete_gamma dm t) *. 0.5 *. f
|
||||
in
|
||||
let emt = exp (-. t) in
|
||||
result.(maxm) <- fmax;
|
||||
for n=maxm-1 downto 0 do
|
||||
result.(n) <- ( (t+.t) *. result.(n+1) +. emt) *. result.(n)
|
||||
done
|
||||
end;
|
||||
result
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user