mirror of
https://gitlab.com/scemama/QCaml.git
synced 2024-11-19 04:22:21 +01:00
187 lines
5.0 KiB
OCaml
187 lines
5.0 KiB
OCaml
|
(** %{ $ \langle ij | H F | kl \rangle $ %} integrals. *)
|
||
|
|
||
|
open Lacaml.D
|
||
|
|
||
|
module Fis = FourIdxStorage
|
||
|
|
||
|
type t = (float, Bigarray.float64_elt, Bigarray.fortran_layout) Bigarray.Genarray.t
|
||
|
* (float, Bigarray.float64_elt, Bigarray.fortran_layout) Bigarray.Genarray.t
|
||
|
|
||
|
|
||
|
let make ~simulation ~mo_basis ~aux_basis_filename () =
|
||
|
|
||
|
let f12 = Util.of_some @@ Simulation.f12 simulation in
|
||
|
let mo_num = MOBasis.size mo_basis in
|
||
|
|
||
|
(* Add auxiliary basis set *)
|
||
|
let aux_basis =
|
||
|
let s =
|
||
|
let charge = Charge.to_int @@ Simulation.charge simulation
|
||
|
and multiplicity = Electrons.multiplicity @@ Simulation.electrons simulation
|
||
|
and nuclei = Simulation.nuclei simulation
|
||
|
in
|
||
|
let general_basis =
|
||
|
Basis.general_basis @@ Simulation.basis simulation
|
||
|
in
|
||
|
GeneralBasis.combine [
|
||
|
general_basis ; GeneralBasis.read aux_basis_filename
|
||
|
]
|
||
|
|> Basis.of_nuclei_and_general_basis nuclei
|
||
|
|> Simulation.make ~f12 ~charge ~multiplicity ~nuclei
|
||
|
in
|
||
|
MOBasis.of_mo_basis s mo_basis
|
||
|
in
|
||
|
|
||
|
let aux_num = MOBasis.size aux_basis in
|
||
|
|
||
|
(* Fire calculation of F12 and ERI *)
|
||
|
let f12 =
|
||
|
MOBasis.f12_ints aux_basis
|
||
|
in
|
||
|
let eri =
|
||
|
MOBasis.two_e_ints aux_basis
|
||
|
in
|
||
|
|
||
|
(* Compute the <ij|QHF|kl> integrals *)
|
||
|
if Parallel.master then Printf.eprintf "Computing HF12 integrals\n%!";
|
||
|
|
||
|
let result_s, result_o =
|
||
|
Bigarray.Genarray.create Float64 Bigarray.fortran_layout [| mo_num ; mo_num ; mo_num ; mo_num |] ,
|
||
|
Bigarray.Genarray.create Float64 Bigarray.fortran_layout [| mo_num ; mo_num ; mo_num ; mo_num |]
|
||
|
in
|
||
|
|
||
|
|
||
|
let h_s = Bigarray.Array3.create Float64 Bigarray.fortran_layout mo_num aux_num aux_num in
|
||
|
let f_s = Bigarray.Array3.create Float64 Bigarray.fortran_layout aux_num aux_num mo_num in
|
||
|
let h_o = Bigarray.Array3.create Float64 Bigarray.fortran_layout mo_num aux_num aux_num in
|
||
|
let f_o = Bigarray.Array3.create Float64 Bigarray.fortran_layout aux_num aux_num mo_num in
|
||
|
let hf_s = Mat.create mo_num mo_num in
|
||
|
let hf_o = Mat.create mo_num mo_num in
|
||
|
|
||
|
for a=1 to mo_num do
|
||
|
for b=1 to mo_num do
|
||
|
for i=1 to mo_num do
|
||
|
h_s.{i, a, b} <- 0. ;
|
||
|
h_o.{i, a, b} <- 0.
|
||
|
done
|
||
|
done
|
||
|
done;
|
||
|
|
||
|
for k=1 to mo_num do
|
||
|
for b=1 to mo_num do
|
||
|
for a=1 to mo_num do
|
||
|
f_s.{a, b, k} <- 0. ;
|
||
|
f_o.{a, b, k} <- 0.
|
||
|
done
|
||
|
done
|
||
|
done;
|
||
|
|
||
|
let task (j,l) =
|
||
|
|
||
|
let h i a b =
|
||
|
h_s.{i, a, b} <- ERI.get_phys eri i j a b -. ERI.get_phys eri i j b a ;
|
||
|
h_o.{i, a, b} <- ERI.get_phys eri i j a b
|
||
|
and f a b k =
|
||
|
f_s.{a, b, k} <- 0.25 *. (F12.get_phys f12 a b k l -. F12.get_phys f12 a b l k) ;
|
||
|
f_o.{a, b, k} <- 0.375 *. F12.get_phys f12 a b k l +. 0.125 *. F12.get_phys f12 b a k l
|
||
|
in
|
||
|
|
||
|
for a=mo_num+1 to aux_num do
|
||
|
for b=mo_num+1 to aux_num do
|
||
|
for i=1 to mo_num do
|
||
|
h i a b
|
||
|
done
|
||
|
done
|
||
|
done;
|
||
|
|
||
|
for k=1 to mo_num do
|
||
|
for b=mo_num+1 to aux_num do
|
||
|
for a=mo_num+1 to aux_num do
|
||
|
f a b k
|
||
|
done
|
||
|
done
|
||
|
done;
|
||
|
|
||
|
(*
|
||
|
for a=1 to mo_num do
|
||
|
for b=mo_num+1 to aux_num do
|
||
|
for i=1 to mo_num do
|
||
|
if i <> a then
|
||
|
h i a b
|
||
|
done
|
||
|
done
|
||
|
done;
|
||
|
|
||
|
for k=1 to mo_num do
|
||
|
for b=mo_num+1 to aux_num do
|
||
|
for a=1 to mo_num do
|
||
|
if k <> a then
|
||
|
f a b k
|
||
|
done
|
||
|
done
|
||
|
done;
|
||
|
*)
|
||
|
let h_o =
|
||
|
Bigarray.(reshape (genarray_of_array3 h_o)) [| mo_num ; aux_num*aux_num |]
|
||
|
|> Bigarray.array2_of_genarray
|
||
|
in
|
||
|
let f_o =
|
||
|
Bigarray.(reshape (genarray_of_array3 f_o)) [| aux_num*aux_num ; mo_num |]
|
||
|
|> Bigarray.array2_of_genarray
|
||
|
in
|
||
|
let h_s =
|
||
|
Bigarray.(reshape (genarray_of_array3 h_s)) [| mo_num ; aux_num*aux_num |]
|
||
|
|> Bigarray.array2_of_genarray
|
||
|
in
|
||
|
let f_s =
|
||
|
Bigarray.(reshape (genarray_of_array3 f_s)) [| aux_num*aux_num ; mo_num |]
|
||
|
|> Bigarray.array2_of_genarray
|
||
|
in
|
||
|
let hf_s = gemm ~alpha:1.0 ~c:hf_s h_s f_s in
|
||
|
let hf_o = gemm ~alpha:1.0 ~c:hf_o h_o f_o in
|
||
|
hf_s, hf_o, j, l
|
||
|
in
|
||
|
|
||
|
let tasks =
|
||
|
let rec next accu = function
|
||
|
| _, 0 -> accu
|
||
|
| 0, l -> next accu (mo_num, l-1)
|
||
|
| j, l -> next ((j,l) :: accu) ((j-1), l)
|
||
|
in
|
||
|
next [] (mo_num, mo_num)
|
||
|
|> Stream.of_list
|
||
|
in
|
||
|
|
||
|
|
||
|
Farm.run ~f:task ~ordered:true tasks
|
||
|
|> Stream.iter (fun (hf_s, hf_o, j, l) ->
|
||
|
(*
|
||
|
Printf.printf "%d %d\n" j l ;
|
||
|
*)
|
||
|
for k=1 to mo_num do
|
||
|
for i=1 to mo_num do
|
||
|
result_s.{i,k,j,l} <- hf_s.{i,k} ;
|
||
|
result_o.{i,k,j,l} <- hf_o.{i,k}
|
||
|
done
|
||
|
done );
|
||
|
|
||
|
|
||
|
|
||
|
(*
|
||
|
for l=1 to mo_num do
|
||
|
for k=1 to mo_num do
|
||
|
for j=1 to mo_num do
|
||
|
for i=1 to mo_num do
|
||
|
Printf.printf "%d %d %d %d %e\n" i j k l result.{i,j,k,l}
|
||
|
done
|
||
|
done
|
||
|
done
|
||
|
done;
|
||
|
Printf.printf "%!";
|
||
|
*)
|
||
|
|
||
|
Parallel.broadcast (lazy (result_s, result_o) )
|
||
|
|
||
|
|
||
|
|