10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-12-22 12:23:31 +01:00

Hash table for zkey_array

This commit is contained in:
Anthony Scemama 2018-03-13 18:24:00 +01:00
parent e3d8582caa
commit e54a5e034a
14 changed files with 82 additions and 69 deletions

View File

@ -28,13 +28,13 @@ let of_nuclei_and_general_basis n b =
if (i > 0) then if (i > 0) then
result.(i) <- Cs.with_index x ( result.(i) <- Cs.with_index x (
result.(i-1).index + result.(i-1).index +
(Array.length result.(i-1).powers )) (Array.length result.(i-1).norm_coef_scale ))
) result ; ) result ;
let size = let size =
let n = ref 0 in let n = ref 0 in
for i=0 to (Array.length result) - 1 do for i=0 to (Array.length result) - 1 do
n := !n + (Array.length (result.(i).powers )) n := !n + (Array.length (result.(i).norm_coef_scale))
done; !n done; !n
in in
{ contracted_shells = result ; size } { contracted_shells = result ; size }

View File

@ -10,19 +10,12 @@ type t = {
size : int; size : int;
norm_coef : float array; norm_coef : float array;
norm_coef_scale : float array; norm_coef_scale : float array;
powers : Zkey.t array;
index : int; index : int;
} }
module Am = AngularMomentum module Am = AngularMomentum
(** Normalization coefficient of contracted function i, which depends on the
exponent and the angular momentum. Two conventions can be chosen : a single
normalisation factor for all functions of the class, or a coefficient which
depends on the powers of x,y and z.
Returns, for each contracted function, an array of functions taking as
argument the [|x;y;z|] powers.
*)
let compute_norm_coef expo totAngMom = let compute_norm_coef expo totAngMom =
let atot = let atot =
Am.to_int totAngMom Am.to_int totAngMom
@ -67,7 +60,7 @@ let make ~index ~expo ~coef ~center ~totAngMom =
) powers ) powers
in in
{ index ; expo ; coef ; center ; totAngMom ; size=Array.length expo ; norm_coef ; { index ; expo ; coef ; center ; totAngMom ; size=Array.length expo ; norm_coef ;
norm_coef_scale ; powers } norm_coef_scale }
let with_index a i = let with_index a i =
@ -79,7 +72,7 @@ let to_string s =
let open Printf in let open Printf in
(match s.totAngMom with (match s.totAngMom with
| Am.S -> sprintf "%3d " (s.index+1) | Am.S -> sprintf "%3d " (s.index+1)
| _ -> sprintf "%3d-%-3d" (s.index+1) (s.index+(Array.length s.powers)) | _ -> sprintf "%3d-%-3d" (s.index+1) (s.index+(Array.length s.norm_coef_scale))
) ^ ) ^
( sprintf "%1s %8.3f %8.3f %8.3f " (Am.to_string s.totAngMom) ( sprintf "%1s %8.3f %8.3f %8.3f " (Am.to_string s.totAngMom)
(get X coord) (get Y coord) (get Z coord) ) ^ (get X coord) (get Y coord) (get Z coord) ) ^

View File

@ -35,8 +35,7 @@ type t = private {
totAngMom : AngularMomentum.t; (** Total angular momentum : {% $l = n_x + n_y + n_z$ %} *) totAngMom : AngularMomentum.t; (** Total angular momentum : {% $l = n_x + n_y + n_z$ %} *)
size : int; (** Number of contracted functions, {% $m$ %} in the formula *) size : int; (** Number of contracted functions, {% $m$ %} in the formula *)
norm_coef : float array; (** Normalization coefficients of primitive functions {% $\mathcal{N}_i$ %} *) norm_coef : float array; (** Normalization coefficients of primitive functions {% $\mathcal{N}_i$ %} *)
norm_coef_scale : float array; (** Scaling factors {% $f_i$ %}, given in the same order as [powers]. *) norm_coef_scale : float array; (** Scaling factors {% $f_i$ %}, given in the same order as [AngularMomentum.zkey_array totAngMom]. *)
powers : Zkey.t array; (** Triplets {% $(n_x,n_y,n_z)$ %} encoded in a {!Zkey.t}. *)
index : int; (** Index in the basis set, represented as an array of contracted shells. *) index : int; (** Index in the basis set, represented as an array of contracted shells. *)
} }

View File

@ -6,6 +6,7 @@ open Bigarray
type t = (float, float32_elt, fortran_layout) Bigarray.Genarray.t type t = (float, float32_elt, fortran_layout) Bigarray.Genarray.t
module Am = AngularMomentum
module Bs = Basis module Bs = Basis
module Cs = ContractedShell module Cs = ContractedShell
module Csp = ContractedShellPair module Csp = ContractedShellPair
@ -212,10 +213,10 @@ let of_basis basis =
) )
else else
out := !out + 1; out := !out + 1;
) shell.(l).powers ) Am.(zkey_array (Singlet shell.(l).Cs.totAngMom))
) shell.(k).powers ) Am.(zkey_array (Singlet shell.(k).Cs.totAngMom))
) shell.(j).powers ) Am.(zkey_array (Singlet shell.(j).Cs.totAngMom))
) shell.(i).powers ) Am.(zkey_array (Singlet shell.(i).Cs.totAngMom))
with NullIntegral -> () with NullIntegral -> ()
done; done;
done; done;

View File

@ -1,3 +1,4 @@
(** Reads a basis set in GAMESS format *)
let read_basis filename = let read_basis filename =
let lexbuf = let lexbuf =
let ic = open_in filename in let ic = open_in filename in

View File

