Added frozen_core

This commit is contained in:
Anthony Scemama 2021-01-01 12:52:50 +01:00
parent 92c23f042f
commit 28e6fda242
5 changed files with 251 additions and 7 deletions

118
mo/frozen_core.org Normal file
View File

@ -0,0 +1,118 @@
#+begin_src elisp tangle: no :results none :exports none
(setq pwd (file-name-directory buffer-file-name))
(setq name (file-name-nondirectory (substring buffer-file-name 0 -4)))
(setq lib (concat pwd "lib/"))
(setq testdir (concat pwd "test/"))
(setq mli (concat lib name ".mli"))
(setq ml (concat lib name ".ml"))
(setq test-ml (concat testdir name ".ml"))
(org-babel-tangle)
#+end_src
* Frozen core
:PROPERTIES:
:header-args: :noweb yes :comments both
:END:
Defines how the core electrons are frozen, for each atom.
** Type
#+NAME: types
#+begin_src ocaml :tangle (eval mli)
type kind =
| All_electron
| Small
| Large
#+end_src
#+begin_src ocaml :tangle (eval mli)
type t
#+end_src
#+begin_src ocaml :tangle (eval ml) :exports none
<<types>>
type t = int array
#+end_src
** Creation
#+begin_src ocaml :tangle (eval mli)
val make : kind -> Particles.Nuclei.t -> t
val of_int_list : int list -> t
val of_int_array : int array -> t
#+end_src
| ~make~ | Creates a ~Frozen_core.t~ with the same kind for all atoms |
| ~of_int_array~ | Creates a ~Frozen_core.t~ giving the number of frozen electrons per atom |
| ~of_int_list~ | Creates a ~Frozen_core.t~ giving the number of frozen electrons per atom |
#+begin_example
let f = Frozen_core.(make Small nuclei) ;;
val f : Frozen_core.t = [|0; 2; 2; 0|]
let f = Frozen_core.(of_int_list [0; 2; 2; 0])
val f : Frozen_core.t = [|0; 2; 2; 0|]
#+end_example
#+begin_src ocaml :tangle (eval ml) :exports none
let make_ae nuclei =
Array.map (fun _ -> 0) nuclei
let make_small nuclei =
Array.map (fun (e,_) -> Particles.Element.small_core e) nuclei
let make_large nuclei =
Array.map (fun (e,_) -> Particles.Element.large_core e) nuclei
let make = function
| All_electron -> make_ae
| Small -> make_small
| Large -> make_large
external of_int_array : int array -> t = "%identity"
let of_int_list = Array.of_list
#+end_src
** Access
#+begin_src ocaml :tangle (eval mli)
val num_elec : t -> int
val num_mos : t -> int
#+end_src
| ~num_elec~ | Number of frozen electrons |
| ~num_mos~ | Number of frozen molecular orbitals |
#+begin_example
Frozen_core.num_elec f ;;
- : int = 4
Frozen_core.num_mos f ;;
- : int = 2
#+end_example
#+begin_src ocaml :tangle (eval ml) :exports none
let num_elec t =
Array.fold_left ( + ) 0 t
let num_mos t =
(num_elec t) / 2
#+end_src
** Printers
#+begin_src ocaml :tangle (eval mli)
val pp : Format.formatter -> t -> unit
#+end_src
#+begin_src ocaml :tangle (eval ml) :exports none
let pp ppf t =
Format.fprintf ppf "@[[|";
Array.iter (fun x -> Format.fprintf ppf "@,@[%d@]" x) t;
Format.fprintf ppf "|]@]";
#+end_src

72
mo/lib/frozen_core.ml Normal file
View File

