From 0928f9ea14f4d43b3656583cd3aaf4fcfffbaca1 Mon Sep 17 00:00:00 2001 From: v1j4y Date: Fri, 15 Oct 2021 12:44:37 +0200 Subject: [PATCH] Moved en_pot to electron. #41 --- org/qmckl_electron.org | 227 +++++++++++++++++++++++++++++++++++-- org/qmckl_local_energy.org | 2 +- org/qmckl_nucleus.org | 203 --------------------------------- 3 files changed, 216 insertions(+), 216 deletions(-) diff --git a/org/qmckl_electron.org b/org/qmckl_electron.org index 7408b60..1435fe4 100644 --- a/org/qmckl_electron.org +++ b/org/qmckl_electron.org @@ -68,18 +68,18 @@ int main() { The following data stored in the context: - |-------------------------------------+--------------------------------------+----------------------------------------------------------------------| - | ~uninitialized~ | ~int32_t~ | Keeps bit set for uninitialized data | - | ~num~ | ~int64_t~ | Total number of electrons | - | ~up_num~ | ~int64_t~ | Number of up-spin electrons | - | ~down_num~ | ~int64_t~ | Number of down-spin electrons | - | ~walk_num~ | ~int64_t~ | Number of walkers | - | ~rescale_factor_kappa_ee~ | ~double~ | The distance scaling factor | - | ~rescale_factor_kappa_en~ | ~double~ | The distance scaling factor | - | ~provided~ | ~bool~ | If true, ~electron~ is valid | - | ~coord_new~ | ~double[walk_num][3][num]~ | New set of electron coordinates | - | ~coord_old~ | ~double[walk_num][3][num]~ | Old set of electron coordinates | - | ~coord_new_date~ | ~uint64_t~ | Last modification date of the coordinates | + |---------------------------+----------------------------+-------------------------------------------| + | ~uninitialized~ | ~int32_t~ | Keeps bit set for uninitialized data | + | ~num~ | ~int64_t~ | Total number of electrons | + | ~up_num~ | ~int64_t~ | Number of up-spin electrons | + | ~down_num~ | ~int64_t~ | Number of down-spin electrons | + | ~walk_num~ | ~int64_t~ | Number of walkers | + | ~rescale_factor_kappa_ee~ | ~double~ | The distance scaling factor | + | ~rescale_factor_kappa_en~ | ~double~ | The distance scaling factor | + | ~provided~ | ~bool~ | If true, ~electron~ is valid | + | ~coord_new~ | ~double[walk_num][3][num]~ | New set of electron coordinates | + | ~coord_old~ | ~double[walk_num][3][num]~ | Old set of electron coordinates | + | ~coord_new_date~ | ~uint64_t~ | Last modification date of the coordinates | Computed data: @@ -94,6 +94,8 @@ int main() { | ~ee_distance_rescaled_deriv_e_date~ | ~uint64_t~ | Last modification date of the electron-electron distance derivatives | | ~ee_pot~ | ~double[walk_num]~ | Electron-electron rescaled distances derivatives | | ~ee_pot_date~ | ~uint64_t~ | Last modification date of the electron-electron distance derivatives | + | ~en_pot~ | double[walk_num] | Electron-nucleus potential energy | + | ~en_pot_date~ | int64_t | Date when the electron-nucleus potential energy was computed | | ~en_distance_rescaled~ | ~double[walk_num][nucl_num][num]~ | Electron-nucleus distances | | ~en_distance_rescaled_date~ | ~uint64_t~ | Last modification date of the electron-electron distances | | ~en_distance_rescaled_deriv_e~ | ~double[walk_num][4][nucl_num][num]~ | Electron-electron rescaled distances derivatives | @@ -113,6 +115,7 @@ typedef struct qmckl_electron_struct { int64_t ee_distance_date; int64_t en_distance_date; int64_t ee_pot_date; + int64_t en_pot_date; int64_t ee_distance_rescaled_date; int64_t ee_distance_rescaled_deriv_e_date; int64_t en_distance_rescaled_date; @@ -122,6 +125,7 @@ typedef struct qmckl_electron_struct { double* ee_distance; double* en_distance; double* ee_pot; + double* en_pot; double* ee_distance_rescaled; double* ee_distance_rescaled_deriv_e; double* en_distance_rescaled; @@ -2604,6 +2608,205 @@ assert (rc == QMCKL_SUCCESS); #+end_src +** Electron-nucleus potential + ~en_potential~ stores the ~en~ potential energy + + \[ + \mathcal{V}_{en} = -\sum_{i=1}^{N_e}\sum_{A=1}^{N_n}\frac{Z_A}{r_{iA}} + \] + + where \(\mathcal{V}_{en}\) is the ~en~ potential, \[r_{iA}\] the ~en~ + distance and \[Z_A\] is the nuclear charge. + +*** Get + + #+begin_src c :comments org :tangle (eval h_func) :noweb yes +qmckl_exit_code qmckl_get_electron_en_potential(qmckl_context context, double* const en_pot); + #+end_src + + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none +qmckl_exit_code qmckl_get_electron_en_potential(qmckl_context context, double* const en_pot) +{ + if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { + return QMCKL_NULL_CONTEXT; + } + + qmckl_exit_code rc; + + rc = qmckl_provide_en_potential(context); + if (rc != QMCKL_SUCCESS) return rc; + + qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; + assert (ctx != NULL); + + size_t sze = ctx->electron.walk_num * sizeof(double); + memcpy(en_pot, ctx->electron.en_pot, sze); + + return QMCKL_SUCCESS; +} + #+end_src + +*** Provide :noexport: + + #+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none +qmckl_exit_code qmckl_provide_en_potential(qmckl_context context); + #+end_src + + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none +qmckl_exit_code qmckl_provide_en_potential(qmckl_context context) +{ + + if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { + return QMCKL_NULL_CONTEXT; + } + + qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; + assert (ctx != NULL); + + if (!ctx->electron.provided) return QMCKL_NOT_PROVIDED; + if (!ctx->nucleus.provided) return QMCKL_NOT_PROVIDED; + + /* Compute if necessary */ + if (ctx->electron.coord_new_date > ctx->electron.en_pot_date) { + + /* Allocate array */ + if (ctx->electron.en_pot == NULL) { + + qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero; + mem_info.size = ctx->electron.walk_num * sizeof(double); + double* en_pot = (double*) qmckl_malloc(context, mem_info); + + if (en_pot == NULL) { + return qmckl_failwith( context, + QMCKL_ALLOCATION_FAILED, + "qmckl_en_potential", + NULL); + } + ctx->electron.en_pot = en_pot; + } + + qmckl_exit_code rc = + qmckl_compute_en_potential(context, + ctx->electron.num, + ctx->nucleus.num, + ctx->electron.walk_num, + ctx->nucleus.charge, + ctx->electron.en_distance, + ctx->electron.en_pot); + if (rc != QMCKL_SUCCESS) { + return rc; + } + + ctx->electron.en_pot_date = ctx->date; + } + + return QMCKL_SUCCESS; +} + #+end_src + +*** Compute + :PROPERTIES: + :Name: qmckl_compute_en_potential + :CRetType: qmckl_exit_code + :FRetType: qmckl_exit_code + :END: + + #+NAME: qmckl_en_potential_args + | qmckl_context | context | in | Global state | + | int64_t | elec_num | in | Number of electrons | + | int64_t | nucl_num | in | Number of nucleii | + | int64_t | walk_num | in | Number of walkers | + | double | charge[nucl_num] | in | charge of nucleus | + | double | en_distance[walk_num][nucl_num][elec_num] | in | Electron-electron rescaled distances | + | double | en_pot[walk_num] | out | Electron-electron potential | + + #+begin_src f90 :comments org :tangle (eval f) :noweb yes +integer function qmckl_compute_en_potential_f(context, elec_num, nucl_num, walk_num, & + charge, en_distance, en_pot) & + result(info) + use qmckl + implicit none + integer(qmckl_context), intent(in) :: context + integer*8 , intent(in) :: elec_num + integer*8 , intent(in) :: nucl_num + integer*8 , intent(in) :: walk_num + double precision , intent(in) :: charge(nucl_num) + double precision , intent(in) :: en_distance(elec_num,nucl_num,walk_num) + double precision , intent(out) :: en_pot(walk_num) + + integer*8 :: nw, i, j + + info = QMCKL_SUCCESS + + if (context == QMCKL_NULL_CONTEXT) then + info = QMCKL_INVALID_CONTEXT + return + endif + + if (elec_num <= 0) then + info = QMCKL_INVALID_ARG_2 + return + endif + + if (walk_num <= 0) then + info = QMCKL_INVALID_ARG_3 + return + endif + + en_pot = 0.0d0 + do nw=1,walk_num + do j=1,nucl_num + do i=1,elec_num + en_pot(nw) = en_pot(nw) - charge(j)/(en_distance(i,j,nw)) + end do + end do + end do + +end function qmckl_compute_en_potential_f + #+end_src + + #+CALL: generate_c_header(table=qmckl_en_potential_args,rettyp=get_value("CRetType"),fname=get_value("Name")) + + #+RESULTS: + #+begin_src c :tangle (eval h_func) :comments org + qmckl_exit_code qmckl_compute_en_potential ( + const qmckl_context context, + const int64_t elec_num, + const int64_t nucl_num, + const int64_t walk_num, + const double* charge, + const double* en_distance, + double* const en_pot ); + #+end_src + + #+CALL: generate_c_interface(table=qmckl_en_potential_args,rettyp=get_value("CRetType"),fname=get_value("Name")) + + #+RESULTS: + #+begin_src f90 :tangle (eval f) :comments org :exports none + integer(c_int32_t) function qmckl_compute_en_potential & + (context, elec_num, nucl_num, walk_num, charge, en_distance, en_pot) & + 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 :: elec_num + integer (c_int64_t) , intent(in) , value :: nucl_num + integer (c_int64_t) , intent(in) , value :: walk_num + real (c_double ) , intent(in) :: charge(nucl_num) + real (c_double ) , intent(in) :: en_distance(elec_num,nucl_num,walk_num) + real (c_double ) , intent(out) :: en_pot(walk_num) + + integer(c_int32_t), external :: qmckl_compute_en_potential_f + info = qmckl_compute_en_potential_f & + (context, elec_num, nucl_num, walk_num, charge, en_distance, en_pot) + + end function qmckl_compute_en_potential + #+end_src + +*** Test + * End of files :noexport: #+begin_src c :tangle (eval h_private_type) diff --git a/org/qmckl_local_energy.org b/org/qmckl_local_energy.org index 339106d..8193ba7 100644 --- a/org/qmckl_local_energy.org +++ b/org/qmckl_local_energy.org @@ -879,7 +879,7 @@ qmckl_exit_code qmckl_provide_potential_energy(qmckl_context context) { ctx->electron.num, ctx->nucleus.num, ctx->electron.ee_pot, - ctx->nucleus.en_pot, + ctx->electron.en_pot, ctx->nucleus.repulsion, ctx->local_energy.e_pot); } else { diff --git a/org/qmckl_nucleus.org b/org/qmckl_nucleus.org index f2e2116..1406087 100644 --- a/org/qmckl_nucleus.org +++ b/org/qmckl_nucleus.org @@ -85,8 +85,6 @@ int main() { | ~nn_distance_rescaled_date~ | int64_t | Date when Nucleus-nucleus rescaled distances were computed | | ~repulsion~ | double | Nuclear repulsion energy | | ~repulsion_date~ | int64_t | Date when the nuclear repulsion energy was computed | - | ~en_pot~ | double[walk_num] | Electron-nucleus potential energy | - | ~en_pot_date~ | int64_t | Date when the electron-nucleus potential energy was computed | ** Data structure @@ -105,8 +103,6 @@ typedef struct qmckl_nucleus_struct { double rescale_factor_kappa; int32_t uninitialized; bool provided; - int64_t en_pot_date; - double* en_pot; } qmckl_nucleus_struct; #+end_src @@ -1145,205 +1141,6 @@ assert(rep - 318.2309879436158 < 1.e-10); #+end_src -** Electron-nucleus potential - ~en_potential~ stores the ~en~ potential energy - - \[ - \mathcal{V}_{en} = -\sum_{i=1}^{N_e}\sum_{A=1}^{N_n}\frac{Z_A}{r_{iA}} - \] - - where \(\mathcal{V}_{en}\) is the ~en~ potential, \[r_{iA}\] the ~en~ - distance and \[Z_A\] is the nuclear charge. - -*** Get - - #+begin_src c :comments org :tangle (eval h_func) :noweb yes -qmckl_exit_code qmckl_get_electron_en_potential(qmckl_context context, double* const en_pot); - #+end_src - - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none -qmckl_exit_code qmckl_get_electron_en_potential(qmckl_context context, double* const en_pot) -{ - if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { - return QMCKL_NULL_CONTEXT; - } - - qmckl_exit_code rc; - - rc = qmckl_provide_en_potential(context); - if (rc != QMCKL_SUCCESS) return rc; - - qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; - assert (ctx != NULL); - - size_t sze = ctx->electron.walk_num * sizeof(double); - memcpy(en_pot, ctx->nucleus.en_pot, sze); - - return QMCKL_SUCCESS; -} - #+end_src - -*** Provide :noexport: - - #+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none -qmckl_exit_code qmckl_provide_en_potential(qmckl_context context); - #+end_src - - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none -qmckl_exit_code qmckl_provide_en_potential(qmckl_context context) -{ - - if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { - return QMCKL_NULL_CONTEXT; - } - - qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; - assert (ctx != NULL); - - if (!ctx->electron.provided) return QMCKL_NOT_PROVIDED; - if (!ctx->nucleus.provided) return QMCKL_NOT_PROVIDED; - - /* Compute if necessary */ - if (ctx->electron.coord_new_date > ctx->nucleus.en_pot_date) { - - /* Allocate array */ - if (ctx->nucleus.en_pot == NULL) { - - qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero; - mem_info.size = ctx->electron.walk_num * sizeof(double); - double* en_pot = (double*) qmckl_malloc(context, mem_info); - - if (en_pot == NULL) { - return qmckl_failwith( context, - QMCKL_ALLOCATION_FAILED, - "qmckl_en_potential", - NULL); - } - ctx->nucleus.en_pot = en_pot; - } - - qmckl_exit_code rc = - qmckl_compute_en_potential(context, - ctx->electron.num, - ctx->nucleus.num, - ctx->electron.walk_num, - ctx->nucleus.charge, - ctx->electron.en_distance, - ctx->nucleus.en_pot); - if (rc != QMCKL_SUCCESS) { - return rc; - } - - ctx->nucleus.en_pot_date = ctx->date; - } - - return QMCKL_SUCCESS; -} - #+end_src - -*** Compute - :PROPERTIES: - :Name: qmckl_compute_en_potential - :CRetType: qmckl_exit_code - :FRetType: qmckl_exit_code - :END: - - #+NAME: qmckl_en_potential_args - | qmckl_context | context | in | Global state | - | int64_t | elec_num | in | Number of electrons | - | int64_t | nucl_num | in | Number of nucleii | - | int64_t | walk_num | in | Number of walkers | - | double | charge[nucl_num] | in | charge of nucleus | - | double | en_distance[walk_num][nucl_num][elec_num] | in | Electron-electron rescaled distances | - | double | en_pot[walk_num] | out | Electron-electron potential | - - #+begin_src f90 :comments org :tangle (eval f) :noweb yes -integer function qmckl_compute_en_potential_f(context, elec_num, nucl_num, walk_num, & - charge, en_distance, en_pot) & - result(info) - use qmckl - implicit none - integer(qmckl_context), intent(in) :: context - integer*8 , intent(in) :: elec_num - integer*8 , intent(in) :: nucl_num - integer*8 , intent(in) :: walk_num - double precision , intent(in) :: charge(nucl_num) - double precision , intent(in) :: en_distance(elec_num,nucl_num,walk_num) - double precision , intent(out) :: en_pot(walk_num) - - integer*8 :: nw, i, j - - info = QMCKL_SUCCESS - - if (context == QMCKL_NULL_CONTEXT) then - info = QMCKL_INVALID_CONTEXT - return - endif - - if (elec_num <= 0) then - info = QMCKL_INVALID_ARG_2 - return - endif - - if (walk_num <= 0) then - info = QMCKL_INVALID_ARG_3 - return - endif - - en_pot = 0.0d0 - do nw=1,walk_num - do j=1,nucl_num - do i=1,elec_num - en_pot(nw) = en_pot(nw) - charge(j)/(en_distance(i,j,nw)) - end do - end do - end do - -end function qmckl_compute_en_potential_f - #+end_src - - #+CALL: generate_c_header(table=qmckl_en_potential_args,rettyp=get_value("CRetType"),fname=get_value("Name")) - - #+RESULTS: - #+begin_src c :tangle (eval h_func) :comments org - qmckl_exit_code qmckl_compute_en_potential ( - const qmckl_context context, - const int64_t elec_num, - const int64_t nucl_num, - const int64_t walk_num, - const double* charge, - const double* en_distance, - double* const en_pot ); - #+end_src - - #+CALL: generate_c_interface(table=qmckl_en_potential_args,rettyp=get_value("CRetType"),fname=get_value("Name")) - - #+RESULTS: - #+begin_src f90 :tangle (eval f) :comments org :exports none - integer(c_int32_t) function qmckl_compute_en_potential & - (context, elec_num, nucl_num, walk_num, charge, en_distance, en_pot) & - 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 :: elec_num - integer (c_int64_t) , intent(in) , value :: nucl_num - integer (c_int64_t) , intent(in) , value :: walk_num - real (c_double ) , intent(in) :: charge(nucl_num) - real (c_double ) , intent(in) :: en_distance(elec_num,nucl_num,walk_num) - real (c_double ) , intent(out) :: en_pot(walk_num) - - integer(c_int32_t), external :: qmckl_compute_en_potential_f - info = qmckl_compute_en_potential_f & - (context, elec_num, nucl_num, walk_num, charge, en_distance, en_pot) - - end function qmckl_compute_en_potential - #+end_src - -*** Test - * End of files :noexport: #+begin_src c :tangle (eval h_private_type)