Skip to content

Commit

Permalink
Partially moved over to enum style parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
uekstrom committed Jun 16, 2010
1 parent 7675ecc commit 51b2aed
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 265 deletions.
3 changes: 3 additions & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ lib/libxcfun.a: $(BASE_OBJ) $(FUN_OBJ)
#lib/libxcfun.so: $(BASE_OBJ) $(FUN_OBJ)
# $(CXX) $(CXXFLAGS) -fPIC -shared -o lib/libxcfun.so $(LIBS) $^

geninterface: src/geninterface.cpp src/parameters.cpp
$(CXX) $(CXXFLAGS) $^ -o $@

funeval: test/funeval.cpp lib/libxcfun.a
$(CXX) $(CXXFLAGS) $< -o $@ -lxcfun

Expand Down
6 changes: 6 additions & 0 deletions include/xcfun.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ extern "C" {
// Index into result[] for derivative with given index (length as input_length() )
int xc_derivative_index(xc_functional fun, const int derivative[]);

// List of all settings
#ifndef XCFUN_INTERNAL
#include "xcfun_autogen.h"
#endif

/* Discover and manipulate settings */
int xc_nr_settings(xc_functional fun);
const char *xc_name_setting(xc_functional fun, int setting_nr);
Expand All @@ -73,6 +78,7 @@ extern "C" {
int xc_setting_is_functional(xc_functional fun, int setting_nr);
double xc_setting_value(xc_functional fun, int setting_nr);


#ifdef __cplusplus
} // End of extern "C"
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class array
}
return *this;
}
void destruct(void)
void destroy(void)
{
free(items);
}
Expand Down
22 changes: 9 additions & 13 deletions src/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "xcfun.h"
#include "config.h"
#include "array.h"
#include "settings.h"
#include "specmath.h"
#include "parameters.h"

// MGGA's have 7 variables (GGA+tau)
#define XC_MAX_NVAR 7
Expand All @@ -20,27 +20,23 @@ typedef double parameter;

// Functions for _user definable parameters_, for example the range
// separation parameter mu.
setting xc_param_lookup(const xc_functional::xc_functional_data *params,
const char *name);
double xc_param_get(const xc_functional::xc_functional_data *params,
const setting &s);
//setting xc_param_lookup(const xc_functional_data *params,
// const char *name);
//double xc_param_get(const xc_functional::xc_functional_data *params,
// const setting &s);


