From 86a92f2494f0feed57d8366d26ab03b690c01925 Mon Sep 17 00:00:00 2001 From: v1j4y Date: Sun, 9 Oct 2022 00:03:45 +0200 Subject: [PATCH 1/4] Added size_max for set determinant. --- org/qmckl_determinant.org | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/org/qmckl_determinant.org b/org/qmckl_determinant.org index 78d54f1..3f03803 100644 --- a/org/qmckl_determinant.org +++ b/org/qmckl_determinant.org @@ -331,8 +331,8 @@ int64_t* qmckl_get_determinant_mo_index_beta (const qmckl_context context) { qmckl_exit_code qmckl_set_determinant_type (const qmckl_context context, const char t); qmckl_exit_code qmckl_set_determinant_det_num_alpha (const qmckl_context context, const int64_t det_num_alpha); qmckl_exit_code qmckl_set_determinant_det_num_beta (const qmckl_context context, const int64_t det_num_beta); -qmckl_exit_code qmckl_set_determinant_mo_index_alpha (const qmckl_context context, const int64_t* mo_index_alpha); -qmckl_exit_code qmckl_set_determinant_mo_index_beta (const qmckl_context context, const int64_t* mo_index_beta); +qmckl_exit_code qmckl_set_determinant_mo_index_alpha (const qmckl_context context, const int64_t* mo_index_alpha, const int64_t size_max); +qmckl_exit_code qmckl_set_determinant_mo_index_beta (const qmckl_context context, const int64_t* mo_index_beta, const int64_t size_max); #+end_src #+NAME:pre2 @@ -405,7 +405,7 @@ qmckl_exit_code qmckl_set_determinant_det_num_beta(qmckl_context context, const <> } -qmckl_exit_code qmckl_set_determinant_mo_index_alpha(qmckl_context context, const int64_t* mo_index_alpha) { +qmckl_exit_code qmckl_set_determinant_mo_index_alpha(qmckl_context context, const int64_t* mo_index_alpha, const int64_t size_max) { <> int32_t mask = 1 << 3; @@ -430,6 +430,13 @@ qmckl_exit_code qmckl_set_determinant_mo_index_alpha(qmckl_context context, con NULL); } + if (size_max * sizeof(int64_t) < mem_info.size) { + return qmckl_failwith( context, + QMCKL_INVALID_ARG_3, + "qmckl_set_determinant_mo_index_alpha", + "input array too small"); + } + memcpy(new_array, mo_index_alpha, mem_info.size); ctx->det.mo_index_alpha = new_array; @@ -437,7 +444,7 @@ qmckl_exit_code qmckl_set_determinant_mo_index_alpha(qmckl_context context, con <> } -qmckl_exit_code qmckl_set_determinant_mo_index_beta(qmckl_context context, const int64_t* mo_index_beta) { +qmckl_exit_code qmckl_set_determinant_mo_index_beta(qmckl_context context, const int64_t* mo_index_beta, const int64_t size_max) { <> int32_t mask = 1 << 4; @@ -462,6 +469,13 @@ qmckl_exit_code qmckl_set_determinant_mo_index_beta(qmckl_context context, cons NULL); } + if (size_max * sizeof(int64_t) < mem_info.size) { + return qmckl_failwith( context, + QMCKL_INVALID_ARG_3, + "qmckl_set_determinant_mo_index_beta", + "input array too small"); + } + memcpy(new_array, mo_index_beta, mem_info.size); ctx->det.mo_index_beta = new_array; From 77d399f4606da181c348ba440283c79feab33aaa Mon Sep 17 00:00:00 2001 From: v1j4y Date: Sun, 9 Oct 2022 00:04:03 +0200 Subject: [PATCH 2/4] Fixed error message. --- org/qmckl_electron.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org/qmckl_electron.org b/org/qmckl_electron.org index a7164d7..af06ba3 100644 --- a/org/qmckl_electron.org +++ b/org/qmckl_electron.org @@ -304,7 +304,7 @@ qmckl_set_electron_coord(qmckl_context context, if (coord == NULL) { return qmckl_failwith( context, - QMCKL_INVALID_ARG_3, + QMCKL_INVALID_ARG_4, "qmckl_set_electron_coord", "coord is a null pointer"); } From b925cac7e2d79c4144b4c1e980a99b44522906c1 Mon Sep 17 00:00:00 2001 From: v1j4y Date: Sun, 9 Oct 2022 00:04:15 +0200 Subject: [PATCH 3/4] Added provide local energy. --- org/qmckl_local_energy.org | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/org/qmckl_local_energy.org b/org/qmckl_local_energy.org index fbee7ae..a2314f1 100644 --- a/org/qmckl_local_energy.org +++ b/org/qmckl_local_energy.org @@ -177,6 +177,42 @@ typedef struct qmckl_local_energy_struct { Some values are initialized by default, and are not concerned by this mechanism. +** Access functions + + When all the data for the local energy have been provided, the following + function returns ~true~. + + #+begin_src c :comments org :tangle (eval h_func) +bool qmckl_local_energy_provided (const qmckl_context context); + #+end_src + + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none +bool qmckl_local_energy_provided(const qmckl_context context) { + + if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { + return false; + } + + qmckl_context_struct* const ctx = (qmckl_context_struct*) context; + assert (ctx != NULL); + + qmckl_exit_code rc; + + if(!qmckl_electron_provided(context)) return QMCKL_NOT_PROVIDED; + + if(!qmckl_nucleus_provided(context)) return QMCKL_NOT_PROVIDED; + + rc = qmckl_provide_ao_basis_ao_vgl(context); + if (rc != QMCKL_SUCCESS) return rc; + + rc = qmckl_provide_mo_basis_mo_vgl(context); + if (rc != QMCKL_SUCCESS) return rc; + + ctx->local_energy.provided = (ctx->local_energy.uninitialized == 0); + return ctx->local_energy.provided; +} + #+end_src + * Computation ** Kinetic energy :PROPERTIES: From b1103a1ae5b3c9bcfd8073ce8138c91538fd10b9 Mon Sep 17 00:00:00 2001 From: v1j4y Date: Sun, 9 Oct 2022 11:32:07 +0200 Subject: [PATCH 4/4] Fixed tests. --- org/qmckl_determinant.org | 4 ++-- org/qmckl_local_energy.org | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/org/qmckl_determinant.org b/org/qmckl_determinant.org index 3f03803..2f20c8a 100644 --- a/org/qmckl_determinant.org +++ b/org/qmckl_determinant.org @@ -1260,10 +1260,10 @@ qmckl_check(context, rc); rc = qmckl_set_determinant_det_num_beta (context, det_num_beta); qmckl_check(context, rc); -rc = qmckl_set_determinant_mo_index_alpha (context, &(mo_index_alpha[0][0][0])); +rc = qmckl_set_determinant_mo_index_alpha (context, &(mo_index_alpha[0][0][0]), det_num_alpha*chbrclf_walk_num*chbrclf_elec_up_num); qmckl_check(context, rc); -rc = qmckl_set_determinant_mo_index_beta (context, &(mo_index_beta[0][0][0])); +rc = qmckl_set_determinant_mo_index_beta (context, &(mo_index_beta[0][0][0]), det_num_beta*chbrclf_walk_num*chbrclf_elec_dn_num); qmckl_check(context, rc); // Get slater-determinant diff --git a/org/qmckl_local_energy.org b/org/qmckl_local_energy.org index a2314f1..0916e86 100644 --- a/org/qmckl_local_energy.org +++ b/org/qmckl_local_energy.org @@ -720,7 +720,7 @@ for(k = 0; k < det_num_alpha; ++k) mo_index_alpha[k][i][j] = j + 1; for(k = 0; k < det_num_beta; ++k) for(i = 0; i < chbrclf_walk_num; ++i) - for(j = 0; j < chbrclf_elec_up_num; ++j) + for(j = 0; j < chbrclf_elec_dn_num; ++j) mo_index_beta[k][i][j] = j + 1; rc = qmckl_set_determinant_type (context, typ); @@ -732,10 +732,10 @@ assert (rc == QMCKL_SUCCESS); rc = qmckl_set_determinant_det_num_beta (context, det_num_beta); assert (rc == QMCKL_SUCCESS); -rc = qmckl_set_determinant_mo_index_alpha (context, &(mo_index_alpha[0][0][0])); +rc = qmckl_set_determinant_mo_index_alpha (context, &(mo_index_alpha[0][0][0]), det_num_alpha*chbrclf_walk_num*chbrclf_elec_up_num); assert (rc == QMCKL_SUCCESS); -rc = qmckl_set_determinant_mo_index_beta (context, &(mo_index_beta[0][0][0])); +rc = qmckl_set_determinant_mo_index_beta (context, &(mo_index_beta[0][0][0]),det_num_beta*chbrclf_walk_num*chbrclf_elec_dn_num); assert (rc == QMCKL_SUCCESS); // Get alpha determinant