-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultishooting.c
1476 lines (1238 loc) · 46.6 KB
/
multishooting.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
/*
Complete routine for generating MofR plot for the massless case of BSs in ST theory.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define NRANSI
#define LEN 1000
typedef struct model
{
double *r;
double *Phi;
double *X;
double *A;
double *eta;
double *m;
double *C; // Compactness defined as m(r)/r
double *R; // Isotropic radius
double *f; // f := R / r
double *psi; // conformal factor, i.e. g_rr = psi^4
double *Psi0;
double *phigrav;
} model;
typedef struct param
{
double rmax;
double mpercentage; // mass % that determines r_BS
double rmatchfac; // Rescale matching radius
int nint;
double omega0;
double mphigrav0;
double A0;
double alpha0;
double beta0;
double phigrav0;
double Amin;
double Amax;
int nzerotarget;
int verbose;
double thresh;
int nmodels;
double lambda4;
double lambda6;
double lambda8;
double sigma0;
char potential[LEN];
} param;
// Functions
void append2Data (const char*, double, double);
void append7Data (const char*, double, double, double, double, double, double, double);
int calcExtAsym ();
void calcIso ();
void calcMass ();
double calcRadius ();
int calcRadius_index ();
int findFreqMinMax (double*, double*);
void initGrid (int, double);
double findMax (double*, int, int);
void intODE (double, double, double, int*, double*, int*);
int iofr (double);
int mygetline (char*, FILE*);
int onemodel (double*, double*, double*, double*);
void openFile (const char*);
void out1D (double*, double*, int, int, const char*);
void printPars ();
void readPars (char*);
void registerPotential();
void rescalePhi ();
void rhsBSint (double*, double*, double*, double*, double*, double*, double, double, double, double, double, double, double, double);
void rhsIso (double*, double, double, double, double);
int shoot ();
double V_series (double);
double Vp_series (double);
double V_solitonic (double);
double Vp_solitonic (double);
double F_st (double);
double derF_st (double);
double W_st (double);
double derW_st (double);
int check_phigrav (double);
// Function pointers
double (*V) (double);
double (*Vp) (double);
double (*W) (double);
double (*derW) (double);
double (*F) (double);
double (*derF) (double);
// Global variables
const double PI = 3.1415926535897932385;
param par;
model star;
/*==========================================================================*/
int main(int argc, char* argv[])
{
int i;
int success;
double omBS, mBS, rBS, CBS, dA;
if(argc != 2) { printf("Usage: %s <parfile>\n\n", argv[0]); exit(0); }
// Parameters
readPars(argv[1]);
printPars();
double phigrav_init = par.phigrav0;
// Register functions
registerPotential();
// Allocate memory
star.r = (double*) malloc((size_t) par.nint * sizeof(double));
star.Phi = (double*) malloc((size_t) par.nint * sizeof(double));
star.X = (double*) malloc((size_t) par.nint * sizeof(double));
star.A = (double*) malloc((size_t) par.nint * sizeof(double));
star.Psi0 = (double*) malloc((size_t) par.nint * sizeof(double));
star.phigrav = (double*) malloc((size_t) par.nint * sizeof(double));
star.eta = (double*) malloc((size_t) par.nint * sizeof(double));
star.m = (double*) malloc((size_t) par.nint * sizeof(double));
star.C = (double*) malloc((size_t) par.nint * sizeof(double));
star.R = (double*) malloc((size_t) par.nint * sizeof(double));
star.f = (double*) malloc((size_t) par.nint * sizeof(double));
star.psi = (double*) malloc((size_t) par.nint * sizeof(double));
openFile("MofR.dat");
openFile("MofA.dat");
openFile("Mofphigrav.dat");
openFile("AuxiliaryInfo.dat");
printf("\n\n A0 phigrav0 omega mass radius max(C)\n");
printf("==============================================================================================================\n");
if(par.nmodels == 1) dA = 0;
else dA = (par.Amax - par.Amin) / (par.nmodels - 1);
for(i = 0; i < par.nmodels; i++)
{
par.phigrav0 = phigrav_init;
par.omega0 = 1; // par.omega0 was overwritten with the last solution.
// Now we want to reinitialize it for the next model.
par.A0 = par.Amin + dA * i;
success = onemodel(&omBS, &mBS, &rBS, &CBS);
if (success==0)
{
printf("No solution found for %11.6g\n", par.A0);
}
else
{
printf("%11.6g %11.6g %16.10g %16.10g %12.6g %12.6g\n",
par.A0, par.phigrav0, omBS, mBS, rBS, CBS);
append2Data("MofR.dat", rBS, mBS);
append2Data("MofA.dat", par.A0, mBS);
append2Data("Mofphigrav.dat", par.phigrav0, mBS);
double alpha0 = exp(star.Phi[0])/sqrt(F(star.phigrav[0]));
append7Data("AuxiliaryInfo.dat", omBS, alpha0, par.phigrav0, par.A0, mBS, rBS, CBS);
}
}
printf("===============================================================================\n");
}
/*==========================================================================*/
int onemodel(double* omBS, double* mBS, double* rBS, double* CBS)
{
int k, i;
int converged, success, check_solution;
for (k = 0; k < 51; ++k)
{
if (par.verbose)
{
printf("I am starting iteration number: %d\n", k);
printf("Gravitational scalar field guess is set to %22.16g\n", par.phigrav0);
}
// Shoot
success = shoot();
if (k == 50 && success == 0)
{
printf("Shooting failed for this central boson amplitude, I could not find omin and omax values!\n");
return 0;
}
else
{
// Calculate exterior
converged = calcExtAsym();
if (converged == 0)
{par.phigrav0 -= 0.0001;}
// Rescale the time-time component of the metric such that it
// corresponds to a Schwarzschild exterior.
rescalePhi();
//This is where we define the surface of the boson star to be -- this should be far enough!
int jj = par.nint - 100;
// Surface criterion of https://iopscience.iop.org/article/10.1088/0264-9381/33/13/135002/pdf Eq.(3.15).
double derivative_term = (star.Phi[jj] - star.Phi[jj-1])/(star.r[jj] - star.r[jj-1]);
double sqrt_expr = sqrt(derivative_term * derivative_term + star.X[jj] * star.X[jj] * star.eta[jj] * star.eta[jj]);
double varphi_surface = 0.0 - (star.X[jj] * star.eta[jj]) / sqrt_expr * atanh( sqrt_expr / (derivative_term + 1 / star.r[jj]));
double criterion = star.phigrav[jj] - varphi_surface;
if (par.verbose)
{
printf("Surface boundary condition: %g\n", varphi_surface);
printf("Gravitational scalar field at the surface boundary condition: %g\n", star.phigrav[jj]);
}
if (converged == 0 && k == 49)
{
printf("I've reached max number of iterations searching for a solution and have not converged\n");
return 0;
}
if (fabs(criterion) < 1e-06 && converged != 0)
{
// for(i = 0; i < par.nint; i++)
// {
// check_solution = check_phigrav(star.phigrav[i]);
// if (check_solution == 0)
// {
// printf("Rejecting solution since it crosses -alpha0/beta0 line!\n");
// return 0;
// }
// }
// Compute diagnostic quantities and transform to isotropic coordinates.
calcMass();
*rBS = calcRadius();
*mBS = star.m[par.nint-1];
*omBS = par.omega0;
*CBS = findMax(star.C, 0, par.nint-1);
calcIso();
//Check the smoothness of the boson scalar field amplitude at the matching coordinate.
double epsilon = *mBS * (1 - 2*(*omBS)*(*omBS))/sqrt(1-(*omBS)*(*omBS));
double factor = pow(star.r[converged], 2+epsilon) * exp(sqrt(1 - *(omBS)*(*omBS)) * star.r[converged]);
double denominator = - 1 - epsilon - star.r[converged] * sqrt(1 - *(omBS)*(*omBS));
double derivative_term = (star.A[converged] - star.A[converged-1])/(star.r[converged] - star.r[converged-1]);
double constantA = factor * derivative_term / denominator;
double A_surface = constantA * pow(star.r[converged], - 1 - epsilon) * exp(-sqrt(1 - (*omBS)*(*omBS)) * star.r[converged]);
double criterion_A = star.A[converged] - A_surface;
if (criterion_A > 1e-4)
{
if (par.verbose) {printf("The bosonic scalar field is not matched smoothly enough. Exiting...\n");}
exit(0);
}
if (par.verbose)
{printf("I get the following difference, %22.16g\n", fabs(criterion));}
break;
}
// If surface criterion not satisfied to the above tolerance, use Newton-Raphson to improve the guess for \varphi_c.
else {
if (par.verbose)
{printf("I get the following difference, %22.16g\n", fabs(criterion));}
par.phigrav0 += 1e-05;
// Calculate the model all over again
shoot();
converged = calcExtAsym();
// if (converged == 0)
// {
// printf("Did not find a solution for this central boson amplitude!\n");
// break;
// }
// else
// {
rescalePhi();
double sqrt_expr_v2 = sqrt(derivative_term * derivative_term + star.X[jj] * star.X[jj] * star.eta[jj] * star.eta[jj]);
double varphi_surface_v2 = 0.0 - (star.X[jj] * star.eta[jj]) / sqrt_expr_v2
* atanh( sqrt_expr_v2 / (derivative_term + 1 / star.r[jj]));
double criterion_v2 = star.phigrav[jj] - varphi_surface_v2;
double criterion_derivative = (criterion_v2 - criterion) / (1e-05);
par.phigrav0 -= (1e-05 + criterion/criterion_derivative);
}
}
}
if(par.verbose)
{
printf("\n===================================================\n");
printf("Physical frequency: omega = %22.16g\n", par.omega0);
printf("Total mass: m = %22.16g\n", star.m[par.nint-1]);
printf("===================================================\n");
}
return 1;
}
/*==========================================================================*/
int shoot()
{
int nzero, oldnzero;
double omcur;
int cnt, success;
double ommax, ommin, om;
int sigAmax, sigAmin, sigA;
double rstopmin, rstopmax, rstop;
if(par.verbose)
{
printf("\n");
printf("omega Zero crossings Rstop sigA\n");
printf("===============================================================\n");
}
// Grid setup
initGrid(par.nint, par.rmax);
// (1) Find an upper and a lower limit for the frequency. This is done
// in findFreqMinMax, starting with omega=1 and then doubling or
// halving the value; see comments in that function. Should this
// search fail, we quit.
success = findFreqMinMax(&ommin, &ommax);
if(success == 0)
{
if (par.verbose)
{printf("Could not find ommin and ommax in shoot\n");}
return 0;
}
else
{
if(par.verbose)
printf("Using omega in [%22.16g, %22.16g]\n", ommin, ommax);
// (2) Now we finetune the frequency such that it sits right on the
// threshold between nzerotarget and nzerotarget+1. This is the
// model we seek with nzerotarget zero crossings.
if(par.verbose)
{
printf("\n");
printf("omega Zero crossings Rstop sigA\n");
printf("===============================================================\n");
}
cnt = 0;
while( (ommax - ommin) > par.thresh )
{
om = 0.5 * (ommin + ommax);
intODE(par.A0, par.phigrav0, om, &nzero, &rstop, &sigA);
if(par.verbose)
printf("%20.15g %d %15.7g %d\n",
om, nzero, rstop, sigA);
if( nzero > par.nzerotarget)
ommax = om; // the test frequency is still an upper limit
else
ommin = om;
// If we fail to reach the threshold over many iterations, we likely
// hit round-off error and reduce the accuracy requirement.
cnt++;
if(cnt > 100)
{
par.thresh *= 10;
cnt = 0;
printf("Changed threshold to %g\n", par.thresh);
}
}
// ommin gives our best estimate for the model, since it has
// nzero zero crossings whereas ommax has one zero crossing more.
// We store this frequency in the parameter omega0 for further use.
par.omega0 = ommin;
return 1;
}
}
/*==========================================================================*/
int findFreqMinMax(double* ommin, double* ommax)
{
double rstop;
int sigA, nzero, cnt, cntmax;
// Our strategy is as follows. We use the fact that the number of
// zero crossings is a non-decreasing function of the frequency;
// increasing omega0 gives you at least as many zero crossings as
// before. We have a target, ntarget. We compute the number of zero
// crossings for omega0 = 1.
// If the resulting n>ntarget, we half omega0 until n <= ntarget
// (note that the stable BS is always the limiting case to have
// one more zero crossing -- the new crossing is at infinity in
// the limiting case). Once we have n <= ntarget, the corresponding
// two omega0 values are the brackets.
// If the resulting n<=ntarget, we double omega0 until we have
// n > ntarget and the ensuing omega0 values are our brackets.
intODE(par.A0, par.phigrav0, par.omega0, &nzero, &rstop, &sigA);
if(par.verbose)
printf("%15.10g %d %15.7g %d\n",
par.omega0, nzero, rstop, sigA);
cnt = 0; // cnt is a sanity measure to avoid hanging
cntmax = 100; // in the loop forever. It should never be
// triggered unless the frequency has values
// of 2^{1000} or 2^{-100}...
if(nzero > par.nzerotarget)
{
*ommin = par.omega0;
while(nzero > par.nzerotarget && cnt < cntmax)
{
*ommax = *ommin;
*ommin /= 2;
intODE(par.A0, par.phigrav0, *ommin, &nzero, &rstop, &sigA);
if(par.verbose)
printf("%15.10g %d %15.7g %d\n",
*ommin, nzero, rstop, sigA);
cnt++;
}
}
else
{
*ommax = par.omega0;
while(nzero <= par.nzerotarget && cnt < cntmax)
{
*ommin = *ommax;
*ommax *= 2;
intODE(par.A0, par.phigrav0, *ommax, &nzero, &rstop, &sigA);
if(par.verbose)
printf("%15.10g %d %15.7g %d\n",
*ommax, nzero, rstop, sigA);
cnt++;
}
}
if(cnt == cntmax)
return 0; // Either upper or lower frequency limit has not been found.
else
return 1;
}
/*==========================================================================*/
void intODE(double A0, double phigrav0, double omega, int* nzero, double* rstop, int* sigAstop)
{
int i, n1, istop;
double dr, r, X, A, eta, Phi, Psi0, phigrav, om;
double rhs_X, rhs_A, rhs_eta, rhs_Phi, rhs_Psi0, rhs_phigrav;
double dX[5], dA[5], dPsi0[5], deta[5], dphigrav[5], dPhi[5];
n1 = par.nint;
om = omega;
*sigAstop = 0; // Default for no stopping
*nzero = 0;
*rstop = star.r[n1-1];
istop = -1; // So we have no vacuum region unless we exceed the amplitude
// Central values
star.X[0] = 1/sqrt(F(phigrav0));
star.A[0] = A0;
star.phigrav[0] = phigrav0;
star.Psi0[0] = 0;
star.eta[0] = 0;
star.Phi[0] = 0; // Phi has a free constant we later match to Schwarzschild
// RK integration
for(i = 1; i < n1; i++)
{
dr = star.r[i] - star.r[i-1];
// 1st RK step
r = star.r[i-1];
X = star.X[i-1];
A = star.A[i-1];
eta = star.eta[i-1];
phigrav = star.phigrav[i-1];
Phi = star.Phi[i-1];
Psi0 = star.Psi0[i-1];
rhsBSint(&rhs_X, &rhs_A, &rhs_eta, &rhs_Phi, &rhs_phigrav, &rhs_Psi0, r, X, A, eta, Phi, phigrav, Psi0, om);
dX[1] = rhs_X * dr;
dA[1] = rhs_A * dr;
dPsi0[1] = rhs_Psi0 * dr;
dphigrav[1] = rhs_phigrav * dr;
deta[1] = rhs_eta * dr;
dPhi[1] = rhs_Phi * dr;
// 2nd RK step
r = star.r[i-1] + 0.5 * dr;
X = star.X[i-1] + 0.5 * dX[1];
A = star.A[i-1] + 0.5 * dA[1];
eta = star.eta[i-1] + 0.5 * deta[1];
phigrav = star.phigrav[i-1] + 0.5 * dphigrav[1];
Phi = star.Phi[i-1] + 0.5 * dPhi[1];
Psi0 = star.Psi0[i-1] + 0.5 * dPsi0[1];
rhsBSint(&rhs_X, &rhs_A, &rhs_eta, &rhs_Phi, &rhs_phigrav, &rhs_Psi0, r, X, A, eta, Phi, phigrav, Psi0, om);
dX[2] = rhs_X * dr;
dA[2] = rhs_A * dr;
dPsi0[2] = rhs_Psi0 * dr;
dphigrav[2] = rhs_phigrav * dr;
deta[2] = rhs_eta * dr;
dPhi[2] = rhs_Phi * dr;
// 3rd RK step
r = star.r[i-1] + 0.5 * dr;
X = star.X[i-1] + 0.5 * dX[2];
A = star.A[i-1] + 0.5 * dA[2];
eta = star.eta[i-1] + 0.5 * deta[2];
phigrav = star.phigrav[i-1] + 0.5 * dphigrav[2];
Phi = star.Phi[i-1] + 0.5 * dPhi[2];
Psi0 = star.Psi0[i-1] + 0.5 * dPsi0[2];
rhsBSint(&rhs_X, &rhs_A, &rhs_eta, &rhs_Phi, &rhs_phigrav, &rhs_Psi0, r, X, A, eta, Phi, phigrav, Psi0, om);
dX[3] = rhs_X * dr;
dA[3] = rhs_A * dr;
dPsi0[3] = rhs_Psi0 * dr;
dphigrav[3] = rhs_phigrav * dr;
deta[3] = rhs_eta * dr;
dPhi[3] = rhs_Phi * dr;
// 4th RK step
r = star.r[i];
X = star.X[i-1] + dX[3];
A = star.A[i-1] + dA[3];
eta = star.eta[i-1] + deta[3];
phigrav = star.phigrav[i-1] + dphigrav[3];
Phi = star.Phi[i-1] + dPhi[3];
Psi0 = star.Psi0[i-1] + dPsi0[3];
rhsBSint(&rhs_X, &rhs_A, &rhs_eta, &rhs_Phi, &rhs_phigrav, &rhs_Psi0, r, X, A, eta, Phi, phigrav, Psi0, om);
dX[4] = rhs_X * dr;
dA[4] = rhs_A * dr;
dPsi0[4] = rhs_Psi0 * dr;
dphigrav[4] = rhs_phigrav * dr;
deta[4] = rhs_eta * dr;
dPhi[4] = rhs_Phi * dr;
// Update variables
star.X[i] = star.X[i-1] + (dX[1] + 2*dX[2] + 2*dX[3] + dX[4] ) / 6.0;
star.A[i] = star.A[i-1] + (dA[1] + 2*dA[2] + 2*dA[3] + dA[4] ) / 6.0;
star.Psi0[i] = star.Psi0[i-1] + (dPsi0[1] + 2*dPsi0[2] + 2*dPsi0[3] + dPsi0[4] ) / 6.0;
star.phigrav[i] = star.phigrav[i-1] + (dphigrav[1] + 2*dphigrav[2] + 2*dphigrav[3] + dphigrav[4] ) / 6.0;
star.eta[i] = star.eta[i-1] + (deta[1]+ 2*deta[2]+ 2*deta[3]+deta[4]) / 6.0;
star.Phi[i] = star.Phi[i-1] + (dPhi[1]+ 2*dPhi[2]+ 2*dPhi[3]+dPhi[4]) / 6.0;
// Analyze: do we cross zero? do we exceed 2*A0?
if(fabs(star.A[i]) > 2*star.A[0] || star.A[i] != star.A[i])
{
*sigAstop = ( (star.A[i-1] > 0) - (star.A[i-1] < 0) );
istop = i-1; // We stop the integration; one point as sanity buffer
// There is one problem here: We regard the present data point and
// also the previous one as unrealiable. The previous point,
// however, might have been counted as a zero crossing. If that
// happened, we wish to undo this counting.
if(star.A[i-1] * star.A[i-2] < 0) (*nzero)--;
break;
}
if(star.A[i] * star.A[i-1] < 0) (*nzero)++;
}
if(istop < 0)
{
*sigAstop = ( (star.A[n1-1] > 0) - (star.A[n1-1] < 0) );
return; // Integration went through; no need for vacuum
}
// Set to vacuum beyond rstop
*rstop = star.r[istop];
// RK integration
for(i = istop; i < n1; i++)
{
dr = star.r[i] - star.r[i-1];
// 1st RK step
r = star.r[i-1];
X = star.X[i-1];
A = 0;
Psi0 = 0;
phigrav = star.phigrav[i-1];
eta = star.eta[i-1];
Phi = star.Phi[i-1];
rhsBSint(&rhs_X, &rhs_A, &rhs_eta, &rhs_Phi, &rhs_phigrav, &rhs_Psi0, r, X, A, eta, Phi, phigrav, Psi0, om);
dX[1] = rhs_X * dr;
dPhi[1] = rhs_Phi * dr;
dphigrav[1] = rhs_phigrav * dr;
deta[1] = rhs_eta * dr;
// 2nd RK step
r = star.r[i-1] + 0.5 * dr;
X = star.X[i-1] + 0.5 * dX[1];
A = 0;
Psi0 = 0;
phigrav = star.phigrav[i-1] + 0.5 * dphigrav[1];
eta = star.eta[i-1] + 0.5 * deta[1];
Phi = star.Phi[i-1] + 0.5 * dPhi[1];
rhsBSint(&rhs_X, &rhs_A, &rhs_eta, &rhs_Phi, &rhs_phigrav, &rhs_Psi0, r, X, A, eta, Phi, phigrav, Psi0, om);
dX[2] = rhs_X * dr;
dPhi[2] = rhs_Phi * dr;
dphigrav[2] = rhs_phigrav * dr;
deta[2] = rhs_eta * dr;
// 3rd RK step
r = star.r[i-1] + 0.5 * dr;
X = star.X[i-1] + 0.5 * dX[2];
A = 0;
Psi0 = 0;
phigrav = star.phigrav[i-1] + 0.5 * dphigrav[2];
eta = star.eta[i-1] + 0.5 * deta[2];
Phi = star.Phi[i-1] + 0.5 * dPhi[2];
rhsBSint(&rhs_X, &rhs_A, &rhs_eta, &rhs_Phi, &rhs_phigrav, &rhs_Psi0, r, X, A, eta, Phi, phigrav, Psi0, om);
dX[3] = rhs_X * dr;
dPhi[3] = rhs_Phi * dr;
dphigrav[3] = rhs_phigrav * dr;
deta[3] = rhs_eta * dr;
// 4th RK step
r = star.r[i];
X = star.X[i-1] + dX[3];
A = 0;
Psi0 = 0;
phigrav = star.phigrav[i-1] + dphigrav[3];
eta = star.eta[i-1] + deta[3];
Phi = star.Phi[i-1] + dPhi[3];
rhsBSint(&rhs_X, &rhs_A, &rhs_eta, &rhs_Phi, &rhs_phigrav, &rhs_Psi0, r, X, A, eta, Phi, phigrav, Psi0, om);
dX[4] = rhs_X * dr;
dPhi[4] = rhs_Phi * dr;
dphigrav[4] = rhs_phigrav * dr;
deta[4] = rhs_eta * dr;
// Update variables
star.X[i] = star.X[i-1] + (dX[1] + 2*dX[2] + 2*dX[3] + dX[4] ) / 6.0;
star.A[i] = 0;
star.Psi0[i] = 0;
star.eta[i] = star.eta[i-1] + (deta[1] + 2*deta[2] + 2*deta[3] + deta[4] ) / 6.0;
star.phigrav[i] = star.phigrav[i-1] + (dphigrav[1] + 2*dphigrav[2] + 2*dphigrav[3] + dphigrav[4] ) / 6.0;
star.Phi[i] = star.Phi[i-1] + (dPhi[1]+ 2*dPhi[2]+ 2*dPhi[3]+dPhi[4]) / 6.0;
}
}
/*==========================================================================*/
void rhsBSint(double* rhs_X, double* rhs_A, double* rhs_eta, double* rhs_Phi, double* rhs_phigrav, double* rhs_Psi0,
double r, double X, double A, double eta, double Phi, double phigrav, double Psi0, double om)
{
if(r < 1.0e-15)
{
// We are at r = 0 and need to use the asymptotic behaviour.
// For eta we use that near r=0, we have
//
// eta(r) = eta(0) + eta'(0)*r + ... = eta'(0)*r + ...
// ==> 2*eta/r = 2*eta'(0) + ...
//
// This gives a factor 1/3 to be applied to the remaining rhs
// of the eta equation.
*rhs_X = 0;
*rhs_phigrav = 0;
*rhs_Psi0 = (-om*om * A * exp(-2*Phi) + (1/F(phigrav)) * Vp(A) * A) / 3;
*rhs_A = 0;
*rhs_eta = (sqrt(F(phigrav)) * derW(phigrav) + 2*PI * derF(phigrav) / (F(phigrav) * sqrt(F(phigrav))) * (om*om * A*A * exp(-2*Phi) * F(phigrav) - 2*V(A))) / 3;
*rhs_Phi = 0;
}
else
{
*rhs_Phi = 0.5 * (F(phigrav)*X*X - 1) / r - r * F(phigrav) * (X*X) * W(phigrav) + (r/2) * (X*X) * (eta*eta) + 2*PI * r * X*X * (1/F(phigrav)) * (Psi0*Psi0 / (X*X)
+ om*om * exp(-2*Phi) * A*A * F(phigrav) - V(A));
*rhs_X = (r/2) * (X*X*X) * (eta*eta) + r * F(phigrav) * (X*X*X) * W(phigrav) - 0.5 * X * (F(phigrav)*X*X - 1) / r - 0.5 * derF(phigrav) * (X*X) * eta + 2*PI * r * X*X*X / F(phigrav)
* (Psi0*Psi0 / (X*X) + om*om * exp(-2*Phi) * A*A * F(phigrav) + V(A));
*rhs_phigrav = X * eta;
*rhs_A = Psi0;
*rhs_eta = - eta * ((*rhs_Phi) - 0.5 * derF(phigrav) * X * eta) - 2 * eta / r + F(phigrav) * X * derW(phigrav) +
+ 2*PI * X * derF(phigrav) * (1/F(phigrav)) * (om*om * exp(-2*Phi) * A*A * F(phigrav) - Psi0*Psi0 / (X*X) - 2*V(A));
*rhs_Psi0 = -2 * Psi0 * (1/r) + Psi0 * ((*rhs_X)/X + 1.5 * derF(phigrav) * X * eta - (*rhs_Phi)) - (X*X) * (om*om) * A * exp(-2*Phi) * F(phigrav) + (X*X) * A * Vp(A);
}
}
/*==========================================================================*/
double V_series(double A)
{
// Potential function
return A*A * (1 + par.lambda4 * A*A + par.lambda6 * A*A*A*A
+ par.lambda8 * A*A*A*A*A*A);
}
/*==========================================================================*/
double Vp_series(double A)
{
// Potential derviative dV / d(A^2)
return 1 + 2*par.lambda4 * A*A + 3*par.lambda6 * A*A*A*A
+ 4*par.lambda8 * A*A*A*A*A*A;
}
/*==========================================================================*/
double V_solitonic(double A)
{
// Solitonic potential function
return A*A * (1 - 2 * A*A / (par.sigma0*par.sigma0))
* (1 - 2 * A*A / (par.sigma0*par.sigma0));
}
/*==========================================================================*/
double Vp_solitonic(double A)
{
// Solitonic potential function
return (1 - 2 * A*A / (par.sigma0*par.sigma0))
* (1 - 6 * A*A / (par.sigma0*par.sigma0));
}
/*==========================================================================*/
double F_st(double phigrav)
{
// Coupling function of the gravitational scalar field
return exp(-2 * par.alpha0 * phigrav - par.beta0 * phigrav * phigrav);
}
/*==========================================================================*/
double derF_st(double phigrav)
{
// Function F_{,\varphi} / F
return -2 * par.alpha0 - 2 * par.beta0 * phigrav;
}
/*==========================================================================*/
double W_st(double phigrav)
{
// Potential for the gravitational scalar field
return 0.5 * par.mphigrav0 * par.mphigrav0 * phigrav * phigrav;
}
/*==========================================================================*/
double derW_st(double phigrav)
{
// Derivative of the potential for the gravitational scalar field
return par.mphigrav0 * par.mphigrav0 * phigrav;
}
/*==========================================================================*/
void initGrid(int n, double rmax)
{
int i;
for(i = 0; i < n; i++)
star.r[i] = rmax * i / (n - 1.0);
}
/*==========================================================================*/
int mygetline( char *s, FILE *ifp )
{
int c, i;
for( i = 0; i < LEN && ( (c = getc(ifp)) != EOF ) && (c != '\n'); i++ )
s[i] = c;
if( c == '\n' ) s[i++] = c;
s[i] = '\0';
return i;
}
/*==========================================================================*/
void out1D(double* x, double* y, int n1, int n2, const char* ofil)
{
int i;
FILE* ofp;
ofp = fopen(ofil, "w");
if(ofp == NULL) { printf("Cannot open %s in out1D\n\n", ofil); exit(0); }
fprintf(ofp, "# %s\n", ofil);
for(i = n1; i <= n2; i++)
fprintf(ofp, "%22.16g %22.16g\n", x[i], y[i]);
fclose(ofp);
}
/*==========================================================================*/
void printPars()
{
printf("=======================================\n");
printf("nint = %d\n", par.nint);
printf("rmax = %g\n", par.rmax);
printf("omega0 = %g\n", par.omega0);
printf("Amin = %g\n", par.Amin);
printf("Amax = %g\n", par.Amax);
printf("mphigrav0 = %g\n", par.mphigrav0);
printf("phigrav0 = %g\n", par.phigrav0);
printf("alpha0 = %g\n", par.alpha0);
printf("beta0 = %g\n", par.beta0);
printf("nzerotarget = %d\n", par.nzerotarget);
printf("thresh = %g\n", par.thresh);
printf("mpercentage = %g\n", par.mpercentage);
printf("rmatchfac = %g\n", par.rmatchfac);
printf("potential = %s\n", par.potential);
if(strcmp(par.potential, "series") == 0)
{
printf("lambda4 = %g\n", par.lambda4);
printf("lambda6 = %g\n", par.lambda6);
printf("lambda8 = %g\n", par.lambda8);
}
else if(strcmp(par.potential, "solitonic") == 0)
printf("sigma0 = %g\n", par.sigma0);
printf("=======================================\n");
}
/*==========================================================================*/
void readPars(char* ifil)
{
FILE* ifp;
char line[LEN];
int n, i;
// First set all parameters to default values
par.nint = 401;
par.rmax = 1;
par.omega0 = 1.0;
par.Amin = 0.1;
par.Amax = 0.1;
par.mphigrav0 = 1.0;
par.alpha0 = 3.0;
par.beta0 = 0.0;
par.phigrav0 = 0.0;
par.nmodels = 1;
par.nzerotarget = 0;
par.verbose = 0;
par.thresh = 2e-16;
par.mpercentage = 90.0;
par.rmatchfac = 1;
strcpy(par.potential, "series");
par.lambda4 = 0;
par.lambda6 = 0;
par.lambda8 = 0;
par.sigma0 = 1;
// Read parameters from file and overwrite default values
ifp = fopen(ifil, "r");
if(ifp == NULL) { printf("Cannot open %s in readPars\n\n", ifil); exit(0); }
while(mygetline(line, ifp) != 0)
{
if(line[0] == '#')
; // Comment line
else
{
n = strlen(line);
// Replace '=' with white space for syntax flexibility
for(i = 0; i < n; i++)
if(line[i] == '=') line[i] = ' ';
// Analyze parameter values
if(strstr(line, "nint") != NULL)
sscanf(line, "nint %d", &(par.nint));
else if(strstr(line, "rmax") != NULL)
sscanf(line, "rmax %le", &(par.rmax));
else if(strstr(line, "omega0") != NULL)
sscanf(line, "omega0 %le", &(par.omega0));
else if(strstr(line, "Amax") != NULL)
sscanf(line, "Amax %le", &(par.Amax));
else if(strstr(line, "Amin") != NULL)
sscanf(line, "Amin %le", &(par.Amin));
else if(strstr(line, "mphigrav0") != NULL)
sscanf(line, "mphigrav0 %le", &(par.mphigrav0));
else if(strstr(line, "alpha0") != NULL)
sscanf(line, "alpha0 %le", &(par.alpha0));
else if(strstr(line, "beta0") != NULL)
sscanf(line, "beta0 %le", &(par.beta0));
else if(strstr(line, "phigrav0") != NULL)
sscanf(line, "phigrav0 %le", &(par.phigrav0));
else if(strstr(line, "nmodels") != NULL)
sscanf(line, "nmodels %d", &(par.nmodels));
else if(strstr(line, "nzerotarget") != NULL)
sscanf(line, "nzerotarget %d", &(par.nzerotarget));
else if(strstr(line, "verbose") != NULL)
sscanf(line, "verbose %d", &(par.verbose));
else if(strstr(line, "thresh") != NULL)
sscanf(line, "thresh %le", &(par.thresh));
else if(strstr(line, "mpercentage") != NULL)
sscanf(line, "mpercentage %le", &(par.mpercentage));
else if(strstr(line, "rmatchfac") != NULL)
sscanf(line, "rmatchfac %le", &(par.rmatchfac));
else if(strstr(line, "potential") != NULL)
sscanf(line, "potential %s", par.potential);
else if(strstr(line, "lambda4") != NULL)
sscanf(line, "lambda4 %le", &(par.lambda4));
else if(strstr(line, "lambda6") != NULL)
sscanf(line, "lambda6 %le", &(par.lambda6));
else if(strstr(line, "lambda8") != NULL)
sscanf(line, "lambda8 %le", &(par.lambda8));
else if(strstr(line, "sigma0") != NULL)
sscanf(line, "sigma0 %le", &(par.sigma0));
}
}
fclose(ifp);
}
/*==========================================================================*/
void registerPotential()
{
if(strcmp(par.potential, "series") == 0)
{
V = (double (*)(double))(V_series);
Vp = (double (*)(double))(Vp_series);
W = (double (*)(double))(W_st);
derW = (double (*)(double))(derW_st);
F = (double (*)(double))(F_st);
derF = (double (*)(double))(derF_st);
}
else if(strcmp(par.potential, "solitonic") == 0)
{
V = (double (*)(double))(V_solitonic);
Vp = (double (*)(double))(Vp_solitonic);
W = (double (*)(double))(W_st);
derW = (double (*)(double))(derW_st);
F = (double (*)(double))(F_st);
derF = (double (*)(double))(derF_st);
}
else
{ printf("Unknown potential: %s\n\n", par.potential); exit(0); }
}
/*==========================================================================*/
void rhsVac(double* rhs_X, double* rhs_Phi, double r, double X, double Phi)
{
if(r < 1.0e-15)
{
// At r = 0, the gradients of the metric functions are zero
*rhs_X = 0;
*rhs_Phi = 0;
}
else
{
*rhs_Phi = 0.5 * (X*X - 1) / r;
*rhs_X = -0.5 * X * (X*X - 1) / r;
}
}
/*==========================================================================*/
int calcExtAsym()
{
int i, k, nzero, sigA, istop, imatch_phigrav, imatch;
double rstop, c1, c2, c3, c4, epsilon, delta, mass;
double r, X, Phi, A, eta, Psi0, phigrav, rhs_X, rhs_Phi, rhs_A, rhs_phigrav, rhs_Psi0, rhs_eta, om, mphigrav, dr;
double dX[5], deta[5], dphigrav[5], dPhi[5], dA[5], dPsi0[5];
// At this stage we have the correct frequency from the shooting
// algorithm. Here we will compute this model and also remove
// the diverging part in the profile and replace it with a smooth
// exterior. Note that we are not yet rescaling time and frequency
// yet, since we will need the complete profile with exterior to do
// that.
intODE(par.A0, par.phigrav0, par.omega0, &nzero, &rstop, &sigA);
if(par.verbose)
{
printf("---------------------------------------------------------------\n");