From edf40dc6ffd918c8b474dd7ebb286b9afc55d617 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 13 Dec 2024 01:13:54 +0100 Subject: [PATCH] Introduced many tests --- org/qmckl_electron.org | 30 +- org/qmckl_jastrow_champ.org | 650 ++++++++++++++++++++++++++++++------ 2 files changed, 573 insertions(+), 107 deletions(-) diff --git a/org/qmckl_electron.org b/org/qmckl_electron.org index c4370fa..a0297bc 100644 --- a/org/qmckl_electron.org +++ b/org/qmckl_electron.org @@ -678,25 +678,32 @@ for (int64_t i=0 ; i<3*elec_num*walk_num ; ++i) { *** Get #+begin_src c :comments org :tangle (eval h_func) :noweb yes -qmckl_exit_code qmckl_get_electron_ee_distance(qmckl_context context, double* const distance); +qmckl_exit_code +qmckl_get_electron_ee_distance(qmckl_context context, + double* const distance, + const int64_t size_max); #+end_src #+begin_src f90 :tangle (eval fh_func) :comments org :exports none interface - integer(c_int32_t) function qmckl_get_electron_ee_distance(context, distance) & + integer(c_int32_t) function qmckl_get_electron_ee_distance(context, distance, size_max) & bind(C) use, intrinsic :: iso_c_binding import implicit none integer (c_int64_t) , intent(in) , value :: context real (c_double ) , intent(out) :: distance(*) + integer (c_int64_t) , intent(in) :: size_max end function end interface #+end_src #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none -qmckl_exit_code qmckl_get_electron_ee_distance(qmckl_context context, double* const distance) +qmckl_exit_code +qmckl_get_electron_ee_distance(qmckl_context context, + double* const distance, + const int64_t size_max) { if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { return QMCKL_NULL_CONTEXT; @@ -707,10 +714,23 @@ qmckl_exit_code qmckl_get_electron_ee_distance(qmckl_context context, double* co rc = qmckl_provide_ee_distance(context); if (rc != QMCKL_SUCCESS) return rc; + if (distance == NULL) { + return qmckl_failwith( context, + QMCKL_INVALID_ARG_2, + "qmckl_get_electron_ee_distance", + "distance is a null pointer"); + } + qmckl_context_struct* const ctx = (qmckl_context_struct*) context; assert (ctx != NULL); - size_t sze = ctx->electron.num * ctx->electron.num * ctx->electron.walker.num; + const int64_t sze = ctx->electron.num * ctx->electron.num * ctx->electron.walker.num; + if (size_max < sze) { + return qmckl_failwith( context, + QMCKL_INVALID_ARG_3, + "qmckl_get_electron_ee_distance", + "size_max < num*num*walk_num"); + } memcpy(distance, ctx->electron.ee_distance, sze * sizeof(double)); return QMCKL_SUCCESS; @@ -901,7 +921,7 @@ assert(qmckl_electron_provided(context)); double ee_distance[walk_num * elec_num * elec_num]; -rc = qmckl_get_electron_ee_distance(context, ee_distance); +rc = qmckl_get_electron_ee_distance(context, ee_distance, walk_num * elec_num * elec_num); // (e1,e2,w) // (0,0,0) == 0. diff --git a/org/qmckl_jastrow_champ.org b/org/qmckl_jastrow_champ.org index b0702e4..ec6bb97 100644 --- a/org/qmckl_jastrow_champ.org +++ b/org/qmckl_jastrow_champ.org @@ -129,7 +129,6 @@ int main() { #+end_src - * Context :PROPERTIES: :Name: qmckl_jastrow_champ @@ -2039,7 +2038,7 @@ qmckl_exit_code qmckl_compute_jastrow_champ_asymp_jasb (const qmckl_context cont #ifdef HAVE_HPC return qmckl_compute_jastrow_champ_asymp_jasb_hpc #else - return qmckl_compute_jastrow_champ_asymp_jasb_doc + return qmckl_compute_jastrow_champ_asymp_jasb_doc #endif (context, bord_num, b_vector, rescale_factor_ee, spin_independent, asymp_jasb); } @@ -2154,15 +2153,39 @@ for (int i=0 ; ijastrow_champ.ee_distance_rescaled_date = ctx->date; + ctx->jastrow_champ.ee_distance_rescaled_gl_date = ctx->date; } return QMCKL_SUCCESS; @@ -2826,7 +2883,7 @@ assert(qmckl_electron_provided(context)); for (int64_t i = 0; i < elec_num; i++) { for (int64_t k = 0; k < 3; k++) { for (int64_t m = -4; m <= 4; m++) { // Apply finite difference displacement - + for (int64_t nw=0 ; nwelectron.num * ctx->nucleus.num * ctx->electron.walker.num; if (size_max < sze) { @@ -4741,7 +4938,7 @@ print ( "[0][6] : ", (1.0 - np.exp(-kappa * np.linalg.norm(elec_6_w1-nucl_1)) )/ : [0][6] : 0.4726452953409436 #+begin_src c :tangle (eval c_test) - +{ assert(qmckl_electron_provided(context)); assert(qmckl_nucleus_provided(context)); @@ -4768,7 +4965,29 @@ assert(fabs(en_distance_rescaled[0][1][5] - 1.2091967687767369) < 1.e-12); // (2,1,2) assert(fabs(en_distance_rescaled[0][0][6] - 0.4726452953409436) < 1.e-12); +} +{ + printf("en_distance_rescaled_hpc\n"); + + double en_distance_rescaled_doc[walk_num*nucl_num*elec_num]; + memset(&(en_distance_rescaled_doc[0]), 0, walk_num*nucl_num*elec_num*sizeof(double)); + rc = qmckl_compute_en_distance_rescaled_doc(context, elec_num, nucl_num, type_nucl_num, + type_nucl_vector, rescale_factor_en, walk_num, + elec_coord, nucl_coord, en_distance_rescaled_doc); + assert(rc == QMCKL_SUCCESS); + + double en_distance_rescaled_hpc[walk_num*nucl_num*elec_num]; + memset(&(en_distance_rescaled_hpc[0]), 0, walk_num*nucl_num*elec_num*sizeof(double)); + rc = qmckl_compute_en_distance_rescaled_hpc(context, elec_num, nucl_num, type_nucl_num, + type_nucl_vector, rescale_factor_en, walk_num, + elec_coord, nucl_coord, en_distance_rescaled_hpc); + assert(rc == QMCKL_SUCCESS); + + for (int64_t i=0 ; ielectron.walker.num; if (size_max < sze) { @@ -5696,6 +5936,37 @@ rc = qmckl_get_jastrow_champ_factor_en(context, factor_en,walk_num); printf("%f %f\n", factor_en[0], 22.781375792083587); assert(fabs(22.781375792083587 - factor_en[0]) < 1.e-12); +{ + printf("factor_en_hpc\n"); + double asymp_jasa[type_nucl_num]; + rc = qmckl_get_jastrow_champ_asymp_jasa(context, asymp_jasa, type_nucl_num); + assert(rc == QMCKL_SUCCESS); + + double en_distance_rescaled[walk_num*nucl_num*elec_num]; + rc = qmckl_get_jastrow_champ_en_distance_rescaled(context, + en_distance_rescaled, + walk_num*nucl_num*elec_num); + assert(rc == QMCKL_SUCCESS); + + double factor_en_doc[walk_num]; + memset(&(factor_en_doc[0]), 0, sizeof(factor_en_doc)); + rc = qmckl_compute_jastrow_champ_factor_en_doc (context, + walk_num, elec_num, nucl_num, type_nucl_num, type_nucl_vector, + aord_num, a_vector, + en_distance_rescaled, asymp_jasa, factor_en_doc); + assert(rc == QMCKL_SUCCESS); + + double factor_en_hpc[walk_num]; + rc = qmckl_compute_jastrow_champ_factor_en_hpc (context, + walk_num, elec_num, nucl_num, type_nucl_num, type_nucl_vector, + aord_num, a_vector, + en_distance_rescaled, asymp_jasa, factor_en_hpc); + assert(rc == QMCKL_SUCCESS); + + for (int64_t i = 0; i < walk_num; i++) { + assert(fabs(factor_en_doc[i] - factor_en_hpc[i]) < 1.e-12); + } +} #+end_src *** Derivative @@ -6284,7 +6555,7 @@ assert(qmckl_jastrow_champ_provided(context)); for (int64_t i = 0; i < elec_num; i++) { for (int64_t k = 0; k < 3; k++) { for (int64_t m = -4; m <= 4; m++) { // Apply finite difference displacement - + for (int64_t nw=0 ; nwelectron.walker.num * ctx->electron.num; - + if (size_max < sze) { return qmckl_failwith( context, QMCKL_INVALID_ARG_3, @@ -11931,7 +12378,6 @@ qmckl_exit_code qmckl_compute_jastrow_champ_gl ( **** Test - #+begin_src c :tangle (eval c_test) printf("Total Jastrow derivatives\n"); /* Check if Jastrow is properly initialized */