12#include "gadgetconfig.h"
20#include "../data/allvars.h"
21#include "../data/dtypes.h"
22#include "../data/mymalloc.h"
23#include "../gravity/ewald.h"
24#include "../gravity/ewaldtensors.h"
25#include "../gravtree/gravtree.h"
27#include "../main/simulation.h"
28#include "../sort/cxxsort.h"
29#include "../system/system.h"
47 if(!ewald_is_initialized)
48 Terminate(
"How come that Ewald tables are not initialized?");
50 int signx, signy, signz;
76 ewald_interpolate(dx, dy, dz, flag, fper);
80 fper.
D1phi[0] *= signx;
81 fper.
D1phi[1] *= signy;
82 fper.
D1phi[2] *= signz;
95 fper.
D3phi[
dXYZ] *= signx * signy * signz;
102 fper.D4phi[
sXXXY] *= signx * signy;
103 fper.D4phi[
sXYYY] *= signx * signy;
104 fper.D4phi[
sXXXZ] *= signx * signz;
105 fper.D4phi[
sXZZZ] *= signx * signz;
106 fper.D4phi[
sYYYZ] *= signy * signz;
107 fper.D4phi[
sYZZZ] *= signy * signz;
108 fper.D4phi[
sXXYZ] *= signy * signz;
109 fper.D4phi[
sXYYZ] *= signx * signz;
110 fper.D4phi[
sXYZZ] *= signx * signy;
112 fper.D5phi[
rXXXXX] *= signx;
113 fper.D5phi[
rYYYYY] *= signy;
114 fper.D5phi[
rZZZZZ] *= signz;
116 fper.D5phi[
rXXXXY] *= signy;
117 fper.D5phi[
rXXXXZ] *= signz;
118 fper.D5phi[
rXYYYY] *= signx;
119 fper.D5phi[
rXZZZZ] *= signx;
120 fper.D5phi[
rYYYYZ] *= signz;
121 fper.D5phi[
rYZZZZ] *= signy;
123 fper.D5phi[
rXXXYY] *= signx;
124 fper.D5phi[
rXXXZZ] *= signx;
125 fper.D5phi[
rXXYYY] *= signy;
126 fper.D5phi[
rXXZZZ] *= signz;
127 fper.D5phi[
rYYYZZ] *= signy;
128 fper.D5phi[
rYYZZZ] *= signz;
130 fper.D5phi[
rXXYZZ] *= signy;
131 fper.D5phi[
rXXYYZ] *= signz;
132 fper.D5phi[
rXYYZZ] *= signx;
134 fper.D5phi[
rXXXYZ] *= signx * signy * signz;
135 fper.D5phi[
rXYYYZ] *= signx * signy * signz;
136 fper.D5phi[
rXYZZZ] *= signx * signy * signz;
158void ewald::ewald_interpolate(
double dx,
double dy,
double dz,
enum interpolate_options flag,
ewald_data &fper)
160 double u = dx * Ewd_fac_intp[0];
166 double v = dy * Ewd_fac_intp[1];
172 double w = dz * Ewd_fac_intp[2];
178 double f1 = (1 - u) * (1 - v) * (1 - w);
179 double f2 = (1 - u) * (1 - v) * (w);
180 double f3 = (1 - u) * (v) * (1 - w);
181 double f4 = (1 - u) * (v) * (w);
182 double f5 = (u) * (1 - v) * (1 - w);
183 double f6 = (u) * (1 - v) * (w);
184 double f7 = (u) * (v) * (1 - w);
185 double f8 = (u) * (v) * (w);
188 ewald_data &C2 = Ewd[ewd_offset(i, j, k + 1)];
189 ewald_data &C3 = Ewd[ewd_offset(i, j + 1, k)];
190 ewald_data &C4 = Ewd[ewd_offset(i, j + 1, k + 1)];
191 ewald_data &C5 = Ewd[ewd_offset(i + 1, j, k)];
192 ewald_data &C6 = Ewd[ewd_offset(i + 1, j, k + 1)];
193 ewald_data &C7 = Ewd[ewd_offset(i + 1, j + 1, k)];
194 ewald_data &C8 = Ewd[ewd_offset(i + 1, j + 1, k + 1)];
213 f1 * C1.D4phi + f2 * C2.D4phi + f3 * C3.D4phi + f4 * C4.D4phi + f5 * C5.D4phi + f6 * C6.D4phi + f7 * C7.D4phi + f8 * C8.D4phi;
216 f1 * C1.D5phi + f2 * C2.D5phi + f3 * C3.D5phi + f4 * C4.D5phi + f5 * C5.D5phi + f6 * C6.D5phi + f7 * C7.D5phi + f8 * C8.D5phi;
219void ewald::test_interpolation_accuracy(
void)
228 for(
int i = 0; i < 1000; i++)
234 double r =
sqrt(x * x + y * y + z * z);
241 double err =
fabs((D0phi_exact - ew.
D0phi) / D0phi_exact);
249 printf(
"%4d r=%g D0_exact=%g D0_interpol=%g rel_error=%g\n", i, r, D0phi_exact, ew.
D0phi, err);
255 for(
int i = 0; i < 1000; i++)
261 double r =
sqrt(x * x + y * y + z * z);
268 double norm = D1phi_exact.
norm();
270 for(
int j = 0; j < 3; j++)
272 double err =
fabs(D1phi_exact[j] - ew.
D1phi[j]) / norm;
280 printf(
"%4d r=%g bin=%d D1_exact[%d]=%g D1_interpol[%d]=%g rel_error=%g\n", i, r,
281 (
int)(r *
All.
BoxSize * Ewd_fac_intp[0]), j, D1phi_exact[j], j, ew.
D1phi[j], err);
289 for(
int i = 0; i < 1000; i++)
295 double r =
sqrt(x * x + y * y + z * z);
302 double norm = D2phi_exact.
norm();
304 for(
int j = 0; j < 6; j++)
306 double err =
fabs((D2phi_exact[j] - ew.
D2phi[j]) / norm);
313 printf(
"%4d r=%g D2_exact[%d]=%g D2_interpol[%d]=%g rel_error=%g\n", i, r, j, D2phi_exact[j], j, ew.
D2phi[j], err);
320 for(
int i = 0; i < 1000; i++)
326 double r =
sqrt(x * x + y * y + z * z);
333 double norm = D3phi_exact.
norm();
335 for(
int j = 0; j < 10; j++)
337 double err =
fabs((D3phi_exact[j] - ew.
D3phi[j]) / norm);
344 printf(
"%4d r=%g D3_exact[%d]=%g D3_interpol[%d]=%g rel_error=%g\n", i, r, j, D3phi_exact[j], j, ew.
D3phi[j], err);
351 for(
int i = 0; i < 1000; i++)
357 double r =
sqrt(x * x + y * y + z * z);
364 double norm = D4phi_exact.
norm();
366 for(
int j = 0; j < 15; j++)
368 double err =
fabs((D4phi_exact[j] - ew.D4phi[j]) / norm);
375 printf(
"%4d r=%g D4_exact[%d]=%g D4_interpol[%d]=%g rel_error=%g\n", i, r, j, D4phi_exact[j], j, ew.D4phi[j], err);
382 for(
int i = 0; i < 1000; i++)
393 double norm = D5phi_exact.
norm();
395 for(
int j = 0; j < 21; j++)
397 double err =
fabs((D5phi_exact[j] - ew.D5phi[j]) / norm);
407 printf(
"D0: max error = %g mean error=%g\n", errmax0, errsum0 / count0);
408 printf(
"D1: max error = %g mean error=%g\n", errmax1, errsum1 / count1);
409 printf(
"D2: max error = %g mean error=%g\n", errmax2, errsum2 / count2);
410 printf(
"D3: max error = %g mean error=%g\n", errmax3, errsum3 / count3);
411 printf(
"D4: max error = %g mean error=%g\n", errmax4, errsum4 / count4);
412 printf(
"D5: max error = %g mean error=%g\n", errmax5, errsum5 / count5);
420 for(
int i = 0; i < 1000; i++)
435 double err =
fabs((D0phi_exact - ew.
D0phi) / D0phi_exact);
446 for(
int i = 0; i < 1000; i++)
461 double norm = D1phi_exact.
norm();
463 for(
int j = 0; j < 3; j++)
465 double err =
fabs(D1phi_exact[j] - ew.
D1phi[j]) / norm;
477 for(
int i = 0; i < 1000; i++)
492 double norm = D2phi_exact.
norm();
494 for(
int j = 0; j < 6; j++)
496 double err =
fabs((D2phi_exact[j] - ew.
D2phi[j]) / norm);
507 for(
int i = 0; i < 1000; i++)
522 double norm = D3phi_exact.
norm();
524 for(
int j = 0; j < 10; j++)
526 double err =
fabs((D3phi_exact[j] - ew.
D3phi[j]) / norm);
537 for(
int i = 0; i < 1000; i++)
552 double norm = D4phi_exact.
norm();
554 for(
int j = 0; j < 15; j++)
556 double err =
fabs((D4phi_exact[j] - ew.D4phi[j]) / norm);
567 for(
int i = 0; i < 1000; i++)
582 double norm = D5phi_exact.
norm();
584 for(
int j = 0; j < 21; j++)
586 double err =
fabs((D5phi_exact[j] - ew.D5phi[j]) / norm);
594 printf(
"Grid look-up: \n\n");
596 printf(
"D0: max error = %g mean error=%g\n", errmax0, errsum0 / count0);
597 printf(
"D1: max error = %g mean error=%g\n", errmax1, errsum1 / count1);
598 printf(
"D2: max error = %g mean error=%g\n", errmax2, errsum2 / count2);
599 printf(
"D3: max error = %g mean error=%g\n", errmax3, errsum3 / count3);
600 printf(
"D4: max error = %g mean error=%g\n", errmax4, errsum4 / count4);
601 printf(
"D5: max error = %g mean error=%g\n", errmax5, errsum5 / count5);
609#ifdef GRAVITY_TALLBOX
610 Terminate(
"GRAVITY_TALLBOX is not implemented");
616 double alpha = 2.0 / leff;
617 double alpha2 = alpha * alpha;
619 int qxmax = (int)(8.0 *
LONG_X / alpha + 0.5);
620 int qymax = (int)(8.0 *
LONG_Y / alpha + 0.5);
621 int qzmax = (int)(8.0 *
LONG_Z / alpha + 0.5);
623 int nxmax = (int)(2.0 * alpha /
LONG_X + 0.5);
624 int nymax = (int)(2.0 * alpha /
LONG_Y + 0.5);
625 int nzmax = (int)(2.0 * alpha /
LONG_Z + 0.5);
627 for(
int nx = -qxmax; nx <= qxmax; nx++)
628 for(
int ny = -qymax; ny <= qymax; ny++)
629 for(
int nz = -qzmax; nz <= qzmax; nz++)
631 double dx = -nx * (1.0 /
LONG_X);
632 double dy = -ny * (1.0 /
LONG_Y);
633 double dz = -nz * (1.0 /
LONG_Z);
637 double r2 = dx * dx + dy * dy + dz * dz;
640 double rinv = (r > 0) ? 1.0 / r : 0.0;
641 double r2inv = rinv * rinv;
642 double r3inv = r2inv * rinv;
643 double r4inv = r2inv * r2inv;
644 double r7inv = r3inv * r4inv;
646 if(nx != 0 || ny != 0 || nz != 0)
650 double ar = alpha * r;
651 double ar2 = ar * ar;
652 double ar3 = ar * ar * ar;
653 double ar5 = ar3 * ar * ar;
654 double ar7 = ar5 * ar * ar;
655 double ar9 = ar7 * ar * ar;
656 double ar11 = ar9 * ar * ar;
657 double xir2 =
pow(dx * rinv, 2);
658 double xir4 =
pow(dx * rinv, 4);
659 double xir6 =
pow(dx * rinv, 6);
661 double yir2 =
pow(dy * rinv, 2);
662 double zir2 =
pow(dz * rinv, 2);
664 P6.
XXXXXX += (450.0 * ar + 300.0 * ar3 + 120.0 * ar5 - xir2 * (9450.0 * ar + 6300.0 * ar3 + 2520.0 * ar5 + 720.0 * ar7) +
665 xir4 * (28350.0 * ar + 18900.0 * ar3 + 7560.0 * ar5 + 2160.0 * ar7 + 480.0 * ar9) -
666 xir6 * (20790.0 * ar + 13860.0 * ar3 + 5544.0 * ar5 + 1584.0 * ar7 + 352.0 * ar9 + 64.0 * ar11)) /
668 erfc(ar) * (225.0 - 4725.0 * xir2 + 14175.0 * xir4 - 10395.0 * xir6) * r7inv;
670 P6.
XXXXYY += (90.0 * ar + 60.0 * ar3 + 24.0 * ar5 - xir2 * (1260.0 * ar + 840.0 * ar3 + 336.0 * ar5 + 96.0 * ar7) +
671 xir4 * (1890.0 * ar + 1260.0 * ar3 + 504.0 * ar5 + 144.0 * ar7 + 32.0 * ar9) -
672 yir2 * (630.0 * ar + 420.0 * ar3 + 168.0 * ar5 + 48.0 * ar7) +
673 xir2 * yir2 * (11340.0 * ar + 7560.0 * ar3 + 3024.0 * ar5 + 864.0 * ar7 + 192.0 * ar9) -
674 xir4 * yir2 * (20790.0 * ar + 13860.0 * ar3 + 5544.0 * ar5 + 1584.0 * ar7 + 352.0 * ar9 + 64.0 * ar11)) /
677 (45.0 - 630.0 * xir2 + 945.0 * xir4 - 315.0 * yir2 + 5670.0 * xir2 * yir2 - 10395.0 * xir4 * yir2) *
681 (30.0 * ar + 20.0 * ar3 + 8.0 * ar5 - (xir2 + yir2 + zir2) * (210.0 * ar + 140.0 * ar3 + 56.0 * ar5 + 16.0 * ar7) +
682 +(xir2 * yir2 + xir2 * zir2 + yir2 * zir2) * (1890.0 * ar + 1260.0 * ar3 + 504.0 * ar5 + 144.0 * ar7 + 32.0 * ar9) -
683 xir2 * yir2 * zir2 * (20790.0 * ar + 13860.0 * ar3 + 5544.0 * ar5 + 1584.0 * ar7 + 352.0 * ar9 + 64.0 * ar11)) /
686 (15.0 - 105.0 * (xir2 + yir2 + zir2) + 945.0 * (xir2 * yir2 + xir2 * zir2 + yir2 * zir2) -
687 10395.0 * xir2 * yir2 * zir2) *
708 for(
int nx = -nxmax; nx <= nxmax; nx++)
709 for(
int ny = -nymax; ny <= nymax; ny++)
710 for(
int nz = -nzmax; nz <= nzmax; nz++)
712 if(nx != 0 || ny != 0 || nz != 0)
717 double k2 = kx * kx + ky * ky + kz * kz;
732#ifdef GRAVITY_TALLBOX
733 Terminate(
"GRAVITY_TALLBOX is not implemented");
739 double alpha = 2.0 / leff;
740 double alpha2 = alpha * alpha;
742 int qxmax = (int)(8.0 *
LONG_X / alpha + 0.5);
743 int qymax = (int)(8.0 *
LONG_Y / alpha + 0.5);
744 int qzmax = (int)(8.0 *
LONG_Z / alpha + 0.5);
746 int nxmax = (int)(2.0 * alpha /
LONG_X + 0.5);
747 int nymax = (int)(2.0 * alpha /
LONG_Y + 0.5);
748 int nzmax = (int)(2.0 * alpha /
LONG_Z + 0.5);
750 for(
int nx = -qxmax; nx <= qxmax; nx++)
751 for(
int ny = -qymax; ny <= qymax; ny++)
752 for(
int nz = -qzmax; nz <= qzmax; nz++)
754 double dx = -nx * (1.0 /
LONG_X);
755 double dy = -ny * (1.0 /
LONG_Y);
756 double dz = -nz * (1.0 /
LONG_Z);
760 double r2 = dx * dx + dy * dy + dz * dz;
763 double rinv = (r > 0) ? 1.0 / r : 0.0;
764 double r2inv = rinv * rinv;
765 double r3inv = r2inv * rinv;
766 double r4inv = r2inv * r2inv;
767 double r5inv = r2inv * r3inv;
768 double r9inv = r4inv * r5inv;
770 if(nx != 0 || ny != 0 || nz != 0)
774 double ar = alpha * r;
775 double ar2 = ar * ar;
776 double ar3 = ar * ar * ar;
777 double ar5 = ar3 * ar * ar;
778 double ar7 = ar5 * ar * ar;
779 double ar9 = ar7 * ar * ar;
780 double ar11 = ar9 * ar * ar;
781 double ar13 = ar11 * ar * ar;
782 double ar15 = ar13 * ar * ar;
783 double xir2 =
pow(dx * rinv, 2);
784 double xir4 =
pow(dx * rinv, 4);
785 double xir6 =
pow(dx * rinv, 6);
786 double xir8 =
pow(dx * rinv, 8);
788 double yir2 =
pow(dy * rinv, 2);
789 double yir4 =
pow(dy * rinv, 4);
790 double zir2 =
pow(dz * rinv, 2);
793 (-(22050.0 * ar + 14700.0 * ar3 + 5880.0 * ar5 + 1680.0 * ar7) +
794 xir2 * (793800.0 * ar + 529200.0 * ar3 + 211680.0 * ar5 + 60480.0 * ar7 + 13440.0 * ar9) -
795 xir4 * (4365900.0 * ar + 2910600.0 * ar3 + 1164240.0 * ar5 + 332640.0 * ar7 + 73920.0 * ar9 + 13440.0 * ar11) +
796 xir6 * (7567560.0 * ar + 5045040.0 * ar3 + 2018016.0 * ar5 + 576576.0 * ar7 + 128128.0 * ar9 + 23296.0 * ar11 +
798 xir8 * (4054050.0 * ar + 2702700.0 * ar3 + 1081080.0 * ar5 + 308880.0 * ar7 + 68640.0 * ar9 + 12480.0 * ar11 +
799 1920.0 * ar13 + 256.0 * ar15)) /
801 erfc(ar) * (-11025.0 + 396900.0 * xir2 - 2182950.0 * xir4 + 3783780.0 * xir6 - 2027025.0 * xir8) * r9inv;
804 (-(3150.0 * ar + 2100.0 * ar3 + 840.0 * ar5 + 240.0 * ar7) +
805 xir2 * (85050.0 * ar + 56700.0 * ar3 + 22680.0 * ar5 + 6480.0 * ar7 + 1440.0 * ar9) -
806 xir4 * (311850.0 * ar + 207900.0 * ar3 + 83160.0 * ar5 + 23760.0 * ar7 + 5280.0 * ar9 + 960.0 * ar11) +
808 (270270.0 * ar + 180180.0 * ar3 + 72072.0 * ar5 + 20592.0 * ar7 + 4576.0 * ar9 + 832.0 * ar11 + 128.0 * ar13) +
809 yir2 * (28350.0 * ar + 18900 * ar3 + 7560.0 * ar5 + 2160 * ar7 + 480 * ar9) -
810 xir2 * yir2 * (935550 * ar + 623700.0 * ar3 + 249480.0 * ar5 + 71280.0 * ar7 + 15840.0 * ar9 + 2880.0 * ar11) +
812 (4054050.0 * ar + 2702700.0 * ar3 + 1081080.0 * ar5 + 308880.0 * ar7 + 68640.0 * ar9 + 12480.0 * ar11 +
815 (4054050.0 * ar + 2702700.0 * ar3 + 1081080.0 * ar5 + 308880.0 * ar7 + 68640.0 * ar9 + 12480.0 * ar11 +
816 1920.0 * ar13 + 256.0 * ar15)) /
819 (-1575.0 + 42525.0 * xir2 - 155925.0 * xir4 + 135135.0 * xir6 + 14175.0 * yir2 - 467775.0 * xir2 * yir2 +
820 2027025.0 * xir4 * yir2 - 2027025 * xir6 * yir2) *
824 (-(1890.0 * ar + 1260.0 * ar3 + 504.0 * ar5 + 144.0 * ar7) +
825 (xir2 + yir2) * (34020.0 * ar + 22680.0 * ar3 + 9072.0 * ar5 + 2592.0 * ar7 + 576.0 * ar9) -
826 (xir4 + yir4) * (62370.0 * ar + 41580.0 * ar3 + 16632.0 * ar5 + 4752.0 * ar7 + 1056.0 * ar9 + 192.0 * ar11) +
827 -xir2 * yir2 * (748440.0 * ar + 498960.0 * ar3 + 199584.0 * ar5 + 57024.0 * ar7 + 12672.0 * ar9 + 2304.0 * ar11) +
829 (xir4 * yir2 + xir2 * yir4) * (1621620.0 * ar + 1081080.0 * ar3 + 432432.0 * ar5 + 123552.0 * ar7 + 27456.0 * ar9 +
830 4992.0 * ar11 + 768.0 * ar13) -
832 (4054050.0 * ar + 2702700.0 * ar3 + 1081080.0 * ar5 + 308880.0 * ar7 + 68640.0 * ar9 + 12480.0 * ar11 +
833 1920.0 * ar13 + 256.0 * ar15)) /
836 (-945.0 + 17010.0 * (xir2 + yir2) - 31185.0 * (xir4 + yir4) - 374220.0 * xir2 * yir2 +
837 810810.0 * (xir4 * yir2 + xir2 * yir4) - 2027025.0 * xir4 * yir4) *
840 P8.
XXXXYYZZ = (-(630.0 * ar + 420.0 * ar3 + 168.0 * ar5 + 48.0 * ar7) +
841 (xir2) * (11340.0 * ar + 7560.0 * ar3 + 3024.0 * ar5 + 864.0 * ar7 + 192.0 * ar9) -
842 (xir4) * (20790.0 * ar + 13860.0 * ar3 + 5544.0 * ar5 + 1584.0 * ar7 + 352.0 * ar9 + 64.0 * ar11) +
843 +(yir2 + zir2) * (5670.0 * ar + 3780.0 * ar3 + 1512.0 * ar5 + 432.0 * ar7 + 96.0 * ar9) -
844 (xir2 * yir2 + xir2 * zir2) *
845 (124740 * ar + 83160.0 * ar3 + 33264.0 * ar5 + 9504 * ar7 + 2112.0 * ar9 + 384.0 * ar11) +
846 (xir4 * yir2 + xir4 * zir2) * (270270.0 * ar + 180180.0 * ar3 + 72072 * ar5 + 20592.0 * ar7 +
847 4576.0 * ar9 + 832.0 * ar11 + 128.0 * ar13) -
848 yir2 * zir2 * (62370.0 * ar + 41580 * ar3 + 16632.0 * ar5 + 4752 * ar7 + 1056.0 * ar9 + 192.0 * ar11) +
849 (xir2 * yir2 * zir2) * (1621620.0 * ar + 1081080.0 * ar3 + 432432.0 * ar5 + 123552.0 * ar7 +
850 27456.0 * ar9 + 4992.0 * ar11 + 768.0 * ar13) -
852 (4054050.0 * ar + 2702700.0 * ar3 + 1081080.0 * ar5 + 308880.0 * ar7 + 68640.0 * ar9 +
853 12480.0 * ar11 + 1920.0 * ar13 + 256.0 * ar15)) /
856 (-315.0 + 5670.0 * xir2 - 10395.0 * xir4 + 2835.0 * (yir2 + zir2) -
857 62370.0 * (xir2 * yir2 + xir2 * zir2) + 135135.0 * xir4 * (yir2 + zir2) - 31185.0 * yir2 * zir2 +
858 810810.0 * xir2 * yir2 * zir2 - 2027025 * xir4 * yir2 * zir2) *
880 for(
int nx = -nxmax; nx <= nxmax; nx++)
881 for(
int ny = -nymax; ny <= nymax; ny++)
882 for(
int nz = -nzmax; nz <= nzmax; nz++)
884 if(nx != 0 || ny != 0 || nz != 0)
889 double k2 = kx * kx + ky * ky + kz * kz;
905#ifdef GRAVITY_TALLBOX
906 Terminate(
"GRAVITY_TALLBOX is not implemented");
912 double alpha = 2.0 / leff;
913 double alpha2 = alpha * alpha;
915 int qxmax = (int)(8.0 *
LONG_X / alpha + 0.5);
916 int qymax = (int)(8.0 *
LONG_Y / alpha + 0.5);
917 int qzmax = (int)(8.0 *
LONG_Z / alpha + 0.5);
919 int nxmax = (int)(2.0 * alpha /
LONG_X + 0.5);
920 int nymax = (int)(2.0 * alpha /
LONG_Y + 0.5);
921 int nzmax = (int)(2.0 * alpha /
LONG_Z + 0.5);
923 for(
int nx = -qxmax; nx <= qxmax; nx++)
924 for(
int ny = -qymax; ny <= qymax; ny++)
925 for(
int nz = -qzmax; nz <= qzmax; nz++)
927 double dx = -nx * (1.0 /
LONG_X);
928 double dy = -ny * (1.0 /
LONG_Y);
929 double dz = -nz * (1.0 /
LONG_Z);
933 double r2 = dx * dx + dy * dy + dz * dz;
936 double rinv = (r > 0) ? 1.0 / r : 0.0;
937 double r2inv = rinv * rinv;
938 double r3inv = r2inv * rinv;
939 double r4inv = r2inv * r2inv;
940 double r7inv = r3inv * r4inv;
941 double r11inv = r4inv * r7inv;
943 if(nx != 0 || ny != 0 || nz != 0)
945 double ar = alpha * r;
946 double ar2 = ar * ar;
947 double ar3 = ar * ar * ar;
948 double ar5 = ar3 * ar * ar;
949 double ar7 = ar5 * ar * ar;
950 double ar9 = ar7 * ar * ar;
951 double ar11 = ar9 * ar * ar;
952 double ar13 = ar11 * ar * ar;
953 double ar15 = ar13 * ar * ar;
954 double ar17 = ar15 * ar * ar;
955 double ar19 = ar17 * ar * ar;
957 double xir2 =
pow(dx * rinv, 2);
958 double xir4 =
pow(dx * rinv, 4);
959 double xir6 =
pow(dx * rinv, 6);
960 double xir8 =
pow(dx * rinv, 8);
961 double xir10 =
pow(dx * rinv, 10);
963 double yir2 =
pow(dy * rinv, 2);
964 double yir4 =
pow(dy * rinv, 4);
965 double zir2 =
pow(dz * rinv, 2);
968 ((1786050.0 * ar + 1190700.0 * ar3 + 476280.0 * ar5 + 136080.0 * ar7 + 30240 * ar9) -
969 xir2 * (98232750.0 * ar + 65488500.0 * ar3 + 26195400.0 * ar5 + 7484400.0 * ar7 + 1663200.0 * ar9 + 302400 * ar11) +
970 xir4 * (851350500.0 * ar + 567567000.0 * ar3 + 227026800.0 * ar5 + 64864800.0 * ar7 + 14414400.0 * ar9 +
971 2620800.0 * ar11 + 403200 * ar13) -
972 xir6 * (2554051500.0 * ar + 1702701000.0 * ar3 + 681080400.0 * ar5 + 194594400.0 * ar7 + 43243200.0 * ar9 +
973 7862400.0 * ar11 + 1209600.0 * ar13 + 161280 * ar15) +
974 xir8 * (3101348250.0 * ar + 2067565500.0 * ar3 + 827026200.0 * ar5 + 236293200.0 * ar7 + 52509600.0 * ar9 +
975 9547200.0 * ar11 + 1468800.0 * ar13 + 195840.0 * ar15 + 23040 * ar17) -
976 xir10 * (1309458150 * ar + 872972100 * ar3 + 349188840 * ar5 + 99768240 * ar7 + 22170720 * ar9 + 4031040 * ar11 +
977 620160 * ar13 + 82688 * ar15 + 9728 * ar17 + 1024.0 * ar19)) /
980 (893025.0 - 49116375.0 * xir2 + 425675250.0 * xir4 - 1277025750 * xir6 + 1550674125.0 * xir8 -
981 654729075.0 * xir10) *
985 ((198450.0 * ar + 132300.0 * ar3 + 52920.0 * ar5 + 15120.0 * ar7 + 3360.0 * ar9) -
986 xir2 * (8731800.0 * ar + 5821200.0 * ar3 + 2328480.0 * ar5 + 665280.0 * ar7 + 147840.0 * ar9 + 26880.0 * ar11) +
987 xir4 * (56756700.0 * ar + 37837800.0 * ar3 + 15135120.0 * ar5 + 4324320.0 * ar7 + 960960.0 * ar9 + 174720.0 * ar11 +
989 xir6 * (113513400.0 * ar + 75675600.0 * ar3 + 30270240.0 * ar5 + 8648640.0 * ar7 + 1921920.0 * ar9 +
990 349440.0 * ar11 + 53760.0 * ar13 + 7168.0 * ar15) +
991 xir8 * (68918850.0 * ar + 45945900.0 * ar3 + 18378360.0 * ar5 + 5250960.0 * ar7 + 1166880.0 * ar9 +
992 212160.0 * ar11 + 32640.0 * ar13 + 4352.0 * ar15 + 512.0 * ar17) -
993 yir2 * (2182950.0 * ar + 1455300.0 * ar3 + 582120.0 * ar5 + 166320.0 * ar7 + 36960.0 * ar9 + 6720.0 * ar11) +
995 (113513400.0 * ar + 75675600.0 * ar3 + 30270240.0 * ar5 + 8648640.0 * ar7 + 1921920.0 * ar9 + 349440.0 * ar11 +
998 (851350500.0 * ar + 567567000.0 * ar3 + 227026800.0 * ar5 + 64864800.0 * ar7 + 14414400.0 * ar9 +
999 2620800.0 * ar11 + 403200.0 * ar13 + 53760.0 * ar15) +
1001 (1929727800.0 * ar + 1286485200.0 * ar3 + 514594080.0 * ar5 + 147026880.0 * ar7 + 32672640.0 * ar9 +
1002 5940480.0 * ar11 + 913920.0 * ar13 + 121856.0 * ar15 + 14336.0 * ar17) -
1004 (1309458150.0 * ar + 872972100.0 * ar3 + 349188840.0 * ar5 + 99768240 * ar7 + 22170720 * ar9 + 4031040 * ar11 +
1005 620160 * ar13 + 82688 * ar15 + 9728 * ar17 + 1024.0 * ar19)) /
1008 (99225.0 - 4365900.0 * xir2 + 28378350.0 * xir4 - 56756700 * xir6 + 34459425.0 * xir8 - 1091475.0 * yir2 +
1009 56756700.0 * xir2 * yir2 - 425675250.0 * xir4 * yir2 + 964863900.0 * xir6 * yir2 - 654729075.0 * xir8 * yir2) *
1013 ((85050.0 * ar + 56700.0 * ar3 + 22680.0 * ar5 + 6480.0 * ar7 + 1440.0 * ar9) -
1014 xir2 * (2806650.0 * ar + 1871100.0 * ar3 + 748440.0 * ar5 + 213840.0 * ar7 + 47520.0 * ar9 + 8640.0 * ar11) +
1015 xir4 * (12162150.0 * ar + 8108100.0 * ar3 + 3243240.0 * ar5 + 926640.0 * ar7 + 205920.0 * ar9 + 37440.0 * ar11 +
1017 xir6 * (12162150.0 * ar + 8108100.0 * ar3 + 3243240.0 * ar5 + 926640.0 * ar7 + 205920.0 * ar9 + 37440.0 * ar11 +
1018 5760.0 * ar13 + 768.0 * ar15) -
1019 yir2 * (1871100.0 * ar + 1247400.0 * ar3 + 498960.0 * ar5 + 142560.0 * ar7 + 31680.0 * ar9 + 5760.0 * ar11) +
1021 (72972900.0 * ar + 48648600 * ar3 + 19459440.0 * ar5 + 5559840.0 * ar7 + 1235520.0 * ar9 + 224640.0 * ar11 +
1024 (364864500.0 * ar + 243243000.0 * ar3 + 97297200.0 * ar5 + 27799200.0 * ar7 + 6177600.0 * ar9 +
1025 1123200.0 * ar11 + 172800.0 * ar13 + 23040.0 * ar15) +
1027 (413513100.0 * ar + 275675400.0 * ar3 + 110270160.0 * ar5 + 31505760.0 * ar7 + 7001280.0 * ar9 +
1028 1272960.0 * ar11 + 195840.0 * ar13 + 26112.0 * ar15 + 3072.0 * ar17) +
1029 yir4 * (4054050.0 * ar + 2702700.0 * ar3 + 1081080.0 * ar5 + 308880.0 * ar7 + 68640.0 * ar9 + 12480.0 * ar11 +
1032 (182432250.0 * ar + 121621500.0 * ar3 + 48648600.0 * ar5 + 13899600 * ar7 + 3088800 * ar9 + 561600 * ar11 +
1033 86400 * ar13 + 11520 * ar15) +
1035 (1033782750.0 * ar + 689188500.0 * ar3 + 275675400.0 * ar5 + 78764400 * ar7 + 17503200 * ar9 + 3182400 * ar11 +
1036 489600 * ar13 + 65280 * ar15 + 7680 * ar17) -
1038 (1309458150.0 * ar + 872972100.0 * ar3 + 349188840.0 * ar5 + 99768240.0 * ar7 + 22170720.0 * ar9 +
1039 4031040.0 * ar11 + 620160.0 * ar13 + 82688.0 * ar15 + 9728.0 * ar17 + 1024.0 * ar19)) /
1042 (42525.0 - 1403325 * xir2 + 6081075.0 * xir4 - 6081075 * xir6 - 935550.0 * yir2 + 36486450.0 * xir2 * yir2 -
1043 182432250.0 * xir4 * yir2 + 206756550.0 * xir6 * yir2 + 2027025.0 * yir4 - 91216125.0 * xir2 * yir4 +
1044 516891375.0 * xir4 * yir4 - 654729075.0 * xir6 * yir4) *
1048 ((28350 * ar + 18900 * ar3 + 7560 * ar5 + 2160 * ar7 + 480 * ar9) -
1049 xir2 * (935550 * ar + 623700 * ar3 + 249480 * ar5 + 71280 * ar7 + 15840 * ar9 + 2880 * ar11) +
1050 xir4 * (4054050 * ar + 2702700 * ar3 + 1081080 * ar5 + 308880 * ar7 + 68640 * ar9 + 12480 * ar11 + 1920 * ar13) -
1051 xir6 * (4054050 * ar + 2702700 * ar3 + 1081080 * ar5 + 308880 * ar7 + 68640 * ar9 + 12480 * ar11 + 1920 * ar13 +
1053 (yir2 + zir2) * (311850 * ar + 207900 * ar3 + 83160 * ar5 + 23760 * ar7 + 5280 * ar9 + 960 * ar11) +
1054 (xir2 * yir2 + xir2 * zir2) *
1055 (12162150 * ar + 8108100 * ar3 + 3243240 * ar5 + 926640 * ar7 + 205920 * ar9 + 37440 * ar11 + 5760 * ar13) -
1056 (xir4 * yir2 + xir4 * zir2) * (60810750 * ar + 40540500 * ar3 + 16216200 * ar5 + 4633200 * ar7 + 1029600 * ar9 +
1057 187200 * ar11 + 28800 * ar13 + 3840 * ar15) +
1058 (xir6 * yir2 + xir6 * zir2) * (68918850 * ar + 45945900 * ar3 + 18378360 * ar5 + 5250960 * ar7 + 1166880 * ar9 +
1059 212160 * ar11 + 32640 * ar13 + 4352 * ar15 + 512 * ar17) +
1061 (4054050 * ar + 2702700 * ar3 + 1081080.0 * ar5 + 308880.0 * ar7 + 68640.0 * ar9 + 12480.0 * ar11 +
1063 xir2 * yir2 * zir2 *
1064 (182432250.0 * ar + 121621500.0 * ar3 + 48648600.0 * ar5 + 13899600 * ar7 + 3088800 * ar9 + 561600 * ar11 +
1065 86400 * ar13 + 11520 * ar15) +
1066 xir4 * yir2 * zir2 *
1067 (1033782750.0 * ar + 689188500.0 * ar3 + 275675400.0 * ar5 + 78764400 * ar7 + 17503200 * ar9 + 3182400 * ar11 +
1068 489600 * ar13 + 65280 * ar15 + 7680 * ar17) -
1069 xir6 * yir2 * zir2 *
1070 (1309458150.0 * ar + 872972100.0 * ar3 + 349188840.0 * ar5 + 99768240.0 * ar7 + 22170720.0 * ar9 +
1071 4031040.0 * ar11 + 620160.0 * ar13 + 82688.0 * ar15 + 9728.0 * ar17 + 1024.0 * ar19)) /
1074 (14175.0 - 467775 * xir2 + 2027025 * xir4 - 2027025 * xir6 - 155925.0 * (yir2 + zir2) +
1075 6081075.0 * xir2 * (yir2 + zir2) - 30405375.0 * xir4 * (yir2 + zir2) + 34459425.0 * xir6 * (yir2 + zir2) +
1076 2027025.0 * yir2 * zir2 - 91216125.0 * xir2 * yir2 * zir2 + 516891375.0 * xir4 * yir2 * zir2 -
1077 654729075.0 * xir6 * yir2 * zir2) *
1081 ((17010 * ar + 11340 * ar3 + 4536 * ar5 + 1296 * ar7 + 288 * ar9) -
1082 (xir2 + yir2) * (374220 * ar + 249480 * ar3 + 99792 * ar5 + 28512 * ar7 + 6336 * ar9 + 1152 * ar11) +
1083 (xir4 + yir4) * (810810 * ar + 540540 * ar3 + 216216 * ar5 + 61776 * ar7 + 13728 * ar9 + 2496 * ar11 + 384 * ar13) +
1085 (9729720 * ar + 6486480 * ar3 + 2594592 * ar5 + 741312 * ar7 + 164736 * ar9 + 29952 * ar11 + 4608 * ar13) -
1086 (xir4 * yir2 + xir2 * yir4) * (24324300 * ar + 16216200 * ar3 + 6486480 * ar5 + 1853280 * ar7 + 411840 * ar9 +
1087 74880 * ar11 + 11520 * ar13 + 1536 * ar15) +
1089 (68918850 * ar + 45945900 * ar3 + 18378360 * ar5 + 5250960 * ar7 + 1166880 * ar9 + 212160 * ar11 +
1090 32640 * ar13 + 4352 * ar15 + 512.0 * ar17) -
1091 zir2 * (187110 * ar + 124740 * ar3 + 49896 * ar5 + 14256 * ar7 + 3168 * ar9 + 576 * ar11) +
1092 (xir2 + yir2) * zir2 *
1093 (4864860 * ar + 3243240 * ar3 + 1297296 * ar5 + 370656 * ar7 + 82368 * ar9 + 14976 * ar11 + 2304 * ar13) -
1094 (xir4 + yir4) * zir2 *
1095 (12162150 * ar + 8108100 * ar3 + 3243240 * ar5 + 926640 * ar7 + 205920 * ar9 + 37440 * ar11 + 5760 * ar13 +
1097 xir2 * yir2 * zir2 *
1098 (145945800 * ar + 97297200 * ar3 + 38918880 * ar5 + 11119680 * ar7 + 2471040 * ar9 + 449280 * ar11 +
1099 69120 * ar13 + 9216 * ar15) +
1100 (xir4 * yir2 + xir2 * yir4) * zir2 *
1101 (413513100 * ar + 275675400 * ar3 + 110270160 * ar5 + 31505760 * ar7 + 7001280 * ar9 + 1272960 * ar11 +
1102 195840 * ar13 + 26112 * ar15 + 3072 * ar17) -
1103 xir4 * yir4 * zir2 *
1104 (1309458150.0 * ar + 872972100.0 * ar3 + 349188840.0 * ar5 + 99768240.0 * ar7 + 22170720.0 * ar9 +
1105 4031040.0 * ar11 + 620160.0 * ar13 + 82688.0 * ar15 + 9728.0 * ar17 + 1024.0 * ar19)) /
1108 (8505.0 - 187110 * (xir2 + yir2) + 405405 * (xir4 + yir4) + 4864860 * xir2 * yir2 -
1109 12162150 * (xir4 * yir2 + xir2 * yir4) + 34459425 * xir4 * yir4 - 93555 * zir2 +
1110 2432430 * (xir2 + yir2) * zir2 - 6081075 * (xir4 + yir4) * zir2 - 72972900 * xir2 * yir2 * zir2 +
1111 206756550 * (xir4 * yir2 + xir2 * yir4) * zir2 - 654729075.0 * xir4 * yir4 * zir2) *
1134 for(
int nx = -nxmax; nx <= nxmax; nx++)
1135 for(
int ny = -nymax; ny <= nymax; ny++)
1136 for(
int nz = -nzmax; nz <= nzmax; nz++)
1138 if(nx != 0 || ny != 0 || nz != 0)
1143 double k2 = kx * kx + ky * ky + kz * kz;
global_data_all_processes All
symtensor3< double > ewald_D3(double x, double y, double z)
ewaldtensor6< double > ewald_P6(void)
double ewald_D0(double x, double y, double z)
This function computes the potential correction term by means of Ewald summation.
symtensor4< double > ewald_D4(double x, double y, double z)
void ewald_corr(double dx, double dy, double dz, enum interpolate_options, ewald_data &fper)
ewaldtensor10< double > ewald_P10(void)
ewaldtensor8< double > ewald_P8(void)
symtensor5< double > ewald_D5(double x, double y, double z)
vector< double > ewald_D1(double x, double y, double z)
This function computes the force correction term (difference between full force of infinite lattice a...
void ewald_corr_exact(double dx, double dy, double dz, enum interpolate_options flag, ewald_data &fper)
symtensor2< double > ewald_D2(double x, double y, double z)
void ewald_gridlookup(const MyIntPosType *p_intpos, const MyIntPosType *target_intpos, enum interpolate_options flag, ewald_data &fper)
MySignedIntPosType pos_to_signedintpos(T posdiff)
int32_t MySignedIntPosType
expr pow(half base, half exp)
symtensor3< MyReal > D3phi
symtensor2< MyReal > D2phi
void init_rng(int thistask)
double get_random_number(void)