-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathgevolution.hpp
1537 lines (1326 loc) · 57.6 KB
/
gevolution.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////
// gevolution.hpp
//////////////////////////
//
// Geneva algorithms for evolution of metric perturbations
// and relativistic free-streaming particles (gevolution)
//
// 1. Suite of Fourier-based methods for the computation of the
// relativistic scalar (Phi, Phi-Psi) and vector modes [see J. Adamek,
// R. Durrer, and M. Kunz, Class. Quant. Grav. 31, 234006 (2014)]
//
// 2. Collection of "update position" and "update velocity/momentum" methods
// [see J. Adamek, D. Daverio, R. Durrer, and M. Kunz, JCAP 1607, 053 (2016)]
//
// 3. Collection of projection methods for the construction of the
// stress-energy-tensor
//
// 4. Fourier-space projection methods for the computation of the
// curl and divergence of the velocity field
//
// Author: Julian Adamek (Université de Genève & Observatoire de Paris & Queen Mary University of London & Universität Zürich)
//
// Last modified: August 2022
//
//////////////////////////
#ifndef GEVOLUTION_HEADER
#define GEVOLUTION_HEADER
#ifndef Cplx
#define Cplx Imag
#endif
using namespace std;
using namespace LATfield2;
//////////////////////////
// prepareFTsource (1)
//////////////////////////
// Description:
// construction of real-space source tensor for Fourier-based solvers
//
// Arguments:
// phi reference to field configuration
// Tij reference to symmetric tensor field containing the space-space
// components of the stress-energy tensor (rescaled by a^3)
// Sij reference to allocated symmetric tensor field which will contain
// the source tensor (may be identical to Tji)
// coeff scaling coefficient for Tij ("8 pi G dx^2 / a")
//
// Returns:
//
//////////////////////////
template <class FieldType>
void prepareFTsource(Field<FieldType> & phi, Field<FieldType> & Tij, Field<FieldType> & Sij, const double coeff)
{
Site x(phi.lattice());
for (x.first(); x.test(); x.next())
{
// 0-0-component:
Sij(x, 0, 0) = coeff * Tij(x, 0, 0);
#ifdef PHINONLINEAR
#ifdef ORIGINALMETRIC
Sij(x, 0, 0) -= 4. * phi(x) * (phi(x-0) + phi(x+0) - 2. * phi(x));
Sij(x, 0, 0) -= 0.5 * (phi(x+0) - phi(x-0)) * (phi(x+0) - phi(x-0));
#else
Sij(x, 0, 0) += 0.5 * (phi(x+0) - phi(x-0)) * (phi(x+0) - phi(x-0));
#endif
#endif
// 1-1-component:
Sij(x, 1, 1) = coeff * Tij(x, 1, 1);
#ifdef PHINONLINEAR
#ifdef ORIGINALMETRIC
Sij(x, 1, 1) -= 4. * phi(x) * (phi(x-1) + phi(x+1) - 2. * phi(x));
Sij(x, 1, 1) -= 0.5 * (phi(x+1) - phi(x-1)) * (phi(x+1) - phi(x-1));
#else
Sij(x, 1, 1) += 0.5 * (phi(x+1) - phi(x-1)) * (phi(x+1) - phi(x-1));
#endif
#endif
// 2-2-component:
Sij(x, 2, 2) = coeff * Tij(x, 2, 2);
#ifdef PHINONLINEAR
#ifdef ORIGINALMETRIC
Sij(x, 2, 2) -= 4. * phi(x) * (phi(x-2) + phi(x+2) - 2. * phi(x));
Sij(x, 2, 2) -= 0.5 * (phi(x+2) - phi(x-2)) * (phi(x+2) - phi(x-2));
#else
Sij(x, 2, 2) += 0.5 * (phi(x+2) - phi(x-2)) * (phi(x+2) - phi(x-2));
#endif
#endif
// 0-1-component:
Sij(x, 0, 1) = coeff * Tij(x, 0, 1);
#ifdef PHINONLINEAR
Sij(x, 0, 1) += phi(x+0) * phi(x+1) - phi(x) * phi(x+0+1);
#ifdef ORIGINALMETRIC
Sij(x, 0, 1) -= 1.5 * phi(x) * phi(x);
Sij(x, 0, 1) += 1.5 * phi(x+0) * phi(x+0);
Sij(x, 0, 1) += 1.5 * phi(x+1) * phi(x+1);
Sij(x, 0, 1) -= 1.5 * phi(x+0+1) * phi(x+0+1);
#else
Sij(x, 0, 1) += 0.5 * phi(x) * phi(x);
Sij(x, 0, 1) -= 0.5 * phi(x+0) * phi(x+0);
Sij(x, 0, 1) -= 0.5 * phi(x+1) * phi(x+1);
Sij(x, 0, 1) += 0.5 * phi(x+0+1) * phi(x+0+1);
#endif
#endif
// 0-2-component:
Sij(x, 0, 2) = coeff * Tij(x, 0, 2);
#ifdef PHINONLINEAR
Sij(x, 0, 2) += phi(x+0) * phi(x+2) - phi(x) * phi(x+0+2);
#ifdef ORIGINALMETRIC
Sij(x, 0, 2) -= 1.5 * phi(x) * phi(x);
Sij(x, 0, 2) += 1.5 * phi(x+0) * phi(x+0);
Sij(x, 0, 2) += 1.5 * phi(x+2) * phi(x+2);
Sij(x, 0, 2) -= 1.5 * phi(x+0+2) * phi(x+0+2);
#else
Sij(x, 0, 2) += 0.5 * phi(x) * phi(x);
Sij(x, 0, 2) -= 0.5 * phi(x+0) * phi(x+0);
Sij(x, 0, 2) -= 0.5 * phi(x+2) * phi(x+2);
Sij(x, 0, 2) += 0.5 * phi(x+0+2) * phi(x+0+2);
#endif
#endif
// 1-2-component:
Sij(x, 1, 2) = coeff * Tij(x, 1, 2);
#ifdef PHINONLINEAR
Sij(x, 1, 2) += phi(x+1) * phi(x+2) - phi(x) * phi(x+1+2);
#ifdef ORIGINALMETRIC
Sij(x, 1, 2) -= 1.5 * phi(x) * phi(x);
Sij(x, 1, 2) += 1.5 * phi(x+1) * phi(x+1);
Sij(x, 1, 2) += 1.5 * phi(x+2) * phi(x+2);
Sij(x, 1, 2) -= 1.5 * phi(x+1+2) * phi(x+1+2);
#else
Sij(x, 1, 2) += 0.5 * phi(x) * phi(x);
Sij(x, 1, 2) -= 0.5 * phi(x+1) * phi(x+1);
Sij(x, 1, 2) -= 0.5 * phi(x+2) * phi(x+2);
Sij(x, 1, 2) += 0.5 * phi(x+1+2) * phi(x+1+2);
#endif
#endif
}
}
//////////////////////////
// prepareFTsource (2)
//////////////////////////
// Description:
// construction of real-space source field for Fourier-based solvers
//
// Arguments:
// phi reference to field configuration (first Bardeen potential)
// chi reference to field configuration (difference between Bardeen potentials, phi-psi)
// source reference to fully dressed source field (rescaled by a^3)
// bgmodel background model of the source (rescaled by a^3) to be subtracted
// result reference to allocated field which will contain the result (may be identical to source)
// coeff diffusion coefficient ("3 H_conformal dx^2 / dtau")
// coeff2 scaling coefficient for the source ("4 pi G dx^2 / a")
// coeff3 scaling coefficient for the psi-term ("3 H_conformal^2 dx^2")
//
// Returns:
//
//////////////////////////
template <class FieldType>
void prepareFTsource(Field<FieldType> & phi, Field<FieldType> & chi, Field<FieldType> & source, const FieldType bgmodel, Field<FieldType> & result, const double coeff, const double coeff2, const double coeff3)
{
Site x(phi.lattice());
for (x.first(); x.test(); x.next())
{
result(x) = coeff2 * (source(x) - bgmodel);
#ifdef PHINONLINEAR
#ifdef ORIGINALMETRIC
result(x) *= 1. - 4. * phi(x);
result(x) -= 0.375 * (phi(x-0) - phi(x+0)) * (phi(x-0) - phi(x+0));
result(x) -= 0.375 * (phi(x-1) - phi(x+1)) * (phi(x-1) - phi(x+1));
result(x) -= 0.375 * (phi(x-2) - phi(x+2)) * (phi(x-2) - phi(x+2));
#else
result(x) *= 1. - 2. * phi(x);
result(x) += 0.125 * (phi(x-0) - phi(x+0)) * (phi(x-0) - phi(x+0));
result(x) += 0.125 * (phi(x-1) - phi(x+1)) * (phi(x-1) - phi(x+1));
result(x) += 0.125 * (phi(x-2) - phi(x+2)) * (phi(x-2) - phi(x+2));
#endif
#endif
result(x) += (coeff3 - coeff) * phi(x) - coeff3 * chi(x);
}
}
#ifdef FFT3D
//////////////////////////
// projectFTscalar
//////////////////////////
// Description:
// projection of the Fourier image of a tensor field on the trace-free
// longitudinal (scalar) component
//
// Arguments:
// SijFT reference to the Fourier image of the input tensor field
// chiFT reference to allocated field which will contain the Fourier
// image of the trace-free longitudinal (scalar) component
//
// Returns:
//
//////////////////////////
void projectFTscalar(Field<Cplx> & SijFT, Field<Cplx> & chiFT, const int add = 0)
{
const int linesize = chiFT.lattice().size(1);
int i;
Real * gridk2;
Cplx * kshift;
rKSite k(chiFT.lattice());
gridk2 = (Real *) malloc(linesize * sizeof(Real));
kshift = (Cplx *) malloc(linesize * sizeof(Cplx));
for (i = 0; i < linesize; i++)
{
gridk2[i] = 2. * (Real) linesize * sin(M_PI * (Real) i / (Real) linesize);
kshift[i] = gridk2[i] * Cplx(cos(M_PI * (Real) i / (Real) linesize), -sin(M_PI * (Real) i / (Real) linesize));
gridk2[i] *= gridk2[i];
}
k.first();
if (k.coord(0) == 0 && k.coord(1) == 0 && k.coord(2) == 0)
{
chiFT(k) = Cplx(0.,0.);
k.next();
}
if (add)
{
for (; k.test(); k.next())
{
chiFT(k) += ((gridk2[k.coord(1)] + gridk2[k.coord(2)] - 2. * gridk2[k.coord(0)]) * SijFT(k, 0, 0) +
(gridk2[k.coord(0)] + gridk2[k.coord(2)] - 2. * gridk2[k.coord(1)]) * SijFT(k, 1, 1) +
(gridk2[k.coord(0)] + gridk2[k.coord(1)] - 2. * gridk2[k.coord(2)]) * SijFT(k, 2, 2) -
6. * kshift[k.coord(0)] * kshift[k.coord(1)] * SijFT(k, 0, 1) -
6. * kshift[k.coord(0)] * kshift[k.coord(2)] * SijFT(k, 0, 2) -
6. * kshift[k.coord(1)] * kshift[k.coord(2)] * SijFT(k, 1, 2)) /
(2. * (gridk2[k.coord(0)] + gridk2[k.coord(1)] + gridk2[k.coord(2)]) * (gridk2[k.coord(0)] + gridk2[k.coord(1)] + gridk2[k.coord(2)]) * linesize);
}
}
else
{
for (; k.test(); k.next())
{
chiFT(k) = ((gridk2[k.coord(1)] + gridk2[k.coord(2)] - 2. * gridk2[k.coord(0)]) * SijFT(k, 0, 0) +
(gridk2[k.coord(0)] + gridk2[k.coord(2)] - 2. * gridk2[k.coord(1)]) * SijFT(k, 1, 1) +
(gridk2[k.coord(0)] + gridk2[k.coord(1)] - 2. * gridk2[k.coord(2)]) * SijFT(k, 2, 2) -
6. * kshift[k.coord(0)] * kshift[k.coord(1)] * SijFT(k, 0, 1) -
6. * kshift[k.coord(0)] * kshift[k.coord(2)] * SijFT(k, 0, 2) -
6. * kshift[k.coord(1)] * kshift[k.coord(2)] * SijFT(k, 1, 2)) /
(2. * (gridk2[k.coord(0)] + gridk2[k.coord(1)] + gridk2[k.coord(2)]) * (gridk2[k.coord(0)] + gridk2[k.coord(1)] + gridk2[k.coord(2)]) * linesize);
}
}
free(gridk2);
free(kshift);
}
//////////////////////////
// evolveFTvector
//////////////////////////
// Description:
// projects the Fourier image of a tensor field on the spin-1 component
// used as a source for the evolution of the vector perturbation
//
// Arguments:
// SijFT reference to the Fourier image of the input tensor field
// BiFT reference to the Fourier image of the vector perturbation
// a2dtau conformal time step times scale factor squared (a^2 * dtau)
//
// Returns:
//
//////////////////////////
void evolveFTvector(Field<Cplx> & SijFT, Field<Cplx> & BiFT, const Real a2dtau)
{
const int linesize = BiFT.lattice().size(1);
int i;
Real * gridk2;
Cplx * kshift;
rKSite k(BiFT.lattice());
Real k4;
gridk2 = (Real *) malloc(linesize * sizeof(Real));
kshift = (Cplx *) malloc(linesize * sizeof(Cplx));
for (i = 0; i < linesize; i++)
{
gridk2[i] = 2. * (Real) linesize * sin(M_PI * (Real) i / (Real) linesize);
kshift[i] = gridk2[i] * Cplx(cos(M_PI * (Real) i / (Real) linesize), -sin(M_PI * (Real) i / (Real) linesize));
gridk2[i] *= gridk2[i];
}
k.first();
if (k.coord(0) == 0 && k.coord(1) == 0 && k.coord(2) == 0)
{
BiFT(k, 0) = Cplx(0.,0.);
BiFT(k, 1) = Cplx(0.,0.);
BiFT(k, 2) = Cplx(0.,0.);
k.next();
}
for (; k.test(); k.next())
{
k4 = gridk2[k.coord(0)] + gridk2[k.coord(1)] + gridk2[k.coord(2)];
k4 *= k4;
BiFT(k, 0) += Cplx(0.,-2.*a2dtau/k4) * (kshift[k.coord(0)].conj() * ((gridk2[k.coord(1)] + gridk2[k.coord(2)]) * SijFT(k, 0, 0)
- gridk2[k.coord(1)] * SijFT(k, 1, 1) - gridk2[k.coord(2)] * SijFT(k, 2, 2) - 2. * kshift[k.coord(1)] * kshift[k.coord(2)] * SijFT(k, 1, 2))
+ (gridk2[k.coord(1)] + gridk2[k.coord(2)] - gridk2[k.coord(0)]) * (kshift[k.coord(1)] * SijFT(k, 0, 1) + kshift[k.coord(2)] * SijFT(k, 0, 2)));
BiFT(k, 1) += Cplx(0.,-2.*a2dtau/k4) * (kshift[k.coord(1)].conj() * ((gridk2[k.coord(0)] + gridk2[k.coord(2)]) * SijFT(k, 1, 1)
- gridk2[k.coord(0)] * SijFT(k, 0, 0) - gridk2[k.coord(2)] * SijFT(k, 2, 2) - 2. * kshift[k.coord(0)] * kshift[k.coord(2)] * SijFT(k, 0, 2))
+ (gridk2[k.coord(0)] + gridk2[k.coord(2)] - gridk2[k.coord(1)]) * (kshift[k.coord(0)] * SijFT(k, 0, 1) + kshift[k.coord(2)] * SijFT(k, 1, 2)));
BiFT(k, 2) += Cplx(0.,-2.*a2dtau/k4) * (kshift[k.coord(2)].conj() * ((gridk2[k.coord(0)] + gridk2[k.coord(1)]) * SijFT(k, 2, 2)
- gridk2[k.coord(0)] * SijFT(k, 0, 0) - gridk2[k.coord(1)] * SijFT(k, 1, 1) - 2. * kshift[k.coord(0)] * kshift[k.coord(1)] * SijFT(k, 0, 1))
+ (gridk2[k.coord(0)] + gridk2[k.coord(1)] - gridk2[k.coord(2)]) * (kshift[k.coord(0)] * SijFT(k, 0, 2) + kshift[k.coord(1)] * SijFT(k, 1, 2)));
}
free(gridk2);
free(kshift);
}
//////////////////////////
// projectFTvector
//////////////////////////
// Description:
// projects the Fourier image of a vector field on the transverse component
// and solves the constraint equation for the vector perturbation
//
// Arguments:
// SiFT reference to the Fourier image of the input vector field
// BiFT reference to the Fourier image of the vector perturbation (can be identical to input)
// coeff rescaling coefficient (default 1)
// modif modification k^2 -> k^2 + modif (default 0)
//
// Returns:
//
//////////////////////////
void projectFTvector(Field<Cplx> & SiFT, Field<Cplx> & BiFT, const Real coeff = 1., const Real modif = 0.)
{
const int linesize = BiFT.lattice().size(1);
int i;
Real * gridk2;
Cplx * kshift;
rKSite k(BiFT.lattice());
Real k2;
Cplx tmp(0., 0.);
gridk2 = (Real *) malloc(linesize * sizeof(Real));
kshift = (Cplx *) malloc(linesize * sizeof(Cplx));
for (i = 0; i < linesize; i++)
{
gridk2[i] = 2. * (Real) linesize * sin(M_PI * (Real) i / (Real) linesize);
kshift[i] = gridk2[i] * Cplx(cos(M_PI * (Real) i / (Real) linesize), -sin(M_PI * (Real) i / (Real) linesize));
gridk2[i] *= gridk2[i];
}
k.first();
if (k.coord(0) == 0 && k.coord(1) == 0 && k.coord(2) == 0)
{
BiFT(k, 0) = Cplx(0.,0.);
BiFT(k, 1) = Cplx(0.,0.);
BiFT(k, 2) = Cplx(0.,0.);
k.next();
}
for (; k.test(); k.next())
{
k2 = gridk2[k.coord(0)] + gridk2[k.coord(1)] + gridk2[k.coord(2)];
tmp = (kshift[k.coord(0)] * SiFT(k, 0) + kshift[k.coord(1)] * SiFT(k, 1) + kshift[k.coord(2)] * SiFT(k, 2)) / k2;
BiFT(k, 0) = (SiFT(k, 0) - kshift[k.coord(0)].conj() * tmp) * 4. * coeff / (k2 + modif);
BiFT(k, 1) = (SiFT(k, 1) - kshift[k.coord(1)].conj() * tmp) * 4. * coeff / (k2 + modif);
BiFT(k, 2) = (SiFT(k, 2) - kshift[k.coord(2)].conj() * tmp) * 4. * coeff / (k2 + modif);
}
free(gridk2);
free(kshift);
}
//////////////////////////
// projectFTtensor
//////////////////////////
// Description:
// projection of the Fourier image of a tensor field on the transverse
// trace-free tensor component
//
// Arguments:
// SijFT reference to the Fourier image of the input tensor field
// hijFT reference to allocated field which will contain the Fourier
// image of the transverse trace-free tensor component
//
// Returns:
//
//////////////////////////
void projectFTtensor(Field<Cplx> & SijFT, Field<Cplx> & hijFT)
{
const int linesize = hijFT.lattice().size(1);
int i;
Real * gridk2;
Cplx * kshift;
rKSite k(hijFT.lattice());
Cplx SxxFT, SxyFT, SxzFT, SyyFT, SyzFT, SzzFT;
Real k2, k6;
gridk2 = (Real *) malloc(linesize * sizeof(Real));
kshift = (Cplx *) malloc(linesize * sizeof(Cplx));
for (i = 0; i < linesize; i++)
{
gridk2[i] = 2. * (Real) linesize * sin(M_PI * (Real) i / (Real) linesize);
kshift[i] = gridk2[i] * Cplx(cos(M_PI * (Real) i / (Real) linesize), -sin(M_PI * (Real) i / (Real) linesize));
gridk2[i] *= gridk2[i];
}
k.first();
if (k.coord(0) == 0 && k.coord(1) == 0 && k.coord(2) == 0)
{
for (i = 0; i < hijFT.components(); i++)
hijFT(k, i) = Cplx(0.,0.);
k.next();
}
for (; k.test(); k.next())
{
SxxFT = SijFT(k, 0, 0);
SxyFT = SijFT(k, 0, 1);
SxzFT = SijFT(k, 0, 2);
SyyFT = SijFT(k, 1, 1);
SyzFT = SijFT(k, 1, 2);
SzzFT = SijFT(k, 2, 2);
k2 = gridk2[k.coord(0)] + gridk2[k.coord(1)] + gridk2[k.coord(2)];
k6 = k2 * k2 * k2 * linesize;
hijFT(k, 0, 0) = ((gridk2[k.coord(0)] - k2) * ((gridk2[k.coord(0)] - k2) * SxxFT + 2. * kshift[k.coord(0)] * (kshift[k.coord(1)] * SxyFT + kshift[k.coord(2)] * SxzFT))
+ ((gridk2[k.coord(0)] + k2) * (gridk2[k.coord(1)] + k2) - 2. * k2 * k2) * SyyFT
+ ((gridk2[k.coord(0)] + k2) * (gridk2[k.coord(2)] + k2) - 2. * k2 * k2) * SzzFT
+ 2. * (gridk2[k.coord(0)] + k2) * kshift[k.coord(1)] * kshift[k.coord(2)] * SyzFT) / k6;
hijFT(k, 0, 1) = (2. * (gridk2[k.coord(0)] - k2) * (gridk2[k.coord(1)] - k2) * SxyFT + (gridk2[k.coord(2)] + k2) * kshift[k.coord(0)].conj() * kshift[k.coord(1)].conj() * SzzFT
+ (gridk2[k.coord(0)] - k2) * kshift[k.coord(1)].conj() * (kshift[k.coord(0)].conj() * SxxFT + 2. * kshift[k.coord(2)] * SxzFT)
+ (gridk2[k.coord(1)] - k2) * kshift[k.coord(0)].conj() * (kshift[k.coord(1)].conj() * SyyFT + 2. * kshift[k.coord(2)] * SyzFT)) / k6;
hijFT(k, 0, 2) = (2. * (gridk2[k.coord(0)] - k2) * (gridk2[k.coord(2)] - k2) * SxzFT + (gridk2[k.coord(1)] + k2) * kshift[k.coord(0)].conj() * kshift[k.coord(2)].conj() * SyyFT
+ (gridk2[k.coord(0)] - k2) * kshift[k.coord(2)].conj() * (kshift[k.coord(0)].conj() * SxxFT + 2. * kshift[k.coord(1)] * SxyFT)
+ (gridk2[k.coord(2)] - k2) * kshift[k.coord(0)].conj() * (kshift[k.coord(2)].conj() * SzzFT + 2. * kshift[k.coord(1)] * SyzFT)) / k6;
hijFT(k, 1, 1) = ((gridk2[k.coord(1)] - k2) * ((gridk2[k.coord(1)] - k2) * SyyFT + 2. * kshift[k.coord(1)] * (kshift[k.coord(0)] * SxyFT + kshift[k.coord(2)] * SyzFT))
+ ((gridk2[k.coord(1)] + k2) * (gridk2[k.coord(0)] + k2) - 2. * k2 * k2) * SxxFT
+ ((gridk2[k.coord(1)] + k2) * (gridk2[k.coord(2)] + k2) - 2. * k2 * k2) * SzzFT
+ 2. * (gridk2[k.coord(1)] + k2) * kshift[k.coord(0)] * kshift[k.coord(2)] * SxzFT) / k6;
hijFT(k, 1, 2) = (2. * (gridk2[k.coord(1)] - k2) * (gridk2[k.coord(2)] - k2) * SyzFT + (gridk2[k.coord(0)] + k2) * kshift[k.coord(1)].conj() * kshift[k.coord(2)].conj() * SxxFT
+ (gridk2[k.coord(1)] - k2) * kshift[k.coord(2)].conj() * (kshift[k.coord(1)].conj() * SyyFT + 2. * kshift[k.coord(0)] * SxyFT)
+ (gridk2[k.coord(2)] - k2) * kshift[k.coord(1)].conj() * (kshift[k.coord(2)].conj() * SzzFT + 2. * kshift[k.coord(0)] * SxzFT)) / k6;
hijFT(k, 2, 2) = ((gridk2[k.coord(2)] - k2) * ((gridk2[k.coord(2)] - k2) * SzzFT + 2. * kshift[k.coord(2)] * (kshift[k.coord(0)] * SxzFT + kshift[k.coord(1)] * SyzFT))
+ ((gridk2[k.coord(2)] + k2) * (gridk2[k.coord(0)] + k2) - 2. * k2 * k2) * SxxFT
+ ((gridk2[k.coord(2)] + k2) * (gridk2[k.coord(1)] + k2) - 2. * k2 * k2) * SyyFT
+ 2. * (gridk2[k.coord(2)] + k2) * kshift[k.coord(0)] * kshift[k.coord(1)] * SxyFT) / k6;
}
free(gridk2);
free(kshift);
}
//////////////////////////
// solveModifiedPoissonFT
//////////////////////////
// Description:
// Modified Poisson solver using the standard Fourier method
//
// Arguments:
// sourceFT reference to the Fourier image of the source field
// potFT reference to the Fourier image of the potential
// coeff coefficient applied to the source ("4 pi G / a")
// modif modification k^2 -> k^2 + modif (default 0 gives standard Poisson equation)
//
// Returns:
//
//////////////////////////
void solveModifiedPoissonFT(Field<Cplx> & sourceFT, Field<Cplx> & potFT, Real coeff, const Real modif = 0.)
{
const int linesize = potFT.lattice().size(1);
int i;
Real * gridk2;
Real * sinc;
rKSite k(potFT.lattice());
gridk2 = (Real *) malloc(linesize * sizeof(Real));
coeff /= -((long) linesize * (long) linesize * (long) linesize);
for (i = 0; i < linesize; i++)
{
gridk2[i] = 2. * (Real) linesize * sin(M_PI * (Real) i / (Real) linesize);
gridk2[i] *= gridk2[i];
}
k.first();
if (k.coord(0) == 0 && k.coord(1) == 0 && k.coord(2) == 0)
{
if (modif == 0.)
potFT(k) = Cplx(0.,0.);
else
potFT(k) = sourceFT(k) * coeff / modif;
k.next();
}
for (; k.test(); k.next())
{
potFT(k) = sourceFT(k) * coeff / (gridk2[k.coord(0)] + gridk2[k.coord(1)] + gridk2[k.coord(2)] + modif);
}
free(gridk2);
}
#endif
//////////////////////////
// update_q
//////////////////////////
// Description:
// Update momentum method (arbitrary momentum)
// Note that vel[3] in the particle structure is used to store q[3] in units
// of the particle mass, such that as q^2 << m^2 a^2 the meaning of vel[3]
// is ~ v*a.
//
// Arguments:
// dtau time step
// dx lattice unit
// part pointer to particle structure
// ref_dist distance vector to reference point
// partInfo global particle properties (unused)
// fields array of pointers to fields appearing in geodesic equation
// fields[0] = phi
// fields[1] = chi
// fields[2] = Bi
// sites array of sites on the respective lattices
// nfield number of fields
// params array of additional parameters
// params[0] = a
// params[1] = scaling coefficient for Bi
// outputs array of reduction variables
// noutputs number of reduction variables
//
// Returns: squared velocity of particle after update
//
//////////////////////////
Real update_q(double dtau, double dx, part_simple * part, double * ref_dist, part_simple_info partInfo, Field<Real> ** fields, Site * sites, int nfield, double * params, double * outputs, int noutputs)
{
#define phi (*fields[0])
#define chi (*fields[1])
#define Bi (*fields[2])
#define xphi (sites[0])
#define xchi (sites[1])
#define xB (sites[2])
Real gradphi[3]={0,0,0};
Real pgradB[3]={0,0,0};
Real v2 = (*part).vel[0] * (*part).vel[0] + (*part).vel[1] * (*part).vel[1] + (*part).vel[2] * (*part).vel[2];
Real e2 = v2 + params[0] * params[0];
#if GRADIENT_ORDER == 1
gradphi[0] = (1.-ref_dist[1]) * (1.-ref_dist[2]) * (phi(xphi+0) - phi(xphi));
gradphi[1] = (1.-ref_dist[0]) * (1.-ref_dist[2]) * (phi(xphi+1) - phi(xphi));
gradphi[2] = (1.-ref_dist[0]) * (1.-ref_dist[1]) * (phi(xphi+2) - phi(xphi));
gradphi[0] += ref_dist[1] * (1.-ref_dist[2]) * (phi(xphi+1+0) - phi(xphi+1));
gradphi[1] += ref_dist[0] * (1.-ref_dist[2]) * (phi(xphi+1+0) - phi(xphi+0));
gradphi[2] += ref_dist[0] * (1.-ref_dist[1]) * (phi(xphi+2+0) - phi(xphi+0));
gradphi[0] += (1.-ref_dist[1]) * ref_dist[2] * (phi(xphi+2+0) - phi(xphi+2));
gradphi[1] += (1.-ref_dist[0]) * ref_dist[2] * (phi(xphi+2+1) - phi(xphi+2));
gradphi[2] += (1.-ref_dist[0]) * ref_dist[1] * (phi(xphi+2+1) - phi(xphi+1));
gradphi[0] += ref_dist[1] * ref_dist[2] * (phi(xphi+2+1+0) - phi(xphi+2+1));
gradphi[1] += ref_dist[0] * ref_dist[2] * (phi(xphi+2+1+0) - phi(xphi+2+0));
gradphi[2] += ref_dist[0] * ref_dist[1] * (phi(xphi+2+1+0) - phi(xphi+1+0));
#elif GRADIENT_ORDER == 2
for (int i=0; i<3; i++)
{
gradphi[i] = 0.5 * (1.-ref_dist[0]) * (1.-ref_dist[1]) * (1.-ref_dist[2]) * (phi(xphi+i) - phi(xphi-i));
gradphi[i] += 0.5 * ref_dist[0] * (1.-ref_dist[1]) * (1.-ref_dist[2]) * (phi(xphi+i+0) - phi(xphi-i+0));
gradphi[i] += 0.5 * (1.-ref_dist[0]) * ref_dist[1] * (1.-ref_dist[2]) * (phi(xphi+i+1) - phi(xphi-i+1));
gradphi[i] += 0.5 * ref_dist[0] * ref_dist[1] * (1.-ref_dist[2]) * (phi(xphi+i+1+0) - phi(xphi-i+1+0));
gradphi[i] += 0.5 * (1.-ref_dist[0]) * (1.-ref_dist[1]) * ref_dist[2] * (phi(xphi+2+i) - phi(xphi+2-i));
gradphi[i] += 0.5 * ref_dist[0] * (1.-ref_dist[1]) * ref_dist[2] * (phi(xphi+2+i+0) - phi(xphi+2-i+0));
gradphi[i] += 0.5 * (1.-ref_dist[0]) * ref_dist[1] * ref_dist[2] * (phi(xphi+2+i+1) - phi(xphi+2-i+1));
gradphi[i] += 0.5 * ref_dist[0] * ref_dist[1] * ref_dist[2] * (phi(xphi+2+i+1+0) - phi(xphi+2-i+1+0));
}
#else
#error GRADIENT_ORDER must be set to 1 or 2
#endif
gradphi[0] *= (v2 + e2) / e2;
gradphi[1] *= (v2 + e2) / e2;
gradphi[2] *= (v2 + e2) / e2;
if (nfield>=2 && fields[1] != NULL)
{
gradphi[0] -= (1.-ref_dist[1]) * (1.-ref_dist[2]) * (chi(xchi+0) - chi(xchi));
gradphi[1] -= (1.-ref_dist[0]) * (1.-ref_dist[2]) * (chi(xchi+1) - chi(xchi));
gradphi[2] -= (1.-ref_dist[0]) * (1.-ref_dist[1]) * (chi(xchi+2) - chi(xchi));
gradphi[0] -= ref_dist[1] * (1.-ref_dist[2]) * (chi(xchi+1+0) - chi(xchi+1));
gradphi[1] -= ref_dist[0] * (1.-ref_dist[2]) * (chi(xchi+1+0) - chi(xchi+0));
gradphi[2] -= ref_dist[0] * (1.-ref_dist[1]) * (chi(xchi+2+0) - chi(xchi+0));
gradphi[0] -= (1.-ref_dist[1]) * ref_dist[2] * (chi(xchi+2+0) - chi(xchi+2));
gradphi[1] -= (1.-ref_dist[0]) * ref_dist[2] * (chi(xchi+2+1) - chi(xchi+2));
gradphi[2] -= (1.-ref_dist[0]) * ref_dist[1] * (chi(xchi+2+1) - chi(xchi+1));
gradphi[0] -= ref_dist[1] * ref_dist[2] * (chi(xchi+2+1+0) - chi(xchi+2+1));
gradphi[1] -= ref_dist[0] * ref_dist[2] * (chi(xchi+2+1+0) - chi(xchi+2+0));
gradphi[2] -= ref_dist[0] * ref_dist[1] * (chi(xchi+2+1+0) - chi(xchi+1+0));
}
e2 = sqrt(e2);
if (nfield>=3 && fields[2] != NULL)
{
pgradB[0] = ((1.-ref_dist[2]) * (Bi(xB+0,1) - Bi(xB,1)) + ref_dist[2] * (Bi(xB+2+0,1) - Bi(xB+2,1))) * (*part).vel[1];
pgradB[0] += ((1.-ref_dist[1]) * (Bi(xB+0,2) - Bi(xB,2)) + ref_dist[1] * (Bi(xB+1+0,2) - Bi(xB+1,2))) * (*part).vel[2];
pgradB[0] += (1.-ref_dist[1]) * (1.-ref_dist[2]) * ((ref_dist[0]-1.) * Bi(xB-0,0) + (1.-2.*ref_dist[0]) * Bi(xB,0) + ref_dist[0] * Bi(xB+0,0)) * (*part).vel[0];
pgradB[0] += ref_dist[1] * (1.-ref_dist[2]) * ((ref_dist[0]-1.) * Bi(xB+1-0,0) + (1.-2.*ref_dist[0]) * Bi(xB+1,0) + ref_dist[0] * Bi(xB+1+0,0)) * (*part).vel[0];
pgradB[0] += (1.-ref_dist[1]) * ref_dist[2] * ((ref_dist[0]-1.) * Bi(xB+2-0,0) + (1.-2.*ref_dist[0]) * Bi(xB+2,0) + ref_dist[0] * Bi(xB+2+0,0)) * (*part).vel[0];
pgradB[0] += ref_dist[1] * ref_dist[2] * ((ref_dist[0]-1.) * Bi(xB+2+1-0,0) + (1.-2.*ref_dist[0]) * Bi(xB+2+1,0) + ref_dist[0] * Bi(xB+2+1+0,0)) * (*part).vel[0];
pgradB[1] = ((1.-ref_dist[0]) * (Bi(xB+1,2) - Bi(xB,2)) + ref_dist[0] * (Bi(xB+1+0,2) - Bi(xB+0,2))) * (*part).vel[2];
pgradB[1] += ((1.-ref_dist[2]) * (Bi(xB+1,0) - Bi(xB,0)) + ref_dist[2] * (Bi(xB+1+2,0) - Bi(xB+2,0))) * (*part).vel[0];
pgradB[1] += (1.-ref_dist[0]) * (1.-ref_dist[2]) * ((ref_dist[1]-1.) * Bi(xB-1,1) + (1.-2.*ref_dist[1]) * Bi(xB,1) + ref_dist[1] * Bi(xB+1,1)) * (*part).vel[1];
pgradB[1] += ref_dist[0] * (1.-ref_dist[2]) * ((ref_dist[1]-1.) * Bi(xB+0-1,1) + (1.-2.*ref_dist[1]) * Bi(xB+0,1) + ref_dist[1] * Bi(xB+0+1,1)) * (*part).vel[1];
pgradB[1] += (1.-ref_dist[0]) * ref_dist[2] * ((ref_dist[1]-1.) * Bi(xB+2-1,1) + (1.-2.*ref_dist[1]) * Bi(xB+2,1) + ref_dist[1] * Bi(xB+2+1,1)) * (*part).vel[1];
pgradB[1] += ref_dist[0] * ref_dist[2] * ((ref_dist[1]-1.) * Bi(xB+2+0-1,1) + (1.-2.*ref_dist[1]) * Bi(xB+2+0,1) + ref_dist[1] * Bi(xB+2+0+1,1)) * (*part).vel[1];
pgradB[2] = ((1.-ref_dist[1]) * (Bi(xB+2,0) - Bi(xB,0)) + ref_dist[1] * (Bi(xB+2+1,0) - Bi(xB+1,0))) * (*part).vel[0];
pgradB[2] += ((1.-ref_dist[0]) * (Bi(xB+2,1) - Bi(xB,1)) + ref_dist[0] * (Bi(xB+2+0,1) - Bi(xB+0,1))) * (*part).vel[1];
pgradB[2] += (1.-ref_dist[0]) * (1.-ref_dist[1]) * ((ref_dist[2]-1.) * Bi(xB-2,2) + (1.-2.*ref_dist[2]) * Bi(xB,2) + ref_dist[2] * Bi(xB+2,2)) * (*part).vel[2];
pgradB[2] += ref_dist[0] * (1.-ref_dist[1]) * ((ref_dist[2]-1.) * Bi(xB+0-2,2) + (1.-2.*ref_dist[2]) * Bi(xB+0,2) + ref_dist[2] * Bi(xB+0+2,2)) * (*part).vel[2];
pgradB[2] += (1.-ref_dist[0]) * ref_dist[1] * ((ref_dist[2]-1.) * Bi(xB+1-2,2) + (1.-2.*ref_dist[2]) * Bi(xB+1,2) + ref_dist[2] * Bi(xB+2+1,2)) * (*part).vel[2];
pgradB[2] += ref_dist[0] * ref_dist[1] * ((ref_dist[2]-1.) * Bi(xB+1+0-2,2) + (1.-2.*ref_dist[2]) * Bi(xB+1+0,2) + ref_dist[2] * Bi(xB+1+0+2,2)) * (*part).vel[2];
gradphi[0] += pgradB[0] / params[1] / e2;
gradphi[1] += pgradB[1] / params[1] / e2;
gradphi[2] += pgradB[2] / params[1] / e2;
}
v2 = 0.;
for (int i=0;i<3;i++)
{
(*part).vel[i] -= dtau * e2 * gradphi[i] / dx;
v2 += (*part).vel[i] * (*part).vel[i];
}
return v2 / params[0] / params[0];
#undef phi
#undef chi
#undef Bi
#undef xphi
#undef xchi
#undef xB
}
//////////////////////////
// update_q_Newton
//////////////////////////
// Description:
// Update momentum method (Newtonian version)
// Note that vel[3] in the particle structure is used to store q[3] in units
// of the particle mass, such that the meaning of vel[3] is v*a.
//
// Arguments:
// dtau time step
// dx lattice unit
// part pointer to particle structure
// ref_dist distance vector to reference point
// partInfo global particle properties (unused)
// fields array of pointers to fields appearing in geodesic equation
// fields[0] = psi
// fields[1] = chi
// sites array of sites on the respective lattices
// nfield number of fields (should be 1)
// params array of additional parameters
// params[0] = a
// outputs array of reduction variables
// noutputs number of reduction variables
//
// Returns: squared velocity of particle after update
//
//////////////////////////
Real update_q_Newton(double dtau, double dx, part_simple * part, double * ref_dist, part_simple_info partInfo, Field<Real> ** fields, Site * sites, int nfield, double * params, double * outputs, int noutputs)
{
#define psi (*fields[0])
#define xpsi (sites[0])
#define chi (*fields[1])
#define xchi (sites[1])
Real gradpsi[3]={0,0,0};
#if GRADIENT_ORDER == 1
gradpsi[0] = (1.-ref_dist[1]) * (1.-ref_dist[2]) * (psi(xpsi+0) - psi(xpsi));
gradpsi[1] = (1.-ref_dist[0]) * (1.-ref_dist[2]) * (psi(xpsi+1) - psi(xpsi));
gradpsi[2] = (1.-ref_dist[0]) * (1.-ref_dist[1]) * (psi(xpsi+2) - psi(xpsi));
gradpsi[0] += ref_dist[1] * (1.-ref_dist[2]) * (psi(xpsi+1+0) - psi(xpsi+1));
gradpsi[1] += ref_dist[0] * (1.-ref_dist[2]) * (psi(xpsi+1+0) - psi(xpsi+0));
gradpsi[2] += ref_dist[0] * (1.-ref_dist[1]) * (psi(xpsi+2+0) - psi(xpsi+0));
gradpsi[0] += (1.-ref_dist[1]) * ref_dist[2] * (psi(xpsi+2+0) - psi(xpsi+2));
gradpsi[1] += (1.-ref_dist[0]) * ref_dist[2] * (psi(xpsi+2+1) - psi(xpsi+2));
gradpsi[2] += (1.-ref_dist[0]) * ref_dist[1] * (psi(xpsi+2+1) - psi(xpsi+1));
gradpsi[0] += ref_dist[1] * ref_dist[2] * (psi(xpsi+2+1+0) - psi(xpsi+2+1));
gradpsi[1] += ref_dist[0] * ref_dist[2] * (psi(xpsi+2+1+0) - psi(xpsi+2+0));
gradpsi[2] += ref_dist[0] * ref_dist[1] * (psi(xpsi+2+1+0) - psi(xpsi+1+0));
#elif GRADIENT_ORDER == 2
for (int i=0; i<3; i++)
{
gradpsi[i] = 0.5 * (1.-ref_dist[0]) * (1.-ref_dist[1]) * (1.-ref_dist[2]) * (psi(xpsi+i) - psi(xpsi-i));
gradpsi[i] += 0.5 * ref_dist[0] * (1.-ref_dist[1]) * (1.-ref_dist[2]) * (psi(xpsi+i+0) - psi(xpsi-i+0));
gradpsi[i] += 0.5 * (1.-ref_dist[0]) * ref_dist[1] * (1.-ref_dist[2]) * (psi(xpsi+i+1) - psi(xpsi-i+1));
gradpsi[i] += 0.5 * ref_dist[0] * ref_dist[1] * (1.-ref_dist[2]) * (psi(xpsi+i+1+0) - psi(xpsi-i+1+0));
gradpsi[i] += 0.5 * (1.-ref_dist[0]) * (1.-ref_dist[1]) * ref_dist[2] * (psi(xpsi+2+i) - psi(xpsi+2-i));
gradpsi[i] += 0.5 * ref_dist[0] * (1.-ref_dist[1]) * ref_dist[2] * (psi(xpsi+2+i+0) - psi(xpsi+2-i+0));
gradpsi[i] += 0.5 * (1.-ref_dist[0]) * ref_dist[1] * ref_dist[2] * (psi(xpsi+2+i+1) - psi(xpsi+2-i+1));
gradpsi[i] += 0.5 * ref_dist[0] * ref_dist[1] * ref_dist[2] * (psi(xpsi+2+i+1+0) - psi(xpsi+2-i+1+0));
}
#else
#error GRADIENT_ORDER must be set to 1 or 2
#endif
if (nfield>=2 && fields[1] != NULL)
{
gradpsi[0] -= (1.-ref_dist[1]) * (1.-ref_dist[2]) * (chi(xchi+0) - chi(xchi));
gradpsi[1] -= (1.-ref_dist[0]) * (1.-ref_dist[2]) * (chi(xchi+1) - chi(xchi));
gradpsi[2] -= (1.-ref_dist[0]) * (1.-ref_dist[1]) * (chi(xchi+2) - chi(xchi));
gradpsi[0] -= ref_dist[1] * (1.-ref_dist[2]) * (chi(xchi+1+0) - chi(xchi+1));
gradpsi[1] -= ref_dist[0] * (1.-ref_dist[2]) * (chi(xchi+1+0) - chi(xchi+0));
gradpsi[2] -= ref_dist[0] * (1.-ref_dist[1]) * (chi(xchi+2+0) - chi(xchi+0));
gradpsi[0] -= (1.-ref_dist[1]) * ref_dist[2] * (chi(xchi+2+0) - chi(xchi+2));
gradpsi[1] -= (1.-ref_dist[0]) * ref_dist[2] * (chi(xchi+2+1) - chi(xchi+2));
gradpsi[2] -= (1.-ref_dist[0]) * ref_dist[1] * (chi(xchi+2+1) - chi(xchi+1));
gradpsi[0] -= ref_dist[1] * ref_dist[2] * (chi(xchi+2+1+0) - chi(xchi+2+1));
gradpsi[1] -= ref_dist[0] * ref_dist[2] * (chi(xchi+2+1+0) - chi(xchi+2+0));
gradpsi[2] -= ref_dist[0] * ref_dist[1] * (chi(xchi+2+1+0) - chi(xchi+1+0));
}
Real v2 = 0.;
for (int i=0;i<3;i++)
{
(*part).vel[i] -= dtau * params[0] * gradpsi[i] / dx;
v2 += (*part).vel[i] * (*part).vel[i];
}
return v2 / params[0] / params[0];
#undef psi
#undef xpsi
#undef chi
#undef xchi
}
//////////////////////////
// update_pos
//////////////////////////
// Description:
// Update position method (arbitrary momentum)
// Note that vel[3] in the particle structure is used to store q[3] in units
// of the particle mass, such that as q^2 << m^2 a^2 the meaning of vel[3]
// is ~ v*a.
//
// Arguments:
// dtau time step
// dx lattice unit
// part pointer to particle structure
// ref_dist distance vector to reference point
// partInfo global particle properties (unused)
// fields array of pointers to fields appearing in geodesic equation
// fields[0] = phi
// fields[1] = chi
// fields[2] = Bi
// sites array of sites on the respective lattices
// nfield number of fields
// params array of additional parameters
// params[0] = a
// params[1] = scaling coefficient for Bi
// outputs array of reduction variables
// noutputs number of reduction variables
//
// Returns:
//
//////////////////////////
void update_pos(double dtau, double dx, part_simple * part, double * ref_dist, part_simple_info partInfo, Field<Real> ** fields, Site * sites, int nfield, double * params, double * outputs, int noutputs)
{
Real v[3];
Real v2 = (*part).vel[0] * (*part).vel[0] + (*part).vel[1] * (*part).vel[1] + (*part).vel[2] * (*part).vel[2];
Real e2 = v2 + params[0] * params[0];
Real phi = 0;
Real chi = 0;
if (nfield >= 1)
{
phi = (*fields[0])(sites[0]) * (1.-ref_dist[0]) * (1.-ref_dist[1]) * (1.-ref_dist[2]);
phi += (*fields[0])(sites[0]+0) * ref_dist[0] * (1.-ref_dist[1]) * (1.-ref_dist[2]);
phi += (*fields[0])(sites[0]+1) * (1.-ref_dist[0]) * ref_dist[1] * (1.-ref_dist[2]);
phi += (*fields[0])(sites[0]+0+1) * ref_dist[0] * ref_dist[1] * (1.-ref_dist[2]);
phi += (*fields[0])(sites[0]+2) * (1.-ref_dist[0]) * (1.-ref_dist[1]) * ref_dist[2];
phi += (*fields[0])(sites[0]+0+2) * ref_dist[0] * (1.-ref_dist[1]) * ref_dist[2];
phi += (*fields[0])(sites[0]+1+2) * (1.-ref_dist[0]) * ref_dist[1] * ref_dist[2];
phi += (*fields[0])(sites[0]+0+1+2) * ref_dist[0] * ref_dist[1] * ref_dist[2];
}
if (nfield >= 2)
{
chi = (*fields[1])(sites[1]) * (1.-ref_dist[0]) * (1.-ref_dist[1]) * (1.-ref_dist[2]);
chi += (*fields[1])(sites[1]+0) * ref_dist[0] * (1.-ref_dist[1]) * (1.-ref_dist[2]);
chi += (*fields[1])(sites[1]+1) * (1.-ref_dist[0]) * ref_dist[1] * (1.-ref_dist[2]);
chi += (*fields[1])(sites[1]+0+1) * ref_dist[0] * ref_dist[1] * (1.-ref_dist[2]);
chi += (*fields[1])(sites[1]+2) * (1.-ref_dist[0]) * (1.-ref_dist[1]) * ref_dist[2];
chi += (*fields[1])(sites[1]+0+2) * ref_dist[0] * (1.-ref_dist[1]) * ref_dist[2];
chi += (*fields[1])(sites[1]+1+2) * (1.-ref_dist[0]) * ref_dist[1] * ref_dist[2];
chi += (*fields[1])(sites[1]+0+1+2) * ref_dist[0] * ref_dist[1] * ref_dist[2];
}
v2 = (1. + (3. - v2 / e2) * phi - chi) / sqrt(e2);
v[0] = (*part).vel[0] * v2;
v[1] = (*part).vel[1] * v2;
v[2] = (*part).vel[2] * v2;
if (nfield >= 3)
{
Real b[3];
b[0] = (*fields[2])(sites[2], 0) * (1.-ref_dist[1]) * (1.-ref_dist[2]);
b[1] = (*fields[2])(sites[2], 1) * (1.-ref_dist[0]) * (1.-ref_dist[2]);
b[2] = (*fields[2])(sites[2], 2) * (1.-ref_dist[0]) * (1.-ref_dist[1]);
b[1] += (*fields[2])(sites[2]+0, 1) * ref_dist[0] * (1.-ref_dist[2]);
b[2] += (*fields[2])(sites[2]+0, 2) * ref_dist[0] * (1.-ref_dist[1]);
b[0] += (*fields[2])(sites[2]+1, 0) * ref_dist[1] * (1.-ref_dist[2]);
b[2] += (*fields[2])(sites[2]+1, 2) * (1.-ref_dist[0]) * ref_dist[1];
b[0] += (*fields[2])(sites[2]+2, 0) * (1.-ref_dist[1]) * ref_dist[2];
b[1] += (*fields[2])(sites[2]+2, 1) * (1.-ref_dist[0]) * ref_dist[2];
b[1] += (*fields[2])(sites[2]+2+0, 1) * ref_dist[0] * ref_dist[2];
b[0] += (*fields[2])(sites[2]+2+1, 0) * ref_dist[1] * ref_dist[2];
b[2] += (*fields[2])(sites[2]+1+0, 2) * ref_dist[0] * ref_dist[1];
for (int l=0;l<3;l++) (*part).pos[l] += dtau*(v[l] + b[l] / params[1]);
}
else
{
for (int l=0;l<3;l++) (*part).pos[l] += dtau*v[l];
}
}
//////////////////////////
// update_pos_Newton
//////////////////////////
// Description:
// Update position method (Newtonian version)
// Note that vel[3] in the particle structure is used to store q[3] in units
// of the particle mass, such that the meaning of vel[3] is v*a.
//
// Arguments:
// dtau time step
// dx lattice unit (unused)
// part pointer to particle structure
// ref_dist distance vector to reference point (unused)
// partInfo global particle properties (unused)
// fields array of pointers to fields appearing in geodesic equation (unused)
// sites array of sites on the respective lattices (unused)
// nfield number of fields (unused)
// params array of additional parameters
// params[0] = a
// outputs array of reduction variables (unused)
// noutputs number of reduction variables (unused)
//
// Returns:
//
//////////////////////////
void update_pos_Newton(double dtau, double dx, part_simple * part, double * ref_dist, part_simple_info partInfo, Field<Real> ** fields, Site * sites, int nfield, double * params, double * outputs, int noutputs)
{
for (int l=0;l<3;l++) (*part).pos[l] += dtau * (*part).vel[l] / params[0];
}
//////////////////////////
// projection_T00_project
//////////////////////////
// Description:
// Particle-mesh projection for T00, including geometric corrections
//
// Arguments:
// pcls pointer to particle handler
// T00 pointer to target field
// a scale factor at projection (needed in order to convert
// canonical momenta to energies)
// phi pointer to Bardeen potential which characterizes the
// geometric corrections (volume distortion); can be set to
// NULL which will result in no corrections applied
// coeff coefficient applied to the projection operation (default 1)
//
// Returns:
//
//////////////////////////
template<typename part, typename part_info, typename part_dataType>
void projection_T00_project(Particles<part, part_info, part_dataType> * pcls, Field<Real> * T00, double a = 1., Field<Real> * phi = NULL, double coeff = 1.)
{
if (T00->lattice().halo() == 0)
{
cout<< "projection_T00_project: target field needs halo > 0" << endl;
exit(-1);
}
Site xPart(pcls->lattice());
Site xField(T00->lattice());
typename std::list<part>::iterator it;
Real referPos[3];
Real weightScalarGridUp[3];
Real weightScalarGridDown[3];
Real dx = pcls->res();
double mass = coeff / (dx*dx*dx);
mass *= *(double*)((char*)pcls->parts_info() + pcls->mass_offset());
mass /= a;
Real e = a, f = 0.;
Real * q;
size_t offset_q = offsetof(part,vel);
Real localCube[8]; // XYZ = 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111
Real localCubePhi[8];
for (int i=0; i<8; i++) localCubePhi[i] = 0.0;
for (xPart.first(),xField.first(); xPart.test(); xPart.next(),xField.next())
{
if (pcls->field()(xPart).size != 0)
{
for(int i=0; i<3; i++) referPos[i] = xPart.coord(i)*dx;
for(int i=0; i<8; i++) localCube[i] = 0.0;
if (phi != NULL)
{
localCubePhi[0] = (*phi)(xField);
localCubePhi[1] = (*phi)(xField+2);
localCubePhi[2] = (*phi)(xField+1);
localCubePhi[3] = (*phi)(xField+1+2);
localCubePhi[4] = (*phi)(xField+0);
localCubePhi[5] = (*phi)(xField+0+2);
localCubePhi[6] = (*phi)(xField+0+1);
localCubePhi[7] = (*phi)(xField+0+1+2);
}
for (it=(pcls->field())(xPart).parts.begin(); it != (pcls->field())(xPart).parts.end(); ++it)
{
for (int i=0; i<3; i++)
{
weightScalarGridUp[i] = ((*it).pos[i] - referPos[i]) / dx;
weightScalarGridDown[i] = 1.0l - weightScalarGridUp[i];
}
if (phi != NULL)
{
q = (Real*)((char*)&(*it)+offset_q);
f = q[0] * q[0] + q[1] * q[1] + q[2] * q[2];
e = sqrt(f + a * a);
f = 3. * e + f / e;
}
//000
localCube[0] += weightScalarGridDown[0]*weightScalarGridDown[1]*weightScalarGridDown[2]*(e+f*localCubePhi[0]);
//001
localCube[1] += weightScalarGridDown[0]*weightScalarGridDown[1]*weightScalarGridUp[2]*(e+f*localCubePhi[1]);
//010
localCube[2] += weightScalarGridDown[0]*weightScalarGridUp[1]*weightScalarGridDown[2]*(e+f*localCubePhi[2]);
//011