1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-12-22 20:36:01 +01:00

Improve electron module

This commit is contained in:
Anthony Scemama 2021-05-15 23:19:13 +02:00
parent 20a5ec4cc3
commit 0fea378698
3 changed files with 117 additions and 45 deletions

3
org/Makefile Normal file
View File

@ -0,0 +1,3 @@
clean check all:
make -C ../ $@

View File

@ -96,20 +96,20 @@ typedef struct qmckl_electron_struct {
** Access functions
#+begin_src c :comments org :tangle (eval h_private_func) :exports none
int64_t qmckl_get_electron_num (const qmckl_context context);
int64_t qmckl_get_electron_up_num (const qmckl_context context);
int64_t qmckl_get_electron_down_num (const qmckl_context context);
int64_t qmckl_get_electron_walk_num (const qmckl_context context);
double* qmckl_get_electron_coord_new (const qmckl_context context);
double* qmckl_get_electron_coord_old (const qmckl_context context);
#+end_src
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~.
#+begin_src c :comments org :tangle (eval h_func)
bool qmckl_electron_provided (const qmckl_context context);
#+begin_src c :comments org :tangle (eval h_func) :exports none
qmckl_exit_code qmckl_get_electron_num (const qmckl_context context, int64_t* num);
qmckl_exit_code qmckl_get_electron_up_num (const qmckl_context context, int64_t* up_num);
qmckl_exit_code qmckl_get_electron_down_num (const qmckl_context context, int64_t* down_num);
qmckl_exit_code qmckl_get_electron_walk_num (const qmckl_context context, int64_t* walk_num);
qmckl_exit_code qmckl_get_electron_coord_new (const qmckl_context context, double* coord);
qmckl_exit_code qmckl_get_electron_coord_old (const qmckl_context context, double* coord);
#+end_src
#+NAME:post
@ -120,10 +120,11 @@ if ( (ctx->electron.uninitialized & mask) != 0) {
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
int64_t qmckl_get_electron_num (const qmckl_context context) {
qmckl_exit_code
qmckl_get_electron_num (const qmckl_context context, int64_t* num) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (char) 0;
return QMCKL_INVALID_CONTEXT;
}
qmckl_context_struct* const ctx = (qmckl_context_struct* const) context;
@ -132,72 +133,88 @@ int64_t qmckl_get_electron_num (const qmckl_context context) {
int32_t mask = 1;
if ( (ctx->electron.uninitialized & mask) != 0) {
return (int64_t) 0;
return QMCKL_NOT_PROVIDED;
}
assert (ctx->electron.num > (int64_t) 0);
return ctx->electron.num;
,*num = ctx->electron.num;
return QMCKL_SUCCESS;
}
int64_t qmckl_get_electron_up_num (const qmckl_context context) {
qmckl_exit_code
qmckl_get_electron_up_num (const qmckl_context context, int64_t* up_num) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (int64_t) 0;
return QMCKL_INVALID_CONTEXT;
}
qmckl_context_struct* const ctx = (qmckl_context_struct* const) context;
assert (ctx != NULL);
int32_t mask = 1 << 1;
int32_t mask = 1;
if ( (ctx->electron.uninitialized & mask) != 0) {
return (int64_t) 0;
return QMCKL_NOT_PROVIDED;
}
assert (ctx->electron.up_num > (int64_t) 0);
return ctx->electron.up_num;
,*up_num = ctx->electron.up_num;
return QMCKL_SUCCESS;
}
int64_t qmckl_get_electron_down_num (const qmckl_context context) {
qmckl_exit_code
qmckl_get_electron_down_num (const qmckl_context context, int64_t* down_num) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (int64_t) 0;
return QMCKL_INVALID_CONTEXT;
}
qmckl_context_struct* const ctx = (qmckl_context_struct* const) context;
assert (ctx != NULL);
int32_t mask = 1 << 2;
int32_t mask = 1;
if ( (ctx->electron.uninitialized & mask) != 0) {
return (int64_t) 0;
return QMCKL_NOT_PROVIDED;
}
assert (ctx->electron.down_num >= (int64_t) 0);
return ctx->electron.down_num;
,*down_num = ctx->electron.down_num;
return QMCKL_SUCCESS;
}
int64_t qmckl_get_electron_walk_num (const qmckl_context context) {
qmckl_exit_code
qmckl_get_electron_walk_num (const qmckl_context context, int64_t* walk_num) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (int64_t) 0;
return QMCKL_INVALID_CONTEXT;
}
qmckl_context_struct* const ctx = (qmckl_context_struct* const) context;
assert (ctx != NULL);
int32_t mask = 1 << 3;
int32_t mask = 2;
if ( (ctx->electron.uninitialized & mask) != 0) {
return (int64_t) 0;
return QMCKL_NOT_PROVIDED;
}
assert (ctx->electron.walk_num > (int64_t) 0);
return ctx->electron.walk_num;
,*walk_num = ctx->electron.walk_num;
return QMCKL_SUCCESS;
}
#+end_src
When all the data relative to electrons have been set, the
following function returns ~true~.
#+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) {
@ -215,7 +232,8 @@ bool qmckl_electron_provided(const qmckl_context context) {
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 ~coord_new~ and ~coord_old~ arrays are both allocated.
initialized, the internal ~coord_new~ and ~coord_old~ arrays are
both allocated.
#+begin_src c :comments org :tangle (eval h_func)
qmckl_exit_code qmckl_set_electron_num (qmckl_context context, const int64_t up_num, const int64_t down_num);
@ -277,9 +295,10 @@ return QMCKL_SUCCESS;
down-spin electrons to the context and we set the number of walkers.
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
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_num(qmckl_context context,
const int64_t up_num,
const int64_t down_num) {
<<pre2>>
if (up_num <= 0) {
@ -308,7 +327,9 @@ qmckl_exit_code qmckl_set_electron_num(qmckl_context context,
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_set_electron_walk_num(qmckl_context context, const int64_t walk_num) {
qmckl_exit_code
qmckl_set_electron_walk_num(qmckl_context context, const int64_t walk_num) {
<<pre2>>
if (walk_num <= 0) {
@ -333,10 +354,16 @@ qmckl_exit_code qmckl_set_electron_walk_num(qmckl_context context, const int64_t
electrons have been set.
#+begin_src c :comments org :tangle (eval c) :noweb yes :exports none
qmckl_exit_code qmckl_set_electron_coord(qmckl_context context, const double* coord) {
qmckl_exit_code
qmckl_set_electron_coord(qmckl_context context, const double* coord) {
<<pre2>>
const int64_t num = qmckl_get_electron_num(context);
int64_t num;
qmckl_exit_code rc;
rc = qmckl_get_electron_num(context, &num);
if (rc != QMCKL_SUCCESS) return rc;
if (num == 0L) {
return qmckl_failwith( context,
QMCKL_FAILURE,
@ -344,7 +371,10 @@ qmckl_exit_code qmckl_set_electron_coord(qmckl_context context, const double* c
"num is not set");
}
const int64_t walk_num = qmckl_get_electron_walk_num(context);
int64_t walk_num;
rc = qmckl_get_electron_walk_num(context, &walk_num);
if (rc != QMCKL_SUCCESS) return rc;
if (walk_num == 0L) {
return qmckl_failwith( context,
QMCKL_FAILURE,
@ -401,17 +431,53 @@ 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];
#+end_src
* Computation

View File

@ -87,7 +87,8 @@ typedef int32_t qmckl_exit_code;
| ~QMCKL_INVALID_CONTEXT~ | 103 | 'Invalid context' |
| ~QMCKL_ALLOCATION_FAILED~ | 104 | 'Allocation failed' |
| ~QMCKL_DEALLOCATION_FAILED~ | 105 | 'De-allocation failed' |
| ~QMCKL_INVALID_EXIT_CODE~ | 106 | 'Invalid exit code' |
| ~QMCKL_NOT_PROVIDED~ | 106 | 'Not provided' |
| ~QMCKL_INVALID_EXIT_CODE~ | 107 | 'Invalid exit code' |
# We need to force Emacs not to indent the Python code:
# -*- org-src-preserve-indentation: t
@ -134,7 +135,8 @@ return '\n'.join(result)
#define QMCKL_INVALID_CONTEXT ((qmckl_exit_code) 103)
#define QMCKL_ALLOCATION_FAILED ((qmckl_exit_code) 104)
#define QMCKL_DEALLOCATION_FAILED ((qmckl_exit_code) 105)
#define QMCKL_INVALID_EXIT_CODE ((qmckl_exit_code) 106)
#define QMCKL_NOT_PROVIDED ((qmckl_exit_code) 106)
#define QMCKL_INVALID_EXIT_CODE ((qmckl_exit_code) 107)
#+end_src
#+begin_src f90 :comments org :tangle (eval fh_type) :exports none
@ -154,7 +156,8 @@ return '\n'.join(result)
integer(qmckl_exit_code), parameter :: QMCKL_INVALID_CONTEXT = 103
integer(qmckl_exit_code), parameter :: QMCKL_ALLOCATION_FAILED = 104
integer(qmckl_exit_code), parameter :: QMCKL_DEALLOCATION_FAILED = 105
integer(qmckl_exit_code), parameter :: QMCKL_INVALID_EXIT_CODE = 106
integer(qmckl_exit_code), parameter :: QMCKL_NOT_PROVIDED = 106
integer(qmckl_exit_code), parameter :: QMCKL_INVALID_EXIT_CODE = 107
#+end_src
:end: