mirror of
https://github.com/TREX-CoE/qmckl.git
synced 2024-08-17 19:01:43 +02:00
Added derivatives of rescale_een_e and rescale_een_n. #22
This commit is contained in:
parent
55ac5b3787
commit
9b697278d7
@ -97,21 +97,25 @@ int main() {
|
|||||||
|
|
||||||
computed data:
|
computed data:
|
||||||
|
|
||||||
|-----------+-------------------------------------------------------------+-------------------------------------------------------------------------------|
|
|-----------+-----------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------|
|
||||||
| ~int64_t~ | ~dim_cord_vect~ | Number of unique C coefficients |
|
| ~int64_t~ | ~dim_cord_vect~ | Number of unique C coefficients |
|
||||||
| ~int64_t~ | ~dim_cord_vect_date~ | Number of unique C coefficients |
|
| ~int64_t~ | ~dim_cord_vect_date~ | Number of unique C coefficients |
|
||||||
| ~double~ | ~asymp_jasb[2]~ | Asymptotic component |
|
| ~double~ | ~asymp_jasb[2]~ | Asymptotic component |
|
||||||
| ~int64_t~ | ~asymp_jasb_date~ | Asymptotic component |
|
| ~int64_t~ | ~asymp_jasb_date~ | Asymptotic component |
|
||||||
| ~double~ | ~cord_vect_full[dim_cord_vect][nucl_num]~ | vector of non-zero coefficients |
|
| ~double~ | ~cord_vect_full[dim_cord_vect][nucl_num]~ | vector of non-zero coefficients |
|
||||||
| ~int64_t~ | ~cord_vect_full_date~ | Keep track of changes here |
|
| ~int64_t~ | ~cord_vect_full_date~ | Keep track of changes here |
|
||||||
| ~int64_t~ | ~lkpm_combined_index[4][dim_cord_vect]~ | Transform l,k,p, and m into consecutive indices |
|
| ~int64_t~ | ~lkpm_combined_index[4][dim_cord_vect]~ | Transform l,k,p, and m into consecutive indices |
|
||||||
| ~int64_t~ | ~lkpm_combined_index_date~ | Transform l,k,p, and m into consecutive indices |
|
| ~int64_t~ | ~lkpm_combined_index_date~ | Transform l,k,p, and m into consecutive indices |
|
||||||
| ~double~ | ~tmp_c[elec_num][nucl_num][ncord + 1][ncord][walk_num]~ | vector of non-zero coefficients |
|
| ~double~ | ~tmp_c[elec_num][nucl_num][ncord + 1][ncord][walk_num]~ | vector of non-zero coefficients |
|
||||||
| ~double~ | ~dtmp_c[elec_num][4][nucl_num][ncord + 1][ncord][walk_num]~ | vector of non-zero coefficients |
|
| ~double~ | ~dtmp_c[elec_num][4][nucl_num][ncord + 1][ncord][walk_num]~ | vector of non-zero coefficients |
|
||||||
| ~double~ | ~een_rescaled_e[walk_num][elec_num][elec_num][0:cord_num]~ | The electron-electron rescaled distances raised to the powers defined by cord |
|
| ~double~ | ~een_rescaled_e[walk_num][elec_num][elec_num][0:cord_num]~ | The electron-electron rescaled distances raised to the powers defined by cord |
|
||||||
| ~int64_t~ | ~een_rescaled_e_date~ | Keep track of the date of creation |
|
| ~int64_t~ | ~een_rescaled_e_date~ | Keep track of the date of creation |
|
||||||
| ~double~ | ~een_rescaled_n[walk_num][elec_num][nucl_num][0:cord_num]~ | The electron-electron rescaled distances raised to the powers defined by cord |
|
| ~double~ | ~een_rescaled_n[walk_num][elec_num][nucl_num][0:cord_num]~ | The electron-electron rescaled distances raised to the powers defined by cord |
|
||||||
| ~int64_t~ | ~een_rescaled_n_date~ | Keep track of the date of creation |
|
| ~int64_t~ | ~een_rescaled_n_date~ | Keep track of the date of creation |
|
||||||
|
| ~double~ | ~een_rescaled_e_deriv_e[walk_num][elec_num][4][elec_num][0:cord_num]~ | The electron-electron rescaled distances raised to the powers defined by cord derivatives wrt electrons |
|
||||||
|
| ~int64_t~ | ~een_rescaled_e_deriv_e_date~ | Keep track of the date of creation |
|
||||||
|
| ~double~ | ~een_rescaled_n_deriv_e[walk_num][elec_num][4][nucl_num][0:cord_num]~ | The electron-electron rescaled distances raised to the powers defined by cord derivatives wrt electrons |
|
||||||
|
| ~int64_t~ | ~een_rescaled_n_deriv_e_date~ | Keep track of the date of creation |
|
||||||
|
|
||||||
For H2O we have the following data:
|
For H2O we have the following data:
|
||||||
|
|
||||||
@ -308,6 +312,10 @@ typedef struct qmckl_jastrow_struct{
|
|||||||
double * een_rescaled_n;
|
double * een_rescaled_n;
|
||||||
int64_t een_rescaled_e_date;
|
int64_t een_rescaled_e_date;
|
||||||
int64_t een_rescaled_n_date;
|
int64_t een_rescaled_n_date;
|
||||||
|
double * een_rescaled_e_deriv_e;
|
||||||
|
double * een_rescaled_n_deriv_e;
|
||||||
|
int64_t een_rescaled_e_deriv_e_date;
|
||||||
|
int64_t een_rescaled_n_deriv_e_date;
|
||||||
bool provided;
|
bool provided;
|
||||||
char * type;
|
char * type;
|
||||||
} qmckl_jastrow_struct;
|
} qmckl_jastrow_struct;
|
||||||
@ -3150,6 +3158,340 @@ assert(fabs(een_rescaled_e[0][1][5][2]-0.3424402276009091) < 1.e-12);
|
|||||||
|
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
** Electron-electron rescaled distances for each order and derivatives
|
||||||
|
|
||||||
|
~een_rescaled_e~ stores the table of the rescaled distances between all
|
||||||
|
pairs of electrons and raised to the power \(p\) defined by ~cord_num~.
|
||||||
|
Here we take its derivatives required for the een jastrow.
|
||||||
|
|
||||||
|
TODO: write formulae
|
||||||
|
|
||||||
|
|
||||||
|
*** Get
|
||||||
|
|
||||||
|
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
|
||||||
|
qmckl_exit_code qmckl_get_jastrow_een_rescaled_e_deriv_e(qmckl_context context, double* const distance_rescaled);
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
|
||||||
|
qmckl_exit_code qmckl_get_jastrow_een_rescaled_e_deriv_e(qmckl_context context, double* const distance_rescaled)
|
||||||
|
{
|
||||||
|
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
|
||||||
|
return QMCKL_NULL_CONTEXT;
|
||||||
|
}
|
||||||
|
|
||||||
|
qmckl_exit_code rc;
|
||||||
|
|
||||||
|
rc = qmckl_provide_een_rescaled_e_deriv_e(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.num * 4 * ctx->electron.num * ctx->electron.walk_num * (ctx->jastrow.cord_num + 1);
|
||||||
|
memcpy(distance_rescaled, ctx->jastrow.een_rescaled_e_deriv_e, sze * sizeof(double));
|
||||||
|
|
||||||
|
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_een_rescaled_e_deriv_e(qmckl_context context);
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
|
||||||
|
qmckl_exit_code qmckl_provide_een_rescaled_e_deriv_e(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);
|
||||||
|
|
||||||
|
/* Check if ee distance is provided */
|
||||||
|
qmckl_exit_code rc = qmckl_provide_een_rescaled_e(context);
|
||||||
|
if(rc != QMCKL_SUCCESS) return rc;
|
||||||
|
|
||||||
|
/* Compute if necessary */
|
||||||
|
if (ctx->date > ctx->jastrow.een_rescaled_e_deriv_e_date) {
|
||||||
|
|
||||||
|
/* Allocate array */
|
||||||
|
if (ctx->jastrow.een_rescaled_e_deriv_e == NULL) {
|
||||||
|
|
||||||
|
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
|
||||||
|
mem_info.size = ctx->electron.num * 4 * ctx->electron.num *
|
||||||
|
ctx->electron.walk_num * (ctx->jastrow.cord_num + 1) * sizeof(double);
|
||||||
|
double* een_rescaled_e_deriv_e = (double*) qmckl_malloc(context, mem_info);
|
||||||
|
|
||||||
|
if (een_rescaled_e_deriv_e == NULL) {
|
||||||
|
return qmckl_failwith( context,
|
||||||
|
QMCKL_ALLOCATION_FAILED,
|
||||||
|
"qmckl_een_rescaled_e_deriv_e",
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
ctx->jastrow.een_rescaled_e_deriv_e = een_rescaled_e_deriv_e;
|
||||||
|
}
|
||||||
|
|
||||||
|
qmckl_exit_code rc =
|
||||||
|
qmckl_compute_factor_een_rescaled_e_deriv_e(context,
|
||||||
|
ctx->electron.walk_num,
|
||||||
|
ctx->electron.num,
|
||||||
|
ctx->jastrow.cord_num,
|
||||||
|
ctx->electron.rescale_factor_kappa_ee,
|
||||||
|
ctx->electron.coord_new,
|
||||||
|
ctx->electron.ee_distance,
|
||||||
|
ctx->jastrow.een_rescaled_e,
|
||||||
|
ctx->jastrow.een_rescaled_e_deriv_e);
|
||||||
|
if (rc != QMCKL_SUCCESS) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->jastrow.een_rescaled_e_deriv_e_date = ctx->date;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QMCKL_SUCCESS;
|
||||||
|
}
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** Compute
|
||||||
|
:PROPERTIES:
|
||||||
|
:Name: qmckl_compute_een_rescaled_e_deriv_e
|
||||||
|
:CRetType: qmckl_exit_code
|
||||||
|
:FRetType: qmckl_exit_code
|
||||||
|
:END:
|
||||||
|
|
||||||
|
#+NAME: qmckl_factor_een_rescaled_e_deriv_e_args
|
||||||
|
| qmckl_context | context | in | Global state |
|
||||||
|
| int64_t | walk_num | in | Number of walkers |
|
||||||
|
| int64_t | elec_num | in | Number of electrons |
|
||||||
|
| int64_t | cord_num | in | Order of polynomials |
|
||||||
|
| double | rescale_factor_kappa_ee | in | Factor to rescale ee distances |
|
||||||
|
| double | coord_new[walk_num][3][elec_num] | in | Electron coordinates |
|
||||||
|
| double | ee_distance[walk_num][elec_num][elec_num] | in | Electron-electron distances |
|
||||||
|
| double | een_rescaled_e[walk_num][elec_num][elec_num][0:cord_num] | in | Electron-electron distances |
|
||||||
|
| double | een_rescaled_e_deriv_e[walk_num][elec_num][4][elec_num][0:cord_num] | out | Electron-electron rescaled distances |
|
||||||
|
|
||||||
|
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
|
||||||
|
integer function qmckl_compute_factor_een_rescaled_e_deriv_e_f(context, walk_num, elec_num, cord_num, rescale_factor_kappa_ee, &
|
||||||
|
coord_new, ee_distance, een_rescaled_e, een_rescaled_e_deriv_e) &
|
||||||
|
result(info)
|
||||||
|
use qmckl
|
||||||
|
implicit none
|
||||||
|
integer(qmckl_context), intent(in) :: context
|
||||||
|
integer*8 , intent(in) :: walk_num
|
||||||
|
integer*8 , intent(in) :: elec_num
|
||||||
|
integer*8 , intent(in) :: cord_num
|
||||||
|
double precision , intent(in) :: rescale_factor_kappa_ee
|
||||||
|
double precision , intent(in) :: coord_new(elec_num,3,walk_num)
|
||||||
|
double precision , intent(in) :: ee_distance(elec_num,elec_num,walk_num)
|
||||||
|
double precision , intent(in) :: een_rescaled_e(0:cord_num,elec_num,elec_num,walk_num)
|
||||||
|
double precision , intent(out) :: een_rescaled_e_deriv_e(0:cord_num,elec_num,4,elec_num,walk_num)
|
||||||
|
double precision,dimension(:,:,:),allocatable :: elec_dist_deriv_e
|
||||||
|
double precision :: x, rij_inv, kappa_l
|
||||||
|
integer*8 :: i, j, k, l, nw, ii
|
||||||
|
|
||||||
|
allocate(elec_dist_deriv_e(4,elec_num,elec_num))
|
||||||
|
|
||||||
|
info = QMCKL_SUCCESS
|
||||||
|
|
||||||
|
if (context == QMCKL_NULL_CONTEXT) then
|
||||||
|
info = QMCKL_INVALID_CONTEXT
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (walk_num <= 0) then
|
||||||
|
info = QMCKL_INVALID_ARG_2
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (elec_num <= 0) then
|
||||||
|
info = QMCKL_INVALID_ARG_3
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (cord_num <= 0) then
|
||||||
|
info = QMCKL_INVALID_ARG_4
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
! Prepare table of exponentiated distances raised to appropriate power
|
||||||
|
een_rescaled_e_deriv_e = 0.0d0
|
||||||
|
do nw = 1, walk_num
|
||||||
|
do j = 1, elec_num
|
||||||
|
do i = 1, elec_num
|
||||||
|
rij_inv = 1.0d0 / ee_distance(i, j, nw)
|
||||||
|
do ii = 1, 3
|
||||||
|
elec_dist_deriv_e(ii, i, j) = (coord_new(i, ii, nw) - coord_new(j, ii, nw)) * rij_inv
|
||||||
|
end do
|
||||||
|
elec_dist_deriv_e(4, i, j) = 2.0d0 * rij_inv
|
||||||
|
end do
|
||||||
|
elec_dist_deriv_e(:, j, j) = 0.0d0
|
||||||
|
end do
|
||||||
|
|
||||||
|
! prepare the actual een table
|
||||||
|
do l = 1, cord_num
|
||||||
|
kappa_l = - dble(l) * rescale_factor_kappa_ee
|
||||||
|
do j = 1, elec_num
|
||||||
|
do i = 1, elec_num
|
||||||
|
do ii = 1, 4
|
||||||
|
een_rescaled_e_deriv_e(l, i, ii, j, nw) = kappa_l * elec_dist_deriv_e(ii, i, j)
|
||||||
|
end do
|
||||||
|
|
||||||
|
een_rescaled_e_deriv_e(l, i, 4, j, nw) = een_rescaled_e_deriv_e(l, i, 4, j, nw) &
|
||||||
|
+ een_rescaled_e_deriv_e(l, i, 1, j, nw) * een_rescaled_e_deriv_e(l, i, 1, j, nw) &
|
||||||
|
+ een_rescaled_e_deriv_e(l, i, 2, j, nw) * een_rescaled_e_deriv_e(l, i, 2, j, nw) &
|
||||||
|
+ een_rescaled_e_deriv_e(l, i, 3, j, nw) * een_rescaled_e_deriv_e(l, i, 3, j, nw)
|
||||||
|
|
||||||
|
do ii = 1, 4
|
||||||
|
een_rescaled_e_deriv_e(l, i, ii, j, nw) = een_rescaled_e_deriv_e(l, i, ii, j, nw) * &
|
||||||
|
een_rescaled_e(l, i, j, nw)
|
||||||
|
end do
|
||||||
|
end do
|
||||||
|
end do
|
||||||
|
end do
|
||||||
|
end do
|
||||||
|
|
||||||
|
end function qmckl_compute_factor_een_rescaled_e_deriv_e_f
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+CALL: generate_c_header(table=qmckl_factor_een_rescaled_e_deriv_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
|
||||||
|
|
||||||
|
#+RESULTS:
|
||||||
|
#+begin_src c :tangle (eval h_func) :comments org
|
||||||
|
qmckl_exit_code qmckl_compute_factor_een_rescaled_e_deriv_e (
|
||||||
|
const qmckl_context context,
|
||||||
|
const int64_t walk_num,
|
||||||
|
const int64_t elec_num,
|
||||||
|
const int64_t cord_num,
|
||||||
|
const double rescale_factor_kappa_ee,
|
||||||
|
const double* coord_new,
|
||||||
|
const double* ee_distance,
|
||||||
|
const double* een_rescaled_e,
|
||||||
|
double* const een_rescaled_e_deriv_e );
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
#+CALL: generate_c_interface(table=qmckl_factor_een_rescaled_e_deriv_e_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_factor_een_rescaled_e_deriv_e &
|
||||||
|
(context, &
|
||||||
|
walk_num, &
|
||||||
|
elec_num, &
|
||||||
|
cord_num, &
|
||||||
|
rescale_factor_kappa_ee, &
|
||||||
|
coord_new, &
|
||||||
|
ee_distance, &
|
||||||
|
een_rescaled_e, &
|
||||||
|
een_rescaled_e_deriv_e) &
|
||||||
|
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 :: walk_num
|
||||||
|
integer (c_int64_t) , intent(in) , value :: elec_num
|
||||||
|
integer (c_int64_t) , intent(in) , value :: cord_num
|
||||||
|
real (c_double ) , intent(in) , value :: rescale_factor_kappa_ee
|
||||||
|
real (c_double ) , intent(in) :: coord_new(elec_num,3,walk_num)
|
||||||
|
real (c_double ) , intent(in) :: ee_distance(elec_num,elec_num,walk_num)
|
||||||
|
real (c_double ) , intent(in) :: een_rescaled_e(0:cord_num,elec_num,elec_num,walk_num)
|
||||||
|
real (c_double ) , intent(out) :: een_rescaled_e_deriv_e(0:cord_num,elec_num,4,elec_num,walk_num)
|
||||||
|
|
||||||
|
integer(c_int32_t), external :: qmckl_compute_factor_een_rescaled_e_deriv_e_f
|
||||||
|
info = qmckl_compute_factor_een_rescaled_e_deriv_e_f &
|
||||||
|
(context, &
|
||||||
|
walk_num, &
|
||||||
|
elec_num, &
|
||||||
|
cord_num, &
|
||||||
|
rescale_factor_kappa_ee, &
|
||||||
|
coord_new, &
|
||||||
|
ee_distance, &
|
||||||
|
een_rescaled_e, &
|
||||||
|
een_rescaled_e_deriv_e)
|
||||||
|
|
||||||
|
end function qmckl_compute_factor_een_rescaled_e_deriv_e
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** Test
|
||||||
|
|
||||||
|
#+begin_src python :results output :exports none :noweb yes
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
<<jastrow_data>>
|
||||||
|
|
||||||
|
elec_coord = np.array(elec_coord)[0]
|
||||||
|
elec_dist = np.zeros(shape=(elec_num, elec_num),dtype=float)
|
||||||
|
for i in range(elec_num):
|
||||||
|
for j in range(elec_num):
|
||||||
|
elec_dist[i, j] = np.linalg.norm(elec_coord[i] - elec_coord[j])
|
||||||
|
|
||||||
|
kappa = 1.0
|
||||||
|
|
||||||
|
een_rescaled_e_ij = np.zeros(shape=(elec_num * (elec_num - 1)//2, cord_num+1), dtype=float)
|
||||||
|
een_rescaled_e_ij[:,0] = 1.0
|
||||||
|
|
||||||
|
k = 0
|
||||||
|
for j in range(elec_num):
|
||||||
|
for i in range(j):
|
||||||
|
een_rescaled_e_ij[k, 1] = np.exp(-kappa * elec_dist[i, j])
|
||||||
|
k = k + 1
|
||||||
|
|
||||||
|
for l in range(2, cord_num + 1):
|
||||||
|
for k in range(elec_num * (elec_num - 1)//2):
|
||||||
|
een_rescaled_e_ij[k, l] = een_rescaled_e_ij[k, l - 1] * een_rescaled_e_ij[k, 1]
|
||||||
|
|
||||||
|
een_rescaled_e = np.zeros(shape=(elec_num, elec_num, cord_num + 1), dtype=float)
|
||||||
|
een_rescaled_e[:,:,0] = 1.0
|
||||||
|
|
||||||
|
for l in range(1,cord_num+1):
|
||||||
|
k = 0
|
||||||
|
for j in range(elec_num):
|
||||||
|
for i in range(j):
|
||||||
|
x = een_rescaled_e_ij[k, l]
|
||||||
|
een_rescaled_e[i, j, l] = x
|
||||||
|
een_rescaled_e[j, i, l] = x
|
||||||
|
k = k + 1
|
||||||
|
|
||||||
|
print(" een_rescaled_e[0, 2, 1] = ",een_rescaled_e[0, 2, 1])
|
||||||
|
print(" een_rescaled_e[0, 3, 1] = ",een_rescaled_e[0, 3, 1])
|
||||||
|
print(" een_rescaled_e[0, 4, 1] = ",een_rescaled_e[0, 4, 1])
|
||||||
|
print(" een_rescaled_e[1, 3, 2] = ",een_rescaled_e[1, 3, 2])
|
||||||
|
print(" een_rescaled_e[1, 4, 2] = ",een_rescaled_e[1, 4, 2])
|
||||||
|
print(" een_rescaled_e[1, 5, 2] = ",een_rescaled_e[1, 5, 2])
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+RESULTS:
|
||||||
|
: een_rescaled_e[0, 2, 1] = 0.08084493981483197
|
||||||
|
: een_rescaled_e[0, 3, 1] = 0.1066745707571846
|
||||||
|
: een_rescaled_e[0, 4, 1] = 0.01754273169464735
|
||||||
|
: een_rescaled_e[1, 3, 2] = 0.02214680362033448
|
||||||
|
: een_rescaled_e[1, 4, 2] = 0.0005700154999202759
|
||||||
|
: een_rescaled_e[1, 5, 2] = 0.3424402276009091
|
||||||
|
|
||||||
|
#+begin_src c :tangle (eval c_test)
|
||||||
|
//assert(qmckl_electron_provided(context));
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//double een_rescaled_e[walk_num][elec_num][elec_num][(cord_num + 1)];
|
||||||
|
//rc = qmckl_get_jastrow_een_rescaled_e(context, &(een_rescaled_e[0][0][0][0]));
|
||||||
|
//
|
||||||
|
//// value of (0,2,1)
|
||||||
|
//assert(fabs(een_rescaled_e[0][0][2][1]-0.08084493981483197) < 1.e-12);
|
||||||
|
//assert(fabs(een_rescaled_e[0][0][3][1]-0.1066745707571846) < 1.e-12);
|
||||||
|
//assert(fabs(een_rescaled_e[0][0][4][1]-0.01754273169464735) < 1.e-12);
|
||||||
|
//assert(fabs(een_rescaled_e[0][1][3][2]-0.02214680362033448) < 1.e-12);
|
||||||
|
//assert(fabs(een_rescaled_e[0][1][4][2]-0.0005700154999202759) < 1.e-12);
|
||||||
|
//assert(fabs(een_rescaled_e[0][1][5][2]-0.3424402276009091) < 1.e-12);
|
||||||
|
|
||||||
|
#+end_src
|
||||||
|
|
||||||
** Electron-nucleus rescaled distances for each order
|
** Electron-nucleus rescaled distances for each order
|
||||||
|
|
||||||
~een_rescaled_n~ stores the table of the rescaled distances between
|
~een_rescaled_n~ stores the table of the rescaled distances between
|
||||||
@ -3452,10 +3794,352 @@ assert(fabs(een_rescaled_n[0][5][1][2]-0.01343938025140174) < 1.e-12);
|
|||||||
|
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
** Electron-nucleus rescaled distances for each order and derivatives
|
||||||
|
|
||||||
|
~een_rescaled_n_deriv_e~ stores the table of the rescaled distances between
|
||||||
|
electrons and nucleii raised to the power \(p\) defined by ~cord_num~:
|
||||||
|
|
||||||
|
|
||||||
|
*** Get
|
||||||
|
|
||||||
|
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
|
||||||
|
qmckl_exit_code qmckl_get_jastrow_een_rescaled_n_deriv_e(qmckl_context context, double* const distance_rescaled);
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
|
||||||
|
qmckl_exit_code qmckl_get_jastrow_een_rescaled_n_deriv_e(qmckl_context context, double* const distance_rescaled)
|
||||||
|
{
|
||||||
|
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
|
||||||
|
return QMCKL_NULL_CONTEXT;
|
||||||
|
}
|
||||||
|
|
||||||
|
qmckl_exit_code rc;
|
||||||
|
|
||||||
|
rc = qmckl_provide_een_rescaled_n_deriv_e(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.num * 4 * ctx->nucleus.num * ctx->electron.walk_num * (ctx->jastrow.cord_num + 1);
|
||||||
|
memcpy(distance_rescaled, ctx->jastrow.een_rescaled_n_deriv_e, sze * sizeof(double));
|
||||||
|
|
||||||
|
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_een_rescaled_n_deriv_e(qmckl_context context);
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
|
||||||
|
qmckl_exit_code qmckl_provide_een_rescaled_n_deriv_e(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);
|
||||||
|
|
||||||
|
/* Check if ee distance is provided */
|
||||||
|
qmckl_exit_code rc = qmckl_provide_en_distance(context);
|
||||||
|
if(rc != QMCKL_SUCCESS) return rc;
|
||||||
|
|
||||||
|
/* Check if ee distance is provided */
|
||||||
|
rc = qmckl_provide_een_rescaled_n(context);
|
||||||
|
if(rc != QMCKL_SUCCESS) return rc;
|
||||||
|
|
||||||
|
/* Compute if necessary */
|
||||||
|
if (ctx->date > ctx->jastrow.een_rescaled_n_deriv_e_date) {
|
||||||
|
|
||||||
|
/* Allocate array */
|
||||||
|
if (ctx->jastrow.een_rescaled_n_deriv_e == NULL) {
|
||||||
|
|
||||||
|
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
|
||||||
|
mem_info.size = ctx->electron.num * 4 * ctx->nucleus.num *
|
||||||
|
ctx->electron.walk_num * (ctx->jastrow.cord_num + 1) * sizeof(double);
|
||||||
|
double* een_rescaled_n_deriv_e = (double*) qmckl_malloc(context, mem_info);
|
||||||
|
|
||||||
|
if (een_rescaled_n_deriv_e == NULL) {
|
||||||
|
return qmckl_failwith( context,
|
||||||
|
QMCKL_ALLOCATION_FAILED,
|
||||||
|
"qmckl_een_rescaled_n_deriv_e",
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
ctx->jastrow.een_rescaled_n_deriv_e = een_rescaled_n_deriv_e;
|
||||||
|
}
|
||||||
|
|
||||||
|
qmckl_exit_code rc =
|
||||||
|
qmckl_compute_factor_een_rescaled_n_deriv_e(context,
|
||||||
|
ctx->electron.walk_num,
|
||||||
|
ctx->electron.num,
|
||||||
|
ctx->nucleus.num,
|
||||||
|
ctx->jastrow.cord_num,
|
||||||
|
ctx->electron.rescale_factor_kappa_en,
|
||||||
|
ctx->electron.coord_new,
|
||||||
|
ctx->nucleus.coord,
|
||||||
|
ctx->electron.en_distance,
|
||||||
|
ctx->jastrow.een_rescaled_n,
|
||||||
|
ctx->jastrow.een_rescaled_n_deriv_e);
|
||||||
|
if (rc != QMCKL_SUCCESS) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->jastrow.een_rescaled_n_deriv_e_date = ctx->date;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QMCKL_SUCCESS;
|
||||||
|
}
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** Compute
|
||||||
|
:PROPERTIES:
|
||||||
|
:Name: qmckl_compute_factor_een_rescaled_n_deriv_e
|
||||||
|
:CRetType: qmckl_exit_code
|
||||||
|
:FRetType: qmckl_exit_code
|
||||||
|
:END:
|
||||||
|
|
||||||
|
#+NAME: qmckl_compute_factor_een_rescaled_n_deriv_e_args
|
||||||
|
| qmckl_context | context | in | Global state |
|
||||||
|
| int64_t | walk_num | in | Number of walkers |
|
||||||
|
| int64_t | elec_num | in | Number of electrons |
|
||||||
|
| int64_t | nucl_num | in | Number of atoms |
|
||||||
|
| int64_t | cord_num | in | Order of polynomials |
|
||||||
|
| double | rescale_factor_kappa_en | in | Factor to rescale ee distances |
|
||||||
|
| double | coord_new[walk_num][3][elec_num] | in | Electron coordinates |
|
||||||
|
| double | coord[3][nucl_num] | in | Nuclear coordinates |
|
||||||
|
| double | en_distance[walk_num][elec_num][nucl_num] | in | Electron-nucleus distances |
|
||||||
|
| double | een_rescaled_n[walk_num][elec_num][nucl_num][0:cord_num] | in | Electron-nucleus distances |
|
||||||
|
| double | een_rescaled_n_deriv_e[walk_num][elec_num][4][nucl_num][0:cord_num] | out | Electron-nucleus rescaled distances |
|
||||||
|
|
||||||
|
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
|
||||||
|
integer function qmckl_compute_factor_een_rescaled_n_deriv_e_f(context, walk_num, elec_num, nucl_num, &
|
||||||
|
cord_num, rescale_factor_kappa_en, &
|
||||||
|
coord_new, coord, en_distance, een_rescaled_n, een_rescaled_n_deriv_e) &
|
||||||
|
result(info)
|
||||||
|
use qmckl
|
||||||
|
implicit none
|
||||||
|
integer(qmckl_context), intent(in) :: context
|
||||||
|
integer*8 , intent(in) :: walk_num
|
||||||
|
integer*8 , intent(in) :: elec_num
|
||||||
|
integer*8 , intent(in) :: nucl_num
|
||||||
|
integer*8 , intent(in) :: cord_num
|
||||||
|
double precision , intent(in) :: rescale_factor_kappa_en
|
||||||
|
double precision , intent(in) :: coord_new(elec_num,3,walk_num)
|
||||||
|
double precision , intent(in) :: coord(nucl_num,3)
|
||||||
|
double precision , intent(in) :: en_distance(elec_num,nucl_num,walk_num)
|
||||||
|
double precision , intent(in) :: een_rescaled_n(0:cord_num,nucl_num,elec_num,walk_num)
|
||||||
|
double precision , intent(out) :: een_rescaled_n_deriv_e(0:cord_num,nucl_num,4,elec_num,walk_num)
|
||||||
|
double precision,dimension(:,:,:),allocatable :: elnuc_dist_deriv_e
|
||||||
|
double precision :: x, ria_inv, kappa_l
|
||||||
|
integer*8 :: i, a, k, l, nw, ii
|
||||||
|
|
||||||
|
allocate(elnuc_dist_deriv_e(4, elec_num, nucl_num))
|
||||||
|
|
||||||
|
info = QMCKL_SUCCESS
|
||||||
|
|
||||||
|
if (context == QMCKL_NULL_CONTEXT) then
|
||||||
|
info = QMCKL_INVALID_CONTEXT
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (walk_num <= 0) then
|
||||||
|
info = QMCKL_INVALID_ARG_2
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (elec_num <= 0) then
|
||||||
|
info = QMCKL_INVALID_ARG_3
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (nucl_num <= 0) then
|
||||||
|
info = QMCKL_INVALID_ARG_4
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (cord_num <= 0) then
|
||||||
|
info = QMCKL_INVALID_ARG_5
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
! Prepare table of exponentiated distances raised to appropriate power
|
||||||
|
een_rescaled_n_deriv_e = 0.0d0
|
||||||
|
do nw = 1, walk_num
|
||||||
|
|
||||||
|
! prepare the actual een table
|
||||||
|
do a = 1, nucl_num
|
||||||
|
do i = 1, elec_num
|
||||||
|
ria_inv = 1.0d0 / en_distance(i, a, nw)
|
||||||
|
do ii = 1, 3
|
||||||
|
elnuc_dist_deriv_e(ii, i, a) = (coord_new(i, ii, nw) - coord(a, ii)) * ria_inv
|
||||||
|
end do
|
||||||
|
elnuc_dist_deriv_e(4, i, a) = 2.0d0 * ria_inv
|
||||||
|
end do
|
||||||
|
end do
|
||||||
|
|
||||||
|
do l = 0, cord_num
|
||||||
|
kappa_l = - dble(l) * rescale_factor_kappa_en
|
||||||
|
do a = 1, nucl_num
|
||||||
|
do i = 1, elec_num
|
||||||
|
do ii = 1, 4
|
||||||
|
een_rescaled_n_deriv_e(l, a, ii, i, nw) = kappa_l * elnuc_dist_deriv_e(ii, i, a)
|
||||||
|
end do
|
||||||
|
|
||||||
|
een_rescaled_n_deriv_e(l, a, 4, i, nw) = een_rescaled_n_deriv_e(l, a, 4, i, nw) &
|
||||||
|
+ een_rescaled_n_deriv_e(l, a, 1, i, nw) * een_rescaled_n_deriv_e(l, a, 1, i, nw) &
|
||||||
|
+ een_rescaled_n_deriv_e(l, a, 2, i, nw) * een_rescaled_n_deriv_e(l, a, 2, i, nw) &
|
||||||
|
+ een_rescaled_n_deriv_e(l, a, 3, i, nw) * een_rescaled_n_deriv_e(l, a, 3, i, nw)
|
||||||
|
|
||||||
|
do ii = 1, 4
|
||||||
|
een_rescaled_n_deriv_e(l, a, ii, i, nw) = een_rescaled_n_deriv_e(l, a, ii, i, nw) * &
|
||||||
|
een_rescaled_n(l, a, i, nw)
|
||||||
|
end do
|
||||||
|
end do
|
||||||
|
end do
|
||||||
|
end do
|
||||||
|
end do
|
||||||
|
|
||||||
|
end function qmckl_compute_factor_een_rescaled_n_deriv_e_f
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+CALL: generate_c_header(table=qmckl_compute_factor_een_rescaled_n_deriv_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
|
||||||
|
|
||||||
|
#+RESULTS:
|
||||||
|
#+begin_src c :tangle (eval h_func) :comments org
|
||||||
|
qmckl_exit_code qmckl_compute_factor_een_rescaled_n_deriv_e (
|
||||||
|
const qmckl_context context,
|
||||||
|
const int64_t walk_num,
|
||||||
|
const int64_t elec_num,
|
||||||
|
const int64_t nucl_num,
|
||||||
|
const int64_t cord_num,
|
||||||
|
const double rescale_factor_kappa_en,
|
||||||
|
const double* coord_new,
|
||||||
|
const double* coord,
|
||||||
|
const double* en_distance,
|
||||||
|
const double* een_rescaled_n,
|
||||||
|
double* const een_rescaled_n_deriv_e );
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+CALL: generate_c_interface(table=qmckl_factor_een_rescaled_n_deriv_e_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_factor_een_rescaled_n_deriv_e &
|
||||||
|
(context, &
|
||||||
|
walk_num, &
|
||||||
|
elec_num, &
|
||||||
|
nucl_num, &
|
||||||
|
cord_num, &
|
||||||
|
rescale_factor_kappa_en, &
|
||||||
|
coord_new, &
|
||||||
|
coord, &
|
||||||
|
en_distance, &
|
||||||
|
een_rescaled_n, &
|
||||||
|
een_rescaled_n_deriv_e) &
|
||||||
|
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 :: walk_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 :: cord_num
|
||||||
|
real (c_double ) , intent(in) , value :: rescale_factor_kappa_en
|
||||||
|
real (c_double ) , intent(in) :: coord_new(elec_num,3,walk_num)
|
||||||
|
real (c_double ) , intent(in) :: coord(nucl_num,3)
|
||||||
|
real (c_double ) , intent(in) :: en_distance(nucl_num,elec_num,walk_num)
|
||||||
|
real (c_double ) , intent(in) :: een_rescaled_n(0:cord_num,nucl_num,elec_num,walk_num)
|
||||||
|
real (c_double ) , intent(out) :: een_rescaled_n_deriv_e(0:cord_num,nucl_num,4,elec_num,walk_num)
|
||||||
|
|
||||||
|
integer(c_int32_t), external :: qmckl_compute_factor_een_rescaled_n_deriv_e_f
|
||||||
|
info = qmckl_compute_factor_een_rescaled_n_deriv_e_f &
|
||||||
|
(context, &
|
||||||
|
walk_num, &
|
||||||
|
elec_num, &
|
||||||
|
nucl_num, &
|
||||||
|
cord_num, &
|
||||||
|
rescale_factor_kappa_en, &
|
||||||
|
coord_new, &
|
||||||
|
coord, &
|
||||||
|
en_distance, &
|
||||||
|
een_rescaled_n, &
|
||||||
|
een_rescaled_n_deriv_e)
|
||||||
|
|
||||||
|
end function qmckl_compute_factor_een_rescaled_n_deriv_e
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** Test
|
||||||
|
|
||||||
|
#+begin_src python :results output :exports none :noweb yes
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
<<jastrow_data>>
|
||||||
|
|
||||||
|
elec_coord = np.array(elec_coord)[0]
|
||||||
|
nucl_coord = np.array(nucl_coord)
|
||||||
|
elnuc_dist = np.zeros(shape=(elec_num, nucl_num),dtype=float)
|
||||||
|
for i in range(elec_num):
|
||||||
|
for a in range(nucl_num):
|
||||||
|
elnuc_dist[i, a] = np.linalg.norm(elec_coord[i] - nucl_coord[:,a])
|
||||||
|
|
||||||
|
kappa = 1.0
|
||||||
|
|
||||||
|
een_rescaled_n = np.zeros(shape=(nucl_num, elec_num, cord_num + 1), dtype=float)
|
||||||
|
een_rescaled_n[:,:,0] = 1.0
|
||||||
|
|
||||||
|
for a in range(nucl_num):
|
||||||
|
for i in range(elec_num):
|
||||||
|
een_rescaled_n[a, i, 1] = np.exp(-kappa * elnuc_dist[i, a])
|
||||||
|
|
||||||
|
for l in range(2,cord_num+1):
|
||||||
|
for a in range(nucl_num):
|
||||||
|
for i in range(elec_num):
|
||||||
|
een_rescaled_n[a, i, l] = een_rescaled_n[a, i, l - 1] * een_rescaled_n[a, i, 1]
|
||||||
|
|
||||||
|
print(" een_rescaled_n[0, 2, 1] = ",een_rescaled_n[0, 2, 1])
|
||||||
|
print(" een_rescaled_n[0, 3, 1] = ",een_rescaled_n[0, 3, 1])
|
||||||
|
print(" een_rescaled_n[0, 4, 1] = ",een_rescaled_n[0, 4, 1])
|
||||||
|
print(" een_rescaled_n[1, 3, 2] = ",een_rescaled_n[1, 3, 2])
|
||||||
|
print(" een_rescaled_n[1, 4, 2] = ",een_rescaled_n[1, 4, 2])
|
||||||
|
print(" een_rescaled_n[1, 5, 2] = ",een_rescaled_n[1, 5, 2])
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+RESULTS:
|
||||||
|
: een_rescaled_n[0, 2, 1] = 0.10612983920006765
|
||||||
|
: een_rescaled_n[0, 3, 1] = 0.135652809635553
|
||||||
|
: een_rescaled_n[0, 4, 1] = 0.023391817607642338
|
||||||
|
: een_rescaled_n[1, 3, 2] = 0.880957224822116
|
||||||
|
: een_rescaled_n[1, 4, 2] = 0.027185942659395074
|
||||||
|
: een_rescaled_n[1, 5, 2] = 0.01343938025140174
|
||||||
|
|
||||||
|
#+begin_src c :tangle (eval c_test)
|
||||||
|
//assert(qmckl_electron_provided(context));
|
||||||
|
//
|
||||||
|
//double een_rescaled_n[walk_num][elec_num][nucl_num][(cord_num + 1)];
|
||||||
|
//rc = qmckl_get_jastrow_een_rescaled_n(context, &(een_rescaled_n[0][0][0][0]));
|
||||||
|
//
|
||||||
|
//// value of (0,2,1)
|
||||||
|
//assert(fabs(een_rescaled_n[0][2][0][1]-0.10612983920006765) < 1.e-12);
|
||||||
|
//assert(fabs(een_rescaled_n[0][3][0][1]-0.135652809635553) < 1.e-12);
|
||||||
|
//assert(fabs(een_rescaled_n[0][4][0][1]-0.023391817607642338) < 1.e-12);
|
||||||
|
//assert(fabs(een_rescaled_n[0][3][1][2]-0.880957224822116) < 1.e-12);
|
||||||
|
//assert(fabs(een_rescaled_n[0][4][1][2]-0.027185942659395074) < 1.e-12);
|
||||||
|
//assert(fabs(een_rescaled_n[0][5][1][2]-0.01343938025140174) < 1.e-12);
|
||||||
|
|
||||||
|
#+end_src
|
||||||
|
|
||||||
** Prepare for electron-electron-nucleus Jastrow \(f_{een}\)
|
** Prepare for electron-electron-nucleus Jastrow \(f_{een}\)
|
||||||
|
|
||||||
Prepare ~cord_vect_full~ and ~lkpm_combined_index~ tables required for the
|
Prepare ~cord_vect_full~ and ~lkpm_combined_index~ tables required for the
|
||||||
calculation of the three-body jastrow ~factor_een~.
|
calculation of the three-body jastrow ~factor_een~ and its derivative
|
||||||
|
~factor_een_deriv_e~.
|
||||||
|
|
||||||
*** Get
|
*** Get
|
||||||
|
|
||||||
@ -4044,7 +4728,6 @@ assert(qmckl_electron_provided(context));
|
|||||||
|
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
** Electron-electron-nucleus Jastrow \(f_{een}\)
|
** Electron-electron-nucleus Jastrow \(f_{een}\)
|
||||||
|
|
||||||
Calculate the electron-electron-nuclear three-body jastrow component ~factor_een~
|
Calculate the electron-electron-nuclear three-body jastrow component ~factor_een~
|
||||||
|
Loading…
Reference in New Issue
Block a user