@ -0,0 +1,72 @@
(* [[file:../frozen_core.org::*Type][Type:3]] *)
type kind =
| All_electron
| Small
| Large
type t = int array
(* Type:3 ends here *)
(* | ~make~ | Creates a ~Frozen_core.t~ with the same kind for all atoms |
* | ~of_int_array~ | Creates a ~Frozen_core.t~ giving the number of frozen electrons per atom |
* | ~of_int_list~ | Creates a ~Frozen_core.t~ giving the number of frozen electrons per atom |
*
* #+begin_example
* let f = Frozen_core.(make Small nuclei) ;;
* val f : Frozen_core.t = [|0; 2; 2; 0|]
*
* let f = Frozen_core.(of_int_list [0; 2; 2; 0])
* val f : Frozen_core.t = [|0; 2; 2; 0|]
* #+end_example *)
(* [[file:../frozen_core.org::*Creation][Creation:2]] *)
let make_ae nuclei =
Array.map (fun _ -> 0) nuclei
let make_small nuclei =
Array.map (fun (e,_) -> Particles.Element.small_core e) nuclei
let make_large nuclei =
Array.map (fun (e,_) -> Particles.Element.large_core e) nuclei
let make = function
| All_electron -> make_ae
| Small -> make_small
| Large -> make_large
external of_int_array : int array -> t = "%identity"
let of_int_list = Array.of_list
(* Creation:2 ends here *)
(* | ~num_elec~ | Number of frozen electrons |
* | ~num_mos~ | Number of frozen molecular orbitals |
*
* #+begin_example
* Frozen_core.num_elec f ;;
* - : int = 4
*
* Frozen_core.num_mos f ;;
* - : int = 2
* #+end_example *)
(* [[file:../frozen_core.org::*Access][Access:2]] *)
let num_elec t =
Array.fold_left ( + ) 0 t
let num_mos t =
(num_elec t) / 2
(* Access:2 ends here *)
(* [[file:../frozen_core.org::*Printers][Printers:2]] *)
let pp ppf t =
Format.fprintf ppf "@[[|";
Array.iter (fun x -> Format.fprintf ppf "@,@[%d@]" x) t;
Format.fprintf ppf "|]@]";
(* Printers:2 ends here *)

39
mo/lib/frozen_core.mli Normal file
View File

@ -0,0 +1,39 @@
(* Type
*
* #+NAME: types *)
(* [[file:../frozen_core.org::types][types]] *)
type kind =
| All_electron
| Small
| Large
(* types ends here *)
(* [[file:../frozen_core.org::*Type][Type:2]] *)
type t
(* Type:2 ends here *)
(* Creation *)
(* [[file:../frozen_core.org::*Creation][Creation:1]] *)
val make : kind -> Particles.Nuclei.t -> t
val of_int_list : int list -> t
val of_int_array : int array -> t
(* Creation:1 ends here *)
(* Access *)
(* [[file:../frozen_core.org::*Access][Access:1]] *)
val num_elec : t -> int
val num_mos : t -> int
(* Access:1 ends here *)
(* Printers *)
(* [[file:../frozen_core.org::*Printers][Printers:1]] *)
val pp : Format.formatter -> t -> unit
(* Printers:1 ends here *)

View File

@ -18,18 +18,31 @@
All printers are fetched automatically using the following script:
#+NAME: printers
#+NAME: raw_printers
#+begin_src sh :results output raw
grep "val pp " ../*/*.org \
| grep -v docs \
| cut -d ":" -f 1 \
| sed 's|^../||' \
| sed 's|.org|.pp" ;|' \
| sed 's|.org||' \
| sed 's|/| |' \
| sed 's/[^ ]*/\u&/g' \
| sed 's| |.|' \
| sed 's|^|"|' \
| grep -v Top.Install_printers.pp
| grep -v Top.Install_printers
#+end_src
#+NAME: printers
#+begin_src python :results output raw :var p=raw_printers
result = []
for l in p.split():
dir, module = l.split('.')
if dir == module:
e = f'"{module}.pp" ;'
else:
e = f'"{dir}.{module}.pp" ;'
result.append(e)
result = '\n'.join(result)
print(result)
#+end_src

View File

@ -1,4 +1,4 @@
(* [[file:../install_printers.org::*Intall printers][Intall printers:2]] *)
(* [[file:../install_printers.org::*Intall printers][Intall printers:3]] *)
let printers =
[
"Common.Angular_momentum.pp" ;
@ -9,11 +9,13 @@ let printers =
"Common.Range.pp" ;
"Common.Spin.pp" ;
"Common.Zkey.pp" ;
"Mo.Frozen_core.pp" ;
"Particles.Electrons.pp" ;
"Particles.Element.pp" ;
"Particles.Nuclei.pp" ;
"Particles.Zmatrix.pp" ;
"Simulation.Simulation.pp" ;
"Perturbation.Mp2.pp" ;
"Simulation.pp" ;
]
@ -32,4 +34,4 @@ let rec install_printers = function
let () =
if not (install_printers printers) then
Format.eprintf "Problem installing QCaml-printers@."
(* Intall printers:2 ends here *)
(* Intall printers:3 ends here *)