From f186b6ef1b2ebc0ccab1ba18e5557614671c79ee Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 27 Mar 2018 16:32:04 +0200 Subject: [PATCH] Cleaning in ERI --- Basis/ERI.ml | 142 ++++++++++++++++++++++----------------------------- 1 file changed, 61 insertions(+), 81 deletions(-) diff --git a/Basis/ERI.ml b/Basis/ERI.ml index 4bbb717..480402e 100644 --- a/Basis/ERI.ml +++ b/Basis/ERI.ml @@ -2,20 +2,9 @@ open Util open Constants -open Bigarray - -let max_ao = 1 lsl 14 - -type index_pair = { first : int ; second : int } 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 As = AtomicShell @@ -23,6 +12,17 @@ module Asp = AtomicShellPair module Bs = Basis module Cs = ContractedShell 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 @@ -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 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 to_powers x = + let to_powers x = let open Zkey in match to_powers x with | Three x -> x | _ -> assert false - in - Array.iteri (fun i_c powers_i -> - let i_c = Cs.index (Csp.shell_a shell_p) + i_c + 1 in - let xi = to_powers powers_i in - Array.iteri (fun j_c powers_j -> - let j_c = Cs.index (Csp.shell_b shell_p) + j_c + 1 in - let xj = to_powers powers_j in - Array.iteri (fun k_c powers_k -> - let k_c = Cs.index (Csp.shell_a shell_q) + k_c + 1 in - let xk = to_powers powers_k in - Array.iteri (fun l_c powers_l -> - let l_c = Cs.index (Csp.shell_b shell_q) + l_c + 1 in - let xl = to_powers powers_l in - let key = Zkey.of_powers_twelve xi xj xk xl in - let value = Zmap.find cls key in - set_chem data i_c j_c k_c l_c value; - ) (Cs.zkey_array (Csp.shell_b shell_q)) - ) (Cs.zkey_array (Csp.shell_a shell_q)) - ) (Cs.zkey_array (Csp.shell_b shell_p)) - ) (Cs.zkey_array (Csp.shell_a shell_p)) + in + + Array.iteri (fun i_c powers_i -> + let i_c = Cs.index (Csp.shell_a shell_p) + i_c + 1 in + let xi = to_powers powers_i in + Array.iteri (fun j_c powers_j -> + let j_c = Cs.index (Csp.shell_b shell_p) + j_c + 1 in + let xj = to_powers powers_j in + Array.iteri (fun k_c powers_k -> + let k_c = Cs.index (Csp.shell_a shell_q) + k_c + 1 in + let xk = to_powers powers_k in + Array.iteri (fun l_c powers_l -> + let l_c = Cs.index (Csp.shell_b shell_q) + l_c + 1 in + let xl = to_powers powers_l in + let key = Zkey.of_powers_twelve xi xj xk xl in + let value = Zmap.find cls key in + set_chem data i_c j_c k_c l_c value; + ) (Cs.zkey_array (Csp.shell_b shell_q)) + ) (Cs.zkey_array (Csp.shell_a shell_q)) + ) (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 and shell = Bs.contracted_shells basis - (*TODO - and atomic_shells = Bs.atomic_shells basis - *) 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 = - FourIdxStorage.create ~size:n `Dense - (* - FourIdxStorage.create ~size:n `Sparse - *) + Fis.create ~size:n `Dense +(* + Fis.create ~size:n `Sparse +*) in - (* Compute ERIs *) - 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 + List.iter (fun shell_p -> let () = if (Cs.index (Csp.shell_a shell_p) > !ishell) then @@ -171,29 +160,20 @@ let of_basis basis = Csp.shell_pairs shell_q in - let swap = - Array.length sp > Array.length sq - in - - (* Compute all the integrals of the class *) let f p q = let cls = class_of_contracted_shell_pairs p q in store_class ~cutoff:integrals_cutoff eri_array cls p q in - if swap then + + if Array.length sp > Array.length sq then f shell_q shell_p else f shell_p shell_q - ) schwartz + ) shell_pairs with Exit -> () - ) schwartz; - Printf.printf "In: %d Out:%d\n" !inn !out ; + ) shell_pairs ; Printf.printf "Computed ERIs in %f seconds\n%!" (Unix.gettimeofday () -. t0); eri_array -(** Write all integrals to a file with the convention *) -let to_file = FourIdxStorage.to_file - -