-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathenviro.cpp
More file actions
3712 lines (3466 loc) · 118 KB
/
Copy pathenviro.cpp
File metadata and controls
3712 lines (3466 loc) · 118 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
#include "enviro.h"
#include <boost/concept_check.hpp>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include "const.h"
#include "elements.h"
#include "gas_radius_helpers.h"
#include "radius_tables.h"
#include "solid_radius_helpers.h"
#include "star_temps.h"
#include "stargen.h"
#include "utils.h"
using namespace std;
string breathability_phrase[4] =
{
"none",
"breathable",
"unbreathable",
"poisonous"
};
map<map<long double, long double>, vector<long double> > polynomial_cache;
long double mass_to_luminosity(long double mass)
{
if (mass <= 0.6224)
{
return 0.3815 * pow(mass, 2.5185);
}
else if (mass <= 1.0)
{
return pow(mass, 4.551);
}
else if (mass <= 3.1623)
{
return pow(mass, 4.351);
}
else if (mass <= 16.0)
{
return 2.7563 * pow(mass, 3.4704);
}
else
{
return 42.321 * pow(mass, 2.4853);
}
}
long double luminosity_to_mass(long double luminosity)
{
long double a = luminosity;
if (a <= (0.3815 * pow(0.6224, 2.5185)))
{
return 1.46613 * pow(a, 0.3970617431010522);
}
else if (a <= 1)
{
return pow(a, 0.2197319270490002);
}
else if (a <= pow(3.1623, 4.351))
{
return pow(a, 0.2298322224775914);
}
else if (a <= (2.7563 * pow(16, 3.4704)))
{
return 0.746654 * pow(a, 0.2881512217611803);
}
else
{
return 0.221579 * pow(a, 0.4023659115599726);
}
}
int getLumIndex(string spec_type)
{
const char *strPtr;
strPtr = strstr(spec_type.c_str(), "Ia0");
if (strPtr != NULL)
{
return 2;
}
else
{
strPtr = strstr(spec_type.c_str(), "Ia");
if (strPtr != NULL)
{
return 2;
}
else
{
strPtr = strstr(spec_type.c_str(), "Ib");
if (strPtr != NULL)
{
return 2;
}
else
{
strPtr = strstr(spec_type.c_str(), "III");
if (strPtr != NULL)
{
return 1;
}
else
{
strPtr = strstr(spec_type.c_str(), "II");
if (strPtr != NULL)
{
return 2;
}
else
{
strPtr = strstr(spec_type.c_str(), "IV");
if (strPtr != NULL)
{
return 1;
}
else
{
strPtr = strstr(spec_type.c_str(), "VI");
if (strPtr != NULL)
{
return 0;
}
else
{
return 0;
}
}
}
}
}
}
}
}
string getStarType(string spec_type)
{
spec_type = my_strtoupper(spec_type);
const char *strPtr;
strPtr = strstr(spec_type.c_str(), "DA");
if (strPtr != NULL)
{
return "WD";
}
else
{
strPtr = strstr(spec_type.c_str(), "DB");
if (strPtr != NULL)
{
return "WD";
}
else
{
strPtr = strstr(spec_type.c_str(), "DC");
if (strPtr != NULL)
{
return "WD";
}
else
{
strPtr = strstr(spec_type.c_str(), "DO");
if (strPtr != NULL)
{
return "WD";
}
else
{
strPtr = strstr(spec_type.c_str(), "DQ");
if (strPtr != NULL)
{
return "WD";
}
else
{
strPtr = strstr(spec_type.c_str(), "DZ");
if (strPtr != NULL)
{
return "WD";
}
else
{
strPtr = strstr(spec_type.c_str(), "WN");
if (strPtr != NULL)
{
return "WN";
}
else
{
strPtr = strstr(spec_type.c_str(), "WC");
if (strPtr != NULL)
{
return "WC";
}
else
{
strPtr = strstr(spec_type.c_str(), "O");
if (strPtr != NULL)
{
return "O";
}
else
{
strPtr = strstr(spec_type.c_str(), "B");
if (strPtr != NULL)
{
return "B";
}
else
{
strPtr = strstr(spec_type.c_str(), "A");
if (strPtr != NULL)
{
return "A";
}
else
{
strPtr = strstr(spec_type.c_str(), "F");
if (strPtr != NULL)
{
return "F";
}
else
{
strPtr = strstr(spec_type.c_str(), "G");
if (strPtr != NULL)
{
return "G";
}
else
{
strPtr = strstr(spec_type.c_str(), "K");
if (strPtr != NULL)
{
return "K";
}
else
{
strPtr = strstr(spec_type.c_str(), "M");
if (strPtr != NULL)
{
return "M";
}
else
{
strPtr = strstr(spec_type.c_str(), "L");
if (strPtr != NULL)
{
return "L";
}
else
{
strPtr = strstr(spec_type.c_str(), "T");
if (strPtr != NULL)
{
return "T";
}
else
{
strPtr = strstr(spec_type.c_str(), "Y");
if (strPtr != NULL)
{
return "Y";
}
else
{
strPtr = strstr(spec_type.c_str(), "H");
if (strPtr != NULL)
{
return "H";
}
else
{
strPtr = strstr(spec_type.c_str(), "E");
if (strPtr != NULL)
{
return "E";
}
else
{
strPtr = strstr(spec_type.c_str(), "I");
if (strPtr != NULL)
{
return "I";
}
else
{
strPtr = strstr(spec_type.c_str(), "R");
if (strPtr != NULL)
{
return "K";
}
else
{
strPtr = strstr(spec_type.c_str(), "S");
if (strPtr != NULL)
{
return "M";
}
else
{
strPtr = strstr(spec_type.c_str(), "N");
if (strPtr != NULL)
{
return "M";
}
else
{
strPtr = strstr(spec_type.c_str(), "C");
if (strPtr != NULL)
{
return "M";
}
else
{
//cerr << "test1" << endl;
cerr << "Unsupported star type: " << spec_type << endl;
exit(EXIT_FAILURE);
return NULL;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
int getSubType(string spec_type)
{
int total_chars;
total_chars = spec_type.size();
string buffer;
for (string::iterator it = spec_type.begin(); it < spec_type.end(); it++)
{
if (isdigit(*it))
{
buffer += *it;
return atoi(buffer.c_str());
}
}
return 0;
}
long double spec_type_to_eff_temp(string spec_type)
{
if (spec_type.empty())
{
return 0;
}
string star_type;
int lumIndex;
int sub_type;
//cout << "test3" << endl;
star_type = getStarType(spec_type);
//cout << "test4" << endl;
sub_type = getSubType(spec_type);
lumIndex = getLumIndex(spec_type);
if (strcmp(star_type.c_str(), "WD") == 0)
{
return tempWD[sub_type];
}
else if (strcmp(star_type.c_str(), "WN") == 0)
{
return tempWN[sub_type];
}
else if (strcmp(star_type.c_str(), "WC") == 0)
{
return tempWC[sub_type];
}
else if (strcmp(star_type.c_str(), "O") == 0)
{
return tempO[lumIndex][sub_type];
}
else if (strcmp(star_type.c_str(), "B") == 0)
{
return tempB[lumIndex][sub_type];
}
else if (strcmp(star_type.c_str(), "A") == 0)
{
return tempA[lumIndex][sub_type];
}
else if (strcmp(star_type.c_str(), "F") == 0)
{
return tempF[lumIndex][sub_type];
}
else if (strcmp(star_type.c_str(), "G") == 0)
{
return tempG[lumIndex][sub_type];
}
else if (strcmp(star_type.c_str(), "K") == 0)
{
//fprintf(stderr, "%u %u %8.8LG\n", lumIndex, sub_type, tempK[lumIndex][sub_type]);
//exit(EXIT_FAILURE);
return tempK[lumIndex][sub_type];
}
else if (strcmp(star_type.c_str(), "M") == 0)
{
return tempM[lumIndex][sub_type];
}
else if (strcmp(star_type.c_str(), "L") == 0)
{
return tempL[sub_type];
}
else if (strcmp(star_type.c_str(), "T") == 0)
{
return tempT[sub_type];
}
else if (strcmp(star_type.c_str(), "Y") == 0)
{
return tempY[sub_type];
}
else if (strcmp(star_type.c_str(), "H") == 0)
{
return tempH[sub_type];
}
else if (strcmp(star_type.c_str(), "I") == 0)
{
return tempI[sub_type];
}
else if (strcmp(star_type.c_str(), "E") == 0)
{
return tempE[sub_type];
}
else
{
//cerr << "test2" << endl;
cerr << "Unsupported star type: " << star_type << endl;
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}
}
string eff_temp_to_spec_type(long double eff_temp, long double luminosity)
{
string clums[] = {"I-a0", "I-a", "I-b", "II", "III", "IV"};
long double rlums[] = {200000.0, 20000.0, 3000.0, 400.0, 11.5, 4.0};
string classes[] = {"x", "O", "B", "A", "F", "G", "K", "M", "L", "T", "Y"};
long double tclass[] = {52000, 30000.0, 10000.0, 7500.0, 6000.0, 5000.0, 3500.0, 2000.0, 1300.0, 700.0, 0.0};
int at;
long double csiz, cdel, cfrac, dt;
string aclass, ac, clum;
char temp[33];
long double xmag;
string output;
if (luminosity == 0)
{
luminosity = 0.0000001; // avoid getting an undefined answer for log(xlum)
}
xmag = 4.83 - (2.5 * (log(luminosity) / log(10.0)));
// determine spectral clas
output = aclass = "????";
at = 0;
for (int i = 1; i <= 10; i++)
{
if (eff_temp > tclass[i])
{
ac = classes[i];
csiz = tclass[i-1] - tclass[i];
cdel = eff_temp - tclass[i];
cfrac = cdel / csiz;
dt = 10.0 - (10.0 * cfrac);
if (dt < 0.0)
{
dt = 0.0;
}
at = floor(dt);
my_itoa(at, temp, 10);
aclass = ac.append(temp);
break;
}
}
clum = " ";
if (eff_temp > 52000) // the hotest a type O star can get is 52000. Any hotter and the star is most likely a Wolf–Rayet star
{
ac = "WN";
csiz = 200000 - 52000;
cdel = eff_temp - 52000;
cfrac = cdel / csiz;
dt = 10.0 - (10.0 * cfrac);
if (dt < 0.0)
{
dt = 0.0;
}
at = floor(dt);
my_itoa(at, temp, 10);
aclass = ac.append(temp);
}
else
{
if (compare_string_char(aclass, 1, "O"))
{
if (xmag < -9)
{
aclass.append("O");
}
else if (xmag < -7)
{
aclass.append("Ia");
}
else if (xmag < -6)
{
aclass.append("Ib");
}
else if (xmag < -4.9)
{
aclass.append("II");
}
else if (xmag < -4)
{
aclass.append("III");
}
else
{
aclass.append("V");
}
}
else if (compare_string_char(aclass, 1, "B"))
{
if (xmag < -9)
{
aclass.append("O");
}
else if (xmag < -7)
{
aclass.append("Ia");
}
else if (xmag < -5)
{
aclass.append("Ib");
}
else if (xmag < -4.5)
{
aclass.append("II");
}
else if (xmag < -0.5)
{
aclass.append("III");
}
else
{
aclass.append("V");
}
}
else if (compare_string_char(aclass, 1, "A"))
{
if (xmag < -9)
{
aclass.append("O");
}
else if (xmag < -7)
{
aclass.append("Ia");
}
else if (xmag < -4.5)
{
aclass.append("Ib");
}
else if (xmag < -2.25)
{
aclass.append("II");
}
else if (xmag < 0)
{
aclass.append("III");
}
else if (xmag < 0.125)
{
aclass.append("IV");
}
else
{
aclass.append("V");
}
}
else if (compare_string_char(aclass, 1, "F"))
{
if (xmag < -9)
{
aclass.append("O");
}
else if (xmag < -7)
{
aclass.append("Ia");
}
else if (xmag < -4.5)
{
aclass.append("Ib");
}
else if (xmag < -2)
{
aclass.append("II");
}
else if (xmag < 1.75)
{
aclass.append("III");
}
else if (xmag < 3)
{
aclass.append("IV");
}
else
{
aclass.append("V");
}
}
else if (compare_string_char(aclass, 1, "G"))
{
if (xmag < -9)
{
aclass.append("O");
}
else if (xmag < -7)
{
aclass.append("Ia");
}
else if (xmag < -4.5)
{
aclass.append("Ib");
}
else if (xmag < -2.25)
{
aclass.append("II");
}
else if (xmag < 1.75)
{
aclass.append("III");
}
else if (xmag < 3)
{
aclass.append("IV");
}
else
{
aclass.append("V");
}
}
else if (compare_string_char(aclass, 1, "K"))
{
if (xmag < -9)
{
aclass.append("O");
}
else if (xmag < -7)
{
aclass.append("Ia");
}
else if (xmag < -4.5)
{
aclass.append("Ib");
}
else if (xmag < -2)
{
aclass.append("II");
}
else if (xmag < 2)
{
aclass.append("III");
}
else if (xmag < 4)
{
aclass.append("IV");
}
else
{
aclass.append("V");
}
}
else if (compare_string_char(aclass, 1, "M"))
{
if (xmag < -9)
{
aclass.append("O");
}
else if (xmag < -7)
{
aclass.append("Ia");
}
else if (xmag < -4.5)
{
aclass.append("Ib");
}
else if (xmag < -2)
{
aclass.append("II");
}
else if (xmag < 2.5)
{
aclass.append("III");
}
else
{
aclass.append("V");
}
}
else
{
aclass.append("V");
}
}
output = aclass;
return output;
}
/*--------------------------------------------------------------------------*/
/* This function, given the orbital radius of a planet in AU, returns */
/* the orbital 'zone' of the particle. */
/*--------------------------------------------------------------------------*/
int orb_zone(long double ecosphere_radius, long double orb_radius)
{
if (orb_radius < (4.0 * ecosphere_radius))
{
return 1;
}
else if (orb_radius < (15.0 * ecosphere_radius))
{
return 2;
}
else
{
return 3;
}
}
/*-------------------------------------------------------------------*/
/* The mass is in units of solar masses, and the density is in units */
/* of grams/cc. The radius returned is in units of km. */
/*-------------------------------------------------------------------*/
long double volume_radius(long double mass, long double density)
{
long double volume;
mass = mass * SOLAR_MASS_IN_GRAMS;
volume = mass / density;
return pow((3.0 * volume) / (4.0 * PI), (1.0 / 3.0)) / CM_PER_KM;
}
/*------------------------------------------------------------------------*/
/* The mass passed in is in units of solar masses, and the orbital radius */
/* is in units of AU. The density is returned in units of grams/cc. */
/*------------------------------------------------------------------------*/
long double empirical_density(long double mass, long double orb_radius, long double r_ecosphere, bool gas_giant)
{
long double temp;
temp = pow(mass * SUN_MASS_IN_EARTH_MASSES, 1.0 / 8.0);
temp = temp * pow1_4(r_ecosphere / orb_radius);
if (gas_giant)
{
return temp * 1.2;
}
else
{
return temp * 5.5;
}
}
/*--------------------------------------------------------------------*/
/* The mass passed in is in units of solar masses, and the equatorial */
/* radius is in km. The density is returned in units of grams/cc. */
/*--------------------------------------------------------------------*/
long double volume_density(long double mass, long double equat_radius)
{
long double volume;
mass = mass * SOLAR_MASS_IN_GRAMS;
equat_radius = equat_radius * CM_PER_KM;
volume = (4.0 * PI * pow3(equat_radius)) / 3.0;
return mass / volume;
}
/*-------------------------------------------------------------------------*/
/* The separation is in units of AU, and both masses are in units of solar */
/* masses. The period returned is in terms of Earth days. */
/*-------------------------------------------------------------------------*/
long double period(long double separation, long double small_mass, long double large_mass)
{
long double period_in_years;
period_in_years = sqrt(pow3(separation) / (small_mass + large_mass));
return period_in_years * DAYS_IN_A_YEAR ;
}
/*--------------------------------------------------------------------------*/
/* Fogg's information for this routine came from Dole "Habitable Planets */
/* for Man", Blaisdell Publishing Company, NY, 1964. From this, he came */
/* up with his eq.12, which is the equation for the 'base_angular_velocity' */
/* below. He then used an equation for the change in angular velocity per */
/* time (dw/dt) from P. Goldreich and S. Soter's paper "Q in the Solar */
/* System" in Icarus, vol 5, pp.375-389 (1966). Using as a comparison the */
/* change in angular velocity for the Earth, Fogg has come up with an */
/* approximation for our new planet (his eq.13) and take that into account. */
/* This is used to find 'change_in_angular_velocity' below. */
/* */
/* Input parameters are mass (in solar masses), radius (in Km), orbital */
/* period (in days), orbital radius (in AU), density (in g/cc), */
/* eccentricity, and whether it is a gas giant or not. */
/* The length of the day is returned in units of hours. */
/*--------------------------------------------------------------------------*/
long double day_length(planet *the_planet, long double parent_mass, bool is_moon)
{
long double planetary_mass_in_grams = the_planet->getMass() * SOLAR_MASS_IN_GRAMS;
long double equatorial_radius_in_cm = the_planet->getRadius() * CM_PER_KM;
long double year_in_hours = the_planet->getOrbPeriod() * 24.0;
bool giant = the_planet->getType() == tGasGiant || the_planet->getType() == tBrownDwarf || the_planet->getType() == tSubGasGiant || the_planet->getType() == tSubSubGasGiant;
long double k2;
long double base_angular_velocity;
long double change_in_angular_velocity;
long double ang_velocity;
long double spin_resonance_factor;
long double day_in_hours;
bool stopped = false;
the_planet->setResonantPeriod(false);
/*if (giant)
{
k2 = 0.24;
}
else
{
k2 = 0.33;
}*/
k2 = calculate_moment_of_inertia_coeffient(the_planet);
// Calculate the base angular velocity
base_angular_velocity = sqrt(2.0 * J * (planetary_mass_in_grams) / (k2 * pow2(equatorial_radius_in_cm)));
// This next calculation determines how much the planet's rotation is
// slowed by the presence of the parent body.
if (!is_moon)
{
change_in_angular_velocity = CHANGE_IN_EARTH_ANG_VEL * (the_planet->getDensity() / EARTH_DENSITY) * (equatorial_radius_in_cm / EARTH_RADIUS) * (EARTH_MASS_IN_GRAMS / planetary_mass_in_grams) * pow(parent_mass, 2.0) * (1.0 / pow(the_planet->getA(), 6.0));
}
else
{
change_in_angular_velocity = CHANGE_IN_EARTH_ANG_VEL * (the_planet->getDensity() / EARTH_DENSITY) * (equatorial_radius_in_cm / EARTH_RADIUS) * (EARTH_MASS_IN_GRAMS / planetary_mass_in_grams) * pow(parent_mass, 2.0) * (1.0 / pow(the_planet->getMoonA(), 6.0));
}
ang_velocity = base_angular_velocity + (change_in_angular_velocity * the_planet->getTheSun().getAge());
if (ang_velocity <= 0.0)
{
stopped = true;
day_in_hours = INCREDIBLY_LARGE_NUMBER;
}
else
{
day_in_hours = RADIANS_PER_ROTATION / (SECONDS_PER_HOUR * ang_velocity);
}
if (day_in_hours >= year_in_hours || stopped)
{
if ((the_planet->getE() > 0.1 && !is_moon) || (the_planet->getMoonE() > 0.1 && is_moon))
{
if (!is_moon)
{
spin_resonance_factor = getSpinResonanceFactor(the_planet->getE());
}
else
{
spin_resonance_factor = getSpinResonanceFactor(the_planet->getMoonE());
}
the_planet->setResonantPeriod(true);
return spin_resonance_factor * year_in_hours;
}
else
{
the_planet->setAxialTilt(0);
return day_in_hours = year_in_hours;
}
}
return day_in_hours;
}
/*---------------------------------------------------------------------*/
/* The orbital radius is expected in units of Astronomical Units (AU). */
/* Inclination is returned in units of degrees. (seb: real) */
/*---------------------------------------------------------------------*/
long double inclination(long double orb_radius, long double parent_mass)
{
// seb: Earth's obliquity is not a good test
// a. want real result, not integer
// b. obliquity of planets near stars is erroded by tidal heating
// ref: http://arxiv.org/abs/1101.2156
// Tidal obliquity evolution of potentialy habitable planets
// Heller et al. (2011)
long double temp;
temp = fabs(gaussian(33.3));
temp = pow(orb_radius/50.0,0.2) * temp;
if (orb_radius < parent_mass)
{
temp = (orb_radius / parent_mass) * temp;
}
return temp;
}
/*-----------------------------------------------------------------------*/
/* This function implements the escape velocity calculation. Note that */
/* it appears that Fogg's eq.15 is incorrect. */
/* The mass is in units of solar mass, the radius in kilometers, and the */
/* velocity returned is in cm/sec. */
/*-----------------------------------------------------------------------*/
long double escape_vel(long double mass, long double radius)
{
long double mass_in_grams, radius_in_cm;
mass_in_grams = mass * SOLAR_MASS_IN_GRAMS;
radius_in_cm = radius * CM_PER_KM;
return sqrt(2.0 * GRAV_CONSTANT * mass_in_grams / radius_in_cm);
}
/*------------------------------------------------------------------------*/
/* This is Fogg's eq.16. The molecular weight (usually assumed to be N2) */
/* is used as the basis of the Root Mean Square (RMS) velocity of the */
/* molecule or atom. The velocity returned is in cm/sec. */
/* Orbital radius is in A.U.(ie: in units of the earth's orbital radius). */
/*------------------------------------------------------------------------*/
long double rms_vel(long double molecular_weight, long double exospheric_temp)
{
return sqrt((3.0 * MOLAR_GAS_CONST * exospheric_temp) / molecular_weight) * CM_PER_METER;
}
long double min_molec_weight(planet *the_planet)
{
long double mass = the_planet->getMass();
long double radius = the_planet->getRadius();
long double temp = the_planet->getExosphericTemp();
long double target = 5.0E9;
long double guess_1 = molecule_limit(mass, radius, temp);
long double guess_2 = guess_1;
long double life = gas_life(guess_1, the_planet);
int loops = 0;
target = the_planet->getTheSun().getAge();
if (life > target)
{
while (life > target && loops++ < 25)
{
guess_1 = guess_1 / 2.0;
life = gas_life(guess_1, the_planet);
}
}
else
{
while (life < target && loops++ < 25)
{
guess_2 = guess_2 * 2.0;
life = gas_life(guess_2, the_planet);
}
}
loops = 0;