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

Fixed Makefile

This commit is contained in:
Anthony Scemama 2021-05-19 01:35:34 +02:00
parent 1504330500
commit 16595f898b
4 changed files with 233 additions and 78 deletions

View File

@ -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

View File

@ -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<walk_num ; ++i) {
rc = qmckl_transpose(context, elec_num, 3,
ptr1, elec_num, ptr2, 3);
if (rc != QMCKL_SUCCESS) return rc;
ptr1 += elec_num * 3;
ptr2 += elec_num * 3;
}
} else {
memcpy(ptr2, ptr1, 3*elec_num*walk_num*sizeof(double));
}
return QMCKL_SUCCESS;
}
@ -288,7 +360,7 @@ qmckl_get_electron_coord (const qmckl_context context, double* elec_coord) {
#+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);
qmckl_exit_code qmckl_set_electron_walk_num (qmckl_context context, const int64_t walk_num);
qmckl_exit_code qmckl_set_electron_coord (qmckl_context context, const double* coord);
qmckl_exit_code qmckl_set_electron_coord (qmckl_context context, const char transp, const double* coord);
#+end_src
#+NAME:pre2
@ -402,22 +474,39 @@ qmckl_set_electron_walk_num(qmckl_context context, const int64_t walk_num) {
overwritten. This can be done only when the data relative to
electrons have been set.
Important: changing the electron coordinates increments the date
in the context.
#+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_set_electron_coord(qmckl_context context, const char transp, const double* coord) {
<<pre2>>
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 ; i<walk_num ; ++i) {
rc = qmckl_transpose(context, 3, elec_num,
&(coord[i*3*elec_num]), 3, ptr1, elec_num);
if (rc != QMCKL_SUCCESS) return rc;
ptr1 += elec_num * 3;
}
} else {
memcpy(ptr1, coord, 3*elec_num*walk_num*sizeof(double));
}
ctx->electron.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 ; i<walk_num ; ++i) {
for (int k=0 ; k<3 ; ++k) {
for (int j=0 ; j<num ; ++j) {
,*x = coord_in[i][j][k];
x += 1;
}
}
}
int64_t nucl_num = chbrclf_nucl_num;
double* charge = chbrclf_charge;
double* nucl_coord = &(chbrclf_nucl_coord[0][0]);
/* --- */
@ -500,21 +592,21 @@ rc = qmckl_get_electron_down_num (context, &n);
assert(rc == QMCKL_NOT_PROVIDED);
rc = qmckl_set_electron_num (context, up_num, down_num);
rc = qmckl_set_electron_num (context, elec_up_num, elec_dn_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);
assert(n == elec_up_num);
rc = qmckl_get_electron_down_num (context, &n);
assert(rc == QMCKL_SUCCESS);
assert(n == down_num);
assert(n == elec_dn_num);
rc = qmckl_get_electron_num (context, &n);
assert(rc == QMCKL_SUCCESS);
assert(n == num);
assert(n == elec_num);
int64_t w;
@ -531,15 +623,15 @@ assert(w == walk_num);
assert(qmckl_electron_provided(context));
rc = qmckl_set_electron_coord (context, coord);
rc = qmckl_set_electron_coord (context, 'N', elec_coord);
assert(rc == QMCKL_SUCCESS);
double coord2[walk_num*3*num];
double elec_coord2[walk_num*3*elec_num];
rc = qmckl_get_electron_coord (context, coord2);
rc = qmckl_get_electron_coord (context, 'N', elec_coord2);
assert(rc == QMCKL_SUCCESS);
for (size_t i=0 ; i<3*num ; ++i) {
assert( coord[i] == coord2[i] );
for (int64_t i=0 ; i<3*elec_num ; ++i) {
assert( elec_coord[i] == elec_coord2[i] );
}
#+end_src
@ -559,11 +651,11 @@ for (size_t i=0 ; i<3*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* distance);
qmckl_exit_code qmckl_get_electron_ee_distance(qmckl_context context, double* const distance);
#+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* distance)
qmckl_exit_code qmckl_get_electron_ee_distance(qmckl_context context, double* const distance)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return QMCKL_NULL_CONTEXT;
@ -731,10 +823,35 @@ qmckl_exit_code qmckl_compute_ee_distance (
*** Test
#+begin_src python :results output :exports none
import numpy as np
elec_1_w1 = np.array( [ -2.26995253563, -5.15737533569, -2.22940072417 ])
elec_2_w1 = np.array( [ 3.51983380318, -1.08717381954, -1.19617708027 ])
elec_1_w2 = np.array( [ -2.34410619736, -3.20016115904, -1.53496759012 ])
elec_2_w2 = np.array( [ 3.17996025085, -1.40260577202, 1.49473607540 ])
print ( "[0][0][0] : ", np.linalg.norm(elec_1_w1-elec_1_w1) )
print ( "[0][1][0] : ", np.linalg.norm(elec_1_w1-elec_2_w1) )
print ( "[1][0][0] : ", np.linalg.norm(elec_2_w1-elec_1_w1) )
print ( "[0][0][1] : ", np.linalg.norm(elec_1_w2-elec_1_w2) )
print ( "[0][1][1] : ", np.linalg.norm(elec_1_w2-elec_2_w2) )
print ( "[1][0][1] : ", np.linalg.norm(elec_2_w2-elec_1_w2) )
#+end_src
#+RESULTS:
: [0][0][0] : 0.0
: [0][1][0] : 7.152322512964209
: [1][0][0] : 7.152322512964209
: [0][0][1] : 0.0
: [0][1][1] : 6.5517646321055665
: [1][0][1] : 6.5517646321055665
#+begin_src c :tangle (eval c_test)
assert(qmckl_electron_provided(context));
double ee_distance[walk_num*num*num];
double ee_distance[walk_num * elec_num * elec_num];
rc = qmckl_get_electron_ee_distance(context, ee_distance);
// (e1,e2,w)
@ -742,19 +859,19 @@ rc = qmckl_get_electron_ee_distance(context, ee_distance);
assert(ee_distance[0] == 0.);
// (1,0,0) == (0,1,0)
assert(ee_distance[1] == ee_distance[num]);
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[num*num] == 0.);
assert(ee_distance[elec_num*elec_num] == 0.);
// (1,0,1) == (0,1,1)
assert(ee_distance[num*num+1] == ee_distance[num*num+num]);
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[num*num+1]-6.5517646321055665) < 1.e-12);
assert(fabs(ee_distance[elec_num*elec_num+1]-6.5517646321055665) < 1.e-12);
#+end_src
@ -954,7 +1071,34 @@ qmckl_exit_code qmckl_compute_en_distance (
*** Test
#+begin_src python :results output :exports none
import numpy as np
elec_1_w1 = np.array( [ -2.26995253563, -5.15737533569, -2.22940072417 ])
elec_2_w1 = np.array( [ 3.51983380318, -1.08717381954, -1.19617708027 ])
elec_1_w2 = np.array( [ -2.34410619736, -3.20016115904, -1.53496759012 ])
elec_2_w2 = np.array( [ 3.17996025085, -1.40260577202, 1.49473607540 ])
nucl_1 = np.array( [ 1.096243353458458e+00, 8.907054016973815e-01, 7.777092280258892e-01 ] )
nucl_2 = np.array( [ 1.168459237342663e+00, 1.125660720053393e+00, 2.833370314829343e+00 ] )
print ( "[0][0][0] : ", np.linalg.norm(elec_1_w1-nucl_1) )
print ( "[0][1][0] : ", np.linalg.norm(elec_1_w1-nucl_2) )
print ( "[0][0][1] : ", np.linalg.norm(elec_2_w1-nucl_1) )
print ( "[1][0][0] : ", np.linalg.norm(elec_1_w2-nucl_1) )
print ( "[1][1][0] : ", np.linalg.norm(elec_1_w2-nucl_2) )
print ( "[1][0][1] : ", np.linalg.norm(elec_2_w2-nucl_1) )
#+end_src
#+RESULTS:
: [0][0][0] : 7.546738741619978
: [0][1][0] : 8.77102435246984
: [0][0][1] : 3.698922010513608
: [1][0][0] : 5.824059436060509
: [1][1][0] : 7.080482110317645
: [1][0][1] : 3.1804527583077356
#+begin_src c :tangle (eval c_test)
assert(!qmckl_nucleus_provided(context));
assert(qmckl_electron_provided(context));
@ -964,31 +1108,34 @@ assert(rc == QMCKL_SUCCESS);
rc = qmckl_set_nucleus_charge (context, charge);
assert (rc == QMCKL_SUCCESS);
rc = qmckl_set_nucleus_coord (context, &(nucl_coord[0]));
rc = qmckl_set_nucleus_coord (context, 'T', nucl_coord);
assert (rc == QMCKL_SUCCESS);
assert(qmckl_nucleus_provided(context));
double en_distance[walk_num][nucl_num][num];
double en_distance[walk_num][nucl_num][elec_num];
rc = qmckl_get_electron_en_distance(context, &(en_distance[0][0][0]));
assert (rc == QMCKL_SUCCESS);
// (e,n,w) in Fortran notation
// (1,1,1)
assert(fabs(en_distance[0][0][0] - 6.855624268793153) < 1.e-12);
assert(fabs(en_distance[0][0][0] - 7.546738741619978) < 1.e-12);
// (1,2,1)
assert(fabs(en_distance[0][1][0] - 8.77102435246984) < 1.e-12);
// (2,1,1)
assert(fabs(en_distance[0][0][1] - 3.698922010513608) < 1.e-12);
// (1,2,1)
assert(fabs(en_distance[0][1][0] - 8.143800105434433) < 1.e-12);
// (1,1,2)
assert(fabs(en_distance[1][0][0] - 5.824059436060509) < 1.e-12);
// (2,2,1)
assert(fabs(en_distance[0][1][1] - 5.16360835635664) < 1.e-12);
// (1,2,2)
assert(fabs(en_distance[1][1][0] - 7.080482110317645) < 1.e-12);
// (4,3,2)
assert(fabs(en_distance[1][2][3] - 12.599138999960012) < 1.e-12);
// (2,1,2)
assert(fabs(en_distance[1][0][1] - 3.1804527583077356) < 1.e-12);
#+end_src

View File

@ -208,23 +208,28 @@ qmckl_get_nucleus_coord (const qmckl_context context, const char transp, double*
int32_t mask = 1 << 2;
if ( (ctx->nucleus.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;

View File

@ -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},