1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2025-01-03 18:16:28 +01:00

Renamed test file to n2 and fixed a few bugs. #162

This commit is contained in:
vijay gopal chilkuri 2021-07-05 14:37:09 +05:30
parent 931d364b1d
commit ad824d0f71
4 changed files with 204 additions and 116 deletions

View File

@ -27,7 +27,8 @@ these factors along with their derivatives.
#include "config.h"
#endif
#include "b2.h"
#include <stdio.h>
#include "n2.h"
int main() {
qmckl_context context;
@ -71,7 +72,7 @@ int main() {
The following data stored in the context:
#+NAME: qmckl_jastrow_args
|------------+-------------------------------------------+-----+-------------------------------------------------------------------|
|------------+--------------------------------------------+-----+-------------------------------------------------------------------|
| ~int32_t~ | ~uninitialized~ | in | Keeps bit set for uninitialized data |
| ~int64_t~ | ~aord_num~ | in | The number of a coeffecients |
| ~int64_t~ | ~bord_num~ | in | The number of b coeffecients |
@ -92,7 +93,7 @@ int main() {
computed data:
|-----------+--------------------------------------------------+-------------------------------------------------|
|-----------+---------------------------------------------------+-------------------------------------------------|
| ~int64_t~ | ~dim_cord_vec~ | Number of unique C coefficients |
| ~double~ | ~asymp_jasb[2]~ | Asymptotic component |
| ~int64_t~ | ~asymp_jasb_date~ | Asymptotic component |
@ -166,14 +167,9 @@ lkpm_of_cindex = [[1 , 1 , 2 , 0],
[3 , 0 , 5 , 1],
[1 , 0 , 5 , 2]]
print(np.array(lkpm_of_cindex).reshape(4,dim_cord_vec))
#+END_SRC
#+RESULTS: jastrow_data
: [[1 1 2 0 0 0 2 1 1 2 3 0 2 1 3 0 0 1 3 1 1 0 3]
: [1 1 3 4 0 2 2 4 0 0 2 4 1 3 1 4 0 1 1 4 1 2 0]
: [4 1 0 0 4 2 1 4 5 0 2 3 5 0 0 3 5 1 3 2 5 0 1]
: [2 5 1 4 1 5 0 2 1 5 1 0 1 5 2 3 0 5 1 1 0 5 2]]
** Data structure
@ -231,7 +227,7 @@ qmckl_exit_code qmckl_init_jastrow(qmckl_context context) {
qmckl_context_struct* const ctx = (qmckl_context_struct* const) context;
assert (ctx != NULL);
ctx->jastrow.uninitialized = (1 << 6) - 1;
ctx->jastrow.uninitialized = (1 << 5) - 1;
/* Default values */
@ -303,7 +299,7 @@ qmckl_exit_code qmckl_get_jastrow_aord_num (const qmckl_context context, int64_t
int32_t mask = 1 << 0;
if ( (ctx->jastrow.uninitialized & mask) != 0) {
return (char) 0;
return QMCKL_NOT_PROVIDED;
}
assert (ctx->jastrow.aord_num > 0);
@ -330,7 +326,7 @@ qmckl_exit_code qmckl_get_jastrow_bord_num (const qmckl_context context, int64_t
int32_t mask = 1 << 0;
if ( (ctx->jastrow.uninitialized & mask) != 0) {
return (char) 0;
return QMCKL_NOT_PROVIDED;
}
assert (ctx->jastrow.bord_num > 0);
@ -357,7 +353,7 @@ qmckl_exit_code qmckl_get_jastrow_cord_num (const qmckl_context context, int64_t
int32_t mask = 1 << 0;
if ( (ctx->jastrow.uninitialized & mask) != 0) {
return (char) 0;
return QMCKL_NOT_PROVIDED;
}
assert (ctx->jastrow.cord_num > 0);
@ -365,7 +361,7 @@ qmckl_exit_code qmckl_get_jastrow_cord_num (const qmckl_context context, int64_t
return QMCKL_SUCCESS;
}
qmckl_exit_code qmckl_get_type_nucl_num (const qmckl_context context, int64_t* const type_nucl_num) {
qmckl_exit_code qmckl_get_jastrow_type_nucl_num (const qmckl_context context, int64_t* const type_nucl_num) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (char) 0;
@ -381,10 +377,10 @@ qmckl_exit_code qmckl_get_type_nucl_num (const qmckl_context context, int64_t* c
qmckl_context_struct* const ctx = (qmckl_context_struct* const) context;
assert (ctx != NULL);
int32_t mask = 1 << 2;
int32_t mask = 1 << 1;
if ( (ctx->jastrow.uninitialized & mask) != 0) {
return (char) 0;
return QMCKL_NOT_PROVIDED;
}
assert (ctx->jastrow.type_nucl_num > 0);
@ -392,7 +388,7 @@ qmckl_exit_code qmckl_get_type_nucl_num (const qmckl_context context, int64_t* c
return QMCKL_SUCCESS;
}
qmckl_exit_code qmckl_get_aord_vector (const qmckl_context context, double * const aord_vector) {
qmckl_exit_code qmckl_get_jastrow_aord_vector (const qmckl_context context, double * const aord_vector) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (char) 0;
@ -408,10 +404,10 @@ qmckl_exit_code qmckl_get_aord_vector (const qmckl_context context, double * con
qmckl_context_struct* const ctx = (qmckl_context_struct* const) context;
assert (ctx != NULL);
int32_t mask = 1 << 3;
int32_t mask = 1 << 2;
if ( (ctx->jastrow.uninitialized & mask) != 0) {
return (char) 0;
return QMCKL_NOT_PROVIDED;
}
assert (ctx->jastrow.aord_vector != NULL);
@ -419,7 +415,7 @@ qmckl_exit_code qmckl_get_aord_vector (const qmckl_context context, double * con
return QMCKL_SUCCESS;
}
qmckl_exit_code qmckl_get_bord_vector (const qmckl_context context, double * const bord_vector) {
qmckl_exit_code qmckl_get_jastrow_bord_vector (const qmckl_context context, double * const bord_vector) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (char) 0;
@ -438,7 +434,7 @@ qmckl_exit_code qmckl_get_bord_vector (const qmckl_context context, double * con
int32_t mask = 1 << 3;
if ( (ctx->jastrow.uninitialized & mask) != 0) {
return (char) 0;
return QMCKL_NOT_PROVIDED;
}
assert (ctx->jastrow.bord_vector != NULL);
@ -446,7 +442,7 @@ qmckl_exit_code qmckl_get_bord_vector (const qmckl_context context, double * con
return QMCKL_SUCCESS;
}
qmckl_exit_code qmckl_get_cord_vector (const qmckl_context context, double * const cord_vector) {
qmckl_exit_code qmckl_get_jastrow_cord_vector (const qmckl_context context, double * const cord_vector) {
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return (char) 0;
@ -462,10 +458,10 @@ qmckl_exit_code qmckl_get_cord_vector (const qmckl_context context, double * con
qmckl_context_struct* const ctx = (qmckl_context_struct* const) context;
assert (ctx != NULL);
int32_t mask = 1 << 3;
int32_t mask = 1 << 4;
if ( (ctx->jastrow.uninitialized & mask) != 0) {
return (char) 0;
return QMCKL_NOT_PROVIDED;
}
assert (ctx->jastrow.cord_vector != NULL);
@ -503,8 +499,8 @@ qmckl_context_struct* const ctx = (qmckl_context_struct* const) context;
ctx->jastrow.uninitialized &= ~mask;
ctx->jastrow.provided = (ctx->jastrow.uninitialized == 0);
if (ctx->jastrow.provided) {
qmckl_exit_code rc_ = qmckl_finalize_basis(context);
if (rc_ != QMCKL_SUCCESS) return rc_;
//qmckl_exit_code rc_ = qmckl_set_jastrow_dependencies(context);
//if (rc_ != QMCKL_SUCCESS) return rc_;
}
return QMCKL_SUCCESS;
@ -536,7 +532,7 @@ qmckl_exit_code qmckl_set_jastrow_ord_num(qmckl_context context, const int64_t a
"cord_num <= 0");
}
int32_t mask = 1 << 1;
int32_t mask = 1 << 0;
ctx->jastrow.aord_num = aord_num;
ctx->jastrow.bord_num = bord_num;
ctx->jastrow.cord_num = cord_num;
@ -554,7 +550,7 @@ qmckl_exit_code qmckl_set_jastrow_type_nucl_num(qmckl_context context, const int
"type_nucl_num < 0");
}
int32_t mask = 1 << 2;
int32_t mask = 1 << 1;
ctx->jastrow.type_nucl_num = type_nucl_num;
<<post2>>
@ -563,12 +559,16 @@ qmckl_exit_code qmckl_set_jastrow_type_nucl_num(qmckl_context context, const int
qmckl_exit_code qmckl_set_jastrow_aord_vector(qmckl_context context, double const * aord_vector) {
<<pre2>>
int32_t mask = 1 << 3;
int32_t mask = 1 << 2;
int64_t aord_num;
qmckl_exit_code rc = qmckl_get_jastrow_aord_num(context, &aord_num);
if (rc != QMCKL_SUCCESS) return rc;
int64_t type_nucl_num;
rc = qmckl_get_jastrow_type_nucl_num(context, &type_nucl_num);
if (rc != QMCKL_SUCCESS) return rc;
if (aord_num == 0) {
return qmckl_failwith( context,
QMCKL_FAILURE,
@ -593,7 +593,7 @@ qmckl_exit_code qmckl_set_jastrow_aord_vector(qmckl_context context, double cons
}
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = aord_num * sizeof(double);
mem_info.size = (aord_num + 1) * type_nucl_num * sizeof(double);
double* new_array = (double*) qmckl_malloc(context, mem_info);
if(new_array == NULL) {
@ -613,7 +613,7 @@ qmckl_exit_code qmckl_set_jastrow_aord_vector(qmckl_context context, double cons
qmckl_exit_code qmckl_set_jastrow_bord_vector(qmckl_context context, double const * bord_vector) {
<<pre2>>
int32_t mask = 1 << 4;
int32_t mask = 1 << 3;
int64_t bord_num;
qmckl_exit_code rc = qmckl_get_jastrow_bord_num(context, &bord_num);
@ -643,7 +643,7 @@ qmckl_exit_code qmckl_set_jastrow_bord_vector(qmckl_context context, double cons
}
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = bord_num * sizeof(double);
mem_info.size = (bord_num + 1) * sizeof(double);
double* new_array = (double*) qmckl_malloc(context, mem_info);
if(new_array == NULL) {
@ -663,12 +663,16 @@ qmckl_exit_code qmckl_set_jastrow_bord_vector(qmckl_context context, double cons
qmckl_exit_code qmckl_set_jastrow_cord_vector(qmckl_context context, double const * cord_vector) {
<<pre2>>
int32_t mask = 1 << 5;
int32_t mask = 1 << 4;
int64_t cord_num;
qmckl_exit_code rc = qmckl_get_jastrow_cord_num(context, &cord_num);
if (rc != QMCKL_SUCCESS) return rc;
int64_t type_nucl_num;
rc = qmckl_get_jastrow_type_nucl_num(context, &type_nucl_num);
if (rc != QMCKL_SUCCESS) return rc;
if (cord_num == 0) {
return qmckl_failwith( context,
QMCKL_FAILURE,
@ -693,7 +697,7 @@ qmckl_exit_code qmckl_set_jastrow_cord_vector(qmckl_context context, double cons
}
qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero;
mem_info.size = cord_num * sizeof(double);
mem_info.size = cord_num * type_nucl_num * sizeof(double);
double* new_array = (double*) qmckl_malloc(context, mem_info);
if(new_array == NULL) {
@ -729,7 +733,7 @@ qmckl_exit_code qmckl_set_jastrow_dependencies(qmckl_context context) {
NULL);
}
int32_t mask = 1 << 6;
int32_t mask = 1 << 5;
<<post2>>
}
@ -794,20 +798,21 @@ qmckl_exit_code qmckl_finalize_jastrow(qmckl_context context) {
** Test
#+begin_src c :tangle (eval c_test)
/* Reference input data */
int64_t walk_num = b2_walk_num;
int64_t elec_num = b2_elec_num;
int64_t elec_up_num = b2_elec_up_num;
int64_t elec_dn_num = b2_elec_dn_num;
int64_t walk_num = n2_walk_num;
int64_t elec_num = n2_elec_num;
int64_t elec_up_num = n2_elec_up_num;
int64_t elec_dn_num = n2_elec_dn_num;
double rescale_factor_kappa_ee = 1.0;
double rescale_factor_kappa_en = 1.0;
double nucl_rescale_factor_kappa = 1.0;
double* elec_coord = &(b2_elec_coord[0][0][0]);
double* elec_coord = &(n2_elec_coord[0][0][0]);
int64_t nucl_num = b2_nucl_num;
double* charge = b2_charge;
double* nucl_coord = &(b2_nucl_coord[0][0]);
const double* nucl_charge = n2_charge;
int64_t nucl_num = n2_nucl_num;
double* charge = n2_charge;
double* nucl_coord = &(n2_nucl_coord[0][0]);
/* --- */
/* Provide Electron data */
qmckl_exit_code rc;
@ -890,6 +895,75 @@ for (int64_t i=0 ; i<3*elec_num ; ++i) {
assert( elec_coord[i] == elec_coord2[i] );
}
/* Provide Nucleus data */
assert(!qmckl_nucleus_provided(context));
rc = qmckl_get_nucleus_num (context, &n);
assert(rc == QMCKL_NOT_PROVIDED);
rc = qmckl_set_nucleus_num (context, nucl_num);
assert(rc == QMCKL_SUCCESS);
assert(!qmckl_nucleus_provided(context));
rc = qmckl_get_nucleus_num (context, &n);
assert(rc == QMCKL_SUCCESS);
assert(n == nucl_num);
double k;
rc = qmckl_get_nucleus_rescale_factor (context, &k);
assert(rc == QMCKL_SUCCESS);
assert(k == 1.0);
rc = qmckl_set_nucleus_rescale_factor (context, nucl_rescale_factor_kappa);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_get_nucleus_rescale_factor (context, &k);
assert(rc == QMCKL_SUCCESS);
assert(k == nucl_rescale_factor_kappa);
double nucl_coord2[3*nucl_num];
rc = qmckl_get_nucleus_coord (context, 'T', nucl_coord2);
assert(rc == QMCKL_NOT_PROVIDED);
rc = qmckl_set_nucleus_coord (context, 'T', &(nucl_coord[0]));
assert(rc == QMCKL_SUCCESS);
assert(!qmckl_nucleus_provided(context));
rc = qmckl_get_nucleus_coord (context, 'N', nucl_coord2);
assert(rc == QMCKL_SUCCESS);
for (size_t k=0 ; k<3 ; ++k) {
for (size_t i=0 ; i<nucl_num ; ++i) {
assert( nucl_coord[nucl_num*k+i] == nucl_coord2[3*i+k] );
}
}
rc = qmckl_get_nucleus_coord (context, 'T', nucl_coord2);
assert(rc == QMCKL_SUCCESS);
for (size_t i=0 ; i<3*nucl_num ; ++i) {
assert( nucl_coord[i] == nucl_coord2[i] );
}
double nucl_charge2[nucl_num];
rc = qmckl_get_nucleus_charge(context, nucl_charge2);
assert(rc == QMCKL_NOT_PROVIDED);
rc = qmckl_set_nucleus_charge(context, nucl_charge);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_get_nucleus_charge(context, nucl_charge2);
assert(rc == QMCKL_SUCCESS);
for (size_t i=0 ; i<nucl_num ; ++i) {
assert( nucl_charge[i] == nucl_charge2[i] );
}
assert(qmckl_nucleus_provided(context));
#+end_src
* Computation
@ -1033,11 +1107,13 @@ integer function qmckl_compute_asymp_jasb_f(context, bord_num, bord_vector, resc
info = QMCKL_INVALID_CONTEXT
return
endif
print *,"In Compute 1", asym_one
if (bord_num <= 0) then
info = QMCKL_INVALID_ARG_2
return
endif
print *,"In Compute 2", asym_one
asym_one = bord_vector(1) * kappa_inv / (1.0d0 + bord_vector(2) * kappa_inv)
asymp_jasb(:) = (/asym_one, 0.5d0 * asym_one/)
@ -1109,38 +1185,49 @@ for i in range(2):
asymp_jasb[i] += bord_vector[p + 1] * x
print("asym_one : ", asym_one)
print("asymp_jasb : ", asymp_jasb)
print("asymp_jasb[0] : ", asymp_jasb[0])
print("asymp_jasb[1] : ", asymp_jasb[1])
#+end_src
#+RESULTS:
: asym_one : 0.43340325572525706
: asymp_jasb : [0.53237506 0.31567343]
: asymp_jasb[0] : 0.5323750557252571
: asymp_jasb[1] : 0.31567342786262853
#+begin_src c :tangle (eval c_test)
assert(qmckl_electron_provided(context));
double* aord_vector = &(n2_aord_vector[0][0]);
double* bord_vector = &(n2_bord_vector[0]);
double* cord_vector = &(n2_cord_vector[0][0]);
double ee_distance[walk_num * elec_num * elec_num];
rc = qmckl_get_electron_ee_distance(context, ee_distance);
/* Initialize the Jastrow data */
rc = qmckl_init_jastrow(context);
assert(!qmckl_jastrow_provided(context));
// (e1,e2,w)
// (0,0,0) == 0.
//assert(ee_distance[0] == 0.);
//
//// (1,0,0) == (0,1,0)
//assert(ee_distance[1] == ee_distance[elec_num]);
//
//// value of (1,0,0)
//assert(fabs(ee_distance[1]-7.152322512964209) < 1.e-12);
//
//// (0,0,1) == 0.
//assert(ee_distance[elec_num*elec_num] == 0.);
//
//// (1,0,1) == (0,1,1)
//assert(ee_distance[elec_num*elec_num+1] == ee_distance[elec_num*elec_num+elec_num]);
//
//// value of (1,0,1)
//assert(fabs(ee_distance[elec_num*elec_num+1]-6.5517646321055665) < 1.e-12);
/* Set the data */
rc = qmckl_set_jastrow_ord_num(context, n2_aord_num, n2_bord_num, n2_cord_num);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_set_jastrow_type_nucl_num(context, n2_type_nucl_num);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_set_jastrow_aord_vector(context, aord_vector);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_set_jastrow_bord_vector(context, bord_vector);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_set_jastrow_cord_vector(context, cord_vector);
assert(rc == QMCKL_SUCCESS);
rc = qmckl_set_jastrow_dependencies(context);
assert(rc == QMCKL_SUCCESS);
/* Check if Jastrow is properly initialized */
assert(qmckl_jastrow_provided(context));
double asymp_jasb[2];
rc = qmckl_get_jastrow_asymp_jasb(context, asymp_jasb);
// calculate asymp_jasb
assert(fabs(asymp_jasb[0]-0.5323750557252571) < 1.e-12);
assert(fabs(asymp_jasb[1]-0.31567342786262853) < 1.e-12);
#+end_src

View File

@ -6,6 +6,7 @@ qmckl_numprec.org
qmckl_nucleus.org
qmckl_electron.org
qmckl_ao.org
qmckl_jastrow.org
qmckl_distance.org
qmckl_utils.org
qmckl_tests.org

View File

@ -1,18 +1,18 @@
#define b2_nucl_num ((int64_t) 2)
#define n2_nucl_num ((int64_t) 2)
double b2_charge[b2_nucl_num] = { 5., 5.};
double n2_charge[n2_nucl_num] = { 5., 5.};
double b2_nucl_coord[3][b2_nucl_num] =
double n2_nucl_coord[3][n2_nucl_num] =
{ {0.000000, 0.000000 },
{0.000000, 0.000000 },
{2.059801, 2.059801 } };
#define b2_elec_up_num ((int64_t) 5)
#define b2_elec_dn_num ((int64_t) 5)
#define b2_elec_num ((int64_t) 10)
#define b2_walk_num ((int64_t) 1)
#define n2_elec_up_num ((int64_t) 5)
#define n2_elec_dn_num ((int64_t) 5)
#define n2_elec_num ((int64_t) 10)
#define n2_walk_num ((int64_t) 1)
double b2_elec_coord[b2_walk_num][b2_elec_num][3] = { {
double n2_elec_coord[n2_walk_num][n2_elec_num][3] = { {
{-0.250655104764153 , 0.503070975550133 , -0.166554344502303},
{-0.587812193472177 , -0.128751981129274 , 0.187773606533075},
{ 1.61335569047166 , -0.615556732874863 , -1.43165470979934 },
@ -26,13 +26,13 @@ double b2_elec_coord[b2_walk_num][b2_elec_num][3] = { {
/* Jastrow related */
#define b2_type_nucl_num ((int64_t) 1)
#define b2_aord_num ((int64_t) 5)
#define b2_bord_num ((int64_t) 5)
#define b2_cord_num ((int64_t) 23)
#define b2_dim_cord_vec ((int64_t) 23)
#define n2_type_nucl_num ((int64_t) 1)
#define n2_aord_num ((int64_t) 5)
#define n2_bord_num ((int64_t) 5)
#define n2_cord_num ((int64_t) 23)
#define n2_dim_cord_vec ((int64_t) 23)
double b2_aord_vector[b2_aord_num + 1][b2_type_nucl_num] = {
double n2_aord_vector[n2_aord_num + 1][n2_type_nucl_num] = {
{ 0. },
{ 0. },
{-0.380512},
@ -40,7 +40,7 @@ double b2_aord_vector[b2_aord_num + 1][b2_type_nucl_num] = {
{-0.031558},
{ 0.021512}};
double b2_bord_vector[b2_bord_num + 1] = {
double n2_bord_vector[n2_bord_num + 1] = {
0.5 ,
0.15366 ,
0.0672262 ,
@ -48,7 +48,7 @@ double b2_bord_vector[b2_bord_num + 1] = {
0.0073096 ,
0.002866 };
double b2_cord_vector[b2_cord_num][b2_type_nucl_num] = {
double n2_cord_vector[n2_cord_num][n2_type_nucl_num] = {
{ 5.717020e-01},
{-5.142530e-01},
{-5.130430e-01},
@ -73,7 +73,7 @@ double b2_cord_vector[b2_cord_num][b2_type_nucl_num] = {
{-4.010475e-02},
{ 6.106710e-03}};
double b2_cord_vector_full[b2_dim_cord_vec][b2_nucl_num] = {
double n2_cord_vector_full[n2_dim_cord_vec][n2_nucl_num] = {
{ 5.717020e-01, 5.717020e-01},
{-5.142530e-01, -5.142530e-01},
{-5.130430e-01, -5.130430e-01},
@ -98,7 +98,7 @@ double b2_cord_vector_full[b2_dim_cord_vec][b2_nucl_num] = {
{-4.010475e-02, -4.010475e-02},
{ 6.106710e-03, 6.106710e-03}};
double b2_lkpm_of_cindex[4][b2_dim_cord_vec] = {
double n2_lkpm_of_cindex[4][n2_dim_cord_vec] = {
{1, 1, 2, 0, 0, 0, 2, 1, 1, 2, 3, 0, 2, 1, 3, 0, 0, 1, 3, 1, 1, 0, 3},
{1, 1, 3, 4, 0, 2, 2, 4, 0, 0, 2, 4, 1, 3, 1, 4, 0, 1, 1, 4, 1, 2, 0},
{4, 1, 0, 0, 4, 2, 1, 4, 5, 0, 2, 3, 5, 0, 0, 3, 5, 1, 3, 2, 5, 0, 1},