forked from Shallyn/pyWaveformGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpCore.c
9751 lines (9044 loc) · 394 KB
/
pCore.c
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
/**
* Writer: Xiaolin.liu
* xiaolin.liu@mail.bnu.edu.cn
*
* This module contains basic functions for calculation.
* Functions list:
* Kernel:
* 20xx.xx.xx, LOC
**/
#include "pCore.h"
#include "myLog.h"
#include <gsl/gsl_integration.h>
#include <gsl/gsl_sf_gamma.h>
#include <gsl/gsl_deriv.h>
#include <gsl/gsl_multiroots.h>
#define GSL_START \
gsl_error_handler_t *saveGSLErrorHandler_; \
saveGSLErrorHandler_ = gsl_set_error_handler_off();
#define GSL_END \
gsl_set_error_handler( saveGSLErrorHandler_ );
/* We need to encapsulate the data for the GSL derivative function */
typedef struct tagPrecEulerAnglesIntegration
{
gsl_spline *alpha_spline;
gsl_spline *beta_spline;
gsl_interp_accel *alpha_acc;
gsl_interp_accel *beta_acc;
}
PrecEulerAnglesIntegration;
/**
* This function finds the value in a vector that is closest to an input value.
* Assumes the input vector is increasing (typically, times or frequencies of
* series). Purely for convenience.
*/
REAL8 FindClosestValueInIncreasingVector(
REAL8Vector *vec, /**<< Input: monotonically increasing vector */
REAL8 value /**<< Input: value to look for */
)
{
UINT index = FindClosestIndex(vec, value);
return vec->data[index];
}
REAL8 SEOBCalculatetplspin(REAL8 m1, REAL8 m2, REAL8 eta, REAL8 chi1dotZ, REAL8 chi2dotZ)
{
REAL8 chiS, chiA, tplspin;
chiS = SEOBCalculateChiS(chi1dotZ, chi2dotZ);
chiA = SEOBCalculateChiA(chi1dotZ, chi2dotZ);
tplspin = (1. - 2. * eta) * chiS + (m1 - m2) / (m1 + m2) * chiA;
return tplspin;
}
static INT XLALEOBSpinPrecCalcSEOBHCoeffConstants(REAL8 eta, SEOBHCoeffConstants *ret)
{
if (!ret)
return CEV_FAILURE;
REAL8 c20 = 1.712;
REAL8 c21 = -1.803949138004582;
REAL8 c22 = -39.77229225266885;
REAL8 c23 = 103.16588921239249;
REAL8 coeffsKK = c20 + c21*eta + c22*eta*eta + c23*eta*eta*eta;
REAL8 m1PlusEtaKK = -1. + eta*coeffsKK;
REAL8 tmp4=(m1PlusEtaKK*m1PlusEtaKK*m1PlusEtaKK);
REAL8 tmp10=m1PlusEtaKK*m1PlusEtaKK;
REAL8 tmp7=(m1PlusEtaKK*m1PlusEtaKK*m1PlusEtaKK*m1PlusEtaKK);
REAL8 tmp6=coeffsKK*coeffsKK;
REAL8 tmp16=pow(m1PlusEtaKK,5.);
REAL8 tmp19=pow(m1PlusEtaKK,6.);
REAL8 tmp18=(coeffsKK*coeffsKK*coeffsKK);
REAL8 tmp23=4.*coeffsKK*tmp7;
REAL8 tmp34=pow(m1PlusEtaKK,7.);
REAL8 tmp28=CST_PI*CST_PI;
REAL8 tmp32=16.*coeffsKK*tmp16;
REAL8 tmp37=pow(m1PlusEtaKK,8.);
REAL8 tmp36=(coeffsKK*coeffsKK*coeffsKK*coeffsKK);
REAL8 tmp64=pow(m1PlusEtaKK,9.);
REAL8 kC0=0.+4.*coeffsKK*tmp4+2.*tmp6*tmp7;
REAL8 kC1=1.*coeffsKK*tmp10-coeffsKK*tmp4;
REAL8 kC2=0.+2.*tmp10-1.3333333333333335*tmp18*tmp19-8.*tmp16*tmp6-8.*coeffsKK*tmp7;
REAL8 kC3=tmp23-2.*coeffsKK*tmp4+2.*tmp16*tmp6-2.*tmp6*tmp7;
REAL8 kC4=0.+31.333333333333332*tmp10-1.28125*tmp10*tmp28+tmp32+8.*tmp18*tmp34+0.6666666666666666*tmp36*tmp37-4.*tmp4+24.*tmp19*tmp6-4.*coeffsKK*tmp7;
REAL8 kC5=-12.*coeffsKK*tmp16+2.*tmp18*tmp19+tmp23-2.*tmp18*tmp34+8.*tmp16*tmp6-12.*tmp19*tmp6;
REAL8 kC6=1.*coeffsKK*tmp16-tmp16*tmp6+0.5*tmp19*tmp6-coeffsKK*tmp7+0.5*tmp6*tmp7;
REAL8 kC7=-35.12753102199746*tmp10+25.6*CST_GAMMA*tmp10-32.*coeffsKK*tmp19+4.443359375*tmp10*tmp28+tmp32-32.*tmp18*tmp37-62.666666666666664*tmp4+2.5625*tmp28*tmp4+4.*tmp19*tmp6-64.*tmp34*tmp6-5.333333333333334*tmp36*tmp64+8.*tmp7-62.666666666666664*coeffsKK*tmp7+2.5625*coeffsKK*tmp28*tmp7-0.2666666666666661*pow(coeffsKK,5.)*pow(m1PlusEtaKK,10.);
REAL8 kC8=-10.*coeffsKK*tmp16+32.*coeffsKK*tmp19-12.*tmp18*tmp34+16.*tmp18*tmp37-1.3333333333333337*tmp36*tmp37-24.*tmp19*tmp6+48.*tmp34*tmp6+1.3333333333333337*tmp36*tmp64-2.*tmp7+2.*coeffsKK*tmp7;
REAL8 kC9=4.*coeffsKK*tmp16-6.*coeffsKK*tmp19-tmp18*tmp19+2.*tmp18*tmp34-tmp18*tmp37-2.*tmp16*tmp6+8.*tmp19*tmp6-6.*tmp34*tmp6;
ret->a0k2 = kC0;
ret->a1k2 = kC1;
ret->a0k3 = kC2;
ret->a1k3 = kC3;
ret->a0k4 = kC4;
ret->a1k4 = kC5;
ret->a2k4 = kC6;
ret->a0k5 = kC7;
ret->a1k5 = kC8;
ret->a2k5 = kC9;
return CEV_SUCCESS;
}
// Calc...
static REAL8 CalPN_calculateAmpDot(REAL8 re, REAL8 im, REAL8 reDot, REAL8 imDot)
{
return (re * reDot + im * imDot) / (sqrt(re*re + im*im));
}
static REAL8 CalPN_calculateAmpDDot(REAL8 re, REAL8 im, REAL8 reDot, REAL8 imDot, REAL8 reDDot, REAL8 imDDot)
{
return ((im*imDDot + pow(imDot,2))*pow(re,2) + pow(re,3)*reDDot + im*re*(im*reDDot - 2*imDot*reDot) +
pow(im,2)*(im*imDDot + pow(reDot,2)))/pow(pow(im,2) + pow(re,2),1.5);
}
static REAL8 CalPN_calculateOmega(REAL8 re, REAL8 im, REAL8 reDot, REAL8 imDot)
{
return (re * imDot - im * reDot) / (re*re + im*im);
}
static REAL8 CalPN_calculateOmegaDot(REAL8 re, REAL8 im, REAL8 reDot, REAL8 imDot, REAL8 reDDot, REAL8 imDDot)
{
return ((pow(im,2) + pow(re,2))*(imDDot*re - im*reDDot) - 2*(imDot*re - im*reDot)*(im*imDot + re*reDot))/pow(pow(im,2) + pow(re,2),2);
}
typedef
struct tagCalPNCoeffsRootParams
{
REAL8 eAmp;
REAL8 eAmpDot;
REAL8 eAmpDDot;
REAL8 eOmega;
REAL8 eOmegaDot;
COMPLEX16 rholm;
COMPLEX16 rholmDot;
COMPLEX16 rholmDDot;
REAL8 nrAmp;
REAL8 nrAmpDot;
REAL8 nrAmpDDot;
REAL8 nrOmega;
REAL8 nrOmegaDot;
REAL8 x0;
REAL8 x0Dot;
REAL8 x0DDot;
REAL8 x1;
REAL8 x1Dot;
REAL8 x1DDot;
REAL8 x2;
REAL8 x2Dot;
REAL8 x2DDot;
int order;
}
CalPNCoeffsRootParams;
static int gslfuncFindCalPNCoeffs(const gsl_vector *x, void *params, gsl_vector *f)
{
CalPNCoeffsRootParams *rootParams = (CalPNCoeffsRootParams *) params;
REAL8 k1, k2, k3, k4, k5;
REAL8 eAmp, eAmpDot, eAmpDDot, eOmega, eOmegaDot, nrAmp, nrOmega, nrAmpDot, nrAmpDDot, nrOmegaDot;
REAL8 x0, x0Dot, x0DDot, x1, x1Dot, x1DDot, x2, x2Dot, x2DDot;
REAL8 eobAmp, eobOmega, eobAmpDot, eobOmegaDot, eobAmpDDot;
REAL8 fr, fi, frDot, fiDot, frDDot, fiDDot;
REAL8 Rpart, Ipart, RpartDot, IpartDot, RpartDDot, IpartDDot;
REAL8 Rtot, RtotDot, RtotDDot, Itot, ItotDot, ItotDDot;
k1 = gsl_vector_get(x, 0);
k2 = gsl_vector_get(x, 1);
k3 = gsl_vector_get(x, 2);
k4 = gsl_vector_get(x, 3);
k5 = gsl_vector_get(x, 4);
x0 = rootParams->x0;
x0Dot = rootParams->x0Dot;
x0DDot = rootParams->x0DDot;
x1 = rootParams->x1;
x1Dot = rootParams->x1Dot;
x1DDot = rootParams->x1DDot;
x2 = rootParams->x2;
x2Dot = rootParams->x2Dot;
x2DDot = rootParams->x2DDot;
COMPLEX16 comb, combDot, combDDot;
REAL8 pre, preDot, preDDot;
int order = rootParams->order;
comb = I*(k1*x0*x1 + k2*x1*x2) + k3*x0*x2 + k4*x0*x0 + k5*x2*x2;
combDot = 2*k4*x0*x0Dot + I*k1*x0Dot*x1 + I*k1*x0*x1Dot + k3*x0Dot*x2 + I*k2*x1Dot*x2 + k3*x0*x2Dot + I*k2*x1*x2Dot + 2*k5*x2*x2Dot;
combDDot = 2*k4*x0*x0DDot + 2*k4*pow(x0Dot,2) + I*k1*x0DDot*x1 + I*k1*x0*x1DDot + I*k1*x0Dot*x1Dot + k3*x0DDot*x2 +
I*k2*x1DDot*x2 + k3*x0*x2DDot + I*k2*x1*x2DDot + 2*k5*x2*x2DDot + 2*k3*x0Dot*x2Dot + I*k2*x1Dot*x2Dot +
2*k5*pow(x2Dot,2);
// print_debug("comb = %f + i%f\n", comb);
// print_debug("combDot = %f + i%f\n", combDot);
// print_debug("combDDot = %f + i%f\n\n", combDDot);
pre = pow(x0, order);
preDot = order * pow(x0, order-1) * x0Dot;
preDDot = order * (order - 1) * pow(x0, order-2) * x0Dot * x0Dot + order * pow(x0, order-1) * x0DDot;
eAmp = rootParams->eAmp;
eAmpDot = rootParams->eAmpDot;
eAmpDDot = rootParams->eAmpDDot;
eOmega = rootParams->eOmega;
eOmegaDot = rootParams->eOmegaDot;
fr = creal(rootParams->rholm);
fi = cimag(rootParams->rholm);
frDot = creal(rootParams->rholmDot);
fiDot = cimag(rootParams->rholmDot);
frDDot = creal(rootParams->rholmDDot);
fiDDot = cimag(rootParams->rholmDDot);
nrAmp = rootParams->nrAmp;
nrAmpDot = rootParams->nrAmpDot;
nrAmpDDot = rootParams->nrAmpDDot;
Rpart = pre * creal(comb);
Ipart = pre * cimag(comb);
RpartDot = creal(pre * combDot + preDot * comb);
IpartDot = cimag(pre * combDot + preDot * comb);
RpartDDot = creal(pre * combDDot + 2*preDot*combDot + preDDot * comb);
IpartDDot = cimag(pre * combDDot + 2*preDot*combDot + preDDot * comb);
Rtot = fr + Rpart;
Itot = fi + Ipart;
RtotDot = frDot + RpartDot;
ItotDot = fiDot + IpartDot;
RtotDDot = frDDot + RpartDDot;
ItotDDot = fiDDot + IpartDDot;
nrOmega = rootParams->nrOmega;
nrOmegaDot = rootParams->nrOmegaDot;
eobAmp = eAmp * sqrt(Rtot*Rtot + Itot*Itot);
eobOmega = eOmega + CalPN_calculateOmega(Rtot, Itot, RtotDot, ItotDot);
eobAmpDot = eAmp * CalPN_calculateAmpDot(Rtot, Itot, RtotDot, ItotDot) + eAmpDot * sqrt(Rtot*Rtot + Itot*Itot);
eobOmegaDot = eOmegaDot + CalPN_calculateOmegaDot(Rtot, Itot, RtotDot, ItotDot, RtotDDot, ItotDDot);
eobAmpDDot = eAmp * CalPN_calculateAmpDDot(Rtot, Itot, RtotDot, ItotDot, RtotDDot, ItotDDot) +
2*eAmpDot * CalPN_calculateAmpDot(Rtot, Itot, RtotDot, ItotDot) + eAmpDDot * sqrt(Rtot*Rtot + Itot*Itot);
// print_debug("IN: nra = %f, ea = %f, eoba = %f\n", nrAmp, eAmp, eobAmp);
// print_debug("IN: nrOmega = %f, eO = %f, eobOmega = %f\n", nrOmega, eOmega, eobOmega);
// print_debug("IN: nrAmpDot = %f, eAD = %f, eobAmpDot = %f\n", nrAmpDot, eAmpDot, eobAmpDot);
// print_debug("IN: nrOmegaDot = %f, eOD = %f, eobOmegaDot = %f\n\n", nrOmegaDot, eOmegaDot, eobOmegaDot);
// print_debug("IN: nrAmpDDot = %f, eADD = %f, eobAmpDDot = %f\n", nrAmpDDot, eAmpDDot, eobAmpDDot);
// print_debug("RST: x = %f + i%f\n", yr, yi);
gsl_vector_set( f, 0, nrAmp - eobAmp);
gsl_vector_set( f, 1, nrOmega - eobOmega);
gsl_vector_set( f, 2, nrAmpDot - eobAmpDot);
gsl_vector_set( f, 3, nrOmegaDot - eobOmegaDot);
gsl_vector_set( f, 4, nrAmpDDot - eobAmpDDot);
return CEV_SUCCESS;
}
static INT FindCalPNCoeffs(COMPLEX16 hLM,
COMPLEX16 hLMDot,
COMPLEX16 hLMDDot,
COMPLEX16 rholm,
COMPLEX16 rholmDot,
COMPLEX16 rholmDDot,
REAL8 nrAmp,
REAL8 nrAmpDot,
REAL8 nrAmpDDot,
REAL8 nrOmega,
REAL8 nrOmegaDot,
REAL8 x0,
REAL8 dx0dt,
REAL8 dx0dt2,
REAL8 x1,
REAL8 dx1dt,
REAL8 dx1dt2,
REAL8 x2,
REAL8 dx2dt,
REAL8 dx2dt2,
INT order,
REAL8 initval,
REAL8 *out1,
REAL8 *out2,
REAL8 *out3,
REAL8 *out4,
REAL8 *out5)
{
int i=0, gslStatus;
const int maxIter = 300;
const gsl_multiroot_fsolver_type *T = gsl_multiroot_fsolver_hybrids;
gsl_multiroot_fsolver *rootSolver = NULL;
gsl_vector *initValues = NULL;
gsl_vector *finalValues = NULL;
gsl_multiroot_function rootFunction;
CalPNCoeffsRootParams rootParams;
REAL8 rst1, rst2, rst3, rst4, rst5;
REAL8 eAmp, eAmpDot, eOmega;
eAmp = cabs(hLM);
eAmpDot = CalPN_calculateAmpDot(creal(hLM), cimag(hLM), creal(hLMDot), cimag(hLMDot));
eOmega = CalPN_calculateOmega(creal(hLM), cimag(hLM), creal(hLMDot), cimag(hLMDot));
rootParams.eAmp = eAmp;
rootParams.eAmpDot = eAmpDot;
rootParams.eAmpDDot = CalPN_calculateAmpDDot(creal(hLM), cimag(hLM), creal(hLMDot), cimag(hLMDot), creal(hLMDDot), cimag(hLMDDot));
rootParams.eOmega = eOmega;
rootParams.eOmegaDot = CalPN_calculateOmegaDot(creal(hLM), cimag(hLM), creal(hLMDot), cimag(hLMDot), creal(hLMDDot), cimag(hLMDDot));
rootParams.rholm = rholm;
rootParams.rholmDot = rholmDot;
rootParams.rholmDDot = rholmDDot;
REAL8 tgtAmp, tgtAmpDot, tgtOmega;
tgtAmp = eAmp + ((nrAmp - eAmp > 0) ? 1. : -1) * (fabs(nrAmp - eAmp)*0.1 < eAmp*0.01 ? fabs(nrAmp-eAmp)*0.1 : eAmp*0.01);
tgtAmpDot = eAmpDot + ((nrAmpDot - eAmpDot > 0) ? 1. : -1) * (fabs(nrAmpDot-eAmpDot)*0.5 < fabs(eAmpDot)*0.1 ? fabs(nrAmpDot-eAmpDot)*0.5 : fabs(eAmpDot)*0.1);
tgtOmega = eOmega + ((nrOmega - eOmega > 0) ? 1. : -1.) * (fabs(nrOmega - eOmega)*0.2 < fabs(eOmega) * 0.1 ? fabs(nrOmega - eOmega)*0.2 : fabs(eOmega)*0.1);
rootParams.nrAmp = tgtAmp;
rootParams.nrAmpDot = tgtAmpDot;
rootParams.nrAmpDDot = nrAmpDDot;
rootParams.nrOmega = tgtOmega;
rootParams.nrOmegaDot = nrOmegaDot;
rootParams.x0 = x0;
rootParams.x0Dot = dx0dt;
rootParams.x0DDot = dx0dt2;
rootParams.x1 = x1;
rootParams.x1Dot = dx1dt;
rootParams.x1DDot = dx1dt2;
rootParams.x2 = x2;
rootParams.x2Dot = dx2dt;
rootParams.x2DDot = dx2dt2;
rootParams.order = order;
rootSolver = gsl_multiroot_fsolver_alloc( T, 5 );
if ( !rootSolver )
{
return CEV_FAILURE;
}
initValues = gsl_vector_calloc( 5 );
if ( !initValues )
{
gsl_multiroot_fsolver_free( rootSolver );
return CEV_FAILURE;
}
gsl_vector_set( initValues, 0, 0.01);
gsl_vector_set( initValues, 1, 0.01 );
gsl_vector_set( initValues, 2, 0.01 );
gsl_vector_set( initValues, 3, initval );
gsl_vector_set( initValues, 4, 0.01 );
rootFunction.f = gslfuncFindCalPNCoeffs;
rootFunction.n = 5;
rootFunction.params = &rootParams;
gsl_multiroot_fsolver_set( rootSolver, &rootFunction, initValues );
do
{
gslStatus = gsl_multiroot_fsolver_iterate( rootSolver );
if ( gslStatus != GSL_SUCCESS )
{
print_warning( "Error in GSL iteration function!\n" );
gsl_multiroot_fsolver_free( rootSolver );
gsl_vector_free( initValues );
return CEV_FAILURE;
}
gslStatus = gsl_multiroot_test_residual( rootSolver->f, 1.0e-10 );
i++;
}
while ( gslStatus == GSL_CONTINUE && i <= maxIter );
if ( i > maxIter && gslStatus != GSL_SUCCESS )
{
gsl_multiroot_fsolver_free( rootSolver );
gsl_vector_free( initValues );
return CEV_FAILURE;
}
finalValues = gsl_multiroot_fsolver_root( rootSolver );
rst1 = gsl_vector_get( finalValues, 0 );
rst2 = gsl_vector_get( finalValues, 1 );
// rst1_i = 0;
rst3 = gsl_vector_get( finalValues, 2 );
rst4 = gsl_vector_get( finalValues, 3 );
// rst2_r = 0;
// rst2_i = 0;
rst5 = gsl_vector_get(finalValues, 4);
*out1 = rst1;
*out2 = rst2;
*out3 = rst3;
*out4 = rst4;
*out5 = rst5;
// print_debug("FINAL: nra = %f, fiteobAmp = %f, nraDot = %f, fiteobAmpDot = %f\n", nrAmp, cabs(fithLM), nrAmpDot, ampDot);
gsl_multiroot_fsolver_free( rootSolver );
gsl_vector_free( initValues );
// gsl_vector_free( finalValues );
return CEV_SUCCESS;
}
static INT XLALSimIMREOBCalcCalibCoefficientHigherModesPrec (
SpinEOBParams * params, /**Output **/
const UINT modeL, /*<< Mode index L */
const UINT modeM, /*<< Mode index M */
SEOBdynamics *seobdynamics, /*<< Dynamics vector */
const REAL8 timeorb, /*<< Time of the peak of the orbital frequency */
const REAL8 m1, /**Component mass 1 */
const REAL8 m2, /**Component mass 2 */
const REAL8 deltaT /**<< Sampling interval */
)
{
// PRINT_LOG_INFO(LOG_DEBUG, "timeorb = %g\n", timeorb);
/* Status of function calls */
UINT i, j;
UINT debugRC = 0;
INT failed = 0;
UINT SEOBWaveformVersion = 451;
/** Physical quantities */
REAL8Vector *timeVec = NULL, *hLMdivrholmVec = NULL;
REAL8Vector polarDynamics, values;
REAL8 valuesdata[14] = {0.};
REAL8 polarDynamicsdata[4] = {0.};
polarDynamics.length = 4;
values.length = 14;
polarDynamics.data = polarDynamicsdata;
values.data = valuesdata;
REAL8 omegaAttachmentPoint, hLMdivrholmAttachmentPoint, rholmNRAttachmentPoint, rholmBeforeCalibAttachmentPoint;
REAL8 rAttachmentPoint, hLMdivrholmEAttachmentPoint, rholmENRAttachmentPoint, rholmERealBeforeCalAP, rholmEImagBeforeCalAP;
REAL8 v;
COMPLEX16Vector *hLMVec = NULL, *rholmpwrlVec = NULL;
COMPLEX16 hLME, rholmpwrlE;
REAL8Vector *rholmpwrlVecReal = NULL;
REAL8Vector *rholmpwrlEVecReal = NULL;
REAL8Vector *rholmpwrlEVecImag = NULL;
REAL8Vector *hLMdivrholmEVec = NULL;
REAL8Vector orbOmegaVec, HamVec, rVec;
UINT retLen = seobdynamics->length;
REAL8 hLMrealAP, hLMimagAP, hLMrealAPDot, hLMrealAPDDot, hLMimagAPDot, hLMimagAPDDot, x0AP, x0DotAP, x0DDotAP;
REAL8Vector *hLMrealVec = NULL;
REAL8Vector *hLMimagVec = NULL;
REAL8Vector *drVec = NULL;
REAL8Vector *ncrvVec = NULL;
/** Find the vaulues of the final spins */
REAL8 mtot = m1+m2;
REAL8 eta = params->eta;
REAL8 s1dotZ = 0, s2dotZ = 0, chi1dotZ = 0, chi2dotZ = 0;
REAL8 chiS = 0;
REAL8 chiA = 0;
REAL8 tplspin = 0;
REAL8 dr, ncrv; // New
REAL8 spin1z_omegaPeak = params->spin1z_omegaPeak;
REAL8 spin2z_omegaPeak = params->spin2z_omegaPeak;
REAL8 chiS_omegaPeak = 0.5*(spin1z_omegaPeak+ spin2z_omegaPeak);
REAL8 chiA_omegaPeak = 0.5*(spin1z_omegaPeak-spin2z_omegaPeak);
/* Create dynamical arrays */
orbOmegaVec.length = HamVec.length = rVec.length = retLen;
hLMVec = CreateCOMPLEX16Vector (retLen);
rholmpwrlVec = CreateCOMPLEX16Vector (retLen);
timeVec = CreateREAL8Vector (retLen);
hLMdivrholmVec = CreateREAL8Vector (retLen);
rholmpwrlVecReal = CreateREAL8Vector (retLen);
hLMdivrholmEVec = CreateREAL8Vector (retLen);
rholmpwrlEVecReal = CreateREAL8Vector (retLen);
rholmpwrlEVecImag = CreateREAL8Vector (retLen);
drVec = CreateREAL8Vector(retLen);
ncrvVec = CreateREAL8Vector(retLen);
if (!hLMVec || !rholmpwrlVec|| !timeVec|| !rholmpwrlVec || !rholmpwrlVecReal || !hLMdivrholmEVec || !rholmpwrlEVecReal)
{failed = 1; goto QUIT;}
orbOmegaVec.data = seobdynamics->omegaVec;
HamVec.data = seobdynamics->hamVec;
rVec.data = seobdynamics->polarrVec;
/* Stuff for interpolating function */
GSL_START;
gsl_spline *spline = NULL;
gsl_interp_accel *acc = NULL;
/* The calibration parameter is only used for 21 and 55 modes, if you try to use this function for other modes, you get an error */
if (!((modeL == 2 && modeM == 1) || (modeL == 5 && modeM == 5)))
{
PRINT_LOG_INFO (LOG_CRITICAL, "Mode %d,%d is not supported by this function.", modeL, modeM);
failed = 1;
goto QUIT;
}
/* Populate time vector as necessary */
for (i = 0; i < timeVec->length; i++)
{
timeVec->data[i] = i * deltaT;
}
/**Initializing stuff for interpolation */
spline = gsl_spline_alloc (gsl_interp_cspline, orbOmegaVec.length);
acc = gsl_interp_accel_alloc ();
/* Calculation of the frequency at the attachment point */
REAL8 timewavePeak = timeorb-XLALSimIMREOBGetNRSpinPeakDeltaTv4 (modeL, modeM, m1, m2, spin1z_omegaPeak, spin2z_omegaPeak, params->hParams);
// print_debug("timewavePeak = %g\n", timewavePeak);
INT status;
status = gsl_spline_init (spline, timeVec->data, orbOmegaVec.data, orbOmegaVec.length);
if (status != GSL_SUCCESS)
{
PRINT_LOG_INFO (LOG_CRITICAL, "gsl_spline_init failed.");
failed = 1;
goto QUIT;
}
gsl_interp_accel_reset (acc);
omegaAttachmentPoint = gsl_spline_eval (spline, timewavePeak, acc);
// REAL8 domAP, ddomAP;
// domAP = gsl_spline_eval_deriv (spline, timewavePeak, acc);
// ddomAP = gsl_spline_eval_deriv2 (spline, timewavePeak, acc);
/** Calculate x0 at the attachment point */
REAL8 drAP, ddrAP;
status = gsl_spline_init (spline, timeVec->data, rVec.data, rVec.length);
if (status != GSL_SUCCESS)
{
PRINT_LOG_INFO (LOG_CRITICAL, "gsl_spline_init failed.");
failed = 1;
goto QUIT;
}
gsl_interp_accel_reset (acc);
rAttachmentPoint = gsl_spline_eval (spline, timewavePeak, acc);
// print_debug("rAttachPoint = %g\n", rAttachmentPoint);
drAP = gsl_spline_eval_deriv (spline, timewavePeak, acc);
ddrAP = gsl_spline_eval_deriv2 (spline, timewavePeak, acc);
x0AP = 1./sqrt(rAttachmentPoint);
x0DotAP = -0.5*drAP / pow(rAttachmentPoint,1.5);
x0DDotAP = 3*drAP*drAP / (4.*pow(rAttachmentPoint, 2.5)) - 0.5*ddrAP / pow(rAttachmentPoint, 1.5);
hLMrealVec = CreateREAL8Vector (retLen);
hLMimagVec = CreateREAL8Vector (retLen);
// print_debug("timewave = %g, Final Time = %g\n", timewavePeak, timeVec->data[orbOmegaVec.length-1]);
/** Calculation and interpolation at the matching point of rho_lm^l + f_lm */
for(i=0; i<orbOmegaVec.length; i++)
{
for ( j=0; j<14; j++)
{
values.data[j] = seobdynamics->array->data[i + (j+1)*retLen];
}
s1dotZ = seobdynamics->s1dotZVec[i];
s2dotZ = seobdynamics->s2dotZVec[i];
polarDynamics.data[0] = seobdynamics->polarrVec[i];
polarDynamics.data[1] = seobdynamics->polarphiVec[i];
polarDynamics.data[2] = seobdynamics->polarprVec[i];
polarDynamics.data[3] = seobdynamics->polarpphiVec[i];
chi1dotZ = s1dotZ * mtot*mtot / (m1*m1);
chi2dotZ = s2dotZ * mtot*mtot / (m2*m2);
chiS = 0.5*(chi1dotZ+chi2dotZ);
chiA = 0.5*(chi1dotZ-chi2dotZ);
tplspin = (1.-2.*eta) * chiS + (m1 - m2)/(m1 + m2) * chiA;
v = cbrt (orbOmegaVec.data[i]);
if (CODE_VERSION == 3)
{
if (EccPrec_CalcSpinPrecFacWaveformCoefficients(
params->hCoeffs, m1, m2, eta, tplspin, chiS, chiA,
seobdynamics->chiSxVec[i], seobdynamics->chiSyVec[i], seobdynamics->chiSzVec[i],
seobdynamics->chiAxVec[i], seobdynamics->chiAyVec[i], seobdynamics->chiAzVec[i],
451) == CEV_FAILURE)
{
PRINT_LOG_INFO(LOG_CRITICAL, "failure in EccPrec_CalcSpinPrecFacWaveformCoefficients at step %d of the loop.", i);
return CEV_FAILURE;
}
}
else
{
if ( XLALSimIMREOBCalcSpinPrecFacWaveformCoefficients( params->hCoeffs, m1, m2, eta, tplspin, chiS, chiA, SEOBWaveformVersion ) == CEV_FAILURE )
{
PRINT_LOG_INFO(LOG_CRITICAL, "failure in XLALSimIMREOBCalcSpinPrecFacWaveformCoefficients at step %d of the loop.", i);
failed = 1;
goto QUIT;
}
}
// if (CODE_VERSION == 0)
// {
if ( XLALSimIMRSpinEOBGetPrecSpinFactorizedWaveform( &(hLMVec->data[i]), &polarDynamics, &values, v, HamVec.data[i], modeL, modeM, params ) == CEV_FAILURE )
{
PRINT_LOG_INFO(LOG_CRITICAL, "failure in XLALSimIMRSpinEOBGetPrecSpinFactorizedWaveform at step %d of the loop.", i);
failed = 1;
goto QUIT;
}
if (XLALSimIMRSpinEOBGetAmplitudeResidualPrec (&(rholmpwrlVec->data[i]), v, HamVec.data[i], modeL, modeM, params) == CEV_FAILURE)
//RC: for the 21 and 55 mode rholmpwrlVec is always real. This is not true for the 33 mode. For this reason, in order to make this function general, we use a complex variable for it.
{
/* TODO: Clean-up */
failed = 1;
goto QUIT;
}
// }
// else
// {
dr = (seobdynamics->posVecx[i]*seobdynamics->velVecx[i] +
seobdynamics->posVecy[i]*seobdynamics->velVecy[i] +
seobdynamics->posVecz[i]*seobdynamics->velVecz[i]) / seobdynamics->polarrVec[i];
ncrv = seobdynamics->polarrVec[i] * orbOmegaVec.data[i];
drVec->data[i] = dr;
ncrvVec->data[i] = ncrv;
if ( XLALSimIMRSpinEOBGetPrecSpinFactorizedWaveformV2( &hLME, &polarDynamics, &values, v, dr, ncrv, seobdynamics->polarprDotVec[i], HamVec.data[i], modeL, modeM, params ) == CEV_FAILURE )
{
PRINT_LOG_INFO(LOG_CRITICAL, "failure in XLALSimIMRSpinEOBGetPrecSpinFactorizedWaveformV2 at step %d of the loop.", i);
failed = 1;
goto QUIT;
}
// if (isnan(params->hCoeffs->h21T2ff10))
// {
// print_debug("ca = (%g, %g, %g), cs = (%g, %g, %g)\n", seobdynamics->chiSxVec[i], seobdynamics->chiSyVec[i], seobdynamics->chiSzVec[i],
// seobdynamics->chiAxVec[i], seobdynamics->chiAyVec[i], seobdynamics->chiAzVec[i]);
// }
if (XLALSimIMRSpinEOBGetAmplitudeResidualPrecV2 (&rholmpwrlE, &polarDynamics, &values, v, dr, ncrv, HamVec.data[i], modeL, modeM, params) == CEV_FAILURE)
//RC: for the 21 and 55 mode rholmpwrlVec is always real. This is not true for the 33 mode. For this reason, in order to make this function general, we use a complex variable for it.
{
/* TODO: Clean-up */
failed = 1;
goto QUIT;
}
// if (isnan(params->hCoeffs->h21T2ff10))
// {
// print_debug("it become nan\n");
// }
// if (creal(rholmpwrlVec->data[i]) == 0.0)
// print_debug("[%d]get\n", i);
// }
rholmpwrlVecReal->data[i] = (REAL8)creal(rholmpwrlVec->data[i]);
hLMdivrholmVec->data[i] = ((REAL8)cabs(hLMVec->data[i]))/fabs(rholmpwrlVecReal->data[i]);
rholmpwrlEVecReal->data[i] = (REAL8) creal(rholmpwrlE);
rholmpwrlEVecImag->data[i] = (REAL8) cimag(rholmpwrlE);
hLMdivrholmEVec->data[i] = ((REAL8)cabs(hLME) / fabs(rholmpwrlEVecReal->data[i]));
hLMrealVec->data[i] = (REAL8) creal(hLME/rholmpwrlE);
hLMimagVec->data[i] = (REAL8) cimag(hLME/rholmpwrlE);
// print_debug("[%d]")
// if (rholmpwrlVecReal->data[i] == 0.0)
// print_debug("[%d]rholmPwrlReal = %.3e + i%.3e, v = %g, dr = %g, ncrv = %g \n",
// i, creal(rholmpwrlVec->data[i]), cimag(rholmpwrlVec->data[i]), v, dr, ncrv);
// if (timeVec->data[i] > 0.9*timewavePeak)
// print_debug("t[%d] = %g, rholmpwrlEVec = %.3e + i%.3e\n",
// i, timeVec->data[i], rholmpwrlEVecReal->data[i], rholmpwrlEVecImag->data[i]);
// print_debug("t[%d] = %g, rholmpwrlEVec = %.3e + i%.3e, hLM = %.3e + i%.3e,r = %g, v = %g, dr = %g, ncrv = %g, ham = %g \n",
// i, timeVec->data[i], rholmpwrlEVecReal->data[i], rholmpwrlEVecImag->data[i], creal(hLME), cimag(hLME), seobdynamics->polarrVec[i], v, dr, ncrv, HamVec.data[i]);
}
status = gsl_spline_init (spline, timeVec->data, hLMdivrholmVec->data, hLMdivrholmVec->length);
if (status != GSL_SUCCESS)
{
PRINT_LOG_INFO (LOG_CRITICAL, "gsl_spline_init failed.");
failed = 1;
goto QUIT;
}
gsl_interp_accel_reset (acc);
hLMdivrholmAttachmentPoint = gsl_spline_eval (spline, timewavePeak, acc);
status = gsl_spline_init (spline, timeVec->data, hLMdivrholmEVec->data, hLMdivrholmEVec->length);
if (status != GSL_SUCCESS)
{
PRINT_LOG_INFO (LOG_CRITICAL, "gsl_spline_init failed.");
failed = 1;
goto QUIT;
}
gsl_interp_accel_reset (acc);
hLMdivrholmEAttachmentPoint = gsl_spline_eval (spline, timewavePeak, acc);
REAL8 nra = 0, nraDot = 0, nraDDot = 0;
REAL8 nrOmega, nrOmegaDot;
nra = XLALSimIMREOBGetNRSpinPeakAmplitudeV4 (modeL, modeM, m1, m2,chiS_omegaPeak, chiA_omegaPeak);
nraDot = XLALSimIMREOBGetNRSpinPeakADotV4(modeL, modeM, m1, m2, chiS_omegaPeak, chiA_omegaPeak);
nraDDot = XLALSimIMREOBGetNRSpinPeakADDotV4(modeL, modeM, m1, m2, chiS_omegaPeak, chiA_omegaPeak);
nrOmega = XLALSimIMREOBGetNRSpinPeakOmegaV4 (modeL, modeM, eta, chiS_omegaPeak + chiA_omegaPeak * (m1 - m2) / (m1 + m2) / (1. - 2. * eta));
nrOmegaDot = XLALSimIMREOBGetNRSpinPeakOmegaDotV4(modeL, modeM, eta, chiS_omegaPeak + chiA_omegaPeak * (m1 - m2) / (m1 + m2) / (1. - 2. * eta));
PRINT_LOG_INFO(LOG_DEBUG, "hNR_%d%d = %g", modeL, modeM, nra);
if((fabs(nra/eta)< 3e-2) && ((modeL == 2) && (modeM == 1)))
{
//R.C.: safeguard to avoid the 21 mode to go to 0
nra = GSL_SIGN(nra)*eta*3e-2;
}
if((fabs(nra/eta)< 1e-4) && ((modeL == 5) && (modeM == 5)))
{
//R.C.: safeguard to avoid the 55 mode to go to 0
nra = GSL_SIGN(nra)*eta*1e-4;
}
rholmNRAttachmentPoint = nra/hLMdivrholmAttachmentPoint;
rholmENRAttachmentPoint = nra/hLMdivrholmEAttachmentPoint;
status = gsl_spline_init (spline, timeVec->data, rholmpwrlVecReal->data, rholmpwrlVecReal->length);
if (status != GSL_SUCCESS)
{
PRINT_LOG_INFO (LOG_CRITICAL, "gsl_spline_init failed.");
failed = 1;
goto QUIT;
}
gsl_interp_accel_reset (acc);
/* rho_lm^l + f_lm before the calibration parameter is set */
rholmBeforeCalibAttachmentPoint = gsl_spline_eval (spline, timewavePeak, acc);
REAL8 rholmErealDot, rholmEimagDot, rholmErealDDot, rholmEimagDDot;
status = gsl_spline_init (spline, timeVec->data, rholmpwrlEVecReal->data, rholmpwrlEVecReal->length);
if (status != GSL_SUCCESS)
{
PRINT_LOG_INFO (LOG_CRITICAL, "gsl_spline_init failed.");
failed = 1;
goto QUIT;
}
gsl_interp_accel_reset (acc);
/* rho_lm^l + f_lm before the calibration parameter is set */
rholmERealBeforeCalAP = gsl_spline_eval (spline, timewavePeak, acc);
rholmErealDot = gsl_spline_eval_deriv (spline, timewavePeak, acc);
rholmErealDDot = gsl_spline_eval_deriv2 (spline, timewavePeak, acc);
status = gsl_spline_init (spline, timeVec->data, rholmpwrlEVecImag->data, rholmpwrlEVecReal->length);
if (status != GSL_SUCCESS)
{
PRINT_LOG_INFO (LOG_CRITICAL, "gsl_spline_init failed.");
failed = 1;
goto QUIT;
}
gsl_interp_accel_reset (acc);
/* rho_lm^l + f_lm before the calibration parameter is set */
rholmEImagBeforeCalAP = gsl_spline_eval (spline, timewavePeak, acc);
rholmEimagDot = gsl_spline_eval_deriv (spline, timewavePeak, acc);
rholmEimagDDot = gsl_spline_eval_deriv2 (spline, timewavePeak, acc);
COMPLEX16 rholmEBeforeCalAP = rholmERealBeforeCalAP + I*rholmEImagBeforeCalAP;
COMPLEX16 rholmEDot = rholmErealDot + I*rholmEimagDot;
COMPLEX16 rholmEDDot = rholmErealDDot + I*rholmEimagDDot;
status = gsl_spline_init (spline, timeVec->data, hLMrealVec->data, hLMdivrholmVec->length);
if (status != GSL_SUCCESS)
{
PRINT_LOG_INFO (LOG_CRITICAL, "gsl_spline_init failed.");
failed = 1;
goto QUIT;
}
gsl_interp_accel_reset (acc);
hLMrealAP = gsl_spline_eval(spline, timewavePeak, acc);
hLMrealAPDot = gsl_spline_eval_deriv(spline, timewavePeak, acc);
hLMrealAPDDot = gsl_spline_eval_deriv2(spline, timewavePeak, acc);
status = gsl_spline_init (spline, timeVec->data, hLMimagVec->data, hLMdivrholmVec->length);
if (status != GSL_SUCCESS)
{
PRINT_LOG_INFO (LOG_CRITICAL, "gsl_spline_init failed.");
failed = 1;
goto QUIT;
}
gsl_interp_accel_reset (acc);
hLMimagAP = gsl_spline_eval(spline, timewavePeak, acc);
hLMimagAPDot = gsl_spline_eval_deriv(spline, timewavePeak, acc);
hLMimagAPDDot = gsl_spline_eval_deriv2(spline, timewavePeak, acc);
// if(debugRC==1){
// FILE *timeomegapeak = NULL;
// timeomegapeak = fopen ("timeomegapeak.dat", "w");
// fprintf(timeomegapeak, "%.16f\n", timewavePeak);
// fclose(timeomegapeak);
// }
REAL8 x1AP, x1APDot, x1APDDot, x2AP, x2APDot, x2APDDot;
status = gsl_spline_init (spline, timeVec->data, drVec->data, drVec->length);
if (status != GSL_SUCCESS)
{
PRINT_LOG_INFO (LOG_CRITICAL, "gsl_spline_init failed.");
failed = 1;
goto QUIT;
}
gsl_interp_accel_reset (acc);
x1AP = gsl_spline_eval(spline, timewavePeak, acc);
x1APDot = gsl_spline_eval_deriv(spline, timewavePeak, acc);
x1APDDot = gsl_spline_eval_deriv2(spline, timewavePeak, acc);
gsl_spline_init (spline, timeVec->data, ncrvVec->data, drVec->length);
gsl_interp_accel_reset (acc);
x2AP = gsl_spline_eval(spline, timewavePeak, acc);
x2APDot = gsl_spline_eval_deriv(spline, timewavePeak, acc);
x2APDDot = gsl_spline_eval_deriv2(spline, timewavePeak, acc);
// print_debug("x1 = %f, x1Dot = %f, x1DDot = %f\n", x1AP, x1APDot, x1APDDot);
// print_debug("x2 = %f, x2Dot = %f, x2DDot = %f\n", x2AP, x2APDot, x2APDDot);
REAL8 PNCalCoeff1, PNCalCoeff2, PNCalCoeff3, PNCalCoeff4, PNCalCoeff5;
COMPLEX16 initval;
COMPLEX16 hLMPeak = hLMrealAP + I*hLMimagAP;
COMPLEX16 hLMPeakDot = hLMrealAPDot + I*hLMimagAPDot;
COMPLEX16 hLMPeakDDot = hLMrealAPDDot + I*hLMimagAPDDot;
int retval;
if ((modeL == 2) && (modeM == 1))
{
/* Here we compute ((rho_lm^l + f_lm + CalPar*omega^7/3)_NR - (rho_lm^l + f_lm)_EOB)/omega^7/3 to get CalPar.
The factor rholmpwrlVecReal->data[0])/cabs(rholmpwrlVecReal->data[0]) is used to know the sign of the function (rho_lm^l + f_lm + CalPar*omega^7/3)_NR which is computed as absolute value */
params->cal21 = (rholmNRAttachmentPoint - rholmBeforeCalibAttachmentPoint)/(pow(omegaAttachmentPoint,7./3.));
initval = (rholmENRAttachmentPoint - rholmEBeforeCalAP)*(pow(rAttachmentPoint,12./2.));
// initval = (rholmENRAttachmentPoint - rholmEBeforeCalAP) /(pow(omegaAttachmentPoint,7./3.));
// retval = FindCalPNCoeffs(hLMPeak, hLMPeakDot, hLMPeakDDot,
// rholmEBeforeCalAP, rholmEDot, rholmEDDot,
// nra, nraDot, nraDDot, nrOmega, nrOmegaDot,
// x0AP, x0DotAP, x0DDotAP,
// x1AP, x1APDot, x1APDDot,
// x2AP, x2APDot, x2APDDot,
// 5, creal(initval), &PNCalCoeff1, &PNCalCoeff2, &PNCalCoeff3, &PNCalCoeff4, &PNCalCoeff5);
params->cal21E = creal(initval);
// if (retval != CEV_SUCCESS)
// params->cal21E = creal(initval);
// else
// {
// params->cal21E1 = PNCalCoeff1;// * rholmEBeforeCalAP / (hLMrealAP + I*hLMimagAP);
// params->cal21E2 = PNCalCoeff2;// * rholmEBeforeCalAP / (hLMrealAP + I*hLMimagAP);
// params->cal21E3 = PNCalCoeff3;
// params->cal21E = PNCalCoeff4;
// params->cal21E4 = PNCalCoeff5;
// print_debug("fitpms = %f, %f, %f, %f, %f, %f\n", PNCalCoeff1, PNCalCoeff2, PNCalCoeff3, PNCalCoeff4, PNCalCoeff5, params->hCoeffs->f21v6);
// }
// Test
// COMPLEX16 fithLMPeak, fithLMDotPeak;
// REAL8 fitALMDotPeak;
// REAL8 Re, Im, ReDot, ImDot;
// fithLMPeak = hLMPeak * (rholmEBeforeCalAP + pow(x0AP, 7) * params->cal21E);
// fithLMPeak = hLMPeak + pow(x0AP, 7)*PNCalCoeff1 + pow(x0AP, 8) * PNCalCoeff2;
// fithLMDotPeak = hLMrealAPDot + I*hLMimagAPDot + 7*pow(x0AP, 6)*x0DotAP*PNCalCoeff1 + 8*pow(x0AP, 7)*x0DotAP * PNCalCoeff2;
// fitALMDotPeak = (cimag(fithLMPeak) * cimag(fithLMDotPeak) + creal(fithLMPeak) * creal(fithLMDotPeak)) / cabs(fithLMPeak);
// print_debug("nra = %f, eoba = %f, nraDot = %f, eobaDot = %f\n", nra, cabs(fithLMPeak), nraDot, fitALMDotPeak);
// print_debug("cal21 = %.16f, nra = %.3f\n", params->cal21, nra);
}
if ((modeL == 5) && (modeM == 5))
{
/* Here we compute ((rho_lm^l + f_lm + CalPar*omega^7/3)_NR - (rho_lm^l + f_lm)_EOB)/omega^7/3 to get CalPar.
The factor rholmpwrlVecReal->data[0])/cabs(rholmpwrlVecReal->data[0]) is used to know the sign of the function (rho_lm^l + f_lm + CalPar*omega^7/3)_NR which is computed as absolute value */
params->cal55 = (rholmNRAttachmentPoint - rholmBeforeCalibAttachmentPoint)/(pow(omegaAttachmentPoint,5./3.));
//printf("params->cal55 = %.16f\n",params->cal55);
}
//if (isnan(params->cal21) || isnan(params->cal21E1) || isnan(params->cal21E2) || isnan(params->cal21E) || isnan(params->cal55))
if (isnan(creal(params->cal21)) || isnan(cimag(params->cal21)) ||
isnan(params->cal21E1) || isnan(params->cal21E2) || isnan(params->cal21E) ||
isnan(creal(params->cal55)) || isnan(cimag(params->cal55)))
{
PRINT_LOG_INFO(LOG_CRITICAL, "(l,m) = (%d, %d) calibration get nan", modeL, modeM);
PRINT_LOG_INFO(LOG_DEBUG, "rholmENRAttachmentPoint = %g, rholmEBeforeCalAP = %g + i %g\n", rholmENRAttachmentPoint, creal(rholmEBeforeCalAP), cimag(rholmEBeforeCalAP));
PRINT_LOG_INFO(LOG_DEBUG, "cal21 = %g + i %g, cal21E = %g, rAttachmentPoint = %g\n", creal(params->cal21), cimag(params->cal21), params->cal21E, rAttachmentPoint);
PRINT_LOG_INFO(LOG_DEBUG, "rholmNRAttachmentPoint = %g, rholmBeforeCalibAttachmentPoint = %g, omegaAttachmentPoint = %g",
rholmNRAttachmentPoint, rholmBeforeCalibAttachmentPoint, omegaAttachmentPoint);
PRINT_LOG_INFO(LOG_DEBUG, "nra = %g, hLMdivrholmAttachmentPoint = %g", nra, hLMdivrholmAttachmentPoint);
failed = 1;
}
QUIT:
gsl_spline_free (spline);
gsl_interp_accel_free (acc);
GSL_END;
STRUCTFREE(hLMdivrholmVec, REAL8Vector);
STRUCTFREE(hLMdivrholmEVec, REAL8Vector);
STRUCTFREE(hLMVec, COMPLEX16Vector);
STRUCTFREE(timeVec, REAL8Vector);
STRUCTFREE(rholmpwrlVec, COMPLEX16Vector);
STRUCTFREE(rholmpwrlVecReal, REAL8Vector);
STRUCTFREE(rholmpwrlEVecReal, REAL8Vector);
STRUCTFREE(rholmpwrlEVecImag, REAL8Vector);
STRUCTFREE(hLMrealVec, REAL8Vector);
STRUCTFREE(hLMimagVec, REAL8Vector);
STRUCTFREE(drVec, REAL8Vector);
STRUCTFREE(ncrvVec, REAL8Vector);
if (failed)
return CEV_FAILURE;
return CEV_SUCCESS;
}
static INT XLALSimIMREOBSACalcCalibCoefficientHigherModes (
SpinEOBParams * params, /**Output **/
const UINT modeL, /*<< Mode index L */
const UINT modeM, /*<< Mode index M */
SEOBSAdynamics *seobdynamics, /*<< Dynamics vector */
const REAL8 timeorb, /*<< Time of the peak of the orbital frequency */
const REAL8 m1, /**Component mass 1 */
const REAL8 m2, /**Component mass 2 */
const REAL8 deltaT /**<< Sampling interval */
)
{
// PRINT_LOG_INFO(LOG_DEBUG, "timeorb = %g\n", timeorb);
/* Status of function calls */
UINT i, j;
UINT debugRC = 0;
INT failed = 0;
UINT SEOBWaveformVersion = 451;
/** Physical quantities */
REAL8Vector *timeVec = NULL, *hLMdivrholmVec = NULL;
REAL8Vector polarDynamics;
// REAL8 valuesdata[14] = {0.};
REAL8 polarDynamicsdata[4] = {0.};
polarDynamics.length = 4;
// values.length = 14;
polarDynamics.data = polarDynamicsdata;
// values.data = valuesdata;
REAL8 omegaAttachmentPoint, hLMdivrholmAttachmentPoint, rholmNRAttachmentPoint, rholmBeforeCalibAttachmentPoint;
REAL8 rAttachmentPoint, hLMdivrholmEAttachmentPoint, rholmENRAttachmentPoint, rholmERealBeforeCalAP, rholmEImagBeforeCalAP;
REAL8 v;
COMPLEX16Vector *hLMVec = NULL, *rholmpwrlVec = NULL;
COMPLEX16 hLME, rholmpwrlE;
REAL8Vector *rholmpwrlVecReal = NULL;
REAL8Vector *rholmpwrlEVecReal = NULL;
REAL8Vector *rholmpwrlEVecImag = NULL;
REAL8Vector *hLMdivrholmEVec = NULL;
REAL8Vector orbOmegaVec, HamVec, rVec;
UINT retLen = seobdynamics->length;
REAL8 hLMrealAP, hLMimagAP, hLMrealAPDot, hLMrealAPDDot, hLMimagAPDot, hLMimagAPDDot, x0AP, x0DotAP, x0DDotAP;
REAL8Vector *hLMrealVec = NULL;
REAL8Vector *hLMimagVec = NULL;
REAL8Vector *drVec = NULL;
REAL8Vector *ncrvVec = NULL;
/** Find the vaulues of the final spins */
REAL8 mtot = m1+m2;
REAL8 eta = params->eta;
REAL8 s1dotZ = 0, s2dotZ = 0, chi1dotZ = 0, chi2dotZ = 0;
REAL8 chiS = 0;
REAL8 chiA = 0;
REAL8 tplspin = 0;
REAL8 dr, ncrv; // New
REAL8 spin1z_omegaPeak = params->chi1;
REAL8 spin2z_omegaPeak = params->chi2;
REAL8 chiS_omegaPeak = 0.5*(spin1z_omegaPeak+ spin2z_omegaPeak);
REAL8 chiA_omegaPeak = 0.5*(spin1z_omegaPeak-spin2z_omegaPeak);
/* Create dynamical arrays */
orbOmegaVec.length = HamVec.length = rVec.length = retLen;
hLMVec = CreateCOMPLEX16Vector (retLen);
rholmpwrlVec = CreateCOMPLEX16Vector (retLen);
timeVec = CreateREAL8Vector (retLen);
hLMdivrholmVec = CreateREAL8Vector (retLen);
rholmpwrlVecReal = CreateREAL8Vector (retLen);
hLMdivrholmEVec = CreateREAL8Vector (retLen);
rholmpwrlEVecReal = CreateREAL8Vector (retLen);
rholmpwrlEVecImag = CreateREAL8Vector (retLen);
drVec = CreateREAL8Vector(retLen);
ncrvVec = CreateREAL8Vector(retLen);
if (!hLMVec || !rholmpwrlVec|| !timeVec|| !rholmpwrlVec || !rholmpwrlVecReal || !hLMdivrholmEVec || !rholmpwrlEVecReal)
{failed = 1; goto QUIT;}
orbOmegaVec.data = seobdynamics->dphiVec;
HamVec.data = seobdynamics->HVec;
rVec.data = seobdynamics->rVec;
GSL_START;
/* Stuff for interpolating function */
gsl_spline *spline = NULL;
gsl_interp_accel *acc = NULL;
/* The calibration parameter is only used for 21 and 55 modes, if you try to use this function for other modes, you get an error */
if (!((modeL == 2 && modeM == 1) || (modeL == 5 && modeM == 5)))
{
PRINT_LOG_INFO (LOG_CRITICAL, "Mode %d,%d is not supported by this function.", modeL, modeM);
failed = 1;
goto QUIT;
}
/* Populate time vector as necessary */
for (i = 0; i < timeVec->length; i++)
{
timeVec->data[i] = i * deltaT;
}
/**Initializing stuff for interpolation */
spline = gsl_spline_alloc (gsl_interp_cspline, orbOmegaVec.length);
acc = gsl_interp_accel_alloc ();
/* Calculation of the frequency at the attachment point */
REAL8 timewavePeak = timeorb-XLALSimIMREOBGetNRSpinPeakDeltaTv4 (modeL, modeM, m1, m2, spin1z_omegaPeak, spin2z_omegaPeak, params->hParams);
// print_debug("timewavePeak = %g\n", timewavePeak);
int status;
status = gsl_spline_init (spline, timeVec->data, orbOmegaVec.data, orbOmegaVec.length);
if (status != GSL_SUCCESS)
{
PRINT_LOG_INFO (LOG_CRITICAL, "gsl_spline_init failed.");
failed = 1;
goto QUIT;
}
gsl_interp_accel_reset (acc);
omegaAttachmentPoint = gsl_spline_eval (spline, timewavePeak, acc);
// REAL8 domAP, ddomAP;
// domAP = gsl_spline_eval_deriv (spline, timewavePeak, acc);
// ddomAP = gsl_spline_eval_deriv2 (spline, timewavePeak, acc);
/** Calculate x0 at the attachment point */
REAL8 drAP, ddrAP;
status = gsl_spline_init (spline, timeVec->data, rVec.data, rVec.length);
if (status != GSL_SUCCESS)
{
PRINT_LOG_INFO (LOG_CRITICAL, "gsl_spline_init failed.");
failed = 1;
goto QUIT;
}
gsl_interp_accel_reset (acc);
rAttachmentPoint = gsl_spline_eval (spline, timewavePeak, acc);
// print_debug("rAttachPoint = %g\n", rAttachmentPoint);
drAP = gsl_spline_eval_deriv (spline, timewavePeak, acc);
ddrAP = gsl_spline_eval_deriv2 (spline, timewavePeak, acc);
x0AP = 1./sqrt(rAttachmentPoint);
x0DotAP = -0.5*drAP / pow(rAttachmentPoint,1.5);
x0DDotAP = 3*drAP*drAP / (4.*pow(rAttachmentPoint, 2.5)) - 0.5*ddrAP / pow(rAttachmentPoint, 1.5);
hLMrealVec = CreateREAL8Vector (retLen);
hLMimagVec = CreateREAL8Vector (retLen);
// print_debug("timewave = %g, Final Time = %g\n", timewavePeak, timeVec->data[orbOmegaVec.length-1]);
/** Calculation and interpolation at the matching point of rho_lm^l + f_lm */
chi1dotZ = params->chi1;
chi2dotZ = params->chi2;
chiS = 0.5*(chi1dotZ+chi2dotZ);
chiA = 0.5*(chi1dotZ-chi2dotZ);
tplspin = (1.-2.*eta) * chiS + (m1 - m2)/(m1 + m2) * chiA;
if ( XLALSimIMREOBCalcSpinPrecFacWaveformCoefficients( params->hCoeffs, m1, m2, eta, tplspin, chiS, chiA, SEOBWaveformVersion ) == CEV_FAILURE )
{
PRINT_LOG_INFO(LOG_CRITICAL, "failure in XLALSimIMREOBCalcSpinPrecFacWaveformCoefficients at step %d of the loop.", i);
failed = 1;
goto QUIT;
}