// Variables for expressing functionals, these are redundant because
// different functionals have different needs.
template<class T>
struct densvars
{
densvars(const xc_functional::xc_functional_data *p) : params(p) {}
densvars(const xc_functional_data *p) : params(p) {}
//For getting user defined parameters
const xc_functional::xc_functional_data *params;
setting lookup(const char *name) const
const xc_functional_data *params;
double get(enum xc_parameters p) const
{
return xc_param_lookup(params,name);
}
double get(const setting &s) const
{
return xc_param_get(params,s);
//FIXME return params->parameters[p];
}

T a, b, gaa, gab, gbb;
Expand Down
3 changes: 3 additions & 0 deletions src/functionals/list_of_functionals.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "functional.h"

/* See also list_of_parameters.h for list of functional
parameters. */

#define SETUP(F) void F(functional &); xc_run_functional_setup(F);

void xcint_setup_functionals()
Expand Down
29 changes: 29 additions & 0 deletions src/geninterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Program to generate a C header and Fortran module file
with the current settings of XCFun. */

#include <cstdio>
#include "xcfun_internal.h"

int main()
{
/* C interface */
FILE *of = fopen("include/xcfun_autogen.h","w");
fprintf(of,"enum xcfun_parameters {\n");
for (int i=0;i<XC_NR_PARAMS;i++)
fprintf(of,"%s,\n",xc_param_get_symbol((xc_parameters)i));
fprintf(of,"XC_NR_PARAMS\n};\n");
fclose(of);

/* Fortran interface */
of = fopen("fortran/xcfun_autogen.F90","w");
fprintf(of,
"module xcfun\n"
" implicit none\n");
fprintf(of," integer, parameter :: XC_NR_PARAMS = %i\n",XC_NR_PARAMS);
for (int i=0;i<XC_NR_PARAMS;i++)
fprintf(of," integer, parameter :: %s = %i\n",
xc_param_get_symbol((xc_parameters)i),i+1);
fprintf(of,"end module\n");
fclose(of);
return 0;
}
55 changes: 40 additions & 15 deletions src/parameters.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
#include <cassert>
#include "parameters.h"
#include "xcfun_internal.h"
#include <cstdio>
#include <cstdlib>

static const char *param_symbols[XC_NR_PARAMS] =
// TODO: Remove this and use the commone one
static void xc_die(const char *message, int code)
{
fprintf(stderr,"XCFun fatal error %i: ",code);
fprintf(stderr,"%s",message);
fprintf(stderr,"\n");
exit(-1);
}

static const char *param_symbols[XC_NR_PARAMS+1] =
{
#define PARAM(name) #name
#include "list_of_parameters.h"
Expand All @@ -11,37 +21,52 @@ static const char *param_symbols[XC_NR_PARAMS] =

static const char *param_short[XC_NR_PARAMS] = {0};
static const char *param_long[XC_NR_PARAMS] = {0};
static double param_default[XC_NR_PARAMS] = {0};

const char *param_get_symbol(enum xc_parameters param)
const char *xc_param_get_symbol(enum xc_parameters param)
{
if (param < 0 or param >= XC_NR_PARAMS)
xc_die("Invalid parameter nr (version mismatch?): ",param);
return param_symbols[XC_NR_PARAMS];
xc_die("Invalid parameter nr (version mismatch?)",param);
return param_symbols[param];
}
const char *param_get_short_description(enum xc_parameters param)
const char *xc_param_get_short_description(enum xc_parameters param)
{
if (param < 0 or param >= XC_NR_PARAMS)
xc_die("Invalid parameter nr (version mismatch?): ",param);
return param_short[XC_NR_PARAMS];
xc_die("Invalid parameter nr (version mismatch?)",param);
return param_short[param];
}
const char *param_get_long_description(enum xc_parameters param)
const char *xc_param_get_long_description(enum xc_parameters param)
{
if (param < 0 or param >= XC_NR_PARAMS)
xc_die("Invalid parameter nr (version mismatch?): ",param);
return param_long[XC_NR_PARAMS];
xc_die("Invalid parameter nr (version mismatch?)",param);
return param_long[param];
}

double xc_param_get_default(enum xc_parameters param)
{
if (param < 0 or param >= XC_NR_PARAMS)
xc_die("Invalid parameter nr (version mismatch?)",param);
return param_default[param];
}

// Short description is a string without newlines!
void param_set_short_description(enum xc_parameters param, const char *text)
void xcint_param_set_short_description(enum xc_parameters param, const char *text)
{
if (param < 0 or param >= XC_NR_PARAMS)
xc_die("Invalid parameter nr (version mismatch?): ",param);
xc_die("Invalid parameter nr (version mismatch?)",param);
param_short[param] = text;
}
// Long description should end with a final newline, and may have many lines.
void param_set_long_description(enum xc_parameters param, const char *text)
void xcint_param_set_long_description(enum xc_parameters param, const char *text)
{
if (param < 0 or param >= XC_NR_PARAMS)
xc_die("Invalid parameter nr (version mismatch?): ",param);
xc_die("Invalid parameter nr (version mismatch?)",param);
param_long[param] = text;
}

void xcint_param_set_default(enum xc_parameters param, double value)
{
if (param < 0 or param >= XC_NR_PARAMS)
xc_die("Invalid parameter nr (version mismatch?)",param);
param_default[param] = value;
}
11 changes: 5 additions & 6 deletions src/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ enum xc_parameters
#undef PARAM
};

const char *param_get_symbol(enum xc_parameters param);
const char *param_get_short_description(enum xc_parameters param);
const char *param_get_long_description(enum xc_parameters param);
const char *xc_param_get_symbol(enum xc_parameters param);
const char *xc_param_get_short_description(enum xc_parameters param);
const char *xc_param_get_long_description(enum xc_parameters param);
// Short description is a string without newlines!
void param_set_short_description(enum xc_parameters param, const char *text);
void xcint_param_set_short_description(enum xc_parameters param, const char *text);
// Long description should end with a final newline, and may have many lines.
void param_set_long_description(enum xc_parameters param, const char *text);

void xcint_param_set_long_description(enum xc_parameters param, const char *text);

#endif
149 changes: 0 additions & 149 deletions src/settings.cpp

This file was deleted.

Loading

0 comments on commit 51b2aed

Please sign in to comment.