Fix missing import in finiterectlat-scatter.py
[qpms.git] / oldtests / ewaldshift_ng.c
blobc5172ad841c322c02af6c5ae951ea7f62fd26d5b
1 // c99 -ggdb -Wall -I ../ ewaldshift2.c ../qpms/ewald.c ../qpms/ewaldsf.c ../qpms/lattices2d.c -lgsl -lm -lblas
3 // implementation of the [LT(4.16)] test
4 #include <math.h>
5 #define M_SQRTPI 1.7724538509055160272981674833411452
6 #define M_SQRT3 1.7320508075688772935274463415058724
7 #include <qpms/ewald.h>
8 #include <qpms/tiny_inlines.h>
9 #include <qpms/indexing.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <float.h>
13 #include <gsl/gsl_sf_legendre.h>
14 typedef struct ewaldtest_triang_params {
15 qpms_l_t lMax;
16 point2d beta;
17 point2d particle_shift;
18 double k;
19 double a;
20 double eta;
21 double maxR;
22 double maxK;
23 double csphase;
24 TriangularLatticeOrientation orientation;
25 } ewaldtest_triang_params;
27 typedef struct ewaldtest_triang_results {
28 ewaldtest_triang_params p;
29 complex double *sigmas_short,
30 *sigmas_long,
31 sigma0,
32 *sigmas_total;
33 double *err_sigmas_short,
34 *err_sigmas_long,
35 err_sigma0,
36 *err_sigmas_total;
37 complex double *regsigmas_416;
38 } ewaldtest_triang_results;
42 const double a = 582e-9;
43 const double inv_a = 4*M_PI/a/M_SQRT3;
44 const double Klen = 4*M_PI/a/3;
47 #define AA (582.e-9)
48 #define INV_A (4*M_PI/AA/M_SQRT3)
49 #define KLEN (4*M_PI/AA/3)
51 ewaldtest_triang_params paramslist[] = {
52 // lMax, beta, shift, k, a, eta, maxR, maxK, csphase, orientation
54 { 2, {2.7, 1}, {0.5,0.1325}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
55 { 2, {2.7, 1}, {0.5,0.1325}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
56 { 2, {2.7, 1}, {0.5,0.1325}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
57 { 2, {2.7, 1}, {0.5,0.1325}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
59 { 2, {1.1, 1}, {0.5,0.1325}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
60 { 2, {1.1, 1}, {0.5,0.1325}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
61 { 2, {1.1, 1}, {0.5,0.1325}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
62 { 2, {1.1, 1}, {0.5,0.1325}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
64 { 2, {1.1, 1}, {0.5,0.}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
65 { 2, {1.1, 1}, {0.5,0.}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
66 { 2, {1.1, 1}, {0.5,0.}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
67 { 2, {1.1, 1}, {0.5,0.}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
71 { 3, {0,4198609.6394310603}, {0,0}, 11255786.828366444, 9.9766126515967311e-07, 29088820.866572164, 20*9.9766126515967311e-07, 20*7272205.21664304, 1., TRIANGULAR_VERTICAL},
72 { 3, {0,4198609.6394310603}, {0,0}, 11255786.828366444, 9.9766126515967311e-07, 0.18*29088820.866572164, 20*9.9766126515967311e-07, 20*7272205.21664304, 1., TRIANGULAR_VERTICAL},
73 { 3, {0,4198609.6394310603}, {0,0}, 11255786.828366444, 9.9766126515967311e-07, 0.13*29088820.866572164, 20*9.9766126515967311e-07, 20*7272205.21664304, 1., TRIANGULAR_VERTICAL},
74 { 3, {0,4198609.6394310603}, {0,0}, 11255786.828366444, 9.9766126515967311e-07, 0.07*29088820.866572164, 20*9.9766126515967311e-07, 20*7272205.21664304, 1., TRIANGULAR_VERTICAL},
75 { 3, {0,4198609.6394310603}, {0,0}, 11255786.828366444, 9.9766126515967311e-07, 0.03*29088820.866572164, 20*9.9766126515967311e-07, 20*7272205.21664304, 1., TRIANGULAR_VERTICAL},
77 // { 3, {0,KLEN}, {0,0}, 2.62 * 4 * M_PI/3/AA, AA, 0.5 / AA, 20*AA, 160/AA, 1., TRIANGULAR_VERTICAL},
78 { 3, {0,KLEN}, {0,0}, 2.62 * 4 * M_PI/3/AA, AA, 2.5 / AA, 20*AA, 160/AA, 1., TRIANGULAR_VERTICAL},
79 { 3, {0,KLEN}, {0,0}, 2.62 * 4 * M_PI/3/AA, AA, 4.5 / AA, 20*AA, 160/AA, 1., TRIANGULAR_VERTICAL},
80 { 3, {0,KLEN}, {0,0}, 2.62 * 4 * M_PI/3/AA, AA, 6.5 / AA, 20*AA, 160/AA, 1., TRIANGULAR_VERTICAL},
81 { 3, {0,KLEN}, {0,0}, 2.62 * 4 * M_PI/3/AA, AA, 8.5 / AA, 20*AA, 160/AA, 1., TRIANGULAR_VERTICAL},
83 { 3, {0,Klen}, {0,0}, 2.62 * 4 * M_PI/3/a, a, 0.5 / a, 20*a, 2*M_PI*160/a, 1., TRIANGULAR_VERTICAL},
84 { 3, {0,Klen}, {0,0}, 2.62 * 4 * M_PI/3/a, a, 2.5 / a, 20*a, 2*M_PI*160/a, 1., TRIANGULAR_VERTICAL},
85 { 3, {0,Klen}, {0,0}, 2.62 * 4 * M_PI/3/a, a, 4.5 / a, 20*a, 2*M_PI*160/a, 1., TRIANGULAR_VERTICAL},
86 { 3, {0,Klen}, {0,0}, 2.62 * 4 * M_PI/3/a, a, 6.5 / a, 20*a, 2*M_PI*160/a, 1., TRIANGULAR_VERTICAL},
87 { 3, {0,Klen}, {0,0}, 2.62 * 4 * M_PI/3/a, a, 8.5 / a, 20*a, 2*M_PI*160/a, 1., TRIANGULAR_VERTICAL},
91 { 2, {1.1, 2.1}, {0.5,0.1325}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
92 { 2, {1.1, 2.1}, {0.5,0.1325}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
93 { 2, {1.1, 2.1}, {0.5,0.1325}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
94 { 2, {1.1, 2.1}, {0.5,0.1325}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
96 { 2, {0, 3.1}, {0.5,0}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
97 { 2, {0, 3.1}, {0.5,0}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
98 { 2, {0, 3.1}, {0.5,0}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
99 { 2, {0, 3.1}, {0.5,0}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
101 { 2, {0, 1.1}, {0.5,0}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
102 { 2, {0, 1.1}, {0.5,0}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
103 { 2, {0, 1.1}, {0.5,0}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
104 { 2, {0, 1.1}, {0.5,0}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
106 { 2, {3.1,0}, {0,0.5}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
107 { 2, {3.1,0}, {0,0.5}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
108 { 2, {3.1,0}, {0,0.5}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
109 { 2, {3.1,0}, {0,0.5}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
111 { 2, {1.1,0}, {0,0.5}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
112 { 2, {1.1,0}, {0,0.5}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
113 { 2, {1.1,0}, {0,0.5}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
114 { 2, {1.1,0}, {0,0.5}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
116 { 2, {3.1,0}, {0,0.5}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
117 { 2, {3.1,0}, {0,0.5}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
118 { 2, {3.1,0}, {0,0.5}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
119 { 2, {3.1,0}, {0,0.5}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
121 { 2, {3.1*0.5,-3.1*0.8}, {0.8,0.5}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
122 { 2, {3.1*0.5,-3.1*0.8}, {0.8,0.5}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
123 { 2, {3.1*0.5,-3.1*0.8}, {0.8,0.5}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
124 { 2, {3.1*0.5,-3.1*0.8}, {0.8,0.5}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
126 { 2, {1.1*0.5,-1.1*0.8}, {0.8,0.5}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
127 { 2, {1.1*0.5,-1.1*0.8}, {0.8,0.5}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
128 { 2, {1.1*0.5,-1.1*0.8}, {0.8,0.5}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
129 { 2, {1.1*0.5,-1.1*0.8}, {0.8,0.5}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
131 // Poloviční posun oproti přodchozímu
132 { 2, {3.1*0.5,-3.1*0.8}, {0.4,0.25}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
133 { 2, {3.1*0.5,-3.1*0.8}, {0.4,0.25}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
134 { 2, {3.1*0.5,-3.1*0.8}, {0.4,0.25}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
135 { 2, {3.1*0.5,-3.1*0.8}, {0.4,0.25}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
137 { 2, {1.1*0.5,-1.1*0.8}, {0.4,0.25}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
138 { 2, {1.1*0.5,-1.1*0.8}, {0.4,0.25}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
139 { 2, {1.1*0.5,-1.1*0.8}, {0.4,0.25}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
140 { 2, {1.1*0.5,-1.1*0.8}, {0.4,0.25}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
142 // miniposun
143 { 3, {3.1*0.5,-3.1*0.8}, {0.004,0.0025}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
144 { 3, {3.1*0.5,-3.1*0.8}, {0.004,0.0025}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
145 { 3, {3.1*0.5,-3.1*0.8}, {0.004,0.0025}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
146 { 3, {3.1*0.5,-3.1*0.8}, {0.004,0.0025}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
148 { 3, {1.1*0.5,-1.1*0.8}, {0.004,0.0025}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
149 { 3, {1.1*0.5,-1.1*0.8}, {0.004,0.0025}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
150 { 3, {1.1*0.5,-1.1*0.8}, {0.004,0.0025}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
151 { 3, {1.1*0.5,-1.1*0.8}, {0.004,0.0025}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
153 { 3, {3.1*0.5,-3.1*0.8}, {-0.004,-0.0025}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
154 { 3, {3.1*0.5,-3.1*0.8}, {-0.004,-0.0025}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
155 { 3, {3.1*0.5,-3.1*0.8}, {-0.004,-0.0025}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
156 { 3, {3.1*0.5,-3.1*0.8}, {-0.004,-0.0025}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
158 { 3, {1.1*0.5,-1.1*0.8}, {-0.004,-0.0025}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
159 { 3, {1.1*0.5,-1.1*0.8}, {-0.004,-0.0025}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
160 { 3, {1.1*0.5,-1.1*0.8}, {-0.004,-0.0025}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
161 { 3, {1.1*0.5,-1.1*0.8}, {-0.004,-0.0025}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
167 { 2, {0, 3.1}, {0,0.5}, 2.3, 0.97, 0.5, 20, 160, 1., TRIANGULAR_VERTICAL},
168 { 2, {0, 3.1}, {0,0.5}, 2.3, 0.97, 1.5, 20, 160, 1., TRIANGULAR_VERTICAL},
169 { 2, {0, 3.1}, {0,0.5}, 2.3, 0.97, 2.5, 20, 160, 1., TRIANGULAR_VERTICAL},
170 { 2, {0, 3.1}, {0,0.5}, 2.3, 0.97, 3.5, 20, 160, 1., TRIANGULAR_VERTICAL},
176 // end:
177 // { 0, {0, 0}, 0, 0, 0, 0, 0, 0, 0}
180 void ewaldtest_triang_results_free(ewaldtest_triang_results *r) {
181 free(r->sigmas_short);
182 free(r->sigmas_long);
183 free(r->sigmas_total);
184 free(r->err_sigmas_long);
185 free(r->err_sigmas_total);
186 free(r->err_sigmas_short);
187 free(r->regsigmas_416);
188 free(r);
192 void dump_points2d_rordered(const points2d_rordered_t *ps, char *filename) {
193 FILE *f = fopen(filename, "w");
194 for (size_t i = 0; i < ps->nrs; ++i) {
195 fprintf(f, "# r = %.16g\n", ps->rs[i]);
196 for (ptrdiff_t j = ps->r_offsets[i]; j < ps->r_offsets[i+1]; ++j)
197 fprintf(f, "%.16g %.16g\n", ps->base[j].x, ps->base[j].y);
199 fclose(f);
203 static inline double san(double x) {
204 return fabs(x) < 1e-13 ? 0 : x;
207 ewaldtest_triang_results *ewaldtest_triang(const ewaldtest_triang_params p);
209 int main() {
210 gsl_set_error_handler(IgnoreUnderflowsGSLErrorHandler);
211 for (size_t i = 0; i < sizeof(paramslist)/sizeof(ewaldtest_triang_params); ++i) {
212 ewaldtest_triang_params p = paramslist[i];
213 ewaldtest_triang_results *r = ewaldtest_triang(p);
214 // TODO print per-test header here
215 printf("===============================\n");
216 printf("a = %g, K = %g, Kmax = %g, Rmax = %g, lMax = %d, eta = %g, k = %g, beta = (%g,%g), ps = (%g,%g), csphase = %g\n",
217 p.a, 4*M_PI/sqrt(3)/p.a, p.maxK, p.maxR, p.lMax, p.eta, p.k, p.beta.x, p.beta.y, p.particle_shift.x, p.particle_shift.y, p.csphase);
218 printf("sigma0: %.16g%+.16gj\n", creal(r->sigma0), cimag(r->sigma0));
219 for (qpms_l_t n = 0; n <= p.lMax; ++n) {
220 for (qpms_m_t m = -n; m <= n; ++m){
221 if ((m+n)%2) continue;
222 qpms_y_t y = qpms_mn2y_sc(m,n);
223 qpms_y_t y_conj = qpms_mn2y_sc(-m,n);
224 // y n m sigma_total (err), regsigmas_416 regsigmas_415_recon
225 printf("%zd %d %d: T:%.16g%+.16gj(%.3g) L:%.16g%+.16gj(%.3g) S:%.16g%+.16gj(%.3g) \n"
226 //"| predict %.16g%+.16gj \n| actual %.16g%+.16gj\n"
228 y, n, m, creal(san(r->sigmas_total[y])), san(cimag(r->sigmas_total[y])),
229 r->err_sigmas_total[y],
230 san(creal(r->sigmas_long[y])), san(cimag(r->sigmas_long[y])),
231 r->err_sigmas_long[y],
232 san(creal(r->sigmas_short[y])), san(cimag(r->sigmas_short[y])),
233 r->err_sigmas_short[y]
234 //san(creal(r->regsigmas_416[y])), san(cimag(r->regsigmas_416[y])),
235 //san(creal(r->sigmas_total[y]) + creal(r->sigmas_total[y_conj])),
236 //san(cimag(r->sigmas_total[y]) - cimag(r->sigmas_total[y_conj]))
240 ewaldtest_triang_results_free(r);
242 return 0;
246 int ewaldtest_counter = 0;
249 ewaldtest_triang_results *ewaldtest_triang(const ewaldtest_triang_params p) {
250 const double a = p.a; //const double a = p.h * sqrt(3);
252 const double A = sqrt(3) * a * a / 2.; // unit cell size
253 const double K_len = 4*M_PI/a/sqrt(3); // reciprocal vector length
256 ewaldtest_triang_results *results = malloc(sizeof(ewaldtest_triang_results));
257 results->p = p;
259 triangular_lattice_gen_t *Rlg = triangular_lattice_gen_init(a, p.orientation, true, 0); // N.B. orig is included
260 triangular_lattice_gen_extend_to_r(Rlg, p.maxR + a);
261 triangular_lattice_gen_t *Klg = triangular_lattice_gen_init(K_len, reverseTriangularLatticeOrientation(p.orientation), true, 0);
262 triangular_lattice_gen_extend_to_r(Klg, p.maxK + K_len);
264 point2d *Rpoints = Rlg->ps.base;
265 size_t nR = Rlg->ps.r_offsets[Rlg->ps.nrs];
267 if (fabs(p.particle_shift.x) ==0 && fabs(p.particle_shift.y) == 0) {
268 points2d_rordered_t Rpos = points2d_rordered_annulus(&(Rlg->ps), 0, false, INFINITY, false);
269 Rpoints = Rpos.base + Rpos.r_offsets[0];
270 nR = Rpos.r_offsets[Rpos.nrs] - Rpos.r_offsets[0];
276 point2d *Kpoints = Klg->ps.base;
277 size_t nK = Klg->ps.r_offsets[Klg->ps.nrs];
279 point2d particle_shift = p.particle_shift;
280 point2d minus_ps = {-particle_shift.x, -particle_shift.y};
281 point2d Rpoints_plus_shift[nR];
282 for(size_t i = 0; i < nR; ++i){
283 Rpoints_plus_shift[i].x = Rpoints[i].x - particle_shift.x;
284 Rpoints_plus_shift[i].y = Rpoints[i].y - particle_shift.y;
289 qpms_y_t nelem_sc = qpms_lMax2nelem_sc(p.lMax);
291 results->sigmas_short = malloc(sizeof(complex double)*nelem_sc);
292 results->sigmas_long = malloc(sizeof(complex double)*nelem_sc);
293 results->sigmas_total = malloc(sizeof(complex double)*nelem_sc);
294 results->err_sigmas_short = malloc(sizeof(double)*nelem_sc);
295 results->err_sigmas_long = malloc(sizeof(double)*nelem_sc);
296 results->err_sigmas_total = malloc(sizeof(double)*nelem_sc);
298 qpms_ewald3_constants_t *c = qpms_ewald3_constants_init(p.lMax, p.csphase);
300 points2d_rordered_t *Kpoints_plus_beta = points2d_rordered_shift(&(Klg->ps), p.beta,
301 8*DBL_EPSILON, 8*DBL_EPSILON);
303 char filename[BUFSIZ];
304 sprintf(filename, "betalattice_%d.out", ewaldtest_counter);
305 dump_points2d_rordered(Kpoints_plus_beta, filename);
308 if (0!=ewald32_sigma_long_points_and_shift(results->sigmas_long,
309 results->err_sigmas_long, c, p.eta, p.k, A,
310 nK, Kpoints,
311 p.beta,
312 particle_shift /*minus_ps*/ ))
313 abort();
314 if (0!=ewald32_sigma_short_points_and_shift(
315 results->sigmas_short, results->err_sigmas_short, c,
316 p.eta, p.k,
317 nR, Rpoints, p.beta, particle_shift))
318 abort();
319 if (0!=ewald32_sigma0(&(results->sigma0), &(results->err_sigma0), c, p.eta, p.k))
320 abort();
321 for(qpms_y_t y = 0; y < nelem_sc; ++y) {
322 results->sigmas_total[y] = results->sigmas_short[y] + results->sigmas_long[y];
323 results->err_sigmas_total[y] = results->err_sigmas_short[y] + results->err_sigmas_long[y];
325 results->sigmas_total[0] += results->sigma0;
326 results->err_sigmas_total[0] += results->err_sigma0;
328 // Now calculate the reference values [LT(4.16)]
329 results->regsigmas_416 = calloc(nelem_sc, sizeof(complex double));
330 results->regsigmas_416[0] = -2 * c->legendre0[gsl_sf_legendre_array_index(0,0)];
333 double legendres[gsl_sf_legendre_array_n(p.lMax)];
334 points2d_rordered_t sel =
335 points2d_rordered_annulus(Kpoints_plus_beta, 0, true, p.k, false);
336 if (0 != sel.nrs)
338 point2d *beta_pq_lessthan_k = sel.base + sel.r_offsets[0];
339 size_t beta_pq_lessthan_k_count = sel.r_offsets[sel.nrs] - sel.r_offsets[0];
340 for(size_t i = 0; i < beta_pq_lessthan_k_count; ++i) {
341 point2d beta_pq = beta_pq_lessthan_k[i];
342 double rbeta_pq = cart2norm(beta_pq);
343 double arg_pq = atan2(beta_pq.y, beta_pq.x);
344 double denom = sqrt(p.k*p.k - rbeta_pq*rbeta_pq);
345 if( gsl_sf_legendre_array_e(GSL_SF_LEGENDRE_NONE,
346 p.lMax, denom/p.k, p.csphase, legendres) != 0)
347 abort();
348 for (qpms_y_t y = 0; y < nelem_sc; ++y) {
349 qpms_l_t n; qpms_m_t m;
350 qpms_y2mn_sc_p(y, &m, &n);
351 if ((m+n)%2 != 0)
352 continue;
353 complex double eimf = cexp(I*m*arg_pq);
354 results->regsigmas_416[y] +=
355 4*M_PI*ipow(n)/p.k/A
356 * eimf * legendres[gsl_sf_legendre_array_index(n,abs(m))] * min1pow_m_neg(m)
357 / denom;
363 points2d_rordered_free(Kpoints_plus_beta);
364 qpms_ewald3_constants_free(c);
365 triangular_lattice_gen_free(Klg);
366 triangular_lattice_gen_free(Rlg);
367 ++ewaldtest_counter;
368 return results;