From 1be1a995296d9d7b2c16de477e7ba7743507679b Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 5 Jan 2022 15:56:25 +0100 Subject: [PATCH] Documentation of Aos --- org/qmckl_ao.org | 1837 +++++++++++++++++++++++++++------------------- tools/lib.org | 46 +- 2 files changed, 1112 insertions(+), 771 deletions(-) diff --git a/org/qmckl_ao.org b/org/qmckl_ao.org index 7b51528..5351de0 100644 --- a/org/qmckl_ao.org +++ b/org/qmckl_ao.org @@ -101,53 +101,35 @@ int main() { * Context - The following arrays are stored in the context: +** Constant data + + The following arrays are stored in the context, and need to be set + when initializing the library: - |---------------------+---------------+----------------------------------------------------------------------| - | Variable | Dimensions | Description | - |---------------------+---------------+----------------------------------------------------------------------| - | ~type~ | | Gaussian (~'G'~) or Slater (~'S'~) | - | ~shell_num~ | | Number of shells | - | ~prim_num~ | | Total number of primitives | - | ~nucleus_index~ | ~[nucl_num]~ | Index of the first shell of each nucleus | - | ~nucleus_shell_num~ | ~[nucl_num]~ | Number of shells per nucleus | - | ~shell_ang_mom~ | ~[shell_num]~ | Angular momentum of each shell | - | ~shell_prim_num~ | ~[shell_num]~ | Number of primitives in each shell | - | ~shell_prim_index~ | ~[shell_num]~ | Address of the first primitive of each shell in the ~EXPONENT~ array | - | ~shell_factor~ | ~[shell_num]~ | Normalization factor for each shell | - | ~exponent~ | ~[prim_num]~ | Array of exponents | - | ~coefficient~ | ~[prim_num]~ | Array of coefficients | - | ~prim_factor~ | ~[prim_num]~ | Normalization factors of the primtives | - | ~ao_num~ | | Number of AOs | - | ~ao_cartesian~ | | If true, use polynomials. Otherwise, use spherical harmonics | - | ~ao_factor~ | ~[ao_num]~ | Normalization factor of the AO | + #+NAME: constant_data + |---------------------+----------------------+----------------------------------------------------------------------| + | Variable | Type | Description | + |---------------------+----------------------+----------------------------------------------------------------------| + | ~type~ | ~char~ | Gaussian (~'G'~) or Slater (~'S'~) | + | ~shell_num~ | ~int64_t~ | Number of shells | + | ~prim_num~ | ~int64_t~ | Total number of primitives | + | ~nucleus_index~ | ~int64_t[nucl_num]~ | Index of the first shell of each nucleus | + | ~nucleus_shell_num~ | ~int64_t[nucl_num]~ | Number of shells per nucleus | + | ~shell_ang_mom~ | ~int32_t[shell_num]~ | Angular momentum of each shell | + | ~shell_prim_num~ | ~int64_t[shell_num]~ | Number of primitives in each shell | + | ~shell_prim_index~ | ~int64_t[shell_num]~ | Address of the first primitive of each shell in the ~EXPONENT~ array | + | ~shell_factor~ | ~double[shell_num]~ | Normalization factor for each shell | + | ~exponent~ | ~double[prim_num]~ | Array of exponents | + | ~coefficient~ | ~double[prim_num]~ | Array of coefficients | + | ~prim_factor~ | ~double[prim_num]~ | Normalization factors of the primtives | + | ~ao_num~ | ~int64_t~ | Number of AOs | + | ~ao_cartesian~ | ~bool~ | If true, use polynomials. Otherwise, use spherical harmonics | + | ~ao_factor~ | ~double[ao_num]~ | Normalization factor of the AO | - Computed data: - - |--------------------------+----------------------------+-----------------------------------------------------------------------------------------------| - | Variable | Dimensions | Description | - |--------------------------+----------------------------+-----------------------------------------------------------------------------------------------| - | ~coefficient_normalized~ | ~[prim_num]~ | Normalized primitive coefficients | - | ~nucleus_prim_index~ | ~[nucl_num]~ | Index of the first primitive for each nucleus | - | ~nucleus_max_ang_mom~ | ~[nucl_num]~ | Maximum angular momentum for each nucleus | - | ~nucleus_range~ | ~[nucl_num]~ | Distance beyond which all the AOs are zero | - |--------------------------+----------------------------+-----------------------------------------------------------------------------------------------| - | ~primitive_vgl~ | ~[5][elec_num][prim_num]~ | Value, gradients, Laplacian of the primitives at electron positions | - | ~primitive_vgl_date~ | ~uint64_t~ | Late modification date of Value, gradients, Laplacian of the primitives at electron positions | - | ~shell_vgl~ | ~[5][elec_num][shell_num]~ | Value, gradients, Laplacian of the primitives at electron positions | - | ~shell_vgl_date~ | ~uint64_t~ | Late modification date of Value, gradients, Laplacian of the AOs at electron positions | - | ~ao_vgl~ | ~[5][elec_num][ao_num]~ | Value, gradients, Laplacian of the primitives at electron positions | - | ~ao_vgl_date~ | ~uint64_t~ | Late modification date of Value, gradients, Laplacian of the AOs at electron positions | - |--------------------------+----------------------------+-----------------------------------------------------------------------------------------------| - | ~nucl_shell_index~ | ~[nucl_num]~ | Index of the first shell for each nucleus | - | ~exponent_sorted~ | ~[prim_num]~ | Array of exponents for sorted primitives | - | ~coeff_norm_sorted~ | ~[prim_num]~ | Array of normalized coefficients for sorted primitives | - | ~prim_factor_sorted~ | ~[prim_num]~ | Normalization factors of the sorted primtives | - - For H_2 with the following basis set, - - #+NAME: basis - #+BEGIN_EXAMPLE + For H_2 with the following basis set, + + #+NAME: basis + #+BEGIN_EXAMPLE HYDROGEN S 5 1 3.387000E+01 6.068000E-03 @@ -165,12 +147,12 @@ P 1 1 3.880000E-01 1.000000E+00 D 1 1 1.057000E+00 1.0000000 - #+END_EXAMPLE + #+END_EXAMPLE - we have: + we have: - #+NAME: params - #+BEGIN_EXAMPLE + #+NAME: params + #+BEGIN_EXAMPLE type = 'G' shell_num = 12 prim_num = 20 @@ -198,11 +180,85 @@ prim_factor = [ 1.0006253235944540e+01, 2.4169531573445120e+00, 7.96109248497664 7.9610924849766440e-01, 3.0734305383061117e-01, 1.2929684417481876e-01, 3.0734305383061117e-01, 1.2929684417481876e-01, 2.1842769845268308e+00, 4.3649547399719840e-01, 1.8135965626177861e+00 ] - #+END_EXAMPLE + #+END_EXAMPLE -** Data structure :noexport: + A scalar variable ~$V$~ present in this table can be set or get by + calling the functions: - #+begin_src c :comments org :tangle (eval h_private_type) + #+NAME: template_scalar_c + #+begin_src C :tangle no +qmckl_exit_code qmckl_set_ao_basis_$V$ ( qmckl_context context, + const $type_of_V$ $V$); + +qmckl_exit_code qmckl_get_ao_basis_$V$ ( const qmckl_context context, + $type_of_V$ const $V$); + #+end_src + + #+begin_src f90 :tangle no +interface + integer(c_int32_t) function qmckl_set_ao_basis_$V$ (context, $V$) & + bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + $f_type_of_V$ , intent(in) , value :: $V$ + end function qmckl_set_ao_basis_$V$ +end interface + +interface + integer(c_int32_t) function qmckl_get_ao_basis_$V$ (context, $V$) & + bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + $f_type_of_V$ , intent(out) :: $V$ + end function qmckl_get_ao_basis_$V$ +end interface + #+end_src + For array variables, use the rule: + + #+NAME: template_array_c + #+begin_src C :tangle no +qmckl_exit_code qmckl_set_ao_basis_$V$ ( qmckl_context context, + const $type_of_V$ $V$, + const int64_t size_max); + +qmckl_exit_code qmckl_get_ao_basis_$V$ ( const qmckl_context context, + $type_of_V$ const $V$, + const int64_t size_max); + #+end_src + + #+begin_src f90 :tangle no +interface + integer(c_int32_t) function qmckl_set_ao_basis_$V$ (context, & + $V$, size_max) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + $f_type_of_V$ , intent(in) , value :: $V$ + integer (c_int64_t) , intent(in) , value :: size_max + end function qmckl_set_ao_basis_$V$ +end interface + +interface + integer(c_int32_t) function qmckl_get_ao_basis_$V$ (context, & + $V$, size_max) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + $f_type_of_V$ , intent(out) :: $V$ + integer (c_int64_t) , intent(in) , value :: size_max + end function qmckl_get_ao_basis_$V$ +end interface + #+end_src + +*** Data structure :noexport: + + #+begin_src c :comments org :tangle (eval h_private_type) typedef struct qmckl_ao_basis_struct { int64_t shell_num; int64_t prim_num; @@ -234,20 +290,20 @@ typedef struct qmckl_ao_basis_struct { bool ao_cartesian; char type; } qmckl_ao_basis_struct; - #+end_src + #+end_src - The ~uninitialized~ integer contains one bit set to one for each - initialization function which has not been called. It becomes equal - to zero after all initialization functions have been called. The - struct is then initialized and ~provided == true~. - Some values are initialized by default, and are not concerned by - this mechanism. + The ~uninitialized~ integer contains one bit set to one for each + initialization function which has not been called. It becomes equal + to zero after all initialization functions have been called. The + struct is then initialized and ~provided == true~. + Some values are initialized by default, and are not concerned by + this mechanism. - #+begin_src c :comments org :tangle (eval h_private_func) + #+begin_src c :comments org :tangle (eval h_private_func) qmckl_exit_code qmckl_init_ao_basis(qmckl_context context); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) + #+begin_src c :comments org :tangle (eval c) qmckl_exit_code qmckl_init_ao_basis(qmckl_context context) { if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { @@ -267,12 +323,13 @@ qmckl_exit_code qmckl_init_ao_basis(qmckl_context context) { return QMCKL_SUCCESS; } - #+end_src + #+end_src -** Initialization functions +*** Initialization functions +**** C interface - #+NAME:pre2 - #+begin_src c :exports none + #+NAME:pre2 + #+begin_src c :exports none if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { return qmckl_failwith( context, QMCKL_INVALID_CONTEXT, @@ -281,10 +338,10 @@ if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { } qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; - #+end_src + #+end_src - #+NAME:post2 - #+begin_src c :exports none + #+NAME:post2 + #+begin_src c :exports none ctx->ao_basis.uninitialized &= ~mask; ctx->ao_basis.provided = (ctx->ao_basis.uninitialized == 0); if (ctx->ao_basis.provided) { @@ -293,18 +350,18 @@ if (ctx->ao_basis.provided) { } return QMCKL_SUCCESS; - #+end_src + #+end_src - To set the basis set, all the following functions need to be - called. + To set the basis set, all the following functions need to be + called. - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_type (qmckl_context context, const char basis_type); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_type(qmckl_context context, const char basis_type) @@ -323,16 +380,16 @@ qmckl_set_ao_basis_type(qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_shell_num (qmckl_context context, const int64_t shell_num); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_shell_num (qmckl_context context, const int64_t shell_num); @@ -360,16 +417,16 @@ qmckl_set_ao_basis_shell_num (qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_prim_num (qmckl_context context, const int64_t prim_num); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_prim_num (qmckl_context context, const int64_t prim_num) @@ -404,16 +461,16 @@ qmckl_set_ao_basis_prim_num (qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_ao_num (qmckl_context context, const int64_t ao_num); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_ao_num (qmckl_context context, const int64_t ao_num) @@ -447,17 +504,17 @@ qmckl_set_ao_basis_ao_num (qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_nucleus_index (qmckl_context context, const int64_t* nucleus_index, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_nucleus_index (qmckl_context context, const int64_t* nucleus_index, @@ -509,17 +566,17 @@ qmckl_set_ao_basis_nucleus_index (qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_nucleus_shell_num (qmckl_context context, const int64_t* nucleus_shell_num, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_nucleus_shell_num (qmckl_context context, const int64_t* nucleus_shell_num, @@ -571,17 +628,17 @@ qmckl_set_ao_basis_nucleus_shell_num (qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_shell_ang_mom (qmckl_context context, const int32_t* shell_ang_mom, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_shell_ang_mom (qmckl_context context, const int32_t* shell_ang_mom, @@ -634,17 +691,17 @@ qmckl_set_ao_basis_shell_ang_mom (qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_shell_prim_num (qmckl_context context, const int64_t* shell_prim_num, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_shell_prim_num (qmckl_context context, const int64_t* shell_prim_num, @@ -697,17 +754,17 @@ qmckl_set_ao_basis_shell_prim_num (qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_shell_prim_index (qmckl_context context, const int64_t* shell_prim_index, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_shell_prim_index (qmckl_context context, const int64_t* shell_prim_index, @@ -759,17 +816,17 @@ qmckl_set_ao_basis_shell_prim_index (qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_shell_factor (qmckl_context context, const double* shell_factor, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_shell_factor (qmckl_context context, const double* shell_factor, @@ -821,17 +878,17 @@ qmckl_set_ao_basis_shell_factor (qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_exponent (qmckl_context context, const double* exponent, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_exponent (qmckl_context context, const double* exponent, @@ -883,17 +940,17 @@ qmckl_set_ao_basis_exponent (qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_coefficient (qmckl_context context, const double* coefficient, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_coefficient (qmckl_context context, const double* coefficient, @@ -945,17 +1002,17 @@ qmckl_set_ao_basis_coefficient (qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_prim_factor (qmckl_context context, const double* prim_factor, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_prim_factor (qmckl_context context, const double* prim_factor, @@ -1007,17 +1064,17 @@ qmckl_set_ao_basis_prim_factor (qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_ao_factor (qmckl_context context, const double* ao_factor, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_ao_factor (qmckl_context context, const double* ao_factor, @@ -1068,16 +1125,16 @@ qmckl_set_ao_basis_ao_factor (qmckl_context context, <> } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_cartesian (qmckl_context context, const bool cartesian); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_cartesian (qmckl_context context, const bool cartesian) @@ -1089,21 +1146,21 @@ qmckl_set_ao_basis_cartesian (qmckl_context context, <> } - #+end_src + #+end_src - When the basis set is completely entered, extra data structures may be - computed to accelerate the calculations. The primitives within each - contraction are sorted in ascending order of their exponents, such - that as soon as a primitive is zero all the following functions - vanish. Also, it is possible to compute a nuclear radius beyond which - all the primitives are zero up to the numerical accuracy defined in - the context. + When the basis set is completely entered, extra data structures may be + computed to accelerate the calculations. The primitives within each + contraction are sorted in ascending order of their exponents, such + that as soon as a primitive is zero all the following functions + vanish. Also, it is possible to compute a nuclear radius beyond which + all the primitives are zero up to the numerical accuracy defined in + the context. - #+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none qmckl_exit_code qmckl_finalize_basis(qmckl_context context); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_finalize_basis(qmckl_context context) { if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { @@ -1231,21 +1288,202 @@ qmckl_exit_code qmckl_finalize_basis(qmckl_context context) { /* TODO : sort the basis set here */ return QMCKL_SUCCESS; } - #+end_src + #+end_src -** Access functions +**** Fortran interface - ~size_max~ is the dimension of the input array, which should be - equal of larger than the value given in the table of the [[Context]] - section. + #+begin_src f90 :tangle (eval fh_func) :comments org +interface + integer(c_int32_t) function qmckl_set_ao_basis_type (context, & + basis_type) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + character(c_char) , intent(in) , value :: basis_type + end function qmckl_set_ao_basis_type +end interface - #+begin_src c :comments org :tangle (eval h_func) +interface + integer(c_int32_t) function qmckl_set_ao_basis_shell_num(context, & + num) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + integer (c_int64_t) , intent(in) , value :: num + end function qmckl_set_ao_basis_shell_num +end interface + +interface + integer(c_int32_t) function qmckl_set_ao_basis_prim_num(context, & + num) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + integer (c_int64_t) , intent(in) , value :: num + end function qmckl_set_ao_basis_prim_num +end interface + +interface + integer(c_int32_t) function qmckl_set_ao_basis_nucleus_index(context, & + idx, size_max) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + integer (c_int64_t) , intent(in) :: idx(*) + integer (c_int64_t) , intent(in) , value :: size_max + end function qmckl_set_ao_basis_nucleus_index +end interface + +interface + integer(c_int32_t) function qmckl_set_ao_basis_nucleus_shell_num(context, & + shell_num, size_max) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + integer (c_int64_t) , intent(in) :: shell_num(*) + integer (c_int64_t) , intent(in) , value :: size_max + end function qmckl_set_ao_basis_nucleus_shell_num +end interface + +interface + integer(c_int32_t) function qmckl_set_ao_basis_shell_ang_mom(context, & + shell_ang_mom, size_max) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + integer (c_int32_t) , intent(in) :: shell_ang_mom(*) + integer (c_int64_t) , intent(in) , value :: size_max + end function qmckl_set_ao_basis_shell_ang_mom +end interface + +interface + integer(c_int32_t) function qmckl_set_ao_basis_shell_prim_num(context, & + shell_prim_num, size_max) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + integer (c_int64_t) , intent(in) :: shell_prim_num(*) + integer (c_int64_t) , intent(in) , value :: size_max + end function qmckl_set_ao_basis_shell_prim_num +end interface + +interface + integer(c_int32_t) function qmckl_set_ao_basis_shell_prim_index(context, & + shell_prim_index, size_max) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + integer (c_int64_t) , intent(in) :: shell_prim_index(*) + integer (c_int64_t) , intent(in) , value :: size_max + end function qmckl_set_ao_basis_shell_prim_index +end interface + +interface + integer(c_int32_t) function qmckl_set_ao_basis_shell_factor(context, & + shell_factor, size_max) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + real (c_double) , intent(in) :: shell_factor(*) + integer (c_int64_t) , intent(in) , value :: size_max + end function qmckl_set_ao_basis_shell_factor +end interface + +interface + integer(c_int32_t) function qmckl_set_ao_basis_exponent(context, & + exponent, size_max) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + real (c_double) , intent(in) :: exponent(*) + integer (c_int64_t) , intent(in) , value :: size_max + end function qmckl_set_ao_basis_exponent +end interface + +interface + integer(c_int32_t) function qmckl_set_ao_basis_coefficient(context, & + coefficient, size_max) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + real (c_double) , intent(in) :: coefficient(*) + integer (c_int64_t) , intent(in) , value :: size_max + end function qmckl_set_ao_basis_coefficient +end interface + +interface + integer(c_int32_t) function qmckl_set_ao_basis_prim_factor(context, & + prim_factor, size_max) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + real (c_double) , intent(in) :: prim_factor(*) + integer (c_int64_t) , intent(in) , value :: size_max + end function qmckl_set_ao_basis_prim_factor +end interface + +interface + integer(c_int32_t) function qmckl_set_ao_basis_ao_num(context, & + num) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + integer (c_int64_t) , intent(in) , value :: num + end function qmckl_set_ao_basis_ao_num +end interface + +interface + integer(c_int32_t) function qmckl_set_ao_basis_cartesian(context, & + cartesian) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + logical (c_bool) , intent(in) , value :: cartesian + end function qmckl_set_ao_basis_cartesian +end interface + +interface + integer(c_int32_t) function qmckl_set_ao_basis_ao_factor(context, & + ao_factor, size_max) bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + integer (c_int64_t) , intent(in) , value :: context + real (c_double) , intent(in) :: ao_factor(*) + integer (c_int64_t) , intent(in) , value :: size_max + end function qmckl_set_ao_basis_ao_factor +end interface + #+end_src + +*** Access functions + + ~size_max~ is the dimension of the input array, which should be + equal of larger than the value given in the table of the [[Context]] + section. + +**** C interface + + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_type (const qmckl_context context, char* const basis_type) - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_type (const qmckl_context context, char* const basis_type) @@ -1277,16 +1515,16 @@ qmckl_get_ao_basis_type (const qmckl_context context, return QMCKL_SUCCESS; } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_shell_num (const qmckl_context context, int64_t* const shell_num); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_shell_num (const qmckl_context context, int64_t* const shell_num) @@ -1315,16 +1553,16 @@ qmckl_get_ao_basis_shell_num (const qmckl_context context, return QMCKL_SUCCESS; } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_prim_num (const qmckl_context context, int64_t* const prim_num); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_prim_num (const qmckl_context context, int64_t* const prim_num) @@ -1354,17 +1592,17 @@ qmckl_get_ao_basis_prim_num (const qmckl_context context, return QMCKL_SUCCESS; } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_nucleus_shell_num (const qmckl_context context, int64_t* const nucleus_shell_num, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_nucleus_shell_num (const qmckl_context context, int64_t* const nucleus_shell_num, @@ -1409,17 +1647,17 @@ qmckl_get_ao_basis_nucleus_shell_num (const qmckl_context context, return QMCKL_SUCCESS; } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_nucleus_index (const qmckl_context context, int64_t* const nucleus_index, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_nucleus_index (const qmckl_context context, int64_t* const nucleus_index, @@ -1465,17 +1703,17 @@ qmckl_get_ao_basis_nucleus_index (const qmckl_context context, } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_shell_ang_mom (const qmckl_context context, int32_t* const shell_ang_mom, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_shell_ang_mom (const qmckl_context context, int32_t* const shell_ang_mom, @@ -1521,17 +1759,17 @@ qmckl_get_ao_basis_shell_ang_mom (const qmckl_context context, } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_shell_prim_num (const qmckl_context context, int64_t* const shell_prim_num, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_shell_prim_num (const qmckl_context context, int64_t* const shell_prim_num, @@ -1577,17 +1815,17 @@ qmckl_get_ao_basis_shell_prim_num (const qmckl_context context, } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_shell_prim_index (const qmckl_context context, int64_t* const shell_prim_index, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_shell_prim_index (const qmckl_context context, int64_t* const shell_prim_index, @@ -1631,17 +1869,17 @@ qmckl_get_ao_basis_shell_prim_index (const qmckl_context context, (size_t) ctx->ao_basis.shell_num * sizeof(int64_t)); return QMCKL_SUCCESS; } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_shell_factor (const qmckl_context context, double* const shell_factor, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_shell_factor (const qmckl_context context, double* const shell_factor, @@ -1687,17 +1925,17 @@ qmckl_get_ao_basis_shell_factor (const qmckl_context context, } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_exponent (const qmckl_context context, double* const exponent, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_exponent (const qmckl_context context, double* const exponent, @@ -1741,17 +1979,17 @@ qmckl_get_ao_basis_exponent (const qmckl_context context, (size_t) ctx->ao_basis.prim_num * sizeof(double)); return QMCKL_SUCCESS; } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_coefficient (const qmckl_context context, double* const coefficient, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_coefficient (const qmckl_context context, double* const coefficient, @@ -1796,17 +2034,17 @@ qmckl_get_ao_basis_coefficient (const qmckl_context context, } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_prim_factor (const qmckl_context context, double* const prim_factor, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_prim_factor (const qmckl_context context, double* const prim_factor, @@ -1851,16 +2089,16 @@ qmckl_get_ao_basis_prim_factor (const qmckl_context context, return QMCKL_SUCCESS; } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_ao_num (const qmckl_context context, int64_t* const ao_num); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_ao_num (const qmckl_context context, int64_t* const ao_num) @@ -1891,17 +2129,17 @@ qmckl_get_ao_basis_ao_num (const qmckl_context context, } - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_get_ao_basis_ao_factor (const qmckl_context context, double* const ao_factor, const int64_t size_max); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_ao_basis_ao_factor (const qmckl_context context, double* const ao_factor, @@ -1944,17 +2182,17 @@ qmckl_get_ao_basis_ao_factor (const qmckl_context context, memcpy(ao_factor, ctx->ao_basis.ao_factor, ctx->ao_basis.ao_num * sizeof(double)); return QMCKL_SUCCESS; } - #+end_src + #+end_src - When all the data for the AOs have been provided, the following - function returns ~true~. + When all the data for the AOs have been provided, the following + function returns ~true~. - #+begin_src c :comments org :tangle (eval h_func) + #+begin_src c :comments org :tangle (eval h_func) bool qmckl_ao_basis_provided (const qmckl_context context); - #+end_src + #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none bool qmckl_ao_basis_provided(const qmckl_context context) { if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { @@ -1966,190 +2204,190 @@ bool qmckl_ao_basis_provided(const qmckl_context context) { return ctx->ao_basis.provided; } - #+end_src + #+end_src -** Fortran interfaces +**** Fortran interface - #+begin_src f90 :tangle (eval fh_func) :comments org :exports none + #+begin_src f90 :tangle (eval fh_func) :comments org interface - integer(c_int32_t) function qmckl_set_ao_basis_type (context, t) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_type (context, & + basis_type) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - character(c_char) , intent(in) , value :: t - end function + character(c_char) , intent(out) :: basis_type + end function qmckl_get_ao_basis_type end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_shell_num(context, num) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_shell_num(context, & + num) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - integer (c_int64_t) , intent(in) , value :: num - end function + integer (c_int64_t) , intent(out) :: num + end function qmckl_get_ao_basis_shell_num end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_prim_num(context, num) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_prim_num(context, & + num) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - integer (c_int64_t) , intent(in) , value :: num - end function + integer (c_int64_t) , intent(out) :: num + end function qmckl_get_ao_basis_prim_num end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_nucleus_index(context, idx, size_max) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_nucleus_shell_num(context, & + shell_num, size_max) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - integer (c_int64_t) , intent(in) :: idx(*) + integer (c_int64_t) , intent(out) :: shell_num(*) integer (c_int64_t) , intent(in) , value :: size_max - end function + end function qmckl_get_ao_basis_nucleus_shell_num end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_nucleus_shell_num(context,shell_num, size_max) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_nucleus_index(context, & + idx, size_max) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - integer (c_int64_t) , intent(in) :: shell_num(*) + integer (c_int64_t) , intent(out) :: idx(*) integer (c_int64_t) , intent(in) , value :: size_max - end function + end function qmckl_get_ao_basis_nucleus_index end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_shell_ang_mom(context,shell_ang_mom, size_max) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_shell_ang_mom(context, & + shell_ang_mom, size_max) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - integer (c_int32_t) , intent(in) :: shell_ang_mom(*) + integer (c_int32_t) , intent(out) :: shell_ang_mom(*) integer (c_int64_t) , intent(in) , value :: size_max - end function + end function qmckl_get_ao_basis_shell_ang_mom end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_shell_prim_num(context,shell_prim_num, size_max) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_shell_prim_num(context, & + shell_prim_num, size_max) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - integer (c_int64_t) , intent(in) :: shell_prim_num(*) + integer (c_int64_t) , intent(out) :: shell_prim_num(*) integer (c_int64_t) , intent(in) , value :: size_max - end function + end function qmckl_get_ao_basis_shell_prim_num end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_shell_prim_index(context,shell_prim_index, size_max) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_shell_prim_index(context, & + shell_prim_index, size_max) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - integer (c_int64_t) , intent(in) :: shell_prim_index(*) + integer (c_int64_t) , intent(out) :: shell_prim_index(*) integer (c_int64_t) , intent(in) , value :: size_max - end function + end function qmckl_get_ao_basis_shell_prim_index end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_shell_factor(context,shell_factor, size_max) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_shell_factor(context, & + shell_factor, size_max) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - real (c_double) , intent(in) :: shell_factor(*) + real (c_double) , intent(out) :: shell_factor(*) integer (c_int64_t) , intent(in) , value :: size_max - end function + end function qmckl_get_ao_basis_shell_factor end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_exponent(context,exponent, size_max) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_exponent(context, & + exponent, size_max) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - real (c_double) , intent(in) :: exponent(*) + real (c_double) , intent(out) :: exponent(*) integer (c_int64_t) , intent(in) , value :: size_max - end function + end function qmckl_get_ao_basis_exponent end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_coefficient(context,coefficient, size_max) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_coefficient(context, & + coefficient, size_max) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - real (c_double) , intent(in) :: coefficient(*) + real (c_double) , intent(out) :: coefficient(*) integer (c_int64_t) , intent(in) , value :: size_max - end function + end function qmckl_get_ao_basis_coefficient end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_prim_factor(context,prim_factor, size_max) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_prim_factor(context, & + prim_factor, size_max) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - real (c_double) , intent(in) :: prim_factor(*) + real (c_double) , intent(out) :: prim_factor(*) integer (c_int64_t) , intent(in) , value :: size_max - end function + end function qmckl_get_ao_basis_prim_factor end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_ao_num(context, num) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_ao_num(context, & + num) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - integer (c_int64_t) , intent(in) , value :: num - end function + integer (c_int64_t) , intent(out) :: num + end function qmckl_get_ao_basis_ao_num end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_cartesian(context,cartesian) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_cartesian(context, & + cartesian) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - logical (c_bool) , intent(in) , value :: cartesian - end function + logical (c_bool) , intent(out) :: cartesian + end function qmckl_get_ao_basis_cartesian end interface interface - integer(c_int32_t) function qmckl_set_ao_basis_ao_factor(context,ao_factor, size_max) & - bind(C) + integer(c_int32_t) function qmckl_get_ao_basis_ao_factor(context, & + ao_factor, size_max) bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context - real (c_double) , intent(in) :: ao_factor(*) + real (c_double) , intent(out) :: ao_factor(*) integer (c_int64_t) , intent(in) , value :: size_max - end function + end function qmckl_get_ao_basis_ao_factor end interface - #+end_src + #+end_src -** Test :noexport: +*** Test :noexport: - #+begin_src c :tangle (eval c_test) :exports none :exports none + #+begin_src c :tangle (eval c_test) :exports none :exports none const int64_t nucl_num = chbrclf_nucl_num; const double* nucl_charge = chbrclf_charge; const double* nucl_coord = &(chbrclf_nucl_coord[0][0]); @@ -2351,47 +2589,181 @@ for (int64_t i=0 ; i < ao_num ; ++i) { assert(ao_factor_test[i] == ao_factor[i]); } - #+end_src + #+end_src + +** Computed data + + The following data is computed as described in the next sections: + + |--------------------------+----------------------------------+-----------------------------------------------------------------------------------------------| + | Variable | Type | Description | + |--------------------------+----------------------------------+-----------------------------------------------------------------------------------------------| + | ~primitive_vgl~ | ~double[5][elec_num][prim_num]~ | Value, gradients, Laplacian of the primitives at electron positions | + | ~primitive_vgl_date~ | ~uint64_t~ | Last modification date of Value, gradients, Laplacian of the primitives at electron positions | + | ~shell_vgl~ | ~double[5][elec_num][shell_num]~ | Value, gradients, Laplacian of the primitives at electron positions | + | ~shell_vgl_date~ | ~uint64_t~ | Last modification date of Value, gradients, Laplacian of the AOs at electron positions | + | ~ao_vgl~ | ~double[5][elec_num][ao_num]~ | Value, gradients, Laplacian of the primitives at electron positions | + | ~ao_vgl_date~ | ~uint64_t~ | Last modification date of Value, gradients, Laplacian of the AOs at electron positions | + +*** Access functions + + #+begin_src c :comments org :tangle (eval h_func) :noweb yes +qmckl_exit_code +qmckl_get_ao_basis_primitive_vgl (qmckl_context context, + double* const primitive_vgl, + const int64_t size_max); + #+end_src + + Returns the array of values, gradients an Laplacian of primitive + basis functions evaluated at the current coordinates. + + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none +qmckl_exit_code +qmckl_get_ao_basis_primitive_vgl (qmckl_context context, + double* const primitive_vgl, + const int64_t size_max) +{ + if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { + return qmckl_failwith( context, + QMCKL_INVALID_CONTEXT, + "qmckl_get_ao_basis_primitive_vgl", + NULL); + } + + qmckl_exit_code rc; + + rc = qmckl_provide_ao_basis_primitive_vgl(context); + if (rc != QMCKL_SUCCESS) return rc; + + qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; + assert (ctx != NULL); + + size_t sze = ctx->ao_basis.prim_num * 5 * ctx->electron.num; + if (size_max < sze) { + return qmckl_failwith( context, + QMCKL_FAILURE, + "qmckl_get_ao_basis_primitive_vgl", + "input array too small"); + } + memcpy(primitive_vgl, ctx->ao_basis.primitive_vgl, sze * sizeof(double)); + + return QMCKL_SUCCESS; +} + #+end_src + + #+begin_src f90 :tangle (eval fh_func) :comments org :exports none + interface + integer(c_int32_t) function qmckl_get_ao_basis_primitive_vgl & + (context, primitive_vgl, size_max) & + bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + + integer (c_int64_t) , intent(in) , value :: context + double precision, intent(out) :: primitive_vgl(*) + integer (c_int64_t) , intent(in) , value :: size_max + end function + end interface + #+end_src + + + + #+begin_src c :comments org :tangle (eval h_func) :noweb yes +qmckl_exit_code +qmckl_get_ao_basis_shell_vgl (qmckl_context context, + double* const shell_vgl, + const int64_t size_max); + #+end_src + + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none +qmckl_exit_code +qmckl_get_ao_basis_shell_vgl (qmckl_context context, + double* const shell_vgl, + const int64_t size_max); +{ + if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { + return qmckl_failwith( context, + QMCKL_INVALID_CONTEXT, + "qmckl_get_ao_basis_shell_vgl", + NULL); + } + + qmckl_exit_code rc; + + rc = qmckl_provide_ao_basis_shell_vgl(context); + if (rc != QMCKL_SUCCESS) return rc; + + qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; + assert (ctx != NULL); + + size_t sze = ctx->ao_basis.shell_num * 5 * ctx->electron.num; + if (size_max < sze) { + return qmckl_failwith( context, + QMCKL_FAILURE, + "qmckl_get_ao_basis_shell_vgl", + "input array too small"); + } + memcpy(shell_vgl, ctx->ao_basis.shell_vgl, sze * sizeof(double)); + + return QMCKL_SUCCESS; +} + #+end_src + + #+begin_src f90 :tangle (eval fh_func) :comments org :exports none + interface + integer(c_int32_t) function qmckl_get_ao_basis_shell_vgl & + (context, shell_vgl, size_max) & + bind(C) + use, intrinsic :: iso_c_binding + import + implicit none + + integer (c_int64_t) , intent(in) , value :: context + double precision, intent(out) :: shell_vgl(*) + integer (c_int64_t) , intent(in) , value :: size_max + end function + end interface + #+end_src * Radial part -** TODO Helper functions to accelerate calculations ** General functions for Gaussian basis functions - ~qmckl_ao_gaussian_vgl~ computes the values, gradients and - Laplacians at a given point of ~n~ Gaussian functions centered at - the same point: + ~qmckl_ao_gaussian_vgl~ computes the values, gradients and + Laplacians at a given point of ~n~ Gaussian functions centered at + the same point: - \[ v_i = \exp(-a_i |X-R|^2) \] - \[ \nabla_x v_i = -2 a_i (X_x - R_x) v_i \] - \[ \nabla_y v_i = -2 a_i (X_y - R_y) v_i \] - \[ \nabla_z v_i = -2 a_i (X_z - R_z) v_i \] - \[ \Delta v_i = a_i (4 |X-R|^2 a_i - 6) v_i \] + \[ v_i = \exp(-a_i |X-R|^2) \] + \[ \nabla_x v_i = -2 a_i (X_x - R_x) v_i \] + \[ \nabla_y v_i = -2 a_i (X_y - R_y) v_i \] + \[ \nabla_z v_i = -2 a_i (X_z - R_z) v_i \] + \[ \Delta v_i = a_i (4 |X-R|^2 a_i - 6) v_i \] - |--------------+------------+------------------------------------------------------| - | Variable | Dimensions | Description | - |--------------+------------+------------------------------------------------------| - | ~context~ | | Global state | - | ~X(3)~ | ~[3]~ | Array containing the coordinates of the points | - | ~R(3)~ | ~[3]~ | Array containing the x,y,z coordinates of the center | - | ~n~ | | Number of computed Gaussians | - | ~A(n)~ | ~[n]~ | Exponents of the Gaussians | - | ~VGL(ldv,5)~ | ~[5][ldv]~ | Value, gradients and Laplacian of the Gaussians | - | ~ldv~ | | Leading dimension of array ~VGL~ | - |--------------+------------+------------------------------------------------------| + |--------------+------------------+------------------------------------------------------| + | Variable | Type | Description | + |--------------+------------------+------------------------------------------------------| + | ~context~ | ~qmckl_context~ | Global state | + | ~X(3)~ | ~double[3]~ | Array containing the coordinates of the points | + | ~R(3)~ | ~double[3]~ | Array containing the x,y,z coordinates of the center | + | ~n~ | ~int64_t~ | Number of computed Gaussians | + | ~A(n)~ | ~double[n]~ | Exponents of the Gaussians | + | ~VGL(ldv,5)~ | ~double[5][ldv]~ | Value, gradients and Laplacian of the Gaussians | + | ~ldv~ | ~int64_t~ | Leading dimension of array ~VGL~ | + |--------------+------------------+------------------------------------------------------| - Requirements + Requirements: - - ~context~ is not 0 - - ~n~ > 0 - - ~ldv~ >= 5 - - ~A(i)~ > 0 for all ~i~ - - ~X~ is allocated with at least $3 \times 8$ bytes - - ~R~ is allocated with at least $3 \times 8$ bytes - - ~A~ is allocated with at least $n \times 8$ bytes - - ~VGL~ is allocated with at least $n \times 5 \times 8$ bytes + - ~context~ \ne 0 + - ~n~ > 0 + - ~ldv~ >= 5 + - ~A(i)~ > 0 for all ~i~ + - ~X~ is allocated with at least $3 \times 8$ bytes + - ~R~ is allocated with at least $3 \times 8$ bytes + - ~A~ is allocated with at least $n \times 8$ bytes + - ~VGL~ is allocated with at least $n \times 5 \times 8$ bytes - #+begin_src c :tangle (eval h_func) + #+begin_src c :tangle (eval h_func) qmckl_exit_code qmckl_ao_gaussian_vgl(const qmckl_context context, const double *X, @@ -2400,9 +2772,9 @@ qmckl_ao_gaussian_vgl(const qmckl_context context, const int64_t *A, const double *VGL, const int64_t ldv); - #+end_src + #+end_src - #+begin_src f90 :tangle (eval f) + #+begin_src f90 :tangle (eval f) integer function qmckl_ao_gaussian_vgl_f(context, X, R, n, A, VGL, ldv) result(info) use qmckl implicit none @@ -2463,9 +2835,9 @@ integer function qmckl_ao_gaussian_vgl_f(context, X, R, n, A, VGL, ldv) result(i end do end function qmckl_ao_gaussian_vgl_f - #+end_src + #+end_src - #+begin_src f90 :tangle (eval f) :exports none + #+begin_src f90 :tangle (eval f) :exports none integer(c_int32_t) function qmckl_ao_gaussian_vgl(context, X, R, n, A, VGL, ldv) & bind(C) result(info) use, intrinsic :: iso_c_binding @@ -2480,9 +2852,9 @@ integer(c_int32_t) function qmckl_ao_gaussian_vgl(context, X, R, n, A, VGL, ldv) integer, external :: qmckl_ao_gaussian_vgl_f info = qmckl_ao_gaussian_vgl_f(context, X, R, n, A, VGL, ldv) end function qmckl_ao_gaussian_vgl - #+end_src + #+end_src - #+begin_src f90 :tangle (eval fh_func) :exports none + #+begin_src f90 :tangle (eval fh_func) :exports none interface integer(c_int32_t) function qmckl_ao_gaussian_vgl(context, X, R, n, A, VGL, ldv) & bind(C) @@ -2494,10 +2866,11 @@ end function qmckl_ao_gaussian_vgl real (c_double) , intent(out) :: VGL(ldv,5) end function qmckl_ao_gaussian_vgl end interface - #+end_src + #+end_src - # Test - #+begin_src f90 :tangle (eval f_test) +*** Test :noexport: + + #+begin_src f90 :tangle (eval f_test) integer(c_int32_t) function test_qmckl_ao_gaussian_vgl(context) bind(C) use qmckl implicit none @@ -2562,49 +2935,169 @@ integer(c_int32_t) function test_qmckl_ao_gaussian_vgl(context) bind(C) deallocate(VGL) end function test_qmckl_ao_gaussian_vgl - #+end_src + #+end_src - #+begin_src c :tangle (eval c_test) :exports none - int test_qmckl_ao_gaussian_vgl(qmckl_context context); - assert(0 == test_qmckl_ao_gaussian_vgl(context)); - #+end_src + #+begin_src c :tangle (eval c_test) :exports none +int test_qmckl_ao_gaussian_vgl(qmckl_context context); +assert(0 == test_qmckl_ao_gaussian_vgl(context)); + #+end_src + +** TODO General functions for Slater basis functions :noexport: +** TODO General functions for Radial functions on a grid :noexport: +** TODO Helper functions to accelerate calculations :noexport: + + |--------------------------+----------------------------------+-----------------------------------------------------------------------------------------------| + | Variable | Type | Description | + |--------------------------+----------------------------------+-----------------------------------------------------------------------------------------------| + | ~coefficient_normalized~ | ~double[prim_num]~ | Normalized primitive coefficients | + | ~nucleus_prim_index~ | ~int64_t[nucl_num]~ | Index of the first primitive for each nucleus | + | ~nucleus_max_ang_mom~ | ~int32_t[nucl_num]~ | Maximum angular momentum for each nucleus | + | ~nucleus_range~ | ~double[nucl_num]~ | Distance beyond which all the AOs are zero | + |--------------------------+----------------------------------+-----------------------------------------------------------------------------------------------| + | ~nucl_shell_index~ | ~int64_t[nucl_num]~ | Index of the first shell for each nucleus | + | ~exponent_sorted~ | ~double[prim_num]~ | Array of exponents for sorted primitives | + | ~coeff_norm_sorted~ | ~double[prim_num]~ | Array of normalized coefficients for sorted primitives | + | ~prim_factor_sorted~ | ~double[prim_num]~ | Normalization factors of the sorted primtives | -** TODO General functions for Slater basis functions -** TODO General functions for Radial functions on a grid ** Computation of primitives -*** Get +*** Compute + :PROPERTIES: + :Name: qmckl_compute_ao_basis_primitive_gaussian_vgl + :CRetType: qmckl_exit_code + :FRetType: qmckl_exit_code + :END: - #+begin_src c :comments org :tangle (eval h_func) :noweb yes -qmckl_exit_code qmckl_get_ao_basis_primitive_vgl(qmckl_context context, double* const primitive_vgl); + #+NAME: qmckl_ao_basis_primitive_gaussian_vgl_args + | Variable | Type | In/Out | Description | + |----------------------+---------------------------------+--------+--------------------------------------------------| + | ~context~ | ~qmckl_context~ | in | Global state | + | ~prim_num~ | ~int64_t~ | in | Number of primitives | + | ~elec_num~ | ~int64_t~ | in | Number of electrons | + | ~nucl_num~ | ~int64_t~ | in | Number of nuclei | + | ~nucleus_prim_index~ | ~int64_t[nucl_num]~ | in | Index of the 1st primitive of each nucleus | + | ~elec_coord~ | ~double[3][elec_num]~ | in | Electron coordinates | + | ~nucl_coord~ | ~double[3][elec_num]~ | in | Nuclear coordinates | + | ~expo~ | ~double[prim_num]~ | in | Exponents of the primitives | + | ~primitive_vgl~ | ~double[5][elec_num][prim_num]~ | out | Value, gradients and Laplacian of the primitives | + + #+CALL: generate_c_header(table=qmckl_ao_basis_primitive_gaussian_vgl_args,rettyp=get_value("CRetType"),fname="qmckl_compute_ao_basis_primitive_gaussian_vgl")) + + #+RESULTS: + #+begin_src c :tangle (eval h_func) :comments org +qmckl_exit_code qmckl_compute_ao_basis_primitive_gaussian_vgl ( + const qmckl_context context, + const int64_t prim_num, + const int64_t elec_num, + const int64_t nucl_num, + const int64_t nucleus_prim_index, + const double elec_coord, + const double nucl_coord, + const double expo, + double* const primitive_vgl ); #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none -qmckl_exit_code qmckl_get_ao_basis_primitive_vgl(qmckl_context context, double* const primitive_vgl) { - if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { - return qmckl_failwith( context, - QMCKL_INVALID_CONTEXT, - "qmckl_get_ao_basis_primitive_vgl", - NULL); - } + #+begin_src f90 :comments org :tangle (eval f) :noweb yes +integer function qmckl_compute_ao_basis_primitive_gaussian_vgl_f( & + context, prim_num, elec_num, nucl_num, & + nucleus_prim_index, elec_coord, nucl_coord, & + expo, primitive_vgl) & + result(info) - qmckl_exit_code rc; + use qmckl + implicit none + integer(qmckl_context), intent(in) :: context + integer*8 , intent(in) :: prim_num + integer*8 , intent(in) :: nucl_num + integer*8 , intent(in) :: elec_num + integer*8 , intent(in) :: nucleus_prim_index(nucl_num+1) + double precision , intent(in) :: elec_coord(elec_num,3) + double precision , intent(in) :: nucl_coord(nucl_num,3) + double precision , intent(in) :: expo(prim_num) + double precision , intent(out) :: primitive_vgl(prim_num,elec_num,5) - rc = qmckl_provide_ao_basis_primitive_vgl(context); - if (rc != QMCKL_SUCCESS) return rc; + integer*8 :: inucl, iprim, ielec + double precision :: x, y, z, two_a, ar2, r2, v, cutoff - qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; - assert (ctx != NULL); + info = QMCKL_SUCCESS - size_t sze = ctx->ao_basis.prim_num * 5 * ctx->electron.num; - memcpy(primitive_vgl, ctx->ao_basis.primitive_vgl, sze * sizeof(double)); + ! Don't compute exponentials when the result will be almost zero. + cutoff = -dlog(1.d-15) - return QMCKL_SUCCESS; -} + do inucl=1,nucl_num + ! C is zero-based, so shift bounds by one + do iprim = nucleus_prim_index(inucl)+1, nucleus_prim_index(inucl+1) + do ielec = 1, elec_num + x = elec_coord(ielec,1) - nucl_coord(inucl,1) + y = elec_coord(ielec,2) - nucl_coord(inucl,2) + z = elec_coord(ielec,3) - nucl_coord(inucl,3) + + r2 = x*x + y*y + z*z + ar2 = expo(iprim)*r2 + if (ar2 > cutoff) cycle + + v = dexp(-ar2) + two_a = -2.d0 * expo(iprim) * v + + primitive_vgl(iprim, ielec, 1) = v + primitive_vgl(iprim, ielec, 2) = two_a * x + primitive_vgl(iprim, ielec, 3) = two_a * y + primitive_vgl(iprim, ielec, 4) = two_a * z + primitive_vgl(iprim, ielec, 5) = two_a * (3.d0 - 2.d0*ar2) + + end do + end do + end do + +end function qmckl_compute_ao_basis_primitive_gaussian_vgl_f #+end_src - -*** Provide + + #+CALL: generate_c_interface(table=qmckl_ao_basis_primitive_gaussian_vgl_args,rettyp=get_value("CRetType"),fname="qmckl_compute_ao_basis_primitive_gaussian_vgl")) + + #+RESULTS: + #+begin_src f90 :tangle (eval f) :comments org :exports none + integer(c_int32_t) function qmckl_compute_ao_basis_primitive_gaussian_vgl & + (context, & + prim_num, & + elec_num, & + nucl_num, & + nucleus_prim_index, & + elec_coord, & + nucl_coord, & + expo, & + primitive_vgl) & + bind(C) result(info) + + use, intrinsic :: iso_c_binding + implicit none + + integer (c_int64_t) , intent(in) , value :: context + integer (c_int64_t) , intent(in) , value :: prim_num + integer (c_int64_t) , intent(in) , value :: elec_num + integer (c_int64_t) , intent(in) , value :: nucl_num + integer (c_int64_t) , intent(in) , value :: nucleus_prim_index + real (c_double ) , intent(in) , value :: elec_coord + real (c_double ) , intent(in) , value :: nucl_coord + real (c_double ) , intent(in) , value :: expo + real (c_double ) , intent(out) :: primitive_vgl + + integer(c_int32_t), external :: qmckl_compute_ao_basis_primitive_gaussian_vgl_f + info = qmckl_compute_ao_basis_primitive_gaussian_vgl_f & + (context, & + prim_num, & + elec_num, & + nucl_num, & + nucleus_prim_index, & + elec_coord, & + nucl_coord, & + expo, & + primitive_vgl) + + end function qmckl_compute_ao_basis_primitive_gaussian_vgl + #+end_src + +*** Provide :noexport: #+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none qmckl_exit_code qmckl_provide_ao_basis_primitive_vgl(qmckl_context context); @@ -2679,135 +3172,9 @@ qmckl_exit_code qmckl_provide_ao_basis_primitive_vgl(qmckl_context context) } #+end_src -*** Compute - :PROPERTIES: - :Name: qmckl_compute_ao_basis_primitive_gaussian_vgl - :CRetType: qmckl_exit_code - :FRetType: qmckl_exit_code - :END: +*** Test :noexport: - #+NAME: qmckl_ao_basis_primitive_gaussian_vgl_args - | qmckl_context | context | in | Global state | - | int64_t | prim_num | in | Number of primitives | - | int64_t | elec_num | in | Number of electrons | - | int64_t | nucl_num | in | Number of nuclei | - | int64_t | nucleus_prim_index[nucl_num] | in | Index of the 1st primitive of each nucleus | - | double | elec_coord[3][elec_num] | in | Electron coordinates | - | double | nucl_coord[3][elec_num] | in | Nuclear coordinates | - | double | expo[prim_num] | in | Exponents of the primitives | - | double | primitive_vgl[5][elec_num][prim_num] | out | Value, gradients and Laplacian of the primitives | - - #+begin_src f90 :comments org :tangle (eval f) :noweb yes -integer function qmckl_compute_ao_basis_primitive_gaussian_vgl_f(context, & - prim_num, elec_num, nucl_num, & - nucleus_prim_index, elec_coord, nucl_coord, expo, primitive_vgl) & - result(info) - use qmckl - implicit none - integer(qmckl_context), intent(in) :: context - integer*8 , intent(in) :: prim_num - integer*8 , intent(in) :: nucl_num - integer*8 , intent(in) :: elec_num - integer*8 , intent(in) :: nucleus_prim_index(nucl_num+1) - double precision , intent(in) :: elec_coord(elec_num,3) - double precision , intent(in) :: nucl_coord(nucl_num,3) - double precision , intent(in) :: expo(prim_num) - double precision , intent(out) :: primitive_vgl(prim_num,elec_num,5) - - integer*8 :: inucl, iprim, ielec - double precision :: x, y, z, two_a, ar2, r2, v, cutoff - - info = QMCKL_SUCCESS - - ! Don't compute exponentials when the result will be almost zero. - cutoff = -dlog(1.d-15) - - do inucl=1,nucl_num - ! C is zero-based, so shift bounds by one - do iprim = nucleus_prim_index(inucl)+1, nucleus_prim_index(inucl+1) - do ielec = 1, elec_num - x = elec_coord(ielec,1) - nucl_coord(inucl,1) - y = elec_coord(ielec,2) - nucl_coord(inucl,2) - z = elec_coord(ielec,3) - nucl_coord(inucl,3) - - r2 = x*x + y*y + z*z - ar2 = expo(iprim)*r2 - if (ar2 > cutoff) cycle - - v = dexp(-ar2) - two_a = -2.d0 * expo(iprim) * v - - primitive_vgl(iprim, ielec, 1) = v - primitive_vgl(iprim, ielec, 2) = two_a * x - primitive_vgl(iprim, ielec, 3) = two_a * y - primitive_vgl(iprim, ielec, 4) = two_a * z - primitive_vgl(iprim, ielec, 5) = two_a * (3.d0 - 2.d0*ar2) - - end do - end do - end do - -end function qmckl_compute_ao_basis_primitive_gaussian_vgl_f - #+end_src - - #+begin_src c :tangle (eval h_private_func) :comments org :exports none -qmckl_exit_code qmckl_compute_ao_basis_primitive_gaussian_vgl( - const qmckl_context context, - const int64_t prim_num, - const int64_t elec_num, - const int64_t nucl_num, - const int64_t* nucleus_prim_index, - const double* elec_coord, - const double* nucl_coord, - const double* expo, - double* const primitive_vgl); - #+end_src - - #+CALL: generate_c_interface(table=qmckl_ao_basis_primitive_gaussian_vgl_args,rettyp=get_value("CRetType"),fname="qmckl_compute_ao_basis_primitive_gaussian_vgl")) - - #+RESULTS: - #+begin_src f90 :tangle (eval f) :comments org :exports none - integer(c_int32_t) function qmckl_compute_ao_basis_primitive_gaussian_vgl & - (context, & - prim_num, & - elec_num, & - nucl_num, & - nucleus_prim_index, & - elec_coord, & - nucl_coord, & - expo, & - primitive_vgl) & - bind(C) result(info) - - use, intrinsic :: iso_c_binding - implicit none - - integer (c_int64_t) , intent(in) , value :: context - integer (c_int64_t) , intent(in) , value :: prim_num - integer (c_int64_t) , intent(in) , value :: elec_num - integer (c_int64_t) , intent(in) , value :: nucl_num - integer (c_int64_t) , intent(in) :: nucleus_prim_index(nucl_num) - real (c_double ) , intent(in) :: elec_coord(elec_num,3) - real (c_double ) , intent(in) :: nucl_coord(elec_num,3) - real (c_double ) , intent(in) :: expo(prim_num) - real (c_double ) , intent(out) :: primitive_vgl(prim_num,elec_num,5) - - integer(c_int32_t), external :: qmckl_compute_ao_basis_primitive_gaussian_vgl_f - info = qmckl_compute_ao_basis_primitive_gaussian_vgl_f & - (context, & - prim_num, & - elec_num, & - nucl_num, & - nucleus_prim_index, & - elec_coord, & - nucl_coord, & - expo, & - primitive_vgl) - - end function qmckl_compute_ao_basis_primitive_gaussian_vgl - #+end_src - - #+begin_src python :results output :exports none + #+begin_src python :results output :exports none :exports none import numpy as np def f(a,x,y): @@ -2851,8 +3218,6 @@ print ( "[7][4][26] : %e"% lf(a,x,y)) : [7][3][26] : 3.495056e-03 : [7][4][26] : 2.040013e-02 -*** Test - #+begin_src c :tangle (eval c_test) :exports none { #define walk_num chbrclf_walk_num @@ -2892,7 +3257,7 @@ assert( fabs(prim_vgl[4][26][7] - ( 2.0392163767356572E-002)) < 1.e-14 ); #+end_src -*** Ideas for improvement +*** Ideas for improvement :noexport: #+begin_src c // j : electrons @@ -2924,52 +3289,199 @@ for (j=0 ; j cutoff) then + cycle + end if + + v = coef_normalized(iprim) * dexp(-ar2) + two_a = -2.d0 * expo(iprim) * v + + shell_vgl(ishell, ielec, 1) = & + shell_vgl(ishell, ielec, 1) + v + + shell_vgl(ishell, ielec, 2) = & + shell_vgl(ishell, ielec, 2) + two_a * x + + shell_vgl(ishell, ielec, 3) = & + shell_vgl(ishell, ielec, 3) + two_a * y + + shell_vgl(ishell, ielec, 4) = & + shell_vgl(ishell, ielec, 4) + two_a * z + + shell_vgl(ishell, ielec, 5) = & + shell_vgl(ishell, ielec, 5) + two_a * (3.d0 - 2.d0*ar2) + + end do + + end do + end do + + end do + +end function qmckl_compute_ao_basis_shell_gaussian_vgl_f #+end_src - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none -qmckl_exit_code qmckl_get_ao_basis_shell_vgl(qmckl_context context, double* const shell_vgl) { + #+CALL: generate_c_interface(table=qmckl_ao_basis_shell_gaussian_vgl_args,rettyp=get_value("CRetType"),fname="qmckl_compute_ao_basis_shell_gaussian_vgl")) - if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { - return qmckl_failwith( context, - QMCKL_INVALID_CONTEXT, - "qmckl_get_ao_basis_shell_vgl", - NULL); - } + #+RESULTS: + #+begin_src f90 :tangle (eval f) :comments org :exports none + integer(c_int32_t) function qmckl_compute_ao_basis_shell_gaussian_vgl & + (context, & + prim_num, & + shell_num, & + elec_num, & + nucl_num, & + nucleus_shell_num, & + nucleus_index, & + shell_prim_index, & + shell_prim_num, & + elec_coord, & + nucl_coord, & + expo, & + coef_normalized, & + shell_vgl) & + bind(C) result(info) - qmckl_exit_code rc; + use, intrinsic :: iso_c_binding + implicit none - rc = qmckl_provide_ao_basis_shell_vgl(context); - if (rc != QMCKL_SUCCESS) return rc; + integer (c_int64_t) , intent(in) , value :: context + integer (c_int64_t) , intent(in) , value :: prim_num + integer (c_int64_t) , intent(in) , value :: shell_num + integer (c_int64_t) , intent(in) , value :: elec_num + integer (c_int64_t) , intent(in) , value :: nucl_num + integer (c_int64_t) , intent(in) , value :: nucleus_shell_num + integer (c_int64_t) , intent(in) , value :: nucleus_index + integer (c_int64_t) , intent(in) , value :: shell_prim_index + integer (c_int64_t) , intent(in) , value :: shell_prim_num + real (c_double ) , intent(in) , value :: elec_coord + real (c_double ) , intent(in) , value :: nucl_coord + real (c_double ) , intent(in) , value :: expo + real (c_double ) , intent(in) , value :: coef_normalized + real (c_double ) , intent(out) :: shell_vgl - qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; - assert (ctx != NULL); + integer(c_int32_t), external :: qmckl_compute_ao_basis_shell_gaussian_vgl_f + info = qmckl_compute_ao_basis_shell_gaussian_vgl_f & + (context, & + prim_num, & + shell_num, & + elec_num, & + nucl_num, & + nucleus_shell_num, & + nucleus_index, & + shell_prim_index, & + shell_prim_num, & + elec_coord, & + nucl_coord, & + expo, & + coef_normalized, & + shell_vgl) - size_t sze = ctx->ao_basis.shell_num * 5 * ctx->electron.num; - memcpy(shell_vgl, ctx->ao_basis.shell_vgl, sze * sizeof(double)); - - return QMCKL_SUCCESS; -} + end function qmckl_compute_ao_basis_shell_gaussian_vgl #+end_src - #+begin_src f90 :tangle (eval fh_func) :comments org :exports none - interface - integer(c_int32_t) function qmckl_get_ao_basis_shell_vgl (context, shell_vgl) & - bind(C) - use, intrinsic :: iso_c_binding - import - implicit none - - integer (c_int64_t) , intent(in) , value :: context - double precision, intent(out) :: shell_vgl(*) - end function - end interface - #+end_src - -*** Provide +*** Provide :noexport: #+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none qmckl_exit_code qmckl_provide_ao_basis_shell_vgl(qmckl_context context); @@ -3055,194 +3567,7 @@ qmckl_exit_code qmckl_provide_ao_basis_shell_vgl(qmckl_context context) } #+end_src -*** Compute - :PROPERTIES: - :Name: qmckl_compute_ao_basis_shell_gaussian_vgl - :CRetType: qmckl_exit_code - :FRetType: qmckl_exit_code - :END: - - #+NAME: qmckl_ao_basis_shell_gaussian_vgl_args - | ~qmckl_context~ | ~context~ | in | Global state | - | ~int64_t~ | ~prim_num~ | in | Number of primitives | - | ~int64_t~ | ~shell_num~ | in | Number of shells | - | ~int64_t~ | ~elec_num~ | in | Number of electrons | - | ~int64_t~ | ~nucl_num~ | in | Number of nuclei | - | ~int64_t~ | ~nucleus_shell_num[nucl_num]~ | in | Number of shells for each nucleus | - | ~int64_t~ | ~nucleus_index[nucl_num]~ | in | Index of the 1st shell of each nucleus | - | ~int64_t~ | ~shell_prim_index[shell_num]~ | in | Index of the 1st primitive of each shell | - | ~int64_t~ | ~shell_prim_num[shell_num]~ | in | Number of primitives per shell | - | ~double~ | ~elec_coord[3][elec_num]~ | in | Electron coordinates | - | ~double~ | ~nucl_coord[3][elec_num]~ | in | Nuclear coordinates | - | ~double~ | ~expo[prim_num]~ | in | Exponents of the primitives | - | ~double~ | ~coef_normalized[prim_num]~ | in | Coefficients of the primitives | - | ~double~ | ~shell_vgl[5][elec_num][shell_num]~ | out | Value, gradients and Laplacian of the shells | - - #+begin_src f90 :comments org :tangle (eval f) :noweb yes -integer function qmckl_compute_ao_basis_shell_gaussian_vgl_f(context, & - prim_num, shell_num, elec_num, nucl_num, & - nucleus_shell_num, nucleus_index, shell_prim_index, shell_prim_num, & - elec_coord, nucl_coord, expo, coef_normalized, shell_vgl) & - result(info) - use qmckl - implicit none - integer(qmckl_context), intent(in) :: context - integer*8 , intent(in) :: prim_num - integer*8 , intent(in) :: shell_num - integer*8 , intent(in) :: nucl_num - integer*8 , intent(in) :: elec_num - integer*8 , intent(in) :: nucleus_shell_num(nucl_num) - integer*8 , intent(in) :: nucleus_index(nucl_num) - integer*8 , intent(in) :: shell_prim_index(shell_num) - integer*8 , intent(in) :: shell_prim_num(shell_num) - double precision , intent(in) :: elec_coord(elec_num,3) - double precision , intent(in) :: nucl_coord(nucl_num,3) - double precision , intent(in) :: expo(prim_num) - double precision , intent(in) :: coef_normalized(prim_num) - double precision , intent(out) :: shell_vgl(shell_num,elec_num,5) - - integer*8 :: inucl, iprim, ielec, ishell - double precision :: x, y, z, two_a, ar2, r2, v, cutoff - - info = QMCKL_SUCCESS - - ! Don't compute exponentials when the result will be almost zero. - ! TODO : Use numerical precision here - cutoff = -dlog(1.d-15) - - do inucl=1,nucl_num - - do ielec = 1, elec_num - - x = elec_coord(ielec,1) - nucl_coord(inucl,1) - y = elec_coord(ielec,2) - nucl_coord(inucl,2) - z = elec_coord(ielec,3) - nucl_coord(inucl,3) - - r2 = x*x + y*y + z*z - - do ishell=nucleus_index(inucl)+1, nucleus_index(inucl)+nucleus_shell_num(inucl) - ! C is zero-based, so shift bounds by one - - shell_vgl(ishell, ielec, 1) = 0.d0 - shell_vgl(ishell, ielec, 2) = 0.d0 - shell_vgl(ishell, ielec, 3) = 0.d0 - shell_vgl(ishell, ielec, 4) = 0.d0 - shell_vgl(ishell, ielec, 5) = 0.d0 - - do iprim = shell_prim_index(ishell)+1, shell_prim_index(ishell)+shell_prim_num(ishell) - - ar2 = expo(iprim)*r2 - if (ar2 > cutoff) then - cycle - end if - - v = coef_normalized(iprim) * dexp(-ar2) - two_a = -2.d0 * expo(iprim) * v - - shell_vgl(ishell, ielec, 1) = & - shell_vgl(ishell, ielec, 1) + v - - shell_vgl(ishell, ielec, 2) = & - shell_vgl(ishell, ielec, 2) + two_a * x - - shell_vgl(ishell, ielec, 3) = & - shell_vgl(ishell, ielec, 3) + two_a * y - - shell_vgl(ishell, ielec, 4) = & - shell_vgl(ishell, ielec, 4) + two_a * z - - shell_vgl(ishell, ielec, 5) = & - shell_vgl(ishell, ielec, 5) + two_a * (3.d0 - 2.d0*ar2) - - end do - - end do - end do - - end do - -end function qmckl_compute_ao_basis_shell_gaussian_vgl_f - #+end_src - -# #+CALL: generate_c_header(table=qmckl_ao_basis_shell_gaussian_vgl_args,rettyp=get_value("CRetType"),fname="qmckl_compute_ao_basis_shell_gaussian_vgl")) - - #+RESULTS: - #+begin_src c :tangle (eval h_private_func) :comments org - qmckl_exit_code qmckl_compute_ao_basis_shell_gaussian_vgl ( - const qmckl_context context, - const int64_t prim_num, - const int64_t shell_num, - const int64_t elec_num, - const int64_t nucl_num, - const int64_t* nucleus_shell_num, - const int64_t* nucleus_index, - const int64_t* shell_prim_index, - const int64_t* shell_prim_num, - const double* elec_coord, - const double* nucl_coord, - const double* expo, - const double* coef_normalized, - double* const shell_vgl ); - #+end_src - - #+CALL: generate_c_interface(table=qmckl_ao_basis_shell_gaussian_vgl_args,rettyp=get_value("CRetType"),fname="qmckl_compute_ao_basis_shell_gaussian_vgl")) - - #+RESULTS: - #+begin_src f90 :tangle (eval f) :comments org :exports none - integer(c_int32_t) function qmckl_compute_ao_basis_shell_gaussian_vgl & - (context, & - prim_num, & - shell_num, & - elec_num, & - nucl_num, & - nucleus_shell_num, & - nucleus_index, & - shell_prim_index, & - shell_prim_num, & - elec_coord, & - nucl_coord, & - expo, & - coef_normalized, & - shell_vgl) & - bind(C) result(info) - - use, intrinsic :: iso_c_binding - implicit none - - integer (c_int64_t) , intent(in) , value :: context - integer (c_int64_t) , intent(in) , value :: prim_num - integer (c_int64_t) , intent(in) , value :: shell_num - integer (c_int64_t) , intent(in) , value :: elec_num - integer (c_int64_t) , intent(in) , value :: nucl_num - integer (c_int64_t) , intent(in) :: nucleus_shell_num(nucl_num) - integer (c_int64_t) , intent(in) :: nucleus_index(nucl_num) - integer (c_int64_t) , intent(in) :: shell_prim_index(shell_num) - integer (c_int64_t) , intent(in) :: shell_prim_num(shell_num) - real (c_double ) , intent(in) :: elec_coord(elec_num,3) - real (c_double ) , intent(in) :: nucl_coord(elec_num,3) - real (c_double ) , intent(in) :: expo(prim_num) - real (c_double ) , intent(in) :: coef_normalized(prim_num) - real (c_double ) , intent(out) :: shell_vgl(shell_num,elec_num,5) - - integer(c_int32_t), external :: qmckl_compute_ao_basis_shell_gaussian_vgl_f - info = qmckl_compute_ao_basis_shell_gaussian_vgl_f & - (context, & - prim_num, & - shell_num, & - elec_num, & - nucl_num, & - nucleus_shell_num, & - nucleus_index, & - shell_prim_index, & - shell_prim_num, & - elec_coord, & - nucl_coord, & - expo, & - coef_normalized, & - shell_vgl) - - end function qmckl_compute_ao_basis_shell_gaussian_vgl - #+end_src +*** Test :noexport: #+begin_src python :results output :exports none import numpy as np @@ -3300,8 +3625,6 @@ print ( "[1][4][26] : %25.15e"% lf(a,x,y)) : [1][3][26] : 2.809546963133958e-02 : [1][4][26] : 1.903338597841753e-02 -*** Test - #+begin_src c :tangle (eval c_test) :exports none { #define walk_num chbrclf_walk_num @@ -3344,7 +3667,7 @@ assert( fabs(shell_vgl[4][26][1] - ( 1.896046117183968e-02)) < 1.e-14 ); } #+end_src - + * Polynomial part Going from the atomic basis set to AOs implies a systematic @@ -3376,40 +3699,38 @@ assert( fabs(shell_vgl[4][26][1] - ( 1.896046117183968e-02)) < 1.e-14 ); \[ P_{ik} = X_i^k \] #+NAME: qmckl_ao_power_args - | qmckl_context | context | in | Global state | - | int64_t | n | in | Number of values | - | double | X[n] | in | Array containing the input values | - | int32_t | LMAX[n] | in | Array containing the maximum power for each value | - | double | P[n][ldp] | out | Array containing all the powers of ~X~ | - | int64_t | ldp | in | Leading dimension of array ~P~ | + | Variable | Type | In/Out | Description | + |-----------+-----------------+--------+---------------------------------------------------| + | ~context~ | ~qmckl_context~ | in | Global state | + | ~n~ | int64_t | in | Number of values | + | ~X~ | double[n] | in | Array containing the input values | + | ~LMAX~ | int32_t[n] | in | Array containing the maximum power for each value | + | ~P~ | double[n][ldp] | out | Array containing all the powers of ~X~ | + | ~ldp~ | int64_t | in | Leading dimension of array ~P~ | -*** Requirements + Requirements: - - ~context~ is not ~QMCKL_NULL_CONTEXT~ - - ~n~ > 0 - - ~X~ is allocated with at least $n \times 8$ bytes - - ~LMAX~ is allocated with at least $n \times 4$ bytes - - ~P~ is allocated with at least $n \times \max_i \text{LMAX}_i \times 8$ bytes - - ~LDP~ >= $\max_i$ ~LMAX[i]~ + - ~context~ is not ~QMCKL_NULL_CONTEXT~ + - ~n~ > 0 + - ~X~ is allocated with at least $n \times 8$ bytes + - ~LMAX~ is allocated with at least $n \times 4$ bytes + - ~P~ is allocated with at least $n \times \max_i \text{LMAX}_i \times 8$ bytes + - ~LDP~ >= $\max_i$ ~LMAX[i]~ -*** C Header + #+CALL: generate_c_header(table=qmckl_ao_power_args,rettyp=get_value("CRetType"),fname="qmckl_ao_power") - #+CALL: generate_c_header(table=qmckl_ao_power_args,rettyp=get_value("CRetType"),fname="qmckl_ao_power") + #+RESULTS: + #+begin_src c :tangle (eval h_func) :comments org +qmckl_exit_code qmckl_ao_power ( + const qmckl_context context, + const int64_t n, + const double X, + const int32_t LMAX, + double* const P, + const int64_t ldp ); + #+end_src - #+RESULTS: - #+begin_src c :tangle (eval h_func) :comments org - qmckl_exit_code qmckl_ao_power ( - const qmckl_context context, - const int64_t n, - const double* X, - const int32_t* LMAX, - double* const P, - const int64_t ldp ); - #+end_src - -*** Source - - #+begin_src f90 :tangle (eval f) + #+begin_src f90 :tangle (eval f) integer function qmckl_ao_power_f(context, n, X, LMAX, P, ldp) result(info) use qmckl implicit none @@ -3453,33 +3774,35 @@ integer function qmckl_ao_power_f(context, n, X, LMAX, P, ldp) result(info) end do end function qmckl_ao_power_f - #+end_src + #+end_src -*** C interface - #+CALL: generate_c_interface(table=qmckl_ao_power_args,rettyp=get_value("CRetType"),fname="qmckl_ao_power") + +*** C interface :noexport: - #+RESULTS: - #+begin_src f90 :tangle (eval f) :comments org :exports none - integer(c_int32_t) function qmckl_ao_power & - (context, n, X, LMAX, P, ldp) & - bind(C) result(info) + #+CALL: generate_c_interface(table=qmckl_ao_power_args,rettyp=get_value("CRetType"),fname="qmckl_ao_power") - use, intrinsic :: iso_c_binding - implicit none + #+RESULTS: + #+begin_src f90 :tangle (eval f) :comments org :exports none + integer(c_int32_t) function qmckl_ao_power & + (context, n, X, LMAX, P, ldp) & + bind(C) result(info) - integer (c_int64_t) , intent(in) , value :: context - integer (c_int64_t) , intent(in) , value :: n - real (c_double ) , intent(in) :: X(n) - integer (c_int32_t) , intent(in) :: LMAX(n) - real (c_double ) , intent(out) :: P(ldp,n) - integer (c_int64_t) , intent(in) , value :: ldp + use, intrinsic :: iso_c_binding + implicit none - integer(c_int32_t), external :: qmckl_ao_power_f - info = qmckl_ao_power_f & - (context, n, X, LMAX, P, ldp) + integer (c_int64_t) , intent(in) , value :: context + integer (c_int64_t) , intent(in) , value :: n + real (c_double ) , intent(in) , value :: X + integer (c_int32_t) , intent(in) , value :: LMAX + real (c_double ) , intent(out) :: P + integer (c_int64_t) , intent(in) , value :: ldp - end function qmckl_ao_power - #+end_src + integer(c_int32_t), external :: qmckl_ao_power_f + info = qmckl_ao_power_f & + (context, n, X, LMAX, P, ldp) + + end function qmckl_ao_power + #+end_src *** Fortran interface @@ -3497,16 +3820,16 @@ end function qmckl_ao_power_f integer (c_int64_t) , intent(in) , value :: context integer (c_int64_t) , intent(in) , value :: n - real (c_double ) , intent(in) :: X(n) - integer (c_int32_t) , intent(in) :: LMAX(n) - real (c_double ) , intent(out) :: P(ldp,n) + real (c_double ) , intent(in) , value :: X + integer (c_int32_t) , intent(in) , value :: LMAX + real (c_double ) , intent(out) :: P integer (c_int64_t) , intent(in) , value :: ldp end function qmckl_ao_power end interface #+end_src -*** Test +*** Test :noexport: #+begin_src f90 :tangle (eval f_test) integer(c_int32_t) function test_qmckl_ao_power(context) bind(C) @@ -3554,8 +3877,8 @@ end function test_qmckl_ao_power #+end_src #+begin_src c :tangle (eval c_test) :exports none - int test_qmckl_ao_power(qmckl_context context); - assert(0 == test_qmckl_ao_power(context)); +int test_qmckl_ao_power(qmckl_context context); +assert(0 == test_qmckl_ao_power(context)); #+end_src ** General functions for Value, Gradient and Laplacian of a polynomial diff --git a/tools/lib.org b/tools/lib.org index 970b323..63db1fa 100644 --- a/tools/lib.org +++ b/tools/lib.org @@ -19,17 +19,19 @@ ** Table of function arguments #+NAME: test - | ~qmckl_context~ | ~context~ | in | Global state | - | ~char~ | ~transa~ | in | Array ~A~ is ~'N'~: Normal, ~'T'~: Transposed | - | ~char~ | ~transb~ | in | Array ~B~ is ~'N'~: Normal, ~'T'~: Transposed | - | ~int64_t~ | ~m~ | in | Number of points in the first set | - | ~int64_t~ | ~n~ | in | Number of points in the second set | - | ~double~ | ~A[][lda]~ | in | Array containing the $m \times 3$ matrix $A$ | - | ~int64_t~ | ~lda~ | in | Leading dimension of array ~A~ | - | ~double~ | ~B[][ldb]~ | in | Array containing the $n \times 3$ matrix $B$ | - | ~int64_t~ | ~ldb~ | in | Leading dimension of array ~B~ | - | ~double~ | ~C[n][ldc]~ | out | Array containing the $m \times n$ matrix $C$ | - | ~int64_t~ | ~ldc~ | in | Leading dimension of array ~C~ | + | Variable | Type | In/Out | Description | + |-----------+------------------+--------+-----------------------------------------------| + | ~context~ | ~qmckl_context~ | in | Global state | + | ~transa~ | ~char~ | in | Array ~A~ is ~'N'~: Normal, ~'T'~: Transposed | + | ~transb~ | ~char~ | in | Array ~B~ is ~'N'~: Normal, ~'T'~: Transposed | + | ~m~ | ~int64_t~ | in | Number of points in the first set | + | ~n~ | ~int64_t~ | in | Number of points in the second set | + | ~A~ | ~double[][lda]~ | in | Array containing the $m \times 3$ matrix $A$ | + | ~lda~ | ~int64_t~ | in | Leading dimension of array ~A~ | + | ~B~ | ~double[][ldb]~ | in | Array containing the $n \times 3$ matrix $B$ | + | ~ldb~ | ~int64_t~ | in | Leading dimension of array ~B~ | + | ~C~ | ~double[n][ldc]~ | out | Array containing the $m \times n$ matrix $C$ | + | ~ldc~ | ~int64_t~ | in | Leading dimension of array ~C~ | *** Fortran-C type conversions @@ -74,9 +76,9 @@ def parse_table(table): result = [] for line in [ [x.replace('~','') for x in y] for y in table]: - d = { "c_type" : line[0], + d = { "c_type" : line[1].split('[')[0], "inout" : line[2].lower(), - "name" : line[1], + "name" : line[0], "comment" : line[3] } # Handle inout @@ -88,7 +90,7 @@ def parse_table(table): d["inout"] == "inout" # Find dimensions (replace [] by [*] to get * in Fortran dimensions) - dims = d["name"].replace("[]","[*]").split('[') + dims = d["c_type"].replace("[]","[*]").split('[') d["rank"] = len(dims) - 1 if d["rank"] == 0: d["dims"] = [] @@ -133,6 +135,22 @@ return template #+END_SRC + #+RESULTS: generate_c_header + #+begin_src c :tangle (eval h_func) :comments org + [] [] ( + const context qmckl_context, + const transa char, + const transb char, + const m int64_t, + const n int64_t, + const A* double, + const lda int64_t, + const B* double, + const ldb int64_t, + C* const double, + const ldc int64_t ); + #+end_src + *** Generates a C interface to the Fortran function #+NAME: generate_c_interface