UP | HOME

Electrons

Table of Contents

1 Context

The following data stored in the context:

uninitialized int32t Keeps bit set for uninitialized data
num int64t Total number of electrons
up_num int64t Number of up-spin electrons
down_num int64t Number of down-spin electrons
walk_num int64t Number of walkers
provided bool If true, electron is valid
coord_new double[walknum][3][num] New set of electron coordinates
coord_old double[walknum][3][num] Old set of electron coordinates
coord_new_date uint64t Last modification date of the coordinates
ee_distance double[walknum][num][num] Electron-electron distances
ee_distance_date uint64t Last modification date of the electron-electron distances

1.1 Data structure

typedef struct qmckl_electron_struct {
  int64_t   num;
  int64_t   up_num;
  int64_t   down_num;
  int64_t   walk_num;
  int64_t   coord_new_date;
  int64_t   ee_distance_date;
  double*   coord_new;
  double*   coord_old;
  double*   ee_distance;
  int32_t   uninitialized;
  bool      provided;
} qmckl_electron_struct;

The uninitialized integer contains one bit set to one for each initialization function which has not bee called. It becomes equal to zero after all initialization functions have been called. The struct is then initialized and provided == true.

1.2 TODO Access functions

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.

When all the data relative to electrons have been set, the following function returns true.

bool qmckl_electron_provided (const qmckl_context context);

1.3 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 initialized, the internal coord_new and coord_old arrays are both allocated.

qmckl_exit_code  qmckl_set_electron_num        (qmckl_context context, const int64_t up_num, const int64_t down_num);
qmckl_exit_code  qmckl_set_electron_walk_num   (qmckl_context context, const int64_t walk_num);
qmckl_exit_code  qmckl_set_electron_coord      (qmckl_context context, const double* coord);

To set the number of electrons, we give the number of up-spin and down-spin electrons to the context and we set the number of walkers.

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 overwritten. This can be done only when the data relative to electrons have been set.

1.4 Test

/* Reference input data */

#define up_num      ((int64_t) 3)
#define down_num    ((int64_t) 2)
#define walk_num    ((int64_t) 2)
#define num         (up_num+down_num)

double coord[walk_num*3*num] =
  { 7.303633091022677881e+00, 1.375868694453235719e+01, 1.167371490471771217e-01,
    4.547755371567960836e+00, 3.245907105524011182e+00, 2.410764357550297110e-01,
    5.932816068137344523e+00, 1.491671465549257469e+01, 3.825374039119375236e-01,
    7.347336142660052083e+00, 1.341946976062362129e+00, 1.648917914228352322e+00,
    5.735221530102248444e+00, 1.064667491680036271e+01, 4.227201772236627297e-01,
    8.099550978782254163e+00, 6.861498941099086757e+00, 4.015884841159429036e-02,
    1.014757367558326173e+01, 5.219335322173662917e+00, 5.037004126899931322e-02,
    1.484094322159507051e+01, 9.777903829455864226e+00, 5.243007994024882767e-02,
    9.081723054990456845e+00, 5.499568496038920173e+00, 2.910446438899221347e-02,
    2.583154239492383653e+00, 1.442282811294904432e+00, 6.387191629878670451e-02 };

/* --- */

qmckl_exit_code rc;

assert(!qmckl_electron_provided(context));

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);


rc = qmckl_set_electron_num (context, up_num, down_num);
assert(rc == QMCKL_SUCCESS);
assert(!qmckl_electron_provided(context));

rc = qmckl_get_electron_up_num (context, &n);
assert(rc == QMCKL_SUCCESS);
assert(n == up_num);

rc = qmckl_get_electron_down_num (context, &n);
assert(rc == QMCKL_SUCCESS);
assert(n == down_num);

rc = qmckl_get_electron_num (context, &n);
assert(rc == QMCKL_SUCCESS);
assert(n == num);


int64_t w;
rc = qmckl_get_electron_walk_num (context, &w);
assert(rc == QMCKL_NOT_PROVIDED);


rc = qmckl_set_electron_walk_num (context, walk_num);
assert(rc == QMCKL_SUCCESS);

rc = qmckl_get_electron_walk_num (context, &w);
assert(rc == QMCKL_SUCCESS);
assert(w == walk_num);

assert(qmckl_electron_provided(context));

rc = qmckl_set_electron_coord (context, coord);
assert(rc == QMCKL_SUCCESS);

/*
double coord2[walk_num*3*num];

rc = qmckl_get_electron_coord_new (context, coord2);
assert(rc == QMCKL_SUCCESS);
for (size_t i=0 ; i<3*num ; ++i) {
  assert( coord[i] == coord2[i] );
 }
 */

2 Computation

The computed data is stored in the context so that it can be reused by different kernels. To ensure that the data is valid, for each computed data the date of the context is stored when it is computed. To know if some data needs to be recomputed, we check if the date of the dependencies are more recent than the date of the data to compute. If it is the case, then the data is recomputed and the current date is stored.

2.1 Electron-electron distances

2.1.1 Get

qmckl_exit_code qmckl_get_electron_ee_distance(qmckl_context context, double* distance);

2.1.2 Compute

qmcklcontext context in Global state
int64t elecnum in Number of electrons
int64t walknum in Number of walkers
double coord[walknum][3][elecnum] in Electron coordinates
double eedistance[walknum][elecnum][elecnum] out Electron-electron distances
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
  double precision      , intent(in)  :: coord(elec_num,3,walk_num)
  double precision      , intent(out) :: ee_distance(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

  !$OMP PARALLEL DO DEFAULT(NONE) &
  !$OMP SHARED(elec_num, walk_num, coord, ee_distance)
  !$OMP PRIVATE(k)
  do k=1,walk_num
     info = qmckl_distance(context, 'T', 'T', elec_num, elec_num, &
          coord(1,1,k), elec_num, &
          coord(1,1,k), elec_num, &
          ee_distance(1,1,k), elec_num)
  end do
  !$OMP END PARALLEL DO

end function qmckl_compute_ee_distance_f

2.1.3 Test

/* Reference input data */

assert(qmckl_electron_provided(context));

double distance[walk_num*num*num];
rc = qmckl_get_electron_ee_distance(context, distance);
rc = qmckl_get_electron_ee_distance(context, distance);
assert(distance[0] == 0.);
assert(distance[1] == distance[num]);
assert(abs(distance[1]-8.6114953086801) < 1.e-12);

Author: TREX CoE

Created: 2021-05-15 Sat 23:32

Validate