10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-12-22 04:13:33 +01:00
This commit is contained in:
Anthony Scemama 2018-01-23 19:26:28 +01:00
parent a20b22dab7
commit e0c0ec1353
3 changed files with 117 additions and 58 deletions

View File

@ -25,8 +25,13 @@ let zero_m ~maxm ~expo_pq_inv ~norm_pq_sq =
let contracted_class shell_a shell_b shell_c shell_d : float Zmap.t = let contracted_class shell_a shell_b shell_c shell_d : float Zmap.t =
TwoElectronRR.contracted_class ~zero_m shell_a shell_b shell_c shell_d TwoElectronRR.contracted_class ~zero_m shell_a shell_b shell_c shell_d
(** Compute all the integrals of a contracted class *)
let contracted_class_shell_pairs ?schwartz_p ?schwartz_q shell_p shell_q : float Zmap.t =
TwoElectronRR.contracted_class_shell_pairs ~zero_m ?schwartz_p ?schwartz_q shell_p shell_q
type n_cls = { n : int ; cls : Z.t array } type n_cls = { n : int ; cls : Z.t array }
exception NullIntegral
(** Write all integrals to a file with the <ij|kl> convention *) (** Write all integrals to a file with the <ij|kl> convention *)
let to_file ~filename basis = let to_file ~filename basis =
@ -38,44 +43,76 @@ let to_file ~filename basis =
in in
let oc = open_out filename in let oc = open_out filename in
(* Pre-compute all shell pairs *)
let shell_pairs =
Array.mapi (fun i shell_a -> Array.map (fun shell_b ->
Shell_pair.create_array shell_a shell_b) (Array.sub basis 0 (i+1)) ) basis
in
(* Pre-compute diagonal integrals for Schwartz *)
let schwartz =
Array.map (fun pair_array -> Array.map (fun pair ->
let cls =
contracted_class_shell_pairs pair pair
in
(cls, Zmap.fold (fun key value accu -> max (abs_float value) accu) cls 0. )
) pair_array ) shell_pairs
in
for i=0 to (Array.length basis) - 1 do for i=0 to (Array.length basis) - 1 do
print_int basis.(i).Contracted_shell.indice ; print_newline (); print_int basis.(i).Contracted_shell.indice ; print_newline ();
for j=0 to i do for j=0 to i do
for k=0 to i do let schwartz_p, schwartz_p_max = schwartz.(i).(j) in
for l=0 to k do try
(* Compute all the integrals of the class *) if (schwartz_p_max < cutoff) then raise NullIntegral;
let cls = let
contracted_class basis.(i) basis.(j) basis.(k) basis.(l) shell_p = shell_pairs.(i).(j)
in in
for k=0 to i do
for l=0 to k do
let schwartz_q, schwartz_q_max = schwartz.(k).(l) in
try
if schwartz_p_max *. schwartz_q_max < cutoff *. cutoff then
raise NullIntegral;
let
shell_q = shell_pairs.(k).(l)
in
(* Compute all the integrals of the class *)
let cls =
contracted_class_shell_pairs ~schwartz_p ~schwartz_q shell_p shell_q
in
(* Write the data in the output file *) (* Write the data in the output file *)
Array.iteri (fun i_c powers_i -> Array.iteri (fun i_c powers_i ->
let i_c = basis.(i).Contracted_shell.indice + i_c + 1 in let i_c = basis.(i).Contracted_shell.indice + i_c + 1 in
let xi = to_int_tuple powers_i in let xi = to_int_tuple powers_i in
Array.iteri (fun j_c powers_j -> Array.iteri (fun j_c powers_j ->
let j_c = basis.(j).Contracted_shell.indice + j_c + 1 in let j_c = basis.(j).Contracted_shell.indice + j_c + 1 in
let xj = to_int_tuple powers_j in let xj = to_int_tuple powers_j in
Array.iteri (fun k_c powers_k -> Array.iteri (fun k_c powers_k ->
let k_c = basis.(k).Contracted_shell.indice + k_c + 1 in let k_c = basis.(k).Contracted_shell.indice + k_c + 1 in
let xk = to_int_tuple powers_k in let xk = to_int_tuple powers_k in
Array.iteri (fun l_c powers_l -> Array.iteri (fun l_c powers_l ->
let l_c = basis.(l).Contracted_shell.indice + l_c + 1 in let l_c = basis.(l).Contracted_shell.indice + l_c + 1 in
let xl = to_int_tuple powers_l in let xl = to_int_tuple powers_l in
let key = let key =
Zkey.of_int_tuple (Zkey.Twelve (xi,xj,xk,xl)) Zkey.of_int_tuple (Zkey.Twelve (xi,xj,xk,xl))
in in
let value = let value =
Zmap.find cls key Zmap.find cls key
in in
if (abs_float value > cutoff) then if (abs_float value > cutoff) then
Printf.fprintf oc "%4d %4d %4d %4d %20.12e\n" Printf.fprintf oc "%4d %4d %4d %4d %20.12e\n"
i_c k_c j_c l_c value i_c k_c j_c l_c value
) basis.(l).Contracted_shell.powers ) basis.(l).Contracted_shell.powers
) basis.(k).Contracted_shell.powers ) basis.(k).Contracted_shell.powers
) basis.(j).Contracted_shell.powers ) basis.(j).Contracted_shell.powers
) basis.(i).Contracted_shell.powers; ) basis.(i).Contracted_shell.powers;
with NullIntegral -> print_endline "Schwartz"; ()
done;
done; done;
done; with NullIntegral -> print_endline "Big Schwartz"; ()
done; done;
done; done;
close_out oc close_out oc

