1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-07-16 08:00:43 +02:00
qmckl/org/qmckl_jastrow_champ.org

10607 lines
396 KiB
Org Mode
Raw Normal View History

2023-03-30 17:07:11 +02:00
#+TITLE: CHAMP Jastrow Factor
2022-01-23 16:18:46 +01:00
2021-06-23 08:48:43 +02:00
#+SETUPFILE: ../tools/theme.setup
#+INCLUDE: ../tools/lib.org
2022-02-09 14:37:38 +01:00
* Introduction
The Jastrow factor depends on the electronic ($\mathbf{r}$) and
nuclear ($\mathbf{R}$) coordinates. Its defined as $\exp(J(\mathbf{r},\mathbf{R}))$, where
\[
2022-02-14 19:11:37 +01:00
J(\mathbf{r},\mathbf{R}) = J_{\text{eN}}(\mathbf{r},\mathbf{R}) + J_{\text{ee}}(\mathbf{r}) + J_{\text{eeN}}(\mathbf{r},\mathbf{R})
2022-02-09 14:37:38 +01:00
\]
2023-03-13 15:32:35 +01:00
2022-09-08 14:04:49 +02:00
In the following, we use the notations $r_{ij} = |\mathbf{r}_i - \mathbf{r}_j|$ and
2022-02-09 14:37:38 +01:00
$R_{i\alpha} = |\mathbf{r}_i - \mathbf{R}_\alpha|$.
$J_{\text{eN}}$ contains electron-nucleus terms:
\[
2022-11-17 15:45:22 +01:00
J_{\text{eN}}(\mathbf{r},\mathbf{R}) =
2023-03-13 15:32:35 +01:00
\sum_{\alpha=1}^{N_\text{nucl}} \sum_{i=1}^{N_\text{elec}}
2023-03-30 12:34:17 +02:00
\frac{a_{1\,\alpha}\, f_\alpha(R_{i\alpha})}{1+a_{2\,\alpha}\, f_\alpha(R_{i\alpha})} +
\sum_{p=2}^{N_\text{ord}^a} a_{p+1\,\alpha}\, [f_\alpha(R_{i\alpha})]^p - J_{\text{eN}}^{\infty \alpha}
2022-02-09 14:37:38 +01:00
\]
2022-02-14 19:11:37 +01:00
$J_{\text{ee}}$ contains electron-electron terms:
2022-02-09 14:37:38 +01:00
\[
2022-02-14 19:11:37 +01:00
J_{\text{ee}}(\mathbf{r}) =
2022-02-09 14:37:38 +01:00
\sum_{i=1}^{N_\text{elec}} \sum_{j=1}^{i-1}
2023-03-01 14:47:32 +01:00
\frac{\frac{1}{2}(1+\delta^{\uparrow\downarrow}_{ij}) b_1\, f_{\text{ee}}(r_{ij})}{1+b_2\, f_{\text{ee}}(r_{ij})} +
2023-03-01 15:36:49 +01:00
\sum_{p=2}^{N_\text{ord}^b} b_{p+1}\, [f_{\text{ee}}(r_{ij})]^p - J_{ee}^\infty
2022-02-09 14:37:38 +01:00
\]
and $J_{\text{eeN}}$ contains electron-electron-Nucleus terms:
2022-09-08 14:04:49 +02:00
\[
J_{\text{eeN}}(\mathbf{r},\mathbf{R}) =
\sum_{\alpha=1}^{N_{\text{nucl}}}
\sum_{i=1}^{N_{\text{elec}}}
\sum_{j=1}^{i-1}
\sum_{p=2}^{N_{\text{ord}}}
\sum_{k=0}^{p-1}
\sum_{l=0}^{p-k-2\delta_{k,0}}
2023-03-01 14:47:32 +01:00
c_{lkp\alpha} \left[ g_\text{ee}({r}_{ij}) \right]^k
2022-09-08 14:04:49 +02:00
\left[ \left[ g_\alpha({R}_{i\alpha}) \right]^l + \left[ g_\alpha({R}_{j\alpha}) \right]^l \right]
\left[ g_\alpha({R}_{i\,\alpha}) \, g_\alpha({R}_{j\alpha}) \right]^{(p-k-l)/2}
\]
2022-02-09 14:37:38 +01:00
$c_{lkp\alpha}$ are non-zero only when $p-k-l$ is even.
$f$ and $g$ are scaling function defined as
\[
2023-03-01 14:47:32 +01:00
f_\alpha(r) = \frac{1-e^{-\kappa_\alpha\, r}}{\kappa_\alpha} \text{ and }
2023-03-30 12:34:17 +02:00
g_\alpha(r) = e^{-\kappa_\alpha\, r} = 1-\kappa_\alpha f_\alpha(r).
2022-02-09 14:37:38 +01:00
\]
2022-02-14 19:11:37 +01:00
The terms $J_{\text{ee}}^\infty$ and $J_{\text{eN}}^\infty$ are shifts to ensure that
2022-02-09 14:37:38 +01:00
$J_{\text{ee}}$ and $J_{\text{eN}}$ have an asymptotic value of zero.
2022-02-14 19:11:37 +01:00
2023-05-19 16:35:05 +02:00
The eN and eeN parameters are the same of all identical nuclei.
2021-06-23 10:55:59 +02:00
* Headers :noexport:
#+begin_src elisp :noexport :results none
(org-babel-lob-ingest "../tools/lib.org")
#+end_src
2021-10-14 21:40:14 +02:00
#+begin_src c :tangle (eval h_private_func)
2023-03-30 17:07:11 +02:00
#ifndef QMCKL_JASTROW_CHAMP_HPF
#define QMCKL_JASTROW_CHAMP_HPF
2021-10-14 21:40:14 +02:00
#+end_src
2021-06-23 10:55:59 +02:00
#+begin_src c :tangle (eval h_private_type)
2023-03-30 17:07:11 +02:00
#ifndef QMCKL_JASTROW_CHAMP_HPT
#define QMCKL_JASTROW_CHAMP_HPT
2021-06-23 10:55:59 +02:00
#include <stdbool.h>
#+end_src
#+begin_src c :tangle (eval c_test) :noweb yes
#include "qmckl.h"
#include <assert.h>
#include <math.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
2021-07-07 16:12:07 +02:00
#include "n2.h"
2023-03-30 17:07:11 +02:00
#include "qmckl_jastrow_champ_private_func.h"
2021-06-23 10:55:59 +02:00
int main() {
qmckl_context context;
context = qmckl_context_create();
#+end_src
#+begin_src c :tangle (eval c)
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#elif HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
#include <math.h>
2022-04-06 11:16:17 +02:00
2021-06-23 10:55:59 +02:00
#include <stdio.h>
#include "qmckl.h"
#include "qmckl_context_private_type.h"
#include "qmckl_memory_private_type.h"
#include "qmckl_memory_private_func.h"
2023-03-30 17:07:11 +02:00
#include "qmckl_jastrow_champ_private_type.h"
#include "qmckl_jastrow_champ_private_func.h"
2022-04-08 10:44:48 +02:00
2021-06-23 10:55:59 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2021-06-23 10:55:59 +02:00
* Context
:PROPERTIES:
2023-03-30 17:07:11 +02:00
:Name: qmckl_jastrow_champ
2021-06-23 10:55:59 +02:00
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
The following data stored in the context:
2022-01-06 02:28:13 +01:00
#+NAME: qmckl_jastrow_args
2023-03-31 14:41:32 +02:00
| Variable | Type | Description |
|---------------------------+---------------------------------------+-------------------------------------------------------------------|
| ~uninitialized~ | ~int32_t~ | Keeps bits set for uninitialized data |
| ~rescale_factor_ee~ | ~double~ | The distance scaling factor |
| ~rescale_factor_en~ | ~double[type_nucl_num]~ | The distance scaling factor |
| ~aord_num~ | ~int64_t~ | The number of a coeffecients |
| ~bord_num~ | ~int64_t~ | The number of b coeffecients |
| ~cord_num~ | ~int64_t~ | The number of c coeffecients |
| ~type_nucl_num~ | ~int64_t~ | Number of Nuclei types |
| ~type_nucl_vector~ | ~int64_t[nucl_num]~ | IDs of types of Nuclei |
| ~a_vector~ | ~double[aord_num + 1][type_nucl_num]~ | a polynomial coefficients |
| ~b_vector~ | ~double[bord_num + 1]~ | b polynomial coefficients |
| ~c_vector~ | ~double[cord_num][type_nucl_num]~ | c polynomial coefficients |
2021-06-23 13:57:01 +02:00
2023-03-30 18:17:33 +02:00
Computed data:
2021-06-23 13:57:01 +02:00
| Variable | Type | In/Out |
|-------------------------------------+-----------------------------------------------------------------+---------------------------------------------------------------------------------------------------------|
| ~dim_c_vector~ | ~int64_t~ | Number of unique C coefficients |
| ~dim_c_vector_date~ | ~uint64_t~ | Number of unique C coefficients |
| ~asymp_jasa~ | ~double[type_nucl_num]~ | Asymptotic component |
| ~asymp_jasa_date~ | ~uint64_t~ | Ladt modification of the asymptotic component |
| ~asymp_jasb~ | ~double[2]~ | Asymptotic component (up- or down-spin) |
| ~asymp_jasb_date~ | ~uint64_t~ | Ladt modification of the asymptotic component |
| ~c_vector_full~ | ~double[dim_c_vector][nucl_num]~ | vector of non-zero coefficients |
| ~c_vector_full_date~ | ~uint64_t~ | Keep track of changes here |
| ~lkpm_combined_index~ | ~int64_t[4][dim_c_vector]~ | Transform l,k,p, and m into consecutive indices |
| ~lkpm_combined_index_date~ | ~uint64_t~ | Transform l,k,p, and m into consecutive indices |
| ~tmp_c~ | ~double[walk_num][cord_num][cord_num+1][nucl_num][elec_num]~ | vector of non-zero coefficients |
| ~dtmp_c~ | ~double[walk_num][elec_num][4][nucl_num][cord_num+1][cord_num]~ | vector of non-zero coefficients |
| ~ee_distance_rescaled~ | ~double[walk_num][num][num]~ | Electron-electron rescaled distances |
| ~ee_distance_rescaled_date~ | ~uint64_t~ | Last modification date of the electron-electron distances |
| ~ee_distance_rescaled_deriv_e~ | ~double[walk_num][4][num][num]~ | Electron-electron rescaled distances derivatives |
| ~ee_distance_rescaled_deriv_e_date~ | ~uint64_t~ | Last modification date of the electron-electron distance derivatives |
| ~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 |
| ~en_distance_rescaled_deriv_e_date~ | ~uint64_t~ | Last modification date of the electron-electron distance derivatives |
| ~een_rescaled_n~ | ~double[walk_num][cord_num+1][nucl_num][elec_num]~ | The electron-electron rescaled distances raised to the powers defined by cord |
| ~een_rescaled_n_date~ | ~uint64_t~ | Keep track of the date of creation |
| ~een_rescaled_e_deriv_e~ | ~double[walk_num][cord_num+1][elec_num][4][elec_num]~ | The electron-electron rescaled distances raised to the powers defined by cord derivatives wrt electrons |
| ~een_rescaled_e_deriv_e_date~ | ~uint64_t~ | Keep track of the date of creation |
| ~een_rescaled_n_deriv_e~ | ~double[walk_num][cord_num+1][nucl_num][4][elec_num]~ | The electron-electron rescaled distances raised to the powers defined by cord derivatives wrt electrons |
| ~een_rescaled_n_deriv_e_date~ | ~uint64_t~ | Keep track of the date of creation |
| ~factor_ee~ | ~double[walk_num]~ | Jastrow factor: electron-electron part |
| ~factor_ee_date~ | ~uint64_t~ | Jastrow factor: electron-electron part |
| ~factor_en~ | ~double[walk_num]~ | Jastrow factor: electron-nucleus part |
| ~factor_en_date~ | ~uint64_t~ | Jastrow factor: electron-nucleus part |
| ~factor_een~ | ~double[walk_num]~ | Jastrow factor: electron-electron-nucleus part |
| ~factor_een_date~ | ~uint64_t~ | Jastrow factor: electron-electron-nucleus part |
| ~factor_ee_deriv_e~ | ~double[walk_num][4][elec_num]~ | Derivative of the Jastrow factor: electron-electron-nucleus part |
| ~factor_ee_deriv_e_date~ | ~uint64_t~ | Keep track of the date for the derivative |
| ~factor_en_deriv_e~ | ~double[walk_num][4][elec_num]~ | Derivative of the Jastrow factor: electron-electron-nucleus part |
| ~factor_en_deriv_e_date~ | ~uint64_t~ | Keep track of the date for the en derivative |
| ~factor_een_deriv_e~ | ~double[walk_num][4][elec_num]~ | Derivative of the Jastrow factor: electron-electron-nucleus part |
| ~factor_een_deriv_e_date~ | ~uint64_t~ | Keep track of the date for the een derivative |
| ~value~ | ~double[walk_num]~ | Value of the Jastrow factor |
| ~value_date~ | ~uint64_t~ | Keep track of the date |
| ~gl~ | ~double[walk_num][4][elec_num]~ | Gradient and Laplacian of the Jastrow factor |
| ~value_date~ | ~uint64_t~ | Keep track of the date |
#+NAME: jastrow_data
2022-02-09 14:37:38 +01:00
#+BEGIN_SRC python :results none :exports none
import numpy as np
2022-02-09 14:37:38 +01:00
# For H2O we have the following data:
2021-07-05 15:02:05 +02:00
elec_num = 10
nucl_num = 2
up_num = 5
down_num = 5
2021-07-06 15:27:14 +02:00
nucl_coord = np.array([ [0.000000, 0.000000 ],
2021-07-05 15:02:05 +02:00
[0.000000, 0.000000 ],
2021-07-06 15:27:14 +02:00
[0.000000, 2.059801 ] ])
2021-07-05 15:02:05 +02:00
2022-11-17 15:45:22 +01:00
elec_coord = np.array( [[[-0.250655104764153 , 0.503070975550133 , -0.166554344502303],
2022-01-31 16:47:28 +01:00
[-0.587812193472177 , -0.128751981129274 , 0.187773606533075],
2021-07-05 15:02:05 +02:00
[ 1.61335569047166 , -0.615556732874863 , -1.43165470979934 ],
[-4.901239896295210E-003 , -1.120440036458986E-002 , 1.99761909330422 ],
[ 0.766647499681200 , -0.293515395797937 , 3.66454589201239 ],
[-0.127732483187947 , -0.138975497694196 , -8.669850480215846E-002],
[-0.232271834949124 , -1.059321673434182E-002 , -0.504862241464867],
[ 1.09360863531826 , -2.036103063808752E-003 , -2.702796910818986E-002],
[-0.108090166832043 , 0.189161729653261 , 2.15398313919894],
2022-11-17 15:45:22 +01:00
[ 0.397978144318712 , -0.254277292595981 , 2.54553335476344]]])
2021-07-05 15:02:05 +02:00
2022-11-17 15:45:22 +01:00
ee_distance_rescaled = np.array([
2022-02-09 14:37:38 +01:00
[ 0.000000000000000, 0.000000000000000, 0.000000000000000,
0.000000000000000, 0.000000000000000, 0.000000000000000,
0.000000000000000, 0.000000000000000, 0.000000000000000,
0.000000000000000 ],
[ 0.550227800352402, 0.000000000000000, 0.000000000000000,
0.000000000000000, 0.000000000000000, 0.000000000000000,
0.000000000000000, 0.000000000000000, 0.000000000000000,
0.000000000000000 ],
[ 0.919155060185168, 0.937695909123175, 0.000000000000000,
0.000000000000000, 0.000000000000000, 0.000000000000000,
0.000000000000000, 0.000000000000000, 0.000000000000000,
0.000000000000000 ],
[ 0.893325429242815, 0.851181978173561, 0.978501685226877,
0.000000000000000, 0.000000000000000, 0.000000000000000,
0.000000000000000, 0.000000000000000, 0.000000000000000,
0.000000000000000 ],
[ 0.982457268305353, 0.976125002619471, 0.994349933143149,
0.844077311588328, 0.000000000000000, 0.000000000000000,
0.000000000000000, 0.000000000000000, 0.000000000000000,
0.000000000000000 ],
[ 0.482407528408731, 0.414816073699124, 0.894716035479343,
0.876540187084407, 0.978921170036895, 0.000000000000000,
0.000000000000000, 0.000000000000000, 0.000000000000000,
0.000000000000000 ],
[ 0.459541909660400, 0.545007215761510, 0.883752955884551,
0.918958134888791, 0.986386936267237, 0.362209822236419,
0.000000000000000, 0.000000000000000, 0.000000000000000,
0.000000000000000 ],
[ 0.763732576854455, 0.817282762358449, 0.801802919535959,
0.900089095449775, 0.975704636491453, 0.707836537586060,
0.755705808346586, 0.000000000000000, 0.000000000000000,
0.000000000000000 ],
[ 0.904249454052971, 0.871097965261373, 0.982717262706270,
0.239901207363622, 0.836519456769083, 0.896135326270534,
0.930694340243023, 0.917708540815567, 0.000000000000000,
0.000000000000000 ],
[ 0.944400908070716, 0.922589018494961, 0.984615718580670,
0.514328661540623, 0.692362267147064, 0.931894098453677,
0.956034127544344, 0.931221472309472, 0.540903688625053,
2022-11-17 15:45:22 +01:00
0.000000000000000 ]])
2021-07-05 15:02:05 +02:00
2021-07-06 12:21:51 +02:00
en_distance_rescaled = np.transpose(np.array([
2022-01-31 16:47:28 +01:00
[ 0.443570948411811 , 0.467602196999105 , 0.893870160799932 ,
0.864347190364447 , 0.976608182392358 , 0.187563183468210 ,
0.426404699872689 , 0.665107090128166 , 0.885246991424583 ,
2021-07-06 12:21:51 +02:00
0.924902909715270 ],
2022-01-31 16:47:28 +01:00
[ 0.899360150637444 , 0.860035135365386 , 0.979659405613798 ,
6.140678415933776E-002, 0.835118398056681 , 0.884071658981068 ,
0.923860000907362 , 0.905203414522289 , 0.211286300932359 ,
2021-07-06 12:21:51 +02:00
0.492104840907350 ]]))
2021-07-06 09:27:14 +02:00
# symmetrize it
for i in range(elec_num):
for j in range(elec_num):
ee_distance_rescaled[i][j] = ee_distance_rescaled[j][i]
2021-07-05 15:02:05 +02:00
2022-11-17 19:20:12 +01:00
# For N2, we have the following data:
type_nucl_num = 1
aord_num = 5
bord_num = 5
cord_num = 5
2022-11-16 11:58:44 +01:00
dim_c_vector= 23
2021-07-06 12:21:51 +02:00
type_nucl_vector = [ 1, 1]
2022-11-17 15:45:22 +01:00
a_vector = np.array([
2021-07-06 12:21:51 +02:00
[0.000000000000000E+000],
[0.000000000000000E+000],
[-0.380512000000000E+000],
[-0.157996000000000E+000],
[-3.155800000000000E-002],
2022-11-17 15:45:22 +01:00
[2.151200000000000E-002]])
2021-07-06 12:21:51 +02:00
2022-11-17 15:45:22 +01:00
b_vector =np.array( [ 0.500000000000000E-000, 0.153660000000000E-000, 6.722620000000000E-002,
2.157000000000000E-002, 7.309600000000000E-003, 2.866000000000000E-003])
2022-11-16 11:58:44 +01:00
c_vector = [ 0.571702000000000E-000, -0.514253000000000E-000, -0.513043000000000E-000,
9.486000000000000E-003, -4.205000000000000E-003, 0.426325800000000E-000,
8.288150000000000E-002, 5.118600000000000E-003, -2.997800000000000E-003,
-5.270400000000000E-003, -7.499999999999999E-005, -8.301649999999999E-002,
1.454340000000000E-002, 5.143510000000000E-002, 9.250000000000000E-004,
-4.099100000000000E-003, 4.327600000000000E-003, -1.654470000000000E-003,
2.614000000000000E-003, -1.477000000000000E-003, -1.137000000000000E-003,
-4.010475000000000E-002, 6.106710000000000E-003 ]
2022-11-16 11:58:44 +01:00
c_vector_full = [
2022-01-31 16:47:28 +01:00
[ 0.571702000000000E-000, -0.514253000000000E-000, -0.513043000000000E-000,
9.486000000000000E-003, -4.205000000000000E-003, 0.426325800000000E-000,
8.288150000000000E-002, 5.118600000000000E-003, -2.997800000000000E-003,
-5.270400000000000E-003, -7.499999999999999E-005, -8.301649999999999E-002,
1.454340000000000E-002, 5.143510000000000E-002, 9.250000000000000E-004,
-4.099100000000000E-003, 4.327600000000000E-003, -1.654470000000000E-003,
2.614000000000000E-003, -1.477000000000000E-003, -1.137000000000000E-003,
-4.010475000000000E-002, 6.106710000000000E-003 ],
2022-01-31 16:47:28 +01:00
[ 0.571702000000000E-000, -0.514253000000000E-000, -0.513043000000000E-000,
9.486000000000000E-003, -4.205000000000000E-003, 0.426325800000000E-000,
8.288150000000000E-002, 5.118600000000000E-003, -2.997800000000000E-003,
-5.270400000000000E-003, -7.499999999999999E-005, -8.301649999999999E-002,
1.454340000000000E-002, 5.143510000000000E-002, 9.250000000000000E-004,
-4.099100000000000E-003, 4.327600000000000E-003, -1.654470000000000E-003,
2.614000000000000E-003, -1.477000000000000E-003, -1.137000000000000E-003,
-4.010475000000000E-002, 6.106710000000000E-003 ],
]
2022-01-31 16:47:28 +01:00
lkpm_combined_index = [[1 , 1 , 2 , 0],
[0 , 0 , 2 , 1],
[1 , 2 , 3 , 0],
[2 , 1 , 3 , 0],
[0 , 1 , 3 , 1],
[1 , 0 , 3 , 1],
[1 , 3 , 4 , 0],
[2 , 2 , 4 , 0],
[0 , 2 , 4 , 1],
[3 , 1 , 4 , 0],
[1 , 1 , 4 , 1],
[2 , 0 , 4 , 1],
[0 , 0 , 4 , 2],
[1 , 4 , 5 , 0],
[2 , 3 , 5 , 0],
[0 , 3 , 5 , 1],
[3 , 2 , 5 , 0],
[1 , 2 , 5 , 1],
[4 , 1 , 5 , 0],
[2 , 1 , 5 , 1],
[0 , 1 , 5 , 2],
[3 , 0 , 5 , 1],
[1 , 0 , 5 , 2]]
2021-07-05 15:02:05 +02:00
kappa = 1.0
kappa_inv = 1.0/kappa
#+END_SRC
2022-01-31 16:47:28 +01:00
2021-06-23 10:55:59 +02:00
** Data structure
#+begin_src c :comments org :tangle (eval h_private_type)
2023-03-30 17:07:11 +02:00
typedef struct qmckl_jastrow_champ_struct{
int64_t * restrict lkpm_combined_index;
int64_t * restrict type_nucl_vector;
double * restrict asymp_jasa;
double * restrict asymp_jasb;
double * restrict a_vector;
double * restrict b_vector;
double * restrict c_vector;
double * restrict c_vector_full;
double * restrict dtmp_c;
double * restrict ee_distance_rescaled;
double * restrict ee_distance_rescaled_deriv_e;
double * restrict een_rescaled_e;
double * restrict een_rescaled_e_deriv_e;
double * restrict een_rescaled_n;
double * restrict een_rescaled_n_deriv_e;
double * restrict en_distance_rescaled;
double * restrict en_distance_rescaled_deriv_e;
double * restrict factor_ee;
double * restrict factor_ee_deriv_e;
double * restrict factor_een;
double * restrict factor_een_deriv_e;
double * restrict factor_en;
double * restrict factor_en_deriv_e;
double * restrict rescale_factor_en;
double * restrict tmp_c;
2023-03-30 18:17:33 +02:00
double * restrict value;
double * restrict gl;
2022-09-08 14:04:49 +02:00
int64_t aord_num;
int64_t bord_num;
int64_t cord_num;
2023-03-30 17:07:11 +02:00
int64_t dim_c_vector;
2022-09-08 14:04:49 +02:00
int64_t type_nucl_num;
2022-11-17 15:45:22 +01:00
uint64_t asymp_jasa_date;
2021-07-08 07:10:24 +02:00
uint64_t asymp_jasb_date;
2022-11-16 11:58:44 +01:00
uint64_t c_vector_full_date;
2023-03-30 17:07:11 +02:00
uint64_t dim_c_vector_date;
uint64_t dtmp_c_date;
uint64_t ee_distance_rescaled_date;
uint64_t ee_distance_rescaled_deriv_e_date;
2021-07-08 07:10:24 +02:00
uint64_t een_rescaled_e_date;
uint64_t een_rescaled_e_deriv_e_date;
2023-03-30 17:07:11 +02:00
uint64_t een_rescaled_n_date;
2021-07-08 07:10:24 +02:00
uint64_t een_rescaled_n_deriv_e_date;
2023-03-30 17:07:11 +02:00
uint64_t en_distance_rescaled_date;
uint64_t en_distance_rescaled_deriv_e_date;
uint64_t factor_ee_date;
uint64_t factor_ee_deriv_e_date;
uint64_t factor_een_date;
uint64_t factor_een_deriv_e_date;
uint64_t factor_en_date;
uint64_t factor_en_deriv_e_date;
uint64_t lkpm_combined_index_date;
uint64_t tmp_c_date;
2023-03-30 18:17:33 +02:00
uint64_t value_date;
uint64_t gl_date;
2023-03-30 17:07:11 +02:00
double rescale_factor_ee;
int32_t uninitialized;
2022-09-08 14:04:49 +02:00
bool provided;
2022-04-06 16:26:35 +02:00
2023-03-30 17:07:11 +02:00
} qmckl_jastrow_champ_struct;
2021-06-23 10:55:59 +02:00
#+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.
2023-03-30 17:07:11 +02:00
#+begin_src c :comments org :tangle (eval h_private_func)
qmckl_exit_code qmckl_init_jastrow_champ(qmckl_context context);
2021-06-23 10:55:59 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2021-06-23 10:55:59 +02:00
#+begin_src c :comments org :tangle (eval c)
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_init_jastrow_champ(qmckl_context context) {
2021-06-23 10:55:59 +02:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return false;
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-06-23 10:55:59 +02:00
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.uninitialized = (1 << 10) - 1;
2021-06-23 10:55:59 +02:00
/* Default values */
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.aord_num = -1;
2023-05-19 16:35:05 +02:00
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.bord_num = -1;
2023-05-19 16:35:05 +02:00
ctx->jastrow_champ.dim_c_vector = -1;
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.cord_num = -1;
2023-05-19 16:35:05 +02:00
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.type_nucl_num = -1;
2021-06-23 10:55:59 +02:00
return QMCKL_SUCCESS;
}
#+end_src
2022-01-31 16:47:28 +01:00
** Initialization functions
2021-06-24 13:56:24 +02:00
To prepare for the Jastrow and its derivative, all the following functions need to be
called.
2021-06-24 13:35:16 +02:00
#+begin_src c :comments org :tangle (eval h_func)
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_set_jastrow_champ_rescale_factor_ee (qmckl_context context, const double kappa_ee);
qmckl_exit_code qmckl_set_jastrow_champ_rescale_factor_en (qmckl_context context, const double* kappa_en, const int64_t size_max);
qmckl_exit_code qmckl_set_jastrow_champ_aord_num (qmckl_context context, const int64_t aord_num);
qmckl_exit_code qmckl_set_jastrow_champ_bord_num (qmckl_context context, const int64_t bord_num);
qmckl_exit_code qmckl_set_jastrow_champ_cord_num (qmckl_context context, const int64_t cord_num);
qmckl_exit_code qmckl_set_jastrow_champ_type_nucl_num (qmckl_context context, const int64_t type_nucl_num);
qmckl_exit_code qmckl_set_jastrow_champ_type_nucl_vector (qmckl_context context, const int64_t* type_nucl_vector, const int64_t nucl_num);
qmckl_exit_code qmckl_set_jastrow_champ_a_vector (qmckl_context context, const double * a_vector, const int64_t size_max);
qmckl_exit_code qmckl_set_jastrow_champ_b_vector (qmckl_context context, const double * b_vector, const int64_t size_max);
qmckl_exit_code qmckl_set_jastrow_champ_c_vector (qmckl_context context, const double * c_vector, const int64_t size_max);
2021-06-24 13:35:16 +02:00
#+end_src
#+NAME:pre2
#+begin_src c :exports none
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
2021-06-24 13:56:24 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-06-24 13:56:24 +02:00
2023-03-30 17:07:11 +02:00
if (mask != 0 && !(ctx->jastrow_champ.uninitialized & mask)) {
return qmckl_failwith( context,
QMCKL_ALREADY_SET,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_*",
NULL);
}
#+end_src
2021-06-24 13:56:24 +02:00
#+NAME:post2
#+begin_src c :exports none
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.uninitialized &= ~mask;
ctx->jastrow_champ.provided = (ctx->jastrow_champ.uninitialized == 0);
if (ctx->jastrow_champ.provided) {
qmckl_exit_code rc_ = qmckl_finalize_jastrow_champ(context);
if (rc_ != QMCKL_SUCCESS) return rc_;
}
2021-06-24 13:56:24 +02:00
return QMCKL_SUCCESS;
2021-06-24 13:35:16 +02:00
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_aord_num(qmckl_context context, const int64_t aord_num)
{
2021-06-24 13:35:16 +02:00
int32_t mask = 1 << 0;
2022-01-31 16:47:28 +01:00
<<pre2>>
2022-11-16 17:54:59 +01:00
if (aord_num < 0) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_aord_num",
2022-11-16 17:54:59 +01:00
"aord_num < 0");
2021-06-24 13:35:16 +02:00
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.aord_num = aord_num;
2023-05-19 16:35:05 +02:00
ctx->jastrow_champ.uninitialized |= (1 << 5);
<<post2>>
}
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_bord_num(qmckl_context context, const int64_t bord_num)
{
int32_t mask = 1 << 1;
<<pre2>>
2022-11-16 17:54:59 +01:00
if (bord_num < 0) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_bord_num",
2022-11-16 17:54:59 +01:00
"bord_num < 0");
2021-06-24 13:35:16 +02:00
}
2022-01-31 16:47:28 +01:00
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.bord_num = bord_num;
2023-05-19 16:35:05 +02:00
ctx->jastrow_champ.uninitialized |= (1 << 6);
<<post2>>
}
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_cord_num(qmckl_context context, const int64_t cord_num)
{
int32_t mask = 1 << 2;
<<pre2>>
2022-11-16 17:54:59 +01:00
if (cord_num < 0) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_cord_num",
2022-11-16 17:54:59 +01:00
"cord_num < 0");
}
2022-11-16 17:54:59 +01:00
int64_t dim_c_vector = -1;
qmckl_exit_code rc = qmckl_compute_dim_c_vector(context, cord_num, &dim_c_vector);
assert (rc == QMCKL_SUCCESS);
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.cord_num = cord_num;
ctx->jastrow_champ.dim_c_vector = dim_c_vector;
2023-05-19 16:35:05 +02:00
ctx->jastrow_champ.uninitialized |= (1 << 7);
2021-06-24 13:35:16 +02:00
<<post2>>
2021-06-24 13:35:16 +02:00
}
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_type_nucl_num(qmckl_context context, const int64_t type_nucl_num)
{
int32_t mask = 1 << 3;
2022-01-31 16:47:28 +01:00
<<pre2>>
if (type_nucl_num <= 0) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_type_nucl_num",
"type_nucl_num < 0");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.type_nucl_num = type_nucl_num;
2021-06-24 13:35:16 +02:00
<<post2>>
}
2021-06-24 13:35:16 +02:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_type_nucl_vector(qmckl_context context,
int64_t const * type_nucl_vector,
const int64_t nucl_num)
{
2021-06-24 13:35:16 +02:00
int32_t mask = 1 << 4;
2021-06-24 13:35:16 +02:00
<<pre2>>
2023-03-30 17:07:11 +02:00
int64_t type_nucl_num = ctx->jastrow_champ.type_nucl_num;
2022-11-16 17:54:59 +01:00
if (type_nucl_num <= 0) {
return qmckl_failwith( context,
2022-11-16 17:54:59 +01:00
QMCKL_NOT_PROVIDED,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_type_nucl_vector",
2022-11-16 17:54:59 +01:00
"type_nucl_num not initialized");
2021-06-24 13:35:16 +02:00
}
2022-01-31 16:47:28 +01:00
if (type_nucl_vector == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_type_nucl_vector",
"type_nucl_vector = NULL");
}
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.type_nucl_vector != NULL) {
qmckl_exit_code rc = qmckl_free(context, ctx->jastrow_champ.type_nucl_vector);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
"qmckl_set_type_nucl_vector",
2023-03-30 17:07:11 +02:00
"Unable to free ctx->jastrow_champ.type_nucl_vector");
}
}
2021-06-24 13:35:16 +02:00
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = nucl_num * sizeof(int64_t);
int64_t* new_array = (int64_t*) qmckl_malloc(context, mem_info);
2021-06-24 13:35:16 +02:00
if(new_array == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_type_nucl_vector",
NULL);
2021-06-24 13:35:16 +02:00
}
memcpy(new_array, type_nucl_vector, mem_info.size);
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.type_nucl_vector = new_array;
<<post2>>
2021-06-24 13:35:16 +02:00
}
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_a_vector(qmckl_context context,
2022-11-16 11:58:44 +01:00
double const * a_vector,
const int64_t size_max)
2022-02-14 19:11:37 +01:00
{
int32_t mask = 1 << 5;
2021-07-06 12:21:51 +02:00
<<pre2>>
2022-01-31 16:47:28 +01:00
2023-03-30 17:07:11 +02:00
int64_t aord_num = ctx->jastrow_champ.aord_num;
2022-11-16 17:54:59 +01:00
if (aord_num < 0) {
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_a_vector",
2022-11-16 17:54:59 +01:00
"aord_num not initialized");
}
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
int64_t type_nucl_num = ctx->jastrow_champ.type_nucl_num;
2021-07-06 12:21:51 +02:00
2022-11-16 17:54:59 +01:00
if (type_nucl_num <= 0) {
return qmckl_failwith( context,
2022-11-16 17:54:59 +01:00
QMCKL_NOT_PROVIDED,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_a_vector",
2022-11-16 17:54:59 +01:00
"type_nucl_num not initialized");
2021-07-06 12:21:51 +02:00
}
2022-11-16 11:58:44 +01:00
if (a_vector == NULL) {
2022-02-14 19:11:37 +01:00
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_a_vector",
2022-11-16 11:58:44 +01:00
"a_vector = NULL");
2022-02-14 19:11:37 +01:00
}
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.a_vector != NULL) {
qmckl_exit_code rc = qmckl_free(context, ctx->jastrow_champ.a_vector);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_a_vector",
"Unable to free ctx->jastrow_champ.a_vector");
}
}
2021-07-06 12:21:51 +02:00
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = (aord_num + 1) * type_nucl_num * sizeof(double);
2021-06-24 13:35:16 +02:00
2022-11-17 19:20:12 +01:00
if (size_max < (aord_num+1)*type_nucl_num ) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_a_vector",
"Array too small. Expected (aord_num+1)*type_nucl_num");
2021-06-24 13:35:16 +02:00
}
double* new_array = (double*) qmckl_malloc(context, mem_info);
if(new_array == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_coefficient",
NULL);
}
2022-01-31 16:47:28 +01:00
2022-11-16 11:58:44 +01:00
memcpy(new_array, a_vector, mem_info.size);
2021-06-24 13:35:16 +02:00
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.a_vector = new_array;
2021-06-24 13:35:16 +02:00
<<post2>>
2021-06-24 13:35:16 +02:00
}
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_b_vector(qmckl_context context,
2022-11-16 11:58:44 +01:00
double const * b_vector,
const int64_t size_max)
{
int32_t mask = 1 << 6;
2021-06-24 13:35:16 +02:00
<<pre2>>
2023-03-30 17:07:11 +02:00
int64_t bord_num = ctx->jastrow_champ.bord_num;
2022-11-16 17:54:59 +01:00
if (bord_num < 0) {
return qmckl_failwith( context,
2022-11-16 17:54:59 +01:00
QMCKL_NOT_PROVIDED,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_b_vector",
2022-11-16 17:54:59 +01:00
"bord_num not initialized");
2021-06-24 13:35:16 +02:00
}
2022-11-16 11:58:44 +01:00
if (b_vector == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_b_vector",
2022-11-16 11:58:44 +01:00
"b_vector = NULL");
}
2022-01-31 16:47:28 +01:00
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.b_vector != NULL) {
qmckl_exit_code rc = qmckl_free(context, ctx->jastrow_champ.b_vector);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_b_vector",
"Unable to free ctx->jastrow_champ.b_vector");
}
2021-06-24 13:35:16 +02:00
}
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = (bord_num + 1) * sizeof(double);
2022-11-16 17:54:59 +01:00
if (size_max < (bord_num+1)) {
2022-02-14 19:11:37 +01:00
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_b_vector",
"Array too small. Expected (bord_num+1)");
2022-02-14 19:11:37 +01:00
}
2021-06-24 13:35:16 +02:00
double* new_array = (double*) qmckl_malloc(context, mem_info);
if(new_array == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_coefficient",
NULL);
}
2022-01-31 16:47:28 +01:00
2022-11-16 11:58:44 +01:00
memcpy(new_array, b_vector, mem_info.size);
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.b_vector = new_array;
<<post2>>
}
2021-06-24 13:35:16 +02:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_c_vector(qmckl_context context,
2022-11-16 11:58:44 +01:00
double const * c_vector,
const int64_t size_max)
{
int32_t mask = 1 << 7;
2021-06-24 13:35:16 +02:00
<<pre2>>
2021-06-24 13:35:16 +02:00
2023-03-30 17:07:11 +02:00
int64_t type_nucl_num = ctx->jastrow_champ.type_nucl_num;
2022-11-16 17:54:59 +01:00
if (type_nucl_num <= 0) {
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_c_vector",
2022-11-16 17:54:59 +01:00
"type_nucl_num not initialized");
}
2023-03-30 17:07:11 +02:00
int64_t dim_c_vector = ctx->jastrow_champ.dim_c_vector;
2022-11-16 17:54:59 +01:00
if (dim_c_vector < 0) {
2022-02-14 19:11:37 +01:00
return qmckl_failwith( context,
2022-11-16 17:54:59 +01:00
QMCKL_NOT_PROVIDED,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_c_vector",
2022-11-16 17:54:59 +01:00
"cord_num not initialized");
2022-02-14 19:11:37 +01:00
}
2021-06-24 13:35:16 +02:00
2022-11-16 11:58:44 +01:00
if (c_vector == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_c_vector",
2022-11-16 11:58:44 +01:00
"c_vector = NULL");
}
2021-06-24 13:35:16 +02:00
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.c_vector != NULL) {
qmckl_exit_code rc = qmckl_free(context, ctx->jastrow_champ.c_vector);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_c_vector",
"Unable to free ctx->jastrow_champ.c_vector");
}
}
2021-06-24 13:35:16 +02:00
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2022-11-16 11:58:44 +01:00
mem_info.size = dim_c_vector * type_nucl_num * sizeof(double);
2021-06-24 13:35:16 +02:00
if ((size_t) size_max < mem_info.size/sizeof(double)) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_c_vector",
2022-11-16 11:58:44 +01:00
"Array too small. Expected dim_c_vector * type_nucl_num");
}
2021-06-24 13:35:16 +02:00
double* new_array = (double*) qmckl_malloc(context, mem_info);
2022-07-09 11:34:38 +02:00
if(new_array == NULL) {
2022-07-09 11:34:38 +02:00
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_coefficient",
2022-07-09 11:34:38 +02:00
NULL);
}
2021-06-24 13:35:16 +02:00
2022-11-16 11:58:44 +01:00
memcpy(new_array, c_vector, mem_info.size);
2021-06-24 13:35:16 +02:00
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.c_vector = new_array;
2021-06-24 13:35:16 +02:00
<<post2>>
}
2021-06-24 13:35:16 +02:00
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_rescale_factor_ee(qmckl_context context,
const double rescale_factor_ee) {
2021-06-24 13:35:16 +02:00
int32_t mask = 1 << 8;
2023-03-13 15:32:35 +01:00
<<pre2>>
2021-06-24 13:35:16 +02:00
if (rescale_factor_ee <= 0.0) {
2021-06-24 13:35:16 +02:00
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_rescale_factor_ee",
"rescale_factor_ee <= 0.0");
2021-06-24 13:35:16 +02:00
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.rescale_factor_ee = rescale_factor_ee;
2021-06-24 13:35:16 +02:00
<<post2>>
}
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_rescale_factor_en(qmckl_context context,
const double* rescale_factor_en,
const int64_t size_max) {
2022-07-09 11:34:38 +02:00
int32_t mask = 1 << 9;
2021-06-24 13:35:16 +02:00
<<pre2>>
2021-06-24 13:35:16 +02:00
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.type_nucl_num <= 0) {
2022-11-17 19:20:12 +01:00
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_rescale_factor_en",
2022-11-17 19:20:12 +01:00
"type_nucl_num not set");
}
if (rescale_factor_en == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_rescale_factor_en",
"Null pointer");
}
2023-03-30 17:07:11 +02:00
if (size_max < ctx->jastrow_champ.type_nucl_num) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_rescale_factor_en",
"Array too small");
}
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.rescale_factor_en != NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_rescale_factor_en",
"Already set");
}
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 17:07:11 +02:00
mem_info.size = ctx->jastrow_champ.type_nucl_num * sizeof(double);
ctx->jastrow_champ.rescale_factor_en = (double*) qmckl_malloc(context, mem_info);
2023-03-30 17:07:11 +02:00
for (int64_t i=0 ; i<ctx->jastrow_champ.type_nucl_num ; ++i) {
if (rescale_factor_en[i] <= 0.0) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_set_jastrow_champ_rescale_factor_en",
"rescale_factor_en <= 0.0");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.rescale_factor_en[i] = rescale_factor_en[i];
}
2021-06-24 13:35:16 +02:00
<<post2>>
}
#+end_src
2021-06-24 13:35:16 +02:00
When the required information is completely entered, other data structures are
computed to accelerate the calculations. The intermediates factors
2023-03-01 14:47:32 +01:00
are precontracted using BLAS LEVEL 3 operations.
2022-02-14 19:11:37 +01:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_finalize_jastrow_champ(qmckl_context context);
#+end_src
2021-06-24 13:35:16 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_finalize_jastrow_champ(qmckl_context context) {
2021-06-24 13:35:16 +02:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
}
2022-07-09 11:34:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2022-01-31 16:47:28 +01:00
/* ----------------------------------- */
/* Check for the necessary information */
/* ----------------------------------- */
2021-07-06 12:21:51 +02:00
if (!(ctx->electron.provided)) {
2021-07-06 12:21:51 +02:00
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
"qmckl_electron",
NULL);
2021-07-06 12:21:51 +02:00
}
if (!(ctx->nucleus.provided)) {
2021-07-06 12:21:51 +02:00
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
"qmckl_nucleus",
2021-07-06 12:21:51 +02:00
NULL);
}
2022-11-17 19:20:12 +01:00
qmckl_exit_code rc;
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_asymp_jasa(context);
2022-11-17 19:20:12 +01:00
assert(rc == QMCKL_SUCCESS);
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_asymp_jasb(context);
2022-11-17 19:20:12 +01:00
assert(rc == QMCKL_SUCCESS);
rc = qmckl_context_touch(context);
return rc;
2021-07-06 12:21:51 +02:00
}
#+end_src
2021-07-06 12:21:51 +02:00
**** Fortran interface
#+begin_src f90 :tangle (eval fh_func) :comments org
interface
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_rescale_factor_ee (context, &
2022-11-14 15:01:56 +01:00
kappa_ee) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
double precision, intent(in), value :: kappa_ee
2023-03-30 17:07:11 +02:00
end function qmckl_set_jastrow_champ_rescale_factor_ee
2022-11-14 15:01:56 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_rescale_factor_en (context, &
2022-11-14 15:01:56 +01:00
kappa_en, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
2022-11-16 17:54:59 +01:00
integer(c_int64_t), intent(in), value :: size_max
2022-11-14 15:01:56 +01:00
double precision, intent(in) :: kappa_en(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_set_jastrow_champ_rescale_factor_en
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_aord_num (context, &
2022-11-14 15:01:56 +01:00
aord_num) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: aord_num
2023-03-30 17:07:11 +02:00
end function qmckl_set_jastrow_champ_aord_num
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_bord_num (context, &
2022-11-14 15:06:58 +01:00
bord_num) bind(C)
2022-11-14 15:01:56 +01:00
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: bord_num
2023-03-30 17:07:11 +02:00
end function qmckl_set_jastrow_champ_bord_num
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_cord_num (context, &
2022-11-14 15:06:58 +01:00
cord_num) bind(C)
2022-11-14 15:01:56 +01:00
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: cord_num
2023-03-30 17:07:11 +02:00
end function qmckl_set_jastrow_champ_cord_num
2022-11-14 15:01:56 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_type_nucl_num (context, &
2022-11-14 15:01:56 +01:00
type_nucl_num) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: type_nucl_num
2023-03-30 17:07:11 +02:00
end function qmckl_set_jastrow_champ_type_nucl_num
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_type_nucl_vector (context, &
2022-11-14 15:01:56 +01:00
type_nucl_vector, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: size_max
2022-11-14 15:06:58 +01:00
integer(c_int64_t), intent(in) :: type_nucl_vector(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_set_jastrow_champ_type_nucl_vector
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_a_vector(context, &
2022-11-16 11:58:44 +01:00
a_vector, size_max) bind(C)
2022-11-14 15:01:56 +01:00
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: size_max
2022-11-16 11:58:44 +01:00
double precision, intent(in) :: a_vector(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_set_jastrow_champ_a_vector
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_b_vector(context, &
2022-11-16 11:58:44 +01:00
b_vector, size_max) bind(C)
2022-11-14 15:01:56 +01:00
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: size_max
2022-11-16 11:58:44 +01:00
double precision, intent(in) :: b_vector(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_set_jastrow_champ_b_vector
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_c_vector(context, &
2022-11-16 11:58:44 +01:00
c_vector, size_max) bind(C)
2022-11-14 15:01:56 +01:00
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: size_max
2022-11-16 11:58:44 +01:00
double precision, intent(in) :: c_vector(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_set_jastrow_champ_c_vector
2023-03-13 15:32:35 +01:00
end interface
#+end_src
** Access functions
2022-02-14 19:11:37 +01:00
#+begin_src c :comments org :tangle (eval h_func) :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_get_jastrow_champ_aord_num (qmckl_context context, int64_t* const aord_num);
qmckl_exit_code qmckl_get_jastrow_champ_bord_num (qmckl_context context, int64_t* const bord_num);
qmckl_exit_code qmckl_get_jastrow_champ_cord_num (qmckl_context context, int64_t* const bord_num);
qmckl_exit_code qmckl_get_jastrow_champ_type_nucl_num (qmckl_context context, int64_t* const type_nucl_num);
qmckl_exit_code qmckl_get_jastrow_champ_type_nucl_vector (qmckl_context context, int64_t* const type_nucl_num, const int64_t size_max);
qmckl_exit_code qmckl_get_jastrow_champ_a_vector (qmckl_context context, double * const a_vector, const int64_t size_max);
qmckl_exit_code qmckl_get_jastrow_champ_b_vector (qmckl_context context, double * const b_vector, const int64_t size_max);
qmckl_exit_code qmckl_get_jastrow_champ_c_vector (qmckl_context context, double * const c_vector, const int64_t size_max);
qmckl_exit_code qmckl_get_jastrow_champ_rescale_factor_ee (const qmckl_context context, double* const rescale_factor_ee);
qmckl_exit_code qmckl_get_jastrow_champ_rescale_factor_en (const qmckl_context context, double* const rescale_factor_en, const int64_t size_max);
qmckl_exit_code qmckl_get_jastrow_champ_dim_c_vector (qmckl_context context, int64_t* const dim_c_vector);
#+end_src
2021-07-06 12:21:51 +02:00
2023-03-13 15:32:35 +01:00
Along with these core functions, calculation of the jastrow factor
requires the following additional information to be set:
2022-07-09 11:34:38 +02:00
2022-01-31 16:47:28 +01:00
When all the data for the AOs have been provided, the following
function returns ~true~.
2022-01-31 16:47:28 +01:00
#+begin_src c :comments org :tangle (eval h_func)
2023-03-30 17:07:11 +02:00
bool qmckl_jastrow_champ_provided (const qmckl_context context);
#+end_src
2021-06-24 13:35:16 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
bool qmckl_jastrow_champ_provided(const qmckl_context context) {
2022-01-31 16:47:28 +01:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return false;
2021-06-24 13:35:16 +02:00
}
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
return ctx->jastrow_champ.provided;
}
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_get_jastrow_champ_aord_num (const qmckl_context context, int64_t* const aord_num) {
2021-06-24 13:35:16 +02:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (char) 0;
2021-06-24 13:35:16 +02:00
}
if (aord_num == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_aord_num",
"aord_num is a null pointer");
}
2021-06-24 13:35:16 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2021-06-24 13:35:16 +02:00
int32_t mask = 1 << 0;
2022-02-14 19:11:37 +01:00
2023-03-30 17:07:11 +02:00
if ( (ctx->jastrow_champ.uninitialized & mask) != 0) {
return QMCKL_NOT_PROVIDED;
}
2021-06-24 13:35:16 +02:00
2023-03-30 17:07:11 +02:00
assert (ctx->jastrow_champ.aord_num > 0);
,*aord_num = ctx->jastrow_champ.aord_num;
return QMCKL_SUCCESS;
}
2022-07-09 11:34:38 +02:00
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_get_jastrow_champ_bord_num (const qmckl_context context, int64_t* const bord_num) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (char) 0;
2021-06-24 13:35:16 +02:00
}
if (bord_num == NULL) {
2021-06-24 13:35:16 +02:00
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_bord_num",
"aord_num is a null pointer");
2021-06-24 13:35:16 +02:00
}
2022-01-31 16:47:28 +01:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2021-06-24 13:35:16 +02:00
int32_t mask = 1 << 1;
2023-03-30 17:07:11 +02:00
if ( (ctx->jastrow_champ.uninitialized & mask) != 0) {
return QMCKL_NOT_PROVIDED;
}
2023-03-30 17:07:11 +02:00
assert (ctx->jastrow_champ.bord_num > 0);
,*bord_num = ctx->jastrow_champ.bord_num;
return QMCKL_SUCCESS;
}
2021-06-24 13:35:16 +02:00
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_get_jastrow_champ_cord_num (const qmckl_context context, int64_t* const cord_num) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (char) 0;
2021-06-24 13:35:16 +02:00
}
if (cord_num == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_cord_num",
"aord_num is a null pointer");
}
2021-06-24 13:35:16 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2021-06-24 13:35:16 +02:00
int32_t mask = 1 << 2;
2022-07-09 11:34:38 +02:00
2023-03-30 17:07:11 +02:00
if ( (ctx->jastrow_champ.uninitialized & mask) != 0) {
return QMCKL_NOT_PROVIDED;
}
2023-03-30 17:07:11 +02:00
assert (ctx->jastrow_champ.cord_num > 0);
,*cord_num = ctx->jastrow_champ.cord_num;
return QMCKL_SUCCESS;
}
2022-01-31 16:47:28 +01:00
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_get_jastrow_champ_type_nucl_num (const qmckl_context context, int64_t* const type_nucl_num) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (char) 0;
2021-06-24 13:35:16 +02:00
}
if (type_nucl_num == NULL) {
2021-06-24 13:35:16 +02:00
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_type_nucl_num",
"type_nucl_num is a null pointer");
2021-06-24 13:35:16 +02:00
}
2022-01-31 16:47:28 +01:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2021-06-24 13:35:16 +02:00
int32_t mask = 1 << 3;
2023-03-30 17:07:11 +02:00
if ( (ctx->jastrow_champ.uninitialized & mask) != 0) {
return QMCKL_NOT_PROVIDED;
}
2023-03-30 17:07:11 +02:00
assert (ctx->jastrow_champ.type_nucl_num > 0);
,*type_nucl_num = ctx->jastrow_champ.type_nucl_num;
return QMCKL_SUCCESS;
}
2021-06-24 13:35:16 +02:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_type_nucl_vector (const qmckl_context context,
int64_t* const type_nucl_vector,
const int64_t size_max)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (char) 0;
2021-06-24 13:35:16 +02:00
}
if (type_nucl_vector == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_type_nucl_vector",
"type_nucl_vector is a null pointer");
}
2021-06-24 13:35:16 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2021-06-24 13:35:16 +02:00
int32_t mask = 1 << 4;
2023-03-30 17:07:11 +02:00
if ( (ctx->jastrow_champ.uninitialized & mask) != 0) {
return QMCKL_NOT_PROVIDED;
}
2021-06-24 13:35:16 +02:00
2023-03-30 17:07:11 +02:00
assert (ctx->jastrow_champ.type_nucl_vector != NULL);
if (size_max < ctx->jastrow_champ.type_nucl_num) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_type_nucl_vector",
"Array too small. Expected jastrow_champ.type_nucl_num");
}
2023-03-30 17:07:11 +02:00
memcpy(type_nucl_vector, ctx->jastrow_champ.type_nucl_vector, ctx->jastrow_champ.type_nucl_num*sizeof(int64_t));
return QMCKL_SUCCESS;
}
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_a_vector (const qmckl_context context,
2022-11-16 11:58:44 +01:00
double * const a_vector,
const int64_t size_max) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (char) 0;
}
2022-11-16 11:58:44 +01:00
if (a_vector == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_a_vector",
2022-11-16 11:58:44 +01:00
"a_vector is a null pointer");
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
int32_t mask = 1 << 5;
2023-03-30 17:07:11 +02:00
if ( (ctx->jastrow_champ.uninitialized & mask) != 0) {
return QMCKL_NOT_PROVIDED;
}
2023-03-30 17:07:11 +02:00
assert (ctx->jastrow_champ.a_vector != NULL);
int64_t sze = (ctx->jastrow_champ.aord_num + 1)*ctx->jastrow_champ.type_nucl_num;
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_a_vector",
"Array too small. Expected (ctx->jastrow_champ.aord_num + 1)*ctx->jastrow_champ.type_nucl_num");
}
2023-03-30 17:07:11 +02:00
memcpy(a_vector, ctx->jastrow_champ.a_vector, sze*sizeof(double));
return QMCKL_SUCCESS;
}
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_b_vector (const qmckl_context context,
2022-11-16 11:58:44 +01:00
double * const b_vector,
const int64_t size_max) {
2022-04-08 10:44:48 +02:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (char) 0;
}
2022-11-16 11:58:44 +01:00
if (b_vector == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_b_vector",
2022-11-16 11:58:44 +01:00
"b_vector is a null pointer");
}
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2022-01-31 16:47:28 +01:00
int32_t mask = 1 << 6;
2021-07-07 16:16:18 +02:00
2023-03-30 17:07:11 +02:00
if ( (ctx->jastrow_champ.uninitialized & mask) != 0) {
return QMCKL_NOT_PROVIDED;
}
2021-07-06 17:54:44 +02:00
2023-03-30 17:07:11 +02:00
assert (ctx->jastrow_champ.b_vector != NULL);
int64_t sze=ctx->jastrow_champ.bord_num +1;
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_b_vector",
"Array too small. Expected (ctx->jastrow_champ.bord_num + 1)");
}
2023-03-30 17:07:11 +02:00
memcpy(b_vector, ctx->jastrow_champ.b_vector, sze*sizeof(double));
return QMCKL_SUCCESS;
}
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_c_vector (const qmckl_context context,
2022-11-16 11:58:44 +01:00
double * const c_vector,
const int64_t size_max) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (char) 0;
}
2021-07-07 16:16:18 +02:00
2022-11-16 11:58:44 +01:00
if (c_vector == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_c_vector",
2022-11-16 11:58:44 +01:00
"c_vector is a null pointer");
}
2021-07-07 16:16:18 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2021-07-07 16:16:18 +02:00
int32_t mask = 1 << 7;
2021-07-07 16:16:18 +02:00
2023-03-30 17:07:11 +02:00
if ( (ctx->jastrow_champ.uninitialized & mask) != 0) {
return QMCKL_NOT_PROVIDED;
}
2021-07-07 16:16:18 +02:00
2023-03-30 17:07:11 +02:00
assert (ctx->jastrow_champ.c_vector != NULL);
2021-07-07 16:16:18 +02:00
2022-11-16 11:58:44 +01:00
int64_t dim_c_vector;
2023-03-30 17:07:11 +02:00
qmckl_exit_code rc = qmckl_get_jastrow_champ_dim_c_vector(context, &dim_c_vector);
if (rc != QMCKL_SUCCESS) return rc;
2021-07-07 16:16:18 +02:00
2023-03-30 17:07:11 +02:00
int64_t sze=dim_c_vector * ctx->jastrow_champ.type_nucl_num;
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_c_vector",
"Array too small. Expected dim_c_vector * jastrow_champ.type_nucl_num");
}
2023-03-30 17:07:11 +02:00
memcpy(c_vector, ctx->jastrow_champ.c_vector, sze*sizeof(double));
return QMCKL_SUCCESS;
}
2021-07-07 16:16:18 +02:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_rescale_factor_ee (const qmckl_context context,
double* const rescale_factor_ee) {
2021-07-07 16:16:18 +02:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
}
if (rescale_factor_ee == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_rescale_factor_ee",
"rescale_factor_ee is a null pointer");
}
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
int32_t mask = 1 << 8;
2023-03-30 17:07:11 +02:00
if ( (ctx->jastrow_champ.uninitialized & mask) != 0) {
return QMCKL_NOT_PROVIDED;
}
2023-03-30 17:07:11 +02:00
assert (ctx->jastrow_champ.rescale_factor_ee > 0.0);
2023-03-30 17:07:11 +02:00
,*rescale_factor_ee = ctx->jastrow_champ.rescale_factor_ee;
return QMCKL_SUCCESS;
}
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_rescale_factor_en (const qmckl_context context,
double* const rescale_factor_en,
const int64_t size_max) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
}
if (rescale_factor_en == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_rescale_factor_en",
"rescale_factor_en is a null pointer");
}
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
int32_t mask = 1 << 9;
2023-03-30 17:07:11 +02:00
if ( (ctx->jastrow_champ.uninitialized & mask) != 0) {
return QMCKL_NOT_PROVIDED;
}
2023-03-30 17:07:11 +02:00
if (size_max < ctx->jastrow_champ.type_nucl_num) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_rescale_factor_en",
"Array to small");
}
2023-03-30 17:07:11 +02:00
assert(ctx->jastrow_champ.rescale_factor_en != NULL);
for (int64_t i=0 ; i<ctx->jastrow_champ.type_nucl_num ; ++i) {
rescale_factor_en[i] = ctx->jastrow_champ.rescale_factor_en[i];
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_get_jastrow_champ_dim_c_vector(qmckl_context context, int64_t* const dim_c_vector)
2023-03-30 12:34:17 +02:00
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
,*dim_c_vector = ctx->jastrow_champ.dim_c_vector;
2023-03-30 12:34:17 +02:00
return QMCKL_SUCCESS;
}
#+end_src
2022-11-16 17:54:59 +01:00
**** Fortran interface
#+begin_src f90 :tangle (eval fh_func) :comments org
interface
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_rescale_factor_ee (context, &
2022-11-16 17:54:59 +01:00
kappa_ee) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
double precision, intent(out) :: kappa_ee
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_rescale_factor_ee
2022-11-16 17:54:59 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_rescale_factor_en (context, &
2022-11-16 17:54:59 +01:00
kappa_en, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: kappa_en(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_rescale_factor_en
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_aord_num (context, &
2022-11-16 17:54:59 +01:00
aord_num) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(out) :: aord_num
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_aord_num
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_bord_num (context, &
2022-11-16 17:54:59 +01:00
bord_num) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(out) :: bord_num
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_bord_num
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_cord_num (context, &
2022-11-16 17:54:59 +01:00
cord_num) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(out) :: cord_num
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_cord_num
2022-11-16 17:54:59 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_type_nucl_num (context, &
2022-11-16 17:54:59 +01:00
type_nucl_num) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(out) :: type_nucl_num
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_type_nucl_num
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_type_nucl_vector (context, &
2022-11-16 17:54:59 +01:00
type_nucl_vector, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context), intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
integer(c_int64_t), intent(out) :: type_nucl_vector(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_type_nucl_vector
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_a_vector(context, &
2022-11-16 17:54:59 +01:00
a_vector, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: a_vector(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_a_vector
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_b_vector(context, &
2022-11-16 17:54:59 +01:00
b_vector, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: b_vector(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_b_vector
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_c_vector(context, &
2022-11-16 17:54:59 +01:00
c_vector, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: c_vector(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_c_vector
2023-03-13 15:32:35 +01:00
2022-11-16 17:54:59 +01:00
end interface
#+end_src
** Test
#+begin_src c :tangle (eval c_test)
/* Reference input data */
int64_t walk_num = n2_walk_num;
int64_t elec_num = n2_elec_num;
int64_t elec_up_num = n2_elec_up_num;
int64_t elec_dn_num = n2_elec_dn_num;
int64_t nucl_num = n2_nucl_num;
double rescale_factor_ee = 1.0;
double rescale_factor_en[2] = { 1.0, 1.0 };
double* elec_coord = &(n2_elec_coord[0][0][0]);
const double* nucl_charge = n2_charge;
double* nucl_coord = &(n2_nucl_coord[0][0]);
int64_t size_max;
/* Provide Electron data */
qmckl_exit_code rc;
assert(!qmckl_electron_provided(context));
rc = qmckl_check(context,
qmckl_set_electron_num (context, elec_up_num, elec_dn_num)
);
assert(rc == QMCKL_SUCCESS);
assert(qmckl_electron_provided(context));
2021-07-07 16:16:18 +02:00
rc = qmckl_check(context,
qmckl_set_electron_coord (context, 'N', walk_num, elec_coord, walk_num*3*elec_num)
);
2021-07-07 16:16:18 +02:00
assert(rc == QMCKL_SUCCESS);
double elec_coord2[walk_num*3*elec_num];
rc = qmckl_check(context,
qmckl_get_electron_coord (context, 'N', elec_coord2, walk_num*3*elec_num)
);
2021-07-07 16:16:18 +02:00
assert(rc == QMCKL_SUCCESS);
for (int64_t i=0 ; i<3*elec_num ; ++i) {
assert( elec_coord[i] == elec_coord2[i] );
}
/* Provide Nucleus data */
assert(!qmckl_nucleus_provided(context));
rc = qmckl_check(context,
qmckl_set_nucleus_num (context, nucl_num)
);
2021-07-07 16:16:18 +02:00
assert(rc == QMCKL_SUCCESS);
assert(!qmckl_nucleus_provided(context));
double nucl_coord2[3*nucl_num];
2022-01-23 16:18:46 +01:00
rc = qmckl_get_nucleus_coord (context, 'T', nucl_coord2, 3*nucl_num);
2021-07-07 16:16:18 +02:00
assert(rc == QMCKL_NOT_PROVIDED);
rc = qmckl_check(context,
qmckl_set_nucleus_coord (context, 'T', &(nucl_coord[0]), 3*nucl_num)
);
2021-07-07 16:16:18 +02:00
assert(rc == QMCKL_SUCCESS);
assert(!qmckl_nucleus_provided(context));
rc = qmckl_check(context,
qmckl_get_nucleus_coord (context, 'N', nucl_coord2, nucl_num*3)
);
2021-07-07 16:16:18 +02:00
assert(rc == QMCKL_SUCCESS);
2021-07-08 06:58:15 +02:00
for (int64_t k=0 ; k<3 ; ++k) {
for (int64_t i=0 ; i<nucl_num ; ++i) {
2021-07-07 16:16:18 +02:00
assert( nucl_coord[nucl_num*k+i] == nucl_coord2[3*i+k] );
}
}
rc = qmckl_check(context,
qmckl_get_nucleus_coord (context, 'T', nucl_coord2, nucl_num*3)
);
2021-07-07 16:16:18 +02:00
assert(rc == QMCKL_SUCCESS);
2021-07-08 06:58:15 +02:00
for (int64_t i=0 ; i<3*nucl_num ; ++i) {
2021-07-07 16:16:18 +02:00
assert( nucl_coord[i] == nucl_coord2[i] );
}
double nucl_charge2[nucl_num];
2022-01-23 16:18:46 +01:00
rc = qmckl_get_nucleus_charge(context, nucl_charge2, nucl_num);
2021-07-07 16:16:18 +02:00
assert(rc == QMCKL_NOT_PROVIDED);
rc = qmckl_check(context,
qmckl_set_nucleus_charge(context, nucl_charge, nucl_num)
);
2021-07-07 16:16:18 +02:00
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
qmckl_get_nucleus_charge(context, nucl_charge2, nucl_num)
);
2021-07-07 16:16:18 +02:00
assert(rc == QMCKL_SUCCESS);
2021-07-08 06:58:15 +02:00
for (int64_t i=0 ; i<nucl_num ; ++i) {
2021-07-07 16:16:18 +02:00
assert( nucl_charge[i] == nucl_charge2[i] );
}
assert(qmckl_nucleus_provided(context));
#+end_src
2022-01-31 16:47:28 +01:00
* Computation
The computed data is stored in the context so that it can be reused
by different kernels. To ensure that the data is valid, for each
computed data the date of the context is stored when it is computed.
To know if some data needs to be recomputed, we check if the date of
the dependencies are more recent than the date of the data to
compute. If it is the case, then the data is recomputed and the
current date is stored.
2022-01-31 16:47:28 +01:00
2023-03-31 14:41:32 +02:00
2023-03-30 12:34:17 +02:00
** Electron-electron component
*** Asymptotic component
2023-03-30 12:34:17 +02:00
Calculate the asymptotic component ~asymp_jasb~ to be substracted from the
electron-electron jastrow factor \(J_{\text{ee}}\). Two values are
computed. The first one is for antiparallel spin pairs, and the
second one for parallel spin pairs.
2023-03-30 12:34:17 +02:00
\[
J_{\text{ee}}^{\infty} = \frac{\frac{1}{2}(1+\delta^{\uparrow \downarrow})\,b_1 \kappa_\text{ee}^{-1}}{1 + b_2\,
\kappa_\text{ee}^{-1}} + \sum_{p=2}^{N_\text{ord}^b} b_{p+1}\, \kappa_\text{ee}^{-p}
\]
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
**** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_asymp_jasb(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const asymp_jasb,
const int64_t size_max);
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_asymp_jasb(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const asymp_jasb,
const int64_t size_max)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2022-11-16 17:54:59 +01:00
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_asymp_jasb",
2022-11-16 17:54:59 +01:00
NULL);
}
2022-11-17 19:20:12 +01:00
/* Provided in finalize_jastrow */
/*
2022-11-18 09:28:13 +01:00
qmckl_exit_code rc;
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_asymp_jasb(context);
2022-11-17 19:20:12 +01:00
if(rc != QMCKL_SUCCESS) return rc;
*/
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2022-02-16 15:14:41 +01:00
int64_t sze = 2;
2022-02-14 19:11:37 +01:00
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_asymp_jasb",
2022-02-14 19:11:37 +01:00
"Array too small. Expected 2");
}
2023-03-30 17:07:11 +02:00
memcpy(asymp_jasb, ctx->jastrow_champ.asymp_jasb, sze * sizeof(double));
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
***** Fortran interface
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src f90 :tangle (eval fh_func) :comments org
2022-11-17 15:45:22 +01:00
interface
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_asymp_jasb(context, &
2022-11-17 15:45:22 +01:00
asymp_jasb, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: asymp_jasb(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_asymp_jasb
2022-11-17 15:45:22 +01:00
end interface
2023-03-30 12:34:17 +02:00
#+end_src
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_asymp_jasb(qmckl_context context);
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_asymp_jasb(qmckl_context context)
{
qmckl_exit_code rc;
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2022-11-16 17:54:59 +01:00
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_asymp_jasb",
2022-11-16 17:54:59 +01:00
NULL);
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
if (!ctx->jastrow_champ.provided) {
2022-11-16 17:54:59 +01:00
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_asymp_jasb",
2022-11-16 17:54:59 +01:00
NULL);
}
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.asymp_jasb_date) {
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.asymp_jasb == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = 2 * sizeof(double);
double* asymp_jasb = (double*) qmckl_malloc(context, mem_info);
if (asymp_jasb == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_asymp_jasb",
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.asymp_jasb = asymp_jasb;
}
2023-03-30 17:07:11 +02:00
rc = qmckl_compute_jastrow_champ_asymp_jasb(context,
ctx->jastrow_champ.bord_num,
ctx->jastrow_champ.b_vector,
ctx->jastrow_champ.rescale_factor_ee,
ctx->jastrow_champ.asymp_jasb);
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.asymp_jasb_date = ctx->date;
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
2023-03-30 17:07:11 +02:00
:Name: qmckl_compute_jastrow_champ_asymp_jasb
2023-03-30 12:34:17 +02:00
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
2023-03-30 12:34:17 +02:00
#+NAME: qmckl_asymp_jasb_args
| Variable | Type | In/Out | Description |
|---------------------+----------------------+--------+-------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~bord_num~ | ~int64_t~ | in | Order of the polynomial |
| ~b_vector~ | ~double[bord_num+1]~ | in | Values of b |
| ~rescale_factor_ee~ | ~double~ | in | Electron coordinates |
| ~asymp_jasb~ | ~double[2]~ | out | Asymptotic value |
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_interface(table=qmckl_asymp_jasb_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-01 15:36:49 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src f90 :tangle (eval f) :comments org :exports none
2023-03-30 17:07:11 +02:00
integer(c_int32_t) function qmckl_compute_jastrow_champ_asymp_jasb_doc &
2023-03-01 15:36:49 +01:00
(context, bord_num, b_vector, rescale_factor_ee, asymp_jasb) &
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 :: bord_num
real (c_double ) , intent(in) :: b_vector(bord_num+1)
real (c_double ) , intent(in) , value :: rescale_factor_ee
real (c_double ) , intent(out) :: asymp_jasb(2)
2023-03-30 17:07:11 +02:00
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_asymp_jasb_doc_f
info = qmckl_compute_jastrow_champ_asymp_jasb_doc_f &
2023-03-01 15:36:49 +01:00
(context, bord_num, b_vector, rescale_factor_ee, asymp_jasb)
2023-03-30 17:07:11 +02:00
end function qmckl_compute_jastrow_champ_asymp_jasb_doc
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-01 15:36:49 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2023-03-30 17:07:11 +02:00
integer function qmckl_compute_jastrow_champ_asymp_jasb_doc_f(context, bord_num, b_vector, rescale_factor_ee, asymp_jasb) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: bord_num
2022-11-16 11:58:44 +01:00
double precision , intent(in) :: b_vector(bord_num + 1)
double precision , intent(in) :: rescale_factor_ee
double precision , intent(out) :: asymp_jasb(2)
integer*8 :: i, p
double precision :: kappa_inv, x, asym_one
kappa_inv = 1.0d0 / rescale_factor_ee
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2022-11-16 17:54:59 +01:00
if (bord_num < 0) then
info = QMCKL_INVALID_ARG_2
return
endif
2022-11-16 11:58:44 +01:00
asym_one = b_vector(1) * kappa_inv / (1.0d0 + b_vector(2) * kappa_inv)
asymp_jasb(:) = (/asym_one, 0.5d0 * asym_one/)
2022-01-31 16:47:28 +01:00
do i = 1, 2
x = kappa_inv
do p = 2, bord_num
x = x * kappa_inv
2022-11-16 11:58:44 +01:00
asymp_jasb(i) = asymp_jasb(i) + b_vector(p + 1) * x
end do
end do
2023-03-30 17:07:11 +02:00
end function qmckl_compute_jastrow_champ_asymp_jasb_doc_f
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_asymp_jasb_doc (const qmckl_context context,
2023-03-01 15:36:49 +01:00
const int64_t bord_num,
const double* b_vector,
const double rescale_factor_ee,
double* const asymp_jasb );
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-13 15:32:35 +01:00
2022-02-03 18:53:04 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_asymp_jasb_hpc (const qmckl_context context,
2023-03-01 15:36:49 +01:00
const int64_t bord_num,
const double* b_vector,
const double rescale_factor_ee,
double* const asymp_jasb );
2023-03-30 12:34:17 +02:00
#+end_src
2022-02-02 16:37:26 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2023-03-01 15:36:49 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_compute_jastrow_champ_asymp_jasb_hpc (const qmckl_context context,
2023-03-01 15:36:49 +01:00
const int64_t bord_num,
const double* b_vector,
const double rescale_factor_ee,
double* const asymp_jasb )
{
if (context == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
}
2023-03-01 15:36:49 +01:00
if (bord_num < 0) {
return QMCKL_INVALID_ARG_2;
}
2022-02-02 16:37:26 +01:00
2023-03-01 15:36:49 +01:00
const double kappa_inv = 1.0 / rescale_factor_ee;
const double asym_one = b_vector[0] * kappa_inv / (1.0 + b_vector[1] * kappa_inv);
asymp_jasb[0] = asym_one;
asymp_jasb[1] = 0.5 * asym_one;
for (int i = 0 ; i<2 ; ++i) {
double x = kappa_inv;
for (int p = 1; p < bord_num; ++p) {
x *= kappa_inv;
asymp_jasb[i] += b_vector[p+1]*x;
2022-02-14 19:11:37 +01:00
}
2023-03-01 15:36:49 +01:00
}
2022-02-02 16:37:26 +01:00
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-27 16:35:39 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_asymp_jasb (const qmckl_context context,
2023-03-01 15:36:49 +01:00
const int64_t bord_num,
const double* b_vector,
const double rescale_factor_ee,
double* const asymp_jasb );
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_asymp_jasb (
2023-03-01 15:36:49 +01:00
const qmckl_context context,
const int64_t bord_num,
const double* b_vector,
const double rescale_factor_ee,
double* const asymp_jasb )
{
#ifdef HAVE_HPC
2023-03-30 17:07:11 +02:00
return qmckl_compute_jastrow_champ_asymp_jasb_hpc (context,
2023-03-01 15:36:49 +01:00
bord_num, b_vector, rescale_factor_ee, asymp_jasb);
#else
2023-03-30 17:07:11 +02:00
return qmckl_compute_jastrow_champ_asymp_jasb_doc (context,
2023-03-01 15:36:49 +01:00
bord_num, b_vector, rescale_factor_ee, asymp_jasb);
#endif
}
2023-03-30 12:34:17 +02:00
#+end_src
**** Test
#+name: asymp_jasb
#+begin_src python :results output :exports none :noweb yes
import numpy as np
<<jastrow_data>>
2022-11-16 11:58:44 +01:00
asym_one = b_vector[0] * kappa_inv / (1.0 + b_vector[1]*kappa_inv)
asymp_jasb = np.array([asym_one, 0.5 * asym_one])
for i in range(2):
x = kappa_inv
for p in range(1,bord_num):
x = x * kappa_inv
2022-11-16 11:58:44 +01:00
asymp_jasb[i] += b_vector[p + 1] * x
print("asym_one : ", asym_one)
print("asymp_jasb[0] : ", asymp_jasb[0])
print("asymp_jasb[1] : ", asymp_jasb[1])
2023-03-30 12:34:17 +02:00
#+end_src
2022-02-14 19:11:37 +01:00
2023-03-30 12:34:17 +02:00
#+RESULTS: asymp_jasb
: asym_one : 0.43340325572525706
: asymp_jasb[0] : 0.5323750557252571
: asymp_jasb[1] : 0.31567342786262853
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval c_test)
2021-07-07 17:00:19 +02:00
assert(qmckl_electron_provided(context));
int64_t type_nucl_num = n2_type_nucl_num;
int64_t* type_nucl_vector = &(n2_type_nucl_vector[0]);
int64_t aord_num = n2_aord_num;
int64_t bord_num = n2_bord_num;
int64_t cord_num = n2_cord_num;
2022-11-16 11:58:44 +01:00
double* a_vector = &(n2_a_vector[0][0]);
double* b_vector = &(n2_b_vector[0]);
double* c_vector = &(n2_c_vector[0][0]);
int64_t dim_c_vector=0;
2021-07-07 17:00:19 +02:00
2023-03-30 17:07:11 +02:00
assert(!qmckl_jastrow_champ_provided(context));
2021-07-07 17:15:55 +02:00
/* Set the data */
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_aord_num(context, aord_num)
);
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_bord_num(context, bord_num)
);
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_cord_num(context, cord_num)
);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_type_nucl_num(context, type_nucl_num)
);
2021-07-07 17:15:55 +02:00
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_type_nucl_vector(context, type_nucl_vector, nucl_num)
);
2021-07-07 17:15:55 +02:00
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_a_vector(context, a_vector,(aord_num+1)*type_nucl_num)
);
2021-07-07 17:15:55 +02:00
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_b_vector(context, b_vector,(bord_num+1))
);
2021-07-07 17:15:55 +02:00
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_dim_c_vector(context, &dim_c_vector)
);
2021-07-07 17:15:55 +02:00
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_c_vector(context, c_vector,dim_c_vector*type_nucl_num)
);
assert(rc == QMCKL_SUCCESS);
double k_ee = 0.;
double k_en[2] = { 0., 0. };
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_rescale_factor_en(context, rescale_factor_en, type_nucl_num)
);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_set_jastrow_champ_rescale_factor_ee(context, rescale_factor_ee)
);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_rescale_factor_ee (context, &k_ee)
);
assert(rc == QMCKL_SUCCESS);
assert(k_ee == rescale_factor_ee);
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_rescale_factor_en (context, &(k_en[0]), type_nucl_num)
);
2021-07-07 17:15:55 +02:00
assert(rc == QMCKL_SUCCESS);
for (int i=0 ; i<type_nucl_num ; ++i) {
assert(k_en[i] == rescale_factor_en[i]);
}
2021-07-07 17:15:55 +02:00
/* Check if Jastrow is properly initialized */
2023-03-30 17:07:11 +02:00
assert(qmckl_jastrow_champ_provided(context));
2021-07-07 17:18:49 +02:00
double asymp_jasb[2];
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_asymp_jasb(context, asymp_jasb,2);
2021-07-07 17:18:49 +02:00
// calculate asymp_jasb
assert(fabs(asymp_jasb[0]-0.5323750557252571) < 1.e-12);
assert(fabs(asymp_jasb[1]-0.31567342786262853) < 1.e-12);
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
*** Electron-electron component
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
Calculate the electron-electron jastrow component ~factor_ee~ using the ~asymp_jasb~
component and the electron-electron rescaled distances ~ee_distance_rescaled~.
2021-07-05 15:02:05 +02:00
2023-03-30 12:34:17 +02:00
\[
f_\text{ee} = \sum_{i,j<i} \left[
\frac{\delta_{ij}^{\uparrow\downarrow} B_0\, C_{ij}}{1 - B_1\,
C_{ij}} + \sum_{k=2}^{n_\text{ord}} B_k\, C_{ij}^k - {J_{\text{ee}}^{\infty}}_{ij} \right]
\]
2021-07-05 15:02:05 +02:00
2023-03-30 12:34:17 +02:00
$\delta$ is the spin factor, $B$ is the vector of $b$ parameters,
$C$ is the array of rescaled distances.
2022-11-16 11:58:44 +01:00
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
**** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_factor_ee(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const factor_ee,
const int64_t size_max);
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 15:02:05 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_factor_ee(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const factor_ee,
const int64_t size_max)
2021-07-05 15:02:05 +02:00
{
qmckl_exit_code rc;
2022-11-16 17:54:59 +01:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_factor_ee",
2022-11-16 17:54:59 +01:00
NULL);
}
2021-07-05 15:02:05 +02:00
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-07-05 15:02:05 +02:00
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_factor_ee(context);
2022-11-16 17:54:59 +01:00
if (rc != QMCKL_SUCCESS) return rc;
2022-08-07 14:57:10 +02:00
int64_t sze=ctx->electron.walker.num;
2022-02-14 19:11:37 +01:00
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_factor_ee",
2022-08-07 14:57:10 +02:00
"Array too small. Expected walker.num");
2022-02-14 19:11:37 +01:00
}
2023-03-30 17:07:11 +02:00
memcpy(factor_ee, ctx->jastrow_champ.factor_ee, sze*sizeof(double));
2021-07-05 15:02:05 +02:00
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 15:02:05 +02:00
2023-03-30 12:34:17 +02:00
***** Fortran interface
2022-11-16 17:54:59 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src f90 :tangle (eval fh_func) :comments org
2022-11-16 17:54:59 +01:00
interface
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_factor_ee (context, &
2022-11-16 17:54:59 +01:00
factor_ee, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: factor_ee(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_factor_ee
2022-11-16 17:54:59 +01:00
end interface
2023-03-30 12:34:17 +02:00
#+end_src
2022-11-16 17:54:59 +01:00
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_factor_ee(qmckl_context context);
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_factor_ee(qmckl_context context)
2021-07-05 15:02:05 +02:00
{
qmckl_exit_code rc;
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2022-11-16 17:54:59 +01:00
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_ee",
2022-11-16 17:54:59 +01:00
NULL);
2021-07-05 15:02:05 +02:00
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-07-05 15:02:05 +02:00
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
if (!ctx->jastrow_champ.provided) {
2022-11-16 17:54:59 +01:00
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_ee",
2022-11-16 17:54:59 +01:00
NULL);
}
2021-07-05 15:02:05 +02:00
rc = qmckl_provide_ee_distance_rescaled(context);
if(rc != QMCKL_SUCCESS) return rc;
2022-11-17 19:20:12 +01:00
/* Provided in finalize_jastrow */
/*
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_asymp_jasb(context);
2022-11-16 11:58:44 +01:00
if(rc != QMCKL_SUCCESS) return rc;
2022-11-17 19:20:12 +01:00
*/
2022-11-16 11:58:44 +01:00
2021-07-05 15:02:05 +02:00
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.factor_ee_date) {
2021-07-05 15:02:05 +02:00
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.factor_ee != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.factor_ee);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_ee",
"Unable to free ctx->jastrow_champ.factor_ee");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_ee = NULL;
}
2022-08-07 14:57:10 +02:00
}
2023-03-13 15:32:35 +01:00
2021-07-05 15:02:05 +02:00
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.factor_ee == NULL) {
2021-07-05 15:02:05 +02:00
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2022-08-07 14:57:10 +02:00
mem_info.size = ctx->electron.walker.num * sizeof(double);
2021-07-05 15:02:05 +02:00
double* factor_ee = (double*) qmckl_malloc(context, mem_info);
if (factor_ee == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_ee",
2021-07-05 15:02:05 +02:00
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_ee = factor_ee;
2021-07-05 15:02:05 +02:00
}
2022-01-31 16:47:28 +01:00
2023-03-31 13:37:35 +02:00
rc = qmckl_compute_jastrow_champ_factor_ee(context,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
2022-04-05 11:44:17 +02:00
ctx->electron.num,
ctx->electron.up_num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.bord_num,
ctx->jastrow_champ.b_vector,
ctx->jastrow_champ.ee_distance_rescaled,
ctx->jastrow_champ.asymp_jasb,
ctx->jastrow_champ.factor_ee);
2021-07-05 15:02:05 +02:00
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_ee_date = ctx->date;
2021-07-05 15:02:05 +02:00
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 15:02:05 +02:00
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
2023-03-31 13:37:35 +02:00
:Name: qmckl_compute_jastrow_champ_factor_ee
2023-03-30 12:34:17 +02:00
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_ee_args
2023-03-30 18:17:33 +02:00
| Variable | Type | In/Out | Description |
|------------------------+----------------------------------------+--------+---------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~up_num~ | ~int64_t~ | in | Number of alpha electrons |
| ~bord_num~ | ~int64_t~ | in | Number of coefficients |
| ~b_vector~ | ~double[bord_num+1]~ | in | List of coefficients |
| ~ee_distance_rescaled~ | ~double[walk_num][elec_num][elec_num]~ | in | Electron-electron distances |
| ~asymp_jasb~ | ~double[2]~ | in | Asymptotic value of the Jastrow |
| ~factor_ee~ | ~double[walk_num]~ | out | $f_{ee}$ |
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_interface(table=qmckl_factor_ee_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2023-03-31 13:37:35 +02:00
integer function qmckl_compute_jastrow_champ_factor_ee_doc_f(context, walk_num, elec_num, up_num, bord_num, &
2022-11-16 11:58:44 +01:00
b_vector, ee_distance_rescaled, asymp_jasb, factor_ee) &
2021-07-05 15:02:05 +02:00
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: walk_num, elec_num, bord_num, up_num
2022-11-16 11:58:44 +01:00
double precision , intent(in) :: b_vector(bord_num + 1)
double precision , intent(in) :: ee_distance_rescaled(elec_num, elec_num, walk_num)
2021-07-05 15:02:05 +02:00
double precision , intent(in) :: asymp_jasb(2)
double precision , intent(out) :: factor_ee(walk_num)
integer*8 :: i, j, p, ipar, nw
2022-04-04 16:56:33 +02:00
double precision :: x, power_ser, spin_fact
2021-07-05 15:02:05 +02:00
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2023-03-13 15:32:35 +01:00
2021-07-05 15:02:05 +02:00
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
2023-03-13 15:32:35 +01:00
2021-07-05 15:02:05 +02:00
if (elec_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
2023-03-13 15:32:35 +01:00
2022-11-16 17:54:59 +01:00
if (bord_num < 0) then
2021-07-05 15:02:05 +02:00
info = QMCKL_INVALID_ARG_4
return
endif
2023-03-13 15:32:35 +01:00
2021-07-05 15:02:05 +02:00
factor_ee = 0.0d0
2023-03-13 15:32:35 +01:00
2021-07-05 15:02:05 +02:00
do nw =1, walk_num
2022-11-16 11:58:44 +01:00
do j = 1, elec_num
do i = 1, j - 1
x = ee_distance_rescaled(i,j,nw)
power_ser = 0.0d0
spin_fact = 1.0d0
ipar = 1
2023-03-13 15:32:35 +01:00
2022-11-16 11:58:44 +01:00
do p = 2, bord_num
x = x * ee_distance_rescaled(i,j,nw)
power_ser = power_ser + b_vector(p + 1) * x
end do
2023-03-13 15:32:35 +01:00
2022-11-16 11:58:44 +01:00
if(j <= up_num .or. i > up_num) then
spin_fact = 0.5d0
ipar = 2
endif
2023-03-13 15:32:35 +01:00
2022-11-16 11:58:44 +01:00
factor_ee(nw) = factor_ee(nw) + spin_fact * b_vector(1) * &
ee_distance_rescaled(i,j,nw) / &
(1.0d0 + b_vector(2) * &
ee_distance_rescaled(i,j,nw)) &
2023-03-13 15:32:35 +01:00
+ power_ser - asymp_jasb(ipar)
2021-07-05 15:02:05 +02:00
end do
end do
end do
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_ee_doc_f
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 15:02:05 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src f90 :tangle (eval f) :comments org :exports none
2023-03-31 13:37:35 +02:00
integer(c_int32_t) function qmckl_compute_jastrow_champ_factor_ee_doc &
2023-03-01 15:36:49 +01:00
(context, walk_num, elec_num, up_num, bord_num, b_vector, ee_distance_rescaled, asymp_jasb, factor_ee) &
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 :: up_num
integer (c_int64_t) , intent(in) , value :: bord_num
real (c_double ) , intent(in) :: b_vector(bord_num+1)
real (c_double ) , intent(in) :: ee_distance_rescaled(elec_num,elec_num,walk_num)
real (c_double ) , intent(in) :: asymp_jasb(2)
real (c_double ) , intent(out) :: factor_ee(walk_num)
2023-03-31 13:37:35 +02:00
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_factor_ee_doc_f
info = qmckl_compute_jastrow_champ_factor_ee_doc_f &
2023-03-01 15:36:49 +01:00
(context, walk_num, elec_num, up_num, bord_num, b_vector, ee_distance_rescaled, asymp_jasb, factor_ee)
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_ee_doc
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-01 15:36:49 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_ee_doc (
2023-03-01 15:36:49 +01:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t up_num,
const int64_t bord_num,
const double* b_vector,
const double* ee_distance_rescaled,
const double* asymp_jasb,
double* const factor_ee );
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-01 15:36:49 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_ee_hpc (
2023-03-01 15:36:49 +01:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t up_num,
const int64_t bord_num,
const double* b_vector,
const double* ee_distance_rescaled,
const double* asymp_jasb,
double* const factor_ee );
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-01 15:36:49 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_ee_hpc (
2022-04-06 10:42:00 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t up_num,
const int64_t bord_num,
2022-11-16 11:58:44 +01:00
const double* b_vector,
2022-04-06 10:42:00 +02:00
const double* ee_distance_rescaled,
const double* asymp_jasb,
double* const factor_ee ) {
2022-04-08 10:44:48 +02:00
if (context == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
2022-04-08 10:44:48 +02:00
}
if (walk_num <= 0) {
return QMCKL_INVALID_ARG_2;
}
2022-04-08 10:44:48 +02:00
if (elec_num <= 0) {
return QMCKL_INVALID_ARG_3;
2022-04-08 10:44:48 +02:00
}
2022-11-16 17:54:59 +01:00
if (bord_num < 0) {
return QMCKL_INVALID_ARG_4;
2022-04-08 10:44:48 +02:00
}
for (int nw = 0; nw < walk_num; ++nw) {
factor_ee[nw] = 0.0; // put init array here.
2023-03-07 14:42:54 +01:00
size_t ishift = nw * elec_num * elec_num;
for (int i = 0; i < elec_num; ++i ) {
for (int j = 0; j < i; ++j) {
2023-03-31 19:58:30 +02:00
double x = ee_distance_rescaled[j + i * elec_num + ishift];
const double x1 = x;
double power_ser = 0.0;
double spin_fact = 1.0;
int ipar = 0; // index of asymp_jasb
2022-04-08 10:44:48 +02:00
for (int p = 1; p < bord_num; ++p) {
x = x * x1;
2023-03-07 14:42:54 +01:00
power_ser += b_vector[p + 1] * x;
}
if(i < up_num || j >= up_num) {
spin_fact = 0.5;
ipar = 1;
}
2022-04-08 10:44:48 +02:00
2023-03-13 15:32:35 +01:00
factor_ee[nw] += spin_fact * b_vector[0] *
x1 / (1.0 + b_vector[1] * x1)
2022-11-16 11:58:44 +01:00
- asymp_jasb[ipar] + power_ser;
}
}
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_ee_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2022-04-08 10:44:48 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_ee (
2022-04-06 16:26:35 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t up_num,
const int64_t bord_num,
2022-11-16 11:58:44 +01:00
const double* b_vector,
2022-04-06 16:26:35 +02:00
const double* ee_distance_rescaled,
const double* asymp_jasb,
2022-04-08 10:44:48 +02:00
double* const factor_ee );
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 15:02:05 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2023-03-01 15:36:49 +01:00
qmckl_exit_code
2023-03-31 13:37:35 +02:00
qmckl_compute_jastrow_champ_factor_ee (const qmckl_context context,
2023-03-01 15:36:49 +01:00
const int64_t walk_num,
const int64_t elec_num,
const int64_t up_num,
const int64_t bord_num,
const double* b_vector,
const double* ee_distance_rescaled,
const double* asymp_jasb,
double* const factor_ee )
{
#ifdef HAVE_HPC
2023-03-31 13:37:35 +02:00
return qmckl_compute_jastrow_champ_factor_ee_hpc(context, walk_num, elec_num,
2023-03-01 15:36:49 +01:00
up_num, bord_num, b_vector, ee_distance_rescaled, asymp_jasb,
factor_ee);
#else
2023-03-31 13:37:35 +02:00
return qmckl_compute_jastrow_champ_factor_ee_doc(context, walk_num, elec_num,
2023-03-01 15:36:49 +01:00
up_num, bord_num, b_vector, ee_distance_rescaled, asymp_jasb,
factor_ee);
#endif
}
2023-03-30 12:34:17 +02:00
#+end_src
**** Test
#+begin_src python :results output :exports none :noweb yes
2021-07-05 15:02:05 +02:00
import numpy as np
<<jastrow_data>>
<<asymp_jasb>>
factor_ee = 0.0
for i in range(0,elec_num):
for j in range(0,i):
x = ee_distance_rescaled[i][j]
pow_ser = 0.0
spin_fact = 1.0
ipar = 0
2022-01-31 16:47:28 +01:00
2021-07-05 15:02:05 +02:00
for p in range(1,bord_num):
x = x * ee_distance_rescaled[i][j]
2022-11-16 11:58:44 +01:00
pow_ser = pow_ser + b_vector[p + 1] * x
2021-07-05 15:02:05 +02:00
if(i < up_num or j >= up_num):
spin_fact = 0.5
ipar = 1
2022-01-31 16:47:28 +01:00
2022-11-16 11:58:44 +01:00
factor_ee = factor_ee + spin_fact * b_vector[0] * ee_distance_rescaled[i][j] \
/ (1.0 + b_vector[1] * ee_distance_rescaled[i][j]) \
2021-07-05 15:02:05 +02:00
- asymp_jasb[ipar] + pow_ser
print("factor_ee :",factor_ee)
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 15:02:05 +02:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
: asym_one : 0.43340325572525706
: asymp_jasb[0] : 0.5323750557252571
: asymp_jasb[1] : 0.31567342786262853
: factor_ee : -4.282760865958113
2022-01-31 16:47:28 +01:00
2021-07-05 15:02:05 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval c_test)
2021-07-07 18:32:27 +02:00
/* Check if Jastrow is properly initialized */
2023-03-30 17:07:11 +02:00
assert(qmckl_jastrow_champ_provided(context));
2021-07-08 08:11:32 +02:00
double factor_ee[walk_num];
rc = qmckl_check(context,
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_factor_ee(context, factor_ee, walk_num)
);
2021-07-08 08:11:32 +02:00
// calculate factor_ee
printf("%e\n%e\n\n",factor_ee[0],-4.282760865958113 );
2021-07-08 08:11:32 +02:00
assert(fabs(factor_ee[0]+4.282760865958113) < 1.e-12);
2021-07-05 15:02:05 +02:00
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
*** Derivative
2021-07-05 19:28:04 +02:00
2023-03-30 12:34:17 +02:00
The derivative of ~factor_ee~ is computed using the ~ee_distance_rescaled~ and
the electron-electron rescaled distances derivatives ~ee_distance_rescaled_deriv_e~.
There are four components, the gradient which has 3 components in the \(x, y, z\)
directions and the laplacian as the last component.
2021-07-05 19:28:04 +02:00
2023-03-30 12:34:17 +02:00
\[ \nabla_i f_\text{ee} = \frac{1}{2}\sum_{j}
\left[\frac{\delta_{ij}^{\uparrow\downarrow} B_0\, \nabla_i
C_{ij}}{(1 - B_1\, C_{ij})^2} + \sum^{n_\text{ord}}_{k=2}
B_k\, k\, C_{ij}^{k-1} \nabla C_{ij} \right] \]
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
# TODO Formula for Laplacian
**** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_factor_ee_deriv_e(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const factor_ee_deriv_e,
const int64_t size_max);
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 19:28:04 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_factor_ee_deriv_e(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const factor_ee_deriv_e,
const int64_t size_max)
2021-07-05 19:28:04 +02:00
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_factor_ee_deriv_e(context);
2021-07-05 19:28:04 +02:00
if (rc != QMCKL_SUCCESS) return rc;
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-07-05 19:28:04 +02:00
assert (ctx != NULL);
2022-08-07 14:57:10 +02:00
int64_t sze = ctx->electron.walker.num * 4 * ctx->electron.num;
2022-02-14 19:11:37 +01:00
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_factor_ee_deriv_e",
2022-02-14 19:11:37 +01:00
"Array too small. Expected 4*walk_num*elec_num");
}
2023-03-30 17:07:11 +02:00
memcpy(factor_ee_deriv_e, ctx->jastrow_champ.factor_ee_deriv_e, sze * sizeof(double));
2021-07-05 19:28:04 +02:00
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 19:28:04 +02:00
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_factor_ee_deriv_e(qmckl_context context);
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_factor_ee_deriv_e(qmckl_context context)
2021-07-05 19:28:04 +02:00
{
qmckl_exit_code rc;
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2022-11-16 17:54:59 +01:00
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_ee_deriv_e",
2022-11-16 17:54:59 +01:00
NULL);
2021-07-05 19:28:04 +02:00
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-07-05 19:28:04 +02:00
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
if (!ctx->jastrow_champ.provided) {
2022-11-16 17:54:59 +01:00
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_ee_deriv_e",
2022-11-16 17:54:59 +01:00
NULL);
}
2021-07-05 19:28:04 +02:00
/* Check if ee rescaled distance is provided */
rc = qmckl_provide_ee_distance_rescaled(context);
if(rc != QMCKL_SUCCESS) return rc;
2021-07-06 09:27:14 +02:00
/* Check if ee rescaled distance deriv e is provided */
rc = qmckl_provide_ee_distance_rescaled_deriv_e(context);
if(rc != QMCKL_SUCCESS) return rc;
2021-07-05 19:28:04 +02:00
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.factor_ee_deriv_e_date) {
2021-07-05 19:28:04 +02:00
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.factor_ee_deriv_e != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.factor_ee_deriv_e);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_ee_deriv_e",
"Unable to free ctx->jastrow_champ.factor_ee_deriv_e");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_ee_deriv_e = NULL;
}
2022-08-07 14:57:10 +02:00
}
2023-03-13 15:32:35 +01:00
2021-07-05 19:28:04 +02:00
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.factor_ee_deriv_e == NULL) {
2021-07-05 19:28:04 +02:00
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2022-08-07 14:57:10 +02:00
mem_info.size = ctx->electron.walker.num * 4 * ctx->electron.num * sizeof(double);
2021-07-05 19:28:04 +02:00
double* factor_ee_deriv_e = (double*) qmckl_malloc(context, mem_info);
if (factor_ee_deriv_e == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_ee_deriv_e",
2021-07-05 19:28:04 +02:00
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_ee_deriv_e = factor_ee_deriv_e;
2021-07-05 19:28:04 +02:00
}
2022-01-31 16:47:28 +01:00
2023-03-31 13:37:35 +02:00
rc = qmckl_compute_jastrow_champ_factor_ee_deriv_e(context,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
2022-04-05 11:44:17 +02:00
ctx->electron.num,
ctx->electron.up_num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.bord_num,
ctx->jastrow_champ.b_vector,
ctx->jastrow_champ.ee_distance_rescaled,
ctx->jastrow_champ.ee_distance_rescaled_deriv_e,
ctx->jastrow_champ.factor_ee_deriv_e);
2021-07-05 19:28:04 +02:00
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_ee_date = ctx->date;
2021-07-05 19:28:04 +02:00
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 19:28:04 +02:00
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
2023-03-31 13:37:35 +02:00
:Name: qmckl_compute_jastrow_champ_factor_ee_deriv_e
2023-03-30 12:34:17 +02:00
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_ee_deriv_e_args
| Variable | Type | In/Out | Description |
|--------------------------------+-------------------------------------------+--------+-----------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~up_num~ | ~int64_t~ | in | Number of alpha electrons |
| ~bord_num~ | ~int64_t~ | in | Number of coefficients |
| ~b_vector~ | ~double[bord_num+1]~ | in | List of coefficients |
| ~ee_distance_rescaled~ | ~double[walk_num][elec_num][elec_num]~ | in | Electron-electron distances |
| ~ee_distance_rescaled_deriv_e~ | ~double[walk_num][4][elec_num][elec_num]~ | in | Electron-electron distances |
| ~factor_ee_deriv_e~ | ~double[walk_num][4][elec_num]~ | out | Electron-electron distances |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2023-03-31 13:37:35 +02:00
integer function qmckl_compute_jastrow_champ_factor_ee_deriv_e_doc_f( &
2022-04-04 23:53:58 +02:00
context, walk_num, elec_num, up_num, bord_num, &
2022-11-16 11:58:44 +01:00
b_vector, ee_distance_rescaled, ee_distance_rescaled_deriv_e, &
2022-04-08 10:44:48 +02:00
factor_ee_deriv_e) &
2021-07-05 19:28:04 +02:00
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: walk_num, elec_num, bord_num, up_num
2022-11-16 11:58:44 +01:00
double precision , intent(in) :: b_vector(bord_num + 1)
2022-02-11 15:27:18 +01:00
double precision , intent(in) :: ee_distance_rescaled(elec_num, elec_num,walk_num)
2022-04-04 23:53:58 +02:00
double precision , intent(in) :: ee_distance_rescaled_deriv_e(4,elec_num, elec_num,walk_num) !TODO
2021-07-06 09:27:14 +02:00
double precision , intent(out) :: factor_ee_deriv_e(elec_num,4,walk_num)
2021-07-05 19:28:04 +02:00
2022-04-08 10:44:48 +02:00
integer*8 :: i, j, p, nw, ii
2021-07-05 19:28:04 +02:00
double precision :: x, spin_fact, y
double precision :: den, invden, invden2, invden3, xinv
double precision :: lap1, lap2, lap3, third
double precision, dimension(3) :: pow_ser_g
double precision, dimension(4) :: dx
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
2022-11-16 17:54:59 +01:00
if (bord_num < 0) then
2021-07-05 19:28:04 +02:00
info = QMCKL_INVALID_ARG_4
return
endif
factor_ee_deriv_e = 0.0d0
third = 1.0d0 / 3.0d0
2022-01-31 16:47:28 +01:00
2021-07-05 19:28:04 +02:00
do nw =1, walk_num
do j = 1, elec_num
do i = 1, elec_num
2022-02-11 15:27:18 +01:00
x = ee_distance_rescaled(i,j,nw)
2021-07-06 09:27:14 +02:00
if(abs(x) < 1.0d-18) cycle
2021-07-05 19:28:04 +02:00
pow_ser_g = 0.0d0
spin_fact = 1.0d0
2022-11-16 11:58:44 +01:00
den = 1.0d0 + b_vector(2) * x
2021-07-05 19:28:04 +02:00
invden = 1.0d0 / den
invden2 = invden * invden
invden3 = invden2 * invden
2021-07-06 09:27:14 +02:00
xinv = 1.0d0 / (x + 1.0d-18)
2021-07-05 19:28:04 +02:00
2022-02-11 15:37:55 +01:00
dx(1) = ee_distance_rescaled_deriv_e(1, i, j, nw)
dx(2) = ee_distance_rescaled_deriv_e(2, i, j, nw)
dx(3) = ee_distance_rescaled_deriv_e(3, i, j, nw)
2022-02-14 19:11:37 +01:00
dx(4) = ee_distance_rescaled_deriv_e(4, i, j, nw)
2021-07-05 19:28:04 +02:00
2023-03-07 14:42:54 +01:00
if((i <= up_num .and. j <= up_num ) .OR. &
(i > up_num .and. j > up_num)) then
2021-07-05 19:28:04 +02:00
spin_fact = 0.5d0
endif
2022-01-31 16:47:28 +01:00
2021-07-05 19:28:04 +02:00
lap1 = 0.0d0
lap2 = 0.0d0
lap3 = 0.0d0
do ii = 1, 3
2022-02-11 15:27:18 +01:00
x = ee_distance_rescaled(i, j, nw)
2021-07-06 09:27:14 +02:00
if(abs(x) < 1.0d-18) cycle
2021-07-05 19:28:04 +02:00
do p = 2, bord_num
2022-11-16 11:58:44 +01:00
y = p * b_vector(p + 1) * x
2021-07-05 19:28:04 +02:00
pow_ser_g(ii) = pow_ser_g(ii) + y * dx(ii)
lap1 = lap1 + (p - 1) * y * xinv * dx(ii) * dx(ii)
lap2 = lap2 + y
2022-02-11 15:27:18 +01:00
x = x * ee_distance_rescaled(i, j, nw)
2021-07-05 19:28:04 +02:00
end do
2022-01-31 16:47:28 +01:00
2022-11-16 11:58:44 +01:00
lap3 = lap3 - 2.0d0 * b_vector(2) * dx(ii) * dx(ii)
2021-07-05 19:28:04 +02:00
2023-03-05 23:38:34 +01:00
factor_ee_deriv_e( j, ii, nw) = factor_ee_deriv_e( j, ii, nw) &
+ spin_fact * b_vector(1) * dx(ii) * invden2 + pow_ser_g(ii)
2021-07-05 19:28:04 +02:00
end do
ii = 4
lap2 = lap2 * dx(ii) * third
lap3 = lap3 + den * dx(ii)
2022-11-16 11:58:44 +01:00
lap3 = lap3 * (spin_fact * b_vector(1) * invden3)
2021-07-06 09:27:14 +02:00
factor_ee_deriv_e( j, ii, nw) = factor_ee_deriv_e( j, ii, nw) + lap1 + lap2 + lap3
2021-07-05 19:28:04 +02:00
end do
end do
end do
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_ee_deriv_e_doc_f
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-08 10:44:48 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_ee_deriv_e_hpc(
2022-04-08 10:44:48 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t up_num,
const int64_t bord_num,
2022-11-16 11:58:44 +01:00
const double* b_vector,
2022-04-08 10:44:48 +02:00
const double* ee_distance_rescaled,
const double* ee_distance_rescaled_deriv_e,
double* const factor_ee_deriv_e ) {
if (context == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
2023-03-13 15:32:35 +01:00
}
2022-04-08 10:44:48 +02:00
if (walk_num <= 0) {
return QMCKL_INVALID_ARG_2;
2023-03-13 15:32:35 +01:00
}
2022-04-08 10:44:48 +02:00
if (elec_num <= 0) {
return QMCKL_INVALID_ARG_3;
}
2022-11-16 17:54:59 +01:00
if (bord_num < 0) {
2022-04-08 10:44:48 +02:00
return QMCKL_INVALID_ARG_4;
}
2023-03-13 15:32:35 +01:00
2022-04-08 10:44:48 +02:00
for (int nw = 0; nw < walk_num; ++nw) {
for (int ii = 0; ii < 4; ++ii) {
for (int j = 0; j < elec_num; ++j) {
factor_ee_deriv_e[j + ii * elec_num + nw * elec_num * 4] = 0.0;
}
}
}
2023-03-13 15:32:35 +01:00
2023-03-31 19:58:30 +02:00
const double third = 1.0 / 3.0;
2022-04-08 10:44:48 +02:00
for (int nw = 0; nw < walk_num; ++nw) {
for (int i = 0; i < elec_num; ++i) {
for (int j = 0; j < elec_num; ++j) {
2023-03-31 19:58:30 +02:00
const double x0 = ee_distance_rescaled[j + i * elec_num + nw * elec_num * elec_num];
if (fabs(x0) < 1.0e-18) continue;
double spin_fact = 1.0;
const double den = 1.0 + b_vector[1] * x0;
const double invden = 1.0 / den;
const double invden2 = invden * invden;
const double invden3 = invden2 * invden;
const double xinv = 1.0 / (x0 + 1.0e-18);
double dx[4];
2022-04-08 10:44:48 +02:00
dx[0] = ee_distance_rescaled_deriv_e[0 \
+ j * 4 + i * 4 * elec_num \
+ nw * 4 * elec_num * elec_num];
dx[1] = ee_distance_rescaled_deriv_e[1 \
+ j * 4 + i * 4 * elec_num \
+ nw * 4 * elec_num * elec_num];
dx[2] = ee_distance_rescaled_deriv_e[2 \
+ j * 4 + i * 4 * elec_num \
+ nw * 4 * elec_num * elec_num];
dx[3] = ee_distance_rescaled_deriv_e[3 \
+ j * 4 + i * 4 * elec_num \
+ nw * 4 * elec_num * elec_num];
if((i <= (up_num-1) && j <= (up_num-1) ) || (i > (up_num-1) && j > (up_num-1))) {
spin_fact = 0.5;
}
2023-03-31 19:58:30 +02:00
double lap1 = 0.0;
double lap2 = 0.0;
double lap3 = 0.0;
double pow_ser_g[3] = {0., 0., 0.};
2022-04-08 10:44:48 +02:00
for (int ii = 0; ii < 3; ++ii) {
2023-03-31 19:58:30 +02:00
double x = x0;
2022-04-08 10:44:48 +02:00
if (fabs(x) < 1.0e-18) continue;
for (int p = 2; p < bord_num+1; ++p) {
2023-03-31 19:58:30 +02:00
const double y = p * b_vector[(p-1) + 1] * x;
2022-04-08 10:44:48 +02:00
pow_ser_g[ii] = pow_ser_g[ii] + y * dx[ii];
lap1 = lap1 + (p - 1) * y * xinv * dx[ii] * dx[ii];
lap2 = lap2 + y;
x = x * ee_distance_rescaled[j + i * elec_num + nw * elec_num * elec_num];
}
2022-11-16 11:58:44 +01:00
lap3 = lap3 - 2.0 * b_vector[1] * dx[ii] * dx[ii];
2022-04-08 10:44:48 +02:00
factor_ee_deriv_e[i + ii * elec_num + nw * elec_num * 4 ] += \
2022-11-16 11:58:44 +01:00
+ spin_fact * b_vector[0] * dx[ii] * invden2 \
2022-04-08 10:44:48 +02:00
+ pow_ser_g[ii] ;
}
2023-01-26 17:55:06 +01:00
int ii = 3;
2022-04-08 10:44:48 +02:00
lap2 = lap2 * dx[ii] * third;
lap3 = lap3 + den * dx[ii];
2022-11-16 11:58:44 +01:00
lap3 = lap3 * (spin_fact * b_vector[0] * invden3);
2022-04-08 10:44:48 +02:00
factor_ee_deriv_e[i + ii*elec_num + nw * elec_num * 4] += lap1 + lap2 + lap3;
}
}
}
2023-03-13 15:32:35 +01:00
2022-04-08 10:44:48 +02:00
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 19:28:04 +02:00
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_ee_deriv_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2021-07-05 19:28:04 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_ee_deriv_e (
2022-04-06 16:26:35 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t up_num,
const int64_t bord_num,
2022-11-16 11:58:44 +01:00
const double* b_vector,
2022-04-06 16:26:35 +02:00
const double* ee_distance_rescaled,
const double* ee_distance_rescaled_deriv_e,
2022-04-08 10:44:48 +02:00
double* const factor_ee_deriv_e );
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 19:28:04 +02:00
2023-03-31 13:37:35 +02:00
#+CALL: generate_c_interface(table=qmckl_factor_ee_deriv_e_args,rettyp=get_value("CRetType"),fname="qmckl_compute_jastrow_champ_factor_ee_deriv_e_doc")
2021-07-05 19:28:04 +02:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
2023-03-31 13:37:35 +02:00
integer(c_int32_t) function qmckl_compute_jastrow_champ_factor_ee_deriv_e_doc &
2022-04-08 10:44:48 +02:00
(context, &
2022-04-06 10:42:00 +02:00
walk_num, &
elec_num, &
up_num, &
bord_num, &
2022-11-16 11:58:44 +01:00
b_vector, &
2022-04-06 10:42:00 +02:00
ee_distance_rescaled, &
ee_distance_rescaled_deriv_e, &
factor_ee_deriv_e) &
2022-04-06 16:26:35 +02:00
bind(C) result(info)
2021-07-05 19:28:04 +02:00
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 :: up_num
integer (c_int64_t) , intent(in) , value :: bord_num
2022-11-16 11:58:44 +01:00
real (c_double ) , intent(in) :: b_vector(bord_num+1)
2021-07-05 19:28:04 +02:00
real (c_double ) , intent(in) :: ee_distance_rescaled(elec_num,elec_num,walk_num)
2021-07-06 09:27:14 +02:00
real (c_double ) , intent(in) :: ee_distance_rescaled_deriv_e(elec_num,elec_num,4,walk_num)
real (c_double ) , intent(out) :: factor_ee_deriv_e(elec_num,4,walk_num)
2021-07-05 19:28:04 +02:00
2023-03-31 13:37:35 +02:00
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_factor_ee_deriv_e_doc_f
info = qmckl_compute_jastrow_champ_factor_ee_deriv_e_doc_f &
2022-04-08 10:44:48 +02:00
(context, &
2022-04-06 10:42:00 +02:00
walk_num, &
elec_num, &
up_num, &
bord_num, &
2022-11-16 11:58:44 +01:00
b_vector, &
2022-04-06 10:42:00 +02:00
ee_distance_rescaled, &
ee_distance_rescaled_deriv_e, &
factor_ee_deriv_e)
2021-07-05 19:28:04 +02:00
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_ee_deriv_e_doc
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-13 15:32:35 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval h_private_func) :comments org
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_ee_deriv_e_hpc (
2022-04-08 10:44:48 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t up_num,
const int64_t bord_num,
2022-11-16 11:58:44 +01:00
const double* b_vector,
2022-04-08 10:44:48 +02:00
const double* ee_distance_rescaled,
const double* ee_distance_rescaled_deriv_e,
double* const factor_ee_deriv_e );
2022-04-08 10:43:42 +02:00
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-08 10:44:48 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval h_private_func) :comments org
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_ee_deriv_e_doc (
2022-04-08 10:44:48 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t up_num,
const int64_t bord_num,
2022-11-16 11:58:44 +01:00
const double* b_vector,
2022-04-08 10:44:48 +02:00
const double* ee_distance_rescaled,
const double* ee_distance_rescaled_deriv_e,
double* const factor_ee_deriv_e );
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-08 10:44:48 +02:00
2022-04-08 10:43:42 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_ee_deriv_e (
2022-04-08 10:44:48 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t up_num,
const int64_t bord_num,
2022-11-16 11:58:44 +01:00
const double* b_vector,
2022-04-08 10:44:48 +02:00
const double* ee_distance_rescaled,
const double* ee_distance_rescaled_deriv_e,
double* const factor_ee_deriv_e ) {
#ifdef HAVE_HPC
2023-03-31 13:37:35 +02:00
return qmckl_compute_jastrow_champ_factor_ee_deriv_e_hpc(context, walk_num, elec_num, up_num, bord_num, b_vector, ee_distance_rescaled, ee_distance_rescaled_deriv_e, factor_ee_deriv_e );
2022-04-08 10:44:48 +02:00
#else
2023-03-31 13:37:35 +02:00
return qmckl_compute_jastrow_champ_factor_ee_deriv_e_doc(context, walk_num, elec_num, up_num, bord_num, b_vector, ee_distance_rescaled, ee_distance_rescaled_deriv_e, factor_ee_deriv_e );
2022-04-08 10:44:48 +02:00
#endif
}
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 19:28:04 +02:00
2022-04-08 10:44:48 +02:00
2023-03-30 12:34:17 +02:00
**** Test
#+begin_src python :results output :exports none :noweb yes
2021-07-05 19:28:04 +02:00
import numpy as np
<<jastrow_data>>
<<asymp_jasb>>
kappa = 1.0
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):
2021-07-06 09:27:14 +02:00
elec_dist[i, j] = np.linalg.norm(elec_coord[i] - elec_coord[j])
2021-07-05 19:28:04 +02:00
elec_dist_deriv_e = np.zeros(shape=(4,elec_num, elec_num),dtype=float)
for j in range(elec_num):
for i in range(elec_num):
rij_inv = 1.0 / elec_dist[i, j]
for ii in range(3):
2021-07-06 09:27:14 +02:00
elec_dist_deriv_e[ii, i, j] = (elec_coord[j][ii] - elec_coord[i][ii]) * rij_inv
2021-07-05 19:28:04 +02:00
elec_dist_deriv_e[3, i, j] = 2.0 * rij_inv
elec_dist_deriv_e[:, j, j] = 0.0
ee_distance_rescaled_deriv_e = np.zeros(shape=(4,elec_num,elec_num),dtype=float)
2021-07-06 09:27:14 +02:00
for j in range(elec_num):
for i in range(elec_num):
2021-07-05 19:28:04 +02:00
f = 1.0 - kappa * ee_distance_rescaled[i][j]
for ii in range(4):
ee_distance_rescaled_deriv_e[ii][i][j] = elec_dist_deriv_e[ii][i][j]
ee_distance_rescaled_deriv_e[3][i][j] = ee_distance_rescaled_deriv_e[3][i][j] + \
2021-07-06 09:27:14 +02:00
(-kappa * ee_distance_rescaled_deriv_e[0][i][j] * ee_distance_rescaled_deriv_e[0][i][j]) + \
(-kappa * ee_distance_rescaled_deriv_e[1][i][j] * ee_distance_rescaled_deriv_e[1][i][j]) + \
(-kappa * ee_distance_rescaled_deriv_e[2][i][j] * ee_distance_rescaled_deriv_e[2][i][j])
2021-07-05 19:28:04 +02:00
for ii in range(4):
ee_distance_rescaled_deriv_e[ii][i][j] = ee_distance_rescaled_deriv_e[ii][i][j] * f
third = 1.0 / 3.0
factor_ee_deriv_e = np.zeros(shape=(4,elec_num),dtype=float)
dx = np.zeros(shape=(4),dtype=float)
pow_ser_g = np.zeros(shape=(4),dtype=float)
2021-07-06 09:27:14 +02:00
for j in range(elec_num):
for i in range(elec_num):
x = ee_distance_rescaled[j][i]
if abs(x) < 1e-18:
continue
2021-07-05 19:28:04 +02:00
pow_ser_g = np.zeros(shape=(4),dtype=float)
spin_fact = 1.0
2022-11-16 11:58:44 +01:00
den = 1.0 + b_vector[1] * ee_distance_rescaled[j][i]
2021-07-05 19:28:04 +02:00
invden = 1.0 / den
invden2 = invden * invden
invden3 = invden2 * invden
2021-07-06 09:27:14 +02:00
xinv = 1.0 / (ee_distance_rescaled[j][i] + 1.0E-18)
2021-07-05 19:28:04 +02:00
ipar = 1
for ii in range(4):
dx[ii] = ee_distance_rescaled_deriv_e[ii][j][i]
2021-07-06 09:27:14 +02:00
if((i <= (up_num-1) and j <= (up_num-1) ) or \
(i > (up_num-1) and j > (up_num-1))):
2021-07-05 19:28:04 +02:00
spin_fact = 0.5
2022-01-31 16:47:28 +01:00
2021-07-05 19:28:04 +02:00
lap1 = 0.0
lap2 = 0.0
lap3 = 0.0
for ii in range(3):
2021-07-06 09:27:14 +02:00
x = ee_distance_rescaled[j][i]
if x < 1e-18:
continue
for p in range(2,bord_num+1):
2022-11-16 11:58:44 +01:00
y = p * b_vector[(p-1) + 1] * x
2021-07-05 19:28:04 +02:00
pow_ser_g[ii] = pow_ser_g[ii] + y * dx[ii]
lap1 = lap1 + (p - 1) * y * xinv * dx[ii] * dx[ii]
lap2 = lap2 + y
2021-07-06 09:27:14 +02:00
x = x * ee_distance_rescaled[j][i]
2022-01-31 16:47:28 +01:00
2022-11-16 11:58:44 +01:00
lap3 = lap3 - 2.0 * b_vector[1] * dx[ii] * dx[ii]
2021-07-05 19:28:04 +02:00
2022-11-16 11:58:44 +01:00
factor_ee_deriv_e[ii][j] = factor_ee_deriv_e[ii][j] + spin_fact * b_vector[0] * \
2021-07-06 09:27:14 +02:00
dx[ii] * invden2 + pow_ser_g[ii]
2021-07-05 19:28:04 +02:00
ii = 3
lap2 = lap2 * dx[ii] * third
lap3 = lap3 + den * dx[ii]
2022-11-16 11:58:44 +01:00
lap3 = lap3 * (spin_fact * b_vector[0] * invden3)
2021-07-05 19:28:04 +02:00
factor_ee_deriv_e[ii][j] = factor_ee_deriv_e[ii][j] + lap1 + lap2 + lap3
2021-07-06 09:27:14 +02:00
print("factor_ee_deriv_e[0][0]:",factor_ee_deriv_e[0][0])
print("factor_ee_deriv_e[1][0]:",factor_ee_deriv_e[1][0])
print("factor_ee_deriv_e[2][0]:",factor_ee_deriv_e[2][0])
print("factor_ee_deriv_e[3][0]:",factor_ee_deriv_e[3][0])
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 19:28:04 +02:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
: asym_one : 0.43340325572525706
: asymp_jasb[0] : 0.5323750557252571
: asymp_jasb[1] : 0.31567342786262853
: factor_ee_deriv_e[0][0]: 0.16364894652107934
: factor_ee_deriv_e[1][0]: -0.6927548119830084
: factor_ee_deriv_e[2][0]: 0.073267755223968
: factor_ee_deriv_e[3][0]: 1.5111672803213185
2022-01-31 16:47:28 +01:00
2021-07-05 19:28:04 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval c_test)
/* Check if Jastrow is properly initialized */
2023-03-30 17:07:11 +02:00
assert(qmckl_jastrow_champ_provided(context));
// calculate factor_ee_deriv_e
double factor_ee_deriv_e[walk_num][4][elec_num];
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_factor_ee_deriv_e(context, &(factor_ee_deriv_e[0][0][0]),walk_num*4*elec_num);
// check factor_ee_deriv_e
assert(fabs(factor_ee_deriv_e[0][0][0]-0.16364894652107934) < 1.e-12);
assert(fabs(factor_ee_deriv_e[0][1][0]+0.6927548119830084 ) < 1.e-12);
assert(fabs(factor_ee_deriv_e[0][2][0]-0.073267755223968 ) < 1.e-12);
assert(fabs(factor_ee_deriv_e[0][3][0]-1.5111672803213185 ) < 1.e-12);
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-05 19:28:04 +02:00
2023-03-30 12:34:17 +02:00
*** Electron-electron rescaled distances
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
~ee_distance_rescaled~ stores the matrix of the rescaled distances between all
pairs of electrons:
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
\[
C_{ij} = \frac{ 1 - e^{-\kappa r_{ij}}}{\kappa}
\]
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
where \(r_{ij}\) is the matrix of electron-electron distances.
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
**** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_get_jastrow_champ_ee_distance_rescaled(qmckl_context context, double* const distance_rescaled);
2023-03-30 12:34:17 +02:00
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_get_jastrow_champ_ee_distance_rescaled(qmckl_context context, double* const distance_rescaled)
2022-11-17 15:45:22 +01:00
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2023-03-30 12:34:17 +02:00
return QMCKL_NULL_CONTEXT;
2022-11-17 15:45:22 +01:00
}
2022-11-18 09:28:13 +01:00
qmckl_exit_code rc;
2023-03-30 12:34:17 +02:00
rc = qmckl_provide_ee_distance_rescaled(context);
if (rc != QMCKL_SUCCESS) return rc;
2022-11-17 15:45:22 +01:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 12:34:17 +02:00
size_t sze = ctx->electron.num * ctx->electron.num * ctx->electron.walker.num;
2023-03-30 17:07:11 +02:00
memcpy(distance_rescaled, ctx->jastrow_champ.ee_distance_rescaled, sze * sizeof(double));
2022-11-17 15:45:22 +01:00
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_provide_ee_distance_rescaled(qmckl_context context);
#+end_src
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_provide_ee_distance_rescaled(qmckl_context context)
2022-11-17 15:45:22 +01:00
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2023-03-30 12:34:17 +02:00
return QMCKL_NULL_CONTEXT;
2022-11-17 15:45:22 +01:00
}
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->electron.walker.point.date > ctx->jastrow_champ.ee_distance_rescaled_date) {
2023-03-30 12:34:17 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.ee_distance_rescaled != NULL) {
qmckl_exit_code rc = qmckl_free(context, ctx->jastrow_champ.ee_distance_rescaled);
2023-03-30 12:34:17 +02:00
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
"qmckl_provide_ee_distance_rescaled",
2023-03-30 17:07:11 +02:00
"Unable to free ctx->jastrow_champ.ee_distance_rescaled");
2023-03-30 12:34:17 +02:00
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.ee_distance_rescaled = NULL;
2023-03-30 12:34:17 +02:00
}
}
2022-11-17 15:45:22 +01:00
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.ee_distance_rescaled == NULL) {
2022-11-17 15:45:22 +01:00
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 12:34:17 +02:00
mem_info.size = ctx->electron.num * ctx->electron.num *
ctx->electron.walker.num * sizeof(double);
double* ee_distance_rescaled = (double*) qmckl_malloc(context, mem_info);
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
if (ee_distance_rescaled == NULL) {
2022-11-17 15:45:22 +01:00
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 12:34:17 +02:00
"qmckl_provide_ee_distance_rescaled",
2022-11-17 15:45:22 +01:00
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.ee_distance_rescaled = ee_distance_rescaled;
2022-11-17 15:45:22 +01:00
}
2023-03-30 12:34:17 +02:00
qmckl_exit_code rc =
qmckl_compute_ee_distance_rescaled(context,
ctx->electron.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.rescale_factor_ee,
2023-03-30 12:34:17 +02:00
ctx->electron.walker.num,
ctx->electron.walker.point.coord.data,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.ee_distance_rescaled);
2022-11-17 15:45:22 +01:00
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.ee_distance_rescaled_date = ctx->date;
2022-11-17 15:45:22 +01:00
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
:Name: qmckl_compute_ee_distance_rescaled
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_ee_distance_rescaled_args
| Variable | Type | In/Out | Description |
|---------------------+----------------------------------------+--------+--------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~rescale_factor_ee~ | ~double~ | in | Factor to rescale ee distances |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~coord~ | ~double[3][walk_num][elec_num]~ | in | Electron coordinates |
| ~ee_distance~ | ~double[walk_num][elec_num][elec_num]~ | out | Electron-electron rescaled distances |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_ee_distance_rescaled_f(context, elec_num, rescale_factor_ee, walk_num, &
coord, ee_distance_rescaled) &
2022-11-17 15:45:22 +01:00
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
2023-03-30 12:34:17 +02:00
integer*8 , intent(in) :: elec_num
double precision , intent(in) :: rescale_factor_ee
integer*8 , intent(in) :: walk_num
double precision , intent(in) :: coord(elec_num,walk_num,3)
double precision , intent(out) :: ee_distance_rescaled(elec_num,elec_num,walk_num)
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
integer*8 :: k
2023-03-13 15:32:35 +01:00
2022-11-17 15:45:22 +01:00
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2023-03-30 12:34:17 +02:00
if (elec_num <= 0) then
2022-11-17 15:45:22 +01:00
info = QMCKL_INVALID_ARG_2
return
endif
2023-03-30 12:34:17 +02:00
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
2023-03-13 15:32:35 +01:00
2023-03-30 12:34:17 +02:00
do k=1,walk_num
info = qmckl_distance_rescaled(context, 'T', 'T', elec_num, elec_num, &
coord(1,k,1), elec_num * walk_num, &
coord(1,k,1), elec_num * walk_num, &
ee_distance_rescaled(1,1,k), elec_num, rescale_factor_ee)
if (info /= QMCKL_SUCCESS) then
exit
endif
2022-11-17 15:45:22 +01:00
end do
2023-03-30 12:34:17 +02:00
end function qmckl_compute_ee_distance_rescaled_f
#+end_src
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval h_private_func) :comments org :exports none
qmckl_exit_code qmckl_compute_ee_distance_rescaled (
const qmckl_context context,
const int64_t elec_num,
const double rescale_factor_ee,
const int64_t walk_num,
const double* coord,
double* const ee_distance_rescaled );
#+end_src
2022-11-17 19:20:12 +01:00
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_ee_distance_rescaled_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2022-11-17 19:20:12 +01:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_ee_distance_rescaled &
(context, elec_num, rescale_factor_ee, walk_num, coord, ee_distance_rescaled) &
bind(C) result(info)
2022-11-17 19:20:12 +01:00
2023-03-30 12:34:17 +02:00
use, intrinsic :: iso_c_binding
implicit none
2022-11-17 19:20:12 +01:00
2023-03-30 12:34:17 +02:00
integer (c_int64_t) , intent(in) , value :: context
integer (c_int64_t) , intent(in) , value :: elec_num
real (c_double ) , intent(in) , value :: rescale_factor_ee
integer (c_int64_t) , intent(in) , value :: walk_num
real (c_double ) , intent(in) :: coord(elec_num,3,walk_num)
real (c_double ) , intent(out) :: ee_distance_rescaled(elec_num,elec_num,walk_num)
2022-11-17 19:20:12 +01:00
2023-03-30 12:34:17 +02:00
integer(c_int32_t), external :: qmckl_compute_ee_distance_rescaled_f
info = qmckl_compute_ee_distance_rescaled_f &
(context, elec_num, rescale_factor_ee, walk_num, coord, ee_distance_rescaled)
2022-11-17 19:20:12 +01:00
2023-03-30 12:34:17 +02:00
end function qmckl_compute_ee_distance_rescaled
#+end_src
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
**** Test
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src python :results output :exports none
import numpy as np
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
kappa = 1.0
2023-03-13 15:32:35 +01:00
2023-03-30 12:34:17 +02:00
elec_1_w1 = np.array( [-0.250655104764153, 0.503070975550133 , -0.166554344502303])
elec_2_w1 = np.array( [-0.587812193472177, -0.128751981129274 , 0.187773606533075])
elec_5_w1 = np.array( [-0.127732483187947, -0.138975497694196 , -8.669850480215846E-002])
elec_6_w1 = np.array( [-0.232271834949124, -1.059321673434182E-002 , -0.504862241464867])
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
print ( "[0][0] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_1_w1-elec_1_w1)) )/kappa )
print ( "[0][1] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_1_w1-elec_2_w1)) )/kappa )
print ( "[1][0] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_2_w1-elec_1_w1)) )/kappa )
print ( "[5][5] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_5_w1-elec_5_w1)) )/kappa )
print ( "[5][6] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_5_w1-elec_6_w1)) )/kappa )
print ( "[6][5] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_6_w1-elec_5_w1)) )/kappa )
#+end_src
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
: [0][0] : 0.0
: [0][1] : 0.5502278003524018
: [1][0] : 0.5502278003524018
: [5][5] : 0.0
: [5][6] : 0.3622098222364193
: [6][5] : 0.3622098222364193
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval c_test)
assert(qmckl_electron_provided(context));
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
double ee_distance_rescaled[walk_num * elec_num * elec_num];
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_ee_distance_rescaled(context, ee_distance_rescaled);
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
// (e1,e2,w)
// (0,0,0) == 0.
assert(ee_distance_rescaled[0] == 0.);
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
// (1,0,0) == (0,1,0)
assert(ee_distance_rescaled[1] == ee_distance_rescaled[elec_num]);
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
// value of (1,0,0)
assert(fabs(ee_distance_rescaled[1]-0.5502278003524018) < 1.e-12);
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
// (0,0,1) == 0.
assert(ee_distance_rescaled[5*elec_num + 5] == 0.);
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
// (1,0,1) == (0,1,1)
assert(ee_distance_rescaled[5*elec_num+6] == ee_distance_rescaled[6*elec_num+5]);
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
// value of (1,0,1)
assert(fabs(ee_distance_rescaled[5*elec_num+6]-0.3622098222364193) < 1.e-12);
2022-11-17 15:45:22 +01:00
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
*** Electron-electron rescaled distance gradients and Laplacian with respect to electron coordinates
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
The rescaled distances, represented by $C_{ij} = (1 - e^{-\kappa_\text{e} r_{ij}})/\kappa_\text{e}$
are differentiated with respect to the electron coordinates.
This information is stored in the tensor
~ee_distance_rescaled_deriv_e~. The initial three sequential
elements of this three-dimensional tensor provide the $x$, $y$, and $z$
direction derivatives, while the fourth index corresponds to the Laplacian.
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
**** Get
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_get_jastrow_champ_ee_distance_rescaled_deriv_e(qmckl_context context, double* const distance_rescaled_deriv_e);
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_get_jastrow_champ_ee_distance_rescaled_deriv_e(qmckl_context context, double* const distance_rescaled_deriv_e)
2021-07-06 12:21:51 +02:00
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2023-03-30 12:34:17 +02:00
return QMCKL_NULL_CONTEXT;
2021-07-06 12:21:51 +02:00
}
qmckl_exit_code rc;
2023-03-30 12:34:17 +02:00
rc = qmckl_provide_ee_distance_rescaled_deriv_e(context);
2021-07-06 12:21:51 +02:00
if (rc != QMCKL_SUCCESS) return rc;
2023-03-30 12:34:17 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
size_t sze = 4 * ctx->electron.num * ctx->electron.num * ctx->electron.walker.num;
2023-03-30 17:07:11 +02:00
memcpy(distance_rescaled_deriv_e, ctx->jastrow_champ.ee_distance_rescaled_deriv_e, sze * sizeof(double));
2021-07-06 12:21:51 +02:00
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2022-11-16 17:54:59 +01:00
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
2022-11-16 17:54:59 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_provide_ee_distance_rescaled_deriv_e(qmckl_context context);
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_provide_ee_distance_rescaled_deriv_e(qmckl_context context)
2021-07-06 12:21:51 +02:00
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2023-03-30 12:34:17 +02:00
return QMCKL_NULL_CONTEXT;
2021-07-06 12:21:51 +02:00
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-07-06 12:21:51 +02:00
assert (ctx != NULL);
2022-11-17 19:20:12 +01:00
2021-07-06 12:21:51 +02:00
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->electron.walker.point.date > ctx->jastrow_champ.ee_distance_rescaled_deriv_e_date) {
2021-07-06 12:21:51 +02:00
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.ee_distance_rescaled_deriv_e != NULL) {
qmckl_exit_code rc = qmckl_free(context, ctx->jastrow_champ.ee_distance_rescaled_deriv_e);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-30 12:34:17 +02:00
"qmckl_provide_ee_distance_rescaled_deriv_e",
2023-03-30 17:07:11 +02:00
"Unable to free ctx->jastrow_champ.ee_distance_rescaled_deriv_e");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.ee_distance_rescaled_deriv_e = NULL;
}
2022-08-07 14:57:10 +02:00
}
2021-07-06 12:21:51 +02:00
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.ee_distance_rescaled_deriv_e == NULL) {
2021-07-06 12:21:51 +02:00
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 12:34:17 +02:00
mem_info.size = 4 * ctx->electron.num * ctx->electron.num *
ctx->electron.walker.num * sizeof(double);
double* ee_distance_rescaled_deriv_e = (double*) qmckl_malloc(context, mem_info);
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
if (ee_distance_rescaled_deriv_e == NULL) {
2021-07-06 12:21:51 +02:00
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 12:34:17 +02:00
"qmckl_provide_ee_distance_rescaled_deriv_e",
2021-07-06 12:21:51 +02:00
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.ee_distance_rescaled_deriv_e = ee_distance_rescaled_deriv_e;
2021-07-06 12:21:51 +02:00
}
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
qmckl_exit_code rc =
qmckl_compute_ee_distance_rescaled_deriv_e(context,
ctx->electron.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.rescale_factor_ee,
2023-03-30 12:34:17 +02:00
ctx->electron.walker.num,
ctx->electron.walker.point.coord.data,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.ee_distance_rescaled_deriv_e);
2021-07-06 12:21:51 +02:00
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-13 15:32:35 +01:00
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.ee_distance_rescaled_date = ctx->date;
2021-07-06 12:21:51 +02:00
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
:Name: qmckl_compute_ee_distance_rescaled_deriv_e
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_ee_distance_rescaled_deriv_e_args
| Variable | Type | In/Out | Description |
|-----------------------+-------------------------------------------+--------+-------------------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~rescale_factor_ee~ | ~double~ | in | Factor to rescale ee distances |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~coord~ | ~double[3][walk_num][elec_num]~ | in | Electron coordinates |
| ~ee_distance_deriv_e~ | ~double[walk_num][4][elec_num][elec_num]~ | out | Electron-electron rescaled distance derivatives |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_ee_distance_rescaled_deriv_e_f(context, elec_num, rescale_factor_ee, walk_num, &
coord, ee_distance_rescaled_deriv_e) &
2021-07-06 12:21:51 +02:00
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
2023-03-30 12:34:17 +02:00
integer*8 , intent(in) :: elec_num
double precision , intent(in) :: rescale_factor_ee
integer*8 , intent(in) :: walk_num
double precision , intent(in) :: coord(elec_num,walk_num,3)
double precision , intent(out) :: ee_distance_rescaled_deriv_e(4,elec_num,elec_num,walk_num)
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
integer*8 :: k
2021-07-06 12:21:51 +02:00
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2023-03-30 12:34:17 +02:00
if (elec_num <= 0) then
2021-07-06 12:21:51 +02:00
info = QMCKL_INVALID_ARG_2
return
endif
2023-03-30 12:34:17 +02:00
if (walk_num <= 0) then
2021-07-06 12:21:51 +02:00
info = QMCKL_INVALID_ARG_3
return
endif
2023-03-30 12:34:17 +02:00
do k=1,walk_num
info = qmckl_distance_rescaled_deriv_e(context, 'T', 'T', elec_num, elec_num, &
coord(1,k,1), elec_num*walk_num, &
coord(1,k,1), elec_num*walk_num, &
ee_distance_rescaled_deriv_e(1,1,1,k), elec_num, rescale_factor_ee)
if (info /= QMCKL_SUCCESS) then
exit
endif
end do
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
end function qmckl_compute_ee_distance_rescaled_deriv_e_f
#+end_src
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval h_private_func) :comments org :exports none
qmckl_exit_code qmckl_compute_ee_distance_rescaled_deriv_e (
const qmckl_context context,
const int64_t elec_num,
const double rescale_factor_ee,
const int64_t walk_num,
const double* coord,
double* const ee_distance_rescaled_deriv_e );
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_ee_distance_rescaled_deriv_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_ee_distance_rescaled_deriv_e &
(context, elec_num, rescale_factor_ee, walk_num, coord, ee_distance_rescaled_deriv_e) &
bind(C) result(info)
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
use, intrinsic :: iso_c_binding
implicit none
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
integer (c_int64_t) , intent(in) , value :: context
integer (c_int64_t) , intent(in) , value :: elec_num
real (c_double ) , intent(in) , value :: rescale_factor_ee
integer (c_int64_t) , intent(in) , value :: walk_num
real (c_double ) , intent(in) :: coord(elec_num,3,walk_num)
real (c_double ) , intent(out) :: ee_distance_rescaled_deriv_e(4,elec_num,elec_num,walk_num)
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
integer(c_int32_t), external :: qmckl_compute_ee_distance_rescaled_deriv_e_f
info = qmckl_compute_ee_distance_rescaled_deriv_e_f &
(context, elec_num, rescale_factor_ee, walk_num, coord, ee_distance_rescaled_deriv_e)
2022-04-08 10:44:48 +02:00
2023-03-30 12:34:17 +02:00
end function qmckl_compute_ee_distance_rescaled_deriv_e
#+end_src
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
**** Test
2022-11-17 19:20:12 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src python :results output :exports none
import numpy as np
2022-11-17 19:20:12 +01:00
2023-03-30 12:34:17 +02:00
# TODO
#+end_src
2022-11-17 19:20:12 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval c_test)
assert(qmckl_electron_provided(context));
2022-11-17 19:20:12 +01:00
2023-03-30 12:34:17 +02:00
double ee_distance_rescaled_deriv_e[4 * walk_num * elec_num * elec_num];
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_ee_distance_rescaled_deriv_e(context, ee_distance_rescaled_deriv_e);
2022-11-17 19:20:12 +01:00
2023-03-30 12:34:17 +02:00
// TODO: Get exact values
//// (e1,e2,w)
//// (0,0,0) == 0.
//assert(ee_distance[0] == 0.);
//
//// (1,0,0) == (0,1,0)
//assert(ee_distance[1] == ee_distance[elec_num]);
//
//// value of (1,0,0)
//assert(fabs(ee_distance[1]-7.152322512964209) < 1.e-12);
//
//// (0,0,1) == 0.
//assert(ee_distance[elec_num*elec_num] == 0.);
//
//// (1,0,1) == (0,1,1)
//assert(ee_distance[elec_num*elec_num+1] == ee_distance[elec_num*elec_num+elec_num]);
//
//// value of (1,0,1)
//assert(fabs(ee_distance[elec_num*elec_num+1]-6.5517646321055665) < 1.e-12);
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-31 14:41:32 +02:00
2023-03-30 12:34:17 +02:00
** Electron-nucleus component
*** Asymptotic component for
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
Calculate the asymptotic component ~asymp_jasa~ to be substracted from the final
electron-nucleus jastrow factor \(J_{\text{eN}}\). The asymptotic component is calculated
via the ~a_vector~ and the electron-nucleus rescale factors ~rescale_factor_en~.
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
\[
J_{\text{en}}^{\infty \alpha} = \frac{a_1 \kappa_\alpha^{-1}}{1 + a_2 \kappa_\alpha^{-1}}
\]
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
**** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_asymp_jasa(qmckl_context context,
2023-03-30 12:34:17 +02:00
double* const asymp_jasa,
const int64_t size_max);
#+end_src
2021-07-06 12:21:51 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_asymp_jasa(qmckl_context context,
2023-03-30 12:34:17 +02:00
double* const asymp_jasa,
const int64_t size_max)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_asymp_jasa",
2023-03-30 12:34:17 +02:00
NULL);
}
2023-03-30 12:34:17 +02:00
/* Provided in finalize_jastrow */
/*
qmckl_exit_code rc;
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_asymp_jasa(context);
2023-03-30 12:34:17 +02:00
if(rc != QMCKL_SUCCESS) return rc;
*/
2022-04-04 16:56:33 +02:00
2023-03-30 12:34:17 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2022-04-04 16:56:33 +02:00
2023-03-30 17:07:11 +02:00
int64_t sze = ctx->jastrow_champ.type_nucl_num;
2023-03-30 12:34:17 +02:00
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_asymp_jasa",
2023-03-30 12:34:17 +02:00
"Array too small. Expected nucleus.num");
}
2023-03-30 17:07:11 +02:00
memcpy(asymp_jasa, ctx->jastrow_champ.asymp_jasa, sze * sizeof(double));
2021-07-06 12:21:51 +02:00
return QMCKL_SUCCESS;
}
2021-07-06 12:21:51 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
***** Fortran interface
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src f90 :tangle (eval fh_func) :comments org
interface
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_asymp_jasa(context, &
2023-03-30 12:34:17 +02:00
asymp_jasa, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: asymp_jasa(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_asymp_jasa
2023-03-30 12:34:17 +02:00
end interface
#+end_src
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_asymp_jasa(qmckl_context context);
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_asymp_jasa(qmckl_context context)
2021-07-06 12:50:17 +02:00
{
qmckl_exit_code rc;
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2022-11-16 17:54:59 +01:00
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_asymp_jasa",
2022-11-16 17:54:59 +01:00
NULL);
2021-07-06 12:50:17 +02:00
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-07-06 12:50:17 +02:00
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
if (!ctx->jastrow_champ.provided) {
2022-11-16 17:54:59 +01:00
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_asymp_jasa",
2022-11-16 17:54:59 +01:00
NULL);
}
2021-07-06 12:50:17 +02:00
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.asymp_jasa_date) {
2022-08-07 14:57:10 +02:00
2021-07-06 12:50:17 +02:00
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.asymp_jasa == NULL) {
2021-07-06 12:50:17 +02:00
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 17:07:11 +02:00
mem_info.size = ctx->jastrow_champ.type_nucl_num * sizeof(double);
2023-03-30 12:34:17 +02:00
double* asymp_jasa = (double*) qmckl_malloc(context, mem_info);
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
if (asymp_jasa == NULL) {
2021-07-06 12:50:17 +02:00
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 12:34:17 +02:00
"qmckl_asymp_jasa",
2021-07-06 12:50:17 +02:00
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.asymp_jasa = asymp_jasa;
2021-07-06 12:50:17 +02:00
}
2022-01-31 16:47:28 +01:00
2023-03-30 17:07:11 +02:00
rc = qmckl_compute_jastrow_champ_asymp_jasa(context,
ctx->jastrow_champ.aord_num,
ctx->jastrow_champ.type_nucl_num,
ctx->jastrow_champ.a_vector,
ctx->jastrow_champ.rescale_factor_en,
ctx->jastrow_champ.asymp_jasa);
2021-07-06 12:50:17 +02:00
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.asymp_jasa_date = ctx->date;
2021-07-06 12:50:17 +02:00
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
2023-03-30 17:07:11 +02:00
:Name: qmckl_compute_jastrow_champ_asymp_jasa
2023-03-30 12:34:17 +02:00
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_asymp_jasa_args
| Variable | Type | In/Out | Description |
|---------------------+-------------------------------------+--------+----------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~aord_num~ | ~int64_t~ | in | Order of the polynomial |
| ~type_nucl_num~ | ~int64_t~ | in | Number of nucleus types |
| ~a_vector~ | ~double[type_nucl_num][aord_num+1]~ | in | Values of a |
| ~rescale_factor_en~ | ~double[type_nucl_num]~ | in | Electron nucleus distances |
| ~asymp_jasa~ | ~double[type_nucl_num]~ | out | Asymptotic value |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2023-03-30 17:07:11 +02:00
integer function qmckl_compute_jastrow_champ_asymp_jasa_f(context, aord_num, type_nucl_num, a_vector, &
2023-03-30 12:34:17 +02:00
rescale_factor_en, asymp_jasa) &
2021-07-06 12:50:17 +02:00
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
2023-03-30 12:34:17 +02:00
integer*8 , intent(in) :: aord_num
integer*8 , intent(in) :: type_nucl_num
2022-11-16 11:58:44 +01:00
double precision , intent(in) :: a_vector(aord_num + 1, type_nucl_num)
2023-03-30 12:34:17 +02:00
double precision , intent(in) :: rescale_factor_en(type_nucl_num)
double precision , intent(out) :: asymp_jasa(type_nucl_num)
integer*8 :: i, j, p
double precision :: kappa_inv, x, asym_one
2021-07-06 12:50:17 +02:00
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2023-03-30 12:34:17 +02:00
if (aord_num < 0) then
2021-07-06 12:50:17 +02:00
info = QMCKL_INVALID_ARG_2
return
endif
2023-03-30 12:34:17 +02:00
do i=1,type_nucl_num
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
kappa_inv = 1.0d0 / rescale_factor_en(i)
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
asymp_jasa(i) = a_vector(1,i) * kappa_inv / (1.0d0 + a_vector(2,i) * kappa_inv)
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
x = kappa_inv
do p = 2, aord_num
x = x * kappa_inv
asymp_jasa(i) = asymp_jasa(i) + a_vector(p+1, i) * x
end do
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
end do
2021-07-06 12:50:17 +02:00
2023-03-30 17:07:11 +02:00
end function qmckl_compute_jastrow_champ_asymp_jasa_f
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_asymp_jasa_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
2023-03-30 17:07:11 +02:00
integer(c_int32_t) function qmckl_compute_jastrow_champ_asymp_jasa &
2023-03-30 12:34:17 +02:00
(context, aord_num, type_nucl_num, a_vector, rescale_factor_en, asymp_jasa) &
bind(C) result(info)
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
use, intrinsic :: iso_c_binding
implicit none
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
integer (c_int64_t) , intent(in) , value :: context
integer (c_int64_t) , intent(in) , value :: aord_num
integer (c_int64_t) , intent(in) , value :: type_nucl_num
real (c_double ) , intent(in) :: a_vector(aord_num+1,type_nucl_num)
real (c_double ) , intent(in) :: rescale_factor_en(type_nucl_num)
real (c_double ) , intent(out) :: asymp_jasa(type_nucl_num)
2021-07-06 12:50:17 +02:00
2023-03-30 17:07:11 +02:00
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_asymp_jasa_f
info = qmckl_compute_jastrow_champ_asymp_jasa_f &
2023-03-30 12:34:17 +02:00
(context, aord_num, type_nucl_num, a_vector, rescale_factor_en, asymp_jasa)
2021-07-06 12:50:17 +02:00
2023-03-30 17:07:11 +02:00
end function qmckl_compute_jastrow_champ_asymp_jasa
2021-07-06 12:50:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_header(table=qmckl_asymp_jasa_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src c :tangle (eval h_func) :comments org
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_asymp_jasa (
2023-03-30 12:34:17 +02:00
const qmckl_context context,
const int64_t aord_num,
const int64_t type_nucl_num,
const double* a_vector,
const double* rescale_factor_en,
double* const asymp_jasa );
2021-07-06 12:50:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Test
#+name: asymp_jasa
#+begin_src python :results output :exports none :noweb yes
2021-07-06 12:50:17 +02:00
import numpy as np
<<jastrow_data>>
2023-03-30 12:34:17 +02:00
asymp_jasa = a_vector[0] * kappa_inv / (1.0 + a_vector[1]*kappa_inv)
x = kappa_inv
for p in range(1,aord_num):
x = x * kappa_inv
asymp_jasa += a_vector[p + 1] * x
print("asymp_jasa[i] : ", asymp_jasa)
2021-07-06 15:27:14 +02:00
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-06 15:27:14 +02:00
2023-03-30 12:34:17 +02:00
#+RESULTS: asymp_jasa
: asymp_jasa[i] : [-0.548554]
2021-07-06 15:27:14 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval c_test)
double asymp_jasa[2];
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_asymp_jasa(context, asymp_jasa, type_nucl_num);
2021-07-06 15:27:14 +02:00
2023-03-30 12:34:17 +02:00
// calculate asymp_jasb
printf("%e %e\n", asymp_jasa[0], -0.548554);
assert(fabs(-0.548554 - asymp_jasa[0]) < 1.e-12);
2021-07-06 15:27:14 +02:00
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
*** Electron-nucleus component
2021-07-06 15:27:14 +02:00
2023-03-30 12:34:17 +02:00
Calculate the electron-electron jastrow component ~factor_en~ using the ~a_vector~
coeffecients and the electron-nucleus rescaled distances ~en_distance_rescaled~.
2021-07-06 15:27:14 +02:00
2023-03-30 12:34:17 +02:00
\[
f_{\alpha}(R_{i\alpha}) = \sum_{i,j<i} \left\{ \frac{ A_0 C_{ij}}{1 - A_1 C_{ij}} + \sum^{N^\alpha_{\text{ord}}}_{k}A_k C_{ij}^k \right\}
\]
2021-07-06 15:27:14 +02:00
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
**** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_factor_en(qmckl_context context,
2023-03-30 12:34:17 +02:00
double* const factor_en,
const int64_t size_max);
#+end_src
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_factor_en(qmckl_context context,
2023-03-30 12:34:17 +02:00
double* const factor_en,
const int64_t size_max)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_factor_en",
2023-03-30 12:34:17 +02:00
NULL);
}
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
qmckl_exit_code rc;
2021-07-06 12:50:17 +02:00
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_factor_en(context);
2023-03-30 12:34:17 +02:00
if (rc != QMCKL_SUCCESS) return rc;
2023-03-30 12:34:17 +02:00
int64_t sze=ctx->electron.walker.num;
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_factor_en",
2023-03-30 12:34:17 +02:00
"Array too small. Expected walker.num");
}
2023-03-30 17:07:11 +02:00
memcpy(factor_en, ctx->jastrow_champ.factor_en, sze*sizeof(double));
2021-07-06 12:50:17 +02:00
2023-03-30 12:34:17 +02:00
return QMCKL_SUCCESS;
}
2021-07-06 12:50:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
***** Fortran interface
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src f90 :tangle (eval fh_func) :comments org
interface
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_factor_en (context, &
2023-03-30 12:34:17 +02:00
factor_en, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: factor_en(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_factor_en
2023-03-30 12:34:17 +02:00
end interface
#+end_src
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_factor_en(qmckl_context context);
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_factor_en(qmckl_context context)
2021-07-07 07:53:04 +02:00
{
qmckl_exit_code rc;
2023-03-30 12:34:17 +02:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_en",
2023-03-30 12:34:17 +02:00
NULL);
}
2021-07-07 07:53:04 +02:00
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-07-07 07:53:04 +02:00
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
if (!ctx->jastrow_champ.provided) {
2023-03-30 12:34:17 +02:00
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_en",
2023-03-30 12:34:17 +02:00
NULL);
2021-07-07 07:53:04 +02:00
}
2023-03-30 12:34:17 +02:00
/* Check if en rescaled distance is provided */
rc = qmckl_provide_en_distance_rescaled(context);
if(rc != QMCKL_SUCCESS) return rc;
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
/* Provided in finalize_jastrow */
/*
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_asymp_jasa(context);
2023-03-30 12:34:17 +02:00
if(rc != QMCKL_SUCCESS) return rc;
*/
2021-07-07 07:53:04 +02:00
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.factor_en_date) {
2021-07-07 07:53:04 +02:00
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.factor_en != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.factor_en);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_en",
"Unable to free ctx->jastrow_champ.factor_en");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_en = NULL;
}
2022-08-07 14:57:10 +02:00
}
2021-07-07 07:53:04 +02:00
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.factor_en == NULL) {
2021-07-07 07:53:04 +02:00
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 12:34:17 +02:00
mem_info.size = ctx->electron.walker.num * sizeof(double);
double* factor_en = (double*) qmckl_malloc(context, mem_info);
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
if (factor_en == NULL) {
2021-07-07 07:53:04 +02:00
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_en",
2021-07-07 07:53:04 +02:00
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_en = factor_en;
2021-07-07 07:53:04 +02:00
}
2023-03-31 13:37:35 +02:00
rc = qmckl_compute_jastrow_champ_factor_en(context,
2023-03-30 12:34:17 +02:00
ctx->electron.walker.num,
ctx->electron.num,
ctx->nucleus.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.type_nucl_num,
ctx->jastrow_champ.type_nucl_vector,
ctx->jastrow_champ.aord_num,
ctx->jastrow_champ.a_vector,
ctx->jastrow_champ.en_distance_rescaled,
ctx->jastrow_champ.asymp_jasa,
ctx->jastrow_champ.factor_en);
2021-07-07 07:53:04 +02:00
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_en_date = ctx->date;
2021-07-07 07:53:04 +02:00
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
2023-03-31 13:37:35 +02:00
:Name: qmckl_compute_jastrow_champ_factor_en_doc
2023-03-30 12:34:17 +02:00
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_en_args
| Variable | Type | In/Out | Description |
|------------------------+----------------------------------------+--------+----------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
2023-03-30 18:17:33 +02:00
| ~nucl_num~ | ~int64_t~ | in | Number of nuclei |
2023-03-30 12:34:17 +02:00
| ~type_nucl_num~ | ~int64_t~ | in | Number of unique nuclei |
2023-03-30 18:17:33 +02:00
| ~type_nucl_vector~ | ~int64_t[nucl_num]~ | in | IDs of unique nuclei |
2023-03-30 12:34:17 +02:00
| ~aord_num~ | ~int64_t~ | in | Number of coefficients |
| ~a_vector~ | ~double[aord_num+1][type_nucl_num]~ | in | List of coefficients |
| ~en_distance_rescaled~ | ~double[walk_num][nucl_num][elec_num]~ | in | Electron-nucleus distances |
| ~asymp_jasa~ | ~double[type_nucl_num]~ | in | Type of nuclei |
| ~factor_en~ | ~double[walk_num]~ | out | Electron-nucleus jastrow |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2023-03-31 13:37:35 +02:00
integer function qmckl_compute_jastrow_champ_factor_en_doc_f( &
2023-03-30 12:34:17 +02:00
context, walk_num, elec_num, nucl_num, type_nucl_num, &
type_nucl_vector, aord_num, a_vector, &
en_distance_rescaled, asymp_jasa, factor_en) &
2021-07-07 07:53:04 +02:00
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
2023-03-30 12:34:17 +02:00
integer*8 , intent(in) :: walk_num, elec_num, aord_num, nucl_num, type_nucl_num
integer*8 , intent(in) :: type_nucl_vector(nucl_num)
double precision , intent(in) :: a_vector(aord_num + 1, type_nucl_num)
double precision , intent(in) :: en_distance_rescaled(elec_num, nucl_num, walk_num)
double precision , intent(in) :: asymp_jasa(type_nucl_num)
double precision , intent(out) :: factor_en(walk_num)
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
integer*8 :: i, a, p, nw
double precision :: x, power_ser
2021-07-07 07:53:04 +02:00
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2023-03-30 12:34:17 +02:00
if (walk_num <= 0) then
2021-07-07 07:53:04 +02:00
info = QMCKL_INVALID_ARG_2
return
endif
2023-03-30 12:34:17 +02:00
if (elec_num <= 0) then
2021-07-07 07:53:04 +02:00
info = QMCKL_INVALID_ARG_3
return
endif
2023-03-30 12:34:17 +02:00
if (nucl_num <= 0) then
info = QMCKL_INVALID_ARG_4
return
endif
2021-07-07 07:53:04 +02:00
2023-03-31 19:20:25 +02:00
if (type_nucl_num <= 0) then
info = QMCKL_INVALID_ARG_4
return
endif
2023-03-30 12:34:17 +02:00
if (aord_num < 0) then
info = QMCKL_INVALID_ARG_7
return
endif
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
do nw =1, walk_num
factor_en(nw) = 0.0d0
do a = 1, nucl_num
do i = 1, elec_num
x = en_distance_rescaled(i, a, nw)
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
factor_en(nw) = factor_en(nw) + a_vector(1, type_nucl_vector(a)) * x / &
(1.0d0 + a_vector(2, type_nucl_vector(a)) * x) - asymp_jasa(type_nucl_vector(a))
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
do p = 2, aord_num
x = x * en_distance_rescaled(i, a, nw)
factor_en(nw) = factor_en(nw) + a_vector(p + 1, type_nucl_vector(a)) * x
end do
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
end do
end do
end do
2021-07-07 07:53:04 +02:00
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_en_doc_f
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_factor_en_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2022-04-08 10:44:48 +02:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
2023-03-31 13:37:35 +02:00
integer(c_int32_t) function qmckl_compute_jastrow_champ_factor_en_doc &
2023-03-30 12:34:17 +02:00
(context, &
walk_num, &
elec_num, &
nucl_num, &
type_nucl_num, &
type_nucl_vector, &
aord_num, &
a_vector, &
en_distance_rescaled, &
asymp_jasa, &
factor_en) &
bind(C) result(info)
2023-03-30 12:34:17 +02:00
use, intrinsic :: iso_c_binding
implicit none
2023-03-30 12:34:17 +02:00
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 :: type_nucl_num
integer (c_int64_t) , intent(in) :: type_nucl_vector(nucl_num)
integer (c_int64_t) , intent(in) , value :: aord_num
real (c_double ) , intent(in) :: a_vector(type_nucl_num,aord_num+1)
real (c_double ) , intent(in) :: en_distance_rescaled(elec_num,nucl_num,walk_num)
real (c_double ) , intent(in) :: asymp_jasa(type_nucl_num)
real (c_double ) , intent(out) :: factor_en(walk_num)
2023-03-31 13:37:35 +02:00
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_factor_en_doc_f
info = qmckl_compute_jastrow_champ_factor_en_doc_f &
2023-03-30 12:34:17 +02:00
(context, &
walk_num, &
elec_num, &
nucl_num, &
type_nucl_num, &
type_nucl_vector, &
aord_num, &
a_vector, &
en_distance_rescaled, &
asymp_jasa, &
factor_en)
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_en_doc
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_header(table=qmckl_factor_en_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+RESULTS:
#+begin_src c :tangle (eval h_func) :comments org
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_en (
2023-03-30 18:17:33 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
const int64_t aord_num,
const double* a_vector,
const double* en_distance_rescaled,
const double* asymp_jasa,
double* const factor_en );
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_en_doc (
2023-03-30 12:34:17 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
const int64_t aord_num,
const double* a_vector,
const double* en_distance_rescaled,
const double* asymp_jasa,
double* const factor_en );
#+end_src
2023-03-30 18:17:33 +02:00
#+begin_src c :tangle (eval c) :comments org
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_en (
2023-03-30 18:17:33 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
const int64_t aord_num,
const double* a_vector,
const double* en_distance_rescaled,
const double* asymp_jasa,
double* const factor_en )
{
#ifdef HAVE_HPC
2023-03-31 13:37:35 +02:00
return qmckl_compute_jastrow_champ_factor_en_doc (context, walk_num, elec_num, nucl_num, type_nucl_num,
2023-03-30 18:17:33 +02:00
type_nucl_vector, aord_num, a_vector, en_distance_rescaled,
asymp_jasa, factor_en );
#else
2023-03-31 13:37:35 +02:00
return qmckl_compute_jastrow_champ_factor_en_doc (context, walk_num, elec_num, nucl_num, type_nucl_num,
2023-03-30 18:17:33 +02:00
type_nucl_vector, aord_num, a_vector, en_distance_rescaled,
asymp_jasa, factor_en );
#endif
}
#+end_src
2023-03-30 12:34:17 +02:00
**** Test
#+begin_src python :results output :exports none :noweb yes
import numpy as np
<<jastrow_data>>
<<asymp_jasa>>
factor_en = 0.0
for a in range(0,nucl_num):
for i in range(0,elec_num):
x = en_distance_rescaled[i][a]
pow_ser = 0.0
for p in range(2,aord_num+1):
x = x * en_distance_rescaled[i][a]
pow_ser = pow_ser + a_vector[(p-1) + 1][type_nucl_vector[a]-1] * x
factor_en = factor_en + a_vector[0][type_nucl_vector[a]-1] * x \
/ (1.0 + a_vector[1][type_nucl_vector[a]-1] * x) \
+ pow_ser
factor_en -= asymp_jasa[type_nucl_vector[a]-1]
print("factor_en :",factor_en)
#+end_src
#+RESULTS:
: asymp_jasa[i] : [-0.548554]
: factor_en : 5.1052574308112755
#+begin_src c :tangle (eval c_test)
/* Check if Jastrow is properly initialized */
2023-03-30 17:07:11 +02:00
assert(qmckl_jastrow_champ_provided(context));
2023-03-30 12:34:17 +02:00
double factor_en[walk_num];
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_factor_en(context, factor_en,walk_num);
2023-03-30 12:34:17 +02:00
// calculate factor_en
assert(fabs(5.1052574308112755 - factor_en[0]) < 1.e-12);
#+end_src
*** Derivative
Calculate the electron-electron jastrow component ~factor_en_deriv_e~ derivative
with respect to the electron coordinates using the ~en_distance_rescaled~ and
~en_distance_rescaled_deriv_e~ which are already calculated previously.
TODO: write equations.
**** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_factor_en_deriv_e(qmckl_context context,
2023-03-30 12:34:17 +02:00
double* const factor_en_deriv_e,
const int64_t size_max);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_factor_en_deriv_e(qmckl_context context,
2023-03-30 12:34:17 +02:00
double* const factor_en_deriv_e,
const int64_t size_max)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
2022-04-08 10:44:48 +02:00
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_factor_en_deriv_e(context);
if (rc != QMCKL_SUCCESS) return rc;
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 12:34:17 +02:00
int64_t sze = ctx->electron.walker.num * 4 * ctx->electron.num;
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_factor_en_deriv_e",
2023-03-30 12:34:17 +02:00
"Array too small. Expected 4*walker.num*elec_num");
}
2023-03-30 17:07:11 +02:00
memcpy(factor_en_deriv_e, ctx->jastrow_champ.factor_en_deriv_e, sze*sizeof(double));
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_factor_en_deriv_e(qmckl_context context);
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_factor_en_deriv_e(qmckl_context context)
{
2023-03-30 12:34:17 +02:00
qmckl_exit_code rc;
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2023-03-30 12:34:17 +02:00
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_en_deriv_e",
2023-03-30 12:34:17 +02:00
NULL);
}
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
if (!ctx->jastrow_champ.provided) {
2023-03-30 12:34:17 +02:00
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_en_deriv_e",
2023-03-30 12:34:17 +02:00
NULL);
}
/* Check if en rescaled distance is provided */
rc = qmckl_provide_en_distance_rescaled(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Check if en rescaled distance derivatives is provided */
rc = qmckl_provide_en_distance_rescaled_deriv_e(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.factor_en_deriv_e_date) {
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.factor_en_deriv_e != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.factor_en_deriv_e);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_en_deriv_e",
"Unable to free ctx->jastrow_champ.factor_en_deriv_e");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_en_deriv_e = NULL;
}
}
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.factor_en_deriv_e == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 12:34:17 +02:00
mem_info.size = ctx->electron.walker.num * 4 * ctx->electron.num * sizeof(double);
double* factor_en_deriv_e = (double*) qmckl_malloc(context, mem_info);
2023-03-30 12:34:17 +02:00
if (factor_en_deriv_e == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_factor_en_deriv_e",
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_en_deriv_e = factor_en_deriv_e;
}
2023-03-31 13:37:35 +02:00
rc = qmckl_compute_jastrow_champ_factor_en_deriv_e(context,
2023-03-30 12:34:17 +02:00
ctx->electron.walker.num,
ctx->electron.num,
ctx->nucleus.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.type_nucl_num,
ctx->jastrow_champ.type_nucl_vector,
ctx->jastrow_champ.aord_num,
ctx->jastrow_champ.a_vector,
ctx->jastrow_champ.en_distance_rescaled,
ctx->jastrow_champ.en_distance_rescaled_deriv_e,
ctx->jastrow_champ.factor_en_deriv_e);
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_en_deriv_e_date = ctx->date;
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
2023-03-31 13:37:35 +02:00
:Name: qmckl_compute_jastrow_champ_factor_en_deriv_e
2023-03-30 12:34:17 +02:00
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_en_deriv_e_args
| Variable | Type | In/Out | Description |
|--------------------------------+-------------------------------------------+--------+---------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
2023-03-30 18:17:33 +02:00
| ~nucl_num~ | ~int64_t~ | in | Number of nuclei |
2023-03-30 12:34:17 +02:00
| ~type_nucl_num~ | ~int64_t~ | in | Number of unique nuclei |
2023-03-30 18:17:33 +02:00
| ~type_nucl_vector~ | ~int64_t[nucl_num]~ | in | IDs of unique nuclei |
2023-03-30 12:34:17 +02:00
| ~aord_num~ | ~int64_t~ | in | Number of coefficients |
| ~a_vector~ | ~double[aord_num+1][type_nucl_num]~ | in | List of coefficients |
| ~en_distance_rescaled~ | ~double[walk_num][nucl_num][elec_num]~ | in | Electron-nucleus distances |
| ~en_distance_rescaled_deriv_e~ | ~double[walk_num][4][nucl_num][elec_num]~ | in | Electron-nucleus distance derivatives |
| ~factor_en_deriv_e~ | ~double[walk_num][4][elec_num]~ | out | Electron-nucleus jastrow |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2023-03-31 13:37:35 +02:00
integer function qmckl_compute_jastrow_champ_factor_en_deriv_e_f( &
2023-03-30 12:34:17 +02:00
context, walk_num, elec_num, nucl_num, type_nucl_num, &
type_nucl_vector, aord_num, a_vector, &
en_distance_rescaled, en_distance_rescaled_deriv_e, factor_en_deriv_e) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
2023-03-30 12:34:17 +02:00
integer*8 , intent(in) :: walk_num, elec_num, aord_num, nucl_num, type_nucl_num
integer*8 , intent(in) :: type_nucl_vector(nucl_num)
double precision , intent(in) :: a_vector(aord_num + 1, type_nucl_num)
double precision , intent(in) :: en_distance_rescaled(elec_num, nucl_num, walk_num)
double precision , intent(in) :: en_distance_rescaled_deriv_e(4, elec_num, nucl_num, walk_num)
double precision , intent(out) :: factor_en_deriv_e(elec_num,4,walk_num)
2023-03-30 12:34:17 +02:00
integer*8 :: i, a, p, ipar, nw, ii
double precision :: x, den, invden, invden2, invden3, xinv
double precision :: y, lap1, lap2, lap3, third
double precision, dimension(3) :: power_ser_g
double precision, dimension(4) :: dx
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2023-03-30 12:34:17 +02:00
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
2023-03-30 12:34:17 +02:00
if (elec_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
2023-03-30 12:34:17 +02:00
if (nucl_num <= 0) then
info = QMCKL_INVALID_ARG_4
return
endif
2023-03-30 12:34:17 +02:00
if (aord_num < 0) then
info = QMCKL_INVALID_ARG_7
return
endif
2023-03-30 12:34:17 +02:00
factor_en_deriv_e = 0.0d0
third = 1.0d0 / 3.0d0
2023-03-30 12:34:17 +02:00
do nw =1, walk_num
do a = 1, nucl_num
do i = 1, elec_num
x = en_distance_rescaled(i,a,nw)
if(abs(x) < 1.0d-18) continue
power_ser_g = 0.0d0
den = 1.0d0 + a_vector(2, type_nucl_vector(a)) * x
invden = 1.0d0 / den
invden2 = invden * invden
invden3 = invden2 * invden
xinv = 1.0d0 / x
2023-03-30 12:34:17 +02:00
do ii = 1, 4
dx(ii) = en_distance_rescaled_deriv_e(ii,i,a,nw)
end do
2023-03-30 12:34:17 +02:00
lap1 = 0.0d0
lap2 = 0.0d0
lap3 = 0.0d0
do ii = 1, 3
x = en_distance_rescaled(i, a, nw)
do p = 2, aord_num
y = p * a_vector(p + 1, type_nucl_vector(a)) * x
power_ser_g(ii) = power_ser_g(ii) + y * dx(ii)
lap1 = lap1 + (p - 1) * y * xinv * dx(ii) * dx(ii)
lap2 = lap2 + y
x = x * en_distance_rescaled(i, a, nw)
end do
2023-03-30 12:34:17 +02:00
lap3 = lap3 - 2.0d0 * a_vector(2, type_nucl_vector(a)) * dx(ii) * dx(ii)
2023-03-30 12:34:17 +02:00
factor_en_deriv_e(i, ii, nw) = factor_en_deriv_e(i, ii, nw) + a_vector(1, type_nucl_vector(a)) &
,* dx(ii) * invden2 &
+ power_ser_g(ii)
2023-03-30 12:34:17 +02:00
end do
2023-03-30 12:34:17 +02:00
ii = 4
lap2 = lap2 * dx(ii) * third
lap3 = lap3 + den * dx(ii)
lap3 = lap3 * a_vector(1, type_nucl_vector(a)) * invden3
factor_en_deriv_e(i, ii, nw) = factor_en_deriv_e(i, ii, nw) + lap1 + lap2 + lap3
2023-03-30 12:34:17 +02:00
end do
end do
end do
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_en_deriv_e_f
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_en_deriv_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_en_deriv_e (
2023-03-30 12:34:17 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
const int64_t aord_num,
const double* a_vector,
const double* en_distance_rescaled,
const double* en_distance_rescaled_deriv_e,
double* const factor_en_deriv_e );
#+end_src
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_factor_en_deriv_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
2023-03-31 13:37:35 +02:00
integer(c_int32_t) function qmckl_compute_jastrow_champ_factor_en_deriv_e &
2023-03-30 12:34:17 +02:00
(context, &
walk_num, &
elec_num, &
nucl_num, &
type_nucl_num, &
type_nucl_vector, &
aord_num, &
a_vector, &
en_distance_rescaled, &
en_distance_rescaled_deriv_e, &
factor_en_deriv_e) &
bind(C) result(info)
2023-03-30 12:34:17 +02:00
use, intrinsic :: iso_c_binding
implicit none
2023-03-30 12:34:17 +02:00
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 :: type_nucl_num
integer (c_int64_t) , intent(in) :: type_nucl_vector(nucl_num)
integer (c_int64_t) , intent(in) , value :: aord_num
real (c_double ) , intent(in) :: a_vector(type_nucl_num,aord_num+1)
real (c_double ) , intent(in) :: en_distance_rescaled(elec_num,nucl_num,walk_num)
real (c_double ) , intent(in) :: en_distance_rescaled_deriv_e(elec_num,nucl_num,4,walk_num)
real (c_double ) , intent(out) :: factor_en_deriv_e(elec_num,4,walk_num)
2023-03-31 13:37:35 +02:00
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_factor_en_deriv_e_f
info = qmckl_compute_jastrow_champ_factor_en_deriv_e_f &
2023-03-30 12:34:17 +02:00
(context, &
walk_num, &
elec_num, &
nucl_num, &
type_nucl_num, &
type_nucl_vector, &
aord_num, &
a_vector, &
en_distance_rescaled, &
en_distance_rescaled_deriv_e, &
factor_en_deriv_e)
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_en_deriv_e
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Test
#+begin_src python :results output :exports none :noweb yes
import numpy as np
2023-03-30 12:34:17 +02:00
<<jastrow_data>>
2023-03-30 12:34:17 +02:00
kappa = 1.0
2023-03-30 12:34:17 +02:00
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 j in range(nucl_num):
elnuc_dist[i, j] = np.linalg.norm(elec_coord[i] - nucl_coord[:,j])
2023-03-30 12:34:17 +02:00
elnuc_dist_deriv_e = np.zeros(shape=(4, elec_num, nucl_num),dtype=float)
for a in range(nucl_num):
for i in range(elec_num):
rij_inv = 1.0 / elnuc_dist[i, a]
for ii in range(3):
elnuc_dist_deriv_e[ii, i, a] = (elec_coord[i][ii] - nucl_coord[ii][a]) * rij_inv
elnuc_dist_deriv_e[3, i, a] = 2.0 * rij_inv
2023-03-30 12:34:17 +02:00
en_distance_rescaled_deriv_e = np.zeros(shape=(4,elec_num,nucl_num),dtype=float)
for a in range(nucl_num):
for i in range(elec_num):
f = 1.0 - kappa * en_distance_rescaled[i][a]
for ii in range(4):
en_distance_rescaled_deriv_e[ii][i][a] = elnuc_dist_deriv_e[ii][i][a]
en_distance_rescaled_deriv_e[3][i][a] = en_distance_rescaled_deriv_e[3][i][a] + \
(-kappa * en_distance_rescaled_deriv_e[0][i][a] * en_distance_rescaled_deriv_e[0][i][a]) + \
(-kappa * en_distance_rescaled_deriv_e[1][i][a] * en_distance_rescaled_deriv_e[1][i][a]) + \
(-kappa * en_distance_rescaled_deriv_e[2][i][a] * en_distance_rescaled_deriv_e[2][i][a])
for ii in range(4):
en_distance_rescaled_deriv_e[ii][i][a] = en_distance_rescaled_deriv_e[ii][i][a] * f
2023-03-30 12:34:17 +02:00
third = 1.0 / 3.0
factor_en_deriv_e = np.zeros(shape=(4,elec_num),dtype=float)
dx = np.zeros(shape=(4),dtype=float)
pow_ser_g = np.zeros(shape=(3),dtype=float)
for a in range(nucl_num):
for i in range(elec_num):
x = en_distance_rescaled[i][a]
if abs(x) < 1e-18:
continue
pow_ser_g = np.zeros(shape=(3),dtype=float)
den = 1.0 + a_vector[1][type_nucl_vector[a]-1] * x
invden = 1.0 / den
invden2 = invden * invden
invden3 = invden2 * invden
xinv = 1.0 / (x + 1.0E-18)
for ii in range(4):
dx[ii] = en_distance_rescaled_deriv_e[ii][i][a]
lap1 = 0.0
lap2 = 0.0
lap3 = 0.0
for ii in range(3):
x = en_distance_rescaled[i][a]
if x < 1e-18:
continue
for p in range(2,aord_num+1):
y = p * a_vector[(p-1) + 1][type_nucl_vector[a]-1] * x
pow_ser_g[ii] = pow_ser_g[ii] + y * dx[ii]
lap1 = lap1 + (p - 1) * y * xinv * dx[ii] * dx[ii]
lap2 = lap2 + y
x = x * en_distance_rescaled[i][a]
lap3 = lap3 - 2.0 * a_vector[1][type_nucl_vector[a]-1] * dx[ii] * dx[ii]
factor_en_deriv_e[ii][i] = factor_en_deriv_e[ii][i] + a_vector[0][type_nucl_vector[a]-1] * \
dx[ii] * invden2 + pow_ser_g[ii]
ii = 3
lap2 = lap2 * dx[ii] * third
lap3 = lap3 + den * dx[ii]
lap3 = lap3 * (a_vector[0][type_nucl_vector[a]-1] * invden3)
factor_en_deriv_e[ii][i] = factor_en_deriv_e[ii][i] + lap1 + lap2 + lap3
print("factor_en_deriv_e[0][0]:",factor_en_deriv_e[0][0])
print("factor_en_deriv_e[1][0]:",factor_en_deriv_e[1][0])
print("factor_en_deriv_e[2][0]:",factor_en_deriv_e[2][0])
print("factor_en_deriv_e[3][0]:",factor_en_deriv_e[3][0])
#+end_src
#+RESULTS:
: factor_en_deriv_e[0][0]: 0.11609919541763383
: factor_en_deriv_e[1][0]: -0.23301394780804574
: factor_en_deriv_e[2][0]: 0.17548337641865783
: factor_en_deriv_e[3][0]: -0.9667363412285741
#+begin_src c :tangle (eval c_test)
/* Check if Jastrow is properly initialized */
2023-03-30 17:07:11 +02:00
assert(qmckl_jastrow_champ_provided(context));
2023-03-30 12:34:17 +02:00
// calculate factor_en_deriv_e
double factor_en_deriv_e[walk_num][4][elec_num];
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_factor_en_deriv_e(context, &(factor_en_deriv_e[0][0][0]),walk_num*4*elec_num);
2023-03-30 12:34:17 +02:00
// check factor_en_deriv_e
assert(fabs(factor_en_deriv_e[0][0][0]-0.11609919541763383) < 1.e-12);
assert(fabs(factor_en_deriv_e[0][1][0]+0.23301394780804574) < 1.e-12);
assert(fabs(factor_en_deriv_e[0][2][0]-0.17548337641865783) < 1.e-12);
assert(fabs(factor_en_deriv_e[0][3][0]+0.9667363412285741 ) < 1.e-12);
#+end_src
*** Electron-nucleus rescaled distances
~en_distance_rescaled~ stores the matrix of the rescaled distances between
electrons and nuclei.
\[
C_{i\alpha} = \frac{ 1 - e^{-\kappa_\alpha R_{i\alpha}}}{\kappa_\alpha}
\]
where \(R_{i\alpha}\) is the matrix of electron-nucleus distances.
**** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
qmckl_exit_code qmckl_get_electron_en_distance_rescaled(qmckl_context context, double* distance_rescaled);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_get_electron_en_distance_rescaled(qmckl_context context, double* distance_rescaled)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
2023-03-30 12:34:17 +02:00
qmckl_exit_code rc;
rc = qmckl_provide_en_distance_rescaled(context);
if (rc != QMCKL_SUCCESS) return rc;
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
size_t sze = ctx->electron.num * ctx->nucleus.num * ctx->electron.walker.num;
2023-03-30 17:07:11 +02:00
memcpy(distance_rescaled, ctx->jastrow_champ.en_distance_rescaled, sze * sizeof(double));
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_provide_en_distance_rescaled(qmckl_context context);
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_provide_en_distance_rescaled(qmckl_context context)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 12:34:17 +02:00
if (!(ctx->nucleus.provided)) {
return QMCKL_NOT_PROVIDED;
}
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->electron.walker.point.date > ctx->jastrow_champ.en_distance_rescaled_date) {
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.en_distance_rescaled != NULL) {
qmckl_exit_code rc = qmckl_free(context, ctx->jastrow_champ.en_distance_rescaled);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-30 12:34:17 +02:00
"qmckl_provide_en_distance_rescaled",
2023-03-30 17:07:11 +02:00
"Unable to free ctx->jastrow_champ.en_distance_rescaled");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.en_distance_rescaled = NULL;
}
}
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.en_distance_rescaled == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 12:34:17 +02:00
mem_info.size = ctx->electron.num * ctx->nucleus.num *
ctx->electron.walker.num * sizeof(double);
double* en_distance_rescaled = (double*) qmckl_malloc(context, mem_info);
2023-03-30 12:34:17 +02:00
if (en_distance_rescaled == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 12:34:17 +02:00
"qmckl_provide_en_distance_rescaled",
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.en_distance_rescaled = en_distance_rescaled;
}
2023-03-30 12:34:17 +02:00
qmckl_exit_code rc =
qmckl_compute_en_distance_rescaled(context,
ctx->electron.num,
ctx->nucleus.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.type_nucl_num,
ctx->jastrow_champ.type_nucl_vector,
ctx->jastrow_champ.rescale_factor_en,
2023-03-30 12:34:17 +02:00
ctx->electron.walker.num,
ctx->electron.walker.point.coord.data,
ctx->nucleus.coord.data,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.en_distance_rescaled);
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.en_distance_rescaled_date = ctx->date;
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
:Name: qmckl_compute_en_distance_rescaled
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_en_distance_rescaled_args
| Variable | Type | In/Out | Description |
|------------------------+----------------------------------------+--------+-----------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~nucl_num~ | ~int64_t~ | in | Number of nuclei |
| ~type_nucl_num~ | ~int64_t~ | in | Number of types of nuclei |
| ~type_nucl_vector~ | ~int64_t[nucl_num]~ | in | Number of types of nuclei |
| ~rescale_factor_en~ | ~double[type_nucl_num]~ | in | The factor for rescaled distances |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_coord~ | ~double[3][walk_num][elec_num]~ | in | Electron coordinates |
| ~nucl_coord~ | ~double[3][elec_num]~ | in | Nuclear coordinates |
| ~en_distance_rescaled~ | ~double[walk_num][nucl_num][elec_num]~ | out | Electron-nucleus distances |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_en_distance_rescaled_f(context, elec_num, nucl_num, type_nucl_num, &
type_nucl_vector, rescale_factor_en, walk_num, elec_coord, &
nucl_coord, en_distance_rescaled) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: elec_num
2023-03-30 12:34:17 +02:00
integer*8 , intent(in) :: nucl_num
integer*8 , intent(in) :: type_nucl_num
integer*8 , intent(in) :: type_nucl_vector(nucl_num)
double precision , intent(in) :: rescale_factor_en(type_nucl_num)
integer*8 , intent(in) :: walk_num
double precision , intent(in) :: elec_coord(elec_num,walk_num,3)
double precision , intent(in) :: nucl_coord(nucl_num,3)
double precision , intent(out) :: en_distance_rescaled(elec_num,nucl_num,walk_num)
integer*8 :: i, k
double precision :: coord(3)
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2023-03-30 12:34:17 +02:00
if (elec_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
2023-03-30 12:34:17 +02:00
if (nucl_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
2023-03-30 12:34:17 +02:00
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_5
return
endif
2023-03-30 12:34:17 +02:00
do i=1, nucl_num
coord(1:3) = nucl_coord(i,1:3)
do k=1,walk_num
info = qmckl_distance_rescaled(context, 'T', 'T', elec_num, 1_8, &
elec_coord(1,k,1), elec_num*walk_num, coord, 1_8, &
en_distance_rescaled(1,i,k), elec_num, rescale_factor_en(type_nucl_vector(i)))
if (info /= QMCKL_SUCCESS) then
return
endif
end do
end do
2023-03-30 12:34:17 +02:00
end function qmckl_compute_en_distance_rescaled_f
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval h_private_func) :comments org :exports none
qmckl_exit_code qmckl_compute_en_distance_rescaled (
const qmckl_context context,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t type_nucl_num,
int64_t* const type_nucl_vector,
const double* rescale_factor_en,
const int64_t walk_num,
const double* elec_coord,
const double* nucl_coord,
double* const en_distance_rescaled );
#+end_src
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_en_distance_rescaled_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_en_distance_rescaled &
(context, &
elec_num, &
nucl_num, &
type_nucl_num, &
type_nucl_vector, &
rescale_factor_en, &
walk_num, &
elec_coord, &
nucl_coord, &
en_distance_rescaled) &
bind(C) result(info)
2023-03-30 12:34:17 +02:00
use, intrinsic :: iso_c_binding
implicit none
2023-03-30 12:34:17 +02:00
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 :: type_nucl_num
integer (c_int64_t) , intent(in) :: type_nucl_vector(nucl_num)
real (c_double ) , intent(in) :: rescale_factor_en(type_nucl_num)
integer (c_int64_t) , intent(in) , value :: walk_num
real (c_double ) , intent(in) :: elec_coord(elec_num,walk_num,3)
real (c_double ) , intent(in) :: nucl_coord(elec_num,3)
real (c_double ) , intent(out) :: en_distance_rescaled(elec_num,nucl_num,walk_num)
2023-03-30 12:34:17 +02:00
integer(c_int32_t), external :: qmckl_compute_en_distance_rescaled_f
info = qmckl_compute_en_distance_rescaled_f &
(context, &
elec_num, &
nucl_num, &
type_nucl_num, &
type_nucl_vector, &
rescale_factor_en, &
walk_num, &
elec_coord, &
nucl_coord, &
en_distance_rescaled)
2023-03-30 12:34:17 +02:00
end function qmckl_compute_en_distance_rescaled
#+end_src
2023-03-30 12:34:17 +02:00
**** Test
2023-03-30 12:34:17 +02:00
#+begin_src python :results output :exports none
import numpy as np
2023-03-30 12:34:17 +02:00
kappa = 1.0
2023-03-30 12:34:17 +02:00
elec_1_w1 = np.array( [-0.250655104764153, 0.503070975550133 , -0.166554344502303])
elec_2_w1 = np.array( [-0.587812193472177, -0.128751981129274 , 0.187773606533075])
elec_5_w1 = np.array( [-0.127732483187947, -0.138975497694196 , -8.669850480215846E-002])
elec_6_w1 = np.array( [-0.232271834949124, -1.059321673434182E-002 , -0.504862241464867])
nucl_1 = np.array( [ 0., 0., 0. ])
nucl_2 = np.array( [ 0., 0., 2.059801 ])
2023-03-30 12:34:17 +02:00
print ( "[0][0] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_1_w1-nucl_1)) )/kappa )
print ( "[1][0] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_1_w1-nucl_2)) )/kappa )
print ( "[0][1] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_2_w1-nucl_1)) )/kappa )
print ( "[0][5] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_5_w1-nucl_1)) )/kappa )
print ( "[1][5] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_5_w1-nucl_2)) )/kappa )
print ( "[0][6] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_6_w1-nucl_1)) )/kappa )
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+RESULTS:
: [0][0] : 0.4435709484118112
: [1][0] : 0.8993601506374442
: [0][1] : 0.46760219699910477
: [0][5] : 0.1875631834682101
: [1][5] : 0.8840716589810682
: [0][6] : 0.42640469987268914
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval c_test)
2023-03-30 12:34:17 +02:00
assert(qmckl_electron_provided(context));
assert(qmckl_nucleus_provided(context));
2023-03-30 12:34:17 +02:00
double en_distance_rescaled[walk_num][nucl_num][elec_num];
2023-03-30 12:34:17 +02:00
rc = qmckl_check(context,
qmckl_get_electron_en_distance_rescaled(context, &(en_distance_rescaled[0][0][0]))
);
assert (rc == QMCKL_SUCCESS);
2023-03-30 12:34:17 +02:00
// (e,n,w) in Fortran notation
// (1,1,1)
assert(fabs(en_distance_rescaled[0][0][0] - 0.4435709484118112) < 1.e-12);
2023-03-30 12:34:17 +02:00
// (1,2,1)
assert(fabs(en_distance_rescaled[0][1][0] - 0.8993601506374442) < 1.e-12);
2023-03-30 12:34:17 +02:00
// (2,1,1)
assert(fabs(en_distance_rescaled[0][0][1] - 0.46760219699910477) < 1.e-12);
2023-03-30 12:34:17 +02:00
// (1,1,2)
assert(fabs(en_distance_rescaled[0][0][5] - 0.1875631834682101) < 1.e-12);
2023-01-26 17:49:24 +01:00
2023-03-30 12:34:17 +02:00
// (1,2,2)
assert(fabs(en_distance_rescaled[0][1][5] - 0.8840716589810682) < 1.e-12);
2023-01-26 17:49:24 +01:00
2023-03-30 12:34:17 +02:00
// (2,1,2)
assert(fabs(en_distance_rescaled[0][0][6] - 0.42640469987268914) < 1.e-12);
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
*** Electron-electron rescaled distance gradients and Laplacian with respect to electron coordinates
2023-03-30 12:34:17 +02:00
The rescaled distances, represented by $C_{i\alpha} = (1 - e^{-\kappa_\alpha R_{i\alpha}})/\kappa$
are differentiated with respect to the electron coordinates.
This information is stored in the tensor
~en_distance_rescaled_deriv_e~. The initial three sequential
elements of this three-index tensor provide the $x$, $y$, and $z$
direction derivatives, while the fourth index corresponds to the Laplacian.
2023-03-30 12:34:17 +02:00
**** Get
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
qmckl_exit_code qmckl_get_electron_en_distance_rescaled_deriv_e(qmckl_context context, double* distance_rescaled_deriv_e);
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_get_electron_en_distance_rescaled_deriv_e(qmckl_context context, double* distance_rescaled_deriv_e)
{
2023-03-30 12:34:17 +02:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
2023-03-30 12:34:17 +02:00
qmckl_exit_code rc;
2023-03-30 12:34:17 +02:00
rc = qmckl_provide_en_distance_rescaled_deriv_e(context);
if (rc != QMCKL_SUCCESS) return rc;
2023-03-30 12:34:17 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 12:34:17 +02:00
size_t sze = 4 * ctx->electron.num * ctx->nucleus.num * ctx->electron.walker.num;
2023-03-30 17:07:11 +02:00
memcpy(distance_rescaled_deriv_e, ctx->jastrow_champ.en_distance_rescaled_deriv_e, sze * sizeof(double));
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_provide_en_distance_rescaled_deriv_e(qmckl_context context);
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_provide_en_distance_rescaled_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*) context;
assert (ctx != NULL);
2023-03-30 12:34:17 +02:00
if (!(ctx->nucleus.provided)) {
return QMCKL_NOT_PROVIDED;
}
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->electron.walker.point.date > ctx->jastrow_champ.en_distance_rescaled_deriv_e_date) {
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.en_distance_rescaled_deriv_e != NULL) {
qmckl_exit_code rc = qmckl_free(context, ctx->jastrow_champ.en_distance_rescaled_deriv_e);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-30 12:34:17 +02:00
"qmckl_provide_en_distance_rescaled_deriv_e",
2023-03-30 17:07:11 +02:00
"Unable to free ctx->jastrow_champ.en_distance_rescaled_deriv_e");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.en_distance_rescaled_deriv_e = NULL;
}
}
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.en_distance_rescaled_deriv_e == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 12:34:17 +02:00
mem_info.size = 4 * ctx->electron.num * ctx->nucleus.num *
ctx->electron.walker.num * sizeof(double);
double* en_distance_rescaled_deriv_e = (double*) qmckl_malloc(context, mem_info);
2023-03-30 12:34:17 +02:00
if (en_distance_rescaled_deriv_e == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 12:34:17 +02:00
"qmckl_provide_en_distance_rescaled_deriv_e",
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.en_distance_rescaled_deriv_e = en_distance_rescaled_deriv_e;
}
2023-03-30 12:34:17 +02:00
qmckl_exit_code rc =
qmckl_compute_en_distance_rescaled_deriv_e(context,
ctx->electron.num,
ctx->nucleus.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.type_nucl_num,
ctx->jastrow_champ.type_nucl_vector,
ctx->jastrow_champ.rescale_factor_en,
2023-03-30 12:34:17 +02:00
ctx->electron.walker.num,
ctx->electron.walker.point.coord.data,
ctx->nucleus.coord.data,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.en_distance_rescaled_deriv_e);
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.en_distance_rescaled_deriv_e_date = ctx->date;
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
:Name: qmckl_compute_en_distance_rescaled_deriv_e
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_en_distance_rescaled_deriv_e_args
| Variable | Type | In/Out | Description |
|--------------------------------+-------------------------------------------+--------+---------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~nucl_num~ | ~int64_t~ | in | Number of nuclei |
| ~type_nucl_num~ | ~int64_t~ | in | Number of nucleus types |
| ~type_nucl_vector~ | ~int64_t[nucl_num]~ | in | Array of nucleus types |
| ~rescale_factor_en~ | ~double[nucl_num]~ | in | The factors for rescaled distances |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_coord~ | ~double[3][walk_num][elec_num]~ | in | Electron coordinates |
| ~nucl_coord~ | ~double[3][elec_num]~ | in | Nuclear coordinates |
| ~en_distance_rescaled_deriv_e~ | ~double[walk_num][nucl_num][elec_num][4]~ | out | Electron-nucleus distance derivatives |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_en_distance_rescaled_deriv_e_f(context, elec_num, nucl_num, &
type_nucl_num, type_nucl_vector, rescale_factor_en, walk_num, elec_coord, &
nucl_coord, en_distance_rescaled_deriv_e) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: elec_num
2023-03-30 12:34:17 +02:00
integer*8 , intent(in) :: nucl_num
integer*8 , intent(in) :: type_nucl_num
integer*8 , intent(in) :: type_nucl_vector(nucl_num)
double precision , intent(in) :: rescale_factor_en(nucl_num)
integer*8 , intent(in) :: walk_num
double precision , intent(in) :: elec_coord(elec_num,walk_num,3)
double precision , intent(in) :: nucl_coord(nucl_num,3)
double precision , intent(out) :: en_distance_rescaled_deriv_e(4,elec_num,nucl_num,walk_num)
2023-03-30 12:34:17 +02:00
integer*8 :: i, k
double precision :: coord(3)
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2023-03-30 12:34:17 +02:00
if (elec_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
2023-03-30 12:34:17 +02:00
if (nucl_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
2023-03-30 12:34:17 +02:00
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_5
return
endif
2023-03-30 12:34:17 +02:00
do i=1, nucl_num
coord(1:3) = nucl_coord(i,1:3)
do k=1,walk_num
info = qmckl_distance_rescaled_deriv_e(context, 'T', 'T', elec_num, 1_8, &
elec_coord(1,k,1), elec_num*walk_num, coord, 1_8, &
en_distance_rescaled_deriv_e(1,1,i,k), elec_num, rescale_factor_en(type_nucl_vector(i)))
if (info /= QMCKL_SUCCESS) then
return
endif
end do
end do
2023-03-30 12:34:17 +02:00
end function qmckl_compute_en_distance_rescaled_deriv_e_f
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval h_private_func) :comments org :exports none
qmckl_exit_code qmckl_compute_en_distance_rescaled_deriv_e (
const qmckl_context context,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t type_nucl_num,
int64_t* const type_nucl_vector,
const double* rescale_factor_en,
const int64_t walk_num,
const double* elec_coord,
const double* nucl_coord,
double* const en_distance_rescaled_deriv_e );
#+end_src
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_en_distance_rescaled_deriv_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_en_distance_rescaled_deriv_e &
(context, &
elec_num, &
2023-03-30 12:34:17 +02:00
nucl_num, &
type_nucl_num, &
type_nucl_vector, &
rescale_factor_en, &
walk_num, &
elec_coord, &
nucl_coord, &
en_distance_rescaled_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 :: elec_num
2023-03-30 12:34:17 +02:00
integer (c_int64_t) , intent(in) , value :: nucl_num
integer (c_int64_t) , intent(in) , value :: type_nucl_num
integer (c_int64_t) , intent(in) :: type_nucl_vector(nucl_num)
real (c_double ) , intent(in) :: rescale_factor_en(nucl_num)
integer (c_int64_t) , intent(in) , value :: walk_num
real (c_double ) , intent(in) :: elec_coord(elec_num,walk_num,3)
real (c_double ) , intent(in) :: nucl_coord(elec_num,3)
real (c_double ) , intent(out) :: en_distance_rescaled_deriv_e(4,elec_num,nucl_num,walk_num)
2023-03-30 12:34:17 +02:00
integer(c_int32_t), external :: qmckl_compute_en_distance_rescaled_deriv_e_f
info = qmckl_compute_en_distance_rescaled_deriv_e_f &
(context, &
elec_num, &
2023-03-30 12:34:17 +02:00
nucl_num, &
type_nucl_num, &
type_nucl_vector, &
rescale_factor_en, &
walk_num, &
elec_coord, &
nucl_coord, &
en_distance_rescaled_deriv_e)
2023-03-30 12:34:17 +02:00
end function qmckl_compute_en_distance_rescaled_deriv_e
#+end_src
2023-03-30 12:34:17 +02:00
**** Test
2023-03-30 12:34:17 +02:00
#+begin_src python :results output :exports none
import numpy as np
2023-03-30 12:34:17 +02:00
# TODO
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval c_test)
2023-03-30 12:34:17 +02:00
assert(qmckl_electron_provided(context));
2023-03-30 12:34:17 +02:00
assert(qmckl_nucleus_provided(context));
2023-03-30 12:34:17 +02:00
double en_distance_rescaled_deriv_e[walk_num][4][nucl_num][elec_num];
2023-03-30 12:34:17 +02:00
rc = qmckl_check(context,
qmckl_get_electron_en_distance_rescaled_deriv_e(context, &(en_distance_rescaled_deriv_e[0][0][0][0]))
);
assert (rc == QMCKL_SUCCESS);
2023-03-30 12:34:17 +02:00
// TODO: check exact values
//// (e,n,w) in Fortran notation
//// (1,1,1)
//assert(fabs(en_distance_rescaled[0][0][0] - 7.546738741619978) < 1.e-12);
//
//// (1,2,1)
//assert(fabs(en_distance_rescaled[0][1][0] - 8.77102435246984) < 1.e-12);
//
//// (2,1,1)
//assert(fabs(en_distance_rescaled[0][0][1] - 3.698922010513608) < 1.e-12);
//
//// (1,1,2)
//assert(fabs(en_distance_rescaled[1][0][0] - 5.824059436060509) < 1.e-12);
//
//// (1,2,2)
//assert(fabs(en_distance_rescaled[1][1][0] - 7.080482110317645) < 1.e-12);
//
//// (2,1,2)
//assert(fabs(en_distance_rescaled[1][0][1] - 3.1804527583077356) < 1.e-12);
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
** Electron-electron-nucleus component
*** Electron-electron rescaled distances in $J_\text{eeN}$
2023-03-30 12:34:17 +02:00
~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~:
2023-03-30 12:34:17 +02:00
\[
C_{ij,p} = \left[ \exp\left(-\kappa_\text{e}\, r_{ij}\right) \right]^p
\]
2023-03-30 12:34:17 +02:00
where \(r_{ij}\) is the matrix of electron-electron distances.
2023-03-30 12:34:17 +02:00
**** Get
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_een_rescaled_e(qmckl_context context,
2023-03-30 12:34:17 +02:00
double* const distance_rescaled,
const int64_t size_max);
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_een_rescaled_e(qmckl_context context,
2023-03-30 12:34:17 +02:00
double* const distance_rescaled,
const int64_t size_max)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
2023-03-30 12:34:17 +02:00
rc = qmckl_provide_een_rescaled_e(context);
if (rc != QMCKL_SUCCESS) return rc;
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
int64_t sze = ctx->electron.num * ctx->electron.num * ctx->electron.walker.num * (ctx->jastrow_champ.cord_num + 1);
2023-03-30 12:34:17 +02:00
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_factor_een_rescaled_e",
"Array too small. Expected ctx->electron.num * ctx->electron.num * ctx->electron.walker.num * (ctx->jastrow_champ.cord_num + 1)");
2023-03-30 12:34:17 +02:00
}
2023-03-30 17:07:11 +02:00
memcpy(distance_rescaled, ctx->jastrow_champ.een_rescaled_e, sze * sizeof(double));
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_provide_een_rescaled_e(qmckl_context context);
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_provide_een_rescaled_e(qmckl_context context)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
2022-04-08 10:44:48 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 12:34:17 +02:00
/* Check if ee distance is provided */
qmckl_exit_code rc = qmckl_provide_ee_distance(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.een_rescaled_e_date) {
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.een_rescaled_e != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.een_rescaled_e);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-30 12:34:17 +02:00
"qmckl_provide_een_rescaled_e",
2023-03-30 17:07:11 +02:00
"Unable to free ctx->jastrow_champ.een_rescaled_e");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_e = NULL;
}
}
2022-04-08 10:44:48 +02:00
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.een_rescaled_e == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 12:34:17 +02:00
mem_info.size = ctx->electron.num * ctx->electron.num *
2023-03-30 17:07:11 +02:00
ctx->electron.walker.num * (ctx->jastrow_champ.cord_num + 1) * sizeof(double);
2023-03-30 12:34:17 +02:00
double* een_rescaled_e = (double*) qmckl_malloc(context, mem_info);
2022-04-08 10:44:48 +02:00
2023-03-30 12:34:17 +02:00
if (een_rescaled_e == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 12:34:17 +02:00
"qmckl_provide_een_rescaled_e",
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_e = een_rescaled_e;
}
2023-03-30 12:34:17 +02:00
rc = qmckl_compute_een_rescaled_e(context,
ctx->electron.walker.num,
ctx->electron.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.cord_num,
ctx->jastrow_champ.rescale_factor_ee,
2023-03-30 12:34:17 +02:00
ctx->electron.ee_distance,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_e);
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_e_date = ctx->date;
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
:Name: qmckl_compute_een_rescaled_e
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_een_rescaled_e_args
2023-03-30 17:07:11 +02:00
| Variable | Type | In/Out | Description |
|---------------------+----------------------------------------------------+--------+------------------------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~cord_num~ | ~int64_t~ | in | Order of polynomials |
| ~rescale_factor_ee~ | ~double~ | in | Factor to rescale ee distances |
| ~ee_distance~ | ~double[walk_num][elec_num][elec_num]~ | in | Electron-electron distances for each walker |
| ~een_rescaled_e~ | ~double[walk_num][0:cord_num][elec_num][elec_num]~ | out | Electron-electron rescaled distances for each walker |
2023-03-30 12:34:17 +02:00
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_een_rescaled_e_doc_f( &
context, walk_num, elec_num, cord_num, rescale_factor_ee, &
ee_distance, een_rescaled_e) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: walk_num
2023-03-30 12:34:17 +02:00
integer*8 , intent(in) :: elec_num
integer*8 , intent(in) :: cord_num
double precision , intent(in) :: rescale_factor_ee
double precision , intent(in) :: ee_distance(elec_num,elec_num,walk_num)
double precision , intent(out) :: een_rescaled_e(elec_num,elec_num,0:cord_num,walk_num)
double precision,dimension(:,:),allocatable :: een_rescaled_e_ij
double precision :: x
integer*8 :: i, j, k, l, nw
2022-04-08 10:44:48 +02:00
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2023-03-30 12:34:17 +02:00
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
2023-03-30 12:34:17 +02:00
if (elec_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
2023-03-30 12:34:17 +02:00
if (cord_num < 0) then
info = QMCKL_INVALID_ARG_4
return
endif
2023-03-30 12:34:17 +02:00
allocate(een_rescaled_e_ij(elec_num * (elec_num - 1) / 2, cord_num + 1))
! Prepare table of exponentiated distances raised to appropriate power
een_rescaled_e = 0.0d0
do nw = 1, walk_num
2023-04-11 19:16:14 +02:00
een_rescaled_e_ij = 0.0d0
een_rescaled_e_ij(:, 1) = 1.0d0
2023-03-30 12:34:17 +02:00
2023-04-11 19:16:14 +02:00
k = 0
do j = 1, elec_num
do i = 1, j - 1
k = k + 1
een_rescaled_e_ij(k, 2) = dexp(-rescale_factor_ee * ee_distance(i, j, nw))
end do
end do
2023-04-11 19:16:14 +02:00
do l = 2, cord_num
do k = 1, elec_num * (elec_num - 1)/2
een_rescaled_e_ij(k, l + 1) = een_rescaled_e_ij(k, l) * een_rescaled_e_ij(k, 2)
end do
end do
2023-03-30 12:34:17 +02:00
2023-04-11 19:16:14 +02:00
! prepare the actual een table
een_rescaled_e(:, :, 0, nw) = 1.0d0
do l = 1, cord_num
k = 0
do j = 1, elec_num
do i = 1, j - 1
k = k + 1
x = een_rescaled_e_ij(k, l + 1)
een_rescaled_e(i, j, l, nw) = x
een_rescaled_e(j, i, l, nw) = x
end do
end do
end do
2023-03-30 12:34:17 +02:00
2023-04-11 19:16:14 +02:00
do l = 0, cord_num
do j = 1, elec_num
een_rescaled_e(j, j, l, nw) = 0.0d0
end do
end do
2023-03-30 12:34:17 +02:00
end do
end function qmckl_compute_een_rescaled_e_doc_f
#+end_src
# #+CALL: generate_c_header(table=qmckl_factor_een_rescaled_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_compute_een_rescaled_e (
const qmckl_context context,
const int64_t walk_num,
2023-03-30 12:34:17 +02:00
const int64_t elec_num,
const int64_t cord_num,
const double rescale_factor_ee,
const double* ee_distance,
double* const een_rescaled_e );
#+end_src
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_factor_een_rescaled_e_args,rettyp=get_value("CRetType"),fname="qmckl_compute_een_rescaled_e_doc")
2022-02-14 19:11:37 +01:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_een_rescaled_e_doc &
(context, walk_num, elec_num, cord_num, rescale_factor_ee, &
ee_distance, een_rescaled_e) &
bind(C) result(info)
2021-07-07 07:53:04 +02:00
use, intrinsic :: iso_c_binding
implicit none
2021-07-07 07:53:04 +02:00
integer (c_int64_t) , intent(in) , value :: context
integer (c_int64_t) , intent(in) , value :: walk_num
2023-03-30 12:34:17 +02:00
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_ee
real (c_double ) , intent(in) :: ee_distance(elec_num,elec_num,walk_num)
real (c_double ) , intent(out) :: een_rescaled_e(elec_num,elec_num,0:cord_num,walk_num)
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
integer(c_int32_t), external :: qmckl_compute_een_rescaled_e_doc_f
info = qmckl_compute_een_rescaled_e_doc_f &
(context, walk_num, elec_num, cord_num, rescale_factor_ee, ee_distance, een_rescaled_e)
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
end function qmckl_compute_een_rescaled_e_doc
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes
qmckl_exit_code qmckl_compute_een_rescaled_e_hpc (
2023-03-31 19:58:30 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t cord_num,
const double rescale_factor_ee,
const double* ee_distance,
double* const een_rescaled_e ) {
2023-03-30 12:34:17 +02:00
if (context == QMCKL_NULL_CONTEXT) {
2023-03-31 19:58:30 +02:00
return QMCKL_INVALID_CONTEXT;
2023-03-30 12:34:17 +02:00
}
if (walk_num <= 0) {
2023-03-31 19:58:30 +02:00
return QMCKL_INVALID_ARG_2;
2023-03-30 12:34:17 +02:00
}
if (elec_num <= 0) {
2023-03-31 19:58:30 +02:00
return QMCKL_INVALID_ARG_3;
2023-03-30 12:34:17 +02:00
}
if (cord_num < 0) {
2023-03-31 19:58:30 +02:00
return QMCKL_INVALID_ARG_4;
2023-03-30 12:34:17 +02:00
}
// Prepare table of exponentiated distances raised to appropriate power
// init
2023-04-11 19:16:14 +02:00
memset(een_rescaled_e,0,walk_num*(cord_num+1)*elec_num*elec_num*sizeof(double));
2023-03-30 12:34:17 +02:00
2023-04-11 18:51:05 +02:00
const size_t elec_pairs = (size_t) (elec_num * (elec_num - 1)) / 2;
const size_t len_een_ij = (size_t) elec_pairs * (cord_num + 1);
2023-03-30 12:34:17 +02:00
// number of elements for the een_rescaled_e_ij[N_e*(N_e-1)/2][cord+1]
// probably in C is better [cord+1, Ne*(Ne-1)/2]
// elec_pairs = (elec_num * (elec_num - 1)) / 2;
// len_een_ij = elec_pairs * (cord_num + 1);
2023-04-11 18:51:05 +02:00
const size_t e2 = elec_num*elec_num;
2023-03-30 12:34:17 +02:00
2023-03-31 19:58:30 +02:00
#ifdef HAVE_OPENMP
#pragma omp parallel for
#endif
2023-04-11 19:16:14 +02:00
for (size_t nw = 0; nw < (size_t) walk_num; ++nw) {
2023-03-30 12:34:17 +02:00
2023-04-11 19:16:14 +02:00
double een_rescaled_e_ij[len_een_ij];
memset(&(een_rescaled_e_ij[0]),0,len_een_ij*sizeof(double));
for (size_t kk = 0; kk < elec_pairs ; ++kk) {
een_rescaled_e_ij[kk]= 1.0;
2023-03-30 12:34:17 +02:00
}
2023-04-11 18:51:05 +02:00
size_t kk = 0;
2023-04-11 19:16:14 +02:00
for (size_t i = 0; i < (size_t) elec_num; ++i) {
#ifdef HAVE_OPENMP
#pragma omp simd
#endif
2023-04-11 18:51:05 +02:00
for (size_t j = 0; j < i; ++j) {
2023-04-11 19:16:14 +02:00
een_rescaled_e_ij[j + kk + elec_pairs] = -rescale_factor_ee * ee_distance[j + i*elec_num + nw*e2];
2023-03-30 12:34:17 +02:00
}
2023-04-11 19:16:14 +02:00
kk += i;
}
#ifdef HAVE_OPENMP
#pragma omp simd
#endif
for (size_t k = elec_pairs; k < 2*elec_pairs; ++k) {
een_rescaled_e_ij[k] = exp(een_rescaled_e_ij[k]);
2023-03-30 12:34:17 +02:00
}
2023-04-11 19:16:14 +02:00
for (size_t l = 2; l < (size_t) (cord_num+1); ++l) {
#ifdef HAVE_OPENMP
#pragma omp simd
#endif
2023-04-11 18:51:05 +02:00
for (size_t k = 0; k < elec_pairs; ++k) {
2023-03-31 19:58:30 +02:00
// een_rescaled_e_ij(k, l + 1) = een_rescaled_e_ij(k, l + 1 - 1) * een_rescaled_e_ij(k, 2)
2023-03-30 12:34:17 +02:00
een_rescaled_e_ij[k+l*elec_pairs] = een_rescaled_e_ij[k + (l - 1)*elec_pairs] * \
2023-03-31 19:58:30 +02:00
een_rescaled_e_ij[k + elec_pairs];
2023-03-30 12:34:17 +02:00
}
}
2023-04-11 18:51:05 +02:00
double* const een_rescaled_e_ = &(een_rescaled_e[nw*(cord_num+1)*e2]);
2023-03-31 19:58:30 +02:00
// prepare the actual een table
2023-04-11 19:16:14 +02:00
#ifdef HAVE_OPENMP
#pragma omp simd
#endif
2023-04-11 18:51:05 +02:00
for (size_t i = 0; i < e2; ++i){
een_rescaled_e_[i] = 1.0;
2023-03-30 12:34:17 +02:00
}
2023-04-11 19:16:14 +02:00
for ( size_t l = 1; l < (size_t) (cord_num+1); ++l) {
2023-04-11 18:51:05 +02:00
double* x = een_rescaled_e_ij + l*elec_pairs;
double* const een_rescaled_e__ = &(een_rescaled_e_[l*e2]);
double* een_rescaled_e_i = een_rescaled_e__;
2023-04-11 19:16:14 +02:00
for (size_t i = 0; i < (size_t) elec_num; ++i) {
2023-04-11 18:51:05 +02:00
for (size_t j = 0; j < i; ++j) {
een_rescaled_e_i[j] = *x;
een_rescaled_e__[i + j*elec_num] = *x;
x += 1;
2023-03-31 19:58:30 +02:00
}
2023-04-11 18:51:05 +02:00
een_rescaled_e_i += elec_num;
2023-03-30 12:34:17 +02:00
}
}
2023-04-11 18:51:05 +02:00
double* const x0 = &(een_rescaled_e[nw*e2*(cord_num+1)]);
2023-04-11 19:16:14 +02:00
for (size_t l = 0; l < (size_t) (cord_num + 1); ++l) {
2023-04-11 18:51:05 +02:00
double* x1 = &(x0[l*e2]);
2023-04-11 19:16:14 +02:00
for (size_t j = 0; j < (size_t) elec_num; ++j) {
2023-04-11 18:51:05 +02:00
,*x1 = 0.0;
x1 += 1+elec_num;
2023-03-31 19:58:30 +02:00
}
2023-03-30 12:34:17 +02:00
}
}
2023-04-11 19:16:14 +02:00
return QMCKL_SUCCESS;
2023-03-30 12:34:17 +02:00
}
#+end_src
# #+CALL: generate_c_header(table=qmckl_factor_een_rescaled_e_args,rettyp=get_value("CRetType"),fname="qmckl_compute_een_rescaled_e_doc")
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_compute_een_rescaled_e (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t cord_num,
const double rescale_factor_ee,
const double* ee_distance,
double* const een_rescaled_e );
#+end_src
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_een_rescaled_e_doc (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t cord_num,
const double rescale_factor_ee,
const double* ee_distance,
double* const een_rescaled_e );
#+end_src
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_een_rescaled_e_hpc (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t cord_num,
const double rescale_factor_ee,
const double* ee_distance,
double* const een_rescaled_e );
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes
qmckl_exit_code qmckl_compute_een_rescaled_e (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t cord_num,
const double rescale_factor_ee,
const double* ee_distance,
double* const een_rescaled_e ) {
#ifdef HAVE_HPC
return qmckl_compute_een_rescaled_e_hpc(context, walk_num, elec_num, cord_num, rescale_factor_ee, ee_distance, een_rescaled_e);
#else
return qmckl_compute_een_rescaled_e_doc(context, walk_num, elec_num, cord_num, rescale_factor_ee, ee_distance, een_rescaled_e);
#endif
}
#+end_src
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
**** Test
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src python :results output :exports none :noweb yes
import numpy as np
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
<<jastrow_data>>
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
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])
2021-09-22 15:47:39 +02:00
2023-03-30 12:34:17 +02:00
kappa = 1.0
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
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
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
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
2023-03-30 12:34:17 +02:00
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]
2023-03-30 12:34:17 +02:00
een_rescaled_e = np.zeros(shape=(elec_num, elec_num, cord_num + 1), dtype=float)
een_rescaled_e[:,:,0] = 1.0
2023-03-30 12:34:17 +02:00
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
2023-03-30 12:34:17 +02:00
for l in range(0,cord_num+1):
for j in range(0, elec_num):
een_rescaled_e[j,j,l] = 0.0
2021-07-07 09:10:23 +02:00
2023-03-30 12:34:17 +02:00
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
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
: een_rescaled_e[0, 2, 1] = 0.08084493981483197
: een_rescaled_e[0, 3, 1] = 0.1066745707571846
: een_rescaled_e[0, 4, 1] = 0.017542731694647366
: een_rescaled_e[1, 3, 2] = 0.02214680362033448
: een_rescaled_e[1, 4, 2] = 0.0005700154999202759
: een_rescaled_e[1, 5, 2] = 0.3424402276009091
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval c_test)
assert(qmckl_electron_provided(context));
2023-03-30 12:34:17 +02:00
double een_rescaled_e[walk_num][(cord_num + 1)][elec_num][elec_num];
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_een_rescaled_e(context, &(een_rescaled_e[0][0][0][0]),elec_num*elec_num*(cord_num+1)*walk_num);
2023-03-30 12:34:17 +02:00
// value of (0,2,1)
assert(fabs(een_rescaled_e[0][1][0][2]-0.08084493981483197) < 1.e-12);
assert(fabs(een_rescaled_e[0][1][0][3]-0.1066745707571846) < 1.e-12);
assert(fabs(een_rescaled_e[0][1][0][4]-0.01754273169464735) < 1.e-12);
assert(fabs(een_rescaled_e[0][2][1][3]-0.02214680362033448) < 1.e-12);
assert(fabs(een_rescaled_e[0][2][1][4]-0.0005700154999202759) < 1.e-12);
assert(fabs(een_rescaled_e[0][2][1][5]-0.3424402276009091) < 1.e-12);
#+end_src
2023-03-30 12:34:17 +02:00
*** Electron-electron rescaled distances derivatives in $J_\text{eeN}$
2023-03-31 14:41:32 +02:00
2023-03-30 12:34:17 +02:00
~een_rescaled_e_deriv_e~ stores the table of the derivatives of the
rescaled distances between all pairs of electrons and raised to the
power $p$ defined by ~cord_num~. Here we take its derivatives
2023-03-30 17:07:11 +02:00
required for the een jastrow_champ.
2023-03-30 12:34:17 +02:00
\[ \frac{\partial}{\partial x} \left[ {g_\text{e}(r)}\right]^p =
-\frac{x}{r} \kappa_\text{e}\, p\,\left[ {g_\text{e}(r)}\right]^p \]
\[ \Delta \left[ {g_\text{e}(r)}\right]^p = \frac{2}{r} \kappa_\text{e}\, p\,\left[ {g_\text{e}(r)}\right]^p \right] + \left(\frac{\partial}{\partial x}\left[ {g_\text{e}(r)}\right]^p \right)^2 + \left(\frac{\partial}{\partial y}\left[ {g_\text{e}(r)}\right]^p \right)^2 + \left(\frac{\partial}{\partial z}\left[ {g_\text{e}(r)}\right]^p \right)^2 \]
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
**** Get
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_een_rescaled_e_deriv_e(qmckl_context context,
2023-03-30 12:34:17 +02:00
double* const distance_rescaled,
const int64_t size_max);
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_een_rescaled_e_deriv_e(qmckl_context context,
2023-03-30 12:34:17 +02:00
double* const distance_rescaled,
const int64_t size_max)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
2023-03-30 12:34:17 +02:00
rc = qmckl_provide_een_rescaled_e_deriv_e(context);
if (rc != QMCKL_SUCCESS) return rc;
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
int64_t sze = ctx->electron.num * 4 * ctx->electron.num * ctx->electron.walker.num * (ctx->jastrow_champ.cord_num + 1);
2023-03-30 12:34:17 +02:00
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_factor_een_deriv_e",
"Array too small. Expected ctx->electron.num * 4 * ctx->electron.num * ctx->electron.walker.num * (ctx->jastrow_champ.cord_num + 1)");
2023-03-30 12:34:17 +02:00
}
2023-03-30 17:07:11 +02:00
memcpy(distance_rescaled, ctx->jastrow_champ.een_rescaled_e_deriv_e, sze * sizeof(double));
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
2023-03-30 12:34:17 +02:00
#+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
2023-03-30 12:34:17 +02:00
#+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;
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 12:34:17 +02:00
/* 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 */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.een_rescaled_e_deriv_e_date) {
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.een_rescaled_e_deriv_e != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.een_rescaled_e_deriv_e);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-30 12:34:17 +02:00
"qmckl_provide_een_rescaled_e_deriv_e",
2023-03-30 17:07:11 +02:00
"Unable to free ctx->jastrow_champ.een_rescaled_e_deriv_e");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_e_deriv_e = NULL;
}
2022-08-07 14:57:10 +02:00
}
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.een_rescaled_e_deriv_e == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 12:34:17 +02:00
mem_info.size = ctx->electron.num * 4 * ctx->electron.num *
2023-03-30 17:07:11 +02:00
ctx->electron.walker.num * (ctx->jastrow_champ.cord_num + 1) * sizeof(double);
2023-03-30 12:34:17 +02:00
double* een_rescaled_e_deriv_e = (double*) qmckl_malloc(context, mem_info);
2023-03-30 12:34:17 +02:00
if (een_rescaled_e_deriv_e == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 12:34:17 +02:00
"qmckl_provide_een_rescaled_e_deriv_e",
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_e_deriv_e = een_rescaled_e_deriv_e;
}
2023-03-31 13:37:35 +02:00
rc = qmckl_compute_jastrow_champ_factor_een_rescaled_e_deriv_e(context,
2023-03-30 12:34:17 +02:00
ctx->electron.walker.num,
ctx->electron.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.cord_num,
ctx->jastrow_champ.rescale_factor_ee,
2023-03-30 12:34:17 +02:00
ctx->electron.walker.point.coord.data,
ctx->electron.ee_distance,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_e,
ctx->jastrow_champ.een_rescaled_e_deriv_e);
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_e_deriv_e_date = ctx->date;
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
2023-03-31 13:37:35 +02:00
:Name: qmckl_compute_jastrow_champ_factor_een_rescaled_e_deriv_e
2023-03-30 12:34:17 +02:00
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_een_rescaled_e_deriv_e_args
| Variable | Type | In/Out | Description |
|--------------------------+-------------------------------------------------------+--------+--------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~cord_num~ | ~int64_t~ | in | Order of polynomials |
| ~rescale_factor_ee~ | ~double~ | in | Factor to rescale ee distances |
| ~coord_ee~ | ~double[walk_num][3][elec_num]~ | in | Electron coordinates |
| ~ee_distance~ | ~double[walk_num][elec_num][elec_num]~ | in | Electron-electron distances |
| ~een_rescaled_e~ | ~double[walk_num][0:cord_num][elec_num][elec_num]~ | in | Electron-electron distances |
| ~een_rescaled_e_deriv_e~ | ~double[walk_num][0:cord_num][elec_num][4][elec_num]~ | out | Electron-electron rescaled distances |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2023-03-31 13:37:35 +02:00
integer function qmckl_compute_jastrow_champ_factor_een_rescaled_e_deriv_e_f( &
2023-03-30 12:34:17 +02:00
context, walk_num, elec_num, cord_num, rescale_factor_ee, &
coord_ee, 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
2023-03-30 12:34:17 +02:00
integer*8 , intent(in) :: elec_num
integer*8 , intent(in) :: cord_num
double precision , intent(in) :: rescale_factor_ee
double precision , intent(in) :: coord_ee(elec_num,3,walk_num)
double precision , intent(in) :: ee_distance(elec_num,elec_num,walk_num)
double precision , intent(in) :: een_rescaled_e(elec_num,elec_num,0:cord_num,walk_num)
double precision , intent(out) :: een_rescaled_e_deriv_e(elec_num,4,elec_num,0:cord_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
2023-03-30 12:34:17 +02:00
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
2023-03-30 12:34:17 +02:00
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
2023-03-30 12:34:17 +02:00
if (elec_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
2023-03-30 12:34:17 +02:00
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_ee(i, ii, nw) - coord_ee(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_ee
do j = 1, elec_num
do i = 1, elec_num
een_rescaled_e_deriv_e(i, 1, j, l, nw) = kappa_l * elec_dist_deriv_e(1, i, j)
een_rescaled_e_deriv_e(i, 2, j, l, nw) = kappa_l * elec_dist_deriv_e(2, i, j)
een_rescaled_e_deriv_e(i, 3, j, l, nw) = kappa_l * elec_dist_deriv_e(3, i, j)
een_rescaled_e_deriv_e(i, 4, j, l, nw) = kappa_l * elec_dist_deriv_e(4, i, j)
een_rescaled_e_deriv_e(i, 4, j, l, nw) = een_rescaled_e_deriv_e(i, 4, j, l, nw) &
+ een_rescaled_e_deriv_e(i, 1, j, l, nw) * een_rescaled_e_deriv_e(i, 1, j, l, nw) &
+ een_rescaled_e_deriv_e(i, 2, j, l, nw) * een_rescaled_e_deriv_e(i, 2, j, l, nw) &
+ een_rescaled_e_deriv_e(i, 3, j, l, nw) * een_rescaled_e_deriv_e(i, 3, j, l, nw)
een_rescaled_e_deriv_e(i, 1, j, l, nw) = een_rescaled_e_deriv_e(i, 1, j, l, nw) * &
een_rescaled_e(i, j, l, nw)
een_rescaled_e_deriv_e(i, 3, j, l, nw) = een_rescaled_e_deriv_e(i, 2, j, l, nw) * &
een_rescaled_e(i, j, l, nw)
een_rescaled_e_deriv_e(i, 3, j, l, nw) = een_rescaled_e_deriv_e(i, 3, j, l, nw) * &
een_rescaled_e(i, j, l, nw)
een_rescaled_e_deriv_e(i, 4, j, l, nw) = een_rescaled_e_deriv_e(i, 4, j, l, nw) * &
een_rescaled_e(i, j, l, nw)
end do
end do
end do
end do
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_een_rescaled_e_deriv_e_f
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_een_rescaled_e_deriv_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_een_rescaled_e_deriv_e (
2023-03-30 12:34:17 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t cord_num,
const double rescale_factor_ee,
const double* coord_ee,
const double* ee_distance,
const double* een_rescaled_e,
double* const een_rescaled_e_deriv_e );
#+end_src
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_factor_een_rescaled_e_deriv_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
2023-03-31 13:37:35 +02:00
integer(c_int32_t) function qmckl_compute_jastrow_champ_factor_een_rescaled_e_deriv_e &
2022-04-06 16:26:35 +02:00
(context, &
walk_num, &
2023-03-30 12:34:17 +02:00
elec_num, &
cord_num, &
rescale_factor_ee, &
coord_ee, &
ee_distance, &
een_rescaled_e, &
een_rescaled_e_deriv_e) &
2022-04-06 16:26:35 +02:00
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
2023-03-30 12:34:17 +02:00
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_ee
real (c_double ) , intent(in) :: coord_ee(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(elec_num,elec_num,0:cord_num,walk_num)
real (c_double ) , intent(out) :: een_rescaled_e_deriv_e(elec_num,4,elec_num,0:cord_num,walk_num)
2023-03-31 13:37:35 +02:00
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_factor_een_rescaled_e_deriv_e_f
info = qmckl_compute_jastrow_champ_factor_een_rescaled_e_deriv_e_f &
2022-04-06 16:26:35 +02:00
(context, &
walk_num, &
2023-03-30 12:34:17 +02:00
elec_num, &
cord_num, &
rescale_factor_ee, &
coord_ee, &
ee_distance, &
een_rescaled_e, &
een_rescaled_e_deriv_e)
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_een_rescaled_e_deriv_e
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Test
#+name: een_e_deriv_e
#+begin_src python :results output :exports none :noweb yes
import numpy as np
2023-03-30 12:34:17 +02:00
<<jastrow_data>>
2023-03-30 12:34:17 +02:00
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])
2021-09-22 11:42:45 +02:00
2023-03-30 12:34:17 +02:00
elec_dist_deriv_e = np.zeros(shape=(4,elec_num, elec_num),dtype=float)
for j in range(elec_num):
for i in range(elec_num):
rij_inv = 1.0 / elec_dist[i, j]
for ii in range(3):
elec_dist_deriv_e[ii, i, j] = -(elec_coord[j][ii] - elec_coord[i][ii]) * rij_inv
elec_dist_deriv_e[3, i, j] = 2.0 * rij_inv
elec_dist_deriv_e[:, j, j] = 0.0
2021-09-22 11:42:45 +02:00
2023-03-30 12:34:17 +02:00
kappa = 1.0
2023-03-30 12:34:17 +02:00
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
2023-03-30 12:34:17 +02:00
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
2023-03-30 12:34:17 +02:00
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
een_rescaled_e_deriv_e = np.zeros(shape=(elec_num,4,elec_num,cord_num+1),dtype=float)
for l in range(0,cord_num+1):
kappa_l = -1.0 * kappa * l
for j in range(0,elec_num):
for i in range(0,elec_num):
for ii in range(0,4):
een_rescaled_e_deriv_e[i,ii,j,l] = kappa_l * elec_dist_deriv_e[ii,i,j]
een_rescaled_e_deriv_e[i,3,j,l] = een_rescaled_e_deriv_e[i,3,j,l] + \
een_rescaled_e_deriv_e[i,0,j,l] * een_rescaled_e_deriv_e[i,0,j,l] + \
een_rescaled_e_deriv_e[i,1,j,l] * een_rescaled_e_deriv_e[i,1,j,l] + \
een_rescaled_e_deriv_e[i,2,j,l] * een_rescaled_e_deriv_e[i,2,j,l]
for ii in range(0,4):
een_rescaled_e_deriv_e[i,ii,j,l] = een_rescaled_e_deriv_e[i,ii,j,l] * een_rescaled_e[i,j,l]
2021-09-22 11:42:45 +02:00
2023-03-30 12:34:17 +02:00
#print(" een_rescaled_e_deriv_e[1, 1, 3, 1] = ",een_rescaled_e_deriv_e[0, 0, 2, 1])
#print(" een_rescaled_e_deriv_e[1, 1, 4, 1] = ",een_rescaled_e_deriv_e[0, 0, 3, 1])
#print(" een_rescaled_e_deriv_e[1, 1, 5, 1] = ",een_rescaled_e_deriv_e[0, 0, 4, 1])
#print(" een_rescaled_e_deriv_e[2, 1, 4, 2] = ",een_rescaled_e_deriv_e[1, 0, 3, 2])
#print(" een_rescaled_e_deriv_e[2, 1, 5, 2] = ",een_rescaled_e_deriv_e[1, 0, 4, 2])
#print(" een_rescaled_e_deriv_e[2, 1, 6, 2] = ",een_rescaled_e_deriv_e[1, 0, 5, 2])
#+end_src
2023-03-30 12:34:17 +02:00
#+RESULTS: een_e_deriv_e
: een_rescaled_e_deriv_e[1, 1, 3, 1] = 0.05991352796887283
: een_rescaled_e_deriv_e[1, 1, 4, 1] = 0.011714035071545248
: een_rescaled_e_deriv_e[1, 1, 5, 1] = 0.00441398875758468
: een_rescaled_e_deriv_e[2, 1, 4, 2] = 0.013553180060167595
: een_rescaled_e_deriv_e[2, 1, 5, 2] = 0.00041342909359870457
: een_rescaled_e_deriv_e[2, 1, 6, 2] = 0.5880599146214673
#+begin_src c :tangle (eval c_test)
double een_rescaled_e_deriv_e[walk_num][(cord_num + 1)][elec_num][4][elec_num];
size_max=walk_num*(cord_num + 1)*elec_num*4*elec_num;
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_een_rescaled_e_deriv_e(context,
2023-03-30 12:34:17 +02:00
&(een_rescaled_e_deriv_e[0][0][0][0][0]),size_max);
// value of (0,0,0,2,1)
assert(fabs(een_rescaled_e_deriv_e[0][1][0][0][2] + 0.05991352796887283 ) < 1.e-12);
assert(fabs(een_rescaled_e_deriv_e[0][1][0][0][3] + 0.011714035071545248 ) < 1.e-12);
assert(fabs(een_rescaled_e_deriv_e[0][1][0][0][4] + 0.00441398875758468 ) < 1.e-12);
assert(fabs(een_rescaled_e_deriv_e[0][2][1][0][3] + 0.013553180060167595 ) < 1.e-12);
assert(fabs(een_rescaled_e_deriv_e[0][2][1][0][4] + 0.00041342909359870457) < 1.e-12);
assert(fabs(een_rescaled_e_deriv_e[0][2][1][0][5] + 0.5880599146214673 ) < 1.e-12);
#+end_src
*** Electron-nucleus rescaled distances in $J_\text{eeN}$
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
~een_rescaled_n~ stores the table of the rescaled distances between
electrons and nuclei raised to the power \(p\) defined by ~cord_num~:
2021-07-07 09:10:23 +02:00
2023-03-30 12:34:17 +02:00
\[
C_{i\alpha,p} = \left[ \exp\left(-\kappa_\alpha\, R_{i\alpha}\right) \right]^p
\]
2021-07-07 09:10:23 +02:00
2023-03-30 12:34:17 +02:00
where \(R_{i\alpha}\) is the matrix of electron-nucleus distances.
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
**** Get
2021-07-07 09:10:23 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_een_rescaled_n(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const distance_rescaled,
const int64_t size_max);
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 09:10:23 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_een_rescaled_n(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const distance_rescaled,
const int64_t size_max)
2021-07-07 09:10:23 +02:00
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
rc = qmckl_provide_een_rescaled_n(context);
if (rc != QMCKL_SUCCESS) return rc;
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-07-07 09:10:23 +02:00
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
int64_t sze = ctx->electron.num * ctx->nucleus.num * ctx->electron.walker.num * (ctx->jastrow_champ.cord_num + 1);
2022-02-14 19:11:37 +01:00
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_factor_een_deriv_e",
"Array too small. Expected ctx->electron.num * ctx->nucleus.num * ctx->electron.walker.num * (ctx->jastrow_champ.cord_num + 1)");
2022-02-14 19:11:37 +01:00
}
2023-03-30 17:07:11 +02:00
memcpy(distance_rescaled, ctx->jastrow_champ.een_rescaled_n, sze * sizeof(double));
2021-07-07 09:10:23 +02:00
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
2021-07-07 09:10:23 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2021-07-07 09:10:23 +02:00
qmckl_exit_code qmckl_provide_een_rescaled_n(qmckl_context context);
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 09:10:23 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2021-07-07 09:10:23 +02:00
qmckl_exit_code qmckl_provide_een_rescaled_n(qmckl_context context)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-07-07 09:10:23 +02:00
assert (ctx != NULL);
/* Check if ee distance is provided */
qmckl_exit_code rc = qmckl_provide_en_distance(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.een_rescaled_n_date) {
2021-07-07 09:10:23 +02:00
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.een_rescaled_n != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.een_rescaled_n);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
"qmckl_provide_een_rescaled_n",
2023-03-30 17:07:11 +02:00
"Unable to free ctx->jastrow_champ.een_rescaled_n");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_n = NULL;
}
2022-08-07 14:57:10 +02:00
}
2021-07-07 09:10:23 +02:00
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.een_rescaled_n == NULL) {
2021-07-07 09:10:23 +02:00
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = ctx->electron.num * ctx->nucleus.num *
2023-03-30 17:07:11 +02:00
ctx->electron.walker.num * (ctx->jastrow_champ.cord_num + 1) * sizeof(double);
2021-07-07 09:10:23 +02:00
double* een_rescaled_n = (double*) qmckl_malloc(context, mem_info);
if (een_rescaled_n == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_provide_een_rescaled_n",
2021-07-07 09:10:23 +02:00
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_n = een_rescaled_n;
2021-07-07 09:10:23 +02:00
}
2022-04-05 11:44:17 +02:00
rc = qmckl_compute_een_rescaled_n(context,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
2022-04-05 11:44:17 +02:00
ctx->electron.num,
ctx->nucleus.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.type_nucl_num,
ctx->jastrow_champ.type_nucl_vector,
ctx->jastrow_champ.cord_num,
ctx->jastrow_champ.rescale_factor_en,
2022-04-05 11:44:17 +02:00
ctx->electron.en_distance,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_n);
2021-07-07 09:10:23 +02:00
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_n_date = ctx->date;
2021-07-07 09:10:23 +02:00
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 09:10:23 +02:00
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
:Name: qmckl_compute_een_rescaled_n
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_een_rescaled_n_args
| Variable | Type | In/Out | Description |
|---------------------+----------------------------------------------------+--------+-------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~nucl_num~ | ~int64_t~ | in | Number of atoms |
| ~type_nucl_num~ | ~int64_t~ | in | Number of atom types |
| ~type_nucl_vector~ | ~int64_t[nucl_num]~ | in | Types of atoms |
| ~cord_num~ | ~int64_t~ | in | Order of polynomials |
| ~rescale_factor_en~ | ~double[nucl_num]~ | in | Factor to rescale ee distances |
| ~en_distance~ | ~double[walk_num][elec_num][nucl_num]~ | in | Electron-nucleus distances |
| ~een_rescaled_n~ | ~double[walk_num][0:cord_num][nucl_num][elec_num]~ | out | Electron-nucleus rescaled distances |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2022-04-04 23:53:58 +02:00
integer function qmckl_compute_een_rescaled_n_f( &
2022-11-17 19:20:12 +01:00
context, walk_num, elec_num, nucl_num, &
type_nucl_num, type_nucl_vector, cord_num, rescale_factor_en, &
2021-07-07 09:10:23 +02:00
en_distance, een_rescaled_n) &
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
2022-11-17 19:20:12 +01:00
integer*8 , intent(in) :: type_nucl_num
2022-11-18 13:30:54 +01:00
integer*8 , intent(in) :: type_nucl_vector(nucl_num)
2021-07-07 09:10:23 +02:00
integer*8 , intent(in) :: cord_num
2022-11-17 19:20:12 +01:00
double precision , intent(in) :: rescale_factor_en(type_nucl_num)
2023-03-13 15:32:35 +01:00
double precision , intent(in) :: en_distance(nucl_num,elec_num,walk_num)
2022-02-11 17:19:36 +01:00
double precision , intent(out) :: een_rescaled_n(elec_num,nucl_num,0:cord_num,walk_num)
2021-07-07 09:10:23 +02:00
double precision :: x
integer*8 :: i, a, k, l, nw
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
2022-11-16 17:54:59 +01:00
if (cord_num < 0) then
2021-07-07 09:10:23 +02:00
info = QMCKL_INVALID_ARG_5
return
endif
! Prepare table of exponentiated distances raised to appropriate power
een_rescaled_n = 0.0d0
do nw = 1, walk_num
2023-03-13 15:32:35 +01:00
2022-11-17 19:20:12 +01:00
! prepare the actual een table
een_rescaled_n(:, :, 0, nw) = 1.0d0
2023-03-13 15:32:35 +01:00
2022-11-17 19:20:12 +01:00
do a = 1, nucl_num
do i = 1, elec_num
2023-03-13 15:32:35 +01:00
een_rescaled_n(i, a, 1, nw) = dexp(-rescale_factor_en(type_nucl_vector(a)) * en_distance(a, i, nw))
2022-11-17 19:20:12 +01:00
end do
end do
2023-03-13 15:32:35 +01:00
2022-11-17 19:20:12 +01:00
do l = 2, cord_num
do a = 1, nucl_num
do i = 1, elec_num
een_rescaled_n(i, a, l, nw) = een_rescaled_n(i, a, l - 1, nw) * een_rescaled_n(i, a, 1, nw)
end do
end do
end do
2021-07-07 09:10:23 +02:00
end do
end function qmckl_compute_een_rescaled_n_f
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 09:10:23 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2022-11-17 19:20:12 +01:00
/*
qmckl_exit_code qmckl_compute_een_rescaled_n (
2022-04-06 10:42:00 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t nucl_num,
2022-11-17 19:20:12 +01:00
const int64_t type_nucl_num,
int64_t* const type_nucl_vector,
2022-04-06 10:42:00 +02:00
const int64_t cord_num,
const double* rescale_factor_en,
2022-04-06 10:42:00 +02:00
const double* en_distance,
double* const een_rescaled_n ) {
2021-07-07 09:10:23 +02:00
if (context == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
2022-04-08 10:44:48 +02:00
}
2021-07-07 09:10:23 +02:00
if (walk_num <= 0) {
return QMCKL_INVALID_ARG_2;
}
2021-07-07 09:10:23 +02:00
if (elec_num <= 0) {
return QMCKL_INVALID_ARG_3;
}
2021-07-07 09:10:23 +02:00
if (nucl_num <= 0) {
return QMCKL_INVALID_ARG_4;
}
2022-11-16 17:54:59 +01:00
if (cord_num < 0) {
return QMCKL_INVALID_ARG_5;
}
// Prepare table of exponentiated distances raised to appropriate power
for (int i = 0; i < (walk_num*(cord_num+1)*nucl_num*elec_num); ++i) {
2022-11-17 19:20:12 +01:00
een_rescaled_n[i] = 1.0;
}
for (int nw = 0; nw < walk_num; ++nw) {
for (int a = 0; a < nucl_num; ++a) {
for (int i = 0; i < elec_num; ++i) {
2022-11-17 19:20:12 +01:00
een_rescaled_n[i + a*elec_num + nw * elec_num*nucl_num*(cord_num+1)] = 1.0;
een_rescaled_n[i + a*elec_num + elec_num*nucl_num + nw*elec_num*nucl_num*(cord_num+1)] =
2023-03-13 15:32:35 +01:00
exp(-rescale_factor_en[type_nucl_vector[a]] * en_distance[a + i*nucl_num + nw*elec_num*nucl_num]);
}
}
for (int l = 2; l < (cord_num+1); ++l){
for (int a = 0; a < nucl_num; ++a) {
for (int i = 0; i < elec_num; ++i) {
2022-11-17 19:20:12 +01:00
een_rescaled_n[i + a*elec_num + l*elec_num*nucl_num + nw*elec_num*nucl_num*(cord_num+1)] =
2023-03-13 15:32:35 +01:00
een_rescaled_n[i + a*elec_num + (l-1)*elec_num*nucl_num + nw*elec_num*nucl_num*(cord_num+1)] *
2022-11-17 19:20:12 +01:00
een_rescaled_n[i + a*elec_num + elec_num*nucl_num + nw*elec_num*nucl_num*(cord_num+1)];
}
}
}
}
return QMCKL_SUCCESS;
}
2022-11-17 19:20:12 +01:00
*/
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_factor_een_rescaled_n_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2022-11-17 19:20:12 +01:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
2022-11-17 19:20:12 +01:00
integer(c_int32_t) function qmckl_compute_een_rescaled_n &
(context, &
walk_num, &
elec_num, &
nucl_num, &
type_nucl_num, &
type_nucl_vector, &
cord_num, &
rescale_factor_en, &
en_distance, &
een_rescaled_n) &
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 :: type_nucl_num
2022-11-18 13:30:54 +01:00
integer (c_int64_t) , intent(in) :: type_nucl_vector(nucl_num)
2022-11-17 19:20:12 +01:00
integer (c_int64_t) , intent(in) , value :: cord_num
real (c_double ) , intent(in) :: rescale_factor_en(nucl_num)
real (c_double ) , intent(in) :: en_distance(nucl_num,elec_num,walk_num)
real (c_double ) , intent(out) :: een_rescaled_n(elec_num,nucl_num,0:cord_num,walk_num)
integer(c_int32_t), external :: qmckl_compute_een_rescaled_n_f
info = qmckl_compute_een_rescaled_n_f &
(context, &
walk_num, &
elec_num, &
nucl_num, &
type_nucl_num, &
type_nucl_vector, &
cord_num, &
rescale_factor_en, &
en_distance, &
een_rescaled_n)
end function qmckl_compute_een_rescaled_n
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-13 15:32:35 +01:00
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_een_rescaled_n_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2021-07-07 09:10:23 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_compute_een_rescaled_n (
2022-04-06 16:26:35 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t nucl_num,
2022-11-17 19:20:12 +01:00
const int64_t type_nucl_num,
int64_t* const type_nucl_vector,
2022-04-06 16:26:35 +02:00
const int64_t cord_num,
const double* rescale_factor_en,
2022-04-06 16:26:35 +02:00
const double* en_distance,
2022-04-08 10:44:48 +02:00
double* const een_rescaled_n );
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 09:10:23 +02:00
2023-03-30 12:34:17 +02:00
**** Test
2021-07-07 09:10:23 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src python :results output :exports none :noweb yes
2021-07-07 09:10:23 +02:00
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])
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 09:10:23 +02:00
2023-03-30 12:34:17 +02:00
#+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));
2022-02-11 17:19:36 +01:00
double een_rescaled_n[walk_num][(cord_num + 1)][nucl_num][elec_num];
2022-02-14 19:11:37 +01:00
size_max=walk_num*(cord_num + 1)*nucl_num*elec_num;
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_een_rescaled_n(context, &(een_rescaled_n[0][0][0][0]),size_max);
// value of (0,2,1)
2022-02-11 17:19:36 +01:00
assert(fabs(een_rescaled_n[0][1][0][2]-0.10612983920006765) < 1.e-12);
assert(fabs(een_rescaled_n[0][1][0][3]-0.135652809635553) < 1.e-12);
assert(fabs(een_rescaled_n[0][1][0][4]-0.023391817607642338) < 1.e-12);
assert(fabs(een_rescaled_n[0][2][1][3]-0.880957224822116) < 1.e-12);
assert(fabs(een_rescaled_n[0][2][1][4]-0.027185942659395074) < 1.e-12);
assert(fabs(een_rescaled_n[0][2][1][5]-0.01343938025140174) < 1.e-12);
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 07:53:04 +02:00
2023-03-30 12:34:17 +02:00
*** Electron-nucleus rescaled distances derivatives in $J_\text{eeN}$
2023-03-30 12:34:17 +02:00
~een_rescaled_n_deriv_e~ stores the table of the derivatives of the
rescaled distances between all electron-nucleus pairs and raised to the
power $p$ defined by ~cord_num~. Here we take its derivatives
2023-03-30 17:07:11 +02:00
required for the een jastrow_champ.
2023-03-30 12:34:17 +02:00
\[ \frac{\partial}{\partial x} \left[ {g_\alpha(R_{i\alpha})}\right]^p =
-\frac{x}{R_{i\alpha}} \kappa_\alpha\, p\,\left[ {g_\alpha(R_{i\alpha})}\right]^p \]
\[ \Delta \left[ {g_\alpha(R_{i\alpha})}\right]^p = \frac{2}{R_{i\alpha}}
\kappa_\alpha\, p\,\left[ {g_\alpha(R_{i\alpha})}\right]^p \right] +
\left(\frac{\partial}{\partial x}\left[ {g_\alpha(R_{i\alpha})}\right]^p
\right)^2 + \left(\frac{\partial}{\partial y}\left[
{g_\alpha(R_{i\alpha})}\right]^p \right)^2 + \left(\frac{\partial}{\partial
z}\left[ {g_\alpha(R_{i\alpha})}\right]^p \right)^2 \]
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
**** Get
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_een_rescaled_n_deriv_e(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const distance_rescaled,
const int64_t size_max);
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_een_rescaled_n_deriv_e(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const distance_rescaled,
const int64_t size_max)
{
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;
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
int64_t sze = ctx->electron.num * 4 * ctx->nucleus.num * ctx->electron.walker.num * (ctx->jastrow_champ.cord_num + 1);
2022-02-14 19:11:37 +01:00
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_factor_een_deriv_e",
"Array too small. Expected ctx->electron.num * 4 * ctx->nucleus.num * ctx->electron.walker.num * (ctx->jastrow_champ.cord_num + 1)");
2022-02-14 19:11:37 +01:00
}
2023-03-30 17:07:11 +02:00
memcpy(distance_rescaled, ctx->jastrow_champ.een_rescaled_n_deriv_e, sze * sizeof(double));
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
2023-03-30 12:34:17 +02:00
#+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);
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+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;
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) 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 */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.een_rescaled_n_deriv_e_date) {
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.een_rescaled_n_deriv_e != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.een_rescaled_n_deriv_e);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
"qmckl_provide_een_rescaled_n_deriv_e",
2023-03-30 17:07:11 +02:00
"Unable to free ctx->jastrow_champ.een_rescaled_n_deriv_e");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_n_deriv_e = NULL;
}
2022-08-07 14:57:10 +02:00
}
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.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 *
2023-03-30 17:07:11 +02:00
ctx->electron.walker.num * (ctx->jastrow_champ.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_provide_een_rescaled_n_deriv_e",
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_n_deriv_e = een_rescaled_n_deriv_e;
}
2023-03-31 13:37:35 +02:00
rc = qmckl_compute_jastrow_champ_factor_een_rescaled_n_deriv_e(context,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
2022-04-05 11:44:17 +02:00
ctx->electron.num,
ctx->nucleus.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.type_nucl_num,
ctx->jastrow_champ.type_nucl_vector,
ctx->jastrow_champ.cord_num,
ctx->jastrow_champ.rescale_factor_en,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.point.coord.data,
2022-04-05 11:44:17 +02:00
ctx->nucleus.coord.data,
ctx->electron.en_distance,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_n,
ctx->jastrow_champ.een_rescaled_n_deriv_e);
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_n_deriv_e_date = ctx->date;
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
2023-03-31 13:37:35 +02:00
:Name: qmckl_compute_jastrow_champ_factor_een_rescaled_n_deriv_e
2023-03-30 12:34:17 +02:00
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
2023-03-31 13:37:35 +02:00
#+NAME: qmckl_compute_jastrow_champ_factor_een_rescaled_n_deriv_e_args
2023-03-30 12:34:17 +02:00
| Variable | Type | In/Out | Description |
|--------------------------+-------------------------------------------------------+--------+-------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~nucl_num~ | ~int64_t~ | in | Number of atoms |
| ~type_nucl_num~ | ~int64_t~ | in | Number of atom types |
| ~type_nucl_vector~ | ~int64_t[nucl_num]~ | in | Types of atoms |
| ~cord_num~ | ~int64_t~ | in | Order of polynomials |
| ~rescale_factor_en~ | ~double[nucl_num]~ | in | Factor to rescale ee distances |
| ~coord_ee~ | ~double[walk_num][3][elec_num]~ | in | Electron coordinates |
| ~coord_en~ | ~double[3][nucl_num]~ | in | Nuclear coordinates |
| ~en_distance~ | ~double[walk_num][elec_num][nucl_num]~ | in | Electron-nucleus distances |
| ~een_rescaled_n~ | ~double[walk_num][0:cord_num][nucl_num][elec_num]~ | in | Electron-nucleus distances |
| ~een_rescaled_n_deriv_e~ | ~double[walk_num][0:cord_num][nucl_num][4][elec_num]~ | out | Electron-nucleus rescaled distances |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2023-03-31 13:37:35 +02:00
integer function qmckl_compute_jastrow_champ_factor_een_rescaled_n_deriv_e_f( &
2022-11-17 19:20:12 +01:00
context, walk_num, elec_num, nucl_num, type_nucl_num, type_nucl_vector, &
cord_num, rescale_factor_en, &
2022-08-07 14:57:10 +02:00
coord_ee, coord_en, 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
2022-11-17 19:20:12 +01:00
integer*8 , intent(in) :: type_nucl_num
2022-11-18 13:30:54 +01:00
integer*8 , intent(in) :: type_nucl_vector(nucl_num)
integer*8 , intent(in) :: cord_num
2022-11-17 19:20:12 +01:00
double precision , intent(in) :: rescale_factor_en(type_nucl_num)
2022-08-07 14:57:10 +02:00
double precision , intent(in) :: coord_ee(elec_num,3,walk_num)
double precision , intent(in) :: coord_en(nucl_num,3)
2023-03-13 15:32:35 +01:00
double precision , intent(in) :: en_distance(nucl_num,elec_num,walk_num)
2022-02-11 17:19:36 +01:00
double precision , intent(in) :: een_rescaled_n(elec_num,nucl_num,0:cord_num,walk_num)
2022-02-11 17:30:15 +01:00
double precision , intent(out) :: een_rescaled_n_deriv_e(elec_num,4,nucl_num,0:cord_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
2022-11-16 17:54:59 +01:00
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
2023-03-13 15:32:35 +01:00
ria_inv = 1.0d0 / en_distance(a, i, nw)
do ii = 1, 3
2022-08-07 14:57:10 +02:00
elnuc_dist_deriv_e(ii, i, a) = (coord_ee(i, ii, nw) - coord_en(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
do a = 1, nucl_num
2022-11-17 19:20:12 +01:00
kappa_l = - dble(l) * rescale_factor_en(type_nucl_vector(a))
do i = 1, elec_num
2022-02-11 17:30:15 +01:00
een_rescaled_n_deriv_e(i, 1, a, l, nw) = kappa_l * elnuc_dist_deriv_e(1, i, a)
een_rescaled_n_deriv_e(i, 2, a, l, nw) = kappa_l * elnuc_dist_deriv_e(2, i, a)
een_rescaled_n_deriv_e(i, 3, a, l, nw) = kappa_l * elnuc_dist_deriv_e(3, i, a)
een_rescaled_n_deriv_e(i, 4, a, l, nw) = kappa_l * elnuc_dist_deriv_e(4, i, a)
een_rescaled_n_deriv_e(i, 4, a, l, nw) = een_rescaled_n_deriv_e(i, 4, a, l, nw) &
+ een_rescaled_n_deriv_e(i, 1, a, l, nw) * een_rescaled_n_deriv_e(i, 1, a, l, nw) &
+ een_rescaled_n_deriv_e(i, 2, a, l, nw) * een_rescaled_n_deriv_e(i, 2, a, l, nw) &
+ een_rescaled_n_deriv_e(i, 3, a, l, nw) * een_rescaled_n_deriv_e(i, 3, a, l, nw)
een_rescaled_n_deriv_e(i, 1, a, l, nw) = een_rescaled_n_deriv_e(i, 1, a, l, nw) * &
een_rescaled_n(i, a, l, nw)
een_rescaled_n_deriv_e(i, 2, a, l, nw) = een_rescaled_n_deriv_e(i, 2, a, l, nw) * &
een_rescaled_n(i, a, l, nw)
een_rescaled_n_deriv_e(i, 3, a, l, nw) = een_rescaled_n_deriv_e(i, 3, a, l, nw) * &
een_rescaled_n(i, a, l, nw)
een_rescaled_n_deriv_e(i, 4, a, l, nw) = een_rescaled_n_deriv_e(i, 4, a, l, nw) * &
een_rescaled_n(i, a, l, nw)
end do
end do
end do
end do
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_een_rescaled_n_deriv_e_f
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-31 13:37:35 +02:00
# #+CALL: generate_c_header(table=qmckl_compute_jastrow_champ_factor_een_rescaled_n_deriv_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_een_rescaled_n_deriv_e (
2022-04-06 16:26:35 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t nucl_num,
2022-11-17 19:20:12 +01:00
const int64_t type_nucl_num,
int64_t* const type_nucl_vector,
2022-04-06 16:26:35 +02:00
const int64_t cord_num,
const double* rescale_factor_en,
2022-08-07 14:57:10 +02:00
const double* coord_ee,
const double* coord_en,
2022-04-06 16:26:35 +02:00
const double* en_distance,
const double* een_rescaled_n,
2022-04-08 10:44:48 +02:00
double* const een_rescaled_n_deriv_e );
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-31 13:37:35 +02:00
#+CALL: generate_c_interface(table=qmckl_compute_jastrow_champ_factor_een_rescaled_n_deriv_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
2023-03-31 13:37:35 +02:00
integer(c_int32_t) function qmckl_compute_jastrow_champ_factor_een_rescaled_n_deriv_e &
2022-04-06 16:26:35 +02:00
(context, &
2022-04-06 10:42:00 +02:00
walk_num, &
elec_num, &
nucl_num, &
2022-11-17 19:20:12 +01:00
type_nucl_num, &
type_nucl_vector, &
2022-04-06 10:42:00 +02:00
cord_num, &
rescale_factor_en, &
2022-08-07 14:57:10 +02:00
coord_ee, &
coord_en, &
2022-04-06 10:42:00 +02:00
en_distance, &
een_rescaled_n, &
een_rescaled_n_deriv_e) &
2022-04-06 16:26:35 +02:00
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
2022-11-17 19:20:12 +01:00
integer (c_int64_t) , intent(in) , value :: type_nucl_num
2022-11-18 13:30:54 +01:00
integer (c_int64_t) , intent(in) :: type_nucl_vector(nucl_num)
integer (c_int64_t) , intent(in) , value :: cord_num
real (c_double ) , intent(in) :: rescale_factor_en(nucl_num)
2022-08-07 14:57:10 +02:00
real (c_double ) , intent(in) :: coord_ee(elec_num,3,walk_num)
real (c_double ) , intent(in) :: coord_en(nucl_num,3)
real (c_double ) , intent(in) :: en_distance(nucl_num,elec_num,walk_num)
2022-04-06 16:26:35 +02:00
real (c_double ) , intent(in) :: een_rescaled_n(elec_num,nucl_num,0:cord_num,walk_num)
2022-02-11 17:30:15 +01:00
real (c_double ) , intent(out) :: een_rescaled_n_deriv_e(elec_num,4,nucl_num,0:cord_num,walk_num)
2023-03-31 13:37:35 +02:00
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_factor_een_rescaled_n_deriv_e_f
info = qmckl_compute_jastrow_champ_factor_een_rescaled_n_deriv_e_f &
2022-04-06 16:26:35 +02:00
(context, &
2022-04-06 10:42:00 +02:00
walk_num, &
elec_num, &
nucl_num, &
2022-11-17 19:20:12 +01:00
type_nucl_num, &
type_nucl_vector, &
2022-04-06 10:42:00 +02:00
cord_num, &
rescale_factor_en, &
2022-08-07 14:57:10 +02:00
coord_ee, &
coord_en, &
2022-04-06 10:42:00 +02:00
en_distance, &
een_rescaled_n, &
een_rescaled_n_deriv_e)
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_een_rescaled_n_deriv_e
2023-03-30 12:34:17 +02:00
#+end_src
2022-02-14 19:11:37 +01:00
2023-03-30 12:34:17 +02:00
**** Test
2022-02-14 19:11:37 +01:00
2023-03-30 12:34:17 +02:00
#+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])
2021-09-22 12:20:39 +02:00
elnuc_dist_deriv_e = np.zeros(shape=(4, elec_num, nucl_num),dtype=float)
for a in range(nucl_num):
for i in range(elec_num):
rij_inv = 1.0 / elnuc_dist[i, a]
for ii in range(3):
elnuc_dist_deriv_e[ii, i, a] = (elec_coord[i][ii] - nucl_coord[ii][a]) * rij_inv
elnuc_dist_deriv_e[3, i, a] = 2.0 * rij_inv
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]
2021-09-22 12:20:39 +02:00
een_rescaled_n_deriv_e = np.zeros(shape=(elec_num,4,nucl_num,cord_num+1),dtype=float)
for l in range(0,cord_num+1):
kappa_l = -1.0 * kappa * l
for j in range(0,elec_num):
for a in range(0,nucl_num):
for ii in range(0,4):
2022-01-31 16:47:28 +01:00
een_rescaled_n_deriv_e[j,ii,a,l] = kappa_l * elnuc_dist_deriv_e[ii,j,a]
2021-09-22 12:20:39 +02:00
een_rescaled_n_deriv_e[j,3,a,l] = een_rescaled_n_deriv_e[j,3,a,l] + \
een_rescaled_n_deriv_e[j,0,a,l] * een_rescaled_n_deriv_e[j,0,a,l] + \
een_rescaled_n_deriv_e[j,1,a,l] * een_rescaled_n_deriv_e[j,1,a,l] + \
2022-01-31 16:47:28 +01:00
een_rescaled_n_deriv_e[j,2,a,l] * een_rescaled_n_deriv_e[j,2,a,l]
2021-09-22 12:20:39 +02:00
for ii in range(0,4):
een_rescaled_n_deriv_e[j,ii,a,l] = een_rescaled_n_deriv_e[j,ii,a,l] * een_rescaled_n[a,j,l]
print(" een_rescaled_n_deriv_e[1, 1, 3, 1] = ",een_rescaled_n_deriv_e[2, 0, 0, 1])
print(" een_rescaled_n_deriv_e[1, 1, 4, 1] = ",een_rescaled_n_deriv_e[3, 0, 0, 1])
print(" een_rescaled_n_deriv_e[1, 1, 5, 1] = ",een_rescaled_n_deriv_e[4, 0, 0, 1])
print(" een_rescaled_n_deriv_e[2, 1, 4, 2] = ",een_rescaled_n_deriv_e[3, 0, 1, 2])
print(" een_rescaled_n_deriv_e[2, 1, 5, 2] = ",een_rescaled_n_deriv_e[4, 0, 1, 2])
print(" een_rescaled_n_deriv_e[2, 1, 6, 2] = ",een_rescaled_n_deriv_e[5, 0, 1, 2])
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+RESULTS:
: een_rescaled_n_deriv_e[1, 1, 3, 1] = -0.07633444246999128
: een_rescaled_n_deriv_e[1, 1, 4, 1] = 0.00033282346259738276
: een_rescaled_n_deriv_e[1, 1, 5, 1] = -0.004775370547333061
: een_rescaled_n_deriv_e[2, 1, 4, 2] = 0.1362654644223866
: een_rescaled_n_deriv_e[2, 1, 5, 2] = -0.0231253431662794
: een_rescaled_n_deriv_e[2, 1, 6, 2] = 0.001593334817691633
#+begin_src c :tangle (eval c_test)
2021-09-21 12:05:03 +02:00
assert(qmckl_electron_provided(context));
2022-02-11 17:30:15 +01:00
double een_rescaled_n_deriv_e[walk_num][(cord_num + 1)][nucl_num][4][elec_num];
2022-02-14 19:11:37 +01:00
size_max=walk_num*(cord_num + 1)*nucl_num*4*elec_num;
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_een_rescaled_n_deriv_e(context, &(een_rescaled_n_deriv_e[0][0][0][0][0]),size_max);
2021-09-21 12:05:03 +02:00
// value of (0,2,1)
2022-02-11 17:30:15 +01:00
assert(fabs(een_rescaled_n_deriv_e[0][1][0][0][2]+0.07633444246999128 ) < 1.e-12);
assert(fabs(een_rescaled_n_deriv_e[0][1][0][0][3]-0.00033282346259738276) < 1.e-12);
assert(fabs(een_rescaled_n_deriv_e[0][1][0][0][4]+0.004775370547333061 ) < 1.e-12);
assert(fabs(een_rescaled_n_deriv_e[0][2][1][0][3]-0.1362654644223866 ) < 1.e-12);
assert(fabs(een_rescaled_n_deriv_e[0][2][1][0][4]+0.0231253431662794 ) < 1.e-12);
assert(fabs(een_rescaled_n_deriv_e[0][2][1][0][5]-0.001593334817691633 ) < 1.e-12);
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
*** Temporary arrays for electron-electron-nucleus Jastrow $f_{een}$
2023-03-31 14:41:32 +02:00
2023-03-30 12:34:17 +02:00
Prepare ~c_vector_full~ and ~lkpm_combined_index~ tables required for the
calculation of the three-body jastrow ~factor_een~ and its derivative
~factor_een_deriv_e~.
2023-03-30 12:34:17 +02:00
**** Get
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_get_jastrow_champ_tmp_c(qmckl_context context, double* const tmp_c);
qmckl_exit_code qmckl_get_jastrow_champ_dtmp_c(qmckl_context context, double* const dtmp_c);
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_get_jastrow_champ_tmp_c(qmckl_context context, double* const tmp_c)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_c_vector_full(context);
if (rc != QMCKL_SUCCESS) return rc;
rc = qmckl_provide_tmp_c(context);
if (rc != QMCKL_SUCCESS) return rc;
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
size_t sze = (ctx->jastrow_champ.cord_num) * (ctx->jastrow_champ.cord_num + 1)
2023-03-31 19:20:25 +02:00
,* ctx->electron.num * ctx->nucleus.num * ctx->electron.walker.num;
2023-03-30 17:07:11 +02:00
memcpy(tmp_c, ctx->jastrow_champ.tmp_c, sze * sizeof(double));
return QMCKL_SUCCESS;
}
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_get_jastrow_champ_dtmp_c(qmckl_context context, double* const dtmp_c)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_c_vector_full(context);
if (rc != QMCKL_SUCCESS) return rc;
rc = qmckl_provide_dtmp_c(context);
if (rc != QMCKL_SUCCESS) return rc;
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 17:07:11 +02:00
size_t sze = (ctx->jastrow_champ.cord_num) * (ctx->jastrow_champ.cord_num + 1)
2023-03-31 19:20:25 +02:00
,*4* ctx->electron.num * ctx->nucleus.num * ctx->electron.walker.num;
2023-03-30 17:07:11 +02:00
memcpy(dtmp_c, ctx->jastrow_champ.dtmp_c, sze * sizeof(double));
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_c_vector_full(qmckl_context context);
qmckl_exit_code qmckl_provide_lkpm_combined_index(qmckl_context context);
qmckl_exit_code qmckl_provide_tmp_c(qmckl_context context);
qmckl_exit_code qmckl_provide_dtmp_c(qmckl_context context);
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-30 17:07:11 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_c_vector_full(qmckl_context context)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-31 19:20:25 +02:00
qmckl_exit_code rc = QMCKL_SUCCESS;
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.c_vector_full_date) {
2023-03-31 19:20:25 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
if (ctx->jastrow_champ.c_vector_full != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.c_vector_full);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
"qmckl_provide_jastrow_champ_c_vector_full",
"Unable to free ctx->jastrow_champ.c_vector_full");
}
ctx->jastrow_champ.c_vector_full = NULL;
}
}
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.c_vector_full == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 17:07:11 +02:00
mem_info.size = ctx->jastrow_champ.dim_c_vector * ctx->nucleus.num * sizeof(double);
2022-11-16 11:58:44 +01:00
double* c_vector_full = (double*) qmckl_malloc(context, mem_info);
2022-11-16 11:58:44 +01:00
if (c_vector_full == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-30 17:07:11 +02:00
"qmckl_provide_jastrow_champ_c_vector_full",
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.c_vector_full = c_vector_full;
}
2022-11-16 11:58:44 +01:00
rc = qmckl_compute_c_vector_full(context,
2022-04-05 11:44:17 +02:00
ctx->nucleus.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.dim_c_vector,
ctx->jastrow_champ.type_nucl_num,
ctx->jastrow_champ.type_nucl_vector,
ctx->jastrow_champ.c_vector,
ctx->jastrow_champ.c_vector_full);
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.c_vector_full_date = ctx->date;
}
return QMCKL_SUCCESS;
}
qmckl_exit_code qmckl_provide_lkpm_combined_index(qmckl_context context)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-31 19:20:25 +02:00
qmckl_exit_code rc = QMCKL_SUCCESS;
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.lkpm_combined_index_date) {
2023-03-31 19:20:25 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
if (ctx->jastrow_champ.lkpm_combined_index != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.lkpm_combined_index);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
"qmckl_provide_jastrow_champ_factor_ee",
"Unable to free ctx->jastrow_champ.lkpm_combined_index");
}
ctx->jastrow_champ.lkpm_combined_index = NULL;
}
}
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.lkpm_combined_index == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 17:07:11 +02:00
mem_info.size = 4 * ctx->jastrow_champ.dim_c_vector * sizeof(int64_t);
int64_t* lkpm_combined_index = (int64_t*) qmckl_malloc(context, mem_info);
if (lkpm_combined_index == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_provide_lkpm_combined_index",
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.lkpm_combined_index = lkpm_combined_index;
}
2022-04-05 11:44:17 +02:00
rc = qmckl_compute_lkpm_combined_index(context,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.cord_num,
ctx->jastrow_champ.dim_c_vector,
ctx->jastrow_champ.lkpm_combined_index);
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.lkpm_combined_index_date = ctx->date;
}
return QMCKL_SUCCESS;
}
qmckl_exit_code qmckl_provide_tmp_c(qmckl_context context)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-01-26 18:45:09 +01:00
qmckl_exit_code rc = QMCKL_SUCCESS;
2023-03-31 19:20:25 +02:00
rc = qmckl_provide_een_rescaled_e(context);
if (rc != QMCKL_SUCCESS) return rc;
rc = qmckl_provide_een_rescaled_n(context);
if (rc != QMCKL_SUCCESS) return rc;
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.tmp_c_date) {
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.tmp_c != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.tmp_c);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
"qmckl_provide_tmp_c",
2023-03-30 17:07:11 +02:00
"Unable to free ctx->jastrow_champ.tmp_c");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.tmp_c = NULL;
}
2022-08-07 14:57:10 +02:00
}
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.tmp_c == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 17:07:11 +02:00
mem_info.size = (ctx->jastrow_champ.cord_num) * (ctx->jastrow_champ.cord_num + 1)
2022-08-07 14:57:10 +02:00
,* ctx->electron.num * ctx->nucleus.num * ctx->electron.walker.num * sizeof(double);
double* tmp_c = (double*) qmckl_malloc(context, mem_info);
if (tmp_c == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_provide_tmp_c",
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.tmp_c = tmp_c;
}
2023-03-01 14:47:32 +01:00
rc = qmckl_compute_tmp_c(context,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.cord_num,
2022-04-06 16:26:35 +02:00
ctx->electron.num,
ctx->nucleus.num,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_e,
ctx->jastrow_champ.een_rescaled_n,
ctx->jastrow_champ.tmp_c);
2022-04-06 17:17:16 +02:00
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.tmp_c_date = ctx->date;
}
2023-01-26 18:42:34 +01:00
return rc;
}
qmckl_exit_code qmckl_provide_dtmp_c(qmckl_context context)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
2023-03-13 15:32:35 +01:00
2022-11-16 17:54:59 +01:00
qmckl_exit_code rc;
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-31 19:20:25 +02:00
rc = qmckl_provide_een_rescaled_e_deriv_e(context);
if (rc != QMCKL_SUCCESS) return rc;
rc = qmckl_provide_een_rescaled_n(context);
if (rc != QMCKL_SUCCESS) return rc;
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.dtmp_c_date) {
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.dtmp_c != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.dtmp_c);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
"qmckl_provide_dtmp_c",
2023-03-30 17:07:11 +02:00
"Unable to free ctx->jastrow_champ.dtmp_c");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.dtmp_c = NULL;
}
2022-08-07 14:57:10 +02:00
}
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.dtmp_c == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2023-03-30 17:07:11 +02:00
mem_info.size = (ctx->jastrow_champ.cord_num) * (ctx->jastrow_champ.cord_num + 1)
2022-08-07 14:57:10 +02:00
,* 4 * ctx->electron.num * ctx->nucleus.num * ctx->electron.walker.num * sizeof(double);
double* dtmp_c = (double*) qmckl_malloc(context, mem_info);
if (dtmp_c == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_provide_dtmp_c",
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.dtmp_c = dtmp_c;
}
2022-04-06 17:17:16 +02:00
2023-03-01 14:47:32 +01:00
rc = qmckl_compute_dtmp_c(context,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.cord_num,
2023-03-01 14:47:32 +01:00
ctx->electron.num,
ctx->nucleus.num,
ctx->electron.walker.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.een_rescaled_e_deriv_e,
ctx->jastrow_champ.een_rescaled_n,
ctx->jastrow_champ.dtmp_c);
2023-03-13 15:32:35 +01:00
if (rc != QMCKL_SUCCESS) {
return rc;
}
2022-04-06 11:16:17 +02:00
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.dtmp_c_date = ctx->date;
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute dim_c_vector
:PROPERTIES:
:Name: qmckl_compute_dim_c_vector
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_dim_c_vector_args
| Variable | Type | In/Out | Description |
|-----------------+-----------------+--------+-----------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~cord_num~ | ~int64_t~ | in | Order of polynomials |
| ~dim_c_vector~ | ~int64_t~ | out | dimension of c_vector_full table |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2022-11-16 11:58:44 +01:00
integer function qmckl_compute_dim_c_vector_f( &
context, cord_num, dim_c_vector) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: cord_num
2022-11-16 11:58:44 +01:00
integer*8 , intent(out) :: dim_c_vector
double precision :: x
integer*8 :: i, a, k, l, p, lmax
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2022-11-16 17:54:59 +01:00
if (cord_num < 0) then
info = QMCKL_INVALID_ARG_2
return
endif
2022-11-16 11:58:44 +01:00
dim_c_vector = 0
do p = 2, cord_num
do k = p - 1, 0, -1
if (k .ne. 0) then
lmax = p - k
else
lmax = p - k - 2
endif
do l = lmax, 0, -1
2021-07-07 15:52:15 +02:00
if (iand(p - k - l, 1_8) == 1) cycle
2022-11-16 11:58:44 +01:00
dim_c_vector = dim_c_vector + 1
end do
end do
end do
2022-11-16 11:58:44 +01:00
end function qmckl_compute_dim_c_vector_f
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2022-11-16 11:58:44 +01:00
qmckl_exit_code qmckl_compute_dim_c_vector (
2022-04-06 10:42:00 +02:00
const qmckl_context context,
const int64_t cord_num,
2022-11-16 11:58:44 +01:00
int64_t* const dim_c_vector){
2022-04-08 10:44:48 +02:00
int lmax;
2022-04-08 10:44:48 +02:00
if (context == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
}
2022-11-16 17:54:59 +01:00
if (cord_num < 0) {
return QMCKL_INVALID_ARG_2;
}
2022-11-16 11:58:44 +01:00
*dim_c_vector = 0;
2022-04-08 10:44:48 +02:00
for (int p=2; p <= cord_num; ++p){
for (int k=p-1; k >= 0; --k) {
if (k != 0) {
lmax = p - k;
} else {
lmax = p - k - 2;
}
for (int l = lmax; l >= 0; --l) {
if ( ((p - k - l) & 1)==1) continue;
2022-11-16 11:58:44 +01:00
*dim_c_vector=*dim_c_vector+1;
}
}
}
2022-04-08 10:44:48 +02:00
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_dim_c_vector_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2022-11-16 11:58:44 +01:00
qmckl_exit_code qmckl_compute_dim_c_vector (
2022-04-06 16:26:35 +02:00
const qmckl_context context,
const int64_t cord_num,
2022-11-16 11:58:44 +01:00
int64_t* const dim_c_vector );
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute c_vector_full
:PROPERTIES:
:Name: qmckl_compute_c_vector_full
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_c_vector_full_args
| Variable | Type | In/Out | Description |
|--------------------+----------------------------------------+--------+------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~nucl_num~ | ~int64_t~ | in | Number of atoms |
| ~dim_c_vector~ | ~int64_t~ | in | dimension of cord full table |
| ~type_nucl_num~ | ~int64_t~ | in | dimension of cord full table |
| ~type_nucl_vector~ | ~int64_t[nucl_num]~ | in | dimension of cord full table |
| ~c_vector~ | ~double[dim_c_vector][type_nucl_num]~ | in | dimension of cord full table |
| ~c_vector_full~ | ~double[dim_c_vector][nucl_num]~ | out | Full list of coefficients |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2022-11-16 11:58:44 +01:00
integer function qmckl_compute_c_vector_full_doc_f( &
context, nucl_num, dim_c_vector, type_nucl_num, &
type_nucl_vector, c_vector, c_vector_full) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: nucl_num
2022-11-16 11:58:44 +01:00
integer*8 , intent(in) :: dim_c_vector
integer*8 , intent(in) :: type_nucl_num
integer*8 , intent(in) :: type_nucl_vector(nucl_num)
2022-11-16 11:58:44 +01:00
double precision , intent(in) :: c_vector(type_nucl_num, dim_c_vector)
double precision , intent(out) :: c_vector_full(nucl_num,dim_c_vector)
double precision :: x
integer*8 :: i, a, k, l, nw
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
if (nucl_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
if (type_nucl_num <= 0) then
info = QMCKL_INVALID_ARG_4
return
endif
2022-11-16 17:54:59 +01:00
if (dim_c_vector < 0) then
info = QMCKL_INVALID_ARG_5
return
endif
do a = 1, nucl_num
2022-11-16 11:58:44 +01:00
c_vector_full(a,1:dim_c_vector) = c_vector(type_nucl_vector(a),1:dim_c_vector)
end do
2022-11-16 11:58:44 +01:00
end function qmckl_compute_c_vector_full_doc_f
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_factor_c_vector_full_args,rettyp=get_value("CRetType"),fname="qmckl_compute_c_vector_full_doc")
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
2022-11-16 11:58:44 +01:00
integer(c_int32_t) function qmckl_compute_c_vector_full_doc &
(context, nucl_num, dim_c_vector, type_nucl_num, type_nucl_vector, c_vector, c_vector_full) &
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 :: nucl_num
2022-11-16 11:58:44 +01:00
integer (c_int64_t) , intent(in) , value :: dim_c_vector
integer (c_int64_t) , intent(in) , value :: type_nucl_num
integer (c_int64_t) , intent(in) :: type_nucl_vector(nucl_num)
2022-11-16 11:58:44 +01:00
real (c_double ) , intent(in) :: c_vector(type_nucl_num,dim_c_vector)
real (c_double ) , intent(out) :: c_vector_full(nucl_num,dim_c_vector)
2022-11-16 11:58:44 +01:00
integer(c_int32_t), external :: qmckl_compute_c_vector_full_doc_f
info = qmckl_compute_c_vector_full_doc_f &
(context, nucl_num, dim_c_vector, type_nucl_num, type_nucl_vector, c_vector, c_vector_full)
2022-11-16 11:58:44 +01:00
end function qmckl_compute_c_vector_full_doc
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2022-11-16 11:58:44 +01:00
qmckl_exit_code qmckl_compute_c_vector_full_hpc (
2022-04-05 14:23:20 +02:00
const qmckl_context context,
const int64_t nucl_num,
2022-11-16 11:58:44 +01:00
const int64_t dim_c_vector,
2022-04-05 14:23:20 +02:00
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
2022-11-16 11:58:44 +01:00
const double* c_vector,
double* const c_vector_full ) {
2022-04-05 14:23:20 +02:00
if (context == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
}
if (nucl_num <= 0) {
return QMCKL_INVALID_ARG_2;
}
if (type_nucl_num <= 0) {
return QMCKL_INVALID_ARG_4;
}
2022-11-16 17:54:59 +01:00
if (dim_c_vector < 0) {
2022-04-05 14:23:20 +02:00
return QMCKL_INVALID_ARG_5;
}
2022-11-16 11:58:44 +01:00
for (int i=0; i < dim_c_vector; ++i) {
2022-04-05 14:23:20 +02:00
for (int a=0; a < nucl_num; ++a){
2022-11-16 11:58:44 +01:00
c_vector_full[a + i*nucl_num] = c_vector[(type_nucl_vector[a]-1)+i*type_nucl_num];
2022-04-05 14:23:20 +02:00
}
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-05 14:23:20 +02:00
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_c_vector_full_args,rettyp=get_value("CRetType"),fname="qmckl_compute_c_vector_full_doc")
2022-04-05 14:23:20 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2022-11-16 11:58:44 +01:00
qmckl_exit_code qmckl_compute_c_vector_full (
2022-04-05 14:23:20 +02:00
const qmckl_context context,
const int64_t nucl_num,
2022-11-16 11:58:44 +01:00
const int64_t dim_c_vector,
2022-04-05 14:23:20 +02:00
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
2022-11-16 11:58:44 +01:00
const double* c_vector,
double* const c_vector_full );
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-05 14:23:20 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval h_private_func) :comments org
2022-11-16 11:58:44 +01:00
qmckl_exit_code qmckl_compute_c_vector_full_doc (
2022-04-05 14:23:20 +02:00
const qmckl_context context,
const int64_t nucl_num,
2022-11-16 11:58:44 +01:00
const int64_t dim_c_vector,
2022-04-05 14:23:20 +02:00
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
2022-11-16 11:58:44 +01:00
const double* c_vector,
double* const c_vector_full );
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-05 14:23:20 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval h_private_func) :comments org
2022-11-16 11:58:44 +01:00
qmckl_exit_code qmckl_compute_c_vector_full_hpc (
2022-04-05 14:23:20 +02:00
const qmckl_context context,
const int64_t nucl_num,
2022-11-16 11:58:44 +01:00
const int64_t dim_c_vector,
2022-04-05 14:23:20 +02:00
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
2022-11-16 11:58:44 +01:00
const double* c_vector,
double* const c_vector_full );
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2022-11-16 11:58:44 +01:00
qmckl_exit_code qmckl_compute_c_vector_full (
2022-04-05 14:23:20 +02:00
const qmckl_context context,
const int64_t nucl_num,
2022-11-16 11:58:44 +01:00
const int64_t dim_c_vector,
2022-04-05 14:23:20 +02:00
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
2022-11-16 11:58:44 +01:00
const double* c_vector,
double* const c_vector_full ) {
2022-04-05 14:23:20 +02:00
#ifdef HAVE_HPC
2022-11-16 11:58:44 +01:00
return qmckl_compute_c_vector_full_hpc(context, nucl_num, dim_c_vector, type_nucl_num, type_nucl_vector, c_vector, c_vector_full);
2022-04-05 14:23:20 +02:00
#else
2022-11-16 11:58:44 +01:00
return qmckl_compute_c_vector_full_doc(context, nucl_num, dim_c_vector, type_nucl_num, type_nucl_vector, c_vector, c_vector_full);
2022-04-05 14:23:20 +02:00
#endif
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute lkpm_combined_index
:PROPERTIES:
:Name: qmckl_compute_lkpm_combined_index
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_lkpm_combined_index_args
| Variable | Type | In/Out | Description |
|-----------------------+-----------------------------+--------+-------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~cord_num~ | ~int64_t~ | in | Order of polynomials |
| ~dim_c_vector~ | ~int64_t~ | in | dimension of cord full table |
| ~lkpm_combined_index~ | ~int64_t[4][dim_c_vector]~ | out | Full list of combined indices |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2022-04-04 23:53:58 +02:00
integer function qmckl_compute_lkpm_combined_index_f( &
2022-11-16 11:58:44 +01:00
context, cord_num, dim_c_vector, lkpm_combined_index) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: cord_num
2022-11-16 11:58:44 +01:00
integer*8 , intent(in) :: dim_c_vector
integer*8 , intent(out) :: lkpm_combined_index(dim_c_vector, 4)
double precision :: x
integer*8 :: i, a, k, l, kk, p, lmax, m
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2022-11-16 17:54:59 +01:00
if (cord_num < 0) then
info = QMCKL_INVALID_ARG_2
return
endif
2022-11-16 17:54:59 +01:00
if (dim_c_vector < 0) then
info = QMCKL_INVALID_ARG_3
return
endif
2021-07-08 07:10:24 +02:00
kk = 0
do p = 2, cord_num
do k = p - 1, 0, -1
if (k .ne. 0) then
lmax = p - k
else
lmax = p - k - 2
end if
do l = lmax, 0, -1
2021-07-07 15:52:15 +02:00
if (iand(p - k - l, 1_8) .eq. 1) cycle
m = (p - k - l)/2
kk = kk + 1
2021-07-07 10:36:18 +02:00
lkpm_combined_index(kk, 1) = l
lkpm_combined_index(kk, 2) = k
lkpm_combined_index(kk, 3) = p
lkpm_combined_index(kk, 4) = m
end do
end do
end do
end function qmckl_compute_lkpm_combined_index_f
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
qmckl_exit_code qmckl_compute_lkpm_combined_index (
2022-04-06 10:42:00 +02:00
const qmckl_context context,
const int64_t cord_num,
2022-11-16 11:58:44 +01:00
const int64_t dim_c_vector,
2022-04-06 10:42:00 +02:00
int64_t* const lkpm_combined_index ) {
int kk, lmax, m;
2022-04-08 10:44:48 +02:00
if (context == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
}
2022-11-16 17:54:59 +01:00
if (cord_num < 0) {
return QMCKL_INVALID_ARG_2;
}
2022-11-16 17:54:59 +01:00
if (dim_c_vector < 0) {
return QMCKL_INVALID_ARG_3;
}
/*
*/
kk = 0;
for (int p = 2; p <= cord_num; ++p) {
for (int k=(p-1); k >= 0; --k) {
if (k != 0) {
lmax = p - k;
} else {
lmax = p - k - 2;
}
for (int l=lmax; l >= 0; --l) {
if (((p - k - l) & 1) == 1) continue;
m = (p - k - l)/2;
lkpm_combined_index[kk ] = l;
2022-11-16 11:58:44 +01:00
lkpm_combined_index[kk + dim_c_vector] = k;
lkpm_combined_index[kk + 2*dim_c_vector] = p;
lkpm_combined_index[kk + 3*dim_c_vector] = m;
kk = kk + 1;
}
}
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_lkpm_combined_index_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_compute_lkpm_combined_index (
2022-04-06 16:26:35 +02:00
const qmckl_context context,
const int64_t cord_num,
2022-11-16 11:58:44 +01:00
const int64_t dim_c_vector,
2022-04-08 10:44:48 +02:00
int64_t* const lkpm_combined_index );
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute tmp_c
:PROPERTIES:
:Name: qmckl_compute_tmp_c
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_tmp_c_args
| Variable | Type | In/Out | Description |
|------------------+------------------------------------------------------------------+--------+-----------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~cord_num~ | ~int64_t~ | in | Order of polynomials |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
2023-03-30 18:17:33 +02:00
| ~nucl_num~ | ~int64_t~ | in | Number of nuclei |
2023-03-30 12:34:17 +02:00
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~een_rescaled_e~ | ~double[walk_num][0:cord_num][elec_num][elec_num]~ | in | Electron-electron rescaled factor |
| ~een_rescaled_n~ | ~double[walk_num][0:cord_num][nucl_num][elec_num]~ | in | Electron-nucleus rescaled factor |
| ~tmp_c~ | ~double[walk_num][0:cord_num-1][0:cord_num][nucl_num][elec_num]~ | out | vector of non-zero coefficients |
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2022-04-06 16:26:35 +02:00
qmckl_exit_code qmckl_compute_tmp_c (const qmckl_context context,
const int64_t cord_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* een_rescaled_e,
const double* een_rescaled_n,
double* const tmp_c )
{
#ifdef HAVE_HPC
return qmckl_compute_tmp_c_hpc(context, cord_num, elec_num, nucl_num, walk_num, een_rescaled_e, een_rescaled_n, tmp_c);
#else
return qmckl_compute_tmp_c_doc(context, cord_num, elec_num, nucl_num, walk_num, een_rescaled_e, een_rescaled_n, tmp_c);
#endif
}
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-08 10:44:48 +02:00
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_tmp_c_args,rettyp=get_value("CRetType"),fname="qmckl_compute_tmp_c")
2022-04-06 16:26:35 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2022-04-06 16:26:35 +02:00
qmckl_exit_code qmckl_compute_tmp_c (
const qmckl_context context,
const int64_t cord_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* een_rescaled_e,
const double* een_rescaled_n,
2022-04-08 10:44:48 +02:00
double* const tmp_c );
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-06 16:26:35 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2022-04-06 16:26:35 +02:00
integer function qmckl_compute_tmp_c_doc_f( &
context, cord_num, elec_num, nucl_num, &
walk_num, een_rescaled_e, een_rescaled_n, tmp_c) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: cord_num
integer*8 , intent(in) :: elec_num
integer*8 , intent(in) :: nucl_num
integer*8 , intent(in) :: walk_num
2022-02-11 16:19:31 +01:00
double precision , intent(in) :: een_rescaled_e(elec_num, elec_num, 0:cord_num, walk_num)
2022-02-11 17:19:36 +01:00
double precision , intent(in) :: een_rescaled_n(elec_num, nucl_num, 0:cord_num, walk_num)
double precision , intent(out) :: tmp_c(elec_num, nucl_num,0:cord_num, 0:cord_num-1, walk_num)
double precision :: x
integer*8 :: i, j, a, l, kk, p, lmax, nw
character :: TransA, TransB
double precision :: alpha, beta
integer*8 :: M, N, K, LDA, LDB, LDC
TransA = 'N'
TransB = 'N'
alpha = 1.0d0
beta = 0.0d0
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2022-11-16 17:54:59 +01:00
if (cord_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
M = elec_num
N = nucl_num*(cord_num + 1)
K = elec_num
2022-02-11 16:19:31 +01:00
LDA = size(een_rescaled_e,1)
2022-02-11 17:19:36 +01:00
LDB = size(een_rescaled_n,1)
LDC = size(tmp_c,1)
do nw=1, walk_num
do i=0, cord_num-1
2022-04-04 16:56:33 +02:00
info = qmckl_dgemm(context, TransA, TransB, M, N, K, alpha, &
2022-02-11 16:19:31 +01:00
een_rescaled_e(1,1,i,nw),LDA*1_8, &
2022-02-11 17:19:36 +01:00
een_rescaled_n(1,1,0,nw),LDB*1_8, &
beta, &
tmp_c(1,1,0,i,nw),LDC)
end do
end do
2022-02-11 17:31:17 +01:00
2022-04-04 16:56:33 +02:00
end function qmckl_compute_tmp_c_doc_f
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval h_private_func) :comments org
2022-04-06 16:26:35 +02:00
qmckl_exit_code qmckl_compute_tmp_c_doc (
const qmckl_context context,
const int64_t cord_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* een_rescaled_e,
const double* een_rescaled_n,
2022-04-08 10:44:48 +02:00
double* const tmp_c );
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-04 16:56:33 +02:00
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_factor_tmp_c_args,rettyp=get_value("FRetType"),fname="qmckl_compute_tmp_c_doc")
2022-04-08 10:44:48 +02:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
2022-04-04 16:56:33 +02:00
integer(c_int32_t) function qmckl_compute_tmp_c_doc &
(context, cord_num, elec_num, nucl_num, walk_num, een_rescaled_e, een_rescaled_n, tmp_c) &
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 :: cord_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 :: walk_num
real (c_double ) , intent(in) :: een_rescaled_e(elec_num,elec_num,0:cord_num,walk_num)
real (c_double ) , intent(in) :: een_rescaled_n(elec_num,nucl_num,0:cord_num,walk_num)
real (c_double ) , intent(out) :: tmp_c(elec_num,nucl_num,0:cord_num,0:cord_num-1,walk_num)
integer(c_int32_t), external :: qmckl_compute_tmp_c_doc_f
info = qmckl_compute_tmp_c_doc_f &
(context, cord_num, elec_num, nucl_num, walk_num, een_rescaled_e, een_rescaled_n, tmp_c)
end function qmckl_compute_tmp_c_doc
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-04 16:56:33 +02:00
2023-03-30 12:34:17 +02:00
***** CPU :noexport:
2022-04-04 16:56:33 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2022-04-04 16:56:33 +02:00
qmckl_exit_code qmckl_compute_tmp_c_hpc (
2022-04-06 10:42:00 +02:00
const qmckl_context context,
const int64_t cord_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* een_rescaled_e,
const double* een_rescaled_n,
double* const tmp_c ) {
if (context == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
}
2022-11-16 17:54:59 +01:00
if (cord_num < 0) {
return QMCKL_INVALID_ARG_2;
2022-04-08 10:44:48 +02:00
}
if (elec_num <= 0) {
return QMCKL_INVALID_ARG_3;
2022-04-08 10:44:48 +02:00
}
if (nucl_num <= 0) {
return QMCKL_INVALID_ARG_4;
2022-04-08 10:44:48 +02:00
}
2022-04-04 16:56:33 +02:00
if (walk_num <= 0) {
return QMCKL_INVALID_ARG_5;
2022-04-08 10:44:48 +02:00
}
2022-04-04 16:56:33 +02:00
qmckl_exit_code info = QMCKL_SUCCESS;
2022-04-04 16:56:33 +02:00
const char TransA = 'N';
const char TransB = 'N';
const double alpha = 1.0;
const double beta = 0.0;
const int64_t M = elec_num;
const int64_t N = nucl_num*(cord_num + 1);
const int64_t K = elec_num;
const int64_t LDA = elec_num;
const int64_t LDB = elec_num;
const int64_t LDC = elec_num;
2022-04-05 09:56:13 +02:00
const int64_t af = elec_num*elec_num;
const int64_t bf = elec_num*nucl_num*(cord_num+1);
const int64_t cf = bf;
2022-04-06 16:26:35 +02:00
#ifdef HAVE_OPENMP
#pragma omp parallel for collapse(2)
#endif
2022-04-04 16:56:33 +02:00
for (int64_t nw=0; nw < walk_num; ++nw) {
for (int64_t i=0; i<cord_num; ++i){
2022-04-06 16:26:35 +02:00
info = qmckl_dgemm(context, TransA, TransB, M, N, K, alpha,
&(een_rescaled_e[af*(i+nw*(cord_num+1))]), LDA,
&(een_rescaled_n[bf*nw]), LDB, beta,
&(tmp_c[cf*(i+nw*cord_num)]), LDC);
}
}
return info;
}
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-06 17:17:16 +02:00
2022-04-06 11:16:17 +02:00
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_header(table=qmckl_factor_tmp_c_args,rettyp=get_value("CRetType"),fname="qmckl_compute_tmp_c")
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src c :tangle (eval h_func) :comments org
2022-04-04 16:56:33 +02:00
qmckl_exit_code qmckl_compute_tmp_c (
const qmckl_context context,
const int64_t cord_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* een_rescaled_e,
const double* een_rescaled_n,
2022-04-08 10:44:48 +02:00
double* const tmp_c );
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_tmp_c_args,rettyp=get_value("CRetType"),fname="qmckl_compute_tmp_c_doc")
2022-04-04 16:56:33 +02:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src c :tangle (eval h_private_func) :comments org
2022-04-04 16:56:33 +02:00
qmckl_exit_code qmckl_compute_tmp_c_doc (
const qmckl_context context,
const int64_t cord_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* een_rescaled_e,
const double* een_rescaled_n,
2022-04-08 10:44:48 +02:00
double* const tmp_c );
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-04 16:56:33 +02:00
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_tmp_c_args,rettyp=get_value("CRetType"),fname="qmckl_compute_tmp_c_hpc")
2022-04-04 16:56:33 +02:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
2022-04-06 17:17:16 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval h_private_func) :comments org
2022-04-04 16:56:33 +02:00
qmckl_exit_code qmckl_compute_tmp_c_hpc (const qmckl_context context,
const int64_t cord_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* een_rescaled_e,
const double* een_rescaled_n,
2022-04-08 10:44:48 +02:00
double* const tmp_c );
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-06 16:26:35 +02:00
2023-03-30 12:34:17 +02:00
**** Compute dtmp_c
:PROPERTIES:
:Name: qmckl_compute_dtmp_c
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_dtmp_c_args
| Variable | Type | In/Out | Description |
|--------------------------+------------------------------------------------------------------+--------+-----------------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~cord_num~ | ~int64_t~ | in | Order of polynomials |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
2023-03-30 18:17:33 +02:00
| ~nucl_num~ | ~int64_t~ | in | Number of nuclei |
2023-03-30 12:34:17 +02:00
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~een_rescaled_e_deriv_e~ | ~double[walk_num][0:cord_num][elec_num][4][elec_num]~ | in | Electron-electron rescaled factor derivatives |
| ~een_rescaled_n~ | ~double[walk_num][0:cord_num][nucl_num][elec_num]~ | in | Electron-nucleus rescaled factor |
| ~dtmp_c~ | ~double[walk_num][0:cord_num-1][0:cord_num][nucl_num][elec_num]~ | out | vector of non-zero coefficients |
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2022-04-06 16:26:35 +02:00
qmckl_exit_code
qmckl_compute_dtmp_c (const qmckl_context context,
const int64_t cord_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* een_rescaled_e_deriv_e,
const double* een_rescaled_n,
double* const dtmp_c );
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-06 16:26:35 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2022-04-06 16:26:35 +02:00
qmckl_exit_code
qmckl_compute_dtmp_c (const qmckl_context context,
const int64_t cord_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* een_rescaled_e_deriv_e,
const double* een_rescaled_n,
double* const dtmp_c )
{
#ifdef HAVE_HPC
return qmckl_compute_dtmp_c_hpc (context, cord_num, elec_num, nucl_num, walk_num, een_rescaled_e_deriv_e,
een_rescaled_n, dtmp_c );
#else
return qmckl_compute_dtmp_c_doc (context, cord_num, elec_num, nucl_num, walk_num, een_rescaled_e_deriv_e,
een_rescaled_n, dtmp_c );
#endif
}
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-06 16:26:35 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2022-04-04 23:53:58 +02:00
integer function qmckl_compute_dtmp_c_doc_f( &
context, cord_num, elec_num, nucl_num, &
walk_num, een_rescaled_e_deriv_e, een_rescaled_n, dtmp_c) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: cord_num
integer*8 , intent(in) :: elec_num
integer*8 , intent(in) :: nucl_num
integer*8 , intent(in) :: walk_num
2022-02-11 17:06:17 +01:00
double precision , intent(in) :: een_rescaled_e_deriv_e(elec_num, 4, elec_num, 0:cord_num, walk_num)
2022-02-11 17:19:36 +01:00
double precision , intent(in) :: een_rescaled_n(elec_num, nucl_num, 0:cord_num, walk_num)
double precision , intent(out) :: dtmp_c(elec_num, 4, nucl_num,0:cord_num, 0:cord_num-1, walk_num)
double precision :: x
integer*8 :: i, j, a, l, kk, p, lmax, nw, ii
character :: TransA, TransB
double precision :: alpha, beta
integer*8 :: M, N, K, LDA, LDB, LDC
TransA = 'N'
TransB = 'N'
alpha = 1.0d0
beta = 0.0d0
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2022-11-16 17:54:59 +01:00
if (cord_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
M = 4*elec_num
N = nucl_num*(cord_num + 1)
K = elec_num
2022-02-11 17:06:17 +01:00
LDA = 4*size(een_rescaled_e_deriv_e,1)
2022-02-11 17:19:36 +01:00
LDB = size(een_rescaled_n,1)
LDC = 4*size(dtmp_c,1)
do nw=1, walk_num
2022-04-04 16:56:33 +02:00
do i=0, cord_num-1
info = qmckl_dgemm(context,TransA, TransB, M, N, K, alpha, &
een_rescaled_e_deriv_e(1,1,1,i,nw),LDA*1_8, &
een_rescaled_n(1,1,0,nw),LDB*1_8, &
beta, &
dtmp_c(1,1,1,0,i,nw),LDC)
end do
end do
2022-04-08 10:44:48 +02:00
2022-04-04 16:56:33 +02:00
end function qmckl_compute_dtmp_c_doc_f
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_factor_dtmp_c_args,rettyp=get_value("FRetType"),fname="qmckl_compute_dtmp_c_doc")
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
2022-04-04 16:56:33 +02:00
integer(c_int32_t) function qmckl_compute_dtmp_c_doc &
(context, cord_num, elec_num, nucl_num, walk_num, een_rescaled_e_deriv_e, een_rescaled_n, dtmp_c) &
bind(C) result(info)
2022-04-04 16:56:33 +02:00
use, intrinsic :: iso_c_binding
implicit none
integer (c_int64_t) , intent(in) , value :: context
integer (c_int64_t) , intent(in) , value :: cord_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 :: walk_num
real (c_double ) , intent(in) :: een_rescaled_e_deriv_e(elec_num,4,elec_num,0:cord_num,walk_num)
real (c_double ) , intent(in) :: een_rescaled_n(elec_num,nucl_num,0:cord_num,walk_num)
real (c_double ) , intent(out) :: dtmp_c(elec_num,nucl_num,0:cord_num,0:cord_num-1,walk_num)
integer(c_int32_t), external :: qmckl_compute_dtmp_c_doc_f
info = qmckl_compute_dtmp_c_doc_f &
(context, cord_num, elec_num, nucl_num, walk_num, een_rescaled_e_deriv_e, een_rescaled_n, dtmp_c)
end function qmckl_compute_dtmp_c_doc
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2022-04-06 16:26:35 +02:00
qmckl_exit_code qmckl_compute_dtmp_c_doc (
const qmckl_context context,
const int64_t cord_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* een_rescaled_e_deriv_e,
const double* een_rescaled_n,
double* const dtmp_c );
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-06 16:26:35 +02:00
2023-03-30 12:34:17 +02:00
***** CPU :noexport:
2022-04-08 10:44:48 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes
2022-04-06 16:26:35 +02:00
qmckl_exit_code
qmckl_compute_dtmp_c_hpc (const qmckl_context context,
const int64_t cord_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* een_rescaled_e_deriv_e,
const double* een_rescaled_n,
double* const dtmp_c )
2022-04-04 16:56:33 +02:00
{
if (context == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
2022-04-08 10:44:48 +02:00
}
2022-11-16 17:54:59 +01:00
if (cord_num < 0) {
return QMCKL_INVALID_ARG_2;
}
if (elec_num <= 0) {
return QMCKL_INVALID_ARG_3;
}
if (nucl_num <= 0) {
return QMCKL_INVALID_ARG_4;
2022-04-08 10:44:48 +02:00
}
2022-04-04 16:56:33 +02:00
if (walk_num <= 0) {
return QMCKL_INVALID_ARG_5;
2022-04-08 10:44:48 +02:00
}
2022-04-04 16:56:33 +02:00
qmckl_exit_code info = QMCKL_SUCCESS;
2022-04-04 16:56:33 +02:00
const char TransA = 'N';
const char TransB = 'N';
const double alpha = 1.0;
const double beta = 0.0;
2022-03-17 22:27:10 +01:00
2022-04-04 16:56:33 +02:00
const int64_t M = 4*elec_num;
const int64_t N = nucl_num*(cord_num + 1);
const int64_t K = elec_num;
2022-03-17 22:27:10 +01:00
2022-04-04 16:56:33 +02:00
const int64_t LDA = 4*elec_num;
const int64_t LDB = elec_num;
const int64_t LDC = 4*elec_num;
2022-04-05 09:56:13 +02:00
const int64_t af = elec_num*elec_num*4;
const int64_t bf = elec_num*nucl_num*(cord_num+1);
const int64_t cf = elec_num*4*nucl_num*(cord_num+1);
2022-04-06 16:26:35 +02:00
#ifdef HAVE_OPENMP
#pragma omp parallel for collapse(2)
#endif
2022-04-04 16:56:33 +02:00
for (int64_t nw=0; nw < walk_num; ++nw) {
2022-04-05 09:56:13 +02:00
for (int64_t i=0; i < cord_num; ++i) {
2022-04-06 16:26:35 +02:00
info = qmckl_dgemm(context, TransA, TransB, M, N, K, alpha,
&(een_rescaled_e_deriv_e[af*(i+nw*(cord_num+1))]), LDA,
&(een_rescaled_n[bf*nw]), LDB, beta,
&(dtmp_c[cf*(i+nw*cord_num)]), LDC);
}
}
return info;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2022-04-04 17:30:38 +02:00
qmckl_exit_code qmckl_compute_dtmp_c_hpc (
2022-04-06 10:42:00 +02:00
const qmckl_context context,
const int64_t cord_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* een_rescaled_e_deriv_e,
const double* een_rescaled_n,
double* const dtmp_c );
2023-03-30 12:34:17 +02:00
#+end_src
2022-04-08 10:44:48 +02:00
2023-03-30 12:34:17 +02:00
**** Test
2023-03-30 12:34:17 +02:00
#+name: helper_funcs
#+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]
2021-09-22 15:47:39 +02:00
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
for l in range(0,cord_num+1):
for j in range(0, elec_num):
een_rescaled_e[j,j,l] = 0.0
lkpm_of_cindex = np.array(lkpm_combined_index).T
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+RESULTS: helper_funcs
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval c_test)
assert(qmckl_electron_provided(context));
double tmp_c[walk_num][cord_num][cord_num+1][nucl_num][elec_num];
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_tmp_c(context, &(tmp_c[0][0][0][0][0]));
double dtmp_c[walk_num][cord_num][cord_num+1][nucl_num][4][elec_num];
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_dtmp_c(context, &(dtmp_c[0][0][0][0][0][0]));
2022-04-06 16:26:35 +02:00
printf("%e\n%e\n", tmp_c[0][0][1][0][0], 2.7083473948352403);
assert(fabs(tmp_c[0][0][1][0][0] - 2.7083473948352403) < 1e-12);
2022-09-22 16:43:57 +02:00
printf("%e\n%e\n", dtmp_c[0][1][0][0][0][0],0.237440520852232);
2022-02-11 17:06:17 +01:00
assert(fabs(dtmp_c[0][1][0][0][0][0] - 0.237440520852232) < 1e-12);
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-31 14:41:32 +02:00
2023-03-30 12:34:17 +02:00
*** Electron-electron-nucleus Jastrow $f_{een}$
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
Calculate the electron-electron-nuclear three-body jastrow component ~factor_een~
using the above prepared tables.
2021-07-07 10:36:18 +02:00
2023-03-30 12:34:17 +02:00
TODO: write equations.
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
**** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_factor_een(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const factor_een,
const int64_t size_max);
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 10:36:18 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_factor_een(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const factor_een,
const int64_t size_max)
2021-07-07 10:36:18 +02:00
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
2023-03-31 13:37:35 +02:00
rc = qmckl_provide_jastrow_champ_factor_een(context);
2021-07-07 10:36:18 +02:00
if (rc != QMCKL_SUCCESS) return rc;
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-07-07 10:36:18 +02:00
assert (ctx != NULL);
2022-08-07 14:57:10 +02:00
int64_t sze = ctx->electron.walker.num;
2022-02-14 19:11:37 +01:00
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_factor_een",
2022-02-14 19:11:37 +01:00
"Array too small. Expected walk_num");
}
2023-03-30 17:07:11 +02:00
memcpy(factor_een, ctx->jastrow_champ.factor_een, sze*sizeof(double));
2021-07-07 10:36:18 +02:00
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 10:36:18 +02:00
2023-03-30 12:34:17 +02:00
***** Fortran interface
2022-11-16 17:54:59 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src f90 :tangle (eval fh_func) :comments org
2022-11-16 17:54:59 +01:00
interface
2023-03-30 17:07:11 +02:00
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_factor_een (context, &
2022-11-16 17:54:59 +01:00
factor_een, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: factor_een(size_max)
2023-03-30 17:07:11 +02:00
end function qmckl_get_jastrow_champ_factor_een
2022-11-16 17:54:59 +01:00
end interface
2023-03-30 12:34:17 +02:00
#+end_src
2022-11-16 17:54:59 +01:00
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_factor_een(qmckl_context context);
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_factor_een(qmckl_context context)
2021-07-07 10:36:18 +02:00
{
qmckl_exit_code rc;
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-07-07 10:36:18 +02:00
assert (ctx != NULL);
/* Check if en rescaled distance is provided */
rc = qmckl_provide_een_rescaled_e(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Check if en rescaled distance derivatives is provided */
rc = qmckl_provide_een_rescaled_n(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Check if en rescaled distance derivatives is provided */
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_c_vector_full(context);
2021-07-07 10:36:18 +02:00
if(rc != QMCKL_SUCCESS) return rc;
/* Check if en rescaled distance derivatives is provided */
rc = qmckl_provide_lkpm_combined_index(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Check if tmp_c is provided */
rc = qmckl_provide_tmp_c(context);
if(rc != QMCKL_SUCCESS) return rc;
2021-07-07 10:36:18 +02:00
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.factor_een_date) {
2021-07-07 10:36:18 +02:00
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.factor_een != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.factor_een);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-31 13:37:35 +02:00
"qmckl_provide_jastrow_champ_factor_een",
2023-03-30 17:07:11 +02:00
"Unable to free ctx->jastrow_champ.factor_een");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_een = NULL;
}
2022-08-07 14:57:10 +02:00
}
2021-07-07 10:36:18 +02:00
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.factor_een == NULL) {
2021-07-07 10:36:18 +02:00
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2022-08-07 14:57:10 +02:00
mem_info.size = ctx->electron.walker.num * sizeof(double);
double* factor_een = (double*) qmckl_malloc(context, mem_info);
if (factor_een == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-31 13:37:35 +02:00
"qmckl_provide_jastrow_champ_factor_een",
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_een = factor_een;
}
2022-01-31 16:47:28 +01:00
2023-03-31 13:37:35 +02:00
rc = qmckl_compute_jastrow_champ_factor_een(context,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
2022-04-05 11:44:17 +02:00
ctx->electron.num,
ctx->nucleus.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.cord_num,
ctx->jastrow_champ.dim_c_vector,
ctx->jastrow_champ.c_vector_full,
ctx->jastrow_champ.lkpm_combined_index,
ctx->jastrow_champ.tmp_c,
ctx->jastrow_champ.een_rescaled_n,
ctx->jastrow_champ.factor_een);
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_een_date = ctx->date;
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute naive
:PROPERTIES:
2023-03-31 13:37:35 +02:00
:Name: qmckl_compute_jastrow_champ_factor_een_naive
2023-03-30 12:34:17 +02:00
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_een_naive_args
| Variable | Type | In/Out | Description |
|-----------------------+----------------------------------------------------+--------+--------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
2023-03-30 18:17:33 +02:00
| ~nucl_num~ | ~int64_t~ | in | Number of nuclei |
2023-03-30 12:34:17 +02:00
| ~cord_num~ | ~int64_t~ | in | order of polynomials |
2023-03-30 18:17:33 +02:00
| ~dim_c_vector~ | ~int64_t~ | in | dimension of full coefficient vector |
| ~c_vector_full~ | ~double[dim_c_vector][nucl_num]~ | in | full coefficient vector |
| ~lkpm_combined_index~ | ~int64_t[4][dim_c_vector]~ | in | combined indices |
2023-03-30 12:34:17 +02:00
| ~een_rescaled_e~ | ~double[walk_num][elec_num][elec_num][0:cord_num]~ | in | Electron-nucleus rescaled |
| ~een_rescaled_n~ | ~double[walk_num][elec_num][nucl_num][0:cord_num]~ | in | Electron-nucleus rescaled factor |
| ~factor_een~ | ~double[walk_num]~ | out | Electron-nucleus jastrow |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2023-03-31 13:37:35 +02:00
integer function qmckl_compute_jastrow_champ_factor_een_naive_f( &
2022-04-04 23:53:58 +02:00
context, walk_num, elec_num, nucl_num, cord_num,&
2022-11-16 11:58:44 +01:00
dim_c_vector, c_vector_full, lkpm_combined_index, &
2022-04-04 23:53:58 +02:00
een_rescaled_e, een_rescaled_n, factor_een) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
2022-11-16 11:58:44 +01:00
integer*8 , intent(in) :: walk_num, elec_num, cord_num, nucl_num, dim_c_vector
integer*8 , intent(in) :: lkpm_combined_index(dim_c_vector,4)
double precision , intent(in) :: c_vector_full(nucl_num, dim_c_vector)
double precision , intent(in) :: een_rescaled_e(0:cord_num, elec_num, elec_num, walk_num)
double precision , intent(in) :: een_rescaled_n(0:cord_num, nucl_num, elec_num, walk_num)
double precision , intent(out) :: factor_een(walk_num)
integer*8 :: i, a, j, l, k, p, m, n, nw
double precision :: accu, accu2, cn
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
2022-11-16 17:54:59 +01:00
if (cord_num < 0) then
info = QMCKL_INVALID_ARG_5
return
endif
factor_een = 0.0d0
do nw =1, walk_num
2022-11-16 11:58:44 +01:00
do n = 1, dim_c_vector
l = lkpm_combined_index(n, 1)
k = lkpm_combined_index(n, 2)
p = lkpm_combined_index(n, 3)
m = lkpm_combined_index(n, 4)
do a = 1, nucl_num
accu2 = 0.0d0
2022-11-16 11:58:44 +01:00
cn = c_vector_full(a, n)
do j = 1, elec_num
accu = 0.0d0
do i = 1, elec_num
accu = accu + een_rescaled_e(k,i,j,nw) * &
een_rescaled_n(m,a,i,nw)
!if(nw .eq. 1) then
! print *,l,k,p,m,j,i,een_rescaled_e(k,i,j,nw), een_rescaled_n(m,a,i,nw), accu
!endif
end do
accu2 = accu2 + accu * een_rescaled_n(m + l,a,j,nw)
!print *, l,m,nw,accu, accu2, een_rescaled_n(m + l, a, j, nw), cn, factor_een(nw)
end do
factor_een(nw) = factor_een(nw) + accu2 * cn
end do
end do
end do
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_een_naive_f
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_een_naive_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_een_naive (
2022-04-06 10:42:00 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t cord_num,
2022-11-16 11:58:44 +01:00
const int64_t dim_c_vector,
const double* c_vector_full,
2022-04-06 10:42:00 +02:00
const int64_t* lkpm_combined_index,
const double* een_rescaled_e,
const double* een_rescaled_n,
double* const factor_een );
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_factor_een_naive_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
2023-03-31 13:37:35 +02:00
integer(c_int32_t) function qmckl_compute_jastrow_champ_factor_een_naive &
2022-04-06 10:42:00 +02:00
(context, &
walk_num, &
elec_num, &
nucl_num, &
cord_num, &
2022-11-16 11:58:44 +01:00
dim_c_vector, &
c_vector_full, &
2022-04-06 10:42:00 +02:00
lkpm_combined_index, &
een_rescaled_e, &
een_rescaled_n, &
factor_een) &
bind(C) result(info)
use, intrinsic :: iso_c_binding
implicit none
2021-07-07 10:36:18 +02:00
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
2022-11-16 11:58:44 +01:00
integer (c_int64_t) , intent(in) , value :: dim_c_vector
real (c_double ) , intent(in) :: c_vector_full(nucl_num,dim_c_vector)
integer (c_int64_t) , intent(in) :: lkpm_combined_index(dim_c_vector,4)
real (c_double ) , intent(in) :: een_rescaled_e(0:cord_num,elec_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) :: factor_een(walk_num)
2021-07-07 10:36:18 +02:00
2023-03-31 13:37:35 +02:00
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_factor_een_naive_f
info = qmckl_compute_jastrow_champ_factor_een_naive_f &
2022-04-06 10:42:00 +02:00
(context, &
walk_num, &
elec_num, &
nucl_num, &
cord_num, &
2022-11-16 11:58:44 +01:00
dim_c_vector, &
c_vector_full, &
2022-04-06 10:42:00 +02:00
lkpm_combined_index, &
een_rescaled_e, &
een_rescaled_n, &
factor_een)
2021-07-07 10:36:18 +02:00
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_een_naive
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 10:36:18 +02:00
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
2023-03-31 13:37:35 +02:00
:Name: qmckl_compute_jastrow_champ_factor_een_doc
2023-03-30 12:34:17 +02:00
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_een_args
2023-03-30 18:17:33 +02:00
| Variable | Type | In/Out | Description |
|-----------------------+------------------------------------------------------------------+--------+--------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~nucl_num~ | ~int64_t~ | in | Number of nuclei |
| ~cord_num~ | ~int64_t~ | in | order of polynomials |
| ~dim_c_vector~ | ~int64_t~ | in | dimension of full coefficient vector |
| ~c_vector_full~ | ~double[dim_c_vector][nucl_num]~ | in | full coefficient vector |
| ~lkpm_combined_index~ | ~int64_t[4][dim_c_vector]~ | in | combined indices |
| ~tmp_c~ | ~double[walk_num][0:cord_num-1][0:cord_num][nucl_num][elec_num]~ | in | vector of non-zero coefficients |
| ~een_rescaled_n~ | ~double[walk_num][0:cord_num][nucl_num][elec_num]~ | in | Electron-nucleus rescaled distances |
| ~factor_een~ | ~double[walk_num]~ | out | Electron-nucleus jastrow |
2023-03-30 12:34:17 +02:00
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2023-03-31 13:37:35 +02:00
integer function qmckl_compute_jastrow_champ_factor_een_doc_f( &
2022-04-04 23:53:58 +02:00
context, walk_num, elec_num, nucl_num, cord_num, &
2022-11-16 11:58:44 +01:00
dim_c_vector, c_vector_full, lkpm_combined_index, &
2022-04-04 23:53:58 +02:00
tmp_c, een_rescaled_n, factor_een) &
2021-07-07 10:36:18 +02:00
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
2022-11-16 11:58:44 +01:00
integer*8 , intent(in) :: walk_num, elec_num, cord_num, nucl_num, dim_c_vector
integer*8 , intent(in) :: lkpm_combined_index(dim_c_vector,4)
double precision , intent(in) :: c_vector_full(nucl_num, dim_c_vector)
double precision , intent(in) :: tmp_c(elec_num, nucl_num,0:cord_num, 0:cord_num-1, walk_num)
2022-02-11 17:19:36 +01:00
double precision , intent(in) :: een_rescaled_n(elec_num, nucl_num, 0:cord_num, walk_num)
2021-07-07 10:36:18 +02:00
double precision , intent(out) :: factor_een(walk_num)
integer*8 :: i, a, j, l, k, p, m, n, nw
double precision :: accu, accu2, cn
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
2022-11-16 17:54:59 +01:00
if (cord_num < 0) then
2021-07-07 10:36:18 +02:00
info = QMCKL_INVALID_ARG_5
return
endif
factor_een = 0.0d0
2021-07-07 10:36:18 +02:00
do nw =1, walk_num
2023-03-30 18:17:33 +02:00
do n = 1, dim_c_vector
l = lkpm_combined_index(n, 1)
k = lkpm_combined_index(n, 2)
p = lkpm_combined_index(n, 3)
m = lkpm_combined_index(n, 4)
2021-07-07 10:36:18 +02:00
2023-03-30 18:17:33 +02:00
do a = 1, nucl_num
cn = c_vector_full(a, n)
if(cn == 0.d0) cycle
2023-03-30 18:17:33 +02:00
accu = 0.0d0
do j = 1, elec_num
accu = accu + een_rescaled_n(j,a,m,nw) * tmp_c(j,a,m+l,k,nw)
end do
factor_een(nw) = factor_een(nw) + accu * cn
end do
end do
2021-07-07 10:36:18 +02:00
end do
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_een_doc_f
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 10:36:18 +02:00
2023-03-30 18:17:33 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_een_args,rettyp=qmckl_exit_code),fname=get_value("Name"))
2021-07-07 10:36:18 +02:00
2023-03-30 18:17:33 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code
2023-03-31 13:37:35 +02:00
qmckl_compute_jastrow_champ_factor_een_doc (const qmckl_context context,
2023-03-30 18:17:33 +02:00
const int64_t walk_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t cord_num,
const int64_t dim_c_vector,
const double* c_vector_full,
const int64_t* lkpm_combined_index,
const double* een_rescaled_e,
const double* een_rescaled_n,
double* const factor_een );
2021-07-07 10:36:18 +02:00
2023-03-30 18:17:33 +02:00
qmckl_exit_code
2023-03-31 13:37:35 +02:00
qmckl_compute_jastrow_champ_factor_een (const qmckl_context context,
2023-03-30 18:17:33 +02:00
const int64_t walk_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t cord_num,
const int64_t dim_c_vector,
const double* c_vector_full,
const int64_t* lkpm_combined_index,
const double* een_rescaled_e,
const double* een_rescaled_n,
double* const factor_een );
#+end_src
2021-07-07 10:36:18 +02:00
2023-03-30 18:17:33 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code
2023-03-31 13:37:35 +02:00
qmckl_compute_jastrow_champ_factor_een (const qmckl_context context,
2023-03-30 18:17:33 +02:00
const int64_t walk_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t cord_num,
const int64_t dim_c_vector,
const double* c_vector_full,
const int64_t* lkpm_combined_index,
const double* een_rescaled_e,
const double* een_rescaled_n,
double* const factor_een )
{
#ifdef HAVE_HPC
2023-03-31 13:37:35 +02:00
return qmckl_compute_jastrow_champ_factor_een_doc (context, walk_num, elec_num, nucl_num, cord_num, dim_c_vector,
2023-03-30 18:17:33 +02:00
c_vector_full, lkpm_combined_index, een_rescaled_e, een_rescaled_n,
factor_een );
#else
2023-03-31 13:37:35 +02:00
return qmckl_compute_jastrow_champ_factor_een_doc (context, walk_num, elec_num, nucl_num, cord_num, dim_c_vector,
2023-03-30 18:17:33 +02:00
c_vector_full, lkpm_combined_index, een_rescaled_e, een_rescaled_n,
factor_een );
#endif
}
#+end_src
2023-03-31 13:37:35 +02:00
#+CALL: generate_c_interface(table=qmckl_factor_een_args,rettyp=get_value("CRetType"),fname="qmckl_compute_jastrow_champ_factor_een_doc"))
2021-07-07 10:36:18 +02:00
2023-03-30 18:17:33 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
2023-03-31 13:37:35 +02:00
integer(c_int32_t) function qmckl_compute_jastrow_champ_factor_een_doc &
2023-03-30 18:17:33 +02:00
(context, &
walk_num, &
elec_num, &
nucl_num, &
cord_num, &
dim_c_vector, &
c_vector_full, &
lkpm_combined_index, &
tmp_c, &
een_rescaled_n, &
factor_een) &
bind(C) result(info)
2021-07-07 10:36:18 +02:00
2023-03-30 18:17:33 +02:00
use, intrinsic :: iso_c_binding
implicit none
2021-07-07 10:36:18 +02:00
2023-03-30 18:17:33 +02:00
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
integer (c_int64_t) , intent(in) , value :: dim_c_vector
real (c_double ) , intent(in) :: c_vector_full(nucl_num,dim_c_vector)
integer (c_int64_t) , intent(in) :: lkpm_combined_index(dim_c_vector,4)
real (c_double ) , intent(in) :: tmp_c(elec_num,nucl_num,0:cord_num,0:cord_num-1,walk_num)
real (c_double ) , intent(in) :: een_rescaled_n(elec_num,nucl_num,0:cord_num,walk_num)
real (c_double ) , intent(out) :: factor_een(walk_num)
2023-03-31 13:37:35 +02:00
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_factor_een_doc_f
info = qmckl_compute_jastrow_champ_factor_een_doc_f &
2023-03-30 18:17:33 +02:00
(context, &
walk_num, &
elec_num, &
nucl_num, &
cord_num, &
dim_c_vector, &
c_vector_full, &
lkpm_combined_index, &
tmp_c, &
een_rescaled_n, &
factor_een)
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_een_doc
2023-03-30 18:17:33 +02:00
#+end_src
2021-07-07 10:36:18 +02:00
2023-03-30 12:34:17 +02:00
**** Test
#+begin_src python :results output :exports none :noweb yes
2021-07-07 10:36:18 +02:00
import numpy as np
<<jastrow_data>>
2021-09-22 15:47:39 +02:00
<<helper_funcs>>
2021-07-07 10:36:18 +02:00
2021-09-22 15:47:39 +02:00
kappa = 1.0
2021-07-07 10:36:18 +02:00
2021-09-22 15:47:39 +02:00
factor_een = 0.0
2022-11-16 11:58:44 +01:00
for n in range(0, dim_c_vector):
2021-09-22 15:47:39 +02:00
l = lkpm_of_cindex[0,n]
k = lkpm_of_cindex[1,n]
p = lkpm_of_cindex[2,n]
m = lkpm_of_cindex[3,n]
for a in range(0, nucl_num):
accu2 = 0.0
2022-11-16 11:58:44 +01:00
cn = c_vector_full[a][n]
2021-09-22 15:47:39 +02:00
for j in range(0, elec_num):
accu = 0.0
for i in range(0, elec_num):
accu = accu + een_rescaled_e[i,j,k] * \
een_rescaled_n[a,i,m]
accu2 = accu2 + accu * een_rescaled_n[a,j,m+l]
factor_een = factor_een + accu2 * cn
print("factor_een:",factor_een)
2023-03-30 12:34:17 +02:00
#+end_src
2021-07-07 10:36:18 +02:00
2023-03-30 12:34:17 +02:00
#+RESULTS:
: factor_een: -0.37407972141304213
2022-01-31 16:47:28 +01:00
2021-07-07 10:36:18 +02:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval c_test)
2021-07-07 10:36:18 +02:00
/* Check if Jastrow is properly initialized */
2023-03-30 17:07:11 +02:00
assert(qmckl_jastrow_champ_provided(context));
2021-09-21 12:05:03 +02:00
double factor_een[walk_num];
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_factor_een(context, &(factor_een[0]),walk_num);
assert(fabs(factor_een[0] + 0.37407972141304213) < 1e-12);
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
*** Electron-electron-nucleus Jastrow $f_{een}$ derivative
2023-03-30 12:34:17 +02:00
Calculate the electron-electron-nuclear three-body jastrow component ~factor_een_deriv_e~
using the above prepared tables.
2023-03-30 12:34:17 +02:00
TODO: write equations.
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
**** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_factor_een_deriv_e(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const factor_een_deriv_e,
const int64_t size_max);
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2022-02-14 19:11:37 +01:00
qmckl_exit_code
2023-03-30 17:07:11 +02:00
qmckl_get_jastrow_champ_factor_een_deriv_e(qmckl_context context,
2022-02-14 19:11:37 +01:00
double* const factor_een_deriv_e,
const int64_t size_max)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
2023-03-31 13:37:35 +02:00
rc = qmckl_provide_jastrow_champ_factor_een_deriv_e(context);
if (rc != QMCKL_SUCCESS) return rc;
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2022-08-07 14:57:10 +02:00
int64_t sze = ctx->electron.walker.num * 4 * ctx->electron.num;
2022-02-14 19:11:37 +01:00
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
2023-03-30 17:07:11 +02:00
"qmckl_get_jastrow_champ_factor_een_deriv_e",
2022-02-14 19:11:37 +01:00
"Array too small. Expected 4*walk_num*elec_num");
}
2023-03-30 17:07:11 +02:00
memcpy(factor_een_deriv_e, ctx->jastrow_champ.factor_een_deriv_e, sze*sizeof(double));
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_factor_een_deriv_e(qmckl_context context);
2023-03-30 12:34:17 +02:00
#+end_src
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_provide_jastrow_champ_factor_een_deriv_e(qmckl_context context)
{
qmckl_exit_code rc;
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
/* Check if en rescaled distance is provided */
rc = qmckl_provide_een_rescaled_e(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Check if en rescaled distance derivatives is provided */
rc = qmckl_provide_een_rescaled_n(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Check if en rescaled distance is provided */
rc = qmckl_provide_een_rescaled_e_deriv_e(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Check if en rescaled distance derivatives is provided */
rc = qmckl_provide_een_rescaled_n_deriv_e(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Check if en rescaled distance derivatives is provided */
2023-03-30 17:07:11 +02:00
rc = qmckl_provide_jastrow_champ_c_vector_full(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Check if en rescaled distance derivatives is provided */
rc = qmckl_provide_lkpm_combined_index(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Check if tmp_c is provided */
rc = qmckl_provide_tmp_c(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Check if dtmp_c is provided */
rc = qmckl_provide_dtmp_c(context);
if(rc != QMCKL_SUCCESS) return rc;
/* Compute if necessary */
2023-03-30 17:07:11 +02:00
if (ctx->date > ctx->jastrow_champ.factor_een_deriv_e_date) {
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.factor_een_deriv_e != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.factor_een_deriv_e);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
2023-03-31 13:37:35 +02:00
"qmckl_provide_jastrow_champ_factor_een_deriv_e",
2023-03-30 17:07:11 +02:00
"Unable to free ctx->jastrow_champ.factor_een_deriv_e");
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_een_deriv_e = NULL;
}
2022-08-07 14:57:10 +02:00
}
/* Allocate array */
2023-03-30 17:07:11 +02:00
if (ctx->jastrow_champ.factor_een_deriv_e == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
2022-08-07 14:57:10 +02:00
mem_info.size = 4 * ctx->electron.num * ctx->electron.walker.num * sizeof(double);
double* factor_een_deriv_e = (double*) qmckl_malloc(context, mem_info);
if (factor_een_deriv_e == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
2023-03-31 13:37:35 +02:00
"qmckl_provide_jastrow_champ_factor_een_deriv_e",
NULL);
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_een_deriv_e = factor_een_deriv_e;
}
2022-01-31 16:47:28 +01:00
2023-03-31 13:37:35 +02:00
rc = qmckl_compute_jastrow_champ_factor_een_deriv_e(context,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
2022-04-05 11:44:17 +02:00
ctx->electron.num,
ctx->nucleus.num,
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.cord_num,
ctx->jastrow_champ.dim_c_vector,
ctx->jastrow_champ.c_vector_full,
ctx->jastrow_champ.lkpm_combined_index,
ctx->jastrow_champ.tmp_c,
ctx->jastrow_champ.dtmp_c,
ctx->jastrow_champ.een_rescaled_n,
ctx->jastrow_champ.een_rescaled_n_deriv_e,
ctx->jastrow_champ.factor_een_deriv_e);
if (rc != QMCKL_SUCCESS) {
return rc;
}
2023-03-30 17:07:11 +02:00
ctx->jastrow_champ.factor_een_deriv_e_date = ctx->date;
}
return QMCKL_SUCCESS;
}
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute Naive
:PROPERTIES:
2023-03-31 13:37:35 +02:00
:Name: qmckl_compute_jastrow_champ_factor_een_deriv_e_naive
2023-03-30 12:34:17 +02:00
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_een_deriv_e_naive_args
| Variable | Type | In/Out | Description |
|--------------------------+-------------------------------------------------------+--------+--------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
2023-03-30 18:17:33 +02:00
| ~nucl_num~ | ~int64_t~ | in | Number of nuclei |
2023-03-30 12:34:17 +02:00
| ~cord_num~ | ~int64_t~ | in | order of polynomials |
2023-03-30 18:17:33 +02:00
| ~dim_c_vector~ | ~int64_t~ | in | dimension of full coefficient vector |
| ~c_vector_full~ | ~double[dim_c_vector][nucl_num]~ | in | full coefficient vector |
| ~lkpm_combined_index~ | ~int64_t[4][dim_c_vector]~ | in | combined indices |
2023-03-30 12:34:17 +02:00
| ~een_rescaled_e~ | ~double[walk_num][elec_num][elec_num][0:cord_num]~ | in | Electron-nucleus rescaled |
| ~een_rescaled_n~ | ~double[walk_num][elec_num][nucl_num][0:cord_num]~ | in | Electron-nucleus rescaled factor |
| ~een_rescaled_e_deriv_e~ | ~double[walk_num][elec_num][4][elec_num][0:cord_num]~ | in | Electron-nucleus rescaled |
| ~een_rescaled_n_deriv_e~ | ~double[walk_num][elec_num][4][nucl_num][0:cord_num]~ | in | Electron-nucleus rescaled factor |
| ~factor_een_deriv_e~ | ~double[walk_num][4][elec_num]~ | out | Electron-nucleus jastrow |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
2023-03-31 13:37:35 +02:00
integer function qmckl_compute_jastrow_champ_factor_een_deriv_e_naive_f( &
2022-11-16 11:58:44 +01:00
context, walk_num, elec_num, nucl_num, cord_num, dim_c_vector, &
c_vector_full, lkpm_combined_index, een_rescaled_e, een_rescaled_n, &
2022-04-04 23:53:58 +02:00
een_rescaled_e_deriv_e, een_rescaled_n_deriv_e, factor_een_deriv_e)&
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
2022-11-16 11:58:44 +01:00
integer*8 , intent(in) :: walk_num, elec_num, cord_num, nucl_num, dim_c_vector
integer*8 , intent(in) :: lkpm_combined_index(dim_c_vector, 4)
double precision , intent(in) :: c_vector_full(nucl_num, dim_c_vector)
double precision , intent(in) :: een_rescaled_e(0:cord_num, elec_num, elec_num, walk_num)
double precision , intent(in) :: een_rescaled_n(0:cord_num, nucl_num, elec_num, walk_num)
double precision , intent(in) :: een_rescaled_e_deriv_e(0:cord_num, elec_num, 4, elec_num, walk_num)
double precision , intent(in) :: een_rescaled_n_deriv_e(0:cord_num, nucl_num, 4, elec_num, walk_num)
double precision , intent(out) :: factor_een_deriv_e(elec_num, 4, walk_num)
integer*8 :: i, a, j, l, k, p, m, n, nw
double precision :: accu, accu2, cn
double precision :: daccu(1:4), daccu2(1:4)
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
2022-11-16 17:54:59 +01:00
if (cord_num < 0) then
info = QMCKL_INVALID_ARG_5
return
endif
factor_een_deriv_e = 0.0d0
2022-01-31 16:47:28 +01:00
do nw =1, walk_num
2022-11-16 11:58:44 +01:00
do n = 1, dim_c_vector
2022-01-31 16:47:28 +01:00
l = lkpm_combined_index(n, 1)
k = lkpm_combined_index(n, 2)
p = lkpm_combined_index(n, 3)
m = lkpm_combined_index(n, 4)
do a = 1, nucl_num
2022-11-16 11:58:44 +01:00
cn = c_vector_full(a, n)
do j = 1, elec_num
accu = 0.0d0
accu2 = 0.0d0
daccu = 0.0d0
daccu2 = 0.0d0
do i = 1, elec_num
accu = accu + een_rescaled_e(k, i, j, nw) * &
een_rescaled_n(m, a, i, nw)
accu2 = accu2 + een_rescaled_e(k, i, j, nw) * &
een_rescaled_n(m + l, a, i, nw)
daccu(1:4) = daccu(1:4) + een_rescaled_e_deriv_e(k, j, 1:4, i, nw) * &
een_rescaled_n(m, a, i, nw)
daccu2(1:4) = daccu2(1:4) + een_rescaled_e_deriv_e(k, j, 1:4, i, nw) * &
een_rescaled_n(m + l, a, i, nw)
end do
factor_een_deriv_e(j, 1:4, nw) = factor_een_deriv_e(j, 1:4, nw) + &
(accu * een_rescaled_n_deriv_e(m + l, a, 1:4, j, nw) &
+ daccu(1:4) * een_rescaled_n(m + l, a, j, nw) &
+ daccu2(1:4) * een_rescaled_n(m, a, j, nw) &
+ accu2 * een_rescaled_n_deriv_e(m, a, 1:4, j, nw)) * cn
factor_een_deriv_e(j, 4, nw) = factor_een_deriv_e(j, 4, nw) + 2.0d0 * ( &
daccu (1) * een_rescaled_n_deriv_e(m + l, a, 1, j, nw) + &
daccu (2) * een_rescaled_n_deriv_e(m + l, a, 2, j, nw) + &
daccu (3) * een_rescaled_n_deriv_e(m + l, a, 3, j, nw) + &
daccu2(1) * een_rescaled_n_deriv_e(m, a, 1, j, nw ) + &
daccu2(2) * een_rescaled_n_deriv_e(m, a, 2, j, nw ) + &
daccu2(3) * een_rescaled_n_deriv_e(m, a, 3, j, nw ) ) * cn
2022-01-31 16:47:28 +01:00
end do
end do
end do
end do
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_een_deriv_e_naive_f
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
# #+CALL: generate_c_header(table=qmckl_factor_een_deriv_e_naive_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2023-03-31 13:37:35 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_factor_een_deriv_e_naive (
2022-04-06 10:42:00 +02:00
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t cord_num,
2022-11-16 11:58:44 +01:00
const int64_t dim_c_vector,
const double* c_vector_full,
2022-04-06 10:42:00 +02:00
const int64_t* lkpm_combined_index,
const double* een_rescaled_e,
const double* een_rescaled_n,
const double* een_rescaled_e_deriv_e,
const double* een_rescaled_n_deriv_e,
double* const factor_een_deriv_e );
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+CALL: generate_c_interface(table=qmckl_factor_een_deriv_e_naive_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
2023-03-31 13:37:35 +02:00
integer(c_int32_t) function qmckl_compute_jastrow_champ_factor_een_deriv_e_naive &
2022-04-06 10:42:00 +02:00
(context, &
walk_num, &
elec_num, &
nucl_num, &
cord_num, &
2022-11-16 11:58:44 +01:00
dim_c_vector, &
c_vector_full, &
2022-04-06 10:42:00 +02:00
lkpm_combined_index, &
een_rescaled_e, &
een_rescaled_n, &
een_rescaled_e_deriv_e, &
een_rescaled_n_deriv_e, &
factor_een_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
2022-11-16 11:58:44 +01:00
integer (c_int64_t) , intent(in) , value :: dim_c_vector
real (c_double ) , intent(in) :: c_vector_full(nucl_num,dim_c_vector)
integer (c_int64_t) , intent(in) :: lkpm_combined_index(dim_c_vector,4)
real (c_double ) , intent(in) :: een_rescaled_e(0:cord_num,elec_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(in) :: een_rescaled_e_deriv_e(0:cord_num,elec_num,4,elec_num,walk_num)
real (c_double ) , intent(in) :: een_rescaled_n_deriv_e(0:cord_num,nucl_num,4,elec_num,walk_num)
real (c_double ) , intent(out) :: factor_een_deriv_e(elec_num,4,walk_num)
2023-03-31 13:37:35 +02:00
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_factor_een_deriv_e_naive_f
info = qmckl_compute_jastrow_champ_factor_een_deriv_e_naive_f &
2022-04-06 10:42:00 +02:00
(context, &
walk_num, &
elec_num, &
nucl_num, &
cord_num, &
2022-11-16 11:58:44 +01:00
dim_c_vector, &
c_vector_full, &
2022-04-06 10:42:00 +02:00
lkpm_combined_index, &
een_rescaled_e, &
een_rescaled_n, &
een_rescaled_e_deriv_e, &
een_rescaled_n_deriv_e, &
factor_een_deriv_e)
2023-03-31 13:37:35 +02:00
end function qmckl_compute_jastrow_champ_factor_een_deriv_e_naive
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
**** Compute
:PROPERTIES:
2023-03-31 13:37:35 +02:00
:Name: qmckl_compute_jastrow_champ_factor_een_deriv_e
2023-03-30 12:34:17 +02:00
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_factor_een_deriv_e_args
| Variable | Type | In/Out | Description |
|--------------------------+---------------------------------------------------------------------+--------+------------------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
2023-03-30 18:17:33 +02:00
| ~nucl_num~ | ~int64_t~ | in | Number of nuclei |
2023-03-30 12:34:17 +02:00
| ~cord_num~ | ~int64_t~ | in | order of polynomials |
2023-03-30 18:17:33 +02:00
| ~dim_c_vector~ | ~int64_t~ | in | dimension of full coefficient vector |
| ~c_vector_full~ | ~double[dim_c_vector][nucl_num]~ | in | full coefficient vector |
| ~lkpm_combined_index~ | ~int64_t[4][dim_c_vector]~ | in | combined indices |
2023-03-30 12:34:17 +02:00
| ~tmp_c~ | ~double[walk_num][0:cord_num-1][0:cord_num][nucl_num][elec_num]~ | in | Temporary intermediate tensor |
| ~dtmp_c~ | ~double[walk_num][0:cord_num-1][0:cord_num][nucl_num][4][elec_num]~ | in | vector of non-zero coefficients |
| ~een_rescaled_n~ | ~double[walk_num][0:cord_num][nucl_num][elec_num]~ | in | Electron-nucleus rescaled factor |
| ~een_rescaled_n_deriv_e~ | ~double[walk_num][0:cord_num][nucl_num][4][elec_num]~ | in | Derivative of Electron-nucleus rescaled factor |
| ~factor_een_deriv_e~ | ~double[walk_num][4][elec_num]~ | out | Derivative of Electron-nucleus jastrow |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_jastrow_champ_factor_een_deriv_e_doc_f( &
2022-04-04 23:53:58 +02:00
context, walk_num, elec_num, nucl_num, &
2022-11-16 11:58:44 +01:00
cord_num, dim_c_vector, c_vector_full, lkpm_combined_index, &
2022-04-04 23:53:58 +02:00
tmp_c, dtmp_c, een_rescaled_n, een_rescaled_n_deriv_e, factor_een_deriv_e)&
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
2022-11-16 11:58:44 +01:00
integer*8 , intent(in) :: walk_num, elec_num, cord_num, nucl_num, dim_c_vector
integer*8 , intent(in) :: lkpm_combined_index(dim_c_vector,4)
double precision , intent(in) :: c_vector_full(nucl_num, dim_c_vector)
double precision , intent(in) :: tmp_c(elec_num, nucl_num,0:cord_num, 0:cord_num-1, walk_num)
double precision , intent(in) :: dtmp_c(elec_num, 4, nucl_num,0:cord_num, 0:cord_num-1, walk_num)
2022-02-11 17:19:36 +01:00
double precision , intent(in) :: een_rescaled_n(elec_num, nucl_num, 0:cord_num, walk_num)
2022-02-11 17:30:15 +01:00
double precision , intent(in) :: een_rescaled_n_deriv_e(elec_num, 4, nucl_num, 0:cord_num, walk_num)
double precision , intent(out) :: factor_een_deriv_e(elec_num,4,walk_num)
integer*8 :: i, a, j, l, k, m, n, nw, ii
double precision :: accu, accu2, cn
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
2022-11-16 17:54:59 +01:00
if (cord_num < 0) then
info = QMCKL_INVALID_ARG_5
return
endif
factor_een_deriv_e = 0.0d0
do nw =1, walk_num
do n = 1, dim_c_vector
l = lkpm_combined_index(n, 1)
k = lkpm_combined_index(n, 2)
m = lkpm_combined_index(n, 4)
do a = 1, nucl_num
cn = c_vector_full(a, n)
if(cn == 0.d0) cycle
do ii = 1, 4
do j = 1, elec_num
factor_een_deriv_e(j,ii,nw) = factor_een_deriv_e(j,ii,nw) + ( &
tmp_c(j,a,m,k,nw) * een_rescaled_n_deriv_e(j,ii,a,m+l,nw) + &
(dtmp_c(j,ii,a,m,k,nw)) * een_rescaled_n(j,a,m+l,nw) + &
(dtmp_c(j,ii,a,m+l,k,nw)) * een_rescaled_n(j,a,m ,nw) + &
tmp_c(j,a,m+l,k,nw) * een_rescaled_n_deriv_e(j,ii,a,m,nw) &
) * cn
end do
end do
cn = cn + cn
do j = 1, elec_num
factor_een_deriv_e(j,4,nw) = factor_een_deriv_e(j,4,nw) + ( &
(dtmp_c(j,1,a,m ,k,nw)) * een_rescaled_n_deriv_e(j,1,a,m+l,nw) + &
(dtmp_c(j,2,a,m ,k,nw)) * een_rescaled_n_deriv_e(j,2,a,m+l,nw) + &
(dtmp_c(j,3,a,m ,k,nw)) * een_rescaled_n_deriv_e(j,3,a,m+l,nw) + &
(dtmp_c(j,1,a,m+l,k,nw)) * een_rescaled_n_deriv_e(j,1,a,m ,nw) + &
(dtmp_c(j,2,a,m+l,k,nw)) * een_rescaled_n_deriv_e(j,2,a,m ,nw) + &
(dtmp_c(j,3,a,m+l,k,nw)) * een_rescaled_n_deriv_e(j,3,a,m ,nw) &
) * cn
end do
end do
end do
end do
end function qmckl_compute_jastrow_champ_factor_een_deriv_e_doc_f
2023-03-30 12:34:17 +02:00
#+end_src
#+CALL: generate_private_c_header(table=qmckl_factor_een_deriv_e_args,rettyp=get_value("CRetType"),fname="qmckl_compute_jastrow_champ_factor_een_deriv_e_doc" )
#+RESULTS:
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_jastrow_champ_factor_een_deriv_e_doc (
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 int64_t dim_c_vector,
const double* c_vector_full,
const int64_t* lkpm_combined_index,
const double* tmp_c,
const double* dtmp_c,
const double* een_rescaled_n,
const double* een_rescaled_n_deriv_e,
double* const factor_een_deriv_e );
#+end_src
#+CALL: generate_c_interface(table=qmckl_factor_een_deriv_e_args,rettyp=get_value("CRetType"),fname="qmckl_compute_jastrow_champ_factor_een_deriv_e_doc"))
2023-03-30 12:34:17 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_jastrow_champ_factor_een_deriv_e_doc &
(context, &
walk_num, &
elec_num, &
nucl_num, &
cord_num, &
dim_c_vector, &
c_vector_full, &
lkpm_combined_index, &
tmp_c, &
dtmp_c, &
een_rescaled_n, &
een_rescaled_n_deriv_e, &
factor_een_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
integer (c_int64_t) , intent(in) , value :: dim_c_vector
real (c_double ) , intent(in) :: c_vector_full(nucl_num,dim_c_vector)
integer (c_int64_t) , intent(in) :: lkpm_combined_index(dim_c_vector,4)
real (c_double ) , intent(in) :: tmp_c(elec_num,nucl_num,0:cord_num,0:cord_num-1,walk_num)
real (c_double ) , intent(in) :: dtmp_c(elec_num,4,nucl_num,0:cord_num,0:cord_num-1,walk_num)
real (c_double ) , intent(in) :: een_rescaled_n(elec_num,nucl_num,0:cord_num,walk_num)
real (c_double ) , intent(in) :: een_rescaled_n_deriv_e(elec_num,4,nucl_num,0:cord_num,walk_num)
real (c_double ) , intent(out) :: factor_een_deriv_e(elec_num,4,walk_num)
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_factor_een_deriv_e_doc_f
info = qmckl_compute_jastrow_champ_factor_een_deriv_e_doc_f &
(context, &
walk_num, &
elec_num, &
nucl_num, &
cord_num, &
dim_c_vector, &
c_vector_full, &
lkpm_combined_index, &
tmp_c, &
dtmp_c, &
een_rescaled_n, &
een_rescaled_n_deriv_e, &
factor_een_deriv_e)
end function qmckl_compute_jastrow_champ_factor_een_deriv_e_doc
#+end_src
#+CALL: generate_private_c_header(table=qmckl_factor_een_deriv_e_args,rettyp=get_value("CRetType"),fname="qmckl_compute_jastrow_champ_factor_een_deriv_e" )
#+RESULTS:
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_jastrow_champ_factor_een_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 int64_t dim_c_vector,
const double* c_vector_full,
const int64_t* lkpm_combined_index,
const double* tmp_c,
const double* dtmp_c,
const double* een_rescaled_n,
const double* een_rescaled_n_deriv_e,
double* const factor_een_deriv_e );
#+end_src
#+begin_src c :tangle (eval c) :comments org
qmckl_exit_code
qmckl_compute_jastrow_champ_factor_een_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 int64_t dim_c_vector,
const double *c_vector_full,
const int64_t *lkpm_combined_index,
const double *tmp_c,
const double *dtmp_c,
const double *een_rescaled_n,
const double *een_rescaled_n_deriv_e,
2023-04-11 18:51:05 +02:00
double* const factor_een_deriv_e)
{
#ifdef HAVE_HPC
return qmckl_compute_jastrow_champ_factor_een_deriv_e_hpc(context, walk_num, elec_num, nucl_num,
cord_num, dim_c_vector, c_vector_full,
lkpm_combined_index, tmp_c, dtmp_c,
een_rescaled_n, een_rescaled_n_deriv_e,
factor_een_deriv_e);
#else
return qmckl_compute_jastrow_champ_factor_een_deriv_e_doc(context, walk_num, elec_num, nucl_num,
cord_num, dim_c_vector, c_vector_full,
lkpm_combined_index, tmp_c, dtmp_c,
een_rescaled_n, een_rescaled_n_deriv_e,
factor_een_deriv_e);
#endif
}
#+end_src
***** HPC implementation :noexport:
#+CALL: generate_private_c_header(table=qmckl_factor_een_deriv_e_args,rettyp=get_value("CRetType"),fname="qmckl_compute_jastrow_champ_factor_een_deriv_e_hpc" )
#+RESULTS:
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code
qmckl_compute_jastrow_champ_factor_een_deriv_e_hpc (
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 int64_t dim_c_vector,
const double* c_vector_full,
const int64_t* lkpm_combined_index,
const double* tmp_c,
const double* dtmp_c,
const double* een_rescaled_n,
const double* een_rescaled_n_deriv_e,
double* const factor_een_deriv_e );
#+end_src
#+begin_src c :tangle (eval c) :comments org
qmckl_exit_code
qmckl_compute_jastrow_champ_factor_een_deriv_e_hpc(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 int64_t dim_c_vector,
const double *c_vector_full,
const int64_t *lkpm_combined_index,
const double *tmp_c,
const double *dtmp_c,
const double *een_rescaled_n,
const double *een_rescaled_n_deriv_e,
2023-04-11 18:51:05 +02:00
double* const factor_een_deriv_e)
{
int64_t info = QMCKL_SUCCESS;
if (context == QMCKL_NULL_CONTEXT) return QMCKL_INVALID_CONTEXT;
if (walk_num <= 0) return QMCKL_INVALID_ARG_2;
if (elec_num <= 0) return QMCKL_INVALID_ARG_3;
if (nucl_num <= 0) return QMCKL_INVALID_ARG_4;
if (cord_num < 0) return QMCKL_INVALID_ARG_5;
2023-04-11 18:51:05 +02:00
memset(factor_een_deriv_e, 0, elec_num*4*walk_num*sizeof(double));
2023-04-11 18:51:05 +02:00
const size_t elec_num2 = elec_num << 1;
const size_t elec_num3 = elec_num * 3;
2022-02-14 19:11:37 +01:00
#ifdef HAVE_OPENMP
2023-04-11 18:51:05 +02:00
#pragma omp parallel for schedule(dynamic)
#endif
2023-04-11 18:51:05 +02:00
for (size_t nw = 0; nw < (size_t) walk_num; ++nw) {
double* const restrict factor_een_deriv_e_0nw = &(factor_een_deriv_e[elec_num*4*nw]);
for (size_t n = 0; n < (size_t) dim_c_vector; ++n) {
const size_t l = lkpm_combined_index[n];
const size_t k = lkpm_combined_index[n+ dim_c_vector];
const size_t m = lkpm_combined_index[n+3*dim_c_vector];
const size_t en = elec_num*nucl_num;
const size_t len = l*en;
const size_t len4 = len << 2;
const size_t cn = cord_num*nw;
const size_t c1 = cord_num+1;
const size_t addr0 = en*(m+c1*(k+cn));
const size_t addr1 = en*(m+cn);
const double* restrict tmp_c_mkn = &(tmp_c[addr0]);
const double* restrict tmp_c_mlkn = tmp_c_mkn + len;
const double* restrict een_rescaled_n_mnw = &(een_rescaled_n[addr1]);
const double* restrict een_rescaled_n_mlnw = een_rescaled_n_mnw + len;
const double* restrict dtmp_c_mknw = &(dtmp_c[addr0 << 2]);
const double* restrict dtmp_c_mlknw = dtmp_c_mknw + len4;
const double* restrict een_rescaled_n_deriv_e_mnw = &(een_rescaled_n_deriv_e[addr1 << 2]);
const double* restrict een_rescaled_n_deriv_e_mlnw = een_rescaled_n_deriv_e_mnw + len4;
for (size_t a = 0; a < (size_t) nucl_num; a++) {
double cn = c_vector_full[a+n*nucl_num];
if (cn == 0.0) continue;
2023-04-11 18:51:05 +02:00
const size_t ishift = elec_num*a;
const size_t ishift4 = ishift << 2;
const double* restrict tmp_c_amlkn = tmp_c_mlkn + ishift;
const double* restrict tmp_c_amkn = tmp_c_mkn + ishift;
const double* restrict een_rescaled_n_amnw = een_rescaled_n_mnw + ishift;
const double* restrict een_rescaled_n_amlnw = een_rescaled_n_mlnw + ishift;
const double* restrict dtmp_c_0amknw = dtmp_c_mknw + ishift4;
const double* restrict dtmp_c_0amlknw = dtmp_c_mlknw + ishift4;
const double* restrict een_rescaled_n_deriv_e_0amnw = een_rescaled_n_deriv_e_mnw + ishift4;
const double* restrict een_rescaled_n_deriv_e_0amlnw = een_rescaled_n_deriv_e_mlnw + ishift4;
const double* restrict dtmp_c_1amknw = dtmp_c_0amknw + elec_num;
const double* restrict dtmp_c_1amlknw = dtmp_c_0amlknw + elec_num;
const double* restrict dtmp_c_2amknw = dtmp_c_0amknw + elec_num2;
const double* restrict dtmp_c_2amlknw = dtmp_c_0amlknw + elec_num2;
const double* restrict dtmp_c_3amknw = dtmp_c_0amknw + elec_num3;
const double* restrict dtmp_c_3amlknw = dtmp_c_0amlknw + elec_num3;
const double* restrict een_rescaled_n_deriv_e_1amnw = een_rescaled_n_deriv_e_0amnw + elec_num;
const double* restrict een_rescaled_n_deriv_e_1amlnw = een_rescaled_n_deriv_e_0amlnw + elec_num;
const double* restrict een_rescaled_n_deriv_e_2amnw = een_rescaled_n_deriv_e_0amnw + elec_num2;
const double* restrict een_rescaled_n_deriv_e_2amlnw = een_rescaled_n_deriv_e_0amlnw + elec_num2;
const double* restrict een_rescaled_n_deriv_e_3amnw = een_rescaled_n_deriv_e_0amnw + elec_num3;
const double* restrict een_rescaled_n_deriv_e_3amlnw = een_rescaled_n_deriv_e_0amlnw + elec_num3;
double* const restrict factor_een_deriv_e_1nw = factor_een_deriv_e_0nw + elec_num;
double* const restrict factor_een_deriv_e_2nw = factor_een_deriv_e_0nw + elec_num2;
double* const restrict factor_een_deriv_e_3nw = factor_een_deriv_e_0nw + elec_num3;
double tmp3[elec_num];
for (size_t j = 0; j < (size_t) elec_num; ++j) {
factor_een_deriv_e_0nw[j] += cn *
(tmp_c_amkn[j] * een_rescaled_n_deriv_e_0amlnw[j] +
dtmp_c_0amknw[j] * een_rescaled_n_amlnw[j] +
dtmp_c_0amlknw[j] * een_rescaled_n_amnw[j] +
tmp_c_amlkn[j] * een_rescaled_n_deriv_e_0amnw[j]);
tmp3[j] =
dtmp_c_0amknw[j] * een_rescaled_n_deriv_e_0amlnw[j] +
dtmp_c_0amlknw[j] * een_rescaled_n_deriv_e_0amnw[j];
}
2023-04-11 18:51:05 +02:00
for (size_t j = 0; j < (size_t) elec_num; ++j) {
factor_een_deriv_e_1nw[j] += cn *
(tmp_c_amkn[j] * een_rescaled_n_deriv_e_1amlnw[j] +
dtmp_c_1amknw[j] * een_rescaled_n_amlnw[j] +
dtmp_c_1amlknw[j] * een_rescaled_n_amnw[j] +
tmp_c_amlkn[j] * een_rescaled_n_deriv_e_1amnw[j]);
tmp3[j] +=
dtmp_c_1amknw[j] * een_rescaled_n_deriv_e_1amlnw[j] +
dtmp_c_1amlknw[j] * een_rescaled_n_deriv_e_1amnw[j];
}
2023-04-11 18:51:05 +02:00
for (size_t j = 0; j < (size_t) elec_num; ++j) {
factor_een_deriv_e_2nw[j] += cn *
(tmp_c_amkn[j] * een_rescaled_n_deriv_e_2amlnw[j] +
dtmp_c_2amknw[j] * een_rescaled_n_amlnw[j] +
dtmp_c_2amlknw[j] * een_rescaled_n_amnw[j] +
tmp_c_amlkn[j] * een_rescaled_n_deriv_e_2amnw[j]);
tmp3[j] +=
dtmp_c_2amknw[j] * een_rescaled_n_deriv_e_2amlnw[j] +
dtmp_c_2amlknw[j] * een_rescaled_n_deriv_e_2amnw[j];
}
for (size_t j = 0; j < (size_t) elec_num; ++j) {
factor_een_deriv_e_3nw[j] += cn *
(tmp_c_amkn[j] * een_rescaled_n_deriv_e_3amlnw[j] +
dtmp_c_3amknw[j] * een_rescaled_n_amlnw[j] +
dtmp_c_3amlknw[j] * een_rescaled_n_amnw[j] +
tmp_c_amlkn[j] * een_rescaled_n_deriv_e_3amnw[j] +
tmp3[j]*2.0);
}
2023-04-11 18:51:05 +02:00
}
}
}
return info;
}
#+end_src
2023-03-30 12:34:17 +02:00
**** Test
#+begin_src python :results output :exports none :noweb yes
import numpy as np
<<jastrow_data>>
<<een_e_deriv_e>>
<<helper_funcs>>
kappa = 1.0
factor_een = 0.0
daccu = np.zeros(4, dtype=float)
daccu2 = np.zeros(4, dtype=float)
een_rescaled_e_deriv_e_t = een_rescaled_e_deriv_e.T
print(een_rescaled_e_deriv_e_t.shape)
2022-11-16 11:58:44 +01:00
for n in range(0, dim_c_vector):
l = lkpm_of_cindex[0,n]
k = lkpm_of_cindex[1,n]
m = lkpm_of_cindex[3,n]
for a in range(0, nucl_num):
2022-11-16 11:58:44 +01:00
cn = c_vector_full[a][n]
for j in range(0, elec_num):
accu = 0.0
accu2 = 0.0
daccu = 0.0
daccu2 = 0.0
for i in range(0, elec_num):
accu = accu + een_rescaled_e[i,j,k] * \
een_rescaled_n[a,i,m]
accu2 = accu2 + een_rescaled_e[i,j,k] * \
een_rescaled_n[a,i,m+l]
# daccu[0:4] = daccu[0:4] + een_rescaled_e_deriv_e_t[k,j,0:4,i,k] * \
# een_rescaled_n[a,i,m]
# daccu[0:4] = daccu[0:4] + een_rescaled_e_deriv_e_t[k,j,0:4,i,k] * \
# een_rescaled_n[a,i,m]
accu2 = accu2 + accu * een_rescaled_n[a,j,m+l]
# factor_een = factor_een + accu2 * cn
print("factor_een:",factor_een)
2023-03-30 12:34:17 +02:00
#+end_src
2023-03-30 12:34:17 +02:00
#+RESULTS:
: (6, 10, 4, 10)
: factor_een: 0.0
2022-01-31 16:47:28 +01:00
2023-03-30 12:34:17 +02:00
#+begin_src c :tangle (eval c_test)
2021-09-21 12:05:03 +02:00
/* Check if Jastrow is properly initialized */
2023-03-30 17:07:11 +02:00
assert(qmckl_jastrow_champ_provided(context));
2021-09-21 12:05:03 +02:00
2022-02-14 19:11:37 +01:00
double factor_een_deriv_e[4][walk_num][elec_num];
2023-03-30 17:07:11 +02:00
rc = qmckl_get_jastrow_champ_factor_een_deriv_e(context, &(factor_een_deriv_e[0][0][0]),4*walk_num*elec_num);
2021-07-07 10:36:18 +02:00
printf("%20.15e\n", factor_een_deriv_e[0][0][0]);
assert(fabs(factor_een_deriv_e[0][0][0] - (-5.481671107220383e-04)) < 1e-12);
printf("%20.15e\n", factor_een_deriv_e[1][0][1]);
assert(fabs(factor_een_deriv_e[1][0][1] - (-5.402107832095666e-02)) < 1e-12);
printf("%20.15e\n", factor_een_deriv_e[2][0][2]);
assert(fabs(factor_een_deriv_e[2][0][2] - (-1.648945927082279e-01)) < 1e-12);
printf("%20.15e\n", factor_een_deriv_e[3][0][3]);
assert(fabs(factor_een_deriv_e[3][0][3] - (-1.269746119491287e+00)) < 1e-12);
2023-03-30 12:34:17 +02:00
#+end_src
2022-11-16 17:54:59 +01:00
2023-03-31 13:37:35 +02:00
** Total Jastrow
2023-03-31 14:41:32 +02:00
2023-03-31 13:37:35 +02:00
*** Value
Value of the total Jastrow factor: $\exp(J)$
**** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
qmckl_exit_code
qmckl_get_jastrow_champ_value(qmckl_context context,
double* const value,
const int64_t size_max);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code
qmckl_get_jastrow_champ_value(qmckl_context context,
double* const value,
const int64_t size_max)
{
qmckl_exit_code rc;
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
"qmckl_get_jastrow_champ_value",
NULL);
}
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2023-03-30 18:17:33 +02:00
2023-03-31 13:37:35 +02:00
rc = qmckl_provide_jastrow_champ_value(context);
if (rc != QMCKL_SUCCESS) return rc;
int64_t sze=ctx->electron.walker.num;
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
"qmckl_get_jastrow_champ_value",
"Array too small. Expected walker.num");
}
memcpy(value, ctx->jastrow_champ.value, sze*sizeof(double));
return QMCKL_SUCCESS;
}
#+end_src
***** Fortran interface
#+begin_src f90 :tangle (eval fh_func) :comments org
interface
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_value (context, &
value, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: value(size_max)
end function qmckl_get_jastrow_champ_value
end interface
#+end_src
**** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_provide_jastrow_champ_value(qmckl_context context);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_provide_jastrow_champ_value(qmckl_context context)
{
qmckl_exit_code rc;
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
"qmckl_provide_jastrow_champ_value",
NULL);
}
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
if (!ctx->jastrow_champ.provided) {
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
"qmckl_provide_jastrow_champ_value",
NULL);
}
rc = qmckl_provide_jastrow_champ_factor_ee(context);
if (rc != QMCKL_SUCCESS) return rc;
rc = qmckl_provide_jastrow_champ_factor_en(context);
if (rc != QMCKL_SUCCESS) return rc;
rc = qmckl_provide_jastrow_champ_factor_een(context);
if (rc != QMCKL_SUCCESS) return rc;
/* Compute if necessary */
if (ctx->date > ctx->jastrow_champ.value_date) {
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
if (ctx->jastrow_champ.value != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.value);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
"qmckl_provide_jastrow_champ_value",
"Unable to free ctx->jastrow_champ.value");
}
ctx->jastrow_champ.value = NULL;
}
}
/* Allocate array */
if (ctx->jastrow_champ.value == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = ctx->electron.walker.num * sizeof(double);
double* value = (double*) qmckl_malloc(context, mem_info);
if (value == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_provide_jastrow_champ_value",
NULL);
}
ctx->jastrow_champ.value = value;
}
rc = qmckl_compute_jastrow_champ_value_doc(context,
ctx->electron.walker.num,
2023-03-31 14:41:32 +02:00
ctx->jastrow_champ.factor_ee,
ctx->jastrow_champ.factor_en,
ctx->jastrow_champ.factor_een,
2023-03-31 13:37:35 +02:00
ctx->jastrow_champ.value);
2023-03-31 14:41:32 +02:00
ctx->jastrow_champ.value_date = ctx->date;
2023-03-31 13:37:35 +02:00
}
return QMCKL_SUCCESS;
}
#+end_src
**** Compute
:PROPERTIES:
:Name: qmckl_compute_jastrow_champ_value_doc
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_jastrow_champ_value_args
| Variable | Type | In/Out | Description |
|------------+--------------------+--------+----------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~f_ee~ | ~double[walk_num]~ | in | ee component |
| ~f_en~ | ~double[walk_num]~ | in | eN component |
| ~f_een~ | ~double[walk_num]~ | in | eeN component |
| ~value~ | ~double[walk_num]~ | out | Total Jastrow factor |
#+CALL: generate_c_interface(table=qmckl_jastrow_champ_value_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_jastrow_champ_value_doc &
(context, walk_num, f_ee, f_en, f_een, value) &
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
real (c_double ) , intent(in) :: f_ee(walk_num)
real (c_double ) , intent(in) :: f_en(walk_num)
real (c_double ) , intent(in) :: f_een(walk_num)
real (c_double ) , intent(out) :: value(walk_num)
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_value_doc_f
info = qmckl_compute_jastrow_champ_value_doc_f &
(context, walk_num, f_ee, f_en, f_een, value)
end function qmckl_compute_jastrow_champ_value_doc
#+end_src
2023-03-30 18:17:33 +02:00
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_jastrow_champ_value_doc_f(context, &
2023-03-31 13:37:35 +02:00
walk_num, f_ee, f_en, f_een, value) &
2023-03-30 18:17:33 +02:00
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
2023-03-31 13:37:35 +02:00
integer*8 , intent(in) :: walk_num
double precision , intent(in) :: f_ee(walk_num), f_en(walk_num), f_een(walk_num)
double precision , intent(out) :: value(walk_num)
2023-03-30 18:17:33 +02:00
2023-03-31 14:41:32 +02:00
integer*8 :: i
2023-03-30 18:17:33 +02:00
2023-03-31 13:37:35 +02:00
info = QMCKL_SUCCESS
2023-03-30 18:17:33 +02:00
2023-03-31 13:37:35 +02:00
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
2023-03-30 18:17:33 +02:00
2023-03-31 13:37:35 +02:00
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
2023-03-30 18:17:33 +02:00
2023-03-31 13:37:35 +02:00
do i = 1, walk_num
value(i) = f_ee(i) + f_en(i) + f_een(i)
end do
2023-03-30 18:17:33 +02:00
2023-03-31 13:37:35 +02:00
do i = 1, walk_num
value(i) = dexp(value(i))
end do
2023-03-30 18:17:33 +02:00
end function qmckl_compute_jastrow_champ_value_doc_f
2023-03-31 13:37:35 +02:00
#+end_src
2023-03-30 18:17:33 +02:00
2023-03-31 14:41:32 +02:00
#+CALL: generate_private_c_header(table=qmckl_jastrow_champ_value_args,rettyp=get_value("CRetType"),fname="qmckl_compute_jastrow_champ_value")
#+RESULTS:
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_jastrow_champ_value (
2023-03-31 13:37:35 +02:00
const qmckl_context context,
const int64_t walk_num,
2023-03-31 14:41:32 +02:00
const double* f_ee,
const double* f_en,
const double* f_een,
double* const value );
#+end_src
2023-03-30 18:17:33 +02:00
2023-03-31 14:41:32 +02:00
#+CALL: generate_private_c_header(table=qmckl_jastrow_champ_value_args,rettyp=get_value("CRetType"),fname="qmckl_compute_jastrow_champ_value_doc")
#+RESULTS:
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_jastrow_champ_value_doc (
2023-03-31 13:37:35 +02:00
const qmckl_context context,
const int64_t walk_num,
2023-03-31 14:41:32 +02:00
const double* f_ee,
const double* f_en,
const double* f_een,
double* const value );
#+end_src
2023-03-30 18:17:33 +02:00
2023-03-31 14:41:32 +02:00
#+CALL: generate_private_c_header(table=qmckl_jastrow_champ_value_args,rettyp=get_value("CRetType"),fname="qmckl_compute_jastrow_champ_value_hpc")
#+RESULTS:
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_jastrow_champ_value_hpc (
2023-03-31 13:37:35 +02:00
const qmckl_context context,
const int64_t walk_num,
2023-03-31 14:41:32 +02:00
const double* f_ee,
const double* f_en,
const double* f_een,
double* const value );
#+end_src
2023-03-30 18:17:33 +02:00
2023-03-31 13:37:35 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
inline qmckl_exit_code
qmckl_compute_jastrow_champ_value_hpc (
const qmckl_context context,
const int64_t walk_num,
const double* factor_ee,
const double* factor_en,
const double* factor_een,
double* const value)
2023-03-31 14:41:32 +02:00
{
2023-03-30 18:17:33 +02:00
2023-03-31 13:37:35 +02:00
if (context == QMCKL_NULL_CONTEXT) return QMCKL_INVALID_CONTEXT;
if (walk_num <= 0 ) return QMCKL_INVALID_ARG_2;
if (factor_ee == NULL ) return QMCKL_INVALID_ARG_3;
if (factor_en == NULL ) return QMCKL_INVALID_ARG_4;
if (factor_een == NULL ) return QMCKL_INVALID_ARG_5;
if (value == NULL ) return QMCKL_INVALID_ARG_6;
for (int64_t i = 0; i < walk_num; ++i) {
value[i] = exp(factor_ee[i] + factor_en[i] + factor_een[i]);
}
2023-03-30 18:17:33 +02:00
2023-03-31 13:37:35 +02:00
return QMCKL_SUCCESS;
}
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes
2023-03-30 18:17:33 +02:00
qmckl_exit_code qmckl_compute_jastrow_champ_value (
2023-03-31 13:37:35 +02:00
const qmckl_context context,
const int64_t walk_num,
const double* factor_ee,
const double* factor_en,
const double* factor_een,
double* const value)
2023-03-30 18:17:33 +02:00
{
2023-03-31 13:37:35 +02:00
#ifdef HAVE_HPC
return qmckl_compute_jastrow_champ_value_hpc (
context, walk_num, factor_ee, factor_en, factor_een, value);
2023-03-30 18:17:33 +02:00
#else
2023-03-31 13:37:35 +02:00
return qmckl_compute_jastrow_champ_value_doc (
context, walk_num, factor_ee, factor_en, factor_een, value);
2023-03-30 18:17:33 +02:00
#endif
}
#+end_src
2023-03-31 13:37:35 +02:00
**** Test
#+begin_src c :tangle (eval c_test)
2023-03-31 14:41:32 +02:00
printf("Total Jastrow value\n");
2023-03-31 13:37:35 +02:00
/* Check if Jastrow is properly initialized */
assert(qmckl_jastrow_champ_provided(context));
rc = qmckl_check(context,
qmckl_get_jastrow_champ_factor_ee(context, &(factor_ee[0]), walk_num)
);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
qmckl_get_jastrow_champ_factor_en(context, &(factor_en[0]), walk_num)
);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
qmckl_get_jastrow_champ_factor_een(context, &(factor_een[0]), walk_num)
);
assert(rc == QMCKL_SUCCESS);
double total_j[walk_num];
rc = qmckl_check(context,
2023-03-31 14:41:32 +02:00
qmckl_get_jastrow_champ_value(context, &(total_j[0]), walk_num)
2023-03-31 13:37:35 +02:00
);
assert(rc == QMCKL_SUCCESS);
for (int64_t i=0 ; i< walk_num ; ++i) {
assert (total_j[i] - exp(factor_ee[i] + factor_en[i] + factor_een[i]) < 1.e-12);
}
2023-03-31 14:41:32 +02:00
#+end_src
*** Derivatives
Gradients and Laplacian of the total Jastrow factor:
\[
\nabla \left[ e^{J(\mathbf{r})} \right] = e^{J(\mathbf{r})} \nabla J(\mathbf{r})
\]
\[
\Delta \left[ e^{J(\mathbf{r})} \right] = e^{J(\mathbf{r})}
\left[ \Delta J(\mathbf{r}) + \nabla J(\mathbf{r}) \cdot \nabla J(\mathbf{r}) \right]
\]
**** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
qmckl_exit_code
qmckl_get_jastrow_champ_gl(qmckl_context context,
double* const gl,
const int64_t size_max);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code
qmckl_get_jastrow_champ_gl(qmckl_context context,
double* const gl,
const int64_t size_max)
{
qmckl_exit_code rc;
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
"qmckl_get_jastrow_champ_gl",
NULL);
}
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
rc = qmckl_provide_jastrow_champ_gl(context);
if (rc != QMCKL_SUCCESS) return rc;
int64_t sze = 4 * ctx->electron.walker.num * ctx->electron.num;
if (size_max < sze) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
"qmckl_get_jastrow_champ_gl",
"Array too small. Expected walker.num * electron.num * 4");
}
memcpy(gl, ctx->jastrow_champ.gl, sze*sizeof(double));
return QMCKL_SUCCESS;
}
#+end_src
***** Fortran interface
#+begin_src f90 :tangle (eval fh_func) :comments org
interface
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_gl (context, &
gl, size_max) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: gl(size_max)
end function qmckl_get_jastrow_champ_gl
end interface
#+end_src
**** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_provide_jastrow_champ_gl(qmckl_context context);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_provide_jastrow_champ_gl(qmckl_context context)
{
qmckl_exit_code rc;
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return qmckl_failwith( context,
QMCKL_INVALID_CONTEXT,
"qmckl_provide_jastrow_champ_gl",
NULL);
}
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
if (!ctx->jastrow_champ.provided) {
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
"qmckl_provide_jastrow_champ_gl",
NULL);
}
rc = qmckl_provide_jastrow_champ_value(context);
if (rc != QMCKL_SUCCESS) return rc;
rc = qmckl_provide_jastrow_champ_factor_ee_deriv_e(context);
if (rc != QMCKL_SUCCESS) return rc;
rc = qmckl_provide_jastrow_champ_factor_en_deriv_e(context);
if (rc != QMCKL_SUCCESS) return rc;
rc = qmckl_provide_jastrow_champ_factor_een_deriv_e(context);
if (rc != QMCKL_SUCCESS) return rc;
/* Compute if necessary */
if (ctx->date > ctx->jastrow_champ.gl_date) {
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
if (ctx->jastrow_champ.gl != NULL) {
rc = qmckl_free(context, ctx->jastrow_champ.gl);
if (rc != QMCKL_SUCCESS) {
return qmckl_failwith( context, rc,
"qmckl_provide_jastrow_champ_gl",
"Unable to free ctx->jastrow_champ.gl");
}
ctx->jastrow_champ.gl = NULL;
}
}
/* Allocate array */
if (ctx->jastrow_champ.gl == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = ctx->electron.walker.num * ctx->electron.num * 4 * sizeof(double);
double* gl = (double*) qmckl_malloc(context, mem_info);
if (gl == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_provide_jastrow_champ_gl",
NULL);
}
ctx->jastrow_champ.gl = gl;
}
rc = qmckl_compute_jastrow_champ_gl_doc(context,
ctx->electron.walker.num,
ctx->electron.num,
ctx->jastrow_champ.value,
ctx->jastrow_champ.factor_ee_deriv_e,
ctx->jastrow_champ.factor_en_deriv_e,
ctx->jastrow_champ.factor_een_deriv_e,
ctx->jastrow_champ.gl);
ctx->jastrow_champ.gl_date = ctx->date;
}
return QMCKL_SUCCESS;
}
#+end_src
**** Compute
:PROPERTIES:
:Name: qmckl_compute_jastrow_champ_gl_doc
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_jastrow_champ_gl_args
| Variable | Type | In/Out | Description |
|------------+---------------------------------+--------+----------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~value~ | ~double[walk_num]~ | in | Total Jastrow |
| ~gl_ee~ | ~double[walk_num][4][elec_num]~ | in | ee component |
| ~gl_en~ | ~double[walk_num][4][elec_num]~ | in | eN component |
| ~gl_een~ | ~double[walk_num][4][elec_num]~ | in | eeN component |
| ~gl~ | ~double[walk_num][4][elec_num]~ | out | Total Jastrow factor |
#+CALL: generate_c_interface(table=qmckl_jastrow_champ_gl_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_jastrow_champ_gl_doc &
(context, walk_num, elec_num, value, gl_ee, gl_en, gl_een, gl) &
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
real (c_double ) , intent(in) :: value(walk_num)
real (c_double ) , intent(in) :: gl_ee(elec_num,4,walk_num)
real (c_double ) , intent(in) :: gl_en(elec_num,4,walk_num)
real (c_double ) , intent(in) :: gl_een(elec_num,4,walk_num)
real (c_double ) , intent(out) :: gl(elec_num,4,walk_num)
integer(c_int32_t), external :: qmckl_compute_jastrow_champ_gl_doc_f
info = qmckl_compute_jastrow_champ_gl_doc_f &
(context, walk_num, elec_num, value, gl_ee, gl_en, gl_een, gl)
end function qmckl_compute_jastrow_champ_gl_doc
#+end_src
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_jastrow_champ_gl_doc_f(context, &
walk_num, elec_num, value, gl_ee, gl_en, gl_een, gl) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: walk_num, elec_num
double precision , intent(in) :: value (walk_num)
double precision , intent(in) :: gl_ee (elec_num,4,walk_num)
double precision , intent(in) :: gl_en (elec_num,4,walk_num)
double precision , intent(in) :: gl_een(elec_num,4,walk_num)
double precision , intent(out) :: gl (elec_num,4,walk_num)
integer*8 :: i, j, k
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
do k = 1, walk_num
do j=1,4
do i = 1, elec_num
gl(i,j,k) = gl_ee(i,j,k) + gl_en(i,j,k) + gl_een(i,j,k)
end do
end do
do i = 1, elec_num
gl(i,4,k) = gl(i,4,k) + &
gl(i,1,k) * gl(i,1,k) + &
gl(i,2,k) * gl(i,2,k) + &
gl(i,3,k) * gl(i,3,k)
end do
gl(:,:,k) = gl(:,:,k) * value(k)
end do
end function qmckl_compute_jastrow_champ_gl_doc_f
#+end_src
#+CALL: generate_private_c_header(table=qmckl_jastrow_champ_gl_args,rettyp=get_value("CRetType"),fname="qmckl_compute_jastrow_champ_gl")
#+RESULTS:
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_jastrow_champ_gl (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const double* value,
const double* gl_ee,
const double* gl_en,
const double* gl_een,
double* const gl );
#+end_src
#+CALL: generate_private_c_header(table=qmckl_jastrow_champ_gl_args,rettyp=get_value("CRetType"),fname="qmckl_compute_jastrow_champ_gl_doc")
#+RESULTS:
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_jastrow_champ_gl_doc (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const double* value,
const double* gl_ee,
const double* gl_en,
const double* gl_een,
double* const gl );
#+end_src
#+CALL: generate_private_c_header(table=qmckl_jastrow_champ_gl_args,rettyp=get_value("CRetType"),fname="qmckl_compute_jastrow_champ_gl_hpc")
#+RESULTS:
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_jastrow_champ_gl_hpc (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const double* value,
const double* gl_ee,
const double* gl_en,
const double* gl_een,
double* const gl );
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
inline qmckl_exit_code
qmckl_compute_jastrow_champ_gl_hpc (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const double* value,
const double* gl_ee,
const double* gl_en,
const double* gl_een,
double* const gl)
{
if (context == QMCKL_NULL_CONTEXT) return QMCKL_INVALID_CONTEXT;
if (walk_num <= 0 ) return QMCKL_INVALID_ARG_2;
if (elec_num <= 0 ) return QMCKL_INVALID_ARG_3;
if (value == NULL ) return QMCKL_INVALID_ARG_4;
if (gl_ee == NULL ) return QMCKL_INVALID_ARG_5;
if (gl_en == NULL ) return QMCKL_INVALID_ARG_6;
if (gl_een == NULL ) return QMCKL_INVALID_ARG_7;
if (gl == NULL ) return QMCKL_INVALID_ARG_8;
for (int64_t k = 0; k < walk_num; ++k) {
for (int64_t j = 0; j < 4; ++j) {
for (int64_t i = 0; i < elec_num; ++i) {
gl[i + elec_num*(j + k*4)] = gl_ee[i + elec_num*(j + k*4)] +
gl_en[i + elec_num*(j + k*4)] + gl_een[i + elec_num*(j + k*4)];
}
}
for (int64_t i = 0; i < elec_num; ++i) {
gl[i + elec_num*(3 + walk_num*4)] +=
gl_ee[i + elec_num*(0 + k*4)] * gl_ee[i + elec_num*(0 + k*4)] +
gl_ee[i + elec_num*(1 + k*4)] * gl_ee[i + elec_num*(1 + k*4)] +
gl_ee[i + elec_num*(2 + k*4)] * gl_ee[i + elec_num*(2 + k*4)];
}
for (int64_t j = 0; j < 4; ++j) {
for (int64_t i = 0; i < elec_num; ++i) {
gl[i + elec_num*(j + k*4)] *= value[k];
}
}
}
return QMCKL_SUCCESS;
}
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes
qmckl_exit_code qmckl_compute_jastrow_champ_gl (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const double* value,
const double* gl_ee,
const double* gl_en,
const double* gl_een,
double* const gl)
{
#ifdef HAVE_HPC
return qmckl_compute_jastrow_champ_gl_hpc (context,
walk_num, elec_num, value, gl_ee, gl_en, gl_een, gl);
#else
return qmckl_compute_jastrow_champ_gl_doc (context,
walk_num, elec_num, value, gl_ee, gl_en, gl_een, gl);
#endif
}
#+end_src
**** Test
#+begin_src c :tangle (eval c_test)
printf("Total Jastrow derivatives\n");
/* Check if Jastrow is properly initialized */
assert(qmckl_jastrow_champ_provided(context));
rc = qmckl_check(context,
qmckl_get_jastrow_champ_factor_ee_deriv_e(context, &(factor_ee_deriv_e[0][0][0]), walk_num*elec_num*4)
);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
qmckl_get_jastrow_champ_factor_en_deriv_e(context, &(factor_en_deriv_e[0][0][0]), walk_num*elec_num*4)
);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
qmckl_get_jastrow_champ_factor_een_deriv_e(context, &(factor_een_deriv_e[0][0][0]), walk_num*elec_num*4)
);
assert(rc == QMCKL_SUCCESS);
double total_j_deriv[walk_num][4][elec_num];
rc = qmckl_check(context,
qmckl_get_jastrow_champ_gl(context, &(total_j_deriv[0][0][0]), walk_num*elec_num*4)
);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_check(context,
qmckl_get_jastrow_champ_value(context, &(total_j[0]), walk_num)
);
assert(rc == QMCKL_SUCCESS);
for (int64_t k=0 ; k< walk_num ; ++k) {
for (int64_t m=0 ; m<4; ++m) {
for (int64_t e=0 ; e<elec_num; ++e) {
if (m < 3) { /* test only gradients */
assert (total_j_deriv[k][m][e]/total_j[k] - (factor_ee_deriv_e[k][m][e] + factor_en_deriv_e[k][m][e] + factor_een_deriv_e[k][m][e]) < 1.e-12);
}
}
}
}
2023-03-31 13:37:35 +02:00
#+end_src
2021-06-23 14:26:01 +02:00
* End of files :noexport:
#+begin_src c :tangle (eval h_private_type)
#endif
#+end_src
2021-10-14 21:40:14 +02:00
#+begin_src c :tangle (eval h_private_func)
#endif
#+end_src
2021-06-23 14:26:01 +02:00
*** Test
#+begin_src c :tangle (eval c_test)
rc = qmckl_context_destroy(context);
2021-06-23 14:26:01 +02:00
assert (rc == QMCKL_SUCCESS);
return 0;
}
#+end_src
# -*- mode: org -*-
# vim: syntax=c