10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-07-17 08:30:22 +02:00
QCaml/gaussian_integrals/lib/two_electron_integrals.ml

168 lines
4.2 KiB
OCaml
Raw Normal View History

2020-09-26 16:45:52 +02:00
(** Two electron integrals
*)
2023-06-16 18:27:23 +02:00
2020-10-09 09:47:57 +02:00
open Common
open Linear_algebra
2020-10-10 10:59:09 +02:00
open Gaussian
2020-10-09 09:47:57 +02:00
open Operators
2020-09-26 16:45:52 +02:00
open Constants
let cutoff = integrals_cutoff
2023-06-16 18:27:23 +02:00
module Bs = Basis
module Cs = Contracted_shell
module Csp = Contracted_shell_pair
2020-09-26 16:45:52 +02:00
module Cspc = Contracted_shell_pair_couple
2023-06-16 18:27:23 +02:00
module Fis = Four_idx_storage
2020-09-26 16:45:52 +02:00
module type Two_ei_structure =
sig
val name : string
val class_of_contracted_shell_pair_couple :
2020-09-28 00:24:36 +02:00
?operator:Operator.t -> Cspc.t -> float Zmap.t
2020-09-26 16:45:52 +02:00
end
2023-06-16 18:27:23 +02:00
2020-09-26 16:45:52 +02:00
module Make(T : Two_ei_structure) = struct
include Four_idx_storage
2020-10-02 23:35:56 +02:00
type t = Basis.t Four_idx_storage.t
2020-09-26 16:45:52 +02:00
2023-06-16 18:27:23 +02:00
let class_of_contracted_shell_pair_couple = T.class_of_contracted_shell_pair_couple
2020-09-26 16:45:52 +02:00
2023-06-16 18:27:23 +02:00
let store_class ?(cutoff=integrals_cutoff) data contracted_shell_pair_couple cls =
let to_powers x =
2020-09-26 16:45:52 +02:00
let open Zkey in
match to_powers x with
| Three x -> x
| _ -> assert false
in
let shell_p = Cspc.shell_pair_p contracted_shell_pair_couple
and shell_q = Cspc.shell_pair_q contracted_shell_pair_couple
in
2023-06-17 02:07:35 +02:00
let expand i_c powers_i shell = (
Cs.index shell + i_c + 1,
to_powers powers_i)
in
let l1 =
Array.mapi (fun i x -> expand i x (Csp.shell_a shell_p))
(Cs.zkey_array (Csp.shell_a shell_p))
in
let l2 =
Array.mapi (fun i x -> expand i x (Csp.shell_b shell_p))
(Cs.zkey_array (Csp.shell_b shell_p))
in
let l3 =
Array.mapi (fun i x -> expand i x (Csp.shell_a shell_q))
(Cs.zkey_array (Csp.shell_a shell_q))
in
let l4 =
Array.mapi (fun i x -> expand i x (Csp.shell_b shell_q))
(Cs.zkey_array (Csp.shell_b shell_q))
in
Array.iter (fun (l_c,xl) ->
Array.iter (fun (k_c,xk) ->
Array.iter (fun (j_c,xj) ->
Array.iter (fun (i_c,xi) ->
let key = Zkey.of_powers_twelve xi xj xk xl in
2020-09-26 16:45:52 +02:00
let value = Zmap.find cls key in
if abs_float value > cutoff then
set_chem data i_c j_c k_c l_c value
2023-06-17 02:07:35 +02:00
) l1
) l2
) l3
) l4
2020-09-26 16:45:52 +02:00
2023-06-16 18:27:23 +02:00
let of_basis ?operator basis =
2020-09-26 16:45:52 +02:00
let n = Bs.size basis
and shell = Bs.contracted_shells basis
in
2023-06-16 18:27:23 +02:00
let eri_array =
2020-09-26 16:45:52 +02:00
Fis.create ~size:n `Dense
(*
Fis.create ~size:n `Sparse
*)
in
let t0 = Unix.gettimeofday () in
let shell_pairs =
Csp.of_contracted_shell_array shell
2023-06-17 01:06:39 +02:00
|> Array.of_list
2020-09-26 16:45:52 +02:00
in
Printf.printf "%d significant shell pairs computed in %f seconds\n"
2023-06-17 01:06:39 +02:00
(Array.length shell_pairs) (Unix.gettimeofday () -. t0);
2020-09-26 16:45:52 +02:00
let t0 = Unix.gettimeofday () in
let f shell_p =
let sp =
Csp.shell_pairs shell_p
in
try
2023-06-17 01:06:39 +02:00
Array.iter (fun shell_q ->
2023-06-16 18:27:23 +02:00
let () =
2020-09-26 16:45:52 +02:00
if Cs.index (Csp.shell_a shell_q) >
Cs.index (Csp.shell_a shell_p) then
raise Exit
in
let sq = Csp.shell_pairs shell_q in
2023-06-16 18:27:23 +02:00
let cspc =
2020-09-26 16:45:52 +02:00
if Array.length sp < Array.length sq then
Cspc.make ~cutoff shell_p shell_q
else
Cspc.make ~cutoff shell_q shell_p
in
match cspc with
| Some cspc ->
let cls =
2020-09-27 23:55:42 +02:00
class_of_contracted_shell_pair_couple ?operator cspc
2020-09-26 16:45:52 +02:00
in
store_class ~cutoff eri_array cspc cls
| None -> ()
2023-06-17 02:07:35 +02:00
) shell_pairs;
with Exit -> ()
2020-09-26 16:45:52 +02:00
in
2023-06-16 18:27:23 +02:00
let pool = Domainslib.Task.setup_pool ~num_domains:Qcaml.num_domains () in
let _ =
Domainslib.Task.run pool (fun _ ->
2023-06-17 01:06:39 +02:00
let n = Array.length shell_pairs in
let i_prev = ref 0 in
shell_pairs
2023-06-17 02:07:35 +02:00
|> Array.map (fun sp -> Domainslib.Task.async pool (fun _ -> f sp) )
2023-06-17 01:06:39 +02:00
|> Array.iteri (fun i task ->
let i = ((10 * i+1)/n) in
if !i_prev <> i then (
i_prev := i;
2023-06-17 02:07:35 +02:00
Printf.printf "%3d %%\n%!" (i*10) );
ignore (Domainslib.Task.await pool task))
2023-06-16 18:27:23 +02:00
)
in
Domainslib.Task.teardown_pool pool;
Printf.printf "Computed %s Integrals in %f seconds\n%!"
2020-09-26 16:45:52 +02:00
T.name (Unix.gettimeofday () -. t0);
eri_array
end