From 16595f898b588bb26209a7cc1c7c42f7cbfb347a Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 19 May 2021 01:35:34 +0200 Subject: [PATCH] Fixed Makefile --- Makefile.am | 3 + org/qmckl_electron.org | 287 +++++++++++++++++++++++++++++++---------- org/qmckl_nucleus.org | 15 ++- org/qmckl_tests.org | 6 +- 4 files changed, 233 insertions(+), 78 deletions(-) diff --git a/Makefile.am b/Makefile.am index 7f735dd..ee6255a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -155,6 +155,9 @@ $(qmckl_f): $(FH_FUNC_FILES) $(FH_TYPE_FILES) $(htmlize_el): $(srcdir)/tools/install_htmlize.sh $(htmlize_el) +tests/chbrclf.h: $(qmckl_h) + + generated.mk: $(ORG_FILES) python $(srcdir)/tools/build_makefile.py diff --git a/org/qmckl_electron.org b/org/qmckl_electron.org index b54aad6..aa8a17e 100644 --- a/org/qmckl_electron.org +++ b/org/qmckl_electron.org @@ -26,8 +26,7 @@ up-spin and down-spin electrons, and the electron coordinates. #include "config.h" #endif -#include "CHBrClF.h" - +#include "chbrclf.h" int main() { qmckl_context context; @@ -143,19 +142,26 @@ if ( (ctx->electron.uninitialized & mask) != 0) { *** Number of electrons #+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_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); #+end_src #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code -qmckl_get_electron_num (const qmckl_context context, int64_t* num) { +qmckl_get_electron_num (const qmckl_context context, int64_t* const num) { if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { return QMCKL_INVALID_CONTEXT; } + if (num == NULL) { + return qmckl_failwith( context, + QMCKL_INVALID_ARG_2, + "qmckl_get_electron_num", + "num is a null pointer"); + } + qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; assert (ctx != NULL); @@ -172,11 +178,18 @@ 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_get_electron_up_num (const qmckl_context context, int64_t* const up_num) { if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { return QMCKL_INVALID_CONTEXT; } + if (up_num == NULL) { + return qmckl_failwith( context, + QMCKL_INVALID_ARG_2, + "qmckl_get_electron_up_num", + "up_num is a null pointer"); + } + qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; assert (ctx != NULL); @@ -193,11 +206,18 @@ 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_get_electron_down_num (const qmckl_context context, int64_t* const down_num) { if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { return QMCKL_INVALID_CONTEXT; } + if (down_num == NULL) { + return qmckl_failwith( context, + QMCKL_INVALID_ARG_2, + "qmckl_get_electron_down_num", + "down_num is a null pointer"); + } + qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; assert (ctx != NULL); @@ -220,16 +240,23 @@ qmckl_get_electron_down_num (const qmckl_context context, int64_t* down_num) { the wave function. ~walk_num~ is the number of walkers. #+begin_src c :comments org :tangle (eval h_func) :exports none -qmckl_exit_code qmckl_get_electron_walk_num (const qmckl_context context, int64_t* walk_num); +qmckl_exit_code qmckl_get_electron_walk_num (const qmckl_context context, int64_t* const walk_num); #+end_src #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code -qmckl_get_electron_walk_num (const qmckl_context context, int64_t* walk_num) { +qmckl_get_electron_walk_num (const qmckl_context context, int64_t* const walk_num) { if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { return QMCKL_INVALID_CONTEXT; } + if (walk_num == NULL) { + return qmckl_failwith( context, + QMCKL_INVALID_ARG_2, + "qmckl_get_electron_walk_num", + "walk_num is a null pointer"); + } + qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; assert (ctx != NULL); @@ -248,31 +275,76 @@ qmckl_get_electron_walk_num (const qmckl_context context, int64_t* walk_num) { *** Electron coordinates Returns the current electron coordinates. The pointer is assumed - to point on a memory block of size ~3 * elec_num * walk_num~. In C - the order of the indices is ~[walk_num][3][elec_num]~ and in - Fortran it is ~(elec_num,3,walk_num)~. + to point on a memory block of size ~3 * elec_num * walk_num~. + The normal order of the indices is: + + | | Normal | Transposed | + |---------+---------------------------+---------------------------| + | C | ~[walk_num][elec_num][3]~ | ~[walk_num][3][elec_num]~ | + | Fortran | ~(3,elec_num,walk_num)~ | ~(elec_num,3,walk_num)~ | + #+begin_src c :comments org :tangle (eval h_func) :exports none -qmckl_exit_code qmckl_get_electron_coord (const qmckl_context context, double* coord); +qmckl_exit_code qmckl_get_electron_coord (const qmckl_context context, const char transp, double* const coord); #+end_src #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code -qmckl_get_electron_coord (const qmckl_context context, double* elec_coord) { +qmckl_get_electron_coord (const qmckl_context context, const char transp, double* const coord) { + if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { return QMCKL_INVALID_CONTEXT; } + 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"); + } + qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; assert (ctx != NULL); if ( !(ctx->electron.provided) ) { - return QMCKL_NOT_PROVIDED; + return qmckl_failwith( context, + QMCKL_NOT_PROVIDED, + "qmckl_get_electron_coord", + "electron data is not provided"); } + int64_t elec_num = ctx->electron.num; + int64_t walk_num = ctx->electron.walk_num; + assert (ctx->electron.coord_new != NULL); - memcpy(elec_coord, ctx->electron.coord_new, ctx->electron.num * ctx->electron.walk_num * 3 * sizeof(double)); + double* ptr1 = ctx->electron.coord_new; + double* ptr2 = coord; + + if (transp == 'N') { + qmckl_exit_code rc; + + for (int64_t i=0 ; i> - int64_t num; + if (transp != 'N' && transp != 'T') { + return qmckl_failwith( context, + QMCKL_INVALID_ARG_2, + "qmckl_set_electron_coord", + "transp should be 'N' or 'T'"); + } + + if (coord == NULL) { + return qmckl_failwith( context, + QMCKL_INVALID_ARG_3, + "qmckl_set_electron_coord", + "coord is a null pointer"); + } + + int64_t elec_num; qmckl_exit_code rc; - rc = qmckl_get_electron_num(context, &num); + rc = qmckl_get_electron_num(context, &elec_num); if (rc != QMCKL_SUCCESS) return rc; - if (num == 0L) { + if (elec_num == 0L) { return qmckl_failwith( context, QMCKL_FAILURE, "qmckl_set_electron_coord", - "num is not set"); + "elec_num is not set"); } int64_t walk_num; @@ -444,7 +533,22 @@ qmckl_set_electron_coord(qmckl_context context, const double* coord) { ctx->electron.coord_old = ctx->electron.coord_new; ctx->electron.coord_new = swap; - memcpy(ctx->electron.coord_new, coord, walk_num * num * 3 * sizeof(double)); + double* ptr1 = ctx->electron.coord_new; + if (transp == 'N') { + qmckl_exit_code rc; + + for (int64_t i=0 ; ielectron.coord_new_date = ctx->date; return QMCKL_SUCCESS; @@ -454,34 +558,22 @@ qmckl_set_electron_coord(qmckl_context context, const double* coord) { ** Test - #+begin_src python :results output :exports none :tangle none + #+begin_src python :results output :exports none import numpy as np #+end_src #+begin_src c :tangle (eval c_test) /* Reference input data */ -const int64_t walk_num = chbrclf_walk_num; -const int64_t elec_num = chbrclf_elec_num; -const int64_t elec_up_num = chbrclf_elec_up_num; -const int64_t elec_dn_num = chbrclf_elec_dn_num; -const double*** elec_coord = chbrclf_elec_coord; +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* elec_coord = &(chbrclf_elec_coord[0][0][0]); -const int64_t nucl_num = chbrclf_nucl_num; -const double* charge = chbrclf_charge; -const double** nucl_coord = chbrclf_nucl_coord; - -double* coord = (double*) malloc(walk_num*num*3*sizeof(double)); - -double* x = coord; -for (int i=0 ; inucleus.uninitialized & mask) != 0) { - return QMCKL_NOT_PROVIDED; + return qmckl_failwith( context, + QMCKL_NOT_PROVIDED, + "qmckl_get_nucleus_coord", + "nucleus data is not provided"); } - int64_t nucl_num; - qmckl_exit_code rc; - rc = qmckl_get_nucleus_num(context, &nucl_num); - if (rc != QMCKL_SUCCESS) return rc; + int64_t nucl_num = ctx->nucleus.num; assert (ctx->nucleus.coord != NULL); if (transp == 'N') { + qmckl_exit_code rc; + rc = qmckl_transpose(context, nucl_num, 3, ctx->nucleus.coord, nucl_num, coord, 3); if (rc != QMCKL_SUCCESS) return rc; + } else { + memcpy(coord, ctx->nucleus.coord, 3*nucl_num*sizeof(double)); + } return QMCKL_SUCCESS; diff --git a/org/qmckl_tests.org b/org/qmckl_tests.org index c9e48d3..77eedd4 100644 --- a/org/qmckl_tests.org +++ b/org/qmckl_tests.org @@ -42,9 +42,9 @@ Br -1.218470 -0.187436 -0.028227 #+begin_src c :tangle ../tests/chbrclf.h #define chbrclf_nucl_num ((int64_t) 5) -const double chbrclf_charge[chbrclf_nucl_num] = { 6., 1., 9., 17., 35. }; +double chbrclf_charge[chbrclf_nucl_num] = { 6., 1., 9., 17., 35. }; -const double chbrclf_nucl_coord[3][chbrclf_nucl_num] = +double chbrclf_nucl_coord[3][chbrclf_nucl_num] = { { 1.096243353458458e+00, 1.168459237342663e+00, 1.487097297712132e+00, 3.497663849983889e+00, -2.302574592081335e+00 }, { 8.907054016973815e-01, 1.125660720053393e+00, 3.119652484478797e+00, -1.302920810073182e+00, -3.542027060505035e-01 }, { 7.777092280258892e-01, 2.833370314829343e+00, -3.855438138411500e-01, -1.272220319439064e-01, -5.334129934317614e-02 } }; @@ -533,7 +533,7 @@ F 1 #define chbrclf_elec_num ((int64_t) 68) #define chbrclf_walk_num ((int64_t) 2) -const double chbrclf_elec_coord[chbrclf_walk_num][chbrclf_elec_num][3] = { { +double chbrclf_elec_coord[chbrclf_walk_num][chbrclf_elec_num][3] = { { {-2.26995253563, -5.15737533569, -2.22940072417}, { 3.51983380318, -1.08717381954, -1.19617708027}, {-1.66791832447, -3.11651110649, 2.11557179689},