From dd95de97f2bebece3db11a0aeeb71b8891fea34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Sat, 18 Aug 2018 08:50:04 +0000 Subject: [PATCH] Test direct quadrature of the sigma2 integral in Ewald sums. C Former-commit-id: 50b7bf83971c9693b59256e6f02b99acb2e84581 --- tests/gsl-int/quadratures.c | 55 +++++++++++++++++++++++++++++++++++++ tests/gsl-int/values.in | 4 +++ 2 files changed, 59 insertions(+) create mode 100644 tests/gsl-int/quadratures.c create mode 100644 tests/gsl-int/values.in diff --git a/tests/gsl-int/quadratures.c b/tests/gsl-int/quadratures.c new file mode 100644 index 0000000..4819e9b --- /dev/null +++ b/tests/gsl-int/quadratures.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +#define EPSABS 0 +#define EPSREL 1e-8 +#define LIMIT 8192 //??? +#define R0 1 + +/* Relevant quadrature methods from gsl: + * gsl_integration_qagiu + * ... and that's probably it. + */ + +//gsl_function sigma2_integrand; + +struct sigma2_integrand_params { + int n; + double k, R; +}; + +static inline double sq(double x) {return x * x;} + +double sigma2_integrand(double ksi, void *params) { + struct sigma2_integrand_params *p = (struct sigma2_integrand_params *) params; + return exp(-sq(p->R*ksi) + sq(p->k/ksi/2)) * pow(ksi, 2*p->n); +} + + +int main(int argc, char **argv) { + struct sigma2_integrand_params p; + gsl_function F; + F.function = sigma2_integrand; + F.params = &p; + gsl_integration_workspace *workspace = gsl_integration_workspace_alloc(LIMIT); + gsl_error_handler_t * old_handler=gsl_set_error_handler_off(); + double eta, eta_orig, k_orig, R_orig; + while (scanf("%d %lf %lf %lf", &(p.n), &k_orig, &R_orig, &eta_orig) == 4) { + eta = eta_orig * R0; + p.k = k_orig * R0; + p.R = R_orig / R0; + double result, abserr; + int retval = gsl_integration_qagiu(&F, eta, EPSABS, EPSREL, + LIMIT, workspace, &result, &abserr); + double normfac = pow(R0, -2*p.n - 1); + result *= normfac; + abserr *= normfac; + printf("%d %.16g %.16g %.16g %.16g %.16g %d\n", p.n, k_orig, R_orig, + eta_orig, result, abserr, retval); + } + gsl_integration_workspace_free(workspace); +} + + diff --git a/tests/gsl-int/values.in b/tests/gsl-int/values.in new file mode 100644 index 0000000..9e4bc09 --- /dev/null +++ b/tests/gsl-int/values.in @@ -0,0 +1,4 @@ +1 1 1 1 +1 5e7 504e-9 0 +1 5e7 504e-9 4e7 +