forked from VirtualPlanetaryLaboratory/vplanet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
stellar.c
1811 lines (1593 loc) · 67 KB
/
stellar.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 stellar.c
@brief Subroutines that control the evolution of the star.
@author Rodrigo Luger ([[email protected]](mailto:[email protected]>))
@date May 12 2015
@par Description
\rst
This module implements the Baraffe stellar evolution tracks
:cite:`Baraffe15`, the Ribas XUV evolution model :cite:`Ribas05`,
and a simple wind/magnetic braking model.
\endrst
*/
#include "vplanet.h"
void BodyCopyStellar(BODY *dest, BODY *src, int foo, int iNumBodies,
int iBody) {
dest[iBody].dLuminosity = src[iBody].dLuminosity;
dest[iBody].dTemperature = src[iBody].dTemperature;
dest[iBody].dSatXUVFrac = src[iBody].dSatXUVFrac;
dest[iBody].dSatXUVTime = src[iBody].dSatXUVTime;
dest[iBody].dXUVBeta = src[iBody].dXUVBeta;
dest[iBody].iStellarModel = src[iBody].iStellarModel;
dest[iBody].iWindModel = src[iBody].iWindModel;
dest[iBody].iXUVModel = src[iBody].iXUVModel;
dest[iBody].iMagBrakingModel = src[iBody].iMagBrakingModel;
dest[iBody].dLXUV = src[iBody].dLXUV;
dest[iBody].bRossbyCut = src[iBody].bRossbyCut;
dest[iBody].bEvolveRG = src[iBody].bEvolveRG;
}
/**************** STELLAR options ********************/
void ReadSatXUVFrac(BODY *body, CONTROL *control, FILES *files,
OPTIONS *options, SYSTEM *system, int iFile) {
/* This parameter cannot exist in primary file */
int lTmp = -1;
double dTmp;
AddOptionDouble(files->Infile[iFile].cIn, options->cName, &dTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
if (dTmp < 0) {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr, "ERROR: %s must be greater than 0.\n", options->cName);
}
LineExit(files->Infile[iFile].cIn, lTmp);
}
body[iFile - 1].dSatXUVFrac = dTmp;
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else if (iFile > 0) {
body[iFile - 1].dSatXUVFrac = options->dDefault;
}
}
void ReadSatXUVTime(BODY *body, CONTROL *control, FILES *files,
OPTIONS *options, SYSTEM *system, int iFile) {
/* This parameter cannot exist in primary file */
int lTmp = -1;
double dTmp;
AddOptionDouble(files->Infile[iFile].cIn, options->cName, &dTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
if (dTmp < 0) {
body[iFile - 1].dSatXUVTime =
dTmp * dNegativeDouble(*options, files->Infile[iFile].cIn,
control->Io.iVerbose);
} else {
body[iFile - 1].dSatXUVTime =
dTmp * fdUnitsTime(control->Units[iFile].iTime);
}
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else if (iFile > 0) {
body[iFile - 1].dSatXUVTime = options->dDefault;
}
}
void ReadXUVBeta(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
SYSTEM *system, int iFile) {
/* This parameter cannot exist in primary file */
int lTmp = -1;
double dTmp;
AddOptionDouble(files->Infile[iFile].cIn, options->cName, &dTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
if (dTmp < 0) {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr, "ERROR: %s must be >= 0.\n", options->cName);
}
LineExit(files->Infile[iFile].cIn, lTmp);
}
body[iFile - 1].dXUVBeta = dTmp;
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else if (iFile > 0) {
body[iFile - 1].dXUVBeta = options->dDefault;
}
}
void ReadStellarModel(BODY *body, CONTROL *control, FILES *files,
OPTIONS *options, SYSTEM *system, int iFile) {
/* This parameter cannot exist in primary file */
int lTmp = -1;
char cTmp[OPTLEN];
AddOptionString(files->Infile[iFile].cIn, options->cName, cTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
if (!memcmp(sLower(cTmp), "ba", 2)) {
body[iFile - 1].iStellarModel = STELLAR_MODEL_BARAFFE;
} else if (!memcmp(sLower(cTmp), "no", 2)) {
body[iFile - 1].iStellarModel = STELLAR_MODEL_NONE;
} else if (!memcmp(sLower(cTmp), "pr", 2)) {
body[iFile - 1].iStellarModel = STELLAR_MODEL_PROXIMACEN;
} else {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr,
"ERROR: Unknown argument to %s: %s. Options are BARAFFE, "
"PROXIMACEN, or NONE.\n",
options->cName, cTmp);
}
LineExit(files->Infile[iFile].cIn, lTmp);
}
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else if (iFile > 0) {
body[iFile - 1].iStellarModel = STELLAR_MODEL_BARAFFE;
}
}
void ReadMagBrakingModel(BODY *body, CONTROL *control, FILES *files,
OPTIONS *options, SYSTEM *system, int iFile) {
/* This parameter cannot exist in primary file */
int lTmp = -1;
char cTmp[OPTLEN];
AddOptionString(files->Infile[iFile].cIn, options->cName, cTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
if (!memcmp(sLower(cTmp), "re", 2)) {
body[iFile - 1].iMagBrakingModel = STELLAR_DJDT_RM12;
} else if (!memcmp(sLower(cTmp), "no", 2)) {
body[iFile - 1].iMagBrakingModel = STELLAR_DJDT_NONE;
} else if (!memcmp(sLower(cTmp), "sk", 2)) {
body[iFile - 1].iMagBrakingModel = STELLAR_DJDT_SK72;
} else if (!memcmp(sLower(cTmp), "ma", 2)) {
body[iFile - 1].iMagBrakingModel = STELLAR_DJDT_MA15;
} else {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr,
"ERROR: Unknown argument to %s: %s. Options are REINERS, "
"SKUMANICH, MATT, or NONE.\n",
options->cName, cTmp);
}
LineExit(files->Infile[iFile].cIn, lTmp);
}
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else if (iFile > 0) {
body[iFile - 1].iMagBrakingModel =
STELLAR_DJDT_RM12; // Default to Reiners & Mohanty 2012 model
}
}
void ReadWindModel(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
SYSTEM *system, int iFile) {
/* This parameter cannot exist in primary file */
int lTmp = -1;
char cTmp[OPTLEN];
AddOptionString(files->Infile[iFile].cIn, options->cName, cTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
if (!memcmp(sLower(cTmp), "re", 2)) {
body[iFile - 1].iWindModel = STELLAR_MODEL_REINERS;
} else if (!memcmp(sLower(cTmp), "no", 2)) {
body[iFile - 1].iWindModel = STELLAR_MODEL_NONE;
} else {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr,
"ERROR: Unknown argument to %s: %s. Options are REINERS or "
"NONE.\n",
options->cName, cTmp);
}
LineExit(files->Infile[iFile].cIn, lTmp);
}
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else if (iFile > 0) {
body[iFile - 1].iWindModel = STELLAR_MODEL_REINERS;
}
}
void ReadXUVModel(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
SYSTEM *system, int iFile) {
/* This parameter cannot exist in primary file */
int lTmp = -1;
char cTmp[OPTLEN];
AddOptionString(files->Infile[iFile].cIn, options->cName, cTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
if (!memcmp(sLower(cTmp), "ri", 2)) {
body[iFile - 1].iXUVModel = STELLAR_MODEL_RIBAS;
} else if (!memcmp(sLower(cTmp), "no", 2)) {
body[iFile - 1].iXUVModel = STELLAR_MODEL_NONE;
} else if (!memcmp(sLower(cTmp), "re", 2)) {
if (control->Io.iVerbose >= VERBINPUT) {
fprintf(stderr, "WARNING: The REINERS XUV model has serious issues. "
"The recommended model is RIBAS.\n");
}
body[iFile - 1].iXUVModel = STELLAR_MODEL_REINERS;
} else {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr,
"ERROR: Unknown argument to %s: %s. Options are RIBAS, REINERS "
"or NONE.\n",
options->cName, cTmp);
}
LineExit(files->Infile[iFile].cIn, lTmp);
}
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else if (iFile > 0) {
body[iFile - 1].iXUVModel = STELLAR_MODEL_RIBAS;
}
}
void ReadHZModel(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
SYSTEM *system, int iFile) {
/* This parameter cannot exist in primary file */
int lTmp = -1;
char cTmp[OPTLEN];
AddOptionString(files->Infile[iFile].cIn, options->cName, cTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
if (!memcmp(sLower(cTmp), "k", 1)) {
body[iFile - 1].iXUVModel = HZ_MODEL_KOPPARAPU;
// We should add more!
} else {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr,
"ERROR: Unknown argument to %s: %s. Options are KOPPARAPU13.\n",
options->cName, cTmp);
}
LineExit(files->Infile[iFile].cIn, lTmp);
}
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else if (iFile > 0) {
body[iFile - 1].iHZModel = HZ_MODEL_KOPPARAPU;
}
}
void ReadRossbyCut(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
SYSTEM *system, int iFile) {
/* This parameter cannot exist in primary file */
int lTmp = -1;
int bTmp;
AddOptionBool(files->Infile[iFile].cIn, options->cName, &bTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
body[iFile - 1].bRossbyCut = bTmp;
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else {
if (iFile > 0) {
body[iFile - 1].bRossbyCut = 0; // Default to NOT using Rossby cut model
}
}
}
void ReadEvolveRG(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
SYSTEM *system, int iFile) {
/* This parameter cannot exist in primary file */
int lTmp = -1;
int bTmp;
AddOptionBool(files->Infile[iFile].cIn, options->cName, &bTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
body[iFile - 1].bEvolveRG = bTmp;
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else {
if (iFile > 0) {
body[iFile - 1].bEvolveRG = 1; // Default to evolve RG
}
}
}
/* Halts */
void ReadHaltEndBaraffeGrid(BODY *body, CONTROL *control, FILES *files,
OPTIONS *options, SYSTEM *system, int iFile) {
/* This parameter cannot exist in primary file */
int lTmp = -1;
int bTmp;
AddOptionBool(files->Infile[iFile].cIn, options->cName, &bTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
control->Halt[iFile - 1].bEndBaraffeGrid = bTmp;
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else {
if (iFile > 0) {
AssignDefaultInt(options, &control->Halt[iFile - 1].bEndBaraffeGrid,
files->iNumInputs);
}
}
}
void InitializeOptionsStellar(OPTIONS *options, fnReadOption fnRead[]) {
int iOpt, iFile;
sprintf(options[OPT_SATXUVFRAC].cName, "dSatXUVFrac");
sprintf(options[OPT_SATXUVFRAC].cDescr, "Saturated XUV luminosity fraction");
sprintf(options[OPT_SATXUVFRAC].cDefault, "1e-3");
sprintf(options[OPT_SATXUVFRAC].cDimension, "nd");
options[OPT_SATXUVFRAC].dDefault = 1.e-3;
options[OPT_SATXUVFRAC].iType = 2;
options[OPT_SATXUVFRAC].bMultiFile = 1;
fnRead[OPT_SATXUVFRAC] = &ReadSatXUVFrac;
sprintf(
options[OPT_SATXUVFRAC].cLongDescr,
"After formation stars emit a nearly constant amount of XUV radiation\n"
"for a time called the \"saturated\" phase. This parameter sets that "
"value\n"
"relative to the total (bolometric) luminosity. Must lie in range "
"[0,1].");
sprintf(options[OPT_SATXUVTIME].cName, "dSatXUVTime");
sprintf(options[OPT_SATXUVTIME].cDescr, "XUV saturation time");
sprintf(options[OPT_SATXUVTIME].cDefault, "0.1 Gyr");
sprintf(options[OPT_SATXUVTIME].cDimension, "time");
options[OPT_SATXUVTIME].dDefault = 1.e8 * YEARSEC;
options[OPT_SATXUVTIME].iType = 0;
options[OPT_SATXUVTIME].bMultiFile = 1;
options[OPT_SATXUVTIME].dNeg = 1e9 * YEARSEC;
sprintf(options[OPT_SATXUVTIME].cNeg, "Gyr");
fnRead[OPT_SATXUVTIME] = &ReadSatXUVTime;
sprintf(options[OPT_SATXUVTIME].cLongDescr,
"The time a star will remain in its \"saturated\" phase.");
sprintf(options[OPT_XUVBETA].cName, "dXUVBeta");
sprintf(options[OPT_XUVBETA].cDescr, "XUV decay power law exponent");
sprintf(options[OPT_XUVBETA].cDefault, "1.23");
sprintf(options[OPT_XUVBETA].cDimension, "nd");
options[OPT_XUVBETA].dDefault = 1.23;
options[OPT_XUVBETA].iType = 2;
options[OPT_XUVBETA].bMultiFile = 1;
fnRead[OPT_XUVBETA] = &ReadXUVBeta;
sprintf(options[OPT_XUVBETA].cLongDescr,
"After the \"saturation\" phase, the ratio of the XUV to total "
"luminosity\n"
"will follow a power law followinfg this exponent. Units are "
"gigayears.");
sprintf(options[OPT_STELLARMODEL].cName, "sStellarModel");
sprintf(options[OPT_STELLARMODEL].cDescr, "Luminosity evolution model");
sprintf(options[OPT_STELLARMODEL].cDefault, "BARAFFE");
sprintf(options[OPT_STELLARMODEL].cValues, "BARAFFE PROXIMA NONE");
options[OPT_STELLARMODEL].iType = 3;
options[OPT_STELLARMODEL].bMultiFile = 1;
fnRead[OPT_STELLARMODEL] = &ReadStellarModel;
sprintf(options[OPT_STELLARMODEL].cLongDescr,
"If BARAFFE is selected, luminosity, effective temperature, radius, "
"and\n"
"radius of gyration will follow the model of Baraffe, I. et al.\n"
"(2015, A&A, 577, 42). PROXIMA will employ the model from Barnes, R. "
"et al.\n"
"(2016, arXiv:1608.06919). NONE will leave them constant.\n");
sprintf(options[OPT_MAGBRAKINGMODEL].cName, "sMagBrakingModel");
sprintf(options[OPT_MAGBRAKINGMODEL].cDescr, "Magnetic braking model.");
sprintf(options[OPT_MAGBRAKINGMODEL].cDefault, "REINERS");
sprintf(options[OPT_MAGBRAKINGMODEL].cValues,
"REINERS, SKUMANICH, MATT, NONE");
options[OPT_MAGBRAKINGMODEL].iType = 3;
options[OPT_MAGBRAKINGMODEL].bMultiFile = 1;
fnRead[OPT_MAGBRAKINGMODEL] = &ReadMagBrakingModel;
sprintf(options[OPT_STELLARMODEL].cLongDescr,
"If REINERS is selected, the stellar magnetic braking model of\n"
"Reiners & Mohanty (2012, ApJ, 746, 43) is used to modify the "
"rotation rate.\n"
"SKUMANICH uses the model from Skumanich, A. (1972, ApJ, 171, 565).\n"
"MATT uses the model from Matt, S. et al. (2015, ApJ, 799, 23).\n"
"NONE applies no magnetic torque.\n");
sprintf(options[OPT_WINDMODEL].cName, "sWindModel");
sprintf(options[OPT_WINDMODEL].cDescr, "Wind Angular Momentum Loss Model");
sprintf(options[OPT_WINDMODEL].cDefault, "REINERS");
options[OPT_WINDMODEL].iType = 3;
options[OPT_WINDMODEL].bMultiFile = 1;
fnRead[OPT_WINDMODEL] = &ReadWindModel;
sprintf(options[OPT_WINDMODEL].cLongDescr,
"If REINERS is selected, the stellar wind model of Reiners and "
"Mohanty\n"
"(2012, ApJ, 746, 43) is used to modify the rotation rate.");
sprintf(options[OPT_XUVMODEL].cName, "sXUVModel");
sprintf(options[OPT_XUVMODEL].cDescr, "XUV Evolution Model");
sprintf(options[OPT_XUVMODEL].cDefault, "RIBAS");
sprintf(options[OPT_XUVMODEL].cValues, "RIBAS REINERS NONE");
options[OPT_XUVMODEL].iType = 3;
options[OPT_XUVMODEL].bMultiFile = 1;
options[OPT_XUVMODEL].iModuleBit = STELLAR;
fnRead[OPT_XUVMODEL] = &ReadXUVModel;
sprintf(
options[OPT_XUVMODEL].cLongDescr,
"This parameter sets the XUV evolution model used in STELLAR. Setting\n"
"this to RIBAS (default) will evolve the XUV luminosity according to \n"
"the saturated power law of Ribas et al (2005, ApJ, 611, 680),\n"
"while setting it to REINERS will use the empirical relations of\n"
"Reiners, Schussler and Passegger (2014, ApJ, 794, 144). Please note "
"that\n"
"the latter model has not been fully vetted. Users may also set this\n"
"parameter to NONE, in which case the XUV luminosity will remain "
"constant.");
sprintf(options[OPT_HZMODEL].cName, "sHZModel");
sprintf(options[OPT_HZMODEL].cDescr, "Habitable Zone Model: Kopparapu13");
sprintf(options[OPT_HZMODEL].cDefault, "Kopparapu13");
options[OPT_HZMODEL].iType = 3;
options[OPT_HZMODEL].bMultiFile = 1;
fnRead[OPT_HZMODEL] = &ReadHZModel;
sprintf(options[OPT_HZMODEL].cLongDescr,
"If KOPPARAPU13 is selected then the Recent Venus, Runaway "
"Greenhouse,\n"
"Maximum Greenhouse, and Early Mars habitable zone limits will be\n"
"calculated from Kopparapu, R. et al. (2013, ApJ, 765, 131).");
sprintf(options[OPT_HALTENDBARAFFEFGRID].cName, "bHaltEndBaraffeGrid");
sprintf(options[OPT_HALTENDBARAFFEFGRID].cDescr,
"Halt when we reach the end of the Baraffe+15 grid?");
sprintf(options[OPT_HALTENDBARAFFEFGRID].cDefault, "1");
options[OPT_HALTENDBARAFFEFGRID].iType = 0;
fnRead[OPT_HALTENDBARAFFEFGRID] = &ReadHaltEndBaraffeGrid;
sprintf(options[OPT_HALTENDBARAFFEFGRID].cLongDescr,
"The BARRAFFE stellar model will only compute parameters until the "
"end of\n"
"the main sequence. Setting this flag to 1 will halt the code if the "
"end\n"
"of the model grid is reached.");
sprintf(options[OPT_ROSSBYCUT].cName, "bRossbyCut");
sprintf(options[OPT_ROSSBYCUT].cDescr,
"Terminate magnetic braking when Rossby number > 2.08?");
sprintf(options[OPT_ROSSBYCUT].cDefault, "0"); // XXX Units?
options[OPT_ROSSBYCUT].iType = 0;
options[OPT_ROSSBYCUT].bMultiFile = 1;
options[OPT_ROSSBYCUT].iModuleBit = STELLAR;
fnRead[OPT_ROSSBYCUT] = &ReadRossbyCut;
sprintf(options[OPT_ROSSBYCUT].cLongDescr,
"Van Saders, J. et al. (2019, ApJ, 872, 128) find that when the "
"stellar\n"
"Rossby number exceeds 2.08, then the magnetic braking is quenched. "
"This\n"
"flag enforces that behavior.");
sprintf(options[OPT_EVOVLERG].cName, "bEvolveRG");
sprintf(options[OPT_EVOVLERG].cDescr, "Evolve stellar radius of gyration?");
sprintf(options[OPT_EVOVLERG].cDefault, "1");
options[OPT_EVOVLERG].iType = 0;
options[OPT_EVOVLERG].bMultiFile = 1;
options[OPT_EVOVLERG].iModuleBit = STELLAR;
fnRead[OPT_EVOVLERG] = &ReadEvolveRG;
sprintf(options[OPT_EVOVLERG].cLongDescr,
"Set this flag to 0 to ignore the role of mass concentration in "
"stellar\n"
"evolution. Only useful for testing purposes.");
}
void ReadOptionsStellar(BODY *body, CONTROL *control, FILES *files,
OPTIONS *options, SYSTEM *system, fnReadOption fnRead[],
int iBody) {
int iOpt;
for (iOpt = OPTSTARTSTELLAR; iOpt < OPTENDSTELLAR; iOpt++) {
if (options[iOpt].iType != -1) {
fnRead[iOpt](body, control, files, &options[iOpt], system, iBody + 1);
}
}
}
/******************* Verify STELLAR ******************/
void VerifyRotRate(BODY *body, CONTROL *control, OPTIONS *options,
UPDATE *update, double dAge, int iBody) {
update[iBody].iaType[update[iBody].iRot][update[iBody].iRotStellar] = 1;
update[iBody].iNumBodies[update[iBody].iRot][update[iBody].iRotStellar] = 1;
update[iBody].iaBody[update[iBody].iRot][update[iBody].iRotStellar] = malloc(
update[iBody]
.iNumBodies[update[iBody].iRot][update[iBody].iRotStellar] *
sizeof(int));
update[iBody].iaBody[update[iBody].iRot][update[iBody].iRotStellar][0] =
iBody;
update[iBody].pdRotRateStellar =
&update[iBody]
.daDerivProc[update[iBody].iRot][update[iBody].iRotStellar];
}
void VerifyLostAngMomStellar(BODY *body, CONTROL *control, OPTIONS *options,
UPDATE *update, double dAge, int iBody) {
update[iBody]
.iaType[update[iBody].iLostAngMom][update[iBody].iLostAngMomStellar] =
1;
update[iBody].iNumBodies[update[iBody].iLostAngMom]
[update[iBody].iLostAngMomStellar] = 1;
update[iBody]
.iaBody[update[iBody].iLostAngMom][update[iBody].iLostAngMomStellar] =
malloc(update[iBody].iNumBodies[update[iBody].iLostAngMom]
[update[iBody].iLostAngMomStellar] *
sizeof(int));
update[iBody].iaBody[update[iBody].iLostAngMom]
[update[iBody].iLostAngMomStellar][0] = iBody;
update[iBody].pdLostAngMomStellar =
&update[iBody].daDerivProc[update[iBody].iLostAngMom]
[update[iBody].iLostAngMomStellar];
}
void VerifyLostEngStellar(BODY *body, CONTROL *control, OPTIONS *options,
UPDATE *update, double dAge, int iBody) {
update[iBody].iaType[update[iBody].iLostEng][update[iBody].iLostEngStellar] =
5;
update[iBody]
.iNumBodies[update[iBody].iLostEng][update[iBody].iLostEngStellar] = 1;
update[iBody].iaBody[update[iBody].iLostEng][update[iBody].iLostEngStellar] =
malloc(update[iBody].iNumBodies[update[iBody].iLostEng]
[update[iBody].iLostEngStellar] *
sizeof(int));
update[iBody]
.iaBody[update[iBody].iLostEng][update[iBody].iLostEngStellar][0] =
iBody;
update[iBody].pdLostEngStellar =
&update[iBody].daDerivProc[update[iBody].iLostEng]
[update[iBody].iLostEngStellar];
}
void VerifyLuminosity(BODY *body, CONTROL *control, OPTIONS *options,
UPDATE *update, double dAge, int iBody) {
// Assign luminosity
if (body[iBody].iStellarModel == STELLAR_MODEL_BARAFFE) {
body[iBody].dLuminosity =
fdLuminosityFunctionBaraffe(body[iBody].dAge, body[iBody].dMass);
if (options[OPT_LUMINOSITY].iLine[iBody + 1] >= 0) {
// User specified luminosity, but we're reading it from the grid!
if (control->Io.iVerbose >= VERBINPUT) {
printf("INFO: Luminosity set for body %d, but this value will be "
"computed from the grid.\n",
iBody);
}
}
} else if (body[iBody].iStellarModel == STELLAR_MODEL_PROXIMACEN) {
body[iBody].dLuminosity =
fdLuminosityFunctionProximaCen(body[iBody].dAge, body[iBody].dMass);
if (options[OPT_LUMINOSITY].iLine[iBody + 1] >= 0) {
// User specified luminosity, but we're reading it from the grid!
if (control->Io.iVerbose >= VERBINPUT) {
printf("INFO: Luminosity set for body %d, but this value will be "
"computed from the grid.\n",
iBody);
}
}
} else if (body[iBody].iStellarModel == STELLAR_MODEL_NONE) {
if (options[OPT_LUMINOSITY].iLine[iBody + 1] == -1) {
// Luminosity must be input if sStellarModel is set to NONE
if (control->Io.iVerbose >= VERBINPUT) {
fprintf(stderr,
"ERROR: If STELLAR model NONE is selected, then %s must be "
"set.\n",
options[OPT_LUMINOSITY].cName);
exit(EXIT_INPUT);
}
}
}
update[iBody].iaType[update[iBody].iLuminosity][0] = 0;
update[iBody].iNumBodies[update[iBody].iLuminosity][0] = 1;
update[iBody].iaBody[update[iBody].iLuminosity][0] = malloc(
update[iBody].iNumBodies[update[iBody].iLuminosity][0] * sizeof(int));
update[iBody].iaBody[update[iBody].iLuminosity][0][0] = iBody;
update[iBody].pdLuminosityStellar =
&update[iBody].daDerivProc[update[iBody].iLuminosity]
[0]; // NOTE: This points to the VALUE of the
// luminosity
}
void VerifyRadius(BODY *body, CONTROL *control, OPTIONS *options,
UPDATE *update, double dAge, int iBody) {
// Assign radius
if (body[iBody].iStellarModel == STELLAR_MODEL_BARAFFE) {
body[iBody].dRadius =
fdRadiusFunctionBaraffe(body[iBody].dAge, body[iBody].dMass);
if (options[OPT_RADIUS].iLine[iBody + 1] >= 0) {
// User specified radius, but we're reading it from the grid!
if (control->Io.iVerbose >= VERBINPUT) {
printf("INFO: Radius set for body %d, but this value will be computed "
"from the grid.\n",
iBody);
}
}
} else if (body[iBody].iStellarModel == STELLAR_MODEL_PROXIMACEN) {
body[iBody].dRadius =
fdRadiusFunctionProximaCen(body[iBody].dAge, body[iBody].dMass);
if (options[OPT_RADIUS].iLine[iBody + 1] >= 0) {
// User specified radius, but we're reading it from the grid!
if (control->Io.iVerbose >= VERBINPUT) {
printf("INFO: Radius set for body %d, but this value will be computed "
"from the grid.\n",
iBody);
}
}
}
update[iBody].iaType[update[iBody].iRadius][0] = 0;
update[iBody].iNumBodies[update[iBody].iRadius][0] = 1;
update[iBody].iaBody[update[iBody].iRadius][0] = malloc(
update[iBody].iNumBodies[update[iBody].iRadius][0] * sizeof(int));
update[iBody].iaBody[update[iBody].iRadius][0][0] = iBody;
update[iBody].pdRadiusStellar =
&update[iBody]
.daDerivProc[update[iBody].iRadius]
[0]; // NOTE: This points to the VALUE of the radius
}
void VerifyRadGyra(BODY *body, CONTROL *control, OPTIONS *options,
UPDATE *update, double dAge, int iBody) {
// If evolving radius of gyration, stellar model must be set
if (body[iBody].bEvolveRG) {
// Assign radius
if (body[iBody].iStellarModel == STELLAR_MODEL_BARAFFE) {
body[iBody].dRadGyra =
fdRadGyraFunctionBaraffe(body[iBody].dAge, body[iBody].dMass);
if (options[OPT_RG].iLine[iBody + 1] >= 0) {
// User specified radius of gyration, but we're reading it from the
// grid!
if (control->Io.iVerbose >= VERBINPUT) {
printf("INFO: Radius of Gyration set for body %d, but this value "
"will be computed from the grid.\n",
iBody);
}
}
} else if (body[iBody].iStellarModel == STELLAR_MODEL_PROXIMACEN) {
if (options[OPT_RG].iLine[iBody + 1] < 0) {
// User specified radius, but we're reading it from the grid!
if (control->Io.iVerbose >= VERBINPUT) {
printf("ERROR: Must set radius of gyration for body %d when using "
"Proxima Cen stellar model.\n",
iBody);
}
exit(1);
}
}
update[iBody].iaType[update[iBody].iRadGyra][0] = 0;
update[iBody].iNumBodies[update[iBody].iRadGyra][0] = 1;
update[iBody].iaBody[update[iBody].iRadGyra][0] = malloc(
update[iBody].iNumBodies[update[iBody].iRadGyra][0] * sizeof(int));
update[iBody].iaBody[update[iBody].iRadGyra][0][0] = iBody;
update[iBody].pdRadGyraStellar =
&update[iBody].daDerivProc[update[iBody].iRadGyra]
[0]; // NOTE: This points to the VALUE of
// the radius of gyration
}
// Not evolving RG, must be supplied by user
else {
if (options[OPT_RG].iLine[iBody + 1] < 0) {
// User specified radius, but we're reading it from the grid!
if (control->Io.iVerbose >= VERBINPUT) {
printf("ERROR: Must set radius of gyration for body %d when its "
"bEvolveRG = 0.\n",
iBody);
}
exit(1);
}
}
}
void VerifyTemperature(BODY *body, CONTROL *control, OPTIONS *options,
UPDATE *update, double dAge, int iBody) {
// Assign temperature
if (body[iBody].iStellarModel == STELLAR_MODEL_BARAFFE) {
body[iBody].dTemperature =
fdTemperatureFunctionBaraffe(body[iBody].dAge, body[iBody].dMass);
if (options[OPT_TEMPERATURE].iLine[iBody + 1] >= 0) {
// User specified temperature, but we're reading it from the grid!
if (control->Io.iVerbose >= VERBINPUT) {
printf("INFO: Temperature set for body %d, but this value will be "
"computed from the grid.\n",
iBody);
}
}
} else if (body[iBody].iStellarModel == STELLAR_MODEL_PROXIMACEN) {
body[iBody].dTemperature =
fdTemperatureFunctionProximaCen(body[iBody].dAge, body[iBody].dMass);
if (options[OPT_TEMPERATURE].iLine[iBody + 1] >= 0) {
// User specified temperature, but we're reading it from the grid!
if (control->Io.iVerbose >= VERBINPUT) {
printf("INFO: Temperature set for body %d, but this value will be "
"computed from the grid.\n",
iBody);
}
}
}
update[iBody].iaType[update[iBody].iTemperature][0] = 0;
update[iBody].iNumBodies[update[iBody].iTemperature][0] = 1;
update[iBody].iaBody[update[iBody].iTemperature][0] = malloc(
update[iBody].iNumBodies[update[iBody].iTemperature][0] * sizeof(int));
update[iBody].iaBody[update[iBody].iTemperature][0][0] = iBody;
update[iBody].pdTemperatureStellar =
&update[iBody].daDerivProc[update[iBody].iTemperature]
[0]; // NOTE: This points to the VALUE of the
// temperature
}
void fnPropsAuxStellar(BODY *body, EVOLVE *evolve, IO *io, UPDATE *update,
int iBody) {
// Set rotation period for rossby number calculations
body[iBody].dRotPer = fdFreqToPer(body[iBody].dRotRate);
// Update LXUV
if (body[iBody].iXUVModel == STELLAR_MODEL_REINERS) {
// REINERS wind model
double dPer, dLXRay, dLXRaySat;
dPer = 2 * PI / body[iBody].dRotRate;
// Unsaturated regime (Reiners, Schussler & Passegger 2014, eqn. (11))
dLXRay = 1.e-7 * pow(10., 30.71 - 2.01 * log10(dPer / DAYSEC));
// Saturated regime (Reiners, Schussler & Passegger 2014)
dLXRaySat = body[iBody].dLuminosity *
pow(10., -3.12 - 0.11 * log10(dPer / DAYSEC));
// Take the lesser value
if (dLXRay > dLXRaySat) {
dLXRay = dLXRaySat;
}
/* Sanz-Forcada et al. (2011), eqn (3)
Not used here, but maybe useful elsewhere?
dLEUV = 1.e7 * pow(10., 4.80 + 0.860 * log10(dLXRay * 1.e-7));
*/
// NOTE: We should add XRay and EUV to get XUV, but the Sanz-Forcada
// model above yields unrealistically high EUV luminosities for M dwarfs.
body[iBody].dLXUV = dLXRay;
} else if (body[iBody].iXUVModel == STELLAR_MODEL_RIBAS) {
// RIBAS power-law decay model
double dAge = body[iBody].dAge / (1.e9 * YEARSEC);
double dTMin = body[iBody].dSatXUVTime / (1.e9 * YEARSEC);
if (dAge >= dTMin) {
body[iBody].dLXUV = body[iBody].dSatXUVFrac * body[iBody].dLuminosity *
pow(dAge / dTMin, -body[iBody].dXUVBeta);
} else {
/* No evolution at times earlier than dSatXUVTime */
body[iBody].dLXUV = body[iBody].dSatXUVFrac * body[iBody].dLuminosity;
}
} else {
// Constant XUV fraction
body[iBody].dLXUV = body[iBody].dSatXUVFrac * body[iBody].dLuminosity;
}
}
void fnForceBehaviorStellar(BODY *body, MODULE *module, EVOLVE *evolve, IO *io,
SYSTEM *system, UPDATE *update,
fnUpdateVariable ***fnUpdate, int iBody,
int iModule) {
// Nothing
}
void AssignStellarDerivatives(BODY *body, EVOLVE *evolve, UPDATE *update,
fnUpdateVariable ***fnUpdate, int iBody) {
fnUpdate[iBody][update[iBody].iRot][update[iBody].iRotStellar] =
&fdDRotRateDt;
fnUpdate[iBody][update[iBody].iLostAngMom][update[iBody].iLostAngMomStellar] =
&fdDJDtMagBrakingStellar;
fnUpdate[iBody][update[iBody].iLostEng][update[iBody].iLostEngStellar] =
&fdDEDtStellar;
fnUpdate[iBody][update[iBody].iLuminosity][0] =
&fdLuminosity; // NOTE: This points to the value of the Luminosity!
fnUpdate[iBody][update[iBody].iRadius][0] =
&fdRadius; // NOTE: This points to the value of the Radius!
fnUpdate[iBody][update[iBody].iTemperature][0] =
&fdTemperature; // NOTE: This points to the value of the Temperature!
if (body[iBody].bEvolveRG) {
fnUpdate[iBody][update[iBody].iRadGyra][0] =
&fdRadGyra; // NOTE: This points to the value of the Radius of
// Gyration!
}
}
void NullStellarDerivatives(BODY *body, EVOLVE *evolve, UPDATE *update,
fnUpdateVariable ***fnUpdate, int iBody) {
fnUpdate[iBody][update[iBody].iRot][update[iBody].iRotStellar] =
&fndUpdateFunctionTiny;
fnUpdate[iBody][update[iBody].iLostAngMom][update[iBody].iLostAngMomStellar] =
&fndUpdateFunctionTiny;
fnUpdate[iBody][update[iBody].iLostEng][update[iBody].iLostEngStellar] =
&fndUpdateFunctionTiny;
fnUpdate[iBody][update[iBody].iLuminosity][0] =
&fndUpdateFunctionTiny; // NOTE: This points to the value of the
// Luminosity!
fnUpdate[iBody][update[iBody].iRadius][0] =
&fndUpdateFunctionTiny; // NOTE: This points to the value of the Radius!
fnUpdate[iBody][update[iBody].iTemperature][0] =
&fndUpdateFunctionTiny; // NOTE: This points to the value of the
// Temperature!
if (body[iBody].bEvolveRG) {
fnUpdate[iBody][update[iBody].iRadGyra][0] =
&fndUpdateFunctionTiny; // NOTE: This points to the value of the
// Radius of Gyration!
}
}
void VerifyStellar(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
OUTPUT *output, SYSTEM *system, UPDATE *update, int iBody,
int iModule) {
/* Stellar is active for this body if this subroutine is called. */
if (update[iBody].iNumLuminosity > 1) {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr,
"ERROR: Looks like there's more than one equation trying to set "
"dLuminosity for body %d!",
iBody);
}
exit(EXIT_INPUT);
}
VerifyLuminosity(body, control, options, update, body[iBody].dAge, iBody);
if (update[iBody].iNumRadius > 1) {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr,
"ERROR: Looks like there's more than one equation trying to set "
"dRadius for body %d!",
iBody);
}
exit(EXIT_INPUT);
}
if (update[iBody].iNumRadGyra > 1) {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr,
"ERROR: Looks like there's more than one equation trying to set "
"dRadGyra for body %d!",
iBody);
}
exit(EXIT_INPUT);
}
VerifyRadius(body, control, options, update, body[iBody].dAge, iBody);
VerifyRadGyra(body, control, options, update, body[iBody].dAge, iBody);
VerifyRotRate(body, control, options, update, body[iBody].dAge, iBody);
if (update[iBody].iNumTemperature > 1) {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr,
"ERROR: Looks like there's more than one equation trying to set "
"dTemperature for body %d!",
iBody);
}
exit(EXIT_INPUT);
}
VerifyTemperature(body, control, options, update, body[iBody].dAge, iBody);
VerifyLostAngMomStellar(body, control, options, update, body[iBody].dAge,
iBody);
VerifyLostEngStellar(body, control, options, update, body[iBody].dAge, iBody);
control->fnForceBehavior[iBody][iModule] = &fnForceBehaviorStellar;
control->fnPropsAux[iBody][iModule] = &fnPropsAuxStellar;
control->Evolve.fnBodyCopy[iBody][iModule] = &BodyCopyStellar;
}
void InitializeModuleStellar(CONTROL *control, MODULE *module) {
/* Anything Here? */
}
/**************** STELLAR update ****************/
void InitializeUpdateStellar(BODY *body, UPDATE *update, int iBody) {
// if (body[iBody].dLuminosity > 0) {
if (update[iBody].iNumLuminosity == 0) {
update[iBody].iNumVars++;
}
update[iBody].iNumLuminosity++;
//}
if (body[iBody].dRadius > 0) {
if (update[iBody].iNumRadius == 0) {
update[iBody].iNumVars++;
}
update[iBody].iNumRadius++;
}
if (body[iBody].dRadGyra > 0 && body[iBody].bEvolveRG) {
if (update[iBody].iNumRadGyra == 0) {
update[iBody].iNumVars++;
}
update[iBody].iNumRadGyra++;
}
// NOTE: Rory and Rodrigo decided to ALWAYS track the rotation evolution of
// the star, so I'm not going to check whether dRotRate is zero here. If it
// is, it gets set to its default value, and we track angular momentum
// conservation from there.
if (update[iBody].iNumRot == 0) {
update[iBody].iNumVars++;
}
update[iBody].iNumRot++;
if (update[iBody].iNumLostAngMom == 0) {
update[iBody].iNumVars++;
}
update[iBody].iNumLostAngMom++;
if (update[iBody].iNumLostEng == 0) {
update[iBody].iNumVars++;
}
update[iBody].iNumLostEng++;
if (body[iBody].dTemperature > 0) {
if (update[iBody].iNumTemperature == 0) {
update[iBody].iNumVars++;
}
update[iBody].iNumTemperature++;
}
}
void FinalizeUpdateEccStellar(BODY *body, UPDATE *update, int *iEqn, int iVar,
int iBody, int iFoo) {
/* Nothing */
}
void FinalizeUpdateLuminosityStellar(BODY *body, UPDATE *update, int *iEqn,
int iVar, int iBody, int iFoo) {
update[iBody].iaModule[iVar][*iEqn] = STELLAR;
update[iBody].iNumLuminosity = (*iEqn)++;
}
void FinalizeUpdateRadiusStellar(BODY *body, UPDATE *update, int *iEqn,
int iVar, int iBody, int iFoo) {
update[iBody].iaModule[iVar][*iEqn] = STELLAR;
update[iBody].iNumRadius = (*iEqn)++;
}
void FinalizeUpdateRadGyraStellar(BODY *body, UPDATE *update, int *iEqn,
int iVar, int iBody, int iFoo) {
if (body[iBody].bEvolveRG) {
update[iBody].iaModule[iVar][*iEqn] = STELLAR;
update[iBody].iNumRadGyra = (*iEqn)++;
}
}
void FinalizeUpdateRotRateStellar(BODY *body, UPDATE *update, int *iEqn,
int iVar, int iBody, int iFoo) {
update[iBody].iaModule[iVar][*iEqn] = STELLAR;
update[iBody].iRotStellar = (*iEqn)++;
}
void FinalizeUpdateLostAngMomStellar(BODY *body, UPDATE *update, int *iEqn,