From fde8ef7d8c14cdc7ef82daefcd9aedb261a434a5 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 19 Jan 2018 18:11:03 +0100 Subject: [PATCH] Changed float array to tuple in Coordinate --- Basis/Contracted_shell.ml | 2 +- Basis/Shell_pair.ml | 9 ++--- Makefile | 2 +- Utils/Coordinate.ml | 74 ++++++++++++++++++--------------------- Utils/Coordinate.mli | 26 +++++++------- 5 files changed, 55 insertions(+), 58 deletions(-) diff --git a/Basis/Contracted_shell.ml b/Basis/Contracted_shell.ml index 389aad0..bfa132f 100644 --- a/Basis/Contracted_shell.ml +++ b/Basis/Contracted_shell.ml @@ -63,7 +63,7 @@ let create ~indice ~expo ~coef ~center ~totAngMom = assert (Array.length expo > 0); let tmp = { indice ; expo ; coef ; center ; totAngMom ; size=Array.length expo ; norm_coef = [||]; - powers = Angular_momentum.zkey_array (Kind_1 totAngMom) } + powers = Angular_momentum.zkey_array (Angular_momentum.Kind_1 totAngMom) } in { tmp with norm_coef = compute_norm_coef tmp } diff --git a/Basis/Shell_pair.ml b/Basis/Shell_pair.ml index af46c61..7c46bf8 100644 --- a/Basis/Shell_pair.ml +++ b/Basis/Shell_pair.ml @@ -15,10 +15,11 @@ type t = { exception Null_contribution -let create_array ?(cutoff=0.) p_a p_b = - let log_cutoff = - if (cutoff = 0.) then infinity - else -. (log cutoff) +let create_array ?cutoff p_a p_b = + let cutoff, log_cutoff = + match cutoff with + | None -> -1., max_float + | Some cutoff -> cutoff, -. (log cutoff) in let center_ab = Coordinate.( diff --git a/Makefile b/Makefile index 20bc775..21caa2a 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ INCLUDE_DIRS=Nuclei,Utils,Basis LIBS= PKGS= -OCAMLCFLAGS="-g" +OCAMLCFLAGS="-g -warn-error A" OCAMLBUILD=ocamlbuild -j 0 -cflags $(OCAMLCFLAGS) -lflags $(OCAMLCFLAGS) -Is $(INCLUDE_DIRS) MLLFILES=$(wildcard */*.mll) $(wildcard *.mll) MLYFILES=$(wildcard */*.mly) $(wildcard *.mly) diff --git a/Utils/Coordinate.ml b/Utils/Coordinate.ml index 51cd7bf..95d2c71 100644 --- a/Utils/Coordinate.ml +++ b/Utils/Coordinate.ml @@ -1,28 +1,28 @@ type t = - | Bohr of float array - | Angstrom of float array + | Bohr of (float * float * float) + | Angstrom of (float * float * float) let a0 = Constants.a0 -let zero = Bohr [| 0. ; 0. ; 0. |] +let zero = Bohr (0., 0., 0.) let of_float_triplet (x,y,z) = function -| `Bohr -> Bohr [|x;y;z|] -| `Angstrom -> Angstrom [|x;y;z|] +| `Bohr -> Bohr (x,y,z) +| `Angstrom -> Angstrom (x,y,z) let of_3_floats x y z = of_float_triplet (x,y,z) -let to_string y = - let result x = - (string_of_float x.(0))^" "^(string_of_float x.(1))^" "^(string_of_float x.(2)) +let to_string t = + let result (x,y,z) = + (string_of_float x)^" "^(string_of_float y)^" "^(string_of_float z) in - match y with + match t with | Bohr x -> (result x) ^ " Bohr" | Angstrom x -> (result x) ^ " Angstrom" -let extract_float_array = function +let extract_float_tuple = function | Bohr a | Angstrom a -> a @@ -30,16 +30,15 @@ let extract_float_array = function (** Linear algebra *) let (|.) s a = match a with - | Bohr [|x;y;z|] -> Bohr [| s*.x; s*.y; s*.z |] - | Angstrom [|x;y;z|] -> Angstrom [| s*.x; s*.y; s*.z |] - | _ -> assert false + | Bohr (x,y,z) -> Bohr ( s*.x, s*.y, s*.z ) + | Angstrom (x,y,z) -> Angstrom ( s*.x, s*.y, s*.z ) let to_Angstrom = function | Angstrom a -> Angstrom a - | Bohr a -> Angstrom (a0 |. Bohr a |> extract_float_array) + | Bohr a -> Angstrom (a0 |. Bohr a |> extract_float_tuple) let to_Bohr = function - | Angstrom a -> Bohr (1./.a0 |. Angstrom a |> extract_float_array) + | Angstrom a -> Bohr (1./.a0 |. Angstrom a |> extract_float_tuple) | Bohr a -> Bohr a let (|-), (|+) = @@ -50,42 +49,39 @@ let (|-), (|+) = | (Angstrom a, Bohr b) -> op f (to_Bohr p) q | (Bohr a, Angstrom b) -> op f p (to_Bohr q) in - (op (fun a b -> - match a,b with - | [|x;y;z|], [|x';y';z'|] -> [| x-.x'; y-.y'; z-.z' |] - | _ -> assert false - ) , - op (fun a b -> - match a,b with - | [|x;y;z|], [|x';y';z'|] -> [| x+.x'; y+.y'; z+.z' |] - | _ -> assert false - ) + (op (fun (x,y,z) (x',y',z') -> ( x-.x', y-.y', z-.z' )) , + op (fun (x,y,z) (x',y',z') -> ( x+.x', y+.y', z+.z' )) ) -let dot p q = - let f = function - | Bohr [|x;y;z|], Bohr [|x';y';z'|] -> x*.x' +. y*.y' +. z*.z' - | _ -> assert false - in - f (to_Bohr p, to_Bohr q) +let rec dot p q = + match (p,q) with + | Bohr (x,y,z), Bohr (x',y',z') -> x*.x' +. y*.y' +. z*.z' + | _ -> dot (to_Bohr p) (to_Bohr q) let norm u = sqrt @@ dot u u -let rec to_float_array a = - to_Bohr a |> extract_float_array +let rec to_tuple a = + to_Bohr a |> extract_float_tuple -let x a = (extract_float_array @@ to_Bohr a).(0) -let y a = (extract_float_array @@ to_Bohr a).(1) -let z a = (extract_float_array @@ to_Bohr a).(2) +let x a = + let (result, _, _) = extract_float_tuple @@ to_Bohr a in + result +let y a = + let (_, result, _) = extract_float_tuple @@ to_Bohr a in + result + +let z a = + let (_, _, result) = extract_float_tuple @@ to_Bohr a in + result let coord a = function - | 0 -> (extract_float_array @@ to_Bohr a).(0) - | 1 -> (extract_float_array @@ to_Bohr a).(1) - | 2 -> (extract_float_array @@ to_Bohr a).(2) + | 0 -> x a + | 1 -> y a + | 2 -> z a | _ -> raise (Invalid_argument "Coordinate") diff --git a/Utils/Coordinate.mli b/Utils/Coordinate.mli index 6fbae0f..0e1599c 100644 --- a/Utils/Coordinate.mli +++ b/Utils/Coordinate.mli @@ -1,18 +1,18 @@ type t -val zero : t -val of_float_triplet : float * float * float -> [< `Angstrom | `Bohr ] -> t -val of_3_floats : float -> float -> float -> [< `Angstrom | `Bohr ] -> t -val to_string : t -> string -val x : t -> float -val y : t -> float -val z : t -> float -val coord : t -> int -> float -val to_float_array : t -> float array -val (|-) : t -> t -> t -val (|+) : t -> t -> t -val (|.) : float -> t -> t -val dot : t -> t -> float val to_Angstrom : t -> t val to_Bohr : t -> t +val zero : t +val of_float_triplet : (float * float * float) -> [< `Angstrom | `Bohr ] -> t +val of_3_floats : float -> float -> float -> [< `Angstrom | `Bohr ] -> t +val ( |. ) : float -> t -> t +val ( |- ) : t -> t -> t +val ( |+ ) : t -> t -> t +val dot : t -> t -> float val norm : t -> float +val to_string : t -> string +val to_tuple : t -> (float * float * float) +val x : t -> float +val y : t -> float +val z : t -> float +val coord : t -> int -> float