1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-11-03 20:54:09 +01:00
qmckl/org/qmckl_electron.org

2986 lines
101 KiB
Org Mode
Raw Normal View History

2021-04-21 01:56:47 +02:00
#+TITLE: Electrons
2021-04-30 01:26:19 +02:00
#+SETUPFILE: ../tools/theme.setup
2021-04-21 01:56:47 +02:00
#+INCLUDE: ../tools/lib.org
In conventional QMC simulations, up-spin and down-spin electrons are
different. The ~electron~ data structure contains the number of
up-spin and down-spin electrons, and the electron coordinates.
2022-08-07 14:57:10 +02:00
The electrons are stored as points in the following order: for each walker,
first up-spin electrons and then down-spin electrons.
If the points are set with the ='N'= flag, the order of
the components is =[ (x,y,z), (x,y,z), ... ]=
Using the ='T'= flage, it is =[ (x,x,x,...), (y,y,y,...), (z,z,z,...) ]=
# TODO: replace the qmckl_matrix by qmckl_point data structures.
2021-04-21 01:56:47 +02:00
* Headers :noexport:
2021-04-30 01:26:19 +02:00
#+begin_src elisp :noexport :results none
2021-04-21 01:56:47 +02:00
(org-babel-lob-ingest "../tools/lib.org")
#+end_src
#+begin_src c :tangle (eval h_private_type)
#ifndef QMCKL_ELECTRON_HPT
#define QMCKL_ELECTRON_HPT
#include <stdbool.h>
2022-08-07 14:57:10 +02:00
#include "qmckl_point_private_type.h"
2021-04-21 01:56:47 +02:00
#+end_src
2021-10-14 21:40:14 +02:00
#+begin_src c :tangle (eval h_private_func)
#ifndef QMCKL_ELECTRON_HPF
#define QMCKL_ELECTRON_HPF
#+end_src
2021-04-21 01:56:47 +02:00
#+begin_src c :tangle (eval c_test) :noweb yes
#include "qmckl.h"
2021-05-18 12:32:28 +02:00
#include <assert.h>
2022-01-23 16:18:46 +01:00
#include <stdio.h>
2021-05-18 12:32:28 +02:00
#include <math.h>
2021-05-10 10:05:50 +02:00
#ifdef HAVE_CONFIG_H
2021-05-10 10:41:59 +02:00
#include "config.h"
2021-05-09 02:12:38 +02:00
#endif
2021-05-19 00:28:56 +02:00
2021-05-19 01:35:34 +02:00
#include "chbrclf.h"
2021-05-19 00:28:56 +02:00
2021-05-11 16:41:03 +02:00
int main() {
2021-04-21 01:56:47 +02:00
qmckl_context context;
context = qmckl_context_create();
#+end_src
#+begin_src c :tangle (eval c)
2021-05-10 10:05:50 +02:00
#ifdef HAVE_CONFIG_H
2021-05-10 10:41:59 +02:00
#include "config.h"
2021-05-09 02:12:38 +02:00
#endif
2021-05-10 10:05:50 +02:00
#ifdef HAVE_STDINT_H
2021-04-21 01:56:47 +02:00
#include <stdint.h>
2021-05-10 10:05:50 +02:00
#elif HAVE_INTTYPES_H
#include <inttypes.h>
#endif
2021-04-21 01:56:47 +02:00
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
2021-04-26 01:45:25 +02:00
#include <math.h>
#include <stdio.h>
2021-04-21 01:56:47 +02:00
2021-05-11 13:57:23 +02:00
#include "qmckl.h"
2021-04-21 01:56:47 +02:00
#include "qmckl_context_private_type.h"
#include "qmckl_memory_private_type.h"
#include "qmckl_memory_private_func.h"
2021-04-26 01:45:25 +02:00
#include "qmckl_electron_private_func.h"
2021-04-21 01:56:47 +02:00
#+end_src
* Context
The following data stored in the context:
2021-04-30 01:26:19 +02:00
2022-08-07 14:57:10 +02:00
| Variable | Type | Description |
|---------------------------+---------------+---------------------------------------|
| ~uninitialized~ | ~int32_t~ | Keeps bit set for uninitialized data |
| ~num~ | ~int64_t~ | Total number of electrons |
| ~up_num~ | ~int64_t~ | Number of up-spin electrons |
| ~down_num~ | ~int64_t~ | Number of down-spin electrons |
| ~rescale_factor_kappa_ee~ | ~double~ | The distance scaling factor |
| ~rescale_factor_kappa_en~ | ~double~ | The distance scaling factor |
| ~provided~ | ~bool~ | If true, ~electron~ is valid |
| ~walker~ | ~qmckl_point~ | Current set of walkers |
| ~walker_old~ | ~qmckl_point~ | Previous set of walkers |
Computed data:
2022-01-26 17:06:51 +01:00
2022-01-06 02:28:13 +01:00
| Variable | Type | Description |
|-------------------------------------+--------------------------------------+----------------------------------------------------------------------|
2022-08-07 14:57:10 +02:00
| ~ee_distance~ | ~double[walker.num][num][num]~ | Electron-electron distances |
| ~ee_distance_date~ | ~uint64_t~ | Last modification date of the electron-electron distances |
2022-08-07 14:57:10 +02:00
| ~en_distance~ | ~double[walker.num][nucl_num][num]~ | Electron-nucleus distances |
| ~en_distance_date~ | ~uint64_t~ | Last modification date of the electron-electron distances |
2022-08-07 14:57:10 +02:00
| ~ee_distance_rescaled~ | ~double[walker.num][num][num]~ | Electron-electron rescaled distances |
| ~ee_distance_rescaled_date~ | ~uint64_t~ | Last modification date of the electron-electron distances |
2022-08-07 14:57:10 +02:00
| ~ee_distance_rescaled_deriv_e~ | ~double[walker.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 |
2022-08-07 14:57:10 +02:00
| ~ee_potential~ | ~double[walker.num]~ | Electron-electron potential energy |
| ~ee_potential_date~ | ~uint64_t~ | Last modification date of the electron-electron potential |
| ~en_potential~ | ~double[walker.num]~ | Electron-nucleus potential energy |
| ~en_potential_date~ | ~int64_t~ | Date when the electron-nucleus potential energy was computed |
| ~en_distance_rescaled~ | ~double[walker.num][nucl_num][num]~ | Electron-nucleus distances |
| ~en_distance_rescaled_date~ | ~uint64_t~ | Last modification date of the electron-electron distances |
2022-08-07 14:57:10 +02:00
| ~en_distance_rescaled_deriv_e~ | ~double[walker.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 |
2021-04-21 01:56:47 +02:00
** Data structure
#+begin_src c :comments org :tangle (eval h_private_type)
2022-08-07 14:57:10 +02:00
typedef struct qmckl_walker_struct {
int64_t num;
qmckl_point_struct point;
} qmckl_walker;
2021-04-21 01:56:47 +02:00
typedef struct qmckl_electron_struct {
2022-01-26 17:06:51 +01:00
int64_t num;
int64_t up_num;
int64_t down_num;
2022-08-07 14:57:10 +02:00
qmckl_walker walker;
qmckl_walker walker_old;
2022-01-26 17:06:51 +01:00
double rescale_factor_kappa_ee;
double rescale_factor_kappa_en;
2022-08-07 14:57:10 +02:00
uint64_t ee_distance_date;
uint64_t en_distance_date;
uint64_t ee_potential_date;
uint64_t en_potential_date;
uint64_t ee_distance_rescaled_date;
uint64_t ee_distance_rescaled_deriv_e_date;
uint64_t en_distance_rescaled_date;
uint64_t en_distance_rescaled_deriv_e_date;
2022-01-26 17:06:51 +01:00
double* ee_distance;
double* en_distance;
2022-08-07 14:57:10 +02:00
double* ee_potential;
double* en_potential;
2022-01-26 17:06:51 +01:00
double* ee_distance_rescaled;
double* ee_distance_rescaled_deriv_e;
double* en_distance_rescaled;
double* en_distance_rescaled_deriv_e;
int32_t uninitialized;
bool provided;
2021-04-21 01:56:47 +02:00
} qmckl_electron_struct;
2021-06-10 22:57:59 +02:00
2021-04-21 01:56:47 +02:00
#+end_src
The ~uninitialized~ integer contains one bit set to one for each
2021-06-10 22:57:59 +02:00
initialization function which has not been called. It becomes equal
2021-04-21 01:56:47 +02:00
to zero after all initialization functions have been called. The
struct is then initialized and ~provided == true~.
2021-06-10 22:57:59 +02:00
Some values are initialized by default, and are not concerned by
this mechanism.
2022-01-26 17:06:51 +01:00
#+begin_src c :comments org :tangle (eval h_private_func)
2021-06-10 22:57:59 +02:00
qmckl_exit_code qmckl_init_electron(qmckl_context context);
#+end_src
2022-01-26 17:06:51 +01:00
2021-06-10 22:57:59 +02:00
#+begin_src c :comments org :tangle (eval c)
qmckl_exit_code qmckl_init_electron(qmckl_context context) {
2021-04-30 01:26:19 +02:00
2021-06-10 22:57:59 +02:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return false;
}
2021-05-18 12:32:28 +02:00
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-06-10 22:57:59 +02:00
assert (ctx != NULL);
2022-08-07 14:57:10 +02:00
ctx->electron.uninitialized = (1 << 1) - 1;
2021-06-10 22:57:59 +02:00
/* Default values */
ctx->electron.rescale_factor_kappa_ee = 1.0;
ctx->electron.rescale_factor_kappa_en = 1.0;
2021-05-18 12:32:28 +02:00
2021-06-10 22:57:59 +02:00
return QMCKL_SUCCESS;
}
#+end_src
2022-01-26 17:06:51 +01:00
2021-05-18 12:32:28 +02:00
#+begin_src c :comments org :tangle (eval h_func)
bool qmckl_electron_provided (const qmckl_context context);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
bool qmckl_electron_provided(const qmckl_context context) {
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-05-18 12:32:28 +02:00
assert (ctx != NULL);
return ctx->electron.provided;
}
#+end_src
** Access functions
2021-04-21 01:56:47 +02:00
2021-05-15 23:19:13 +02:00
Access functions return ~QMCKL_SUCCESS~ when the data has been
successfully retrieved. It returnes ~QMCKL_INVALID_CONTEXT~ when
the context is not a valid context, and ~QMCKL_NOT_PROVIDED~ when
the data has not been provided. If the function returns
successfully, the variable pointed by the pointer given in argument
contains the requested data. Otherwise, this variable is untouched.
2021-05-19 00:28:56 +02:00
2021-05-18 12:32:28 +02:00
#+NAME:post
#+begin_src c :exports none
2021-04-21 01:56:47 +02:00
if ( (ctx->electron.uninitialized & mask) != 0) {
return NULL;
}
2021-05-18 12:32:28 +02:00
#+end_src
2022-01-26 17:06:51 +01:00
2021-05-18 12:32:28 +02:00
*** Number of electrons
2021-05-19 00:28:56 +02:00
2021-05-18 12:32:28 +02:00
#+begin_src c :comments org :tangle (eval h_func) :exports none
2021-05-19 01:35:34 +02:00
qmckl_exit_code qmckl_get_electron_num (const qmckl_context context, int64_t* const num);
qmckl_exit_code qmckl_get_electron_up_num (const qmckl_context context, int64_t* const up_num);
qmckl_exit_code qmckl_get_electron_down_num (const qmckl_context context, int64_t* const down_num);
2021-05-18 12:32:28 +02:00
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2021-05-15 23:19:13 +02:00
qmckl_exit_code
2021-05-19 01:35:34 +02:00
qmckl_get_electron_num (const qmckl_context context, int64_t* const num) {
2021-04-21 01:56:47 +02:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2021-05-15 23:19:13 +02:00
return QMCKL_INVALID_CONTEXT;
2021-04-21 01:56:47 +02:00
}
2021-05-19 01:35:34 +02:00
if (num == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
"qmckl_get_electron_num",
"num is a null pointer");
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-04-21 01:56:47 +02:00
assert (ctx != NULL);
int32_t mask = 1 << 0;
2021-04-21 01:56:47 +02:00
if ( (ctx->electron.uninitialized & mask) != 0) {
2021-05-15 23:19:13 +02:00
return QMCKL_NOT_PROVIDED;
2021-04-21 01:56:47 +02:00
}
assert (ctx->electron.num > (int64_t) 0);
2021-05-15 23:19:13 +02:00
,*num = ctx->electron.num;
return QMCKL_SUCCESS;
2021-04-21 01:56:47 +02:00
}
2021-05-15 23:19:13 +02:00
qmckl_exit_code
2021-05-19 01:35:34 +02:00
qmckl_get_electron_up_num (const qmckl_context context, int64_t* const up_num) {
2021-04-21 01:56:47 +02:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2021-05-15 23:19:13 +02:00
return QMCKL_INVALID_CONTEXT;
2021-04-21 01:56:47 +02:00
}
2021-05-19 01:35:34 +02:00
if (up_num == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
"qmckl_get_electron_up_num",
"up_num is a null pointer");
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-04-21 01:56:47 +02:00
assert (ctx != NULL);
int32_t mask = 1 << 0;
2021-04-21 01:56:47 +02:00
if ( (ctx->electron.uninitialized & mask) != 0) {
2021-05-15 23:19:13 +02:00
return QMCKL_NOT_PROVIDED;
2021-04-21 01:56:47 +02:00
}
assert (ctx->electron.up_num > (int64_t) 0);
2021-05-15 23:19:13 +02:00
,*up_num = ctx->electron.up_num;
return QMCKL_SUCCESS;
2021-04-21 01:56:47 +02:00
}
2021-05-15 23:19:13 +02:00
qmckl_exit_code
2021-05-19 01:35:34 +02:00
qmckl_get_electron_down_num (const qmckl_context context, int64_t* const down_num) {
2021-04-21 01:56:47 +02:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2021-05-15 23:19:13 +02:00
return QMCKL_INVALID_CONTEXT;
2021-04-21 01:56:47 +02:00
}
2021-05-19 01:35:34 +02:00
if (down_num == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
"qmckl_get_electron_down_num",
"down_num is a null pointer");
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-04-21 01:56:47 +02:00
assert (ctx != NULL);
int32_t mask = 1 << 0;
2021-04-21 01:56:47 +02:00
if ( (ctx->electron.uninitialized & mask) != 0) {
2021-05-15 23:19:13 +02:00
return QMCKL_NOT_PROVIDED;
2021-04-21 01:56:47 +02:00
}
assert (ctx->electron.down_num >= (int64_t) 0);
2021-05-15 23:19:13 +02:00
,*down_num = ctx->electron.down_num;
return QMCKL_SUCCESS;
2021-04-21 01:56:47 +02:00
}
2021-05-18 12:32:28 +02:00
#+end_src
2021-04-21 01:56:47 +02:00
2021-05-18 12:32:28 +02:00
*** Number of walkers
2021-05-19 00:28:56 +02:00
2021-05-18 12:32:28 +02:00
A walker is a set of electron coordinates that are arguments of
the wave function. ~walk_num~ is the number of walkers.
2021-05-19 00:28:56 +02:00
2021-05-18 12:32:28 +02:00
#+begin_src c :comments org :tangle (eval h_func) :exports none
2021-05-19 01:35:34 +02:00
qmckl_exit_code qmckl_get_electron_walk_num (const qmckl_context context, int64_t* const walk_num);
2021-05-18 12:32:28 +02:00
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2021-05-15 23:19:13 +02:00
qmckl_exit_code
2021-05-19 01:35:34 +02:00
qmckl_get_electron_walk_num (const qmckl_context context, int64_t* const walk_num) {
2021-04-21 01:56:47 +02:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2021-05-15 23:19:13 +02:00
return QMCKL_INVALID_CONTEXT;
2021-04-21 01:56:47 +02:00
}
2021-05-19 01:35:34 +02:00
if (walk_num == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
"qmckl_get_electron_walk_num",
"walk_num is a null pointer");
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-04-21 01:56:47 +02:00
assert (ctx != NULL);
2022-08-07 14:57:10 +02:00
,*walk_num = ctx->electron.walker.num;
2021-05-15 23:19:13 +02:00
return QMCKL_SUCCESS;
2021-04-21 01:56:47 +02:00
}
2021-05-18 12:32:28 +02:00
#+end_src
*** Scaling factors Kappa
#+begin_src c :comments org :tangle (eval h_func) :exports none
2021-06-10 22:57:59 +02:00
qmckl_exit_code qmckl_get_electron_rescale_factor_ee (const qmckl_context context, double* const rescale_factor_kappa_ee);
qmckl_exit_code qmckl_get_electron_rescale_factor_en (const qmckl_context context, double* const rescale_factor_kappa_en);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code
2021-06-10 22:57:59 +02:00
qmckl_get_electron_rescale_factor_ee (const qmckl_context context, double* const rescale_factor_kappa_ee) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
}
if (rescale_factor_kappa_ee == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2021-06-10 22:57:59 +02:00
"qmckl_get_electron_rescale_factor_ee",
"rescale_factor_kappa_ee is a null pointer");
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2021-06-10 22:57:59 +02:00
assert (ctx->electron.rescale_factor_kappa_ee > 0.0);
2021-06-10 22:57:59 +02:00
*rescale_factor_kappa_ee = ctx->electron.rescale_factor_kappa_ee;
return QMCKL_SUCCESS;
}
qmckl_exit_code
2021-06-10 22:57:59 +02:00
qmckl_get_electron_rescale_factor_en (const qmckl_context context, double* const rescale_factor_kappa_en) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
}
if (rescale_factor_kappa_en == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
2021-06-10 22:57:59 +02:00
"qmckl_get_electron_rescale_factor_en",
"rescale_factor_kappa_en is a null pointer");
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
2021-06-10 22:57:59 +02:00
assert (ctx->electron.rescale_factor_kappa_en > 0.0);
*rescale_factor_kappa_en = ctx->electron.rescale_factor_kappa_en;
return QMCKL_SUCCESS;
}
#+end_src
2021-05-18 12:32:28 +02:00
*** Electron coordinates
2021-05-19 00:28:56 +02:00
2021-05-18 12:32:28 +02:00
Returns the current electron coordinates. The pointer is assumed
2022-08-07 14:57:10 +02:00
to point on a memory block of size ~size_max~ \ge ~3 * elec_num * walker.num~.
2021-05-19 22:49:32 +02:00
The order of the indices is:
2021-05-19 01:35:34 +02:00
2022-08-07 14:57:10 +02:00
| | Normal | Transposed |
|---------+----------------------------+----------------------------|
| C | ~[walker.num*elec_num][3]~ | ~[3][walker.num*elec_num]~ |
| Fortran | ~(3,walker.num*elec_num)~ | ~(walker.num*elec_num, 3)~ |
2021-05-19 01:35:34 +02:00
2021-05-19 00:28:56 +02:00
2021-05-18 12:32:28 +02:00
#+begin_src c :comments org :tangle (eval h_func) :exports none
2022-01-23 16:18:46 +01:00
qmckl_exit_code
qmckl_get_electron_coord (const qmckl_context context,
const char transp,
double* const coord,
const int64_t size_max);
2021-05-18 12:32:28 +02:00
#+end_src
2022-08-07 14:57:10 +02:00
As the ~walker~ attribute is equal to ~points~, returning the
current electron coordinates is equivalent to returning the
current points.
2022-01-26 17:06:51 +01:00
2021-05-18 12:32:28 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code
2022-01-23 16:18:46 +01:00
qmckl_get_electron_coord (const qmckl_context context,
const char transp,
double* const coord,
const int64_t size_max)
{
2021-05-19 01:35:34 +02:00
if (transp != 'N' && transp != 'T') {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
"qmckl_get_electron_coord",
"transp should be 'N' or 'T'");
}
if (coord == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
"qmckl_get_electron_coord",
"coord is a null pointer");
}
2022-01-26 17:06:51 +01:00
if (size_max <= 0) {
2021-05-19 01:35:34 +02:00
return qmckl_failwith( context,
2022-01-26 17:06:51 +01:00
QMCKL_INVALID_ARG_4,
2021-05-19 01:35:34 +02:00
"qmckl_get_electron_coord",
2022-01-26 17:06:51 +01:00
"size_max should be > 0");
2021-05-18 12:32:28 +02:00
}
2022-01-26 17:06:51 +01:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
}
2021-05-19 01:35:34 +02:00
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2022-01-26 17:06:51 +01:00
assert (ctx != NULL);
if (!ctx->electron.provided) {
2022-01-23 16:18:46 +01:00
return qmckl_failwith( context,
2022-01-26 17:06:51 +01:00
QMCKL_NOT_PROVIDED,
2022-01-23 16:18:46 +01:00
"qmckl_get_electron_coord",
2022-01-26 17:06:51 +01:00
NULL);
2022-01-23 16:18:46 +01:00
}
2022-08-07 14:57:10 +02:00
assert (ctx->point.num == ctx->electron.walker.point.num);
assert (ctx->point.coord.data == ctx->electron.walker.point.coord.data);
2021-05-19 01:35:34 +02:00
2022-01-26 17:06:51 +01:00
return qmckl_get_point(context, transp, coord, size_max);
2021-04-21 01:56:47 +02:00
}
2021-05-18 12:32:28 +02:00
#+end_src
2021-04-30 01:26:19 +02:00
2021-04-21 01:56:47 +02:00
** Initialization functions
To set the data relative to the electrons in the context, the
following functions need to be called. When the data structure is
2021-05-15 23:19:13 +02:00
initialized, the internal ~coord_new~ and ~coord_old~ arrays are
2022-08-07 14:57:10 +02:00
both not allocated.
2021-04-30 01:26:19 +02:00
2021-04-21 01:56:47 +02:00
#+begin_src c :comments org :tangle (eval h_func)
2021-06-10 22:57:59 +02:00
qmckl_exit_code qmckl_set_electron_num (qmckl_context context, const int64_t up_num, const int64_t down_num);
2022-08-07 14:57:10 +02:00
qmckl_exit_code qmckl_set_electron_coord (qmckl_context context, const char transp, const int64_t walk_num, const double* coord, const int64_t size_max);
2021-06-10 22:57:59 +02:00
qmckl_exit_code qmckl_set_electron_rescale_factor_ee (qmckl_context context, const double kappa_ee);
qmckl_exit_code qmckl_set_electron_rescale_factor_en (qmckl_context context, const double kappa_en);
2021-04-21 01:56:47 +02:00
#+end_src
#+NAME:pre2
2021-04-21 13:00:24 +02:00
#+begin_src c :exports none
2021-04-21 01:56:47 +02:00
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;
if (mask != 0 && !(ctx->electron.uninitialized & mask)) {
return qmckl_failwith( context,
QMCKL_ALREADY_SET,
"qmckl_set_electron_*",
NULL);
}
2021-04-21 01:56:47 +02:00
#+end_src
#+NAME:post2
2021-04-21 13:00:24 +02:00
#+begin_src c :exports none
2021-04-30 01:26:19 +02:00
ctx->electron.uninitialized &= ~mask;
2021-04-21 01:56:47 +02:00
ctx->electron.provided = (ctx->electron.uninitialized == 0);
return QMCKL_SUCCESS;
#+end_src
2021-04-30 01:26:19 +02:00
2021-04-21 01:56:47 +02:00
To set the number of electrons, we give the number of up-spin and
2021-04-21 13:00:24 +02:00
down-spin electrons to the context and we set the number of walkers.
2021-04-30 01:26:19 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2021-05-15 23:19:13 +02:00
qmckl_exit_code
qmckl_set_electron_num(qmckl_context context,
const int64_t up_num,
const int64_t down_num) {
int32_t mask = 1 << 0;
2021-04-21 01:56:47 +02:00
<<pre2>>
if (up_num <= 0) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
"qmckl_set_electron_num",
"up_num <= 0");
}
2021-09-27 17:18:43 +02:00
if (down_num < 0) {
2021-04-21 01:56:47 +02:00
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
"qmckl_set_electron_num",
2021-09-27 17:18:43 +02:00
"down_num < 0");
2021-04-21 01:56:47 +02:00
}
ctx->electron.up_num = up_num;
ctx->electron.down_num = down_num;
ctx->electron.num = up_num + down_num;
<<post2>>
}
#+end_src
2021-04-30 01:26:19 +02:00
Next we set the rescale parameter for the rescaled distance metric.
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code
2021-06-10 22:57:59 +02:00
qmckl_set_electron_rescale_factor_ee(qmckl_context context,
const double rescale_factor_kappa_ee) {
int32_t mask = 0; // can be changed
<<pre2>>
2021-06-10 22:57:59 +02:00
if (rescale_factor_kappa_ee <= 0.0) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
"qmckl_set_electron_rescale_factor_ee",
"rescale_factor_kappa_ee <= 0.0");
}
2021-06-10 22:57:59 +02:00
ctx->electron.rescale_factor_kappa_ee = rescale_factor_kappa_ee;
2021-06-10 22:57:59 +02:00
return QMCKL_SUCCESS;
}
2021-06-10 22:57:59 +02:00
qmckl_exit_code
qmckl_set_electron_rescale_factor_en(qmckl_context context,
const double rescale_factor_kappa_en) {
int32_t mask = 0; // can be changed
2021-06-10 22:57:59 +02:00
<<pre2>>
2021-06-10 22:57:59 +02:00
if (rescale_factor_kappa_en <= 0.0) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
"qmckl_set_electron_rescale_factor_en",
"rescale_factor_kappa_en <= 0.0");
}
ctx->electron.rescale_factor_kappa_en = rescale_factor_kappa_en;
2021-06-10 22:57:59 +02:00
return QMCKL_SUCCESS;
}
2021-06-27 15:48:46 +02:00
#+end_src
#+begin_src f90 :comments org :tangle (eval fh_func) :noweb yes
interface
integer(c_int32_t) function qmckl_set_electron_num(context, alpha, beta) bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
2022-01-26 17:06:51 +01:00
integer (c_int64_t) , intent(in) , value :: context
2021-06-27 15:48:46 +02:00
integer (c_int64_t) , intent(in) , value :: alpha
2022-01-26 17:06:51 +01:00
integer (c_int64_t) , intent(in) , value :: beta
2021-06-27 15:48:46 +02:00
end function
end interface
#+end_src
2022-08-07 14:57:10 +02:00
2021-04-21 01:56:47 +02:00
The following function sets the electron coordinates of all the
walkers. When this is done, the pointers to the old and new sets
of coordinates are swapped, and the new coordinates are
2021-04-21 13:00:24 +02:00
overwritten. This can be done only when the data relative to
electrons have been set.
2021-04-30 01:26:19 +02:00
2022-08-07 14:57:10 +02:00
~size_max~ should be equal equal or geater than ~elec_num *
walker.num * 3~, to be symmetric with ~qmckl_get_electron_coord~.
2022-01-26 17:06:51 +01:00
2021-05-19 01:35:34 +02:00
Important: changing the electron coordinates increments the date
in the context.
2021-04-21 13:00:24 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2021-05-15 23:19:13 +02:00
qmckl_exit_code
2022-01-17 16:09:41 +01:00
qmckl_set_electron_coord(qmckl_context context,
const char transp,
2022-08-07 14:57:10 +02:00
const int64_t walk_num,
2022-01-17 16:09:41 +01:00
const double* coord,
const int64_t size_max)
{
2021-05-15 23:19:13 +02:00
int32_t mask = 0; // coord can be changed
2021-04-21 01:56:47 +02:00
<<pre2>>
2021-05-19 01:35:34 +02:00
if (transp != 'N' && transp != 'T') {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
"qmckl_set_electron_coord",
"transp should be 'N' or 'T'");
}
2022-08-07 14:57:10 +02:00
if (walk_num <= 0) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
"qmckl_set_electron_coord",
"walk_num <= 0");
}
2021-05-19 01:35:34 +02:00
if (coord == NULL) {
return qmckl_failwith( context,
QMCKL_INVALID_ARG_3,
"qmckl_set_electron_coord",
"coord is a null pointer");
}
2022-01-26 17:06:51 +01:00
const int64_t elec_num = ctx->electron.num;
2021-05-15 23:19:13 +02:00
2021-05-19 01:35:34 +02:00
if (elec_num == 0L) {
2021-04-21 01:56:47 +02:00
return qmckl_failwith( context,
QMCKL_FAILURE,
"qmckl_set_electron_coord",
2021-05-19 01:35:34 +02:00
"elec_num is not set");
2021-04-21 01:56:47 +02:00
}
2021-04-30 01:26:19 +02:00
2021-04-21 01:56:47 +02:00
/* Swap pointers */
2022-08-07 14:57:10 +02:00
qmckl_walker tmp = ctx->electron.walker_old;
ctx->electron.walker_old = ctx->electron.walker;
ctx->electron.walker = tmp;
memcpy(&(ctx->point), &(ctx->electron.walker.point), sizeof(qmckl_point_struct));
2021-05-19 01:35:34 +02:00
2022-01-26 17:06:51 +01:00
qmckl_exit_code rc;
2022-08-07 14:57:10 +02:00
rc = qmckl_set_point(context, transp, walk_num*elec_num, coord, size_max);
2022-08-10 14:30:04 +02:00
if (rc != QMCKL_SUCCESS) return rc;
2022-01-26 17:06:51 +01:00
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num = walk_num;
memcpy(&(ctx->electron.walker.point), &(ctx->point), sizeof(qmckl_point_struct));
2021-04-21 01:56:47 +02:00
return QMCKL_SUCCESS;
2021-04-30 01:26:19 +02:00
2021-04-21 01:56:47 +02:00
}
#+end_src
2021-06-27 15:48:46 +02:00
#+begin_src f90 :comments org :tangle (eval fh_func) :noweb yes
interface
2022-08-07 14:57:10 +02:00
integer(c_int32_t) function qmckl_set_electron_coord(context, transp, walk_num, coord, size_max) bind(C)
2021-06-27 15:48:46 +02:00
use, intrinsic :: iso_c_binding
import
implicit none
2022-01-26 17:06:51 +01:00
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: transp
2022-08-07 14:57:10 +02:00
integer (c_int64_t) , intent(in) , value :: walk_num
2021-06-27 15:48:46 +02:00
double precision , intent(in) :: coord(*)
2022-01-17 16:09:41 +01:00
integer (c_int64_t) , intent(in) , value :: size_max
2021-06-27 15:48:46 +02:00
end function
end interface
#+end_src
2021-04-21 01:56:47 +02:00
** Test
2021-05-19 01:35:34 +02:00
#+begin_src python :results output :exports none
2021-05-19 00:28:56 +02:00
import numpy as np
#+end_src
2021-04-21 01:56:47 +02:00
2021-05-19 00:28:56 +02:00
#+begin_src c :tangle (eval c_test)
/* Reference input data */
2021-05-19 01:35:34 +02:00
int64_t walk_num = chbrclf_walk_num;
int64_t elec_num = chbrclf_elec_num;
int64_t elec_up_num = chbrclf_elec_up_num;
int64_t elec_dn_num = chbrclf_elec_dn_num;
double rescale_factor_kappa_ee = 1.0;
double rescale_factor_kappa_en = 1.0;
double nucl_rescale_factor_kappa = 1.0;
2021-05-19 01:35:34 +02:00
double* elec_coord = &(chbrclf_elec_coord[0][0][0]);
int64_t nucl_num = chbrclf_nucl_num;
double* charge = chbrclf_charge;
double* nucl_coord = &(chbrclf_nucl_coord[0][0]);
2021-04-30 01:26:19 +02:00
2021-04-21 01:56:47 +02:00
/* --- */
2021-04-30 01:26:19 +02:00
2021-04-21 01:56:47 +02:00
qmckl_exit_code rc;
2021-05-11 16:41:03 +02:00
assert(!qmckl_electron_provided(context));
2021-04-21 01:56:47 +02:00
2021-05-15 23:19:13 +02:00
int64_t n;
rc = qmckl_get_electron_num (context, &n);
assert(rc == QMCKL_NOT_PROVIDED);
rc = qmckl_get_electron_up_num (context, &n);
assert(rc == QMCKL_NOT_PROVIDED);
rc = qmckl_get_electron_down_num (context, &n);
assert(rc == QMCKL_NOT_PROVIDED);
2021-05-19 01:35:34 +02:00
rc = qmckl_set_electron_num (context, elec_up_num, elec_dn_num);
2021-05-11 16:41:03 +02:00
assert(rc == QMCKL_SUCCESS);
2022-08-07 14:57:10 +02:00
assert(qmckl_electron_provided(context));
2021-04-21 01:56:47 +02:00
2021-05-15 23:19:13 +02:00
rc = qmckl_get_electron_up_num (context, &n);
assert(rc == QMCKL_SUCCESS);
2021-05-19 01:35:34 +02:00
assert(n == elec_up_num);
2021-05-15 23:19:13 +02:00
rc = qmckl_get_electron_down_num (context, &n);
assert(rc == QMCKL_SUCCESS);
2021-05-19 01:35:34 +02:00
assert(n == elec_dn_num);
2021-05-15 23:19:13 +02:00
rc = qmckl_get_electron_num (context, &n);
assert(rc == QMCKL_SUCCESS);
2021-05-19 01:35:34 +02:00
assert(n == elec_num);
2021-05-15 23:19:13 +02:00
2021-06-10 22:57:59 +02:00
double k_ee = 0.;
double k_en = 0.;
rc = qmckl_get_electron_rescale_factor_ee (context, &k_ee);
assert(rc == QMCKL_SUCCESS);
assert(k_ee == 1.0);
2021-06-10 22:57:59 +02:00
rc = qmckl_get_electron_rescale_factor_en (context, &k_en);
assert(rc == QMCKL_SUCCESS);
assert(k_en == 1.0);
2021-06-10 22:57:59 +02:00
rc = qmckl_set_electron_rescale_factor_en(context, rescale_factor_kappa_en);
assert(rc == QMCKL_SUCCESS);
2021-06-10 22:57:59 +02:00
rc = qmckl_set_electron_rescale_factor_ee(context, rescale_factor_kappa_ee);
assert(rc == QMCKL_SUCCESS);
2021-06-10 22:57:59 +02:00
rc = qmckl_get_electron_rescale_factor_ee (context, &k_ee);
assert(rc == QMCKL_SUCCESS);
assert(k_ee == rescale_factor_kappa_ee);
2021-06-10 22:57:59 +02:00
rc = qmckl_get_electron_rescale_factor_en (context, &k_en);
assert(rc == QMCKL_SUCCESS);
assert(k_en == rescale_factor_kappa_en);
2021-05-15 23:19:13 +02:00
2022-08-07 14:57:10 +02:00
int64_t w = 0;
2021-05-15 23:19:13 +02:00
rc = qmckl_get_electron_walk_num (context, &w);
2022-08-07 14:57:10 +02:00
assert(rc == QMCKL_SUCCESS);
assert(w == 0);
2021-05-15 23:19:13 +02:00
2022-08-07 14:57:10 +02:00
assert(qmckl_electron_provided(context));
rc = qmckl_set_electron_coord (context, 'N', walk_num, elec_coord, walk_num*elec_num*3);
2021-05-11 16:41:03 +02:00
assert(rc == QMCKL_SUCCESS);
2021-05-15 23:19:13 +02:00
rc = qmckl_get_electron_walk_num (context, &w);
assert(rc == QMCKL_SUCCESS);
assert(w == walk_num);
2021-05-19 01:35:34 +02:00
double elec_coord2[walk_num*3*elec_num];
2021-05-15 23:19:13 +02:00
2022-01-23 16:18:46 +01:00
rc = qmckl_get_electron_coord (context, 'N', elec_coord2, walk_num*3*elec_num);
2021-05-16 00:53:17 +02:00
assert(rc == QMCKL_SUCCESS);
2022-01-23 16:18:46 +01:00
for (int64_t i=0 ; i<3*elec_num*walk_num ; ++i) {
2022-01-26 17:06:51 +01:00
printf("%f %f\n", elec_coord[i], elec_coord2[i]);
2021-05-19 01:35:34 +02:00
assert( elec_coord[i] == elec_coord2[i] );
2021-05-16 00:53:17 +02:00
}
2021-04-21 01:56:47 +02:00
#+end_src
2021-04-26 01:45:25 +02:00
* Computation
2021-05-19 00:28:56 +02:00
2021-04-26 01:45:25 +02:00
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-26 17:06:51 +01:00
2021-04-26 01:45:25 +02:00
** Electron-electron distances
2021-04-30 01:26:19 +02:00
2021-04-26 01:45:25 +02:00
*** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
2021-05-19 01:35:34 +02:00
qmckl_exit_code qmckl_get_electron_ee_distance(qmckl_context context, double* const distance);
2021-04-26 01:45:25 +02:00
#+end_src
2021-04-30 01:26:19 +02:00
2021-07-04 15:19:57 +02:00
#+begin_src f90 :tangle (eval fh_func) :comments org :exports none
interface
integer(c_int32_t) function qmckl_get_electron_ee_distance(context, distance) &
bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (c_int64_t) , intent(in) , value :: context
real (c_double ) , intent(out) :: distance(*)
end function
end interface
#+end_src
2021-04-30 01:26:19 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2021-05-19 01:35:34 +02:00
qmckl_exit_code qmckl_get_electron_ee_distance(qmckl_context context, double* const distance)
2021-04-26 01:45:25 +02:00
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2021-05-18 12:32:28 +02:00
return QMCKL_NULL_CONTEXT;
2021-04-26 01:45:25 +02:00
}
2021-05-19 00:28:56 +02:00
qmckl_exit_code rc;
2021-05-18 12:32:28 +02:00
rc = qmckl_provide_ee_distance(context);
2021-04-26 01:45:25 +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-04-26 01:45:25 +02:00
assert (ctx != NULL);
2022-08-07 14:57:10 +02:00
size_t sze = ctx->electron.num * ctx->electron.num * ctx->electron.walker.num;
2021-04-26 01:45:25 +02:00
memcpy(distance, ctx->electron.ee_distance, sze * sizeof(double));
return QMCKL_SUCCESS;
}
#+end_src
2021-05-18 12:32:28 +02:00
2021-04-26 01:45:25 +02:00
*** Provide :noexport:
2021-04-30 01:26:19 +02:00
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
2021-04-26 01:45:25 +02:00
qmckl_exit_code qmckl_provide_ee_distance(qmckl_context context);
#+end_src
2021-04-30 01:26:19 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2021-04-26 01:45:25 +02:00
qmckl_exit_code qmckl_provide_ee_distance(qmckl_context context)
{
2021-05-18 12:32:28 +02:00
2021-04-26 01:45:25 +02:00
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
2021-05-18 12:32:28 +02:00
return QMCKL_NULL_CONTEXT;
2021-04-26 01:45:25 +02:00
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-04-26 01:45:25 +02:00
assert (ctx != NULL);
2021-04-30 01:26:19 +02:00
2021-04-26 01:45:25 +02:00
/* Compute if necessary */
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.point.date > ctx->electron.ee_distance_date) {
2021-04-26 01:45:25 +02:00
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
free(ctx->electron.ee_distance);
ctx->electron.ee_distance = NULL;
}
2021-04-26 01:45:25 +02:00
/* Allocate array */
if (ctx->electron.ee_distance == NULL) {
2021-04-30 01:26:19 +02:00
2021-04-26 01:45:25 +02:00
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = ctx->electron.num * ctx->electron.num *
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num * sizeof(double);
2021-04-26 01:45:25 +02:00
double* ee_distance = (double*) qmckl_malloc(context, mem_info);
2021-04-30 01:26:19 +02:00
2021-04-26 01:45:25 +02:00
if (ee_distance == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_ee_distance",
NULL);
}
ctx->electron.ee_distance = ee_distance;
}
qmckl_exit_code rc =
qmckl_compute_ee_distance(context,
2021-04-30 01:26:19 +02:00
ctx->electron.num,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
ctx->electron.walker.point.coord.data,
2021-04-26 01:45:25 +02:00
ctx->electron.ee_distance);
if (rc != QMCKL_SUCCESS) {
return rc;
}
ctx->electron.ee_distance_date = ctx->date;
}
return QMCKL_SUCCESS;
}
#+end_src
*** Compute
:PROPERTIES:
:Name: qmckl_compute_ee_distance
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
2021-04-30 01:26:19 +02:00
2021-04-26 01:45:25 +02:00
#+NAME: qmckl_ee_distance_args
2022-01-06 02:28:13 +01:00
| Variable | Type | In/Out | Description |
|---------------+----------------------------------------+--------+-----------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~coord~ | ~double[3][walk_num][elec_num]~ | in | Electron coordinates |
2022-01-06 02:28:13 +01:00
| ~ee_distance~ | ~double[walk_num][elec_num][elec_num]~ | out | Electron-electron distances |
2021-04-26 01:45:25 +02:00
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_ee_distance_f(context, elec_num, walk_num, coord, ee_distance) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: elec_num
integer*8 , intent(in) :: walk_num
2022-01-23 16:18:46 +01:00
double precision , intent(in) :: coord(elec_num,walk_num,3)
2021-04-26 01:45:25 +02:00
double precision , intent(out) :: ee_distance(elec_num,elec_num,walk_num)
2022-01-23 16:18:46 +01:00
integer*8 :: k, i, j
double precision :: x, y, z
2021-04-26 01:45:25 +02:00
info = QMCKL_SUCCESS
2021-04-30 01:26:19 +02:00
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
2021-04-26 01:45:25 +02:00
endif
2021-04-30 01:26:19 +02:00
if (elec_num <= 0) then
2021-04-26 01:45:25 +02:00
info = QMCKL_INVALID_ARG_2
2021-04-30 01:26:19 +02:00
return
2021-04-26 01:45:25 +02:00
endif
2021-04-30 01:26:19 +02:00
if (walk_num <= 0) then
2021-04-26 01:45:25 +02:00
info = QMCKL_INVALID_ARG_3
2021-04-30 01:26:19 +02:00
return
2021-04-26 01:45:25 +02:00
endif
do k=1,walk_num
info = qmckl_distance(context, 'T', 'T', elec_num, elec_num, &
2022-01-23 16:18:46 +01:00
coord(1,k,1), elec_num * walk_num, &
coord(1,k,1), elec_num * walk_num, &
2021-04-26 01:45:25 +02:00
ee_distance(1,1,k), elec_num)
2021-05-19 00:28:56 +02:00
if (info /= QMCKL_SUCCESS) then
exit
endif
2021-04-26 01:45:25 +02:00
end do
end function qmckl_compute_ee_distance_f
#+end_src
#+begin_src c :tangle (eval h_private_func) :comments org :exports none
2021-05-16 00:53:17 +02:00
qmckl_exit_code qmckl_compute_ee_distance (
2021-04-26 01:45:25 +02:00
const qmckl_context context,
const int64_t elec_num,
const int64_t walk_num,
const double* coord,
2021-04-30 01:26:19 +02:00
double* const ee_distance );
2021-04-26 01:45:25 +02:00
#+end_src
#+CALL: generate_c_interface(table=qmckl_ee_distance_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
2021-04-30 01:26:19 +02:00
2021-04-26 01:45:25 +02:00
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_ee_distance &
(context, elec_num, walk_num, coord, ee_distance) &
bind(C) result(info)
use, intrinsic :: iso_c_binding
implicit none
integer (c_int64_t) , intent(in) , value :: context
integer (c_int64_t) , intent(in) , value :: elec_num
integer (c_int64_t) , intent(in) , value :: walk_num
real (c_double ) , intent(in) :: coord(elec_num,3,walk_num)
real (c_double ) , intent(out) :: ee_distance(elec_num,elec_num,walk_num)
integer(c_int32_t), external :: qmckl_compute_ee_distance_f
info = qmckl_compute_ee_distance_f &
(context, elec_num, walk_num, coord, ee_distance)
end function qmckl_compute_ee_distance
#+end_src
*** Test
2022-01-26 17:06:51 +01:00
2021-05-19 01:35:34 +02:00
#+begin_src python :results output :exports none
import numpy as np
elec_1_w1 = np.array( [ -2.26995253563, -5.15737533569, -2.22940072417 ])
elec_2_w1 = np.array( [ 3.51983380318, -1.08717381954, -1.19617708027 ])
elec_1_w2 = np.array( [ -2.34410619736, -3.20016115904, -1.53496759012 ])
elec_2_w2 = np.array( [ 3.17996025085, -1.40260577202, 1.49473607540 ])
print ( "[0][0][0] : ", np.linalg.norm(elec_1_w1-elec_1_w1) )
print ( "[0][1][0] : ", np.linalg.norm(elec_1_w1-elec_2_w1) )
print ( "[1][0][0] : ", np.linalg.norm(elec_2_w1-elec_1_w1) )
print ( "[0][0][1] : ", np.linalg.norm(elec_1_w2-elec_1_w2) )
print ( "[0][1][1] : ", np.linalg.norm(elec_1_w2-elec_2_w2) )
print ( "[1][0][1] : ", np.linalg.norm(elec_2_w2-elec_1_w2) )
#+end_src
#+RESULTS:
: [0][0][0] : 0.0
: [0][1][0] : 7.152322512964209
: [1][0][0] : 7.152322512964209
: [0][0][1] : 0.0
: [0][1][1] : 6.5517646321055665
: [1][0][1] : 6.5517646321055665
2021-04-26 01:45:25 +02:00
#+begin_src c :tangle (eval c_test)
2021-05-11 16:41:03 +02:00
assert(qmckl_electron_provided(context));
2021-04-26 01:45:25 +02:00
2021-05-19 01:35:34 +02:00
double ee_distance[walk_num * elec_num * elec_num];
2021-05-18 12:32:28 +02:00
rc = qmckl_get_electron_ee_distance(context, ee_distance);
2021-05-19 00:28:56 +02:00
// (e1,e2,w)
// (0,0,0) == 0.
2021-05-18 12:32:28 +02:00
assert(ee_distance[0] == 0.);
2021-05-19 00:28:56 +02:00
// (1,0,0) == (0,1,0)
2021-05-19 01:35:34 +02:00
assert(ee_distance[1] == ee_distance[elec_num]);
2021-05-19 00:28:56 +02:00
// value of (1,0,0)
assert(fabs(ee_distance[1]-7.152322512964209) < 1.e-12);
// (0,0,1) == 0.
2021-05-19 01:35:34 +02:00
assert(ee_distance[elec_num*elec_num] == 0.);
2021-05-19 00:28:56 +02:00
// (1,0,1) == (0,1,1)
2021-05-19 01:35:34 +02:00
assert(ee_distance[elec_num*elec_num+1] == ee_distance[elec_num*elec_num+elec_num]);
2021-05-19 00:28:56 +02:00
// value of (1,0,1)
2021-05-19 01:35:34 +02:00
assert(fabs(ee_distance[elec_num*elec_num+1]-6.5517646321055665) < 1.e-12);
2021-05-18 12:32:28 +02:00
#+end_src
** Electron-electron rescaled distances
~ee_distance_rescaled~ stores the matrix of the rescaled distances between all
pairs of electrons:
\[
C_{ij} = \left( 1 - \exp{-\kappa C_{ij}}\right)/\kappa
\]
where \(C_{ij}\) is the matrix of electron-electron distances.
*** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
qmckl_exit_code qmckl_get_electron_ee_distance_rescaled(qmckl_context context, double* const distance_rescaled);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_get_electron_ee_distance_rescaled(qmckl_context context, double* const distance_rescaled)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
rc = qmckl_provide_ee_distance_rescaled(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
size_t sze = ctx->electron.num * ctx->electron.num * ctx->electron.walker.num;
memcpy(distance_rescaled, ctx->electron.ee_distance_rescaled, sze * sizeof(double));
return QMCKL_SUCCESS;
}
#+end_src
*** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_provide_ee_distance_rescaled(qmckl_context context);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_provide_ee_distance_rescaled(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);
/* Compute if necessary */
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.point.date > ctx->electron.ee_distance_rescaled_date) {
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
free(ctx->electron.ee_distance_rescaled);
ctx->electron.ee_distance_rescaled = NULL;
}
/* Allocate array */
if (ctx->electron.ee_distance_rescaled == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = ctx->electron.num * ctx->electron.num *
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num * sizeof(double);
double* ee_distance_rescaled = (double*) qmckl_malloc(context, mem_info);
if (ee_distance_rescaled == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_ee_distance_rescaled",
NULL);
}
ctx->electron.ee_distance_rescaled = ee_distance_rescaled;
}
qmckl_exit_code rc =
qmckl_compute_ee_distance_rescaled(context,
ctx->electron.num,
ctx->electron.rescale_factor_kappa_en,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
ctx->electron.walker.point.coord.data,
ctx->electron.ee_distance_rescaled);
if (rc != QMCKL_SUCCESS) {
return rc;
}
ctx->electron.ee_distance_rescaled_date = ctx->date;
}
return QMCKL_SUCCESS;
}
#+end_src
*** Compute
:PROPERTIES:
:Name: qmckl_compute_ee_distance_rescaled
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_ee_distance_rescaled_args
2022-01-17 15:54:21 +01:00
| Variable | Type | In/Out | Description |
|---------------------------+----------------------------------------+--------+--------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~rescale_factor_kappa_ee~ | ~double~ | in | Factor to rescale ee distances |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
2022-04-04 17:30:38 +02:00
| ~coord~ | ~double[3][walk_num][elec_num]~ | in | Electron coordinates |
2022-01-17 15:54:21 +01:00
| ~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_kappa_ee, walk_num, &
coord, ee_distance_rescaled) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: elec_num
double precision , intent(in) :: rescale_factor_kappa_ee
integer*8 , intent(in) :: walk_num
2022-04-04 17:30:38 +02:00
double precision , intent(in) :: coord(elec_num,walk_num,3)
double precision , intent(out) :: ee_distance_rescaled(elec_num,elec_num,walk_num)
integer*8 :: k
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
if (elec_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
do k=1,walk_num
info = qmckl_distance_rescaled(context, 'T', 'T', elec_num, elec_num, &
2022-01-23 16:18:46 +01:00
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_kappa_ee)
if (info /= QMCKL_SUCCESS) then
exit
endif
end do
end function qmckl_compute_ee_distance_rescaled_f
#+end_src
#+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_kappa_ee,
const int64_t walk_num,
const double* coord,
double* const ee_distance_rescaled );
#+end_src
#+CALL: generate_c_interface(table=qmckl_ee_distance_rescaled_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_ee_distance_rescaled &
(context, elec_num, rescale_factor_kappa_ee, walk_num, coord, ee_distance_rescaled) &
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
real (c_double ) , intent(in) , value :: rescale_factor_kappa_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)
integer(c_int32_t), external :: qmckl_compute_ee_distance_rescaled_f
info = qmckl_compute_ee_distance_rescaled_f &
(context, elec_num, rescale_factor_kappa_ee, walk_num, coord, ee_distance_rescaled)
end function qmckl_compute_ee_distance_rescaled
#+end_src
*** Test
#+begin_src python :results output :exports none
import numpy as np
kappa = 1.0
elec_1_w1 = np.array( [ -2.26995253563, -5.15737533569, -2.22940072417 ])
elec_2_w1 = np.array( [ 3.51983380318, -1.08717381954, -1.19617708027 ])
elec_1_w2 = np.array( [ -2.34410619736, -3.20016115904, -1.53496759012 ])
elec_2_w2 = np.array( [ 3.17996025085, -1.40260577202, 1.49473607540 ])
print ( "[0][0][0] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_1_w1-elec_1_w1)) )/kappa )
print ( "[0][1][0] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_1_w1-elec_2_w1)) )/kappa )
print ( "[1][0][0] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_2_w1-elec_1_w1)) )/kappa )
print ( "[0][0][1] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_1_w2-elec_1_w2)) )/kappa )
print ( "[0][1][1] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_1_w2-elec_2_w2)) )/kappa )
print ( "[1][0][1] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_2_w2-elec_1_w2)) )/kappa )
#+end_src
#+RESULTS:
: [0][0][0] : 0.0
: [0][1][0] : 0.9992169566605263
: [1][0][0] : 0.9992169566605263
: [0][0][1] : 0.0
: [0][1][1] : 0.9985724058042633
: [1][0][1] : 0.9985724058042633
#+begin_src c :tangle (eval c_test)
assert(qmckl_electron_provided(context));
double ee_distance_rescaled[walk_num * elec_num * elec_num];
rc = qmckl_get_electron_ee_distance_rescaled(context, ee_distance_rescaled);
// (e1,e2,w)
// (0,0,0) == 0.
assert(ee_distance_rescaled[0] == 0.);
// (1,0,0) == (0,1,0)
assert(ee_distance_rescaled[1] == ee_distance_rescaled[elec_num]);
// value of (1,0,0)
assert(fabs(ee_distance_rescaled[1]-0.9992169566605263) < 1.e-12);
// (0,0,1) == 0.
assert(ee_distance_rescaled[elec_num*elec_num] == 0.);
// (1,0,1) == (0,1,1)
assert(ee_distance_rescaled[elec_num*elec_num+1] == ee_distance_rescaled[elec_num*elec_num+elec_num]);
// value of (1,0,1)
assert(fabs(ee_distance_rescaled[elec_num*elec_num+1]-0.9985724058042633) < 1.e-12);
#+end_src
2022-04-04 17:30:38 +02:00
** Electron-electron rescaled distance gradients and Laplacian with respect to electron coords
2022-01-26 17:06:51 +01:00
The rescaled distances which is given as $R = (1 - \exp{-\kappa r})/\kappa$
2021-06-01 10:15:09 +02:00
needs to be perturbed with respect to the electorn coordinates.
2022-01-26 17:06:51 +01:00
This data is stored in the ~ee_distance_rescaled_deriv_e~ tensor. The
The first three elements of this three index tensor ~[4][num][num]~ gives the
derivatives in the x, y, and z directions $dx, dy, dz$ and the last index
gives the Laplacian $\partial x^2 + \partial y^2 + \partial z^2$.
*** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
qmckl_exit_code qmckl_get_electron_ee_distance_rescaled_deriv_e(qmckl_context context, double* const distance_rescaled_deriv_e);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_get_electron_ee_distance_rescaled_deriv_e(qmckl_context context, double* const distance_rescaled_deriv_e)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
rc = qmckl_provide_ee_distance_rescaled_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
size_t sze = 4 * ctx->electron.num * ctx->electron.num * ctx->electron.walker.num;
memcpy(distance_rescaled_deriv_e, ctx->electron.ee_distance_rescaled_deriv_e, sze * sizeof(double));
return QMCKL_SUCCESS;
}
#+end_src
*** Provide :noexport:
2022-01-26 17:06:51 +01: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
#+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)
{
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);
/* Compute if necessary */
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.point.date > ctx->electron.ee_distance_rescaled_deriv_e_date) {
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
free(ctx->electron.ee_distance_rescaled_deriv_e);
ctx->electron.ee_distance_rescaled_deriv_e = NULL;
}
/* Allocate array */
if (ctx->electron.ee_distance_rescaled_deriv_e == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = 4 * ctx->electron.num * ctx->electron.num *
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num * sizeof(double);
double* ee_distance_rescaled_deriv_e = (double*) qmckl_malloc(context, mem_info);
if (ee_distance_rescaled_deriv_e == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_ee_distance_rescaled_deriv_e",
NULL);
}
ctx->electron.ee_distance_rescaled_deriv_e = ee_distance_rescaled_deriv_e;
}
qmckl_exit_code rc =
qmckl_compute_ee_distance_rescaled_deriv_e(context,
ctx->electron.num,
ctx->electron.rescale_factor_kappa_en,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
ctx->electron.walker.point.coord.data,
ctx->electron.ee_distance_rescaled_deriv_e);
if (rc != QMCKL_SUCCESS) {
return rc;
}
ctx->electron.ee_distance_rescaled_date = ctx->date;
}
return QMCKL_SUCCESS;
}
#+end_src
*** Compute
:PROPERTIES:
:Name: qmckl_compute_ee_distance_rescaled_deriv_e
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
2021-06-01 09:57:38 +02:00
#+NAME: qmckl_ee_distance_rescaled_deriv_e_args
2022-01-06 02:28:13 +01:00
| Variable | Type | In/Out | Description |
|---------------------------+-------------------------------------------+--------+-------------------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~rescale_factor_kappa_ee~ | ~double~ | in | Factor to rescale ee distances |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
2022-04-04 17:30:38 +02:00
| ~coord~ | ~double[3][walk_num][elec_num]~ | in | Electron coordinates |
2022-01-06 02:28:13 +01:00
| ~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_kappa_ee, walk_num, &
coord, ee_distance_rescaled_deriv_e) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: elec_num
double precision , intent(in) :: rescale_factor_kappa_ee
integer*8 , intent(in) :: walk_num
2022-04-04 17:30:38 +02:00
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)
integer*8 :: k
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
if (elec_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
do k=1,walk_num
info = qmckl_distance_rescaled_deriv_e(context, 'T', 'T', elec_num, elec_num, &
2022-04-04 17:30:38 +02:00
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_kappa_ee)
if (info /= QMCKL_SUCCESS) then
exit
endif
end do
end function qmckl_compute_ee_distance_rescaled_deriv_e_f
#+end_src
#+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_kappa_ee,
const int64_t walk_num,
const double* coord,
double* const ee_distance_rescaled_deriv_e );
#+end_src
#+CALL: generate_c_interface(table=qmckl_ee_distance_rescaled_deriv_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_ee_distance_rescaled_deriv_e &
(context, elec_num, rescale_factor_kappa_ee, walk_num, coord, ee_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
real (c_double ) , intent(in) , value :: rescale_factor_kappa_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)
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_kappa_ee, walk_num, coord, ee_distance_rescaled_deriv_e)
end function qmckl_compute_ee_distance_rescaled_deriv_e
#+end_src
*** Test
#+begin_src python :results output :exports none
import numpy as np
# TODO
#+end_src
#+begin_src c :tangle (eval c_test)
assert(qmckl_electron_provided(context));
double ee_distance_rescaled_deriv_e[4 * walk_num * elec_num * elec_num];
rc = qmckl_get_electron_ee_distance_rescaled_deriv_e(context, ee_distance_rescaled_deriv_e);
// 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);
#+end_src
** Electron-electron potential
2022-01-26 17:06:51 +01:00
2022-08-07 14:57:10 +02:00
~ee_potential~ is given by
\[
\mathcal{V}_{ee} = \sum_{i=1}^{N_e}\sum_{j>i}^{N_e}\frac{1}{r_{ij}}
\]
where \(\mathcal{V}_{ee}\) is the ~ee~ potential and \[r_{ij}\] the ~ee~
distance.
*** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
2022-08-07 14:57:10 +02:00
qmckl_exit_code qmckl_get_electron_ee_potential(qmckl_context context, double* const ee_potential);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2022-08-07 14:57:10 +02:00
qmckl_exit_code qmckl_get_electron_ee_potential(qmckl_context context, double* const ee_potential)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
rc = qmckl_provide_ee_potential(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
size_t sze = ctx->electron.walker.num * sizeof(double);
memcpy(ee_potential, ctx->electron.ee_potential, sze);
return QMCKL_SUCCESS;
}
#+end_src
2022-01-26 17:06:51 +01:00
*** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_provide_ee_potential(qmckl_context context);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_provide_ee_potential(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);
if (!ctx->electron.provided) return QMCKL_NOT_PROVIDED;
qmckl_exit_code rc = qmckl_provide_ee_distance(context);
if (rc != QMCKL_SUCCESS) return rc;
/* Compute if necessary */
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.point.date > ctx->electron.ee_potential_date) {
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
free(ctx->electron.ee_potential);
ctx->electron.ee_distance_rescaled_deriv_e = NULL;
}
/* Allocate array */
2022-08-07 14:57:10 +02:00
if (ctx->electron.ee_potential == NULL) {
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* ee_potential = (double*) qmckl_malloc(context, mem_info);
2022-08-07 14:57:10 +02:00
if (ee_potential == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_ee_potential",
NULL);
}
2022-08-07 14:57:10 +02:00
ctx->electron.ee_potential = ee_potential;
}
2022-02-16 15:14:41 +01:00
rc = qmckl_compute_ee_potential(context,
ctx->electron.num,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
ctx->electron.ee_distance,
2022-08-07 14:57:10 +02:00
ctx->electron.ee_potential);
if (rc != QMCKL_SUCCESS) {
return rc;
}
2022-08-07 14:57:10 +02:00
ctx->electron.ee_potential_date = ctx->date;
}
return QMCKL_SUCCESS;
}
#+end_src
*** Compute
:PROPERTIES:
:Name: qmckl_compute_ee_potential
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_ee_potential_args
2022-08-07 14:57:10 +02:00
| Variable | Type | In/Out | Description |
|----------------+----------------------------------------+--------+--------------------------------------|
| ~context~ | ~qmckl_context~ | in | Global state |
| ~elec_num~ | ~int64_t~ | in | Number of electrons |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~ee_distance~ | ~double[walk_num][elec_num][elec_num]~ | in | Electron-electron rescaled distances |
| ~ee_potential~ | ~double[walk_num]~ | out | Electron-electron potential |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_ee_potential_f(context, elec_num, walk_num, &
2022-08-07 14:57:10 +02:00
ee_distance, ee_potential) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: elec_num
integer*8 , intent(in) :: walk_num
double precision , intent(in) :: ee_distance(elec_num,elec_num,walk_num)
2022-08-07 14:57:10 +02:00
double precision , intent(out) :: ee_potential(walk_num)
integer*8 :: nw, i, j
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
if (elec_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
2022-08-07 14:57:10 +02:00
ee_potential = 0.0d0
do nw=1,walk_num
do j=2,elec_num
do i=1,j-1
if (dabs(ee_distance(i,j,nw)) > 1e-5) then
2022-08-07 14:57:10 +02:00
ee_potential(nw) = ee_potential(nw) + 1.0d0/(ee_distance(i,j,nw))
endif
end do
end do
end do
end function qmckl_compute_ee_potential_f
#+end_src
#+CALL: generate_c_header(table=qmckl_ee_potential_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+RESULTS:
#+begin_src c :tangle (eval h_func) :comments org
qmckl_exit_code qmckl_compute_ee_potential (
const qmckl_context context,
const int64_t elec_num,
const int64_t walk_num,
const double* ee_distance,
2022-08-07 14:57:10 +02:00
double* const ee_potential );
#+end_src
#+CALL: generate_c_interface(table=qmckl_ee_potential_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_ee_potential &
2022-08-07 14:57:10 +02:00
(context, elec_num, walk_num, ee_distance, ee_potential) &
bind(C) result(info)
use, intrinsic :: iso_c_binding
implicit none
integer (c_int64_t) , intent(in) , value :: context
integer (c_int64_t) , intent(in) , value :: elec_num
integer (c_int64_t) , intent(in) , value :: walk_num
real (c_double ) , intent(in) :: ee_distance(elec_num,elec_num,walk_num)
2022-08-07 14:57:10 +02:00
real (c_double ) , intent(out) :: ee_potential(walk_num)
integer(c_int32_t), external :: qmckl_compute_ee_potential_f
info = qmckl_compute_ee_potential_f &
2022-08-07 14:57:10 +02:00
(context, elec_num, walk_num, ee_distance, ee_potential)
end function qmckl_compute_ee_potential
#+end_src
*** Test
2021-10-15 13:05:50 +02:00
#+begin_src c :tangle (eval c_test)
2022-08-07 14:57:10 +02:00
double ee_potential[walk_num];
2021-10-15 13:05:50 +02:00
2022-08-07 14:57:10 +02:00
rc = qmckl_get_electron_ee_potential(context, &(ee_potential[0]));
2021-10-15 13:05:50 +02:00
assert (rc == QMCKL_SUCCESS);
#+end_src
2021-05-19 00:28:56 +02:00
** Electron-nucleus distances
2021-05-18 12:32:28 +02:00
*** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
qmckl_exit_code qmckl_get_electron_en_distance(qmckl_context context, double* distance);
#+end_src
2021-07-04 15:19:57 +02:00
#+begin_src f90 :tangle (eval fh_func) :comments org :exports none
interface
integer(c_int32_t) function qmckl_get_electron_en_distance(context, distance) &
bind(C)
use, intrinsic :: iso_c_binding
import
implicit none
integer (c_int64_t) , intent(in) , value :: context
real (c_double ) , intent(out) :: distance(*)
end function
end interface
#+end_src
2021-05-18 12:32:28 +02:00
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_get_electron_en_distance(qmckl_context context, double* distance)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
2021-05-19 00:28:56 +02:00
qmckl_exit_code rc;
2021-05-18 12:32:28 +02:00
rc = qmckl_provide_en_distance(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-05-18 12:32:28 +02:00
assert (ctx != NULL);
2022-08-07 14:57:10 +02:00
size_t sze = ctx->electron.num * ctx->nucleus.num * ctx->electron.walker.num;
2021-05-18 12:32:28 +02:00
memcpy(distance, ctx->electron.en_distance, sze * sizeof(double));
return QMCKL_SUCCESS;
}
#+end_src
*** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_provide_en_distance(qmckl_context context);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_provide_en_distance(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-05-18 12:32:28 +02:00
assert (ctx != NULL);
if (!(ctx->nucleus.provided)) {
2021-06-10 22:57:59 +02:00
return qmckl_failwith( context,
QMCKL_NOT_PROVIDED,
"qmckl_provide_en_distance",
NULL);
2021-05-18 12:32:28 +02:00
}
/* Compute if necessary */
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.point.date > ctx->electron.en_distance_date) {
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
free(ctx->electron.en_distance);
ctx->electron.en_distance = NULL;
}
2021-05-18 12:32:28 +02:00
/* Allocate array */
if (ctx->electron.en_distance == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = ctx->electron.num * ctx->nucleus.num *
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num * sizeof(double);
2021-05-18 12:32:28 +02:00
double* en_distance = (double*) qmckl_malloc(context, mem_info);
if (en_distance == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_en_distance",
NULL);
}
ctx->electron.en_distance = en_distance;
}
qmckl_exit_code rc =
qmckl_compute_en_distance(context,
ctx->electron.num,
ctx->nucleus.num,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
ctx->electron.walker.point.coord.data,
2022-01-23 16:18:46 +01:00
ctx->nucleus.coord.data,
2021-05-18 12:32:28 +02:00
ctx->electron.en_distance);
if (rc != QMCKL_SUCCESS) {
return rc;
}
ctx->electron.en_distance_date = ctx->date;
}
return QMCKL_SUCCESS;
}
#+end_src
*** Compute
:PROPERTIES:
:Name: qmckl_compute_en_distance
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_en_distance_args
2022-01-06 02:28:13 +01:00
| 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 |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
2022-04-04 17:30:38 +02:00
| ~elec_coord~ | ~double[3][walk_num][elec_num]~ | in | Electron coordinates |
2022-01-06 02:28:13 +01:00
| ~nucl_coord~ | ~double[3][elec_num]~ | in | Nuclear coordinates |
| ~en_distance~ | ~double[walk_num][nucl_num][elec_num]~ | out | Electron-nucleus distances |
2021-05-18 12:32:28 +02:00
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_en_distance_f(context, elec_num, nucl_num, walk_num, elec_coord, nucl_coord, en_distance) &
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: elec_num
integer*8 , intent(in) :: nucl_num
integer*8 , intent(in) :: walk_num
2022-01-23 16:18:46 +01:00
double precision , intent(in) :: elec_coord(elec_num,walk_num,3)
2021-05-19 00:28:56 +02:00
double precision , intent(in) :: nucl_coord(nucl_num,3)
2021-05-18 12:32:28 +02:00
double precision , intent(out) :: en_distance(elec_num,nucl_num,walk_num)
integer*8 :: k
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
if (elec_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
if (nucl_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_4
return
endif
do k=1,walk_num
info = qmckl_distance(context, 'T', 'T', elec_num, nucl_num, &
2022-01-23 16:18:46 +01:00
elec_coord(1,k,1), elec_num * walk_num, &
2021-05-18 12:32:28 +02:00
nucl_coord, nucl_num, &
en_distance(1,1,k), elec_num)
2021-05-19 00:28:56 +02:00
if (info /= QMCKL_SUCCESS) then
exit
endif
2021-05-18 12:32:28 +02:00
end do
end function qmckl_compute_en_distance_f
#+end_src
#+begin_src c :tangle (eval h_private_func) :comments org :exports none
qmckl_exit_code qmckl_compute_en_distance (
const qmckl_context context,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* elec_coord,
const double* nucl_coord,
double* const en_distance );
#+end_src
#+CALL: generate_c_interface(table=qmckl_en_distance_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_en_distance &
(context, elec_num, nucl_num, walk_num, elec_coord, nucl_coord, en_distance) &
bind(C) result(info)
use, intrinsic :: iso_c_binding
implicit none
integer (c_int64_t) , intent(in) , value :: context
integer (c_int64_t) , intent(in) , value :: elec_num
integer (c_int64_t) , intent(in) , value :: nucl_num
integer (c_int64_t) , intent(in) , value :: walk_num
2022-01-23 16:18:46 +01:00
real (c_double ) , intent(in) :: elec_coord(elec_num,walk_num,3)
2021-05-19 00:28:56 +02:00
real (c_double ) , intent(in) :: nucl_coord(elec_num,3)
2021-05-18 12:32:28 +02:00
real (c_double ) , intent(out) :: en_distance(elec_num,nucl_num,walk_num)
integer(c_int32_t), external :: qmckl_compute_en_distance_f
info = qmckl_compute_en_distance_f &
(context, elec_num, nucl_num, walk_num, elec_coord, nucl_coord, en_distance)
end function qmckl_compute_en_distance
#+end_src
*** Test
2021-05-19 01:35:34 +02:00
#+begin_src python :results output :exports none
import numpy as np
elec_1_w1 = np.array( [ -2.26995253563, -5.15737533569, -2.22940072417 ])
elec_2_w1 = np.array( [ 3.51983380318, -1.08717381954, -1.19617708027 ])
elec_1_w2 = np.array( [ -2.34410619736, -3.20016115904, -1.53496759012 ])
elec_2_w2 = np.array( [ 3.17996025085, -1.40260577202, 1.49473607540 ])
nucl_1 = np.array( [ 1.096243353458458e+00, 8.907054016973815e-01, 7.777092280258892e-01 ] )
nucl_2 = np.array( [ 1.168459237342663e+00, 1.125660720053393e+00, 2.833370314829343e+00 ] )
print ( "[0][0][0] : ", np.linalg.norm(elec_1_w1-nucl_1) )
print ( "[0][1][0] : ", np.linalg.norm(elec_1_w1-nucl_2) )
print ( "[0][0][1] : ", np.linalg.norm(elec_2_w1-nucl_1) )
print ( "[1][0][0] : ", np.linalg.norm(elec_1_w2-nucl_1) )
print ( "[1][1][0] : ", np.linalg.norm(elec_1_w2-nucl_2) )
print ( "[1][0][1] : ", np.linalg.norm(elec_2_w2-nucl_1) )
#+end_src
#+RESULTS:
: [0][0][0] : 7.546738741619978
: [0][1][0] : 8.77102435246984
: [0][0][1] : 3.698922010513608
: [1][0][0] : 5.824059436060509
: [1][1][0] : 7.080482110317645
: [1][0][1] : 3.1804527583077356
2021-05-18 12:32:28 +02:00
#+begin_src c :tangle (eval c_test)
2021-05-19 01:35:34 +02:00
2021-05-19 00:28:56 +02:00
assert(!qmckl_nucleus_provided(context));
2021-05-18 12:32:28 +02:00
assert(qmckl_electron_provided(context));
2021-05-19 00:28:56 +02:00
rc = qmckl_set_nucleus_num (context, nucl_num);
assert(rc == QMCKL_SUCCESS);
2022-01-23 16:18:46 +01:00
rc = qmckl_set_nucleus_charge (context, charge, nucl_num);
2021-05-19 00:28:56 +02:00
assert (rc == QMCKL_SUCCESS);
2022-01-23 16:18:46 +01:00
rc = qmckl_set_nucleus_coord (context, 'T', nucl_coord, 3*nucl_num);
2021-05-19 00:28:56 +02:00
assert (rc == QMCKL_SUCCESS);
assert(qmckl_nucleus_provided(context));
2021-05-19 01:35:34 +02:00
double en_distance[walk_num][nucl_num][elec_num];
2021-05-19 00:28:56 +02:00
rc = qmckl_get_electron_en_distance(context, &(en_distance[0][0][0]));
assert (rc == QMCKL_SUCCESS);
// (e,n,w) in Fortran notation
// (1,1,1)
2021-05-19 01:35:34 +02:00
assert(fabs(en_distance[0][0][0] - 7.546738741619978) < 1.e-12);
// (1,2,1)
assert(fabs(en_distance[0][1][0] - 8.77102435246984) < 1.e-12);
2021-05-19 00:28:56 +02:00
// (2,1,1)
assert(fabs(en_distance[0][0][1] - 3.698922010513608) < 1.e-12);
2021-05-19 01:35:34 +02:00
// (1,1,2)
assert(fabs(en_distance[1][0][0] - 5.824059436060509) < 1.e-12);
2021-05-19 00:28:56 +02:00
2021-05-19 01:35:34 +02:00
// (1,2,2)
assert(fabs(en_distance[1][1][0] - 7.080482110317645) < 1.e-12);
2021-05-19 00:28:56 +02:00
2021-05-19 01:35:34 +02:00
// (2,1,2)
assert(fabs(en_distance[1][0][1] - 3.1804527583077356) < 1.e-12);
2021-04-26 01:45:25 +02:00
#+end_src
** Electron-nucleus rescaled distances
2022-01-26 17:06:51 +01:00
~en_distance_rescaled~ stores the matrix of the rescaled distances between
2022-01-17 15:54:21 +01:00
electrons and nuclei.
2021-06-22 14:58:42 +02:00
\[
C_{ij} = \left( 1 - \exp{-\kappa C_{ij}}\right)/\kappa
\]
where \(C_{ij}\) 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
2022-01-23 16:18:46 +01:00
#+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;
}
qmckl_exit_code rc;
rc = qmckl_provide_en_distance_rescaled(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
size_t sze = ctx->electron.num * ctx->nucleus.num * ctx->electron.walker.num;
memcpy(distance_rescaled, ctx->electron.en_distance_rescaled, sze * sizeof(double));
return QMCKL_SUCCESS;
}
#+end_src
*** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_provide_en_distance_rescaled(qmckl_context context);
#+end_src
#+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;
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
if (!(ctx->nucleus.provided)) {
return QMCKL_NOT_PROVIDED;
}
/* Compute if necessary */
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.point.date > ctx->electron.en_distance_rescaled_date) {
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
free(ctx->electron.en_distance_rescaled);
ctx->electron.en_distance_rescaled = NULL;
}
/* Allocate array */
if (ctx->electron.en_distance_rescaled == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = ctx->electron.num * ctx->nucleus.num *
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num * sizeof(double);
double* en_distance_rescaled = (double*) qmckl_malloc(context, mem_info);
if (en_distance_rescaled == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_en_distance_rescaled",
NULL);
}
ctx->electron.en_distance_rescaled = en_distance_rescaled;
}
qmckl_exit_code rc =
qmckl_compute_en_distance_rescaled(context,
ctx->electron.num,
ctx->nucleus.num,
ctx->electron.rescale_factor_kappa_en,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
ctx->electron.walker.point.coord.data,
2022-01-23 16:18:46 +01:00
ctx->nucleus.coord.data,
ctx->electron.en_distance_rescaled);
if (rc != QMCKL_SUCCESS) {
return rc;
}
ctx->electron.en_distance_rescaled_date = ctx->date;
}
return QMCKL_SUCCESS;
}
#+end_src
*** Compute
:PROPERTIES:
:Name: qmckl_compute_en_distance_rescaled
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
2022-01-06 02:28:13 +01:00
#+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 |
| ~rescale_factor_kappa_en~ | ~double~ | in | The factor for rescaled distances |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
2022-04-04 17:30:38 +02:00
| ~elec_coord~ | ~double[3][walk_num][elec_num]~ | in | Electron coordinates |
2022-01-06 02:28:13 +01:00
| ~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, rescale_factor_kappa_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
integer*8 , intent(in) :: nucl_num
double precision , intent(in) :: rescale_factor_kappa_en
integer*8 , intent(in) :: walk_num
2022-01-23 16:18:46 +01:00
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 :: k
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
if (elec_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
if (nucl_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
! TODO: comparison with 0
!if (rescale_factor_kappa_en <= 0) then
! info = QMCKL_INVALID_ARG_4
! return
!endif
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_5
return
endif
do k=1,walk_num
info = qmckl_distance_rescaled(context, 'T', 'T', elec_num, nucl_num, &
2022-01-23 16:18:46 +01:00
elec_coord(1,k,1), elec_num*walk_num, &
nucl_coord, nucl_num, &
en_distance_rescaled(1,1,k), elec_num, rescale_factor_kappa_en)
if (info /= QMCKL_SUCCESS) then
exit
endif
end do
end function qmckl_compute_en_distance_rescaled_f
#+end_src
#+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 double rescale_factor_kappa_en,
const int64_t walk_num,
const double* elec_coord,
const double* nucl_coord,
double* const en_distance_rescaled );
#+end_src
#+CALL: generate_c_interface(table=qmckl_en_distance_rescaled_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_en_distance_rescaled &
(context, elec_num, nucl_num, rescale_factor_kappa_en, walk_num, elec_coord, nucl_coord, en_distance_rescaled) &
bind(C) result(info)
use, intrinsic :: iso_c_binding
implicit none
integer (c_int64_t) , intent(in) , value :: context
integer (c_int64_t) , intent(in) , value :: elec_num
integer (c_int64_t) , intent(in) , value :: nucl_num
real (c_double ) , intent(in) , value :: rescale_factor_kappa_en
integer (c_int64_t) , intent(in) , value :: walk_num
2022-01-23 16:18:46 +01:00
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)
integer(c_int32_t), external :: qmckl_compute_en_distance_rescaled_f
info = qmckl_compute_en_distance_rescaled_f &
(context, elec_num, nucl_num, rescale_factor_kappa_en, walk_num, elec_coord, nucl_coord, en_distance_rescaled)
end function qmckl_compute_en_distance_rescaled
#+end_src
*** Test
#+begin_src python :results output :exports none
import numpy as np
kappa = 1.0
elec_1_w1 = np.array( [ -2.26995253563, -5.15737533569, -2.22940072417 ])
elec_2_w1 = np.array( [ 3.51983380318, -1.08717381954, -1.19617708027 ])
elec_1_w2 = np.array( [ -2.34410619736, -3.20016115904, -1.53496759012 ])
elec_2_w2 = np.array( [ 3.17996025085, -1.40260577202, 1.49473607540 ])
nucl_1 = np.array( [ 1.096243353458458e+00, 8.907054016973815e-01, 7.777092280258892e-01 ] )
nucl_2 = np.array( [ 1.168459237342663e+00, 1.125660720053393e+00, 2.833370314829343e+00 ] )
print ( "[0][0][0] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_1_w1-nucl_1)) )/kappa )
print ( "[0][1][0] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_1_w1-nucl_2)) )/kappa )
print ( "[0][0][1] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_2_w1-nucl_1)) )/kappa )
print ( "[1][0][0] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_1_w2-nucl_1)) )/kappa )
print ( "[1][1][0] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_1_w2-nucl_2)) )/kappa )
print ( "[1][0][1] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_2_w2-nucl_1)) )/kappa )
#+end_src
#+RESULTS:
: [0][0][0] : 0.9994721712909764
: [0][1][0] : 0.9998448354439821
: [0][0][1] : 0.9752498074577688
: [1][0][0] : 0.9970444172399963
: [1][1][0] : 0.9991586325813303
: [1][0][1] : 0.9584331688679852
#+begin_src c :tangle (eval c_test)
assert(qmckl_electron_provided(context));
assert(qmckl_nucleus_provided(context));
double en_distance_rescaled[walk_num][nucl_num][elec_num];
rc = qmckl_get_electron_en_distance_rescaled(context, &(en_distance_rescaled[0][0][0]));
assert (rc == QMCKL_SUCCESS);
// (e,n,w) in Fortran notation
// (1,1,1)
assert(fabs(en_distance_rescaled[0][0][0] - 0.9994721712909764) < 1.e-12);
// (1,2,1)
assert(fabs(en_distance_rescaled[0][1][0] - 0.9998448354439821) < 1.e-12);
// (2,1,1)
assert(fabs(en_distance_rescaled[0][0][1] - 0.9752498074577688) < 1.e-12);
// (1,1,2)
assert(fabs(en_distance_rescaled[1][0][0] - 0.9970444172399963) < 1.e-12);
// (1,2,2)
assert(fabs(en_distance_rescaled[1][1][0] - 0.9991586325813303) < 1.e-12);
// (2,1,2)
assert(fabs(en_distance_rescaled[1][0][1] - 0.9584331688679852) < 1.e-12);
#+end_src
** Electron-nucleus rescaled distance gradients and laplacian with respect to electron coords
2022-01-26 17:06:51 +01:00
The rescaled distances which is given as $R = (1 - \exp{-\kappa r})/\kappa$
2021-06-01 10:15:09 +02:00
needs to be perturbed with respect to the nuclear coordinates.
2022-01-26 17:06:51 +01:00
This data is stored in the ~en_distance_rescaled_deriv_e~ tensor. The
The first three elements of this three index tensor ~[4][nucl_num][elec_num]~ gives the
2021-06-01 10:15:09 +02:00
derivatives in the x, y, and z directions $dx, dy, dz$ and the last index
gives the Laplacian $\partial x^2 + \partial y^2 + \partial z^2$.
*** Get
#+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
#+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)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
rc = qmckl_provide_en_distance_rescaled_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
size_t sze = 4 * ctx->electron.num * ctx->nucleus.num * ctx->electron.walker.num;
memcpy(distance_rescaled_deriv_e, ctx->electron.en_distance_rescaled_deriv_e, sze * sizeof(double));
return QMCKL_SUCCESS;
}
#+end_src
*** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_provide_en_distance_rescaled_deriv_e(qmckl_context context);
#+end_src
#+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;
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
assert (ctx != NULL);
if (!(ctx->nucleus.provided)) {
return QMCKL_NOT_PROVIDED;
}
/* Compute if necessary */
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.point.date > ctx->electron.en_distance_rescaled_deriv_e_date) {
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
free(ctx->electron.en_distance_rescaled_deriv_e);
ctx->electron.en_distance_rescaled_deriv_e = NULL;
}
/* Allocate array */
if (ctx->electron.en_distance_rescaled_deriv_e == NULL) {
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = 4 * ctx->electron.num * ctx->nucleus.num *
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num * sizeof(double);
double* en_distance_rescaled_deriv_e = (double*) qmckl_malloc(context, mem_info);
if (en_distance_rescaled_deriv_e == NULL) {
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_en_distance_rescaled_deriv_e",
NULL);
}
ctx->electron.en_distance_rescaled_deriv_e = en_distance_rescaled_deriv_e;
}
qmckl_exit_code rc =
qmckl_compute_en_distance_rescaled_deriv_e(context,
ctx->electron.num,
ctx->nucleus.num,
ctx->electron.rescale_factor_kappa_en,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
ctx->electron.walker.point.coord.data,
2022-01-23 16:18:46 +01:00
ctx->nucleus.coord.data,
ctx->electron.en_distance_rescaled_deriv_e);
if (rc != QMCKL_SUCCESS) {
return rc;
}
ctx->electron.en_distance_rescaled_deriv_e_date = ctx->date;
}
return QMCKL_SUCCESS;
}
#+end_src
*** 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
2022-01-06 02:28:13 +01:00
| 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 |
| ~rescale_factor_kappa_en~ | ~double~ | in | The factor for rescaled distances |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
2022-04-04 17:30:38 +02:00
| ~elec_coord~ | ~double[3][walk_num][elec_num]~ | in | Electron coordinates |
2022-01-06 02:28:13 +01:00
| ~nucl_coord~ | ~double[3][elec_num]~ | in | Nuclear coordinates |
2022-04-04 17:30:38 +02:00
| ~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, &
rescale_factor_kappa_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
integer*8 , intent(in) :: nucl_num
double precision , intent(in) :: rescale_factor_kappa_en
integer*8 , intent(in) :: walk_num
2022-01-23 16:18:46 +01:00
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)
integer*8 :: k
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
if (elec_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
if (nucl_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
! TODO: comparison with 0
!if (rescale_factor_kappa_en <= 0) then
! info = QMCKL_INVALID_ARG_4
! return
!endif
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_5
return
endif
do k=1,walk_num
info = qmckl_distance_rescaled_deriv_e(context, 'T', 'T', elec_num, nucl_num, &
2022-01-23 16:18:46 +01:00
elec_coord(1,k,1), elec_num*walk_num, &
nucl_coord, nucl_num, &
en_distance_rescaled_deriv_e(1,1,1,k), elec_num, rescale_factor_kappa_en)
if (info /= QMCKL_SUCCESS) then
exit
endif
end do
end function qmckl_compute_en_distance_rescaled_deriv_e_f
#+end_src
#+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 double rescale_factor_kappa_en,
const int64_t walk_num,
const double* elec_coord,
const double* nucl_coord,
double* const en_distance_rescaled_deriv_e );
#+end_src
#+CALL: generate_c_interface(table=qmckl_en_distance_rescaled_deriv_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_en_distance_rescaled_deriv_e &
(context, elec_num, nucl_num, rescale_factor_kappa_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
integer (c_int64_t) , intent(in) , value :: nucl_num
real (c_double ) , intent(in) , value :: rescale_factor_kappa_en
integer (c_int64_t) , intent(in) , value :: walk_num
2022-01-23 16:18:46 +01:00
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(elec_num,nucl_num,walk_num)
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, nucl_num, rescale_factor_kappa_en, walk_num, elec_coord, nucl_coord, en_distance_rescaled_deriv_e)
end function qmckl_compute_en_distance_rescaled_deriv_e
#+end_src
*** Test
2022-01-26 17:06:51 +01:00
#+begin_src python :results output :exports none
import numpy as np
# TODO
#+end_src
#+begin_src c :tangle (eval c_test)
assert(qmckl_electron_provided(context));
rc = qmckl_set_nucleus_rescale_factor (context, nucl_rescale_factor_kappa);
assert(rc == QMCKL_SUCCESS);
assert(qmckl_nucleus_provided(context));
double en_distance_rescaled_deriv_e[walk_num][4][nucl_num][elec_num];
rc = qmckl_get_electron_en_distance_rescaled_deriv_e(context, &(en_distance_rescaled_deriv_e[0][0][0][0]));
assert (rc == QMCKL_SUCCESS);
// TODO: check exact values
//// (e,n,w) in Fortran notation
//// (1,1,1)
2021-06-03 22:34:23 +02:00
//assert(fabs(en_distance_rescaled[0][0][0] - 7.546738741619978) < 1.e-12);
//
//// (1,2,1)
2021-06-03 22:34:23 +02:00
//assert(fabs(en_distance_rescaled[0][1][0] - 8.77102435246984) < 1.e-12);
//
//// (2,1,1)
2021-06-03 22:34:23 +02:00
//assert(fabs(en_distance_rescaled[0][0][1] - 3.698922010513608) < 1.e-12);
//
//// (1,1,2)
2021-06-03 22:34:23 +02:00
//assert(fabs(en_distance_rescaled[1][0][0] - 5.824059436060509) < 1.e-12);
//
//// (1,2,2)
2021-06-03 22:34:23 +02:00
//assert(fabs(en_distance_rescaled[1][1][0] - 7.080482110317645) < 1.e-12);
//
//// (2,1,2)
2021-06-03 22:34:23 +02:00
//assert(fabs(en_distance_rescaled[1][0][1] - 3.1804527583077356) < 1.e-12);
#+end_src
2021-10-15 12:44:37 +02:00
** Electron-nucleus potential
~en_potential~ stores the ~en~ potential energy
\[
\mathcal{V}_{en} = -\sum_{i=1}^{N_e}\sum_{A=1}^{N_n}\frac{Z_A}{r_{iA}}
\]
where \(\mathcal{V}_{en}\) is the ~en~ potential, \[r_{iA}\] the ~en~
distance and \[Z_A\] is the nuclear charge.
2022-01-26 17:06:51 +01:00
2021-10-15 12:44:37 +02:00
*** Get
#+begin_src c :comments org :tangle (eval h_func) :noweb yes
2022-08-07 14:57:10 +02:00
qmckl_exit_code qmckl_get_electron_en_potential(qmckl_context context, double* const en_potential);
2021-10-15 12:44:37 +02:00
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
2022-08-07 14:57:10 +02:00
qmckl_exit_code qmckl_get_electron_en_potential(qmckl_context context, double* const en_potential)
2021-10-15 12:44:37 +02:00
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
qmckl_exit_code rc;
rc = qmckl_provide_en_potential(context);
if (rc != QMCKL_SUCCESS) return rc;
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-10-15 12:44:37 +02:00
assert (ctx != NULL);
2022-08-07 14:57:10 +02:00
size_t sze = ctx->electron.walker.num * sizeof(double);
memcpy(en_potential, ctx->electron.en_potential, sze);
2021-10-15 12:44:37 +02:00
return QMCKL_SUCCESS;
}
#+end_src
2022-01-26 17:06:51 +01:00
2021-10-15 12:44:37 +02:00
*** Provide :noexport:
#+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none
qmckl_exit_code qmckl_provide_en_potential(qmckl_context context);
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_provide_en_potential(qmckl_context context)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
}
2022-04-05 11:03:38 +02:00
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
2021-10-15 12:44:37 +02:00
assert (ctx != NULL);
if (!ctx->electron.provided) return QMCKL_NOT_PROVIDED;
if (!ctx->nucleus.provided) return QMCKL_NOT_PROVIDED;
qmckl_exit_code rc = qmckl_provide_en_distance(context);
if (rc != QMCKL_SUCCESS) return rc;
2021-10-15 12:44:37 +02:00
/* Compute if necessary */
2022-08-07 14:57:10 +02:00
if (ctx->electron.walker.point.date > ctx->electron.en_potential_date) {
if (ctx->electron.walker.num > ctx->electron.walker_old.num) {
free(ctx->electron.en_potential);
ctx->electron.en_potential = NULL;
}
2021-10-15 12:44:37 +02:00
/* Allocate array */
2022-08-07 14:57:10 +02:00
if (ctx->electron.en_potential == NULL) {
2021-10-15 12:44:37 +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* en_potential = (double*) qmckl_malloc(context, mem_info);
2021-10-15 12:44:37 +02:00
2022-08-07 14:57:10 +02:00
if (en_potential == NULL) {
2021-10-15 12:44:37 +02:00
return qmckl_failwith( context,
QMCKL_ALLOCATION_FAILED,
"qmckl_en_potential",
NULL);
}
2022-08-07 14:57:10 +02:00
ctx->electron.en_potential = en_potential;
2021-10-15 12:44:37 +02:00
}
2022-02-16 15:14:41 +01:00
rc = qmckl_compute_en_potential(context,
2021-10-15 12:44:37 +02:00
ctx->electron.num,
ctx->nucleus.num,
2022-08-07 14:57:10 +02:00
ctx->electron.walker.num,
2022-01-23 16:18:46 +01:00
ctx->nucleus.charge.data,
2021-10-15 12:44:37 +02:00
ctx->electron.en_distance,
2022-08-07 14:57:10 +02:00
ctx->electron.en_potential);
2021-10-15 12:44:37 +02:00
if (rc != QMCKL_SUCCESS) {
return rc;
}
2022-08-07 14:57:10 +02:00
ctx->electron.en_potential_date = ctx->date;
2021-10-15 12:44:37 +02:00
}
return QMCKL_SUCCESS;
}
#+end_src
*** Compute
:PROPERTIES:
:Name: qmckl_compute_en_potential
:CRetType: qmckl_exit_code
:FRetType: qmckl_exit_code
:END:
#+NAME: qmckl_en_potential_args
2022-08-07 14:57:10 +02:00
| 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 |
| ~walk_num~ | ~int64_t~ | in | Number of walkers |
| ~charge~ | ~double[nucl_num]~ | in | charge of nucleus |
| ~en_distance~ | ~double[walk_num][nucl_num][elec_num]~ | in | Electron-electron rescaled distances |
| ~en_potential~ | ~double[walk_num]~ | out | Electron-electron potential |
2021-10-15 12:44:37 +02:00
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_en_potential_f(context, elec_num, nucl_num, walk_num, &
2022-08-07 14:57:10 +02:00
charge, en_distance, en_potential) &
2021-10-15 12:44:37 +02:00
result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in) :: context
integer*8 , intent(in) :: elec_num
integer*8 , intent(in) :: nucl_num
integer*8 , intent(in) :: walk_num
double precision , intent(in) :: charge(nucl_num)
double precision , intent(in) :: en_distance(elec_num,nucl_num,walk_num)
2022-08-07 14:57:10 +02:00
double precision , intent(out) :: en_potential(walk_num)
2021-10-15 12:44:37 +02:00
integer*8 :: nw, i, j
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
info = QMCKL_INVALID_CONTEXT
return
endif
if (elec_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
if (walk_num <= 0) then
info = QMCKL_INVALID_ARG_3
return
endif
2022-08-07 14:57:10 +02:00
en_potential = 0.0d0
2021-10-15 12:44:37 +02:00
do nw=1,walk_num
do j=1,nucl_num
do i=1,elec_num
if (dabs(en_distance(i,j,nw)) > 1e-5) then
2022-08-07 14:57:10 +02:00
en_potential(nw) = en_potential(nw) - charge(j)/(en_distance(i,j,nw))
endif
2021-10-15 12:44:37 +02:00
end do
end do
end do
end function qmckl_compute_en_potential_f
#+end_src
#+CALL: generate_c_header(table=qmckl_en_potential_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+RESULTS:
#+begin_src c :tangle (eval h_func) :comments org
qmckl_exit_code qmckl_compute_en_potential (
const qmckl_context context,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* charge,
const double* en_distance,
2022-08-07 14:57:10 +02:00
double* const en_potential );
2021-10-15 12:44:37 +02:00
#+end_src
#+CALL: generate_c_interface(table=qmckl_en_potential_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_en_potential &
2022-08-07 14:57:10 +02:00
(context, elec_num, nucl_num, walk_num, charge, en_distance, en_potential) &
2021-10-15 12:44:37 +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 :: elec_num
integer (c_int64_t) , intent(in) , value :: nucl_num
integer (c_int64_t) , intent(in) , value :: walk_num
real (c_double ) , intent(in) :: charge(nucl_num)
real (c_double ) , intent(in) :: en_distance(elec_num,nucl_num,walk_num)
2022-08-07 14:57:10 +02:00
real (c_double ) , intent(out) :: en_potential(walk_num)
2021-10-15 12:44:37 +02:00
integer(c_int32_t), external :: qmckl_compute_en_potential_f
info = qmckl_compute_en_potential_f &
2022-08-07 14:57:10 +02:00
(context, elec_num, nucl_num, walk_num, charge, en_distance, en_potential)
2021-10-15 12:44:37 +02:00
end function qmckl_compute_en_potential
#+end_src
*** Test
2021-10-15 13:05:50 +02:00
#+begin_src c :tangle (eval c_test)
2022-08-07 14:57:10 +02:00
double en_potential[walk_num];
2021-10-15 13:05:50 +02:00
2022-08-07 14:57:10 +02:00
rc = qmckl_get_electron_en_potential(context, &(en_potential[0]));
2021-10-15 13:05:50 +02:00
assert (rc == QMCKL_SUCCESS);
#+end_src
2022-01-26 17:06:51 +01:00
2022-01-17 15:54:21 +01:00
** Generate initial coordinates
*** Compute :noexport:
2022-04-04 17:30:38 +02:00
# begin_src f90 :comments org :tangle (eval f) :noweb yes
2022-01-17 15:54:21 +01:00
subroutine draw_init_points
implicit none
BEGIN_DOC
! Place randomly electrons around nuclei
END_DOC
integer :: iwalk
logical, allocatable :: do_elec(:)
integer :: acc_num
2022-01-26 17:06:51 +01:00
2022-01-17 15:54:21 +01:00
real, allocatable :: xmin(:,:)
2022-01-26 17:06:51 +01:00
2022-01-17 15:54:21 +01:00
integer :: i, j, k, l, kk
2022-01-26 17:06:51 +01:00
2022-01-17 15:54:21 +01:00
real :: norm
allocate (do_elec(elec_num), xmin(3,elec_num))
xmin = -huge(1.)
norm = 0.
do i=1,elec_alpha_num
do j=1,ao_num
norm += mo_coef_transp(i,j)*mo_coef_transp(i,j)
enddo
enddo
norm = sqrt(norm/float(elec_alpha_num))
call rinfo( irp_here, 'Norm : ', norm )
call rinfo( irp_here, 'mo_scale: ' , mo_scale )
mo_coef_transp = mo_coef_transp/norm
2022-01-26 17:06:51 +01:00
2022-01-17 15:54:21 +01:00
double precision :: qmc_ranf
real :: mo_max
do i=1,elec_alpha_num
l=1
xmin(1,i) = mo_coef_transp(i,1)*mo_coef_transp(i,1) - 0.001*qmc_ranf()
do j=2,ao_num
xmin(2,i) = mo_coef_transp(i,j)*mo_coef_transp(i,j) - 0.001*qmc_ranf()
if (xmin(2,i) > xmin(1,i) ) then
xmin(1,i) = xmin(2,i)
l = ao_nucl(j)
endif
enddo
xmin(1,i) = nucl_coord(l,1)
xmin(2,i) = nucl_coord(l,2)
xmin(3,i) = nucl_coord(l,3)
enddo
2022-01-26 17:06:51 +01:00
2022-01-17 15:54:21 +01:00
call iinfo(irp_here, 'Det num = ', det_num )
do k=1,elec_beta_num
i = k+elec_alpha_num
l=1
xmin(1,i) = mo_coef_transp(k,1)*mo_coef_transp(k,1) - 0.001*qmc_ranf()
do j=2,ao_num
xmin(2,i) = mo_coef_transp(k,j)*mo_coef_transp(k,j) - 0.001*qmc_ranf()
if (xmin(2,i) > xmin(1,i) ) then
xmin(1,i) = xmin(2,i)
l = ao_nucl(j)
endif
enddo
xmin(1,i) = nucl_coord(l,1)
xmin(2,i) = nucl_coord(l,2)
xmin(3,i) = nucl_coord(l,3)
enddo
2022-01-26 17:06:51 +01:00
2022-01-17 15:54:21 +01:00
call rinfo( irp_here, 'time step =', time_step )
do iwalk=1,walk_num
2022-01-26 17:06:51 +01:00
print *, 'Generating initial positions for walker', iwalk
2022-01-17 15:54:21 +01:00
acc_num = 0
do_elec = .True.
integer :: iter
do iter = 1,10000
if (acc_num >= elec_num) then
exit
endif
double precision :: gauss
real :: re_compute
re_compute = 0.
do while (re_compute < 1.e-6)
do i=1,elec_num
if (do_elec(i)) then
do l=1,3
elec_coord(i,l) = xmin(l,i) + 1.5*(0.5-qmc_ranf())
enddo
endif
enddo
TOUCH elec_coord
re_compute = minval(nucl_elec_dist(1:nucl_num,1:elec_num))
enddo
2022-01-26 17:06:51 +01:00
2022-01-17 15:54:21 +01:00
do i=1,elec_alpha_num
if (do_elec(i)) then
if ( mo_value_transp(i,i)**2 >= qmc_ranf()) then
acc_num += 1
do_elec(i) = .False.
endif
endif
enddo
2022-01-26 17:06:51 +01:00
2022-01-17 15:54:21 +01:00
do i=1,elec_beta_num
if (do_elec(i+elec_alpha_num)) then
if ( mo_value_transp(i,i+elec_alpha_num)**2 >= qmc_ranf()) then
acc_num += 1
do_elec(i+elec_alpha_num) = .False.
endif
endif
enddo
2022-01-26 17:06:51 +01:00
2022-01-17 15:54:21 +01:00
enddo
2022-01-26 17:06:51 +01:00
2022-01-17 15:54:21 +01:00
do l=1,3
do i=1,elec_num+1
elec_coord_full(i,l,iwalk) = elec_coord(i,l)
enddo
enddo
enddo
if (.not.is_worker) then
call ezfio_set_electrons_elec_coord_pool_size(walk_num)
call ezfio_set_electrons_elec_coord_pool(elec_coord_full)
endif
SOFT_TOUCH elec_coord elec_coord_full
deallocate (do_elec, xmin)
2022-01-26 17:06:51 +01:00
2022-01-17 15:54:21 +01:00
end
# end_src
2021-04-21 01:56:47 +02:00
* End of files :noexport:
2021-04-30 01:26:19 +02:00
2021-04-21 01:56:47 +02:00
#+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-04-21 01:56:47 +02:00
*** Test
#+begin_src c :tangle (eval c_test)
if (qmckl_context_destroy(context) != QMCKL_SUCCESS)
return QMCKL_FAILURE;
2021-05-11 16:41:03 +02:00
return 0;
2021-04-21 01:56:47 +02:00
}
#+end_src
2021-04-30 01:26:19 +02:00
*** Compute file names
2021-04-30 01:26:19 +02:00
#+begin_src emacs-lisp
; The following is required to compute the file names
(setq pwd (file-name-directory buffer-file-name))
(setq name (file-name-nondirectory (substring buffer-file-name 0 -4)))
(setq f (concat pwd name "_f.f90"))
(setq fh (concat pwd name "_fh.f90"))
(setq c (concat pwd name ".c"))
(setq h (concat name ".h"))
(setq h_private (concat name "_private.h"))
(setq c_test (concat pwd "test_" name ".c"))
(setq f_test (concat pwd "test_" name "_f.f90"))
; Minted
(require 'ox-latex)
(setq org-latex-listings 'minted)
(add-to-list 'org-latex-packages-alist '("" "listings"))
(add-to-list 'org-latex-packages-alist '("" "color"))
#+end_src
2021-04-21 01:56:47 +02:00
#+RESULTS:
| | color |
| | listings |
2021-04-30 01:26:19 +02:00
2021-04-21 01:56:47 +02:00
# -*- mode: org -*-
# vim: syntax=c
2021-04-30 01:26:19 +02:00
2021-04-21 01:56:47 +02:00