-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathBaseStar.cpp
More file actions
executable file
·4504 lines (3720 loc) · 235 KB
/
BaseStar.cpp
File metadata and controls
executable file
·4504 lines (3720 loc) · 235 KB
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
// gsl includes
#include <gsl/gsl_roots.h>
#include <gsl/gsl_cdf.h>
#include "Rand.h"
#include "BaseStar.h"
#include "vector3d.h"
#include "BH.h"
// boost includes
#include <boost/math/distributions.hpp>
using std::max;
using std::min;
BaseStar::BaseStar() {
// initialise member variables
m_ObjectId = globalObjectId++; // unique object id - remains for life of star (even through evolution to other phases)
m_ObjectPersistence = OBJECT_PERSISTENCE::PERMANENT; // object persistence - permanent or ephemeral (ephemeral used for ephemeral clones)
m_InitialStellarType = STELLAR_TYPE::STAR; // stellar type - changes throughout life of star (through evolution to other phases)
m_StellarType = STELLAR_TYPE::STAR; // stellar type - changes throughout life of star (through evolution to other phases)
m_Error = ERROR::NONE; // clear error flag
}
BaseStar::BaseStar(const unsigned long int p_RandomSeed,
const double p_MZAMS,
const double p_Metallicity,
const KickParameters p_KickParameters,
const double p_RotationalFrequency) {
// initialise member variables
m_ObjectId = globalObjectId++; // unique object id - remains for life of star (even through evolution to other phases)
m_ObjectPersistence = OBJECT_PERSISTENCE::PERMANENT; // object persistence - permanent or ephemeral (ephemeral used for ephemeral clones)
m_InitialStellarType = STELLAR_TYPE::STAR; // stellar type - changes throughout life of star (through evolution to other phases)
m_StellarType = STELLAR_TYPE::STAR; // stellar type - changes throughout life of star (through evolution to other phases)
m_Error = ERROR::NONE; // clear error flag
m_CHE = false; // initially
m_EvolutionStatus = EVOLUTION_STATUS::CONTINUE; // initially
// Initialise member variables from input parameters
// (kick parameters initialised below - see m_SupernovaDetails)
m_RandomSeed = p_RandomSeed;
m_MZAMS = p_MZAMS;
m_Metallicity = p_Metallicity;
// Initialise metallicity dependent values
m_Log10Metallicity = log10(m_Metallicity);
// Initialise coefficients, parameters and constants
// initialise m_Timescales vector - so we have the right number of entries
for (int i = 0; i < static_cast<int>(TIMESCALE::COUNT); i++) {
m_Timescales.push_back(DEFAULT_INITIAL_DOUBLE_VALUE);
}
// initialise m_GBParams vector - so we have the right number of entries
for (int i = 0; i < static_cast<int>(GBP::COUNT); i++) {
m_GBParams.push_back(DEFAULT_INITIAL_DOUBLE_VALUE);
}
// initialise m_MassCutoffs vector - so we have the right number of entries
for (int i = 0; i < static_cast<int>(MASS_CUTOFF::COUNT); i++) {
m_MassCutoffs.push_back(DEFAULT_INITIAL_DOUBLE_VALUE);
}
// initialise m_LConstants vector - so we have the right number of entries
for (int i = 0; i < static_cast<int>(L_CONSTANTS::COUNT); i++) {
m_LConstants.push_back(DEFAULT_INITIAL_DOUBLE_VALUE);
}
// initialise m_RConstants vector - so we have the right number of entries
for (int i = 0; i < static_cast<int>(R_CONSTANTS::COUNT); i++) {
m_RConstants.push_back(DEFAULT_INITIAL_DOUBLE_VALUE);
}
// initialise m_GammaConstants vector - so we have the right number of entries
for (int i = 0; i < static_cast<int>(GAMMA_CONSTANTS::COUNT); i++) {
m_GammaConstants.push_back(DEFAULT_INITIAL_DOUBLE_VALUE);
}
// calculate coefficients, constants etc.
CalculateRCoefficients(LogMetallicityXiHurley(), m_RCoefficients);
CalculateLCoefficients(LogMetallicityXiHurley(), m_LCoefficients);
CalculateMassCutoffs(m_Metallicity, LogMetallicityXiHurley(), m_MassCutoffs);
CalculateAnCoefficients(m_AnCoefficients, m_LConstants, m_RConstants, m_GammaConstants);
CalculateBnCoefficients(m_BnCoefficients);
m_XExponent = CalculateGBRadiusXExponent();
m_Alpha1 = CalculateAlpha1();
m_Alpha3 = CalculateAlpha3();
m_Alpha4 = CalculateAlpha4();
// initialise remaining member variables
// Zero age main sequence parameters
m_InitialMainSequenceCoreMass = DEFAULT_INITIAL_DOUBLE_VALUE; // initialised in MS_gt_07 class if BRCEK core mass prescription is used
m_RZAMS = CalculateRadiusAtZAMS(m_MZAMS);
m_LZAMS = CalculateLuminosityAtZAMS(m_MZAMS);
m_TZAMS = CalculateTemperatureOnPhase_Static(m_LZAMS, m_RZAMS);
// Initial abundances
m_InitialHeliumAbundance = CalculateInitialHeliumAbundance();
m_HeliumAbundanceCore = m_InitialHeliumAbundance;
m_HeliumAbundanceSurface = m_InitialHeliumAbundance;
m_InitialHydrogenAbundance = CalculateInitialHydrogenAbundance();
m_HydrogenAbundanceCore = m_InitialHydrogenAbundance;
m_HydrogenAbundanceSurface = m_InitialHydrogenAbundance;
// Effective initial Zero Age Main Sequence parameters corresponding to Mass0
m_RZAMS0 = m_RZAMS;
m_LZAMS0 = m_LZAMS;
// Current timestep attributes
m_Time = DEFAULT_INITIAL_DOUBLE_VALUE;
m_Dt = DEFAULT_INITIAL_DOUBLE_VALUE;
m_Tau = DEFAULT_INITIAL_DOUBLE_VALUE;
m_Age = 0.0; // ensure age = 0.0 at construction (rather than default initial value)
m_MainSequenceCoreMass = DEFAULT_INITIAL_DOUBLE_VALUE;
m_Mass = m_MZAMS;
m_Mass0 = m_MZAMS;
m_Luminosity = m_LZAMS;
m_Radius = m_RZAMS;
m_Temperature = m_TZAMS;
m_TotalMassLossRate = DEFAULT_INITIAL_DOUBLE_VALUE;
m_ComponentVelocity = Vector3d();
m_OmegaCHE = CalculateOmegaCHE(m_MZAMS, m_Metallicity);
m_OmegaZAMS = p_RotationalFrequency >= 0.0 // valid rotational frequency passed in?
? _2_PI * p_RotationalFrequency // yes - convert from cycles/yr to rad/yr and use it
: CalculateZAMSAngularFrequency(m_MZAMS, m_RZAMS); // no - calculate it
m_AngularMomentum = CalculateMomentOfInertiaAU() * m_OmegaZAMS;
m_CoreMass = DEFAULT_INITIAL_DOUBLE_VALUE;
m_COCoreMass = DEFAULT_INITIAL_DOUBLE_VALUE;
m_HeCoreMass = DEFAULT_INITIAL_DOUBLE_VALUE;
m_Mu = DEFAULT_INITIAL_DOUBLE_VALUE;
m_Mdot = DEFAULT_INITIAL_DOUBLE_VALUE;
m_DominantMassLossRate = MASS_LOSS_TYPE::NONE;
m_MinimumLuminosityOnPhase = DEFAULT_INITIAL_DOUBLE_VALUE;
m_LBVphaseFlag = false;
m_EnvelopeJustExpelledByPulsations = false;
// Previous timestep attributes
m_StellarTypePrev = m_StellarType;
m_MassPrev = m_MZAMS;
m_RadiusPrev = m_RZAMS;
m_DtPrev = DEFAULT_INITIAL_DOUBLE_VALUE;
// Supernova details
m_SupernovaDetails.initialKickParameters = p_KickParameters;
m_SupernovaDetails.events.current = SN_EVENT::NONE;
m_SupernovaDetails.events.past = SN_EVENT::NONE;
m_SupernovaDetails.coreMassAtCOFormation = DEFAULT_INITIAL_DOUBLE_VALUE;
m_SupernovaDetails.coreRadiusAtCOFormation = DEFAULT_INITIAL_DOUBLE_VALUE;
m_SupernovaDetails.COCoreMassAtCOFormation = DEFAULT_INITIAL_DOUBLE_VALUE;
m_SupernovaDetails.HeCoreMassAtCOFormation = DEFAULT_INITIAL_DOUBLE_VALUE;
m_SupernovaDetails.totalMassAtCOFormation = DEFAULT_INITIAL_DOUBLE_VALUE;
m_SupernovaDetails.totalRadiusAtCOFormation= DEFAULT_INITIAL_DOUBLE_VALUE;
m_SupernovaDetails.drawnKickMagnitude = DEFAULT_INITIAL_DOUBLE_VALUE;
m_SupernovaDetails.kickMagnitude = DEFAULT_INITIAL_DOUBLE_VALUE;
m_SupernovaDetails.isHydrogenPoor = false;
m_SupernovaDetails.fallbackFraction = DEFAULT_INITIAL_DOUBLE_VALUE;
m_SupernovaDetails.eccentricAnomaly = DEFAULT_INITIAL_DOUBLE_VALUE;
m_SupernovaDetails.trueAnomaly = DEFAULT_INITIAL_DOUBLE_VALUE;
m_SupernovaDetails.supernovaState = SN_STATE::NONE;
m_SupernovaDetails.kickMagnitudeRandom = p_KickParameters.magnitudeRandom;
m_SupernovaDetails.theta = p_KickParameters.theta;
m_SupernovaDetails.phi = p_KickParameters.phi;
m_SupernovaDetails.meanAnomaly = p_KickParameters.meanAnomaly;
m_SupernovaDetails.rocketKickMagnitude = DEFAULT_INITIAL_DOUBLE_VALUE;
m_SupernovaDetails.rocketKickPhi = DEFAULT_INITIAL_DOUBLE_VALUE;
m_SupernovaDetails.rocketKickTheta = DEFAULT_INITIAL_DOUBLE_VALUE;
// Calculates the Baryonic mass for which the GravitationalRemnantMass will be equal to the maximumNeutronStarMass (inverse of SolveQuadratic())
// needed to decide whether to calculate Fryer+2012 for Neutron Star or Black Hole in GiantBranch::CalculateGravitationalRemnantMass()
// calculate only once for entire simulation of N binaries in the future.
m_BaryonicMassOfMaximumNeutronStarMass = (0.075 * OPTIONS->MaximumNeutronStarMass() * OPTIONS->MaximumNeutronStarMass()) + OPTIONS->MaximumNeutronStarMass();
// Pulsar details
m_PulsarDetails.magneticField = DEFAULT_INITIAL_DOUBLE_VALUE;
m_PulsarDetails.spinPeriod = DEFAULT_INITIAL_DOUBLE_VALUE;
m_PulsarDetails.spinFrequency = DEFAULT_INITIAL_DOUBLE_VALUE;
m_PulsarDetails.spinDownRate = DEFAULT_INITIAL_DOUBLE_VALUE;
m_PulsarDetails.birthPeriod = DEFAULT_INITIAL_DOUBLE_VALUE;
m_PulsarDetails.birthSpinDownRate = DEFAULT_INITIAL_DOUBLE_VALUE;
// Mass Transfer Donor Type History
m_MassTransferDonorHistory = ST_VECTOR();
}
///////////////////////////////////////////////////////////////////////////////////////
// //
// CLASS FUNCTIONS //
// //
///////////////////////////////////////////////////////////////////////////////////////
/*
* Determine the value of the requested property of the constituent star (parameter p_Property)
*
* The property is a boost variant variable, and is one of the following types:
*
* STAR_PROPERTY - any individual star property
* STAR_1_PROPERTY - property of the primary (m_Star1)
* STAR_2_PROPERTY - property of the secondary (m_Star2)
* SUPERNOVA_PROPERTY - property of the star that has gone supernova
* COMPANION_PROPERTY - property of the companion to the supernova
* BINARY_PROPERTY - property of the binary
* PROGRAM_OPTION - program option
*
* This function handles properties of type:
*
* STAR_PROPERTY, STAR_1_PROPERTY, STAR_2_PROPERTY, SUPERNOVA_PROPERTY, COMPANION_PROPERTY
*
* only - anything else will result in an error being thrown and the evolution of the star (or binary)
* terminated.
*
* This is the function used to retrieve values for properties required to be printed.
* This allows the composition of the log records to be dynamically modified - this is
* how we allow users to specify what properties they want recorded in log files.
*
* The functional return is the value of the property requested.
*
*
* COMPAS_VARIABLE StellarPropertyValue(const T_ANY_PROPERTY p_Property)
*
* @param [IN] p_Property The property for which the value is required
* @return The value of the requested property
*/
COMPAS_VARIABLE BaseStar::StellarPropertyValue(const T_ANY_PROPERTY p_Property) const {
COMPAS_VARIABLE value;
ANY_STAR_PROPERTY property;
switch (boost::apply_visitor(VariantPropertyType(), p_Property)) {
case ANY_PROPERTY_TYPE::T_STAR_PROPERTY : { STAR_PROPERTY prop = boost::get<STAR_PROPERTY>(p_Property); property = (ANY_STAR_PROPERTY)prop; } break;
case ANY_PROPERTY_TYPE::T_STAR_1_PROPERTY : { STAR_1_PROPERTY prop = boost::get<STAR_1_PROPERTY>(p_Property); property = (ANY_STAR_PROPERTY)prop; } break;
case ANY_PROPERTY_TYPE::T_STAR_2_PROPERTY : { STAR_2_PROPERTY prop = boost::get<STAR_2_PROPERTY>(p_Property); property = (ANY_STAR_PROPERTY)prop; } break;
case ANY_PROPERTY_TYPE::T_SUPERNOVA_PROPERTY: { SUPERNOVA_PROPERTY prop = boost::get<SUPERNOVA_PROPERTY>(p_Property); property = (ANY_STAR_PROPERTY)prop; } break;
case ANY_PROPERTY_TYPE::T_COMPANION_PROPERTY: { COMPANION_PROPERTY prop = boost::get<COMPANION_PROPERTY>(p_Property); property = (ANY_STAR_PROPERTY)prop; } break;
default: // unexpected stellar property type
// the only ways this can happen are if someone added a stellar type property (into ANY_PROPERTY_TYPE)
// and it isn't accounted for in this code, or if there is a defect in the code that causes
// this function to be called with a bad parameter. We should not default here, with or without a
// warning - this is a code defect, so we flag it as an error and that will result in termination of
// the evolution of the star or binary.
// The correct fix for this is to add code for the missing property type or find and fix the code defect.
THROW_ERROR(ERROR::UNEXPECTED_STELLAR_PROPERTY_TYPE); // throw error
}
switch (property) {
case ANY_STAR_PROPERTY::AGE: value = Age(); break;
case ANY_STAR_PROPERTY::ANGULAR_MOMENTUM: value = AngularMomentum(); break;
case ANY_STAR_PROPERTY::BINDING_ENERGY_FIXED: value = CalculateBindingEnergy(OPTIONS->CommonEnvelopeLambda()); break;
case ANY_STAR_PROPERTY::BINDING_ENERGY_NANJING: value = CalculateBindingEnergy(CalculateLambdaNanjing()); break;
case ANY_STAR_PROPERTY::BINDING_ENERGY_LOVERIDGE: value = CalculateBindingEnergy(CalculateLambdaLoveridge()); break;
case ANY_STAR_PROPERTY::BINDING_ENERGY_LOVERIDGE_WINDS: value = CalculateBindingEnergy(CalculateLambdaLoveridge(m_Mass - m_CoreMass, true)); break;
case ANY_STAR_PROPERTY::BINDING_ENERGY_KRUCKOW: value = CalculateBindingEnergy(CalculateLambdaKruckow()); break;
case ANY_STAR_PROPERTY::BINDING_ENERGY_CONVECTIVE_ENVELOPE: value = CalculateConvectiveEnvelopeBindingEnergy(CalculateConvectiveEnvelopeLambdaPicker(CalculateConvectiveEnvelopeMass())); break;
case ANY_STAR_PROPERTY::CHEMICALLY_HOMOGENEOUS_MAIN_SEQUENCE: value = CHonMS(); break;
case ANY_STAR_PROPERTY::CO_CORE_MASS: value = COCoreMass(); break;
case ANY_STAR_PROPERTY::CO_CORE_MASS_AT_COMPACT_OBJECT_FORMATION: value = SN_COCoreMassAtCOFormation(); break;
case ANY_STAR_PROPERTY::CONVECTIVE_ENV_MASS: std::tie(value, std::ignore) = CalculateConvectiveEnvelopeMass(); break;
case ANY_STAR_PROPERTY::CORE_MASS: value = CoreMass(); break;
case ANY_STAR_PROPERTY::CORE_MASS_AT_COMPACT_OBJECT_FORMATION: value = SN_CoreMassAtCOFormation(); break;
case ANY_STAR_PROPERTY::CORE_RADIUS_AT_COMPACT_OBJECT_FORMATION: value = SN_CoreRadiusAtCOFormation(); break;
case ANY_STAR_PROPERTY::DRAWN_KICK_MAGNITUDE: value = SN_DrawnKickMagnitude(); break;
case ANY_STAR_PROPERTY::DOMINANT_MASS_LOSS_RATE: value = DominantMassLossRate(); break;
case ANY_STAR_PROPERTY::DT: value = Dt(); break;
case ANY_STAR_PROPERTY::DYNAMICAL_TIMESCALE: value = CalculateDynamicalTimescale(); break;
case ANY_STAR_PROPERTY::ECCENTRIC_ANOMALY: value = SN_EccentricAnomaly(); break;
case ANY_STAR_PROPERTY::ENV_MASS: value = Mass() - CoreMass(); break;
case ANY_STAR_PROPERTY::ERROR: value = Error(); break;
case ANY_STAR_PROPERTY::EVOL_STATUS: value = EvolutionStatus(); break;
case ANY_STAR_PROPERTY::EXPERIENCED_AIC: value = ExperiencedAIC(); break;
case ANY_STAR_PROPERTY::EXPERIENCED_HeSD: value = ExperiencedHeSD(); break;
case ANY_STAR_PROPERTY::EXPERIENCED_CCSN: value = ExperiencedCCSN(); break;
case ANY_STAR_PROPERTY::EXPERIENCED_ECSN: value = ExperiencedECSN(); break;
case ANY_STAR_PROPERTY::EXPERIENCED_PISN: value = ExperiencedPISN(); break;
case ANY_STAR_PROPERTY::EXPERIENCED_PPISN: value = ExperiencedPPISN(); break;
case ANY_STAR_PROPERTY::EXPERIENCED_SNIA: value = ExperiencedSNIA(); break;
case ANY_STAR_PROPERTY::EXPERIENCED_SN_TYPE: value = ExperiencedSN_Type(); break;
case ANY_STAR_PROPERTY::EXPERIENCED_USSN: value = ExperiencedUSSN(); break;
case ANY_STAR_PROPERTY::FALLBACK_FRACTION: value = SN_FallbackFraction(); break;
case ANY_STAR_PROPERTY::MASS_TRANSFER_DONOR_HISTORY: value = GetMassTransferDonorHistoryString(); break;
case ANY_STAR_PROPERTY::HE_CORE_MASS: value = HeCoreMass(); break;
case ANY_STAR_PROPERTY::HE_CORE_MASS_AT_COMPACT_OBJECT_FORMATION: value = SN_HeCoreMassAtCOFormation(); break;
case ANY_STAR_PROPERTY::HELIUM_ABUNDANCE_CORE: value = HeliumAbundanceCore(); break;
case ANY_STAR_PROPERTY::HELIUM_ABUNDANCE_SURFACE: value = HeliumAbundanceSurface(); break;
case ANY_STAR_PROPERTY::HYDROGEN_ABUNDANCE_CORE: value = HydrogenAbundanceCore(); break;
case ANY_STAR_PROPERTY::HYDROGEN_ABUNDANCE_SURFACE: value = HydrogenAbundanceSurface(); break;
case ANY_STAR_PROPERTY::IS_HYDROGEN_POOR: value = SN_IsHydrogenPoor(); break;
case ANY_STAR_PROPERTY::ID: value = ObjectId(); break;
case ANY_STAR_PROPERTY::INITIAL_HELIUM_ABUNDANCE: value = CalculateInitialHeliumAbundance(); break;
case ANY_STAR_PROPERTY::INITIAL_HYDROGEN_ABUNDANCE: value = CalculateInitialHydrogenAbundance(); break;
case ANY_STAR_PROPERTY::INITIAL_STELLAR_TYPE: value = InitialStellarType(); break;
case ANY_STAR_PROPERTY::INITIAL_STELLAR_TYPE_NAME: value = STELLAR_TYPE_LABEL.at(InitialStellarType()); break;
case ANY_STAR_PROPERTY::IS_AIC: value = IsAIC(); break;
case ANY_STAR_PROPERTY::IS_CCSN: value = IsCCSN(); break;
case ANY_STAR_PROPERTY::IS_HeSD: value = IsHeSD(); break;
case ANY_STAR_PROPERTY::IS_ECSN: value = IsECSN(); break;
case ANY_STAR_PROPERTY::IS_PISN: value = IsPISN(); break;
case ANY_STAR_PROPERTY::IS_PPISN: value = IsPPISN(); break;
case ANY_STAR_PROPERTY::IS_SNIA: value = IsSNIA(); break;
case ANY_STAR_PROPERTY::IS_USSN: value = IsUSSN(); break;
case ANY_STAR_PROPERTY::KICK_MAGNITUDE: value = SN_KickMagnitude(); break;
case ANY_STAR_PROPERTY::LAMBDA_CONVECTIVE_ENVELOPE: value = CalculateConvectiveEnvelopeLambdaPicker(CalculateConvectiveEnvelopeMass()); break;
case ANY_STAR_PROPERTY::LAMBDA_DEWI: value = CalculateLambdaDewi(); break;
case ANY_STAR_PROPERTY::LAMBDA_FIXED: value = OPTIONS->CommonEnvelopeLambda(); break;
case ANY_STAR_PROPERTY::LAMBDA_KRUCKOW: value = CalculateLambdaKruckow(); break;
case ANY_STAR_PROPERTY::LAMBDA_KRUCKOW_BOTTOM: value = CalculateLambdaKruckow(m_Radius, -1.0); break;
case ANY_STAR_PROPERTY::LAMBDA_KRUCKOW_MIDDLE: value = CalculateLambdaKruckow(m_Radius, -4.0 / 5.0); break;
case ANY_STAR_PROPERTY::LAMBDA_KRUCKOW_TOP: value = CalculateLambdaKruckow(m_Radius, -2.0 / 3.0); break;
case ANY_STAR_PROPERTY::LAMBDA_LOVERIDGE: value = CalculateLambdaLoveridge(m_Mass - m_CoreMass, false); break;
case ANY_STAR_PROPERTY::LAMBDA_LOVERIDGE_WINDS: value = CalculateLambdaLoveridge(m_Mass - m_CoreMass, true); break;
case ANY_STAR_PROPERTY::LAMBDA_NANJING: value = CalculateLambdaNanjing(); break;
case ANY_STAR_PROPERTY::LBV_PHASE_FLAG: value = LBV_PhaseFlag(); break;
case ANY_STAR_PROPERTY::LUMINOSITY: value = Luminosity(); break;
case ANY_STAR_PROPERTY::MASS: value = Mass(); break;
case ANY_STAR_PROPERTY::MASS_0: value = Mass0(); break;
case ANY_STAR_PROPERTY::MDOT: value = Mdot(); break;
case ANY_STAR_PROPERTY::MEAN_ANOMALY: value = SN_MeanAnomaly(); break;
case ANY_STAR_PROPERTY::METALLICITY: value = Metallicity(); break;
case ANY_STAR_PROPERTY::MOMENT_OF_INERTIA: value = CalculateMomentOfInertia(); break;
case ANY_STAR_PROPERTY::MZAMS: value = MZAMS(); break;
case ANY_STAR_PROPERTY::OMEGA: value = Omega() / SECONDS_IN_YEAR; break;
case ANY_STAR_PROPERTY::OMEGA_BREAK: value = OmegaBreak() / SECONDS_IN_YEAR; break;
case ANY_STAR_PROPERTY::OMEGA_ZAMS: value = OmegaZAMS() / SECONDS_IN_YEAR; break;
case ANY_STAR_PROPERTY::PULSAR_MAGNETIC_FIELD: value = PulsarMagneticField(); break;
case ANY_STAR_PROPERTY::PULSAR_SPIN_DOWN_RATE: value = PulsarSpinDownRate(); break;
case ANY_STAR_PROPERTY::PULSAR_SPIN_FREQUENCY: value = PulsarSpinFrequency(); break;
case ANY_STAR_PROPERTY::PULSAR_SPIN_PERIOD: value = PulsarSpinPeriod(); break;
case ANY_STAR_PROPERTY::PULSAR_BIRTH_PERIOD: value = PulsarBirthPeriod(); break;
case ANY_STAR_PROPERTY::PULSAR_BIRTH_SPIN_DOWN_RATE: value = PulsarBirthSpinDownRate(); break;
case ANY_STAR_PROPERTY::RADIAL_EXPANSION_TIMESCALE: value = CalculateRadialExpansionTimescale(); break;
case ANY_STAR_PROPERTY::RADIUS: value = Radius(); break;
case ANY_STAR_PROPERTY::RANDOM_SEED: value = RandomSeed(); break;
case ANY_STAR_PROPERTY::ROCKET_KICK_MAGNITUDE: value = SN_RocketKickMagnitude(); break;
case ANY_STAR_PROPERTY::ROCKET_KICK_PHI: value = SN_RocketKickPhi(); break;
case ANY_STAR_PROPERTY::ROCKET_KICK_THETA: value = SN_RocketKickTheta(); break;
case ANY_STAR_PROPERTY::RZAMS: value = RZAMS(); break;
case ANY_STAR_PROPERTY::SN_TYPE: value = SN_Type(); break;
case ANY_STAR_PROPERTY::SPEED: value = Speed(); break;
case ANY_STAR_PROPERTY::STELLAR_TYPE: value = StellarType(); break;
case ANY_STAR_PROPERTY::STELLAR_TYPE_NAME: value = STELLAR_TYPE_LABEL.at(StellarType()); break;
case ANY_STAR_PROPERTY::STELLAR_TYPE_PREV: value = StellarTypePrev(); break;
case ANY_STAR_PROPERTY::STELLAR_TYPE_PREV_NAME: value = STELLAR_TYPE_LABEL.at(StellarTypePrev()); break;
case ANY_STAR_PROPERTY::SUPERNOVA_KICK_MAGNITUDE_RANDOM_NUMBER: value = SN_KickMagnitudeRandom(); break;
case ANY_STAR_PROPERTY::SUPERNOVA_PHI: value = SN_Phi(); break;
case ANY_STAR_PROPERTY::SUPERNOVA_THETA: value = SN_Theta(); break;
case ANY_STAR_PROPERTY::TEMPERATURE: value = Temperature() * TSOL; break;
case ANY_STAR_PROPERTY::THERMAL_TIMESCALE: value = CalculateThermalTimescale(); break;
case ANY_STAR_PROPERTY::TIME: value = Time(); break;
case ANY_STAR_PROPERTY::TIMESCALE_MS: value = Timescale(TIMESCALE::tMS); break;
case ANY_STAR_PROPERTY::TOTAL_MASS_AT_COMPACT_OBJECT_FORMATION: value = SN_TotalMassAtCOFormation(); break;
case ANY_STAR_PROPERTY::TOTAL_RADIUS_AT_COMPACT_OBJECT_FORMATION: value = SN_TotalRadiusAtCOFormation(); break;
case ANY_STAR_PROPERTY::TRUE_ANOMALY: value = SN_TrueAnomaly(); break;
case ANY_STAR_PROPERTY::TZAMS: value = TZAMS() * TSOL; break;
case ANY_STAR_PROPERTY::VELOCITY_X: value = VelocityX(); break;
case ANY_STAR_PROPERTY::VELOCITY_Y: value = VelocityY(); break;
case ANY_STAR_PROPERTY::VELOCITY_Z: value = VelocityZ(); break;
case ANY_STAR_PROPERTY::ZETA_HURLEY: value = CalculateZetaAdiabaticHurley2002(m_CoreMass); break;
case ANY_STAR_PROPERTY::ZETA_HURLEY_HE: value = CalculateZetaAdiabaticHurley2002(m_HeCoreMass); break;
case ANY_STAR_PROPERTY::ZETA_SOBERMAN: value = CalculateZetaAdiabaticSPH(m_CoreMass); break;
case ANY_STAR_PROPERTY::ZETA_SOBERMAN_HE: value = CalculateZetaAdiabaticSPH(m_HeCoreMass); break;
default: // unexpected stellar property
// the only ways this can happen are if someone added a stellar property (into ANY_STAR_PROPERTY),
// or allowed users to specify a stellar property (via the logfile definitions file), and it isn't
// accounted for in this code. We should not default here, with or without a warning - this is a
// code defect, so we flag it as an error and that will result in termination of the evolution of
// the star or binary.
// The correct fix for this is to add code for the missing property, or prevent it from being
// specified in the logfile definitions file.
THROW_ERROR(ERROR::UNEXPECTED_STELLAR_PROPERTY); // throw error
}
return value;
}
/*
* Determine the value of the requested property of the star (parameter p_Property)
*
* The property is a boost variant variable, and is one of the following types:
*
* STAR_PROPERTY - any individual star property
* STAR_1_PROPERTY - property of the primary (m_Star1)
* STAR_2_PROPERTY - property of the secondary (m_Star2)
* SUPERNOVA_PROPERTY - property of the star that has gone supernova
* COMPANION_PROPERTY - property of the companion to the supernova
* BINARY_PROPERTY - property of the binary
* PROGRAM_OPTION - program option
*
* This function calls the appropriate helper function to retrieve the value.
*
* This function handles properties of type:
*
* STAR_PROPERTY, PROGRAM_OPTION
*
* only - anything else will result in an error being thrown and the evolution of the star (or binary)
* terminated.
*
* This is the function used to retrieve values for properties required to be printed.
* This allows the composition of the log records to be dynamically modified - this is
* how we allow users to specify what properties they want recorded in log files.
*
* The functional return is the value of the property requested.
*
*
* COMPAS_VARIABLE PropertyValue(const T_ANY_PROPERTY p_Property) const
*
* @param [IN] p_Property The property for which the value is required
* @return The value of the requested property
*/
COMPAS_VARIABLE BaseStar::PropertyValue(const T_ANY_PROPERTY p_Property) const {
COMPAS_VARIABLE value = 0.0; // default property value
switch (boost::apply_visitor(VariantPropertyType(), p_Property)) { // which property type?
case ANY_PROPERTY_TYPE::T_STAR_PROPERTY: value = StellarPropertyValue(p_Property); break; // star property
case ANY_PROPERTY_TYPE::T_PROGRAM_OPTION: value = OPTIONS->OptionValue(p_Property); break; // program option
default: // unexpected property type
// the only ways this can happen are if someone added a stellar type property (into ANY_PROPERTY_TYPE)
// and it isn't accounted for in this code, or if there is a defect in the code that causes
// this function to be called with a bad parameter. We should not default here, with or without a
// warning - this is a code defect, so we flag it as an error and that will result in termination of
// the evolution of the star or binary.
// The correct fix for this is to add code for the missing property type or find and fix the code defect.
THROW_ERROR(ERROR::UNEXPECTED_STELLAR_PROPERTY_TYPE); // throw error
}
return value;
}
///////////////////////////////////////////////////////////////////////////////////////
// //
// COEFFICIENT AND CONSTANT CALCULATIONS ETC. //
// //
///////////////////////////////////////////////////////////////////////////////////////
/*
* Calculate a(n) coefficients
*
* a(n) coefficients depend on a star's metallicity only - so this only needs to be done once per star (upon creation)
*
* Vectors are passed by reference here for performance - preference would be to pass const& and
* pass modified value back by functional return, but this way is faster. This function isn't
* called too often, but the pattern is the same for others that are called many, many times.
*
*
* void CalculateAnCoefficients(DBL_VECTOR &p_AnCoefficients,
* DBL_VECTOR &p_LConstants,
* DBL_VECTOR &p_RConstants,
* DBL_VECTOR &p_GammaConstants)
*
* @param [IN/OUT] p_AnCoefficients a(n) coefficients - calculated here
* @param [IN/OUT] p_LConstants Luminosity constants - calculated here
* @param [IN/OUT] p_RConstants Radius constants - calculated here
* @param [IN/OUT] p_GammaConstants Gamma constants - calculated here
*/
void BaseStar::CalculateAnCoefficients(DBL_VECTOR &p_AnCoefficients,
DBL_VECTOR &p_LConstants,
DBL_VECTOR &p_RConstants,
DBL_VECTOR &p_GammaConstants) {
#define a p_AnCoefficients // for convenience and readability - undefined at end of function
#define index coeff.first // for convenience and readability - undefined at end of function
#define coeff(x) coeff.second[AB_TCoeff::x] // for convenience and readability - undefined at end of function
#define LConstants(x) p_LConstants[static_cast<int>(L_CONSTANTS::x)] // for convenience and readability - undefined at end of function
#define RConstants(x) p_RConstants[static_cast<int>(R_CONSTANTS::x)] // for convenience and readability - undefined at end of function
#define GammaConstants(x) p_GammaConstants[static_cast<int>(GAMMA_CONSTANTS::x)] // for convenience and readability - undefined at end of function
double Z = m_Metallicity;
double xi = LogMetallicityXiHurley();
double sigma = LogMetallicitySigma();
// pow() is slow - use multiplication
// do these calculations once only - and esp. outside the loop
double xi_2 = xi * xi;
double xi_3 = xi * xi_2;
double xi_4 = xi_2 * xi_2;
// calculate initial values for a(n) coefficients
a.push_back(0.0); // this is a dummy entry - so our index is the same as that in Hurley et al. 2000 (we just ignore the zeroeth entry)
for (auto coeff: A_COEFF) {
a.push_back(coeff(ALPHA) + (coeff(BETA) * xi) + (coeff(GAMMA) * xi_2) + (coeff(ETA) * xi_3) + (coeff(MU) * xi_4));
}
// Special cases - see Hurley et al. 2000
a[11] *= a[14];
a[12] *= a[14];
a[17] = PPOW(10.0, max((0.097 - (0.1072 * (sigma + 3.0))), max(0.097, min(0.1461, (0.1461 + (0.1237 * (sigma + 2.0)))))));
a[18] *= a[20];
a[19] *= a[20];
a[29] = PPOW(a[29], (a[32]));
a[33] = min(1.4, 1.5135 + (0.3769 * xi));
a[33] = max(0.6355 - (0.4192 * xi), max(1.25, a[33]));
a[42] = min(1.25, max(1.1, a[42]));
a[44] = min(1.3, max(0.45, a[44]));
a[49] = max(a[49], 0.145);
a[50] = min(a[50], (0.306 + (0.053 * xi)));
a[51] = min(a[51], (0.3625 + (0.062 * xi)));
a[52] = max(a[52], 0.9);
a[52] = (utils::Compare(Z, 0.01) > 0) ? min(a[52], 1.0) : a[52];
a[53] = max(a[53], 1.0);
a[53] = (utils::Compare(Z, 0.01) > 0) ? min(a[53], 1.1) : a[53];
a[57] = min(1.4, a[57]);
a[57] = max((0.6355 - (0.4192 * xi)), max(1.25, a[57]));
a[62] = max(0.065, a[62]);
a[63] = (utils::Compare(Z, 0.004) < 0) ? min(0.055, a[63]) : a[63];
a[66] = max(a[66], min(1.6, -0.308 - (1.046 * xi)));
a[66] = max(0.8, min(0.8 - (2.0 * xi), a[66]));
a[68] = max(0.9, min(a[68], 1.0));
// Need bAlphaR - calculate it now
RConstants(B_ALPHA_R) = (a[58] * PPOW(a[66], a[60])) / (a[59] + PPOW(a[66], a[61])); // Hurley et al. 2000, eq 21a (wrong in the arxiv version - says = a59*M**(a61))
// Continue special cases
a[64] = (utils::Compare(a[68], a[66]) > 0) ? RConstants(B_ALPHA_R) : max(0.091, min(0.121, a[64]));
a[68] = min(a[68], a[66]);
a[72] = (utils::Compare(Z, 0.01) > 0) ? max(a[72], 0.95) : a[72];
a[74] = max(1.4, min(a[74], 1.6));
a[75] = max(1.0, min(a[75], 1.27));
a[75] = max(a[75], 0.6355 - (0.4192 * xi));
a[76] = max(a[76], -0.1015564 - (0.2161264 * xi) - (0.05182516 * xi_2));
a[77] = max((-0.3868776 - (0.5457078 * xi) - (0.1463472 * xi_2)), min(0.0, a[77]));
a[78] = max(0.0, min(a[78], 7.454 + (9.046 * xi)));
a[79] = min(a[79], max(2.0, -13.3 - (18.6 * xi)));
a[80] = max(0.0585542, a[80]);
a[81] = min(1.5, max(0.4, a[81]));
LConstants(B_ALPHA_L) = (a[45] + (a[46] * PPOW(2.0, a[48]))) / (PPOW(2.0, 0.4) + (a[47] * PPOW(2.0, 1.9))); // Hurley et al. 2000, eq 19a
LConstants(B_BETA_L) = max(0.0, (a[54] - (a[55] * PPOW(a[57], a[56])))); // Hurley et al. 2000, eq 20
LConstants(B_DELTA_L) = min((a[34] / PPOW(a[33], a[35])), (a[36] / PPOW(a[33], a[37]))); // Hurley et al. 2000, eq 16
RConstants(C_ALPHA_R) = (a[58] * PPOW(a[67], a[60])) / (a[59] + PPOW(a[67], a[61])); // Hurley et al. 2000, eq 21a (wrong in the arxiv version)
RConstants(B_BETA_R) = (a[69] * 8.0 * M_SQRT2) / (a[70] + PPOW(2.0, a[71])); // Hurley et al. 2000, eq 22a
RConstants(C_BETA_R) = (a[69] * 16384.0) / (a[70] + PPOW(16.0, a[71])); // Hurley et al. 2000, eq 22a
RConstants(B_DELTA_R) = (a[38] + a[39] * 8.0 * M_SQRT2) / (a[40] * 8.0 + PPOW(2.0, a[41])) - 1.0; // Hurley et al. 2000, eq 17
GammaConstants(B_GAMMA) = max(0.0, a[76] + (a[77] * PPOW((1.0 - a[78]), a[79]))); // Hurley et al. 2000, eq 23 and discussion immediately following - max() confirmed in BSE Fortran code
GammaConstants(C_GAMMA) = (utils::Compare(a[75], 1.0) <= 0) ? GammaConstants(B_GAMMA) : a[80]; // Hurley et al. 2000, eq 23 and discussion immediately following - <= 1.0 confirmed in BSE Fortran code
#undef GammaConstants
#undef RConstants
#undef LConstants
#undef coeff
#undef index
#undef a
}
/*
* Calculate b(n) coefficients
*
* b(n) coefficients depend on a star's metallicity only - so this only needs to be done once per star (upon creation)
*
* Vectors are passed by reference here for performance - preference would be to pass const& and
* pass modified value back by functional return, but this way is faster. This function isn't
* called too often, but the pattern is the same for others that are called many, many times.
*
*
* void CalculateBnCoefficients(DBL_VECTOR &p_BnCoefficients)
*
* @param [IN/OUT] p_BnCoefficients b(n) coefficients - calculated here
*/
void BaseStar::CalculateBnCoefficients(DBL_VECTOR &p_BnCoefficients) {
#define b p_BnCoefficients // for convenience and readability - undefined at end of function
#define index coeff.first // for convenience and readability - undefined at end of function
#define coeff(x) coeff.second[AB_TCoeff::x] // for convenience and readability - undefined at end of function
#define massCutoffs(x) m_MassCutoffs[static_cast<int>(MASS_CUTOFF::x)] // for convenience and readability - undefined at end of function
double Z = m_Metallicity;
double xi = LogMetallicityXiHurley();
double sigma = LogMetallicitySigma();
double rho = LogMetallicityRho();
// pow() is slow - use multiplication
// do these calculations once only - and esp. outside the loop
double xi_2 = xi * xi;
double xi_3 = xi * xi_2;
double xi_4 = xi_2 * xi_2;
double xi_5 = xi * xi_4;
double rho_2 = rho * rho;
double rho_3 = rho * rho_2;
b.push_back(0.0); // this is a dummy entry for b(n) coefficients - so our index is the same as that in Hurley et al. 2000
for (auto coeff: B_COEFF) {
b.push_back(coeff(ALPHA) + (coeff(BETA) * xi) + (coeff(GAMMA) * xi_2) + (coeff(ETA) * xi_3) + (coeff(MU) * xi_4));
}
// Special Cases - see Hurley et al. 2000
b[1] = min(0.54, b[1]);
b[2] = PPOW(10.0, (-4.6739 - (0.9394 * sigma)));
b[2] = min(max(b[2], (-0.04167 + (55.67 * Z))), (0.4771 - (9329.21 * PPOW(Z, 2.94))));
b[3] = PPOW(10.0, max(-0.1451, (-2.2794 - (1.5175 * sigma) - (0.254 * sigma * sigma))));
b[3] = (utils::Compare(Z, 0.004) > 0) ? max(b[3], 0.7307 + (14265.1 * PPOW(Z, 3.395))) : b[3];
b[4] += 0.1231572 * xi_5;
b[6] += 0.01640687 * xi_5;
b[11] = b[11] * b[11];
b[13] = b[13] * b[13];
b[14] = PPOW(b[14], b[15]);
b[16] = PPOW(b[16], b[15]);
b[17] = (utils::Compare(xi, -1.0) > 0) ? 1.0 - (0.3880523 * PPOW((xi + 1.0), 2.862149)) : 1.0;
b[24] = PPOW(b[24], b[28]);
b[26] = 5.0 - (0.09138012 * PPOW(Z, -0.3671407));
b[27] = PPOW(b[27], (2.0 * b[28]));
b[31] = PPOW(b[31], b[33]);
b[34] = PPOW(b[34], b[33]);
b[36] = b[36] * b[36] * b[36] * b[36];
b[37] = 4.0 * b[37];
b[38] = b[38] * b[38] * b[38] * b[38];
b[40] = max(b[40], 1.0);
b[41] = PPOW(b[41], b[42]);
b[44] = b[44] * b[44] * b[44] * b[44] * b[44];
b[45] = utils::Compare(rho, 0.0) <= 0 ? 1.0 : 1.0 - ((2.47162 * rho) - (5.401682 * rho_2) + (3.247361 * rho_3));
b[46] = -1.0 * b[46] * log10(massCutoffs(MHeF) / massCutoffs(MFGB));
b[47] = (1.127733 * rho) + (0.2344416 * rho_2) - (0.3793726 * rho_3);
b[51] -= 0.1343798 * xi_5;
b[53] += 0.4426929 * xi_5;
b[55] = min((0.99164 - (743.123 * PPOW(Z, 2.83))), b[55]);
b[56] += 0.1140142 * xi_5;
b[57] -= 0.01308728 * xi_5;
#undef massCutoffs
#undef coeff
#undef index
#undef b
}
/*
* Calculate all alpha-like metallicity dependent luminosity coefficients
*
* Luminosity coefficients depend on a star's metallicity only - so this only needs to be done once per star (upon creation)
*
* Vectors are passed by reference here for performance - preference would be to pass const& and
* pass modified value back by functional return, but this way is faster. This function isn't
* called too often, but the pattern is the same for others that are called many, many times.
*
*
* void CalculateLCoefficients(const double p_LogMetallicityXi, DBL_VECTOR &p_LCoefficients)
*
* @param [IN] p_LogMetallicityXi log10(Metallicity / Zsol) - xi in Hurley et al. 2000
* @param [IN/OUT] p_LCoefficients Luminosity coefficients - calculated here
*/
void BaseStar::CalculateLCoefficients(const double p_LogMetallicityXi, DBL_VECTOR &p_LCoefficients) {
#define index coeff.first // for convenience and readability - undefined at end of function
#define coeff(x) coeff.second[LR_TCoeff::x] // for convenience and readability - undefined at end of function
// pow() is slow - use multiplication
// do these calculations once only - and esp. outside the loop
double xi = p_LogMetallicityXi;
double xi_2 = xi * xi;
double xi_3 = xi * xi_2;
double xi_4 = xi_2 * xi_2;
// iterate over Luminosity coefficients constants L_COEFF (see constants.h)
// These are from table 1 in Tout et al. 1996
// Each row (indexed by 'index') defines the coefficients of the 5 terms (coefficients 'a', 'b', 'c', 'd' & 'e')
for(auto coeff: L_COEFF) {
p_LCoefficients.push_back(coeff(a) + (coeff(b) * xi) + (coeff(c) * xi_2) + (coeff(d) * xi_3) + (coeff(e) * xi_4));
}
#undef coeff
#undef index
}
/*
* Calculate all alpha-like metallicity dependent radius coefficients
*
* Radius coefficients depend on a star's metallicity only - so this only needs to be done once per star (upon creation)
*
* Vectors are passed by reference here for performance - preference would be to pass const& and
* pass modified value back by functional return, but this way is faster. This function isn't
* called too often, but the pattern is the same for others that are called many, many times.
*
*
* void CalculateRCoefficients(const double p_LogMetallicityXi, DBL_VECTOR &p_RCoefficients)
*
* @param [IN] p_LogMetallicityXi log10(Metallicity / Zsol) - xi in Hurley et al. 2000
* @param [IN/OUT] p_LCoefficients Radius coefficients - calculated here
*/
void BaseStar::CalculateRCoefficients(const double p_LogMetallicityXi, DBL_VECTOR &p_RCoefficients) {
#define index coeff.first // for convenience and readability - undefined at end of function
#define coeff(x) coeff.second[LR_TCoeff::x] // for convenience and readability - undefined at end of function
// pow() is slow - use multiplication
// do these calculations once only - and esp. outside the loop
double xi = p_LogMetallicityXi;
double xi_2 = xi * xi;
double xi_3 = xi * xi_2;
double xi_4 = xi_2 * xi_2;
// iterate over Radius coefficients constants R_COEFF (see constants.h)
// These are from table 2 in Tout et al. 1996
// Each row (indexed by 'index') defines the coefficients of the 5 terms (coefficients 'a', 'b', 'c', 'd' & 'e')
for(auto coeff: R_COEFF) {
p_RCoefficients.push_back(coeff(a) + (coeff(b) * xi) + (coeff(c) * xi_2) + (coeff(d) * xi_3) + (coeff(e) * xi_4));
}
#undef coeff
#undef index
}
/*
* Calculate the constant alpha1
*
* Hurley et al, 2000, just after eq 49
*
* Alpha1 depends on a star's metallicity only - so this only needs to be done once per star (upon creation)
*
*
* double CalculateAlpha1()
*
* @return Metallicity dependent constant alpha1
*/
double BaseStar::CalculateAlpha1() const {
#define b m_BnCoefficients // for convenience and readability - undefined at end of function
#define massCutoffs(x) m_MassCutoffs[static_cast<int>(MASS_CUTOFF::x)] // for convenience and readability - undefined at end of function
double LHeI_MHeF = (b[11] + (b[12] * PPOW(massCutoffs(MHeF), 3.8))) / (b[13] + (massCutoffs(MHeF) * massCutoffs(MHeF)));
return ((b[9] * PPOW(massCutoffs(MHeF), b[10])) - LHeI_MHeF) / LHeI_MHeF;
#undef massCutoffs
#undef b
}
/*
* Calculate the constant alpha3
*
* Hurley et al. 2000, just after eq 56
*
* Alpha3 depends on a star's metallicity only - so this only needs to be done once per star (upon creation)
*
*
* double CalculateAlpha3()
*
* @return Metallicity dependent constant alpha3
*/
double BaseStar::CalculateAlpha3() const {
#define b m_BnCoefficients // for convenience and readability - undefined at end of function
#define massCutoffs(x) m_MassCutoffs[static_cast<int>(MASS_CUTOFF::x)] // for convenience and readability - undefined at end of function
double LBAGB = (b[31] + (b[32] * PPOW(massCutoffs(MHeF), (b[33] + 1.8)))) / (b[34] + PPOW(massCutoffs(MHeF), b[33]));
return ((b[29] * PPOW(massCutoffs(MHeF), b[30])) - LBAGB) / LBAGB;
#undef massCutoffs
#undef b
}
/*
* Calculate the constant alpha4
*
* Hurley et al. 2000, just after eq 57
*
* Alpha4 depends on a star's metallicity only - so this only needs to be done once per star (upon creation)
*
*
* double CalculateAlpha4()
*
* @return Metallicity dependent constant alpha4
*/
double BaseStar::CalculateAlpha4() const {
#define b m_BnCoefficients // for convenience and readability - undefined at end of function
#define massCutoffs(x) m_MassCutoffs[static_cast<int>(MASS_CUTOFF::x)] // for convenience and readability - undefined at end of function
double MHeF = massCutoffs(MHeF);
double MHeF_5 = MHeF * MHeF * MHeF * MHeF * MHeF; // pow() is slow - use multiplication
double tBGB_MHeF = CalculateLifetimeToBGB(MHeF); // tBGB for mass M = MHeF
double tHe_MHeF = tBGB_MHeF * (b[41] * PPOW(MHeF, b[42]) + b[43] * MHeF_5) / (b[44] + MHeF_5);
return ((tHe_MHeF - b[39]) / b[39]);
#undef massCutoffs
#undef b
}
///////////////////////////////////////////////////////////////////////////////////////
// //
// PARAMETERS, MISCELLANEOUS CALCULATIONS AND FUNCTIONS ETC. //
// //
///////////////////////////////////////////////////////////////////////////////////////
/*
* Calculate mass cutoffs:
*
* MHook: the metallicity dependent mass above which a hook appears on the MS
* MHeF : the metallicity dependent maximum initial mass for which He ignites degenerately in the He Flash
* MFGB : the metallicity dependent maximum mass at which He ignites degenerately on the First Giant Branch (FGB)
*
* Mass cutoffs depend on a star's metallicity only - so this only needs to be done once per star (upon creation)
*
* Vectors are passed by reference here for performance - preference would be to pass const& and
* pass modified value back by functional return, but this way is faster. This function isn't
* called too often, but the pattern is the same for others that are called many, many times.
*
*
* void CalculateMassCutoffs(const double p_Metallicity, const double p_LogMetallicityXi, DBL_VECTOR &p_MassCutoffs)
*
* @param [IN] p_Metallicity Metallicity Z (Z = 0.02 = Zsol)
* @param [IN] p_LogMetallicityXi log10(Metallicity / Zsol) - xi in Hurley et al. 2000
* @param [IN/OUT] p_MassCutoffs Mass cutoffs - calculated here
*/
void BaseStar::CalculateMassCutoffs(const double p_Metallicity, const double p_LogMetallicityXi, DBL_VECTOR &p_MassCutoffs) {
#define massCutoffs(x) p_MassCutoffs[static_cast<int>(MASS_CUTOFF::x)] // for convenience and readability - undefined at end of function
double xi_2 = p_LogMetallicityXi * p_LogMetallicityXi; // pow() is slow - use multiplication
massCutoffs(MHook) = 1.0185 + (0.16015 * p_LogMetallicityXi) + (0.0892 * xi_2); // MHook - Hurley et al. 2000, eq 1
massCutoffs(MHeF) = 1.995 + (0.25 * p_LogMetallicityXi) + (0.087 * xi_2); // MHeF - Hurley et al. 2000, eq 2
double top = 13.048 * PPOW((p_Metallicity / ZSOL_HURLEY), 0.06);
double bottom = 1.0 + (0.0012 * PPOW((ZSOL_HURLEY / p_Metallicity), 1.27));
massCutoffs(MFGB) = top / bottom; // MFGB - Hurley et al. 2000, eq 3
massCutoffs(MCHE) = 100.0; // MCHE - Mandel/Butler - CHE calculation
#undef massCutoffs
}
/*
* Calculate the parameter x for the Giant Branch
*
* X depends on a star's metallicity only - so this only needs to be done once per star (upon creation)
*
* Hybrid of b5 and b7 from Hurley et al. 2000
* Hurley et al. 2000, eq 47
*
*
* double CalculateGBRadiusXExponent()
*
* @return 'x' exponent to which Radius depends on Mass (at constant Luminosity)- 'x' in Hurley et al. 2000, eq 47
*/
double BaseStar::CalculateGBRadiusXExponent() const {
// pow()is slow - use multiplication
double xi = LogMetallicityXiHurley();
double xi_2 = xi * xi;
double xi_3 = xi_2 * xi;
double xi_4 = xi_2 * xi_2;
return 0.30406 + (0.0805 * xi) + (0.0897 * xi_2) + (0.0878 * xi_3) + (0.0222 * xi_4); // Hurley et al. 2000, eq 47
}
/*
* Calculate the perturbation parameter b
*
* Hurley et al. 2000, eq 103
*
*
* double CalculatePerturbationB(const double p_Mass)
*
* @param [IN] p_Mass Mass in Msol
* @return Perturbation parameter b
*/
double BaseStar::CalculatePerturbationB(const double p_Mass) const {
return 0.002 * max(1.0, (2.5 / p_Mass));
}
/*
* Calculate the perturbation parameter c
*
* Hurley et al. 2000, eq 104
*
*
* double CalculatePerturbationC(const double p_Mass)
*
* @param [IN] p_Mass Mass in Msol
* @return Perturbation parameter c
*/
double BaseStar::CalculatePerturbationC(double p_Mass) const {
return 0.006 * max(1.0, (2.5 / p_Mass));
}
/*
* Calculate the perturbation parameter s
*
* Hurley et al. 2000, eq 101
*
*
* double CalculatePerturbationS(const double p_Mass)
*
* @param [IN] p_Mu Perturbation parameter mu
* @param [IN] p_Mass Mass in Msol
* @return Perturbation parameter s
*/
double BaseStar::CalculatePerturbationS(const double p_Mu, const double p_Mass) const {
double b = CalculatePerturbationB(p_Mass);
double b_3 = b * b * b; // pow() is slow - use multiplication
double mu_b_3 = p_Mu * p_Mu * p_Mu / b_3; // calculate once, use many times...
return ((1.0 + b_3) * mu_b_3) / (1.0 + mu_b_3);
}
/*
* Calculate the perturbation parameter q
*
* Hurley et al. 2000, eq 105
*
*
* double CalculatePerturbationQ(const double p_Radius, const double p_Rc)
*
* @param [IN] p_Radius Radius in Rsol
* @param [IN] p_Rc Radius that the remnant would have if the star immediately lost its envelope (in Rsol)
* @return Perturbation parameter q
*/
double BaseStar::CalculatePerturbationQ(const double p_Radius, const double p_Rc) const {
return log(p_Radius / p_Rc); // really is natural log
}
/*
* Calculate the perturbation parameter r
*
* Hurley et al. 2000, eq 102
*
*
* double CalculatePerturbationR(const double p_Mu, const double p_Mass, const double p_Radius, const double p_Rc)
*
* @param [IN] p_Mu Perturbation parameter mu
* @param [IN] p_Mass Mass in Msol
* @param [IN] p_Radius Radius in Rsol
* @param [IN] p_Rc Radius that the remnant would have if the star immediately lost its envelope (in Rsol)
* @return Perturbation parameter r
*/
double BaseStar::CalculatePerturbationR(const double p_Mu, const double p_Mass, const double p_Radius, const double p_Rc) const {
double r = 0.0;
if (utils::Compare(p_Mu, 0.0) > 0 && utils::Compare(p_Radius, p_Rc) > 0) { // only if mu > 0 and radius is larger than core radius, otherwise r = 0 and perturbed radius = core radius
double c = CalculatePerturbationC(p_Mass);
double c_3 = c * c * c; // pow() is slow - use multiplication
double mu_c_3 = p_Mu * p_Mu * p_Mu / c_3; // calculate once
double q = CalculatePerturbationQ(p_Radius, p_Rc);
double exponent = min((0.1 / q), (-14.0 / log10(p_Mu))); // Hurley et al. 2000 is just 0.1 / q, but the Hurley sse code does this (`rpertf()` in `zfuncs.f`) - no explanation.
r = ((1.0 + c_3) * mu_c_3 * PPOW((p_Mu), exponent)) / ((1.0 + mu_c_3));
}
return r;
}