View File

@ -12,6 +12,8 @@ type t = {
norm_fun : int array -> int array -> float; norm_fun : int array -> int array -> float;
i : int; i : int;
j : int; j : int;
shell_a : Contracted_shell.t;
shell_b : Contracted_shell.t;
} }
exception Null_contribution exception Null_contribution
@ -80,7 +82,7 @@ let create_array ?cutoff p_a p_b =
let center_a = let center_a =
Coordinate.(center |- Contracted_shell.center p_a) Coordinate.(center |- Contracted_shell.center p_a)
in in
Some { i ; j ; norm_fun ; norm ; coef ; expo ; expo_inv ; center ; center_a ; center_ab ; norm_sq } Some { i ; j ; shell_a=p_a ; shell_b=p_b ; norm_fun ; norm ; coef ; expo ; expo_inv ; center ; center_a ; center_ab ; norm_sq }
with with
| Null_contribution -> None | Null_contribution -> None
) )

View File

@ -168,13 +168,14 @@ let hvrr_two_e m (angMom_a, angMom_b, angMom_c, angMom_d)
let contracted_class_shell_pairs ~zero_m ?schwartz_p ?schwartz_q shell_p shell_q : float Zmap.t =
(** Computes all the two-electron integrals of the contracted shell quartet *) let shell_a = shell_p.(0).Shell_pair.shell_a
let contracted_class ~zero_m shell_a shell_b shell_c shell_d : float Zmap.t = and shell_b = shell_p.(0).Shell_pair.shell_b
and shell_c = shell_q.(0).Shell_pair.shell_a
let shell_p = Shell_pair.create_array shell_a shell_b and shell_d = shell_q.(0).Shell_pair.shell_b
and shell_q = Shell_pair.create_array shell_c shell_d in
and maxm = let maxm =
let open Angular_momentum in let open Angular_momentum in
(to_int @@ Contracted_shell.totAngMom shell_a) + (to_int @@ Contracted_shell.totAngMom shell_b) (to_int @@ Contracted_shell.totAngMom shell_a) + (to_int @@ Contracted_shell.totAngMom shell_b)
+ (to_int @@ Contracted_shell.totAngMom shell_c) + (to_int @@ Contracted_shell.totAngMom shell_d) + (to_int @@ Contracted_shell.totAngMom shell_c) + (to_int @@ Contracted_shell.totAngMom shell_d)
@ -248,31 +249,44 @@ let contracted_class ~zero_m shell_a shell_b shell_c shell_d : float Zmap.t =
let map = Array.init maxm (fun _ -> Zmap.create (Array.length class_indices)) in let map = Array.init maxm (fun _ -> Zmap.create (Array.length class_indices)) in
(* Compute the integral class from the primitive shell quartet *) (* Compute the integral class from the primitive shell quartet *)
Array.iteri (fun i key -> Array.iteri (fun i key ->
let a = Zkey.to_int_array Zkey.Kind_12 key in
let (angMomA,angMomB,angMomC,angMomD) = let (angMomA,angMomB,angMomC,angMomD) =
let a = Zkey.to_int_array Zkey.Kind_12 key in
( [| a.(0) ; a.(1) ; a.(2) |], ( [| a.(0) ; a.(1) ; a.(2) |],
[| a.(3) ; a.(4) ; a.(5) |], [| a.(3) ; a.(4) ; a.(5) |],
[| a.(6) ; a.(7) ; a.(8) |], [| a.(6) ; a.(7) ; a.(8) |],
[| a.(9) ; a.(10) ; a.(11) |] ) [| a.(9) ; a.(10) ; a.(11) |] )
in in
try try
(*
(* Schwartz screening *) (* Schwartz screening *)
let schwartz_p = (*
Zmap.find overlaps_p @@ Zkey.of_int_array ~kind:Zkey.Kind_6 let schwartz_p =
[| angMomA.(0) ; angMomA.(1) ; angMomA.(2) ; let key =
angMomB.(0) ; angMomB.(1) ; angMomB.(2) |] Zkey.of_int_array Zkey.Kind_12
|> abs_float [| a.(0) ; a.(1) ; a.(2) ;
a.(3) ; a.(4) ; a.(5) ;
a.(0) ; a.(1) ; a.(2) ;
a.(3) ; a.(4) ; a.(5) |]
in
match schwartz_p with
| None -> 1.
| Some schwartz_p -> Zmap.find schwartz_p key
in in
let schwartz_q = if schwartz_p < cutoff then raise NullQuartet;
Zmap.find overlaps_q @@ Zkey.of_int_array ~kind:Zkey.Kind_6 let schwartz_q =
[| angMomC.(0) ; angMomC.(1) ; angMomC.(2) ; let key =
angMomD.(0) ; angMomD.(1) ; angMomD.(2) |] Zkey.of_int_array Zkey.Kind_12
|> abs_float [| a.(6) ; a.(7) ; a.(8) ;
a.(9) ; a.(10) ; a.(11) ;
a.(6) ; a.(7) ; a.(8) ;
a.(9) ; a.(10) ; a.(11) |]
in
match schwartz_q with
| None -> 1.
| Some schwartz_q -> Zmap.find schwartz_q key
in in
if schwartz_p*.schwartz_q = 0. then if schwartz_p *. schwartz_q < cutoff2 then raise NullQuartet;
() ; (*raise NullQuartet; *) *)
*)
let norm = let norm =
shell_p.(ab).Shell_pair.norm_fun angMomA angMomB *. shell_q.(cd).Shell_pair.norm_fun angMomC angMomD shell_p.(ab).Shell_pair.norm_fun angMomA angMomB *. shell_q.(cd).Shell_pair.norm_fun angMomC angMomD
@ -288,9 +302,6 @@ let contracted_class ~zero_m shell_a shell_b shell_c shell_d : float Zmap.t =
map ) map )
in in
contracted_class.(i) <- contracted_class.(i) +. coef_prod *. integral contracted_class.(i) <- contracted_class.(i) +. coef_prod *. integral
(*
;if (schwartz_p*.schwartz_q < cutoff2) then Printf.printf "%e %e\n" (schwartz_p*.schwartz_q) integral;
*)
with NullQuartet -> () with NullQuartet -> ()
) class_indices ) class_indices
with NullQuartet -> () with NullQuartet -> ()
@ -304,3 +315,12 @@ let contracted_class ~zero_m shell_a shell_b shell_c shell_d : float Zmap.t =
(** Computes all the two-electron integrals of the contracted shell quartet *)
let contracted_class ~zero_m shell_a shell_b shell_c shell_d : float Zmap.t =
let shell_p = Shell_pair.create_array shell_a shell_b
and shell_q = Shell_pair.create_array shell_c shell_d
in
contracted_class_shell_pairs ~zero_m shell_p shell_q