forked from VirtualPlanetaryLaboratory/vplanet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
body.c
1492 lines (1262 loc) · 43.9 KB
/
body.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
/**
@file body.c
@brief Relationships between parameters associated with individual bodies.
@author Rory Barnes ([RoryBarnes](https://github.com/RoryBarnes/))
@date May 7 2014
This file contains subroutines that describe physical properties of
any body. This includes conversions between the option parameter (a property
that may be used at input) and the system parameter (the property in the BODY
struct that is always up-to-date). If unsure between here and system.c, put
here. Also includes mathemtatical relationships.
*/
#include "vplanet.h"
/*
* Mathematical Relationships
*/
/**
Calculate the sign of a number
@param dValue The number whose sign is to be calculated
@param iSign The sign of the number
@return the sign (-1,0, or 1).
*/
int fiSign(double dValue) {
int iSign;
if (fabs(dValue) > EPS) { // EPS set in vplanet.h
iSign = (int)(dValue / fabs(dValue));
} else {
iSign = 0;
}
return iSign;
}
/**
Calcaulte the derivative of a period.
@param dRotRate The rotational frequency
@param dDrotrateDt The time derivative of the rotational frequency
@return The time derivative of the rotational frequency
*/
double fdDPerDt(double dRotRate, double dDrotrateDt) {
return -2 * PI * dDrotrateDt / (dRotRate * dRotRate);
}
/**
Caclulate the characteristic timescale for a variable to change that is
controlled by only 1 module.
@param dVar The value of the variable
@param dDeriv The value of the variable's time derivative
@return The timescale of the variable's change: |x/(dx/dt)|. If the
derivative is 0, return 0.
*/
double fdTimescale(double dVar, double dDeriv) {
if (dDeriv != 0) {
return fabs(dVar / dDeriv);
} else {
return 0;
}
}
/**
Caclulate the characteristic timescale for a variable to change that is
controlled by multiple processes.
@param dVar The value of the variable
@param dDeriv Array of the values of the variable's time derivatives
@param iNum The number of derivatives
@param dTime Dummy variable to keep track of the sum of the derivative
@param iPert Index of the perturbing process
@return The timescale of the variable's change: |x/Sum(dx/dt)|
*/
double fdTimescaleMulti(double dVar, double *dDeriv, int iNum) {
double dTime;
int iPert;
dTime = 0;
for (iPert = 0; iPert < iNum; iPert++) {
if (dDeriv[iPert] != 0) {
dTime += dDeriv[iPert]; // Note that here dTime is actullay the rate
}
dTime = fabs(dVar / dTime);
}
return dTime;
}
/**
Convert an angular frequency to a period
@param dFreq The frequency
@return The period
*/
double fdFreqToPer(double dFreq) {
return 2 * PI / dFreq;
}
/**
Convert a period to an angular frequency
@param dPeriod The period
@return The frequency
*/
double fdPerToFreq(double dPeriod) {
return 2 * PI / dPeriod;
}
/*
* Physical Relationships
*/
/**
Calculate a body's gravitational potential energy
@param dMass The body's mass
@param dRadius The body's radius
@return The body's potential energy
*/
double fdBodyPotEnergy(double dMass, double dRadius) {
/* ALPHA_STRUCT is structural constant for spherical mass distribution
potential energy (E_pot = -ALPHA*BIGG*M^2/R = 0.6), see vplanet.h. */
return -ALPHA_STRUCT * BIGG * dMass * dMass / dRadius;
}
/**
Calculate a body's rotational angular momentum
@param dRadGyra Body's radius of gyration
@param dMass Body's mass
@param dRad Body's radius
@param dOmega Body's rotational frequency
@return Body's rotational angular momentum
*/
double fdRotAngMom(double dRadGyra, double dMass, double dRad, double dOmega) {
return dRadGyra * dRadGyra * dMass * dRad * dRad * dOmega;
}
/**
Calculate a body's rotational kinetic energy
@param dMass Body's mass
@param dRadius Body's radius
@param dRadyGyra Body's radius of gyration
@param dOmega Body's rotational frequency
@return Body's rotational jinetic energy
*/
double fdRotKinEnergy(double dMass, double dRadius, double dRadGyra,
double dOmega) {
return 0.5 * dRadGyra * dRadGyra * dMass * dRadius * dRadius * dOmega *
dOmega;
}
/**
Convert a rotational frequency to a rotational velocity
@param dRadius Body's radius
@param dFreq Body's rotational frequency
@return Body's rotational velocity
*/
double fdRadiusFreqToRotVel(double dRadius, double dFreq) {
return dRadius * dFreq;
}
/**
Convert rotational velocity to rotational frequency
@param dRotVel Body's rotational velocity
@param dRadius Body's radius
@return Body's rotational frequency
*/
double fdRadiusRotVelToFreq(double dRotVel, double dRadius) {
return dRotVel / dRadius;
}
/**
Calculate radius from density and mass
@param dDensity Body's bulk density
@param dMass Body's mass
@return Body's Radius
*/
double fdDensityMassToRadius(double dDensity, double dMass) {
return pow((3 * dDensity / (4 * PI * dMass)), (1. / 3));
}
/**
Calculate Mass from Radius and density
@param dRadius Body's radius
@param dDensity Body's bulk density
@return Body's mass
*/
double fdMassFromRadiusDensity(double dRadius, double dDensity) {
return 4 * PI * pow(dRadius, 3) / (3 * dDensity);
}
/**
Calculate rotational velocity from radius and rotation frequency
@param dRadius Body's radius
@param dRotRate Body's rotational frequency
@return Body's rotational velocity
*/
double fdRotVel(double dRadius, double dRotRate) {
return dRadius * dRotRate;
}
/**
Calculate density for a uniform sphere
@param dMass Body's mass
@param Body's radius
@return Body's bulk density
*/
double fdSphereDensity(double dMass, double dRadius) {
double dDensity;
dDensity = 3 * dMass / (4 * PI * pow(dRadius, 3));
return dDensity;
}
/*
* Published Mass - Radius Relationships
*/
/**
Stellar mass-radius relationship from New Light on Dark Stars, Table 4.1.
See Barnes et al. (2013) Astrobiology 13:225-250.
@param dRadius Stellar radius
@param x Log base-10 of the stellar radius in solar units
@param y Log base-10 of the stellar mass in solar units
@return Stellar Mass
*/
double fdRadToMass_ReidHawley(double dRadius) {
double x, y;
x = log10(dRadius / RSUN);
y = 0.1277 + 2.185 * x + 3.135 * x * x + 1.9031 * x * x * x;
return pow(10, y) * MSUN;
}
/**
Stellar mass-radius relationship from New Light on Dark Stars, Table 4.1.
See Barnes et al. (2013) Astrobiology 13:225-250.
@param dMass Stellar mass
@param x Log base-10 of the stellar radius in solar units
@param y Log base-10 of the stellar mass in solar units
@return Stellar Radius
*/
double fdMassToRad_ReidHawley(double dMass) {
double x, y;
x = log10(dMass / MSUN);
y = 0.1424 + 1.568 * x - 0.2342 * x * x - 0.5581 * x * x * x;
return pow(10, y) * RSUN;
}
/**
Stellar mass-radius relationship from Gorda, S. Yu. & Svechnikov, M. A. 1999,
Astronomy Reports, 43, 521-525.
@param dMass Stellar Mass
@return Stellar radius
*/
double fdMassToRad_GordaSvech99(double dMass) {
dMass = log10(dMass / MSUN);
if (dMass > 0.14) {
return pow(10, (0.096 + 0.652 * log10(dMass))) * RSUN;
} else {
return pow(10, (0.1 + 1.03 * log10(dMass))) * RSUN;
}
}
/**
Stellar mass-radius relationship from Gorda, S. Yu. & Svechnikov, M. A. 1999,
Astronomy Reports, 43, 521-525. Reverse fit from Barnes et al. (2013)
Astrobiology 13:225-250.
@param dRadius Stellar Radius
@param x Log base-10 of the stellar radius in solar units
@param y Log base-10 of the stellar mass in solar units
@return Stellar mass
*/
double fdRadToMass_GordaSvech99(double dRadius) {
double x, y;
x = log10(dRadius / RSUN);
y = -0.09709 + 0.9709 * x - 2.502e-5 * x * x - 1.34e-5 * x * x * x;
return pow(10, y);
}
/**
Stellar mass-radius relationship from Bayless, A.J. & Orosz, J.A. 2006,
ApJ, 651, 1155-1165.
@param dMass Stellar Mass
@param dRadius Stellar radius is solar units
@return Stellar radius
*/
double fdMassToRad_BaylessOrosz06(double dMass) {
double dRadius;
dMass = dMass / MSUN;
dRadius = 0.0324 + 0.9343 * dMass + 0.0374 * dMass * dMass;
return dRadius * RSUN;
}
/**
Stellar mass-radius relationship from Bayless, A.J. & Orosz, J.A. 2006,
ApJ, 651, 1155-1165.
@param dRadius Stellar Radius
@param dMasss Stellar masss is solar units
@return Stellar masss
*/
double fdRadToMass_BaylessOrosz06(double dRadius) {
double dMass;
dRadius = dRadius / RSUN;
dMass = -0.03477 + 1.07146 * dRadius - 8.171 * dRadius * dRadius -
0.0412 * dRadius * dRadius * dRadius;
return dMass * MSUN;
}
/**
Terrestrial planet mass-radius relationship from Sotin et al 2007, Icarus,
191, 337-351.
@param dMass Planetary mass
@return Planetary radius
*/
double fdMassToRad_Sotin07(double dMass) {
return pow(dMass / MEARTH, 0.272) * REARTH;
}
double fdMassToRad_LehmerCatling17(double dMass) {
return 1.3 * pow(dMass, 0.27);
}
/**
Terrestrial planet mass-radius relationship from Sotin et al 2007, Icarus,
191, 337-351.
@param dRadius Planetary radius
@return Planetary mass
*/
double fdRadToMass_Sotin07(double dRadius) {
return pow(dRadius / REARTH, 3.6765) * MEARTH;
}
/**
Assign Radius based on mass and published relationship
@param dMass Body's mass
@param iRelation ID of mass-radius relationship to use
@return Body's radius as provided by appropriate relationship
*/
double fdMassToRad(double dMass, int iRelation) {
if (iRelation == REIDHAWLEY) {
return fdMassToRad_ReidHawley(dMass);
} else if (iRelation == GORDASVECH99) {
return fdMassToRad_GordaSvech99(dMass);
} else if (iRelation == BAYLESSOROSZ06) {
return fdMassToRad_BaylessOrosz06(dMass);
} else if (iRelation == SOTIN07) {
return fdMassToRad_Sotin07(dMass);
}
/* Need to add more! */
/* Whoops! */
fprintf(stderr, "ERROR: Unknown mass-radius relationship.\n");
fprintf(stderr, "Mass: %.3e, Relationship: %d\n", dMass, iRelation);
exit(EXIT_UNITS);
}
// Assign mass from radius and published relationship
double fdRadToMass(double dMass, int iRelation) {
if (iRelation == REIDHAWLEY) {
return fdRadToMass_ReidHawley(dMass);
} else if (iRelation == GORDASVECH99) {
return fdRadToMass_GordaSvech99(dMass);
} else if (iRelation == BAYLESSOROSZ06) {
return fdRadToMass_BaylessOrosz06(dMass);
} else if (iRelation == SOTIN07) {
return fdRadToMass_Sotin07(dMass);
} else {
/* Whoops! */
fprintf(stderr, "ERROR: Unknown mass-radius relation.\n");
exit(EXIT_UNITS);
}
}
/**
Copy the body struct from src to dest
@param dest Struct to receive the src
@param src Struct that contains original information
*/
void BodyCopy(BODY *dest, BODY *src, EVOLVE *evolve) {
int iBody, iModule;
/* This subroutine only includes parameters needed for more than 1 module,
Module-specific parameters belong in the fnBodyCopy subroutines. */
for (iBody = 0; iBody < evolve->iNumBodies; iBody++) {
strcpy(dest[iBody].cName, src[iBody].cName);
dest[iBody].iBodyType = src[iBody].iBodyType;
dest[iBody].dMass = src[iBody].dMass;
dest[iBody].dRadius = src[iBody].dRadius;
dest[iBody].dRadGyra = src[iBody].dRadGyra;
dest[iBody].dXobl = src[iBody].dXobl;
dest[iBody].dYobl = src[iBody].dYobl;
dest[iBody].dZobl = src[iBody].dZobl;
dest[iBody].dRotRate = src[iBody].dRotRate;
dest[iBody].dAge = src[iBody].dAge;
// iBody=0 could be in galhabit, so dEcc is overloaded
// If every run DistOrb w/GalHabit, there could be trouble
dest[iBody].dEcc = src[iBody].dEcc;
dest[iBody].dPrecA = src[iBody].dPrecA;
dest[iBody].dObliquity = src[iBody].dObliquity;
dest[iBody].dLostAngMom = src[iBody].dLostAngMom;
dest[iBody].dLostEng = src[iBody].dLostEng;
dest[iBody].dAlbedoGlobal = src[iBody].dAlbedoGlobal;
dest[iBody].bCalcDynEllip = src[iBody].bCalcDynEllip;
dest[iBody].bBinary = src[iBody].bBinary;
dest[iBody].bDistOrb = src[iBody].bDistOrb;
dest[iBody].bDistRot = src[iBody].bDistRot;
dest[iBody].bEqtide = src[iBody].bEqtide;
dest[iBody].bFlare = src[iBody].bFlare;
dest[iBody].bGalHabit = src[iBody].bGalHabit;
dest[iBody].bPoise = src[iBody].bPoise;
dest[iBody].bStellar = src[iBody].bStellar;
dest[iBody].bThermint = src[iBody].bThermint;
dest[iBody].bRadheat = src[iBody].bRadheat;
dest[iBody].bSpiNBody = src[iBody].bSpiNBody;
dest[iBody].bMantle = src[iBody].bMantle;
dest[iBody].bOcean = src[iBody].bOcean;
dest[iBody].bEnv = src[iBody].bEnv;
// dest[iBody].dLXUV = src[iBody].dLXUV;
// Im(k_2) properties
dest[iBody].dK2Man = src[iBody].dK2Man;
dest[iBody].dTidalQMan = src[iBody].dTidalQMan;
dest[iBody].dImK2Man = src[iBody].dImK2Man;
// These copies are needed to avoid floating point exceptions in
// (eqtide + !thermint) bodies
dest[iBody].dShmodUMan = src[iBody].dShmodUMan;
dest[iBody].dStiffness = src[iBody].dStiffness;
dest[iBody].dImK2ManOrbModel = src[iBody].dImK2ManOrbModel;
dest[iBody].bUseOuterTidalQ = src[iBody].bUseOuterTidalQ;
if (iBody > 0) {
dest[iBody].dHecc = src[iBody].dHecc;
dest[iBody].dKecc = src[iBody].dKecc;
dest[iBody].dSemi = src[iBody].dSemi;
dest[iBody].dRadius = src[iBody].dRadius;
dest[iBody].dMeanMotion = src[iBody].dMeanMotion;
}
/* Copy module-specific properties */
for (iModule = 0; iModule < evolve->iNumModules[iBody]; iModule++) {
evolve->fnBodyCopy[iBody][iModule](dest, src, evolve->iEqtideModel,
evolve->iNumBodies, iBody);
}
}
}
/**
Calculate rotational variables from obliquity and precession angle
@param body Body struct
@param iBody Index of the body struct for the body's whose rotational spins
is to be calculated.
*/
void CalcXYZobl(BODY *body, int iBody) {
body[iBody].dXobl = sin(body[iBody].dObliquity) * cos(body[iBody].dPrecA);
body[iBody].dYobl = sin(body[iBody].dObliquity) * sin(body[iBody].dPrecA);
body[iBody].dZobl = cos(body[iBody].dObliquity);
}
/**
Calculate equilibrium shape of planet using scaling laws and solar system
values. If the value is less then Venus', return Venus'.
@param body BODY struct
@param iBody Index of the body struct for the body's whose equilibrium shape
is to be calculated.
@param J2Earth Earth's current oblateness
@param J2Venus Venus' current oblateness
@param CEarth Earth's current moment of inertia?
@param nuEarth ???
@param EdEarth ???
@param dTmp ???
@param dDynEllip Dynamical ellipticity
@return Dynamical elliptiticy
*/
double CalcDynEllipEq(BODY *body, int iBody) {
double J2Earth = 1.08262668e-3, J2Venus = 4.56e-6, CEarth = 8.034e37;
double nuEarth, EdEarth, EdVenus, dTmp, dDynEllip, dJ2;
// EdEarth = J2Earth*MEARTH*pow(REARTH,2)/CEarth;
// EdVenus = J2Venus/0.336;
nuEarth = 2 * PI / (DAYSEC);
dJ2 = J2Earth * pow(body[iBody].dRotRate / nuEarth, 2) *
pow(body[iBody].dRadius / REARTH, 3) * MEARTH / body[iBody].dMass;
if (dJ2 < J2Venus) {
dJ2 = J2Venus;
}
dDynEllip = dJ2 / body[iBody].dSpecMomInertia;
// dTmp = EdEarth*MEARTH/(pow(nuEarth,2)*pow(REARTH,3));
//
// dDynEllip =
// dTmp*pow(body[iBody].dRotRate,2)*pow(body[iBody].dRadius,3)/body[iBody].dMass;
// if (dDynEllip < EdVenus)
// dDynEllip = EdVenus;
return dDynEllip;
}
/**
Lehmer+ (2017)'s model for the radius of a planet where it's losing its
atmopshere due to XUV radiation.
@param dMassEnv Envelope's mass
@param dGravAccel Body's gravitational acceleration
@param dRadSurf Surface Radius of rocky core
@param dScaleHeight Atmospheric scale height
@param dPresSurf pressure at surface due to envelope
@param dRadXUV radius from center of planet where optical depth of XUV is
unity
*/
double fdLehmerRadius(BODY *body, int iBody) {
double dRadXUV, dRoche;
dRadXUV = body[iBody].dRadSolid * body[iBody].dRadSolid /
(body[iBody].dScaleHeight *
log(body[iBody].dPresXUV / body[iBody].dPresSurf) +
body[iBody].dRadSolid);
dRoche = fdRocheRadius(body, iBody);
// printf("%lf %lf %lf %lf
// %lf\n",body[iBody].dPresXUV,body[iBody].dPresSurf,body[iBody].dGravAccel,body[iBody].dEnvelopeMass,dRadXUV);
if (dRadXUV <= 0) {
dRadXUV = dRoche;
}
if (dRadXUV > dRoche) {
dRadXUV = dRoche;
}
if (dRadXUV < body[iBody].dRadSolid) {
dRadXUV = body[iBody].dRadSolid;
}
if (body[iBody].dEnvelopeMass == 0) {
dRadXUV = body[iBody].dRadSolid;
}
return dRadXUV;
}
/**
Lehmer+ (2017)'s model for the pressure of a planet where it's losing its
atmopshere due to XUV radiation.
@param dMassEnv Envelope's mass
@param dGravAccel Body's gravitational acceleration
@param dRadSurf Surface Radius of rocky core
@param dPresXUV Pressure at base of thermosphere
@param dScaleHeight Atmospheric scale height
@param dPresSurf pressure at surface due to envelope
*/
double fdLehmerPres(double dMassEnv, double dGravAccel, double dRadSurf) {
double dPresSurf;
dPresSurf =
dGravAccel * dMassEnv / (4 * PI * dRadSurf * dRadSurf); // [kg/ms2]
// if (dPresSurf < 0)
// printf("%lf %lf %lf %lf\n",dGravAccel,dRadSurf,dMassEnv,dPresSurf);
return dPresSurf;
}
/**
Thermal temperature of an object heated by the radiation of its primary.
@param dFlux Incident flux on the body
@param dTemp Thermal temperature
*/
double fdThermalTemp(BODY *body, int iBody) {
double dFlux, dTemp;
dFlux = body[0].dLuminosity * (1 - body[iBody].dAlbedoGlobal) /
(4 * PI * body[iBody].dSemi * body[iBody].dSemi);
dTemp = pow(dFlux / SIGMA, 0.25);
return dTemp;
}
double fdImK2Total(BODY *body, int iBody) {
if (body[iBody].bUseOuterTidalQ) {
if (body[iBody].bEnv) {
return body[iBody].dImK2Env;
}
if (body[iBody].bOcean) {
return body[iBody].dImK2Ocean;
}
return body[iBody].dImK2Man;
}
if (body[iBody].bMantle || body[iBody].bOcean || body[iBody].bEnv) {
return body[iBody].dImK2Man + body[iBody].dImK2Ocean + body[iBody].dImK2Env;
} else {
return -body[iBody].dK2 / body[iBody].dTidalQ;
}
}
/**
Function compute upper mantle k2 Love number
@param body Body struct
@param iBody Index of body
@return Upper mantle k2 Love number
*/
double fdK2Man(BODY *body, int iBody) {
double dK2Man = 1.5 / (1 + 9.5 * body[iBody].dShmodUMan / body[iBody].dStiffness);
return dK2Man;
}
double fdTidalQMan(BODY *body, int iBody) {
double ShmodUManArr;
ShmodUManArr = body[iBody].dShmodUMan * body[iBody].dMeltfactorUMan;
double dTidalQMan = body[iBody].dDynamViscos * body[iBody].dMeanMotion /
body[iBody].dShmodUMan;
return dTidalQMan;
}
double fdImK2ManThermint(BODY *body, int iBody) {
double dDenom2 = pow(1.5 * body[iBody].dTidalQMan / body[iBody].dK2Man, 2.);
double imk2 = -(57. / 4) * body[iBody].dDynamViscos *
body[iBody].dMeanMotion /
((body[iBody].dStiffness) * (1.0 + dDenom2));
return imk2;
}
/**
Function compute upper mantle imaginary component of k2 Love number
@param body Body struct
@param iBody Index of body
@return Imaginary component of k2 Love number
*/
double fdImK2Man(BODY *body, int iBody) {
if (body[iBody].bThermint) {
body[iBody].dK2 = fdK2Man(body, iBody);
return fdImK2ManThermint(body, iBody);
} else {
return body[iBody].dImK2Man;
}
}
/** Calculate total k_2 and Im(k_2) for a body. This value depends on which
tidal model is called, and it the properties depend on the internal properties.
void AssignTidalProperties(BODY *body,EVOLVE *evolve,int iBody) {
if (body[iBody].bThermint) {
// The planet's tidal response depends on mantle properties
body[iBody].dK2=fdK2Man(body,iBody);
body[iBody].dImK2=fdImK2Man(body,iBody);
} else {
We're in a CPL/CTL type mode, and let's start building the total K2 and
ImK2 with the mantle. This should be sorted out in Verify.
body[iBody].dK2 = body[iBody].dK2Man;
body[iBody].dImK2 = body[iBody].dImK2Man;
}
// Include tidal dissapation due to oceans
if (body[iBody].bOceanTides) {
// weighted by the love number of each component
body[iBody].dK2 += body[iBody].dK2Ocean;
body[iBody].dImK2 += body[iBody].dImK2Ocean;
}
// Include tidal dissapation due to envelope
if (body[iBody].bEnvTides) {
// weighted by the love number of each component
body[iBody].dK2 += body[iBody].dK2Env;
body[iBody].dImK2 += body[iBody].dImK2Env;
}
// Sanity checks: enforce upper bound
if (body[iBody].dK2 > 1.5) {
body[iBody].dK2 = 1.5;
fprintf(stderr,"WARNING: body[%d].dK2 > 1.5 at time %.5e
years.\n",iBody,evolve->dTime/YEARSEC);
}
}
*/
/**
Function compute secular mantle heat flow: heat sinks - sources
@param body Body struct
@param iBody Index of body
@return Heat flow of secular mantle cooling
*/
double fdHflowSecMan(BODY *body, EVOLVE *evolve, int iBody) {
double dHflowSecMan = 0;
if (body[iBody].bThermint) {
dHflowSecMan += fdPowerThermint(body, iBody);
// dHflowSecMan += fdHflowSecManThermint(body,iBody);
}
if (body[iBody].bEqtide) {
// dHflowSecMan -= fdTidePower(body,iBody,evolve->iEqtideModel); // formerly
// dTidalPowerMan
dHflowSecMan -= body[iBody].dTidalPowMan;
}
// Should add RadHeat here
return dHflowSecMan;
}
/**
For use with `fdProximaCenStellar()` to interpolate stellar properties
(temperature, radius, luminosity) from a grid.
@param dVal Value of (temperature, radius, luminosity)
@param daArr Array of values from Yonsei-Yale tracks
@param iDim Length of array
@param iIndex Index of dArr correpoinding to the value
@return iIndex
*/
int fiGetLowerBoundProximaCen(double dVal, const double *daArr, int iDim) {
int iIndex;
for (iIndex = 0; iIndex < iDim - 2; iIndex++) {
if (dVal < daArr[iIndex + 1]) {
break;
}
}
return iIndex;
}
/**
For use with `fdProximaCenStellar()` to interpolate stellar properties
(temperature, radius, luminosity) from a grid. This function
linearly interpolates over data, given indices of lower bounds on grid xi, yi
and normalized distances to the interpolation point dx, dy.
What are these arguments?
*/
double fdProximaCenBiLinear(int iALEN, double const data_lo[PROXIMACEN_ALEN],
double const data_hi[PROXIMACEN_ALEN], int xi,
int yi, double dx, double dy) {
double C0, C1, C;
if (dx == 0) {
C0 = data_lo[xi];
C1 = data_hi[xi];
} else {
C0 = data_lo[xi] * (1 - dx) + data_lo[xi + 1] * dx;
C1 = data_hi[xi] * (1 - dx) + data_hi[xi + 1] * dx;
}
if (dy == 0) {
C = C0;
} else {
C = C0 * (1 - dy) + C1 * dy;
}
return C;
}
/**
For use with `fdProximaCenStellar()` to interpolate stellar properties
(temperature, radius, luminosity) from a grid.
What are these arguments?
*/
double fdProximaCenInterpolate(int iALEN, int iMLEN,
double const xarr[PROXIMACEN_ALEN],
double const yarr[PROXIMACEN_MLEN],
double const data_lo[PROXIMACEN_ALEN],
double const data_hi[PROXIMACEN_ALEN], double A,
double M, int *iError) {
double dx, dy;
int xi, yi;
int dxi, dyi;
double result = 0;
// Let's enforce a minimum age of 0.001 GYR and a maximum age of 10.0 GYR
// NOTE: This results in a constant luminosity at times beyond this range.
if (A < 0.001) {
A = 0.001;
}
if (A > 10.00) {
A = 10.00;
}
// Bounds on mass
if (M < 0.1) {
*iError = STELLAR_ERR_OUTOFBOUNDS_LO;
return 0;
} else if (M > 0.15) {
*iError = STELLAR_ERR_OUTOFBOUNDS_HI;
return 0;
}
// Get the lower bound
xi = fiGetLowerBoundProximaCen(log10(A), xarr, iALEN);
yi = fiGetLowerBoundProximaCen(M, yarr, iMLEN);
// Paranoia check (REMOVE)
if (yi < 0) {
*iError = STELLAR_ERR_OUTOFBOUNDS_LO;
return 0;
} else if (yi > 1) {
*iError = STELLAR_ERR_OUTOFBOUNDS_HI;
return 0;
}
// Normalized distance to grid points
dx = (log10(A) - xarr[xi]) / (xarr[xi + 1] - xarr[xi]);
dy = (M - yarr[yi]) / (yarr[yi + 1] - yarr[yi]);
// Calculate
result = fdProximaCenBiLinear(iALEN, data_lo, data_hi, xi, yi, dx, dy);
if (isnan(result)) {
*iError = PROXIMACEN_ERROR;
return 0;
}
*iError = 0;
return result;
}
/**
Computes the temperature, luminosity, or radius of Proxima Centauri
by interpolating from a grid. The isochrones are from the Y^2 website
http://www.astro.yale.edu/demarque/fs255_grid.tar.gz
with [Fe/H] = +0.3 track and mixing length parameter
alpha_MLT = 1.0. These were linearly interpolated between the 0.1 MSUN and
0.15 MSUN tracks to create luminosity, temperature, and radius
interpolants, which are functions of a single variable (the age).
The grid was then rectified and copied as constant arrays to `body.h`.
Note that in order to match the present-day luminosity (see below),
I had to fudge a bit. I ended up scaling the entire luminosity
track down by 15% to get it to match. I then re-computed the
temperature to be consistent with the radius. Now all three
quantities (L, R, and T) match within less than 1 sigma.
DATA FROM Boyajian+12; SECOND ROW FROM Demory+09 (direct measurements)
# Fe/H Radius Luminosity Teff Mass Lx/Lbol
# 0.19 0.1410 ± 0.0070 0.00155 ± 0.00002 3054 ± 79
0.118 2.83E−04 0.00165 ± 0.00015 3098 ± 56 0.123 ± 0.006
What are these arguments?
*/
double fdProximaCenStellar(int iParam, double A, double M, int *iError) {
double res;
double dLum, dRad;
if (iParam == PROXIMACEN_T) {
// Get fudged luminosity
dLum = fdProximaCenInterpolate(PROXIMACEN_ALEN, PROXIMACEN_MLEN,
PROXIMACEN_AARR, PROXIMACEN_MARR,
PROXIMACEN_LOGL_LO, PROXIMACEN_LOGL_HI,
A / (1.e9 * YEARSEC), M / MSUN, iError);
dLum = LSUN * pow(10., dLum * PROXIMACEN_FUDGE);
// Get radius
dRad = fdProximaCenInterpolate(PROXIMACEN_ALEN, PROXIMACEN_MLEN,
PROXIMACEN_AARR, PROXIMACEN_MARR,
PROXIMACEN_LOGR_LO, PROXIMACEN_LOGR_HI,
A / (1.e9 * YEARSEC), M / MSUN, iError);
dRad = RSUN * pow(10., dRad);
// Compute self-consistent temperature
res = pow(dLum / (4 * PI * dRad * dRad * SIGMA), 0.25);
return res;
} else if (iParam == PROXIMACEN_L) {
res = fdProximaCenInterpolate(PROXIMACEN_ALEN, PROXIMACEN_MLEN,
PROXIMACEN_AARR, PROXIMACEN_MARR,
PROXIMACEN_LOGL_LO, PROXIMACEN_LOGL_HI,
A / (1.e9 * YEARSEC), M / MSUN, iError);
return LSUN * pow(10., res * PROXIMACEN_FUDGE);
} else if (iParam == PROXIMACEN_R) {
res = fdProximaCenInterpolate(PROXIMACEN_ALEN, PROXIMACEN_MLEN,
PROXIMACEN_AARR, PROXIMACEN_MARR,
PROXIMACEN_LOGR_LO, PROXIMACEN_LOGR_HI,
A / (1.e9 * YEARSEC), M / MSUN, iError);
return RSUN * pow(10., res);
} else {
*iError = PROXIMACEN_ERROR;
return 0;
}
}
/**
For use with `fdProximaCenBRadius()` to interpolate the radius of
Proxima Cen b from a grid, assuming it has a gaseous composition
@param dVal Value of (temperature, radius, luminosity)
@param daArr Array of values from Yonsei-Yale tracks
@param iDim Length of array
@param iIndex Index of dArr correpoinding to the value
@return iIndex
*/
int fiGetLowerBoundProximaCenB(double dVal, const double *daArr, int iDim) {
int iIndex;
for (iIndex = 0; iIndex < iDim - 2; iIndex++) {
if (dVal < daArr[iIndex + 1]) {
break;
}
}
return iIndex;
}
/**
For use with `fdProximaCenBRadius()` to interpolate the radius of
Proxima Cen b from a grid, assuming it has a gaseous composition
What are the arguments?
*/
double fdProximaCenBLinear(int xi, int yi, double dx, double dy) {
// Linearly interpolate over data, given indices of lower bounds on grid xi,
// yi and normalized distances to the interpolation point dx, dy.
double C0, C1, C;
if (dx == 0) {
C0 = daProxCenBRadius[xi][yi];
C1 = daProxCenBRadius[xi][yi + 1];
} else {
C0 = daProxCenBRadius[xi][yi] * (1 - dx) +
daProxCenBRadius[xi + 1][yi] * dx;
C1 = daProxCenBRadius[xi][yi + 1] * (1 - dx) +
daProxCenBRadius[xi + 1][yi + 1] * dx;
}
if (dy == 0) {
C = C0;
} else {
C = C0 * (1 - dy) + C1 * dy;
}
return C;
}
/**
For use with `fdProximaCenBRadius()` to interpolate the radius of
Proxima Cen b from a grid, assuming it has a gaseous composition
Here I'm assuming a mass of 1.27 MEARTH and a solid body radius of 1.074 REARTH.
I'm using the Lopez+12 grids from Luger et al. (2015)
and smoothing over sharp (presumably) numerical features.
What are the arguments?
*/
double fdProximaCenBRadius(double C, double A, double M) {