10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-07-25 20:27:28 +02:00

Cleaning in ERI

This commit is contained in:
Anthony Scemama 2018-03-27 16:32:04 +02:00
parent ab7abda328
commit f186b6ef1b

View File

@ -2,20 +2,9 @@
open Util open Util
open Constants open Constants
open Bigarray
let max_ao = 1 lsl 14
type index_pair = { first : int ; second : int }
type t = FourIdxStorage.t type t = FourIdxStorage.t
let get_chem = FourIdxStorage.get_chem
let get_phys = FourIdxStorage.get_phys
let set_chem = FourIdxStorage.set_chem
let set_phys = FourIdxStorage.set_phys
module Am = AngularMomentum module Am = AngularMomentum
module As = AtomicShell module As = AtomicShell
@ -23,6 +12,17 @@ module Asp = AtomicShellPair
module Bs = Basis module Bs = Basis
module Cs = ContractedShell module Cs = ContractedShell
module Csp = ContractedShellPair module Csp = ContractedShellPair
module Fis = FourIdxStorage
let get_chem = Fis.get_chem
let get_phys = Fis.get_phys
let set_chem = Fis.set_chem
let set_phys = Fis.set_phys
let to_file = Fis.to_file
(** (00|00)^m : Fundamental electron repulsion integral (** (00|00)^m : Fundamental electron repulsion integral
@ -67,49 +67,45 @@ let class_of_contracted_shell_pairs shell_p shell_q =
let filter_contracted_shell_pairs ?(cutoff=integrals_cutoff) shell_pairs = let filter_contracted_shell_pairs ?(cutoff=integrals_cutoff) shell_pairs =
let t0 = Unix.gettimeofday () in List.map (fun pair ->
let cls =
class_of_contracted_shell_pairs pair pair
in
(pair, Zmap.fold (fun key value accu -> max (abs_float value) accu) cls 0. )
) shell_pairs
|> List.filter (fun (_, schwartz_p_max) -> schwartz_p_max >= cutoff)
|> List.map fst
let schwartz =
List.map (fun pair ->
let cls =
class_of_contracted_shell_pairs pair pair
in
(pair, Zmap.fold (fun key value accu -> max (abs_float value) accu) cls 0. )
) shell_pairs
|> List.filter (fun (_, schwartz_p_max) -> schwartz_p_max >= cutoff)
|> List.map fst
in
Printf.printf "%d shell pairs computed in %f seconds\n"
(List.length schwartz) (Unix.gettimeofday () -. t0);
schwartz
let store_class ?(cutoff=integrals_cutoff) data cls shell_p shell_q = let store_class ?(cutoff=integrals_cutoff) data cls shell_p shell_q =
let to_powers x = let to_powers x =
let open Zkey in let open Zkey in
match to_powers x with match to_powers x with
| Three x -> x | Three x -> x
| _ -> assert false | _ -> assert false
in in
Array.iteri (fun i_c powers_i ->
let i_c = Cs.index (Csp.shell_a shell_p) + i_c + 1 in Array.iteri (fun i_c powers_i ->
let xi = to_powers powers_i in let i_c = Cs.index (Csp.shell_a shell_p) + i_c + 1 in
Array.iteri (fun j_c powers_j -> let xi = to_powers powers_i in
let j_c = Cs.index (Csp.shell_b shell_p) + j_c + 1 in Array.iteri (fun j_c powers_j ->
let xj = to_powers powers_j in let j_c = Cs.index (Csp.shell_b shell_p) + j_c + 1 in
Array.iteri (fun k_c powers_k -> let xj = to_powers powers_j in
let k_c = Cs.index (Csp.shell_a shell_q) + k_c + 1 in Array.iteri (fun k_c powers_k ->
let xk = to_powers powers_k in let k_c = Cs.index (Csp.shell_a shell_q) + k_c + 1 in
Array.iteri (fun l_c powers_l -> let xk = to_powers powers_k in
let l_c = Cs.index (Csp.shell_b shell_q) + l_c + 1 in Array.iteri (fun l_c powers_l ->
let xl = to_powers powers_l in let l_c = Cs.index (Csp.shell_b shell_q) + l_c + 1 in
let key = Zkey.of_powers_twelve xi xj xk xl in let xl = to_powers powers_l in
let value = Zmap.find cls key in let key = Zkey.of_powers_twelve xi xj xk xl in
set_chem data i_c j_c k_c l_c value; let value = Zmap.find cls key in
) (Cs.zkey_array (Csp.shell_b shell_q)) set_chem data i_c j_c k_c l_c value;
) (Cs.zkey_array (Csp.shell_a shell_q)) ) (Cs.zkey_array (Csp.shell_b shell_q))
) (Cs.zkey_array (Csp.shell_b shell_p)) ) (Cs.zkey_array (Csp.shell_a shell_q))
) (Cs.zkey_array (Csp.shell_a shell_p)) ) (Cs.zkey_array (Csp.shell_b shell_p))
) (Cs.zkey_array (Csp.shell_a shell_p))
@ -120,36 +116,29 @@ let of_basis basis =
let n = Bs.size basis let n = Bs.size basis
and shell = Bs.contracted_shells basis and shell = Bs.contracted_shells basis
(*TODO
and atomic_shells = Bs.atomic_shells basis
*)
in in
(* Pre-compute all shell pairs *)
let shell_pairs =
Csp.of_contracted_shell_array shell
in
(* Pre-compute diagonal integrals for Schwartz *)
let schwartz =
filter_contracted_shell_pairs shell_pairs
in
(* 4D data initialization *)
let eri_array = let eri_array =
FourIdxStorage.create ~size:n `Dense Fis.create ~size:n `Dense
(* (*
FourIdxStorage.create ~size:n `Sparse Fis.create ~size:n `Sparse
*) *)
in in
(* Compute ERIs *)
let t0 = Unix.gettimeofday () in let t0 = Unix.gettimeofday () in
let inn = ref 0 and out = ref 0 in
let shell_pairs =
Csp.of_contracted_shell_array shell
|> filter_contracted_shell_pairs ~cutoff:integrals_cutoff
in
Printf.printf "%d significant shell pairs computed in %f seconds\n"
(List.length shell_pairs) (Unix.gettimeofday () -. t0);
let t0 = Unix.gettimeofday () in
let ishell = ref 0 in let ishell = ref 0 in
List.iter (fun shell_p -> List.iter (fun shell_p ->
let () = let () =
if (Cs.index (Csp.shell_a shell_p) > !ishell) then if (Cs.index (Csp.shell_a shell_p) > !ishell) then
@ -171,29 +160,20 @@ let of_basis basis =
Csp.shell_pairs shell_q Csp.shell_pairs shell_q
in in
let swap =
Array.length sp > Array.length sq
in
(* Compute all the integrals of the class *)
let f p q = let f p q =
let cls = class_of_contracted_shell_pairs p q in let cls = class_of_contracted_shell_pairs p q in
store_class ~cutoff:integrals_cutoff eri_array cls p q store_class ~cutoff:integrals_cutoff eri_array cls p q
in in
if swap then
if Array.length sp > Array.length sq then
f shell_q shell_p f shell_q shell_p
else else
f shell_p shell_q f shell_p shell_q
) schwartz ) shell_pairs
with Exit -> () with Exit -> ()
) schwartz; ) shell_pairs ;
Printf.printf "In: %d Out:%d\n" !inn !out ;
Printf.printf "Computed ERIs in %f seconds\n%!" (Unix.gettimeofday () -. t0); Printf.printf "Computed ERIs in %f seconds\n%!" (Unix.gettimeofday () -. t0);
eri_array eri_array
(** Write all integrals to a file with the <ij|kl> convention *)
let to_file = FourIdxStorage.to_file