@ -155,8 +155,8 @@ let of_basis basis =
in in
result.{i_c,j_c} <- value; result.{i_c,j_c} <- value;
result.{j_c,i_c} <- value; result.{j_c,i_c} <- value;
) shell.(i).powers ) Am.(zkey_array (Singlet shell.(i).Cs.totAngMom))
) shell.(j).powers ) Am.(zkey_array (Singlet shell.(j).Cs.totAngMom))
done; done;
done; done;
Mat.detri result; Mat.detri result;

View File

@ -6,7 +6,9 @@ open Lacaml.D
type t = Mat.t type t = Mat.t
module Am = AngularMomentum
module Bs = Basis module Bs = Basis
module Cs = ContractedShell
(** (0|0)^m : Fundamental electron-nucleus repulsion integral (** (0|0)^m : Fundamental electron-nucleus repulsion integral
$ \int \phi_p(r1) 1/r_{C} dr_1 $ $ \int \phi_p(r1) 1/r_{C} dr_1 $
@ -86,8 +88,8 @@ let of_basis_nuclei basis nuclei =
in in
eni_array.{j_c,i_c} <- value; eni_array.{j_c,i_c} <- value;
eni_array.{i_c,j_c} <- value; eni_array.{i_c,j_c} <- value;
) shell.(j).powers ) Am.(zkey_array (Singlet shell.(j).Cs.totAngMom))
) shell.(i).powers ) Am.(zkey_array (Singlet shell.(i).Cs.totAngMom))
done; done;
done; done;
Mat.detri eni_array; Mat.detri eni_array;

View File

@ -127,8 +127,8 @@ let of_basis basis =
in in
result.{i_c,j_c} <- value; result.{i_c,j_c} <- value;
result.{j_c,i_c} <- value; result.{j_c,i_c} <- value;
) shell.(i).powers ) Am.(zkey_array (Singlet shell.(i).Cs.totAngMom))
) shell.(j).powers ) Am.(zkey_array (Singlet shell.(j).Cs.totAngMom))
done; done;
done; done;
Mat.detri result; Mat.detri result;

View File

@ -8,22 +8,23 @@ let hvrr (angMom_a, angMom_b) (expo_inv_p) (center_ab, center_pa)
(** Vertical recurrence relations *) (** Vertical recurrence relations *)
let rec vrr angMom_a = let rec vrr angMom_a =
if angMom_a < 0 then 0. if angMom_a > 0 then
else if angMom_a = 0 then 1. chop center_pa (fun () -> vrr (angMom_a-1))
else +. chop (0.5 *. float_of_int (angMom_a-1) *. expo_inv_p)
(chop center_pa (fun () -> vrr (angMom_a-1)))
+. chop (0.5 *. (float_of_int (angMom_a-1)) *. expo_inv_p)
(fun () -> vrr (angMom_a-2)) (fun () -> vrr (angMom_a-2))
else if angMom_a = 0 then 1.
else 0.
(** Horizontal recurrence relations *) (** Horizontal recurrence relations *)
and hrr angMom_a angMom_b = and hrr angMom_a angMom_b =
if angMom_b < 0 then 0. if angMom_b > 0 then
else if angMom_b = 0 then vrr angMom_a
else
hrr (angMom_a+1) (angMom_b-1) +. chop center_ab hrr (angMom_a+1) (angMom_b-1) +. chop center_ab
(fun () -> hrr angMom_a (angMom_b-1) ) (fun () -> hrr angMom_a (angMom_b-1) )
else if angMom_b = 0 then
vrr angMom_a
else 0.
in in
hrr angMom_a angMom_b hrr angMom_a angMom_b

View File

@ -1,5 +1,6 @@
open Lacaml.D open Lacaml.D
open Simulation open Simulation
open Constants
type t = Mat.t type t = Mat.t
@ -17,6 +18,7 @@ let make ~density simulation =
for nu = 1 to nBas do for nu = 1 to nBas do
for lambda = 1 to nBas do for lambda = 1 to nBas do
let p = m_P.{lambda,sigma} in let p = m_P.{lambda,sigma} in
if abs_float p > epsilon then
for mu = 1 to nu do for mu = 1 to nu do
m_F.{mu,nu} <- m_F.{mu,nu} +. p *. m_F.{mu,nu} <- m_F.{mu,nu} +. p *.
(m_G.{mu,lambda,nu,sigma} -. 0.5 *. m_G.{mu,lambda,sigma,nu}) (m_G.{mu,lambda,nu,sigma} -. 0.5 *. m_G.{mu,lambda,sigma,nu})

View File

@ -68,8 +68,12 @@ let n_functions a =
(a*a + 3*a + 2)/2 (a*a + 3*a + 2)/2
let zkey_array_memo : (kind, Zkey.t array) Hashtbl.t =
Hashtbl.create 13
(** Returns an array of Zkeys corresponding to all possible angular momenta *) (** Returns an array of Zkeys corresponding to all possible angular momenta *)
let zkey_array a = let zkey_array a =
let keys_1d l = let keys_1d l =
let create_z { x ; y ; _ } = let create_z { x ; y ; _ } =
Powers.of_int_tuple (x,y,l-(x+y)) Powers.of_int_tuple (x,y,l-(x+y))
@ -93,6 +97,12 @@ let zkey_array a =
|> List.rev |> List.rev
in in
try
Hashtbl.find zkey_array_memo a
with Not_found ->
let result =
begin begin
match a with match a with
| Singlet l1 -> | Singlet l1 ->
@ -130,4 +140,7 @@ let zkey_array a =
|> List.concat |> List.concat
end end
|> Array.of_list |> Array.of_list
in
Hashtbl.add zkey_array_memo a result;
result

View File

@ -67,3 +67,4 @@ val equal : t -> t -> bool
val compare : t -> t -> int val compare : t -> t -> int
(** Comparison function, used for sorting. *) (** Comparison function, used for sorting. *)