Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions pylibxc/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
XC_FLAGS_STABLE = (1 << 13) # 8192
XC_FLAGS_DEVELOPMENT = (1 << 14) # 16384
XC_FLAGS_NEEDS_LAPLACIAN = (1 << 15) # 32768

XC_TAU_EXPLICIT = 0
XC_TAU_EXPANSION = 1
XC_FLAGS_NEEDS_TAU = (1 << 16) # 65536

XC_MAX_REFERENCES = 5

32 changes: 32 additions & 0 deletions src/add_param_num.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import re
import glob

left = r'p->params = libxc_malloc(sizeof('
right= r'));'

new_left = r'p->params = malloc(sizeof('
new_right= r'));'

pattern = fr'{re.escape(left)}(.*?){re.escape(right)}'
count = 0
for file_path in glob.iglob('*.c'):
if os.path.isfile(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
file_content = file.read()

match = re.search(pattern, file_content)

if match:
count += 1
struct_name = match.group(1)
new_line = f'{new_left}{struct_name}{new_right} \n p->params_size = sizeof({struct_name});'
print(f'in {file_path}, find {new_line}')

file_content = re.sub(pattern, new_line, file_content)
print(file_content)

with open(file_path, 'w', encoding='utf-8') as file:
file.write(file_content)

print(f'{count} files are changed')
10 changes: 5 additions & 5 deletions src/deorbitalize_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ xc_mgga_evaluate_functional(const xc_func_type *func, size_t np,

if(func->info->flags & XC_FLAGS_HAVE_EXC)
mzk = zk;

/* Evaluate the functional */
switch(func->info->family){
case XC_FAMILY_LDA:
Expand Down Expand Up @@ -286,10 +286,10 @@ xc_deorbitalize_init(xc_func_type *p, int mgga_id, int ked_id)

/* allocate structures needed for */
p->n_func_aux = 2;
p->func_aux = (xc_func_type **) libxc_malloc(2*sizeof(xc_func_type *));
p->func_aux = (xc_func_type **) malloc(2*sizeof(xc_func_type *));

p->func_aux[0] = (xc_func_type *) libxc_malloc(sizeof(xc_func_type));
p->func_aux[1] = (xc_func_type *) libxc_malloc(sizeof(xc_func_type));
p->func_aux[0] = (xc_func_type *) malloc(sizeof(xc_func_type));
p->func_aux[1] = (xc_func_type *) malloc(sizeof(xc_func_type));

xc_func_init (p->func_aux[0], mgga_id, p->nspin);
xc_func_init (p->func_aux[1], ked_id, p->nspin);
Expand Down Expand Up @@ -470,4 +470,4 @@ xc_mgga_funcs_variants xc_deorbitalize_func =
{deorb_new, deorb_new, deorb_new, deorb_new, deorb_new},
{deorb_new, deorb_new, deorb_new, deorb_new, deorb_new}
};

1 change: 0 additions & 1 deletion src/expint_e1.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,3 @@ GPU_FUNCTION double xc_expint_e1_impl(double x, const int scale){

return e1;
}

33 changes: 16 additions & 17 deletions src/functionals.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ char *xc_functional_get_name(int number)
if(xc_functional_keys[ii].number == number) {
/* return duplicated: caller has the responsibility to dealloc string.
Do this the old way since strdup and strndup aren't C standard. */
p = (char *) libxc_malloc(strlen(xc_functional_keys[ii].name) + 1);
p = (char *) malloc(strlen(xc_functional_keys[ii].name) + 1);
strcpy(p,xc_functional_keys[ii].name);
return p;
}
Expand Down Expand Up @@ -229,7 +229,7 @@ void xc_available_functional_names(char **list)

/* Arrange list of functional IDs by name */
N=xc_number_of_functionals();
idlist=(int *) libxc_malloc(N*sizeof(int));
idlist=(int *) malloc(N*sizeof(int));
for(ii=0;ii<N;ii++) {
idlist[ii]=ii;
}
Expand All @@ -241,15 +241,15 @@ void xc_available_functional_names(char **list)
}

/* Deallocate work array */
libxc_free(idlist);
free(idlist);
}

/*------------------------------------------------------*/
xc_func_type *xc_func_alloc(void)
{
xc_func_type *func;

func = (xc_func_type *) libxc_malloc (sizeof (xc_func_type));
func = (xc_func_type *) malloc (sizeof (xc_func_type));
return func;
}

Expand All @@ -273,6 +273,7 @@ void xc_func_nullify(xc_func_type *func)

func->ext_params = NULL;
func->params = NULL;
func->params_size = 0;

func->dens_threshold = 0.0;
func->zeta_threshold = 0.0;
Expand All @@ -293,13 +294,11 @@ int xc_func_init(xc_func_type *func, int functional, int nspin)
/* initialize structure */
func->nspin = nspin;

// we have to make a copy because the *_known_funct arrays live in
// host memory (libxc_malloc instead returns memory than can be read
// from GPU and CPU).
xc_func_info_type * finfo = (xc_func_info_type *) libxc_malloc(sizeof(xc_func_info_type));
// TODO: remove the copy
xc_func_info_type * finfo = (xc_func_info_type *) malloc(sizeof(xc_func_info_type));

// initialize the dimension structure
libxc_memset(&(func->dim), 0, sizeof(xc_dimensions));
memset(&(func->dim), 0, sizeof(xc_dimensions));
switch(xc_family_from_id(functional, NULL, &number)){
case(XC_FAMILY_LDA):
*finfo = *xc_lda_known_funct[number];
Expand Down Expand Up @@ -354,7 +353,7 @@ int xc_func_init(xc_func_type *func, int functional, int nspin)

/* see if we need to initialize the external parameters */
if(func->info->ext_params.n > 0) {
func->ext_params = (double *) libxc_malloc(func->info->ext_params.n * sizeof(double));
func->ext_params = (double *) malloc(func->info->ext_params.n * sizeof(double));
xc_func_set_ext_params(func, func->info->ext_params.values);

/* sanity check external parameter names and descriptions */
Expand Down Expand Up @@ -395,30 +394,30 @@ void xc_func_end(xc_func_type *func)

for(ii=0; ii<func->n_func_aux; ii++){
xc_func_end(func->func_aux[ii]);
libxc_free(func->func_aux[ii]);
free(func->func_aux[ii]);
}
libxc_free(func->func_aux);
free(func->func_aux);
}

/* deallocate coefficients for mixed functionals */
if(func->mix_coef != NULL)
libxc_free(func->mix_coef);
free(func->mix_coef);

/* deallocate any used parameter */
if(func->ext_params != NULL)
libxc_free(func->ext_params);
free(func->ext_params);
if(func->params != NULL)
libxc_free(func->params);
free(func->params);

libxc_free((void *) func->info);
free((void *) func->info);

xc_func_nullify(func);
}

/*------------------------------------------------------*/
void xc_func_free(xc_func_type *p)
{
libxc_free(p);
free(p);
}

/*------------------------------------------------------*/
Expand Down
2 changes: 1 addition & 1 deletion src/genwiki.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ char * sanitize_link(const char * doi) {
buf[j++]='\0';

/* Allocate return array */
r = (char *) libxc_malloc(strlen(buf) + 1);
r = (char *) malloc(strlen(buf) + 1);
strcpy(r,buf);

return r;
Expand Down
38 changes: 19 additions & 19 deletions src/gga.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ xc_gga_sanity_check(const xc_func_info_type *info, int order, xc_gga_out_params
order);
exit(1);
}

/* sanity check */
if(out->zk != NULL && !(info->flags & XC_FLAGS_HAVE_EXC)){
fprintf(stderr, "Functional '%s' does not provide an implementation of Exc\n",
Expand All @@ -46,7 +46,7 @@ xc_gga_sanity_check(const xc_func_info_type *info, int order, xc_gga_out_params
info->name);
exit(1);
}
check_out_var(v2rhosigma);
check_out_var(v2rhosigma);
check_out_var(v2sigma2);
}

Expand Down Expand Up @@ -153,7 +153,7 @@ void xc_gga_new(const xc_func_type *func, int order, size_t np, const double *rh

xc_gga_sanity_check(func->info, order, out);
xc_gga_initalize(func, np, out);

/* call the GGA routines */
if(func->info->gga != NULL){
if(func->nspin == XC_UNPOLARIZED){
Expand Down Expand Up @@ -196,7 +196,7 @@ xc_gga(const xc_func_type *p, size_t np, const double *rho, const double *sigma,
if(order < 0) return;

xc_gga_out_params out;
libxc_memset(&out, 0, sizeof(xc_gga_out_params));
memset(&out, 0, sizeof(xc_gga_out_params));
out.zk = zk;
out.vrho = vrho; out.vsigma = vsigma;
out.v2rho2 = v2rho2; out.v2rhosigma = v2rhosigma; out.v2sigma2 = v2sigma2;
Expand All @@ -214,9 +214,9 @@ xc_gga_exc(const xc_func_type *p, size_t np, const double *rho, const double *si
double *zk)
{
xc_gga_out_params out;
libxc_memset(&out, 0, sizeof(xc_gga_out_params));
memset(&out, 0, sizeof(xc_gga_out_params));
out.zk = zk;

xc_gga_new(p, 0, np, rho, sigma, &out);
}

Expand All @@ -225,10 +225,10 @@ xc_gga_exc_vxc(const xc_func_type *p, size_t np, const double *rho, const double
double *zk, double *vrho, double *vsigma)
{
xc_gga_out_params out;
libxc_memset(&out, 0, sizeof(xc_gga_out_params));
memset(&out, 0, sizeof(xc_gga_out_params));
out.zk = zk;
out.vrho = vrho; out.vsigma = vsigma;

xc_gga_new(p, 1, np, rho, sigma, &out);
}

Expand All @@ -238,11 +238,11 @@ xc_gga_exc_vxc_fxc (const xc_func_type *p, size_t np, const double *rho, const d
double *v2rho2, double *v2rhosigma, double *v2sigma2)
{
xc_gga_out_params out;
libxc_memset(&out, 0, sizeof(xc_gga_out_params));
memset(&out, 0, sizeof(xc_gga_out_params));
out.zk = zk;
out.vrho = vrho; out.vsigma = vsigma;
out.v2rho2 = v2rho2; out.v2rhosigma = v2rhosigma; out.v2sigma2 = v2sigma2;

xc_gga_new(p, 2, np, rho, sigma, &out);
}

Expand All @@ -252,10 +252,10 @@ xc_gga_vxc_fxc (const xc_func_type *p, size_t np, const double *rho, const doubl
double *v2rho2, double *v2rhosigma, double *v2sigma2)
{
xc_gga_out_params out;
libxc_memset(&out, 0, sizeof(xc_gga_out_params));
memset(&out, 0, sizeof(xc_gga_out_params));
out.vrho = vrho; out.vsigma = vsigma;
out.v2rho2 = v2rho2; out.v2rhosigma = v2rhosigma; out.v2sigma2 = v2sigma2;

xc_gga_new(p, 2, np, rho, sigma, &out);
}

Expand All @@ -265,12 +265,12 @@ xc_gga_exc_vxc_fxc_kxc (const xc_func_type *p, size_t np, const double *rho, con
double *v3rho3, double *v3rho2sigma, double *v3rhosigma2, double *v3sigma3)
{
xc_gga_out_params out;
libxc_memset(&out, 0, sizeof(xc_gga_out_params));
memset(&out, 0, sizeof(xc_gga_out_params));
out.zk = zk;
out.vrho = vrho; out.vsigma = vsigma;
out.v2rho2 = v2rho2; out.v2rhosigma = v2rhosigma; out.v2sigma2 = v2sigma2;
out.v3rho3 = v3rho3; out.v3rho2sigma = v3rho2sigma; out.v3rhosigma2 = v3rhosigma2; out.v3sigma3 = v3sigma3;

xc_gga_new(p, 3, np, rho, sigma, &out);
}

Expand All @@ -280,7 +280,7 @@ xc_gga_vxc_fxc_kxc (const xc_func_type *p, size_t np, const double *rho, const d
double *v3rho3, double *v3rho2sigma, double *v3rhosigma2, double *v3sigma3)
{
xc_gga_out_params out;
libxc_memset(&out, 0, sizeof(xc_gga_out_params));
memset(&out, 0, sizeof(xc_gga_out_params));
out.vrho = vrho; out.vsigma = vsigma;
out.v2rho2 = v2rho2; out.v2rhosigma = v2rhosigma; out.v2sigma2 = v2sigma2;
out.v3rho3 = v3rho3; out.v3rho2sigma = v3rho2sigma; out.v3rhosigma2 = v3rhosigma2; out.v3sigma3 = v3sigma3;
Expand All @@ -293,7 +293,7 @@ xc_gga_vxc(const xc_func_type *p, size_t np, const double *rho, const double *si
double *vrho, double *vsigma)
{
xc_gga_out_params out;
libxc_memset(&out, 0, sizeof(xc_gga_out_params));
memset(&out, 0, sizeof(xc_gga_out_params));
out.vrho = vrho; out.vsigma = vsigma;

xc_gga_new(p, 1, np, rho, sigma, &out);
Expand All @@ -304,7 +304,7 @@ xc_gga_fxc(const xc_func_type *p, size_t np, const double *rho, const double *si
double *v2rho2, double *v2rhosigma, double *v2sigma2)
{
xc_gga_out_params out;
libxc_memset(&out, 0, sizeof(xc_gga_out_params));
memset(&out, 0, sizeof(xc_gga_out_params));
out.v2rho2 = v2rho2; out.v2rhosigma = v2rhosigma; out.v2sigma2 = v2sigma2;

xc_gga_new(p, 2, np, rho, sigma, &out);
Expand All @@ -315,7 +315,7 @@ xc_gga_kxc(const xc_func_type *p, size_t np, const double *rho, const double *si
double *v3rho3, double *v3rho2sigma, double *v3rhosigma2, double *v3sigma3)
{
xc_gga_out_params out;
libxc_memset(&out, 0, sizeof(xc_gga_out_params));
memset(&out, 0, sizeof(xc_gga_out_params));
out.v3rho3 = v3rho3; out.v3rho2sigma = v3rho2sigma; out.v3rhosigma2 = v3rhosigma2; out.v3sigma3 = v3sigma3;

xc_gga_new(p, 3, np, rho, sigma, &out);
Expand All @@ -327,7 +327,7 @@ xc_gga_lxc(const xc_func_type *p, size_t np, const double *rho, const double *si
double *v4rho4, double *v4rho3sigma, double *v4rho2sigma2, double *v4rhosigma3, double *v4sigma4)
{
xc_gga_out_params out;
libxc_memset(&out, 0, sizeof(xc_gga_out_params));
memset(&out, 0, sizeof(xc_gga_out_params));
out.v4rho4 = v4rho4; out.v4rho3sigma = v4rho3sigma; out.v4rho2sigma2 = v4rho2sigma2; out.v4rhosigma3 = v4rhosigma3; out.v4sigma4 = v4sigma4;

xc_gga_new(p, 4, np, rho, sigma, &out);
Expand Down
3 changes: 2 additions & 1 deletion src/gga_c_am05.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ static void
gga_c_am05_init(xc_func_type *p)
{
assert(p!=NULL && p->params == NULL);
p->params = libxc_malloc(sizeof(gga_c_am05_params));
p->params = malloc(sizeof(gga_c_am05_params));
p->params_size = sizeof(gga_c_am05_params);
}

#include "maple2c/gga_exc/gga_c_am05.c"
Expand Down
3 changes: 2 additions & 1 deletion src/gga_c_bmk.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ static const double par_hyb_tau_hcth[BMK_N_PAR] = {

static void gga_c_bmk_init(xc_func_type *p) {
assert(p->params == NULL);
p->params = libxc_malloc(sizeof(gga_c_bmk_params));
p->params = malloc(sizeof(gga_c_bmk_params));
p->params_size = sizeof(gga_c_bmk_params);
}

#include "maple2c/gga_exc/gga_c_bmk.c"
Expand Down
3 changes: 2 additions & 1 deletion src/gga_c_ccdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ typedef struct{
static void gga_c_ccdf_init(xc_func_type *p)
{
assert(p!=NULL && p->params == NULL);
p->params = libxc_malloc(sizeof(gga_c_ccdf_params));
p->params = malloc(sizeof(gga_c_ccdf_params));
p->params_size = sizeof(gga_c_ccdf_params);
}

#define N_PAR 5
Expand Down
3 changes: 2 additions & 1 deletion src/gga_c_chachiyo.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ static void
gga_c_chachiyo_init(xc_func_type *p)
{
assert(p!=NULL && p->params == NULL);
p->params = libxc_malloc(sizeof(gga_c_chachiyo_params));
p->params = malloc(sizeof(gga_c_chachiyo_params));
p->params_size = sizeof(gga_c_chachiyo_params);
}

#include "maple2c/gga_exc/gga_c_chachiyo.c"
Expand Down
3 changes: 2 additions & 1 deletion src/gga_c_lm.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ static void
gga_c_lm_init(xc_func_type *p)
{
assert(p!=NULL && p->params == NULL);
p->params = libxc_malloc(sizeof(gga_c_lm_params));
p->params = malloc(sizeof(gga_c_lm_params));
p->params_size = sizeof(gga_c_lm_params);
}

#define N_PAR 1
Expand Down
Loading